Added settings page for sync ip/port and future settings
parent
ef1353e82b
commit
6e4aa55266
|
|
@ -14,13 +14,15 @@ import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.runtime.setValue
|
import androidx.compose.runtime.setValue
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
import xyz.pixelatedw.recipe.MainActivity
|
import xyz.pixelatedw.recipe.MainActivity
|
||||||
import xyz.pixelatedw.recipe.utils.sync
|
import xyz.pixelatedw.recipe.utils.sync
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun ImportDropdownMenu(ctx: MainActivity) {
|
fun ImportDropdownMenu(ctx: MainActivity, modifier: Modifier) {
|
||||||
var expanded by remember { mutableStateOf(false) }
|
var expanded by remember { mutableStateOf(false) }
|
||||||
Box(
|
Box(
|
||||||
|
modifier = modifier,
|
||||||
) {
|
) {
|
||||||
IconButton(
|
IconButton(
|
||||||
onClick = { expanded = !expanded }
|
onClick = { expanded = !expanded }
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
package xyz.pixelatedw.recipe.ui.components
|
package xyz.pixelatedw.recipe.ui.components
|
||||||
|
|
||||||
import android.content.Intent
|
import android.content.Context
|
||||||
import androidx.compose.foundation.background
|
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.foundation.layout.PaddingValues
|
import androidx.compose.foundation.layout.PaddingValues
|
||||||
|
|
@ -10,15 +9,19 @@ import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
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.text.KeyboardOptions
|
||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
import androidx.compose.material.icons.filled.Add
|
|
||||||
import androidx.compose.material.icons.filled.Delete
|
import androidx.compose.material.icons.filled.Delete
|
||||||
|
import androidx.compose.material.icons.filled.Settings
|
||||||
|
import androidx.compose.material3.Button
|
||||||
import androidx.compose.material3.Icon
|
import androidx.compose.material3.Icon
|
||||||
import androidx.compose.material3.IconButton
|
import androidx.compose.material3.IconButton
|
||||||
import androidx.compose.material3.OutlinedTextField
|
import androidx.compose.material3.OutlinedTextField
|
||||||
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.collectAsState
|
import androidx.compose.runtime.collectAsState
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.runtime.mutableIntStateOf
|
||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.runtime.setValue
|
import androidx.compose.runtime.setValue
|
||||||
|
|
@ -27,6 +30,7 @@ import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
import androidx.compose.ui.graphics.vector.ImageVector
|
import androidx.compose.ui.graphics.vector.ImageVector
|
||||||
import androidx.compose.ui.res.vectorResource
|
import androidx.compose.ui.res.vectorResource
|
||||||
|
import androidx.compose.ui.text.input.KeyboardType
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.navigation.compose.NavHost
|
import androidx.navigation.compose.NavHost
|
||||||
import androidx.navigation.compose.composable
|
import androidx.navigation.compose.composable
|
||||||
|
|
@ -35,9 +39,11 @@ import xyz.pixelatedw.recipe.MainActivity
|
||||||
import xyz.pixelatedw.recipe.R
|
import xyz.pixelatedw.recipe.R
|
||||||
import xyz.pixelatedw.recipe.data.RecipeWithTags
|
import xyz.pixelatedw.recipe.data.RecipeWithTags
|
||||||
import xyz.pixelatedw.recipe.data.RecipesView
|
import xyz.pixelatedw.recipe.data.RecipesView
|
||||||
import xyz.pixelatedw.recipe.utils.sync
|
import xyz.pixelatedw.recipe.utils.DEFAULT_SYNC_SERVER_IP
|
||||||
|
import xyz.pixelatedw.recipe.utils.DEFAULT_SYNC_SERVER_PORT
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun MainScreen(ctx: MainActivity, padding: PaddingValues, view: RecipesView) {
|
fun MainScreen(ctx: MainActivity, padding: PaddingValues, view: RecipesView) {
|
||||||
val recipes = view.recipes.collectAsState()
|
val recipes = view.recipes.collectAsState()
|
||||||
|
|
@ -45,6 +51,11 @@ fun MainScreen(ctx: MainActivity, padding: PaddingValues, view: RecipesView) {
|
||||||
val search = view.search.collectAsState()
|
val search = view.search.collectAsState()
|
||||||
val filters = view.tagFilters.collectAsState()
|
val filters = view.tagFilters.collectAsState()
|
||||||
|
|
||||||
|
val prefs = ctx.getPreferences(Context.MODE_PRIVATE)
|
||||||
|
|
||||||
|
var syncIp by remember { mutableStateOf(prefs.getString("syncServerIp", DEFAULT_SYNC_SERVER_IP)!!) }
|
||||||
|
var syncPort by remember { mutableIntStateOf(prefs.getInt("syncServerPort", DEFAULT_SYNC_SERVER_PORT)) }
|
||||||
|
|
||||||
val navController = rememberNavController()
|
val navController = rememberNavController()
|
||||||
|
|
||||||
var openDeletionDialog by remember { mutableStateOf(false) }
|
var openDeletionDialog by remember { mutableStateOf(false) }
|
||||||
|
|
@ -101,13 +112,15 @@ fun MainScreen(ctx: MainActivity, padding: PaddingValues, view: RecipesView) {
|
||||||
horizontalArrangement = Arrangement.spacedBy(4.dp)
|
horizontalArrangement = Arrangement.spacedBy(4.dp)
|
||||||
) {
|
) {
|
||||||
OutlinedTextField(
|
OutlinedTextField(
|
||||||
modifier = Modifier.weight(0.7f),
|
modifier = Modifier
|
||||||
|
.weight(0.7f)
|
||||||
|
.padding(end = 4.dp),
|
||||||
value = search.value.orEmpty(),
|
value = search.value.orEmpty(),
|
||||||
onValueChange = { search -> view.setSearch(search) },
|
onValueChange = { search -> view.setSearch(search) },
|
||||||
)
|
)
|
||||||
// Tags
|
// Tags
|
||||||
IconButton(
|
IconButton(
|
||||||
modifier = Modifier.weight(0.15f),
|
modifier = Modifier.weight(0.1f),
|
||||||
onClick = { openTagFilterDialog = true },
|
onClick = { openTagFilterDialog = true },
|
||||||
) {
|
) {
|
||||||
Icon(
|
Icon(
|
||||||
|
|
@ -118,7 +131,7 @@ fun MainScreen(ctx: MainActivity, padding: PaddingValues, view: RecipesView) {
|
||||||
// Import / Delete
|
// Import / Delete
|
||||||
if (selectedEntries.isNotEmpty()) {
|
if (selectedEntries.isNotEmpty()) {
|
||||||
IconButton(
|
IconButton(
|
||||||
modifier = Modifier.weight(0.15f),
|
modifier = Modifier.weight(0.1f),
|
||||||
onClick = {
|
onClick = {
|
||||||
openDeletionDialog = true
|
openDeletionDialog = true
|
||||||
},
|
},
|
||||||
|
|
@ -130,7 +143,17 @@ fun MainScreen(ctx: MainActivity, padding: PaddingValues, view: RecipesView) {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ImportDropdownMenu(ctx)
|
ImportDropdownMenu(ctx, Modifier.weight(0.1f))
|
||||||
|
}
|
||||||
|
// Options
|
||||||
|
IconButton(
|
||||||
|
modifier = Modifier.weight(0.1f),
|
||||||
|
onClick = { navController.navigate("settings") },
|
||||||
|
) {
|
||||||
|
Icon(
|
||||||
|
imageVector = Icons.Default.Settings,
|
||||||
|
contentDescription = "Open settings menu"
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
LazyColumn {
|
LazyColumn {
|
||||||
|
|
@ -193,5 +216,43 @@ fun MainScreen(ctx: MainActivity, padding: PaddingValues, view: RecipesView) {
|
||||||
composable("info") {
|
composable("info") {
|
||||||
RecipeInfo(ctx, view, navController, padding, active.value!!)
|
RecipeInfo(ctx, view, navController, padding, active.value!!)
|
||||||
}
|
}
|
||||||
|
composable("settings") {
|
||||||
|
Column(modifier = Modifier.padding(start = 12.dp, top = 48.dp)) {
|
||||||
|
OutlinedTextField(
|
||||||
|
label = { Text("Sync Server IP") },
|
||||||
|
singleLine = true,
|
||||||
|
value = syncIp,
|
||||||
|
onValueChange = { syncIp = it },
|
||||||
|
)
|
||||||
|
|
||||||
|
OutlinedTextField(
|
||||||
|
modifier = Modifier.padding(top = 8.dp),
|
||||||
|
label = { Text("Sync Server IP") },
|
||||||
|
singleLine = true,
|
||||||
|
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Number),
|
||||||
|
value = syncPort.toString(),
|
||||||
|
onValueChange = {
|
||||||
|
syncPort = when (it.toIntOrNull()) {
|
||||||
|
null -> syncPort
|
||||||
|
else -> it.toInt()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
Button(
|
||||||
|
modifier = Modifier.padding(top = 8.dp),
|
||||||
|
onClick = {
|
||||||
|
with (prefs.edit()) {
|
||||||
|
putString("syncServerIp", syncIp)
|
||||||
|
putInt("syncServerPort", syncPort)
|
||||||
|
apply()
|
||||||
|
}
|
||||||
|
navController.navigate("list")
|
||||||
|
},
|
||||||
|
) {
|
||||||
|
Text("Save")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue