improved contacts handling

This commit is contained in:
Juha Heinanen
2018-11-18 15:30:15 +02:00
parent a5e22786c4
commit 2f55f5729b
5 changed files with 40 additions and 40 deletions

View File

@ -6,11 +6,9 @@ import android.content.DialogInterface
import android.content.Intent
import android.os.Bundle
import android.support.v7.app.AlertDialog
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
@ -30,13 +28,38 @@ class ContactListAdapter(private val cxt: Context, private val rows: ArrayList<C
nameView.textSize = 20f
nameView.setPadding(6, 6, 0, 6)
if (aor != "") {
nameView.setOnClickListener {_ ->
val i = Intent(cxt, ChatActivity::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.setOnClickListener { _ ->
val dialogClickListener = DialogInterface.OnClickListener { _, which ->
when (which) {
DialogInterface.BUTTON_NEUTRAL -> {
val intent = Intent(cxt, MainActivity::class.java)
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK or
Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_CLEAR_TOP)
intent.putExtra("action", "call")
intent.putExtra("uap", Account.findUa(aor)!!.uap)
intent.putExtra("peer", ContactsActivity.contacts[position].uri)
(cxt as Activity).startActivity(intent)
}
DialogInterface.BUTTON_NEGATIVE -> {
val intent = Intent(cxt, ChatsActivity::class.java)
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
val b = Bundle()
b.putString("aor", aor)
b.putString("peer", ContactsActivity.contacts[position].uri)
intent.putExtras(b)
(cxt as Activity).startActivity(intent)
}
DialogInterface.BUTTON_POSITIVE -> {
}
}
}
val builder = AlertDialog.Builder(cxt, R.style.Theme_AppCompat)
builder.setMessage("Do you want to call or send message to " +
"${ContactsActivity.contacts[position].name}?")
.setNeutralButton("Call", dialogClickListener)
.setNegativeButton("Send Message", dialogClickListener)
.setPositiveButton("Cancel", dialogClickListener)
.show()
}
}
nameView.setOnLongClickListener { _ ->

View File

@ -3,11 +3,9 @@ package com.tutpro.baresip
import android.app.Activity
import android.content.*
import android.os.Bundle
import android.support.v7.app.AlertDialog
import android.support.v7.app.AppCompatActivity
import android.util.Log
import android.view.MenuItem
import android.widget.AdapterView
import android.widget.ImageButton
import android.widget.ListView
@ -28,27 +26,7 @@ class ContactsActivity : AppCompatActivity() {
val aor = intent.extras.getString("aor")
clAdapter = ContactListAdapter(this, contacts, aor)
listView.adapter = clAdapter
listView.onItemLongClickListener = AdapterView.OnItemLongClickListener { _, _, pos, _ ->
val dialogClickListener = DialogInterface.OnClickListener { _, which ->
when (which) {
DialogInterface.BUTTON_NEGATIVE -> {
ContactsActivity.contacts.removeAt(pos)
ContactsActivity.saveContacts()
clAdapter.notifyDataSetChanged()
}
DialogInterface.BUTTON_POSITIVE -> {
}
}
}
val builder = AlertDialog.Builder(this@ContactsActivity,
R.style.Theme_AppCompat)
builder.setMessage("Do you want to delete ${contacts[pos].name}?")
.setPositiveButton("Cancel", dialogClickListener)
.setNegativeButton("Delete Contact", dialogClickListener)
.show()
true
}
listView.isLongClickable = true
val plusButton = findViewById(R.id.plusButton) as ImageButton
plusButton.setOnClickListener {
@ -62,10 +40,7 @@ class ContactsActivity : AppCompatActivity() {
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
if (resultCode == RESULT_OK) {
Log.d("Baresip", "Notifying clAdapter")
clAdapter.notifyDataSetChanged()
}
if (resultCode == RESULT_OK) clAdapter.notifyDataSetChanged()
}
override fun onOptionsItemSelected(item: MenuItem): Boolean {

View File

@ -14,7 +14,7 @@
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:transcriptMode="alwaysScroll"
android:layout_above="@id/text">
android:layout_above="@id/text" >
</ListView>
<EditText

View File

@ -12,7 +12,9 @@
<ListView
android:id="@+id/contacts"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
android:layout_height="match_parent"
android:layout_above="@id/plusButton" >
</ListView>
<ImageButton
android:id="@+id/plusButton"

View File

@ -7,7 +7,7 @@
<TextView
android:id="@+id/contactName"
android:layout_width="wrap_content"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:textSize="20sp"
@ -22,7 +22,7 @@
android:layout_alignParentEnd="true"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:layout_marginStart="6dp"
android:layout_marginStart="10dp"
android:src="@drawable/edit"
android:background="@null"
android:scaleType="centerCrop" >