diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/actions/NewPostView.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/actions/NewPostView.kt index 620e393c5..579509116 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/actions/NewPostView.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/actions/NewPostView.kt @@ -26,6 +26,7 @@ import androidx.compose.material.icons.outlined.Bolt import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.getValue +import androidx.compose.runtime.livedata.observeAsState import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.rememberCoroutineScope @@ -47,6 +48,7 @@ import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.input.KeyboardCapitalization import androidx.compose.ui.text.input.TextFieldValue +import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.text.style.TextDirection import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp @@ -58,9 +60,8 @@ import coil.compose.AsyncImage import com.vitorpamplona.amethyst.R import com.vitorpamplona.amethyst.model.Account import com.vitorpamplona.amethyst.model.Note -import com.vitorpamplona.amethyst.service.model.TextNoteEvent +import com.vitorpamplona.amethyst.model.User import com.vitorpamplona.amethyst.ui.components.* -import com.vitorpamplona.amethyst.ui.note.ReplyInformation import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel import com.vitorpamplona.amethyst.ui.screen.loggedIn.TextSpinner import com.vitorpamplona.amethyst.ui.screen.loggedIn.UserLine @@ -145,10 +146,8 @@ fun NewPostView(onClose: () -> Unit, baseReplyTo: Note? = null, quote: Note? = n .fillMaxWidth() .verticalScroll(scroolState) ) { - if (postViewModel.replyTos != null && baseReplyTo?.event is TextNoteEvent) { - ReplyInformation(postViewModel.replyTos, postViewModel.mentions, account, "✖ ") { - postViewModel.removeFromReplyList(it) - } + Notifying(postViewModel.mentions) { + postViewModel.removeFromReplyList(it) } OutlinedTextField( @@ -345,6 +344,47 @@ fun NewPostView(onClose: () -> Unit, baseReplyTo: Note? = null, quote: Note? = n } } +@OptIn(ExperimentalLayoutApi::class) +@Composable +fun Notifying(baseMentions: List?, onClick: (User) -> Unit) { + val mentions = baseMentions?.toSet() + + FlowRow(verticalAlignment = Alignment.CenterVertically, modifier = Modifier.padding(horizontal = 10.dp)) { + if (!mentions.isNullOrEmpty()) { + Text( + stringResource(R.string.reply_notify), + fontWeight = FontWeight.Bold, + color = MaterialTheme.colors.onSurface.copy(alpha = 0.32f) + ) + + mentions.forEachIndexed { idx, user -> + val innerUserState by user.live().metadata.observeAsState() + val innerUser = innerUserState?.user + + innerUser?.let { myUser -> + Spacer(modifier = Modifier.width(5.dp)) + + Button( + shape = RoundedCornerShape(20.dp), + colors = ButtonDefaults.buttonColors( + backgroundColor = MaterialTheme.colors.primary.copy(alpha = 0.32f) + ), + onClick = { + onClick(myUser) + } + ) { + Text( + "✖ ${myUser.toBestDisplayName()}", + color = Color.White, + textAlign = TextAlign.Center + ) + } + } + } + } + } +} + @Composable private fun AddPollButton( isPollActive: Boolean, diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/actions/NewPostViewModel.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/actions/NewPostViewModel.kt index 4b12675d4..a74a15d7a 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/actions/NewPostViewModel.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/actions/NewPostViewModel.kt @@ -198,8 +198,8 @@ open class NewPostViewModel : ViewModel() { } } - open fun removeFromReplyList(it: User) { - mentions = mentions?.minus(it) + open fun removeFromReplyList(userToRemove: User) { + mentions = mentions?.filter { it != userToRemove } } open fun updateMessage(it: TextFieldValue) { diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 7818c049f..50c42780f 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -394,4 +394,6 @@ %1$s sats From %1$s for %1$s + + Notify: