added background job indicator for star, fork, watch and mark single/all as read to at least let users know what is going on #173

This commit is contained in:
Kosh 2017-03-19 10:49:18 +08:00
parent 8193278a78
commit abe6ab6065
4 changed files with 89 additions and 13 deletions

View File

@ -1,13 +1,16 @@
package com.fastaccess.provider.tasks.git;
import android.app.IntentService;
import android.app.NotificationManager;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.IntDef;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.NotificationCompat;
import com.fastaccess.R;
import com.fastaccess.helper.BundleConstant;
import com.fastaccess.helper.Bundler;
import com.fastaccess.provider.rest.RestProvider;
@ -31,6 +34,8 @@ public class GithubActionService extends IntentService {
public static final int STAR_GIST = 6;
public static final int UNSTAR_GIST = 7;
public static final int FORK_GIST = 8;
private NotificationCompat.Builder notification;
private NotificationManager notificationManager;
@IntDef({
STAR_REPO,
@ -105,81 +110,122 @@ public class GithubActionService extends IntentService {
private void forkGist(@Nullable String id) {
if (id != null) {
String msg = getString(R.string.forking, getString(R.string.gist));
RestProvider.getGistService()
.forkGist(id)
.doOnSubscribe(() -> showNotification(msg))
.subscribeOn(Schedulers.io())
.subscribe(response -> {
}, Throwable::printStackTrace);
}, throwable -> hideNotification(msg), () -> hideNotification(msg));
}
}
private void forkRepo(@Nullable String id, @Nullable String login) {
if (id != null && login != null) {
String msg = getString(R.string.forking, id);
RestProvider.getRepoService()
.forkRepo(login, id)
.doOnSubscribe(() -> showNotification(msg))
.subscribeOn(Schedulers.io())
.subscribe(response -> {
}, Throwable::printStackTrace);
}, throwable -> hideNotification(msg), () -> hideNotification(msg));
}
}
private void starGist(@Nullable String id) {
if (id != null) {
String msg = getString(R.string.staring, getString(R.string.gist));
RestProvider.getGistService()
.starGist(id)
.doOnSubscribe(() -> showNotification(msg))
.subscribeOn(Schedulers.io())
.subscribe(response -> {
}, Throwable::printStackTrace);
}, throwable -> hideNotification(msg), () -> hideNotification(msg));
}
}
private void starRepo(@Nullable String id, @Nullable String login) {
if (id != null && login != null) {
String msg = getString(R.string.staring, id);
RestProvider.getRepoService()
.starRepo(login, id)
.doOnSubscribe(() -> showNotification(msg))
.subscribeOn(Schedulers.io())
.subscribe(response -> {
}, Throwable::printStackTrace);
}, throwable -> hideNotification(msg), () -> hideNotification(msg));
}
}
private void unStarGist(@Nullable String id) {
if (id != null) {
String msg = getString(R.string.un_staring, getString(R.string.gist));
RestProvider.getGistService()
.unStarGist(id)
.doOnSubscribe(() -> showNotification(msg))
.subscribeOn(Schedulers.io())
.subscribe(response -> {
}, Throwable::printStackTrace);
}, throwable -> hideNotification(msg), () -> hideNotification(msg));
}
}
private void unStarRepo(@Nullable String id, @Nullable String login) {
if (id != null && login != null) {
String msg = getString(R.string.un_staring, id);
RestProvider.getRepoService()
.unstarRepo(login, id)
.doOnSubscribe(() -> showNotification(msg))
.subscribeOn(Schedulers.io())
.subscribe(response -> {
}, Throwable::printStackTrace);
}, throwable -> hideNotification(msg), () -> hideNotification(msg));
}
}
private void unWatchRepo(@Nullable String id, @Nullable String login) {
if (id != null && login != null) {
String msg = getString(R.string.un_watching, id);
RestProvider.getRepoService()
.unwatchRepo(login, id)
.doOnSubscribe(() -> showNotification(msg))
.subscribeOn(Schedulers.io())
.subscribe(response -> {
}, Throwable::printStackTrace);
}, throwable -> hideNotification(msg), () -> hideNotification(msg));
}
}
private void watchRepo(@Nullable String id, @Nullable String login) {
if (id != null && login != null) {
String msg = getString(R.string.watching, id);
RestProvider.getRepoService()
.watchRepo(login, id)
.doOnSubscribe(() -> showNotification(msg))
.subscribeOn(Schedulers.io())
.subscribe(response -> {
}, Throwable::printStackTrace);
}, throwable -> hideNotification(msg), () -> hideNotification(msg));
}
}
private NotificationCompat.Builder getNotification(@NonNull String title) {
if (notification == null) {
notification = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_sync)
.setProgress(0, 100, true);
}
notification.setContentTitle(title);
return notification;
}
private NotificationManager getNotificationManager() {
if (notificationManager == null) {
notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
}
return notificationManager;
}
private void showNotification(@NonNull String msg) {
getNotificationManager().notify(msg.hashCode(), getNotification(msg).build());
}
private void hideNotification(@NonNull String msg) {
getNotificationManager().cancel(msg.hashCode());
}
}

