mirror of
https://github.com/rt-bishop/Look4Sat.git
synced 2026-10-02 03:15:37 +00:00
Added more functionality to SettingsScreen.kt
This commit is contained in:
1 parent
3da5b43e0a
commit
466c029be6
10 files changed
+198
-136
No files matched your search
@@ -50,7 +50,7 @@ class SettingsManager @Inject constructor(private val prefs: SharedPreferences)
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun loadStationLocator(): String {
|
override fun loadStationLocator(): String {
|
||||||
return prefs.getString(keyLocator, null) ?: "null"
|
return prefs.getString(keyLocator, null) ?: ""
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun saveStationLocator(locator: String) {
|
override fun saveStationLocator(locator: String) {
|
||||||
@@ -107,11 +107,11 @@ class SettingsManager @Inject constructor(private val prefs: SharedPreferences)
|
|||||||
prefs.edit { putDouble(keyMinElevation, minElevation) }
|
prefs.edit { putDouble(keyMinElevation, minElevation) }
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getUseUTC(): Boolean {
|
override fun isUtcEnabled(): Boolean {
|
||||||
return prefs.getBoolean(keyTimeUTC, false)
|
return prefs.getBoolean(keyTimeUTC, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun setUseUTC(value: Boolean) {
|
override fun setUtcState(value: Boolean) {
|
||||||
prefs.edit { putBoolean(keyTimeUTC, value) }
|
prefs.edit { putBoolean(keyTimeUTC, value) }
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -123,27 +123,27 @@ class SettingsManager @Inject constructor(private val prefs: SharedPreferences)
|
|||||||
prefs.edit { putLong(keyLastUpdateTime, updateTime) }
|
prefs.edit { putLong(keyLastUpdateTime, updateTime) }
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getAutoUpdateEnabled(): Boolean {
|
override fun isUpdateEnabled(): Boolean {
|
||||||
return prefs.getBoolean(keyAutoUpdateEnabled, true)
|
return prefs.getBoolean(keyAutoUpdateEnabled, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun setAutoUpdateEnabled(value: Boolean) {
|
override fun setUpdateState(value: Boolean) {
|
||||||
prefs.edit { putBoolean(keyAutoUpdateEnabled, value) }
|
prefs.edit { putBoolean(keyAutoUpdateEnabled, value) }
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getUseCompass(): Boolean {
|
override fun isSensorEnabled(): Boolean {
|
||||||
return prefs.getBoolean(keyCompass, true)
|
return prefs.getBoolean(keyCompass, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun setUseCompass(value: Boolean) {
|
override fun setSensorState(value: Boolean) {
|
||||||
prefs.edit { putBoolean(keyCompass, value) }
|
prefs.edit { putBoolean(keyCompass, value) }
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getShowSweep(): Boolean {
|
override fun isSweepEnabled(): Boolean {
|
||||||
return prefs.getBoolean(keyRadarSweep, true)
|
return prefs.getBoolean(keyRadarSweep, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun setShowSweep(value: Boolean) {
|
override fun setSweepState(value: Boolean) {
|
||||||
prefs.edit { putBoolean(keyRadarSweep, value) }
|
prefs.edit { putBoolean(keyRadarSweep, value) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ class MainApplication : Application() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun checkAutoUpdate() {
|
private fun checkAutoUpdate() {
|
||||||
if (settingsManager.getAutoUpdateEnabled()) {
|
if (settingsManager.isUpdateEnabled()) {
|
||||||
val timeDelta = System.currentTimeMillis() - settingsManager.getLastUpdateTime()
|
val timeDelta = System.currentTimeMillis() - settingsManager.getLastUpdateTime()
|
||||||
if (timeDelta > 172800000) { // 48 hours in ms
|
if (timeDelta > 172800000) { // 48 hours in ms
|
||||||
val sdf = SimpleDateFormat("d MMM yyyy - HH:mm:ss", Locale.getDefault())
|
val sdf = SimpleDateFormat("d MMM yyyy - HH:mm:ss", Locale.getDefault())
|
||||||
|
|||||||
+1
-1
@@ -90,7 +90,7 @@ class PassesViewModel @Inject constructor(
|
|||||||
calculatePasses()
|
calculatePasses()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun shouldUseUTC() = settings.getUseUTC()
|
fun shouldUseUTC() = settings.isUtcEnabled()
|
||||||
|
|
||||||
fun calculatePasses(
|
fun calculatePasses(
|
||||||
hoursAhead: Int = 1,
|
hoursAhead: Int = 1,
|
||||||
|
|||||||
@@ -95,16 +95,16 @@ class RadarViewModel @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun enableSensor() {
|
fun enableSensor() {
|
||||||
if (settings.getUseCompass()) orientationManager.startListening(this)
|
if (settings.isSensorEnabled()) orientationManager.startListening(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun disableSensor() {
|
fun disableSensor() {
|
||||||
if (settings.getUseCompass()) orientationManager.stopListening()
|
if (settings.isSensorEnabled()) orientationManager.stopListening()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getUseCompass(): Boolean = settings.getUseCompass()
|
fun getUseCompass(): Boolean = settings.isSensorEnabled()
|
||||||
|
|
||||||
fun getShowSweep(): Boolean = settings.getShowSweep()
|
fun getShowSweep(): Boolean = settings.isSweepEnabled()
|
||||||
|
|
||||||
override fun onOrientationChanged(azimuth: Float, pitch: Float, roll: Float) {
|
override fun onOrientationChanged(azimuth: Float, pitch: Float, roll: Float) {
|
||||||
_orientation.value = Triple(azimuth + getMagDeclination(stationPos), pitch, roll)
|
_orientation.value = Triple(azimuth + getMagDeclination(stationPos), pitch, roll)
|
||||||
|
|||||||
+11
-19
@@ -20,17 +20,14 @@ import com.rtbishop.look4sat.presentation.MainTheme
|
|||||||
@Preview(showBackground = true)
|
@Preview(showBackground = true)
|
||||||
@Composable
|
@Composable
|
||||||
private fun LocatorDialogPreview() {
|
private fun LocatorDialogPreview() {
|
||||||
MainTheme { LocatorDialog(8, 16.0, {}) { _, _ -> } }
|
MainTheme { LocatorDialog("IO91vl", {}) { } }
|
||||||
}
|
}
|
||||||
|
|
||||||
@OptIn(ExperimentalMaterial3Api::class)
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
@Composable
|
@Composable
|
||||||
fun LocatorDialog(
|
fun LocatorDialog(qthLocator: String, hide: () -> Unit, save: (String) -> Unit) {
|
||||||
hours: Int, elevation: Double, toggle: () -> Unit, save: (Int, Double) -> Unit
|
val locator = rememberSaveable { mutableStateOf(qthLocator) }
|
||||||
) {
|
Dialog(onDismissRequest = { hide() }) {
|
||||||
val hoursValue = rememberSaveable { mutableStateOf(hours) }
|
|
||||||
val elevValue = rememberSaveable { mutableStateOf(elevation) }
|
|
||||||
Dialog(onDismissRequest = { toggle() }) {
|
|
||||||
ElevatedCard {
|
ElevatedCard {
|
||||||
Column(
|
Column(
|
||||||
horizontalAlignment = Alignment.CenterHorizontally,
|
horizontalAlignment = Alignment.CenterHorizontally,
|
||||||
@@ -41,24 +38,19 @@ fun LocatorDialog(
|
|||||||
color = MaterialTheme.colorScheme.primary
|
color = MaterialTheme.colorScheme.primary
|
||||||
)
|
)
|
||||||
Text(text = stringResource(id = R.string.locator_text))
|
Text(text = stringResource(id = R.string.locator_text))
|
||||||
OutlinedTextField(value = hoursValue.value.toString(), onValueChange = { newValue ->
|
OutlinedTextField(value = locator.value, onValueChange = { locator.value = it })
|
||||||
val hoursAhead = try {
|
|
||||||
newValue.toInt()
|
|
||||||
} catch (exception: Exception) {
|
|
||||||
12
|
|
||||||
}
|
|
||||||
hoursValue.value = hoursAhead
|
|
||||||
})
|
|
||||||
Row(
|
Row(
|
||||||
horizontalArrangement = Arrangement.SpaceBetween,
|
horizontalArrangement = Arrangement.SpaceBetween,
|
||||||
modifier = Modifier.fillMaxWidth()
|
modifier = Modifier.fillMaxWidth()
|
||||||
) {
|
) {
|
||||||
CardButton(onClick = { toggle() }, text = "Cancel")
|
CardButton(
|
||||||
|
onClick = { hide() }, text = stringResource(id = R.string.btn_cancel)
|
||||||
|
)
|
||||||
CardButton(
|
CardButton(
|
||||||
onClick = {
|
onClick = {
|
||||||
save(hoursValue.value, elevValue.value)
|
save(locator.value)
|
||||||
toggle()
|
hide()
|
||||||
}, text = "Accept"
|
}, text = stringResource(id = R.string.btn_accept)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+21
-28
@@ -20,17 +20,15 @@ import com.rtbishop.look4sat.presentation.MainTheme
|
|||||||
@Preview(showBackground = true)
|
@Preview(showBackground = true)
|
||||||
@Composable
|
@Composable
|
||||||
private fun PositionDialogPreview() {
|
private fun PositionDialogPreview() {
|
||||||
MainTheme { PositionDialog(8, 16.0, {}) { _, _ -> } }
|
MainTheme { PositionDialog(0.0, 0.0, {}) { _, _ -> } }
|
||||||
}
|
}
|
||||||
|
|
||||||
@OptIn(ExperimentalMaterial3Api::class)
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
@Composable
|
@Composable
|
||||||
fun PositionDialog(
|
fun PositionDialog(lat: Double, lon: Double, hide: () -> Unit, save: (Double, Double) -> Unit) {
|
||||||
hours: Int, elevation: Double, toggle: () -> Unit, save: (Int, Double) -> Unit
|
val latValue = rememberSaveable { mutableStateOf(lat.toString()) }
|
||||||
) {
|
val lonValue = rememberSaveable { mutableStateOf(lon.toString()) }
|
||||||
val hoursValue = rememberSaveable { mutableStateOf(hours) }
|
Dialog(onDismissRequest = { hide() }) {
|
||||||
val elevValue = rememberSaveable { mutableStateOf(elevation) }
|
|
||||||
Dialog(onDismissRequest = { toggle() }) {
|
|
||||||
ElevatedCard {
|
ElevatedCard {
|
||||||
Column(
|
Column(
|
||||||
horizontalAlignment = Alignment.CenterHorizontally,
|
horizontalAlignment = Alignment.CenterHorizontally,
|
||||||
@@ -41,36 +39,31 @@ fun PositionDialog(
|
|||||||
color = MaterialTheme.colorScheme.primary
|
color = MaterialTheme.colorScheme.primary
|
||||||
)
|
)
|
||||||
Text(text = stringResource(id = R.string.position_lat_text))
|
Text(text = stringResource(id = R.string.position_lat_text))
|
||||||
OutlinedTextField(value = hoursValue.value.toString(), onValueChange = { newValue ->
|
OutlinedTextField(value = latValue.value, onValueChange = { latValue.value = it })
|
||||||
val hoursAhead = try {
|
|
||||||
newValue.toInt()
|
|
||||||
} catch (exception: Exception) {
|
|
||||||
12
|
|
||||||
}
|
|
||||||
hoursValue.value = hoursAhead
|
|
||||||
})
|
|
||||||
Text(text = stringResource(id = R.string.position_lon_text))
|
Text(text = stringResource(id = R.string.position_lon_text))
|
||||||
OutlinedTextField(value = elevValue.value.toString(), onValueChange = { newValue ->
|
OutlinedTextField(value = lonValue.value, onValueChange = { lonValue.value = it })
|
||||||
val maxElevation = try {
|
|
||||||
newValue.toDouble()
|
|
||||||
} catch (exception: Exception) {
|
|
||||||
16.0
|
|
||||||
}
|
|
||||||
elevValue.value = maxElevation
|
|
||||||
})
|
|
||||||
Row(
|
Row(
|
||||||
horizontalArrangement = Arrangement.SpaceBetween,
|
horizontalArrangement = Arrangement.SpaceBetween,
|
||||||
modifier = Modifier.fillMaxWidth()
|
modifier = Modifier.fillMaxWidth()
|
||||||
) {
|
) {
|
||||||
CardButton(onClick = { toggle() }, text = "Cancel")
|
|
||||||
CardButton(
|
CardButton(
|
||||||
onClick = {
|
onClick = { hide() }, text = stringResource(id = R.string.btn_cancel)
|
||||||
save(hoursValue.value, elevValue.value)
|
)
|
||||||
toggle()
|
CardButton(
|
||||||
}, text = "Accept"
|
onClick = { saveValues(latValue.value, lonValue.value, hide, save) },
|
||||||
|
text = stringResource(id = R.string.btn_accept)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun saveValues(lat: String, lon: String, hide: () -> Unit, save: (Double, Double) -> Unit) {
|
||||||
|
val latValue = lat.toDoubleOrNull() ?: 0.0
|
||||||
|
val lonValue = lon.toDoubleOrNull() ?: 0.0
|
||||||
|
val newLat = if (latValue > 90) 90.0 else if (latValue < -90) -90.0 else latValue
|
||||||
|
val newLon = if (lonValue > 180) 180.0 else if (lonValue < -180) -180.0 else lonValue
|
||||||
|
save(newLat, newLon)
|
||||||
|
hide()
|
||||||
|
}
|
||||||
+95
-53
@@ -1,9 +1,16 @@
|
|||||||
package com.rtbishop.look4sat.presentation.settingsScreen
|
package com.rtbishop.look4sat.presentation.settingsScreen
|
||||||
|
|
||||||
|
import android.Manifest
|
||||||
|
import android.os.Build
|
||||||
|
import androidx.activity.compose.rememberLauncherForActivityResult
|
||||||
|
import androidx.activity.result.contract.ActivityResultContracts
|
||||||
import androidx.compose.foundation.layout.*
|
import androidx.compose.foundation.layout.*
|
||||||
import androidx.compose.foundation.lazy.LazyColumn
|
import androidx.compose.foundation.lazy.LazyColumn
|
||||||
import androidx.compose.material3.*
|
import androidx.compose.material3.*
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.collectAsState
|
||||||
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
import androidx.compose.runtime.saveable.rememberSaveable
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.platform.LocalContext
|
import androidx.compose.ui.platform.LocalContext
|
||||||
@@ -14,12 +21,15 @@ import androidx.compose.ui.text.style.TextAlign
|
|||||||
import androidx.compose.ui.tooling.preview.Preview
|
import androidx.compose.ui.tooling.preview.Preview
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.compose.ui.unit.sp
|
import androidx.compose.ui.unit.sp
|
||||||
|
import androidx.hilt.navigation.compose.hiltViewModel
|
||||||
import androidx.navigation.NavController
|
import androidx.navigation.NavController
|
||||||
import com.rtbishop.look4sat.BuildConfig
|
import com.rtbishop.look4sat.BuildConfig
|
||||||
import com.rtbishop.look4sat.R
|
import com.rtbishop.look4sat.R
|
||||||
|
import com.rtbishop.look4sat.domain.model.OtherSettings
|
||||||
import com.rtbishop.look4sat.presentation.CardButton
|
import com.rtbishop.look4sat.presentation.CardButton
|
||||||
import com.rtbishop.look4sat.presentation.MainTheme
|
import com.rtbishop.look4sat.presentation.MainTheme
|
||||||
import com.rtbishop.look4sat.presentation.gotoUrl
|
import com.rtbishop.look4sat.presentation.gotoUrl
|
||||||
|
import com.rtbishop.look4sat.presentation.showToast
|
||||||
|
|
||||||
private const val POLICY_URL = "https://sites.google.com/view/look4sat-privacy-policy/home"
|
private const val POLICY_URL = "https://sites.google.com/view/look4sat-privacy-policy/home"
|
||||||
private const val LICENSE_URL = "https://www.gnu.org/licenses/gpl-3.0.html"
|
private const val LICENSE_URL = "https://www.gnu.org/licenses/gpl-3.0.html"
|
||||||
@@ -29,10 +39,71 @@ private const val FDROID_URL = "https://f-droid.org/en/packages/com.rtbishop.loo
|
|||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun SettingsScreen(navController: NavController) {
|
fun SettingsScreen(navController: NavController) {
|
||||||
|
val context = LocalContext.current
|
||||||
|
val viewModel: SettingsViewModel = hiltViewModel()
|
||||||
|
|
||||||
|
// Permissions setup
|
||||||
|
val bluetoothContract = ActivityResultContracts.RequestPermission()
|
||||||
|
val bluetoothError = stringResource(R.string.BTremote_perm_error)
|
||||||
|
val bluetoothPerm = when {
|
||||||
|
Build.VERSION.SDK_INT < Build.VERSION_CODES.S -> Manifest.permission.BLUETOOTH
|
||||||
|
else -> Manifest.permission.BLUETOOTH_CONNECT
|
||||||
|
}
|
||||||
|
val bluetoothRequest = rememberLauncherForActivityResult(bluetoothContract) { isGranted ->
|
||||||
|
viewModel.setBTEnabled(isGranted)
|
||||||
|
if (!isGranted) showToast(context, bluetoothError)
|
||||||
|
}
|
||||||
|
val locationContract = ActivityResultContracts.RequestMultiplePermissions()
|
||||||
|
val locationError = stringResource(R.string.location_gps_error)
|
||||||
|
val locationPermCoarse = Manifest.permission.ACCESS_COARSE_LOCATION
|
||||||
|
val locationPermFine = Manifest.permission.ACCESS_FINE_LOCATION
|
||||||
|
val locationRequest = rememberLauncherForActivityResult(locationContract) { permissions ->
|
||||||
|
when {
|
||||||
|
permissions[locationPermFine] == true -> viewModel.setPositionFromGps()
|
||||||
|
permissions[locationPermCoarse] == true -> viewModel.setPositionFromNet()
|
||||||
|
else -> showToast(context, locationError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
val contentContract = ActivityResultContracts.GetContent()
|
||||||
|
val contentRequest = rememberLauncherForActivityResult(contentContract) { uri ->
|
||||||
|
uri?.let { viewModel.updateFromFile(uri.toString()) }
|
||||||
|
}
|
||||||
|
|
||||||
|
// Location settings
|
||||||
|
val setGpsLoc = { locationRequest.launch(arrayOf(locationPermCoarse, locationPermFine)) }
|
||||||
|
val geoPos = viewModel.getStationPosition()
|
||||||
|
val showPosDialog = rememberSaveable { mutableStateOf(false) }
|
||||||
|
val togglePosDialog = { showPosDialog.value = showPosDialog.value.not() }
|
||||||
|
val savePos = { lat: Double, lon: Double -> viewModel.setStationPosition(lat, lon) }
|
||||||
|
if (showPosDialog.value) {
|
||||||
|
PositionDialog(lat = geoPos.lat, lon = geoPos.lon, hide = togglePosDialog, save = savePos)
|
||||||
|
}
|
||||||
|
val qthLocator = viewModel.getStationLocator()
|
||||||
|
val showLocDialog = rememberSaveable { mutableStateOf(false) }
|
||||||
|
val toggleLocDialog = { showLocDialog.value = showLocDialog.value.not() }
|
||||||
|
val saveLocator = { locator: String -> viewModel.setPositionFromQth(locator) }
|
||||||
|
if (showLocDialog.value) {
|
||||||
|
LocatorDialog(qthLocator = qthLocator, hide = toggleLocDialog, save = saveLocator)
|
||||||
|
}
|
||||||
|
// Data settings
|
||||||
|
val updateFromWeb = { viewModel.updateFromWeb() }
|
||||||
|
val updateFromFile = { contentRequest.launch("*/*") }
|
||||||
|
val clearAllData = { viewModel.clearAllData() }
|
||||||
|
// Other settings
|
||||||
|
val otherSettings = viewModel.otherSettings.collectAsState()
|
||||||
|
val setUtc = { value: Boolean -> viewModel.setUtcState(value) }
|
||||||
|
val setUpdate = { value: Boolean -> viewModel.setUpdateState(value) }
|
||||||
|
val setSweep = { value: Boolean -> viewModel.setSweepState(value) }
|
||||||
|
val setSensor = { value: Boolean -> viewModel.setSensorState(value) }
|
||||||
|
|
||||||
|
// Screen setup
|
||||||
LazyColumn(
|
LazyColumn(
|
||||||
modifier = Modifier.padding(6.dp), verticalArrangement = Arrangement.spacedBy(6.dp)
|
modifier = Modifier.padding(6.dp), verticalArrangement = Arrangement.spacedBy(6.dp)
|
||||||
) {
|
) {
|
||||||
item { CardAbout(BuildConfig.VERSION_NAME) }
|
item { CardAbout(BuildConfig.VERSION_NAME) }
|
||||||
|
item { LocationCard(setGpsLoc, togglePosDialog, toggleLocDialog) }
|
||||||
|
item { DataCard(updateFromWeb, updateFromFile, clearAllData) }
|
||||||
|
item { OtherCard(otherSettings.value, setUtc, setUpdate, setSweep, setSensor) }
|
||||||
item { CardCredits() }
|
item { CardCredits() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -93,11 +164,13 @@ private fun CardAbout(version: String, modifier: Modifier = Modifier) {
|
|||||||
@Preview(showBackground = true)
|
@Preview(showBackground = true)
|
||||||
@Composable
|
@Composable
|
||||||
private fun LocationCardPreview() {
|
private fun LocationCardPreview() {
|
||||||
MainTheme { LocationCard() }
|
MainTheme { LocationCard({}, {}, {}) }
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
private fun LocationCard() {
|
private fun LocationCard(
|
||||||
|
setGpsLoc: () -> Unit, togglePosDialog: () -> Unit, toggleLocDialog: () -> Unit
|
||||||
|
) {
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
// setPositionText(viewModel.getStationPosition())
|
// setPositionText(viewModel.getStationPosition())
|
||||||
ElevatedCard(modifier = Modifier.fillMaxWidth()) {
|
ElevatedCard(modifier = Modifier.fillMaxWidth()) {
|
||||||
@@ -124,15 +197,15 @@ private fun LocationCard() {
|
|||||||
}
|
}
|
||||||
Row(horizontalArrangement = Arrangement.SpaceEvenly) {
|
Row(horizontalArrangement = Arrangement.SpaceEvenly) {
|
||||||
CardButton(
|
CardButton(
|
||||||
onClick = { }, // locationRequest.launch(arrayOf(locationFine, locationCoarse))
|
onClick = setGpsLoc, // locationRequest.launch(arrayOf(locationFine, locationCoarse))
|
||||||
text = stringResource(id = R.string.btn_gps), modifier = Modifier.weight(1f)
|
text = stringResource(id = R.string.btn_gps), modifier = Modifier.weight(1f)
|
||||||
)
|
)
|
||||||
CardButton(
|
CardButton(
|
||||||
onClick = { }, // open Position dialog
|
onClick = togglePosDialog, // open Position dialog
|
||||||
text = stringResource(id = R.string.btn_manual), modifier = Modifier.weight(1f)
|
text = stringResource(id = R.string.btn_manual), modifier = Modifier.weight(1f)
|
||||||
) // viewModel.setStationPosition(position.first, position.second)
|
) // viewModel.setStationPosition(position.first, position.second)
|
||||||
CardButton(
|
CardButton(
|
||||||
onClick = { }, // open Locator dialog
|
onClick = toggleLocDialog, // open Locator dialog
|
||||||
text = stringResource(id = R.string.btn_qth), modifier = Modifier.weight(1f)
|
text = stringResource(id = R.string.btn_qth), modifier = Modifier.weight(1f)
|
||||||
) // viewModel.setPositionFromQth(locator)
|
) // viewModel.setPositionFromQth(locator)
|
||||||
}
|
}
|
||||||
@@ -143,11 +216,11 @@ private fun LocationCard() {
|
|||||||
@Preview(showBackground = true)
|
@Preview(showBackground = true)
|
||||||
@Composable
|
@Composable
|
||||||
private fun DataCardPreview() {
|
private fun DataCardPreview() {
|
||||||
MainTheme { DataCard() }
|
MainTheme { DataCard({}, {}, {}) }
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
private fun DataCard() {
|
private fun DataCard(updateOnline: () -> Unit, updateFile: () -> Unit, clearData: () -> Unit) {
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
// setUpdateTime(viewModel.getLastUpdateTime())
|
// setUpdateTime(viewModel.getLastUpdateTime())
|
||||||
// viewModel.entriesTotal
|
// viewModel.entriesTotal
|
||||||
@@ -176,15 +249,15 @@ private fun DataCard() {
|
|||||||
}
|
}
|
||||||
Row(horizontalArrangement = Arrangement.SpaceEvenly) {
|
Row(horizontalArrangement = Arrangement.SpaceEvenly) {
|
||||||
CardButton(
|
CardButton(
|
||||||
onClick = { }, // viewModel.updateFromWeb()
|
onClick = updateOnline, // viewModel.updateFromWeb()
|
||||||
text = stringResource(id = R.string.btn_web), modifier = Modifier.weight(1f)
|
text = stringResource(id = R.string.btn_web), modifier = Modifier.weight(1f)
|
||||||
)
|
)
|
||||||
CardButton(
|
CardButton(
|
||||||
onClick = { }, // contentRequest.launch("*/*")
|
onClick = updateFile, // contentRequest.launch("*/*")
|
||||||
text = stringResource(id = R.string.btn_file), modifier = Modifier.weight(1f)
|
text = stringResource(id = R.string.btn_file), modifier = Modifier.weight(1f)
|
||||||
)
|
)
|
||||||
CardButton(
|
CardButton(
|
||||||
onClick = { }, // viewModel.clearAllData()
|
onClick = clearData, // viewModel.clearAllData()
|
||||||
text = stringResource(id = R.string.btn_clear), modifier = Modifier.weight(1f)
|
text = stringResource(id = R.string.btn_clear), modifier = Modifier.weight(1f)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -192,33 +265,6 @@ private fun DataCard() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//private val viewModel: SettingsViewModel by viewModels()
|
|
||||||
//private val bluetooth = when {
|
|
||||||
// Build.VERSION.SDK_INT < Build.VERSION_CODES.S -> Manifest.permission.BLUETOOTH
|
|
||||||
// else -> Manifest.permission.BLUETOOTH_CONNECT
|
|
||||||
//}
|
|
||||||
//private val bluetoothContract = ActivityResultContracts.RequestPermission()
|
|
||||||
//private val bluetoothRequest = registerForActivityResult(bluetoothContract) { isGranted ->
|
|
||||||
// if (!isGranted) {
|
|
||||||
// showToast(getString(R.string.BTremote_perm_error))
|
|
||||||
// toggleBTstate(isGranted)
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
//private val locationFine = Manifest.permission.ACCESS_FINE_LOCATION
|
|
||||||
//private val locationCoarse = Manifest.permission.ACCESS_COARSE_LOCATION
|
|
||||||
//private val locationContract = ActivityResultContracts.RequestMultiplePermissions()
|
|
||||||
//private val locationRequest = registerForActivityResult(locationContract) { permissions ->
|
|
||||||
// when {
|
|
||||||
// permissions[locationFine] == true -> viewModel.setPositionFromGps()
|
|
||||||
// permissions[locationCoarse] == true -> viewModel.setPositionFromNet()
|
|
||||||
// else -> showToast(getString(R.string.location_gps_error))
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
//private val contentContract = ActivityResultContracts.GetContent()
|
|
||||||
//private val contentRequest = registerForActivityResult(contentContract) { uri ->
|
|
||||||
// uri?.let { viewModel.updateFromFile(uri.toString()) }
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
//private fun setupRemoteCard() {
|
//private fun setupRemoteCard() {
|
||||||
// binding.run {
|
// binding.run {
|
||||||
// settingsRemote.remoteSwitch.apply {
|
// settingsRemote.remoteSwitch.apply {
|
||||||
@@ -264,24 +310,20 @@ private fun DataCard() {
|
|||||||
// }
|
// }
|
||||||
//}
|
//}
|
||||||
//
|
//
|
||||||
//private fun toggleBTstate(value: Boolean) {
|
|
||||||
// binding.run {
|
|
||||||
// viewModel.setBTEnabled(value)
|
|
||||||
// settingsBtremote.BTremoteSwitch.isChecked = value
|
|
||||||
// settingsBtremote.BTremoteAddress.isEnabled = value
|
|
||||||
// settingsBtremote.BTremoteFormat.isEnabled = value
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
@Preview(showBackground = true)
|
@Preview(showBackground = true)
|
||||||
@Composable
|
@Composable
|
||||||
private fun OtherCardPreview() {
|
private fun OtherCardPreview() {
|
||||||
MainTheme { OtherCard() }
|
MainTheme { }
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
private fun OtherCard() {
|
private fun OtherCard(
|
||||||
val context = LocalContext.current
|
settings: OtherSettings,
|
||||||
|
setUtc: (Boolean) -> Unit,
|
||||||
|
setUpdate: (Boolean) -> Unit,
|
||||||
|
setSweep: (Boolean) -> Unit,
|
||||||
|
setSensor: (Boolean) -> Unit
|
||||||
|
) {
|
||||||
ElevatedCard(modifier = Modifier.fillMaxWidth()) {
|
ElevatedCard(modifier = Modifier.fillMaxWidth()) {
|
||||||
Column(modifier = Modifier.padding(4.dp)) {
|
Column(modifier = Modifier.padding(4.dp)) {
|
||||||
Text(text = stringResource(id = R.string.other_title))
|
Text(text = stringResource(id = R.string.other_title))
|
||||||
@@ -291,7 +333,7 @@ private fun OtherCard() {
|
|||||||
modifier = Modifier.fillMaxWidth()
|
modifier = Modifier.fillMaxWidth()
|
||||||
) {
|
) {
|
||||||
Text(text = stringResource(id = R.string.other_switch_utc))
|
Text(text = stringResource(id = R.string.other_switch_utc))
|
||||||
Switch(checked = true, onCheckedChange = {})
|
Switch(checked = settings.isUtcEnabled, onCheckedChange = { setUtc(it) })
|
||||||
} // viewModel.setUseUTC(isChecked)
|
} // viewModel.setUseUTC(isChecked)
|
||||||
Row(
|
Row(
|
||||||
horizontalArrangement = Arrangement.SpaceBetween,
|
horizontalArrangement = Arrangement.SpaceBetween,
|
||||||
@@ -299,7 +341,7 @@ private fun OtherCard() {
|
|||||||
modifier = Modifier.fillMaxWidth()
|
modifier = Modifier.fillMaxWidth()
|
||||||
) {
|
) {
|
||||||
Text(text = stringResource(id = R.string.other_switch_update))
|
Text(text = stringResource(id = R.string.other_switch_update))
|
||||||
Switch(checked = true, onCheckedChange = {})
|
Switch(checked = settings.isUpdateEnabled, onCheckedChange = { setUpdate(it) })
|
||||||
} // AutoUpdateEnabled(isChecked)
|
} // AutoUpdateEnabled(isChecked)
|
||||||
Row(
|
Row(
|
||||||
horizontalArrangement = Arrangement.SpaceBetween,
|
horizontalArrangement = Arrangement.SpaceBetween,
|
||||||
@@ -307,7 +349,7 @@ private fun OtherCard() {
|
|||||||
modifier = Modifier.fillMaxWidth()
|
modifier = Modifier.fillMaxWidth()
|
||||||
) {
|
) {
|
||||||
Text(text = stringResource(id = R.string.other_switch_sweep))
|
Text(text = stringResource(id = R.string.other_switch_sweep))
|
||||||
Switch(checked = true, onCheckedChange = {})
|
Switch(checked = settings.isSweepEnabled, onCheckedChange = { setSweep(it) })
|
||||||
} // viewModel.setShowSweep(isChecked)
|
} // viewModel.setShowSweep(isChecked)
|
||||||
Row(
|
Row(
|
||||||
horizontalArrangement = Arrangement.SpaceBetween,
|
horizontalArrangement = Arrangement.SpaceBetween,
|
||||||
@@ -315,7 +357,7 @@ private fun OtherCard() {
|
|||||||
modifier = Modifier.fillMaxWidth()
|
modifier = Modifier.fillMaxWidth()
|
||||||
) {
|
) {
|
||||||
Text(text = stringResource(id = R.string.other_switch_sensors))
|
Text(text = stringResource(id = R.string.other_switch_sensors))
|
||||||
Switch(checked = true, onCheckedChange = {})
|
Switch(checked = settings.isSensorEnabled, onCheckedChange = { setSensor(it) })
|
||||||
} // viewModel.setUseCompass(isChecked)
|
} // viewModel.setUseCompass(isChecked)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+40
-13
@@ -22,9 +22,12 @@ import com.rtbishop.look4sat.domain.IDataRepository
|
|||||||
import com.rtbishop.look4sat.domain.ILocationManager
|
import com.rtbishop.look4sat.domain.ILocationManager
|
||||||
import com.rtbishop.look4sat.domain.ISettingsManager
|
import com.rtbishop.look4sat.domain.ISettingsManager
|
||||||
import com.rtbishop.look4sat.domain.model.DataState
|
import com.rtbishop.look4sat.domain.model.DataState
|
||||||
|
import com.rtbishop.look4sat.domain.model.OtherSettings
|
||||||
import com.rtbishop.look4sat.domain.predict.GeoPos
|
import com.rtbishop.look4sat.domain.predict.GeoPos
|
||||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||||
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
import kotlinx.coroutines.flow.SharedFlow
|
import kotlinx.coroutines.flow.SharedFlow
|
||||||
|
import kotlinx.coroutines.flow.StateFlow
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
@HiltViewModel
|
@HiltViewModel
|
||||||
@@ -34,6 +37,36 @@ class SettingsViewModel @Inject constructor(
|
|||||||
private val settings: ISettingsManager
|
private val settings: ISettingsManager
|
||||||
) : ViewModel() {
|
) : ViewModel() {
|
||||||
|
|
||||||
|
private val _otherSettings = MutableStateFlow(
|
||||||
|
OtherSettings(
|
||||||
|
settings.isUtcEnabled(),
|
||||||
|
settings.isUpdateEnabled(),
|
||||||
|
settings.isSweepEnabled(),
|
||||||
|
settings.isSensorEnabled()
|
||||||
|
)
|
||||||
|
)
|
||||||
|
val otherSettings: StateFlow<OtherSettings> = _otherSettings
|
||||||
|
|
||||||
|
fun setUtcState(value: Boolean) {
|
||||||
|
settings.setUtcState(value)
|
||||||
|
_otherSettings.value = otherSettings.value.copy(isUtcEnabled = value)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun setUpdateState(value: Boolean) {
|
||||||
|
settings.setUpdateState(value)
|
||||||
|
_otherSettings.value = otherSettings.value.copy(isUpdateEnabled = value)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun setSweepState(value: Boolean) {
|
||||||
|
settings.setSweepState(value)
|
||||||
|
_otherSettings.value = otherSettings.value.copy(isSweepEnabled = value)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun setSensorState(value: Boolean) {
|
||||||
|
settings.setSensorState(value)
|
||||||
|
_otherSettings.value = otherSettings.value.copy(isSensorEnabled = value)
|
||||||
|
}
|
||||||
|
|
||||||
val entriesTotal = repository.getEntriesTotal()
|
val entriesTotal = repository.getEntriesTotal()
|
||||||
val radiosTotal = repository.getRadiosTotal()
|
val radiosTotal = repository.getRadiosTotal()
|
||||||
|
|
||||||
@@ -43,23 +76,15 @@ class SettingsViewModel @Inject constructor(
|
|||||||
|
|
||||||
fun clearAllData() = repository.clearAllData()
|
fun clearAllData() = repository.clearAllData()
|
||||||
|
|
||||||
fun getUseUTC(): Boolean = settings.getUseUTC()
|
fun getUseUTC(): Boolean = settings.isUtcEnabled()
|
||||||
|
|
||||||
fun setUseUTC(value: Boolean) = settings.setUseUTC(value)
|
|
||||||
|
|
||||||
fun getLastUpdateTime(): Long = settings.getLastUpdateTime()
|
fun getLastUpdateTime(): Long = settings.getLastUpdateTime()
|
||||||
|
|
||||||
fun getAutoUpdateEnabled(): Boolean = settings.getAutoUpdateEnabled()
|
fun getAutoUpdateEnabled(): Boolean = settings.isUpdateEnabled()
|
||||||
|
|
||||||
fun setAutoUpdateEnabled(value: Boolean) = settings.setAutoUpdateEnabled(value)
|
fun getUseCompass(): Boolean = settings.isSensorEnabled()
|
||||||
|
|
||||||
fun getUseCompass(): Boolean = settings.getUseCompass()
|
fun getShowSweep(): Boolean = settings.isSweepEnabled()
|
||||||
|
|
||||||
fun setUseCompass(value: Boolean) = settings.setUseCompass(value)
|
|
||||||
|
|
||||||
fun getShowSweep(): Boolean = settings.getShowSweep()
|
|
||||||
|
|
||||||
fun setShowSweep(value: Boolean) = settings.setShowSweep(value)
|
|
||||||
|
|
||||||
fun getRotatorEnabled(): Boolean = settings.getRotatorEnabled()
|
fun getRotatorEnabled(): Boolean = settings.getRotatorEnabled()
|
||||||
|
|
||||||
@@ -89,7 +114,7 @@ class SettingsViewModel @Inject constructor(
|
|||||||
|
|
||||||
fun setBTDeviceAddr(value: String) = settings.setBTDeviceAddr(value)
|
fun setBTDeviceAddr(value: String) = settings.setBTDeviceAddr(value)
|
||||||
|
|
||||||
fun getUpdateState() = repository.updateState
|
fun getDataUpdateState() = repository.updateState
|
||||||
|
|
||||||
fun setUpdateHandled() = repository.setUpdateStateHandled()
|
fun setUpdateHandled() = repository.setUpdateStateHandled()
|
||||||
|
|
||||||
@@ -97,6 +122,8 @@ class SettingsViewModel @Inject constructor(
|
|||||||
|
|
||||||
fun getStationPosition(): GeoPos = locationManager.getStationPosition()
|
fun getStationPosition(): GeoPos = locationManager.getStationPosition()
|
||||||
|
|
||||||
|
fun getStationLocator(): String = settings.loadStationLocator()
|
||||||
|
|
||||||
fun setStationPosition(lat: Double, lon: Double) = locationManager.setStationPosition(lat, lon)
|
fun setStationPosition(lat: Double, lon: Double) = locationManager.setStationPosition(lat, lon)
|
||||||
|
|
||||||
fun setPositionFromGps() = locationManager.setPositionFromGps()
|
fun setPositionFromGps() = locationManager.setPositionFromGps()
|
||||||
|
|||||||
@@ -67,25 +67,25 @@ interface ISettingsManager {
|
|||||||
|
|
||||||
fun setMinElevation(minElevation: Double)
|
fun setMinElevation(minElevation: Double)
|
||||||
|
|
||||||
fun getUseUTC(): Boolean
|
fun isUtcEnabled(): Boolean
|
||||||
|
|
||||||
fun setUseUTC(value: Boolean)
|
fun setUtcState(value: Boolean)
|
||||||
|
|
||||||
fun getLastUpdateTime(): Long
|
fun getLastUpdateTime(): Long
|
||||||
|
|
||||||
fun setLastUpdateTime(updateTime: Long)
|
fun setLastUpdateTime(updateTime: Long)
|
||||||
|
|
||||||
fun getAutoUpdateEnabled(): Boolean
|
fun isUpdateEnabled(): Boolean
|
||||||
|
|
||||||
fun setAutoUpdateEnabled(value: Boolean)
|
fun setUpdateState(value: Boolean)
|
||||||
|
|
||||||
fun getUseCompass(): Boolean
|
fun isSensorEnabled(): Boolean
|
||||||
|
|
||||||
fun setUseCompass(value: Boolean)
|
fun setSensorState(value: Boolean)
|
||||||
|
|
||||||
fun getShowSweep(): Boolean
|
fun isSweepEnabled(): Boolean
|
||||||
|
|
||||||
fun setShowSweep(value: Boolean)
|
fun setSweepState(value: Boolean)
|
||||||
|
|
||||||
fun saveModesSelection(modes: List<String>)
|
fun saveModesSelection(modes: List<String>)
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
package com.rtbishop.look4sat.domain.model
|
||||||
|
|
||||||
|
data class OtherSettings(
|
||||||
|
val isUtcEnabled: Boolean,
|
||||||
|
val isUpdateEnabled: Boolean,
|
||||||
|
val isSweepEnabled: Boolean,
|
||||||
|
val isSensorEnabled: Boolean
|
||||||
|
)
|
||||||
Reference in new issue
Block a user