kopia lustrzana https://github.com/vitorpamplona/amethyst
Fixes "author_is_elon" bug
rodzic
22adbddd88
commit
737244fb60
|
@ -3,10 +3,6 @@ package com.vitorpamplona.amethyst.model
|
|||
import com.baha.url.preview.BahaUrlPreview
|
||||
import com.baha.url.preview.IUrlPreviewCallback
|
||||
import com.baha.url.preview.UrlInfoItem
|
||||
import com.vitorpamplona.amethyst.ui.components.imageExtension
|
||||
import com.vitorpamplona.amethyst.ui.components.isValidURL
|
||||
import com.vitorpamplona.amethyst.ui.components.noProtocolUrlValidator
|
||||
import com.vitorpamplona.amethyst.ui.components.videoExtension
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.Job
|
||||
|
@ -47,29 +43,4 @@ object UrlCachedPreviewer {
|
|||
).fetchUrlPreview()
|
||||
}
|
||||
}
|
||||
|
||||
fun findUrlsInMessage(message: String): List<String> {
|
||||
return message.split('\n').map { paragraph ->
|
||||
paragraph.split(' ').filter { word: String ->
|
||||
isValidURL(word) || noProtocolUrlValidator.matcher(word).matches()
|
||||
}
|
||||
}.flatten()
|
||||
}
|
||||
|
||||
fun preloadPreviewsFor(note: Note) {
|
||||
note.event?.content()?.let {
|
||||
findUrlsInMessage(it).forEach {
|
||||
val removedParamsFromUrl = it.split("?")[0].lowercase()
|
||||
if (imageExtension.matcher(removedParamsFromUrl).matches()) {
|
||||
// Preload Images? Isn't this too heavy?
|
||||
} else if (videoExtension.matcher(removedParamsFromUrl).matches()) {
|
||||
// Do nothing for now.
|
||||
} else if (isValidURL(removedParamsFromUrl)) {
|
||||
previewInfo(it)
|
||||
} else {
|
||||
previewInfo("https://$it")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -167,7 +167,7 @@ fun NewPostView(onClose: () -> Unit, baseReplyTo: Note? = null, quote: Note? = n
|
|||
if (isValidURL(myUrlPreview)) {
|
||||
val removedParamsFromUrl =
|
||||
myUrlPreview.split("?")[0].lowercase()
|
||||
if (imageExtension.matcher(removedParamsFromUrl).matches()) {
|
||||
if (imageExtensions.any { removedParamsFromUrl.endsWith(it, true) }) {
|
||||
AsyncImage(
|
||||
model = myUrlPreview,
|
||||
contentDescription = myUrlPreview,
|
||||
|
@ -182,9 +182,7 @@ fun NewPostView(onClose: () -> Unit, baseReplyTo: Note? = null, quote: Note? = n
|
|||
RoundedCornerShape(15.dp)
|
||||
)
|
||||
)
|
||||
} else if (videoExtension.matcher(removedParamsFromUrl)
|
||||
.matches()
|
||||
) {
|
||||
} else if (videoExtensions.any { removedParamsFromUrl.endsWith(it, true) }) {
|
||||
VideoView(myUrlPreview)
|
||||
} else {
|
||||
UrlPreview(myUrlPreview, myUrlPreview)
|
||||
|
|
|
@ -46,8 +46,8 @@ import java.net.URISyntaxException
|
|||
import java.net.URL
|
||||
import java.util.regex.Pattern
|
||||
|
||||
val imageExtension = Pattern.compile("(.*/)*.+\\.(png|jpg|gif|bmp|jpeg|webp|svg)$", Pattern.CASE_INSENSITIVE)
|
||||
val videoExtension = Pattern.compile("(.*/)*.+\\.(mp4|avi|wmv|mpg|amv|webm|mov)$", Pattern.CASE_INSENSITIVE)
|
||||
val imageExtensions = listOf("png", "jpg", "gif", "bmp", "jpeg", "webp", "svg")
|
||||
val videoExtensions = listOf("mp4", "avi", "wmv", "mpg", "amv", "webm", "mov")
|
||||
|
||||
// Group 1 = url, group 4 additional chars
|
||||
val noProtocolUrlValidator = Pattern.compile("(([\\w\\d-]+\\.)*[a-zA-Z][\\w-]+[\\.\\:]\\w+([\\/\\?\\=\\&\\#\\.]?[\\w-]+)*\\/?)(.*)")
|
||||
|
@ -138,10 +138,10 @@ fun RichTextViewer(
|
|||
// sequence of images will render in a slideview
|
||||
if (isValidURL(word)) {
|
||||
val removedParamsFromUrl = word.split("?")[0].lowercase()
|
||||
if (imageExtension.matcher(removedParamsFromUrl).matches()) {
|
||||
if (imageExtensions.any { word.endsWith(it, true) }) {
|
||||
imagesForPager.add(word)
|
||||
}
|
||||
if (videoExtension.matcher(removedParamsFromUrl).matches()) {
|
||||
if (videoExtensions.any { word.endsWith(it, true) }) {
|
||||
imagesForPager.add(word)
|
||||
}
|
||||
}
|
||||
|
@ -160,9 +160,9 @@ fun RichTextViewer(
|
|||
|
||||
if (isValidURL(word)) {
|
||||
val removedParamsFromUrl = word.split("?")[0].lowercase()
|
||||
if (imageExtension.matcher(removedParamsFromUrl).matches()) {
|
||||
if (imageExtensions.any { word.endsWith(it, true) }) {
|
||||
ZoomableImageView(word, imagesForPager)
|
||||
} else if (videoExtension.matcher(removedParamsFromUrl).matches()) {
|
||||
} else if (videoExtensions.any { word.endsWith(it, true) }) {
|
||||
ZoomableImageView(word, imagesForPager)
|
||||
} else {
|
||||
UrlPreview(word, "$word ")
|
||||
|
|
|
@ -62,7 +62,7 @@ fun ZoomableImageView(word: String, images: List<String> = listOf(word)) {
|
|||
mutableStateOf<AsyncImagePainter.State?>(null)
|
||||
}
|
||||
|
||||
if (imageExtension.matcher(word).matches()) {
|
||||
if (imageExtensions.any { word.endsWith(it, true) }) {
|
||||
AsyncImage(
|
||||
model = word,
|
||||
contentDescription = word,
|
||||
|
@ -171,7 +171,7 @@ fun ZoomableImageDialog(imageUrl: String, allImages: List<String> = listOf(image
|
|||
|
||||
@Composable
|
||||
private fun RenderImageOrVideo(imageUrl: String) {
|
||||
if (imageExtension.matcher(imageUrl).matches()) {
|
||||
if (imageExtensions.any { imageUrl.endsWith(it, true) }) {
|
||||
AsyncImage(
|
||||
model = imageUrl,
|
||||
contentDescription = stringResource(id = R.string.profile_image),
|
||||
|
|
Ładowanie…
Reference in New Issue