diff options
author | stefan-niedermann <info@niedermann.it> | 2019-02-08 13:05:41 +0300 |
---|---|---|
committer | stefan-niedermann <info@niedermann.it> | 2019-02-08 13:05:41 +0300 |
commit | 8e876c2c7614bb6308bd93425beeb8a8506e795c (patch) | |
tree | ff57ca0d714057a6cd32fe56c915ed2874009551 /app/src/main/java/it/niedermann/owncloud/notes/persistence | |
parent | 547cb83890011801d51fc5d4f227b36b4e72c90e (diff) |
#519 Synchronize on WiFi only
- Make `OnSharedPreferencesListener` local
- Use "wifiOnly" via string resource instead of hard coded literal
Diffstat (limited to 'app/src/main/java/it/niedermann/owncloud/notes/persistence')
-rw-r--r-- | app/src/main/java/it/niedermann/owncloud/notes/persistence/NoteServerSyncHelper.java | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/app/src/main/java/it/niedermann/owncloud/notes/persistence/NoteServerSyncHelper.java b/app/src/main/java/it/niedermann/owncloud/notes/persistence/NoteServerSyncHelper.java index dfeca986..1312b29a 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/persistence/NoteServerSyncHelper.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/persistence/NoteServerSyncHelper.java @@ -67,14 +67,8 @@ public class NoteServerSyncHelper { // Track network connection changes using a BroadcastReceiver private boolean networkConnected = false; - boolean syncOnlyOnWifi = false; - - private SharedPreferences.OnSharedPreferenceChangeListener onSharedPreferenceChangeListener = (SharedPreferences prefs, String key) -> { - if ("wifiOnly".equals(key)) { - syncOnlyOnWifi = prefs.getBoolean("wifiOnly", false); - updateNetworkStatus(); - } - }; + private String syncOnlyOnWifiKey = ""; + private boolean syncOnlyOnWifi = false; private final BroadcastReceiver networkReceiver = new BroadcastReceiver() { @Override @@ -114,6 +108,7 @@ public class NoteServerSyncHelper { private NoteServerSyncHelper(NoteSQLiteOpenHelper db) { this.dbHelper = db; this.appContext = db.getContext().getApplicationContext(); + this.syncOnlyOnWifiKey = appContext.getResources().getString(R.string.pref_key_wifi_only); new Thread() { @Override public void run() { @@ -125,8 +120,14 @@ public class NoteServerSyncHelper { appContext.registerReceiver(networkReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION)); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this.appContext); + SharedPreferences.OnSharedPreferenceChangeListener onSharedPreferenceChangeListener = (SharedPreferences changedPrefs, String key) -> { + if (syncOnlyOnWifiKey.equals(key)) { + syncOnlyOnWifi = changedPrefs.getBoolean(syncOnlyOnWifiKey, false); + updateNetworkStatus(); + } + }; prefs.registerOnSharedPreferenceChangeListener(onSharedPreferenceChangeListener); - syncOnlyOnWifi = prefs.getBoolean("wifiOnly", false); + syncOnlyOnWifi = prefs.getBoolean(syncOnlyOnWifiKey, false); updateNetworkStatus(); // bind to certifciate service to block sync attempts if service is not ready |