mirror of
https://github.com/M66B/FairEmail.git
synced 2026-04-07 01:23:38 +02:00
Added data saver warning / resolution
This commit is contained in:
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
@@ -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());
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user