Skip to content

Commit

Permalink
[m]: updated to the best method for provide picture result
Browse files Browse the repository at this point in the history
  • Loading branch information
BadKiko committed Feb 12, 2024
1 parent 614cc36 commit c460a94
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .idea/kotlinc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 9 additions & 9 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
[versions]
accompanist-permissions = "0.33.1-alpha"
agp = "8.3.0-alpha01"
coil-compose = "2.4.0"
agp = "8.2.2"
coil-compose = "2.5.0"
github-landscapist-coil = "2.2.8"
kotlin = "1.8.10"
core-ktx = "1.10.1"
kotlin = "1.9.22"
core-ktx = "1.12.0"
junit = "4.13.2"
androidx-test-ext-junit = "1.1.5"
espresso-core = "3.5.1"
landscapist-placeholder = "2.2.8"
lifecycle-runtime-ktx = "2.6.1"
activity-compose = "1.7.2"
material3 = "1.2.0-alpha06"
compose-bom = "2023.08.00"
ui="1.6.0-alpha04"
lifecycle-runtime-ktx = "2.7.0"
activity-compose = "1.8.2"
material3 = "1.2.0"
compose-bom = "2024.02.00"
ui="1.6.1"

[libraries]
accompanist-permissions = { module = "com.google.accompanist:accompanist-permissions", version.ref = "accompanist-permissions" }
Expand Down
3 changes: 2 additions & 1 deletion kige/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ android {
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles("consumer-rules.pro")
}

buildFeatures {
compose = true
}
composeOptions {
kotlinCompilerExtensionVersion = "1.4.3"
kotlinCompilerExtensionVersion = "1.5.9"
}
buildTypes {
release {
Expand Down
4 changes: 0 additions & 4 deletions kige/src/main/java/com/kiko/kige/data/state/KigeState.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,4 @@ data class KigeState(
fun hide(coroutineScope: CoroutineScope, onHided: () -> Unit) {
rememberGalleryState.hide(coroutineScope, onHided)
}

fun choosePhoto(newImageUri: String) {
_photoUri.value = newImageUri
}
}
15 changes: 14 additions & 1 deletion kige/src/main/java/com/kiko/kige/ui/components/GallerySheet.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

package com.kiko.kige.ui.components

import androidx.compose.foundation.Image
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
Expand All @@ -16,12 +17,18 @@ import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.ModalBottomSheet
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.painter.Painter
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.unit.dp
import coil.compose.rememberAsyncImagePainter
import com.kiko.kige.data.remembers.rememberKigeState
import com.kiko.kige.data.state.GalleryState
import com.kiko.kige.data.state.KigeState
Expand All @@ -36,7 +43,11 @@ import com.skydoves.landscapist.placeholder.shimmer.ShimmerPlugin
internal fun GallerySheet(
rememberGalleryState: GalleryState,
rememberKigeState: KigeState,
onSelect: (painter: Painter) -> Unit
) {
var selectedPhotoUri by remember { mutableStateOf("") }
val selectedPainter = rememberAsyncImagePainter(model = selectedPhotoUri)

val coroutineScope = rememberCoroutineScope()

if (rememberGalleryState.visibleState.value) {
Expand All @@ -63,11 +74,13 @@ internal fun GallerySheet(
verticalArrangement = Arrangement.spacedBy(8.dp)
) {
items(photos) { photoUri ->

CoilImage(
modifier = rememberGalleryState.galleryUIState.imagesModifier
.clickable {
rememberKigeState.hide(coroutineScope) {
rememberKigeState.choosePhoto(photoUri)
selectedPhotoUri = photoUri
onSelect(selectedPainter)
}
},
component = rememberImageComponent {
Expand Down
15 changes: 10 additions & 5 deletions kige/src/main/java/com/kiko/kige/ui/components/KigePicker.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.os.Build
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.graphics.painter.Painter
import com.google.accompanist.permissions.ExperimentalPermissionsApi
import com.google.accompanist.permissions.isGranted
import com.google.accompanist.permissions.rememberPermissionState
Expand All @@ -20,7 +21,8 @@ import kotlinx.coroutines.launch
@OptIn(ExperimentalPermissionsApi::class)
@Composable
fun KigePicker(
rememberKigeState: KigeState = rememberKigeState()
rememberKigeState: KigeState = rememberKigeState(),
onSelect: (painter: Painter) -> Unit
) {
if (rememberKigeState.visibleState.value) {
val readExternalPermission = if (Build.VERSION.SDK_INT < 33)
Expand All @@ -34,14 +36,16 @@ fun KigePicker(
CreateGallerySheet(
coroutineScope,
rememberKigeState.rememberGalleryState,
rememberKigeState
rememberKigeState,
onSelect
)
} else {
PermissionSheet(rememberKigeState.rememberPermissionState) {
CreateGallerySheet(
coroutineScope,
rememberKigeState.rememberGalleryState,
rememberKigeState
rememberKigeState,
onSelect
)
}

Expand All @@ -58,9 +62,10 @@ fun KigePicker(
private fun CreateGallerySheet(
coroutineScope: CoroutineScope,
rememberKigeGalleryState: GalleryState,
rememberKigeState: KigeState
rememberKigeState: KigeState,
onSelect: (painter: Painter) -> Unit
) {
GallerySheet(rememberKigeGalleryState, rememberKigeState)
GallerySheet(rememberKigeGalleryState, rememberKigeState, onSelect)

LaunchedEffect(true) {
coroutineScope.launch {
Expand Down
2 changes: 1 addition & 1 deletion samplekige/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ android {
compose = true
}
composeOptions {
kotlinCompilerExtensionVersion = "1.4.3"
kotlinCompilerExtensionVersion = "1.5.9"
}
packaging {
resources {
Expand Down
23 changes: 21 additions & 2 deletions samplekige/src/main/java/com/kiko/kige/samplekige/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,21 @@ package com.kiko.kige.samplekige
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.Button
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.painter.Painter
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.tooling.preview.Preview
import coil.compose.AsyncImage
import com.kiko.kige.data.remembers.rememberKigeState
Expand All @@ -21,11 +29,22 @@ class MainActivity : ComponentActivity() {
super.onCreate(savedInstanceState)
setContent {
KigeTheme {
var image by remember { mutableStateOf<Painter?>(null) }

val rememberKigeState = rememberKigeState()
KigePicker(rememberKigeState)

AsyncImage(model = rememberKigeState.photoUri.value, contentDescription = null)
KigePicker(rememberKigeState) {
image = it
}

image?.let {
Image(
modifier = Modifier.fillMaxSize(),
painter = it,
contentDescription = "",
contentScale = ContentScale.FillBounds
)
}

Button({
rememberKigeState.expand()
Expand Down

0 comments on commit c460a94

Please sign in to comment.