refactor: cleaning up
This commit is contained in:
parent
ccb083050b
commit
62ae292436
2 changed files with 34 additions and 17 deletions
|
@ -7,9 +7,10 @@ import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.material.Tab
|
import androidx.compose.material.Tab
|
||||||
import androidx.compose.material.TabRow
|
import androidx.compose.material.TabRow
|
||||||
import androidx.compose.material.Text
|
import androidx.compose.material.Text
|
||||||
import androidx.compose.runtime.*
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.graphics.Color
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.compose.ui.window.WindowState
|
import androidx.compose.ui.window.WindowState
|
||||||
import xyz.atnrch.wrench.components.filemanager.center.empty.DefaultDisplay
|
import xyz.atnrch.wrench.components.filemanager.center.empty.DefaultDisplay
|
||||||
|
@ -25,30 +26,33 @@ fun WatcherDisplay(
|
||||||
watcherManager: WatcherManager,
|
watcherManager: WatcherManager,
|
||||||
currentClick: Int,
|
currentClick: Int,
|
||||||
outputs: MutableList<Path>,
|
outputs: MutableList<Path>,
|
||||||
onEntryClick: (id: Int) -> Unit
|
onEntryClick: (id: Int) -> Unit,
|
||||||
|
tabIndex: Int,
|
||||||
|
tabTitles: List<String>,
|
||||||
|
onTabChange: (id: Int) -> Unit
|
||||||
) {
|
) {
|
||||||
var tabIndex by remember { mutableStateOf(0) } // 1.
|
|
||||||
val tabTitles = listOf("File Manager", "Servers")
|
Column {
|
||||||
Column { // 2.
|
|
||||||
TabRow(
|
TabRow(
|
||||||
selectedTabIndex = tabIndex,
|
selectedTabIndex = tabIndex,
|
||||||
backgroundColor = UIColors.ORANGE
|
backgroundColor = UIColors.ORANGE,
|
||||||
|
contentColor = Color.White
|
||||||
) { // 3.
|
) { // 3.
|
||||||
tabTitles.forEachIndexed { index, title ->
|
tabTitles.forEachIndexed { index, title ->
|
||||||
Tab(selected = tabIndex == index, // 4.
|
Tab(selected = tabIndex == index,
|
||||||
onClick = { tabIndex = index },
|
onClick = { onTabChange(index) },
|
||||||
text = { Text(text = title) }) // 5.
|
text = { Text(text = title) })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
when (tabIndex) { // 6.
|
when (tabIndex) {
|
||||||
0 -> getDisplayDependingOnSize(state, watcherManager, currentClick, outputs, onEntryClick)
|
0 -> FileManagerDisplay(state, watcherManager, currentClick, outputs, onEntryClick)
|
||||||
1 -> Text("There content")
|
1 -> TODO("Add Server Manager")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun getDisplayDependingOnSize(
|
fun FileManagerDisplay(
|
||||||
state: WindowState,
|
state: WindowState,
|
||||||
watcherManager: WatcherManager,
|
watcherManager: WatcherManager,
|
||||||
currentClick: Int,
|
currentClick: Int,
|
||||||
|
@ -61,7 +65,7 @@ fun getDisplayDependingOnSize(
|
||||||
verticalArrangement = Arrangement.Top,
|
verticalArrangement = Arrangement.Top,
|
||||||
horizontalAlignment = Alignment.CenterHorizontally
|
horizontalAlignment = Alignment.CenterHorizontally
|
||||||
) {
|
) {
|
||||||
displayEntries(true, watcherManager, currentClick, outputs, onEntryClick)
|
DisplayEntries(true, watcherManager, currentClick, outputs, onEntryClick)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Row(
|
Row(
|
||||||
|
@ -69,13 +73,13 @@ fun getDisplayDependingOnSize(
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
horizontalArrangement = Arrangement.Center
|
horizontalArrangement = Arrangement.Center
|
||||||
) {
|
) {
|
||||||
displayEntries(false, watcherManager, currentClick, outputs, onEntryClick)
|
DisplayEntries(false, watcherManager, currentClick, outputs, onEntryClick)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun displayEntries(
|
fun DisplayEntries(
|
||||||
minmode: Boolean,
|
minmode: Boolean,
|
||||||
watcherManager: WatcherManager,
|
watcherManager: WatcherManager,
|
||||||
currentClick: Int,
|
currentClick: Int,
|
||||||
|
|
|
@ -17,6 +17,7 @@ import java.nio.file.Path
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun WrenchScaffold(state: WindowState) {
|
fun WrenchScaffold(state: WindowState) {
|
||||||
|
// i love god objects
|
||||||
val scaffoldState: ScaffoldState = rememberScaffoldState()
|
val scaffoldState: ScaffoldState = rememberScaffoldState()
|
||||||
val entries: MutableMap<Int, WatcherEntry> = remember { mutableStateMapOf() }
|
val entries: MutableMap<Int, WatcherEntry> = remember { mutableStateMapOf() }
|
||||||
val outputs: MutableList<Path> = remember { mutableStateListOf() }
|
val outputs: MutableList<Path> = remember { mutableStateListOf() }
|
||||||
|
@ -24,6 +25,8 @@ fun WrenchScaffold(state: WindowState) {
|
||||||
val watcherManager = remember { WatcherManager(entries) }
|
val watcherManager = remember { WatcherManager(entries) }
|
||||||
val watcher = remember { Watcher(watcherManager, snackBarDataHolder) }
|
val watcher = remember { Watcher(watcherManager, snackBarDataHolder) }
|
||||||
var currentClick by remember { mutableStateOf(-1) }
|
var currentClick by remember { mutableStateOf(-1) }
|
||||||
|
var tabIndex by remember { mutableStateOf(0) }
|
||||||
|
val tabTitles = listOf("File Manager", "Servers")
|
||||||
|
|
||||||
Scaffold(
|
Scaffold(
|
||||||
scaffoldState = scaffoldState,
|
scaffoldState = scaffoldState,
|
||||||
|
@ -32,5 +35,15 @@ fun WrenchScaffold(state: WindowState) {
|
||||||
isFloatingActionButtonDocked = true,
|
isFloatingActionButtonDocked = true,
|
||||||
backgroundColor = UIColors.PRIMARY,
|
backgroundColor = UIColors.PRIMARY,
|
||||||
bottomBar = { BottomAppBar(state, watcherManager, watcher, currentClick, outputs) { currentClick = it } }
|
bottomBar = { BottomAppBar(state, watcherManager, watcher, currentClick, outputs) { currentClick = it } }
|
||||||
) { WatcherDisplay(state, watcherManager, currentClick, outputs) { currentClick = it } }
|
) {
|
||||||
|
WatcherDisplay(
|
||||||
|
state,
|
||||||
|
watcherManager,
|
||||||
|
currentClick,
|
||||||
|
outputs,
|
||||||
|
{ currentClick = it },
|
||||||
|
tabIndex,
|
||||||
|
tabTitles
|
||||||
|
) { tabIndex = it }
|
||||||
|
}
|
||||||
}
|
}
|
Reference in a new issue