2022-06-19 23:17:48 +02:00
|
|
|
package eu.kanade.presentation.components
|
|
|
|
|
2023-12-25 22:31:40 +01:00
|
|
|
import androidx.compose.foundation.ScrollState
|
|
|
|
import androidx.compose.foundation.layout.Box
|
2022-06-19 23:17:48 +02:00
|
|
|
import androidx.compose.foundation.layout.ColumnScope
|
|
|
|
import androidx.compose.foundation.layout.sizeIn
|
2023-12-25 22:31:40 +01:00
|
|
|
import androidx.compose.foundation.rememberScrollState
|
2022-10-15 17:16:01 +02:00
|
|
|
import androidx.compose.material.icons.Icons
|
2023-11-16 04:19:02 +01:00
|
|
|
import androidx.compose.material.icons.automirrored.outlined.ArrowRight
|
2022-10-15 17:16:01 +02:00
|
|
|
import androidx.compose.material.icons.outlined.RadioButtonChecked
|
|
|
|
import androidx.compose.material.icons.outlined.RadioButtonUnchecked
|
|
|
|
import androidx.compose.material3.DropdownMenuItem
|
|
|
|
import androidx.compose.material3.Icon
|
2022-10-15 18:05:52 +02:00
|
|
|
import androidx.compose.material3.MaterialTheme
|
2022-06-19 23:17:48 +02:00
|
|
|
import androidx.compose.runtime.Composable
|
2022-10-30 16:06:41 +01:00
|
|
|
import androidx.compose.runtime.getValue
|
|
|
|
import androidx.compose.runtime.mutableStateOf
|
|
|
|
import androidx.compose.runtime.remember
|
|
|
|
import androidx.compose.runtime.setValue
|
2022-06-19 23:17:48 +02:00
|
|
|
import androidx.compose.ui.Modifier
|
|
|
|
import androidx.compose.ui.unit.DpOffset
|
|
|
|
import androidx.compose.ui.unit.dp
|
|
|
|
import androidx.compose.ui.window.PopupProperties
|
2023-11-18 19:54:56 +01:00
|
|
|
import tachiyomi.i18n.MR
|
2023-11-19 01:41:33 +01:00
|
|
|
import tachiyomi.presentation.core.i18n.stringResource
|
2022-06-19 23:17:48 +02:00
|
|
|
import androidx.compose.material3.DropdownMenu as ComposeDropdownMenu
|
|
|
|
|
2023-12-25 22:31:40 +01:00
|
|
|
/**
|
|
|
|
* DropdownMenu but overlaps anchor and has width constraints to better
|
|
|
|
* match non-Compose implementation.
|
|
|
|
*/
|
2022-06-19 23:17:48 +02:00
|
|
|
@Composable
|
|
|
|
fun DropdownMenu(
|
|
|
|
expanded: Boolean,
|
|
|
|
onDismissRequest: () -> Unit,
|
|
|
|
modifier: Modifier = Modifier,
|
2022-10-29 22:14:44 +02:00
|
|
|
offset: DpOffset = DpOffset(8.dp, (-56).dp),
|
2023-12-25 22:31:40 +01:00
|
|
|
scrollState: ScrollState = rememberScrollState(),
|
2022-06-19 23:17:48 +02:00
|
|
|
properties: PopupProperties = PopupProperties(focusable = true),
|
|
|
|
content: @Composable ColumnScope.() -> Unit,
|
|
|
|
) {
|
|
|
|
ComposeDropdownMenu(
|
|
|
|
expanded = expanded,
|
|
|
|
onDismissRequest = onDismissRequest,
|
|
|
|
modifier = modifier.sizeIn(minWidth = 196.dp, maxWidth = 196.dp),
|
2022-10-29 22:14:44 +02:00
|
|
|
offset = offset,
|
2023-12-25 22:31:40 +01:00
|
|
|
scrollState = scrollState,
|
2022-06-19 23:17:48 +02:00
|
|
|
properties = properties,
|
|
|
|
content = content,
|
|
|
|
)
|
|
|
|
}
|
2022-10-15 17:16:01 +02:00
|
|
|
|
|
|
|
@Composable
|
2022-10-15 18:05:52 +02:00
|
|
|
fun RadioMenuItem(
|
2022-10-15 17:16:01 +02:00
|
|
|
text: @Composable () -> Unit,
|
|
|
|
isChecked: Boolean,
|
2023-12-25 22:31:40 +01:00
|
|
|
modifier: Modifier = Modifier,
|
2022-10-15 18:05:52 +02:00
|
|
|
onClick: () -> Unit,
|
2022-10-15 17:16:01 +02:00
|
|
|
) {
|
|
|
|
DropdownMenuItem(
|
|
|
|
text = text,
|
|
|
|
onClick = onClick,
|
|
|
|
trailingIcon = {
|
|
|
|
if (isChecked) {
|
|
|
|
Icon(
|
|
|
|
imageVector = Icons.Outlined.RadioButtonChecked,
|
2023-11-19 01:41:33 +01:00
|
|
|
contentDescription = stringResource(MR.strings.selected),
|
2022-10-15 18:05:52 +02:00
|
|
|
tint = MaterialTheme.colorScheme.primary,
|
2022-10-15 17:16:01 +02:00
|
|
|
)
|
|
|
|
} else {
|
|
|
|
Icon(
|
|
|
|
imageVector = Icons.Outlined.RadioButtonUnchecked,
|
2023-11-19 01:41:33 +01:00
|
|
|
contentDescription = stringResource(MR.strings.not_selected),
|
2022-10-15 17:16:01 +02:00
|
|
|
)
|
|
|
|
}
|
|
|
|
},
|
2023-12-25 22:31:40 +01:00
|
|
|
modifier = modifier,
|
2022-10-15 17:16:01 +02:00
|
|
|
)
|
|
|
|
}
|
2022-10-30 16:06:41 +01:00
|
|
|
|
|
|
|
@Composable
|
2023-05-21 17:02:56 +02:00
|
|
|
fun NestedMenuItem(
|
|
|
|
text: @Composable () -> Unit,
|
|
|
|
children: @Composable ColumnScope.(() -> Unit) -> Unit,
|
2023-12-25 22:31:40 +01:00
|
|
|
modifier: Modifier = Modifier,
|
2022-10-30 16:06:41 +01:00
|
|
|
) {
|
2023-05-21 17:02:56 +02:00
|
|
|
var nestedExpanded by remember { mutableStateOf(false) }
|
|
|
|
val closeMenu = { nestedExpanded = false }
|
2022-10-30 16:06:41 +01:00
|
|
|
|
2023-12-25 22:31:40 +01:00
|
|
|
Box {
|
|
|
|
DropdownMenuItem(
|
|
|
|
text = text,
|
|
|
|
onClick = { nestedExpanded = true },
|
|
|
|
trailingIcon = {
|
|
|
|
Icon(
|
|
|
|
imageVector = Icons.AutoMirrored.Outlined.ArrowRight,
|
|
|
|
contentDescription = null,
|
|
|
|
)
|
|
|
|
},
|
|
|
|
)
|
2023-05-21 17:02:56 +02:00
|
|
|
|
2023-12-25 22:31:40 +01:00
|
|
|
DropdownMenu(
|
|
|
|
expanded = nestedExpanded,
|
|
|
|
onDismissRequest = closeMenu,
|
|
|
|
modifier = modifier,
|
|
|
|
) {
|
|
|
|
children(closeMenu)
|
|
|
|
}
|
2022-10-30 16:06:41 +01:00
|
|
|
}
|
|
|
|
}
|