Refactoring some names for the parsers.
This commit is contained in:
File diff suppressed because it is too large
Load Diff
+2
-2
@@ -43,7 +43,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.commons.ExpandableTextParser
|
||||
import com.vitorpamplona.amethyst.commons.ExpandableTextCutOffCalculator
|
||||
import com.vitorpamplona.amethyst.ui.note.getGradient
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
|
||||
import com.vitorpamplona.amethyst.ui.theme.ButtonBorder
|
||||
@@ -63,7 +63,7 @@ fun ExpandableRichTextViewer(
|
||||
) {
|
||||
var showFullText by remember { mutableStateOf(false) }
|
||||
|
||||
val whereToCut = remember(content) { ExpandableTextParser.computeWhereToCutIfPostIsTooLong(content) }
|
||||
val whereToCut = remember(content) { ExpandableTextCutOffCalculator.indexToCutOff(content) }
|
||||
|
||||
val text by
|
||||
remember(content) {
|
||||
|
||||
@@ -29,8 +29,8 @@ import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import com.vitorpamplona.amethyst.commons.ZoomableUrlImage
|
||||
import com.vitorpamplona.amethyst.commons.ZoomableUrlVideo
|
||||
import com.vitorpamplona.amethyst.commons.MediaUrlImage
|
||||
import com.vitorpamplona.amethyst.commons.MediaUrlVideo
|
||||
import com.vitorpamplona.amethyst.model.UrlCachedPreviewer
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
|
||||
import com.vitorpamplona.amethyst.ui.theme.HalfVertPadding
|
||||
@@ -69,7 +69,7 @@ fun LoadUrlPreview(
|
||||
if (state.previewInfo.mimeType.type == "image") {
|
||||
Box(modifier = HalfVertPadding) {
|
||||
ZoomableContentView(
|
||||
content = ZoomableUrlImage(url),
|
||||
content = MediaUrlImage(url),
|
||||
roundedCorner = true,
|
||||
accountViewModel = accountViewModel,
|
||||
)
|
||||
@@ -77,7 +77,7 @@ fun LoadUrlPreview(
|
||||
} else if (state.previewInfo.mimeType.type == "video") {
|
||||
Box(modifier = HalfVertPadding) {
|
||||
ZoomableContentView(
|
||||
content = ZoomableUrlVideo(url),
|
||||
content = MediaUrlVideo(url),
|
||||
roundedCorner = true,
|
||||
accountViewModel = accountViewModel,
|
||||
)
|
||||
|
||||
@@ -78,6 +78,7 @@ import com.vitorpamplona.amethyst.commons.HashTagSegment
|
||||
import com.vitorpamplona.amethyst.commons.ImageSegment
|
||||
import com.vitorpamplona.amethyst.commons.InvoiceSegment
|
||||
import com.vitorpamplona.amethyst.commons.LinkSegment
|
||||
import com.vitorpamplona.amethyst.commons.MediaUrlImage
|
||||
import com.vitorpamplona.amethyst.commons.PhoneSegment
|
||||
import com.vitorpamplona.amethyst.commons.RegularTextSegment
|
||||
import com.vitorpamplona.amethyst.commons.RichTextParser
|
||||
@@ -85,7 +86,6 @@ import com.vitorpamplona.amethyst.commons.RichTextViewerState
|
||||
import com.vitorpamplona.amethyst.commons.SchemelessUrlSegment
|
||||
import com.vitorpamplona.amethyst.commons.Segment
|
||||
import com.vitorpamplona.amethyst.commons.WithdrawSegment
|
||||
import com.vitorpamplona.amethyst.commons.ZoomableUrlImage
|
||||
import com.vitorpamplona.amethyst.model.HashtagIcon
|
||||
import com.vitorpamplona.amethyst.model.Note
|
||||
import com.vitorpamplona.amethyst.model.User
|
||||
@@ -417,7 +417,7 @@ private fun RenderContentAsMarkdown(
|
||||
ZoomableContentView(
|
||||
content =
|
||||
remember(destination, tags) {
|
||||
RichTextParser().parseMediaUrl(destination, tags ?: EmptyTagList) ?: ZoomableUrlImage(url = destination)
|
||||
RichTextParser().parseMediaUrl(destination, tags ?: EmptyTagList) ?: MediaUrlImage(url = destination)
|
||||
},
|
||||
roundedCorner = true,
|
||||
accountViewModel = accountViewModel,
|
||||
|
||||
@@ -106,13 +106,13 @@ import coil.compose.AsyncImage
|
||||
import coil.compose.AsyncImagePainter
|
||||
import coil.imageLoader
|
||||
import com.vitorpamplona.amethyst.R
|
||||
import com.vitorpamplona.amethyst.commons.ZoomableContent
|
||||
import com.vitorpamplona.amethyst.commons.ZoomableLocalImage
|
||||
import com.vitorpamplona.amethyst.commons.ZoomableLocalVideo
|
||||
import com.vitorpamplona.amethyst.commons.ZoomablePreloadedContent
|
||||
import com.vitorpamplona.amethyst.commons.ZoomableUrlContent
|
||||
import com.vitorpamplona.amethyst.commons.ZoomableUrlImage
|
||||
import com.vitorpamplona.amethyst.commons.ZoomableUrlVideo
|
||||
import com.vitorpamplona.amethyst.commons.BaseMediaContent
|
||||
import com.vitorpamplona.amethyst.commons.MediaLocalImage
|
||||
import com.vitorpamplona.amethyst.commons.MediaLocalVideo
|
||||
import com.vitorpamplona.amethyst.commons.MediaPreloadedContent
|
||||
import com.vitorpamplona.amethyst.commons.MediaUrlContent
|
||||
import com.vitorpamplona.amethyst.commons.MediaUrlImage
|
||||
import com.vitorpamplona.amethyst.commons.MediaUrlVideo
|
||||
import com.vitorpamplona.amethyst.service.BlurHashRequester
|
||||
import com.vitorpamplona.amethyst.ui.actions.CloseButton
|
||||
import com.vitorpamplona.amethyst.ui.actions.InformationDialog
|
||||
@@ -147,8 +147,8 @@ import net.engawapg.lib.zoomable.zoomable
|
||||
@Composable
|
||||
@OptIn(ExperimentalFoundationApi::class)
|
||||
fun ZoomableContentView(
|
||||
content: ZoomableContent,
|
||||
images: ImmutableList<ZoomableContent> = remember(content) { listOf(content).toImmutableList() },
|
||||
content: BaseMediaContent,
|
||||
images: ImmutableList<BaseMediaContent> = remember(content) { listOf(content).toImmutableList() },
|
||||
roundedCorner: Boolean,
|
||||
accountViewModel: AccountViewModel,
|
||||
) {
|
||||
@@ -169,13 +169,13 @@ fun ZoomableContentView(
|
||||
Modifier.fillMaxWidth()
|
||||
}
|
||||
|
||||
if (content is ZoomableUrlContent) {
|
||||
if (content is MediaUrlContent) {
|
||||
mainImageModifier =
|
||||
mainImageModifier.combinedClickable(
|
||||
onClick = { dialogOpen = true },
|
||||
onLongClick = { shareOpen.value = true },
|
||||
)
|
||||
} else if (content is ZoomablePreloadedContent) {
|
||||
} else if (content is MediaPreloadedContent) {
|
||||
mainImageModifier =
|
||||
mainImageModifier.combinedClickable(
|
||||
onClick = { dialogOpen = true },
|
||||
@@ -186,11 +186,11 @@ fun ZoomableContentView(
|
||||
}
|
||||
|
||||
when (content) {
|
||||
is ZoomableUrlImage ->
|
||||
is MediaUrlImage ->
|
||||
SensitivityWarning(content.contentWarning != null, accountViewModel) {
|
||||
UrlImageView(content, mainImageModifier, accountViewModel = accountViewModel)
|
||||
}
|
||||
is ZoomableUrlVideo ->
|
||||
is MediaUrlVideo ->
|
||||
SensitivityWarning(content.contentWarning != null, accountViewModel) {
|
||||
VideoView(
|
||||
videoUri = content.url,
|
||||
@@ -205,9 +205,9 @@ fun ZoomableContentView(
|
||||
accountViewModel = accountViewModel,
|
||||
)
|
||||
}
|
||||
is ZoomableLocalImage ->
|
||||
is MediaLocalImage ->
|
||||
LocalImageView(content, mainImageModifier, accountViewModel = accountViewModel)
|
||||
is ZoomableLocalVideo ->
|
||||
is MediaLocalVideo ->
|
||||
content.localFile?.let {
|
||||
VideoView(
|
||||
videoUri = it.toUri().toString(),
|
||||
@@ -229,7 +229,7 @@ fun ZoomableContentView(
|
||||
|
||||
@Composable
|
||||
private fun LocalImageView(
|
||||
content: ZoomableLocalImage,
|
||||
content: MediaLocalImage,
|
||||
mainImageModifier: Modifier,
|
||||
topPaddingForControllers: Dp = Dp.Unspecified,
|
||||
accountViewModel: AccountViewModel,
|
||||
@@ -296,7 +296,7 @@ private fun LocalImageView(
|
||||
|
||||
@Composable
|
||||
private fun UrlImageView(
|
||||
content: ZoomableUrlImage,
|
||||
content: MediaUrlImage,
|
||||
mainImageModifier: Modifier,
|
||||
topPaddingForControllers: Dp = Dp.Unspecified,
|
||||
accountViewModel: AccountViewModel,
|
||||
@@ -419,7 +419,7 @@ private fun InlineDownloadIcon(showImage: MutableState<Boolean>) =
|
||||
@OptIn(ExperimentalLayoutApi::class)
|
||||
private fun AddedImageFeatures(
|
||||
painter: MutableState<AsyncImagePainter.State?>,
|
||||
content: ZoomableLocalImage,
|
||||
content: MediaLocalImage,
|
||||
contentScale: ContentScale,
|
||||
myModifier: Modifier,
|
||||
verifiedModifier: Modifier,
|
||||
@@ -481,7 +481,7 @@ private fun AddedImageFeatures(
|
||||
@OptIn(ExperimentalLayoutApi::class)
|
||||
private fun AddedImageFeatures(
|
||||
painter: MutableState<AsyncImagePainter.State?>,
|
||||
content: ZoomableUrlImage,
|
||||
content: MediaUrlImage,
|
||||
contentScale: ContentScale,
|
||||
myModifier: Modifier,
|
||||
verifiedModifier: Modifier,
|
||||
@@ -576,8 +576,8 @@ fun aspectRatio(dim: String?): Float? {
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun DisplayUrlWithLoadingSymbol(content: ZoomableContent) {
|
||||
var cnt by remember { mutableStateOf<ZoomableContent?>(null) }
|
||||
private fun DisplayUrlWithLoadingSymbol(content: BaseMediaContent) {
|
||||
var cnt by remember { mutableStateOf<BaseMediaContent?>(null) }
|
||||
|
||||
LaunchedEffect(Unit) {
|
||||
launch(Dispatchers.IO) {
|
||||
@@ -590,7 +590,7 @@ private fun DisplayUrlWithLoadingSymbol(content: ZoomableContent) {
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun DisplayUrlWithLoadingSymbolWait(content: ZoomableContent) {
|
||||
private fun DisplayUrlWithLoadingSymbolWait(content: BaseMediaContent) {
|
||||
val uri = LocalUriHandler.current
|
||||
|
||||
val primary = MaterialTheme.colorScheme.primary
|
||||
@@ -602,7 +602,7 @@ private fun DisplayUrlWithLoadingSymbolWait(content: ZoomableContent) {
|
||||
val annotatedTermsString =
|
||||
remember {
|
||||
buildAnnotatedString {
|
||||
if (content is ZoomableUrlContent) {
|
||||
if (content is MediaUrlContent) {
|
||||
withStyle(clickableTextStyle) {
|
||||
pushStringAnnotation("routeToImage", "")
|
||||
append(content.url + " ")
|
||||
@@ -624,7 +624,7 @@ private fun DisplayUrlWithLoadingSymbolWait(content: ZoomableContent) {
|
||||
|
||||
val pressIndicator =
|
||||
remember {
|
||||
if (content is ZoomableUrlContent) {
|
||||
if (content is MediaUrlContent) {
|
||||
Modifier.clickable { runCatching { uri.openUri(content.url) } }
|
||||
} else {
|
||||
Modifier
|
||||
@@ -676,8 +676,8 @@ fun DisplayBlurHash(
|
||||
|
||||
@Composable
|
||||
fun ZoomableImageDialog(
|
||||
imageUrl: ZoomableContent,
|
||||
allImages: ImmutableList<ZoomableContent> = listOf(imageUrl).toImmutableList(),
|
||||
imageUrl: BaseMediaContent,
|
||||
allImages: ImmutableList<BaseMediaContent> = listOf(imageUrl).toImmutableList(),
|
||||
onDismiss: () -> Unit,
|
||||
accountViewModel: AccountViewModel,
|
||||
) {
|
||||
@@ -740,8 +740,8 @@ fun ZoomableImageDialog(
|
||||
@Composable
|
||||
@OptIn(ExperimentalFoundationApi::class)
|
||||
private fun DialogContent(
|
||||
allImages: ImmutableList<ZoomableContent>,
|
||||
imageUrl: ZoomableContent,
|
||||
allImages: ImmutableList<BaseMediaContent>,
|
||||
imageUrl: BaseMediaContent,
|
||||
onDismiss: () -> Unit,
|
||||
accountViewModel: AccountViewModel,
|
||||
) {
|
||||
@@ -801,13 +801,13 @@ private fun DialogContent(
|
||||
CloseButton(onPress = onDismiss)
|
||||
|
||||
allImages.getOrNull(pagerState.currentPage)?.let { myContent ->
|
||||
if (myContent is ZoomableUrlContent) {
|
||||
if (myContent is MediaUrlContent) {
|
||||
Row {
|
||||
CopyToClipboard(content = myContent)
|
||||
Spacer(modifier = StdHorzSpacer)
|
||||
SaveToGallery(url = myContent.url)
|
||||
}
|
||||
} else if (myContent is ZoomableLocalImage && myContent.localFileExists()) {
|
||||
} else if (myContent is MediaLocalImage && myContent.localFileExists()) {
|
||||
SaveToGallery(
|
||||
localFile = myContent.localFile!!,
|
||||
mimeType = myContent.mimeType,
|
||||
@@ -857,7 +857,7 @@ fun InlineCarrousel(
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun CopyToClipboard(content: ZoomableContent) {
|
||||
private fun CopyToClipboard(content: BaseMediaContent) {
|
||||
val popupExpanded = remember { mutableStateOf(false) }
|
||||
|
||||
OutlinedButton(
|
||||
@@ -877,7 +877,7 @@ private fun CopyToClipboard(content: ZoomableContent) {
|
||||
@Composable
|
||||
private fun ShareImageAction(
|
||||
popupExpanded: MutableState<Boolean>,
|
||||
content: ZoomableContent,
|
||||
content: BaseMediaContent,
|
||||
onDismiss: () -> Unit,
|
||||
) {
|
||||
DropdownMenu(
|
||||
@@ -886,7 +886,7 @@ private fun ShareImageAction(
|
||||
) {
|
||||
val clipboardManager = LocalClipboardManager.current
|
||||
|
||||
if (content is ZoomableUrlContent) {
|
||||
if (content is MediaUrlContent) {
|
||||
DropdownMenuItem(
|
||||
text = { Text(stringResource(R.string.copy_url_to_clipboard)) },
|
||||
onClick = {
|
||||
@@ -905,7 +905,7 @@ private fun ShareImageAction(
|
||||
}
|
||||
}
|
||||
|
||||
if (content is ZoomablePreloadedContent) {
|
||||
if (content is MediaPreloadedContent) {
|
||||
DropdownMenuItem(
|
||||
text = { Text(stringResource(R.string.copy_the_note_id_to_the_clipboard)) },
|
||||
onClick = {
|
||||
@@ -919,7 +919,7 @@ private fun ShareImageAction(
|
||||
|
||||
@Composable
|
||||
private fun RenderImageOrVideo(
|
||||
content: ZoomableContent,
|
||||
content: BaseMediaContent,
|
||||
roundedCorner: Boolean,
|
||||
topPaddingForControllers: Dp = Dp.Unspecified,
|
||||
onControllerVisibilityChanged: ((Boolean) -> Unit)? = null,
|
||||
@@ -928,7 +928,7 @@ private fun RenderImageOrVideo(
|
||||
) {
|
||||
val automaticallyStartPlayback = remember { mutableStateOf<Boolean>(true) }
|
||||
|
||||
if (content is ZoomableUrlImage) {
|
||||
if (content is MediaUrlImage) {
|
||||
val mainModifier =
|
||||
Modifier.fillMaxSize()
|
||||
.zoomable(
|
||||
@@ -947,7 +947,7 @@ private fun RenderImageOrVideo(
|
||||
accountViewModel,
|
||||
alwayShowImage = true,
|
||||
)
|
||||
} else if (content is ZoomableUrlVideo) {
|
||||
} else if (content is MediaUrlVideo) {
|
||||
Row(verticalAlignment = Alignment.CenterVertically, modifier = Modifier.fillMaxSize(1f)) {
|
||||
VideoViewInner(
|
||||
videoUri = content.url,
|
||||
@@ -960,7 +960,7 @@ private fun RenderImageOrVideo(
|
||||
onControllerVisibilityChanged = onControllerVisibilityChanged,
|
||||
)
|
||||
}
|
||||
} else if (content is ZoomableLocalImage) {
|
||||
} else if (content is MediaLocalImage) {
|
||||
val mainModifier =
|
||||
Modifier.fillMaxSize()
|
||||
.zoomable(
|
||||
@@ -979,7 +979,7 @@ private fun RenderImageOrVideo(
|
||||
accountViewModel,
|
||||
alwayShowImage = true,
|
||||
)
|
||||
} else if (content is ZoomableLocalVideo) {
|
||||
} else if (content is MediaLocalVideo) {
|
||||
Row(verticalAlignment = Alignment.CenterVertically, modifier = Modifier.fillMaxSize(1f)) {
|
||||
content.localFile?.let {
|
||||
VideoViewInner(
|
||||
@@ -999,7 +999,7 @@ private fun RenderImageOrVideo(
|
||||
|
||||
@OptIn(ExperimentalCoilApi::class)
|
||||
private fun verifyHash(
|
||||
content: ZoomableUrlContent,
|
||||
content: MediaUrlContent,
|
||||
context: Context,
|
||||
): Boolean? {
|
||||
if (content.hash == null) return null
|
||||
|
||||
@@ -95,12 +95,12 @@ import coil.request.SuccessResult
|
||||
import com.fonfon.kgeohash.GeoHash
|
||||
import com.fonfon.kgeohash.toGeoHash
|
||||
import com.vitorpamplona.amethyst.R
|
||||
import com.vitorpamplona.amethyst.commons.BaseMediaContent
|
||||
import com.vitorpamplona.amethyst.commons.MediaLocalImage
|
||||
import com.vitorpamplona.amethyst.commons.MediaLocalVideo
|
||||
import com.vitorpamplona.amethyst.commons.MediaUrlImage
|
||||
import com.vitorpamplona.amethyst.commons.MediaUrlVideo
|
||||
import com.vitorpamplona.amethyst.commons.RichTextParser
|
||||
import com.vitorpamplona.amethyst.commons.ZoomableContent
|
||||
import com.vitorpamplona.amethyst.commons.ZoomableLocalImage
|
||||
import com.vitorpamplona.amethyst.commons.ZoomableLocalVideo
|
||||
import com.vitorpamplona.amethyst.commons.ZoomableUrlImage
|
||||
import com.vitorpamplona.amethyst.commons.ZoomableUrlVideo
|
||||
import com.vitorpamplona.amethyst.model.AddressableNote
|
||||
import com.vitorpamplona.amethyst.model.Channel
|
||||
import com.vitorpamplona.amethyst.model.Note
|
||||
@@ -3065,9 +3065,9 @@ fun FileHeaderDisplay(
|
||||
val isImage = RichTextParser.isImageUrl(fullUrl)
|
||||
val uri = note.toNostrUri()
|
||||
|
||||
mutableStateOf<ZoomableContent>(
|
||||
mutableStateOf<BaseMediaContent>(
|
||||
if (isImage) {
|
||||
ZoomableUrlImage(
|
||||
MediaUrlImage(
|
||||
url = fullUrl,
|
||||
description = description,
|
||||
hash = hash,
|
||||
@@ -3076,7 +3076,7 @@ fun FileHeaderDisplay(
|
||||
uri = uri,
|
||||
)
|
||||
} else {
|
||||
ZoomableUrlVideo(
|
||||
MediaUrlVideo(
|
||||
url = fullUrl,
|
||||
description = description,
|
||||
hash = hash,
|
||||
@@ -3124,9 +3124,9 @@ fun VideoDisplay(
|
||||
val isImage = RichTextParser.isImageUrl(fullUrl)
|
||||
val uri = note.toNostrUri()
|
||||
|
||||
mutableStateOf<ZoomableContent>(
|
||||
mutableStateOf<BaseMediaContent>(
|
||||
if (isImage) {
|
||||
ZoomableUrlImage(
|
||||
MediaUrlImage(
|
||||
url = fullUrl,
|
||||
description = description,
|
||||
hash = hash,
|
||||
@@ -3135,7 +3135,7 @@ fun VideoDisplay(
|
||||
uri = uri,
|
||||
)
|
||||
} else {
|
||||
ZoomableUrlVideo(
|
||||
MediaUrlVideo(
|
||||
url = fullUrl,
|
||||
description = description,
|
||||
hash = hash,
|
||||
@@ -3265,17 +3265,17 @@ private fun ObserverAndRenderNIP95(
|
||||
|
||||
val newContent =
|
||||
if (mimeType?.startsWith("image") == true) {
|
||||
ZoomableLocalImage(
|
||||
MediaLocalImage(
|
||||
localFile = localDir,
|
||||
mimeType = mimeType,
|
||||
description = description,
|
||||
blurhash = blurHash,
|
||||
dim = dimensions,
|
||||
blurhash = blurHash,
|
||||
isVerified = true,
|
||||
uri = uri,
|
||||
)
|
||||
} else {
|
||||
ZoomableLocalVideo(
|
||||
MediaLocalVideo(
|
||||
localFile = localDir,
|
||||
mimeType = mimeType,
|
||||
description = description,
|
||||
@@ -3286,7 +3286,7 @@ private fun ObserverAndRenderNIP95(
|
||||
)
|
||||
}
|
||||
|
||||
mutableStateOf<ZoomableContent?>(newContent)
|
||||
mutableStateOf<BaseMediaContent?>(newContent)
|
||||
}
|
||||
|
||||
Crossfade(targetState = content) {
|
||||
|
||||
@@ -101,7 +101,7 @@ import androidx.lifecycle.distinctUntilChanged
|
||||
import androidx.lifecycle.map
|
||||
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||
import com.vitorpamplona.amethyst.R
|
||||
import com.vitorpamplona.amethyst.commons.ZoomableUrlVideo
|
||||
import com.vitorpamplona.amethyst.commons.MediaUrlVideo
|
||||
import com.vitorpamplona.amethyst.model.AddressableNote
|
||||
import com.vitorpamplona.amethyst.model.Channel
|
||||
import com.vitorpamplona.amethyst.model.LiveActivitiesChannel
|
||||
@@ -681,7 +681,7 @@ fun ShowVideoStreaming(
|
||||
) {
|
||||
val zoomableUrlVideo =
|
||||
remember(it) {
|
||||
ZoomableUrlVideo(
|
||||
MediaUrlVideo(
|
||||
url = url,
|
||||
description = title,
|
||||
artworkUri = artworkUri,
|
||||
|
||||
Reference in New Issue
Block a user