From 51bf59980dac43b9d082416d753eea87588cd64d Mon Sep 17 00:00:00 2001 From: M66B Date: Sat, 10 Nov 2018 11:09:30 +0000 Subject: [PATCH] Allow disabling update check --- .../java/eu/faircode/email/ActivityView.java | 16 ++++++++++------ .../java/eu/faircode/email/FragmentOptions.java | 11 +++++++++++ app/src/main/res/layout/fragment_options.xml | 12 +++++++++++- app/src/main/res/values/strings.xml | 1 + 4 files changed, 33 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/ActivityView.java b/app/src/main/java/eu/faircode/email/ActivityView.java index dc15338187..5e2ea91888 100644 --- a/app/src/main/java/eu/faircode/email/ActivityView.java +++ b/app/src/main/java/eu/faircode/email/ActivityView.java @@ -573,10 +573,13 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB } private void checkUpdate() { - final long now = new Date().getTime(); - final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); + long now = new Date().getTime(); + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); + if (!prefs.getBoolean("updates", true)) + return; if (prefs.getLong("last_update_check", 0) + UPDATE_INTERVAL > now) return; + prefs.edit().putLong("last_update_check", now).apply(); new SimpleTask() { @Override @@ -593,17 +596,18 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB json.append(line); JSONObject jroot = new JSONObject(json.toString()); + if (jroot.has("tag_name") && jroot.has("html_url") && jroot.has("assets")) { - prefs.edit().putLong("last_update_check", now).apply(); - + // Get update info UpdateInfo info = new UpdateInfo(); info.tag_name = jroot.getString("tag_name"); info.html_url = jroot.getString("html_url"); if (TextUtils.isEmpty(info.html_url)) return null; + // Check if new release JSONArray jassets = jroot.getJSONArray("assets"); for (int i = 0; i < jassets.length(); i++) { JSONObject jasset = jassets.getJSONObject(i); @@ -622,12 +626,12 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB } } } + + return null; } finally { if (urlConnection != null) urlConnection.disconnect(); } - - return null; } @Override diff --git a/app/src/main/java/eu/faircode/email/FragmentOptions.java b/app/src/main/java/eu/faircode/email/FragmentOptions.java index 7c2198e138..0e37d000e0 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOptions.java +++ b/app/src/main/java/eu/faircode/email/FragmentOptions.java @@ -53,6 +53,7 @@ public class FragmentOptions extends FragmentEx implements SharedPreferences.OnS private SwitchCompat swSender; private SwitchCompat swInsecure; private Spinner spDownload; + private SwitchCompat swUpdates; private SwitchCompat swDebug; @Override @@ -75,6 +76,7 @@ public class FragmentOptions extends FragmentEx implements SharedPreferences.OnS swSender = view.findViewById(R.id.swSender); swInsecure = view.findViewById(R.id.swInsecure); spDownload = view.findViewById(R.id.spDownload); + swUpdates = view.findViewById(R.id.swUpdates); swDebug = view.findViewById(R.id.swDebug); // Wire controls @@ -222,6 +224,15 @@ public class FragmentOptions extends FragmentEx implements SharedPreferences.OnS } }); + swUpdates.setChecked(prefs.getBoolean("updates", true)); + swUpdates.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { + prefs.edit().putBoolean("updates", checked).apply(); + } + }); + swUpdates.setVisibility(Helper.isPlayStoreInstall(getContext()) ? View.GONE : View.VISIBLE); + swDebug.setChecked(prefs.getBoolean("debug", false)); swDebug.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override diff --git a/app/src/main/res/layout/fragment_options.xml b/app/src/main/res/layout/fragment_options.xml index e2e59992d1..2d67c65fa0 100644 --- a/app/src/main/res/layout/fragment_options.xml +++ b/app/src/main/res/layout/fragment_options.xml @@ -137,10 +137,20 @@ android:layout_height="wrap_content" android:layout_marginStart="12dp" android:entries="@array/downloadNames" + app:layout_constraintBottom_toBottomOf="@id/tvDownload" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toEndOf="@id/tvDownload" app:layout_constraintTop_toTopOf="@id/tvDownload" /> + + + app:layout_constraintTop_toBottomOf="@id/swUpdates" /> \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 465d3c7433..88ef6fd3f4 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -104,6 +104,7 @@ Allow editing sender address Most providers do not allow modified sender addresses Automatically download messages and attachments on a metered connection up to + Check for updates Debug mode Select …