mirror of
https://github.com/deltachat/deltachat-android.git
synced 2025-10-03 09:49:21 +02:00
show warning if background notifications will be unreliable
This commit is contained in:
parent
fcc1ab1079
commit
2deb61477f
3 changed files with 18 additions and 3 deletions
|
@ -28,6 +28,7 @@ import org.thoughtcrime.securesms.ApplicationPreferencesActivity;
|
|||
import org.thoughtcrime.securesms.R;
|
||||
import org.thoughtcrime.securesms.connect.DcHelper;
|
||||
import org.thoughtcrime.securesms.connect.KeepAliveService;
|
||||
import org.thoughtcrime.securesms.notifications.FcmReceiveService;
|
||||
import org.thoughtcrime.securesms.util.Prefs;
|
||||
|
||||
public class NotificationsPreferenceFragment extends ListSummaryPreferenceFragment implements Preference.OnPreferenceChangeListener {
|
||||
|
@ -99,6 +100,7 @@ public class NotificationsPreferenceFragment extends ListSummaryPreferenceFragme
|
|||
notificationsEnabled.setOnPreferenceChangeListener((preference, newValue) -> {
|
||||
boolean enabled = (Boolean) newValue;
|
||||
dcContext.setMuted(!enabled);
|
||||
notificationsEnabled.setSummary(getSummary(getContext(), ""));
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
@ -126,6 +128,7 @@ public class NotificationsPreferenceFragment extends ListSummaryPreferenceFragme
|
|||
// update ignoreBattery in onResume() to reflects changes done in the system settings
|
||||
ignoreBattery.setChecked(isIgnoringBatteryOptimizations());
|
||||
notificationsEnabled.setChecked(!dcContext.isMuted());
|
||||
notificationsEnabled.setSummary(getSummary(getContext(), ""));
|
||||
mentionNotifEnabled.setChecked(dcContext.isMentionsEnabled());
|
||||
|
||||
// set without altering "unset" state of the preference
|
||||
|
@ -160,6 +163,7 @@ public class NotificationsPreferenceFragment extends ListSummaryPreferenceFragme
|
|||
} else {
|
||||
context.stopService(new Intent(context, KeepAliveService.class));
|
||||
}
|
||||
notificationsEnabled.setSummary(getSummary(context, ""));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -239,11 +243,21 @@ public class NotificationsPreferenceFragment extends ListSummaryPreferenceFragme
|
|||
}
|
||||
|
||||
public static CharSequence getSummary(Context context) {
|
||||
return getSummary(context, context.getString(R.string.on));
|
||||
}
|
||||
|
||||
public static CharSequence getSummary(Context context, String defaultOnValue) {
|
||||
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU || notificationManager.areNotificationsEnabled()) {
|
||||
return context.getString(DcHelper.getContext(context).isMuted() ? R.string.off : R.string.on);
|
||||
if (DcHelper.getContext(context).isMuted()) {
|
||||
return "⚠️ " + context.getString(R.string.notifications_disabled);
|
||||
}
|
||||
if (FcmReceiveService.getToken() == null && !Prefs.reliableService(context)) {
|
||||
return "⚠️ " + context.getString(R.string.unreliable_bg_notifications);
|
||||
}
|
||||
return defaultOnValue;
|
||||
} else {
|
||||
return context.getString(R.string.disabled_in_system_settings);
|
||||
return "⚠️ " + context.getString(R.string.disabled_in_system_settings);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -228,7 +228,7 @@ public class Prefs {
|
|||
}
|
||||
|
||||
// if the key was unset, then calculate default value
|
||||
return isPushEnabled(context) || !DcHelper.getAccounts(context).isAllChatmail();
|
||||
return !isPushEnabled(context) || !DcHelper.getAccounts(context).isAllChatmail();
|
||||
}
|
||||
|
||||
// vibrate
|
||||
|
|
|
@ -1035,6 +1035,7 @@
|
|||
<string name="notify_name_only">Name only</string>
|
||||
<string name="notify_no_name_or_message">No name or message</string>
|
||||
<string name="notifications_disabled">Notifications disabled</string>
|
||||
<string name="unreliable_bg_notifications">Push-notifications unavailable, please enable Force Background Connection for reliable notifications</string>
|
||||
<string name="new_messages">New messages</string>
|
||||
<!-- Body text for a generic "New messages" notification. Shown if we do not have more information about a new messages. Note, that the string is also referenced at https://github.com/deltachat/notifiers -->
|
||||
<string name="new_messages_body">You have new messages</string>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue