ProfileActivity: Do menus correctly
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
parent
d6d6f34088
commit
87d3200b29
@ -52,14 +52,6 @@ abstract class ProfileActivity extends ServiceClientActivity<ProfileServiceInter
|
|||||||
return true;
|
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
|
@Override
|
||||||
public void onSaveInstanceState(Bundle outState) {
|
public void onSaveInstanceState(Bundle outState) {
|
||||||
super.onSaveInstanceState(outState);
|
super.onSaveInstanceState(outState);
|
||||||
|
@ -20,14 +20,20 @@ public class ProfileDetailActivity extends ProfileActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onMenuEdit(MenuItem item) {
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
final Intent intent = new Intent(this, ProfileEditActivity.class);
|
switch (item.getItemId()) {
|
||||||
intent.putExtra(KEY_PROFILE_NAME, getCurrentProfile());
|
case R.id.menu_action_edit:
|
||||||
startActivity(intent);
|
final Intent intent = new Intent(this, ProfileEditActivity.class);
|
||||||
}
|
intent.putExtra(KEY_PROFILE_NAME, getCurrentProfile());
|
||||||
|
startActivity(intent);
|
||||||
@Override
|
return true;
|
||||||
public void onMenuSave(MenuItem item) {
|
case R.id.menu_action_save:
|
||||||
throw new IllegalStateException();
|
throw new IllegalStateException();
|
||||||
|
case R.id.menu_settings:
|
||||||
|
startActivity(new Intent(this, SettingsActivity.class));
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.wireguard.android;
|
package com.wireguard.android;
|
||||||
|
|
||||||
|
import android.content.Intent;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -8,12 +9,18 @@ import android.view.MenuItem;
|
|||||||
|
|
||||||
public class ProfileEditActivity extends ProfileActivity {
|
public class ProfileEditActivity extends ProfileActivity {
|
||||||
@Override
|
@Override
|
||||||
public void onMenuEdit(MenuItem item) {
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
throw new IllegalStateException();
|
switch (item.getItemId()) {
|
||||||
}
|
case R.id.menu_action_edit:
|
||||||
|
throw new IllegalStateException();
|
||||||
@Override
|
case R.id.menu_action_save:
|
||||||
public void onMenuSave(MenuItem item) {
|
finish();
|
||||||
|
return false;
|
||||||
|
case R.id.menu_settings:
|
||||||
|
startActivity(new Intent(this, SettingsActivity.class));
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,29 +35,28 @@ public class ProfileListActivity extends ProfileActivity {
|
|||||||
}
|
}
|
||||||
transaction.commit();
|
transaction.commit();
|
||||||
if (isEditing())
|
if (isEditing())
|
||||||
onMenuEdit(null);
|
startEditing();
|
||||||
else
|
else
|
||||||
onProfileSelected(getCurrentProfile());
|
onProfileSelected(getCurrentProfile());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onMenuEdit(MenuItem item) {
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
setIsEditing(true);
|
switch (item.getItemId()) {
|
||||||
if (isSplitLayout) {
|
case R.id.menu_action_edit:
|
||||||
updateLayout(getCurrentProfile());
|
startEditing();
|
||||||
} else {
|
return true;
|
||||||
final Intent intent = new Intent(this, ProfileEditActivity.class);
|
case R.id.menu_action_save:
|
||||||
intent.putExtra(KEY_PROFILE_NAME, getCurrentProfile());
|
getFragmentManager().popBackStack();
|
||||||
startActivity(intent);
|
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) {
|
public void onProfileSelected(String profile) {
|
||||||
setIsEditing(false);
|
setIsEditing(false);
|
||||||
if (isSplitLayout) {
|
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) {
|
public void updateLayout(String profile) {
|
||||||
final Fragment fragment = getFragmentManager().findFragmentById(R.id.fragment_container);
|
final Fragment fragment = getFragmentManager().findFragmentById(R.id.fragment_container);
|
||||||
if (isEditing() && profile == null)
|
if (isEditing() && profile == null)
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
<item
|
<item
|
||||||
|
android:id="@+id/menu_settings"
|
||||||
android:alphabeticShortcut="s"
|
android:alphabeticShortcut="s"
|
||||||
android:icon="@drawable/ic_settings"
|
android:icon="@drawable/ic_settings"
|
||||||
android:onClick="onMenuSettings"
|
|
||||||
android:showAsAction="never"
|
android:showAsAction="never"
|
||||||
android:title="@string/settings"/>
|
android:title="@string/settings" />
|
||||||
</menu>
|
</menu>
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
<item
|
<item
|
||||||
|
android:id="@+id/menu_action_edit"
|
||||||
android:alphabeticShortcut="e"
|
android:alphabeticShortcut="e"
|
||||||
android:icon="@drawable/ic_action_edit"
|
android:icon="@drawable/ic_action_edit"
|
||||||
android:onClick="onMenuEdit"
|
|
||||||
android:showAsAction="always"
|
android:showAsAction="always"
|
||||||
android:title="@string/edit" />
|
android:title="@string/edit" />
|
||||||
</menu>
|
</menu>
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
<item
|
<item
|
||||||
|
android:id="@+id/menu_action_save"
|
||||||
android:alphabeticShortcut="s"
|
android:alphabeticShortcut="s"
|
||||||
android:icon="@drawable/ic_action_save"
|
android:icon="@drawable/ic_action_save"
|
||||||
android:onClick="onMenuSave"
|
|
||||||
android:showAsAction="always"
|
android:showAsAction="always"
|
||||||
android:title="@string/save" />
|
android:title="@string/save" />
|
||||||
</menu>
|
</menu>
|
Loading…
Reference in New Issue
Block a user