Added option to disable notifying in the foreground

pull/184/head
M66B 4 years ago
parent 2367d260c0
commit 9366320529

@ -625,6 +625,8 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
iff.addAction(ACTION_EDIT_RULE);
lbm.registerReceiver(receiver, iff);
ServiceSynchronize.state(this, true);
checkUpdate(false);
checkIntent();
}
@ -632,8 +634,11 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
@Override
protected void onPause() {
super.onPause();
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(this);
lbm.unregisterReceiver(receiver);
ServiceSynchronize.state(this, false);
}

@ -3163,7 +3163,7 @@ class Core {
}
}
static void notifyMessages(Context context, List<TupleMessageEx> messages, Map<Long, List<Long>> groupNotifying) {
static void notifyMessages(Context context, List<TupleMessageEx> messages, Map<Long, List<Long>> groupNotifying, boolean foreground) {
if (messages == null)
messages = new ArrayList<>();
@ -3171,7 +3171,10 @@ class Core {
if (nm == null)
return;
DB db = DB.getInstance(context);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean notify_background_only = prefs.getBoolean("notify_background_only", false);
boolean notify_summary = prefs.getBoolean("notify_summary", false);
boolean notify_preview = prefs.getBoolean("notify_preview", true);
boolean notify_preview_only = prefs.getBoolean("notify_preview_only", false);
@ -3208,6 +3211,13 @@ class Core {
if (notify_preview && notify_preview_only && !message.content)
continue;
if (foreground && notify_background_only && message.notifying >= 0) {
Log.i("Notify foreground=" + message.id + " notifying=" + message.notifying);
if (message.notifying == 0)
db.message().setMessageNotifying(message.id, 1);
continue;
}
long group = (pro && message.accountNotify ? message.account : 0);
if (!message.folderUnified)
group = -message.folder;
@ -3275,8 +3285,6 @@ class Core {
Log.i("Notify group=" + group + " count=" + notifications.size() +
" added=" + add.size() + " removed=" + remove.size());
DB db = DB.getInstance(context);
if (notifications.size() == 0) {
String tag = "unseen." + group + "." + 0;
Log.i("Notify cancel tag=" + tag);

@ -70,6 +70,7 @@ public class FragmentOptionsNotifications extends FragmentBase implements Shared
private SwitchCompat swBadge;
private SwitchCompat swUnseenIgnored;
private SwitchCompat swNotifyBackgroundOnly;
private SwitchCompat swNotifyKnown;
private TextView tvNotifyKnownPro;
private SwitchCompat swNotifySummary;
@ -93,7 +94,7 @@ public class FragmentOptionsNotifications extends FragmentBase implements Shared
"notify_flag", "notify_seen", "notify_snooze",
"light", "sound",
"badge", "unseen_ignored",
"notify_known", "notify_summary", "notify_remove", "notify_clear",
"notify_background_only", "notify_known", "notify_summary", "notify_remove", "notify_clear",
"notify_preview", "notify_preview_all", "notify_preview_only", "wearable_preview",
"biometrics_notify",
"alert_once"
@ -130,6 +131,7 @@ public class FragmentOptionsNotifications extends FragmentBase implements Shared
swBadge = view.findViewById(R.id.swBadge);
swUnseenIgnored = view.findViewById(R.id.swUnseenIgnored);
swNotifyBackgroundOnly = view.findViewById(R.id.swNotifyBackgroundOnly);
swNotifyKnown = view.findViewById(R.id.swNotifyKnown);
tvNotifyKnownPro = view.findViewById(R.id.tvNotifyKnownPro);
swNotifySummary = view.findViewById(R.id.swNotifySummary);
@ -308,6 +310,14 @@ public class FragmentOptionsNotifications extends FragmentBase implements Shared
}
});
swNotifyBackgroundOnly.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("notify_background_only", checked).apply();
enableOptions();
}
});
swNotifyKnown.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
@ -457,6 +467,7 @@ public class FragmentOptionsNotifications extends FragmentBase implements Shared
swBadge.setChecked(prefs.getBoolean("badge", true));
swUnseenIgnored.setChecked(prefs.getBoolean("unseen_ignored", false));
swNotifyBackgroundOnly.setChecked(prefs.getBoolean("notify_background_only", false));
swNotifyKnown.setChecked(prefs.getBoolean("notify_known", false));
swNotifySummary.setChecked(prefs.getBoolean("notify_summary", false));
swNotifyRemove.setChecked(prefs.getBoolean("notify_remove", true));

@ -102,6 +102,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
private int lastAccounts = 0;
private int lastOperations = 0;
private boolean foreground = false;
private Map<Long, Core.State> coreStates = new Hashtable<>();
private MutableLiveData<ConnectionHelper.NetworkState> liveNetworkState = new MutableLiveData<>();
private MutableLiveData<List<TupleAccountState>> liveAccountState = new MutableLiveData<>();
@ -509,7 +510,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
@Override
public void run() {
try {
Core.notifyMessages(ServiceSynchronize.this, messages, groupNotifying);
Core.notifyMessages(ServiceSynchronize.this, messages, groupNotifying, foreground);
} catch (SecurityException ex) {
Log.w(ex);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ServiceSynchronize.this);
@ -717,6 +718,10 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
onWakeup(intent);
break;
case "state":
onState(intent);
break;
case "alarm":
onAlarm(intent);
break;
@ -772,6 +777,10 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
}
}
private void onState(Intent intent) {
foreground = intent.getBooleanExtra("foreground", false);
}
private void onAlarm(Intent intent) {
Bundle command = new Bundle();
schedule(this);
@ -2145,6 +2154,13 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
.setAction("alarm"));
}
static void state(Context context, boolean foreground) {
start(context,
new Intent(context, ServiceSynchronize.class)
.setAction("state")
.putExtra("foreground", foreground));
}
static void watchdog(Context context) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean enabled = prefs.getBoolean("enabled", true);

@ -328,6 +328,17 @@
app:layout_constraintTop_toBottomOf="@id/tvBadgeHint"
app:switchPadding="12dp" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swNotifyBackgroundOnly"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_advanced_notify_background"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swUnseenIgnored"
app:switchPadding="12dp" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swNotifyKnown"
android:layout_width="0dp"
@ -336,7 +347,7 @@
android:text="@string/title_advanced_notify_known"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swUnseenIgnored"
app:layout_constraintTop_toBottomOf="@id/swNotifyBackgroundOnly"
app:switchPadding="12dp" />
<eu.faircode.email.FixedTextView

@ -413,6 +413,7 @@
<string name="title_advanced_badge">Show launcher icon with number of new messages</string>
<string name="title_advanced_unseen_ignored">Let the number of new messages match the number of notifications</string>
<string name="title_advanced_notify_background">Show notifications when on the background only</string>
<string name="title_advanced_notify_known">Show notifications for contacts only</string>
<string name="title_advanced_notify_summary">Show summary notification only</string>
<string name="title_advanced_notify_preview">Show message preview in notifications</string>

Loading…
Cancel
Save