This repository was archived by the owner on Aug 21, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Implement Share vCard feature #93
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file modified
BIN
+2.05 KB
(100%)
...r.app.homeUi.presentation.home.share.components.ShareHeaderTest.shareHeader.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
homeUi/src/main/kotlin/com/gravatar/app/homeUi/presentation/DrawableUtils.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| package com.gravatar.app.homeUi.presentation | ||
|
|
||
| import android.content.Context | ||
| import android.graphics.Bitmap | ||
| import android.graphics.drawable.Drawable | ||
| import androidx.core.graphics.drawable.toBitmap | ||
| import coil.ImageLoader | ||
| import coil.request.ImageRequest | ||
| import java.io.ByteArrayOutputStream | ||
| import kotlin.io.encoding.Base64 | ||
| import kotlin.io.encoding.ExperimentalEncodingApi | ||
|
|
||
| internal class DrawableUtils(private val context: Context) { | ||
|
|
||
| private val imageLoader = ImageLoader(context) | ||
|
|
||
| suspend fun downloadDrawable(url: String): Drawable? { | ||
| return try { | ||
| val request = ImageRequest.Builder(context) | ||
| .data(url) | ||
| .build() | ||
| imageLoader.execute(request).drawable | ||
| } catch (_: Exception) { | ||
| null | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Converts a Drawable to a Base64 encoded string. | ||
| * | ||
| * @param drawable The Drawable to convert. | ||
| * @param format The desired image format (Bitmap.CompressFormat.PNG or Bitmap.CompressFormat.JPEG). | ||
| * @param quality The quality for JPEG compression (0-100). | ||
| * @return The Base64 encoded string representation of the image, or null if conversion fails. | ||
| */ | ||
| @OptIn(ExperimentalEncodingApi::class) | ||
| @Suppress("TooGenericExceptionCaught") | ||
| internal fun drawableToBase64( | ||
| drawable: Drawable, | ||
| format: Bitmap.CompressFormat = Bitmap.CompressFormat.JPEG, | ||
| quality: Int = 30 | ||
| ): Result<String> { | ||
| val bitmap = drawable.toBitmap() | ||
|
|
||
| return try { | ||
| val base64String = ByteArrayOutputStream().use { outputStream -> | ||
| bitmap.compress(format, quality, outputStream) | ||
| Base64.encode(outputStream.toByteArray()) | ||
| } | ||
| Result.success(base64String) | ||
| } catch (e: Exception) { | ||
| Result.failure(e) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
homeUi/src/main/kotlin/com/gravatar/app/homeUi/presentation/home/share/ShareAction.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| package com.gravatar.app.homeUi.presentation.home.share | ||
|
|
||
| import java.io.File | ||
|
|
||
| internal sealed class ShareAction { | ||
| data class ShareVCard(val vCardFile: File) : ShareAction() | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.