Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert base64 text to images/gifs #960

Merged
merged 9 commits into from
Jul 11, 2024

Conversation

greenart7c3
Copy link
Contributor

fixes #951

@greenart7c3
Copy link
Contributor Author

It still freezes the app if i press the show more button. Should I try to change the text note to make it convert the base64 to a image?

@vitorpamplona
Copy link
Owner

I think we will have to :(

}

val imageBytes = runCatching { Base64.decode(base64String2, Base64.DEFAULT) }.getOrNull()

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can also use the Base64 Requester which I think does the decoding in an IO thread.

            val context = LocalContext.current
            val base64Painter =
                rememberAsyncImagePainter(
                    model = Base64Requester.imageRequest(context, model),
                )

            Image(
                painter = base64Painter,
                contentDescription = contentDescription,
                modifier = modifier,
                alignment = alignment,
                contentScale = contentScale,
                colorFilter = colorFilter,
            )

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using this makes base64 gifs not work

@greenart7c3 greenart7c3 changed the title Cut the text when the content length is greater than SHORT_TEXT_LENGTH and theres no spaces and new lines Convert base64 text to images/gifs Jul 1, 2024
Copy link
Contributor

@KotlinGeekDev KotlinGeekDev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please @greenart7c3 can you try this solution?(It's a slight modification of @vitorpamplona 's suggestion. Needs Coil's gif library extension, see here.
Edit: moved LocalContext call to the top, for correctness.

val context = LocalContext.current
val gifImageLoader = ImageLoader.Builder(context)
    .components {
        if (SDK_INT >= 28) {
            add(ImageDecoderDecoder.Factory())
        } else {
            add(GifDecoder.Factory())
        }
    }
    .build()

val base64Painter =
    rememberAsyncImagePainter(
      model = Base64Requester.imageRequest(context, model),
      imageLoader = gifImageLoader
    )

Image(
    painter = base64Painter,
    contentDescription = contentDescription,
    modifier = modifier,
    alignment = alignment,
    contentScale = contentScale,
    colorFilter = colorFilter,
)   

@greenart7c3
Copy link
Contributor Author

Thanks, I'll test this tomorrow morning

@greenart7c3
Copy link
Contributor Author

Gifs doesn't animate when I use this solution

@KotlinGeekDev
Copy link
Contributor

Gifs doesn't animate when I use this solution

Thanks for the feedback. I guess the problem is at the level of Coil then.

@davotoula
Copy link
Contributor

davotoula commented Jul 6, 2024

Trying this pull request. How is this functionality invoked from the app please?

Edit: never mind, found the associated bug!

@davotoula
Copy link
Contributor

Very slow scrolling of home feed on first try. Is this a known issue or just cache priming?

@greenart7c3
Copy link
Contributor Author

I'll look at this later. Have you tried creating a release build to see if it's slow too?

@davotoula
Copy link
Contributor

It was a debug build... And trying other branches with a debug build it's similarly slow.

So I suspect it's the debug build rather than your PR 👍

@vitorpamplona
Copy link
Owner

Yeah, debug will always be extremely slow due to the added tracking points for debug.

Use the "benchmark" build variant to see real speeds.

@davotoula
Copy link
Contributor

Good point, thanks!

@vitorpamplona vitorpamplona merged commit 8d9ecb2 into vitorpamplona:main Jul 11, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] App freezes when opening the dm screen
4 participants