improved contact list by adding edit button and made possible to click
contact for a call or message
This commit is contained in:
@ -23,7 +23,6 @@ import java.util.GregorianCalendar
|
||||
class CallsActivity : AppCompatActivity() {
|
||||
|
||||
internal var uaHistory = ArrayList<CallRow>()
|
||||
internal var aor: String = ""
|
||||
|
||||
public override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
@ -31,7 +30,7 @@ class CallsActivity : AppCompatActivity() {
|
||||
|
||||
val listview = findViewById(R.id.history) as ListView
|
||||
|
||||
aor = intent.extras.getString("aor")
|
||||
val aor = intent.extras.getString("aor")
|
||||
aorGenerateHistory(aor)
|
||||
|
||||
val adapter = CallListAdapter(this, uaHistory)
|
||||
|
||||
@ -2,6 +2,7 @@ package com.tutpro.baresip
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Context
|
||||
import android.content.DialogInterface
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.support.v7.app.AlertDialog
|
||||
@ -9,13 +10,15 @@ import android.util.Log
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.AdapterView
|
||||
import android.widget.ArrayAdapter
|
||||
import android.widget.ImageButton
|
||||
import android.widget.TextView
|
||||
|
||||
import java.util.*
|
||||
|
||||
class ContactListAdapter(private val cxt: Context, private val rows: ArrayList<Contact>) :
|
||||
class ContactListAdapter(private val cxt: Context, private val rows: ArrayList<Contact>,
|
||||
private val aor: String) :
|
||||
ArrayAdapter<Contact>(cxt, R.layout.contact_row, rows) {
|
||||
|
||||
override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
|
||||
@ -26,7 +29,37 @@ class ContactListAdapter(private val cxt: Context, private val rows: ArrayList<C
|
||||
nameView.text = row.name
|
||||
nameView.textSize = 20f
|
||||
nameView.setPadding(6, 6, 0, 6)
|
||||
nameView.setOnClickListener { _ ->
|
||||
if (aor != "") {
|
||||
nameView.setOnClickListener {_ ->
|
||||
val i = Intent(cxt, MessageActivity::class.java)
|
||||
val b = Bundle()
|
||||
b.putString("aor", aor)
|
||||
b.putString("peer", ContactsActivity.contacts[position].uri)
|
||||
i.putExtras(b)
|
||||
(cxt as Activity).startActivityForResult(i, MainActivity.MESSAGE_CODE)
|
||||
}
|
||||
}
|
||||
nameView.setOnLongClickListener { _ ->
|
||||
val dialogClickListener = DialogInterface.OnClickListener { _, which ->
|
||||
when (which) {
|
||||
DialogInterface.BUTTON_NEGATIVE -> {
|
||||
ContactsActivity.contacts.removeAt(position)
|
||||
ContactsActivity.saveContacts()
|
||||
this.notifyDataSetChanged()
|
||||
}
|
||||
DialogInterface.BUTTON_POSITIVE -> {
|
||||
}
|
||||
}
|
||||
}
|
||||
val builder = AlertDialog.Builder(cxt, R.style.Theme_AppCompat)
|
||||
builder.setMessage("Do you want to delete ${ContactsActivity.contacts[position].name}?")
|
||||
.setPositiveButton("Cancel", dialogClickListener)
|
||||
.setNegativeButton("Delete Contact", dialogClickListener)
|
||||
.show()
|
||||
true
|
||||
}
|
||||
val actionView = rowView.findViewById(R.id.action) as ImageButton
|
||||
actionView.setOnClickListener { _ ->
|
||||
val i = Intent(cxt, ContactActivity::class.java)
|
||||
val b = Bundle()
|
||||
b.putBoolean("new", false)
|
||||
|
||||
@ -23,8 +23,10 @@ class ContactsActivity : AppCompatActivity() {
|
||||
setContentView(R.layout.activity_contacts)
|
||||
|
||||
val listView = findViewById(R.id.contacts) as ListView
|
||||
|
||||
Log.d("Baresip", "Got ${contacts.size} contacts")
|
||||
clAdapter = ContactListAdapter(this, contacts)
|
||||
val aor = intent.extras.getString("aor")
|
||||
clAdapter = ContactListAdapter(this, contacts, aor)
|
||||
listView.adapter = clAdapter
|
||||
|
||||
listView.onItemLongClickListener = AdapterView.OnItemLongClickListener { _, _, pos, _ ->
|
||||
|
||||
@ -292,6 +292,12 @@ class MainActivity : AppCompatActivity() {
|
||||
|
||||
contactsButton.setOnClickListener {
|
||||
val i = Intent(this@MainActivity, ContactsActivity::class.java)
|
||||
val b = Bundle()
|
||||
if (aorSpinner.selectedItemPosition >= 0)
|
||||
b.putString("aor", uas[aorSpinner.selectedItemPosition].account.aor)
|
||||
else
|
||||
b.putString("aor", "")
|
||||
i.putExtras(b)
|
||||
startActivityForResult(i, CONTACTS_CODE)
|
||||
}
|
||||
|
||||
@ -787,11 +793,6 @@ class MainActivity : AppCompatActivity() {
|
||||
startActivityForResult(i, ACCOUNTS_CODE)
|
||||
return true
|
||||
}
|
||||
R.id.contacts -> {
|
||||
i = Intent(this, ContactsActivity::class.java)
|
||||
startActivityForResult(i, CONTACTS_CODE)
|
||||
return true
|
||||
}
|
||||
R.id.config -> {
|
||||
i = Intent(this, EditConfigActivity::class.java)
|
||||
startActivityForResult(i, EDIT_CONFIG_CODE)
|
||||
|
||||
@ -21,7 +21,7 @@
|
||||
android:layout_alignParentEnd="true"
|
||||
android:paddingTop="5dp"
|
||||
android:paddingBottom="5dp"
|
||||
android:layout_marginLeft="6dp"
|
||||
android:layout_marginStart="6dp"
|
||||
android:icon="@android:drawable/ic_menu_delete"
|
||||
android:scaleType="centerCrop" >
|
||||
</ImageButton>
|
||||
|
||||
@ -7,7 +7,7 @@
|
||||
android:paddingLeft="@dimen/activity_horizontal_margin"
|
||||
android:paddingRight="@dimen/activity_horizontal_margin"
|
||||
android:paddingTop="@dimen/activity_vertical_margin"
|
||||
tools:context="com.tutpro.baresip.HistoryActivity">
|
||||
tools:context=".CallsActivity">
|
||||
|
||||
<ListView
|
||||
android:id="@+id/history"
|
||||
|
||||
@ -2,7 +2,8 @@
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/contactRow"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" >
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/contactName"
|
||||
@ -13,4 +14,18 @@
|
||||
android:layout_marginBottom="6dp">
|
||||
</TextView>
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/action"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:paddingTop="5dp"
|
||||
android:paddingBottom="5dp"
|
||||
android:layout_marginStart="6dp"
|
||||
android:src="@drawable/edit"
|
||||
android:background="@null"
|
||||
android:scaleType="centerCrop" >
|
||||
</ImageButton>
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
Reference in New Issue
Block a user