this improves #212 by adding mark as read action to notification panel & eliminate keeping notification in the notification panel #202

This commit is contained in:
Kosh 2017-04-05 14:37:08 +08:00
parent 7e0a407863
commit a6d8f5aa75
4 changed files with 68 additions and 34 deletions

View File

@ -73,6 +73,7 @@
android:name="android.support.PARENT_ACTIVITY"
android:value=".ui.modules.repos.RepoPagerView"/>
</activity>
<activity
android:name=".ui.modules.repos.issues.create.CreateIssueView"
android:configChanges="keyboard|orientation|screenSize"
@ -80,7 +81,6 @@
<activity
android:name=".ui.modules.repos.pull_requests.pull_request.details.PullRequestPagerView"
android:label="@string/pull_request"
android:parentActivityName=".ui.modules.repos.RepoPagerView">
<meta-data
@ -90,7 +90,6 @@
<activity
android:name=".ui.modules.repos.code.commit.details.CommitPagerView"
android:label="@string/commit"
android:parentActivityName=".ui.modules.repos.RepoPagerView">
<meta-data
@ -131,7 +130,13 @@
android:value=".ui.modules.main.MainView"/>
</activity>
<activity android:name=".ui.modules.search.SearchView"/>
<activity
android:name=".ui.modules.search.SearchView"
android:parentActivityName=".ui.modules.main.MainView">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".ui.modules.main.MainView"/>
</activity>
<activity
android:name=".ui.modules.notification.NotificationActivityView"

View File

