In chat activity, replaced long click with short click and made whole message clickable
This commit is contained in:
@@ -2,7 +2,6 @@ package com.tutpro.baresip
|
|||||||
|
|
||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.DialogInterface
|
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.os.SystemClock
|
import android.os.SystemClock
|
||||||
@@ -11,10 +10,12 @@ import android.view.MenuItem
|
|||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.WindowManager
|
import android.view.WindowManager
|
||||||
import android.view.inputmethod.InputMethodManager
|
import android.view.inputmethod.InputMethodManager
|
||||||
import android.widget.*
|
import android.widget.EditText
|
||||||
|
import android.widget.ImageButton
|
||||||
|
import android.widget.ListView
|
||||||
|
import android.widget.Toast
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.lifecycle.Observer
|
import androidx.lifecycle.Observer
|
||||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
|
||||||
import com.tutpro.baresip.databinding.ActivityChatBinding
|
import com.tutpro.baresip.databinding.ActivityChatBinding
|
||||||
|
|
||||||
class ChatActivity : AppCompatActivity() {
|
class ChatActivity : AppCompatActivity() {
|
||||||
@@ -78,63 +79,21 @@ class ChatActivity : AppCompatActivity() {
|
|||||||
listView = binding.messages
|
listView = binding.messages
|
||||||
|
|
||||||
chatMessages = uaPeerMessages(aor, peerUri)
|
chatMessages = uaPeerMessages(aor, peerUri)
|
||||||
mlAdapter = MessageListAdapter(this, chatMessages)
|
mlAdapter = MessageListAdapter(this, peerUri, chatMessages)
|
||||||
|
|
||||||
val messagesObserver = Observer<Long> { mlAdapter.notifyDataSetChanged() }
|
val messagesObserver = Observer<Long> {
|
||||||
|
chatMessages.clear()
|
||||||
|
chatMessages.addAll(uaPeerMessages(aor, peerUri))
|
||||||
|
mlAdapter.notifyDataSetChanged()
|
||||||
|
}
|
||||||
BaresipService.messageUpdate.observe(this, messagesObserver)
|
BaresipService.messageUpdate.observe(this, messagesObserver)
|
||||||
|
|
||||||
listView.adapter = mlAdapter
|
listView.adapter = mlAdapter
|
||||||
listView.isLongClickable = true
|
//listView.isLongClickable = true
|
||||||
val footerView = View(applicationContext)
|
val footerView = View(applicationContext)
|
||||||
listView.addFooterView(footerView)
|
listView.addFooterView(footerView)
|
||||||
listView.smoothScrollToPosition(mlAdapter.count - 1)
|
listView.smoothScrollToPosition(mlAdapter.count - 1)
|
||||||
|
|
||||||
listView.onItemLongClickListener = AdapterView.OnItemLongClickListener { _, _, pos, _ ->
|
|
||||||
val dialogClickListener = DialogInterface.OnClickListener { _, which ->
|
|
||||||
when (which) {
|
|
||||||
DialogInterface.BUTTON_POSITIVE -> {
|
|
||||||
val i = Intent(this, ContactActivity::class.java)
|
|
||||||
val b = Bundle()
|
|
||||||
b.putBoolean("new", true)
|
|
||||||
b.putString("uri", peerUri)
|
|
||||||
i.putExtras(b)
|
|
||||||
startActivity(i)
|
|
||||||
}
|
|
||||||
DialogInterface.BUTTON_NEGATIVE -> {
|
|
||||||
Message.messages().remove(chatMessages[pos])
|
|
||||||
chatMessages.removeAt(pos)
|
|
||||||
mlAdapter.notifyDataSetChanged()
|
|
||||||
if (chatMessages.size == 0) {
|
|
||||||
listView.removeFooterView(footerView)
|
|
||||||
}
|
|
||||||
Message.save()
|
|
||||||
}
|
|
||||||
DialogInterface.BUTTON_NEUTRAL -> {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
val builder = MaterialAlertDialogBuilder(this@ChatActivity, R.style.AlertDialogTheme)
|
|
||||||
if (Contact.contactName(peerUri) == peerUri)
|
|
||||||
with (builder) {
|
|
||||||
setTitle(R.string.confirmation)
|
|
||||||
setMessage(String.format(getString(R.string.long_message_question),
|
|
||||||
chatPeer))
|
|
||||||
setNeutralButton(getString(R.string.cancel), dialogClickListener)
|
|
||||||
setNegativeButton(getString(R.string.delete), dialogClickListener)
|
|
||||||
setPositiveButton(getString(R.string.add_contact), dialogClickListener)
|
|
||||||
show()
|
|
||||||
}
|
|
||||||
else
|
|
||||||
with (builder) {
|
|
||||||
setTitle(R.string.confirmation)
|
|
||||||
setMessage(getText(R.string.short_message_question))
|
|
||||||
setNeutralButton(getString(R.string.cancel), dialogClickListener)
|
|
||||||
setNegativeButton(getString(R.string.delete), dialogClickListener)
|
|
||||||
show()
|
|
||||||
}
|
|
||||||
true
|
|
||||||
}
|
|
||||||
|
|
||||||
newMessage = binding.text
|
newMessage = binding.text
|
||||||
newMessage.onFocusChangeListener = View.OnFocusChangeListener { _, hasFocus ->
|
newMessage.onFocusChangeListener = View.OnFocusChangeListener { _, hasFocus ->
|
||||||
if (hasFocus) {
|
if (hasFocus) {
|
||||||
@@ -185,10 +144,9 @@ class ChatActivity : AppCompatActivity() {
|
|||||||
newMessage.requestFocus()
|
newMessage.requestFocus()
|
||||||
BaresipService.chatTexts.remove("$aor::$peerUri")
|
BaresipService.chatTexts.remove("$aor::$peerUri")
|
||||||
}
|
}
|
||||||
mlAdapter.clear()
|
chatMessages.clear()
|
||||||
chatMessages = uaPeerMessages(aor, peerUri)
|
chatMessages.addAll(uaPeerMessages(aor, peerUri))
|
||||||
mlAdapter = MessageListAdapter(this, chatMessages)
|
mlAdapter.notifyDataSetChanged()
|
||||||
listView.adapter = mlAdapter
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onPause() {
|
override fun onPause() {
|
||||||
|
|||||||
@@ -1,18 +1,23 @@
|
|||||||
package com.tutpro.baresip
|
package com.tutpro.baresip
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.content.DialogInterface
|
||||||
|
import android.content.Intent
|
||||||
import android.graphics.Typeface
|
import android.graphics.Typeface
|
||||||
import androidx.core.content.ContextCompat
|
import android.os.Bundle
|
||||||
import android.text.format.DateUtils.isToday
|
import android.text.format.DateUtils.isToday
|
||||||
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.*
|
import android.widget.ArrayAdapter
|
||||||
|
import android.widget.LinearLayout
|
||||||
|
import android.widget.TextView
|
||||||
|
import androidx.core.content.ContextCompat
|
||||||
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||||
import java.text.DateFormat
|
import java.text.DateFormat
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
class MessageListAdapter(private val ctx: Context, private val rows: ArrayList<Message>) :
|
class MessageListAdapter(private val ctx: Context, private val peerUri: String, private val rows: ArrayList<Message>) :
|
||||||
ArrayAdapter<Message>(ctx, R.layout.message, rows) {
|
ArrayAdapter<Message>(ctx, R.layout.message, rows) {
|
||||||
|
|
||||||
private val layoutInflater = LayoutInflater.from(context)
|
private val layoutInflater = LayoutInflater.from(context)
|
||||||
@@ -37,6 +42,56 @@ class MessageListAdapter(private val ctx: Context, private val rows: ArrayList<M
|
|||||||
viewHolder = rowView.tag as ViewHolder
|
viewHolder = rowView.tag as ViewHolder
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val listener = View.OnClickListener {
|
||||||
|
val dialogClickListener = DialogInterface.OnClickListener { _, which ->
|
||||||
|
when (which) {
|
||||||
|
DialogInterface.BUTTON_POSITIVE -> {
|
||||||
|
val i = Intent(ctx, ContactActivity::class.java)
|
||||||
|
val b = Bundle()
|
||||||
|
b.putBoolean("new", true)
|
||||||
|
b.putString("uri", peerUri)
|
||||||
|
i.putExtras(b)
|
||||||
|
ctx.startActivity(i)
|
||||||
|
}
|
||||||
|
DialogInterface.BUTTON_NEGATIVE -> {
|
||||||
|
Message.messages().remove(rows[position])
|
||||||
|
Message.save()
|
||||||
|
rows.removeAt(position)
|
||||||
|
this.notifyDataSetChanged()
|
||||||
|
//if (rows.size == 0) {
|
||||||
|
// listView.removeFooterView(footerView)
|
||||||
|
//}
|
||||||
|
}
|
||||||
|
DialogInterface.BUTTON_NEUTRAL -> {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
val builder = MaterialAlertDialogBuilder(ctx, R.style.AlertDialogTheme)
|
||||||
|
val chatPeer = Contact.contactName(peerUri)
|
||||||
|
if (Contact.contactName(peerUri) == peerUri)
|
||||||
|
with (builder) {
|
||||||
|
setTitle(R.string.confirmation)
|
||||||
|
setMessage(String.format(ctx.getString(R.string.long_message_question),
|
||||||
|
chatPeer))
|
||||||
|
setNeutralButton(ctx.getString(R.string.cancel), dialogClickListener)
|
||||||
|
setNegativeButton(ctx.getString(R.string.delete), dialogClickListener)
|
||||||
|
setPositiveButton(ctx.getString(R.string.add_contact), dialogClickListener)
|
||||||
|
show()
|
||||||
|
}
|
||||||
|
else
|
||||||
|
with (builder) {
|
||||||
|
setTitle(R.string.confirmation)
|
||||||
|
setMessage(ctx.getText(R.string.short_message_question))
|
||||||
|
setNeutralButton(ctx.getString(R.string.cancel), dialogClickListener)
|
||||||
|
setNegativeButton(ctx.getString(R.string.delete), dialogClickListener)
|
||||||
|
show()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
viewHolder.layoutView.setOnClickListener(listener)
|
||||||
|
viewHolder.infoView.setOnClickListener(listener)
|
||||||
|
viewHolder.textView.setOnClickListener(listener)
|
||||||
|
|
||||||
val message = rows[position]
|
val message = rows[position]
|
||||||
|
|
||||||
val down = (message.direction == R.drawable.arrow_down_green) ||
|
val down = (message.direction == R.drawable.arrow_down_green) ||
|
||||||
|
|||||||
@@ -10,6 +10,8 @@
|
|||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
android:clickable="true"
|
||||||
|
android:focusable="true"
|
||||||
tools:ignore="UselessParent" >
|
tools:ignore="UselessParent" >
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
@@ -19,6 +21,8 @@
|
|||||||
android:layout_marginTop="5dp"
|
android:layout_marginTop="5dp"
|
||||||
android:layout_marginStart="5dp"
|
android:layout_marginStart="5dp"
|
||||||
android:textSize="12sp"
|
android:textSize="12sp"
|
||||||
|
android:clickable="true"
|
||||||
|
android:focusable="true"
|
||||||
android:text="" >
|
android:text="" >
|
||||||
</TextView>
|
</TextView>
|
||||||
|
|
||||||
@@ -31,6 +35,8 @@
|
|||||||
android:layout_marginBottom="5dp"
|
android:layout_marginBottom="5dp"
|
||||||
android:textSize="16sp"
|
android:textSize="16sp"
|
||||||
android:textIsSelectable="true"
|
android:textIsSelectable="true"
|
||||||
|
android:clickable="true"
|
||||||
|
android:focusable="true"
|
||||||
android:text="" >
|
android:text="" >
|
||||||
</TextView>
|
</TextView>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user