From bc9259d042724d305b8c6b763d15c3ab93962fe2 Mon Sep 17 00:00:00 2001 From: M66B Date: Fri, 19 Apr 2019 20:13:27 +0200 Subject: [PATCH] Added setting to disable downloading while roaming --- .../eu/faircode/email/FragmentOptions.java | 14 ++++++++++++- .../main/java/eu/faircode/email/Helper.java | 3 ++- app/src/main/res/layout/fragment_options.xml | 20 +++++++++---------- app/src/main/res/values/strings.xml | 2 +- 4 files changed, 25 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/FragmentOptions.java b/app/src/main/java/eu/faircode/email/FragmentOptions.java index 7011303c2b..b07f356b0f 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOptions.java +++ b/app/src/main/java/eu/faircode/email/FragmentOptions.java @@ -71,6 +71,7 @@ public class FragmentOptions extends FragmentBase implements SharedPreferences.O private TextView tvConnectionRoaming; private SwitchCompat swMetered; private Spinner spDownload; + private SwitchCompat swRoaming; private Spinner spStartup; private SwitchCompat swDate; @@ -126,7 +127,7 @@ public class FragmentOptions extends FragmentBase implements SharedPreferences.O private final static String[] ADVANCED_OPTIONS = new String[]{ "enabled", "schedule_start", "schedule_end", - "metered", "download", + "metered", "download", "roaming", "startup", "date", "threading", "avatars", "identicons", "name_email", "subject_italic", "flags", "preview", "addresses", "monospaced", "autohtml", "autoimages", "actionbar", "pull", "swipenav", "autoexpand", "autoclose", "autonext", "collapse", "autoread", "automove", @@ -155,6 +156,7 @@ public class FragmentOptions extends FragmentBase implements SharedPreferences.O tvConnectionRoaming = view.findViewById(R.id.tvConnectionRoaming); swMetered = view.findViewById(R.id.swMetered); spDownload = view.findViewById(R.id.spDownload); + swRoaming = view.findViewById(R.id.swRoaming); spStartup = view.findViewById(R.id.spStartup); swDate = view.findViewById(R.id.swDate); @@ -281,6 +283,14 @@ public class FragmentOptions extends FragmentBase implements SharedPreferences.O } }); + swRoaming.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { + prefs.edit().putBoolean("roaming", checked).apply(); + ServiceSynchronize.reload(getContext(), "roaming=" + checked); + } + }); + spStartup.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView adapterView, View view, int position, long id) { @@ -652,6 +662,8 @@ public class FragmentOptions extends FragmentBase implements SharedPreferences.O break; } + swRoaming.setChecked(prefs.getBoolean("roaming", true)); + boolean compact = prefs.getBoolean("compact", false); String startup = prefs.getString("startup", "unified"); diff --git a/app/src/main/java/eu/faircode/email/Helper.java b/app/src/main/java/eu/faircode/email/Helper.java index 93fa44eb69..d6adfa8ecd 100644 --- a/app/src/main/java/eu/faircode/email/Helper.java +++ b/app/src/main/java/eu/faircode/email/Helper.java @@ -808,6 +808,7 @@ public class Helper { static NetworkState getNetworkState(Context context) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); boolean metered = prefs.getBoolean("metered", true); + boolean roaming = prefs.getBoolean("roaming", true); NetworkState state = new NetworkState(); Boolean isMetered = isMetered(context); @@ -815,7 +816,7 @@ public class Helper { state.unmetered = (isMetered != null && !isMetered); state.suitable = (isMetered != null && (metered || !isMetered)); - if (state.connected) { + if (state.connected && !roaming) { ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { NetworkInfo ani = cm.getActiveNetworkInfo(); diff --git a/app/src/main/res/layout/fragment_options.xml b/app/src/main/res/layout/fragment_options.xml index 2aee619192..afb58f7da5 100644 --- a/app/src/main/res/layout/fragment_options.xml +++ b/app/src/main/res/layout/fragment_options.xml @@ -225,19 +225,17 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/tvDownload" /> - + app:layout_constraintTop_toBottomOf="@id/spDownload" + app:switchPadding="12dp" /> + app:layout_constraintTop_toBottomOf="@id/swRoaming" /> Use metered connections Automatically download messages and attachments on a metered connection up to + Download messages and attachments while roaming Browse messages on the server Show on start screen @@ -206,7 +207,6 @@ Globally disable or enable receiving and sending of messages Metered connections are generally mobile connections or paid Wi-Fi hotspots Disabling this option will disable receiving and sending messages on mobile internet connections - Message texts and attachments will never be downloaded when roaming Fetch more messages when scrolling down Group messages related to each other When disabled only names will be shown when available