Commit c01a7a20 authored by Grigory Fedorov's avatar Grigory Fedorov

ContactViewer: "remove contact" option added to action menu.

parent 2af84378
...@@ -35,6 +35,7 @@ import com.xabber.android.data.roster.AbstractContact; ...@@ -35,6 +35,7 @@ import com.xabber.android.data.roster.AbstractContact;
import com.xabber.android.data.roster.OnContactChangedListener; import com.xabber.android.data.roster.OnContactChangedListener;
import com.xabber.android.data.roster.RosterContact; import com.xabber.android.data.roster.RosterContact;
import com.xabber.android.data.roster.RosterManager; import com.xabber.android.data.roster.RosterManager;
import com.xabber.android.ui.dialog.ContactDeleteDialogFragment;
import com.xabber.android.ui.helper.ContactTitleExpandableToolbarInflater; import com.xabber.android.ui.helper.ContactTitleExpandableToolbarInflater;
import com.xabber.android.ui.helper.ManagedActivity; import com.xabber.android.ui.helper.ManagedActivity;
import com.xabber.androiddev.R; import com.xabber.androiddev.R;
...@@ -224,7 +225,7 @@ public class ContactViewer extends ManagedActivity implements ...@@ -224,7 +225,7 @@ public class ContactViewer extends ManagedActivity implements
@Override @Override
public boolean onCreateOptionsMenu(Menu menu) { public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater=getMenuInflater(); MenuInflater inflater=getMenuInflater();
inflater.inflate(R.menu.edit_contact, menu); inflater.inflate(R.menu.contact_viewer, menu);
return true; return true;
} }
...@@ -232,10 +233,15 @@ public class ContactViewer extends ManagedActivity implements ...@@ -232,10 +233,15 @@ public class ContactViewer extends ManagedActivity implements
@Override @Override
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) { switch (item.getItemId()) {
case R.id.action_edit_contact: case R.id.action_edit_groups:
startActivity(ContactEditor.createIntent(this, account, bareAddress)); startActivity(ContactEditor.createIntent(this, account, bareAddress));
return true; return true;
case R.id.action_remove_contact:
ContactDeleteDialogFragment.newInstance(account, bareAddress)
.show(getFragmentManager(), "CONTACT_DELETE");
return true;
default: default:
return super.onOptionsItemSelected(item); return super.onOptionsItemSelected(item);
} }
......
...@@ -105,12 +105,13 @@ public class ContactViewerFragment extends Fragment { ...@@ -105,12 +105,13 @@ public class ContactViewerFragment extends Fragment {
addXmppItem(getString(R.string.contact_viewer_jid), bareAddress, R.drawable.ic_xmpp_24dp); addXmppItem(getString(R.string.contact_viewer_jid), bareAddress, R.drawable.ic_xmpp_24dp);
RosterContact rosterContact = RosterManager.getInstance().getRosterContact(account, bareAddress); RosterContact rosterContact = RosterManager.getInstance().getRosterContact(account, bareAddress);
contactNameEditText.setText(rosterContact.getName()); if (rosterContact == null || !rosterContact.isConnected()) {
contactNameEditText.setText(bareAddress);
if (!rosterContact.isConnected()) {
return; return;
} }
contactNameEditText.setText(rosterContact.getName());
List<View> resourcesList = new ArrayList<>(); List<View> resourcesList = new ArrayList<>();
for (ResourceItem resourceItem for (ResourceItem resourceItem
......
...@@ -7,6 +7,8 @@ import com.xabber.android.data.Application; ...@@ -7,6 +7,8 @@ import com.xabber.android.data.Application;
import com.xabber.android.data.NetworkException; import com.xabber.android.data.NetworkException;
import com.xabber.android.data.account.AccountManager; import com.xabber.android.data.account.AccountManager;
import com.xabber.android.data.roster.RosterManager; import com.xabber.android.data.roster.RosterManager;
import com.xabber.android.ui.ContactList;
import com.xabber.android.ui.ContactViewer;
import com.xabber.androiddev.R; import com.xabber.androiddev.R;
public class ContactDeleteDialogFragment extends ConfirmDialogFragment { public class ContactDeleteDialogFragment extends ConfirmDialogFragment {
...@@ -44,6 +46,10 @@ public class ContactDeleteDialogFragment extends ConfirmDialogFragment { ...@@ -44,6 +46,10 @@ public class ContactDeleteDialogFragment extends ConfirmDialogFragment {
} catch (NetworkException e) { } catch (NetworkException e) {
Application.getInstance().onError(e); Application.getInstance().onError(e);
} }
if (getActivity() instanceof ContactViewer) {
startActivity(ContactList.createIntent(getActivity()));
}
return true; return true;
} }
......
<?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"
xmlns:app="http://schemas.android.com/apk/res-auto"> xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:id="@+id/action_edit_contact" <item android:id="@+id/action_edit_groups"
android:title="@string/contact_editor" android:title="@string/edit_contact_groups"
app:showAsAction="always" app:showAsAction="never"
android:orderInCategory="100" android:orderInCategory="100"
android:icon="@drawable/ic_create_white_24dp"
/> />
<item android:id="@+id/action_remove_contact"
android:title="@string/remove_contact"
app:showAsAction="never"
android:orderInCategory="110"
/>
</menu> </menu>
\ No newline at end of file
...@@ -115,4 +115,7 @@ ...@@ -115,4 +115,7 @@
<string name="please_wait">Пожалуйста, подождите...</string> <string name="please_wait">Пожалуйста, подождите...</string>
<!-- http://dl.dropbox.com/u/1029995/com.xabber.android/contact_viewer_xmpp.png --> <!-- http://dl.dropbox.com/u/1029995/com.xabber.android/contact_viewer_xmpp.png -->
<string name="unknown">Не известно</string> <string name="unknown">Не известно</string>
<string name="edit_contact_groups">Редактировать группы</string>
<string name="remove_contact">Удалить контакт</string>
</resources> </resources>
\ No newline at end of file
...@@ -115,4 +115,9 @@ ...@@ -115,4 +115,9 @@
<string name="please_wait">Please wait...</string> <string name="please_wait">Please wait...</string>
<!-- http://dl.dropbox.com/u/1029995/com.xabber.android/contact_viewer_xmpp.png --> <!-- http://dl.dropbox.com/u/1029995/com.xabber.android/contact_viewer_xmpp.png -->
<string name="unknown">Unknown</string> <string name="unknown">Unknown</string>
<string name="edit_contact_groups">Edit groups</string>
<string name="remove_contact">Remove contact</string>
</resources> </resources>
\ 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