- Started work on letter based avatars.
This commit is contained in:
@@ -3,6 +3,7 @@ package com.tutpro.baresip
|
||||
import android.content.Context
|
||||
import android.graphics.Color
|
||||
import android.graphics.Typeface
|
||||
import android.graphics.drawable.GradientDrawable
|
||||
import android.support.v4.content.ContextCompat
|
||||
import android.text.format.DateUtils.isToday
|
||||
import android.view.LayoutInflater
|
||||
@@ -10,6 +11,7 @@ import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.ArrayAdapter
|
||||
import android.widget.LinearLayout
|
||||
import android.widget.RelativeLayout
|
||||
import android.widget.TextView
|
||||
|
||||
import java.text.SimpleDateFormat
|
||||
@@ -21,40 +23,43 @@ 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 chatView = inflater.inflate(R.layout.chat, parent, false)
|
||||
val layout = chatView.findViewById(R.id.chat) as LinearLayout
|
||||
val lp = layout.layoutParams as LinearLayout.LayoutParams
|
||||
val rowView = inflater.inflate(R.layout.chat_row, parent, false)
|
||||
val avatarView = rowView.findViewById(R.id.avatar) as TextView
|
||||
val avatarBackground = avatarView.background as GradientDrawable
|
||||
val layout = rowView.findViewById(R.id.chat) as LinearLayout
|
||||
val lp = layout.layoutParams as RelativeLayout.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)))
|
||||
peer = Utils.uriUserPart(message.peerUri)
|
||||
else
|
||||
peer = contactName
|
||||
if (message.direction == R.drawable.arrow_down_green) {
|
||||
layout.setBackgroundResource(R.drawable.peer_bg)
|
||||
sender = peer
|
||||
val contact = ContactsActivity.findContact(message.peerUri)
|
||||
if (contact != null) {
|
||||
peer = contact.name
|
||||
avatarBackground.setColor(contact.color)
|
||||
} else {
|
||||
layout.setBackgroundResource(R.drawable.you_bg)
|
||||
sender = cxt.getString(R.string.you)
|
||||
if (Utils.uriHostPart(message.peerUri) == Utils.uriHostPart(message.aor))
|
||||
peer = Utils.uriUserPart(message.peerUri)
|
||||
else
|
||||
peer = Utils.uriAor(message.peerUri)
|
||||
avatarBackground.setColor(Color.RED)
|
||||
}
|
||||
val peerView = chatView.findViewById(R.id.peer) as TextView
|
||||
avatarView.text = "${peer[0]}"
|
||||
if (message.direction == R.drawable.arrow_down_green) {
|
||||
layout.setBackgroundResource(R.drawable.message_in_bg)
|
||||
} else {
|
||||
layout.setBackgroundResource(R.drawable.message_out_bg)
|
||||
}
|
||||
val peerView = rowView.findViewById(R.id.peer) as TextView
|
||||
peerView.setText(peer)
|
||||
val infoView = chatView.findViewById(R.id.info) as TextView
|
||||
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)) {
|
||||
val fmt = SimpleDateFormat("HH:mm")
|
||||
info = fmt.format(cal.time)
|
||||
fmt = SimpleDateFormat("HH:mm")
|
||||
} else {
|
||||
val fmt = SimpleDateFormat("dd/MM, HH:mm")
|
||||
info = fmt.format(cal.time)
|
||||
fmt = SimpleDateFormat("dd/MM, HH:mm")
|
||||
}
|
||||
if (info.length < 6) info = "${cxt.getString(R.string.today)} $info"
|
||||
infoView.text = "$info - $sender"
|
||||
infoView.text = fmt.format(cal.time)
|
||||
if (message.direction == R.drawable.arrow_up_red) {
|
||||
if (message.responseCode != 0)
|
||||
infoView.text = "${infoView.text} - ${cxt.getString(R.string.message_failed)}: " +
|
||||
@@ -63,11 +68,11 @@ class ChatListAdapter(private val cxt: Context, private var rows: ArrayList<Mess
|
||||
infoView.text = "${infoView.text} - ${cxt.getString(R.string.sending_failed)}"
|
||||
infoView.setTextColor(ContextCompat.getColor(cxt, R.color.colorAccent))
|
||||
}
|
||||
val textView = chatView.findViewById(R.id.text) as TextView
|
||||
val textView = rowView.findViewById(R.id.text) as TextView
|
||||
textView.text = message.message
|
||||
if (message.new)
|
||||
textView.setTypeface(null, Typeface.BOLD)
|
||||
return chatView
|
||||
return rowView
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ package com.tutpro.baresip
|
||||
import java.nio.charset.StandardCharsets
|
||||
import java.util.ArrayList
|
||||
|
||||
class Contact(var name: String, var uri: String) {
|
||||
class Contact(var name: String, var uri: String, var color: Int) {
|
||||
|
||||
companion object {
|
||||
|
||||
@@ -35,7 +35,7 @@ class Contact(var name: String, var uri: String) {
|
||||
uri = uri.substringAfter("<").substringBefore(">")
|
||||
// Currently no need to make baresip aware of the contact
|
||||
// Api.contact_add("\"$name\" $uri")
|
||||
BaresipService.contacts.add(Contact(name, uri))
|
||||
BaresipService.contacts.add(Contact(name, uri, Utils.randomColor()))
|
||||
}
|
||||
}
|
||||
return true
|
||||
|
||||
@@ -2,6 +2,9 @@ package com.tutpro.baresip
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Intent
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.graphics.drawable.GradientDrawable
|
||||
import android.graphics.drawable.ShapeDrawable
|
||||
import android.os.Bundle
|
||||
import android.support.v7.app.AppCompatActivity
|
||||
import android.view.Menu
|
||||
@@ -10,17 +13,21 @@ import android.widget.*
|
||||
|
||||
class ContactActivity : AppCompatActivity() {
|
||||
|
||||
lateinit var avatarView: TextView
|
||||
lateinit var nameView: EditText
|
||||
lateinit var uriView: EditText
|
||||
|
||||
internal var index = 0
|
||||
internal var new = false
|
||||
|
||||
private var index = 0
|
||||
private var color = Utils.randomColor()
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_contact)
|
||||
|
||||
avatarView = findViewById(R.id.Avatar) as TextView
|
||||
nameView = findViewById(R.id.Name) as EditText
|
||||
uriView = findViewById(R.id.Uri) as EditText
|
||||
|
||||
@@ -28,7 +35,9 @@ class ContactActivity : AppCompatActivity() {
|
||||
val uOrI: String
|
||||
|
||||
if (new) {
|
||||
setTitle(getString(R.string.new_contact))
|
||||
title = getString(R.string.new_contact)
|
||||
val background = avatarView.background as GradientDrawable
|
||||
background.setColor(color)
|
||||
nameView.setText("")
|
||||
nameView.hint = getString(R.string.contact_name)
|
||||
nameView.setSelection(nameView.text.length)
|
||||
@@ -43,6 +52,10 @@ 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)
|
||||
if (name.length > 0)
|
||||
avatarView.text = "${name[0]}"
|
||||
setTitle(name)
|
||||
nameView.setText(name)
|
||||
uriView.setText(Contact.contacts()[index].uri)
|
||||
@@ -114,7 +127,7 @@ class ContactActivity : AppCompatActivity() {
|
||||
BaresipService.activities.removeAt(0)
|
||||
return true
|
||||
} else {
|
||||
Contact.contacts().add(Contact(newName, newUri))
|
||||
Contact.contacts().add(Contact(newName, newUri, color))
|
||||
}
|
||||
} else {
|
||||
Contact.contacts()[index].uri = newUri
|
||||
|
||||
@@ -4,6 +4,7 @@ import android.app.Activity
|
||||
import android.content.Context
|
||||
import android.content.DialogInterface
|
||||
import android.content.Intent
|
||||
import android.graphics.drawable.GradientDrawable
|
||||
import android.os.Bundle
|
||||
import android.support.v7.app.AlertDialog
|
||||
import android.view.LayoutInflater
|
||||
@@ -23,6 +24,11 @@ class ContactListAdapter(private val cxt: Context, private val rows: ArrayList<C
|
||||
val row = rows[pos]
|
||||
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
|
||||
val background = avatarView.background as GradientDrawable
|
||||
background.setColor(row.color)
|
||||
if (row.name.length > 0)
|
||||
avatarView.text = "${row.name[0]}"
|
||||
val nameView = rowView.findViewById(R.id.contactName) as TextView
|
||||
nameView.text = row.name
|
||||
nameView.textSize = 20f
|
||||
|
||||
@@ -87,6 +87,14 @@ class ContactsActivity : AppCompatActivity() {
|
||||
return name
|
||||
}
|
||||
|
||||
fun findContact(uri: String): Contact? {
|
||||
for (c in Contact.contacts())
|
||||
if ((Utils.uriUserPart(c.uri) == Utils.uriUserPart(uri)) &&
|
||||
(Utils.uriHostPart(c.uri) == Utils.uriHostPart(uri)))
|
||||
return c
|
||||
return null
|
||||
}
|
||||
|
||||
fun nameExists(name: String, ignoreCase: Boolean): Boolean {
|
||||
for (c in Contact.contacts())
|
||||
if (c.name.equals(name, ignoreCase = ignoreCase)) return true
|
||||
|
||||
@@ -27,11 +27,11 @@ class MessageListAdapter(private val cxt: Context, private val rows: ArrayList<M
|
||||
val peer: String
|
||||
if (up) {
|
||||
lp.setMargins(75, 10, 0, 10)
|
||||
layout.setBackgroundResource(R.drawable.you_bg)
|
||||
layout.setBackgroundResource(R.drawable.message_out_bg)
|
||||
peer = cxt.getString(R.string.you)
|
||||
} else {
|
||||
lp.setMargins(0, 10, 75, 10)
|
||||
layout.setBackgroundResource(R.drawable.peer_bg)
|
||||
layout.setBackgroundResource(R.drawable.message_in_bg)
|
||||
val contactName = ContactsActivity.contactName(message.peerUri)
|
||||
if (contactName.startsWith("sip:") &&
|
||||
(Utils.uriHostPart(message.peerUri) == Utils.uriHostPart(message.aor)))
|
||||
|
||||
@@ -6,6 +6,7 @@ import android.content.Context
|
||||
import android.support.v7.app.AlertDialog
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageManager
|
||||
import android.graphics.Color
|
||||
import android.net.LinkAddress
|
||||
import android.os.Bundle
|
||||
import android.support.v4.app.ActivityCompat
|
||||
@@ -66,6 +67,10 @@ object Utils {
|
||||
return uri.substringAfter(":").substringBefore("@")
|
||||
}
|
||||
|
||||
fun uriAor(uri: String): String {
|
||||
return uriUserPart(uri) + "@" + uriHostPart(uri)
|
||||
}
|
||||
|
||||
fun friendlyUri(uri: String, domain: String): String {
|
||||
var u = uri
|
||||
if (uri.startsWith("<") && (uri.endsWith(">")))
|
||||
@@ -510,4 +515,8 @@ object Utils {
|
||||
Log.d("Baresip", "Dumping intent finish")
|
||||
}
|
||||
|
||||
fun randomColor(): Int {
|
||||
val rnd = Random()
|
||||
return Color.argb(255, rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user