Intercepts backhandler to save drafts

This commit is contained in:
Vitor Pamplona
2025-08-27 08:56:40 -04:00
parent 8624dcf2d4
commit 56dec11901
7 changed files with 63 additions and 0 deletions

View File

@@ -21,6 +21,7 @@
package com.vitorpamplona.amethyst.ui.note.nip22Comments
import android.net.Uri
import androidx.activity.compose.BackHandler
import androidx.compose.foundation.horizontalScroll
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
@@ -135,6 +136,14 @@ fun GenericCommentPostScreen(
) {
WatchAndLoadMyEmojiList(accountViewModel)
BackHandler {
accountViewModel.runIOCatching {
postViewModel.sendDraftSync()
postViewModel.cancel()
}
nav.popBack()
}
Scaffold(
topBar = {
PostingTopBar(

View File

@@ -21,6 +21,7 @@
package com.vitorpamplona.amethyst.ui.screen.loggedIn.chats.privateDM.send
import android.net.Uri
import androidx.activity.compose.BackHandler
import androidx.compose.foundation.horizontalScroll
import androidx.compose.foundation.layout.Arrangement.Absolute.spacedBy
import androidx.compose.foundation.layout.Box
@@ -165,6 +166,14 @@ fun NewGroupDMScreen(
WatchAndLoadMyEmojiList(accountViewModel)
BackHandler {
accountViewModel.runIOCatching {
postViewModel.sendDraftSync()
postViewModel.cancel()
}
nav.popBack()
}
Scaffold(
topBar = {
PostingTopBar(

View File

@@ -20,6 +20,7 @@
*/
package com.vitorpamplona.amethyst.ui.screen.loggedIn.chats.privateDM.send
import androidx.activity.compose.BackHandler
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
@@ -79,6 +80,14 @@ fun PrivateMessageEditFieldRow(
onSendNewMessage: () -> Unit,
nav: INav,
) {
BackHandler {
accountViewModel.runIOCatching {
channelScreenModel.sendDraftSync()
channelScreenModel.cancel()
}
nav.popBack()
}
channelScreenModel.replyTo.value?.let {
DisplayReplyingToNote(it, accountViewModel, nav) {
channelScreenModel.clearReply()

View File

@@ -20,6 +20,7 @@
*/
package com.vitorpamplona.amethyst.ui.screen.loggedIn.chats.publicChannels.send
import androidx.activity.compose.BackHandler
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
@@ -60,6 +61,14 @@ fun EditFieldRow(
onSendNewMessage: suspend () -> Unit,
nav: INav,
) {
BackHandler {
accountViewModel.runIOCatching {
channelScreenModel.sendDraftSync()
channelScreenModel.cancel()
}
nav.popBack()
}
channelScreenModel.replyTo.value?.let {
DisplayReplyingToNote(it, accountViewModel, nav) {
channelScreenModel.clearReply()

View File

@@ -21,6 +21,7 @@
package com.vitorpamplona.amethyst.ui.screen.loggedIn.discover.nip99Classifieds
import android.net.Uri
import androidx.activity.compose.BackHandler
import androidx.compose.foundation.horizontalScroll
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
@@ -136,6 +137,14 @@ fun NewProductScreen(
) {
WatchAndLoadMyEmojiList(accountViewModel)
BackHandler {
accountViewModel.runIOCatching {
postViewModel.sendDraftSync()
postViewModel.cancel()
}
nav.popBack()
}
Scaffold(
topBar = {
PostingTopBar(

View File

@@ -23,6 +23,7 @@ package com.vitorpamplona.amethyst.ui.screen.loggedIn.home
import android.content.Intent
import android.net.Uri
import android.os.Parcelable
import androidx.activity.compose.BackHandler
import androidx.compose.foundation.horizontalScroll
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
@@ -164,6 +165,14 @@ private fun NewPostScreenInner(
) {
WatchAndLoadMyEmojiList(accountViewModel)
BackHandler {
accountViewModel.runIOCatching {
postViewModel.sendDraftSync()
postViewModel.cancel()
}
nav.popBack()
}
Scaffold(
topBar = {
PostingTopBar(

View File

@@ -20,6 +20,7 @@
*/
package com.vitorpamplona.amethyst.ui.screen.loggedIn.notifications.publicMessages
import androidx.activity.compose.BackHandler
import androidx.compose.foundation.horizontalScroll
import androidx.compose.foundation.layout.Arrangement.Absolute.spacedBy
import androidx.compose.foundation.layout.Column
@@ -128,6 +129,14 @@ fun NewPublicMessageScreen(
WatchAndLoadMyEmojiList(accountViewModel)
BackHandler {
accountViewModel.runIOCatching {
postViewModel.sendDraftSync()
postViewModel.cancel()
}
nav.popBack()
}
Scaffold(
topBar = {
PostingTopBar(