mirror of
https://github.com/LiveFastEatTrashRaccoon/RaccoonForLemmy.git
synced 2025-02-04 03:37:34 +01:00
fix: IllegalStateException when opening SortBottomSheet (#931)
This commit is contained in:
parent
541cf7255d
commit
fd13d1c7b8
@ -1,5 +1,6 @@
|
|||||||
package com.github.diegoberaldin.raccoonforlemmy.core.commonui.modals
|
package com.github.diegoberaldin.raccoonforlemmy.core.commonui.modals
|
||||||
|
|
||||||
|
import androidx.compose.animation.Crossfade
|
||||||
import androidx.compose.foundation.Image
|
import androidx.compose.foundation.Image
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
import androidx.compose.foundation.layout.Box
|
import androidx.compose.foundation.layout.Box
|
||||||
@ -20,14 +21,14 @@ import androidx.compose.material3.Icon
|
|||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.runtime.mutableStateOf
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
|
import androidx.compose.runtime.setValue
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.graphics.ColorFilter
|
import androidx.compose.ui.graphics.ColorFilter
|
||||||
import cafe.adriel.voyager.core.screen.Screen
|
import cafe.adriel.voyager.core.screen.Screen
|
||||||
import cafe.adriel.voyager.navigator.LocalNavigator
|
|
||||||
import cafe.adriel.voyager.navigator.Navigator
|
|
||||||
import cafe.adriel.voyager.navigator.currentOrThrow
|
|
||||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.theme.Spacing
|
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.theme.Spacing
|
||||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.components.BottomSheetHeader
|
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.components.BottomSheetHeader
|
||||||
import com.github.diegoberaldin.raccoonforlemmy.core.l10n.LocalXmlStrings
|
import com.github.diegoberaldin.raccoonforlemmy.core.l10n.LocalXmlStrings
|
||||||
@ -41,6 +42,12 @@ import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data.toInt
|
|||||||
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data.toReadableName
|
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data.toReadableName
|
||||||
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data.toSortType
|
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data.toSortType
|
||||||
|
|
||||||
|
private sealed interface SortBottomSheetLevel {
|
||||||
|
data object Main : SortBottomSheetLevel
|
||||||
|
|
||||||
|
data object Top : SortBottomSheetLevel
|
||||||
|
}
|
||||||
|
|
||||||
class SortBottomSheet(
|
class SortBottomSheet(
|
||||||
private val values: List<Int>,
|
private val values: List<Int>,
|
||||||
private val comments: Boolean = false,
|
private val comments: Boolean = false,
|
||||||
@ -62,100 +69,32 @@ class SortBottomSheet(
|
|||||||
),
|
),
|
||||||
verticalArrangement = Arrangement.spacedBy(Spacing.s),
|
verticalArrangement = Arrangement.spacedBy(Spacing.s),
|
||||||
) {
|
) {
|
||||||
Navigator(
|
var level by remember { mutableStateOf<SortBottomSheetLevel>(SortBottomSheetLevel.Main) }
|
||||||
SortBottomSheetMain(
|
Crossfade(
|
||||||
values = values,
|
targetState = level,
|
||||||
expandTop = expandTop,
|
) { currentLevel ->
|
||||||
comments = comments,
|
when (currentLevel) {
|
||||||
defaultForCommunity = defaultForCommunity,
|
SortBottomSheetLevel.Main -> {
|
||||||
screenKey = screenKey,
|
SortBottomSheetMain(
|
||||||
),
|
values = values,
|
||||||
)
|
expandTop = expandTop,
|
||||||
}
|
comments = comments,
|
||||||
}
|
defaultForCommunity = defaultForCommunity,
|
||||||
}
|
screenKey = screenKey,
|
||||||
|
onNavigateUp = {
|
||||||
internal class SortBottomSheetMain(
|
level = SortBottomSheetLevel.Top
|
||||||
private val comments: Boolean,
|
},
|
||||||
private val values: List<Int>,
|
|
||||||
private val expandTop: Boolean = false,
|
|
||||||
private val defaultForCommunity: Boolean = false,
|
|
||||||
private val screenKey: String?,
|
|
||||||
) : Screen {
|
|
||||||
@Composable
|
|
||||||
override fun Content() {
|
|
||||||
val navigator = LocalNavigator.currentOrThrow
|
|
||||||
val navigationCoordinator = remember { getNavigationCoordinator() }
|
|
||||||
val notificationCenter = remember { getNotificationCenter() }
|
|
||||||
Column {
|
|
||||||
BottomSheetHeader(LocalXmlStrings.current.homeSortTitle)
|
|
||||||
Column(
|
|
||||||
modifier = Modifier.fillMaxWidth().verticalScroll(rememberScrollState()),
|
|
||||||
verticalArrangement = Arrangement.spacedBy(Spacing.xxs),
|
|
||||||
) {
|
|
||||||
for (value in values) {
|
|
||||||
val sortValue = value.toSortType()
|
|
||||||
Row(
|
|
||||||
modifier =
|
|
||||||
Modifier
|
|
||||||
.padding(
|
|
||||||
horizontal = Spacing.s,
|
|
||||||
vertical = Spacing.s,
|
|
||||||
)
|
|
||||||
.fillMaxWidth()
|
|
||||||
.onClick(
|
|
||||||
onClick = {
|
|
||||||
if (sortValue == SortType.Top.Generic && expandTop) {
|
|
||||||
navigator.push(
|
|
||||||
SortBottomSheetTop(
|
|
||||||
comments = comments,
|
|
||||||
defaultForCommunity = defaultForCommunity,
|
|
||||||
screenKey = screenKey,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
val event =
|
|
||||||
if (comments) {
|
|
||||||
NotificationCenterEvent.ChangeCommentSortType(
|
|
||||||
value = sortValue,
|
|
||||||
screenKey = screenKey,
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
NotificationCenterEvent.ChangeSortType(
|
|
||||||
value = sortValue,
|
|
||||||
defaultForCommunity = defaultForCommunity,
|
|
||||||
screenKey = screenKey,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
notificationCenter.send(event)
|
|
||||||
navigationCoordinator.hideBottomSheet()
|
|
||||||
}
|
|
||||||
},
|
|
||||||
),
|
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
|
||||||
) {
|
|
||||||
val name =
|
|
||||||
buildString {
|
|
||||||
append(sortValue.toReadableName())
|
|
||||||
if (sortValue == SortType.Top.Generic && expandTop) {
|
|
||||||
append("…")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Text(
|
|
||||||
text = name,
|
|
||||||
style = MaterialTheme.typography.bodyLarge,
|
|
||||||
color = MaterialTheme.colorScheme.onBackground,
|
|
||||||
)
|
)
|
||||||
Spacer(modifier = Modifier.weight(1f))
|
}
|
||||||
Image(
|
|
||||||
imageVector =
|
SortBottomSheetLevel.Top -> {
|
||||||
if (sortValue == SortType.Top.Generic && expandTop) {
|
SortBottomSheetTop(
|
||||||
Icons.Default.ChevronRight
|
comments = comments,
|
||||||
} else {
|
defaultForCommunity = defaultForCommunity,
|
||||||
sortValue.toIcon()
|
screenKey = screenKey,
|
||||||
},
|
onNavigateDown = {
|
||||||
contentDescription = null,
|
level = SortBottomSheetLevel.Main
|
||||||
colorFilter = ColorFilter.tint(MaterialTheme.colorScheme.onBackground),
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -164,66 +103,38 @@ internal class SortBottomSheetMain(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class SortBottomSheetTop(
|
@Composable
|
||||||
private val comments: Boolean,
|
private fun SortBottomSheetMain(
|
||||||
private val values: List<Int> =
|
comments: Boolean,
|
||||||
listOf(
|
values: List<Int>,
|
||||||
SortType.Top.PastHour,
|
expandTop: Boolean = false,
|
||||||
SortType.Top.Past6Hours,
|
defaultForCommunity: Boolean = false,
|
||||||
SortType.Top.Past12Hours,
|
screenKey: String?,
|
||||||
SortType.Top.Day,
|
onNavigateUp: () -> Unit,
|
||||||
SortType.Top.Week,
|
) {
|
||||||
SortType.Top.Month,
|
val navigationCoordinator = remember { getNavigationCoordinator() }
|
||||||
SortType.Top.Year,
|
val notificationCenter = remember { getNotificationCenter() }
|
||||||
).map { it.toInt() },
|
Column {
|
||||||
private val defaultForCommunity: Boolean = false,
|
BottomSheetHeader(LocalXmlStrings.current.homeSortTitle)
|
||||||
private val screenKey: String?,
|
Column(
|
||||||
) : Screen {
|
modifier = Modifier.fillMaxWidth().verticalScroll(rememberScrollState()),
|
||||||
@Composable
|
verticalArrangement = Arrangement.spacedBy(Spacing.xxs),
|
||||||
override fun Content() {
|
) {
|
||||||
val navigator = LocalNavigator.currentOrThrow
|
for (value in values) {
|
||||||
val navigationCoordinator = remember { getNavigationCoordinator() }
|
val sortValue = value.toSortType()
|
||||||
val notificationCenter = remember { getNotificationCenter() }
|
|
||||||
|
|
||||||
Column {
|
|
||||||
Box(
|
|
||||||
contentAlignment = Alignment.Center,
|
|
||||||
) {
|
|
||||||
BottomSheetHeader(SortType.Top.Generic.toReadableName() + "…")
|
|
||||||
Row(
|
Row(
|
||||||
modifier = Modifier.padding(start = Spacing.xxs),
|
modifier =
|
||||||
) {
|
Modifier
|
||||||
Icon(
|
.padding(
|
||||||
modifier =
|
horizontal = Spacing.s,
|
||||||
Modifier
|
vertical = Spacing.s,
|
||||||
.onClick(
|
)
|
||||||
onClick = {
|
.fillMaxWidth()
|
||||||
navigator.pop()
|
.onClick(
|
||||||
},
|
onClick = {
|
||||||
),
|
if (sortValue == SortType.Top.Generic && expandTop) {
|
||||||
imageVector = Icons.AutoMirrored.Default.ArrowBack,
|
onNavigateUp()
|
||||||
tint = MaterialTheme.colorScheme.onBackground,
|
} else {
|
||||||
contentDescription = null,
|
|
||||||
)
|
|
||||||
Spacer(modifier = Modifier.weight(1f))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Column(
|
|
||||||
modifier = Modifier.fillMaxWidth().verticalScroll(rememberScrollState()),
|
|
||||||
verticalArrangement = Arrangement.spacedBy(Spacing.xxs),
|
|
||||||
) {
|
|
||||||
for (value in values) {
|
|
||||||
val sortValue = value.toSortType()
|
|
||||||
Row(
|
|
||||||
modifier =
|
|
||||||
Modifier
|
|
||||||
.padding(
|
|
||||||
horizontal = Spacing.s,
|
|
||||||
vertical = Spacing.s,
|
|
||||||
)
|
|
||||||
.fillMaxWidth()
|
|
||||||
.onClick(
|
|
||||||
onClick = {
|
|
||||||
val event =
|
val event =
|
||||||
if (comments) {
|
if (comments) {
|
||||||
NotificationCenterEvent.ChangeCommentSortType(
|
NotificationCenterEvent.ChangeCommentSortType(
|
||||||
@ -239,22 +150,129 @@ internal class SortBottomSheetTop(
|
|||||||
}
|
}
|
||||||
notificationCenter.send(event)
|
notificationCenter.send(event)
|
||||||
navigationCoordinator.hideBottomSheet()
|
navigationCoordinator.hideBottomSheet()
|
||||||
},
|
}
|
||||||
),
|
},
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
),
|
||||||
) {
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
Text(
|
) {
|
||||||
text = sortValue.toReadableName(),
|
val name =
|
||||||
style = MaterialTheme.typography.bodyLarge,
|
buildString {
|
||||||
color = MaterialTheme.colorScheme.onBackground,
|
append(sortValue.toReadableName())
|
||||||
)
|
if (sortValue == SortType.Top.Generic && expandTop) {
|
||||||
Spacer(modifier = Modifier.weight(1f))
|
append("…")
|
||||||
Image(
|
}
|
||||||
imageVector = sortValue.toIcon(),
|
}
|
||||||
contentDescription = null,
|
Text(
|
||||||
colorFilter = ColorFilter.tint(MaterialTheme.colorScheme.onBackground),
|
text = name,
|
||||||
)
|
style = MaterialTheme.typography.bodyLarge,
|
||||||
}
|
color = MaterialTheme.colorScheme.onBackground,
|
||||||
|
)
|
||||||
|
Spacer(modifier = Modifier.weight(1f))
|
||||||
|
Image(
|
||||||
|
imageVector =
|
||||||
|
if (sortValue == SortType.Top.Generic && expandTop) {
|
||||||
|
Icons.Default.ChevronRight
|
||||||
|
} else {
|
||||||
|
sortValue.toIcon()
|
||||||
|
},
|
||||||
|
contentDescription = null,
|
||||||
|
colorFilter = ColorFilter.tint(MaterialTheme.colorScheme.onBackground),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun SortBottomSheetTop(
|
||||||
|
comments: Boolean,
|
||||||
|
values: List<Int> =
|
||||||
|
listOf(
|
||||||
|
SortType.Top.PastHour,
|
||||||
|
SortType.Top.Past6Hours,
|
||||||
|
SortType.Top.Past12Hours,
|
||||||
|
SortType.Top.Day,
|
||||||
|
SortType.Top.Week,
|
||||||
|
SortType.Top.Month,
|
||||||
|
SortType.Top.Year,
|
||||||
|
).map { it.toInt() },
|
||||||
|
defaultForCommunity: Boolean = false,
|
||||||
|
screenKey: String?,
|
||||||
|
onNavigateDown: () -> Unit,
|
||||||
|
) {
|
||||||
|
val navigationCoordinator = remember { getNavigationCoordinator() }
|
||||||
|
val notificationCenter = remember { getNotificationCenter() }
|
||||||
|
|
||||||
|
Column {
|
||||||
|
Box(
|
||||||
|
contentAlignment = Alignment.Center,
|
||||||
|
) {
|
||||||
|
BottomSheetHeader(SortType.Top.Generic.toReadableName() + "…")
|
||||||
|
Row(
|
||||||
|
modifier = Modifier.padding(start = Spacing.xxs),
|
||||||
|
) {
|
||||||
|
Icon(
|
||||||
|
modifier =
|
||||||
|
Modifier
|
||||||
|
.onClick(
|
||||||
|
onClick = {
|
||||||
|
onNavigateDown()
|
||||||
|
},
|
||||||
|
),
|
||||||
|
imageVector = Icons.AutoMirrored.Default.ArrowBack,
|
||||||
|
tint = MaterialTheme.colorScheme.onBackground,
|
||||||
|
contentDescription = null,
|
||||||
|
)
|
||||||
|
Spacer(modifier = Modifier.weight(1f))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Column(
|
||||||
|
modifier = Modifier.fillMaxWidth().verticalScroll(rememberScrollState()),
|
||||||
|
verticalArrangement = Arrangement.spacedBy(Spacing.xxs),
|
||||||
|
) {
|
||||||
|
for (value in values) {
|
||||||
|
val sortValue = value.toSortType()
|
||||||
|
Row(
|
||||||
|
modifier =
|
||||||
|
Modifier
|
||||||
|
.padding(
|
||||||
|
horizontal = Spacing.s,
|
||||||
|
vertical = Spacing.s,
|
||||||
|
)
|
||||||
|
.fillMaxWidth()
|
||||||
|
.onClick(
|
||||||
|
onClick = {
|
||||||
|
val event =
|
||||||
|
if (comments) {
|
||||||
|
NotificationCenterEvent.ChangeCommentSortType(
|
||||||
|
value = sortValue,
|
||||||
|
screenKey = screenKey,
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
NotificationCenterEvent.ChangeSortType(
|
||||||
|
value = sortValue,
|
||||||
|
defaultForCommunity = defaultForCommunity,
|
||||||
|
screenKey = screenKey,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
notificationCenter.send(event)
|
||||||
|
navigationCoordinator.hideBottomSheet()
|
||||||
|
},
|
||||||
|
),
|
||||||
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
|
) {
|
||||||
|
Text(
|
||||||
|
text = sortValue.toReadableName(),
|
||||||
|
style = MaterialTheme.typography.bodyLarge,
|
||||||
|
color = MaterialTheme.colorScheme.onBackground,
|
||||||
|
)
|
||||||
|
Spacer(modifier = Modifier.weight(1f))
|
||||||
|
Image(
|
||||||
|
imageVector = sortValue.toIcon(),
|
||||||
|
contentDescription = null,
|
||||||
|
colorFilter = ColorFilter.tint(MaterialTheme.colorScheme.onBackground),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user