Commit c0f6e151 authored by Grigory Fedorov's avatar Grigory Fedorov

Merge branch 'feature/options_menu' into develop

parents 155af8df 06010393
...@@ -14,15 +14,11 @@ ...@@ -14,15 +14,11 @@
*/ */
package com.xabber.android.ui; package com.xabber.android.ui;
import java.util.Collection;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.app.NavUtils;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem;
import android.view.View; import android.view.View;
import com.xabber.android.data.ActivityManager; import com.xabber.android.data.ActivityManager;
...@@ -43,6 +39,8 @@ import com.xabber.android.ui.widget.PageSwitcher; ...@@ -43,6 +39,8 @@ import com.xabber.android.ui.widget.PageSwitcher;
import com.xabber.android.ui.widget.PageSwitcher.OnSelectListener; import com.xabber.android.ui.widget.PageSwitcher.OnSelectListener;
import com.xabber.androiddev.R; import com.xabber.androiddev.R;
import java.util.Collection;
/** /**
* Chat activity. * Chat activity.
* *
...@@ -101,6 +99,7 @@ public class ChatViewer extends ManagedActivity implements OnSelectListener, ...@@ -101,6 +99,7 @@ public class ChatViewer extends ManagedActivity implements OnSelectListener,
setContentView(R.layout.chat_viewer); setContentView(R.layout.chat_viewer);
chatViewerAdapter = new ChatViewerAdapter(this, account, user); chatViewerAdapter = new ChatViewerAdapter(this, account, user);
pageSwitcher = (PageSwitcher) findViewById(R.id.switcher); pageSwitcher = (PageSwitcher) findViewById(R.id.switcher);
pageSwitcher.setAdapter(chatViewerAdapter); pageSwitcher.setAdapter(chatViewerAdapter);
pageSwitcher.setOnSelectListener(this); pageSwitcher.setOnSelectListener(this);
...@@ -395,15 +394,4 @@ public class ChatViewer extends ManagedActivity implements OnSelectListener, ...@@ -395,15 +394,4 @@ public class ChatViewer extends ManagedActivity implements OnSelectListener,
return ACTION_ATTENTION.equals(intent.getAction()); return ACTION_ATTENTION.equals(intent.getAction());
} }
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
// Respond to the action bar's Up/Home button
case android.R.id.home:
NavUtils.navigateUpFromSameTask(this);
return true;
}
return super.onOptionsItemSelected(item);
}
} }
...@@ -80,15 +80,6 @@ public class ContactList extends ManagedActivity implements OnChoosedListener, O ...@@ -80,15 +80,6 @@ public class ContactList extends ManagedActivity implements OnChoosedListener, O
private static final String SAVED_ACTION = "com.xabber.android.ui.ContactList.SAVED_ACTION"; private static final String SAVED_ACTION = "com.xabber.android.ui.ContactList.SAVED_ACTION";
private static final String SAVED_SEND_TEXT = "com.xabber.android.ui.ContactList.SAVED_SEND_TEXT"; private static final String SAVED_SEND_TEXT = "com.xabber.android.ui.ContactList.SAVED_SEND_TEXT";
private static final int OPTION_MENU_ADD_CONTACT_ID = 0x02;
private static final int OPTION_MENU_STATUS_EDITOR_ID = 0x04;
private static final int OPTION_MENU_PREFERENCE_EDITOR_ID = 0x05;
private static final int OPTION_MENU_CHAT_LIST_ID = 0x06;
private static final int OPTION_MENU_JOIN_ROOM_ID = 0x07;
private static final int OPTION_MENU_EXIT_ID = 0x08;
private static final int OPTION_MENU_SEARCH_ID = 0x0A;
private static final int OPTION_MENU_CLOSE_CHATS_ID = 0x0B;
private static final int DIALOG_CLOSE_APPLICATION_ID = 0x57; private static final int DIALOG_CLOSE_APPLICATION_ID = 0x57;
private static final String CONTACT_LIST_TAG = "CONTACT_LIST"; private static final String CONTACT_LIST_TAG = "CONTACT_LIST";
...@@ -273,48 +264,43 @@ public class ContactList extends ManagedActivity implements OnChoosedListener, O ...@@ -273,48 +264,43 @@ public class ContactList extends ManagedActivity implements OnChoosedListener, O
@Override @Override
public boolean onCreateOptionsMenu(Menu menu) { public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu); super.onCreateOptionsMenu(menu);
menu.add(0, OPTION_MENU_ADD_CONTACT_ID, 0, getMenuInflater().inflate(R.menu.contact_list, menu);
getText(R.string.contact_add)).setIcon(
R.drawable.ic_menu_invite);
menu.add(0, OPTION_MENU_CLOSE_CHATS_ID, 0,
getText(R.string.close_chats)).setIcon(
R.drawable.ic_menu_end_conversation);
menu.add(0, OPTION_MENU_PREFERENCE_EDITOR_ID, 0,
getResources().getText(R.string.preference_editor)).setIcon(
android.R.drawable.ic_menu_preferences);
menu.add(0, OPTION_MENU_STATUS_EDITOR_ID, 0,
getText(R.string.status_editor)).setIcon(
R.drawable.ic_menu_notifications);
menu.add(0, OPTION_MENU_EXIT_ID, 0, getText(R.string.exit)).setIcon(
android.R.drawable.ic_menu_close_clear_cancel);
menu.add(0, OPTION_MENU_JOIN_ROOM_ID, 0, getText(R.string.muc_add));
menu.add(0, OPTION_MENU_SEARCH_ID, 0,
getText(android.R.string.search_go));
menu.add(0, OPTION_MENU_CHAT_LIST_ID, 0, getText(R.string.chat_list))
.setIcon(R.drawable.ic_menu_friendslist);
return true; return true;
} }
@Override @Override
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
super.onOptionsItemSelected(item);
switch (item.getItemId()) { switch (item.getItemId()) {
case OPTION_MENU_ADD_CONTACT_ID: case R.id.action_search:
startActivity(ContactAdd.createIntent(this)); search();
return true; return true;
case OPTION_MENU_STATUS_EDITOR_ID: case R.id.action_change_status:
startActivity(StatusEditor.createIntent(this)); startActivity(StatusEditor.createIntent(this));
return true; return true;
case OPTION_MENU_PREFERENCE_EDITOR_ID: case R.id.action_add_contact:
startActivity(PreferenceEditor.createIntent(this)); startActivity(ContactAdd.createIntent(this));
return true; return true;
case OPTION_MENU_CHAT_LIST_ID: case R.id.action_close_chats:
startActivity(ChatList.createIntent(this)); closeAllChats();
return true; return true;
case OPTION_MENU_JOIN_ROOM_ID: case R.id.action_join_conference:
startActivity(MUCEditor.createIntent(this)); startActivity(MUCEditor.createIntent(this));
return true; return true;
case OPTION_MENU_EXIT_ID: case R.id.action_chat_list:
startActivity(ChatList.createIntent(this));
return true;
case R.id.action_settings:
startActivity(PreferenceEditor.createIntent(this));
return true;
case R.id.action_exit:
exit();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
private void exit() {
Application.getInstance().requestToClose(); Application.getInstance().requestToClose();
showDialog(DIALOG_CLOSE_APPLICATION_ID); showDialog(DIALOG_CLOSE_APPLICATION_ID);
getContactListFragment().unregisterListeners(); getContactListFragment().unregisterListeners();
...@@ -325,11 +311,9 @@ public class ContactList extends ManagedActivity implements OnChoosedListener, O ...@@ -325,11 +311,9 @@ public class ContactList extends ManagedActivity implements OnChoosedListener, O
finish(); finish();
} }
}, CLOSE_ACTIVITY_AFTER_DELAY); }, CLOSE_ACTIVITY_AFTER_DELAY);
return true; }
case OPTION_MENU_SEARCH_ID:
search(); private void closeAllChats() {
return true;
case OPTION_MENU_CLOSE_CHATS_ID:
for (AbstractChat chat : MessageManager.getInstance() for (AbstractChat chat : MessageManager.getInstance()
.getActiveChats()) { .getActiveChats()) {
MessageManager.getInstance().closeChat(chat.getAccount(), MessageManager.getInstance().closeChat(chat.getAccount(),
...@@ -338,9 +322,6 @@ public class ContactList extends ManagedActivity implements OnChoosedListener, O ...@@ -338,9 +322,6 @@ public class ContactList extends ManagedActivity implements OnChoosedListener, O
chat.getAccount(), chat.getUser()); chat.getAccount(), chat.getUser());
} }
getContactListFragment().getAdapter().onChange(); getContactListFragment().getAdapter().onChange();
return true;
}
return false;
} }
private ContactListFragment getContactListFragment() { private ContactListFragment getContactListFragment() {
......
...@@ -46,8 +46,6 @@ public abstract class GroupListActivity extends ManagedListActivity implements ...@@ -46,8 +46,6 @@ public abstract class GroupListActivity extends ManagedListActivity implements
private static final String SAVED_GROUPS = "com.xabber.android.ui.ContactList.SAVED_GROUPS"; private static final String SAVED_GROUPS = "com.xabber.android.ui.ContactList.SAVED_GROUPS";
private static final String SAVED_SELECTED = "com.xabber.android.ui.ContactList.SAVED_SELECTED"; private static final String SAVED_SELECTED = "com.xabber.android.ui.ContactList.SAVED_SELECTED";
static final int OPTION_MENU_ADD_GROUP_ID = 1;
private ArrayAdapter<String> arrayAdapter; private ArrayAdapter<String> arrayAdapter;
private ListView listView; private ListView listView;
...@@ -73,7 +71,7 @@ public abstract class GroupListActivity extends ManagedListActivity implements ...@@ -73,7 +71,7 @@ public abstract class GroupListActivity extends ManagedListActivity implements
listView = getListView(); listView = getListView();
listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
listView.setOnItemClickListener(this); listView.setOnItemClickListener(this);
arrayAdapter = new ArrayAdapter<String>(this, arrayAdapter = new ArrayAdapter<>(this,
android.R.layout.simple_list_item_multiple_choice, android.R.layout.simple_list_item_multiple_choice,
new ArrayList<String>()); new ArrayList<String>());
LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE); LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
...@@ -113,7 +111,7 @@ public abstract class GroupListActivity extends ManagedListActivity implements ...@@ -113,7 +111,7 @@ public abstract class GroupListActivity extends ManagedListActivity implements
* @return Actual groups from adapter. * @return Actual groups from adapter.
*/ */
private ArrayList<String> getGroups() { private ArrayList<String> getGroups() {
ArrayList<String> groups = new ArrayList<String>(); ArrayList<String> groups = new ArrayList<>();
for (int position = 0; position < arrayAdapter.getCount(); position++) for (int position = 0; position < arrayAdapter.getCount(); position++)
groups.add(arrayAdapter.getItem(position)); groups.add(arrayAdapter.getItem(position));
return groups; return groups;
...@@ -123,7 +121,7 @@ public abstract class GroupListActivity extends ManagedListActivity implements ...@@ -123,7 +121,7 @@ public abstract class GroupListActivity extends ManagedListActivity implements
* @return Actual selected groups from adapter. * @return Actual selected groups from adapter.
*/ */
public ArrayList<String> getSelected() { public ArrayList<String> getSelected() {
ArrayList<String> groups = new ArrayList<String>(); ArrayList<String> groups = new ArrayList<>();
for (int position = 0; position < arrayAdapter.getCount(); position++) for (int position = 0; position < arrayAdapter.getCount(); position++)
if (listView.isItemChecked(position if (listView.isItemChecked(position
+ listView.getHeaderViewsCount())) { + listView.getHeaderViewsCount())) {
...@@ -134,16 +132,14 @@ public abstract class GroupListActivity extends ManagedListActivity implements ...@@ -134,16 +132,14 @@ public abstract class GroupListActivity extends ManagedListActivity implements
@Override @Override
public boolean onCreateOptionsMenu(Menu menu) { public boolean onCreateOptionsMenu(Menu menu) {
menu.add(0, OPTION_MENU_ADD_GROUP_ID, 0, getMenuInflater().inflate(R.menu.create_new_group, menu);
getResources().getText(R.string.group_add)).setIcon(
android.R.drawable.ic_menu_add);
return true; return true;
} }
@Override @Override
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) { switch (item.getItemId()) {
case OPTION_MENU_ADD_GROUP_ID: case R.id.action_create_new_group:
showGroupAddDialog(); showGroupAddDialog();
return true; return true;
} }
...@@ -169,7 +165,7 @@ public abstract class GroupListActivity extends ManagedListActivity implements ...@@ -169,7 +165,7 @@ public abstract class GroupListActivity extends ManagedListActivity implements
* @param selected * @param selected
*/ */
void setGroups(Collection<String> groups, Collection<String> selected) { void setGroups(Collection<String> groups, Collection<String> selected) {
ArrayList<String> list = new ArrayList<String>(groups); ArrayList<String> list = new ArrayList<>(groups);
Collections.sort(list); Collections.sort(list);
arrayAdapter.clear(); arrayAdapter.clear();
for (int position = 0; position < list.size(); position++) { for (int position = 0; position < list.size(); position++) {
......
...@@ -26,7 +26,6 @@ import android.view.View; ...@@ -26,7 +26,6 @@ import android.view.View;
import android.widget.AdapterView; import android.widget.AdapterView;
import android.widget.AdapterView.AdapterContextMenuInfo; import android.widget.AdapterView.AdapterContextMenuInfo;
import android.widget.AdapterView.OnItemClickListener; import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.EditText; import android.widget.EditText;
import android.widget.ListView; import android.widget.ListView;
import android.widget.Spinner; import android.widget.Spinner;
...@@ -49,8 +48,6 @@ public class StatusEditor extends ManagedListActivity implements ...@@ -49,8 +48,6 @@ public class StatusEditor extends ManagedListActivity implements
private static final String SAVED_TEXT = "com.xabber.android.ui.StatusEditor.SAVED_TEXT"; private static final String SAVED_TEXT = "com.xabber.android.ui.StatusEditor.SAVED_TEXT";
private static final String SAVED_MODE = "com.xabber.android.ui.StatusEditor.SAVED_MODE"; private static final String SAVED_MODE = "com.xabber.android.ui.StatusEditor.SAVED_MODE";
static final public int OPTION_MENU_CLEAR_STATUSES_ID = 1;
static final public int CONTEXT_MENU_SELECT_STATUS_ID = 10; static final public int CONTEXT_MENU_SELECT_STATUS_ID = 10;
static final public int CONTEXT_MENU_EDIT_STATUS_ID = 11; static final public int CONTEXT_MENU_EDIT_STATUS_ID = 11;
static final public int CONTEXT_MENU_REMOVE_STATUS_ID = 12; static final public int CONTEXT_MENU_REMOVE_STATUS_ID = 12;
...@@ -95,7 +92,7 @@ public class StatusEditor extends ManagedListActivity implements ...@@ -95,7 +92,7 @@ public class StatusEditor extends ManagedListActivity implements
statusTextView = (EditText) header.findViewById(R.id.status_text); statusTextView = (EditText) header.findViewById(R.id.status_text);
statusModeView = (Spinner) header.findViewById(R.id.status_mode); statusModeView = (Spinner) header.findViewById(R.id.status_mode);
statusModeView.setAdapter(new StatusModeAdapter(this)); statusModeView.setAdapter(new StatusModeAdapter(this));
((Button) findViewById(R.id.ok)).setOnClickListener(this); findViewById(R.id.ok).setOnClickListener(this);
StatusMode statusMode; StatusMode statusMode;
String statusText; String statusText;
...@@ -155,9 +152,9 @@ public class StatusEditor extends ManagedListActivity implements ...@@ -155,9 +152,9 @@ public class StatusEditor extends ManagedListActivity implements
@Override @Override
public boolean onCreateOptionsMenu(Menu menu) { public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu); super.onCreateOptionsMenu(menu);
menu.add(0, OPTION_MENU_CLEAR_STATUSES_ID, 0, getMenuInflater().inflate(R.menu.delete_status_message, menu);
getResources().getText(R.string.clear_statuses)).setIcon(
android.R.drawable.ic_menu_close_clear_cancel);
return true; return true;
} }
...@@ -165,7 +162,7 @@ public class StatusEditor extends ManagedListActivity implements ...@@ -165,7 +162,7 @@ public class StatusEditor extends ManagedListActivity implements
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
super.onOptionsItemSelected(item); super.onOptionsItemSelected(item);
switch (item.getItemId()) { switch (item.getItemId()) {
case OPTION_MENU_CLEAR_STATUSES_ID: case R.id.action_delete_status_message:
AccountManager.getInstance().clearSavedStatuses(); AccountManager.getInstance().clearSavedStatuses();
adapter.onChange(); adapter.onChange();
return true; return true;
......
<?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_join_conference"
android:title="@string/muc_join"
app:showAsAction="ifRoom"
android:orderInCategory="80"
android:visible="false"
android:icon="@drawable/ic_group_white_24dp"
/>
<item android:id="@+id/action_invite_to_chat"
android:title="@string/muc_invite"
app:showAsAction="never"
android:orderInCategory="90"
android:visible="false"
/>
<item android:id="@+id/action_edit_contact"
android:title="@string/contact_editor"
app:showAsAction="ifRoom"
android:orderInCategory="100"
android:visible="false"
android:icon="@drawable/ic_create_white_24dp"
/>
<item android:id="@+id/action_chat_list"
android:title="@string/chat_list"
app:showAsAction="never"
android:orderInCategory="110"
/>
<item android:id="@+id/action_chat_settings"
android:title="@string/chat_settings"
app:showAsAction="never"
android:orderInCategory="120"
/>
<item android:id="@+id/action_show_history"
android:title="@string/show_history"
app:showAsAction="never"
android:orderInCategory="130"
/>
<item android:id="@+id/action_authorization_settings"
android:title="@string/muc_edit"
app:showAsAction="never"
android:orderInCategory="133"
android:visible="false"
/>
<item android:id="@+id/action_leave_conference"
android:title="@string/muc_leave"
app:showAsAction="never"
android:orderInCategory="136"
android:visible="false"
/>
<item android:id="@+id/action_close_chat"
android:title="@string/close_chat"
app:showAsAction="ifRoom"
android:orderInCategory="140"
android:visible="false"
android:icon="@drawable/ic_clear_white_24dp"
/>
<item android:id="@+id/action_clear_text"
android:title="@string/clear_message"
app:showAsAction="never"
android:orderInCategory="150"
/>
<item android:id="@+id/action_clear_history"
android:title="@string/clear_history"
app:showAsAction="never"
android:orderInCategory="160"
/>
<item android:id="@+id/action_export_chat"
android:title="@string/export_chat"
app:showAsAction="never"
android:orderInCategory="170"
/>
<item android:id="@+id/action_call_attention"
android:title="@string/call_attention"
app:showAsAction="never"
android:orderInCategory="180"
/>
<item android:id="@+id/action_otr_encryption"
android:title="@string/otr_encryption"
app:showAsAction="never"
android:orderInCategory="190">
<menu>
<item android:id="@+id/action_start_encryption"
android:title="@string/otr_start"
app:showAsAction="never"
android:orderInCategory="100"
android:visible="false"
/>
<item android:id="@+id/action_restart_encryption"
android:title="@string/otr_refresh"
app:showAsAction="never"
android:orderInCategory="105"
android:visible="false"
/>
<item android:id="@+id/action_stop_encryption"
android:title="@string/otr_end"
app:showAsAction="never"
android:orderInCategory="110"
/>
<item android:id="@+id/action_verify_with_fingerprint"
android:title="@string/otr_verify_fingerprint"
app:showAsAction="never"
android:orderInCategory="120"
/>
<item android:id="@+id/action_verify_with_question"
android:title="@string/otr_verify_question"
app:showAsAction="never"
android:orderInCategory="130"
/>
<item android:id="@+id/action_verify_with_shared_secret"
android:title="@string/otr_verify_secret"
app:showAsAction="never"
android:orderInCategory="140"
/>
</menu>
</item>
<item android:id="@+id/action_list_of_occupants"
android:title="@string/occupant_list"
app:showAsAction="never"
android:orderInCategory="200"
android:visible="false"
/>
</menu>
\ No newline at end of file
<?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_search"
android:title="@android:string/search_go"
app:showAsAction="always"
android:orderInCategory="100"
android:icon="@drawable/ic_search_white_24dp"
/>
<item android:id="@+id/action_add_contact"
android:title="@string/contact_add"
app:showAsAction="ifRoom"
android:icon="@drawable/ic_person_add_white_24dp"
android:orderInCategory="110"
/>
<item android:id="@+id/action_join_conference"
android:title="@string/muc_add"
app:showAsAction="ifRoom"
android:icon="@drawable/ic_group_white_24dp"
android:orderInCategory="120"
/>
<item android:id="@+id/action_change_status"
android:title="@string/status_editor"
app:showAsAction="never"
android:orderInCategory="130"
/>
<item android:id="@+id/action_chat_list"
android:title="@string/chat_list"
app:showAsAction="never"
android:orderInCategory="140"
/>
<item android:id="@+id/action_close_chats"
android:title="@string/close_chats"
app:showAsAction="never"
android:orderInCategory="150"
/>
<item android:id="@+id/action_settings"
android:title="@string/preference_editor"
app:showAsAction="never"
android:orderInCategory="160"
android:icon="@drawable/ic_settings_white_24dp"
/>
<item android:id="@+id/action_exit"
android:title="@string/exit"
app:showAsAction="never"
android:orderInCategory="200"
/>
</menu>
\ No newline at end of file
<?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_create_new_group"
android:title="@string/group_add"
app:showAsAction="ifRoom"
android:icon="@drawable/ic_group_add_white_24dp"
android:orderInCategory="100"
/>
</menu>
\ No newline at end of file
<?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_delete_status_message"
android:title="@string/clear_statuses"
app:showAsAction="ifRoom"
android:icon="@drawable/ic_delete_white_24dp"
android:orderInCategory="100"
/>
</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