improved contacts handling
This commit is contained in:
@@ -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 { _ ->
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user