From 32d669a661edec69f88f5d2646071de761b87630 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Fri, 1 Jun 2018 07:34:00 +0200 Subject: theme: add dark theme with toggle Signed-off-by: Jason A. Donenfeld --- .../wireguard/android/activity/BaseActivity.java | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'app/src/main/java/com/wireguard/android/activity/BaseActivity.java') diff --git a/app/src/main/java/com/wireguard/android/activity/BaseActivity.java b/app/src/main/java/com/wireguard/android/activity/BaseActivity.java index a0f3c32f..16e66817 100644 --- a/app/src/main/java/com/wireguard/android/activity/BaseActivity.java +++ b/app/src/main/java/com/wireguard/android/activity/BaseActivity.java @@ -16,6 +16,7 @@ import com.wireguard.android.Application; import com.wireguard.android.backend.GoBackend; import com.wireguard.android.model.Tunnel; import com.wireguard.android.model.TunnelManager; +import com.wireguard.android.util.Topic; import java.util.Objects; @@ -23,7 +24,7 @@ import java.util.Objects; * Base class for activities that need to remember the currently-selected tunnel. */ -public abstract class BaseActivity extends AppCompatActivity { +public abstract class BaseActivity extends AppCompatActivity implements Topic.Subscriber { private static final String KEY_SELECTED_TUNNEL = "selected_tunnel"; private final SelectionChangeRegistry selectionChangeRegistry = new SelectionChangeRegistry(); @@ -40,6 +41,8 @@ public abstract class BaseActivity extends AppCompatActivity { @Override protected void onCreate(final Bundle savedInstanceState) { + subscribeTopics(); + // Restore the saved tunnel if there is one; otherwise grab it from the arguments. String savedTunnelName = null; if (savedInstanceState != null) @@ -62,6 +65,12 @@ public abstract class BaseActivity extends AppCompatActivity { } } + @Override + protected void onDestroy() { + unsubscribeTopics(); + super.onDestroy(); + } + @Override protected void onSaveInstanceState(final Bundle outState) { if (selectedTunnel != null) @@ -105,4 +114,14 @@ public abstract class BaseActivity extends AppCompatActivity { super(new SelectionChangeNotifier()); } } + + @Override + public void onTopicPublished(Topic topic) { + recreate(); + } + + @Override + public Topic[] getSubscription() { + return new Topic[] { Application.getComponent().getThemeChangeTopic() }; + } } -- cgit v1.2.3