mirror of
https://github.com/Suwayomi/TachideskJUI.git
synced 2025-12-11 15:22:03 +01:00
Add Category editing to the library settings
This commit is contained in:
@@ -12,6 +12,8 @@ import androidx.compose.foundation.layout.Column
|
|||||||
import androidx.compose.foundation.layout.Row
|
import androidx.compose.foundation.layout.Row
|
||||||
import androidx.compose.foundation.layout.Spacer
|
import androidx.compose.foundation.layout.Spacer
|
||||||
import androidx.compose.foundation.layout.fillMaxSize
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
|
import androidx.compose.foundation.layout.height
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.foundation.lazy.LazyColumn
|
import androidx.compose.foundation.lazy.LazyColumn
|
||||||
import androidx.compose.foundation.lazy.itemsIndexed
|
import androidx.compose.foundation.lazy.itemsIndexed
|
||||||
@@ -23,6 +25,7 @@ import androidx.compose.material.IconButton
|
|||||||
import androidx.compose.material.LocalContentAlpha
|
import androidx.compose.material.LocalContentAlpha
|
||||||
import androidx.compose.material.LocalContentColor
|
import androidx.compose.material.LocalContentColor
|
||||||
import androidx.compose.material.MaterialTheme
|
import androidx.compose.material.MaterialTheme
|
||||||
|
import androidx.compose.material.Surface
|
||||||
import androidx.compose.material.Text
|
import androidx.compose.material.Text
|
||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
import androidx.compose.material.icons.filled.Add
|
import androidx.compose.material.icons.filled.Add
|
||||||
@@ -42,53 +45,61 @@ import androidx.compose.ui.unit.dp
|
|||||||
import ca.gosyer.ui.base.vm.viewModel
|
import ca.gosyer.ui.base.vm.viewModel
|
||||||
import ca.gosyer.util.compose.ThemedWindow
|
import ca.gosyer.util.compose.ThemedWindow
|
||||||
|
|
||||||
fun openCategoriesMenu() {
|
fun openCategoriesMenu(notifyFinished: (() -> Unit)? = null) {
|
||||||
val windowEvents = WindowEvents()
|
val windowEvents = WindowEvents()
|
||||||
ThemedWindow("TachideskJUI - Categories", events = windowEvents) {
|
ThemedWindow("TachideskJUI - Categories", events = windowEvents) {
|
||||||
CategoriesMenu(windowEvents)
|
CategoriesMenu(notifyFinished, windowEvents)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun CategoriesMenu(windowEvents: WindowEvents) {
|
fun CategoriesMenu(notifyFinished: (() -> Unit)? = null, windowEvents: WindowEvents) {
|
||||||
val vm = viewModel<CategoriesMenuViewModel>()
|
val vm = viewModel<CategoriesMenuViewModel>()
|
||||||
val categories by vm.categories.collectAsState()
|
val categories by vm.categories.collectAsState()
|
||||||
remember {
|
remember {
|
||||||
windowEvents.onClose = { vm.updateCategories() }
|
windowEvents.onClose = {
|
||||||
|
vm.updateCategories()
|
||||||
|
notifyFinished?.invoke()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Box {
|
Surface {
|
||||||
LazyColumn(modifier = Modifier.fillMaxSize()) {
|
Box {
|
||||||
itemsIndexed(categories) { i, category ->
|
LazyColumn(modifier = Modifier.fillMaxSize()) {
|
||||||
CategoryRow(
|
itemsIndexed(categories) { i, category ->
|
||||||
category = category,
|
CategoryRow(
|
||||||
moveUpEnabled = i != 0,
|
category = category,
|
||||||
moveDownEnabled = i != categories.lastIndex,
|
moveUpEnabled = i != 0,
|
||||||
onMoveUp = { vm.moveUp(category) },
|
moveDownEnabled = i != categories.lastIndex,
|
||||||
onMoveDown = { vm.moveDown(category) },
|
onMoveUp = { vm.moveUp(category) },
|
||||||
onRename = {
|
onMoveDown = { vm.moveDown(category) },
|
||||||
openRenameDialog(category) {
|
onRename = {
|
||||||
vm.renameCategory(category, it)
|
openRenameDialog(category) {
|
||||||
}
|
vm.renameCategory(category, it)
|
||||||
},
|
}
|
||||||
onDelete = {
|
},
|
||||||
openDeleteDialog(category) {
|
onDelete = {
|
||||||
vm.deleteCategory(category)
|
openDeleteDialog(category) {
|
||||||
}
|
vm.deleteCategory(category)
|
||||||
},
|
}
|
||||||
)
|
},
|
||||||
}
|
)
|
||||||
}
|
}
|
||||||
ExtendedFloatingActionButton(
|
item {
|
||||||
text = { Text(text = "Add") },
|
Spacer(Modifier.height(80.dp).fillMaxWidth())
|
||||||
icon = { Icon(imageVector = Icons.Default.Add, contentDescription = null) },
|
|
||||||
modifier = Modifier.align(Alignment.BottomEnd).padding(16.dp),
|
|
||||||
onClick = {
|
|
||||||
openCreateDialog {
|
|
||||||
vm.createCategory(it)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
ExtendedFloatingActionButton(
|
||||||
|
text = { Text(text = "Add") },
|
||||||
|
icon = { Icon(imageVector = Icons.Default.Add, contentDescription = null) },
|
||||||
|
modifier = Modifier.align(Alignment.BottomEnd).padding(16.dp),
|
||||||
|
onClick = {
|
||||||
|
openCreateDialog {
|
||||||
|
vm.createCategory(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,20 +9,40 @@ package ca.gosyer.ui.settings
|
|||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.foundation.lazy.LazyColumn
|
import androidx.compose.foundation.lazy.LazyColumn
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.collectAsState
|
||||||
import ca.gosyer.data.library.LibraryPreferences
|
import ca.gosyer.data.library.LibraryPreferences
|
||||||
|
import ca.gosyer.data.server.interactions.CategoryInteractionHandler
|
||||||
import ca.gosyer.ui.base.components.Toolbar
|
import ca.gosyer.ui.base.components.Toolbar
|
||||||
|
import ca.gosyer.ui.base.prefs.PreferenceRow
|
||||||
import ca.gosyer.ui.base.prefs.SwitchPreference
|
import ca.gosyer.ui.base.prefs.SwitchPreference
|
||||||
import ca.gosyer.ui.base.vm.ViewModel
|
import ca.gosyer.ui.base.vm.ViewModel
|
||||||
import ca.gosyer.ui.base.vm.viewModel
|
import ca.gosyer.ui.base.vm.viewModel
|
||||||
|
import ca.gosyer.ui.categories.openCategoriesMenu
|
||||||
import ca.gosyer.ui.main.Route
|
import ca.gosyer.ui.main.Route
|
||||||
import com.github.zsoltk.compose.router.BackStack
|
import com.github.zsoltk.compose.router.BackStack
|
||||||
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
|
import kotlinx.coroutines.flow.asStateFlow
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
class SettingsLibraryViewModel @Inject constructor(
|
class SettingsLibraryViewModel @Inject constructor(
|
||||||
libraryPreferences: LibraryPreferences
|
libraryPreferences: LibraryPreferences,
|
||||||
|
private val categoryHandler: CategoryInteractionHandler
|
||||||
) : ViewModel() {
|
) : ViewModel() {
|
||||||
|
|
||||||
val showAllCategory = libraryPreferences.showAllCategory().asStateFlow()
|
val showAllCategory = libraryPreferences.showAllCategory().asStateFlow()
|
||||||
|
private val _categories = MutableStateFlow(0)
|
||||||
|
val categories = _categories.asStateFlow()
|
||||||
|
|
||||||
|
init {
|
||||||
|
refreshCategoryCount()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun refreshCategoryCount() {
|
||||||
|
scope.launch {
|
||||||
|
_categories.value = categoryHandler.getCategories().size
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
@@ -35,6 +55,13 @@ fun SettingsLibraryScreen(navController: BackStack<Route>) {
|
|||||||
item {
|
item {
|
||||||
SwitchPreference(preference = vm.showAllCategory, title = "Show all category")
|
SwitchPreference(preference = vm.showAllCategory, title = "Show all category")
|
||||||
}
|
}
|
||||||
|
item {
|
||||||
|
PreferenceRow(
|
||||||
|
"Categories",
|
||||||
|
onClick = { openCategoriesMenu(vm::refreshCategoryCount) },
|
||||||
|
subtitle = vm.categories.collectAsState().value.toString()
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user