feat: sticky library control strip on Library screen with scan confirmations
This commit is contained in:
1 parent
97fda5a3df
commit
7d58013aa1
2 files changed
+111
-52
No files matched your search
@@ -1,5 +1,6 @@
|
|||||||
package com.trafero.app.ui.screens.library
|
package com.trafero.app.ui.screens.library
|
||||||
|
|
||||||
|
import androidx.compose.foundation.background
|
||||||
import androidx.compose.foundation.clickable
|
import androidx.compose.foundation.clickable
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
@@ -12,6 +13,9 @@ import androidx.compose.foundation.layout.heightIn
|
|||||||
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.items
|
import androidx.compose.foundation.lazy.items
|
||||||
|
import androidx.compose.foundation.rememberScrollState
|
||||||
|
import androidx.compose.foundation.verticalScroll
|
||||||
|
import androidx.compose.material3.AlertDialog
|
||||||
import androidx.compose.material3.Button
|
import androidx.compose.material3.Button
|
||||||
import androidx.compose.material3.Card
|
import androidx.compose.material3.Card
|
||||||
import androidx.compose.material3.DropdownMenu
|
import androidx.compose.material3.DropdownMenu
|
||||||
@@ -19,6 +23,7 @@ import androidx.compose.material3.DropdownMenuItem
|
|||||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||||
import androidx.compose.material3.ModalBottomSheet
|
import androidx.compose.material3.ModalBottomSheet
|
||||||
import androidx.compose.material3.OutlinedTextField
|
import androidx.compose.material3.OutlinedTextField
|
||||||
|
import androidx.compose.material3.Switch
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.material3.TextButton
|
import androidx.compose.material3.TextButton
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
@@ -31,6 +36,7 @@ import androidx.compose.runtime.rememberCoroutineScope
|
|||||||
import androidx.compose.runtime.setValue
|
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.draw.scale
|
||||||
import androidx.compose.ui.text.font.FontFamily
|
import androidx.compose.ui.text.font.FontFamily
|
||||||
import androidx.compose.ui.text.font.FontStyle
|
import androidx.compose.ui.text.font.FontStyle
|
||||||
import androidx.compose.ui.text.font.FontWeight
|
import androidx.compose.ui.text.font.FontWeight
|
||||||
@@ -81,6 +87,22 @@ fun LibraryScreen(nav: NavController) {
|
|||||||
var sortMenu by remember { mutableStateOf(false) }
|
var sortMenu by remember { mutableStateOf(false) }
|
||||||
val pageSize = 30
|
val pageSize = 30
|
||||||
val scope = rememberCoroutineScope()
|
val scope = rememberCoroutineScope()
|
||||||
|
var pendingScan by remember { mutableStateOf<Pair<LibInfo, String>?>(null) }
|
||||||
|
|
||||||
|
fun launchScan(lib: LibInfo, mode: String) {
|
||||||
|
scope.launch {
|
||||||
|
runCatching { repo.scanLibrary(lib.id, lib.folder, mode) }
|
||||||
|
.onSuccess {
|
||||||
|
error = if (mode == "scanFresh") "Full scan queued: " + lib.name
|
||||||
|
else "Scan (new files) queued: " + lib.name
|
||||||
|
}
|
||||||
|
.onFailure { error = TraferoRepo.describeError(it) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun refreshLibs() {
|
||||||
|
scope.launch { runCatching { repo.libraries() }.onSuccess { libs = it } }
|
||||||
|
}
|
||||||
|
|
||||||
LaunchedEffect(Unit) { runCatching { repo.libraries() }.onSuccess { libs = it } }
|
LaunchedEffect(Unit) { runCatching { repo.libraries() }.onSuccess { libs = it } }
|
||||||
|
|
||||||
@@ -98,7 +120,25 @@ fun LibraryScreen(nav: NavController) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Column(Modifier.fillMaxSize()) {
|
Column(Modifier.fillMaxSize()) {
|
||||||
Row(Modifier.padding(horizontal = 12.dp), horizontalArrangement = Arrangement.spacedBy(8.dp)) {
|
// Sticky library control strip: watch toggle + scans for every library,
|
||||||
|
// capped to ~3 rows (internal scroll) so the file list stays usable.
|
||||||
|
if (libs.isNotEmpty()) {
|
||||||
|
Column(
|
||||||
|
Modifier.fillMaxWidth()
|
||||||
|
.background(MaterialTheme.colorScheme.surfaceVariant.copy(alpha = 0.45f))
|
||||||
|
.heightIn(max = 150.dp)
|
||||||
|
.verticalScroll(rememberScrollState())
|
||||||
|
.padding(horizontal = 12.dp, vertical = 2.dp)
|
||||||
|
) {
|
||||||
|
libs.forEach { lib ->
|
||||||
|
LibControlRow(lib, repo,
|
||||||
|
onScan = { l, mode -> pendingScan = l to mode }) { msg ->
|
||||||
|
if (msg != null) error = msg else refreshLibs()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Row(Modifier.padding(horizontal = 12.dp, vertical = 6.dp), horizontalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||||
OutlinedTextField(value = query, onValueChange = { query = it }, singleLine = true,
|
OutlinedTextField(value = query, onValueChange = { query = it }, singleLine = true,
|
||||||
label = { Text("Search files") }, modifier = Modifier.weight(1f))
|
label = { Text("Search files") }, modifier = Modifier.weight(1f))
|
||||||
}
|
}
|
||||||
@@ -142,6 +182,74 @@ fun LibraryScreen(nav: NavController) {
|
|||||||
FileDetailSheet(repo, row) { msg -> error = msg; selected = null }
|
FileDetailSheet(repo, row) { msg -> error = msg; selected = null }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Scan confirmations: full scan is destructive (wipes + re-queues everything),
|
||||||
|
// so it warns explicitly and offers the safe scan-for-new-files alternative.
|
||||||
|
pendingScan?.let { (lib, mode) ->
|
||||||
|
AlertDialog(
|
||||||
|
onDismissRequest = { pendingScan = null },
|
||||||
|
title = { Text(if (mode == "scanFresh") "Full scan warning" else "Scan for new files?") },
|
||||||
|
text = {
|
||||||
|
Text(if (mode == "scanFresh")
|
||||||
|
"A full scan of \"" + lib.name + "\" will wipe the database and rescan the entire library, then re-queue everything for health checks and transcoding. In most circumstances, scanning for new files is recommended. Are you sure?"
|
||||||
|
else "Scanning \"" + lib.name + "\" for new files may take some time. Are you sure?")
|
||||||
|
},
|
||||||
|
confirmButton = {
|
||||||
|
Row(horizontalArrangement = Arrangement.spacedBy(4.dp)) {
|
||||||
|
if (mode == "scanFresh") {
|
||||||
|
TextButton(onClick = {
|
||||||
|
pendingScan = null
|
||||||
|
launchScan(lib, "scanFindNew")
|
||||||
|
}) { Text("Scan new") }
|
||||||
|
}
|
||||||
|
TextButton(onClick = {
|
||||||
|
pendingScan = null
|
||||||
|
launchScan(lib, mode)
|
||||||
|
}) { Text("Proceed") }
|
||||||
|
}
|
||||||
|
},
|
||||||
|
dismissButton = {
|
||||||
|
TextButton(onClick = { pendingScan = null }) { Text("Cancel") }
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun LibControlRow(
|
||||||
|
lib: LibInfo,
|
||||||
|
repo: TraferoRepo,
|
||||||
|
onScan: (LibInfo, String) -> Unit,
|
||||||
|
onResult: (String?) -> Unit
|
||||||
|
) {
|
||||||
|
val scope = rememberCoroutineScope()
|
||||||
|
Row(
|
||||||
|
Modifier.fillMaxWidth().padding(vertical = 1.dp),
|
||||||
|
verticalAlignment = Alignment.CenterVertically
|
||||||
|
) {
|
||||||
|
Text(lib.name, Modifier.weight(1f).padding(end = 6.dp), maxLines = 1,
|
||||||
|
overflow = TextOverflow.Ellipsis, style = MaterialTheme.typography.bodyMedium,
|
||||||
|
fontWeight = FontWeight.SemiBold)
|
||||||
|
Text("Watch", style = MaterialTheme.typography.labelSmall,
|
||||||
|
color = MaterialTheme.colorScheme.onSurfaceVariant)
|
||||||
|
Switch(
|
||||||
|
checked = lib.folderWatching,
|
||||||
|
onCheckedChange = { on ->
|
||||||
|
scope.launch {
|
||||||
|
runCatching { repo.toggleFolderWatch(lib.id, lib.folder, on) }
|
||||||
|
.onSuccess { onResult(null) }
|
||||||
|
.onFailure { onResult(TraferoRepo.describeError(it)) }
|
||||||
|
}
|
||||||
|
},
|
||||||
|
modifier = Modifier.scale(0.7f)
|
||||||
|
)
|
||||||
|
TextButton(onClick = { onScan(lib, "scanFindNew") }) {
|
||||||
|
Text("Scan new", style = MaterialTheme.typography.labelMedium)
|
||||||
|
}
|
||||||
|
TextButton(onClick = { onScan(lib, "scanFresh") }) {
|
||||||
|
Text("Full scan", style = MaterialTheme.typography.labelMedium)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package com.trafero.app.ui.screens.settings
|
package com.trafero.app.ui.screens.settings
|
||||||
|
|
||||||
import androidx.compose.foundation.clickable
|
import androidx.compose.foundation.clickable
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
|
||||||
import androidx.compose.foundation.layout.Column
|
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
|
||||||
@@ -28,9 +27,7 @@ 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.text.font.FontWeight
|
import androidx.compose.ui.text.font.FontWeight
|
||||||
import androidx.compose.ui.text.style.TextOverflow
|
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import com.trafero.app.data.model.LibInfo
|
|
||||||
import com.trafero.app.data.model.ServerProfile
|
import com.trafero.app.data.model.ServerProfile
|
||||||
import com.trafero.app.data.repo.TraferoRepo
|
import com.trafero.app.data.repo.TraferoRepo
|
||||||
import com.trafero.app.di.AppContainer
|
import com.trafero.app.di.AppContainer
|
||||||
@@ -51,7 +48,6 @@ fun SettingsScreen(container: AppContainer) {
|
|||||||
val book by container.serverStore.book.collectAsState(initial = com.trafero.app.data.store.ServerBook())
|
val book by container.serverStore.book.collectAsState(initial = com.trafero.app.data.store.ServerBook())
|
||||||
var error by remember { mutableStateOf<String?>(null) }
|
var error by remember { mutableStateOf<String?>(null) }
|
||||||
var settings by remember { mutableStateOf<com.trafero.app.data.model.GlobalSettings?>(null) }
|
var settings by remember { mutableStateOf<com.trafero.app.data.model.GlobalSettings?>(null) }
|
||||||
var libs by remember { mutableStateOf<List<LibInfo>>(emptyList()) }
|
|
||||||
var editing by remember { mutableStateOf<ServerProfile?>(null) }
|
var editing by remember { mutableStateOf<ServerProfile?>(null) }
|
||||||
var addingNew by remember { mutableStateOf(false) }
|
var addingNew by remember { mutableStateOf(false) }
|
||||||
var confirmDelete by remember { mutableStateOf<ServerProfile?>(null) }
|
var confirmDelete by remember { mutableStateOf<ServerProfile?>(null) }
|
||||||
@@ -59,8 +55,8 @@ fun SettingsScreen(container: AppContainer) {
|
|||||||
val poll = rememberPollState()
|
val poll = rememberPollState()
|
||||||
pollLoop(ctx.refreshMs, listOf<Any?>("settings"), poll) {
|
pollLoop(ctx.refreshMs, listOf<Any?>("settings"), poll) {
|
||||||
if (repo != null) {
|
if (repo != null) {
|
||||||
runCatching { repo.globalSettings() to repo.libraries() }
|
runCatching { repo.globalSettings() }
|
||||||
.onSuccess { (g, l) -> settings = g; libs = l; error = null; poll.success() }
|
.onSuccess { g -> settings = g; error = null; poll.success() }
|
||||||
.onFailure { poll.failure(it, hasData = settings != null)?.let { msg -> error = msg } }
|
.onFailure { poll.failure(it, hasData = settings != null)?.let { msg -> error = msg } }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -91,14 +87,6 @@ fun SettingsScreen(container: AppContainer) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (libs.isNotEmpty()) {
|
|
||||||
SectionCard("Libraries") {
|
|
||||||
libs.forEach { lib ->
|
|
||||||
LibRow(lib, repo) { msg -> if (msg != null) error = msg }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
SectionCard("Servers") {
|
SectionCard("Servers") {
|
||||||
book.profiles.forEach { p ->
|
book.profiles.forEach { p ->
|
||||||
Card(Modifier.fillMaxWidth().padding(vertical = 4.dp)) {
|
Card(Modifier.fillMaxWidth().padding(vertical = 4.dp)) {
|
||||||
@@ -153,40 +141,3 @@ private fun ToggleRow(label: String, checked: Boolean, onChange: (Boolean) -> Un
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
|
||||||
private fun LibRow(lib: LibInfo, repo: TraferoRepo?, onResult: (String?) -> Unit) {
|
|
||||||
val scope = rememberCoroutineScope()
|
|
||||||
Column(Modifier.fillMaxWidth().padding(vertical = 8.dp)) {
|
|
||||||
Row(verticalAlignment = Alignment.CenterVertically) {
|
|
||||||
Column(Modifier.weight(1f)) {
|
|
||||||
Text(lib.name, fontWeight = FontWeight.SemiBold)
|
|
||||||
Text(lib.folder, maxLines = 1, overflow = TextOverflow.Ellipsis,
|
|
||||||
style = MaterialTheme.typography.bodySmall,
|
|
||||||
color = MaterialTheme.colorScheme.onSurfaceVariant)
|
|
||||||
}
|
|
||||||
Column(horizontalAlignment = Alignment.CenterHorizontally) {
|
|
||||||
Text("Watch", style = MaterialTheme.typography.labelSmall)
|
|
||||||
Switch(checked = lib.folderWatching, onCheckedChange = { on ->
|
|
||||||
scope.launch {
|
|
||||||
runCatching { repo?.toggleFolderWatch(lib.id, lib.folder, on) }
|
|
||||||
.onFailure { onResult(TraferoRepo.describeError(it)) }
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
|
|
||||||
OutlinedButton(onClick = {
|
|
||||||
scope.launch {
|
|
||||||
runCatching { repo?.scanLibrary(lib.id, lib.folder, "scanFindNew") }
|
|
||||||
.onFailure { onResult(TraferoRepo.describeError(it)) }
|
|
||||||
}
|
|
||||||
}) { Text("Scan new") }
|
|
||||||
OutlinedButton(onClick = {
|
|
||||||
scope.launch {
|
|
||||||
runCatching { repo?.scanLibrary(lib.id, lib.folder, "scanFresh") }
|
|
||||||
.onFailure { onResult(TraferoRepo.describeError(it)) }
|
|
||||||
}
|
|
||||||
}) { Text("Full scan") }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in new issue
Block a user