From 5abcb98a67039bea8196b19138ae032b82785e6f Mon Sep 17 00:00:00 2001 From: Juha Heinanen Date: Mon, 11 Mar 2019 06:42:59 +0200 Subject: [PATCH] started work on improving chat user interfaces --- .../kotlin/com/tutpro/baresip/ChatActivity.kt | 5 +- .../com/tutpro/baresip/ChatListAdapter.kt | 42 +++++++++++------ .../com/tutpro/baresip/MessageListAdapter.kt | 40 +++++++++++----- app/src/main/res/drawable/peer_bg.xml | 11 +++++ app/src/main/res/drawable/you_bg.xml | 11 +++++ app/src/main/res/layout/activity_chat.xml | 4 ++ app/src/main/res/layout/activity_chats.xml | 1 + app/src/main/res/layout/chat.xml | 47 +++++++++++++++++++ app/src/main/res/layout/message.xml | 43 ++++++----------- 9 files changed, 147 insertions(+), 57 deletions(-) create mode 100644 app/src/main/res/drawable/peer_bg.xml create mode 100644 app/src/main/res/drawable/you_bg.xml create mode 100644 app/src/main/res/layout/chat.xml diff --git a/app/src/main/kotlin/com/tutpro/baresip/ChatActivity.kt b/app/src/main/kotlin/com/tutpro/baresip/ChatActivity.kt index bf27c71c..3ec4554b 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/ChatActivity.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/ChatActivity.kt @@ -50,7 +50,8 @@ class ChatActivity : AppCompatActivity() { var chatPeer = ContactsActivity.contactName(peerUri) if (chatPeer.startsWith("sip:")) { - if (Utils.checkTelNo(Utils.uriUserPart(peerUri))) + if (Utils.checkTelNo(Utils.uriUserPart(peerUri)) || + (Utils.uriHostPart(peerUri) == Utils.aorDomain(aor))) chatPeer = Utils.uriUserPart(peerUri) else chatPeer = chatPeer.substring(4) @@ -68,7 +69,7 @@ class ChatActivity : AppCompatActivity() { listView.isLongClickable = true val footerView = View(applicationContext) listView.addFooterView(footerView) - listView.smoothScrollToPosition(mlAdapter.count) + listView.smoothScrollToPosition(mlAdapter.count - 1) listView.onItemLongClickListener = AdapterView.OnItemLongClickListener { _, _, pos, _ -> val dialogClickListener = DialogInterface.OnClickListener { _, which -> diff --git a/app/src/main/kotlin/com/tutpro/baresip/ChatListAdapter.kt b/app/src/main/kotlin/com/tutpro/baresip/ChatListAdapter.kt index 38c1645e..9f4ee31c 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/ChatListAdapter.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/ChatListAdapter.kt @@ -7,7 +7,7 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.ArrayAdapter -import android.widget.ImageView +import android.widget.LinearLayout import android.widget.TextView import java.text.SimpleDateFormat @@ -19,35 +19,47 @@ class ChatListAdapter(private val cxt: Context, private var rows: ArrayList) : ArrayAdapter(cxt, R.layout.message, rows) { override fun getView(position: Int, convertView: View?, parent: ViewGroup): View { val message = rows[position] + val up = (message.direction == R.drawable.arrow_up_green) || + (message.direction == R.drawable.arrow_up_red) val inflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater val messageView = inflater.inflate(R.layout.message, parent, false) - val directionView = messageView.findViewById(R.id.direction) as ImageView - directionView.setImageResource(message.direction) - val timeView = messageView.findViewById(R.id.time) as TextView - val time: String + val layout = messageView.findViewById(R.id.message) as LinearLayout + val lp = layout.layoutParams as LinearLayout.LayoutParams + val peer: String + if (up) { + lp.setMargins(75, 10, 0, 10) + layout.setBackgroundResource(R.drawable.you_bg) + peer = "You" + } else { + lp.setMargins(0, 10, 75, 10) + layout.setBackgroundResource(R.drawable.peer_bg) + val contactName = ContactsActivity.contactName(message.peerUri) + if (contactName.startsWith("sip:") && + (Utils.uriHostPart(message.peerUri) == Utils.uriHostPart(message.aor))) + peer = Utils.uriUserPart(message.peerUri) + else + peer = contactName + } + layout.layoutParams = lp + val infoView = messageView.findViewById(R.id.info) as TextView + var info: String val cal = GregorianCalendar() cal.timeInMillis = message.timeStamp if (isToday(message.timeStamp)) { val fmt = SimpleDateFormat("HH:mm") - time = fmt.format(cal.time) + info = fmt.format(cal.time) } else { - val fmt = SimpleDateFormat("dd.MM") - time = fmt.format(cal.time) + val fmt = SimpleDateFormat("dd/MM, HH:mm") + info = fmt.format(cal.time) } - timeView.text = time + if (info.length < 6) info = "Today $info" + infoView.text = "$info - $peer" val textView = messageView.findViewById(R.id.text) as TextView textView.text = message.message if (message.new) textView.setTypeface(null, Typeface.BOLD) diff --git a/app/src/main/res/drawable/peer_bg.xml b/app/src/main/res/drawable/peer_bg.xml new file mode 100644 index 00000000..42323121 --- /dev/null +++ b/app/src/main/res/drawable/peer_bg.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/app/src/main/res/drawable/you_bg.xml b/app/src/main/res/drawable/you_bg.xml new file mode 100644 index 00000000..47d7a067 --- /dev/null +++ b/app/src/main/res/drawable/you_bg.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/app/src/main/res/layout/activity_chat.xml b/app/src/main/res/layout/activity_chat.xml index 32115a82..7026dad1 100644 --- a/app/src/main/res/layout/activity_chat.xml +++ b/app/src/main/res/layout/activity_chat.xml @@ -13,6 +13,7 @@ android:id="@+id/account" android:layout_width="fill_parent" android:layout_height="wrap_content" + android:layout_marginBottom="10dp" android:gravity="center_horizontal" > @@ -21,7 +22,10 @@ android:layout_width="fill_parent" android:layout_height="match_parent" android:transcriptMode="alwaysScroll" + android:stackFromBottom="true" android:layout_below="@id/account" + android:divider="#00000000" + android:dividerHeight="15dp" android:layout_above="@id/text" > diff --git a/app/src/main/res/layout/activity_chats.xml b/app/src/main/res/layout/activity_chats.xml index 148ddb8c..a14bb738 100644 --- a/app/src/main/res/layout/activity_chats.xml +++ b/app/src/main/res/layout/activity_chats.xml @@ -13,6 +13,7 @@ android:id="@+id/account" android:layout_width="fill_parent" android:layout_height="wrap_content" + android:layout_marginBottom="10dp" android:gravity="center_horizontal" > diff --git a/app/src/main/res/layout/chat.xml b/app/src/main/res/layout/chat.xml new file mode 100644 index 00000000..baa6c55f --- /dev/null +++ b/app/src/main/res/layout/chat.xml @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/message.xml b/app/src/main/res/layout/message.xml index 7d3e1939..6e0797f0 100644 --- a/app/src/main/res/layout/message.xml +++ b/app/src/main/res/layout/message.xml @@ -2,50 +2,35 @@ + android:layout_height="wrap_content"> - - - + android:layout_height="wrap_content" > - - -