Merge remote-tracking branch 'origin/profiles-list-management' into profiles-list-management

This commit is contained in:
KotlinGeekDev
2024-10-17 19:39:23 +01:00
8 changed files with 77 additions and 27 deletions
@@ -981,6 +981,10 @@ open class NewPostViewModel : ViewModel() {
draftTextChanges.trySend("") draftTextChanges.trySend("")
} }
open fun addToMessage(it: String) {
updateMessage(TextFieldValue(message.text + " " + it))
}
open fun updateMessage(it: TextFieldValue) { open fun updateMessage(it: TextFieldValue) {
message = it message = it
urlPreview = findUrlInMessage() urlPreview = findUrlInMessage()
@@ -293,7 +293,7 @@ fun AppNavigation(
popEnterTransition = { scaleIn }, popEnterTransition = { scaleIn },
popExitTransition = { slideOutVerticallyToBottom }, popExitTransition = { slideOutVerticallyToBottom },
) { ) {
val draftMessage = it.message() val draftMessage = it.arguments?.getString("message")?.ifBlank { null }
val attachment = val attachment =
it.arguments?.getString("attachment")?.ifBlank { null }?.let { it.arguments?.getString("attachment")?.ifBlank { null }?.let {
Uri.parse(it) Uri.parse(it)
@@ -304,6 +304,7 @@ fun AppNavigation(
val version = it.arguments?.getString("version") val version = it.arguments?.getString("version")
val draft = it.arguments?.getString("draft") val draft = it.arguments?.getString("draft")
val enableMessageInterface = it.arguments?.getBoolean("enableMessageInterface") ?: false val enableMessageInterface = it.arguments?.getBoolean("enableMessageInterface") ?: false
NewPostScreen( NewPostScreen(
message = draftMessage, message = draftMessage,
attachment = attachment, attachment = attachment,
@@ -333,9 +334,12 @@ private fun NavigateIfIntentRequested(
accountStateViewModel: AccountStateViewModel, accountStateViewModel: AccountStateViewModel,
) { ) {
val activity = LocalContext.current.getActivity() val activity = LocalContext.current.getActivity()
var newAccount by remember { mutableStateOf<String?>(null) }
if (activity.intent.action == Intent.ACTION_SEND) { if (activity.intent.action == Intent.ACTION_SEND) {
// avoids restarting the new Post screen when the intent is for the screen.
// Microsoft's swift key sends Gifs as new actions
if (isBaseRoute(nav.controller, Route.NewPost.base)) return
// saves the intent to avoid processing again // saves the intent to avoid processing again
var message by remember { var message by remember {
mutableStateOf( mutableStateOf(
@@ -356,6 +360,8 @@ private fun NavigateIfIntentRequested(
media = null media = null
message = null message = null
} else { } else {
var newAccount by remember { mutableStateOf<String?>(null) }
var currentIntentNextPage by remember { var currentIntentNextPage by remember {
mutableStateOf( mutableStateOf(
activity.intent activity.intent
@@ -404,12 +410,16 @@ private fun NavigateIfIntentRequested(
val consumer = val consumer =
Consumer<Intent> { intent -> Consumer<Intent> { intent ->
if (intent.action == Intent.ACTION_SEND) { if (intent.action == Intent.ACTION_SEND) {
intent.getStringExtra(Intent.EXTRA_TEXT)?.let { // avoids restarting the new Post screen when the intent is for the screen.
nav.newStack(buildNewPostRoute(draftMessage = it)) // Microsoft's swift key sends Gifs as new actions
} if (!isBaseRoute(nav.controller, Route.NewPost.base)) {
intent.getStringExtra(Intent.EXTRA_TEXT)?.let {
nav.newStack(buildNewPostRoute(draftMessage = it))
}
(intent.getParcelableExtra<Parcelable>(Intent.EXTRA_STREAM) as? Uri)?.let { (intent.getParcelableExtra<Parcelable>(Intent.EXTRA_STREAM) as? Uri)?.let {
nav.newStack(buildNewPostRoute(attachment = it)) nav.newStack(buildNewPostRoute(attachment = it))
}
} }
} else { } else {
val uri = intent.data?.toString() val uri = intent.data?.toString()
@@ -248,6 +248,15 @@ sealed class Route(
) )
} }
fun isBaseRoute(
navController: NavHostController,
startsWith: String,
): Boolean =
navController.currentBackStackEntry
?.destination
?.route
?.startsWith(startsWith) ?: false
fun getRouteWithArguments(navController: NavHostController): String? { fun getRouteWithArguments(navController: NavHostController): String? {
val currentEntry = navController.currentBackStackEntry ?: return null val currentEntry = navController.currentBackStackEntry ?: return null
return getRouteWithArguments(currentEntry.destination, currentEntry.arguments) return getRouteWithArguments(currentEntry.destination, currentEntry.arguments)
@@ -48,7 +48,6 @@ import androidx.compose.foundation.layout.ExperimentalLayoutApi
import androidx.compose.foundation.layout.FlowRow import androidx.compose.foundation.layout.FlowRow
import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.size
@@ -81,6 +80,7 @@ import androidx.compose.ui.Alignment.Companion.CenterStart
import androidx.compose.ui.Alignment.Companion.CenterVertically import androidx.compose.ui.Alignment.Companion.CenterVertically
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.StrokeCap
import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalDensity import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.semantics.Role import androidx.compose.ui.semantics.Role
@@ -116,10 +116,11 @@ import com.vitorpamplona.amethyst.ui.note.types.RenderReaction
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
import com.vitorpamplona.amethyst.ui.stringRes import com.vitorpamplona.amethyst.ui.stringRes
import com.vitorpamplona.amethyst.ui.theme.ButtonBorder import com.vitorpamplona.amethyst.ui.theme.ButtonBorder
import com.vitorpamplona.amethyst.ui.theme.DarkerGreen
import com.vitorpamplona.amethyst.ui.theme.Font14SP import com.vitorpamplona.amethyst.ui.theme.Font14SP
import com.vitorpamplona.amethyst.ui.theme.HalfDoubleVertSpacer import com.vitorpamplona.amethyst.ui.theme.HalfDoubleVertSpacer
import com.vitorpamplona.amethyst.ui.theme.HalfPadding import com.vitorpamplona.amethyst.ui.theme.HalfPadding
import com.vitorpamplona.amethyst.ui.theme.Height24dpFilledModifier
import com.vitorpamplona.amethyst.ui.theme.Height4dpFilledModifier
import com.vitorpamplona.amethyst.ui.theme.ModifierWidth3dp import com.vitorpamplona.amethyst.ui.theme.ModifierWidth3dp
import com.vitorpamplona.amethyst.ui.theme.NoSoTinyBorders import com.vitorpamplona.amethyst.ui.theme.NoSoTinyBorders
import com.vitorpamplona.amethyst.ui.theme.ReactionRowExpandButton import com.vitorpamplona.amethyst.ui.theme.ReactionRowExpandButton
@@ -141,7 +142,7 @@ import com.vitorpamplona.amethyst.ui.theme.TinyBorders
import com.vitorpamplona.amethyst.ui.theme.defaultTweenDuration import com.vitorpamplona.amethyst.ui.theme.defaultTweenDuration
import com.vitorpamplona.amethyst.ui.theme.defaultTweenFloatSpec import com.vitorpamplona.amethyst.ui.theme.defaultTweenFloatSpec
import com.vitorpamplona.amethyst.ui.theme.defaultTweenIntOffsetSpec import com.vitorpamplona.amethyst.ui.theme.defaultTweenIntOffsetSpec
import com.vitorpamplona.amethyst.ui.theme.mediumImportanceLink import com.vitorpamplona.amethyst.ui.theme.fundraiserProgressColor
import com.vitorpamplona.amethyst.ui.theme.placeholderText import com.vitorpamplona.amethyst.ui.theme.placeholderText
import com.vitorpamplona.amethyst.ui.theme.reactionBox import com.vitorpamplona.amethyst.ui.theme.reactionBox
import com.vitorpamplona.amethyst.ui.theme.ripple24dp import com.vitorpamplona.amethyst.ui.theme.ripple24dp
@@ -348,22 +349,13 @@ fun RenderZapRaiser(
} }
} }
val color =
if (zapraiserStatus.progress > 0.99) {
DarkerGreen
} else {
MaterialTheme.colorScheme.mediumImportanceLink
}
LinearProgressIndicator( LinearProgressIndicator(
modifier = modifier = if (details) Height24dpFilledModifier else Height4dpFilledModifier,
remember(details) { color = MaterialTheme.colorScheme.fundraiserProgressColor,
Modifier
.fillMaxWidth()
.height(if (details) 24.dp else 4.dp)
},
color = color,
progress = { zapraiserStatus.progress }, progress = { zapraiserStatus.progress },
gapSize = 0.dp,
strokeCap = StrokeCap.Square,
drawStopIndicator = {},
) )
if (details) { if (details) {
@@ -380,7 +372,7 @@ fun RenderZapRaiser(
text = text =
stringRes(id = R.string.sats_to_complete, totalPercentage, zapraiserStatus.left), stringRes(id = R.string.sats_to_complete, totalPercentage, zapraiserStatus.left),
modifier = NoSoTinyBorders, modifier = NoSoTinyBorders,
color = MaterialTheme.colorScheme.placeholderText, // color = MaterialTheme.colorScheme.placeholderText,
fontSize = Font14SP, fontSize = Font14SP,
maxLines = 1, maxLines = 1,
) )
@@ -21,9 +21,11 @@
package com.vitorpamplona.amethyst.ui.screen.loggedIn package com.vitorpamplona.amethyst.ui.screen.loggedIn
import android.Manifest import android.Manifest
import android.content.Intent
import android.graphics.Bitmap import android.graphics.Bitmap
import android.net.Uri import android.net.Uri
import android.os.Build import android.os.Build
import android.os.Parcelable
import android.util.Log import android.util.Log
import android.util.Size import android.util.Size
import android.widget.Toast import android.widget.Toast
@@ -119,6 +121,7 @@ import androidx.compose.ui.text.style.TextDirection
import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp import androidx.compose.ui.unit.sp
import androidx.core.util.Consumer
import androidx.lifecycle.compose.collectAsStateWithLifecycle import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.lifecycle.viewmodel.compose.viewModel import androidx.lifecycle.viewmodel.compose.viewModel
import coil.compose.AsyncImage import coil.compose.AsyncImage
@@ -146,7 +149,8 @@ import com.vitorpamplona.amethyst.ui.components.InvoiceRequest
import com.vitorpamplona.amethyst.ui.components.LoadUrlPreview import com.vitorpamplona.amethyst.ui.components.LoadUrlPreview
import com.vitorpamplona.amethyst.ui.components.VideoView import com.vitorpamplona.amethyst.ui.components.VideoView
import com.vitorpamplona.amethyst.ui.components.ZapRaiserRequest import com.vitorpamplona.amethyst.ui.components.ZapRaiserRequest
import com.vitorpamplona.amethyst.ui.navigation.INav import com.vitorpamplona.amethyst.ui.navigation.Nav
import com.vitorpamplona.amethyst.ui.navigation.getActivity
import com.vitorpamplona.amethyst.ui.note.BaseUserPicture import com.vitorpamplona.amethyst.ui.note.BaseUserPicture
import com.vitorpamplona.amethyst.ui.note.CancelIcon import com.vitorpamplona.amethyst.ui.note.CancelIcon
import com.vitorpamplona.amethyst.ui.note.CloseIcon import com.vitorpamplona.amethyst.ui.note.CloseIcon
@@ -203,12 +207,13 @@ fun NewPostScreen(
draft: Note? = null, draft: Note? = null,
enableMessageInterface: Boolean = false, enableMessageInterface: Boolean = false,
accountViewModel: AccountViewModel, accountViewModel: AccountViewModel,
nav: INav, nav: Nav,
) { ) {
val postViewModel: NewPostViewModel = viewModel() val postViewModel: NewPostViewModel = viewModel()
postViewModel.wantsDirectMessage = enableMessageInterface postViewModel.wantsDirectMessage = enableMessageInterface
val context = LocalContext.current val context = LocalContext.current
val activity = context.getActivity()
val scrollState = rememberScrollState() val scrollState = rememberScrollState()
val scope = rememberCoroutineScope() val scope = rememberCoroutineScope()
@@ -250,6 +255,27 @@ fun NewPostScreen(
NostrSearchEventOrUserDataSource.stop() NostrSearchEventOrUserDataSource.stop()
} }
} }
DisposableEffect(nav, activity) {
// Microsoft's swift key sends Gifs as new actions
val consumer =
Consumer<Intent> { intent ->
if (intent.action == Intent.ACTION_SEND) {
intent.getStringExtra(Intent.EXTRA_TEXT)?.ifBlank { null }?.let {
postViewModel.addToMessage(it)
}
(intent.getParcelableExtra<Parcelable>(Intent.EXTRA_STREAM) as? Uri)?.let {
postViewModel.selectImage(it)
}
}
}
activity.addOnNewIntentListener(consumer)
onDispose { activity.removeOnNewIntentListener(consumer) }
}
Scaffold( Scaffold(
topBar = { topBar = {
TopAppBar( TopAppBar(
@@ -53,3 +53,6 @@ val DarkWarningColor = Color(0xFFF8DE22)
val LightAllGoodColor = Color(0xFF339900) val LightAllGoodColor = Color(0xFF339900)
val DarkAllGoodColor = Color(0xFF99cc33) val DarkAllGoodColor = Color(0xFF99cc33)
val LightFundraiserProgressColor = Color(0xFF3DB601)
val DarkFundraiserProgressColor = Color(0xFF61A229)
@@ -178,6 +178,9 @@ val UserNameMaxRowHeight = Modifier.fillMaxWidth()
val Height24dpModifier = Modifier.height(24.dp) val Height24dpModifier = Modifier.height(24.dp)
val Height4dpModifier = Modifier.height(4.dp) val Height4dpModifier = Modifier.height(4.dp)
val Height24dpFilledModifier = Modifier.fillMaxWidth().height(24.dp)
val Height4dpFilledModifier = Modifier.fillMaxWidth().height(4.dp)
val AccountPictureModifier = Modifier.size(55.dp).clip(shape = CircleShape) val AccountPictureModifier = Modifier.size(55.dp).clip(shape = CircleShape)
val HeaderPictureModifier = Modifier.size(34.dp).clip(shape = CircleShape) val HeaderPictureModifier = Modifier.size(34.dp).clip(shape = CircleShape)
@@ -397,6 +397,9 @@ val ColorScheme.warningColor: Color
val ColorScheme.allGoodColor: Color val ColorScheme.allGoodColor: Color
get() = if (isLight) LightAllGoodColor else DarkAllGoodColor get() = if (isLight) LightAllGoodColor else DarkAllGoodColor
val ColorScheme.fundraiserProgressColor: Color
get() = if (isLight) LightFundraiserProgressColor else DarkFundraiserProgressColor
val ColorScheme.markdownStyle: RichTextStyle val ColorScheme.markdownStyle: RichTextStyle
get() = if (isLight) MarkDownStyleOnLight else MarkDownStyleOnDark get() = if (isLight) MarkDownStyleOnLight else MarkDownStyleOnDark