use accountviewmodel as parameter instead of MutableState

This commit is contained in:
greenart7c3
2023-07-10 08:01:16 -03:00
parent f95023f59d
commit 6d4a887d00
14 changed files with 158 additions and 312 deletions
@@ -6,11 +6,22 @@ import android.os.Build
import android.util.Size
import android.widget.Toast
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.imePadding
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.windowInsetsPadding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.*
import androidx.compose.material.MaterialTheme
import androidx.compose.material.OutlinedTextField
import androidx.compose.material.Surface
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
@@ -29,8 +40,7 @@ import androidx.compose.ui.window.Dialog
import androidx.compose.ui.window.DialogProperties
import coil.compose.AsyncImage
import com.vitorpamplona.amethyst.R
import com.vitorpamplona.amethyst.model.Account
import com.vitorpamplona.amethyst.ui.components.*
import com.vitorpamplona.amethyst.ui.components.VideoView
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
import com.vitorpamplona.amethyst.ui.screen.loggedIn.TextSpinner
import com.vitorpamplona.amethyst.ui.theme.placeholderText
@@ -107,7 +117,7 @@ fun NewMediaView(uri: Uri, onClose: () -> Unit, postViewModel: NewMediaModel, ac
.fillMaxWidth()
.verticalScroll(scroolState)
) {
ImageVideoPost(postViewModel, account)
ImageVideoPost(postViewModel, accountViewModel)
}
}
}
@@ -123,7 +133,7 @@ fun isNIP94Server(selectedServer: ServersAvailable?): Boolean {
}
@Composable
fun ImageVideoPost(postViewModel: NewMediaModel, acc: Account) {
fun ImageVideoPost(postViewModel: NewMediaModel, accountViewModel: AccountViewModel) {
val fileServers = listOf(
// Triple(ServersAvailable.IMGUR_NIP_94, stringResource(id = R.string.upload_server_imgur_nip94), stringResource(id = R.string.upload_server_imgur_nip94_explainer)),
Triple(ServersAvailable.NOSTRIMG_NIP_94, stringResource(id = R.string.upload_server_nostrimg_nip94), stringResource(id = R.string.upload_server_nostrimg_nip94_explainer)),
@@ -179,11 +189,8 @@ fun ImageVideoPost(postViewModel: NewMediaModel, acc: Account) {
)
}
} else {
val automaticallyStartPlayback = remember {
mutableStateOf(true)
}
postViewModel.galleryUri?.let {
VideoView(it.toString(), automaticallyStartPlayback = automaticallyStartPlayback)
VideoView(it.toString(), accountViewModel = accountViewModel)
}
}
}
@@ -194,7 +201,7 @@ fun ImageVideoPost(postViewModel: NewMediaModel, acc: Account) {
) {
TextSpinner(
label = stringResource(id = R.string.file_server),
placeholder = fileServers.firstOrNull { it.first == acc.defaultFileServer }?.second ?: fileServers[0].second,
placeholder = fileServers.firstOrNull { it.first == accountViewModel.account.defaultFileServer }?.second ?: fileServers[0].second,
options = fileServerOptions,
explainers = fileServerExplainers,
onSelect = {
@@ -272,7 +272,8 @@ fun NewPostView(onClose: () -> Unit, baseReplyTo: Note? = null, quote: Note? = n
scope.launch {
postViewModel.imageUploadingError.emit(it)
}
}
},
accountViewModel = accountViewModel
)
}
}
@@ -330,9 +331,9 @@ fun NewPostView(onClose: () -> Unit, baseReplyTo: Note? = null, quote: Note? = n
)
)
} else if (videoExtensions.any { removedParamsFromUrl.endsWith(it) }) {
VideoView(myUrlPreview, automaticallyStartPlayback = remember { mutableStateOf(true) })
VideoView(myUrlPreview, accountViewModel = accountViewModel)
} else {
UrlPreview(myUrlPreview, myUrlPreview, remember { mutableStateOf(true) })
UrlPreview(myUrlPreview, myUrlPreview, accountViewModel)
}
} else if (startsWithNIP19Scheme(myUrlPreview)) {
val bgColor = MaterialTheme.colors.background
@@ -348,7 +349,7 @@ fun NewPostView(onClose: () -> Unit, baseReplyTo: Note? = null, quote: Note? = n
nav
)
} else if (noProtocolUrlValidator.matcher(myUrlPreview).matches()) {
UrlPreview("https://$myUrlPreview", myUrlPreview, remember { mutableStateOf(true) })
UrlPreview("https://$myUrlPreview", myUrlPreview, accountViewModel)
}
}
}
@@ -836,7 +837,8 @@ fun ImageVideoDescription(
defaultServer: ServersAvailable,
onAdd: (String, ServersAvailable, Boolean) -> Unit,
onCancel: () -> Unit,
onError: (String) -> Unit
onError: (String) -> Unit,
accountViewModel: AccountViewModel
) {
val resolver = LocalContext.current.contentResolver
val mediaType = resolver.getType(uri) ?: ""
@@ -966,7 +968,7 @@ fun ImageVideoDescription(
)
}
} else {
VideoView(uri.toString(), automaticallyStartPlayback = remember { mutableStateOf(true) })
VideoView(uri.toString(), accountViewModel = accountViewModel)
}
}
@@ -15,7 +15,6 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.derivedStateOf
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.setValue
@@ -25,7 +24,6 @@ import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import com.vitorpamplona.amethyst.R
import com.vitorpamplona.amethyst.service.connectivitystatus.ConnectivityStatus
import com.vitorpamplona.amethyst.ui.actions.ImmutableListOfLists
import com.vitorpamplona.amethyst.ui.note.getGradient
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
@@ -44,30 +42,6 @@ fun ExpandableRichTextViewer(
accountViewModel: AccountViewModel,
nav: (String) -> Unit
) {
val accountState by accountViewModel.accountLiveData.observeAsState()
val settings = accountState?.account?.settings
val isMobile = ConnectivityStatus.isOnMobileData.value
val automaticallyStartPlayback = remember {
mutableStateOf(
when (settings?.automaticallyStartPlayback) {
true -> !isMobile
false -> false
else -> true
}
)
}
val automaticallyShowUrlPreview = remember {
mutableStateOf(
when (settings?.automaticallyShowUrlPreview) {
true -> !isMobile
false -> false
else -> true
}
)
}
var showFullText by remember { mutableStateOf(false) }
val whereToCut = remember(content) {
@@ -96,8 +70,6 @@ fun ExpandableRichTextViewer(
tags,
backgroundColor,
accountViewModel,
automaticallyStartPlayback,
automaticallyShowUrlPreview,
nav
)
@@ -108,15 +108,13 @@ fun RichTextViewer(
tags: ImmutableListOfLists<String>,
backgroundColor: MutableState<Color>,
accountViewModel: AccountViewModel,
automaticallyStartPlayback: MutableState<Boolean>,
automaticallyShowUrlPreview: MutableState<Boolean>,
nav: (String) -> Unit
) {
Column(modifier = modifier) {
if (remember(content) { isMarkdown(content) }) {
RenderContentAsMarkdown(content, tags, nav)
} else {
RenderRegular(content, tags, canPreview, backgroundColor, accountViewModel, automaticallyStartPlayback, automaticallyShowUrlPreview, nav)
RenderRegular(content, tags, canPreview, backgroundColor, accountViewModel, nav)
}
}
}
@@ -129,8 +127,6 @@ private fun RenderRegular(
canPreview: Boolean,
backgroundColor: MutableState<Color>,
accountViewModel: AccountViewModel,
automaticallyStartPlayback: MutableState<Boolean>,
automaticallyShowUrlPreview: MutableState<Boolean>,
nav: (String) -> Unit
) {
val state by remember(content) {
@@ -160,8 +156,6 @@ private fun RenderRegular(
backgroundColor,
textStyle,
accountViewModel,
automaticallyStartPlayback,
automaticallyShowUrlPreview,
nav
)
}
@@ -241,13 +235,11 @@ private fun RenderWordWithPreview(
backgroundColor: MutableState<Color>,
style: TextStyle,
accountViewModel: AccountViewModel,
automaticallyStartPlayback: MutableState<Boolean>,
automaticallyShowUrlPreview: MutableState<Boolean>,
nav: (String) -> Unit
) {
when (word) {
is ImageSegment -> ZoomableContentView(word.segmentText, state, accountViewModel, automaticallyStartPlayback)
is LinkSegment -> UrlPreview(word.segmentText, word.segmentText, automaticallyShowUrlPreview)
is ImageSegment -> ZoomableContentView(word.segmentText, state, accountViewModel)
is LinkSegment -> UrlPreview(word.segmentText, word.segmentText, accountViewModel)
is EmojiSegment -> RenderCustomEmoji(word.segmentText, state)
is InvoiceSegment -> MayBeInvoicePreview(word.segmentText)
is WithdrawSegment -> MayBeWithdrawal(word.segmentText)
@@ -267,11 +259,10 @@ private fun RenderWordWithPreview(
private fun ZoomableContentView(
word: String,
state: RichTextViewerState,
accountViewModel: AccountViewModel,
automaticallyStartPlayback: MutableState<Boolean>
accountViewModel: AccountViewModel
) {
state.imagesForPager[word]?.let {
ZoomableContentView(it, state.imageList, accountViewModel, automaticallyStartPlayback)
ZoomableContentView(it, state.imageList, accountViewModel)
}
}
@@ -4,18 +4,28 @@ import androidx.compose.animation.Crossfade
import androidx.compose.animation.core.tween
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import com.vitorpamplona.amethyst.model.UrlCachedPreviewer
import com.vitorpamplona.amethyst.service.connectivitystatus.ConnectivityStatus
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
@Composable
fun UrlPreview(url: String, urlText: String, automaticallyShowUrlPreview: MutableState<Boolean>) {
if (!automaticallyShowUrlPreview.value) {
fun UrlPreview(url: String, urlText: String, accountViewModel: AccountViewModel) {
val settings = accountViewModel.account.settings
val isMobile = ConnectivityStatus.isOnMobileData.value
val automaticallyShowUrlPreview = when (settings.automaticallyShowUrlPreview) {
true -> !isMobile
false -> false
else -> true
}
if (!automaticallyShowUrlPreview) {
ClickableUrl(urlText, url)
} else {
var urlPreviewState by remember(url) {
@@ -43,7 +53,7 @@ fun UrlPreview(url: String, urlText: String, automaticallyShowUrlPreview: Mutabl
) { state ->
when (state) {
is UrlPreviewState.Loaded -> {
UrlPreviewCard(url, state.previewInfo, automaticallyShowUrlPreview)
UrlPreviewCard(url, state.previewInfo, accountViewModel)
}
else -> {
@@ -20,7 +20,9 @@ import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import coil.compose.AsyncImage
import com.vitorpamplona.amethyst.R
import com.vitorpamplona.amethyst.service.connectivitystatus.ConnectivityStatus
import com.vitorpamplona.amethyst.service.previews.UrlInfoItem
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
import com.vitorpamplona.amethyst.ui.theme.QuoteBorder
import com.vitorpamplona.amethyst.ui.theme.subtleBorder
@@ -28,62 +30,72 @@ import com.vitorpamplona.amethyst.ui.theme.subtleBorder
fun UrlPreviewCard(
url: String,
previewInfo: UrlInfoItem,
automaticallyShowUrlPreview: MutableState<Boolean>
accountViewModel: AccountViewModel
) {
if (!automaticallyShowUrlPreview.value) {
return ClickableUrl(url, url)
val settings = accountViewModel.account.settings
val isMobile = ConnectivityStatus.isOnMobileData.value
val automaticallyShowUrlPreview = when (settings.automaticallyShowUrlPreview) {
true -> !isMobile
false -> false
else -> true
}
val uri = LocalUriHandler.current
Row(
modifier = Modifier
.clickable { runCatching { uri.openUri(url) } }
.clip(shape = QuoteBorder)
.border(
1.dp,
MaterialTheme.colors.subtleBorder,
QuoteBorder
)
) {
Column {
AsyncImage(
model = previewInfo.imageUrlFullPath,
contentDescription = stringResource(R.string.preview_card_image_for, previewInfo.url),
contentScale = ContentScale.FillWidth,
modifier = Modifier.fillMaxWidth()
)
if (!automaticallyShowUrlPreview) {
ClickableUrl(url, url)
} else {
val uri = LocalUriHandler.current
Text(
text = previewInfo.verifiedUrl?.host ?: previewInfo.url,
style = MaterialTheme.typography.caption,
modifier = Modifier
.fillMaxWidth()
.padding(start = 10.dp, end = 10.dp, top = 10.dp),
color = Color.Gray,
maxLines = 1,
overflow = TextOverflow.Ellipsis
)
Row(
modifier = Modifier
.clickable { runCatching { uri.openUri(url) } }
.clip(shape = QuoteBorder)
.border(
1.dp,
MaterialTheme.colors.subtleBorder,
QuoteBorder
)
) {
Column {
AsyncImage(
model = previewInfo.imageUrlFullPath,
contentDescription = stringResource(R.string.preview_card_image_for, previewInfo.url),
contentScale = ContentScale.FillWidth,
modifier = Modifier.fillMaxWidth()
)
Text(
text = previewInfo.title,
style = MaterialTheme.typography.body2,
modifier = Modifier
.fillMaxWidth()
.padding(start = 10.dp, end = 10.dp),
maxLines = 1,
overflow = TextOverflow.Ellipsis
)
Text(
text = previewInfo.verifiedUrl?.host ?: previewInfo.url,
style = MaterialTheme.typography.caption,
modifier = Modifier
.fillMaxWidth()
.padding(start = 10.dp, end = 10.dp, top = 10.dp),
color = Color.Gray,
maxLines = 1,
overflow = TextOverflow.Ellipsis
)
Text(
text = previewInfo.description,
style = MaterialTheme.typography.caption,
modifier = Modifier
.fillMaxWidth()
.padding(start = 10.dp, end = 10.dp, bottom = 10.dp),
color = Color.Gray,
maxLines = 3,
overflow = TextOverflow.Ellipsis
)
Text(
text = previewInfo.title,
style = MaterialTheme.typography.body2,
modifier = Modifier
.fillMaxWidth()
.padding(start = 10.dp, end = 10.dp),
maxLines = 1,
overflow = TextOverflow.Ellipsis
)
Text(
text = previewInfo.description,
style = MaterialTheme.typography.caption,
modifier = Modifier
.fillMaxWidth()
.padding(start = 10.dp, end = 10.dp, bottom = 10.dp),
color = Color.Gray,
maxLines = 3,
overflow = TextOverflow.Ellipsis
)
}
}
}
}
@@ -61,6 +61,8 @@ import com.google.android.exoplayer2.ui.StyledPlayerView
import com.google.android.exoplayer2.upstream.DataSource
import com.vitorpamplona.amethyst.VideoCache
import com.vitorpamplona.amethyst.service.HttpClient
import com.vitorpamplona.amethyst.service.connectivitystatus.ConnectivityStatus
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlin.time.ExperimentalTime
@@ -73,7 +75,7 @@ fun LoadThumbAndThenVideoView(
videoUri: String,
description: String? = null,
thumbUri: String,
showVideo: MutableState<Boolean>,
accountViewModel: AccountViewModel,
onDialog: ((Boolean) -> Unit)? = null
) {
var loadingFinished by remember { mutableStateOf<Pair<Boolean, Drawable?>>(Pair(false, null)) }
@@ -99,9 +101,9 @@ fun LoadThumbAndThenVideoView(
if (loadingFinished.first) {
if (loadingFinished.second != null) {
VideoView(videoUri, description, VideoThumb(loadingFinished.second), showVideo, onDialog)
VideoView(videoUri, description, VideoThumb(loadingFinished.second), accountViewModel, onDialog)
} else {
VideoView(videoUri, description, null, showVideo, onDialog)
VideoView(videoUri, description, null, accountViewModel, onDialog)
}
}
}
@@ -112,11 +114,11 @@ fun VideoView(
videoUri: String,
description: String? = null,
thumb: VideoThumb? = null,
automaticallyStartPlayback: MutableState<Boolean>,
accountViewModel: AccountViewModel,
onDialog: ((Boolean) -> Unit)? = null
) {
val (value, elapsed) = measureTimedValue {
VideoView1(videoUri, description, thumb, onDialog, automaticallyStartPlayback)
VideoView1(videoUri, description, thumb, onDialog, accountViewModel)
}
Log.d("Rendering Metrics", "VideoView $elapsed $videoUri")
}
@@ -127,7 +129,7 @@ fun VideoView1(
description: String? = null,
thumb: VideoThumb? = null,
onDialog: ((Boolean) -> Unit)? = null,
automaticallyStartPlayback: MutableState<Boolean>
accountViewModel: AccountViewModel
) {
var exoPlayerData by remember { mutableStateOf<VideoPlayer?>(null) }
val defaultToStart by remember { mutableStateOf(DefaultMutedSetting.value) }
@@ -142,7 +144,7 @@ fun VideoView1(
}
exoPlayerData?.let {
VideoView(videoUri, description, it, defaultToStart, thumb, onDialog, automaticallyStartPlayback = automaticallyStartPlayback)
VideoView(videoUri, description, it, defaultToStart, thumb, onDialog, accountViewModel)
}
DisposableEffect(Unit) {
@@ -161,10 +163,10 @@ fun VideoView(
defaultToStart: Boolean = false,
thumb: VideoThumb? = null,
onDialog: ((Boolean) -> Unit)? = null,
automaticallyStartPlayback: MutableState<Boolean>
accountViewModel: AccountViewModel
) {
val (value, elapsed) = measureTimedValue {
VideoView1(videoUri, description, exoPlayerData, defaultToStart, thumb, onDialog, automaticallyStartPlayback)
val (_, elapsed) = measureTimedValue {
VideoView1(videoUri, description, exoPlayerData, defaultToStart, thumb, onDialog, accountViewModel)
}
Log.d("Rendering Metrics", "VideoView $elapsed $videoUri")
}
@@ -177,12 +179,25 @@ fun VideoView1(
defaultToStart: Boolean = false,
thumb: VideoThumb? = null,
onDialog: ((Boolean) -> Unit)? = null,
automaticallyStartPlayback: MutableState<Boolean>
accountViewModel: AccountViewModel
) {
val lifecycleOwner = rememberUpdatedState(LocalLifecycleOwner.current)
val media = remember { MediaItem.Builder().setUri(videoUri).build() }
val settings = accountViewModel.account.settings
val isMobile = ConnectivityStatus.isOnMobileData.value
val automaticallyStartPlayback = remember {
mutableStateOf(
when (settings.automaticallyStartPlayback) {
true -> !isMobile
false -> false
else -> true
}
)
}
exoPlayerData.exoPlayer.apply {
repeatMode = Player.REPEAT_MODE_ALL
videoScalingMode = C.VIDEO_SCALING_MODE_SCALE_TO_FIT
@@ -172,8 +172,7 @@ fun figureOutMimeType(fullUrl: String): ZoomableContent {
fun ZoomableContentView(
content: ZoomableContent,
images: ImmutableList<ZoomableContent> = listOf(content).toImmutableList(),
accountViewModel: AccountViewModel,
automaticallyStartPlayback: MutableState<Boolean>
accountViewModel: AccountViewModel
) {
val clipboardManager = LocalClipboardManager.current
@@ -202,16 +201,16 @@ fun ZoomableContentView(
when (content) {
is ZoomableUrlImage -> UrlImageView(content, mainImageModifier, accountViewModel)
is ZoomableUrlVideo -> VideoView(content.url, content.description, automaticallyStartPlayback = automaticallyStartPlayback) { dialogOpen = true }
is ZoomableUrlVideo -> VideoView(content.url, content.description, accountViewModel = accountViewModel) { dialogOpen = true }
is ZoomableLocalImage -> LocalImageView(content, mainImageModifier, accountViewModel)
is ZoomableLocalVideo ->
content.localFile?.let {
VideoView(it.toUri().toString(), content.description, automaticallyStartPlayback = automaticallyStartPlayback) { dialogOpen = true }
VideoView(it.toUri().toString(), content.description, accountViewModel = accountViewModel) { dialogOpen = true }
}
}
if (dialogOpen) {
ZoomableImageDialog(content, images, onDismiss = { dialogOpen = false })
ZoomableImageDialog(content, images, onDismiss = { dialogOpen = false }, accountViewModel)
}
}
@@ -541,7 +540,7 @@ private fun DisplayBlurHash(
@OptIn(ExperimentalFoundationApi::class)
@Composable
fun ZoomableImageDialog(imageUrl: ZoomableContent, allImages: ImmutableList<ZoomableContent> = listOf(imageUrl).toImmutableList(), onDismiss: () -> Unit) {
fun ZoomableImageDialog(imageUrl: ZoomableContent, allImages: ImmutableList<ZoomableContent> = listOf(imageUrl).toImmutableList(), onDismiss: () -> Unit, accountViewModel: AccountViewModel) {
val view = LocalView.current
DisposableEffect(key1 = Unit) {
@@ -583,11 +582,11 @@ fun ZoomableImageDialog(imageUrl: ZoomableContent, allImages: ImmutableList<Zoom
pagerState = pagerState,
itemsCount = allImages.size,
itemContent = { index ->
RenderImageOrVideo(allImages[index], null, remember { mutableStateOf(true) })
RenderImageOrVideo(allImages[index], accountViewModel)
}
)
} else {
RenderImageOrVideo(imageUrl, null, remember { mutableStateOf(true) })
RenderImageOrVideo(imageUrl, accountViewModel)
}
Row(
@@ -612,7 +611,7 @@ fun ZoomableImageDialog(imageUrl: ZoomableContent, allImages: ImmutableList<Zoom
}
@Composable
fun RenderImageOrVideo(content: ZoomableContent, accountViewModel: AccountViewModel?, automaticallyStartPlayback: MutableState<Boolean>) {
fun RenderImageOrVideo(content: ZoomableContent, accountViewModel: AccountViewModel) {
val mainModifier = Modifier
.fillMaxSize()
.zoomable(rememberZoomState())
@@ -621,14 +620,14 @@ fun RenderImageOrVideo(content: ZoomableContent, accountViewModel: AccountViewMo
UrlImageView(content = content, mainImageModifier = mainModifier, accountViewModel)
} else if (content is ZoomableUrlVideo) {
Row(verticalAlignment = Alignment.CenterVertically, modifier = Modifier.fillMaxSize(1f)) {
VideoView(content.url, content.description, automaticallyStartPlayback = automaticallyStartPlayback)
VideoView(content.url, content.description, accountViewModel = accountViewModel)
}
} else if (content is ZoomableLocalImage) {
LocalImageView(content = content, mainImageModifier = mainModifier, accountViewModel)
} else if (content is ZoomableLocalVideo) {
Row(verticalAlignment = Alignment.CenterVertically, modifier = Modifier.fillMaxSize(1f)) {
content.localFile?.let {
VideoView(it.toUri().toString(), content.description, automaticallyStartPlayback = automaticallyStartPlayback)
VideoView(it.toUri().toString(), content.description, accountViewModel = accountViewModel)
}
}
}
@@ -94,20 +94,6 @@ fun ChannelCardCompose(
it.note.event == null
}.distinctUntilChanged().observeAsState(baseNote.event == null)
val accountState by accountViewModel.accountLiveData.observeAsState()
val settings = accountState?.account?.settings
val isMobile = ConnectivityStatus.isOnMobileData.value
val automaticallyStartPlayback = remember {
mutableStateOf(
when (settings?.automaticallyStartPlayback) {
true -> !isMobile
false -> false
else -> true
}
)
}
Crossfade(targetState = isBlank) {
if (it) {
LongPressToQuickAction(baseNote = baseNote, accountViewModel = accountViewModel) { showPopup ->
@@ -128,7 +114,6 @@ fun ChannelCardCompose(
modifier,
parentBackgroundColor,
accountViewModel,
automaticallyStartPlayback,
nav
)
}
@@ -142,7 +127,6 @@ fun CheckHiddenChannelCardCompose(
modifier: Modifier = Modifier,
parentBackgroundColor: MutableState<Color>? = null,
accountViewModel: AccountViewModel,
automaticallyStartPlayback: MutableState<Boolean>,
nav: (String) -> Unit
) {
val isHidden by accountViewModel.accountLiveData.map {
@@ -157,7 +141,6 @@ fun CheckHiddenChannelCardCompose(
modifier,
parentBackgroundColor,
accountViewModel,
automaticallyStartPlayback,
nav
)
}
@@ -171,7 +154,6 @@ fun LoadedChannelCardCompose(
modifier: Modifier = Modifier,
parentBackgroundColor: MutableState<Color>? = null,
accountViewModel: AccountViewModel,
automaticallyStartPlayback: MutableState<Boolean>,
nav: (String) -> Unit
) {
var state by remember {
@@ -203,7 +185,6 @@ fun LoadedChannelCardCompose(
modifier,
parentBackgroundColor,
accountViewModel,
automaticallyStartPlayback,
nav
)
}
@@ -217,7 +198,6 @@ fun RenderChannelCardReportState(
modifier: Modifier = Modifier,
parentBackgroundColor: MutableState<Color>? = null,
accountViewModel: AccountViewModel,
automaticallyStartPlayback: MutableState<Boolean>,
nav: (String) -> Unit
) {
var showReportedNote by remember { mutableStateOf(false) }
@@ -239,7 +219,6 @@ fun RenderChannelCardReportState(
modifier,
parentBackgroundColor,
accountViewModel,
automaticallyStartPlayback,
nav
)
}
@@ -253,7 +232,6 @@ fun NormalChannelCard(
modifier: Modifier = Modifier,
parentBackgroundColor: MutableState<Color>? = null,
accountViewModel: AccountViewModel,
automaticallyStartPlayback: MutableState<Boolean>,
nav: (String) -> Unit
) {
LongPressToQuickAction(baseNote = baseNote, accountViewModel = accountViewModel) { showPopup ->
@@ -263,7 +241,6 @@ fun NormalChannelCard(
modifier,
parentBackgroundColor,
accountViewModel,
automaticallyStartPlayback,
showPopup,
nav
)
@@ -277,7 +254,6 @@ private fun CheckNewAndRenderChannelCard(
modifier: Modifier = Modifier,
parentBackgroundColor: MutableState<Color>? = null,
accountViewModel: AccountViewModel,
automaticallyStartPlayback: MutableState<Boolean>,
showPopup: () -> Unit,
nav: (String) -> Unit
) {
@@ -335,7 +311,6 @@ private fun CheckNewAndRenderChannelCard(
InnerChannelCardWithReactions(
baseNote = baseNote,
accountViewModel = accountViewModel,
automaticallyStartPlayback,
nav = nav
)
}
@@ -345,7 +320,6 @@ private fun CheckNewAndRenderChannelCard(
fun InnerChannelCardWithReactions(
baseNote: Note,
accountViewModel: AccountViewModel,
automaticallyStartPlayback: MutableState<Boolean>,
nav: (String) -> Unit
) {
Column(StdPadding) {
@@ -366,12 +340,11 @@ fun InnerChannelCardWithReactions(
private fun RenderNoteRow(
baseNote: Note,
accountViewModel: AccountViewModel,
automaticallyStartPlayback: MutableState<Boolean>,
nav: (String) -> Unit
) {
when (remember { baseNote.event }) {
is LiveActivitiesEvent -> {
RenderLiveActivityThumb(baseNote, accountViewModel, automaticallyStartPlayback, nav)
RenderLiveActivityThumb(baseNote, accountViewModel, nav)
}
is CommunityDefinitionEvent -> {
RenderCommunitiesThumb(baseNote, accountViewModel, nav)
@@ -386,7 +359,6 @@ private fun RenderNoteRow(
fun RenderLiveActivityThumb(
baseNote: Note,
accountViewModel: AccountViewModel,
automaticallyStartPlayback: MutableState<Boolean>,
nav: (String) -> Unit
) {
val noteEvent = baseNote.event as? LiveActivitiesEvent ?: return
@@ -525,7 +497,6 @@ fun RenderLiveActivityThumb(
Modifier.padding(start = 0.dp, end = 0.dp, top = 5.dp, bottom = 5.dp)
},
accountViewModel = accountViewModel,
automaticallyStartPlayback = automaticallyStartPlayback,
nav = nav
)
}
@@ -211,30 +211,6 @@ fun NoteCompose(
it.note.event == null
}.distinctUntilChanged().observeAsState(baseNote.event == null)
val accountState by accountViewModel.accountLiveData.observeAsState()
val settings = accountState?.account?.settings
val isMobile = ConnectivityStatus.isOnMobileData.value
val showImage = remember {
mutableStateOf(
when (settings?.automaticallyShowImages) {
true -> !isMobile
false -> false
else -> true
}
)
}
val automaticallyStartPlayback = remember {
mutableStateOf(
when (settings?.automaticallyStartPlayback) {
true -> !isMobile
false -> false
else -> true
}
)
}
Crossfade(targetState = isBlank) {
if (it) {
LongPressToQuickAction(baseNote = baseNote, accountViewModel = accountViewModel) { showPopup ->
@@ -260,8 +236,6 @@ fun NoteCompose(
addMarginTop,
parentBackgroundColor,
accountViewModel,
showImage,
automaticallyStartPlayback,
nav
)
}
@@ -280,8 +254,6 @@ fun CheckHiddenNoteCompose(
addMarginTop: Boolean = true,
parentBackgroundColor: MutableState<Color>? = null,
accountViewModel: AccountViewModel,
showImage: MutableState<Boolean>,
automaticallyStartPlayback: MutableState<Boolean>,
nav: (String) -> Unit
) {
val isHidden by accountViewModel.accountLiveData.map {
@@ -301,8 +273,6 @@ fun CheckHiddenNoteCompose(
addMarginTop,
parentBackgroundColor,
accountViewModel,
showImage,
automaticallyStartPlayback,
nav
)
}
@@ -328,8 +298,6 @@ fun LoadedNoteCompose(
addMarginTop: Boolean = true,
parentBackgroundColor: MutableState<Color>? = null,
accountViewModel: AccountViewModel,
showImage: MutableState<Boolean>,
automaticallyStartPlayback: MutableState<Boolean>,
nav: (String) -> Unit
) {
var state by remember {
@@ -366,8 +334,6 @@ fun LoadedNoteCompose(
addMarginTop,
parentBackgroundColor,
accountViewModel,
showImage,
automaticallyStartPlayback,
nav
)
}
@@ -386,8 +352,6 @@ fun RenderReportState(
addMarginTop: Boolean = true,
parentBackgroundColor: MutableState<Color>? = null,
accountViewModel: AccountViewModel,
showImage: MutableState<Boolean>,
automaticallyStartPlayback: MutableState<Boolean>,
nav: (String) -> Unit
) {
var showReportedNote by remember { mutableStateOf(false) }
@@ -417,8 +381,6 @@ fun RenderReportState(
canPreview,
parentBackgroundColor,
accountViewModel,
showImage,
automaticallyStartPlayback,
nav
)
}
@@ -454,8 +416,6 @@ fun NormalNote(
canPreview: Boolean = true,
parentBackgroundColor: MutableState<Color>? = null,
accountViewModel: AccountViewModel,
showImage: MutableState<Boolean>,
automaticallyStartPlayback: MutableState<Boolean>,
nav: (String) -> Unit
) {
when (baseNote.event) {
@@ -464,7 +424,6 @@ fun NormalNote(
showVideo = !makeItShort,
showBottomDiviser = true,
accountViewModel = accountViewModel,
automaticallyStartPlayback = automaticallyStartPlayback,
nav = nav
)
is CommunityDefinitionEvent -> CommunityHeader(
@@ -490,8 +449,6 @@ fun NormalNote(
canPreview,
parentBackgroundColor,
accountViewModel,
showImage,
automaticallyStartPlayback,
showPopup,
nav
)
@@ -789,8 +746,6 @@ private fun CheckNewAndRenderNote(
canPreview: Boolean = true,
parentBackgroundColor: MutableState<Color>? = null,
accountViewModel: AccountViewModel,
showImage: MutableState<Boolean>,
automaticallyStartPlayback: MutableState<Boolean>,
showPopup: () -> Unit,
nav: (String) -> Unit
) {
@@ -855,8 +810,6 @@ private fun CheckNewAndRenderNote(
makeItShort = makeItShort,
canPreview = canPreview,
accountViewModel = accountViewModel,
showImage = showImage,
automaticallyStartPlayback = automaticallyStartPlayback,
nav = nav
)
}
@@ -907,8 +860,6 @@ fun InnerNoteWithReactions(
makeItShort: Boolean,
canPreview: Boolean,
accountViewModel: AccountViewModel,
showImage: MutableState<Boolean>,
automaticallyStartPlayback: MutableState<Boolean>,
nav: (String) -> Unit
) {
val notBoostedNorQuote = !isBoostedNote && !isQuotedNote
@@ -947,7 +898,6 @@ fun InnerNoteWithReactions(
showSecondRow = showSecondRow,
backgroundColor = backgroundColor,
accountViewModel = accountViewModel,
automaticallyStartPlayback = automaticallyStartPlayback,
nav = nav
)
}
@@ -993,7 +943,6 @@ private fun NoteBody(
showSecondRow: Boolean,
backgroundColor: MutableState<Color>,
accountViewModel: AccountViewModel,
automaticallyStartPlayback: MutableState<Boolean>,
nav: (String) -> Unit
) {
FirstUserInfoRow(
@@ -1019,7 +968,6 @@ private fun NoteBody(
unPackReply,
backgroundColor,
accountViewModel,
automaticallyStartPlayback,
nav
)
}
@@ -1327,7 +1275,7 @@ fun RenderAppDefinition(
)
if (zoomImageDialogOpen) {
ZoomableImageDialog(imageUrl = figureOutMimeType(it.banner!!), onDismiss = { zoomImageDialogOpen = false })
ZoomableImageDialog(imageUrl = figureOutMimeType(it.banner!!), onDismiss = { zoomImageDialogOpen = false }, accountViewModel = accountViewModel)
}
} else {
Image(
@@ -1378,7 +1326,7 @@ fun RenderAppDefinition(
}
if (zoomImageDialogOpen) {
ZoomableImageDialog(imageUrl = figureOutMimeType(it.banner!!), onDismiss = { zoomImageDialogOpen = false })
ZoomableImageDialog(imageUrl = figureOutMimeType(it.banner!!), onDismiss = { zoomImageDialogOpen = false }, accountViewModel = accountViewModel)
}
Spacer(Modifier.weight(1f))
@@ -2118,7 +2066,6 @@ private fun ReplyRow(
unPackReply: Boolean,
backgroundColor: MutableState<Color>,
accountViewModel: AccountViewModel,
automaticallyStartPlayback: MutableState<Boolean>,
nav: (String) -> Unit
) {
val noteEvent = note.event
@@ -2154,7 +2101,6 @@ private fun ReplyRow(
showBottomDiviser = false,
modifier = remember { Modifier.padding(vertical = 5.dp) },
accountViewModel = accountViewModel,
automaticallyStartPlayback = automaticallyStartPlayback,
nav = nav
)
@@ -2942,7 +2888,7 @@ fun FileHeaderDisplay(note: Note, accountViewModel: AccountViewModel) {
Crossfade(targetState = content) {
if (it != null) {
SensitivityWarning(note = note, accountViewModel = accountViewModel) {
ZoomableContentView(content = it)
ZoomableContentView(content = it, accountViewModel = accountViewModel)
}
}
}
@@ -3028,7 +2974,7 @@ private fun RenderNIP95(
Crossfade(targetState = content) {
if (it != null) {
SensitivityWarning(note = header, accountViewModel = accountViewModel) {
ZoomableContentView(content = it)
ZoomableContentView(content = it, accountViewModel = accountViewModel)
}
}
}
@@ -3099,13 +3045,13 @@ fun AudioTrackHeader(noteEvent: AudioTrackEvent, accountViewModel: AccountViewMo
videoUri = media,
description = noteEvent.subject(),
thumbUri = cover,
showVideo = remember { mutableStateOf(true) }
accountViewModel = accountViewModel
)
}
?: VideoView(
videoUri = media,
description = noteEvent.subject(),
automaticallyStartPlayback = remember { mutableStateOf(true) }
accountViewModel = accountViewModel
)
}
}
@@ -3230,7 +3176,7 @@ fun RenderLiveActivityEventInner(baseNote: Note, accountViewModel: AccountViewMo
VideoView(
videoUri = media,
description = subject,
automaticallyStartPlayback = remember { mutableStateOf(true) }
accountViewModel = accountViewModel
)
}
} else {
@@ -23,7 +23,6 @@ import androidx.compose.material.Icon
import androidx.compose.material.IconButton
import androidx.compose.material.MaterialTheme
import androidx.compose.material.ProvideTextStyle
import androidx.compose.material.SnackbarDefaults.backgroundColor
import androidx.compose.material.Text
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.MoreVert
@@ -55,7 +54,6 @@ import androidx.compose.ui.unit.sp
import coil.compose.AsyncImage
import com.vitorpamplona.amethyst.R
import com.vitorpamplona.amethyst.model.Note
import com.vitorpamplona.amethyst.service.connectivitystatus.ConnectivityStatus
import com.vitorpamplona.amethyst.service.model.AppDefinitionEvent
import com.vitorpamplona.amethyst.service.model.AudioTrackEvent
import com.vitorpamplona.amethyst.service.model.BadgeDefinitionEvent
@@ -75,19 +73,6 @@ import com.vitorpamplona.amethyst.service.model.RelaySetEvent
import com.vitorpamplona.amethyst.service.model.RepostEvent
import com.vitorpamplona.amethyst.ui.components.ObserveDisplayNip05Status
import com.vitorpamplona.amethyst.ui.note.*
import com.vitorpamplona.amethyst.ui.note.BadgeDisplay
import com.vitorpamplona.amethyst.ui.note.BlankNote
import com.vitorpamplona.amethyst.ui.note.DisplayFollowingHashtagsInPost
import com.vitorpamplona.amethyst.ui.note.DisplayPoW
import com.vitorpamplona.amethyst.ui.note.DisplayReward
import com.vitorpamplona.amethyst.ui.note.HiddenNote
import com.vitorpamplona.amethyst.ui.note.NoteAuthorPicture
import com.vitorpamplona.amethyst.ui.note.NoteCompose
import com.vitorpamplona.amethyst.ui.note.NoteDropDownMenu
import com.vitorpamplona.amethyst.ui.note.NoteQuickActionMenu
import com.vitorpamplona.amethyst.ui.note.NoteUsernameDisplay
import com.vitorpamplona.amethyst.ui.note.ReactionsRow
import com.vitorpamplona.amethyst.ui.note.timeAgo
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
import com.vitorpamplona.amethyst.ui.screen.loggedIn.ChannelHeader
import com.vitorpamplona.amethyst.ui.theme.lessImportantLink
@@ -245,19 +230,6 @@ fun NoteMaster(
val accountState by accountViewModel.accountLiveData.observeAsState()
val account = accountState?.account ?: return
val settings = accountState?.account?.settings
val isMobile = ConnectivityStatus.isOnMobileData.value
val automaticallyStartPlayback = remember {
mutableStateOf(
when (settings?.automaticallyStartPlayback) {
true -> !isMobile
false -> false
else -> true
}
)
}
var showHiddenNote by remember { mutableStateOf(false) }
val context = LocalContext.current
@@ -417,7 +389,6 @@ fun NoteMaster(
showVideo = true,
showBottomDiviser = false,
accountViewModel = accountViewModel,
automaticallyStartPlayback = automaticallyStartPlayback,
nav = nav
)
} else if (noteEvent is FileHeaderEvent) {
@@ -87,7 +87,6 @@ import com.vitorpamplona.amethyst.model.Note
import com.vitorpamplona.amethyst.model.PublicChatChannel
import com.vitorpamplona.amethyst.model.User
import com.vitorpamplona.amethyst.service.NostrChannelDataSource
import com.vitorpamplona.amethyst.service.connectivitystatus.ConnectivityStatus
import com.vitorpamplona.amethyst.service.model.LiveActivitiesEvent.Companion.STATUS_LIVE
import com.vitorpamplona.amethyst.service.model.Participant
import com.vitorpamplona.amethyst.ui.actions.ImmutableListOfLists
@@ -200,20 +199,6 @@ fun ChannelScreen(
val lifeCycleOwner = LocalLifecycleOwner.current
val accountState by accountViewModel.accountLiveData.observeAsState()
val settings = accountState?.account?.settings
val isMobile = ConnectivityStatus.isOnMobileData.value
val automaticallyStartPlayback = remember {
mutableStateOf(
when (settings?.automaticallyStartPlayback) {
true -> !isMobile
false -> false
else -> true
}
)
}
LaunchedEffect(Unit) {
NostrChannelDataSource.start()
feedViewModel.invalidateData()
@@ -254,7 +239,6 @@ fun ChannelScreen(
showVideo = true,
showBottomDiviser = true,
accountViewModel = accountViewModel,
automaticallyStartPlayback = automaticallyStartPlayback,
nav = nav
)
@@ -534,7 +518,6 @@ fun ChannelHeader(
showBottomDiviser: Boolean,
modifier: Modifier = StdPadding,
accountViewModel: AccountViewModel,
automaticallyStartPlayback: MutableState<Boolean>,
nav: (String) -> Unit
) {
val channelHex by remember {
@@ -548,7 +531,6 @@ fun ChannelHeader(
showVideo = showVideo,
showBottomDiviser = showBottomDiviser,
accountViewModel = accountViewModel,
automaticallyStartPlayback = automaticallyStartPlayback,
nav = nav
)
}
@@ -562,7 +544,6 @@ fun ChannelHeader(
showFlag: Boolean = true,
modifier: Modifier = StdPadding,
accountViewModel: AccountViewModel,
automaticallyStartPlayback: MutableState<Boolean>,
nav: (String) -> Unit
) {
var baseChannel by remember { mutableStateOf(LocalCache.channels[channelHex]) }
@@ -583,7 +564,6 @@ fun ChannelHeader(
showFlag,
modifier,
accountViewModel,
automaticallyStartPlayback,
nav
)
}
@@ -597,7 +577,6 @@ fun ChannelHeader(
showFlag: Boolean = true,
modifier: Modifier = StdPadding,
accountViewModel: AccountViewModel,
automaticallyStartPlayback: MutableState<Boolean>,
nav: (String) -> Unit
) {
Column(Modifier.fillMaxWidth()) {
@@ -653,7 +632,8 @@ private fun ShowVideoStreaming(
}
ZoomableContentView(
content = zoomableUrlVideo
content = zoomableUrlVideo,
accountViewModel = accountViewModel
)
}
}
@@ -599,7 +599,7 @@ private fun ProfileHeader(
var zoomImageDialogOpen by remember { mutableStateOf(false) }
Box {
DrawBanner(baseUser)
DrawBanner(baseUser, accountViewModel)
Box(
modifier = Modifier
@@ -688,7 +688,7 @@ private fun ProfileHeader(
val profilePic = baseUser.profilePicture()
if (zoomImageDialogOpen && profilePic != null) {
ZoomableImageDialog(figureOutMimeType(profilePic), onDismiss = { zoomImageDialogOpen = false })
ZoomableImageDialog(figureOutMimeType(profilePic), onDismiss = { zoomImageDialogOpen = false }, accountViewModel = accountViewModel)
}
}
@@ -1260,7 +1260,7 @@ private fun WatchAndRenderBadgeImage(
@OptIn(ExperimentalFoundationApi::class)
@Composable
fun DrawBanner(baseUser: User) {
fun DrawBanner(baseUser: User, accountViewModel: AccountViewModel) {
val userState by baseUser.live().metadata.observeAsState()
val banner = remember(userState) { userState?.user?.info?.banner }
@@ -1284,7 +1284,7 @@ fun DrawBanner(baseUser: User) {
)
if (zoomImageDialogOpen) {
ZoomableImageDialog(imageUrl = figureOutMimeType(banner), onDismiss = { zoomImageDialogOpen = false })
ZoomableImageDialog(imageUrl = figureOutMimeType(banner), onDismiss = { zoomImageDialogOpen = false }, accountViewModel = accountViewModel)
}
} else {
Image(
@@ -62,7 +62,6 @@ import com.google.accompanist.permissions.rememberPermissionState
import com.vitorpamplona.amethyst.R
import com.vitorpamplona.amethyst.model.Note
import com.vitorpamplona.amethyst.service.NostrVideoDataSource
import com.vitorpamplona.amethyst.service.connectivitystatus.ConnectivityStatus
import com.vitorpamplona.amethyst.service.model.FileHeaderEvent
import com.vitorpamplona.amethyst.service.model.FileStorageHeaderEvent
import com.vitorpamplona.amethyst.ui.actions.GallerySelect
@@ -193,29 +192,6 @@ fun RenderPage(
nav: (String) -> Unit
) {
val feedState by videoFeedView.feedContent.collectAsState()
val accountState by accountViewModel.accountLiveData.observeAsState()
val settings = accountState?.account?.settings
val isMobile = ConnectivityStatus.isOnMobileData.value
val showImage = remember {
mutableStateOf(
when (settings?.automaticallyShowImages) {
true -> !isMobile
false -> false
else -> true
}
)
}
val automaticallyStartPlayback = remember {
mutableStateOf(
when (settings?.automaticallyStartPlayback) {
true -> !isMobile
false -> false
else -> true
}
)
}
Box() {
Column {
@@ -237,8 +213,6 @@ fun RenderPage(
state.feed,
pagerState,
accountViewModel,
showImage,
automaticallyStartPlayback,
nav
)
}
@@ -258,8 +232,6 @@ fun SlidingCarousel(
feed: MutableState<ImmutableList<Note>>,
pagerState: PagerState,
accountViewModel: AccountViewModel,
showImage: MutableState<Boolean>,
automaticallyStartPlayback: MutableState<Boolean>,
nav: (String) -> Unit
) {
VerticalPager(
@@ -272,7 +244,7 @@ fun SlidingCarousel(
}
) { index ->
feed.value.getOrNull(index)?.let { note ->
RenderVideoOrPictureNote(note, accountViewModel, showImage, automaticallyStartPlayback, nav)
RenderVideoOrPictureNote(note, accountViewModel, nav)
}
}
}
@@ -281,8 +253,6 @@ fun SlidingCarousel(
private fun RenderVideoOrPictureNote(
note: Note,
accountViewModel: AccountViewModel,
showImage: MutableState<Boolean>,
automaticallyStartPlayback: MutableState<Boolean>,
nav: (String) -> Unit
) {
Column(remember { Modifier.fillMaxSize(1f) }) {