check for load images option

This commit is contained in:
greenart7c3
2023-07-05 09:21:48 -03:00
parent 68e8a13f73
commit fee6f19d5e
10 changed files with 197 additions and 40 deletions
@@ -15,6 +15,7 @@ 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
@@ -24,6 +25,7 @@ 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
@@ -42,6 +44,20 @@ fun ExpandableRichTextViewer(
accountViewModel: AccountViewModel,
nav: (String) -> Unit
) {
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
}
)
}
var showFullText by remember { mutableStateOf(false) }
val whereToCut = remember(content) {
@@ -70,6 +86,7 @@ fun ExpandableRichTextViewer(
tags,
backgroundColor,
accountViewModel,
showImage,
nav
)
@@ -108,13 +108,14 @@ fun RichTextViewer(
tags: ImmutableListOfLists<String>,
backgroundColor: MutableState<Color>,
accountViewModel: AccountViewModel,
showImage: MutableState<Boolean>,
nav: (String) -> Unit
) {
Column(modifier = modifier) {
if (remember(content) { isMarkdown(content) }) {
RenderContentAsMarkdown(content, tags, nav)
} else {
RenderRegular(content, tags, canPreview, backgroundColor, accountViewModel, nav)
RenderRegular(content, tags, canPreview, backgroundColor, accountViewModel, showImage, nav)
}
}
}
@@ -127,6 +128,7 @@ private fun RenderRegular(
canPreview: Boolean,
backgroundColor: MutableState<Color>,
accountViewModel: AccountViewModel,
showImage: MutableState<Boolean>,
nav: (String) -> Unit
) {
val state by remember(content) {
@@ -156,6 +158,7 @@ private fun RenderRegular(
backgroundColor,
textStyle,
accountViewModel,
showImage,
nav
)
}
@@ -235,10 +238,11 @@ private fun RenderWordWithPreview(
backgroundColor: MutableState<Color>,
style: TextStyle,
accountViewModel: AccountViewModel,
showImage: MutableState<Boolean>,
nav: (String) -> Unit
) {
when (word) {
is ImageSegment -> ZoomableContentView(word.segmentText, state)
is ImageSegment -> ZoomableContentView(word.segmentText, state, showImage)
is LinkSegment -> UrlPreview(word.segmentText, word.segmentText)
is EmojiSegment -> RenderCustomEmoji(word.segmentText, state)
is InvoiceSegment -> MayBeInvoicePreview(word.segmentText)
@@ -256,9 +260,9 @@ private fun RenderWordWithPreview(
}
@Composable
private fun ZoomableContentView(word: String, state: RichTextViewerState) {
private fun ZoomableContentView(word: String, state: RichTextViewerState, showImage: MutableState<Boolean>) {
state.imagesForPager[word]?.let {
ZoomableContentView(it, state.imageList)
ZoomableContentView(it, state.imageList, showImage)
}
}
@@ -253,6 +253,9 @@ private fun RenderVideoPlayer(
.defaultMinSize(minHeight = 70.dp)
.align(Alignment.Center)
.onVisibilityChanges { visible ->
if (!showVideo.value) {
playerData.exoPlayer.stop()
}
if (!showVideo.value && visible && !playerData.exoPlayer.isPlaying) {
playerData.exoPlayer.pause()
} else if (visible && !playerData.exoPlayer.isPlaying) {
@@ -5,7 +5,6 @@ import android.os.Build
import android.util.Log
import android.widget.Toast
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.combinedClickable
import androidx.compose.foundation.layout.Arrangement
@@ -72,7 +71,6 @@ import coil.imageLoader
import com.vitorpamplona.amethyst.R
import com.vitorpamplona.amethyst.model.toHexKey
import com.vitorpamplona.amethyst.service.BlurHashRequester
import com.vitorpamplona.amethyst.service.connectivitystatus.ConnectivityStatus
import com.vitorpamplona.amethyst.ui.actions.CloseButton
import com.vitorpamplona.amethyst.ui.actions.LoadingAnimation
import com.vitorpamplona.amethyst.ui.actions.SaveToGallery
@@ -170,7 +168,7 @@ fun figureOutMimeType(fullUrl: String): ZoomableContent {
@Composable
@OptIn(ExperimentalFoundationApi::class)
fun ZoomableContentView(content: ZoomableContent, images: ImmutableList<ZoomableContent> = listOf(content).toImmutableList()) {
fun ZoomableContentView(content: ZoomableContent, images: ImmutableList<ZoomableContent> = listOf(content).toImmutableList(), showImage: MutableState<Boolean>) {
val clipboardManager = LocalClipboardManager.current
// store the dialog open or close state
@@ -178,12 +176,6 @@ fun ZoomableContentView(content: ZoomableContent, images: ImmutableList<Zoomable
mutableStateOf(false)
}
val isOnMobileData by ConnectivityStatus.isOnMobileData
val showImage = remember {
mutableStateOf(!isOnMobileData)
}
var mainImageModifier = MaterialTheme.colors.imageModifier
if (content is ZoomableUrlContent) {
@@ -205,7 +197,7 @@ fun ZoomableContentView(content: ZoomableContent, images: ImmutableList<Zoomable
when (content) {
is ZoomableUrlImage -> UrlImageView(content, mainImageModifier, showImage)
is ZoomableUrlVideo -> VideoView(content.url, content.description, showVideo = showImage) { dialogOpen = true }
is ZoomableLocalImage -> LocalImageView(content, mainImageModifier)
is ZoomableLocalImage -> LocalImageView(content, mainImageModifier, showImage)
is ZoomableLocalVideo ->
content.localFile?.let {
VideoView(it.toUri().toString(), content.description, showVideo = showImage) { dialogOpen = true }
@@ -220,7 +212,8 @@ fun ZoomableContentView(content: ZoomableContent, images: ImmutableList<Zoomable
@Composable
private fun LocalImageView(
content: ZoomableLocalImage,
mainImageModifier: Modifier
mainImageModifier: Modifier,
showImage: MutableState<Boolean>
) {
if (content.localFile != null && content.localFile.exists()) {
BoxWithConstraints(contentAlignment = Alignment.Center) {
@@ -245,17 +238,19 @@ private fun LocalImageView(
mutableStateOf<AsyncImagePainter.State?>(null)
}
AsyncImage(
model = content.localFile,
contentDescription = content.description,
contentScale = contentScale,
modifier = myModifier,
onState = {
painterState.value = it
}
)
if (showImage.value) {
AsyncImage(
model = content.localFile,
contentDescription = content.description,
contentScale = contentScale,
modifier = myModifier,
onState = {
painterState.value = it
}
)
}
AddedImageFeatures(painterState, content, contentScale, myModifier, verifierModifier)
AddedImageFeatures(painterState, content, contentScale, myModifier, verifierModifier, showImage)
}
} else {
BlankNote()
@@ -313,8 +308,18 @@ private fun AddedImageFeatures(
content: ZoomableLocalImage,
contentScale: ContentScale,
myModifier: Modifier,
verifiedModifier: Modifier
verifiedModifier: Modifier,
showImage: MutableState<Boolean>
) {
if (!showImage.value) {
return Column(horizontalAlignment = Alignment.CenterHorizontally) {
ClickableUrl(urlText = "${content.uri} ", url = content.uri)
Button(onClick = { showImage.value = true }) {
Text("Load image")
}
}
}
when (painter.value) {
null, is AsyncImagePainter.State.Loading -> {
if (content.blurhash != null) {
@@ -537,11 +542,11 @@ fun ZoomableImageDialog(imageUrl: ZoomableContent, allImages: ImmutableList<Zoom
pagerState = pagerState,
itemsCount = allImages.size,
itemContent = { index ->
RenderImageOrVideo(allImages[index])
RenderImageOrVideo(allImages[index], remember { mutableStateOf(true) })
}
)
} else {
RenderImageOrVideo(imageUrl)
RenderImageOrVideo(imageUrl, remember { mutableStateOf(true) })
}
Row(
@@ -566,13 +571,10 @@ fun ZoomableImageDialog(imageUrl: ZoomableContent, allImages: ImmutableList<Zoom
}
@Composable
fun RenderImageOrVideo(content: ZoomableContent) {
fun RenderImageOrVideo(content: ZoomableContent, showImage: MutableState<Boolean>) {
val mainModifier = Modifier
.fillMaxSize()
.zoomable(rememberZoomState())
val showImage = remember {
mutableStateOf(true)
}
if (content is ZoomableUrlImage) {
UrlImageView(content = content, mainImageModifier = mainModifier, showImage)
@@ -581,7 +583,7 @@ fun RenderImageOrVideo(content: ZoomableContent) {
VideoView(content.url, content.description, showVideo = showImage)
}
} else if (content is ZoomableLocalImage) {
LocalImageView(content = content, mainImageModifier = mainModifier)
LocalImageView(content = content, mainImageModifier = mainModifier, showImage)
} else if (content is ZoomableLocalVideo) {
Row(verticalAlignment = Alignment.CenterVertically, modifier = Modifier.fillMaxSize(1f)) {
content.localFile?.let {
@@ -52,6 +52,7 @@ import com.vitorpamplona.amethyst.model.User
import com.vitorpamplona.amethyst.service.OnlineChecker
import com.vitorpamplona.amethyst.service.model.ChannelCreateEvent
import com.vitorpamplona.amethyst.service.model.CommunityDefinitionEvent
import com.vitorpamplona.amethyst.service.connectivitystatus.ConnectivityStatus
import com.vitorpamplona.amethyst.service.model.LiveActivitiesEvent
import com.vitorpamplona.amethyst.service.model.LiveActivitiesEvent.Companion.STATUS_ENDED
import com.vitorpamplona.amethyst.service.model.LiveActivitiesEvent.Companion.STATUS_LIVE
@@ -93,6 +94,20 @@ 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 showImage = remember {
mutableStateOf(
when (settings?.automaticallyShowImages) {
true -> !isMobile
false -> false
else -> true
}
)
}
Crossfade(targetState = isBlank) {
if (it) {
LongPressToQuickAction(baseNote = baseNote, accountViewModel = accountViewModel) { showPopup ->
@@ -113,6 +128,7 @@ fun ChannelCardCompose(
modifier,
parentBackgroundColor,
accountViewModel,
showImage,
nav
)
}
@@ -126,6 +142,7 @@ fun CheckHiddenChannelCardCompose(
modifier: Modifier = Modifier,
parentBackgroundColor: MutableState<Color>? = null,
accountViewModel: AccountViewModel,
showImage: MutableState<Boolean>,
nav: (String) -> Unit
) {
val isHidden by accountViewModel.accountLiveData.map {
@@ -140,6 +157,7 @@ fun CheckHiddenChannelCardCompose(
modifier,
parentBackgroundColor,
accountViewModel,
showImage,
nav
)
}
@@ -153,6 +171,7 @@ fun LoadedChannelCardCompose(
modifier: Modifier = Modifier,
parentBackgroundColor: MutableState<Color>? = null,
accountViewModel: AccountViewModel,
showImage: MutableState<Boolean>,
nav: (String) -> Unit
) {
var state by remember {
@@ -184,6 +203,7 @@ fun LoadedChannelCardCompose(
modifier,
parentBackgroundColor,
accountViewModel,
showImage,
nav
)
}
@@ -197,6 +217,7 @@ fun RenderChannelCardReportState(
modifier: Modifier = Modifier,
parentBackgroundColor: MutableState<Color>? = null,
accountViewModel: AccountViewModel,
showImage: MutableState<Boolean>,
nav: (String) -> Unit
) {
var showReportedNote by remember { mutableStateOf(false) }
@@ -218,6 +239,7 @@ fun RenderChannelCardReportState(
modifier,
parentBackgroundColor,
accountViewModel,
showImage,
nav
)
}
@@ -231,6 +253,7 @@ fun NormalChannelCard(
modifier: Modifier = Modifier,
parentBackgroundColor: MutableState<Color>? = null,
accountViewModel: AccountViewModel,
showImage: MutableState<Boolean>,
nav: (String) -> Unit
) {
LongPressToQuickAction(baseNote = baseNote, accountViewModel = accountViewModel) { showPopup ->
@@ -240,6 +263,7 @@ fun NormalChannelCard(
modifier,
parentBackgroundColor,
accountViewModel,
showImage,
showPopup,
nav
)
@@ -253,6 +277,7 @@ private fun CheckNewAndRenderChannelCard(
modifier: Modifier = Modifier,
parentBackgroundColor: MutableState<Color>? = null,
accountViewModel: AccountViewModel,
showImage: MutableState<Boolean>,
showPopup: () -> Unit,
nav: (String) -> Unit
) {
@@ -310,6 +335,7 @@ private fun CheckNewAndRenderChannelCard(
InnerChannelCardWithReactions(
baseNote = baseNote,
accountViewModel = accountViewModel,
showImage,
nav = nav
)
}
@@ -319,6 +345,7 @@ private fun CheckNewAndRenderChannelCard(
fun InnerChannelCardWithReactions(
baseNote: Note,
accountViewModel: AccountViewModel,
showImage: MutableState<Boolean>,
nav: (String) -> Unit
) {
Column(StdPadding) {
@@ -339,11 +366,12 @@ fun InnerChannelCardWithReactions(
private fun RenderNoteRow(
baseNote: Note,
accountViewModel: AccountViewModel,
showImage: MutableState<Boolean>,
nav: (String) -> Unit
) {
when (remember { baseNote.event }) {
is LiveActivitiesEvent -> {
RenderLiveActivityThumb(baseNote, accountViewModel, nav)
RenderLiveActivityThumb(baseNote, accountViewModel, showImage, nav)
}
is CommunityDefinitionEvent -> {
RenderCommunitiesThumb(baseNote, accountViewModel, nav)
@@ -355,7 +383,7 @@ private fun RenderNoteRow(
}
@Composable
fun RenderLiveActivityThumb(baseNote: Note, accountViewModel: AccountViewModel, nav: (String) -> Unit) {
fun RenderLiveActivityThumb(baseNote: Note, accountViewModel: AccountViewModel, showImage: MutableState<Boolean>, nav: (String) -> Unit) {
val noteEvent = baseNote.event as? LiveActivitiesEvent ?: return
val eventUpdates by baseNote.live().metadata.observeAsState()
@@ -492,6 +520,7 @@ fun RenderLiveActivityThumb(baseNote: Note, accountViewModel: AccountViewModel,
Modifier.padding(start = 0.dp, end = 0.dp, top = 5.dp, bottom = 5.dp)
},
accountViewModel = accountViewModel,
showImage = showImage,
nav = nav
)
}
@@ -86,6 +86,7 @@ import com.vitorpamplona.amethyst.model.User
import com.vitorpamplona.amethyst.model.UserMetadata
import com.vitorpamplona.amethyst.service.OnlineChecker
import com.vitorpamplona.amethyst.service.model.ATag
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.BadgeAwardEvent
@@ -210,6 +211,20 @@ 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
}
)
}
Crossfade(targetState = isBlank) {
if (it) {
LongPressToQuickAction(baseNote = baseNote, accountViewModel = accountViewModel) { showPopup ->
@@ -235,6 +250,7 @@ fun NoteCompose(
addMarginTop,
parentBackgroundColor,
accountViewModel,
showImage,
nav
)
}
@@ -253,6 +269,7 @@ fun CheckHiddenNoteCompose(
addMarginTop: Boolean = true,
parentBackgroundColor: MutableState<Color>? = null,
accountViewModel: AccountViewModel,
showImage: MutableState<Boolean>,
nav: (String) -> Unit
) {
val isHidden by accountViewModel.accountLiveData.map {
@@ -272,6 +289,7 @@ fun CheckHiddenNoteCompose(
addMarginTop,
parentBackgroundColor,
accountViewModel,
showImage,
nav
)
}
@@ -297,6 +315,7 @@ fun LoadedNoteCompose(
addMarginTop: Boolean = true,
parentBackgroundColor: MutableState<Color>? = null,
accountViewModel: AccountViewModel,
showImage: MutableState<Boolean>,
nav: (String) -> Unit
) {
var state by remember {
@@ -333,6 +352,7 @@ fun LoadedNoteCompose(
addMarginTop,
parentBackgroundColor,
accountViewModel,
showImage,
nav
)
}
@@ -351,6 +371,7 @@ fun RenderReportState(
addMarginTop: Boolean = true,
parentBackgroundColor: MutableState<Color>? = null,
accountViewModel: AccountViewModel,
showImage: MutableState<Boolean>,
nav: (String) -> Unit
) {
var showReportedNote by remember { mutableStateOf(false) }
@@ -380,6 +401,7 @@ fun RenderReportState(
canPreview,
parentBackgroundColor,
accountViewModel,
showImage,
nav
)
}
@@ -415,6 +437,7 @@ fun NormalNote(
canPreview: Boolean = true,
parentBackgroundColor: MutableState<Color>? = null,
accountViewModel: AccountViewModel,
showImage: MutableState<Boolean>,
nav: (String) -> Unit
) {
when (baseNote.event) {
@@ -423,6 +446,7 @@ fun NormalNote(
showVideo = !makeItShort,
showBottomDiviser = true,
accountViewModel = accountViewModel,
showImage = showImage,
nav = nav
)
is CommunityDefinitionEvent -> CommunityHeader(
@@ -448,6 +472,7 @@ fun NormalNote(
canPreview,
parentBackgroundColor,
accountViewModel,
showImage,
showPopup,
nav
)
@@ -745,6 +770,7 @@ private fun CheckNewAndRenderNote(
canPreview: Boolean = true,
parentBackgroundColor: MutableState<Color>? = null,
accountViewModel: AccountViewModel,
showImage: MutableState<Boolean>,
showPopup: () -> Unit,
nav: (String) -> Unit
) {
@@ -809,6 +835,7 @@ private fun CheckNewAndRenderNote(
makeItShort = makeItShort,
canPreview = canPreview,
accountViewModel = accountViewModel,
showImage = showImage,
nav = nav
)
}
@@ -859,6 +886,7 @@ fun InnerNoteWithReactions(
makeItShort: Boolean,
canPreview: Boolean,
accountViewModel: AccountViewModel,
showImage: MutableState<Boolean>,
nav: (String) -> Unit
) {
val notBoostedNorQuote = !isBoostedNote && !isQuotedNote
@@ -897,6 +925,7 @@ fun InnerNoteWithReactions(
showSecondRow = showSecondRow,
backgroundColor = backgroundColor,
accountViewModel = accountViewModel,
showImage = showImage,
nav = nav
)
}
@@ -942,6 +971,7 @@ private fun NoteBody(
showSecondRow: Boolean,
backgroundColor: MutableState<Color>,
accountViewModel: AccountViewModel,
showImage: MutableState<Boolean>,
nav: (String) -> Unit
) {
FirstUserInfoRow(
@@ -967,6 +997,7 @@ private fun NoteBody(
unPackReply,
backgroundColor,
accountViewModel,
showImage,
nav
)
}
@@ -977,6 +1008,7 @@ private fun NoteBody(
makeItShort,
canPreview,
accountViewModel,
showImage,
nav
)
}
@@ -988,11 +1020,12 @@ private fun RenderNoteRow(
makeItShort: Boolean,
canPreview: Boolean,
accountViewModel: AccountViewModel,
showImage: MutableState<Boolean>,
nav: (String) -> Unit
) {
when (baseNote.event) {
is AppDefinitionEvent -> {
RenderAppDefinition(baseNote, accountViewModel, nav)
RenderAppDefinition(baseNote, accountViewModel, showImage, nav)
}
is ReactionEvent -> {
@@ -1236,6 +1269,7 @@ fun RenderPoll(
fun RenderAppDefinition(
note: Note,
accountViewModel: AccountViewModel,
showImage: MutableState<Boolean>,
nav: (String) -> Unit
) {
val noteEvent = note.event as? AppDefinitionEvent ?: return
@@ -2065,6 +2099,7 @@ private fun ReplyRow(
unPackReply: Boolean,
backgroundColor: MutableState<Color>,
accountViewModel: AccountViewModel,
showImage: MutableState<Boolean>,
nav: (String) -> Unit
) {
val noteEvent = note.event
@@ -2100,6 +2135,7 @@ private fun ReplyRow(
showBottomDiviser = false,
modifier = remember { Modifier.padding(vertical = 5.dp) },
accountViewModel = accountViewModel,
showImage = showImage,
nav = nav
)
@@ -55,6 +55,7 @@ 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
@@ -244,6 +245,19 @@ fun NoteMaster(
val accountState by accountViewModel.accountLiveData.observeAsState()
val account = accountState?.account ?: return
val settings = accountState?.account?.settings
val isMobile = ConnectivityStatus.isOnMobileData.value
val showImage = remember {
mutableStateOf(
when (settings?.automaticallyShowImages) {
true -> !isMobile
false -> false
else -> true
}
)
}
var showHiddenNote by remember { mutableStateOf(false) }
val context = LocalContext.current
@@ -398,7 +412,7 @@ fun NoteMaster(
) {
Column() {
if ((noteEvent is ChannelCreateEvent || noteEvent is ChannelMetadataEvent) && note.channelHex() != null) {
ChannelHeader(channelHex = note.channelHex()!!, showVideo = true, showBottomDiviser = false, accountViewModel = accountViewModel, nav = nav)
ChannelHeader(channelHex = note.channelHex()!!, showVideo = true, showBottomDiviser = false, accountViewModel = accountViewModel, showImage = showImage, nav = nav)
} else if (noteEvent is FileHeaderEvent) {
FileHeaderDisplay(baseNote, accountViewModel)
} else if (noteEvent is FileStorageHeaderEvent) {
@@ -431,7 +445,7 @@ fun NoteMaster(
nav
)
} else if (noteEvent is AppDefinitionEvent) {
RenderAppDefinition(baseNote, accountViewModel, nav)
RenderAppDefinition(baseNote, accountViewModel, showImage, nav)
} else if (noteEvent is HighlightEvent) {
DisplayHighlight(
noteEvent.quote(),
@@ -87,6 +87,7 @@ 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
@@ -199,6 +200,20 @@ fun ChannelScreen(
val lifeCycleOwner = LocalLifecycleOwner.current
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
}
)
}
LaunchedEffect(Unit) {
NostrChannelDataSource.start()
feedViewModel.invalidateData()
@@ -239,6 +254,7 @@ fun ChannelScreen(
showVideo = true,
showBottomDiviser = true,
accountViewModel = accountViewModel,
showImage = showImage,
nav = nav
)
@@ -518,6 +534,7 @@ fun ChannelHeader(
showBottomDiviser: Boolean,
modifier: Modifier = StdPadding,
accountViewModel: AccountViewModel,
showImage: MutableState<Boolean>,
nav: (String) -> Unit
) {
val channelHex by remember {
@@ -531,6 +548,7 @@ fun ChannelHeader(
showVideo = showVideo,
showBottomDiviser = showBottomDiviser,
accountViewModel = accountViewModel,
showImage = showImage,
nav = nav
)
}
@@ -544,6 +562,7 @@ fun ChannelHeader(
showFlag: Boolean = true,
modifier: Modifier = StdPadding,
accountViewModel: AccountViewModel,
showImage: MutableState<Boolean>,
nav: (String) -> Unit
) {
var baseChannel by remember { mutableStateOf(LocalCache.channels[channelHex]) }
@@ -564,6 +583,7 @@ fun ChannelHeader(
showFlag,
modifier,
accountViewModel,
showImage,
nav
)
}
@@ -577,6 +597,7 @@ fun ChannelHeader(
showFlag: Boolean = true,
modifier: Modifier = StdPadding,
accountViewModel: AccountViewModel,
showImage: MutableState<Boolean>,
nav: (String) -> Unit
) {
Column(Modifier.fillMaxWidth()) {
@@ -57,6 +57,7 @@ import com.vitorpamplona.amethyst.model.LocalCache
import com.vitorpamplona.amethyst.model.Note
import com.vitorpamplona.amethyst.model.User
import com.vitorpamplona.amethyst.service.NostrUserProfileDataSource
import com.vitorpamplona.amethyst.service.connectivitystatus.ConnectivityStatus
import com.vitorpamplona.amethyst.service.model.AppDefinitionEvent
import com.vitorpamplona.amethyst.service.model.BadgeDefinitionEvent
import com.vitorpamplona.amethyst.service.model.BadgeProfilesEvent
@@ -598,6 +599,20 @@ private fun ProfileHeader(
var popupExpanded by remember { mutableStateOf(false) }
var zoomImageDialogOpen by remember { mutableStateOf(false) }
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
}
)
}
Box {
DrawBanner(baseUser)
@@ -1260,7 +1275,7 @@ private fun WatchAndRenderBadgeImage(
@OptIn(ExperimentalFoundationApi::class)
@Composable
public fun DrawBanner(baseUser: User) {
fun DrawBanner(baseUser: User) {
val userState by baseUser.live().metadata.observeAsState()
val banner = remember(userState) { userState?.user?.info?.banner }
@@ -62,6 +62,7 @@ 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
@@ -192,7 +193,19 @@ 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
}
)
}
Box() {
Column {
Crossfade(
@@ -213,6 +226,7 @@ fun RenderPage(
state.feed,
pagerState,
accountViewModel,
showImage,
nav
)
}
@@ -232,6 +246,7 @@ fun SlidingCarousel(
feed: MutableState<ImmutableList<Note>>,
pagerState: PagerState,
accountViewModel: AccountViewModel,
showImage: MutableState<Boolean>,
nav: (String) -> Unit
) {
VerticalPager(
@@ -244,7 +259,7 @@ fun SlidingCarousel(
}
) { index ->
feed.value.getOrNull(index)?.let { note ->
RenderVideoOrPictureNote(note, accountViewModel, nav)
RenderVideoOrPictureNote(note, accountViewModel, showImage, nav)
}
}
}
@@ -253,6 +268,7 @@ fun SlidingCarousel(
private fun RenderVideoOrPictureNote(
note: Note,
accountViewModel: AccountViewModel,
showImage: MutableState<Boolean>,
nav: (String) -> Unit
) {
Column(remember { Modifier.fillMaxSize(1f) }) {