Commit 7dca2c1a authored by Grigory Fedorov's avatar Grigory Fedorov

BaseListEditor, AccountList and PhraseList: xml resources used to create options menu.

parent 4b73b403
...@@ -44,8 +44,7 @@ public abstract class BaseListEditor<T> extends ManagedListActivity implements ...@@ -44,8 +44,7 @@ public abstract class BaseListEditor<T> extends ManagedListActivity implements
private static final String SAVED_ACTION_WITH = "com.xabber.android.ui.BaseListActivity.SAVED_ACTION_WITH"; private static final String SAVED_ACTION_WITH = "com.xabber.android.ui.BaseListActivity.SAVED_ACTION_WITH";
private static final int OPTION_MENU_ADD_ID = Menu.FIRST; private static final int CONTEXT_MENU_DELETE_ID = 0x10;
private static final int CONTEXT_MENU_DELETE_ID = 0x10;
private static final int DIALOG_DELETE_ID = 0x100; private static final int DIALOG_DELETE_ID = 0x100;
private T actionWith; private T actionWith;
...@@ -83,7 +82,9 @@ public abstract class BaseListEditor<T> extends ManagedListActivity implements ...@@ -83,7 +82,9 @@ public abstract class BaseListEditor<T> extends ManagedListActivity implements
protected abstract void putSavedValue(Bundle bundle, String key, protected abstract void putSavedValue(Bundle bundle, String key,
T actionWith); T actionWith);
protected abstract int getAddTextResourceId(); protected abstract int getOptionsMenuId();
protected abstract int getAddActionId();
protected abstract Intent getAddIntent(); protected abstract Intent getAddIntent();
...@@ -114,17 +115,15 @@ public abstract class BaseListEditor<T> extends ManagedListActivity implements ...@@ -114,17 +115,15 @@ public abstract class BaseListEditor<T> extends ManagedListActivity implements
putSavedValue(outState, SAVED_ACTION_WITH, actionWith); putSavedValue(outState, SAVED_ACTION_WITH, actionWith);
} }
@Override @Override
public boolean onCreateOptionsMenu(Menu menu) { public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu); super.onCreateOptionsMenu(menu);
menu.add(0, OPTION_MENU_ADD_ID, 0, getString(getAddTextResourceId())) getMenuInflater().inflate(getOptionsMenuId(), menu);
.setIcon(R.drawable.ic_add_white_24dp) menu.findItem(getAddActionId()).setIntent(getAddIntent());
.setIntent(getAddIntent()) return true;
.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS); }
return true;
}
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @Override
public void onCreateContextMenu(ContextMenu menu, View v, public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenuInfo menuInfo) { ContextMenuInfo menuInfo) {
......
...@@ -49,11 +49,16 @@ public class AccountList extends BaseListEditor<String> implements ...@@ -49,11 +49,16 @@ public class AccountList extends BaseListEditor<String> implements
} }
@Override @Override
protected int getAddTextResourceId() { protected int getOptionsMenuId() {
return R.string.account_add; return R.menu.add_account;
} }
@Override @Override
protected int getAddActionId() {
return R.id.action_add_account;
}
@Override
protected Intent getAddIntent() { protected Intent getAddIntent() {
return AccountAdd.createIntent(this); return AccountAdd.createIntent(this);
} }
...@@ -142,7 +147,7 @@ public class AccountList extends BaseListEditor<String> implements ...@@ -142,7 +147,7 @@ public class AccountList extends BaseListEditor<String> implements
bundle.putString(key, actionWith); bundle.putString(key, actionWith);
} }
public static Intent createIntent(Context context) { public static Intent createIntent(Context context) {
return new Intent(context, AccountList.class); return new Intent(context, AccountList.class);
} }
......
...@@ -35,11 +35,16 @@ public class PhraseList extends BaseListEditor<Integer> { ...@@ -35,11 +35,16 @@ public class PhraseList extends BaseListEditor<Integer> {
} }
@Override @Override
protected int getAddTextResourceId() { protected int getOptionsMenuId() {
return R.string.phrase_add; return R.menu.add_phrase;
} }
@Override @Override
protected int getAddActionId() {
return R.id.action_add_phrase;
}
@Override
protected Intent getAddIntent() { protected Intent getAddIntent() {
return PhraseEditor.createIntent(this); return PhraseEditor.createIntent(this);
} }
...@@ -83,7 +88,7 @@ public class PhraseList extends BaseListEditor<Integer> { ...@@ -83,7 +88,7 @@ public class PhraseList extends BaseListEditor<Integer> {
bundle.putInt(key, actionWith); bundle.putInt(key, actionWith);
} }
public static Intent createIntent(Context context) { public static Intent createIntent(Context context) {
return new Intent(context, PhraseList.class); return new Intent(context, PhraseList.class);
} }
......
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:id="@+id/action_add_account"
android:title="@string/account_add"
app:showAsAction="always"
android:icon="@drawable/ic_add_white_24dp"/>
</menu>
\ No newline at end of file
<?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 android:id="@+id/action_add" xmlns:app="http://schemas.android.com/apk/res-auto">
android:title="Add" <item android:id="@+id/action_add_phrase"
android:orderInCategory="105" android:title="@string/phrase_add"
android:showAsAction="always" app:showAsAction="always"
android:icon="@drawable/ic_add_white_24dp"/> android:icon="@drawable/ic_add_white_24dp"/>
</menu> </menu>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment