From cda1c2c3a12b4c18f13771dd4b58aab6e465176b Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Fri, 7 Feb 2014 02:57:36 +0100 Subject: [PATCH] refresh contact list --- gen/de/gultsch/chat/R.java | 93 +++++++++--------- res/drawable-hdpi/ic_action_refresh.png | Bin 0 -> 678 bytes res/drawable-mdpi/ic_action_refresh.png | Bin 0 -> 507 bytes res/drawable-xhdpi/ic_action_refresh.png | Bin 0 -> 901 bytes res/drawable-xxhdpi/ic_action_refresh.png | Bin 0 -> 1274 bytes res/layout/activity_new_conversation.xml | 11 ++- res/menu/newconversation.xml | 6 ++ src/de/gultsch/chat/entities/Contact.java | 10 +- .../chat/persistance/DatabaseBackend.java | 7 +- .../chat/services/XmppConnectionService.java | 19 +++- .../gultsch/chat/ui/ConversationActivity.java | 35 ++++--- .../gultsch/chat/ui/ConversationFragment.java | 4 +- .../chat/ui/NewConversationActivity.java | 67 ++++++++++--- 13 files changed, 166 insertions(+), 86 deletions(-) create mode 100644 res/drawable-hdpi/ic_action_refresh.png create mode 100644 res/drawable-mdpi/ic_action_refresh.png create mode 100644 res/drawable-xhdpi/ic_action_refresh.png create mode 100644 res/drawable-xxhdpi/ic_action_refresh.png diff --git a/gen/de/gultsch/chat/R.java b/gen/de/gultsch/chat/R.java index 555148f92..c377ff75f 100644 --- a/gen/de/gultsch/chat/R.java +++ b/gen/de/gultsch/chat/R.java @@ -30,56 +30,59 @@ public final class R { public static final int ic_action_add=0x7f020001; public static final int ic_action_add_person=0x7f020002; public static final int ic_action_delete=0x7f020003; - public static final int ic_action_send=0x7f020004; - public static final int ic_action_send_now=0x7f020005; - public static final int ic_action_unsecure=0x7f020006; - public static final int ic_launcher=0x7f020007; - public static final int ic_profile=0x7f020008; - public static final int message_border=0x7f020009; - public static final int notification=0x7f02000a; - public static final int section_header=0x7f02000b; + public static final int ic_action_refresh=0x7f020004; + public static final int ic_action_send=0x7f020005; + public static final int ic_action_send_now=0x7f020006; + public static final int ic_action_unsecure=0x7f020007; + public static final int ic_launcher=0x7f020008; + public static final int ic_profile=0x7f020009; + public static final int message_border=0x7f02000a; + public static final int notification=0x7f02000b; + public static final int section_header=0x7f02000c; } public static final class id { - public static final int account_confirm_password_desc=0x7f0a0011; - public static final int account_delete=0x7f0a0025; - public static final int account_disable=0x7f0a0026; - public static final int account_enable=0x7f0a0027; + public static final int account_confirm_password_desc=0x7f0a0012; + public static final int account_delete=0x7f0a0026; + public static final int account_disable=0x7f0a0027; + public static final int account_enable=0x7f0a0028; public static final int account_jid=0x7f0a0000; - public static final int account_list=0x7f0a001a; - public static final int account_password=0x7f0a000e; - public static final int account_password_confirm2=0x7f0a0012; + public static final int account_list=0x7f0a001b; + public static final int account_password=0x7f0a000f; + public static final int account_password_confirm2=0x7f0a0013; public static final int account_status=0x7f0a0002; - public static final int account_usetls=0x7f0a000f; - public static final int action_accounts=0x7f0a0022; - public static final int action_add=0x7f0a001e; - public static final int action_add_account=0x7f0a0024; - public static final int action_archive=0x7f0a0021; - public static final int action_details=0x7f0a0020; - public static final int action_security=0x7f0a001f; - public static final int action_settings=0x7f0a0023; - public static final int contactList=0x7f0a0005; - public static final int contact_display_name=0x7f0a0007; - public static final int contact_jid=0x7f0a0008; - public static final int contact_photo=0x7f0a0006; - public static final int contacts_header=0x7f0a0004; - public static final int conversation_image=0x7f0a0009; - public static final int conversation_lastmsg=0x7f0a000b; - public static final int conversation_lastupdate=0x7f0a000c; - public static final int conversation_name=0x7f0a000a; - public static final int edit_account_register_new=0x7f0a0010; - public static final int list=0x7f0a0018; - public static final int message_body=0x7f0a001c; - public static final int message_photo=0x7f0a001b; - public static final int message_time=0x7f0a001d; - public static final int messages_view=0x7f0a0016; - public static final int new_conversation_search=0x7f0a0003; - public static final int selected_conversation=0x7f0a0019; - public static final int slidingpanelayout=0x7f0a0017; - public static final int textSendButton=0x7f0a0015; - public static final int textView1=0x7f0a000d; + public static final int account_usetls=0x7f0a0010; + public static final int action_accounts=0x7f0a0023; + public static final int action_add=0x7f0a001f; + public static final int action_add_account=0x7f0a0025; + public static final int action_archive=0x7f0a0022; + public static final int action_details=0x7f0a0021; + public static final int action_refresh_contacts=0x7f0a0029; + public static final int action_security=0x7f0a0020; + public static final int action_settings=0x7f0a0024; + public static final int contactList=0x7f0a0006; + public static final int contact_display_name=0x7f0a0008; + public static final int contact_jid=0x7f0a0009; + public static final int contact_photo=0x7f0a0007; + public static final int contacts_header=0x7f0a0005; + public static final int conversation_image=0x7f0a000a; + public static final int conversation_lastmsg=0x7f0a000c; + public static final int conversation_lastupdate=0x7f0a000d; + public static final int conversation_name=0x7f0a000b; + public static final int edit_account_register_new=0x7f0a0011; + public static final int list=0x7f0a0019; + public static final int message_body=0x7f0a001d; + public static final int message_photo=0x7f0a001c; + public static final int message_time=0x7f0a001e; + public static final int messages_view=0x7f0a0017; + public static final int new_conversation_search=0x7f0a0004; + public static final int progressBar1=0x7f0a0003; + public static final int selected_conversation=0x7f0a001a; + public static final int slidingpanelayout=0x7f0a0018; + public static final int textSendButton=0x7f0a0016; + public static final int textView1=0x7f0a000e; public static final int textView2=0x7f0a0001; - public static final int textinput=0x7f0a0014; - public static final int textsend=0x7f0a0013; + public static final int textinput=0x7f0a0015; + public static final int textsend=0x7f0a0014; } public static final class layout { public static final int account_row=0x7f030000; diff --git a/res/drawable-hdpi/ic_action_refresh.png b/res/drawable-hdpi/ic_action_refresh.png new file mode 100644 index 0000000000000000000000000000000000000000..45b22282fc9a8955714ccc581926615b21ab9f8a GIT binary patch literal 678 zcmV;X0$KfuP)PBh z(#*x-0~LT~5_ps`Xg351_yTk;?Y2&)sIWeU@nE>t4gq+%fMH2H)>c9Vcs!BZDFFa~ zPvB2UNm>UY$Tva;DR(EJ0iS`UVB1B*dNiMvt)MZo1RkAo%ZwgV&HafJ0u(J`#VrJ$ zGM}-eNOcwyiWLt}Fcew@@5Y44ZiRF?H2@#iz?YghpPLXEFafM30wsXoc#+Hj__1R5 z6Q8nCIck)ueCCn~2t~;Bsvd}ZCm`oK-yPNnf^sfqrsF{>3N z_;I_f&Hus(X5yeO!{{IIiWI!yBx2{xTgE{z-E}2;0zH9iCh#M`04g=hy&bZ$h5!Hn M07*qoM6N<$g8Nk_lmGw# literal 0 HcmV?d00001 diff --git a/res/drawable-mdpi/ic_action_refresh.png b/res/drawable-mdpi/ic_action_refresh.png new file mode 100644 index 0000000000000000000000000000000000000000..de008e51a306771d6820dcd24871bb30360e1525 GIT binary patch literal 507 zcmVJNRCwC#SG`WdFc5B07qXg>tYM9m ziH_{7U7Kg18{!q<8N%9?u3g(H60BL>HEUQoqpNf}e0J?L{HZ6M>?W7{?$3AbXmq0g zOhr*BpUm07;152zaiG!!mTTY)IU%n#@D6x`>m6_k{8-m@Bk7z3fZxJ$!$2ve$i~3V zAs1!pT@B{ zmb<_k2gfVe)N*O5T=QUjKn*NdC3EB6G1Ru>R(Wb9I0Y>ON(H&b*7afyXfOgs;Tl`( x6+Tl;&H!%vw(l>OQLO0S`{&|Bf0{l77yyZQf|ZLckgWg!002ovPDHLkV1gTK=LP@( literal 0 HcmV?d00001 diff --git a/res/drawable-xhdpi/ic_action_refresh.png b/res/drawable-xhdpi/ic_action_refresh.png new file mode 100644 index 0000000000000000000000000000000000000000..cdc160d4c6210f179e79553093ebb2547f0330a5 GIT binary patch literal 901 zcmV;01A6?4P)RCwC#T0L*uFc4)8FYc<;-Dk=K$DH3;rA)DueC=? zXm8L8XnSb+cDvoT^n>sJsJ(mF_M9rl9h1gEE}$huS_XV}M&A>9AH~R^y#UFgg*;+1 zI13=+%Zi92pb+00oP01A0OWDTZ(0Uw3r@@nbeG-*pjp4InXwlbJ0c$w`AFgM zf@Z7=b|qO$Jvhc1KR@YJ046Xsfh3=+V8%SNYpfVoB`b67$P|_{y-~RCD>X5@2NE_lp6Lw}xphu;c=n z1^I<3d76;pxBw+0GiG^PTLe>Vk4!A#0_cZL9$*>+IMaX7iS&)AkMC{z*a(d@XDVW% zGiGi(A5&}H7{Dz}PrepbbOmVjeP3tal>pw7*Ak!>ssHo;vk-u?G%maI7S`FI?K{T<}=*z8~A{PJOq4@66w`lNW$0QwfuuD(_Cmjt0_1EckNy zq-M4olY`CL;cFYTmTDJU;h%=@WfrHpTuB~hKhx>Rg$oph* z$fAy&4H}&r&~lebHa!^h9(t(<(2vg)pId7Zuddi!3;6-;+O#C^LVynqS3#k63dCbF z^+X&#cKF)YOH00000NkvXXu0mjfAz_hF literal 0 HcmV?d00001 diff --git a/res/drawable-xxhdpi/ic_action_refresh.png b/res/drawable-xxhdpi/ic_action_refresh.png new file mode 100644 index 0000000000000000000000000000000000000000..cb847f3780ffe9c430bdd0e525ad2e48127b7b91 GIT binary patch literal 1274 zcmVFccPC7P6*ey@nC) zn9{LXVa*C#kF|e8t{bemZm_b3m5yZM&WvPDRFH@%(&t~i`}0))#%kwWkS60;UxvCJX9zDs zl(`>feupk3gqWHpGbuqn;b3PhfHggJ0ezuvNShzDAQl$n6RyfwQIG;);?I2gUX6`z zzjS-i?Xp1N_gVn+PP!mXJiYY9Gw~^??^AA#q1Pb!lM_2)dehJdIu z0?_0~On#&QzXD+Lzt?a%6umsBF@9cbuKO8s*m}s}=%D7K4LigzDll!In9KbfFGtfU%${)0U|EQW(&t1D3=q!k>URf$)&xW7631< zm?ED!=$5kpQ_{7RnoEHI?83B1P%R_?j($vYKF^?9&H_x@zm&*$A%Hi0G6?`QH){be zpxI9zkOxFR1#mGJR5$>4HT>j>$8^(H+ zwm-Bdq%B?Z`-3(MU@E<65r~Uw#s%#N`GeL9U`Jre_BRlKEKJ${3Ib?W0BZ<9E(tR& zHYIgtdm#WbjH`V}#N@P}*11g^&0+{Z4r7bYzybud|Eu9+i@K|Q5I{a?o26;1P3_GF z5Wsfrk1X6z;$owjk0QPIF?3X*SqG}P7~;Rw1!}heS8&`dXHU>zNKVt1SA$GaR*oO;B9FxBi()@|# zGu*oDI}`zkkYC}vqFdM27s|1fGXe6;p4>vmoW-tR%!dH#5_jX$=Vr=i$0fc-eqW@z z$AhJjqOKIa&I|hK$dV|h zSgK5EY3iOb889fR`CwMpc#!h>O$lJ5+J8FYzc^na z+G$zOV4a_ty!wgoq_KK8L>Hi2*8{Nfcz$5vB?zx00000 k000000001x#cu%y058#~Dpx%2*#H0l07*qoM6N<$f=F^#1poj5 literal 0 HcmV?d00001 diff --git a/res/layout/activity_new_conversation.xml b/res/layout/activity_new_conversation.xml index c993ce491..88e1b802f 100644 --- a/res/layout/activity_new_conversation.xml +++ b/res/layout/activity_new_conversation.xml @@ -4,6 +4,16 @@ android:layout_height="match_parent" android:background="#e5e5e5" > + + + - \ No newline at end of file diff --git a/res/menu/newconversation.xml b/res/menu/newconversation.xml index 4f9b6da05..ca6a57e10 100644 --- a/res/menu/newconversation.xml +++ b/res/menu/newconversation.xml @@ -1,5 +1,11 @@ + getContacts() { + public List getContacts(Account account) { List list = new ArrayList(); SQLiteDatabase db = this.getReadableDatabase(); - Cursor cursor = db.query(Contact.TABLENAME, null, null, null, null, + String args[] = {account.getUuid()}; + Cursor cursor = db.query(Contact.TABLENAME, null, Contact.ACCOUNT+"=?", args, null, null, null); while (cursor.moveToNext()) { list.add(Contact.fromCursor(cursor)); diff --git a/src/de/gultsch/chat/services/XmppConnectionService.java b/src/de/gultsch/chat/services/XmppConnectionService.java index c5477ae08..457c06b67 100644 --- a/src/de/gultsch/chat/services/XmppConnectionService.java +++ b/src/de/gultsch/chat/services/XmppConnectionService.java @@ -18,6 +18,7 @@ import de.gultsch.chat.xmpp.IqPacket; import de.gultsch.chat.xmpp.MessagePacket; import de.gultsch.chat.xmpp.OnIqPacketReceived; import de.gultsch.chat.xmpp.OnMessagePacketReceived; +import de.gultsch.chat.xmpp.OnPresencePacketReceived; import de.gultsch.chat.xmpp.OnStatusChanged; import de.gultsch.chat.xmpp.PresencePacket; import de.gultsch.chat.xmpp.XmppConnection; @@ -123,6 +124,18 @@ public class XmppConnectionService extends Service { } } }; + + private OnPresencePacketReceived presenceListener = new OnPresencePacketReceived() { + + @Override + public void onPresencePacketReceived(Account account, PresencePacket packet) { + String jid = packet.getAttribute("from"); + String type = packet.getAttribute("type"); + if (type==null) { + Log.d(LOGTAG,"online presence from "+jid); + } + } + }; public class XmppConnectionBinder extends Binder { public XmppConnectionService getService() { @@ -157,6 +170,7 @@ public class XmppConnectionService extends Service { XmppConnection connection = new XmppConnection(account, pm); connection.setOnMessagePacketReceivedListener(this.messageListener); connection.setOnStatusChangedListener(this.statusListener); + connection.setOnPresencePacketReceivedListener(this.presenceListener); Thread thread = new Thread(connection); thread.start(); return connection; @@ -185,8 +199,8 @@ public class XmppConnectionService extends Service { databaseBackend.updateMessage(message); } - public void getRoster(final OnRosterFetchedListener listener) { - List contacts = databaseBackend.getContacts(); + public void getRoster(Account account, final OnRosterFetchedListener listener) { + List contacts = databaseBackend.getContacts(account); if (listener != null) { listener.onRosterFetched(contacts); } @@ -249,7 +263,6 @@ public class XmppConnectionService extends Service { if (roster != null) { for (Element item : roster.getChildren()) { Contact contact; - Log.d(LOGTAG, item.toString()); String name = item.getAttribute("name"); String jid = item.getAttribute("jid"); if (phoneContacts.containsKey(jid)) { diff --git a/src/de/gultsch/chat/ui/ConversationActivity.java b/src/de/gultsch/chat/ui/ConversationActivity.java index d9c497f8e..7e4cd34d5 100644 --- a/src/de/gultsch/chat/ui/ConversationActivity.java +++ b/src/de/gultsch/chat/ui/ConversationActivity.java @@ -40,7 +40,7 @@ public class ConversationActivity extends XmppActivity { protected SlidingPaneLayout spl; private List conversationList = new ArrayList(); - private int selectedConversation = 0; + private Conversation selectedConversation = null; private ListView listView; private boolean paneShouldBeOpen = true; @@ -50,7 +50,7 @@ public class ConversationActivity extends XmppActivity { @Override public void onConversationListChanged() { - final Conversation currentConv = conversationList.get(selectedConversation); + final Conversation currentConv = getSelectedConversation(); conversationList.clear(); conversationList.addAll(xmppConnectionService .getConversations()); @@ -59,14 +59,14 @@ public class ConversationActivity extends XmppActivity { @Override public void run() { updateConversationList(); - for(int i = 0; i < conversationList.size(); ++i) { - if (currentConv.equals(conversationList.get(i))) { - selectedConversation = i; + /*for(int i = 0; i < conversationList.size(); ++i) { + if (currentConv == conversationList.get(i)) { + selectedConversation = conversationList.get(i); break; } - } + }*/ if(paneShouldBeOpen) { - selectedConversation = 0; + selectedConversation = conversationList.get(0); if (conversationList.size() >= 1) { swapConversationFragment(); } else { @@ -88,7 +88,7 @@ public class ConversationActivity extends XmppActivity { return this.conversationList; } - public int getSelectedConversation() { + public Conversation getSelectedConversation() { return this.selectedConversation; } @@ -164,8 +164,8 @@ public class ConversationActivity extends XmppActivity { public void onItemClick(AdapterView arg0, View clickedView, int position, long arg3) { paneShouldBeOpen = false; - if (selectedConversation != position) { - selectedConversation = position; + if (selectedConversation != conversationList.get(position)) { + selectedConversation = conversationList.get(position); swapConversationFragment(); //.onBackendConnected(conversationList.get(position)); } else { spl.closePane(); @@ -202,7 +202,7 @@ public class ConversationActivity extends XmppActivity { paneShouldBeOpen = false; if (conversationList.size() > 0) { getActionBar().setDisplayHomeAsUpEnabled(true); - getActionBar().setTitle(conversationList.get(selectedConversation).getName()); + getActionBar().setTitle(getSelectedConversation().getName()); invalidateOptionsMenu(); } } @@ -225,6 +225,11 @@ public class ConversationActivity extends XmppActivity { ((MenuItem) menu.findItem(R.id.action_security)).setVisible(false); } else { ((MenuItem) menu.findItem(R.id.action_add)).setVisible(false); + if (this.getSelectedConversation()!=null) { + if (this.getSelectedConversation().getMode() == Conversation.MODE_MULTI) { + ((MenuItem) menu.findItem(R.id.action_security)).setVisible(false); + } + } } return true; } @@ -245,12 +250,12 @@ public class ConversationActivity extends XmppActivity { startActivity(new Intent(this, NewConversationActivity.class)); break; case R.id.action_archive: - Conversation conv = getConversationList().get(selectedConversation); + Conversation conv = getSelectedConversation(); conv.setStatus(Conversation.STATUS_ARCHIVED); paneShouldBeOpen = true; spl.openPane(); xmppConnectionService.archiveConversation(conv); - selectedConversation = 0; + selectedConversation = conversationList.get(0); break; default: break; @@ -333,7 +338,7 @@ public class ConversationActivity extends XmppActivity { for(int i = 0; i < conversationList.size(); ++i) { if (conversationList.get(i).getUuid().equals(convToView)) { - selectedConversation = i; + selectedConversation = conversationList.get(i); } } paneShouldBeOpen = false; @@ -356,7 +361,7 @@ public class ConversationActivity extends XmppActivity { selectedFragment.onBackendConnected(); } else { Log.d("gultsch","conversationactivity. no old fragment found. creating new one"); - selectedConversation = 0; + selectedConversation = conversationList.get(0); Log.d("gultsch","selected conversation is #"+selectedConversation); swapConversationFragment(); } diff --git a/src/de/gultsch/chat/ui/ConversationFragment.java b/src/de/gultsch/chat/ui/ConversationFragment.java index f2726945a..319c3a317 100644 --- a/src/de/gultsch/chat/ui/ConversationFragment.java +++ b/src/de/gultsch/chat/ui/ConversationFragment.java @@ -161,7 +161,7 @@ public class ConversationFragment extends Fragment { final ConversationActivity activity = (ConversationActivity) getActivity(); if (activity.xmppConnectionServiceBound) { - this.conversation = activity.getConversationList().get(activity.getSelectedConversation()); + this.conversation = activity.getSelectedConversation(); updateMessages(); // rendering complete. now go tell activity to close pane if (!activity.shouldPaneBeOpen()) { @@ -176,7 +176,7 @@ public class ConversationFragment extends Fragment { public void onBackendConnected() { Log.d("gultsch","calling on backend connected in conversation fragment"); final ConversationActivity activity = (ConversationActivity) getActivity(); - this.conversation = activity.getConversationList().get(activity.getSelectedConversation()); + this.conversation = activity.getSelectedConversation(); updateMessages(); // rendering complete. now go tell activity to close pane if (!activity.shouldPaneBeOpen()) { diff --git a/src/de/gultsch/chat/ui/NewConversationActivity.java b/src/de/gultsch/chat/ui/NewConversationActivity.java index cbd68def8..ec445e6c2 100644 --- a/src/de/gultsch/chat/ui/NewConversationActivity.java +++ b/src/de/gultsch/chat/ui/NewConversationActivity.java @@ -27,6 +27,7 @@ import android.widget.AdapterView.OnItemClickListener; import android.widget.ArrayAdapter; import android.widget.EditText; import android.widget.ListView; +import android.widget.ProgressBar; import android.widget.TextView; import android.widget.ImageView; import android.annotation.SuppressLint; @@ -210,21 +211,25 @@ public class NewConversationActivity extends XmppActivity { } this.accounts = xmppConnectionService.getAccounts(); this.rosterContacts.clear(); - xmppConnectionService.getRoster(new OnRosterFetchedListener() { - - @Override - public void onRosterFetched(List roster) { - rosterContacts.addAll(roster); - runOnUiThread(new Runnable() { - + for(int i = 0; i < accounts.size(); ++i) { + if (accounts.get(i).getStatus()==Account.STATUS_ONLINE) { + xmppConnectionService.getRoster(accounts.get(i),new OnRosterFetchedListener() { + @Override - public void run() { - updateAggregatedContacts(); + public void onRosterFetched(List roster) { + rosterContacts.addAll(roster); + runOnUiThread(new Runnable() { + + @Override + public void run() { + updateAggregatedContacts(); + } + }); + } }); - - } - }); + } + } } @Override @@ -243,10 +248,48 @@ public class NewConversationActivity extends XmppActivity { case R.id.action_accounts: startActivity(new Intent(this, ManageAccountActivity.class)); break; + case R.id.action_refresh_contacts: + refreshContacts(); + break; default: break; } return super.onOptionsItemSelected(item); } + private void refreshContacts() { + final ProgressBar progress = (ProgressBar) findViewById(R.id.progressBar1); + final EditText searchBar = (EditText) findViewById(R.id.new_conversation_search); + final TextView contactsHeader = (TextView) findViewById(R.id.contacts_header); + final ListView contactList = (ListView) findViewById(R.id.contactList); + searchBar.setVisibility(View.GONE); + contactsHeader.setVisibility(View.GONE); + contactList.setVisibility(View.GONE); + progress.setVisibility(View.VISIBLE); + this.accounts = xmppConnectionService.getAccounts(); + this.rosterContacts.clear(); + for (int i = 0; i < accounts.size(); ++i) { + if (accounts.get(i).getStatus()==Account.STATUS_ONLINE) { + xmppConnectionService.updateRoster(accounts.get(i), + new OnRosterFetchedListener() { + + @Override + public void onRosterFetched(final List roster) { + runOnUiThread(new Runnable() { + + @Override + public void run() { + rosterContacts.addAll(roster); + progress.setVisibility(View.GONE); + searchBar.setVisibility(View.VISIBLE); + contactList.setVisibility(View.VISIBLE); + contactList.setVisibility(View.VISIBLE); + updateAggregatedContacts(); + } + }); + } + }); + } + } + } }