From f5572f7ea56a3e7234f8247c26c3076ab488ab23 Mon Sep 17 00:00:00 2001 From: Vitor Pamplona Date: Mon, 16 Jan 2023 12:57:23 -0500 Subject: [PATCH] Support for Gifs and SVGs --- README.md | 7 +++++-- app/build.gradle | 7 ++++++- .../vitorpamplona/amethyst/ui/MainActivity.kt | 17 +++++++++++++++++ .../amethyst/ui/components/RichTextViewer.kt | 4 ++-- .../amethyst/ui/components/ZoomableImageView.kt | 2 +- 5 files changed, 31 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index d100facae..e2b407a63 100644 --- a/README.md +++ b/README.md @@ -11,10 +11,13 @@ Amethyst brings the best social network to your Android phone. Just insert your - [x] Notifications Feed - [x] Global Feed - [x] Reactions (like, boost, reply) -- [x] Image Preview +- [x] Image Preview (gifs, svgs) - [x] Url Preview - [x] View Threads -- [ ] Private Messages +- [x] Private Messages +- [x] User Profiles (follow/unfollow) +- [ ] Notification Bubbles +- [ ] Dropdown to Link Users/Posts when writting - [ ] Communities - [ ] Profile Edit - [ ] Relay Edit diff --git a/app/build.gradle b/app/build.gradle index ad29fa16f..4b3ebe67a 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -99,9 +99,14 @@ dependencies { // view videos implementation 'com.google.android.exoplayer:exoplayer:2.18.2' + // view gifs + implementation "io.coil-kt:coil-gif:2.2.2" + // view svgs + implementation("io.coil-kt:coil-svg:2.2.2") + // tabs for user profiles implementation "com.google.accompanist:accompanist-pager:$accompanist_version" // Pager - implementation "com.google.accompanist:accompanist-pager-indicators:$accompanist_version" // Pager Indicators + implementation "com.google.accompanist:accompanist-pager-indicators:$accompanist_version" testImplementation 'junit:junit:4.13.2' androidTestImplementation 'androidx.test.ext:junit:1.1.5' diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/MainActivity.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/MainActivity.kt index fd4554428..e6e58c618 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/MainActivity.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/MainActivity.kt @@ -1,5 +1,6 @@ package com.vitorpamplona.amethyst.ui +import android.os.Build.VERSION.SDK_INT import android.os.Bundle import androidx.activity.ComponentActivity import androidx.activity.compose.setContent @@ -8,6 +9,11 @@ import androidx.compose.material.MaterialTheme import androidx.compose.material.Surface import androidx.compose.ui.Modifier import androidx.lifecycle.viewmodel.compose.viewModel +import coil.Coil +import coil.ImageLoader +import coil.decode.GifDecoder +import coil.decode.ImageDecoderDecoder +import coil.decode.SvgDecoder import com.vitorpamplona.amethyst.KeyStorage import com.vitorpamplona.amethyst.service.NostrAccountDataSource import com.vitorpamplona.amethyst.service.NostrChatroomListDataSource @@ -29,6 +35,17 @@ class MainActivity : ComponentActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) + Coil.setImageLoader { + ImageLoader.Builder(this).components { + if (SDK_INT >= 28) { + add(ImageDecoderDecoder.Factory()) + } else { + add(GifDecoder.Factory()) + } + add(SvgDecoder.Factory()) + }.build() + } + setContent { AmethystTheme { // A surface container using the 'background' color from the theme diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/components/RichTextViewer.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/components/RichTextViewer.kt index 0d89e8fad..d2be737cc 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/components/RichTextViewer.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/components/RichTextViewer.kt @@ -19,7 +19,7 @@ import java.net.URISyntaxException import java.net.URL import java.util.regex.Pattern -val imageExtension = Pattern.compile("(.*/)*.+\\.(png|jpg|gif|bmp|jpeg|webp)$") +val imageExtension = Pattern.compile("(.*/)*.+\\.(png|jpg|gif|bmp|jpeg|webp|svg)$") val videoExtension = Pattern.compile("(.*/)*.+\\.(mp4|avi|wmv|mpg|amv|webm)$") val noProtocolUrlValidator = Pattern.compile("^[-a-zA-Z0-9@:%._\\+~#=]{1,256}\\.[a-zA-Z0-9()]{1,6}\\b(?:[-a-zA-Z0-9()@:%_\\+.~#?&//=]*)$") val tagIndex = Pattern.compile(".*\\#\\[([0-9]+)\\].*") @@ -54,7 +54,7 @@ fun RichTextViewer(content: String, tags: List>?, note: Note, accou } else if (isValidURL(word)) { val removedParamsFromUrl = word.split("?")[0].toLowerCase() if (imageExtension.matcher(removedParamsFromUrl).matches()) { - ExtendedImageView(word) + ZoomableImageView(word) } else if (videoExtension.matcher(removedParamsFromUrl).matches()) { VideoView(word) } else { diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/components/ZoomableImageView.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/components/ZoomableImageView.kt index 7a26db3ef..9407388af 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/components/ZoomableImageView.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/components/ZoomableImageView.kt @@ -29,7 +29,7 @@ import com.vitorpamplona.amethyst.ui.actions.CloseButton @Composable @OptIn(ExperimentalComposeUiApi::class) -fun ExtendedImageView(word: String) { +fun ZoomableImageView(word: String) { // store the dialog open or close state var dialogOpen by remember { mutableStateOf(false)