watcher: remove old settings for watch settings controller.

implement notifications for <Oreo.
feature/sentry
Floens 6 years ago
parent 327489f844
commit 8e08f0fa56
  1. 2
      Clover/app/src/main/java/org/floens/chan/core/manager/WatchManager.java
  2. 59
      Clover/app/src/main/java/org/floens/chan/ui/controller/WatchSettingsController.java
  3. 117
      Clover/app/src/main/java/org/floens/chan/ui/notification/ThreadWatchNotifications.java
  4. 2
      Clover/app/src/main/res/values/strings.xml

@ -565,7 +565,7 @@ public class WatchManager {
threadWatchNotifications.showForWatchers(pinWatchers);
} else {
threadWatchNotifications.hide();
threadWatchNotifications.hideAll();
}
}

@ -18,17 +18,25 @@
package org.floens.chan.ui.controller;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.provider.Settings;
import android.support.v7.widget.SwitchCompat;
import android.widget.CompoundButton;
import org.floens.chan.R;
import org.floens.chan.core.settings.ChanSettings;
import org.floens.chan.ui.notification.ThreadWatchNotifications;
import org.floens.chan.ui.settings.BooleanSettingView;
import org.floens.chan.ui.settings.LinkSettingView;
import org.floens.chan.ui.settings.ListSettingView;
import org.floens.chan.ui.settings.SettingView;
import org.floens.chan.ui.settings.SettingsController;
import org.floens.chan.ui.settings.SettingsGroup;
import org.floens.chan.ui.view.CrossfadeView;
import org.floens.chan.utils.AndroidUtils;
import static org.floens.chan.Chan.injector;
public class WatchSettingsController extends SettingsController implements CompoundButton.OnCheckedChangeListener {
private CrossfadeView crossfadeView;
@ -36,10 +44,8 @@ public class WatchSettingsController extends SettingsController implements Compo
private SettingView enableBackground;
private SettingView backgroundTimeout;
private SettingView notifyMode;
private SettingView soundMode;
private SettingView peekMode;
private SettingView ledMode;
private SettingView normalChannel;
private SettingView mentionChannel;
public WatchSettingsController(Context context) {
super(context);
@ -70,10 +76,10 @@ public class WatchSettingsController extends SettingsController implements Compo
if (!ChanSettings.watchBackground.get()) {
setSettingViewVisibility(backgroundTimeout, false, false);
setSettingViewVisibility(notifyMode, false, false);
setSettingViewVisibility(soundMode, false, false);
setSettingViewVisibility(peekMode, false, false);
setSettingViewVisibility(ledMode, false, false);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
setSettingViewVisibility(normalChannel, false, false);
setSettingViewVisibility(mentionChannel, false, false);
}
}
}
@ -90,10 +96,10 @@ public class WatchSettingsController extends SettingsController implements Compo
if (item == enableBackground) {
boolean enabled = ChanSettings.watchBackground.get();
setSettingViewVisibility(backgroundTimeout, enabled, true);
setSettingViewVisibility(notifyMode, enabled, true);
setSettingViewVisibility(soundMode, enabled, true);
setSettingViewVisibility(peekMode, enabled, true);
setSettingViewVisibility(ledMode, enabled, true);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
setSettingViewVisibility(normalChannel, enabled, true);
setSettingViewVisibility(mentionChannel, enabled, true);
}
}
}
@ -104,6 +110,7 @@ public class WatchSettingsController extends SettingsController implements Compo
enableBackground = settings.add(new BooleanSettingView(this, ChanSettings.watchBackground, R.string.setting_watch_enable_background, R.string.setting_watch_enable_background_description));
int[] timeouts = new int[]{
60 * 1000,
10 * 60 * 1000,
15 * 60 * 1000,
30 * 60 * 1000,
@ -124,17 +131,23 @@ public class WatchSettingsController extends SettingsController implements Compo
}
});
notifyMode = settings.add(new ListSettingView<>(this, ChanSettings.watchNotifyMode, R.string.setting_watch_notify_mode,
context.getResources().getStringArray(R.array.setting_watch_notify_modes), new String[]{"all", "quotes"}));
soundMode = settings.add(new ListSettingView<>(this, ChanSettings.watchSound, R.string.setting_watch_sound,
context.getResources().getStringArray(R.array.setting_watch_sounds), new String[]{"all", "quotes"}));
peekMode = settings.add(new BooleanSettingView(this, ChanSettings.watchPeek, R.string.setting_watch_peek, R.string.setting_watch_peek_description));
ledMode = settings.add(new ListSettingView<>(this, ChanSettings.watchLed, R.string.setting_watch_led,
context.getResources().getStringArray(R.array.setting_watch_leds),
new String[]{"-1", "ffffffff", "ffff0000", "ffffff00", "ff00ff00", "ff00ffff", "ff0000ff", "ffff00ff"}));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
injector().instance(ThreadWatchNotifications.class).ensureChannels();
normalChannel = settings.add(new LinkSettingView(this, R.string.setting_watch_channel_normal, 0, v -> {
Intent intent = new Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS);
intent.putExtra(Settings.EXTRA_APP_PACKAGE, context.getPackageName());
intent.putExtra(Settings.EXTRA_CHANNEL_ID, ThreadWatchNotifications.CHANNEL_ID_WATCH_NORMAL);
AndroidUtils.openIntent(intent);
}));
mentionChannel = settings.add(new LinkSettingView(this, R.string.setting_watch_channel_mention, 0, v -> {
Intent intent = new Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS);
intent.putExtra(Settings.EXTRA_APP_PACKAGE, context.getPackageName());
intent.putExtra(Settings.EXTRA_CHANNEL_ID, ThreadWatchNotifications.CHANNEL_ID_WATCH_MENTION);
AndroidUtils.openIntent(intent);
}));
}
groups.add(settings);
}

