diff --git a/app/src/main/java/eu/faircode/email/FragmentDialogDataSaver.java b/app/src/main/java/eu/faircode/email/FragmentDialogDataSaver.java new file mode 100644 index 0000000000..f2c268cb47 --- /dev/null +++ b/app/src/main/java/eu/faircode/email/FragmentDialogDataSaver.java @@ -0,0 +1,64 @@ +package eu.faircode.email; + +/* + This file is part of FairEmail. + + FairEmail is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + FairEmail is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with FairEmail. If not, see . + + Copyright 2018-2024 by Marcel Bokhorst (M66B) +*/ + +import android.app.Dialog; +import android.content.Context; +import android.content.DialogInterface; +import android.content.Intent; +import android.content.SharedPreferences; +import android.net.Uri; +import android.os.Bundle; +import android.provider.Settings; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.appcompat.app.AlertDialog; +import androidx.preference.PreferenceManager; + +public class FragmentDialogDataSaver extends FragmentDialogBase { + @NonNull + @Override + public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) { + final Context context = getContext(); + + return new AlertDialog.Builder(context) + .setIcon(R.drawable.twotone_data_saver_off_24) + .setTitle(R.string.title_setup_data) + .setMessage(R.string.title_hint_data_saver) + .setPositiveButton(R.string.title_fix, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + Intent settings = new Intent( + Settings.ACTION_IGNORE_BACKGROUND_DATA_RESTRICTIONS_SETTINGS, + Uri.parse("package:" + BuildConfig.APPLICATION_ID)); + context.startActivity(settings); + } + }) + .setNegativeButton(R.string.title_dismiss, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); + prefs.edit().putBoolean("datasaver_reminder", false).apply(); + } + }) + .create(); + } +} diff --git a/app/src/main/java/eu/faircode/email/FragmentMessages.java b/app/src/main/java/eu/faircode/email/FragmentMessages.java index 191fb8a6b9..1ca9a372aa 100644 --- a/app/src/main/java/eu/faircode/email/FragmentMessages.java +++ b/app/src/main/java/eu/faircode/email/FragmentMessages.java @@ -249,6 +249,7 @@ public class FragmentMessages extends FragmentBase private TextView tvAirplane; private TextView tvNotifications; private TextView tvBatteryOptimizations; + private TextView tvDataSaver; private TextView tvSupport; private ImageButton ibHintSupport; private ImageButton ibHintSwipe; @@ -273,6 +274,7 @@ public class FragmentMessages extends FragmentBase private Group grpAirplane; private Group grpNotifications; private Group grpBatteryOptimizations; + private Group grpDataSaver; private Group grpSupport; private Group grpHintSupport; private Group grpHintSwipe; @@ -568,6 +570,7 @@ public class FragmentMessages extends FragmentBase tvAirplane = view.findViewById(R.id.tvAirplane); tvNotifications = view.findViewById(R.id.tvNotifications); tvBatteryOptimizations = view.findViewById(R.id.tvBatteryOptimizations); + tvDataSaver = view.findViewById(R.id.tvDataSaver); tvSupport = view.findViewById(R.id.tvSupport); ibHintSupport = view.findViewById(R.id.ibHintSupport); ibHintSwipe = view.findViewById(R.id.ibHintSwipe); @@ -593,6 +596,7 @@ public class FragmentMessages extends FragmentBase grpAirplane = view.findViewById(R.id.grpAirplane); grpNotifications = view.findViewById(R.id.grpNotifications); grpBatteryOptimizations = view.findViewById(R.id.grpBatteryOptimizations); + grpDataSaver = view.findViewById(R.id.grpDataSaver); grpSupport = view.findViewById(R.id.grpSupport); grpHintSupport = view.findViewById(R.id.grpHintSupport); grpHintSwipe = view.findViewById(R.id.grpHintSwipe); @@ -666,6 +670,13 @@ public class FragmentMessages extends FragmentBase } }); + tvDataSaver.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + new FragmentDialogDataSaver().show(getParentFragmentManager(), "datasaver"); + } + }); + grpSupport.setVisibility(View.GONE); tvSupport.setOnClickListener(new View.OnClickListener() { @Override @@ -1944,6 +1955,7 @@ public class FragmentMessages extends FragmentBase grpAirplane.setVisibility(View.GONE); grpNotifications.setVisibility(View.GONE); grpBatteryOptimizations.setVisibility(View.GONE); + grpDataSaver.setVisibility(View.GONE); tvNoEmail.setVisibility(View.GONE); tvNoEmailHint.setVisibility(View.GONE); etSearch.setVisibility(View.GONE); @@ -5335,6 +5347,7 @@ public class FragmentMessages extends FragmentBase prefs.registerOnSharedPreferenceChangeListener(this); onSharedPreferenceChanged(prefs, "notifications_reminder"); + onSharedPreferenceChanged(prefs, "datasaver_reminder"); onSharedPreferenceChanged(prefs, "pro"); if (viewType == AdapterMessage.ViewType.UNIFIED || viewType == AdapterMessage.ViewType.FOLDER) { @@ -5400,6 +5413,14 @@ public class FragmentMessages extends FragmentBase grpNotifications.setVisibility(canNotify || !notifications_reminder ? View.GONE : View.VISIBLE); } + if (grpDataSaver != null && + ("enabled".equals(key) || "datasaver_reminder".equals(key))) { + boolean enabled = prefs.getBoolean("enabled", true); + boolean isDataSaving = ConnectionHelper.isDataSaving(getContext()); + boolean datasaver_reminder = prefs.getBoolean(key, true); + grpDataSaver.setVisibility(enabled && isDataSaving && datasaver_reminder ? View.VISIBLE : View.GONE); + } + if (grpSupport != null && ("pro".equals(key) || "banner_hidden".equals(key))) { boolean pro = ActivityBilling.isPro(getContext()); diff --git a/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java b/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java index 1881d4f985..b3a0927b35 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java +++ b/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java @@ -308,6 +308,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc "raw_asked", "all_read_asked", "delete_asked", "cc_bcc", "inline_image_hint", "compose_reference", "send_dialog", "setup_reminder", "was_ignoring", "setup_advanced", + "notifications_reminder", "datasaver_reminder", "signature_images_hint", "gmail_checked", "eml_auto_confirm", @@ -316,8 +317,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc "redmi_note", "accept_space", "accept_unsupported", "junk_hint", - "last_update_check", "last_announcement_check", - "notifications_reminder" + "last_update_check", "last_announcement_check" }; @Override diff --git a/app/src/main/res/drawable/twotone_data_saver_off_24.xml b/app/src/main/res/drawable/twotone_data_saver_off_24.xml new file mode 100644 index 0000000000..7a0a8be353 --- /dev/null +++ b/app/src/main/res/drawable/twotone_data_saver_off_24.xml @@ -0,0 +1,10 @@ + + + diff --git a/app/src/main/res/layout/fragment_messages.xml b/app/src/main/res/layout/fragment_messages.xml index 3b07876bbb..6e23d1a9ff 100644 --- a/app/src/main/res/layout/fragment_messages.xml +++ b/app/src/main/res/layout/fragment_messages.xml @@ -91,6 +91,31 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/tvBatteryOptimizations" /> + + + + + app:layout_constraintTop_toBottomOf="@+id/vSeparatorDataSaver" /> + + No notification permissions Notification permissions are required for (account) alerts too. Notifications for new messages can be turned off in the settings. Battery optimizations still enabled + If the data saver is enabled, the app will not be able to sync in the background and connection errors may occur. If you have a question or a problem, please use the support menu to get help Swipe left to trash; Swipe right to archive (if available); The swipe actions can be configured in the account settings Long press a message to start selecting multiple messages; Hold and swipe up or down to select more messages