Notify more aggressively

* Add setting to show notification on the lockscreen
* Don't block notifications in the contact-/-group/-forum/-bloglist

Signed-off-by: goapunk <noobie@goapunks.net>
This commit is contained in:
goapunk
2017-07-02 15:06:51 +02:00
parent 500d5f0efe
commit 4416aaaa4c
9 changed files with 59 additions and 166 deletions

View File

@@ -61,6 +61,7 @@ import static android.content.Context.NOTIFICATION_SERVICE;
import static android.content.Intent.FLAG_ACTIVITY_CLEAR_TOP; import static android.content.Intent.FLAG_ACTIVITY_CLEAR_TOP;
import static android.support.v4.app.NotificationCompat.CATEGORY_MESSAGE; import static android.support.v4.app.NotificationCompat.CATEGORY_MESSAGE;
import static android.support.v4.app.NotificationCompat.CATEGORY_SOCIAL; import static android.support.v4.app.NotificationCompat.CATEGORY_SOCIAL;
import static android.support.v4.app.NotificationCompat.VISIBILITY_PRIVATE;
import static android.support.v4.app.NotificationCompat.VISIBILITY_SECRET; import static android.support.v4.app.NotificationCompat.VISIBILITY_SECRET;
import static java.util.logging.Level.WARNING; import static java.util.logging.Level.WARNING;
import static org.briarproject.briar.android.activity.BriarActivity.GROUP_ID; import static org.briarproject.briar.android.activity.BriarActivity.GROUP_ID;
@@ -327,7 +328,12 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
} }
if (Build.VERSION.SDK_INT >= 21) { if (Build.VERSION.SDK_INT >= 21) {
b.setCategory(CATEGORY_MESSAGE); b.setCategory(CATEGORY_MESSAGE);
b.setVisibility(VISIBILITY_SECRET); boolean showOnLockScreen =
settings.getBoolean(PREF_NOTIFY_LOCK_SCREEN, false);
if (showOnLockScreen)
b.setVisibility(VISIBILITY_PRIVATE);
else
b.setVisibility(VISIBILITY_SECRET);
} }
Object o = appContext.getSystemService(NOTIFICATION_SERVICE); Object o = appContext.getSystemService(NOTIFICATION_SERVICE);
NotificationManager nm = (NotificationManager) o; NotificationManager nm = (NotificationManager) o;
@@ -347,17 +353,6 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
return defaults; return defaults;
} }
@Override
public void clearAllContactNotifications() {
androidExecutor.runOnUiThread(new Runnable() {
@Override
public void run() {
clearContactNotification();
clearIntroductionSuccessNotification();
}
});
}
@UiThread @UiThread
private void showGroupMessageNotification(final GroupId g) { private void showGroupMessageNotification(final GroupId g) {
androidExecutor.runOnUiThread(new Runnable() { androidExecutor.runOnUiThread(new Runnable() {
@@ -432,7 +427,12 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
} }
if (Build.VERSION.SDK_INT >= 21) { if (Build.VERSION.SDK_INT >= 21) {
b.setCategory(CATEGORY_SOCIAL); b.setCategory(CATEGORY_SOCIAL);
b.setVisibility(VISIBILITY_SECRET); boolean showOnLockScreen =
settings.getBoolean(PREF_NOTIFY_LOCK_SCREEN, false);
if (showOnLockScreen)
b.setVisibility(VISIBILITY_PRIVATE);
else
b.setVisibility(VISIBILITY_SECRET);
} }
Object o = appContext.getSystemService(NOTIFICATION_SERVICE); Object o = appContext.getSystemService(NOTIFICATION_SERVICE);
NotificationManager nm = (NotificationManager) o; NotificationManager nm = (NotificationManager) o;
@@ -440,16 +440,6 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
} }
} }
@Override
public void clearAllGroupMessageNotifications() {
androidExecutor.runOnUiThread(new Runnable() {
@Override
public void run() {
clearGroupMessageNotification();
}
});
}
@UiThread @UiThread
private void showForumPostNotification(final GroupId g) { private void showForumPostNotification(final GroupId g) {
androidExecutor.runOnUiThread(new Runnable() { androidExecutor.runOnUiThread(new Runnable() {
@@ -524,7 +514,12 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
} }
if (Build.VERSION.SDK_INT >= 21) { if (Build.VERSION.SDK_INT >= 21) {
b.setCategory(CATEGORY_SOCIAL); b.setCategory(CATEGORY_SOCIAL);
b.setVisibility(VISIBILITY_SECRET); boolean showOnLockScreen =
settings.getBoolean(PREF_NOTIFY_LOCK_SCREEN, false);
if (showOnLockScreen)
b.setVisibility(VISIBILITY_PRIVATE);
else
b.setVisibility(VISIBILITY_SECRET);
} }
Object o = appContext.getSystemService(NOTIFICATION_SERVICE); Object o = appContext.getSystemService(NOTIFICATION_SERVICE);
NotificationManager nm = (NotificationManager) o; NotificationManager nm = (NotificationManager) o;
@@ -532,16 +527,6 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
} }
} }
@Override
public void clearAllForumPostNotifications() {
androidExecutor.runOnUiThread(new Runnable() {
@Override
public void run() {
clearForumPostNotification();
}
});
}
@UiThread @UiThread
private void showBlogPostNotification(final GroupId g) { private void showBlogPostNotification(final GroupId g) {
androidExecutor.runOnUiThread(new Runnable() { androidExecutor.runOnUiThread(new Runnable() {
@@ -602,7 +587,12 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
b.setContentIntent(t.getPendingIntent(nextRequestId++, 0)); b.setContentIntent(t.getPendingIntent(nextRequestId++, 0));
if (Build.VERSION.SDK_INT >= 21) { if (Build.VERSION.SDK_INT >= 21) {
b.setCategory(CATEGORY_SOCIAL); b.setCategory(CATEGORY_SOCIAL);
b.setVisibility(VISIBILITY_SECRET); boolean showOnLockScreen =
settings.getBoolean(PREF_NOTIFY_LOCK_SCREEN, false);
if (showOnLockScreen)
b.setVisibility(VISIBILITY_PRIVATE);
else
b.setVisibility(VISIBILITY_SECRET);
} }
Object o = appContext.getSystemService(NOTIFICATION_SERVICE); Object o = appContext.getSystemService(NOTIFICATION_SERVICE);
NotificationManager nm = (NotificationManager) o; NotificationManager nm = (NotificationManager) o;
@@ -610,16 +600,6 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
} }
} }
@Override
public void clearAllBlogPostNotifications() {
androidExecutor.runOnUiThread(new Runnable() {
@Override
public void run() {
clearBlogPostNotification();
}
});
}
private void showIntroductionNotification() { private void showIntroductionNotification() {
androidExecutor.runOnUiThread(new Runnable() { androidExecutor.runOnUiThread(new Runnable() {
@Override @Override
@@ -658,7 +638,12 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
b.setContentIntent(t.getPendingIntent(nextRequestId++, 0)); b.setContentIntent(t.getPendingIntent(nextRequestId++, 0));
if (Build.VERSION.SDK_INT >= 21) { if (Build.VERSION.SDK_INT >= 21) {
b.setCategory(CATEGORY_MESSAGE); b.setCategory(CATEGORY_MESSAGE);
b.setVisibility(VISIBILITY_SECRET); boolean showOnLockScreen =
settings.getBoolean(PREF_NOTIFY_LOCK_SCREEN, false);
if (showOnLockScreen)
b.setVisibility(VISIBILITY_PRIVATE);
else
b.setVisibility(VISIBILITY_SECRET);
} }
Object o = appContext.getSystemService(NOTIFICATION_SERVICE); Object o = appContext.getSystemService(NOTIFICATION_SERVICE);
NotificationManager nm = (NotificationManager) o; NotificationManager nm = (NotificationManager) o;
@@ -704,87 +689,4 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager,
} }
}); });
} }
@Override
public void blockAllContactNotifications() {
androidExecutor.runOnUiThread(new Runnable() {
@Override
public void run() {
blockContacts = true;
blockIntroductions = true;
}
});
}
@Override
public void unblockAllContactNotifications() {
androidExecutor.runOnUiThread(new Runnable() {
@Override
public void run() {
blockContacts = false;
blockIntroductions = false;
}
});
}
@Override
public void blockAllGroupMessageNotifications() {
androidExecutor.runOnUiThread(new Runnable() {
@Override
public void run() {
blockGroups = true;
}
});
}
@Override
public void unblockAllGroupMessageNotifications() {
androidExecutor.runOnUiThread(new Runnable() {
@Override
public void run() {
blockGroups = false;
}
});
}
@Override
public void blockAllForumPostNotifications() {
androidExecutor.runOnUiThread(new Runnable() {
@Override
public void run() {
blockForums = true;
}
});
}
@Override
public void unblockAllForumPostNotifications() {
androidExecutor.runOnUiThread(new Runnable() {
@Override
public void run() {
blockForums = false;
}
});
}
@Override
public void blockAllBlogPostNotifications() {
androidExecutor.runOnUiThread(new Runnable() {
@Override
public void run() {
blockBlogs = true;
}
});
}
@Override
public void unblockAllBlogPostNotifications() {
androidExecutor.runOnUiThread(new Runnable() {
@Override
public void run() {
blockBlogs = false;
}
});
}
} }

View File

@@ -53,14 +53,11 @@ class FeedControllerImpl extends BaseControllerImpl
public void onStart() { public void onStart() {
super.onStart(); super.onStart();
if (listener == null) throw new IllegalStateException(); if (listener == null) throw new IllegalStateException();
notificationManager.blockAllBlogPostNotifications();
notificationManager.clearAllBlogPostNotifications();
} }
@Override @Override
public void onStop() { public void onStop() {
super.onStop(); super.onStop();
notificationManager.unblockAllBlogPostNotifications();
} }
@Override @Override

View File

@@ -178,8 +178,6 @@ public class ContactListFragment extends BaseFragment implements EventListener {
@Override @Override
public void onStart() { public void onStart() {
super.onStart(); super.onStart();
notificationManager.blockAllContactNotifications();
notificationManager.clearAllContactNotifications();
eventBus.addListener(this); eventBus.addListener(this);
loadContacts(); loadContacts();
list.startPeriodicUpdate(); list.startPeriodicUpdate();
@@ -189,7 +187,6 @@ public class ContactListFragment extends BaseFragment implements EventListener {
public void onStop() { public void onStop() {
super.onStop(); super.onStop();
eventBus.removeListener(this); eventBus.removeListener(this);
notificationManager.unblockAllContactNotifications();
adapter.clear(); adapter.clear();
list.showProgressBar(); list.showProgressBar();
list.stopPeriodicUpdate(); list.stopPeriodicUpdate();

View File

@@ -119,8 +119,6 @@ public class ForumListFragment extends BaseEventFragment implements
@Override @Override
public void onStart() { public void onStart() {
super.onStart(); super.onStart();
notificationManager.blockAllForumPostNotifications();
notificationManager.clearAllForumPostNotifications();
loadForums(); loadForums();
loadAvailableForums(); loadAvailableForums();
list.startPeriodicUpdate(); list.startPeriodicUpdate();
@@ -129,7 +127,6 @@ public class ForumListFragment extends BaseEventFragment implements
@Override @Override
public void onStop() { public void onStop() {
super.onStop(); super.onStop();
notificationManager.unblockAllForumPostNotifications();
adapter.clear(); adapter.clear();
list.showProgressBar(); list.showProgressBar();
list.stopPeriodicUpdate(); list.stopPeriodicUpdate();

View File

@@ -79,15 +79,12 @@ class GroupListControllerImpl extends DbControllerImpl
throw new IllegalStateException( throw new IllegalStateException(
"GroupListListener needs to be attached"); "GroupListListener needs to be attached");
eventBus.addListener(this); eventBus.addListener(this);
notificationManager.blockAllGroupMessageNotifications();
notificationManager.clearAllGroupMessageNotifications();
} }
@Override @Override
@CallSuper @CallSuper
public void onStop() { public void onStop() {
eventBus.removeListener(this); eventBus.removeListener(this);
notificationManager.unblockAllGroupMessageNotifications();
} }
@Override @Override

View File

@@ -6,6 +6,7 @@ import android.content.Intent;
import android.media.Ringtone; import android.media.Ringtone;
import android.media.RingtoneManager; import android.media.RingtoneManager;
import android.net.Uri; import android.net.Uri;
import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.support.v7.preference.CheckBoxPreference; import android.support.v7.preference.CheckBoxPreference;
import android.support.v7.preference.ListPreference; import android.support.v7.preference.ListPreference;
@@ -54,6 +55,7 @@ import static org.briarproject.briar.android.activity.RequestCodes.REQUEST_RINGT
import static org.briarproject.briar.api.android.AndroidNotificationManager.PREF_NOTIFY_BLOG; import static org.briarproject.briar.api.android.AndroidNotificationManager.PREF_NOTIFY_BLOG;
import static org.briarproject.briar.api.android.AndroidNotificationManager.PREF_NOTIFY_FORUM; import static org.briarproject.briar.api.android.AndroidNotificationManager.PREF_NOTIFY_FORUM;
import static org.briarproject.briar.api.android.AndroidNotificationManager.PREF_NOTIFY_GROUP; import static org.briarproject.briar.api.android.AndroidNotificationManager.PREF_NOTIFY_GROUP;
import static org.briarproject.briar.api.android.AndroidNotificationManager.PREF_NOTIFY_LOCK_SCREEN;
import static org.briarproject.briar.api.android.AndroidNotificationManager.PREF_NOTIFY_PRIVATE; import static org.briarproject.briar.api.android.AndroidNotificationManager.PREF_NOTIFY_PRIVATE;
import static org.briarproject.briar.api.android.AndroidNotificationManager.PREF_NOTIFY_RINGTONE_NAME; import static org.briarproject.briar.api.android.AndroidNotificationManager.PREF_NOTIFY_RINGTONE_NAME;
import static org.briarproject.briar.api.android.AndroidNotificationManager.PREF_NOTIFY_RINGTONE_URI; import static org.briarproject.briar.api.android.AndroidNotificationManager.PREF_NOTIFY_RINGTONE_URI;
@@ -81,6 +83,8 @@ public class SettingsFragment extends PreferenceFragmentCompat
private CheckBoxPreference notifyForumPosts; private CheckBoxPreference notifyForumPosts;
private CheckBoxPreference notifyBlogPosts; private CheckBoxPreference notifyBlogPosts;
private CheckBoxPreference notifyVibration; private CheckBoxPreference notifyVibration;
private CheckBoxPreference notifyLockscreen;
private Preference notifySound; private Preference notifySound;
// Fields that are accessed from background threads must be volatile // Fields that are accessed from background threads must be volatile
@@ -114,6 +118,8 @@ public class SettingsFragment extends PreferenceFragmentCompat
"pref_key_notify_blog_posts"); "pref_key_notify_blog_posts");
notifyVibration = (CheckBoxPreference) findPreference( notifyVibration = (CheckBoxPreference) findPreference(
"pref_key_notify_vibration"); "pref_key_notify_vibration");
notifyLockscreen = (CheckBoxPreference) findPreference(
"pref_key_notify_lock_screen");
notifySound = findPreference("pref_key_notify_sound"); notifySound = findPreference("pref_key_notify_sound");
enableBluetooth.setOnPreferenceChangeListener(this); enableBluetooth.setOnPreferenceChangeListener(this);
@@ -123,7 +129,10 @@ public class SettingsFragment extends PreferenceFragmentCompat
notifyForumPosts.setOnPreferenceChangeListener(this); notifyForumPosts.setOnPreferenceChangeListener(this);
notifyBlogPosts.setOnPreferenceChangeListener(this); notifyBlogPosts.setOnPreferenceChangeListener(this);
notifyVibration.setOnPreferenceChangeListener(this); notifyVibration.setOnPreferenceChangeListener(this);
if (Build.VERSION.SDK_INT >= 21) {
notifyLockscreen.setVisible(true);
notifyLockscreen.setOnPreferenceChangeListener(this);
}
notifySound.setOnPreferenceClickListener( notifySound.setOnPreferenceClickListener(
new Preference.OnPreferenceClickListener() { new Preference.OnPreferenceClickListener() {
@Override @Override
@@ -234,6 +243,9 @@ public class SettingsFragment extends PreferenceFragmentCompat
notifyVibration.setChecked(settings.getBoolean( notifyVibration.setChecked(settings.getBoolean(
PREF_NOTIFY_VIBRATION, true)); PREF_NOTIFY_VIBRATION, true));
notifyLockscreen.setChecked(settings.getBoolean(
PREF_NOTIFY_LOCK_SCREEN, false));
String text; String text;
if (settings.getBoolean(PREF_NOTIFY_SOUND, true)) { if (settings.getBoolean(PREF_NOTIFY_SOUND, true)) {
String ringtoneName = String ringtoneName =
@@ -290,6 +302,10 @@ public class SettingsFragment extends PreferenceFragmentCompat
Settings s = new Settings(); Settings s = new Settings();
s.putBoolean(PREF_NOTIFY_VIBRATION, (Boolean) o); s.putBoolean(PREF_NOTIFY_VIBRATION, (Boolean) o);
storeSettings(s); storeSettings(s);
} else if (preference == notifyLockscreen) {
Settings s = new Settings();
s.putBoolean(PREF_NOTIFY_LOCK_SCREEN, (Boolean) o);
storeSettings(s);
} }
return true; return true;
} }

View File

@@ -18,23 +18,16 @@ public interface AndroidNotificationManager {
String PREF_NOTIFY_RINGTONE_NAME = "notifyRingtoneName"; String PREF_NOTIFY_RINGTONE_NAME = "notifyRingtoneName";
String PREF_NOTIFY_RINGTONE_URI = "notifyRingtoneUri"; String PREF_NOTIFY_RINGTONE_URI = "notifyRingtoneUri";
String PREF_NOTIFY_VIBRATION = "notifyVibration"; String PREF_NOTIFY_VIBRATION = "notifyVibration";
String PREF_NOTIFY_LOCK_SCREEN = "notifyLockScreen";
void clearContactNotification(ContactId c); void clearContactNotification(ContactId c);
void clearAllContactNotifications();
void clearGroupMessageNotification(GroupId g); void clearGroupMessageNotification(GroupId g);
void clearAllGroupMessageNotifications();
void clearForumPostNotification(GroupId g); void clearForumPostNotification(GroupId g);
void clearAllForumPostNotifications();
void clearBlogPostNotification(GroupId g); void clearBlogPostNotification(GroupId g);
void clearAllBlogPostNotifications();
void blockContactNotification(ContactId c); void blockContactNotification(ContactId c);
void unblockContactNotification(ContactId c); void unblockContactNotification(ContactId c);
@@ -42,20 +35,4 @@ public interface AndroidNotificationManager {
void blockNotification(GroupId g); void blockNotification(GroupId g);
void unblockNotification(GroupId g); void unblockNotification(GroupId g);
void blockAllContactNotifications();
void unblockAllContactNotifications();
void blockAllGroupMessageNotifications();
void unblockAllGroupMessageNotifications();
void blockAllForumPostNotifications();
void unblockAllForumPostNotifications();
void blockAllBlogPostNotifications();
void unblockAllBlogPostNotifications();
} }

View File

@@ -348,6 +348,8 @@
<string name="notify_blog_posts_setting_title">Blog posts</string> <string name="notify_blog_posts_setting_title">Blog posts</string>
<string name="notify_blog_posts_setting_summary">Show alerts for blog posts</string> <string name="notify_blog_posts_setting_summary">Show alerts for blog posts</string>
<string name="notify_vibration_setting">Vibrate</string> <string name="notify_vibration_setting">Vibrate</string>
<string name="notify_lock_screen_setting_title">Lock Screen</string>
<string name="notify_lock_screen_setting_summary">Show notifications on the lock screen</string>
<string name="notify_sound_setting">Sound</string> <string name="notify_sound_setting">Sound</string>
<string name="notify_sound_setting_default">Default ringtone</string> <string name="notify_sound_setting_default">Default ringtone</string>
<string name="notify_sound_setting_disabled">None</string> <string name="notify_sound_setting_disabled">None</string>

View File

@@ -85,6 +85,14 @@
android:title="@string/notify_blog_posts_setting_title" android:title="@string/notify_blog_posts_setting_title"
android:summary="@string/notify_blog_posts_setting_summary"/> android:summary="@string/notify_blog_posts_setting_summary"/>
<CheckBoxPreference
android:defaultValue="false"
android:key="pref_key_notify_lock_screen"
android:persistent="false"
android:title="@string/notify_lock_screen_setting_title"
android:summary="@string/notify_lock_screen_setting_summary"
android:visibility="gone"/>
<CheckBoxPreference <CheckBoxPreference
android:defaultValue="true" android:defaultValue="true"
android:key="pref_key_notify_vibration" android:key="pref_key_notify_vibration"