diff options
author | Samuel Holland <samuel@sholland.org> | 2017-08-10 01:04:46 -0500 |
---|---|---|
committer | Samuel Holland <samuel@sholland.org> | 2017-08-10 01:04:46 -0500 |
commit | 87d3200b29d43ec5ee93de18d016c483cb3cb239 (patch) | |
tree | bfbf77f55083ffd8ee5771ae73bce7c77f38aed5 /app/src/main/java/com/wireguard | |
parent | d6d6f3408860d4f3abba07b4c749d215edbf7cb7 (diff) |
ProfileActivity: Do menus correctly
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'app/src/main/java/com/wireguard')
4 files changed, 56 insertions, 39 deletions
diff --git a/app/src/main/java/com/wireguard/android/ProfileActivity.java b/app/src/main/java/com/wireguard/android/ProfileActivity.java index 49502d07..29d249d4 100644 --- a/app/src/main/java/com/wireguard/android/ProfileActivity.java +++ b/app/src/main/java/com/wireguard/android/ProfileActivity.java @@ -52,14 +52,6 @@ abstract class ProfileActivity extends ServiceClientActivity<ProfileServiceInter return true; } - public abstract void onMenuEdit(MenuItem item); - - public abstract void onMenuSave(MenuItem item); - - public void onMenuSettings(MenuItem item) { - startActivity(new Intent(this, SettingsActivity.class)); - } - @Override public void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); diff --git a/app/src/main/java/com/wireguard/android/ProfileDetailActivity.java b/app/src/main/java/com/wireguard/android/ProfileDetailActivity.java index 5f537935..3e70de93 100644 --- a/app/src/main/java/com/wireguard/android/ProfileDetailActivity.java +++ b/app/src/main/java/com/wireguard/android/ProfileDetailActivity.java @@ -20,14 +20,20 @@ public class ProfileDetailActivity extends ProfileActivity { } @Override - public void onMenuEdit(MenuItem item) { - final Intent intent = new Intent(this, ProfileEditActivity.class); - intent.putExtra(KEY_PROFILE_NAME, getCurrentProfile()); - startActivity(intent); - } - - @Override - public void onMenuSave(MenuItem item) { - throw new IllegalStateException(); + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case R.id.menu_action_edit: + final Intent intent = new Intent(this, ProfileEditActivity.class); + intent.putExtra(KEY_PROFILE_NAME, getCurrentProfile()); + startActivity(intent); + return true; + case R.id.menu_action_save: + throw new IllegalStateException(); + case R.id.menu_settings: + startActivity(new Intent(this, SettingsActivity.class)); + return true; + default: + return false; + } } } diff --git a/app/src/main/java/com/wireguard/android/ProfileEditActivity.java b/app/src/main/java/com/wireguard/android/ProfileEditActivity.java index 01caf2c4..92d68904 100644 --- a/app/src/main/java/com/wireguard/android/ProfileEditActivity.java +++ b/app/src/main/java/com/wireguard/android/ProfileEditActivity.java @@ -1,5 +1,6 @@ package com.wireguard.android; +import android.content.Intent; import android.view.MenuItem; /** @@ -8,12 +9,18 @@ import android.view.MenuItem; public class ProfileEditActivity extends ProfileActivity { @Override - public void onMenuEdit(MenuItem item) { - throw new IllegalStateException(); - } - - @Override - public void onMenuSave(MenuItem item) { - + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case R.id.menu_action_edit: + throw new IllegalStateException(); + case R.id.menu_action_save: + finish(); + return false; + case R.id.menu_settings: + startActivity(new Intent(this, SettingsActivity.class)); + return true; + default: + return false; + } } } diff --git a/app/src/main/java/com/wireguard/android/ProfileListActivity.java b/app/src/main/java/com/wireguard/android/ProfileListActivity.java index 565533ae..1e344060 100644 --- a/app/src/main/java/com/wireguard/android/ProfileListActivity.java +++ b/app/src/main/java/com/wireguard/android/ProfileListActivity.java @@ -35,29 +35,28 @@ public class ProfileListActivity extends ProfileActivity { } transaction.commit(); if (isEditing()) - onMenuEdit(null); + startEditing(); else onProfileSelected(getCurrentProfile()); } @Override - public void onMenuEdit(MenuItem item) { - setIsEditing(true); - if (isSplitLayout) { - updateLayout(getCurrentProfile()); - } else { - final Intent intent = new Intent(this, ProfileEditActivity.class); - intent.putExtra(KEY_PROFILE_NAME, getCurrentProfile()); - startActivity(intent); + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case R.id.menu_action_edit: + startEditing(); + return true; + case R.id.menu_action_save: + getFragmentManager().popBackStack(); + return false; + case R.id.menu_settings: + startActivity(new Intent(this, SettingsActivity.class)); + return true; + default: + return false; } } - @Override - public void onMenuSave(MenuItem item) { - setIsEditing(false); - - } - public void onProfileSelected(String profile) { setIsEditing(false); if (isSplitLayout) { @@ -71,6 +70,19 @@ public class ProfileListActivity extends ProfileActivity { } } + private void startEditing() { + if (isSplitLayout) { + setIsEditing(true); + updateLayout(getCurrentProfile()); + } else if (getCurrentProfile() != null) { + final Intent intent = new Intent(this, ProfileEditActivity.class); + intent.putExtra(KEY_PROFILE_NAME, getCurrentProfile()); + startActivity(intent); + setCurrentProfile(null); + setIsEditing(false); + } + } + public void updateLayout(String profile) { final Fragment fragment = getFragmentManager().findFragmentById(R.id.fragment_container); if (isEditing() && profile == null) |