Refactor AppBarActions and clean up code (#1635)
* remove parentheses * Refactor AppBarActions to improve readability and maintainability * Refactor callback parameters in AppBar actions for clarity
This commit is contained in:
parent
dc3d034109
commit
21cb1921a3
6 changed files with 108 additions and 112 deletions
|
|
@ -336,47 +336,46 @@ fun SourceFeedToolbar(
|
||||||
// KMK -->
|
// KMK -->
|
||||||
actions = {
|
actions = {
|
||||||
AppBarActions(
|
AppBarActions(
|
||||||
actions = persistentListOf<AppBar.AppBarAction>().builder()
|
actions = persistentListOf<AppBar.AppBarAction>().builder().apply {
|
||||||
.apply {
|
add(bulkSelectionButton(isRunning, toggleSelectionMode))
|
||||||
add(bulkSelectionButton(isRunning, toggleSelectionMode))
|
|
||||||
|
|
||||||
onWebViewClick?.let {
|
onWebViewClick?.let { func ->
|
||||||
add(
|
|
||||||
AppBar.Action(
|
|
||||||
title = stringResource(MR.strings.action_web_view),
|
|
||||||
onClick = { onWebViewClick() },
|
|
||||||
icon = Icons.Outlined.Public,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
// KMK -->
|
|
||||||
add(
|
add(
|
||||||
AppBar.OverflowAction(
|
AppBar.Action(
|
||||||
title = stringResource(MR.strings.pref_incognito_mode),
|
title = stringResource(MR.strings.action_web_view),
|
||||||
onClick = onToggleIncognito,
|
onClick = { func() },
|
||||||
|
icon = Icons.Outlined.Public,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
// KMK <--
|
|
||||||
|
|
||||||
onSortFeedClick?.let {
|
|
||||||
add(
|
|
||||||
AppBar.OverflowAction(
|
|
||||||
title = stringResource(KMR.strings.action_sort_feed),
|
|
||||||
onClick = { onSortFeedClick() },
|
|
||||||
),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
onSourceSettingClick?.let {
|
|
||||||
add(
|
|
||||||
AppBar.OverflowAction(
|
|
||||||
title = stringResource(MR.strings.label_settings),
|
|
||||||
onClick = { onSourceSettingClick() },
|
|
||||||
),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// KMK -->
|
||||||
|
add(
|
||||||
|
AppBar.OverflowAction(
|
||||||
|
title = stringResource(MR.strings.pref_incognito_mode),
|
||||||
|
onClick = onToggleIncognito,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
// KMK <--
|
||||||
|
|
||||||
|
onSortFeedClick?.let { func ->
|
||||||
|
add(
|
||||||
|
AppBar.OverflowAction(
|
||||||
|
title = stringResource(KMR.strings.action_sort_feed),
|
||||||
|
onClick = { func() },
|
||||||
|
),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
onSourceSettingClick?.let { func ->
|
||||||
|
add(
|
||||||
|
AppBar.OverflowAction(
|
||||||
|
title = stringResource(MR.strings.label_settings),
|
||||||
|
onClick = { func() },
|
||||||
|
),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
.build(),
|
.build(),
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -209,7 +209,7 @@ fun BrowseSourceEHentaiListItem(
|
||||||
MangaCoverHide.Book(
|
MangaCoverHide.Book(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxHeight(),
|
.fillMaxHeight(),
|
||||||
bgColor = bgColor ?: (MaterialTheme.colorScheme.surface.takeIf { isSelected }),
|
bgColor = bgColor ?: MaterialTheme.colorScheme.surface.takeIf { isSelected },
|
||||||
tint = onBgColor,
|
tint = onBgColor,
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -219,7 +219,7 @@ fun BrowseSourceEHentaiListItem(
|
||||||
.fillMaxHeight(),
|
.fillMaxHeight(),
|
||||||
// KMK -->
|
// KMK -->
|
||||||
alpha = if (isSelected) GRID_SELECTED_COVER_ALPHA else coverAlpha,
|
alpha = if (isSelected) GRID_SELECTED_COVER_ALPHA else coverAlpha,
|
||||||
bgColor = bgColor ?: (MaterialTheme.colorScheme.surface.takeIf { isSelected }),
|
bgColor = bgColor ?: MaterialTheme.colorScheme.surface.takeIf { isSelected },
|
||||||
tint = onBgColor,
|
tint = onBgColor,
|
||||||
// KMK <--
|
// KMK <--
|
||||||
data = coverData,
|
data = coverData,
|
||||||
|
|
|
||||||
|
|
@ -39,27 +39,26 @@ fun BrowseSourceSimpleToolbar(
|
||||||
var selectingDisplayMode by remember { mutableStateOf(false) }
|
var selectingDisplayMode by remember { mutableStateOf(false) }
|
||||||
// KMK -->
|
// KMK -->
|
||||||
AppBarActions(
|
AppBarActions(
|
||||||
actions = persistentListOf<AppBar.AppBarAction>().builder()
|
actions = persistentListOf<AppBar.AppBarAction>().builder().apply {
|
||||||
.apply {
|
displayMode?.let { mode ->
|
||||||
displayMode?.let {
|
add(
|
||||||
add(
|
AppBar.Action(
|
||||||
AppBar.Action(
|
title = stringResource(MR.strings.action_display_mode),
|
||||||
title = stringResource(MR.strings.action_display_mode),
|
icon = if (mode == LibraryDisplayMode.List) {
|
||||||
icon = if (displayMode == LibraryDisplayMode.List) {
|
Icons.AutoMirrored.Filled.ViewList
|
||||||
Icons.AutoMirrored.Filled.ViewList
|
} else {
|
||||||
} else {
|
Icons.Filled.ViewModule
|
||||||
Icons.Filled.ViewModule
|
},
|
||||||
},
|
onClick = { selectingDisplayMode = true },
|
||||||
onClick = { selectingDisplayMode = true },
|
),
|
||||||
),
|
)
|
||||||
)
|
|
||||||
}
|
|
||||||
toggleSelectionMode?.let {
|
|
||||||
add(
|
|
||||||
bulkSelectionButton(isRunning, toggleSelectionMode),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
toggleSelectionMode?.let { mode ->
|
||||||
|
add(
|
||||||
|
bulkSelectionButton(isRunning, mode),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
.build(),
|
.build(),
|
||||||
)
|
)
|
||||||
// KMK <--
|
// KMK <--
|
||||||
|
|
|
||||||
|
|
@ -30,53 +30,51 @@ fun BulkSelectionToolbar(
|
||||||
titleContent = { Text(text = "$selectedCount") },
|
titleContent = { Text(text = "$selectedCount") },
|
||||||
actions = {
|
actions = {
|
||||||
AppBarActions(
|
AppBarActions(
|
||||||
actions = persistentListOf<AppBar.AppBarAction>()
|
actions = persistentListOf<AppBar.AppBarAction>().builder().apply {
|
||||||
.builder()
|
if (onSelectAll != null) {
|
||||||
.apply {
|
add(
|
||||||
if (onSelectAll != null) {
|
AppBar.Action(
|
||||||
add(
|
title = stringResource(MR.strings.action_select_all),
|
||||||
AppBar.Action(
|
icon = Icons.Filled.SelectAll,
|
||||||
title = stringResource(MR.strings.action_select_all),
|
onClick = onSelectAll,
|
||||||
icon = Icons.Filled.SelectAll,
|
),
|
||||||
onClick = onSelectAll,
|
)
|
||||||
),
|
}
|
||||||
)
|
if (onReverseSelection != null) {
|
||||||
}
|
add(
|
||||||
if (onReverseSelection != null) {
|
AppBar.Action(
|
||||||
add(
|
title = stringResource(MR.strings.action_select_inverse),
|
||||||
AppBar.Action(
|
icon = Icons.Outlined.FlipToBack,
|
||||||
title = stringResource(MR.strings.action_select_inverse),
|
onClick = onReverseSelection,
|
||||||
icon = Icons.Outlined.FlipToBack,
|
),
|
||||||
onClick = onReverseSelection,
|
)
|
||||||
),
|
}
|
||||||
)
|
if (isRunning) {
|
||||||
}
|
add(
|
||||||
if (isRunning) {
|
AppBar.ActionCompose(
|
||||||
add(
|
title = stringResource(KMR.strings.action_bulk_select),
|
||||||
AppBar.ActionCompose(
|
) {
|
||||||
title = stringResource(KMR.strings.action_bulk_select),
|
CircularProgressIndicator(
|
||||||
) {
|
modifier = Modifier
|
||||||
CircularProgressIndicator(
|
.size(24.dp),
|
||||||
modifier = Modifier
|
strokeWidth = 2.dp,
|
||||||
.size(24.dp),
|
)
|
||||||
strokeWidth = 2.dp,
|
},
|
||||||
)
|
)
|
||||||
|
} else {
|
||||||
|
add(
|
||||||
|
AppBar.Action(
|
||||||
|
title = stringResource(MR.strings.add_to_library),
|
||||||
|
icon = Icons.Filled.Favorite,
|
||||||
|
onClick = {
|
||||||
|
if (selectedCount > 0) {
|
||||||
|
onChangeCategoryClick()
|
||||||
|
}
|
||||||
},
|
},
|
||||||
)
|
),
|
||||||
} else {
|
)
|
||||||
add(
|
}
|
||||||
AppBar.Action(
|
}.build(),
|
||||||
title = stringResource(MR.strings.add_to_library),
|
|
||||||
icon = Icons.Filled.Favorite,
|
|
||||||
onClick = {
|
|
||||||
if (selectedCount > 0) {
|
|
||||||
onChangeCategoryClick()
|
|
||||||
}
|
|
||||||
},
|
|
||||||
),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}.build(),
|
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
isActionMode = true,
|
isActionMode = true,
|
||||||
|
|
|
||||||
|
|
@ -105,7 +105,7 @@ fun MangaCompactGridItem(
|
||||||
MangaCoverHide.Book(
|
MangaCoverHide.Book(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth(),
|
.fillMaxWidth(),
|
||||||
bgColor = bgColor ?: (MaterialTheme.colorScheme.surface.takeIf { isSelected }),
|
bgColor = bgColor ?: MaterialTheme.colorScheme.surface.takeIf { isSelected },
|
||||||
tint = onBgColor,
|
tint = onBgColor,
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -119,7 +119,7 @@ fun MangaCompactGridItem(
|
||||||
data = coverData,
|
data = coverData,
|
||||||
// KMK -->
|
// KMK -->
|
||||||
alpha = if (isSelected) GRID_SELECTED_COVER_ALPHA else coverAlpha,
|
alpha = if (isSelected) GRID_SELECTED_COVER_ALPHA else coverAlpha,
|
||||||
bgColor = bgColor ?: (MaterialTheme.colorScheme.surface.takeIf { isSelected }),
|
bgColor = bgColor ?: MaterialTheme.colorScheme.surface.takeIf { isSelected },
|
||||||
tint = onBgColor,
|
tint = onBgColor,
|
||||||
// KMK <--
|
// KMK <--
|
||||||
)
|
)
|
||||||
|
|
@ -241,7 +241,7 @@ fun MangaComfortableGridItem(
|
||||||
MangaCoverHide.Book(
|
MangaCoverHide.Book(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth(),
|
.fillMaxWidth(),
|
||||||
bgColor = bgColor ?: (MaterialTheme.colorScheme.surface.takeIf { isSelected }),
|
bgColor = bgColor ?: MaterialTheme.colorScheme.surface.takeIf { isSelected },
|
||||||
tint = onBgColor,
|
tint = onBgColor,
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -255,7 +255,7 @@ fun MangaComfortableGridItem(
|
||||||
data = coverData,
|
data = coverData,
|
||||||
// KMK -->
|
// KMK -->
|
||||||
alpha = if (isSelected) GRID_SELECTED_COVER_ALPHA else coverAlpha,
|
alpha = if (isSelected) GRID_SELECTED_COVER_ALPHA else coverAlpha,
|
||||||
bgColor = bgColor ?: (MaterialTheme.colorScheme.surface.takeIf { isSelected }),
|
bgColor = bgColor ?: MaterialTheme.colorScheme.surface.takeIf { isSelected },
|
||||||
tint = onBgColor,
|
tint = onBgColor,
|
||||||
onCoverLoaded = { _, result ->
|
onCoverLoaded = { _, result ->
|
||||||
val image = result.result.image
|
val image = result.result.image
|
||||||
|
|
@ -274,7 +274,7 @@ fun MangaComfortableGridItem(
|
||||||
data = coverData,
|
data = coverData,
|
||||||
// KMK -->
|
// KMK -->
|
||||||
alpha = if (isSelected) GRID_SELECTED_COVER_ALPHA else coverAlpha,
|
alpha = if (isSelected) GRID_SELECTED_COVER_ALPHA else coverAlpha,
|
||||||
bgColor = bgColor ?: (MaterialTheme.colorScheme.surface.takeIf { isSelected }),
|
bgColor = bgColor ?: MaterialTheme.colorScheme.surface.takeIf { isSelected },
|
||||||
tint = onBgColor,
|
tint = onBgColor,
|
||||||
onCoverLoaded = { _, result ->
|
onCoverLoaded = { _, result ->
|
||||||
val image = result.result.image
|
val image = result.result.image
|
||||||
|
|
@ -461,7 +461,7 @@ fun MangaListItem(
|
||||||
MangaCoverHide.Square(
|
MangaCoverHide.Square(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxHeight(),
|
.fillMaxHeight(),
|
||||||
bgColor = bgColor ?: (MaterialTheme.colorScheme.surface.takeIf { isSelected }),
|
bgColor = bgColor ?: MaterialTheme.colorScheme.surface.takeIf { isSelected },
|
||||||
tint = onBgColor,
|
tint = onBgColor,
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -475,7 +475,7 @@ fun MangaListItem(
|
||||||
data = coverData,
|
data = coverData,
|
||||||
// KMK -->
|
// KMK -->
|
||||||
alpha = coverAlpha,
|
alpha = coverAlpha,
|
||||||
bgColor = bgColor ?: (MaterialTheme.colorScheme.surface.takeIf { isSelected }),
|
bgColor = bgColor ?: MaterialTheme.colorScheme.surface.takeIf { isSelected },
|
||||||
tint = onBgColor,
|
tint = onBgColor,
|
||||||
size = MangaCover.Size.Big,
|
size = MangaCover.Size.Big,
|
||||||
// KMK <--
|
// KMK <--
|
||||||
|
|
|
||||||
|
|
@ -309,7 +309,7 @@ private fun UpdatesUiItem(
|
||||||
MangaCoverHide.Book(
|
MangaCoverHide.Book(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.width(UpdateItemWidth),
|
.width(UpdateItemWidth),
|
||||||
bgColor = bgColor ?: (MaterialTheme.colorScheme.surface.takeIf { selected }),
|
bgColor = bgColor ?: MaterialTheme.colorScheme.surface.takeIf { selected },
|
||||||
tint = onBgColor,
|
tint = onBgColor,
|
||||||
size = MangaCover.Size.Medium,
|
size = MangaCover.Size.Medium,
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue