mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-04-20 22:23:37 +00:00
Testing click deletion of messages. (Messages still stored after sending new message or connecting to radio)
This commit is contained in:
parent
bdfb1acca9
commit
c08c652d97
2 changed files with 36 additions and 3 deletions
|
|
@ -46,6 +46,13 @@ class MessagesState(private val ui: UIViewModel) : Logging {
|
|||
messages.value = messagesList
|
||||
}
|
||||
|
||||
fun removeMessage(m: DataPacket) {
|
||||
debug("Removing message from view id=${m.id}")
|
||||
|
||||
messagesList.remove(m)
|
||||
messages.value = messagesList;
|
||||
}
|
||||
|
||||
fun updateStatus(id: Int, status: MessageStatus) {
|
||||
// Super inefficent but this is rare
|
||||
debug("Handling message status change $id: $status")
|
||||
|
|
@ -80,4 +87,20 @@ class MessagesState(private val ui: UIViewModel) : Logging {
|
|||
// FIXME - why is the first time we are called p is already in the list at this point?
|
||||
addMessage(p)
|
||||
}
|
||||
|
||||
fun deleteMessage(str: String, dest: String = DataPacket.ID_BROADCAST) {
|
||||
val service = ui.meshService
|
||||
val p = DataPacket(str, dest)
|
||||
|
||||
if (service != null) {
|
||||
try {
|
||||
service.send(p)
|
||||
} catch (ex: RemoteException) {
|
||||
p.errorMessage = "Error: ${ex.message}"
|
||||
}
|
||||
} else {
|
||||
p.errorMessage = "Error: No Mesh service"
|
||||
}
|
||||
removeMessage(p)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ class MessagesFragment : ScreenFragment("Messages"), Logging {
|
|||
private val binding get() = _binding!!
|
||||
|
||||
private val model: UIViewModel by activityViewModels()
|
||||
|
||||
|
||||
// Allows textMultiline with IME_ACTION_SEND
|
||||
fun EditText.onActionSend(func: () -> Unit) {
|
||||
setImeOptions(EditorInfo.IME_ACTION_SEND)
|
||||
|
|
@ -164,6 +164,10 @@ class MessagesFragment : ScreenFragment("Messages"), Logging {
|
|||
// Set cardview offset and color.
|
||||
val marginParams = holder.card.layoutParams as ViewGroup.MarginLayoutParams
|
||||
val messageOffset = resources.getDimensionPixelOffset(R.dimen.message_offset)
|
||||
holder.card.setOnLongClickListener {
|
||||
this.onLongCLick(position)
|
||||
true
|
||||
}
|
||||
if (isMe) {
|
||||
marginParams.leftMargin = messageOffset
|
||||
marginParams.rightMargin = 0
|
||||
|
|
@ -232,6 +236,12 @@ class MessagesFragment : ScreenFragment("Messages"), Logging {
|
|||
if (itemCount != 0)
|
||||
binding.messageListView.scrollToPosition(itemCount - 1)
|
||||
}
|
||||
|
||||
fun onLongCLick(position: Int) {
|
||||
messages = messages.filter { x -> x != messages[position] }.toTypedArray()
|
||||
onMessagesChanged(messages.toList())
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
override fun onCreateView(
|
||||
|
|
@ -282,8 +292,8 @@ class MessagesFragment : ScreenFragment("Messages"), Logging {
|
|||
binding.textInputLayout.isEnabled =
|
||||
model.isConnected.value != MeshService.ConnectionState.DISCONNECTED
|
||||
|
||||
// Just being connected is enough to allow sending texts I think
|
||||
// && model.nodeDB.myId.value != null && model.radioConfig.value != null
|
||||
// Just being connected is enough to allow sending texts I think
|
||||
// && model.nodeDB.myId.value != null && model.radioConfig.value != null
|
||||
}
|
||||
|
||||
model.isConnected.observe(viewLifecycleOwner, Observer { _ ->
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue