feat: non-working implementation of layout saving
This commit is contained in:
parent
00a2f3946e
commit
a42eb486e4
5 changed files with 56 additions and 6 deletions
0
layout.json
Normal file
0
layout.json
Normal file
|
@ -7,10 +7,11 @@ import androidx.compose.material.rememberScaffoldState
|
|||
import androidx.compose.runtime.*
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.window.WindowState
|
||||
import xyz.atnrch.wrench.data.SnackBarDataHolder
|
||||
import xyz.atnrch.wrench.gui.filemanager.bottom.FloatingButton
|
||||
import xyz.atnrch.wrench.gui.filemanager.top.TopBar
|
||||
import xyz.atnrch.wrench.data.SnackBarDataHolder
|
||||
import xyz.atnrch.wrench.gui.style.UIColors
|
||||
import xyz.atnrch.wrench.json.JsonConfig
|
||||
import xyz.atnrch.wrench.watcher.Watcher
|
||||
import xyz.atnrch.wrench.watcher.WatcherEntry
|
||||
import xyz.atnrch.wrench.watcher.WatcherManager
|
||||
|
@ -26,6 +27,11 @@ fun WrenchScaffold(state: WindowState) {
|
|||
val watcherManager = remember { WatcherManager(entries) }
|
||||
val watcher = remember { Watcher(watcherManager, snackBarDataHolder) }
|
||||
val tabTitles = listOf("File Manager", "Servers")
|
||||
val jsonConfig = JsonConfig {
|
||||
it.forEach { entry ->
|
||||
watcherManager.addFile(entry.file, entry.outputs)
|
||||
}
|
||||
}
|
||||
|
||||
var currentClick by remember { mutableStateOf(-1) }
|
||||
var tabIndex by remember { mutableStateOf(0) }
|
||||
|
@ -37,7 +43,7 @@ fun WrenchScaffold(state: WindowState) {
|
|||
} else {
|
||||
Scaffold(
|
||||
scaffoldState = scaffoldState,
|
||||
topBar = { TopBar() },
|
||||
topBar = { TopBar(jsonConfig, tabIndex, entries.values) },
|
||||
floatingActionButton = { if (tabIndex == 0) FloatingButton(watcherManager) },
|
||||
isFloatingActionButtonDocked = true,
|
||||
backgroundColor = UIColors.PRIMARY,
|
||||
|
|
|
@ -14,9 +14,15 @@ import androidx.compose.ui.graphics.Color
|
|||
import androidx.compose.ui.unit.dp
|
||||
import xyz.atnrch.wrench.gui.style.Fonts
|
||||
import xyz.atnrch.wrench.gui.style.UIColors
|
||||
import xyz.atnrch.wrench.json.JsonConfig
|
||||
import xyz.atnrch.wrench.watcher.WatcherEntry
|
||||
|
||||
@Composable
|
||||
fun TopBar() {
|
||||
fun TopBar(
|
||||
jsonConfig: JsonConfig,
|
||||
tabIndex: Int,
|
||||
values: MutableCollection<WatcherEntry>
|
||||
) {
|
||||
TopAppBar(
|
||||
backgroundColor = UIColors.DARK,
|
||||
contentColor = Color.White,
|
||||
|
@ -33,6 +39,11 @@ fun TopBar() {
|
|||
text = "Wrench",
|
||||
fontFamily = Fonts.JOST_MEDIUM
|
||||
)
|
||||
},
|
||||
actions = {
|
||||
if (tabIndex == 0) {
|
||||
TopBarButtons(jsonConfig, values)
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
package xyz.atnrch.wrench.gui.filemanager.top
|
||||
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.material.Button
|
||||
import androidx.compose.material.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.unit.dp
|
||||
import xyz.atnrch.wrench.json.JsonConfig
|
||||
import xyz.atnrch.wrench.watcher.WatcherEntry
|
||||
|
||||
@Composable
|
||||
fun TopBarButtons(
|
||||
jsonConfig: JsonConfig,
|
||||
values: MutableCollection<WatcherEntry>
|
||||
) {
|
||||
Button(onClick = {
|
||||
jsonConfig.writeLayout(values.toList())
|
||||
}) {
|
||||
Text("Save")
|
||||
}
|
||||
Spacer(Modifier.width(10.dp))
|
||||
Button(onClick = {
|
||||
jsonConfig.readLayout()
|
||||
}) {
|
||||
Text("Load")
|
||||
}
|
||||
Spacer(Modifier.width(10.dp))
|
||||
}
|
|
@ -7,7 +7,9 @@ import java.io.File
|
|||
import java.io.FileReader
|
||||
import java.io.FileWriter
|
||||
|
||||
class JsonConfig {
|
||||
class JsonConfig(
|
||||
private val onWatcherEntriesUpdate: (List<WatcherEntry>) -> Unit
|
||||
) {
|
||||
private val gson: Gson = Gson().newBuilder().serializeNulls().setPrettyPrinting().create()
|
||||
private val file = File("layout.json")
|
||||
private val watcherEntryType = object : TypeToken<List<WatcherEntry>>() {}.type
|
||||
|
@ -17,6 +19,7 @@ class JsonConfig {
|
|||
}
|
||||
|
||||
fun readLayout() {
|
||||
gson.fromJson<List<WatcherEntry>>(FileReader(file), watcherEntryType)
|
||||
val entries = gson.fromJson<List<WatcherEntry>>(FileReader(file), watcherEntryType)
|
||||
onWatcherEntriesUpdate.invoke(entries)
|
||||
}
|
||||
}
|
Reference in a new issue