Refactor overflow menus into a composable
(cherry picked from commit df773ee15c814e03267fdfcd81d4e12d38a3508b) # Conflicts: # app/src/main/java/eu/kanade/presentation/library/components/LibraryToolbar.kt # app/src/main/java/eu/kanade/presentation/manga/components/MangaToolbar.kt
This commit is contained in:
parent
621e9dbc41
commit
81d9ac81ce
@ -1,20 +1,29 @@
|
||||
package eu.kanade.presentation.components
|
||||
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.ColumnScope
|
||||
import androidx.compose.foundation.layout.sizeIn
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.outlined.MoreVert
|
||||
import androidx.compose.material.icons.outlined.RadioButtonChecked
|
||||
import androidx.compose.material.icons.outlined.RadioButtonUnchecked
|
||||
import androidx.compose.material3.DropdownMenuItem
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
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.res.stringResource
|
||||
import androidx.compose.ui.unit.DpOffset
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.window.PopupProperties
|
||||
import eu.kanade.tachiyomi.R
|
||||
import me.saket.cascade.CascadeColumnScope
|
||||
import me.saket.cascade.CascadeDropdownMenu
|
||||
import androidx.compose.material3.DropdownMenu as ComposeDropdownMenu
|
||||
|
||||
@Composable
|
||||
@ -61,3 +70,27 @@ fun RadioMenuItem(
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun OverflowMenu(
|
||||
content: @Composable CascadeColumnScope.(() -> Unit) -> Unit,
|
||||
) {
|
||||
var moreExpanded by remember { mutableStateOf(false) }
|
||||
val closeMenu = { moreExpanded = false }
|
||||
|
||||
Box {
|
||||
IconButton(onClick = { moreExpanded = !moreExpanded }) {
|
||||
Icon(
|
||||
imageVector = Icons.Outlined.MoreVert,
|
||||
contentDescription = stringResource(R.string.abc_action_menu_overflow_description),
|
||||
)
|
||||
}
|
||||
CascadeDropdownMenu(
|
||||
expanded = moreExpanded,
|
||||
onDismissRequest = closeMenu,
|
||||
offset = DpOffset(8.dp, (-56).dp),
|
||||
) {
|
||||
content(closeMenu)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,14 +1,12 @@
|
||||
package eu.kanade.presentation.library.components
|
||||
|
||||
import androidx.compose.foundation.isSystemInDarkTheme
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.text.KeyboardActions
|
||||
import androidx.compose.foundation.text.KeyboardOptions
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.outlined.FilterList
|
||||
import androidx.compose.material.icons.outlined.FlipToBack
|
||||
import androidx.compose.material.icons.outlined.MoreVert
|
||||
import androidx.compose.material.icons.outlined.Search
|
||||
import androidx.compose.material.icons.outlined.SelectAll
|
||||
import androidx.compose.material3.DropdownMenuItem
|
||||
@ -19,10 +17,6 @@ import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TopAppBarScrollBehavior
|
||||
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.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalFocusManager
|
||||
@ -32,7 +26,7 @@ import androidx.compose.ui.text.input.ImeAction
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.unit.sp
|
||||
import eu.kanade.presentation.components.AppBar
|
||||
import eu.kanade.presentation.components.DropdownMenu
|
||||
import eu.kanade.presentation.components.OverflowMenu
|
||||
import eu.kanade.presentation.components.Pill
|
||||
import eu.kanade.presentation.components.SearchToolbar
|
||||
import eu.kanade.presentation.library.LibraryState
|
||||
@ -146,45 +140,32 @@ fun LibraryRegularToolbar(
|
||||
IconButton(onClick = onClickFilter) {
|
||||
Icon(Icons.Outlined.FilterList, contentDescription = stringResource(R.string.action_filter), tint = filterTint)
|
||||
}
|
||||
var moreExpanded by remember { mutableStateOf(false) }
|
||||
Box {
|
||||
IconButton(onClick = { moreExpanded = !moreExpanded }) {
|
||||
Icon(
|
||||
imageVector = Icons.Outlined.MoreVert,
|
||||
contentDescription = stringResource(R.string.abc_action_menu_overflow_description),
|
||||
)
|
||||
}
|
||||
val onDismissRequest = { moreExpanded = false }
|
||||
DropdownMenu(
|
||||
expanded = moreExpanded,
|
||||
onDismissRequest = onDismissRequest,
|
||||
) {
|
||||
OverflowMenu { closeMenu ->
|
||||
DropdownMenuItem(
|
||||
text = { Text(text = stringResource(R.string.pref_category_library_update)) },
|
||||
onClick = {
|
||||
onClickRefresh()
|
||||
closeMenu()
|
||||
},
|
||||
)
|
||||
DropdownMenuItem(
|
||||
text = { Text(text = stringResource(R.string.action_open_random_manga)) },
|
||||
onClick = {
|
||||
onClickOpenRandomManga()
|
||||
closeMenu()
|
||||
},
|
||||
)
|
||||
// SY -->
|
||||
if (onClickSyncExh != null) {
|
||||
DropdownMenuItem(
|
||||
text = { Text(text = stringResource(R.string.pref_category_library_update)) },
|
||||
text = { Text(text = stringResource(R.string.sync_favorites)) },
|
||||
onClick = {
|
||||
onClickRefresh()
|
||||
onDismissRequest()
|
||||
onClickSyncExh()
|
||||
closeMenu()
|
||||
},
|
||||
)
|
||||
DropdownMenuItem(
|
||||
text = { Text(text = stringResource(R.string.action_open_random_manga)) },
|
||||
onClick = {
|
||||
onClickOpenRandomManga()
|
||||
onDismissRequest()
|
||||
},
|
||||
)
|
||||
// SY -->
|
||||
if (onClickSyncExh != null) {
|
||||
DropdownMenuItem(
|
||||
text = { Text(text = stringResource(R.string.sync_favorites)) },
|
||||
onClick = {
|
||||
onClickSyncExh()
|
||||
onDismissRequest()
|
||||
},
|
||||
)
|
||||
}
|
||||
// SY <--
|
||||
}
|
||||
// SY <--
|
||||
}
|
||||
},
|
||||
incognitoMode = incognitoMode,
|
||||
|
@ -8,7 +8,6 @@ import androidx.compose.material.icons.outlined.Close
|
||||
import androidx.compose.material.icons.outlined.Download
|
||||
import androidx.compose.material.icons.outlined.FilterList
|
||||
import androidx.compose.material.icons.outlined.FlipToBack
|
||||
import androidx.compose.material.icons.outlined.MoreVert
|
||||
import androidx.compose.material.icons.outlined.SelectAll
|
||||
import androidx.compose.material3.DropdownMenuItem
|
||||
import androidx.compose.material3.Icon
|
||||
@ -20,10 +19,8 @@ import androidx.compose.material3.TopAppBar
|
||||
import androidx.compose.material3.TopAppBarDefaults
|
||||
import androidx.compose.material3.surfaceColorAtElevation
|
||||
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.draw.alpha
|
||||
import androidx.compose.ui.res.stringResource
|
||||
@ -31,6 +28,7 @@ import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.unit.dp
|
||||
import eu.kanade.presentation.components.AppStateBanners
|
||||
import eu.kanade.presentation.components.DropdownMenu
|
||||
import eu.kanade.presentation.components.OverflowMenu
|
||||
import eu.kanade.presentation.manga.DownloadAction
|
||||
import eu.kanade.presentation.theme.active
|
||||
import eu.kanade.tachiyomi.R
|
||||
@ -163,82 +161,69 @@ fun MangaToolbar(
|
||||
}
|
||||
|
||||
if (listOfNotNull(onClickShare, onClickEditCategory, onClickMigrate, onClickEditInfo, onClickRecommend, onClickMergedSettings).isNotEmpty()) {
|
||||
var moreExpanded by remember { mutableStateOf(false) }
|
||||
Box {
|
||||
IconButton(onClick = { moreExpanded = !moreExpanded }) {
|
||||
Icon(
|
||||
imageVector = Icons.Outlined.MoreVert,
|
||||
contentDescription = stringResource(R.string.abc_action_menu_overflow_description),
|
||||
OverflowMenu { closeMenu ->
|
||||
if (onClickEditCategory != null) {
|
||||
DropdownMenuItem(
|
||||
text = { Text(text = stringResource(R.string.action_edit_categories)) },
|
||||
onClick = {
|
||||
onClickEditCategory()
|
||||
closeMenu()
|
||||
},
|
||||
)
|
||||
}
|
||||
val onDismissRequest = { moreExpanded = false }
|
||||
DropdownMenu(
|
||||
expanded = moreExpanded,
|
||||
onDismissRequest = onDismissRequest,
|
||||
) {
|
||||
if (onClickEditCategory != null) {
|
||||
DropdownMenuItem(
|
||||
text = { Text(text = stringResource(R.string.action_edit_categories)) },
|
||||
onClick = {
|
||||
onClickEditCategory()
|
||||
onDismissRequest()
|
||||
},
|
||||
)
|
||||
}
|
||||
if (onClickMigrate != null) {
|
||||
DropdownMenuItem(
|
||||
text = { Text(text = stringResource(R.string.action_migrate)) },
|
||||
onClick = {
|
||||
onClickMigrate()
|
||||
onDismissRequest()
|
||||
},
|
||||
)
|
||||
}
|
||||
if (onClickShare != null) {
|
||||
DropdownMenuItem(
|
||||
text = { Text(text = stringResource(R.string.action_share)) },
|
||||
onClick = {
|
||||
onClickShare()
|
||||
onDismissRequest()
|
||||
},
|
||||
)
|
||||
}
|
||||
if (onClickMerge != null) {
|
||||
DropdownMenuItem(
|
||||
text = { Text(text = stringResource(R.string.merge)) },
|
||||
onClick = {
|
||||
onClickMerge()
|
||||
onDismissRequest()
|
||||
},
|
||||
)
|
||||
}
|
||||
if (onClickEditInfo != null) {
|
||||
DropdownMenuItem(
|
||||
text = { Text(text = stringResource(R.string.action_edit_info)) },
|
||||
onClick = {
|
||||
onClickEditInfo()
|
||||
onDismissRequest()
|
||||
},
|
||||
)
|
||||
}
|
||||
if (onClickRecommend != null) {
|
||||
DropdownMenuItem(
|
||||
text = { Text(text = stringResource(R.string.az_recommends)) },
|
||||
onClick = {
|
||||
onClickRecommend()
|
||||
onDismissRequest()
|
||||
},
|
||||
)
|
||||
}
|
||||
if (onClickMergedSettings != null) {
|
||||
DropdownMenuItem(
|
||||
text = { Text(text = stringResource(R.string.merge_settings)) },
|
||||
onClick = {
|
||||
onClickMergedSettings()
|
||||
onDismissRequest()
|
||||
},
|
||||
)
|
||||
}
|
||||
if (onClickMigrate != null) {
|
||||
DropdownMenuItem(
|
||||
text = { Text(text = stringResource(R.string.action_migrate)) },
|
||||
onClick = {
|
||||
onClickMigrate()
|
||||
closeMenu()
|
||||
},
|
||||
)
|
||||
}
|
||||
if (onClickShare != null) {
|
||||
DropdownMenuItem(
|
||||
text = { Text(text = stringResource(R.string.action_share)) },
|
||||
onClick = {
|
||||
onClickShare()
|
||||
closeMenu()
|
||||
},
|
||||
)
|
||||
}
|
||||
if (onClickMerge != null) {
|
||||
DropdownMenuItem(
|
||||
text = { Text(text = stringResource(R.string.merge)) },
|
||||
onClick = {
|
||||
onClickMerge()
|
||||
closeMenu()
|
||||
},
|
||||
)
|
||||
}
|
||||
if (onClickEditInfo != null) {
|
||||
DropdownMenuItem(
|
||||
text = { Text(text = stringResource(R.string.action_edit_info)) },
|
||||
onClick = {
|
||||
onClickEditInfo()
|
||||
closeMenu()
|
||||
},
|
||||
)
|
||||
}
|
||||
if (onClickRecommend != null) {
|
||||
DropdownMenuItem(
|
||||
text = { Text(text = stringResource(R.string.az_recommends)) },
|
||||
onClick = {
|
||||
onClickRecommend()
|
||||
closeMenu()
|
||||
},
|
||||
)
|
||||
}
|
||||
if (onClickMergedSettings != null) {
|
||||
DropdownMenuItem(
|
||||
text = { Text(text = stringResource(R.string.merge_settings)) },
|
||||
onClick = {
|
||||
onClickMergedSettings()
|
||||
closeMenu()
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,6 @@ import androidx.compose.foundation.layout.navigationBarsPadding
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.outlined.ArrowForward
|
||||
import androidx.compose.material.icons.outlined.Deselect
|
||||
import androidx.compose.material.icons.outlined.MoreVert
|
||||
import androidx.compose.material.icons.outlined.SelectAll
|
||||
import androidx.compose.material3.DropdownMenuItem
|
||||
import androidx.compose.material3.Icon
|
||||
@ -42,8 +41,8 @@ import eu.davidea.flexibleadapter.FlexibleAdapter
|
||||
import eu.kanade.domain.UnsortedPreferences
|
||||
import eu.kanade.domain.source.service.SourcePreferences
|
||||
import eu.kanade.presentation.components.AppBar
|
||||
import eu.kanade.presentation.components.DropdownMenu
|
||||
import eu.kanade.presentation.components.ExtendedFloatingActionButton
|
||||
import eu.kanade.presentation.components.OverflowMenu
|
||||
import eu.kanade.presentation.components.Scaffold
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.databinding.PreMigrationListBinding
|
||||
@ -136,27 +135,21 @@ class PreMigrationController(bundle: Bundle? = null) :
|
||||
contentDescription = stringResource(R.string.action_select_all),
|
||||
)
|
||||
}
|
||||
val (expanded, onExpanded) = remember { mutableStateOf(false) }
|
||||
Box {
|
||||
IconButton(onClick = { onExpanded(!expanded) }) {
|
||||
Icon(
|
||||
imageVector = Icons.Outlined.MoreVert,
|
||||
contentDescription = stringResource(R.string.label_more),
|
||||
)
|
||||
}
|
||||
DropdownMenu(
|
||||
expanded = expanded,
|
||||
onDismissRequest = { onExpanded(false) },
|
||||
) {
|
||||
DropdownMenuItem(
|
||||
text = { Text(stringResource(R.string.match_enabled_sources)) },
|
||||
onClick = { matchSelection(true) },
|
||||
)
|
||||
DropdownMenuItem(
|
||||
text = { Text(stringResource(R.string.match_pinned_sources)) },
|
||||
onClick = { matchSelection(false) },
|
||||
)
|
||||
}
|
||||
OverflowMenu { closeMenu ->
|
||||
DropdownMenuItem(
|
||||
text = { Text(stringResource(R.string.match_enabled_sources)) },
|
||||
onClick = {
|
||||
matchSelection(true)
|
||||
closeMenu()
|
||||
},
|
||||
)
|
||||
DropdownMenuItem(
|
||||
text = { Text(stringResource(R.string.match_pinned_sources)) },
|
||||
onClick = {
|
||||
matchSelection(false)
|
||||
closeMenu()
|
||||
},
|
||||
)
|
||||
}
|
||||
},
|
||||
)
|
||||
|
@ -14,11 +14,9 @@ import androidx.compose.foundation.layout.navigationBarsPadding
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.PlayArrow
|
||||
import androidx.compose.material.icons.outlined.MoreVert
|
||||
import androidx.compose.material.icons.outlined.Pause
|
||||
import androidx.compose.material3.DropdownMenuItem
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TopAppBarDefaults
|
||||
@ -52,6 +50,7 @@ import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import eu.kanade.presentation.components.AppBar
|
||||
import eu.kanade.presentation.components.EmptyScreen
|
||||
import eu.kanade.presentation.components.ExtendedFloatingActionButton
|
||||
import eu.kanade.presentation.components.OverflowMenu
|
||||
import eu.kanade.presentation.components.Pill
|
||||
import eu.kanade.presentation.components.Scaffold
|
||||
import eu.kanade.tachiyomi.R
|
||||
@ -61,7 +60,6 @@ import eu.kanade.tachiyomi.databinding.DownloadListBinding
|
||||
import eu.kanade.tachiyomi.source.model.Page
|
||||
import eu.kanade.tachiyomi.ui.base.controller.FullComposeController
|
||||
import eu.kanade.tachiyomi.util.lang.launchUI
|
||||
import me.saket.cascade.CascadeDropdownMenu
|
||||
import rx.Observable
|
||||
import rx.Subscription
|
||||
import rx.android.schedulers.AndroidSchedulers
|
||||
@ -147,69 +145,69 @@ class DownloadController :
|
||||
navigateUp = router::popCurrentController,
|
||||
actions = {
|
||||
if (downloadList.isNotEmpty()) {
|
||||
var expanded by remember { mutableStateOf(false) }
|
||||
Box {
|
||||
IconButton(onClick = { expanded = !expanded }) {
|
||||
Icon(
|
||||
imageVector = Icons.Outlined.MoreVert,
|
||||
contentDescription = stringResource(R.string.abc_action_menu_overflow_description),
|
||||
)
|
||||
}
|
||||
CascadeDropdownMenu(
|
||||
expanded = expanded,
|
||||
onDismissRequest = { expanded = false },
|
||||
) {
|
||||
DropdownMenuItem(
|
||||
text = { Text(text = stringResource(R.string.action_reorganize_by)) },
|
||||
children = {
|
||||
DropdownMenuItem(
|
||||
text = { Text(text = stringResource(R.string.action_order_by_upload_date)) },
|
||||
children = {
|
||||
DropdownMenuItem(
|
||||
text = { Text(text = stringResource(R.string.action_newest)) },
|
||||
onClick = {
|
||||
reorderQueue({ it.download.chapter.date_upload }, true)
|
||||
expanded = false
|
||||
},
|
||||
)
|
||||
DropdownMenuItem(
|
||||
text = { Text(text = stringResource(R.string.action_oldest)) },
|
||||
onClick = {
|
||||
reorderQueue({ it.download.chapter.date_upload }, false)
|
||||
expanded = false
|
||||
},
|
||||
)
|
||||
},
|
||||
)
|
||||
DropdownMenuItem(
|
||||
text = { Text(text = stringResource(R.string.action_order_by_chapter_number)) },
|
||||
children = {
|
||||
DropdownMenuItem(
|
||||
text = { Text(text = stringResource(R.string.action_asc)) },
|
||||
onClick = {
|
||||
reorderQueue({ it.download.chapter.chapter_number }, false)
|
||||
expanded = false
|
||||
},
|
||||
)
|
||||
DropdownMenuItem(
|
||||
text = { Text(text = stringResource(R.string.action_desc)) },
|
||||
onClick = {
|
||||
reorderQueue({ it.download.chapter.chapter_number }, true)
|
||||
expanded = false
|
||||
},
|
||||
)
|
||||
},
|
||||
)
|
||||
},
|
||||
)
|
||||
DropdownMenuItem(
|
||||
text = { Text(text = stringResource(R.string.action_cancel_all)) },
|
||||
onClick = {
|
||||
presenter.clearQueue(context)
|
||||
expanded = false
|
||||
},
|
||||
)
|
||||
}
|
||||
OverflowMenu { closeMenu ->
|
||||
DropdownMenuItem(
|
||||
text = { Text(text = stringResource(R.string.action_reorganize_by)) },
|
||||
children = {
|
||||
DropdownMenuItem(
|
||||
text = { Text(text = stringResource(R.string.action_order_by_upload_date)) },
|
||||
children = {
|
||||
DropdownMenuItem(
|
||||
text = { Text(text = stringResource(R.string.action_newest)) },
|
||||
onClick = {
|
||||
reorderQueue(
|
||||
{ it.download.chapter.date_upload },
|
||||
true,
|
||||
)
|
||||
closeMenu()
|
||||
},
|
||||
)
|
||||
DropdownMenuItem(
|
||||
text = { Text(text = stringResource(R.string.action_oldest)) },
|
||||
onClick = {
|
||||
reorderQueue(
|
||||
{ it.download.chapter.date_upload },
|
||||
false,
|
||||
)
|
||||
closeMenu()
|
||||
},
|
||||
)
|
||||
},
|
||||
)
|
||||
DropdownMenuItem(
|
||||
text = { Text(text = stringResource(R.string.action_order_by_chapter_number)) },
|
||||
children = {
|
||||
DropdownMenuItem(
|
||||
text = { Text(text = stringResource(R.string.action_asc)) },
|
||||
onClick = {
|
||||
reorderQueue(
|
||||
{ it.download.chapter.chapter_number },
|
||||
false,
|
||||
)
|
||||
closeMenu()
|
||||
},
|
||||
)
|
||||
DropdownMenuItem(
|
||||
text = { Text(text = stringResource(R.string.action_desc)) },
|
||||
onClick = {
|
||||
reorderQueue(
|
||||
{ it.download.chapter.chapter_number },
|
||||
true,
|
||||
)
|
||||
closeMenu()
|
||||
},
|
||||
)
|
||||
},
|
||||
)
|
||||
},
|
||||
)
|
||||
DropdownMenuItem(
|
||||
text = { Text(text = stringResource(R.string.action_cancel_all)) },
|
||||
onClick = {
|
||||
presenter.clearQueue(context)
|
||||
closeMenu()
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
},
|
||||
|
Loading…
x
Reference in New Issue
Block a user