Allow disabling update check

pull/146/head
M66B 7 years ago
parent a9450edc3f
commit 51bf59980d

@ -573,10 +573,13 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
} }
private void checkUpdate() { private void checkUpdate() {
final long now = new Date().getTime(); long now = new Date().getTime();
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
if (!prefs.getBoolean("updates", true))
return;
if (prefs.getLong("last_update_check", 0) + UPDATE_INTERVAL > now) if (prefs.getLong("last_update_check", 0) + UPDATE_INTERVAL > now)
return; return;
prefs.edit().putLong("last_update_check", now).apply();
new SimpleTask<UpdateInfo>() { new SimpleTask<UpdateInfo>() {
@Override @Override
@ -593,17 +596,18 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
json.append(line); json.append(line);
JSONObject jroot = new JSONObject(json.toString()); JSONObject jroot = new JSONObject(json.toString());
if (jroot.has("tag_name") && if (jroot.has("tag_name") &&
jroot.has("html_url") && jroot.has("html_url") &&
jroot.has("assets")) { jroot.has("assets")) {
prefs.edit().putLong("last_update_check", now).apply(); // Get update info
UpdateInfo info = new UpdateInfo(); UpdateInfo info = new UpdateInfo();
info.tag_name = jroot.getString("tag_name"); info.tag_name = jroot.getString("tag_name");
info.html_url = jroot.getString("html_url"); info.html_url = jroot.getString("html_url");
if (TextUtils.isEmpty(info.html_url)) if (TextUtils.isEmpty(info.html_url))
return null; return null;
// Check if new release
JSONArray jassets = jroot.getJSONArray("assets"); JSONArray jassets = jroot.getJSONArray("assets");
for (int i = 0; i < jassets.length(); i++) { for (int i = 0; i < jassets.length(); i++) {
JSONObject jasset = jassets.getJSONObject(i); JSONObject jasset = jassets.getJSONObject(i);
@ -622,12 +626,12 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
} }
} }
} }
return null;
} finally { } finally {
if (urlConnection != null) if (urlConnection != null)
urlConnection.disconnect(); urlConnection.disconnect();
} }
return null;
} }
@Override @Override

@ -53,6 +53,7 @@ public class FragmentOptions extends FragmentEx implements SharedPreferences.OnS
private SwitchCompat swSender; private SwitchCompat swSender;
private SwitchCompat swInsecure; private SwitchCompat swInsecure;
private Spinner spDownload; private Spinner spDownload;
private SwitchCompat swUpdates;
private SwitchCompat swDebug; private SwitchCompat swDebug;
@Override @Override
@ -75,6 +76,7 @@ public class FragmentOptions extends FragmentEx implements SharedPreferences.OnS
swSender = view.findViewById(R.id.swSender); swSender = view.findViewById(R.id.swSender);
swInsecure = view.findViewById(R.id.swInsecure); swInsecure = view.findViewById(R.id.swInsecure);
spDownload = view.findViewById(R.id.spDownload); spDownload = view.findViewById(R.id.spDownload);
swUpdates = view.findViewById(R.id.swUpdates);
swDebug = view.findViewById(R.id.swDebug); swDebug = view.findViewById(R.id.swDebug);
// Wire controls // 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.setChecked(prefs.getBoolean("debug", false));
swDebug.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { swDebug.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override @Override

@ -137,10 +137,20 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="12dp" android:layout_marginStart="12dp"
android:entries="@array/downloadNames" android:entries="@array/downloadNames"
app:layout_constraintBottom_toBottomOf="@id/tvDownload"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/tvDownload" app:layout_constraintStart_toEndOf="@id/tvDownload"
app:layout_constraintTop_toTopOf="@id/tvDownload" /> app:layout_constraintTop_toTopOf="@id/tvDownload" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swUpdates"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_advanced_updates"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvDownload" />
<androidx.appcompat.widget.SwitchCompat <androidx.appcompat.widget.SwitchCompat
android:id="@+id/swDebug" android:id="@+id/swDebug"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -148,6 +158,6 @@
android:layout_marginTop="12dp" android:layout_marginTop="12dp"
android:text="@string/title_advanced_debug" android:text="@string/title_advanced_debug"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvDownload" /> app:layout_constraintTop_toBottomOf="@id/swUpdates" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView> </ScrollView>

@ -104,6 +104,7 @@
<string name="title_advanced_sender">Allow editing sender address</string> <string name="title_advanced_sender">Allow editing sender address</string>
<string name="title_advanced_sender_hint">Most providers do not allow modified sender addresses</string> <string name="title_advanced_sender_hint">Most providers do not allow modified sender addresses</string>
<string name="title_advanced_download">Automatically download messages and attachments on a metered connection up to</string> <string name="title_advanced_download">Automatically download messages and attachments on a metered connection up to</string>
<string name="title_advanced_updates">Check for updates</string>
<string name="title_advanced_debug">Debug mode</string> <string name="title_advanced_debug">Debug mode</string>
<string name="title_select">Select &#8230;</string> <string name="title_select">Select &#8230;</string>

Loading…
Cancel
Save