@ -12,10 +12,10 @@ import android.support.v4.app.NotificationCompat;
import com.annimon.stream.Stream;
import com.fastaccess.R;
import com.fastaccess.data.dao.model.Comment;
import com.fastaccess.data.dao.model.Login;
import com.fastaccess.data.dao.model.Notification;
import com.fastaccess.helper.AppHelper;
import com.fastaccess.helper.BundleConstant;
import com.fastaccess.helper.InputHelper;
import com.fastaccess.helper.PrefGetter;
import com.fastaccess.helper.RxHelper;
@ -50,7 +50,7 @@ public class NotificationSchedulerJobTask extends JobService {
.getNotifications(0)
.subscribeOn(Schedulers.io())
.subscribe(item -> {
AppHelper.cancelNotification(this, BundleConstant.REQUEST_CODE);
AppHelper.cancelAllNotifications(getApplicationContext());
if (item != null) {
onSave(item.getItems());
}
@ -100,17 +100,16 @@ public class NotificationSchedulerJobTask extends JobService {
.filter(Notification::isUnread)
.count();
if (count == 0) {
AppHelper.cancelNotification(this, BundleConstant.REQUEST_CODE);
AppHelper.cancelAllNotifications(getApplicationContext());
return;
}
Context context = getApplicationContext();
Bitmap largeIcon = BitmapFactory.decodeResource(context.getResources(),
R.mipmap.ic_launcher);
int accentColor = ViewHelper.getAccentColor(context);
Notification firstNotification = notificationThreadModels.get(0);
android.app.Notification grouped = getSummaryGroupNotification(firstNotification, accentColor, largeIcon);
showNotification(BundleConstant.REQUEST_CODE, grouped);
showNotification((int) firstNotification.getId(), grouped);
Stream.of(notificationThreadModels)
.filter(notification -> notification.isUnread() && notification.getId() != firstNotification.getId())
.limit(10)
@ -119,35 +118,48 @@ public class NotificationSchedulerJobTask extends JobService {
RestProvider.getNotificationService().getComment(thread.getSubject().getLatestCommentUrl())
.subscribeOn(Schedulers.io())
.subscribe(comment -> {
android.app.Notification toAdd = getNotification(thread.getSubject().getTitle(),
thread.getRepository().getFullName())
.setStyle(new NotificationCompat.BigTextStyle()
.bigText(comment.getBody())
.setBigContentTitle(comment.getUser() != null ? comment.getUser().getLogin() : ""))
.setLargeIcon(largeIcon)
.setContentIntent(getPendingIntent(thread.getId(), thread.getSubject().getUrl()))
.setGroup(NOTIFICATION_GROUP_ID)
.setColor(accentColor)
.addAction(R.drawable.ic_github, context.getString(R.string.open), getPendingIntent(thread.getId(),
thread.getSubject().getUrl()))
.build();
android.app.Notification toAdd = getNotificationWithComment(context, largeIcon, accentColor, thread, comment);
showNotification((int) thread.getId(), toAdd);
}, Throwable::printStackTrace);
} else {
android.app.Notification toAdd = getNotification(thread.getSubject().getTitle(),
thread.getRepository().getFullName())
.setLargeIcon(largeIcon)
.setContentIntent(getPendingIntent(thread.getId(), thread.getSubject().getUrl()))
.setGroup(NOTIFICATION_GROUP_ID)
.setColor(accentColor)
.addAction(R.drawable.ic_github, context.getString(R.string.open), getPendingIntent(thread.getId(), thread
.getSubject().getUrl()))
.build();
showNotification((int) thread.getId(), toAdd);
showNotificationWithoutCommnet(context, largeIcon, accentColor, thread);
}
});
}
private void showNotificationWithoutCommnet(Context context, Bitmap largeIcon, int accentColor, Notification thread) {
android.app.Notification toAdd = getNotification(thread.getSubject().getTitle(),
thread.getRepository().getFullName())
.setLargeIcon(largeIcon)
.setContentIntent(getPendingIntent(thread.getId(), thread.getSubject().getUrl()))
.setGroup(NOTIFICATION_GROUP_ID)
.setColor(accentColor)
.addAction(R.drawable.ic_github, context.getString(R.string.open), getPendingIntent(thread.getId(), thread
.getSubject().getUrl()))
.addAction(R.drawable.ic_eye_off, context.getString(R.string.mark_as_read), getReadOnlyPendingIntent(thread.getId(), thread
.getSubject().getUrl()))
.build();
showNotification((int) thread.getId(), toAdd);
}
private android.app.Notification getNotificationWithComment(Context context, Bitmap largeIcon, int accentColor,
Notification thread, Comment comment) {
return getNotification(thread.getSubject().getTitle(),
thread.getRepository().getFullName())
.setStyle(new NotificationCompat.BigTextStyle()
.bigText(comment.getBody())
.setBigContentTitle(comment.getUser() != null ? comment.getUser().getLogin() : ""))
.setLargeIcon(largeIcon)
.setContentIntent(getPendingIntent(thread.getId(), thread.getSubject().getUrl()))
.setGroup(NOTIFICATION_GROUP_ID)
.setColor(accentColor)
.addAction(R.drawable.ic_github, context.getString(R.string.open), getPendingIntent(thread.getId(),
thread.getSubject().getUrl()))
.addAction(R.drawable.ic_eye_off, context.getString(R.string.mark_as_read), getReadOnlyPendingIntent(thread.getId(),
thread.getSubject().getUrl()))
.build();
}
private android.app.Notification getSummaryGroupNotification(@NonNull Notification notification, int accentColor, Bitmap largeIcon) {
return getNotification(notification.getSubject().getTitle(), notification.getRepository().getFullName())
.setLargeIcon(largeIcon)
@ -155,6 +167,10 @@ public class NotificationSchedulerJobTask extends JobService {
.setGroupSummary(true)
.setColor(accentColor)
.setContentIntent(getPendingIntent(notification.getId(), notification.getSubject().getUrl()))
.addAction(R.drawable.ic_github, getString(R.string.open),
getPendingIntent(notification.getId(), notification.getSubject().getUrl()))
.addAction(R.drawable.ic_eye_off, getString(R.string.mark_as_read), getReadOnlyPendingIntent(notification.getId(),
notification.getSubject().getUrl()))
.setAutoCancel(true)
.build();
}
@ -171,6 +187,12 @@ public class NotificationSchedulerJobTask extends JobService {
mNotificationManager.notify(id, notification);
}
private PendingIntent getReadOnlyPendingIntent(long id, @NonNull String url) {
Intent intent = ReadNotificationService.start(this, id, url, true);
return PendingIntent.getService(this, (int) id, intent,
PendingIntent.FLAG_UPDATE_CURRENT);
}
private PendingIntent getPendingIntent(long id, @NonNull String url) {
Intent intent = ReadNotificationService.start(this, id, url);
return PendingIntent.getService(this, (int) id, intent,

View File

@ -43,11 +43,16 @@ public class ReadNotificationService extends IntentService {
}
public static Intent start(@NonNull Context context, long id, @NonNull String url) {
return start(context, id, url, false);
}
public static Intent start(@NonNull Context context, long id, @NonNull String url, boolean onlyRead) {
Intent intent = new Intent(context.getApplicationContext(), ReadNotificationService.class);
intent.putExtras(Bundler.start()
.put(BundleConstant.EXTRA_TYPE, OPEN_NOTIFICATIO)
.put(BundleConstant.EXTRA, url)
.put(BundleConstant.ID, id)
.put(BundleConstant.YES_NO_EXTRA, onlyRead)
.end());
return intent;
}
@ -74,18 +79,19 @@ public class ReadNotificationService extends IntentService {
} else if (type == READ_ALL) {
markMultiAsRead(bundle.getLongArray(BundleConstant.ID));
} else if (type == OPEN_NOTIFICATIO) {
openNotification(bundle.getLong(BundleConstant.ID), bundle.getString(BundleConstant.EXTRA));
openNotification(bundle.getLong(BundleConstant.ID), bundle.getString(BundleConstant.EXTRA),
bundle.getBoolean(BundleConstant.YES_NO_EXTRA));
}
}
}
private void openNotification(long id, @Nullable String url) {
private void openNotification(long id, @Nullable String url, boolean readOnly) {
if (id > 0 && url != null) {
AppHelper.cancelNotification(this, (int) id);
if (!PrefGetter.isMarkAsReadEnabled()) {
if (!PrefGetter.isMarkAsReadEnabled() || readOnly) {
markSingleAsRead(id);
}
SchemeParser.launchUri(this, Uri.parse(url), true);
if (!readOnly) SchemeParser.launchUri(this, Uri.parse(url), true);
}
}

View File

@ -337,4 +337,5 @@
<string name="no_members">No members</string>
<string name="no_teams">No teams</string>
<string name="no_orgs">No Organizations</string>
<string name="mark_as_read">Mark as read</string>
</resources>