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)
|
||||
|
||||
Reference in New Issue
Block a user