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