feat: display files added to Watcher
This commit is contained in:
parent
d291b07510
commit
69187207f6
6 changed files with 55 additions and 56 deletions
|
@ -11,9 +11,12 @@ import androidx.compose.ui.graphics.Color
|
|||
import androidx.compose.ui.unit.dp
|
||||
import xyz.atnrch.wrench.colors.WrenchColors
|
||||
import xyz.atnrch.wrench.logger.Logger
|
||||
import xyz.atnrch.wrench.watcher.WatcherManager
|
||||
|
||||
@Composable
|
||||
fun AddButton() {
|
||||
fun AddButton(
|
||||
watcherManager: WatcherManager
|
||||
) {
|
||||
//.............
|
||||
// ADD BUTTON (FLOATING)
|
||||
//.............
|
||||
|
@ -21,6 +24,7 @@ fun AddButton() {
|
|||
{
|
||||
createFileChooser({
|
||||
Logger.info("Path: ${it.absolutePath}")
|
||||
watcherManager.addFile(it)
|
||||
}, {
|
||||
Logger.info("No file selected.")
|
||||
})
|
||||
|
|
|
@ -6,21 +6,56 @@ import androidx.compose.foundation.layout.fillMaxSize
|
|||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.material.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.text.TextStyle
|
||||
import androidx.compose.ui.unit.ExperimentalUnitApi
|
||||
import androidx.compose.ui.unit.TextUnit
|
||||
import androidx.compose.ui.unit.TextUnitType
|
||||
import androidx.compose.ui.unit.dp
|
||||
import xyz.atnrch.wrench.watcher.WatcherManager
|
||||
|
||||
@OptIn(ExperimentalUnitApi::class)
|
||||
@Composable
|
||||
fun WrenchFileManagerInput() {
|
||||
fun WatcherDisplay(
|
||||
watcherManager: WatcherManager
|
||||
) {
|
||||
var selectedFile = remember { mutableStateOf("") }
|
||||
|
||||
Box(
|
||||
contentAlignment = Alignment.CenterStart,
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
) {
|
||||
Column(
|
||||
modifier = Modifier.padding(96.dp)
|
||||
modifier = Modifier.padding(84.dp)
|
||||
) {
|
||||
Text("Test")
|
||||
Text("Test2")
|
||||
//.............
|
||||
// INPUT SIDE
|
||||
//.............
|
||||
watcherManager.getEntries().forEach {
|
||||
Text(
|
||||
text = "${it.file.absolutePath}",
|
||||
style = TextStyle(
|
||||
color = Color.Black,
|
||||
fontSize = TextUnit(15F, TextUnitType.Sp)
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
Box(
|
||||
contentAlignment = Alignment.CenterEnd,
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
) {
|
||||
Column(
|
||||
modifier = Modifier.padding(84.dp)
|
||||
) {
|
||||
//.............
|
||||
// OUTPUT SIDE
|
||||
//.............
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,39 +0,0 @@
|
|||
package xyz.atnrch.wrench.components
|
||||
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.material.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.unit.dp
|
||||
|
||||
@Composable
|
||||
fun WrenchFileManagerOutput() {
|
||||
Box(
|
||||
contentAlignment = Alignment.CenterEnd,
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
) {
|
||||
Column(
|
||||
modifier = Modifier.padding(96.dp)
|
||||
) {
|
||||
val backgroundColor = remember { mutableStateOf(Color.Black) }
|
||||
|
||||
Text(
|
||||
text = "Test",
|
||||
color = backgroundColor.value,
|
||||
modifier = Modifier.clickable {
|
||||
println("Click!")
|
||||
backgroundColor.value = Color.Red
|
||||
}
|
||||
)
|
||||
Text("Test2")
|
||||
}
|
||||
}
|
||||
}
|
|
@ -3,20 +3,21 @@ package xyz.atnrch.wrench.components
|
|||
import androidx.compose.material.Scaffold
|
||||
import androidx.compose.runtime.*
|
||||
import xyz.atnrch.wrench.watcher.Watcher
|
||||
import xyz.atnrch.wrench.watcher.WatcherEntry
|
||||
import xyz.atnrch.wrench.watcher.WatcherManager
|
||||
|
||||
@Composable
|
||||
fun WrenchScaffold() {
|
||||
val watcher = remember { Watcher() }
|
||||
val entries: MutableList<WatcherEntry> = remember { mutableStateListOf() }
|
||||
val watcher = remember { Watcher(entries) }
|
||||
val watcherManager = remember { WatcherManager(entries) }
|
||||
var buttonState by remember { mutableStateOf(false) }
|
||||
|
||||
Scaffold(
|
||||
topBar = { TopBar() },
|
||||
floatingActionButton = { AddButton() },
|
||||
floatingActionButton = { AddButton(watcherManager) },
|
||||
isFloatingActionButtonDocked = true,
|
||||
bottomBar = { BottomAppBar(watcher, buttonState) { buttonState = it } }
|
||||
) {
|
||||
WrenchFileManagerInput()
|
||||
WrenchFileManagerOutput()
|
||||
}
|
||||
) { WatcherDisplay(watcherManager) }
|
||||
|
||||
}
|
|
@ -6,7 +6,7 @@ import xyz.atnrch.wrench.logger.Logger
|
|||
import java.nio.file.Files
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
class Watcher {
|
||||
class Watcher(private val entries: MutableList<WatcherEntry>) {
|
||||
companion object {
|
||||
var WATCHING = false
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ class Watcher {
|
|||
Logger.info("Started Watcher.")
|
||||
while (WATCHING) {
|
||||
delay(TimeUnit.SECONDS.toMillis(5))
|
||||
val manager = WatcherManager()
|
||||
val manager = WatcherManager(entries)
|
||||
for (entry: WatcherEntry in manager.getEntries()) {
|
||||
entry.map.forEach {
|
||||
Files.copy(entry.file.toPath(), it.toAbsolutePath())
|
||||
|
|
|
@ -3,16 +3,14 @@ package xyz.atnrch.wrench.watcher
|
|||
import xyz.atnrch.wrench.logger.Logger
|
||||
import java.io.File
|
||||
|
||||
class WatcherManager {
|
||||
private val entries: ArrayList<WatcherEntry> = arrayListOf()
|
||||
|
||||
class WatcherManager(private val entries: MutableList<WatcherEntry>) {
|
||||
fun addFile(file: File) {
|
||||
val watcherEntry = WatcherEntry(file, arrayListOf())
|
||||
entries.add(watcherEntry)
|
||||
Logger.info("Tracking new file: ${file.name} (${file.absolutePath})")
|
||||
}
|
||||
|
||||
fun getEntries(): ArrayList<WatcherEntry> {
|
||||
fun getEntries(): MutableList<WatcherEntry> {
|
||||
return entries
|
||||
}
|
||||
}
|
Reference in a new issue