put stray preference handling into Preferences
This moves a few stray preference handling instances into Preferences, and move the non-preference "lastUpdateCheck" state to local only to UpdateService. This will still work with existing installs since the String constant value is the same.
This commit is contained in:
		
							parent
							
								
									721d4a300a
								
							
						
					
					
						commit
						77e041d640
					
				@ -54,7 +54,6 @@ public final class Preferences implements SharedPreferences.OnSharedPreferenceCh
 | 
			
		||||
    public static final String PREF_CACHE_APK = "cacheDownloaded";
 | 
			
		||||
    public static final String PREF_UNSTABLE_UPDATES = "unstableUpdates";
 | 
			
		||||
    public static final String PREF_EXPERT = "expert";
 | 
			
		||||
    public static final String PREF_UPD_LAST = "lastUpdateCheck";
 | 
			
		||||
    public static final String PREF_PRIVILEGED_INSTALLER = "privilegedInstaller";
 | 
			
		||||
    public static final String PREF_UNINSTALL_PRIVILEGED_APP = "uninstallPrivilegedApp";
 | 
			
		||||
    public static final String PREF_LOCAL_REPO_NAME = "localRepoName";
 | 
			
		||||
@ -179,6 +178,14 @@ public final class Preferences implements SharedPreferences.OnSharedPreferenceCh
 | 
			
		||||
        return preferences.getString(PREF_LOCAL_REPO_NAME, getDefaultLocalRepoName());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean isUpdateNotificationEnabled() {
 | 
			
		||||
        return preferences.getBoolean(PREF_UPD_NOTIFY, true);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean isUpdateOnlyOnWifi() {
 | 
			
		||||
        return preferences.getBoolean(PREF_UPD_WIFI_ONLY, false);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * This preference's default is set dynamically based on whether Orbot is
 | 
			
		||||
     * installed. If Orbot is installed, default to using Tor, the user can still override
 | 
			
		||||
 | 
			
		||||
@ -73,6 +73,8 @@ public class UpdateService extends IntentService implements ProgressListener {
 | 
			
		||||
    public static final int STATUS_ERROR_LOCAL_SMALL = 4;
 | 
			
		||||
    public static final int STATUS_INFO = 5;
 | 
			
		||||
 | 
			
		||||
    private static final String STATE_LAST_UPDATED = "lastUpdateCheck";
 | 
			
		||||
 | 
			
		||||
    private LocalBroadcastManager localBroadcastManager;
 | 
			
		||||
 | 
			
		||||
    private static final int NOTIFY_ID_UPDATING = 0;
 | 
			
		||||
@ -295,7 +297,7 @@ public class UpdateService extends IntentService implements ProgressListener {
 | 
			
		||||
            Log.i(TAG, "Skipping update - disabled");
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
        long lastUpdate = prefs.getLong(Preferences.PREF_UPD_LAST, 0);
 | 
			
		||||
        long lastUpdate = prefs.getLong(STATE_LAST_UPDATED, 0);
 | 
			
		||||
        long elapsed = System.currentTimeMillis() - lastUpdate;
 | 
			
		||||
        if (elapsed < interval * 60 * 60 * 1000) {
 | 
			
		||||
            Log.i(TAG, "Skipping update - done " + elapsed
 | 
			
		||||
@ -318,9 +320,7 @@ public class UpdateService extends IntentService implements ProgressListener {
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
 | 
			
		||||
        if (activeNetwork.getType() != ConnectivityManager.TYPE_WIFI
 | 
			
		||||
                && prefs.getBoolean(Preferences.PREF_UPD_WIFI_ONLY, false)) {
 | 
			
		||||
        if (activeNetwork.getType() != ConnectivityManager.TYPE_WIFI && Preferences.get().isUpdateOnlyOnWifi()) {
 | 
			
		||||
            Log.i(TAG, "Skipping update - wifi not available");
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
@ -343,8 +343,6 @@ public class UpdateService extends IntentService implements ProgressListener {
 | 
			
		||||
                return;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
 | 
			
		||||
 | 
			
		||||
            // Grab some preliminary information, then we can release the
 | 
			
		||||
            // database while we do all the downloading, etc...
 | 
			
		||||
            List<Repo> repos = RepoProvider.Helper.all(this);
 | 
			
		||||
@ -395,13 +393,14 @@ public class UpdateService extends IntentService implements ProgressListener {
 | 
			
		||||
            } else {
 | 
			
		||||
                notifyContentProviders();
 | 
			
		||||
 | 
			
		||||
                if (prefs.getBoolean(Preferences.PREF_UPD_NOTIFY, true)) {
 | 
			
		||||
                if (Preferences.get().isUpdateNotificationEnabled()) {
 | 
			
		||||
                    performUpdateNotification();
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
 | 
			
		||||
            SharedPreferences.Editor e = prefs.edit();
 | 
			
		||||
            e.putLong(Preferences.PREF_UPD_LAST, System.currentTimeMillis());
 | 
			
		||||
            e.putLong(STATE_LAST_UPDATED, System.currentTimeMillis());
 | 
			
		||||
            PreferencesCompat.apply(e);
 | 
			
		||||
 | 
			
		||||
            if (errorRepos == 0) {
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user