Commit 33074dd2 authored by Grigory Fedorov's avatar Grigory Fedorov

ContactViewerFragment: jabber name can be edited in toolbar. RosterManager: setName method added.

parent 8c8c65d1
......@@ -348,11 +348,28 @@ public class RosterManager implements OnDisconnectListener, OnPacketListener,
return;
}
}
updateRosterContact(account, bareAddress, name, groups);
}
public void setName(String account, String bareAddress, String name) throws NetworkException {
RosterContact contact = getRosterContact(account, bareAddress);
if (contact == null)
throw new NetworkException(R.string.ENTRY_IS_NOT_FOUND);
if (contact.getRealName().equals(name)) {
return;
}
updateRosterContact(account, bareAddress, name, contact.getGroupNames());
}
private void updateRosterContact(String account, String bareAddress, String name, Collection<String> groups) throws NetworkException {
RosterPacket packet = new RosterPacket();
packet.setType(IQ.Type.SET);
RosterPacket.Item item = new RosterPacket.Item(bareAddress, name);
for (String group : groups)
for (String group : groups) {
item.addGroupName(group);
}
packet.addRosterItem(item);
ConnectionManager.getInstance().sendPacket(account, packet);
}
......
......@@ -200,9 +200,6 @@ public class ContactViewer extends ManagedActivity implements
contactTitleExpandableToolbarInflater = new ContactTitleExpandableToolbarInflater(this);
AbstractContact bestContact = RosterManager.getInstance().getBestContact(account, bareAddress);
contactTitleExpandableToolbarInflater.onCreate(bestContact);
findViewById(R.id.status_icon).setVisibility(View.GONE);
findViewById(R.id.status_text).setVisibility(View.GONE);
}
@Override
......@@ -333,4 +330,10 @@ public class ContactViewer extends ManagedActivity implements
public static Map<EmailType, Integer> getEmailTypeMap() {
return EMAIL_TYPE_MAP;
}
public View getContactTitleView() {
return findViewById(R.id.expandable_contact_title);
}
}
......@@ -7,10 +7,13 @@ import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.xabber.android.data.Application;
import com.xabber.android.data.NetworkException;
import com.xabber.android.data.extension.capability.CapabilitiesManager;
import com.xabber.android.data.extension.capability.ClientInfo;
import com.xabber.android.data.roster.PresenceManager;
......@@ -37,6 +40,10 @@ public class ContactViewerFragment extends Fragment {
private LinearLayout xmppItems;
private LinearLayout contactInfoItems;
String account;
String bareAddress;
private EditText contactNameEditText;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
......@@ -52,9 +59,29 @@ public class ContactViewerFragment extends Fragment {
xmppItems = (LinearLayout) view.findViewById(R.id.xmpp_items);
contactInfoItems = (LinearLayout) view.findViewById(R.id.contact_info_items);
View contactTitleView = ((ContactViewer) getActivity()).getContactTitleView();
contactTitleView.findViewById(R.id.status_icon).setVisibility(View.GONE);
contactTitleView.findViewById(R.id.status_text).setVisibility(View.GONE);
contactTitleView.findViewById(R.id.name).setVisibility(View.GONE);
contactNameEditText = (EditText) contactTitleView.findViewById(R.id.contact_name_edit);
contactNameEditText.setVisibility(View.VISIBLE);
return view;
}
@Override
public void onPause() {
super.onPause();
try {
String name = contactNameEditText.getText().toString();
RosterManager.getInstance().setName(account, bareAddress, name);
} catch (NetworkException e) {
Application.getInstance().onError(e);
}
}
/**
* @param source
* @param value
......@@ -70,13 +97,17 @@ public class ContactViewerFragment extends Fragment {
}
public void updateContact(String account, String bareAddress) {
this.account = account;
this.bareAddress = bareAddress;
xmppItems.removeAllViews();
addXmppItem(getString(R.string.contact_viewer_jid), bareAddress, R.drawable.ic_xmpp_24dp);
RosterContact rosterContact = RosterManager.getInstance().getRosterContact(account, bareAddress);
addXmppItem(getString(R.string.contact_viewer_name), rosterContact == null ? null : rosterContact.getRealName(), null);
if (rosterContact == null || !rosterContact.isConnected()) {
contactNameEditText.setText(rosterContact.getName());
if (!rosterContact.isConnected()) {
return;
}
......@@ -288,8 +319,8 @@ public class ContactViewerFragment extends Fragment {
}
}
private void addItem(List<View> nameList, LinearLayout contactInfoItems, String label, String value) {
View itemView = createItemView(contactInfoItems, label, value, null);
private void addItem(List<View> nameList, ViewGroup rootView, String label, String value) {
View itemView = createItemView(rootView, label, value, null);
if (itemView != null) {
nameList.add(itemView);
}
......@@ -307,7 +338,6 @@ public class ContactViewerFragment extends Fragment {
}
}
private View createItemView(ViewGroup rootView, String label, String value, Integer iconResource) {
if (value == null || value.isEmpty() ) {
return null;
......
......@@ -3,7 +3,8 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
android:descendantFocusability="beforeDescendants"
android:focusableInTouchMode="true" >
<com.github.ksoichiro.android.observablescrollview.ObservableScrollView
android:id="@+id/scroll"
......@@ -71,6 +72,20 @@
android:textSize="18sp"
android:textStyle="bold" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:textColor="@color/primary_text_default_material_dark"
android:text="Name"
android:singleLine="true"
android:ems="10"
android:id="@+id/contact_name_edit"
android:gravity="center_vertical"
android:visibility="gone"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
/>
<TextView
android:id="@+id/status_text"
android:layout_width="wrap_content"
......
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