From 9a77d2f070f59c4dba500711f2edd549c8323168 Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Thu, 26 Jul 2012 14:18:52 +0200 Subject: [PATCH] Improved chat view --- res/layout/avatar.xml | 4 +- res/layout/chat.xml | 6 +- res/layout/chat_bubble_alt_incoming.xml | 25 ++++++++ res/layout/chat_bubble_alt_outgoing.xml | 24 ++++++++ res/layout/chat_bubble_incoming.xml | 24 ++++++++ res/layout/chat_bubble_outgoing.xml | 24 ++++++++ res/values/custom.xml | 5 +- res/values/non_localizable_custom.xml | 1 + src/org/linphone/ChatFragment.java | 6 +- src/org/linphone/ChatStorage.java | 3 +- src/org/linphone/ui/BubbleChat.java | 76 ++++++++++++++++++------- 11 files changed, 165 insertions(+), 33 deletions(-) create mode 100644 res/layout/chat_bubble_alt_incoming.xml create mode 100644 res/layout/chat_bubble_alt_outgoing.xml create mode 100644 res/layout/chat_bubble_incoming.xml create mode 100644 res/layout/chat_bubble_outgoing.xml diff --git a/res/layout/avatar.xml b/res/layout/avatar.xml index 4c486b70b..d28185d34 100644 --- a/res/layout/avatar.xml +++ b/res/layout/avatar.xml @@ -2,7 +2,7 @@ + + + + + + + \ No newline at end of file diff --git a/res/layout/chat_bubble_alt_outgoing.xml b/res/layout/chat_bubble_alt_outgoing.xml new file mode 100644 index 000000000..8b2d3ae6a --- /dev/null +++ b/res/layout/chat_bubble_alt_outgoing.xml @@ -0,0 +1,24 @@ + + + + + + + + \ No newline at end of file diff --git a/res/layout/chat_bubble_incoming.xml b/res/layout/chat_bubble_incoming.xml new file mode 100644 index 000000000..0af3791b3 --- /dev/null +++ b/res/layout/chat_bubble_incoming.xml @@ -0,0 +1,24 @@ + + + + + + + + \ No newline at end of file diff --git a/res/layout/chat_bubble_outgoing.xml b/res/layout/chat_bubble_outgoing.xml new file mode 100644 index 000000000..4c9bd9a5d --- /dev/null +++ b/res/layout/chat_bubble_outgoing.xml @@ -0,0 +1,24 @@ + + + + + + + + \ No newline at end of file diff --git a/res/values/custom.xml b/res/values/custom.xml index a5c050b2e..77c17cd97 100644 --- a/res/values/custom.xml +++ b/res/values/custom.xml @@ -1,9 +1,8 @@ - HH:mm:ss d MMM - few seconds ago - HH:mm:ss + HH:mm d MMM + HH:mm Linphone 2 Linphone diff --git a/res/values/non_localizable_custom.xml b/res/values/non_localizable_custom.xml index 3832407ad..fc9efc42e 100644 --- a/res/values/non_localizable_custom.xml +++ b/res/values/non_localizable_custom.xml @@ -15,6 +15,7 @@ true true true + true true true diff --git a/src/org/linphone/ChatFragment.java b/src/org/linphone/ChatFragment.java index 09cb19d67..bfd28350e 100644 --- a/src/org/linphone/ChatFragment.java +++ b/src/org/linphone/ChatFragment.java @@ -154,7 +154,7 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneO @Override public void onClick(View v) { - if (chatRoom != null && message != null) { + if (chatRoom != null && message != null && message.getText().length() > 0) { String messageToSend = message.getText().toString(); message.setText(""); @@ -164,7 +164,7 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneO LinphoneActivity.instance().onMessageSent(sipUri, messageToSend); } - displayMessage(previousMessageID + 2, messageToSend, getString(R.string.now_date_format), false, messagesLayout); + displayMessage(previousMessageID + 2, messageToSend, String.valueOf(System.currentTimeMillis()), false, messagesLayout); scrollToEnd(); } } @@ -182,7 +182,7 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneO public void onMessageReceived(LinphoneAddress from, String message) { if (from.asStringUriOnly().equals(sipUri)) { int id = previousMessageID + 2; - displayMessage(id, message, getString(R.string.now_date_format), true, messagesLayout); + displayMessage(id, message, String.valueOf(System.currentTimeMillis()), true, messagesLayout); scrollToEnd(); } } diff --git a/src/org/linphone/ChatStorage.java b/src/org/linphone/ChatStorage.java index f2a85f7f3..8df0b5c23 100644 --- a/src/org/linphone/ChatStorage.java +++ b/src/org/linphone/ChatStorage.java @@ -54,13 +54,14 @@ public class ChatStorage { values.put("localContact", from); values.put("remoteContact", to); values.put("direction", OUTGOING); + values.put("read", READ); } else if (to.equals("")) { values.put("localContact", to); values.put("remoteContact", from); values.put("direction", INCOMING); + values.put("read", NOT_READ); } values.put("message", message); - values.put("read", NOT_READ); values.put("time", System.currentTimeMillis()); return (int) db.insert(TABLE_NAME, null, values); } diff --git a/src/org/linphone/ui/BubbleChat.java b/src/org/linphone/ui/BubbleChat.java index 17f59b80f..69cf44e1e 100644 --- a/src/org/linphone/ui/BubbleChat.java +++ b/src/org/linphone/ui/BubbleChat.java @@ -24,14 +24,15 @@ import java.util.Map.Entry; import org.linphone.LinphoneUtils; import org.linphone.R; -import org.linphone.core.Log; import android.content.Context; import android.graphics.Color; import android.text.Spannable; import android.text.SpannableStringBuilder; import android.text.style.ImageSpan; +import android.view.LayoutInflater; import android.view.View; +import android.widget.LinearLayout; import android.widget.RelativeLayout; import android.widget.RelativeLayout.LayoutParams; import android.widget.TextView; @@ -77,7 +78,7 @@ public class BubbleChat { public BubbleChat(Context context, int id, String message, String time, boolean isIncoming, int previousID) { view = new RelativeLayout(context); - LayoutParams layoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); + LayoutParams layoutParams = new LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); if (isIncoming) { layoutParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT); @@ -92,30 +93,63 @@ public class BubbleChat { layoutParams.addRule(RelativeLayout.BELOW, previousID); } - TextView messageView = new TextView(context); - messageView.setId(id); - messageView.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); - if (context.getResources().getBoolean(R.bool.emoticons_in_messages)) { - messageView.setText(getSmiledText(context, message)); - } else { - messageView.setText(message); - } - messageView.setTextColor(Color.BLACK); - view.setId(id); layoutParams.setMargins(0, LinphoneUtils.pixelsToDpi(context.getResources(), 10), 0, 0); view.setLayoutParams(layoutParams); - view.addView(messageView); if (context.getResources().getBoolean(R.bool.display_messages_time)) { - TextView timeView = new TextView(context); - LayoutParams timeParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); - timeParams.addRule(RelativeLayout.BELOW, id); - timeView.setLayoutParams(timeParams); - timeView.setText(timestampToHumanDate(context, time)); - timeView.setTextColor(Color.GRAY); - timeView.setTextSize(12); - view.addView(timeView); + if (context.getResources().getBoolean(R.bool.display_time_aside)) { + LinearLayout layout; + if (isIncoming) { + layout = (LinearLayout) LayoutInflater.from(context).inflate(R.layout.chat_bubble_alt_incoming, null); + } else { + layout = (LinearLayout) LayoutInflater.from(context).inflate(R.layout.chat_bubble_alt_outgoing, null); + } + + TextView msgView = (TextView) layout.findViewById(R.id.message); + if (context.getResources().getBoolean(R.bool.emoticons_in_messages)) { + msgView.setText(getSmiledText(context, message)); + } else { + msgView.setText(message); + } + + TextView timeView = (TextView) layout.findViewById(R.id.time); + timeView.setText(timestampToHumanDate(context, time)); + + view.addView(layout); + } else { + LinearLayout layout; + if (isIncoming) { + layout = (LinearLayout) LayoutInflater.from(context).inflate(R.layout.chat_bubble_incoming, null); + } else { + layout = (LinearLayout) LayoutInflater.from(context).inflate(R.layout.chat_bubble_outgoing, null); + } + + TextView msgView = (TextView) layout.findViewById(R.id.message); + if (context.getResources().getBoolean(R.bool.emoticons_in_messages)) { + msgView.setText(getSmiledText(context, message)); + } else { + msgView.setText(message); + } + + TextView timeView = (TextView) layout.findViewById(R.id.time); + timeView.setText(timestampToHumanDate(context, time)); + + view.addView(layout); + } + } else { + TextView messageView = new TextView(context); + messageView.setId(id); + messageView.setTextColor(Color.BLACK); + messageView.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); + + if (context.getResources().getBoolean(R.bool.emoticons_in_messages)) { + messageView.setText(getSmiledText(context, message)); + } else { + messageView.setText(message); + } + + view.addView(messageView); } }