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