Skip to content

Commit

Permalink
feat: fix the resource type issue in AssetInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
huhx committed Jan 3, 2024
1 parent 31a5029 commit 957a7c5
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 16 deletions.
7 changes: 6 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-feature
android:name="android.hardware.camera"
android:required="false" />

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"
android:maxSdkVersion="32" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.INTERNET" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ data class AssetInfo(
return BitmapFactory.decodeFile(uriString)
}

val resourceType: AssetResourceType = AssetResourceType.fromFileName(uriString)
val resourceType: AssetResourceType = AssetResourceType.fromFileName(filename)

// todo: 这种方式还是存在问题
val randomName: String = run {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ private fun DisplayBottomBar(viewModel: AssetViewModel, onPicked: (List<AssetInf
@OptIn(ExperimentalFoundationApi::class)
@Composable
private fun AssetTab(tabs: List<TabItem>, pagerState: PagerState) {
val coroutineScope = rememberCoroutineScope()
val scope = rememberCoroutineScope()

TabRow(selectedTabIndex = pagerState.currentPage, indicator = {}) {
tabs.forEachIndexed { index, tab ->
Expand All @@ -172,9 +172,7 @@ private fun AssetTab(tabs: List<TabItem>, pagerState: PagerState) {
text = { Text(text = stringResource(tab.resourceId)) },
selectedContentColor = MaterialTheme.colorScheme.onSurface,
unselectedContentColor = Color.Gray,
onClick = {
coroutineScope.launch { pagerState.animateScrollToPage(index) }
}
onClick = { scope.launch { pagerState.animateScrollToPage(index) } }
)
}
}
Expand Down Expand Up @@ -228,7 +226,7 @@ private fun AssetImage(

private sealed class TabItem(
@StringRes val resourceId: Int,
val screen: @Composable (AssetViewModel) -> Unit
val screen: @Composable (AssetViewModel) -> Unit,
) {
data object All : TabItem(R.string.tab_item_all, { viewModel -> AssetContent(viewModel, RequestType.COMMON) })

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,7 @@ internal fun AssetImageIndicator(
Toast.makeText(context, errorMessage, Toast.LENGTH_SHORT).show()
return@Surface
}
if (isSelected) {
assetSelected.add(assetInfo)
} else {
assetSelected.remove(assetInfo)
}
if (isSelected) assetSelected.add(assetInfo) else assetSelected.remove(assetInfo)
},
modifier = Modifier
.padding(6.dp)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,12 @@ internal class AssetViewModel(
fun getAssets(requestType: RequestType): List<AssetInfo> {
val assetList = _directoryGroup.first { it.directory == directory }.assets

return when (requestType) {
RequestType.COMMON -> assetList
RequestType.IMAGE -> assetList.filter(AssetInfo::isImage)
RequestType.VIDEO -> assetList.filter(AssetInfo::isVideo)
return assetList.filter {
when (requestType) {
RequestType.COMMON -> true
RequestType.IMAGE -> it.isImage()
RequestType.VIDEO -> it.isVideo()
}
}
}

Expand Down

0 comments on commit 957a7c5

Please sign in to comment.