summaryrefslogtreecommitdiffhomepage
path: root/app/src/main/java/com/wireguard/android/activity/SettingsActivity.java
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2018-06-05 01:49:54 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2018-06-05 02:02:09 +0200
commit27072972ab944467bf7286afe4bfd89a4b795753 (patch)
tree54f8cba070fe72a4ba96d61bade23f434a894f98 /app/src/main/java/com/wireguard/android/activity/SettingsActivity.java
parentd56e95c576ebcc9c070a41e1c13fb78951ef63b1 (diff)
DarkMode: move to shared preferences listener
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'app/src/main/java/com/wireguard/android/activity/SettingsActivity.java')
-rw-r--r--app/src/main/java/com/wireguard/android/activity/SettingsActivity.java44
1 files changed, 2 insertions, 42 deletions
diff --git a/app/src/main/java/com/wireguard/android/activity/SettingsActivity.java b/app/src/main/java/com/wireguard/android/activity/SettingsActivity.java
index d7238b96..cfc9f3ef 100644
--- a/app/src/main/java/com/wireguard/android/activity/SettingsActivity.java
+++ b/app/src/main/java/com/wireguard/android/activity/SettingsActivity.java
@@ -21,7 +21,6 @@ import android.view.MenuItem;
import com.wireguard.android.Application;
import com.wireguard.android.R;
import com.wireguard.android.backend.WgQuickBackend;
-import com.wireguard.android.util.Topic;
import java.util.ArrayList;
import java.util.Arrays;
@@ -33,7 +32,7 @@ import java.util.Map;
* Interface for changing application-global persistent settings.
*/
-public class SettingsActivity extends AppCompatActivity implements Topic.Subscriber {
+public class SettingsActivity extends ThemeChangeAwareActivity {
private final Map<Integer, PermissionRequestCallback> permissionRequestCallbacks = new HashMap<>();
private int permissionRequestCounter;
@@ -59,7 +58,6 @@ public class SettingsActivity extends AppCompatActivity implements Topic.Subscri
@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- subscribeTopics();
if (getSupportFragmentManager().findFragmentById(android.R.id.content) == null) {
getSupportFragmentManager().beginTransaction()
.add(android.R.id.content, new SettingsFragment())
@@ -68,12 +66,6 @@ public class SettingsActivity extends AppCompatActivity implements Topic.Subscri
}
@Override
- protected void onDestroy() {
- unsubscribeTopics();
- super.onDestroy();
- }
-
- @Override
public boolean onOptionsItemSelected(final MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
@@ -99,18 +91,7 @@ public class SettingsActivity extends AppCompatActivity implements Topic.Subscri
void done(String[] permissions, int[] grantResults);
}
- @Override
- public void onTopicPublished(final Topic topic) {
- if (topic == Application.getComponent().getThemeChangeTopic())
- recreate();
- }
-
- @Override
- public Topic[] getSubscription() {
- return new Topic[] { Application.getComponent().getThemeChangeTopic() };
- }
-
- public static class SettingsFragment extends PreferenceFragmentCompat implements SharedPreferences.OnSharedPreferenceChangeListener {
+ public static class SettingsFragment extends PreferenceFragmentCompat {
@Override
public void onCreatePreferences(final Bundle savedInstanceState, final String key) {
addPreferencesFromResource(R.xml.preferences);
@@ -121,26 +102,5 @@ public class SettingsActivity extends AppCompatActivity implements Topic.Subscri
getPreferenceScreen().removePreference(pref);
}
}
-
- @Override
- public void onResume() {
- super.onResume();
- getPreferenceManager().getSharedPreferences().registerOnSharedPreferenceChangeListener(this);
- }
-
- @Override
- public void onPause() {
- getPreferenceManager().getSharedPreferences().unregisterOnSharedPreferenceChangeListener(this);
- super.onPause();
- }
-
- @Override
- public void onSharedPreferenceChanged(final SharedPreferences sharedPreferences, final String key) {
- if ("dark_theme".equals(key)) {
- AppCompatDelegate.setDefaultNightMode(
- sharedPreferences.getBoolean(key, false) ? AppCompatDelegate.MODE_NIGHT_YES : AppCompatDelegate.MODE_NIGHT_NO);
- Application.getComponent().getThemeChangeTopic().publish(false);
- }
- }
}
}