- More work on character avatars.
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
package com.tutpro.baresip
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.drawable.GradientDrawable
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
@ -8,18 +9,34 @@ 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) {
|
||||
|
||||
override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
|
||||
val row = 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 avatarView = rowView.findViewById(R.id.avatar) as TextView
|
||||
val avatarBackground = avatarView.background as GradientDrawable
|
||||
val contact = ContactsActivity.findContact(callRow.peerUri)
|
||||
val peer: String
|
||||
if (contact != null) {
|
||||
peer = contact.name
|
||||
avatarBackground.setColor(contact.color)
|
||||
} else {
|
||||
if (Utils.uriHostPart(callRow.peerUri) == Utils.uriHostPart(callRow.aor))
|
||||
peer = Utils.uriUserPart(callRow.peerUri)
|
||||
else
|
||||
peer = Utils.uriAor(callRow.peerUri)
|
||||
avatarBackground.setColor(Utils.randomColor())
|
||||
}
|
||||
avatarView.text = "${peer[0]}"
|
||||
val directions = rowView.findViewById(R.id.directions) as LinearLayout
|
||||
var count = 1
|
||||
for (d in row.directions) {
|
||||
for (d in callRow.directions) {
|
||||
if (count > 3) {
|
||||
val etc = rowView.findViewById(R.id.etc) as TextView
|
||||
etc.text = "..."
|
||||
@ -35,13 +52,13 @@ class CallListAdapter(private val cxt: Context, private val rows: ArrayList<Call
|
||||
count++
|
||||
}
|
||||
val peerURIView = rowView.findViewById(R.id.peer_uri) as TextView
|
||||
val contactName = ContactsActivity.contactName(row.peerURI)
|
||||
val contactName = ContactsActivity.contactName(callRow.peerUri)
|
||||
if (contactName.startsWith("sip:"))
|
||||
peerURIView.text = Utils.friendlyUri(contactName, Utils.aorDomain(row.aor))
|
||||
peerURIView.text = Utils.friendlyUri(contactName, Utils.aorDomain(callRow.aor))
|
||||
else
|
||||
peerURIView.text = contactName
|
||||
val timeView = rowView.findViewById(R.id.time) as TextView
|
||||
timeView.text = row.time
|
||||
timeView.text = callRow.time
|
||||
return rowView
|
||||
}
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
package com.tutpro.baresip
|
||||
|
||||
class CallRow(val aor: String, val peerURI: String, val direction: Int, val time: String, val index: Int) {
|
||||
class CallRow(val aor: String, val peerUri: String, val direction: Int, val time: String, val index: Int) {
|
||||
|
||||
val directions = ArrayList<Int>()
|
||||
val indexes = ArrayList<Int>()
|
||||
|
||||
@ -6,16 +6,15 @@ import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.support.v7.app.AlertDialog
|
||||
import android.support.v7.app.AppCompatActivity
|
||||
import android.text.format.DateUtils.isToday
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import android.widget.AdapterView
|
||||
import android.widget.ListView
|
||||
import android.widget.TextView
|
||||
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.ArrayList
|
||||
import java.util.Calendar
|
||||
import java.util.GregorianCalendar
|
||||
import java.text.DateFormat
|
||||
|
||||
class CallsActivity : AppCompatActivity() {
|
||||
|
||||
@ -46,7 +45,7 @@ class CallsActivity : AppCompatActivity() {
|
||||
listView.isLongClickable = true
|
||||
|
||||
listView.onItemClickListener = AdapterView.OnItemClickListener { _, _, pos, _ ->
|
||||
val peerUri = uaHistory[pos].peerURI
|
||||
val peerUri = uaHistory[pos].peerUri
|
||||
var peerName = ContactsActivity.contactName(peerUri)
|
||||
if (peerName.startsWith("sip:"))
|
||||
peerName = Utils.friendlyUri(peerName, Utils.aorDomain(aor))
|
||||
@ -77,7 +76,7 @@ class CallsActivity : AppCompatActivity() {
|
||||
}
|
||||
|
||||
listView.onItemLongClickListener = AdapterView.OnItemLongClickListener { _, _, pos, _ ->
|
||||
val peerUri = uaHistory[pos].peerURI
|
||||
val peerUri = uaHistory[pos].peerUri
|
||||
val peerName = ContactsActivity.contactName(peerUri)
|
||||
val dialogClickListener = DialogInterface.OnClickListener { _, which ->
|
||||
when (which) {
|
||||
@ -194,7 +193,6 @@ class CallsActivity : AppCompatActivity() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
private fun aorGenerateHistory(aor: String) {
|
||||
uaHistory.clear()
|
||||
for (i in BaresipService.callHistory.indices.reversed()) {
|
||||
@ -211,18 +209,16 @@ class CallsActivity : AppCompatActivity() {
|
||||
direction = R.drawable.arrow_up_green
|
||||
else
|
||||
direction = R.drawable.arrow_up_red
|
||||
if (uaHistory.isNotEmpty() && (uaHistory.last().peerURI == h.peerURI)) {
|
||||
if (uaHistory.isNotEmpty() && (uaHistory.last().peerUri == h.peerURI)) {
|
||||
uaHistory.last().directions.add(direction)
|
||||
uaHistory.last().indexes.add(i)
|
||||
} else {
|
||||
val time: String
|
||||
if (isToday(h.time)) {
|
||||
val fmt = SimpleDateFormat("HH:mm")
|
||||
time = fmt.format(h.time.time)
|
||||
} else {
|
||||
val fmt = SimpleDateFormat("dd.MM")
|
||||
time = fmt.format(h.time.time)
|
||||
}
|
||||
val fmt: DateFormat
|
||||
if (isToday(h.time.timeInMillis))
|
||||
fmt = DateFormat.getTimeInstance(DateFormat.SHORT)
|
||||
else
|
||||
fmt = DateFormat.getDateInstance(DateFormat.SHORT)
|
||||
val time = fmt.format(h.time.time)
|
||||
uaHistory.add(CallRow(h.aor, h.peerURI, direction, time, i))
|
||||
}
|
||||
}
|
||||
@ -235,11 +231,4 @@ class CallsActivity : AppCompatActivity() {
|
||||
uaHistory.removeAt(i)
|
||||
}
|
||||
|
||||
private fun isToday(time: GregorianCalendar): Boolean {
|
||||
val now = GregorianCalendar()
|
||||
return now.get(Calendar.YEAR) == time.get(Calendar.YEAR) &&
|
||||
now.get(Calendar.MONTH) == time.get(Calendar.MONTH) &&
|
||||
now.get(Calendar.DAY_OF_MONTH) == time.get(Calendar.DAY_OF_MONTH)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -14,8 +14,8 @@ import android.widget.LinearLayout
|
||||
import android.widget.RelativeLayout
|
||||
import android.widget.TextView
|
||||
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.*
|
||||
import java.text.DateFormat
|
||||
|
||||
class ChatListAdapter(private val cxt: Context, private var rows: ArrayList<Message>) :
|
||||
ArrayAdapter<Message>(cxt, R.layout.message, rows) {
|
||||
@ -50,22 +50,22 @@ class ChatListAdapter(private val cxt: Context, private var rows: ArrayList<Mess
|
||||
val peerView = rowView.findViewById(R.id.peer) as TextView
|
||||
peerView.setText(peer)
|
||||
val infoView = rowView.findViewById(R.id.info) as TextView
|
||||
var info: String
|
||||
val cal = GregorianCalendar()
|
||||
cal.timeInMillis = message.timeStamp
|
||||
val fmt: SimpleDateFormat
|
||||
if (isToday(message.timeStamp)) {
|
||||
fmt = SimpleDateFormat("HH:mm")
|
||||
} else {
|
||||
fmt = SimpleDateFormat("dd/MM, HH:mm")
|
||||
}
|
||||
val fmt: DateFormat
|
||||
if (isToday(message.timeStamp))
|
||||
fmt = DateFormat.getTimeInstance(DateFormat.SHORT)
|
||||
else
|
||||
fmt = DateFormat.getDateInstance(DateFormat.SHORT)
|
||||
infoView.text = fmt.format(cal.time)
|
||||
if (message.direction == R.drawable.arrow_up_red) {
|
||||
val info: String
|
||||
if (message.responseCode != 0)
|
||||
infoView.text = "${infoView.text} - ${cxt.getString(R.string.message_failed)}: " +
|
||||
"${message.responseCode} ${message.responseReason}"
|
||||
info = "${infoView.text} - ${cxt.getString(R.string.message_failed)}: " +
|
||||
"${message.responseCode} ${message.responseReason}"
|
||||
else
|
||||
infoView.text = "${infoView.text} - ${cxt.getString(R.string.sending_failed)}"
|
||||
info = "${infoView.text} - ${cxt.getString(R.string.sending_failed)}"
|
||||
infoView.text = info
|
||||
infoView.setTextColor(ContextCompat.getColor(cxt, R.color.colorAccent))
|
||||
}
|
||||
val textView = rowView.findViewById(R.id.text) as TextView
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
package com.tutpro.baresip
|
||||
|
||||
import java.nio.charset.StandardCharsets
|
||||
import java.util.ArrayList
|
||||
|
||||
class Contact(var name: String, var uri: String, var color: Int) {
|
||||
@ -23,7 +22,7 @@ class Contact(var name: String, var uri: String, var color: Int) {
|
||||
fun restore(): Boolean {
|
||||
val content = Utils.getFileContents(BaresipService.filesPath + "/contacts")
|
||||
if (content == null) return false
|
||||
val contacts = String(content, StandardCharsets.ISO_8859_1)
|
||||
val contacts = String(content)
|
||||
Api.contacts_remove()
|
||||
BaresipService.contacts.clear()
|
||||
contacts.lines().forEach {
|
||||
|
||||
@ -5,10 +5,12 @@ import android.content.Intent
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.graphics.drawable.GradientDrawable
|
||||
import android.graphics.drawable.ShapeDrawable
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.support.v7.app.AppCompatActivity
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import android.view.inputmethod.InputMethodManager
|
||||
import android.widget.*
|
||||
|
||||
class ContactActivity : AppCompatActivity() {
|
||||
@ -20,7 +22,7 @@ class ContactActivity : AppCompatActivity() {
|
||||
internal var new = false
|
||||
|
||||
private var index = 0
|
||||
private var color = Utils.randomColor()
|
||||
private var color = 0
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
|
||||
@ -36,6 +38,7 @@ class ContactActivity : AppCompatActivity() {
|
||||
|
||||
if (new) {
|
||||
title = getString(R.string.new_contact)
|
||||
color = Utils.randomColor()
|
||||
val background = avatarView.background as GradientDrawable
|
||||
background.setColor(color)
|
||||
nameView.setText("")
|
||||
@ -52,8 +55,8 @@ class ContactActivity : AppCompatActivity() {
|
||||
} else {
|
||||
index = intent.getIntExtra("index", 0)
|
||||
val name = Contact.contacts()[index].name
|
||||
val background = avatarView.background as GradientDrawable
|
||||
background.setColor(Contact.contacts()[index].color)
|
||||
color = Contact.contacts()[index].color
|
||||
(avatarView.background as GradientDrawable).setColor(color)
|
||||
if (name.length > 0)
|
||||
avatarView.text = "${name[0]}"
|
||||
setTitle(name)
|
||||
@ -62,6 +65,11 @@ class ContactActivity : AppCompatActivity() {
|
||||
uOrI = index.toString()
|
||||
}
|
||||
|
||||
avatarView.setOnClickListener { view ->
|
||||
color = Utils.randomColor()
|
||||
(avatarView.background as GradientDrawable).setColor(color)
|
||||
}
|
||||
|
||||
BaresipService.activities.add(0, "contact,$new,$uOrI")
|
||||
|
||||
}
|
||||
@ -132,6 +140,7 @@ class ContactActivity : AppCompatActivity() {
|
||||
} else {
|
||||
Contact.contacts()[index].uri = newUri
|
||||
Contact.contacts()[index].name = newName
|
||||
Contact.contacts()[index].color = color
|
||||
}
|
||||
|
||||
Contact.contacts().sortBy { Contact -> Contact.name }
|
||||
|
||||
@ -20,8 +20,8 @@ class ContactListAdapter(private val cxt: Context, private val rows: ArrayList<C
|
||||
private val aor: String) :
|
||||
ArrayAdapter<Contact>(cxt, R.layout.contact_row, rows) {
|
||||
|
||||
override fun getView(pos: Int, convertView: View?, parent: ViewGroup): View {
|
||||
val row = rows[pos]
|
||||
override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
|
||||
val row = rows[position]
|
||||
val inflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
|
||||
val rowView = inflater.inflate(R.layout.contact_row, parent, false)
|
||||
val avatarView = rowView.findViewById(R.id.avatar) as TextView
|
||||
@ -51,7 +51,7 @@ class ContactListAdapter(private val cxt: Context, private val rows: ArrayList<C
|
||||
} else {
|
||||
BaresipService.activities.clear()
|
||||
i.putExtra("uap", ua.uap)
|
||||
i.putExtra("peer", Contact.contacts()[pos].uri)
|
||||
i.putExtra("peer", Contact.contacts()[position].uri)
|
||||
(cxt as Activity).startActivity(i)
|
||||
}
|
||||
}
|
||||
@ -61,7 +61,7 @@ class ContactListAdapter(private val cxt: Context, private val rows: ArrayList<C
|
||||
}
|
||||
val builder = AlertDialog.Builder(cxt, R.style.Theme_AppCompat)
|
||||
builder.setMessage(String.format(cxt.getString(R.string.contact_action_question),
|
||||
Contact.contacts()[pos].name))
|
||||
Contact.contacts()[position].name))
|
||||
.setNeutralButton(cxt.getText(R.string.cancel), dialogClickListener)
|
||||
.setNegativeButton(cxt.getText(R.string.call), dialogClickListener)
|
||||
.setPositiveButton(cxt.getText(R.string.send_message), dialogClickListener)
|
||||
@ -72,7 +72,7 @@ class ContactListAdapter(private val cxt: Context, private val rows: ArrayList<C
|
||||
val dialogClickListener = DialogInterface.OnClickListener { _, which ->
|
||||
when (which) {
|
||||
DialogInterface.BUTTON_POSITIVE -> {
|
||||
Contact.contacts().removeAt(pos)
|
||||
Contact.contacts().removeAt(position)
|
||||
Contact.save()
|
||||
this.notifyDataSetChanged()
|
||||
}
|
||||
@ -82,7 +82,7 @@ class ContactListAdapter(private val cxt: Context, private val rows: ArrayList<C
|
||||
}
|
||||
val builder = AlertDialog.Builder(cxt, R.style.Theme_AppCompat)
|
||||
builder.setMessage(String.format(cxt.getString(R.string.contact_delete_question),
|
||||
Contact.contacts()[pos].name))
|
||||
Contact.contacts()[position].name))
|
||||
.setNegativeButton(cxt.getText(R.string.cancel), dialogClickListener)
|
||||
.setPositiveButton(cxt.getText(R.string.delete), dialogClickListener)
|
||||
.show()
|
||||
@ -93,7 +93,7 @@ class ContactListAdapter(private val cxt: Context, private val rows: ArrayList<C
|
||||
val i = Intent(cxt, ContactActivity::class.java)
|
||||
val b = Bundle()
|
||||
b.putBoolean("new", false)
|
||||
b.putInt("index", pos)
|
||||
b.putInt("index", position)
|
||||
i.putExtras(b)
|
||||
(cxt as Activity).startActivityForResult(i, MainActivity.CONTACT_CODE)
|
||||
}
|
||||
|
||||
@ -9,10 +9,9 @@ import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.*
|
||||
|
||||
import java.text.SimpleDateFormat
|
||||
import java.text.DateFormat
|
||||
import java.util.*
|
||||
|
||||
|
||||
class MessageListAdapter(private val cxt: Context, private val rows: ArrayList<Message>) :
|
||||
ArrayAdapter<Message>(cxt, R.layout.message, rows) {
|
||||
|
||||
@ -44,23 +43,22 @@ class MessageListAdapter(private val cxt: Context, private val rows: ArrayList<M
|
||||
var info: String
|
||||
val cal = GregorianCalendar()
|
||||
cal.timeInMillis = message.timeStamp
|
||||
if (isToday(message.timeStamp)) {
|
||||
val fmt = SimpleDateFormat("HH:mm")
|
||||
info = fmt.format(cal.time)
|
||||
} else {
|
||||
val fmt = SimpleDateFormat("dd/MM, HH:mm")
|
||||
info = fmt.format(cal.time)
|
||||
}
|
||||
val fmt: DateFormat
|
||||
if (isToday(message.timeStamp))
|
||||
fmt = DateFormat.getTimeInstance(DateFormat.SHORT)
|
||||
else
|
||||
fmt = DateFormat.getDateInstance(DateFormat.SHORT)
|
||||
info = fmt.format(cal.time)
|
||||
if (info.length < 6) info = "${cxt.getString(R.string.today)} $info"
|
||||
infoView.text = "$info - $peer"
|
||||
info = "$info - $peer"
|
||||
if (message.direction == R.drawable.arrow_up_red) {
|
||||
if (message.responseCode != 0)
|
||||
infoView.text = "${infoView.text} - ${cxt.getString(R.string.message_failed)}: " +
|
||||
"${message.responseCode} ${message.responseReason}"
|
||||
info = "$info - ${cxt.getString(R.string.message_failed)}: " + "${message.responseCode} ${message.responseReason}"
|
||||
else
|
||||
infoView.text = "${infoView.text} - ${cxt.getString(R.string.sending_failed)}"
|
||||
info = "$info - ${cxt.getString(R.string.sending_failed)}"
|
||||
infoView.setTextColor(ContextCompat.getColor(cxt, R.color.colorAccent))
|
||||
}
|
||||
infoView.text = info
|
||||
val textView = messageView.findViewById(R.id.text) as TextView
|
||||
textView.text = message.message
|
||||
if (message.new)
|
||||
|
||||
@ -517,6 +517,7 @@ object Utils {
|
||||
|
||||
fun randomColor(): Int {
|
||||
val rnd = Random()
|
||||
return Color.argb(255, rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256))
|
||||
return Color.argb(255, rnd.nextInt(256), rnd.nextInt(256),
|
||||
rnd.nextInt(256))
|
||||
}
|
||||
}
|
||||
|
||||
@ -20,7 +20,9 @@
|
||||
android:id="@+id/calls"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:layout_below="@id/account" >
|
||||
android:layout_below="@id/account"
|
||||
android:divider="#00000000"
|
||||
android:dividerHeight="10dp" >
|
||||
</ListView>
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
@ -8,29 +8,47 @@
|
||||
android:layout_marginTop="0dp"
|
||||
android:descendantFocusability="blocksDescendants" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/avatar"
|
||||
android:layout_width="36dp"
|
||||
android:layout_height="36dp"
|
||||
android:layout_centerVertical="true"
|
||||
android:scaleType="centerInside"
|
||||
android:background="@drawable/circle"
|
||||
android:textSize="24sp"
|
||||
android:textStyle="bold"
|
||||
android:textAllCaps="true"
|
||||
android:textColor="@android:color/white"
|
||||
android:gravity="center" >
|
||||
</TextView>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/directions"
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentStart="true"
|
||||
android:layout_centerVertical="true" />
|
||||
android:layout_toEndOf="@id/avatar"
|
||||
android:layout_marginStart="5dp"
|
||||
android:layout_centerVertical="true" >
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/time"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:focusable="false"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:layout_centerVertical="true"
|
||||
android:focusable="false"
|
||||
android:gravity="end"
|
||||
android:textAlignment="gravity"
|
||||
android:paddingTop="5dp"
|
||||
android:paddingBottom="5dp"
|
||||
android:paddingStart="0dp"
|
||||
android:paddingEnd="5dp"
|
||||
android:textSize="18sp"
|
||||
android:textSize="12sp"
|
||||
android:maxLines="1"
|
||||
android:text="" />
|
||||
android:text="" >
|
||||
</TextView>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/etc"
|
||||
@ -38,7 +56,8 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_toEndOf="@id/directions"
|
||||
android:paddingTop="10dp"
|
||||
android:text="" />
|
||||
android:text="" >
|
||||
</TextView>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/peer_uri"
|
||||
@ -55,6 +74,7 @@
|
||||
android:textSize="18sp"
|
||||
android:maxLines="1"
|
||||
android:ellipsize="end"
|
||||
android:text="" />
|
||||
android:text="" >
|
||||
</TextView>
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
@ -25,7 +25,7 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_toEndOf="@id/avatar"
|
||||
android:layout_marginStart="10dp"
|
||||
android:layout_marginStart="5dp"
|
||||
android:textSize="20sp"
|
||||
android:layout_marginBottom="6dp">
|
||||
</TextView>
|
||||
|
||||
Reference in New Issue
Block a user