Extracted triedEmptyUpdate preference.

This commit is contained in:
Peter Serwylo 2017-03-14 07:59:38 +11:00
parent a3de43ff7a
commit 259dd38ae9
4 changed files with 31 additions and 16 deletions

View File

@ -68,6 +68,7 @@ public final class Preferences implements SharedPreferences.OnSharedPreferenceCh
public static final String PREF_PROXY_PORT = "proxyPort";
public static final String PREF_SHOW_NFC_DURING_SWAP = "showNfcDuringSwap";
public static final String PREF_POST_PRIVILEGED_INSTALL = "postPrivilegedInstall";
public static final String PREF_TRIED_EMPTY_UPDATE = "triedEmptyUpdate";
private static final boolean DEFAULT_ROOTED = true;
private static final boolean DEFAULT_HIDE_ANTI_FEATURE_APPS = false;
@ -182,6 +183,20 @@ public final class Preferences implements SharedPreferences.OnSharedPreferenceCh
}
}
/**
* Used the first time F-Droid is installed to flag whether or not we have tried to request
* apps from the repo. This is used so that when there is no apps available, we can differentiate
* between whether the repos actually have no apps (in which case we don't need to continue
* asking), or whether there is no apps because we have never actually asked to update the repos.
*/
public boolean hasTriedEmptyUpdate() {
return preferences.getBoolean(PREF_TRIED_EMPTY_UPDATE, false);
}
public void setTriedEmptyUpdate(boolean value) {
preferences.edit().putBoolean(PREF_TRIED_EMPTY_UPDATE, value).apply();
}
public boolean getUnstableUpdates() {
return preferences.getBoolean(PREF_UNSTABLE_UPDATES, DEFAULT_UNSTABLE_UPDATES);
}

View File

@ -28,6 +28,7 @@ import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.preference.PreferenceManager;
import android.text.TextUtils;
import android.util.Log;
@ -880,7 +881,8 @@ class DBHelper extends SQLiteOpenHelper {
private void resetTransient(SQLiteDatabase db) {
Utils.debugLog(TAG, "Removing app + apk tables so they can be recreated. Next time F-Droid updates it should trigger an index update.");
context.getSharedPreferences("FDroid", Context.MODE_PRIVATE)
PreferenceManager.getDefaultSharedPreferences(context)
.edit()
.putBoolean("triedEmptyUpdate", false)
.apply();
@ -924,8 +926,12 @@ class DBHelper extends SQLiteOpenHelper {
if (oldVersion >= 42) {
return;
}
context.getSharedPreferences("FDroid", Context.MODE_PRIVATE).edit()
.putBoolean("triedEmptyUpdate", false).apply();
PreferenceManager.getDefaultSharedPreferences(context)
.edit()
.putBoolean("triedEmptyUpdate", false)
.apply();
db.execSQL("drop table " + AppMetadataTable.NAME);
db.execSQL("drop table " + ApkTable.NAME);
clearRepoEtags(db);

View File

@ -1,8 +1,6 @@
package org.fdroid.fdroid.views.fragments;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.net.Uri;
import android.os.Build;
@ -143,12 +141,10 @@ public abstract class AppListFragment extends ListFragment implements
* be bad.
*/
private boolean updateEmptyRepos() {
final String triedEmptyUpdate = "triedEmptyUpdate";
SharedPreferences prefs = getActivity().getPreferences(Context.MODE_PRIVATE);
boolean hasTriedEmptyUpdate = prefs.getBoolean(triedEmptyUpdate, false);
if (!hasTriedEmptyUpdate) {
Preferences prefs = Preferences.get();
if (!prefs.hasTriedEmptyUpdate()) {
Utils.debugLog(TAG, "Empty app list, and we haven't done an update yet. Forcing repo update.");
prefs.edit().putBoolean(triedEmptyUpdate, true).apply();
prefs.setTriedEmptyUpdate(true);
UpdateService.updateNow(getActivity());
return true;
}

View File

@ -3,7 +3,6 @@ package org.fdroid.fdroid.views.main;
import android.app.SearchManager;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.NonNull;
@ -19,6 +18,7 @@ import org.fdroid.fdroid.AppDetails;
import org.fdroid.fdroid.AppDetails2;
import org.fdroid.fdroid.FDroidApp;
import org.fdroid.fdroid.NfcHelper;
import org.fdroid.fdroid.Preferences;
import org.fdroid.fdroid.R;
import org.fdroid.fdroid.UpdateService;
import org.fdroid.fdroid.Utils;
@ -85,12 +85,10 @@ public class MainActivity extends AppCompatActivity implements BottomNavigationV
* don't try to do it automatically again.
*/
private void initialRepoUpdateIfRequired() {
final String triedEmptyUpdate = "triedEmptyUpdate";
SharedPreferences prefs = getPreferences(Context.MODE_PRIVATE);
boolean hasTriedEmptyUpdate = prefs.getBoolean(triedEmptyUpdate, false);
if (!hasTriedEmptyUpdate) {
Preferences prefs = Preferences.get();
if (!prefs.hasTriedEmptyUpdate()) {
Utils.debugLog(TAG, "We haven't done an update yet. Forcing repo update.");
prefs.edit().putBoolean(triedEmptyUpdate, true).apply();
prefs.setTriedEmptyUpdate(true);
UpdateService.updateNow(this);
}
}