Commit 7d17df87 authored by Grigory Fedorov's avatar Grigory Fedorov

ContactViewerFragment: separate views for xmpp data and vcard info.

parent 20fa4b61
...@@ -11,7 +11,6 @@ import android.widget.ImageView; ...@@ -11,7 +11,6 @@ import android.widget.ImageView;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
import com.xabber.android.data.LogManager;
import com.xabber.android.data.extension.capability.CapabilitiesManager; import com.xabber.android.data.extension.capability.CapabilitiesManager;
import com.xabber.android.data.extension.capability.ClientInfo; import com.xabber.android.data.extension.capability.ClientInfo;
import com.xabber.android.data.roster.PresenceManager; import com.xabber.android.data.roster.PresenceManager;
...@@ -34,6 +33,7 @@ import com.xabber.xmpp.vcard.VCardProperty; ...@@ -34,6 +33,7 @@ import com.xabber.xmpp.vcard.VCardProperty;
import java.util.List; import java.util.List;
public class ContactViewerFragment extends Fragment { public class ContactViewerFragment extends Fragment {
private LinearLayout xmppItems;
private LinearLayout contactInfoItems; private LinearLayout contactInfoItems;
@Override @Override
...@@ -48,6 +48,7 @@ public class ContactViewerFragment extends Fragment { ...@@ -48,6 +48,7 @@ public class ContactViewerFragment extends Fragment {
View view = inflater.inflate(R.layout.contact_viewer_fragment, container, false); View view = inflater.inflate(R.layout.contact_viewer_fragment, container, false);
xmppItems = (LinearLayout) view.findViewById(R.id.xmpp_items);
contactInfoItems = (LinearLayout) view.findViewById(R.id.contact_info_items); contactInfoItems = (LinearLayout) view.findViewById(R.id.contact_info_items);
return view; return view;
...@@ -68,9 +69,11 @@ public class ContactViewerFragment extends Fragment { ...@@ -68,9 +69,11 @@ public class ContactViewerFragment extends Fragment {
} }
public void updateContact(String account, String bareAddress) { public void updateContact(String account, String bareAddress) {
addContactInfoItem(R.string.contact_viewer_jid, bareAddress); xmppItems.removeAllViews();
addXmppItem(getString(R.string.contact_viewer_jid), bareAddress, null);
RosterContact rosterContact = RosterManager.getInstance().getRosterContact(account, bareAddress); RosterContact rosterContact = RosterManager.getInstance().getRosterContact(account, bareAddress);
addContactInfoItem(R.string.contact_viewer_name, rosterContact == null ? null : rosterContact.getRealName()); addXmppItem(getString(R.string.contact_viewer_name), rosterContact == null ? null : rosterContact.getRealName(), null);
if (rosterContact != null && rosterContact.isConnected()) if (rosterContact != null && rosterContact.isConnected())
for (ResourceItem resourceItem for (ResourceItem resourceItem
...@@ -109,16 +112,17 @@ public class ContactViewerFragment extends Fragment { ...@@ -109,16 +112,17 @@ public class ContactViewerFragment extends Fragment {
label = label + ", " + client; label = label + ", " + client;
} }
addContactInfoItem(label, resourceItem.getVerbose(), R.drawable.ic_xmpp_24dp); addXmppItem(label, resourceItem.getVerbose(), R.drawable.ic_xmpp_24dp);
} }
} }
public void updateVCard(VCard vCard) { public void updateVCard(VCard vCard) {
LogManager.i(this, "updateVCard.");
if (vCard == null) { if (vCard == null) {
return; return;
} }
contactInfoItems.removeAllViews();
addContactInfoItem(R.string.vcard_nick_name, vCard.getField(VCardProperty.NICKNAME)); addContactInfoItem(R.string.vcard_nick_name, vCard.getField(VCardProperty.NICKNAME));
addContactInfoItem(getString(R.string.vcard_formatted_name), vCard.getFormattedName(), R.drawable.ic_contact_info_24dp); addContactInfoItem(getString(R.string.vcard_formatted_name), vCard.getFormattedName(), R.drawable.ic_contact_info_24dp);
addContactInfoItem(R.string.vcard_prefix_name, vCard.getField(NameProperty.PREFIX)); addContactInfoItem(R.string.vcard_prefix_name, vCard.getField(NameProperty.PREFIX));
...@@ -195,15 +199,28 @@ public class ContactViewerFragment extends Fragment { ...@@ -195,15 +199,28 @@ public class ContactViewerFragment extends Fragment {
} }
private void addContactInfoItem(String label, String value, Integer iconResource) { private void addContactInfoItem(String label, String value, Integer iconResource) {
LogManager.i(this, label + ": " + value); View contactInfoItem = createItemView(contactInfoItems, label, value, iconResource);
if (contactInfoItem != null) {
contactInfoItems.addView(contactInfoItem);
}
}
private void addXmppItem(String label, String value, Integer iconResource) {
View contactInfoItem = createItemView(xmppItems, label, value, iconResource);
if (contactInfoItem != null) {
xmppItems.addView(contactInfoItem);
}
}
private View createItemView(ViewGroup rootView, String label, String value, Integer iconResource) {
if (value == null || value.isEmpty() ) { if (value == null || value.isEmpty() ) {
return; return null;
} }
final LayoutInflater inflater LayoutInflater inflater = (LayoutInflater) getActivity().getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
= (LayoutInflater) getActivity().getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
View contactInfoItem = inflater.inflate(R.layout.contact_info_item, contactInfoItems, false); View contactInfoItem = inflater.inflate(R.layout.contact_info_item, rootView, false);
((TextView)contactInfoItem.findViewById(R.id.contact_info_item_name)).setText(label); ((TextView)contactInfoItem.findViewById(R.id.contact_info_item_name)).setText(label);
((TextView)contactInfoItem.findViewById(R.id.contact_info_item_value)).setText(value); ((TextView)contactInfoItem.findViewById(R.id.contact_info_item_value)).setText(value);
...@@ -211,8 +228,7 @@ public class ContactViewerFragment extends Fragment { ...@@ -211,8 +228,7 @@ public class ContactViewerFragment extends Fragment {
if (iconResource != null) { if (iconResource != null) {
((ImageView) contactInfoItem.findViewById(R.id.contact_info_group_icon)).setImageResource(iconResource); ((ImageView) contactInfoItem.findViewById(R.id.contact_info_group_icon)).setImageResource(iconResource);
} }
return contactInfoItem;
contactInfoItems.addView(contactInfoItem);
} }
} }
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout <LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/contact_info_items"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical" android:orientation="vertical"
> >
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/xmpp_items"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
/>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/contact_info_items"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
/>
</LinearLayout> </LinearLayout>
\ 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