summaryrefslogtreecommitdiffhomepage
path: root/app/src/main
diff options
context:
space:
mode:
authorSamuel Holland <samuel@sholland.org>2017-08-10 01:04:46 -0500
committerSamuel Holland <samuel@sholland.org>2017-08-10 01:04:46 -0500
commit87d3200b29d43ec5ee93de18d016c483cb3cb239 (patch)
treebfbf77f55083ffd8ee5771ae73bce7c77f38aed5 /app/src/main
parentd6d6f3408860d4f3abba07b4c749d215edbf7cb7 (diff)
ProfileActivity: Do menus correctly
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'app/src/main')
-rw-r--r--app/src/main/java/com/wireguard/android/ProfileActivity.java8
-rw-r--r--app/src/main/java/com/wireguard/android/ProfileDetailActivity.java24
-rw-r--r--app/src/main/java/com/wireguard/android/ProfileEditActivity.java21
-rw-r--r--app/src/main/java/com/wireguard/android/ProfileListActivity.java42
-rw-r--r--app/src/main/res/menu/main.xml4
-rw-r--r--app/src/main/res/menu/profile_detail.xml2
-rw-r--r--app/src/main/res/menu/profile_edit.xml (renamed from app/src/main/res/menu/profile_detail_edit.xml)2
7 files changed, 60 insertions, 43 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)
diff --git a/app/src/main/res/menu/main.xml b/app/src/main/res/menu/main.xml
index 96479d08..462558ec 100644
--- a/app/src/main/res/menu/main.xml
+++ b/app/src/main/res/menu/main.xml
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
+ android:id="@+id/menu_settings"
android:alphabeticShortcut="s"
android:icon="@drawable/ic_settings"
- android:onClick="onMenuSettings"
android:showAsAction="never"
- android:title="@string/settings"/>
+ android:title="@string/settings" />
</menu>
diff --git a/app/src/main/res/menu/profile_detail.xml b/app/src/main/res/menu/profile_detail.xml
index 499adcdb..c00c1603 100644
--- a/app/src/main/res/menu/profile_detail.xml
+++ b/app/src/main/res/menu/profile_detail.xml
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
+ android:id="@+id/menu_action_edit"
android:alphabeticShortcut="e"
android:icon="@drawable/ic_action_edit"
- android:onClick="onMenuEdit"
android:showAsAction="always"
android:title="@string/edit" />
</menu>
diff --git a/app/src/main/res/menu/profile_detail_edit.xml b/app/src/main/res/menu/profile_edit.xml
index ad97fcbf..44e719c7 100644
--- a/app/src/main/res/menu/profile_detail_edit.xml
+++ b/app/src/main/res/menu/profile_edit.xml
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
+ android:id="@+id/menu_action_save"
android:alphabeticShortcut="s"
android:icon="@drawable/ic_action_save"
- android:onClick="onMenuSave"
android:showAsAction="always"
android:title="@string/save" />
</menu>