started work on improving chat user interfaces
This commit is contained in:
@ -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 ->
|
||||
|
||||
@ -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<Mess
|
||||
override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
|
||||
val message = rows[position]
|
||||
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 peerView = messageView.findViewById(R.id.peer) as TextView
|
||||
val chatView = inflater.inflate(R.layout.chat, parent, false)
|
||||
val layout = chatView.findViewById(R.id.chat) as LinearLayout
|
||||
val lp = layout.layoutParams as LinearLayout.LayoutParams
|
||||
lp.setMargins(10, 10, 10, 10)
|
||||
val peer: String
|
||||
val sender: String
|
||||
val contactName = ContactsActivity.contactName(message.peerUri)
|
||||
if (contactName.startsWith("sip:") &&
|
||||
(Utils.uriHostPart(message.peerUri) == Utils.uriHostPart(message.aor)))
|
||||
peerView.text = Utils.uriUserPart(message.peerUri)
|
||||
peer = Utils.uriUserPart(message.peerUri)
|
||||
else
|
||||
peerView.text = contactName
|
||||
val timeView = messageView.findViewById(R.id.time) as TextView
|
||||
val time: String
|
||||
peer = contactName
|
||||
if (message.direction == R.drawable.arrow_down_green) {
|
||||
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()
|
||||
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
|
||||
val textView = messageView.findViewById(R.id.text) as TextView
|
||||
if (info.length < 6) info = "Today $info"
|
||||
infoView.text = "$info - $sender"
|
||||
val textView = chatView.findViewById(R.id.text) as TextView
|
||||
textView.text = message.message
|
||||
if (message.new) {
|
||||
textView.setTypeface(null, Typeface.BOLD)
|
||||
message.new = false
|
||||
}
|
||||
return messageView
|
||||
return chatView
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -6,34 +6,52 @@ import android.text.format.DateUtils.isToday
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.ArrayAdapter
|
||||
import android.widget.ImageView
|
||||
import android.widget.TextView
|
||||
import android.widget.*
|
||||
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.*
|
||||
|
||||
|
||||
class MessageListAdapter(private val cxt: Context, private val rows: ArrayList<Message>) :
|
||||
ArrayAdapter<Message>(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)
|
||||
|
||||
11
app/src/main/res/drawable/peer_bg.xml
Normal file
11
app/src/main/res/drawable/peer_bg.xml
Normal file
@ -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>
|
||||
11
app/src/main/res/drawable/you_bg.xml
Normal file
11
app/src/main/res/drawable/you_bg.xml
Normal file
@ -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:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="10dp"
|
||||
android:gravity="center_horizontal" >
|
||||
</TextView>
|
||||
|
||||
@ -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" >
|
||||
</ListView>
|
||||
|
||||
|
||||
@ -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" >
|
||||
</TextView>
|
||||
|
||||
|
||||
47
app/src/main/res/layout/chat.xml
Normal file
47
app/src/main/res/layout/chat.xml
Normal file
@ -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"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="0dp"
|
||||
android:layout_marginTop="0dp" >
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/header"
|
||||
android:orientation="horizontal"
|
||||
android:id="@+id/message"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="fill_parent"
|
||||
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>
|
||||
android:layout_height="wrap_content" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/peer"
|
||||
android:layout_width="wrap_content"
|
||||
android:id="@+id/info"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="4dp"
|
||||
android:textSize="16sp"
|
||||
android:layout_marginTop="5dp"
|
||||
android:layout_marginStart="5dp"
|
||||
android:textSize="12sp"
|
||||
android:text="" >
|
||||
</TextView>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/time"
|
||||
android:layout_width="match_parent"
|
||||
android:id="@+id/text"
|
||||
android:layout_width="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:text="" >
|
||||
</TextView>
|
||||
|
||||
</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>
|
||||
|
||||
Reference in New Issue
Block a user