refactored newconversationactivty to use array adapter
This commit is contained in:
parent
52da0fe7c9
commit
efba73ffd0
|
@ -38,56 +38,50 @@ public final class R {
|
||||||
public static final int section_header=0x7f02000a;
|
public static final int section_header=0x7f02000a;
|
||||||
}
|
}
|
||||||
public static final class id {
|
public static final class id {
|
||||||
public static final int account_confirm_password_desc=0x7f0a0017;
|
public static final int account_confirm_password_desc=0x7f0a0011;
|
||||||
public static final int account_jid=0x7f0a0000;
|
public static final int account_jid=0x7f0a0000;
|
||||||
public static final int account_list=0x7f0a0027;
|
public static final int account_list=0x7f0a0021;
|
||||||
public static final int account_password=0x7f0a0015;
|
public static final int account_password=0x7f0a000f;
|
||||||
public static final int account_password_confirm2=0x7f0a0018;
|
public static final int account_password_confirm2=0x7f0a0012;
|
||||||
public static final int account_server=0x7f0a001d;
|
public static final int account_server=0x7f0a0017;
|
||||||
public static final int account_show_advanced=0x7f0a0019;
|
public static final int account_show_advanced=0x7f0a0013;
|
||||||
public static final int account_status=0x7f0a0002;
|
public static final int account_status=0x7f0a0002;
|
||||||
public static final int account_username=0x7f0a0013;
|
public static final int account_username=0x7f0a000d;
|
||||||
public static final int action_accounts=0x7f0a002f;
|
public static final int action_accounts=0x7f0a0029;
|
||||||
public static final int action_add=0x7f0a002b;
|
public static final int action_add=0x7f0a0025;
|
||||||
public static final int action_add_account=0x7f0a0031;
|
public static final int action_add_account=0x7f0a002b;
|
||||||
public static final int action_archive=0x7f0a002e;
|
public static final int action_archive=0x7f0a0028;
|
||||||
public static final int action_details=0x7f0a002d;
|
public static final int action_details=0x7f0a0027;
|
||||||
public static final int action_security=0x7f0a002c;
|
public static final int action_security=0x7f0a0026;
|
||||||
public static final int action_settings=0x7f0a0030;
|
public static final int action_settings=0x7f0a002a;
|
||||||
public static final int advanced_options=0x7f0a001a;
|
public static final int advanced_options=0x7f0a0014;
|
||||||
public static final int contact_display_name=0x7f0a000c;
|
public static final int contactList=0x7f0a0005;
|
||||||
public static final int contact_divider=0x7f0a000e;
|
public static final int contact_display_name=0x7f0a0007;
|
||||||
public static final int contact_jid=0x7f0a000d;
|
public static final int contact_jid=0x7f0a0008;
|
||||||
public static final int contact_photo=0x7f0a000b;
|
public static final int contact_photo=0x7f0a0006;
|
||||||
public static final int conversation_image=0x7f0a000f;
|
public static final int contacts_header=0x7f0a0004;
|
||||||
public static final int conversation_lastmsg=0x7f0a0011;
|
public static final int conversation_image=0x7f0a0009;
|
||||||
public static final int conversation_lastupdate=0x7f0a0012;
|
public static final int conversation_lastmsg=0x7f0a000b;
|
||||||
public static final int conversation_name=0x7f0a0010;
|
public static final int conversation_lastupdate=0x7f0a000c;
|
||||||
public static final int create_new_contact=0x7f0a000a;
|
public static final int conversation_name=0x7f0a000a;
|
||||||
public static final int editText3=0x7f0a001f;
|
public static final int editText3=0x7f0a0019;
|
||||||
public static final int edit_account_register_new=0x7f0a0016;
|
public static final int edit_account_register_new=0x7f0a0010;
|
||||||
public static final int jabber_contacts=0x7f0a0008;
|
public static final int list=0x7f0a001f;
|
||||||
public static final int jabber_contacts_header=0x7f0a0007;
|
public static final int message_body=0x7f0a0023;
|
||||||
public static final int list=0x7f0a0025;
|
public static final int message_photo=0x7f0a0022;
|
||||||
public static final int message_body=0x7f0a0029;
|
public static final int message_time=0x7f0a0024;
|
||||||
public static final int message_photo=0x7f0a0028;
|
public static final int messages_view=0x7f0a001d;
|
||||||
public static final int message_time=0x7f0a002a;
|
|
||||||
public static final int messages_view=0x7f0a0023;
|
|
||||||
public static final int new_contact_header=0x7f0a0009;
|
|
||||||
public static final int new_conversation_search=0x7f0a0003;
|
public static final int new_conversation_search=0x7f0a0003;
|
||||||
public static final int phone_contacts=0x7f0a0006;
|
public static final int selected_conversation=0x7f0a0020;
|
||||||
public static final int phone_contacts_header=0x7f0a0005;
|
public static final int server_input_layout=0x7f0a0015;
|
||||||
public static final int scrollView1=0x7f0a0004;
|
public static final int slidingpanelayout=0x7f0a001e;
|
||||||
public static final int selected_conversation=0x7f0a0026;
|
public static final int textSendButton=0x7f0a001c;
|
||||||
public static final int server_input_layout=0x7f0a001b;
|
public static final int textView1=0x7f0a000e;
|
||||||
public static final int slidingpanelayout=0x7f0a0024;
|
|
||||||
public static final int textSendButton=0x7f0a0022;
|
|
||||||
public static final int textView1=0x7f0a0014;
|
|
||||||
public static final int textView2=0x7f0a0001;
|
public static final int textView2=0x7f0a0001;
|
||||||
public static final int textView3=0x7f0a001c;
|
public static final int textView3=0x7f0a0016;
|
||||||
public static final int textView4=0x7f0a001e;
|
public static final int textView4=0x7f0a0018;
|
||||||
public static final int textinput=0x7f0a0021;
|
public static final int textinput=0x7f0a001b;
|
||||||
public static final int textsend=0x7f0a0020;
|
public static final int textsend=0x7f0a001a;
|
||||||
}
|
}
|
||||||
public static final class layout {
|
public static final class layout {
|
||||||
public static final int account_row=0x7f030000;
|
public static final int account_row=0x7f030000;
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:background="#f9f9f9">
|
android:background="#e5e5e5" >
|
||||||
|
|
||||||
<EditText
|
<EditText
|
||||||
android:id="@+id/new_conversation_search"
|
android:id="@+id/new_conversation_search"
|
||||||
|
@ -11,72 +11,36 @@
|
||||||
android:layout_alignParentLeft="true"
|
android:layout_alignParentLeft="true"
|
||||||
android:layout_alignParentRight="true"
|
android:layout_alignParentRight="true"
|
||||||
android:layout_alignParentTop="true"
|
android:layout_alignParentTop="true"
|
||||||
|
android:background="#eee"
|
||||||
android:ems="10"
|
android:ems="10"
|
||||||
android:inputType="textEmailAddress"
|
|
||||||
android:hint="Search or enter Jabber ID"
|
android:hint="Search or enter Jabber ID"
|
||||||
android:background="#ffffff"
|
android:inputType="textEmailAddress"
|
||||||
android:layout_marginTop="12dp"
|
android:paddingBottom="12dp"
|
||||||
android:layout_marginBottom="12dp"
|
android:paddingLeft="8dp"
|
||||||
android:layout_marginLeft="8dp"
|
android:paddingRight="8dp"
|
||||||
android:layout_marginRight="8dp"/>
|
android:paddingTop="12dp" />
|
||||||
|
|
||||||
<ScrollView
|
<TextView
|
||||||
android:id="@+id/scrollView1"
|
android:id="@+id/contacts_header"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="Contacts"
|
||||||
|
style="@style/sectionHeader"
|
||||||
|
android:layout_below="@+id/new_conversation_search"
|
||||||
|
android:paddingLeft="8dp"
|
||||||
|
android:paddingTop="8dp"
|
||||||
|
android:paddingRight="8dp"/>
|
||||||
|
|
||||||
|
<ListView
|
||||||
|
android:id="@+id/contactList"
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="fill_parent"
|
android:layout_height="fill_parent"
|
||||||
android:layout_alignParentBottom="true"
|
android:layout_alignParentBottom="true"
|
||||||
android:layout_alignParentLeft="true"
|
android:layout_alignParentLeft="true"
|
||||||
android:layout_alignParentRight="true"
|
android:layout_alignParentRight="true"
|
||||||
android:layout_below="@+id/new_conversation_search"
|
android:layout_below="@+id/contacts_header"
|
||||||
android:background="#e5e5e5" >
|
tools:listitem="@layout/contact" >
|
||||||
|
|
||||||
<LinearLayout
|
</ListView>
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="380dp"
|
|
||||||
android:orientation="vertical"
|
|
||||||
android:padding="8dp" >
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/phone_contacts_header"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:text="Phone Contacts"
|
|
||||||
style="@style/sectionHeader"/>
|
|
||||||
<LinearLayout
|
|
||||||
android:id="@+id/phone_contacts"
|
|
||||||
android:layout_height="fill_parent"
|
|
||||||
android:layout_width="fill_parent"
|
|
||||||
android:orientation="vertical">
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/jabber_contacts_header"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:text="Jabber Contacts"
|
|
||||||
style="@style/sectionHeader"/>
|
|
||||||
<LinearLayout
|
|
||||||
android:id="@+id/jabber_contacts"
|
|
||||||
android:layout_height="fill_parent"
|
|
||||||
android:layout_width="fill_parent"
|
|
||||||
android:orientation="vertical">
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/new_contact_header"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:text="create new contact"
|
|
||||||
style="@style/sectionHeader"
|
|
||||||
android:visibility="gone"/>
|
|
||||||
<LinearLayout
|
|
||||||
android:id="@+id/create_new_contact"
|
|
||||||
android:layout_height="fill_parent"
|
|
||||||
android:layout_width="fill_parent"
|
|
||||||
android:orientation="vertical"
|
|
||||||
android:visibility="gone">
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
</LinearLayout>
|
|
||||||
</ScrollView>
|
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
|
@ -1,12 +1,8 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:orientation="vertical"
|
|
||||||
android:layout_width="fill_parent"
|
|
||||||
android:layout_height="wrap_content">
|
|
||||||
<RelativeLayout
|
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:paddingTop="8dp"
|
android:padding="8dp"
|
||||||
android:paddingBottom="8dp">
|
android:paddingBottom="8dp">
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
|
@ -39,6 +35,3 @@
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
<View style="@style/Divider"
|
|
||||||
android:id="@+id/contact_divider"/>
|
|
||||||
</LinearLayout>
|
|
|
@ -129,7 +129,6 @@ public class ConversationActivity extends XmppActivity {
|
||||||
});
|
});
|
||||||
spl = (SlidingPaneLayout) findViewById(id.slidingpanelayout);
|
spl = (SlidingPaneLayout) findViewById(id.slidingpanelayout);
|
||||||
spl.setParallaxDistance(150);
|
spl.setParallaxDistance(150);
|
||||||
spl.openPane();
|
|
||||||
spl.setShadowResource(R.drawable.es_slidingpane_shadow);
|
spl.setShadowResource(R.drawable.es_slidingpane_shadow);
|
||||||
spl.setSliderFadeColor(0);
|
spl.setSliderFadeColor(0);
|
||||||
spl.setPanelSlideListener(new PanelSlideListener() {
|
spl.setPanelSlideListener(new PanelSlideListener() {
|
||||||
|
@ -286,6 +285,7 @@ public class ConversationActivity extends XmppActivity {
|
||||||
startActivity(new Intent(this, NewConversationActivity.class));
|
startActivity(new Intent(this, NewConversationActivity.class));
|
||||||
finish();
|
finish();
|
||||||
} else {
|
} else {
|
||||||
|
spl.openPane();
|
||||||
//find currently loaded fragment
|
//find currently loaded fragment
|
||||||
ConversationFragment selectedFragment = (ConversationFragment) getFragmentManager().findFragmentByTag("conversation");
|
ConversationFragment selectedFragment = (ConversationFragment) getFragmentManager().findFragmentByTag("conversation");
|
||||||
if (selectedFragment!=null) {
|
if (selectedFragment!=null) {
|
||||||
|
|
|
@ -157,6 +157,9 @@ public class ConversationFragment extends Fragment {
|
||||||
// rendering complete. now go tell activity to close pane
|
// rendering complete. now go tell activity to close pane
|
||||||
if (!activity.shouldPaneBeOpen()) {
|
if (!activity.shouldPaneBeOpen()) {
|
||||||
activity.getSlidingPaneLayout().closePane();
|
activity.getSlidingPaneLayout().closePane();
|
||||||
|
activity.getActionBar().setDisplayHomeAsUpEnabled(true);
|
||||||
|
activity.getActionBar().setTitle(conversation.getName());
|
||||||
|
activity.invalidateOptionsMenu();
|
||||||
}
|
}
|
||||||
|
|
||||||
int size = this.messageList.size();
|
int size = this.messageList.size();
|
||||||
|
@ -173,6 +176,9 @@ public class ConversationFragment extends Fragment {
|
||||||
// rendering complete. now go tell activity to close pane
|
// rendering complete. now go tell activity to close pane
|
||||||
if (!activity.shouldPaneBeOpen()) {
|
if (!activity.shouldPaneBeOpen()) {
|
||||||
activity.getSlidingPaneLayout().closePane();
|
activity.getSlidingPaneLayout().closePane();
|
||||||
|
activity.getActionBar().setDisplayHomeAsUpEnabled(true);
|
||||||
|
activity.getActionBar().setTitle(conversation.getName());
|
||||||
|
activity.invalidateOptionsMenu();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,14 @@
|
||||||
package de.gultsch.chat.ui;
|
package de.gultsch.chat.ui;
|
||||||
|
|
||||||
import java.util.LinkedHashMap;
|
import java.util.ArrayList;
|
||||||
import java.util.Map.Entry;
|
import java.util.Collections;
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import de.gultsch.chat.R;
|
import de.gultsch.chat.R;
|
||||||
import de.gultsch.chat.entities.Account;
|
import de.gultsch.chat.entities.Account;
|
||||||
import de.gultsch.chat.entities.Contact;
|
import de.gultsch.chat.entities.Contact;
|
||||||
import de.gultsch.chat.entities.Conversation;
|
import de.gultsch.chat.entities.Conversation;
|
||||||
import de.gultsch.chat.persistance.DatabaseBackend;
|
|
||||||
import de.gultsch.chat.utils.Validator;
|
import de.gultsch.chat.utils.Validator;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.provider.ContactsContract;
|
import android.provider.ContactsContract;
|
||||||
|
@ -18,8 +19,12 @@ import android.view.LayoutInflater;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.View.OnClickListener;
|
import android.view.ViewGroup;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.AdapterView;
|
||||||
|
import android.widget.AdapterView.OnItemClickListener;
|
||||||
|
import android.widget.ArrayAdapter;
|
||||||
|
import android.widget.EditText;
|
||||||
|
import android.widget.ListView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
@ -31,10 +36,53 @@ import android.database.Cursor;
|
||||||
|
|
||||||
public class NewConversationActivity extends XmppActivity {
|
public class NewConversationActivity extends XmppActivity {
|
||||||
|
|
||||||
final protected LinkedHashMap<Contact, View> availablePhoneContacts = new LinkedHashMap<Contact, View>();
|
protected List<Contact> phoneContacts = new ArrayList<Contact>();
|
||||||
final protected LinkedHashMap<Contact, View> availableJabberContacts = new LinkedHashMap<Contact, View>();
|
protected List<Contact> rosterContacts = new ArrayList<Contact>();
|
||||||
protected View newContactView;
|
protected List<Contact> aggregatedContacts = new ArrayList<Contact>();
|
||||||
protected Contact newContact;
|
protected ListView contactsView;
|
||||||
|
protected ArrayAdapter<Contact> contactsAdapter;
|
||||||
|
|
||||||
|
protected EditText search;
|
||||||
|
protected String searchString = "";
|
||||||
|
private TextView contactsHeader;
|
||||||
|
|
||||||
|
protected void updateAggregatedContacts() {
|
||||||
|
|
||||||
|
aggregatedContacts.clear();
|
||||||
|
for (Contact contact : phoneContacts) {
|
||||||
|
if (contact.match(searchString))
|
||||||
|
aggregatedContacts.add(contact);
|
||||||
|
}
|
||||||
|
for (Contact contact : rosterContacts) {
|
||||||
|
if (contact.match(searchString))
|
||||||
|
aggregatedContacts.add(contact);
|
||||||
|
}
|
||||||
|
|
||||||
|
Collections.sort(aggregatedContacts, new Comparator<Contact>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int compare(Contact lhs, Contact rhs) {
|
||||||
|
return lhs.getDisplayName().compareTo(rhs.getDisplayName());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (aggregatedContacts.size() == 0) {
|
||||||
|
|
||||||
|
if (Validator.isValidJid(searchString)) {
|
||||||
|
String name = searchString.split("@")[0];
|
||||||
|
Contact newContact = new Contact(name, searchString,
|
||||||
|
DEFAULT_PROFILE_PHOTO);
|
||||||
|
aggregatedContacts.add(newContact);
|
||||||
|
contactsHeader.setText("Create new contact");
|
||||||
|
} else {
|
||||||
|
contactsHeader.setText("Contacts");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
contactsHeader.setText("Contacts");
|
||||||
|
}
|
||||||
|
|
||||||
|
contactsAdapter.notifyDataSetChanged();
|
||||||
|
}
|
||||||
|
|
||||||
static final String[] PROJECTION = new String[] {
|
static final String[] PROJECTION = new String[] {
|
||||||
ContactsContract.Data.CONTACT_ID,
|
ContactsContract.Data.CONTACT_ID,
|
||||||
|
@ -48,96 +96,26 @@ public class NewConversationActivity extends XmppActivity {
|
||||||
+ "\") AND (" + ContactsContract.CommonDataKinds.Im.PROTOCOL
|
+ "\") AND (" + ContactsContract.CommonDataKinds.Im.PROTOCOL
|
||||||
+ "=\"" + ContactsContract.CommonDataKinds.Im.PROTOCOL_JABBER
|
+ "=\"" + ContactsContract.CommonDataKinds.Im.PROTOCOL_JABBER
|
||||||
+ "\")";
|
+ "\")";
|
||||||
protected static final String DEFAULT_PROFILE_PHOTO = "android.resource://de.gultsch.chat/" + R.drawable.ic_profile;
|
protected static final String DEFAULT_PROFILE_PHOTO = "android.resource://de.gultsch.chat/"
|
||||||
|
+ R.drawable.ic_profile;
|
||||||
protected View getViewForContact(Contact contact) {
|
|
||||||
LayoutInflater inflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
|
||||||
View view = (View) inflater.inflate(R.layout.contact,null);
|
|
||||||
((TextView) view.findViewById(R.id.contact_display_name)).setText(contact.getDisplayName());
|
|
||||||
((TextView) view.findViewById(R.id.contact_jid)).setText(contact.getJid());
|
|
||||||
((ImageView) view.findViewById(R.id.contact_photo)).setImageURI(contact.getProfilePhoto());
|
|
||||||
view.setOnClickListener(new OnClickListener() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
Contact clickedContact = null;
|
|
||||||
for(Entry<Contact, View> entry : availablePhoneContacts.entrySet()) {
|
|
||||||
if (entry.getValue() == v) {
|
|
||||||
clickedContact = entry.getKey();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for(Entry<Contact, View> entry : availableJabberContacts.entrySet()) {
|
|
||||||
if (entry.getValue() == v) {
|
|
||||||
clickedContact = entry.getKey();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (newContactView==v) {
|
|
||||||
clickedContact = newContact;
|
|
||||||
}
|
|
||||||
Log.d("gultsch","clicked on "+clickedContact.getDisplayName());
|
|
||||||
|
|
||||||
|
|
||||||
Account account = new Account();
|
|
||||||
|
|
||||||
Conversation conversation = xmppConnectionService.findOrCreateConversation(account, clickedContact);
|
|
||||||
|
|
||||||
Intent viewConversationIntent = new Intent(v.getContext(),ConversationActivity.class);
|
|
||||||
viewConversationIntent.setAction(Intent.ACTION_VIEW);
|
|
||||||
viewConversationIntent.putExtra(ConversationActivity.CONVERSATION, conversation.getUuid());
|
|
||||||
viewConversationIntent.setType(ConversationActivity.VIEW_CONVERSATION);
|
|
||||||
viewConversationIntent.setFlags(viewConversationIntent.getFlags() | Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
|
||||||
startActivity(viewConversationIntent);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return view;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
if (DatabaseBackend.getInstance(this).getConversationCount() < 1) {
|
|
||||||
getActionBar().setDisplayHomeAsUpEnabled(false);
|
|
||||||
getActionBar().setHomeButtonEnabled(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
setContentView(R.layout.activity_new_conversation);
|
setContentView(R.layout.activity_new_conversation);
|
||||||
CursorLoader mCursorLoader = new CursorLoader(this,
|
|
||||||
ContactsContract.Data.CONTENT_URI, PROJECTION, SELECTION, null,
|
contactsHeader = (TextView) findViewById(R.id.contacts_header);
|
||||||
null);
|
|
||||||
mCursorLoader.registerListener(0, new OnLoadCompleteListener<Cursor>() {
|
search = (EditText) findViewById(R.id.new_conversation_search);
|
||||||
|
search.addTextChangedListener(new TextWatcher() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLoadComplete(Loader<Cursor> arg0, Cursor cursor) {
|
public void onTextChanged(CharSequence s, int start, int before,
|
||||||
while (cursor.moveToNext()) {
|
int count) {
|
||||||
String profilePhoto = cursor.getString(cursor.getColumnIndex(ContactsContract.Data.PHOTO_THUMBNAIL_URI));
|
searchString = search.getText().toString();
|
||||||
if (profilePhoto == null) {
|
updateAggregatedContacts();
|
||||||
profilePhoto = DEFAULT_PROFILE_PHOTO;
|
|
||||||
}
|
|
||||||
Contact contact = new Contact(
|
|
||||||
cursor.getString(cursor
|
|
||||||
.getColumnIndex(ContactsContract.Data.DISPLAY_NAME)),
|
|
||||||
cursor.getString(cursor
|
|
||||||
.getColumnIndex(ContactsContract.CommonDataKinds.Im.DATA)),
|
|
||||||
profilePhoto
|
|
||||||
);
|
|
||||||
View contactView = getViewForContact(contact);
|
|
||||||
availablePhoneContacts.put(contact, getViewForContact(contact));
|
|
||||||
((LinearLayout) findViewById(R.id.phone_contacts)).addView(contactView);
|
|
||||||
}
|
|
||||||
updateAvailableContacts();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
mCursorLoader.startLoading();
|
|
||||||
|
|
||||||
((TextView) findViewById(R.id.new_conversation_search)).addTextChangedListener(new TextWatcher() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
|
||||||
updateAvailableContacts();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -154,65 +132,91 @@ public class NewConversationActivity extends XmppActivity {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
contactsView = (ListView) findViewById(R.id.contactList);
|
||||||
|
contactsAdapter = new ArrayAdapter<Contact>(getApplicationContext(),
|
||||||
|
R.layout.contact, aggregatedContacts) {
|
||||||
|
@Override
|
||||||
|
public View getView(int position, View view, ViewGroup parent) {
|
||||||
|
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||||
|
if (view == null) {
|
||||||
|
view = (View) inflater.inflate(R.layout.contact, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void updateAvailableContacts() {
|
((TextView) view.findViewById(R.id.contact_display_name))
|
||||||
String search = ((TextView) findViewById(R.id.new_conversation_search)).getText().toString();
|
.setText(getItem(position).getDisplayName());
|
||||||
|
((TextView) view.findViewById(R.id.contact_jid))
|
||||||
|
.setText(getItem(position).getJid());
|
||||||
|
((ImageView) view.findViewById(R.id.contact_photo))
|
||||||
|
.setImageURI(getItem(position).getProfilePhoto());
|
||||||
|
return view;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
contactsView.setAdapter(contactsAdapter);
|
||||||
|
contactsView.setOnItemClickListener(new OnItemClickListener() {
|
||||||
|
|
||||||
LinearLayout phoneContacts = (LinearLayout) findViewById(R.id.phone_contacts);
|
@Override
|
||||||
filterAvailableContacts(phoneContacts,this.availablePhoneContacts,search);
|
public void onItemClick(AdapterView<?> arg0, View view, int pos,
|
||||||
|
long arg3) {
|
||||||
|
Contact clickedContact = aggregatedContacts.get(pos);
|
||||||
|
Log.d("gultsch",
|
||||||
|
"clicked on " + clickedContact.getDisplayName());
|
||||||
|
|
||||||
if (phoneContacts.getChildCount() == 0) {
|
Account account = new Account();
|
||||||
findViewById(R.id.phone_contacts_header).setVisibility(View.GONE);
|
|
||||||
} else {
|
Conversation conversation = xmppConnectionService
|
||||||
findViewById(R.id.phone_contacts_header).setVisibility(View.VISIBLE);
|
.findOrCreateConversation(account, clickedContact);
|
||||||
|
|
||||||
|
Intent viewConversationIntent = new Intent(view.getContext(),
|
||||||
|
ConversationActivity.class);
|
||||||
|
viewConversationIntent.setAction(Intent.ACTION_VIEW);
|
||||||
|
viewConversationIntent.putExtra(
|
||||||
|
ConversationActivity.CONVERSATION,
|
||||||
|
conversation.getUuid());
|
||||||
|
viewConversationIntent
|
||||||
|
.setType(ConversationActivity.VIEW_CONVERSATION);
|
||||||
|
viewConversationIntent.setFlags(viewConversationIntent
|
||||||
|
.getFlags() | Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||||
|
startActivity(viewConversationIntent);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
LinearLayout jabberContacts = (LinearLayout) findViewById(R.id.jabber_contacts);
|
@Override
|
||||||
filterAvailableContacts(jabberContacts,this.availableJabberContacts,search);
|
public void onStart() {
|
||||||
if (jabberContacts.getChildCount() == 0) {
|
super.onStart();
|
||||||
findViewById(R.id.jabber_contacts_header).setVisibility(View.GONE);
|
|
||||||
} else {
|
|
||||||
findViewById(R.id.jabber_contacts_header).setVisibility(View.VISIBLE);
|
|
||||||
}
|
|
||||||
|
|
||||||
LinearLayout createNewContact = (LinearLayout) findViewById(R.id.create_new_contact);
|
CursorLoader mCursorLoader = new CursorLoader(this,
|
||||||
if (Validator.isValidJid(search)) {
|
ContactsContract.Data.CONTENT_URI, PROJECTION, SELECTION, null,
|
||||||
createNewContact.removeAllViews();
|
null);
|
||||||
String name = search.split("@")[0];
|
mCursorLoader.registerListener(0, new OnLoadCompleteListener<Cursor>() {
|
||||||
newContact = new Contact(name,search,DEFAULT_PROFILE_PHOTO);
|
|
||||||
newContactView = getViewForContact(newContact);
|
|
||||||
newContactView.findViewById(R.id.contact_divider).setVisibility(View.GONE);
|
|
||||||
createNewContact.addView(newContactView);
|
|
||||||
createNewContact.setVisibility(View.VISIBLE);
|
|
||||||
((TextView) findViewById(R.id.new_contact_header)).setVisibility(View.VISIBLE);
|
|
||||||
} else {
|
|
||||||
createNewContact.setVisibility(View.GONE);
|
|
||||||
((TextView) findViewById(R.id.new_contact_header)).setVisibility(View.GONE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void filterAvailableContacts(
|
@Override
|
||||||
LinearLayout layout, LinkedHashMap<Contact, View> contacts, String search) {
|
public void onLoadComplete(Loader<Cursor> arg0, Cursor cursor) {
|
||||||
layout.removeAllViews();
|
phoneContacts.clear();
|
||||||
for(Entry<Contact, View> entry : contacts.entrySet()) {
|
while (cursor.moveToNext()) {
|
||||||
|
String profilePhoto = cursor.getString(cursor
|
||||||
|
.getColumnIndex(ContactsContract.Data.PHOTO_THUMBNAIL_URI));
|
||||||
|
if (profilePhoto == null) {
|
||||||
|
profilePhoto = DEFAULT_PROFILE_PHOTO;
|
||||||
|
}
|
||||||
|
Contact contact = new Contact(
|
||||||
|
cursor.getString(cursor
|
||||||
|
.getColumnIndex(ContactsContract.Data.DISPLAY_NAME)),
|
||||||
|
cursor.getString(cursor
|
||||||
|
.getColumnIndex(ContactsContract.CommonDataKinds.Im.DATA)),
|
||||||
|
profilePhoto);
|
||||||
|
phoneContacts.add(contact);
|
||||||
|
}
|
||||||
|
updateAggregatedContacts();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
mCursorLoader.startLoading();
|
||||||
|
|
||||||
if (entry.getKey().match(search)) {
|
|
||||||
entry.getValue().setVisibility(View.VISIBLE);
|
|
||||||
entry.getValue().findViewById(R.id.contact_divider).setVisibility(View.VISIBLE);
|
|
||||||
layout.addView(entry.getValue());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
int contactsCount = layout.getChildCount();
|
|
||||||
if (contactsCount>=1) {
|
|
||||||
View lastContact = layout.getChildAt(contactsCount - 1);
|
|
||||||
lastContact.findViewById(R.id.contact_divider).setVisibility(View.GONE);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
void onBackendConnected() {
|
void onBackendConnected() {
|
||||||
if (xmppConnectionService.getConversationCount()==0) {
|
if (xmppConnectionService.getConversationCount() == 0) {
|
||||||
getActionBar().setDisplayHomeAsUpEnabled(false);
|
getActionBar().setDisplayHomeAsUpEnabled(false);
|
||||||
getActionBar().setHomeButtonEnabled(false);
|
getActionBar().setHomeButtonEnabled(false);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue