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
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 T actionWith;
......@@ -83,7 +82,9 @@ public abstract class BaseListEditor<T> extends ManagedListActivity implements
protected abstract void putSavedValue(Bundle bundle, String key,
T actionWith);
protected abstract int getAddTextResourceId();
protected abstract int getOptionsMenuId();
protected abstract int getAddActionId();
protected abstract Intent getAddIntent();
......@@ -114,17 +115,15 @@ public abstract class BaseListEditor<T> extends ManagedListActivity implements
putSavedValue(outState, SAVED_ACTION_WITH, actionWith);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
menu.add(0, OPTION_MENU_ADD_ID, 0, getString(getAddTextResourceId()))
.setIcon(R.drawable.ic_add_white_24dp)
.setIntent(getAddIntent())
.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
return true;
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
getMenuInflater().inflate(getOptionsMenuId(), menu);
menu.findItem(getAddActionId()).setIntent(getAddIntent());
return true;
}
@SuppressWarnings("unchecked")
@SuppressWarnings("unchecked")
@Override
public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenuInfo menuInfo) {
......
......@@ -49,11 +49,16 @@ public class AccountList extends BaseListEditor<String> implements
}
@Override
protected int getAddTextResourceId() {
return R.string.account_add;
}
protected int getOptionsMenuId() {
return R.menu.add_account;
}
@Override
@Override
protected int getAddActionId() {
return R.id.action_add_account;
}
@Override
protected Intent getAddIntent() {
return AccountAdd.createIntent(this);
}
......@@ -142,7 +147,7 @@ public class AccountList extends BaseListEditor<String> implements
bundle.putString(key, actionWith);
}
public static Intent createIntent(Context context) {
public static Intent createIntent(Context context) {
return new Intent(context, AccountList.class);
}
......
......@@ -35,11 +35,16 @@ public class PhraseList extends BaseListEditor<Integer> {
}
@Override
protected int getAddTextResourceId() {
return R.string.phrase_add;
}
protected int getOptionsMenuId() {
return R.menu.add_phrase;
}
@Override
@Override
protected int getAddActionId() {
return R.id.action_add_phrase;
}
@Override
protected Intent getAddIntent() {
return PhraseEditor.createIntent(this);
}
......@@ -83,7 +88,7 @@ public class PhraseList extends BaseListEditor<Integer> {
bundle.putInt(key, actionWith);
}
public static Intent createIntent(Context context) {
public static Intent createIntent(Context context) {
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"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/action_add"
android:title="Add"
android:orderInCategory="105"
android:showAsAction="always"
<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_phrase"
android:title="@string/phrase_add"
app:showAsAction="always"
android:icon="@drawable/ic_add_white_24dp"/>
</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