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