-
Notifications
You must be signed in to change notification settings - Fork 15
#34 Replace MaterialFilePicker dependency and fragmentActivity usage #81
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
Open
ZiXOps
wants to merge
18
commits into
icerockdev:develop
Choose a base branch
from
ZiXOps:replace-fragment-activity-usage
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
47b6d32
#34 up moko permissions version 0.15.0 -> 0.18.0
99c9e9e
#34 replace FragmentActivity to ComponentActivity at bind MediaPicker…
c98aa71
#34 remove fragmentManager and mediaFilePicker usage usage
d358b7f
#34 add ImagePickerDelegate
39c2649
#34 add MediaPickerDelegate
9f788f9
#34 add FilePickerDelegate
1e82571
#34 Up kotlin version
0cd5051
#34 Add OptIn annotations
425c22f
#34 Fix pass image max size params
ccf893d
#34 Fix detekt
b02edf7
#34 Fix check bind activity base class
3a81ec6
#34 Add copyright
6ae0752
#34 Add base PickerDelegate class
219c489
#34 Update README.md
f36d66a
#34 Code style
d569f33
#34 add more common logic at PickerDelegate
399fb6b
#34 code style
bfeda11
#34 code style
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
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
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
81 changes: 81 additions & 0 deletions
81
media/src/androidMain/kotlin/dev/icerock/moko/media/picker/CameraPickerDelegate.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,81 @@ | ||
| /* | ||
| * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. | ||
| */ | ||
|
|
||
| package dev.icerock.moko.media.picker | ||
|
|
||
| import android.content.Context | ||
| import android.graphics.Bitmap | ||
| import android.net.Uri | ||
| import androidx.activity.result.ActivityResultLauncher | ||
| import androidx.activity.result.ActivityResultRegistry | ||
| import androidx.activity.result.contract.ActivityResultContracts | ||
|
|
||
| internal class CameraPickerDelegate : | ||
| ImagePickerDelegate<CameraPickerDelegate.CameraPickerCallbackData, Uri, Bitmap>() { | ||
|
|
||
| override fun registerActivityResult( | ||
| context: Context, | ||
| activityResultRegistry: ActivityResultRegistry | ||
| ): ActivityResultLauncher<Uri> = activityResultRegistry.register( | ||
| PICK_CAMERA_IMAGE_KEY, | ||
| ActivityResultContracts.TakePicture(), | ||
| ) { result -> | ||
| val callbackData = callback ?: return@register | ||
| callback = null | ||
|
|
||
| if (!result) { | ||
| callbackData.callback.invoke(Result.failure(CanceledException())) | ||
| return@register | ||
| } | ||
|
|
||
| processResult( | ||
| context = context, | ||
| callback = callbackData.callback, | ||
| uri = callbackData.outputUri, | ||
| maxImageWidth = callbackData.maxWidth, | ||
| maxImageHeight = callbackData.maxHeight, | ||
| ) | ||
| } | ||
|
|
||
| override fun createCallback( | ||
| callback: (Result<Bitmap>) -> Unit, | ||
| mediaOptions: MediaOptions? | ||
| ): CameraPickerCallbackData { | ||
| val cameraPickerMediaOptions = mediaOptions as? CameraPickerMediaOptions | ||
| val outputUri = cameraPickerMediaOptions?.outputUri ?: Uri.EMPTY | ||
| val maxWidth = cameraPickerMediaOptions?.maxWidth ?: 0 | ||
| val maxHeight = cameraPickerMediaOptions?.maxHeight ?: 0 | ||
| return CameraPickerCallbackData( | ||
| callback, | ||
| outputUri, | ||
| maxWidth, | ||
| maxHeight, | ||
| ) | ||
| } | ||
|
|
||
| override fun launchActivityResult(mediaOptions: MediaOptions?) { | ||
| val cameraPickerMediaOptions = mediaOptions as? CameraPickerMediaOptions | ||
| val outputUri = cameraPickerMediaOptions?.outputUri ?: Uri.EMPTY | ||
| pickerLauncherHolder.value?.launch( | ||
| outputUri | ||
| ) | ||
| } | ||
|
|
||
| class CameraPickerCallbackData( | ||
| override val callback: (Result<Bitmap>) -> Unit, | ||
| val outputUri: Uri, | ||
| val maxWidth: Int, | ||
| val maxHeight: Int, | ||
| ) : CallbackData<Bitmap> | ||
|
|
||
| class CameraPickerMediaOptions( | ||
| val outputUri: Uri, | ||
| val maxWidth: Int, | ||
| val maxHeight: Int, | ||
| ) : MediaOptions | ||
|
|
||
| companion object { | ||
| private const val PICK_CAMERA_IMAGE_KEY = "PickCameraImageKey" | ||
| } | ||
| } |
83 changes: 83 additions & 0 deletions
83
media/src/androidMain/kotlin/dev/icerock/moko/media/picker/FilePickerDelegate.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,83 @@ | ||
| /* | ||
| * Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. | ||
| */ | ||
|
|
||
| package dev.icerock.moko.media.picker | ||
|
|
||
| import android.annotation.SuppressLint | ||
| import android.content.ContentResolver | ||
| import android.content.Context | ||
| import android.provider.OpenableColumns | ||
| import androidx.activity.result.ActivityResultLauncher | ||
| import androidx.activity.result.ActivityResultRegistry | ||
| import androidx.activity.result.contract.ActivityResultContracts | ||
| import dev.icerock.moko.media.FileMedia | ||
| import java.io.File | ||
|
|
||
| internal class FilePickerDelegate : | ||
| PickerDelegate<FilePickerDelegate.FilePickerCallbackData, Array<String>, FileMedia>() { | ||
|
|
||
| override fun registerActivityResult( | ||
| context: Context, | ||
| activityResultRegistry: ActivityResultRegistry | ||
| ): ActivityResultLauncher<Array<String>> = activityResultRegistry.register( | ||
| PICK_FILE_KEY, | ||
| ActivityResultContracts.OpenDocument(), | ||
| ) { uri -> | ||
| val callbackData = callback ?: return@register | ||
| callback = null | ||
|
|
||
| val callback = callbackData.callback | ||
|
|
||
| if (uri == null) { | ||
| callback.invoke(Result.failure(CanceledException())) | ||
| return@register | ||
| } | ||
|
|
||
| val path = uri.path | ||
| if (path == null) { | ||
| callback.invoke(Result.failure(java.lang.IllegalStateException("File is null"))) | ||
| return@register | ||
| } | ||
|
|
||
| @SuppressLint("Range") | ||
| val fileNameWithExtension = if (uri.scheme == ContentResolver.SCHEME_CONTENT) { | ||
| val cursor = context.contentResolver.query(uri, null, null, null, null) | ||
| cursor?.use { | ||
| if (!it.moveToFirst()) null | ||
| else it.getString(it.getColumnIndex(OpenableColumns.DISPLAY_NAME)) | ||
| } | ||
| } else null | ||
|
|
||
| val file = File(path) | ||
| val name = file.name | ||
| val result = Result.success( | ||
| FileMedia( | ||
| fileNameWithExtension ?: name, | ||
| uri.toString(), | ||
| ) | ||
| ) | ||
| callback.invoke(result) | ||
| } | ||
|
|
||
| override fun createCallback( | ||
| callback: (Result<FileMedia>) -> Unit, | ||
| mediaOptions: MediaOptions? | ||
| ): FilePickerCallbackData = FilePickerCallbackData(callback) | ||
|
|
||
| override fun launchActivityResult(mediaOptions: MediaOptions?) { | ||
| pickerLauncherHolder.value?.launch( | ||
| arrayOf( | ||
| "*/*", | ||
| ) | ||
| ) | ||
| } | ||
|
|
||
| class FilePickerCallbackData( | ||
| override val callback: (Result<FileMedia>) -> Unit | ||
| ) : CallbackData<FileMedia> | ||
|
|
||
| companion object { | ||
| private const val PICK_FILE_KEY = "PickFileKey" | ||
| } | ||
| } | ||
68 changes: 0 additions & 68 deletions
68
media/src/androidMain/kotlin/dev/icerock/moko/media/picker/FilePickerFragment.kt
This file was deleted.
Oops, something went wrong.
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.