This commit is contained in:
k0shk0sh 2019-12-26 10:16:05 +01:00
parent 150a336c02
commit 059fbc9d75
2 changed files with 43 additions and 24 deletions

View File

@ -5,6 +5,7 @@ import android.app.NotificationManager;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import androidx.annotation.IntDef;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
@ -18,6 +19,7 @@ import com.fastaccess.provider.rest.RestProvider;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.schedulers.Schedulers;
@ -37,6 +39,7 @@ public class GithubActionService extends IntentService {
public static final int FORK_GIST = 8;
private NotificationCompat.Builder notification;
private NotificationManager notificationManager;
private CompositeDisposable disposable = new CompositeDisposable();
@IntDef({
STAR_REPO,
@ -112,99 +115,114 @@ public class GithubActionService extends IntentService {
}
}
@Override public void onDestroy() {
disposable.clear();
super.onDestroy();
}
private void forkGist(@Nullable String id, boolean isEnterprise) {
if (id != null) {
String msg = getString(R.string.forking, getString(R.string.gist));
RestProvider.getGistService(isEnterprise)
.forkGist(id)
.doOnSubscribe(disposable -> showNotification(msg))
.subscribeOn(Schedulers.io())
.subscribe(response -> {
}, throwable -> hideNotification(msg), () -> hideNotification(msg));
disposable.add(
RestProvider.getGistService(isEnterprise)
.forkGist(id)
.doOnSubscribe(disposable -> showNotification(msg))
.subscribeOn(Schedulers.io())
.subscribe(response -> {
}, throwable -> hideNotification(msg), () -> hideNotification(msg))
);
}
}
private void forkRepo(@Nullable String id, @Nullable String login, boolean isEnterprise) {
if (id != null && login != null) {
String msg = getString(R.string.forking, id);
RestProvider.getRepoService(isEnterprise)
.forkRepo(login, id)
.doOnSubscribe(disposable -> showNotification(msg))
.subscribeOn(Schedulers.io())
.subscribe(response -> {
}, throwable -> hideNotification(msg), () -> hideNotification(msg));
disposable.add(
RestProvider.getRepoService(isEnterprise)
.forkRepo(login, id)
.doOnSubscribe(disposable -> showNotification(msg))
.subscribeOn(Schedulers.io())
.subscribe(response -> {
}, throwable -> hideNotification(msg), () -> hideNotification(msg))
);
}
}
private void starGist(@Nullable String id, boolean isEnterprise) {
if (id != null) {
String msg = getString(R.string.starring, getString(R.string.gist));
RestProvider.getGistService(isEnterprise)
disposable.add(RestProvider.getGistService(isEnterprise)
.starGist(id)
.doOnSubscribe(disposable -> showNotification(msg))
.subscribeOn(Schedulers.io())
.subscribe(response -> {
}, throwable -> hideNotification(msg), () -> hideNotification(msg));
}, throwable -> hideNotification(msg), () -> hideNotification(msg))
);
}
}
private void starRepo(@Nullable String id, @Nullable String login, boolean isEnterprise) {
if (id != null && login != null) {
String msg = getString(R.string.starring, id);
RestProvider.getRepoService(isEnterprise)
disposable.add(RestProvider.getRepoService(isEnterprise)
.starRepo(login, id)
.doOnSubscribe(disposable -> showNotification(msg))
.subscribeOn(Schedulers.io())
.subscribe(response -> {
}, throwable -> hideNotification(msg), () -> hideNotification(msg));
}, throwable -> hideNotification(msg), () -> hideNotification(msg))
);
}
}
private void unStarGist(@Nullable String id, boolean isEnterprise) {
if (id != null) {
String msg = getString(R.string.un_starring, getString(R.string.gist));
RestProvider.getGistService(isEnterprise)
disposable.add(RestProvider.getGistService(isEnterprise)
.unStarGist(id)
.doOnSubscribe(disposable -> showNotification(msg))
.subscribeOn(Schedulers.io())
.subscribe(response -> {
}, throwable -> hideNotification(msg), () -> hideNotification(msg));
}, throwable -> hideNotification(msg), () -> hideNotification(msg))
);
}
}
private void unStarRepo(@Nullable String id, @Nullable String login, boolean isEnterprise) {
if (id != null && login != null) {
String msg = getString(R.string.un_starring, id);
RestProvider.getRepoService(isEnterprise)
disposable.add(RestProvider.getRepoService(isEnterprise)
.unstarRepo(login, id)
.doOnSubscribe(disposable -> showNotification(msg))
.subscribeOn(Schedulers.io())
.subscribe(response -> {
}, throwable -> hideNotification(msg), () -> hideNotification(msg));
}, throwable -> hideNotification(msg), () -> hideNotification(msg))
);
}
}
private void unWatchRepo(@Nullable String id, @Nullable String login, boolean isEnterprise) {
if (id != null && login != null) {
String msg = getString(R.string.un_watching, id);
RestProvider.getRepoService(isEnterprise)
disposable.add(RestProvider.getRepoService(isEnterprise)
.unwatchRepo(login, id)
.doOnSubscribe(disposable -> showNotification(msg))
.subscribeOn(Schedulers.io())
.subscribe(response -> {
}, throwable -> hideNotification(msg), () -> hideNotification(msg));
}, throwable -> hideNotification(msg), () -> hideNotification(msg))
);
}
}
private void watchRepo(@Nullable String id, @Nullable String login, boolean isEnterprise) {
if (id != null && login != null) {
String msg = getString(R.string.watching, id);
RestProvider.getRepoService(isEnterprise)
disposable.add(RestProvider.getRepoService(isEnterprise)
.watchRepo(login, id)
.doOnSubscribe(disposable -> showNotification(msg))
.subscribeOn(Schedulers.io())
.subscribe(response -> {
}, throwable -> hideNotification(msg), () -> hideNotification(msg));
}, throwable -> hideNotification(msg), () -> hideNotification(msg))
);
}
}

View File

@ -115,6 +115,7 @@ public class CommentsHelper {
@NonNull public static ArrayList<String> getUsers(@NonNull List<Comment> comments) {
return Stream.of(comments)
.filter(comment -> comment.getUser() != null)
.map(comment -> comment.getUser().getLogin())
.distinct()
.collect(Collectors.toCollection(ArrayList::new));