mirror of
https://github.com/LiveFastEatTrashRaccoon/RaccoonForLemmy.git
synced 2025-02-02 03:47:09 +01:00
enhancement: display public images on Imgur (#294)
* normalize URLs for Imgur.com * update post layout to handle Imgur images
This commit is contained in:
parent
c13388485b
commit
fa3fcfa047
@ -53,6 +53,7 @@ import com.livefast.eattrash.raccoonforlemmy.core.utils.compose.onClick
|
||||
import com.livefast.eattrash.raccoonforlemmy.core.utils.di.getShareHelper
|
||||
import com.livefast.eattrash.raccoonforlemmy.core.utils.looksLikeAVideo
|
||||
import com.livefast.eattrash.raccoonforlemmy.core.utils.looksLikeAnImage
|
||||
import com.livefast.eattrash.raccoonforlemmy.core.utils.normalizeImgurUrl
|
||||
import com.livefast.eattrash.raccoonforlemmy.core.utils.texttoolbar.getCustomTextToolbar
|
||||
import com.livefast.eattrash.raccoonforlemmy.domain.lemmy.data.CommunityModel
|
||||
import com.livefast.eattrash.raccoonforlemmy.domain.lemmy.data.PostModel
|
||||
@ -593,6 +594,7 @@ private fun ExtendedPost(
|
||||
val postLinkUrl =
|
||||
post.url
|
||||
.orEmpty()
|
||||
.normalizeImgurUrl()
|
||||
.takeIf {
|
||||
it != post.imageUrl &&
|
||||
it != post.videoUrl &&
|
||||
|
@ -79,8 +79,15 @@ val String.looksLikeAVideo: Boolean
|
||||
return extensions.any { this.endsWith(it) }
|
||||
}
|
||||
|
||||
val String.isRedGifs: Boolean
|
||||
get() = contains("redgifs.com")
|
||||
fun String.normalizeImgurUrl(): String =
|
||||
this.let {
|
||||
if (it.contains("i.imgur.com") && !it.looksLikeAnImage) {
|
||||
// add extension so that is can be resolved
|
||||
"$it.jpeg"
|
||||
} else {
|
||||
it
|
||||
}
|
||||
}
|
||||
|
||||
fun String?.ellipsize(
|
||||
length: Int = 100,
|
||||
|
@ -2,6 +2,7 @@ package com.livefast.eattrash.raccoonforlemmy.domain.lemmy.data
|
||||
|
||||
import com.livefast.eattrash.raccoonforlemmy.core.utils.looksLikeAVideo
|
||||
import com.livefast.eattrash.raccoonforlemmy.core.utils.looksLikeAnImage
|
||||
import com.livefast.eattrash.raccoonforlemmy.core.utils.normalizeImgurUrl
|
||||
|
||||
data class PostModel(
|
||||
val id: Long = 0,
|
||||
@ -33,7 +34,14 @@ data class PostModel(
|
||||
)
|
||||
|
||||
val PostModel.imageUrl: String
|
||||
get() = (url?.takeIf { it.looksLikeAnImage } ?: thumbnailUrl).orEmpty()
|
||||
get() =
|
||||
url
|
||||
?.normalizeImgurUrl()
|
||||
?.takeIf { it.looksLikeAnImage } ?: thumbnailUrl
|
||||
.orEmpty()
|
||||
|
||||
val PostModel.videoUrl: String
|
||||
get() = url?.takeIf { it.looksLikeAVideo }.orEmpty()
|
||||
get() =
|
||||
url
|
||||
?.takeIf { it.looksLikeAVideo }
|
||||
.orEmpty()
|
||||
|
Loading…
x
Reference in New Issue
Block a user