Skip to content

Commit

Permalink
fix: the issue the preview images not correct
Browse files Browse the repository at this point in the history
  • Loading branch information
huhx committed Feb 26, 2024
1 parent 45eb4bf commit 2510f9f
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
11 changes: 7 additions & 4 deletions compose_image_picker/src/main/java/com/huhx/picker/AssetRoute.kt
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,19 @@ internal fun AssetPickerRoute(
AssetRoute.preview,
arguments = listOf(
navArgument("index") { type = NavType.IntType },
navArgument("dateString") { type = NavType.StringType },
navArgument("requestType") { type = NavType.StringType },
)
) {
val arguments = it.arguments!!
val index = arguments.getInt("index")
val requestType = arguments.getString("requestType")
val assets = viewModel.getAssets(RequestType.valueOf(requestType!!))
val dateString = arguments.getString("dateString")
val assets = viewModel.getGroupedAssets(RequestType.valueOf(requestType!!))

AssetPreviewScreen(
index = index,
assets = assets,
assets = assets.getOrDefault(dateString, listOf()),
selectedList = viewModel.selectedList,
navigateUp = { navController.navigateUp() },
)
Expand All @@ -73,11 +75,12 @@ internal fun AssetPickerRoute(

object AssetRoute {
const val display = "asset_display"
const val preview = "asset_preview?index={index}&requestType={requestType}"
const val preview = "asset_preview?index={index}&dateString={dateString}&requestType={requestType}"
const val selector = "asset_selector?directory={directory}"

fun preview(index: Int, requestType: RequestType): String {
fun preview(index: Int, dateString: String, requestType: RequestType): String {
return preview.replaceFirst("{index}", index.toString())
.replaceFirst("{dateString}", dateString)
.replaceFirst("{requestType}", requestType.name)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ private fun AssetContent(viewModel: AssetViewModel, requestType: RequestType) {
itemsIndexed(resources, key = { _, it -> it.id }) { index, assetInfo ->
AssetImage(
assetInfo = assetInfo,
navigateToPreview = { viewModel.navigateToPreview(index, requestType) },
navigateToPreview = { viewModel.navigateToPreview(index, dateString, requestType) },
selectedList = viewModel.selectedList,
onLongClick = { selected -> viewModel.toggleSelect(selected, assetInfo) }
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
@file:OptIn(ExperimentalMaterial3Api::class)

package com.huhx.picker.view

import android.os.Build
Expand Down Expand Up @@ -64,6 +62,7 @@ import com.huhx.picker.component.SelectedAssetImageItem
import com.huhx.picker.model.AssetInfo
import kotlinx.coroutines.launch

@OptIn(ExperimentalMaterial3Api::class)
@UnstableApi
@Composable
fun AssetPreviewScreen(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ internal class AssetViewModel(
return selectedIds.containsAll(ids)
}

fun navigateToPreview(index: Int, requestType: RequestType) {
navController.navigate(AssetRoute.preview(index, requestType))
fun navigateToPreview(index: Int, dateString: String, requestType: RequestType) {
navController.navigate(AssetRoute.preview(index, dateString, requestType))
}

fun deleteImage(cameraUri: Uri?) {
Expand Down

0 comments on commit 2510f9f

Please sign in to comment.