@ -22,8 +22,8 @@ import javax.inject.Singleton;
@Singleton
public class ThreadWatchNotifications extends NotificationHelper {
private static final String CHANNEL_ID_WATCH_NORMAL = "watch:normal";
private static final String CHANNEL_ID_WATCH_MENTION = "watch:mention";
public static final String CHANNEL_ID_WATCH_NORMAL = "watch:normal";
public static final String CHANNEL_ID_WATCH_MENTION = "watch:mention";
private static final int NOTIFICATION_ID_WATCH_NORMAL = 0x10000;
private static final int NOTIFICATION_ID_WATCH_NORMAL_MASK = 0xffff;
private static final int NOTIFICATION_ID_WATCH_MENTION = 0x20000;
@ -39,20 +39,18 @@ public class ThreadWatchNotifications extends NotificationHelper {
}
public void showForWatchers(List<WatchManager.PinWatcher> pinWatchers) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
showPinSummaries(pinWatchers);
} else {
// legacy notification
}
showPinSummaries(pinWatchers);
}
public void hide() {
public void hideAll() {
notificationManager.cancelAll();
}
@TargetApi(Build.VERSION_CODES.O)
private void showPinSummaries(List<WatchManager.PinWatcher> pinWatchers) {
ensureChannels();
if (isOreo()) {
ensureChannels();
}
for (WatchManager.PinWatcher pinWatcher : pinWatchers) {
if (!pinWatcher.requiresNotificationUpdate()) {
@ -60,62 +58,70 @@ public class ThreadWatchNotifications extends NotificationHelper {
}
// Normal thread posts.
int normalId = NOTIFICATION_ID_WATCH_NORMAL +
(pinWatcher.getPinId() & NOTIFICATION_ID_WATCH_NORMAL_MASK);
if (!pinWatcher.getUnviewedPosts().isEmpty()) {
NotificationCompat.Builder builder =
new NotificationCompat.Builder(applicationContext,
CHANNEL_ID_WATCH_NORMAL);
NotificationCompat.MessagingStyle messagingStyle =
new NotificationCompat.MessagingStyle("");
builder.setSmallIcon(R.drawable.ic_stat_notify);
if (pinWatcher.getThumbnailBitmap() != null) {
builder.setLargeIcon(pinWatcher.getThumbnailBitmap());
}
String subTitle = "(" + pinWatcher.getUnviewedPosts().size() + ")";
messagingStyle.setConversationTitle(pinWatcher.getTitle() + " " + subTitle);
messagingStyle.setGroupConversation(true);
addPostsToMessagingStyle(messagingStyle, pinWatcher.getUnviewedPosts());
builder.setStyle(messagingStyle);
setNotificationIntent(builder);
int id = NOTIFICATION_ID_WATCH_NORMAL +
(pinWatcher.getPinId() & NOTIFICATION_ID_WATCH_NORMAL_MASK);
notificationManager.notify(id, builder.build());
buildMessagingStyleNotification(pinWatcher, pinWatcher.getUnviewedPosts(),
false, CHANNEL_ID_WATCH_NORMAL);
notificationManager.notify(normalId, builder.build());
} else {
notificationManager.cancel(normalId);
}
// Posts that mention you.
int mentionId = NOTIFICATION_ID_WATCH_MENTION +
(pinWatcher.getPinId() & NOTIFICATION_ID_WATCH_MENTION_MASK);
if (!pinWatcher.getUnviewedQuotes().isEmpty()) {
NotificationCompat.Builder builder =
new NotificationCompat.Builder(applicationContext,
CHANNEL_ID_WATCH_MENTION);
buildMessagingStyleNotification(pinWatcher, pinWatcher.getUnviewedQuotes(),
true, CHANNEL_ID_WATCH_MENTION);
NotificationCompat.MessagingStyle messagingStyle =
new NotificationCompat.MessagingStyle("");
notificationManager.notify(mentionId, builder.build());
} else {
notificationManager.cancel(mentionId);
}
builder.setSmallIcon(R.drawable.ic_stat_notify_alert);
builder.setSubText("Mentions");
if (pinWatcher.getThumbnailBitmap() != null) {
builder.setLargeIcon(pinWatcher.getThumbnailBitmap());
}
pinWatcher.hadNotificationUpdate();
}
}
String subTitle = "(" + pinWatcher.getUnviewedQuotes().size() + " mentions)";
messagingStyle.setConversationTitle(pinWatcher.getTitle() + " " + subTitle);
messagingStyle.setGroupConversation(true);
addPostsToMessagingStyle(messagingStyle, pinWatcher.getUnviewedQuotes());
builder.setStyle(messagingStyle);
private NotificationCompat.Builder buildMessagingStyleNotification(
WatchManager.PinWatcher pinWatcher, List<Post> posts, boolean mentions,
String channelId) {
NotificationCompat.Builder builder =
new NotificationCompat.Builder(applicationContext, channelId);
setNotificationIntent(builder);
NotificationCompat.MessagingStyle messagingStyle =
new NotificationCompat.MessagingStyle("");
int id = NOTIFICATION_ID_WATCH_MENTION +
(pinWatcher.getPinId() & NOTIFICATION_ID_WATCH_MENTION_MASK);
notificationManager.notify(id, builder.build());
}
builder.setSmallIcon(!mentions ?
R.drawable.ic_stat_notify : R.drawable.ic_stat_notify_alert);
if (mentions) {
builder.setSubText("Mentions");
}
if (pinWatcher.getThumbnailBitmap() != null) {
builder.setLargeIcon(pinWatcher.getThumbnailBitmap());
}
if (mentions && !isOreo()) {
builder.setDefaults(NotificationCompat.DEFAULT_SOUND |
NotificationCompat.DEFAULT_VIBRATE);
}
pinWatcher.hadNotificationUpdate();
String subTitle;
if (!mentions) {
subTitle = "(" + posts.size() + ")";
} else {
subTitle = "(" + posts.size() + " mentions)";
}
messagingStyle.setConversationTitle(pinWatcher.getTitle() + " " + subTitle);
messagingStyle.setGroupConversation(true);
addPostsToMessagingStyle(messagingStyle, posts);
builder.setStyle(messagingStyle);
setNotificationIntent(builder);
return builder;
}
private void addPostsToMessagingStyle(NotificationCompat.MessagingStyle messagingStyle,
@ -145,7 +151,6 @@ public class ThreadWatchNotifications extends NotificationHelper {
}
}
@TargetApi(Build.VERSION_CODES.O)
private void setNotificationIntent(NotificationCompat.Builder builder) {
Intent intent = new Intent(applicationContext, BoardActivity.class);
intent.setAction(Intent.ACTION_MAIN);
@ -162,7 +167,7 @@ public class ThreadWatchNotifications extends NotificationHelper {
}
@TargetApi(Build.VERSION_CODES.O)
private void ensureChannels() {
public void ensureChannels() {
NotificationChannel normalChannel = new NotificationChannel(
CHANNEL_ID_WATCH_NORMAL, "Thread updates",
NotificationManager.IMPORTANCE_DEFAULT);
@ -177,4 +182,8 @@ public class ThreadWatchNotifications extends NotificationHelper {
mentionChannel.enableLights(true);
notificationManager.createNotificationChannel(mentionChannel);
}
private boolean isOreo() {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.O;
}
}

@ -408,6 +408,8 @@ Enable \"Play videos with external player\" in the settings to play videos with
<item>Blue</item>
<item>Purple</item>
</string-array>
<string name="setting_watch_channel_normal">Notification settings for thread updates</string>
<string name="setting_watch_channel_mention">Notification settings for thread mentions</string>
<!-- Main About group -->
<string name="settings_group_about">About</string>

Loading…
Cancel
Save