mirror of
https://github.com/deltachat/deltachat-android.git
synced 2025-10-03 01:39:18 +02:00
default to permanent notification if push is not possible
This commit is contained in:
parent
152360d94a
commit
39c48d3dcd
2 changed files with 34 additions and 4 deletions
|
@ -38,6 +38,7 @@ public class NotificationsPreferenceFragment extends ListSummaryPreferenceFragme
|
||||||
private CheckBoxPreference ignoreBattery;
|
private CheckBoxPreference ignoreBattery;
|
||||||
private CheckBoxPreference notificationsEnabled;
|
private CheckBoxPreference notificationsEnabled;
|
||||||
private CheckBoxPreference mentionNotifEnabled;
|
private CheckBoxPreference mentionNotifEnabled;
|
||||||
|
private CheckBoxPreference reliableService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle paramBundle) {
|
public void onCreate(Bundle paramBundle) {
|
||||||
|
@ -85,7 +86,7 @@ public class NotificationsPreferenceFragment extends ListSummaryPreferenceFragme
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
CheckBoxPreference reliableService = this.findPreference("pref_reliable_service");
|
reliableService = this.findPreference("pref_reliable_service");
|
||||||
if (reliableService != null) {
|
if (reliableService != null) {
|
||||||
reliableService.setOnPreferenceChangeListener((preference, newValue) -> {
|
reliableService.setOnPreferenceChangeListener((preference, newValue) -> {
|
||||||
Context context = getContext();
|
Context context = getContext();
|
||||||
|
@ -132,6 +133,10 @@ public class NotificationsPreferenceFragment extends ListSummaryPreferenceFragme
|
||||||
ignoreBattery.setChecked(isIgnoringBatteryOptimizations());
|
ignoreBattery.setChecked(isIgnoringBatteryOptimizations());
|
||||||
notificationsEnabled.setChecked(!dcContext.isMuted());
|
notificationsEnabled.setChecked(!dcContext.isMuted());
|
||||||
mentionNotifEnabled.setChecked(dcContext.isMentionsEnabled());
|
mentionNotifEnabled.setChecked(dcContext.isMentionsEnabled());
|
||||||
|
if (Prefs.reliableService(getActivity())) {
|
||||||
|
// only alter the "unset" state of the preference if true
|
||||||
|
reliableService.setChecked(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -12,10 +12,12 @@ import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.core.app.NotificationCompat;
|
import androidx.core.app.NotificationCompat;
|
||||||
|
|
||||||
|
import com.b44t.messenger.DcAccounts;
|
||||||
import com.b44t.messenger.DcContext;
|
import com.b44t.messenger.DcContext;
|
||||||
|
|
||||||
import org.thoughtcrime.securesms.BuildConfig;
|
import org.thoughtcrime.securesms.BuildConfig;
|
||||||
import org.thoughtcrime.securesms.connect.DcHelper;
|
import org.thoughtcrime.securesms.connect.DcHelper;
|
||||||
|
import org.thoughtcrime.securesms.notifications.FcmReceiveService;
|
||||||
import org.thoughtcrime.securesms.preferences.widgets.NotificationPrivacyPreference;
|
import org.thoughtcrime.securesms.preferences.widgets.NotificationPrivacyPreference;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -212,13 +214,36 @@ public class Prefs {
|
||||||
return result==null? null : Uri.parse(result);
|
return result==null? null : Uri.parse(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static boolean isAllChatmail(Context context) {
|
||||||
|
DcAccounts dcAccounts = DcHelper.getAccounts(context);
|
||||||
|
for (int accountId : dcAccounts.getAll()) {
|
||||||
|
DcContext dcContext = dcAccounts.getAccount(accountId);
|
||||||
|
if (!dcContext.isChatmail()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
public static boolean reliableService(Context context) {
|
public static boolean reliableService(Context context) {
|
||||||
|
final String key = "pref_reliable_service";
|
||||||
|
boolean value = false;
|
||||||
try {
|
try {
|
||||||
return getBooleanPreference(context, "pref_reliable_service", false);
|
value = getBooleanPreference(context, key, false);
|
||||||
|
} catch(Exception e) {}
|
||||||
|
boolean value2;
|
||||||
|
try {
|
||||||
|
value2 = getBooleanPreference(context, key, !value);
|
||||||
|
} catch(Exception e) {
|
||||||
|
value2 = !value;
|
||||||
}
|
}
|
||||||
catch(Exception e) {
|
|
||||||
return false;
|
// if the key was unset, then calculate default value
|
||||||
|
if (value != value2) {
|
||||||
|
value = FcmReceiveService.getToken() == null || !isAllChatmail(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
// vibrate
|
// vibrate
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue