Use viewholder in adapters
This commit is contained in:
@@ -17,31 +17,49 @@ import java.util.*
|
|||||||
class AccountListAdapter(private val cxt: Context, private val rows: ArrayList<AccountRow>) :
|
class AccountListAdapter(private val cxt: Context, private val rows: ArrayList<AccountRow>) :
|
||||||
ArrayAdapter<AccountRow>(cxt, R.layout.account_row, rows) {
|
ArrayAdapter<AccountRow>(cxt, R.layout.account_row, rows) {
|
||||||
|
|
||||||
override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
|
private val layoutInflater = LayoutInflater.from(context)
|
||||||
|
|
||||||
|
private class ViewHolder(view: View?) {
|
||||||
|
val aorView = view?.findViewById(R.id.aor) as TextView
|
||||||
|
val actionView = view?.findViewById(R.id.action) as ImageButton
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getView(position: Int, view: View?, parent: ViewGroup): View {
|
||||||
|
|
||||||
|
val viewHolder: ViewHolder
|
||||||
|
val rowView: View
|
||||||
|
val ua = UserAgent.uas()[position]
|
||||||
|
|
||||||
|
if (view == null) {
|
||||||
|
rowView = layoutInflater.inflate(R.layout.account_row, parent, false)
|
||||||
|
viewHolder = ViewHolder(rowView)
|
||||||
|
rowView.tag = viewHolder
|
||||||
|
} else {
|
||||||
|
rowView = view
|
||||||
|
viewHolder = rowView.tag as ViewHolder
|
||||||
|
}
|
||||||
|
|
||||||
val row = rows[position]
|
val row = rows[position]
|
||||||
val inflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
|
viewHolder.aorView.text = row.aor.split(":")[0]
|
||||||
val rowView = inflater.inflate(R.layout.account_row, parent, false)
|
viewHolder.aorView.textSize = 20f
|
||||||
val aorView = rowView.findViewById(R.id.aor) as TextView
|
viewHolder.aorView.setPadding(6, 6, 0, 6)
|
||||||
aorView.text = row.aor.split(":")[0]
|
viewHolder.actionView.setImageResource(row.action)
|
||||||
aorView.textSize = 20f
|
|
||||||
aorView.setPadding(6, 6, 0, 6)
|
viewHolder.aorView.setOnClickListener {
|
||||||
aorView.setOnClickListener {
|
|
||||||
val i = Intent(cxt, AccountActivity::class.java)
|
val i = Intent(cxt, AccountActivity::class.java)
|
||||||
val b = Bundle()
|
val b = Bundle()
|
||||||
b.putString("aor", UserAgent.uas()[position].account.aor)
|
b.putString("aor", UserAgent.uas()[position].account.aor)
|
||||||
i.putExtras(b)
|
i.putExtras(b)
|
||||||
(cxt as Activity).startActivityForResult(i, MainActivity.ACCOUNT_CODE)
|
(cxt as Activity).startActivityForResult(i, MainActivity.ACCOUNT_CODE)
|
||||||
}
|
}
|
||||||
val ua = UserAgent.uas()[position]
|
|
||||||
val actionView = rowView.findViewById(R.id.action) as ImageButton
|
viewHolder.actionView.setOnClickListener {
|
||||||
actionView.setImageResource(row.action)
|
|
||||||
actionView.setOnClickListener {
|
|
||||||
val titleView = View.inflate(cxt, R.layout.alert_title, null) as TextView
|
val titleView = View.inflate(cxt, R.layout.alert_title, null) as TextView
|
||||||
titleView.text = cxt.getString(R.string.confirmation)
|
titleView.text = cxt.getString(R.string.confirmation)
|
||||||
with (AlertDialog.Builder(cxt, R.style.AlertDialog)) {
|
with (AlertDialog.Builder(cxt, R.style.AlertDialog)) {
|
||||||
setCustomTitle(titleView)
|
setCustomTitle(titleView)
|
||||||
setMessage(String.format(cxt.getString(R.string.delete_account),
|
setMessage(String.format(cxt.getString(R.string.delete_account),
|
||||||
aorView.text))
|
viewHolder.aorView.text))
|
||||||
setPositiveButton(cxt.getText(R.string.delete)) { dialog, _ ->
|
setPositiveButton(cxt.getText(R.string.delete)) { dialog, _ ->
|
||||||
Api.ua_destroy(ua.uap)
|
Api.ua_destroy(ua.uap)
|
||||||
CallHistory.clear(ua.account.aor)
|
CallHistory.clear(ua.account.aor)
|
||||||
@@ -58,6 +76,7 @@ class AccountListAdapter(private val cxt: Context, private val rows: ArrayList<A
|
|||||||
show()
|
show()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return rowView
|
return rowView
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,52 +2,68 @@ package com.tutpro.baresip
|
|||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.graphics.drawable.GradientDrawable
|
import android.graphics.drawable.GradientDrawable
|
||||||
import androidx.core.content.ContextCompat
|
|
||||||
import androidx.cardview.widget.CardView
|
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.ArrayAdapter
|
import android.widget.*
|
||||||
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) {
|
||||||
|
|
||||||
override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
|
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
|
||||||
|
}
|
||||||
|
|
||||||
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) {
|
||||||
textAvatarView.visibility = View.GONE
|
viewHolder.textAvatarView.visibility = View.GONE
|
||||||
cardAvatarView.visibility = View.VISIBLE
|
viewHolder.cardAvatarView.visibility = View.VISIBLE
|
||||||
cardImageAvatarView.setImageBitmap(avatarImage)
|
viewHolder.cardImageAvatarView.setImageBitmap(avatarImage)
|
||||||
} else {
|
} else {
|
||||||
textAvatarView.visibility = View.VISIBLE
|
viewHolder.textAvatarView.visibility = View.VISIBLE
|
||||||
cardAvatarView.visibility = View.GONE
|
viewHolder.cardAvatarView.visibility = View.GONE
|
||||||
(textAvatarView.background as GradientDrawable).setColor(contact.color)
|
(viewHolder.textAvatarView.background as GradientDrawable).setColor(contact.color)
|
||||||
textAvatarView.text = "${contact.name[0]}"
|
viewHolder.textAvatarView.text = "${contact.name[0]}"
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
textAvatarView.visibility = View.VISIBLE
|
viewHolder.textAvatarView.visibility = View.VISIBLE
|
||||||
cardAvatarView.visibility = View.GONE
|
viewHolder.cardAvatarView.visibility = View.GONE
|
||||||
textAvatarView.setBackgroundResource(R.drawable.person_image)
|
viewHolder.textAvatarView.setBackgroundResource(R.drawable.person_image)
|
||||||
}
|
}
|
||||||
val directions = rowView.findViewById(R.id.directions) as LinearLayout
|
|
||||||
var count = 1
|
var count = 1
|
||||||
for (d in callRow.directions) {
|
for (d in callRow.directions) {
|
||||||
if (count > 3) {
|
if (count > 3) {
|
||||||
val etc = rowView.findViewById(R.id.etc) as TextView
|
viewHolder.etcView.text = "..."
|
||||||
etc.text = "..."
|
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
val dirView = ImageView(cxt)
|
val dirView = ImageView(cxt)
|
||||||
@@ -56,17 +72,18 @@ 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)
|
||||||
directions.addView(dirView)
|
viewHolder.directionsView.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:"))
|
||||||
peerURIView.text = Utils.friendlyUri(contactName, Utils.aorDomain(callRow.aor))
|
viewHolder.peerUriView.text = Utils.friendlyUri(contactName, Utils.aorDomain(callRow.aor))
|
||||||
else
|
else
|
||||||
peerURIView.text = contactName
|
viewHolder.peerUriView.text = contactName
|
||||||
val timeView = rowView.findViewById(R.id.time) as TextView
|
|
||||||
timeView.text = callRow.time
|
viewHolder.timeView.text = callRow.time
|
||||||
|
|
||||||
return rowView
|
return rowView
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,43 +17,64 @@ import java.text.DateFormat
|
|||||||
class ChatListAdapter(private val ctx: Context, private var rows: ArrayList<Message>) :
|
class ChatListAdapter(private val ctx: Context, private var rows: ArrayList<Message>) :
|
||||||
ArrayAdapter<Message>(ctx, R.layout.message, rows) {
|
ArrayAdapter<Message>(ctx, R.layout.message, rows) {
|
||||||
|
|
||||||
override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
|
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.ImageAvatar) as ImageView
|
||||||
|
val layoutView = view?.findViewById(R.id.chat) as LinearLayout
|
||||||
|
val peerView = view?.findViewById(R.id.peer) as TextView
|
||||||
|
val infoView = view?.findViewById(R.id.info) as TextView
|
||||||
|
val textView = view?.findViewById(R.id.text) 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.chat_row, parent, false)
|
||||||
|
viewHolder = ViewHolder(rowView)
|
||||||
|
rowView.tag = viewHolder
|
||||||
|
} else {
|
||||||
|
rowView = view
|
||||||
|
viewHolder = rowView.tag as ViewHolder
|
||||||
|
}
|
||||||
|
|
||||||
val message = rows[position]
|
val message = rows[position]
|
||||||
val inflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
|
|
||||||
val rowView = inflater.inflate(R.layout.chat_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.ImageAvatar) as ImageView
|
|
||||||
val layout = rowView.findViewById(R.id.chat) as LinearLayout
|
|
||||||
val contact = ContactsActivity.findContact(message.peerUri)
|
val contact = ContactsActivity.findContact(message.peerUri)
|
||||||
val peer: String
|
val peer: String
|
||||||
if (contact != null) {
|
if (contact != null) {
|
||||||
peer = contact.name
|
peer = contact.name
|
||||||
val avatarImage = contact.avatarImage
|
val avatarImage = contact.avatarImage
|
||||||
if (avatarImage != null) {
|
if (avatarImage != null) {
|
||||||
textAvatarView.visibility = View.GONE
|
viewHolder.textAvatarView.visibility = View.GONE
|
||||||
cardAvatarView.visibility = View.VISIBLE
|
viewHolder.cardAvatarView.visibility = View.VISIBLE
|
||||||
cardImageAvatarView.setImageBitmap(avatarImage)
|
viewHolder.cardImageAvatarView.setImageBitmap(avatarImage)
|
||||||
} else {
|
} else {
|
||||||
textAvatarView.visibility = View.VISIBLE
|
viewHolder.textAvatarView.visibility = View.VISIBLE
|
||||||
cardAvatarView.visibility = View.GONE
|
viewHolder.cardAvatarView.visibility = View.GONE
|
||||||
(textAvatarView.background as GradientDrawable).setColor(contact.color)
|
(viewHolder.textAvatarView.background as GradientDrawable).setColor(contact.color)
|
||||||
textAvatarView.text = "${peer[0]}"
|
viewHolder.textAvatarView.text = "${peer[0]}"
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
peer = Utils.friendlyUri(message.peerUri, message.aor)
|
peer = Utils.friendlyUri(message.peerUri, message.aor)
|
||||||
textAvatarView.visibility = View.VISIBLE
|
viewHolder.textAvatarView.visibility = View.VISIBLE
|
||||||
cardAvatarView.visibility = View.GONE
|
viewHolder.cardAvatarView.visibility = View.GONE
|
||||||
textAvatarView.setBackgroundResource(R.drawable.person_image)
|
viewHolder.textAvatarView.setBackgroundResource(R.drawable.person_image)
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((message.direction == R.drawable.arrow_down_green) ||
|
if ((message.direction == R.drawable.arrow_down_green) ||
|
||||||
(message.direction == R.drawable.arrow_down_red))
|
(message.direction == R.drawable.arrow_down_red))
|
||||||
layout.setBackgroundResource(R.drawable.message_in_bg)
|
viewHolder.layoutView.setBackgroundResource(R.drawable.message_in_bg)
|
||||||
else
|
else
|
||||||
layout.setBackgroundResource(R.drawable.message_out_bg)
|
viewHolder.layoutView.setBackgroundResource(R.drawable.message_out_bg)
|
||||||
val peerView = rowView.findViewById(R.id.peer) as TextView
|
|
||||||
peerView.setText(peer)
|
viewHolder.peerView.setText(peer)
|
||||||
val infoView = rowView.findViewById(R.id.info) as TextView
|
|
||||||
val cal = GregorianCalendar()
|
val cal = GregorianCalendar()
|
||||||
cal.timeInMillis = message.timeStamp
|
cal.timeInMillis = message.timeStamp
|
||||||
val fmt: DateFormat
|
val fmt: DateFormat
|
||||||
@@ -61,21 +82,22 @@ class ChatListAdapter(private val ctx: Context, private var rows: ArrayList<Mess
|
|||||||
fmt = DateFormat.getTimeInstance(DateFormat.SHORT)
|
fmt = DateFormat.getTimeInstance(DateFormat.SHORT)
|
||||||
else
|
else
|
||||||
fmt = DateFormat.getDateInstance(DateFormat.SHORT)
|
fmt = DateFormat.getDateInstance(DateFormat.SHORT)
|
||||||
infoView.text = fmt.format(cal.time)
|
viewHolder.infoView.text = fmt.format(cal.time)
|
||||||
if (message.direction == R.drawable.arrow_up_red) {
|
if (message.direction == R.drawable.arrow_up_red) {
|
||||||
val info: String
|
val info: String
|
||||||
if (message.responseCode != 0)
|
if (message.responseCode != 0)
|
||||||
info = "${infoView.text} - ${ctx.getString(R.string.message_failed)}: " +
|
info = "${viewHolder.infoView.text} - ${ctx.getString(R.string.message_failed)}: " +
|
||||||
"${message.responseCode} ${message.responseReason}"
|
"${message.responseCode} ${message.responseReason}"
|
||||||
else
|
else
|
||||||
info = "${infoView.text} - ${ctx.getString(R.string.sending_failed)}"
|
info = "${viewHolder.infoView.text} - ${ctx.getString(R.string.sending_failed)}"
|
||||||
infoView.text = info
|
viewHolder.infoView.text = info
|
||||||
infoView.setTextColor(ContextCompat.getColor(ctx, R.color.colorAccent))
|
viewHolder.infoView.setTextColor(ContextCompat.getColor(ctx, R.color.colorAccent))
|
||||||
}
|
}
|
||||||
val textView = rowView.findViewById(R.id.text) as TextView
|
|
||||||
textView.text = message.message
|
viewHolder.textView.text = message.message
|
||||||
if (message.new)
|
if (message.new)
|
||||||
textView.setTypeface(null, Typeface.BOLD)
|
viewHolder.textView.setTypeface(null, Typeface.BOLD)
|
||||||
|
|
||||||
return rowView
|
return rowView
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -25,37 +25,56 @@ class ContactListAdapter(private val ctx: Context, private val rows: ArrayList<C
|
|||||||
private val aor: String) :
|
private val aor: String) :
|
||||||
ArrayAdapter<Contact>(ctx, R.layout.contact_row, rows) {
|
ArrayAdapter<Contact>(ctx, R.layout.contact_row, rows) {
|
||||||
|
|
||||||
|
private val layoutInflater = LayoutInflater.from(context)
|
||||||
private var lastClick: Long = 0
|
private var lastClick: Long = 0
|
||||||
|
|
||||||
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 imageAvatarView = view?.findViewById(R.id.ImageAvatar) as ImageView
|
||||||
|
val nameView = view?.findViewById(R.id.contactName) as TextView
|
||||||
|
val actionView = view?.findViewById(R.id.edit) as ImageButton
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getView(position: Int, view: View?, parent: ViewGroup): View {
|
||||||
|
|
||||||
|
val viewHolder: ViewHolder
|
||||||
|
val rowView: View
|
||||||
|
|
||||||
|
if (view == null) {
|
||||||
|
rowView = layoutInflater.inflate(R.layout.contact_row, parent, false)
|
||||||
|
viewHolder = ViewHolder(rowView)
|
||||||
|
rowView.tag = viewHolder
|
||||||
|
} else {
|
||||||
|
rowView = view
|
||||||
|
viewHolder = rowView.tag as ViewHolder
|
||||||
|
}
|
||||||
|
|
||||||
val contact = rows[position]
|
val contact = rows[position]
|
||||||
val inflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
|
|
||||||
val rowView = inflater.inflate(R.layout.contact_row, parent, false)
|
|
||||||
val textAvatarView = rowView.findViewById(R.id.TextAvatar) as TextView
|
|
||||||
val cardAvatarView = rowView.findViewById(R.id.CardAvatar) as CardView
|
|
||||||
val imageAvatarView = rowView.findViewById(R.id.ImageAvatar) as ImageView
|
|
||||||
val avatarImage = contact.avatarImage
|
val avatarImage = contact.avatarImage
|
||||||
if (avatarImage != null) {
|
if (avatarImage != null) {
|
||||||
textAvatarView.visibility = View.GONE
|
viewHolder.textAvatarView.visibility = View.GONE
|
||||||
cardAvatarView.visibility = View.VISIBLE
|
viewHolder.cardAvatarView.visibility = View.VISIBLE
|
||||||
imageAvatarView.visibility = View.VISIBLE
|
viewHolder.imageAvatarView.visibility = View.VISIBLE
|
||||||
imageAvatarView.setImageBitmap(avatarImage)
|
viewHolder.imageAvatarView.setImageBitmap(avatarImage)
|
||||||
} else {
|
} else {
|
||||||
textAvatarView.visibility = View.VISIBLE
|
viewHolder.textAvatarView.visibility = View.VISIBLE
|
||||||
cardAvatarView.visibility = View.GONE
|
viewHolder.cardAvatarView.visibility = View.GONE
|
||||||
imageAvatarView.visibility = View.GONE
|
viewHolder.imageAvatarView.visibility = View.GONE
|
||||||
(textAvatarView.background as GradientDrawable).setColor(contact.color)
|
(viewHolder.textAvatarView.background as GradientDrawable).setColor(contact.color)
|
||||||
if (contact.name.isNotEmpty())
|
if (contact.name.isNotEmpty())
|
||||||
textAvatarView.text = "${contact.name[0]}"
|
viewHolder.textAvatarView.text = "${contact.name[0]}"
|
||||||
else
|
else
|
||||||
textAvatarView.text = ""
|
viewHolder.textAvatarView.text = ""
|
||||||
}
|
}
|
||||||
val nameView = rowView.findViewById(R.id.contactName) as TextView
|
|
||||||
nameView.text = contact.name
|
viewHolder.nameView.text = contact.name
|
||||||
nameView.textSize = 20f
|
viewHolder.nameView.textSize = 20f
|
||||||
nameView.setPadding(6, 6, 0, 6)
|
viewHolder.nameView.setPadding(6, 6, 0, 6)
|
||||||
|
|
||||||
if (aor != "") {
|
if (aor != "") {
|
||||||
nameView.setOnClickListener { _ ->
|
viewHolder.nameView.setOnClickListener { _ ->
|
||||||
val dialogClickListener = DialogInterface.OnClickListener { _, which ->
|
val dialogClickListener = DialogInterface.OnClickListener { _, which ->
|
||||||
when (which) {
|
when (which) {
|
||||||
DialogInterface.BUTTON_POSITIVE, DialogInterface.BUTTON_NEGATIVE -> {
|
DialogInterface.BUTTON_POSITIVE, DialogInterface.BUTTON_NEGATIVE -> {
|
||||||
@@ -93,7 +112,8 @@ class ContactListAdapter(private val ctx: Context, private val rows: ArrayList<C
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
nameView.setOnLongClickListener { _ ->
|
|
||||||
|
viewHolder.nameView.setOnLongClickListener { _ ->
|
||||||
val dialogClickListener = DialogInterface.OnClickListener { _, which ->
|
val dialogClickListener = DialogInterface.OnClickListener { _, which ->
|
||||||
when (which) {
|
when (which) {
|
||||||
DialogInterface.BUTTON_POSITIVE -> {
|
DialogInterface.BUTTON_POSITIVE -> {
|
||||||
@@ -126,8 +146,8 @@ class ContactListAdapter(private val ctx: Context, private val rows: ArrayList<C
|
|||||||
}
|
}
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
val actionView = rowView.findViewById(R.id.edit) as ImageButton
|
|
||||||
actionView.setOnClickListener { _ ->
|
viewHolder.actionView.setOnClickListener { _ ->
|
||||||
if (SystemClock.elapsedRealtime() - lastClick > 1000) {
|
if (SystemClock.elapsedRealtime() - lastClick > 1000) {
|
||||||
lastClick = SystemClock.elapsedRealtime()
|
lastClick = SystemClock.elapsedRealtime()
|
||||||
val i = Intent(ctx, ContactActivity::class.java)
|
val i = Intent(ctx, ContactActivity::class.java)
|
||||||
@@ -138,6 +158,7 @@ class ContactListAdapter(private val ctx: Context, private val rows: ArrayList<C
|
|||||||
(ctx as Activity).startActivityForResult(i, MainActivity.CONTACT_CODE)
|
(ctx as Activity).startActivityForResult(i, MainActivity.CONTACT_CODE)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return rowView
|
return rowView
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,31 +15,50 @@ import java.util.*
|
|||||||
class MessageListAdapter(private val ctx: Context, private val rows: ArrayList<Message>) :
|
class MessageListAdapter(private val ctx: Context, private val rows: ArrayList<Message>) :
|
||||||
ArrayAdapter<Message>(ctx, R.layout.message, rows) {
|
ArrayAdapter<Message>(ctx, R.layout.message, rows) {
|
||||||
|
|
||||||
override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
|
private val layoutInflater = LayoutInflater.from(context)
|
||||||
|
|
||||||
|
private class ViewHolder(view: View?) {
|
||||||
|
val layoutView = view?.findViewById(R.id.message) as LinearLayout
|
||||||
|
val infoView = view?.findViewById(R.id.info) as TextView
|
||||||
|
val textView = view?.findViewById(R.id.text) 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.message, parent, false)
|
||||||
|
viewHolder = ViewHolder(rowView)
|
||||||
|
rowView.tag = viewHolder
|
||||||
|
} else {
|
||||||
|
rowView = view
|
||||||
|
viewHolder = rowView.tag as ViewHolder
|
||||||
|
}
|
||||||
|
|
||||||
val message = rows[position]
|
val message = rows[position]
|
||||||
|
|
||||||
val up = (message.direction == R.drawable.arrow_up_green) ||
|
val up = (message.direction == R.drawable.arrow_up_green) ||
|
||||||
(message.direction == R.drawable.arrow_up_red)
|
(message.direction == R.drawable.arrow_up_red)
|
||||||
val inflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
|
val lp = viewHolder.layoutView.layoutParams as LinearLayout.LayoutParams
|
||||||
val messageView = inflater.inflate(R.layout.message, parent, false)
|
|
||||||
val layout = messageView.findViewById(R.id.message) as LinearLayout
|
|
||||||
val lp = layout.layoutParams as LinearLayout.LayoutParams
|
|
||||||
val peer: String
|
val peer: String
|
||||||
if (up) {
|
peer = if (up) {
|
||||||
lp.setMargins(75, 10, 0, 10)
|
lp.setMargins(75, 10, 0, 10)
|
||||||
layout.setBackgroundResource(R.drawable.message_out_bg)
|
viewHolder.layoutView.setBackgroundResource(R.drawable.message_out_bg)
|
||||||
peer = ctx.getString(R.string.you)
|
ctx.getString(R.string.you)
|
||||||
} else {
|
} else {
|
||||||
lp.setMargins(0, 10, 75, 10)
|
lp.setMargins(0, 10, 75, 10)
|
||||||
layout.setBackgroundResource(R.drawable.message_in_bg)
|
viewHolder.layoutView.setBackgroundResource(R.drawable.message_in_bg)
|
||||||
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)))
|
||||||
peer = Utils.uriUserPart(message.peerUri)
|
Utils.uriUserPart(message.peerUri)
|
||||||
else
|
else
|
||||||
peer = contactName
|
contactName
|
||||||
}
|
}
|
||||||
layout.layoutParams = lp
|
viewHolder.layoutView.layoutParams = lp
|
||||||
val infoView = messageView.findViewById(R.id.info) as TextView
|
|
||||||
var info: String
|
var info: String
|
||||||
val cal = GregorianCalendar()
|
val cal = GregorianCalendar()
|
||||||
cal.timeInMillis = message.timeStamp
|
cal.timeInMillis = message.timeStamp
|
||||||
@@ -56,14 +75,15 @@ class MessageListAdapter(private val ctx: Context, private val rows: ArrayList<M
|
|||||||
info = "$info - ${ctx.getString(R.string.message_failed)}: " + "${message.responseCode} ${message.responseReason}"
|
info = "$info - ${ctx.getString(R.string.message_failed)}: " + "${message.responseCode} ${message.responseReason}"
|
||||||
else
|
else
|
||||||
info = "$info - ${ctx.getString(R.string.sending_failed)}"
|
info = "$info - ${ctx.getString(R.string.sending_failed)}"
|
||||||
infoView.setTextColor(ContextCompat.getColor(ctx, R.color.colorAccent))
|
viewHolder.infoView.setTextColor(ContextCompat.getColor(ctx, R.color.colorAccent))
|
||||||
}
|
}
|
||||||
infoView.text = info
|
viewHolder.infoView.text = info
|
||||||
val textView = messageView.findViewById(R.id.text) as TextView
|
|
||||||
textView.text = message.message
|
viewHolder.textView.text = message.message
|
||||||
if (message.new)
|
if (message.new)
|
||||||
textView.setTypeface(null, Typeface.BOLD)
|
viewHolder.textView.setTypeface(null, Typeface.BOLD)
|
||||||
return messageView
|
|
||||||
|
return rowView
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,32 +5,50 @@ 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.ImageButton
|
||||||
import android.widget.ImageView
|
import android.widget.ImageView
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
|
|
||||||
import java.util.ArrayList
|
import java.util.ArrayList
|
||||||
|
|
||||||
class UaSpinnerAdapter(private val cxt: Context, private val uas: ArrayList<UserAgent>,
|
class UaSpinnerAdapter(cxt: Context, private val uas: ArrayList<UserAgent>,
|
||||||
private val images: ArrayList<Int>) :
|
private val images: ArrayList<Int>) :
|
||||||
ArrayAdapter<Int>(cxt, android.R.layout.simple_spinner_item, images) {
|
ArrayAdapter<Int>(cxt, android.R.layout.simple_spinner_item, images) {
|
||||||
|
|
||||||
override fun getDropDownView(position: Int, convertView: View?, parent: ViewGroup): View {
|
private val layoutInflater = LayoutInflater.from(context)
|
||||||
return getImageForPosition(position, parent)
|
|
||||||
|
private class ViewHolder(view: View?) {
|
||||||
|
val textView = view?.findViewById(R.id.spinnerText) as TextView
|
||||||
|
val imageView = view?.findViewById(R.id.spinnerImage) as ImageView
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
|
override fun getDropDownView(position: Int, view: View?, parent: ViewGroup): View {
|
||||||
return getImageForPosition(position, parent)
|
return getImageForPosition(position, view, parent)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getImageForPosition(position: Int, parent: ViewGroup): View {
|
override fun getView(position: Int, view: View?, parent: ViewGroup): View {
|
||||||
val inflater = cxt.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
|
return getImageForPosition(position, view, parent)
|
||||||
val row = inflater.inflate(R.layout.account_spinner, parent, false)
|
}
|
||||||
val textView = row.findViewById(R.id.spinnerText) as TextView
|
|
||||||
textView.text = uas[position].account.aor.split(":")[1]
|
private fun getImageForPosition(position: Int, view: View?, parent: ViewGroup): View {
|
||||||
textView.textSize = 17f
|
|
||||||
val imageView = row.findViewById(R.id.spinnerImage) as ImageView
|
val viewHolder: ViewHolder
|
||||||
imageView.setImageResource(images[position])
|
val rowView: View
|
||||||
return row
|
|
||||||
|
if (view == null) {
|
||||||
|
rowView = layoutInflater.inflate(R.layout.account_spinner, parent, false)
|
||||||
|
viewHolder = ViewHolder(rowView)
|
||||||
|
rowView.tag = viewHolder
|
||||||
|
} else {
|
||||||
|
rowView = view
|
||||||
|
viewHolder = rowView.tag as ViewHolder
|
||||||
|
}
|
||||||
|
|
||||||
|
viewHolder.textView.text = uas[position].account.aor.split(":")[1]
|
||||||
|
viewHolder.textView.textSize = 17f
|
||||||
|
viewHolder.imageView.setImageResource(images[position])
|
||||||
|
|
||||||
|
return rowView
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user