Yokan / rebuild
Course 1 8624561

CustomNavigationSettingsScreen.kt

composeApp/src/commonMain/kotlin/eu/friedcutlet/yokan/ui/screens/settings/navigation/CustomNavigationSettingsScreen.kt

implementation137 lines
1package eu.friedcutlet.yokan.ui.screens.settings.navigation23import androidx.compose.foundation.layout.Box4import androidx.compose.foundation.layout.Row5import androidx.compose.foundation.layout.fillMaxWidth6import androidx.compose.foundation.layout.height7import androidx.compose.foundation.layout.padding8import androidx.compose.foundation.layout.size9import androidx.compose.material.icons.Icons10import androidx.compose.material.icons.filled.DragHandle11import androidx.compose.material3.Icon12import androidx.compose.material3.ListItem13import androidx.compose.material3.ListItemDefaults14import androidx.compose.material3.MaterialTheme15import androidx.compose.material3.Surface16import androidx.compose.material3.Switch17import androidx.compose.material3.Text18import androidx.compose.runtime.Composable19import androidx.compose.ui.Alignment20import androidx.compose.ui.Modifier21import androidx.compose.ui.graphics.Color22import androidx.compose.ui.unit.dp23import eu.friedcutlet.yokan.database.DbSettings24import eu.friedcutlet.yokan.ui.components.ReorderableColumn25import eu.friedcutlet.yokan.ui.components.hoverHighlight26import eu.friedcutlet.yokan.ui.navigation.NavSection27import eu.friedcutlet.yokan.ui.navigation.completeNavigationOrder28import eu.friedcutlet.yokan.ui.navigation.hiddenNavigationSections29import eu.friedcutlet.yokan.ui.navigation.localizedTitle30import eu.friedcutlet.yokan.ui.navigation.withNavSectionHiddenToggled31import eu.friedcutlet.yokan.ui.navigation.withNavSectionMoved32import eu.friedcutlet.yokan.ui.screens.settings.SettingsScaffold33import org.jetbrains.compose.resources.stringResource34import yokan.composeapp.generated.resources.Res35import yokan.composeapp.generated.resources.merge_library_nav_mobile3637@Composable38internal fun CustomNavigationSettingsScreen(39    title: String,40    settings: DbSettings,41    onUpdate: ((DbSettings) -> DbSettings) -> Unit,42    onBack: () -> Unit,43) {44    val hidden = hiddenNavigationSections(settings)45    val ordered = completeNavigationOrder(settings)46    val alwaysVisible = setOf(47        NavSection.Browse,48        NavSection.More,49    )5051    SettingsScaffold(title, onBack) {52        item {53            ListItem(54                modifier = Modifier55                    .fillMaxWidth()56                    .padding(horizontal = 15.dp, vertical = 10.dp)57                    .hoverHighlight {58                        onUpdate {59                            it.copy(mergeLibraryNavMobile = !settings.mergeLibraryNavMobile)60                        }61                    },62                headlineContent = { Text(stringResource(Res.string.merge_library_nav_mobile)) },63                trailingContent = {64                    Switch(65                        checked = settings.mergeLibraryNavMobile,66                        onCheckedChange = { value ->67                            onUpdate { it.copy(mergeLibraryNavMobile = value) }68                        },69                    )70                },71                colors = ListItemDefaults.colors(containerColor = Color.Transparent),72            )73        }74        item {75            ReorderableColumn(76                items = ordered,77                key = { it.name },78                onMove = { from, to -> onUpdate { it.withNavSectionMoved(ordered[from], to - from) } },79                modifier = Modifier.padding(horizontal = 15.dp),80            ) { section, dragHandle, isDragging ->81                val enabled = section !in alwaysVisible82                Surface(83                    color = if (isDragging) MaterialTheme.colorScheme.surface else Color.Transparent,84                    shadowElevation = if (isDragging) 6.dp else 0.dp,85                ) {86                    Row(87                        modifier = Modifier.fillMaxWidth(),88                        verticalAlignment = Alignment.CenterVertically,89                    ) {90                        Box(91                            modifier = Modifier92                                .size(48.dp)93                                .then(dragHandle),94                            contentAlignment = Alignment.Center,95                        ) {96                            Icon(97                                Icons.Filled.DragHandle,98                                contentDescription = "Drag to reorder",99                            )100                        }101                        ListItem(102                            modifier = Modifier103                                .weight(1f)104                                .height(48.dp)105                                .let {106                                    if (enabled) {107                                        it.hoverHighlight {108                                            if (section == NavSection.LocalLibrary) {109                                                onUpdate { it.copy(showLocalLibraryNavigation = !settings.showLocalLibraryNavigation) }110                                            } else onUpdate { it.withNavSectionHiddenToggled(section) }111                                        }112                                    } else {113                                        it114                                    }115                                },116                            headlineContent = {117                                Text(localizedTitle(section))118                            },119                            trailingContent = {120                                Switch(121                                    checked = if (section == NavSection.LocalLibrary) settings.showLocalLibraryNavigation else section !in hidden,122                                    onCheckedChange = {123                                        if (enabled && section == NavSection.LocalLibrary) {124                                            onUpdate { it.copy(showLocalLibraryNavigation = !it.showLocalLibraryNavigation) }125                                        } else if (enabled) onUpdate { it.withNavSectionHiddenToggled(section) }126                                    },127                                    enabled = enabled,128                                )129                            },130                            colors = ListItemDefaults.colors(containerColor = Color.Transparent),131                        )132                    }133                }134            }135        }136    }137}138

Search chapters, reference and source filenames.