From 09d04937b9e33daa6cbba04ce174c2bcc9dc69f9 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Mon, 27 Nov 2017 03:13:34 +0100 Subject: Settings: show quick tile config if no primary is defined This seems like a horrific set of hacks. --- app/src/main/java/com/wireguard/android/ConfigListPreference.java | 2 ++ app/src/main/java/com/wireguard/android/QuickTileService.java | 8 +++++++- app/src/main/java/com/wireguard/android/SettingsActivity.java | 8 +++++++- 3 files changed, 16 insertions(+), 2 deletions(-) (limited to 'app/src/main/java') diff --git a/app/src/main/java/com/wireguard/android/ConfigListPreference.java b/app/src/main/java/com/wireguard/android/ConfigListPreference.java index 131b0a43..e0bcc672 100644 --- a/app/src/main/java/com/wireguard/android/ConfigListPreference.java +++ b/app/src/main/java/com/wireguard/android/ConfigListPreference.java @@ -34,4 +34,6 @@ public class ConfigListPreference extends ListPreference { public ConfigListPreference(final Context context) { this(context, null); } + + public void show() { showDialog(null); } } diff --git a/app/src/main/java/com/wireguard/android/QuickTileService.java b/app/src/main/java/com/wireguard/android/QuickTileService.java index 31ebe568..e512b1ad 100644 --- a/app/src/main/java/com/wireguard/android/QuickTileService.java +++ b/app/src/main/java/com/wireguard/android/QuickTileService.java @@ -30,7 +30,13 @@ public class QuickTileService extends TileService { else service.enable(config.getName()); } else { - startActivityAndCollapse(new Intent(this, ConfigActivity.class)); + if (service != null && service.getConfigs().isEmpty()) { + startActivityAndCollapse(new Intent(this, ConfigActivity.class)); + } else { + final Intent intent = new Intent(this, SettingsActivity.class); + intent.putExtra("showQuickTile", true); + startActivityAndCollapse(intent); + } } } diff --git a/app/src/main/java/com/wireguard/android/SettingsActivity.java b/app/src/main/java/com/wireguard/android/SettingsActivity.java index 6fa3f897..be9f5bf4 100644 --- a/app/src/main/java/com/wireguard/android/SettingsActivity.java +++ b/app/src/main/java/com/wireguard/android/SettingsActivity.java @@ -10,7 +10,11 @@ public class SettingsActivity extends Activity { protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); final FragmentTransaction transaction = getFragmentManager().beginTransaction(); - transaction.replace(android.R.id.content, new SettingsFragment()).commit(); + final Bundle args = new Bundle(); + args.putBoolean("showQuickTile", getIntent().getBooleanExtra("showQuickTile", false)); + final SettingsFragment fragment = new SettingsFragment(); + fragment.setArguments(args); + transaction.replace(android.R.id.content, fragment).commit(); } public static class SettingsFragment extends PreferenceFragment { @@ -18,6 +22,8 @@ public class SettingsActivity extends Activity { public void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preferences); + if (getArguments().getBoolean("showQuickTile")) + ((ConfigListPreference) findPreference("primary_config")).show(); } } } -- cgit v1.2.3