View File

@ -1,13 +1,16 @@
package com.fastaccess.provider.tasks.notification;
import android.app.IntentService;
import android.app.NotificationManager;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.NotificationCompat;
import com.annimon.stream.LongStream;
import com.fastaccess.R;
import com.fastaccess.helper.BundleConstant;
import com.fastaccess.helper.Bundler;
import com.fastaccess.provider.rest.RestProvider;
@ -22,6 +25,8 @@ public class ReadNotificationService extends IntentService {
public static final int READ_SINGLE = 1;
public static final int READ_ALL = 2;
private NotificationCompat.Builder notification;
private NotificationManager notificationManager;
public static void start(@NonNull Context context, long id) {
Intent intent = new Intent(context.getApplicationContext(), ReadNotificationService.class);
@ -66,7 +71,26 @@ public class ReadNotificationService extends IntentService {
private void markSingleAsRead(long id) {
RestProvider.getNotificationService()
.markAsRead(String.valueOf(id))
.doOnSubscribe(() -> getNotificationManager().notify((int) id, getNotification().build()))
.subscribeOn(Schedulers.io())
.subscribe(booleanResponse -> {}, Throwable::printStackTrace);
.subscribe(booleanResponse -> {
}, Throwable::printStackTrace, () -> getNotificationManager().cancel((int) id));
}
public NotificationCompat.Builder getNotification() {
if (notification == null) {
notification = new NotificationCompat.Builder(this)
.setContentTitle(getString(R.string.marking_as_read))
.setSmallIcon(R.drawable.ic_sync)
.setProgress(0, 100, true);
}
return notification;
}
public NotificationManager getNotificationManager() {
if (notificationManager == null) {
notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
}
return notificationManager;
}
}

View File

@ -13,7 +13,6 @@ import com.fastaccess.data.dao.model.Event;
import com.fastaccess.data.dao.model.Login;
import com.fastaccess.data.dao.model.Repo;
import com.fastaccess.data.dao.types.EventsType;
import com.fastaccess.helper.InputHelper;
import com.fastaccess.helper.RxHelper;
import com.fastaccess.provider.rest.RestProvider;
import com.fastaccess.provider.scheme.SchemeParser;
@ -112,9 +111,7 @@ class FeedsPresenter extends BasePresenter<FeedsMvp.View> implements FeedsMvp.Pr
SchemeParser.launchUri(v.getContext(), Uri.parse(item.getPayload().getPullRequest().getHtmlUrl()), true);
} else {
Repo repoModel = item.getRepo();
String name = InputHelper.isEmpty(repoModel.getName()) ? repoModel.getFullName() : repoModel.getName();
if (name == null) return;
if (item.getRepo() != null) SchemeParser.launchUri(v.getContext(), Uri.parse(name), true);
if (item.getRepo() != null) SchemeParser.launchUri(v.getContext(), Uri.parse(repoModel.getName()), true);
}
}
}

View File

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportHeight="24.0"
android:viewportWidth="24.0">
<path
android:fillColor="@color/primary_text"
android:pathData="M12,4L12,1L8,5l4,4L12,6c3.31,0 6,2.69 6,6 0,1.01 -0.25,1.97 -0.7,2.8l1.46,1.46C19.54,15.03 20,13.57 20,12c0,-4.42 -3.58,-8 -8,-8zM12,18c-3.31,0 -6,-2.69 -6,-6 0,-1.01 0.25,-1.97 0.7,-2.8L5.24,7.74C4.46,8.97 4,10.43 4,12c0,4.42 3.58,8 8,8v3l4,-4 -4,-4v3z"/>
</vector>