-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
383 additions
and
52 deletions.
There are no files selected for viewing
This file contains 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,16 @@ | ||
{ | ||
"plugins": [ | ||
{ | ||
"type": "add", | ||
"pluginName": "fleet.gradle" | ||
}, | ||
{ | ||
"type": "add", | ||
"pluginName": "fleet.kotlin" | ||
}, | ||
{ | ||
"type": "add", | ||
"pluginName": "fleet.mercury" | ||
} | ||
] | ||
} |
This file contains 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
41 changes: 41 additions & 0 deletions
41
composeApp/src/androidMain/kotlin/dev/datlag/aniflow/other/ImagePickerState.android.kt
This file contains 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,41 @@ | ||
package dev.datlag.aniflow.other | ||
|
||
import android.net.Uri | ||
import androidx.activity.compose.ManagedActivityResultLauncher | ||
import androidx.activity.compose.rememberLauncherForActivityResult | ||
import androidx.activity.result.PickVisualMediaRequest | ||
import androidx.activity.result.contract.ActivityResultContracts | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.ui.platform.LocalContext | ||
|
||
actual data class ImagePickerState( | ||
private val mediaPicker: ManagedActivityResultLauncher<PickVisualMediaRequest, Uri?> | ||
) { | ||
actual fun launch() { | ||
mediaPicker.launch(PickVisualMediaRequest(ActivityResultContracts.PickVisualMedia.ImageOnly)) | ||
} | ||
} | ||
|
||
@Composable | ||
actual fun rememberImagePickerState(onPick: (ByteArray?) -> Unit): ImagePickerState { | ||
val context = LocalContext.current | ||
val mediaPicker = rememberLauncherForActivityResult( | ||
contract = ActivityResultContracts.PickVisualMedia(), | ||
onResult = { uri -> | ||
onPick( | ||
uri?.let { | ||
context.contentResolver.openInputStream(it)?.use { input -> | ||
input.readBytes() | ||
} | ||
} | ||
) | ||
} | ||
) | ||
|
||
return remember(mediaPicker) { | ||
ImagePickerState( | ||
mediaPicker | ||
) | ||
} | ||
} |
This file contains 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 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
12 changes: 12 additions & 0 deletions
12
composeApp/src/commonMain/kotlin/dev/datlag/aniflow/other/ImagePickerState.kt
This file contains 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,12 @@ | ||
package dev.datlag.aniflow.other | ||
|
||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.graphics.ImageBitmap | ||
import io.ktor.utils.io.* | ||
|
||
expect class ImagePickerState { | ||
fun launch() | ||
} | ||
|
||
@Composable | ||
expect fun rememberImagePickerState(onPick: (ByteArray?) -> Unit = { }): ImagePickerState |
This file contains 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 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 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 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 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 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 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
15 changes: 15 additions & 0 deletions
15
composeApp/src/iosMain/kotlin/dev/datlag/aniflow/other/ImagePickerState.ios.kt
This file contains 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,15 @@ | ||
package dev.datlag.aniflow.other | ||
|
||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.graphics.ImageBitmap | ||
import io.ktor.utils.io.* | ||
|
||
actual object ImagePickerState { | ||
actual fun launch() { | ||
} | ||
} | ||
|
||
@Composable | ||
actual fun rememberImagePickerState(onPick: (ByteArray?) -> Unit): ImagePickerState { | ||
return ImagePickerState | ||
} |
This file contains 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.