Fix little bug with chat notification
authorDa Risk <darisk972@gmail.com>
Mon, 21 Dec 2009 22:44:54 +0100
changeset 592 1a929f74b5e0
parent 591 ba5ce70f1024
child 593 54a7d59a3f09
Fix little bug with chat notification
default.properties
res/layout/contactlist.xml
src/com/beem/project/beem/service/BeemChatManager.java
src/com/beem/project/beem/ui/Chat.java
--- a/default.properties	Mon Dec 21 21:04:06 2009 +0100
+++ b/default.properties	Mon Dec 21 22:44:54 2009 +0100
@@ -10,5 +10,5 @@
 # Indicates whether an apk should be generated for each density.
 split.density=false
 # Project target.
-target=android-3
+target=android-5
 apk-configurations=
--- a/res/layout/contactlist.xml	Mon Dec 21 21:04:06 2009 +0100
+++ b/res/layout/contactlist.xml	Mon Dec 21 22:44:54 2009 +0100
@@ -11,8 +11,10 @@
 	<LinearLayout android:layout_width="fill_parent"
 		android:layout_height="fill_parent" android:orientation="horizontal"
 		android:padding="2px">
-		<ListView android:id="@+id/contactlist" android:layout_width="fill_parent"
-			android:layout_height="fill_parent" />
+		<ListView android:id="@+id/contactlist"
+		    android:layout_width="fill_parent" android:layout_height="fill_parent"
+		    android:transcriptMode="alwaysScroll" />
+		<!-- normal should be better -->
 	</LinearLayout>
 
 </LinearLayout>
--- a/src/com/beem/project/beem/service/BeemChatManager.java	Mon Dec 21 21:04:06 2009 +0100
+++ b/src/com/beem/project/beem/service/BeemChatManager.java	Mon Dec 21 22:44:54 2009 +0100
@@ -141,7 +141,7 @@
 		notification.flags = Notification.FLAG_AUTO_CANCEL;
 		notification.setLatestEventInfo(mService, tickerText, mService
 			.getString(R.string.BeemChatManagerNewMessage), makeChatIntent(chat));
-		mService.sendNotification(chat.hashCode(), notification);
+		mService.sendNotification(chat.getParticipant().getJID().hashCode(), notification);
 	    } catch (RemoteException e) {
 		Log.e(TAG, e.getMessage());
 	    }
@@ -154,6 +154,8 @@
 	public void processMessage(IChat chat, Message message) {
 	    try {
 		if (!chat.isOpen() && message.getBody() != null) {
+		    if (chat instanceof ChatAdapter)
+			mChats.put(chat.getParticipant().getJID(), (ChatAdapter) chat);
 		    notifyNewChat(chat);
 		}
 	    } catch (RemoteException e) {
@@ -214,6 +216,7 @@
     public IChat createChat(String jid, IMessageListener listener) {
 	String key = StringUtils.parseBareAddress(jid);
 	ChatAdapter result;
+	Log.d(TAG, "Get chat key = "+key);
 	if (mChats.containsKey(key)) {
 	    result = mChats.get(key);
 	    result.addMessageListener(listener);
@@ -231,6 +234,9 @@
      */
     @Override
     public void destroyChat(IChat chat) throws RemoteException {
+	// Can't remove it. otherwise we will lose all futur message in this chat
+	// chat.removeMessageListener(mChatListener);
+	deleteChatNotification(chat);
 	mChats.remove(chat.getParticipant().getJID());
     }
 
@@ -239,7 +245,11 @@
      */
     @Override
     public void deleteChatNotification(IChat chat) {
-	mService.deleteNotification(chat.hashCode());
+	try {
+	    mService.deleteNotification(chat.getParticipant().getJID().hashCode());
+	} catch (RemoteException e) {
+	    Log.v(TAG, "Remote exception ", e);
+	}
     }
 
     /**
--- a/src/com/beem/project/beem/ui/Chat.java	Mon Dec 21 21:04:06 2009 +0100
+++ b/src/com/beem/project/beem/ui/Chat.java	Mon Dec 21 22:44:54 2009 +0100
@@ -363,6 +363,7 @@
 	String fromName = null;
 	List<Message> chatMessages = mChat.getMessages();
 	mListMessages.clear();
+	mMessagesListAdapter.notifyDataSetChanged();
 	MessageText lastMessage = null;
 
 	for (Message m : chatMessages) {