Commit f9d4c9a2 authored by Grigory Fedorov's avatar Grigory Fedorov

ContactViewer: new "edit alias" menu item.

parent d715229a
......@@ -14,17 +14,22 @@
*/
package com.xabber.android.ui;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.text.InputType;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;
import com.xabber.android.data.Application;
import com.xabber.android.data.LogManager;
import com.xabber.android.data.NetworkException;
import com.xabber.android.data.account.OnAccountChangedListener;
import com.xabber.android.data.entity.BaseEntity;
import com.xabber.android.data.extension.vcard.OnVCardListener;
......@@ -233,6 +238,11 @@ public class ContactViewer extends ManagedActivity implements
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_edit_alias:
editAlias();
return true;
case R.id.action_edit_groups:
startActivity(ContactEditor.createIntent(this, account, bareAddress));
return true;
......@@ -247,6 +257,37 @@ public class ContactViewer extends ManagedActivity implements
}
}
private void editAlias() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(R.string.edit_alias);
final EditText input = new EditText(this);
input.setInputType(InputType.TYPE_TEXT_VARIATION_PERSON_NAME);
RosterContact rosterContact = RosterManager.getInstance().getRosterContact(account, bareAddress);
input.setText(rosterContact.getName());
builder.setView(input);
builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
try {
RosterManager.getInstance().setName(account, bareAddress, input.getText().toString());
} catch (NetworkException e) {
Application.getInstance().onError(e);
}
}
});
builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
builder.show();
}
private ContactViewerFragment getFragment() {
return (ContactViewerFragment) getFragmentManager()
.findFragmentById(R.id.scrollable_container);
......
<?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_edit_alias"
android:title="@string/edit_alias"
app:showAsAction="never"
android:orderInCategory="90"
/>
<item android:id="@+id/action_edit_groups"
android:title="@string/edit_contact_groups"
app:showAsAction="never"
......
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- http://dl.dropbox.com/u/1029995/com.xabber.android/contact_list_contact_context_menu.png -->
<string name="contact_viewer">Просмотр информации</string>
<string name="contact_viewer">Информация о контакте</string>
<!-- http://dl.dropbox.com/u/1029995/com.xabber.android/contact_viewer_xmpp.png -->
<string name="contact_viewer_for">Просмотр информации о %s</string>
<!-- http://dl.dropbox.com/u/1029995/com.xabber.android/contact_viewer_xmpp.png -->
......@@ -116,6 +116,7 @@
<!-- http://dl.dropbox.com/u/1029995/com.xabber.android/contact_viewer_xmpp.png -->
<string name="unknown">Не известно</string>
<string name="edit_alias">Редактировать псевдоним</string>
<string name="edit_contact_groups">Редактировать группы</string>
<string name="remove_contact">Удалить контакт</string>
</resources>
\ No newline at end of file
......@@ -28,4 +28,8 @@
<string name="auto">Автоматически</string>
<string name="save">Сохранить</string>
<string name="ok">Ok</string>
<string name="cancel">Отмена</string>
</resources>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- http://dl.dropbox.com/u/1029995/com.xabber.android/contact_list_contact_context_menu.png -->
<string name="contact_viewer">View information</string>
<string name="contact_viewer">Contact info</string>
<!-- http://dl.dropbox.com/u/1029995/com.xabber.android/contact_viewer_xmpp.png -->
<string name="contact_viewer_for">View information about %s</string>
<!-- http://dl.dropbox.com/u/1029995/com.xabber.android/contact_viewer_xmpp.png -->
......@@ -116,6 +116,7 @@
<!-- http://dl.dropbox.com/u/1029995/com.xabber.android/contact_viewer_xmpp.png -->
<string name="unknown">Unknown</string>
<string name="edit_alias">Edit alias</string>
<string name="edit_contact_groups">Edit groups</string>
<string name="remove_contact">Remove contact</string>
......
......@@ -28,4 +28,7 @@
<string name="auto">Automatically</string>
<string name="save">Save</string>
<string name="ok">Ok</string>
<string name="cancel">Cancel</string>
</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