Call list related fixes

This commit is contained in:
Juha Heinanen
2021-02-17 11:57:52 +02:00
parent c5533a8ad9
commit 9260362fad

View File

@ -6,64 +6,48 @@ import androidx.cardview.widget.CardView
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.*
import android.widget.ArrayAdapter
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.TextView
import java.util.*
class CallListAdapter(private val cxt: Context, private val rows: ArrayList<CallRow>) :
ArrayAdapter<CallRow>(cxt, R.layout.call_row, rows) {
private val layoutInflater = LayoutInflater.from(context)
private class ViewHolder(view: View?) {
val textAvatarView = view?.findViewById(R.id.TextAvatar) as TextView
val cardAvatarView = view?.findViewById(R.id.CardAvatar) as CardView
val cardImageAvatarView = view?.findViewById(R.id.CardImageAvatar) as ImageView
val directionsView = view?.findViewById(R.id.directions) as LinearLayout
val etcView = view?.findViewById(R.id.etc) as TextView
val peerUriView = view?.findViewById(R.id.peer_uri) as TextView
val timeView = view?.findViewById(R.id.time) as TextView
}
override fun getView(position: Int, view: View?, parent: ViewGroup): View {
val viewHolder: ViewHolder
val rowView: View
if (view == null) {
rowView = layoutInflater.inflate(R.layout.call_row, parent, false)
viewHolder = CallListAdapter.ViewHolder(rowView)
rowView.tag = viewHolder
} else {
rowView = view
viewHolder = rowView.tag as ViewHolder
}
override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
val callRow = rows[position]
val inflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
val rowView = inflater.inflate(R.layout.call_row, parent, false)
val textAvatarView = rowView.findViewById(R.id.TextAvatar) as TextView
val cardAvatarView = rowView.findViewById(R.id.CardAvatar) as CardView
val cardImageAvatarView = rowView.findViewById(R.id.CardImageAvatar) as ImageView
val contact = ContactsActivity.findContact(callRow.peerUri)
if (contact != null) {
val avatarImage = contact.avatarImage
if (avatarImage != null) {
viewHolder.textAvatarView.visibility = View.GONE
viewHolder.cardAvatarView.visibility = View.VISIBLE
viewHolder.cardImageAvatarView.setImageBitmap(avatarImage)
textAvatarView.visibility = View.GONE
cardAvatarView.visibility = View.VISIBLE
cardImageAvatarView.setImageBitmap(avatarImage)
} else {
viewHolder.textAvatarView.visibility = View.VISIBLE
viewHolder.cardAvatarView.visibility = View.GONE
(viewHolder.textAvatarView.background as GradientDrawable).setColor(contact.color)
viewHolder.textAvatarView.text = "${contact.name[0]}"
textAvatarView.visibility = View.VISIBLE
cardAvatarView.visibility = View.GONE
(textAvatarView.background as GradientDrawable).setColor(contact.color)
textAvatarView.text = "${contact.name[0]}"
}
} else {
viewHolder.textAvatarView.visibility = View.VISIBLE
viewHolder.cardAvatarView.visibility = View.GONE
viewHolder.textAvatarView.setBackgroundResource(R.drawable.person_image)
textAvatarView.visibility = View.VISIBLE
cardAvatarView.visibility = View.GONE
textAvatarView.setBackgroundResource(R.drawable.person_image)
}
val directions = rowView.findViewById(R.id.directions) as LinearLayout
directions.removeAllViews()
var count = 1
for (d in callRow.directions) {
if (count > 3) {
viewHolder.etcView.text = "..."
val etc = rowView.findViewById(R.id.etc) as TextView
etc.text = "..."
break
}
val dirView = ImageView(cxt)
@ -72,18 +56,17 @@ class CallListAdapter(private val cxt: Context, private val rows: ArrayList<Call
dirView.layoutParams = params
dirView.setPadding(0, 5, 0, 0)
dirView.setImageResource(d)
viewHolder.directionsView.addView(dirView)
directions.addView(dirView)
count++
}
val peerURIView = rowView.findViewById(R.id.peer_uri) as TextView
val contactName = ContactsActivity.contactName(callRow.peerUri)
if (contactName.startsWith("sip:"))
viewHolder.peerUriView.text = Utils.friendlyUri(contactName, Utils.aorDomain(callRow.aor))
peerURIView.text = Utils.friendlyUri(contactName, Utils.aorDomain(callRow.aor))
else
viewHolder.peerUriView.text = contactName
viewHolder.timeView.text = callRow.time
peerURIView.text = contactName
val timeView = rowView.findViewById(R.id.time) as TextView
timeView.text = callRow.time
return rowView
}