improved contacts handling
This commit is contained in:
@ -6,11 +6,9 @@ import android.content.DialogInterface
|
|||||||
import android.content.Intent
|
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.util.Log
|
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.widget.AdapterView
|
|
||||||
import android.widget.ArrayAdapter
|
import android.widget.ArrayAdapter
|
||||||
import android.widget.ImageButton
|
import android.widget.ImageButton
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
@ -30,13 +28,38 @@ class ContactListAdapter(private val cxt: Context, private val rows: ArrayList<C
|
|||||||
nameView.textSize = 20f
|
nameView.textSize = 20f
|
||||||
nameView.setPadding(6, 6, 0, 6)
|
nameView.setPadding(6, 6, 0, 6)
|
||||||
if (aor != "") {
|
if (aor != "") {
|
||||||
nameView.setOnClickListener {_ ->
|
nameView.setOnClickListener { _ ->
|
||||||
val i = Intent(cxt, ChatActivity::class.java)
|
val dialogClickListener = DialogInterface.OnClickListener { _, which ->
|
||||||
val b = Bundle()
|
when (which) {
|
||||||
b.putString("aor", aor)
|
DialogInterface.BUTTON_NEUTRAL -> {
|
||||||
b.putString("peer", ContactsActivity.contacts[position].uri)
|
val intent = Intent(cxt, MainActivity::class.java)
|
||||||
i.putExtras(b)
|
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK or
|
||||||
(cxt as Activity).startActivityForResult(i, MainActivity.MESSAGE_CODE)
|
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 { _ ->
|
nameView.setOnLongClickListener { _ ->
|
||||||
|
|||||||
@ -3,11 +3,9 @@ package com.tutpro.baresip
|
|||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
import android.content.*
|
import android.content.*
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.support.v7.app.AlertDialog
|
|
||||||
import android.support.v7.app.AppCompatActivity
|
import android.support.v7.app.AppCompatActivity
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
import android.widget.AdapterView
|
|
||||||
import android.widget.ImageButton
|
import android.widget.ImageButton
|
||||||
import android.widget.ListView
|
import android.widget.ListView
|
||||||
|
|
||||||
@ -28,27 +26,7 @@ class ContactsActivity : AppCompatActivity() {
|
|||||||
val aor = intent.extras.getString("aor")
|
val aor = intent.extras.getString("aor")
|
||||||
clAdapter = ContactListAdapter(this, contacts, aor)
|
clAdapter = ContactListAdapter(this, contacts, aor)
|
||||||
listView.adapter = clAdapter
|
listView.adapter = clAdapter
|
||||||
|
listView.isLongClickable = true
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
||||||
val plusButton = findViewById(R.id.plusButton) as ImageButton
|
val plusButton = findViewById(R.id.plusButton) as ImageButton
|
||||||
plusButton.setOnClickListener {
|
plusButton.setOnClickListener {
|
||||||
@ -62,10 +40,7 @@ class ContactsActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||||
if (resultCode == RESULT_OK) {
|
if (resultCode == RESULT_OK) clAdapter.notifyDataSetChanged()
|
||||||
Log.d("Baresip", "Notifying clAdapter")
|
|
||||||
clAdapter.notifyDataSetChanged()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||||
|
|||||||
@ -14,7 +14,7 @@
|
|||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:transcriptMode="alwaysScroll"
|
android:transcriptMode="alwaysScroll"
|
||||||
android:layout_above="@id/text">
|
android:layout_above="@id/text" >
|
||||||
</ListView>
|
</ListView>
|
||||||
|
|
||||||
<EditText
|
<EditText
|
||||||
|
|||||||
@ -12,7 +12,9 @@
|
|||||||
<ListView
|
<ListView
|
||||||
android:id="@+id/contacts"
|
android:id="@+id/contacts"
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="fill_parent" />
|
android:layout_height="match_parent"
|
||||||
|
android:layout_above="@id/plusButton" >
|
||||||
|
</ListView>
|
||||||
|
|
||||||
<ImageButton
|
<ImageButton
|
||||||
android:id="@+id/plusButton"
|
android:id="@+id/plusButton"
|
||||||
|
|||||||
@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/contactName"
|
android:id="@+id/contactName"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_centerVertical="true"
|
android:layout_centerVertical="true"
|
||||||
android:textSize="20sp"
|
android:textSize="20sp"
|
||||||
@ -22,7 +22,7 @@
|
|||||||
android:layout_alignParentEnd="true"
|
android:layout_alignParentEnd="true"
|
||||||
android:paddingTop="5dp"
|
android:paddingTop="5dp"
|
||||||
android:paddingBottom="5dp"
|
android:paddingBottom="5dp"
|
||||||
android:layout_marginStart="6dp"
|
android:layout_marginStart="10dp"
|
||||||
android:src="@drawable/edit"
|
android:src="@drawable/edit"
|
||||||
android:background="@null"
|
android:background="@null"
|
||||||
android:scaleType="centerCrop" >
|
android:scaleType="centerCrop" >
|
||||||
|
|||||||
Reference in New Issue
Block a user