Allow disabling update check

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

@ -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<UpdateInfo>() {
@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

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

@ -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" />
<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
android:id="@+id/swDebug"
android:layout_width="match_parent"
@ -148,6 +158,6 @@
android:layout_marginTop="12dp"
android:text="@string/title_advanced_debug"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvDownload" />
app:layout_constraintTop_toBottomOf="@id/swUpdates" />
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>

@ -104,6 +104,7 @@
<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_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_select">Select &#8230;</string>

Loading…
Cancel
Save