Added data saver warning / resolution

pull/214/head
M66B 11 months ago
parent f6850c7de8
commit 0bc6945591

@ -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

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M13,2.05v3.03c3.39,0.49 6,3.39 6,6.92c0,0.9 -0.18,1.75 -0.48,2.54l2.6,1.53C21.68,14.83 22,13.45 22,12C22,6.82 18.05,2.55 13,2.05zM12,19c-3.87,0 -7,-3.13 -7,-7c0,-3.53 2.61,-6.43 6,-6.92V2.05C5.94,2.55 2,6.81 2,12c0,5.52 4.47,10 9.99,10c3.31,0 6.24,-1.61 8.06,-4.09l-2.6,-1.53C16.17,17.98 14.21,19 12,19z"/>
</vector>

@ -91,6 +91,31 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvBatteryOptimizations" />
<TextView
android:id="@+id/tvDataSaver"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:background="?android:attr/selectableItemBackground"
android:drawableStart="@drawable/twotone_warning_24"
android:drawablePadding="6dp"
android:paddingHorizontal="12dp"
android:paddingVertical="6dp"
android:text="@string/title_setup_data"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
app:drawableTint="?attr/colorWarning"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/vSeparatorBatteryOptimizations" />
<View
android:id="@+id/vSeparatorDataSaver"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="?attr/colorSeparator"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvDataSaver" />
<TextView
android:id="@+id/tvSupport"
android:layout_width="wrap_content"
@ -101,7 +126,7 @@
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/vSeparatorBatteryOptimizations" />
app:layout_constraintTop_toBottomOf="@+id/vSeparatorDataSaver" />
<View
android:id="@+id/vSeparatorSupport"
@ -496,6 +521,12 @@
android:layout_height="0dp"
app:constraint_referenced_ids="tvBatteryOptimizations,vSeparatorBatteryOptimizations" />
<androidx.constraintlayout.widget.Group
android:id="@+id/grpDataSaver"
android:layout_width="0dp"
android:layout_height="0dp"
app:constraint_referenced_ids="tvDataSaver,vSeparatorDataSaver" />
<androidx.constraintlayout.widget.Group
android:id="@+id/grpSupport"
android:layout_width="0dp"

@ -2219,6 +2219,7 @@
<string name="title_hint_notifications">No notification permissions</string>
<string name="title_hint_notifications_remark">Notification permissions are required for (account) alerts too. Notifications for new messages can be turned off in the settings.</string>
<string name="title_hint_battery_optimizations">Battery optimizations still enabled</string>
<string name="title_hint_data_saver">If the data saver is enabled, the app will not be able to sync in the background and connection errors may occur.</string>
<string name="title_hint_support">If you have a question or a problem, please use the support menu to get help</string>
<string name="title_hint_message_actions">Swipe left to trash; Swipe right to archive (if available); The swipe actions can be configured in the account settings</string>
<string name="title_hint_message_selection">Long press a message to start selecting multiple messages; Hold and swipe up or down to select more messages</string>

Loading…
Cancel
Save