mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-18 12:28:40 +00:00
feat: show dot-prefixed folders in game picker
This commit is contained in:
1 parent
22eac0831d
commit
0127fa24aa
4 files changed
+34
-9
No files matched your search
@@ -274,7 +274,7 @@ object AddedGames {
|
||||
|
||||
class FolderResult(val added: List<Game>, val already: Int)
|
||||
|
||||
fun addFolder(context: Context, dir: File, onGame: (Game) -> Unit = {}, onChecking: (String?) -> Unit = {}): FolderResult {
|
||||
fun addFolder(context: Context, dir: File, onGame: (Game) -> Unit = {}, onChecking: (String?) -> Unit = {}, showHidden: Boolean = false): FolderResult {
|
||||
val app = context.applicationContext
|
||||
// Binds are mounted at session start, so a new one reaches the session from the next start.
|
||||
if (guestPath(app, dir) == null) bindFolder(app, dir)
|
||||
@@ -283,7 +283,7 @@ object AddedGames {
|
||||
var already = 0
|
||||
val fresh = ArrayList<String>()
|
||||
val added = ArrayList<Game>()
|
||||
for (sub in dir.listFiles { f -> f.isDirectory && !f.name.startsWith(".") }?.sortedBy { it.name.lowercase() }.orEmpty()) {
|
||||
for (sub in dir.listFiles { f -> f.isDirectory && (showHidden || !f.name.startsWith(".")) }?.sortedBy { it.name.lowercase() }.orEmpty()) {
|
||||
val path = canonical(sub)
|
||||
if (listed.any { it == path || inside(path, it) || inside(it, path) }) { already++; continue }
|
||||
onChecking(sub.name)
|
||||
|
||||
@@ -27,6 +27,8 @@ import androidx.compose.material.icons.outlined.Image
|
||||
import androidx.compose.material.icons.outlined.InsertDriveFile
|
||||
import androidx.compose.material.icons.outlined.SdCard
|
||||
import androidx.compose.material.icons.outlined.Smartphone
|
||||
import androidx.compose.material.icons.outlined.Visibility
|
||||
import androidx.compose.material.icons.outlined.VisibilityOff
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
@@ -81,8 +83,8 @@ internal class PickFolder(val dir: File, val readable: Boolean)
|
||||
|
||||
internal class PickListing(val folders: List<PickFolder>, val files: List<File>)
|
||||
|
||||
internal fun pickListing(dir: File, kind: PickKind): PickListing {
|
||||
val all = dir.listFiles()?.filter { !it.name.startsWith(".") }.orEmpty().sortedBy { it.name.lowercase() }
|
||||
internal fun pickListing(dir: File, kind: PickKind, showHidden: Boolean = false): PickListing {
|
||||
val all = dir.listFiles()?.filter { showHidden || !it.name.startsWith(".") }.orEmpty().sortedBy { it.name.lowercase() }
|
||||
return PickListing(
|
||||
all.filter { it.isDirectory }.map { PickFolder(it, it.canRead() && it.list() != null) },
|
||||
all.filter { it.isFile && it.extension.lowercase() in kind.extensions },
|
||||
@@ -92,11 +94,13 @@ internal fun pickListing(dir: File, kind: PickKind): PickListing {
|
||||
@Composable
|
||||
internal fun ExePickerDialog(
|
||||
title: String, kind: PickKind = PickKind.EXE, start: File? = null,
|
||||
onAddAll: ((File) -> Unit)? = null, onPick: (File) -> Unit, onDismiss: () -> Unit,
|
||||
onAddAll: ((File, Boolean) -> Unit)? = null, onPick: (File) -> Unit, onDismiss: () -> Unit,
|
||||
) {
|
||||
val ctx = LocalContext.current
|
||||
val colors = MaterialTheme.colorScheme
|
||||
val density = LocalDensity.current
|
||||
val prefs = remember(ctx) { ctx.getSharedPreferences("game_picker", Context.MODE_PRIVATE) }
|
||||
var showHidden by remember { mutableStateOf(prefs.getBoolean("show_hidden", false)) }
|
||||
val shown = rememberShown(onDismiss)
|
||||
val close = { shown.targetState = false }
|
||||
val volumes = remember { pickVolumes(ctx) }
|
||||
@@ -107,14 +111,23 @@ internal fun ExePickerDialog(
|
||||
val back = { if (dir == null) close() else up() }
|
||||
val first = remember(dir) { FocusRequester() }
|
||||
LaunchedEffect(dir) { focusWithinFrames({ false }) { first } }
|
||||
val listing = remember(dir) { dir?.let { pickListing(it, kind) } }
|
||||
val listing = remember(dir, showHidden) { dir?.let { pickListing(it, kind, showHidden) } }
|
||||
var locked by remember { mutableStateOf<Dp?>(null) }
|
||||
AppDialog(
|
||||
shown, close, "filePicker", wide = false, maxWidth = 520.dp, width = locked, fitContent = locked == null, back = back,
|
||||
modifier = Modifier.onSizeChanged { if (locked == null && it.width > 0) locked = with(density) { it.width.toDp() } },
|
||||
) {
|
||||
Column(verticalArrangement = Arrangement.spacedBy(6.dp), modifier = Modifier.fillMaxWidth()) {
|
||||
DialogTitleRow(title, onClose = close)
|
||||
DialogTitleRow(title, onClose = close, leading = {
|
||||
SmallIconButton(
|
||||
if (showHidden) Icons.Outlined.VisibilityOff else Icons.Outlined.Visibility,
|
||||
stringResource(if (showHidden) R.string.fm_hide_hidden else R.string.fm_show_hidden),
|
||||
if (showHidden) colors.primary else colors.onSurfaceVariant,
|
||||
) {
|
||||
showHidden = !showHidden
|
||||
prefs.edit().putBoolean("show_hidden", showHidden).apply()
|
||||
}
|
||||
})
|
||||
if (dir != null && volume != null) {
|
||||
val crumbs = listOf(volume.label) + dir!!.path.removePrefix(volume.root.path).split('/').filter { it.isNotEmpty() }
|
||||
Text(crumbs.joinToString(" › "), fontSize = 12.sp, color = colors.onSurfaceVariant, maxLines = 1, overflow = TextOverflow.Ellipsis)
|
||||
@@ -135,7 +148,7 @@ internal fun ExePickerDialog(
|
||||
val shownListing = listing ?: PickListing(emptyList(), emptyList())
|
||||
PickerRow(Icons.AutoMirrored.Outlined.ArrowBack, "..", null, focus = first, onClick = up)
|
||||
if (onAddAll != null && shownListing.folders.any { it.readable }) {
|
||||
PickerRow(Icons.Filled.Add, stringResource(R.string.games_add_all), null, accent = true) { onAddAll(dir!!); close() }
|
||||
PickerRow(Icons.Filled.Add, stringResource(R.string.games_add_all), null, accent = true) { onAddAll(dir!!, showHidden); close() }
|
||||
}
|
||||
for (f in shownListing.folders) key(f.dir.path) {
|
||||
PickerRow(Icons.Outlined.Folder, f.dir.name, null, enabled = f.readable) { dir = f.dir }
|
||||
|
||||
@@ -424,7 +424,7 @@ private fun GamesDialogs(a: FrontEndActions, games: List<Library.SteamGame>) {
|
||||
val st = GamesDialogState
|
||||
if (st.adding) ExePickerDialog(
|
||||
stringResource(R.string.games_add_title),
|
||||
onAddAll = { dir ->
|
||||
onAddAll = { dir, showHidden ->
|
||||
st.summary = emptyList<com.droiddeck.launcher.frontend.AddedGames.Game>() to 0
|
||||
st.checking = dir.name
|
||||
scope.launch {
|
||||
@@ -433,6 +433,7 @@ private fun GamesDialogs(a: FrontEndActions, games: List<Library.SteamGame>) {
|
||||
ctx.applicationContext, dir,
|
||||
onGame = { g -> scope.launch { st.summary?.let { (list, n) -> st.summary = (list + g) to n } } },
|
||||
onChecking = { name -> scope.launch { st.checking = name } },
|
||||
showHidden = showHidden,
|
||||
)
|
||||
}
|
||||
st.checking = null
|
||||
|
||||
Reference in new issue
Block a user