mirror of https://github.com/M66B/FairEmail.git
Added option to check for main updates only
This commit is contained in:
parent
5f5fc90e10
commit
17dd33c6a6
|
@ -724,23 +724,32 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkUpdate(boolean always) {
|
private void checkUpdate(boolean always) {
|
||||||
if (Helper.isPlayStoreInstall() || !Helper.hasValidFingerprint(this))
|
if (!BuildConfig.DEBUG &&
|
||||||
|
(Helper.isPlayStoreInstall() || !Helper.hasValidFingerprint(this)))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
long now = new Date().getTime();
|
long now = new Date().getTime();
|
||||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
if (!always && !prefs.getBoolean("updates", true))
|
boolean updates = prefs.getBoolean("updates", true);
|
||||||
|
boolean updates_main = prefs.getBoolean("updates_main", false);
|
||||||
|
long last_update_check = prefs.getLong("last_update_check", 0);
|
||||||
|
|
||||||
|
if (!always && !updates)
|
||||||
return;
|
return;
|
||||||
if (!always && prefs.getLong("last_update_check", 0) + UPDATE_INTERVAL > now)
|
if (!always && last_update_check + UPDATE_INTERVAL > now)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
prefs.edit().putLong("last_update_check", now).apply();
|
prefs.edit().putLong("last_update_check", now).apply();
|
||||||
|
|
||||||
Bundle args = new Bundle();
|
Bundle args = new Bundle();
|
||||||
args.putBoolean("always", always);
|
args.putBoolean("always", always);
|
||||||
|
args.putBoolean("updates_main", updates_main);
|
||||||
|
|
||||||
new SimpleTask<UpdateInfo>() {
|
new SimpleTask<UpdateInfo>() {
|
||||||
@Override
|
@Override
|
||||||
protected UpdateInfo onExecute(Context context, Bundle args) throws Throwable {
|
protected UpdateInfo onExecute(Context context, Bundle args) throws Throwable {
|
||||||
|
boolean updates_main = args.getBoolean("updates_main");
|
||||||
|
|
||||||
StringBuilder response = new StringBuilder();
|
StringBuilder response = new StringBuilder();
|
||||||
HttpsURLConnection urlConnection = null;
|
HttpsURLConnection urlConnection = null;
|
||||||
try {
|
try {
|
||||||
|
@ -774,6 +783,8 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
|
||||||
|
|
||||||
JSONObject jroot = new JSONObject(response.toString());
|
JSONObject jroot = new JSONObject(response.toString());
|
||||||
|
|
||||||
|
if (!jroot.has("name") || jroot.isNull("name"))
|
||||||
|
throw new IOException("name field missing");
|
||||||
if (!jroot.has("tag_name") || jroot.isNull("tag_name"))
|
if (!jroot.has("tag_name") || jroot.isNull("tag_name"))
|
||||||
throw new IOException("tag_name field missing");
|
throw new IOException("tag_name field missing");
|
||||||
if (!jroot.has("html_url") || jroot.isNull("html_url"))
|
if (!jroot.has("html_url") || jroot.isNull("html_url"))
|
||||||
|
@ -781,6 +792,10 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
|
||||||
if (!jroot.has("assets") || jroot.isNull("assets"))
|
if (!jroot.has("assets") || jroot.isNull("assets"))
|
||||||
throw new IOException("assets section missing");
|
throw new IOException("assets section missing");
|
||||||
|
|
||||||
|
String name = jroot.getString("name");
|
||||||
|
if (updates_main && !name.contains("*"))
|
||||||
|
return null;
|
||||||
|
|
||||||
// Get update info
|
// 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");
|
||||||
|
@ -791,8 +806,8 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
|
||||||
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);
|
||||||
if (jasset.has("name") && !jasset.isNull("name")) {
|
if (jasset.has("name") && !jasset.isNull("name")) {
|
||||||
String name = jasset.getString("name");
|
String filename = jasset.getString("name");
|
||||||
if (name.endsWith(".apk")) {
|
if (filename.endsWith(".apk")) {
|
||||||
Log.i("Latest version=" + info.tag_name);
|
Log.i("Latest version=" + info.tag_name);
|
||||||
if (BuildConfig.VERSION_NAME.equals(info.tag_name))
|
if (BuildConfig.VERSION_NAME.equals(info.tag_name))
|
||||||
return null;
|
return null;
|
||||||
|
@ -812,6 +827,7 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
|
||||||
@Override
|
@Override
|
||||||
protected void onExecuted(Bundle args, UpdateInfo info) {
|
protected void onExecuted(Bundle args, UpdateInfo info) {
|
||||||
boolean always = args.getBoolean("always");
|
boolean always = args.getBoolean("always");
|
||||||
|
|
||||||
if (info == null) {
|
if (info == null) {
|
||||||
if (always)
|
if (always)
|
||||||
ToastEx.makeText(ActivityView.this, BuildConfig.VERSION_NAME, Toast.LENGTH_LONG).show();
|
ToastEx.makeText(ActivityView.this, BuildConfig.VERSION_NAME, Toast.LENGTH_LONG).show();
|
||||||
|
|
|
@ -59,6 +59,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
|
||||||
private SwitchCompat swWatchdog;
|
private SwitchCompat swWatchdog;
|
||||||
private SwitchCompat swOptimize;
|
private SwitchCompat swOptimize;
|
||||||
private SwitchCompat swUpdates;
|
private SwitchCompat swUpdates;
|
||||||
|
private SwitchCompat swUpdatesMain;
|
||||||
private SwitchCompat swExperiments;
|
private SwitchCompat swExperiments;
|
||||||
private TextView tvExperimentsHint;
|
private TextView tvExperimentsHint;
|
||||||
private SwitchCompat swCrashReports;
|
private SwitchCompat swCrashReports;
|
||||||
|
@ -74,10 +75,11 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
|
||||||
private TextView tvStorageSpace;
|
private TextView tvStorageSpace;
|
||||||
private TextView tvFingerprint;
|
private TextView tvFingerprint;
|
||||||
|
|
||||||
|
private Group grpUpdates;
|
||||||
private Group grpDebug;
|
private Group grpDebug;
|
||||||
|
|
||||||
private final static String[] RESET_OPTIONS = new String[]{
|
private final static String[] RESET_OPTIONS = new String[]{
|
||||||
"fts", "english", "watchdog", "auto_optimize", "updates", "experiments", "crash_reports", "debug"
|
"fts", "english", "watchdog", "auto_optimize", "updates", "updates_main", "experiments", "crash_reports", "debug"
|
||||||
};
|
};
|
||||||
|
|
||||||
private final static String[] RESET_QUESTIONS = new String[]{
|
private final static String[] RESET_QUESTIONS = new String[]{
|
||||||
|
@ -105,6 +107,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
|
||||||
swWatchdog = view.findViewById(R.id.swWatchdog);
|
swWatchdog = view.findViewById(R.id.swWatchdog);
|
||||||
swOptimize = view.findViewById(R.id.swOptimize);
|
swOptimize = view.findViewById(R.id.swOptimize);
|
||||||
swUpdates = view.findViewById(R.id.swUpdates);
|
swUpdates = view.findViewById(R.id.swUpdates);
|
||||||
|
swUpdatesMain = view.findViewById(R.id.swUpdatesMain);
|
||||||
swExperiments = view.findViewById(R.id.swExperiments);
|
swExperiments = view.findViewById(R.id.swExperiments);
|
||||||
tvExperimentsHint = view.findViewById(R.id.tvExperimentsHint);
|
tvExperimentsHint = view.findViewById(R.id.tvExperimentsHint);
|
||||||
swCrashReports = view.findViewById(R.id.swCrashReports);
|
swCrashReports = view.findViewById(R.id.swCrashReports);
|
||||||
|
@ -120,6 +123,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
|
||||||
tvStorageSpace = view.findViewById(R.id.tvStorageSpace);
|
tvStorageSpace = view.findViewById(R.id.tvStorageSpace);
|
||||||
tvFingerprint = view.findViewById(R.id.tvFingerprint);
|
tvFingerprint = view.findViewById(R.id.tvFingerprint);
|
||||||
|
|
||||||
|
grpUpdates = view.findViewById(R.id.grpUpdates);
|
||||||
grpDebug = view.findViewById(R.id.grpDebug);
|
grpDebug = view.findViewById(R.id.grpDebug);
|
||||||
|
|
||||||
setOptions();
|
setOptions();
|
||||||
|
@ -207,6 +211,14 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
|
||||||
NotificationManager nm = (NotificationManager) getContext().getSystemService(Context.NOTIFICATION_SERVICE);
|
NotificationManager nm = (NotificationManager) getContext().getSystemService(Context.NOTIFICATION_SERVICE);
|
||||||
nm.cancel(Helper.NOTIFICATION_UPDATE);
|
nm.cancel(Helper.NOTIFICATION_UPDATE);
|
||||||
}
|
}
|
||||||
|
swUpdatesMain.setEnabled(checked);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
swUpdatesMain.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||||
|
@Override
|
||||||
|
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
||||||
|
prefs.edit().putBoolean("updates_main", checked).apply();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -384,9 +396,8 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
|
||||||
swWatchdog.setChecked(prefs.getBoolean("watchdog", true));
|
swWatchdog.setChecked(prefs.getBoolean("watchdog", true));
|
||||||
swOptimize.setChecked(prefs.getBoolean("auto_optimize", false));
|
swOptimize.setChecked(prefs.getBoolean("auto_optimize", false));
|
||||||
swUpdates.setChecked(prefs.getBoolean("updates", true));
|
swUpdates.setChecked(prefs.getBoolean("updates", true));
|
||||||
swUpdates.setVisibility(
|
swUpdatesMain.setChecked(prefs.getBoolean("updates_main", false));
|
||||||
Helper.isPlayStoreInstall() || !Helper.hasValidFingerprint(getContext())
|
swUpdatesMain.setEnabled(swUpdates.isChecked());
|
||||||
? View.GONE : View.VISIBLE);
|
|
||||||
swExperiments.setChecked(prefs.getBoolean("experiments", false));
|
swExperiments.setChecked(prefs.getBoolean("experiments", false));
|
||||||
swCrashReports.setChecked(prefs.getBoolean("crash_reports", false));
|
swCrashReports.setChecked(prefs.getBoolean("crash_reports", false));
|
||||||
tvUuid.setText(prefs.getString("uuid", null));
|
tvUuid.setText(prefs.getString("uuid", null));
|
||||||
|
@ -403,6 +414,10 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
|
||||||
Helper.humanReadableByteCount(Helper.getTotalStorageSpace(), true)));
|
Helper.humanReadableByteCount(Helper.getTotalStorageSpace(), true)));
|
||||||
tvFingerprint.setText(Helper.getFingerprint(getContext()));
|
tvFingerprint.setText(Helper.getFingerprint(getContext()));
|
||||||
|
|
||||||
|
grpUpdates.setVisibility(!BuildConfig.DEBUG &&
|
||||||
|
(Helper.isPlayStoreInstall() || !Helper.hasValidFingerprint(getContext()))
|
||||||
|
? View.GONE : View.VISIBLE);
|
||||||
|
|
||||||
grpDebug.setVisibility(swDebug.isChecked() || BuildConfig.DEBUG ? View.VISIBLE : View.GONE);
|
grpDebug.setVisibility(swDebug.isChecked() || BuildConfig.DEBUG ? View.VISIBLE : View.GONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -146,6 +146,17 @@
|
||||||
app:layout_constraintTop_toBottomOf="@id/swOptimize"
|
app:layout_constraintTop_toBottomOf="@id/swOptimize"
|
||||||
app:switchPadding="12dp" />
|
app:switchPadding="12dp" />
|
||||||
|
|
||||||
|
<androidx.appcompat.widget.SwitchCompat
|
||||||
|
android:id="@+id/swUpdatesMain"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="12dp"
|
||||||
|
android:text="@string/title_advanced_updates_main"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@id/swUpdates"
|
||||||
|
app:switchPadding="12dp" />
|
||||||
|
|
||||||
<androidx.appcompat.widget.SwitchCompat
|
<androidx.appcompat.widget.SwitchCompat
|
||||||
android:id="@+id/swExperiments"
|
android:id="@+id/swExperiments"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
|
@ -156,7 +167,7 @@
|
||||||
android:visibility="gone"
|
android:visibility="gone"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toBottomOf="@id/swUpdates"
|
app:layout_constraintTop_toBottomOf="@id/swUpdatesMain"
|
||||||
app:switchPadding="12dp" />
|
app:switchPadding="12dp" />
|
||||||
|
|
||||||
<eu.faircode.email.FixedTextView
|
<eu.faircode.email.FixedTextView
|
||||||
|
@ -322,6 +333,12 @@
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toBottomOf="@id/tvStorageSpace" />
|
app:layout_constraintTop_toBottomOf="@id/tvStorageSpace" />
|
||||||
|
|
||||||
|
<androidx.constraintlayout.widget.Group
|
||||||
|
android:id="@+id/grpUpdates"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="0dp"
|
||||||
|
app:constraint_referenced_ids="swUpdates,swUpdatesMain" />
|
||||||
|
|
||||||
<androidx.constraintlayout.widget.Group
|
<androidx.constraintlayout.widget.Group
|
||||||
android:id="@+id/grpDebug"
|
android:id="@+id/grpDebug"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
|
|
|
@ -432,6 +432,7 @@
|
||||||
<string name="title_advanced_watchdog">Periodically check if FairEmail is still active</string>
|
<string name="title_advanced_watchdog">Periodically check if FairEmail is still active</string>
|
||||||
<string name="title_advanced_optimize">Automatically optimize settings</string>
|
<string name="title_advanced_optimize">Automatically optimize settings</string>
|
||||||
<string name="title_advanced_updates">Check for updates</string>
|
<string name="title_advanced_updates">Check for updates</string>
|
||||||
|
<string name="title_advanced_updates_main">Check for main updates only</string>
|
||||||
<string name="title_advanced_experiments">Try experimental features</string>
|
<string name="title_advanced_experiments">Try experimental features</string>
|
||||||
<string name="title_advanced_crash_reports">Send error reports</string>
|
<string name="title_advanced_crash_reports">Send error reports</string>
|
||||||
<string name="title_advanced_debug">Debug mode</string>
|
<string name="title_advanced_debug">Debug mode</string>
|
||||||
|
|
Loading…
Reference in New Issue