mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-04-20 22:23:37 +00:00
Added popup to prompt delete when user long presses
This commit is contained in:
parent
929d81cec2
commit
bc0c682eea
2 changed files with 69 additions and 1 deletions
|
|
@ -1,5 +1,9 @@
|
||||||
package com.geeksville.mesh.ui
|
package com.geeksville.mesh.ui
|
||||||
|
|
||||||
|
import android.app.AlertDialog
|
||||||
|
import android.app.Dialog
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.DialogInterface
|
||||||
import android.graphics.Color
|
import android.graphics.Color
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.text.InputType
|
import android.text.InputType
|
||||||
|
|
@ -12,6 +16,7 @@ import android.widget.ImageView
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
import androidx.cardview.widget.CardView
|
import androidx.cardview.widget.CardView
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
|
import androidx.fragment.app.DialogFragment
|
||||||
import androidx.fragment.app.activityViewModels
|
import androidx.fragment.app.activityViewModels
|
||||||
import androidx.lifecycle.Observer
|
import androidx.lifecycle.Observer
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
|
|
@ -25,6 +30,7 @@ import com.geeksville.mesh.databinding.MessagesFragmentBinding
|
||||||
import com.geeksville.mesh.model.UIViewModel
|
import com.geeksville.mesh.model.UIViewModel
|
||||||
import com.geeksville.mesh.service.MeshService
|
import com.geeksville.mesh.service.MeshService
|
||||||
import com.google.android.material.chip.Chip
|
import com.google.android.material.chip.Chip
|
||||||
|
import kotlinx.serialization.descriptors.buildSerialDescriptor
|
||||||
import java.text.DateFormat
|
import java.text.DateFormat
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
|
|
@ -40,6 +46,54 @@ fun EditText.on(actionId: Int, func: () -> Unit) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//class DeleteMessageDialog : DialogFragment() {
|
||||||
|
// private lateinit var listener: NoticeDialogListener
|
||||||
|
//
|
||||||
|
// interface NoticeDialogListener {
|
||||||
|
// fun onDialogPositiveClick(dialog: DialogFragment)
|
||||||
|
// fun onDialogNegativeClick(dialog: DialogFragment)
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// // Override the Fragment.onAttach() method to instantiate the NoticeDialogListener
|
||||||
|
// override fun onAttach(context: Context) {
|
||||||
|
// super.onAttach(context)
|
||||||
|
// // Verify that the host activity implements the callback interface
|
||||||
|
// try {
|
||||||
|
// // Instantiate the NoticeDialogListener so we can send events to the host
|
||||||
|
// listener = context as NoticeDialogListener
|
||||||
|
// } catch (e: ClassCastException) {
|
||||||
|
// // The activity doesn't implement the interface, throw exception
|
||||||
|
// throw ClassCastException(
|
||||||
|
// (context.toString() +
|
||||||
|
// " must implement NoticeDialogListener")
|
||||||
|
// )
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//}
|
||||||
|
|
||||||
|
class DeleteMessageDialog : DialogFragment() {
|
||||||
|
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
||||||
|
return activity?.let {
|
||||||
|
|
||||||
|
var delete = false;
|
||||||
|
val builder = AlertDialog.Builder(it)
|
||||||
|
builder.setMessage(R.string.delete_selected_message)
|
||||||
|
.setPositiveButton(R.string.delete,
|
||||||
|
DialogInterface.OnClickListener { dialog, id ->
|
||||||
|
delete = true
|
||||||
|
})
|
||||||
|
.setNegativeButton(R.string.cancel,
|
||||||
|
DialogInterface.OnClickListener { dialog, id ->
|
||||||
|
delete = false
|
||||||
|
})
|
||||||
|
// Create the AlertDialog object and return it
|
||||||
|
builder.create()
|
||||||
|
} ?: throw IllegalStateException("Activity cannot be null")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class MessagesFragment : ScreenFragment("Messages"), Logging {
|
class MessagesFragment : ScreenFragment("Messages"), Logging {
|
||||||
|
|
||||||
private var _binding: MessagesFragmentBinding? = null
|
private var _binding: MessagesFragmentBinding? = null
|
||||||
|
|
@ -165,7 +219,19 @@ class MessagesFragment : ScreenFragment("Messages"), Logging {
|
||||||
val marginParams = holder.card.layoutParams as ViewGroup.MarginLayoutParams
|
val marginParams = holder.card.layoutParams as ViewGroup.MarginLayoutParams
|
||||||
val messageOffset = resources.getDimensionPixelOffset(R.dimen.message_offset)
|
val messageOffset = resources.getDimensionPixelOffset(R.dimen.message_offset)
|
||||||
holder.card.setOnLongClickListener {
|
holder.card.setOnLongClickListener {
|
||||||
model.messagesState.deleteMessage(messages[position], position)
|
val deleteMessageDialog = AlertDialog.Builder(context)
|
||||||
|
// deleteMessageDialog.setTitle(R.string.delete_selected_message)
|
||||||
|
deleteMessageDialog.setMessage(R.string.delete_selected_message)
|
||||||
|
deleteMessageDialog.setPositiveButton(
|
||||||
|
R.string.delete
|
||||||
|
) { _, _ ->
|
||||||
|
model.messagesState.deleteMessage((messages[position]), position)
|
||||||
|
}
|
||||||
|
deleteMessageDialog.setNegativeButton(R.string.cancel,
|
||||||
|
DialogInterface.OnClickListener { _, _ ->
|
||||||
|
})
|
||||||
|
deleteMessageDialog.create()
|
||||||
|
deleteMessageDialog.show()
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
if (isMe) {
|
if (isMe) {
|
||||||
|
|
|
||||||
|
|
@ -120,4 +120,6 @@
|
||||||
<string name="why_camera_required">We must be granted access to the camera to read QR codes. No pictures or videos will be saved.</string>
|
<string name="why_camera_required">We must be granted access to the camera to read QR codes. No pictures or videos will be saved.</string>
|
||||||
<string name="modem_config_slow_short">Short Range / Slow</string>
|
<string name="modem_config_slow_short">Short Range / Slow</string>
|
||||||
<string name="modem_config_slow_medium">Medium Range / Slow</string>
|
<string name="modem_config_slow_medium">Medium Range / Slow</string>
|
||||||
|
<string name="delete_selected_message">Delete selected message?</string>
|
||||||
|
<string name="delete">Delete</string>
|
||||||
</resources>
|
</resources>
|
||||||
Loading…
Add table
Add a link
Reference in a new issue