started work on improving chat user interfaces
This commit is contained in:
@@ -50,7 +50,8 @@ class ChatActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
var chatPeer = ContactsActivity.contactName(peerUri)
|
var chatPeer = ContactsActivity.contactName(peerUri)
|
||||||
if (chatPeer.startsWith("sip:")) {
|
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)
|
chatPeer = Utils.uriUserPart(peerUri)
|
||||||
else
|
else
|
||||||
chatPeer = chatPeer.substring(4)
|
chatPeer = chatPeer.substring(4)
|
||||||
@@ -68,7 +69,7 @@ class ChatActivity : AppCompatActivity() {
|
|||||||
listView.isLongClickable = true
|
listView.isLongClickable = true
|
||||||
val footerView = View(applicationContext)
|
val footerView = View(applicationContext)
|
||||||
listView.addFooterView(footerView)
|
listView.addFooterView(footerView)
|
||||||
listView.smoothScrollToPosition(mlAdapter.count)
|
listView.smoothScrollToPosition(mlAdapter.count - 1)
|
||||||
|
|
||||||
listView.onItemLongClickListener = AdapterView.OnItemLongClickListener { _, _, pos, _ ->
|
listView.onItemLongClickListener = AdapterView.OnItemLongClickListener { _, _, pos, _ ->
|
||||||
val dialogClickListener = DialogInterface.OnClickListener { _, which ->
|
val dialogClickListener = DialogInterface.OnClickListener { _, which ->
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import android.view.LayoutInflater
|
|||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.widget.ArrayAdapter
|
import android.widget.ArrayAdapter
|
||||||
import android.widget.ImageView
|
import android.widget.LinearLayout
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
|
|
||||||
import java.text.SimpleDateFormat
|
import java.text.SimpleDateFormat
|
||||||
@@ -19,35 +19,47 @@ class ChatListAdapter(private val cxt: Context, private var rows: ArrayList<Mess
|
|||||||
override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
|
override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
|
||||||
val message = rows[position]
|
val message = rows[position]
|
||||||
val inflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
|
val inflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
|
||||||
val messageView = inflater.inflate(R.layout.message, parent, false)
|
val chatView = inflater.inflate(R.layout.chat, parent, false)
|
||||||
val directionView = messageView.findViewById(R.id.direction) as ImageView
|
val layout = chatView.findViewById(R.id.chat) as LinearLayout
|
||||||
directionView.setImageResource(message.direction)
|
val lp = layout.layoutParams as LinearLayout.LayoutParams
|
||||||
val peerView = messageView.findViewById(R.id.peer) as TextView
|
lp.setMargins(10, 10, 10, 10)
|
||||||
|
val peer: String
|
||||||
|
val sender: String
|
||||||
val contactName = ContactsActivity.contactName(message.peerUri)
|
val contactName = ContactsActivity.contactName(message.peerUri)
|
||||||
if (contactName.startsWith("sip:") &&
|
if (contactName.startsWith("sip:") &&
|
||||||
(Utils.uriHostPart(message.peerUri) == Utils.uriHostPart(message.aor)))
|
(Utils.uriHostPart(message.peerUri) == Utils.uriHostPart(message.aor)))
|
||||||
peerView.text = Utils.uriUserPart(message.peerUri)
|
peer = Utils.uriUserPart(message.peerUri)
|
||||||
else
|
else
|
||||||
peerView.text = contactName
|
peer = contactName
|
||||||
val timeView = messageView.findViewById(R.id.time) as TextView
|
if (message.direction == R.drawable.arrow_down_green) {
|
||||||
val time: String
|
layout.setBackgroundResource(R.drawable.peer_bg)
|
||||||
|
sender = peer
|
||||||
|
} else {
|
||||||
|
layout.setBackgroundResource(R.drawable.you_bg)
|
||||||
|
sender = "You"
|
||||||
|
}
|
||||||
|
val peerView = chatView.findViewById(R.id.peer) as TextView
|
||||||
|
peerView.setText(peer)
|
||||||
|
val infoView = chatView.findViewById(R.id.info) as TextView
|
||||||
|
var info: String
|
||||||
val cal = GregorianCalendar()
|
val cal = GregorianCalendar()
|
||||||
cal.timeInMillis = message.timeStamp
|
cal.timeInMillis = message.timeStamp
|
||||||
if (isToday(message.timeStamp)) {
|
if (isToday(message.timeStamp)) {
|
||||||
val fmt = SimpleDateFormat("HH:mm")
|
val fmt = SimpleDateFormat("HH:mm")
|
||||||
time = fmt.format(cal.time)
|
info = fmt.format(cal.time)
|
||||||
} else {
|
} else {
|
||||||
val fmt = SimpleDateFormat("dd.MM")
|
val fmt = SimpleDateFormat("dd/MM, HH:mm")
|
||||||
time = fmt.format(cal.time)
|
info = fmt.format(cal.time)
|
||||||
}
|
}
|
||||||
timeView.text = time
|
if (info.length < 6) info = "Today $info"
|
||||||
val textView = messageView.findViewById(R.id.text) as TextView
|
infoView.text = "$info - $sender"
|
||||||
|
val textView = chatView.findViewById(R.id.text) as TextView
|
||||||
textView.text = message.message
|
textView.text = message.message
|
||||||
if (message.new) {
|
if (message.new) {
|
||||||
textView.setTypeface(null, Typeface.BOLD)
|
textView.setTypeface(null, Typeface.BOLD)
|
||||||
message.new = false
|
message.new = false
|
||||||
}
|
}
|
||||||
return messageView
|
return chatView
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,34 +6,52 @@ import android.text.format.DateUtils.isToday
|
|||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.widget.ArrayAdapter
|
import android.widget.*
|
||||||
import android.widget.ImageView
|
|
||||||
import android.widget.TextView
|
|
||||||
|
|
||||||
import java.text.SimpleDateFormat
|
import java.text.SimpleDateFormat
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
|
|
||||||
class MessageListAdapter(private val cxt: Context, private val rows: ArrayList<Message>) :
|
class MessageListAdapter(private val cxt: Context, private val rows: ArrayList<Message>) :
|
||||||
ArrayAdapter<Message>(cxt, R.layout.message, rows) {
|
ArrayAdapter<Message>(cxt, R.layout.message, rows) {
|
||||||
|
|
||||||
override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
|
override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
|
||||||
val message = rows[position]
|
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 inflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
|
||||||
val messageView = inflater.inflate(R.layout.message, parent, false)
|
val messageView = inflater.inflate(R.layout.message, parent, false)
|
||||||
val directionView = messageView.findViewById(R.id.direction) as ImageView
|
val layout = messageView.findViewById(R.id.message) as LinearLayout
|
||||||
directionView.setImageResource(message.direction)
|
val lp = layout.layoutParams as LinearLayout.LayoutParams
|
||||||
val timeView = messageView.findViewById(R.id.time) as TextView
|
val peer: String
|
||||||
val time: 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()
|
val cal = GregorianCalendar()
|
||||||
cal.timeInMillis = message.timeStamp
|
cal.timeInMillis = message.timeStamp
|
||||||
if (isToday(message.timeStamp)) {
|
if (isToday(message.timeStamp)) {
|
||||||
val fmt = SimpleDateFormat("HH:mm")
|
val fmt = SimpleDateFormat("HH:mm")
|
||||||
time = fmt.format(cal.time)
|
info = fmt.format(cal.time)
|
||||||
} else {
|
} else {
|
||||||
val fmt = SimpleDateFormat("dd.MM")
|
val fmt = SimpleDateFormat("dd/MM, HH:mm")
|
||||||
time = fmt.format(cal.time)
|
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
|
val textView = messageView.findViewById(R.id.text) as TextView
|
||||||
textView.text = message.message
|
textView.text = message.message
|
||||||
if (message.new) textView.setTypeface(null, Typeface.BOLD)
|
if (message.new) textView.setTypeface(null, Typeface.BOLD)
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
|
||||||
|
<item>
|
||||||
|
<shape android:shape="rectangle">
|
||||||
|
<solid android:color="#E0E0E0"/>
|
||||||
|
<corners android:radius="10dp"/>
|
||||||
|
</shape>
|
||||||
|
</item>
|
||||||
|
|
||||||
|
</layer-list>
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
|
||||||
|
<item>
|
||||||
|
<shape android:shape="rectangle">
|
||||||
|
<solid android:color="#B3E5FC"/>
|
||||||
|
<corners android:radius="10dp"/>
|
||||||
|
</shape>
|
||||||
|
</item>
|
||||||
|
|
||||||
|
</layer-list>
|
||||||
@@ -13,6 +13,7 @@
|
|||||||
android:id="@+id/account"
|
android:id="@+id/account"
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginBottom="10dp"
|
||||||
android:gravity="center_horizontal" >
|
android:gravity="center_horizontal" >
|
||||||
</TextView>
|
</TextView>
|
||||||
|
|
||||||
@@ -21,7 +22,10 @@
|
|||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:transcriptMode="alwaysScroll"
|
android:transcriptMode="alwaysScroll"
|
||||||
|
android:stackFromBottom="true"
|
||||||
android:layout_below="@id/account"
|
android:layout_below="@id/account"
|
||||||
|
android:divider="#00000000"
|
||||||
|
android:dividerHeight="15dp"
|
||||||
android:layout_above="@id/text" >
|
android:layout_above="@id/text" >
|
||||||
</ListView>
|
</ListView>
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
android:id="@+id/account"
|
android:id="@+id/account"
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginBottom="10dp"
|
||||||
android:gravity="center_horizontal" >
|
android:gravity="center_horizontal" >
|
||||||
</TextView>
|
</TextView>
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,47 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/chat"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="wrap_content" >
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/peer"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="5dp"
|
||||||
|
android:layout_marginStart="5dp"
|
||||||
|
android:textSize="16sp"
|
||||||
|
android:textStyle="bold"
|
||||||
|
android:text="" >
|
||||||
|
</TextView>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/info"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="5dp"
|
||||||
|
android:layout_marginStart="5dp"
|
||||||
|
android:textSize="12sp"
|
||||||
|
android:text="" >
|
||||||
|
</TextView>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/text"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="5dp"
|
||||||
|
android:layout_marginEnd="5dp"
|
||||||
|
android:layout_marginBottom="5dp"
|
||||||
|
android:textSize="16sp"
|
||||||
|
android:text="" >
|
||||||
|
</TextView>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
@@ -2,50 +2,35 @@
|
|||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content">
|
||||||
android:layout_marginBottom="0dp"
|
|
||||||
android:layout_marginTop="0dp" >
|
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:id="@+id/header"
|
android:id="@+id/message"
|
||||||
android:orientation="horizontal"
|
android:orientation="vertical"
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content" >
|
||||||
android:layout_marginTop="6dp" >
|
|
||||||
|
|
||||||
<ImageView
|
|
||||||
android:id="@+id/direction"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content" >
|
|
||||||
</ImageView>
|
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/peer"
|
android:id="@+id/info"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginStart="4dp"
|
android:layout_marginTop="5dp"
|
||||||
android:textSize="16sp"
|
android:layout_marginStart="5dp"
|
||||||
|
android:textSize="12sp"
|
||||||
android:text="" >
|
android:text="" >
|
||||||
</TextView>
|
</TextView>
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/time"
|
android:id="@+id/text"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:gravity="end"
|
android:layout_marginStart="5dp"
|
||||||
|
android:layout_marginEnd="5dp"
|
||||||
|
android:layout_marginBottom="5dp"
|
||||||
android:textSize="16sp"
|
android:textSize="16sp"
|
||||||
android:text="" >
|
android:text="" >
|
||||||
</TextView>
|
</TextView>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/text"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginBottom="4dp"
|
|
||||||
android:textSize="16sp"
|
|
||||||
android:text="" >
|
|
||||||
</TextView>
|
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|||||||
Reference in New Issue
Block a user