kopia lustrzana https://github.com/rt-bishop/Look4Sat
Added more functionality to SettingsScreen.kt
rodzic
73e0454a22
commit
a8e5bf3e43
|
@ -50,7 +50,7 @@ class SettingsManager @Inject constructor(private val prefs: SharedPreferences)
|
|||
}
|
||||
|
||||
override fun loadStationLocator(): String {
|
||||
return prefs.getString(keyLocator, null) ?: "null"
|
||||
return prefs.getString(keyLocator, null) ?: ""
|
||||
}
|
||||
|
||||
override fun saveStationLocator(locator: String) {
|
||||
|
@ -107,11 +107,11 @@ class SettingsManager @Inject constructor(private val prefs: SharedPreferences)
|
|||
prefs.edit { putDouble(keyMinElevation, minElevation) }
|
||||
}
|
||||
|
||||
override fun getUseUTC(): Boolean {
|
||||
override fun isUtcEnabled(): Boolean {
|
||||
return prefs.getBoolean(keyTimeUTC, false)
|
||||
}
|
||||
|
||||
override fun setUseUTC(value: Boolean) {
|
||||
override fun setUtcState(value: Boolean) {
|
||||
prefs.edit { putBoolean(keyTimeUTC, value) }
|
||||
}
|
||||
|
||||
|
@ -123,27 +123,27 @@ class SettingsManager @Inject constructor(private val prefs: SharedPreferences)
|
|||
prefs.edit { putLong(keyLastUpdateTime, updateTime) }
|
||||
}
|
||||
|
||||
override fun getAutoUpdateEnabled(): Boolean {
|
||||
override fun isUpdateEnabled(): Boolean {
|
||||
return prefs.getBoolean(keyAutoUpdateEnabled, true)
|
||||
}
|
||||
|
||||
override fun setAutoUpdateEnabled(value: Boolean) {
|
||||
override fun setUpdateState(value: Boolean) {
|
||||
prefs.edit { putBoolean(keyAutoUpdateEnabled, value) }
|
||||
}
|
||||
|
||||
override fun getUseCompass(): Boolean {
|
||||
override fun isSensorEnabled(): Boolean {
|
||||
return prefs.getBoolean(keyCompass, true)
|
||||
}
|
||||
|
||||
override fun setUseCompass(value: Boolean) {
|
||||
override fun setSensorState(value: Boolean) {
|
||||
prefs.edit { putBoolean(keyCompass, value) }
|
||||
}
|
||||
|
||||
override fun getShowSweep(): Boolean {
|
||||
override fun isSweepEnabled(): Boolean {
|
||||
return prefs.getBoolean(keyRadarSweep, true)
|
||||
}
|
||||
|
||||
override fun setShowSweep(value: Boolean) {
|
||||
override fun setSweepState(value: Boolean) {
|
||||
prefs.edit { putBoolean(keyRadarSweep, value) }
|
||||
}
|
||||
|
||||
|
|
|
@ -45,7 +45,7 @@ class MainApplication : Application() {
|
|||
}
|
||||
|
||||
private fun checkAutoUpdate() {
|
||||
if (settingsManager.getAutoUpdateEnabled()) {
|
||||
if (settingsManager.isUpdateEnabled()) {
|
||||
val timeDelta = System.currentTimeMillis() - settingsManager.getLastUpdateTime()
|
||||
if (timeDelta > 172800000) { // 48 hours in ms
|
||||
val sdf = SimpleDateFormat("d MMM yyyy - HH:mm:ss", Locale.getDefault())
|
||||
|
|
|
@ -90,7 +90,7 @@ class PassesViewModel @Inject constructor(
|
|||
calculatePasses()
|
||||
}
|
||||
|
||||
fun shouldUseUTC() = settings.getUseUTC()
|
||||
fun shouldUseUTC() = settings.isUtcEnabled()
|
||||
|
||||
fun calculatePasses(
|
||||
hoursAhead: Int = 1,
|
||||
|
|
|
@ -95,16 +95,16 @@ class RadarViewModel @Inject constructor(
|
|||
}
|
||||
|
||||
fun enableSensor() {
|
||||
if (settings.getUseCompass()) orientationManager.startListening(this)
|
||||
if (settings.isSensorEnabled()) orientationManager.startListening(this)
|
||||
}
|
||||
|
||||
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) {
|
||||
_orientation.value = Triple(azimuth + getMagDeclination(stationPos), pitch, roll)
|
||||
|
|
|
@ -20,17 +20,14 @@ import com.rtbishop.look4sat.presentation.MainTheme
|
|||
@Preview(showBackground = true)
|
||||
@Composable
|
||||
private fun LocatorDialogPreview() {
|
||||
MainTheme { LocatorDialog(8, 16.0, {}) { _, _ -> } }
|
||||
MainTheme { LocatorDialog("IO91vl", {}) { } }
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun LocatorDialog(
|
||||
hours: Int, elevation: Double, toggle: () -> Unit, save: (Int, Double) -> Unit
|
||||
) {
|
||||
val hoursValue = rememberSaveable { mutableStateOf(hours) }
|
||||
val elevValue = rememberSaveable { mutableStateOf(elevation) }
|
||||
Dialog(onDismissRequest = { toggle() }) {
|
||||
fun LocatorDialog(qthLocator: String, hide: () -> Unit, save: (String) -> Unit) {
|
||||
val locator = rememberSaveable { mutableStateOf(qthLocator) }
|
||||
Dialog(onDismissRequest = { hide() }) {
|
||||
ElevatedCard {
|
||||
Column(
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
|
@ -41,24 +38,19 @@ fun LocatorDialog(
|
|||
color = MaterialTheme.colorScheme.primary
|
||||
)
|
||||
Text(text = stringResource(id = R.string.locator_text))
|
||||
OutlinedTextField(value = hoursValue.value.toString(), onValueChange = { newValue ->
|
||||
val hoursAhead = try {
|
||||
newValue.toInt()
|
||||
} catch (exception: Exception) {
|
||||
12
|
||||
}
|
||||
hoursValue.value = hoursAhead
|
||||
})
|
||||
OutlinedTextField(value = locator.value, onValueChange = { locator.value = it })
|
||||
Row(
|
||||
horizontalArrangement = Arrangement.SpaceBetween,
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
) {
|
||||
CardButton(onClick = { toggle() }, text = "Cancel")
|
||||
CardButton(
|
||||
onClick = { hide() }, text = stringResource(id = R.string.btn_cancel)
|
||||
)
|
||||
CardButton(
|
||||
onClick = {
|
||||
save(hoursValue.value, elevValue.value)
|
||||
toggle()
|
||||
}, text = "Accept"
|
||||
save(locator.value)
|
||||
hide()
|
||||
}, text = stringResource(id = R.string.btn_accept)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,17 +20,15 @@ import com.rtbishop.look4sat.presentation.MainTheme
|
|||
@Preview(showBackground = true)
|
||||
@Composable
|
||||
private fun PositionDialogPreview() {
|
||||
MainTheme { PositionDialog(8, 16.0, {}) { _, _ -> } }
|
||||
MainTheme { PositionDialog(0.0, 0.0, {}) { _, _ -> } }
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun PositionDialog(
|
||||
hours: Int, elevation: Double, toggle: () -> Unit, save: (Int, Double) -> Unit
|
||||
) {
|
||||
val hoursValue = rememberSaveable { mutableStateOf(hours) }
|
||||
val elevValue = rememberSaveable { mutableStateOf(elevation) }
|
||||
Dialog(onDismissRequest = { toggle() }) {
|
||||
fun PositionDialog(lat: Double, lon: Double, hide: () -> Unit, save: (Double, Double) -> Unit) {
|
||||
val latValue = rememberSaveable { mutableStateOf(lat.toString()) }
|
||||
val lonValue = rememberSaveable { mutableStateOf(lon.toString()) }
|
||||
Dialog(onDismissRequest = { hide() }) {
|
||||
ElevatedCard {
|
||||
Column(
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
|
@ -41,36 +39,31 @@ fun PositionDialog(
|
|||
color = MaterialTheme.colorScheme.primary
|
||||
)
|
||||
Text(text = stringResource(id = R.string.position_lat_text))
|
||||
OutlinedTextField(value = hoursValue.value.toString(), onValueChange = { newValue ->
|
||||
val hoursAhead = try {
|
||||
newValue.toInt()
|
||||
} catch (exception: Exception) {
|
||||
12
|
||||
}
|
||||
hoursValue.value = hoursAhead
|
||||
})
|
||||
OutlinedTextField(value = latValue.value, onValueChange = { latValue.value = it })
|
||||
Text(text = stringResource(id = R.string.position_lon_text))
|
||||
OutlinedTextField(value = elevValue.value.toString(), onValueChange = { newValue ->
|
||||
val maxElevation = try {
|
||||
newValue.toDouble()
|
||||
} catch (exception: Exception) {
|
||||
16.0
|
||||
}
|
||||
elevValue.value = maxElevation
|
||||
})
|
||||
OutlinedTextField(value = lonValue.value, onValueChange = { lonValue.value = it })
|
||||
Row(
|
||||
horizontalArrangement = Arrangement.SpaceBetween,
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
) {
|
||||
CardButton(onClick = { toggle() }, text = "Cancel")
|
||||
CardButton(
|
||||
onClick = {
|
||||
save(hoursValue.value, elevValue.value)
|
||||
toggle()
|
||||
}, text = "Accept"
|
||||
onClick = { hide() }, text = stringResource(id = R.string.btn_cancel)
|
||||
)
|
||||
CardButton(
|
||||
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()
|
||||
}
|
||||
|
|
|
@ -1,9 +1,16 @@
|
|||
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.lazy.LazyColumn
|
||||
import androidx.compose.material3.*
|
||||
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.Modifier
|
||||
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.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import androidx.hilt.navigation.compose.hiltViewModel
|
||||
import androidx.navigation.NavController
|
||||
import com.rtbishop.look4sat.BuildConfig
|
||||
import com.rtbishop.look4sat.R
|
||||
import com.rtbishop.look4sat.domain.model.OtherSettings
|
||||
import com.rtbishop.look4sat.presentation.CardButton
|
||||
import com.rtbishop.look4sat.presentation.MainTheme
|
||||
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 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
|
||||
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(
|
||||
modifier = Modifier.padding(6.dp), verticalArrangement = Arrangement.spacedBy(6.dp)
|
||||
) {
|
||||
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() }
|
||||
}
|
||||
}
|
||||
|
@ -93,11 +164,13 @@ private fun CardAbout(version: String, modifier: Modifier = Modifier) {
|
|||
@Preview(showBackground = true)
|
||||
@Composable
|
||||
private fun LocationCardPreview() {
|
||||
MainTheme { LocationCard() }
|
||||
MainTheme { LocationCard({}, {}, {}) }
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun LocationCard() {
|
||||
private fun LocationCard(
|
||||
setGpsLoc: () -> Unit, togglePosDialog: () -> Unit, toggleLocDialog: () -> Unit
|
||||
) {
|
||||
val context = LocalContext.current
|
||||
// setPositionText(viewModel.getStationPosition())
|
||||
ElevatedCard(modifier = Modifier.fillMaxWidth()) {
|
||||
|
@ -124,15 +197,15 @@ private fun LocationCard() {
|
|||
}
|
||||
Row(horizontalArrangement = Arrangement.SpaceEvenly) {
|
||||
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)
|
||||
)
|
||||
CardButton(
|
||||
onClick = { }, // open Position dialog
|
||||
onClick = togglePosDialog, // open Position dialog
|
||||
text = stringResource(id = R.string.btn_manual), modifier = Modifier.weight(1f)
|
||||
) // viewModel.setStationPosition(position.first, position.second)
|
||||
CardButton(
|
||||
onClick = { }, // open Locator dialog
|
||||
onClick = toggleLocDialog, // open Locator dialog
|
||||
text = stringResource(id = R.string.btn_qth), modifier = Modifier.weight(1f)
|
||||
) // viewModel.setPositionFromQth(locator)
|
||||
}
|
||||
|
@ -143,11 +216,11 @@ private fun LocationCard() {
|
|||
@Preview(showBackground = true)
|
||||
@Composable
|
||||
private fun DataCardPreview() {
|
||||
MainTheme { DataCard() }
|
||||
MainTheme { DataCard({}, {}, {}) }
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun DataCard() {
|
||||
private fun DataCard(updateOnline: () -> Unit, updateFile: () -> Unit, clearData: () -> Unit) {
|
||||
val context = LocalContext.current
|
||||
// setUpdateTime(viewModel.getLastUpdateTime())
|
||||
// viewModel.entriesTotal
|
||||
|
@ -176,15 +249,15 @@ private fun DataCard() {
|
|||
}
|
||||
Row(horizontalArrangement = Arrangement.SpaceEvenly) {
|
||||
CardButton(
|
||||
onClick = { }, // viewModel.updateFromWeb()
|
||||
onClick = updateOnline, // viewModel.updateFromWeb()
|
||||
text = stringResource(id = R.string.btn_web), modifier = Modifier.weight(1f)
|
||||
)
|
||||
CardButton(
|
||||
onClick = { }, // contentRequest.launch("*/*")
|
||||
onClick = updateFile, // contentRequest.launch("*/*")
|
||||
text = stringResource(id = R.string.btn_file), modifier = Modifier.weight(1f)
|
||||
)
|
||||
CardButton(
|
||||
onClick = { }, // viewModel.clearAllData()
|
||||
onClick = clearData, // viewModel.clearAllData()
|
||||
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() {
|
||||
// binding.run {
|
||||
// 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)
|
||||
@Composable
|
||||
private fun OtherCardPreview() {
|
||||
MainTheme { OtherCard() }
|
||||
MainTheme { }
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun OtherCard() {
|
||||
val context = LocalContext.current
|
||||
private fun OtherCard(
|
||||
settings: OtherSettings,
|
||||
setUtc: (Boolean) -> Unit,
|
||||
setUpdate: (Boolean) -> Unit,
|
||||
setSweep: (Boolean) -> Unit,
|
||||
setSensor: (Boolean) -> Unit
|
||||
) {
|
||||
ElevatedCard(modifier = Modifier.fillMaxWidth()) {
|
||||
Column(modifier = Modifier.padding(4.dp)) {
|
||||
Text(text = stringResource(id = R.string.other_title))
|
||||
|
@ -291,7 +333,7 @@ private fun OtherCard() {
|
|||
modifier = Modifier.fillMaxWidth()
|
||||
) {
|
||||
Text(text = stringResource(id = R.string.other_switch_utc))
|
||||
Switch(checked = true, onCheckedChange = {})
|
||||
Switch(checked = settings.isUtcEnabled, onCheckedChange = { setUtc(it) })
|
||||
} // viewModel.setUseUTC(isChecked)
|
||||
Row(
|
||||
horizontalArrangement = Arrangement.SpaceBetween,
|
||||
|
@ -299,7 +341,7 @@ private fun OtherCard() {
|
|||
modifier = Modifier.fillMaxWidth()
|
||||
) {
|
||||
Text(text = stringResource(id = R.string.other_switch_update))
|
||||
Switch(checked = true, onCheckedChange = {})
|
||||
Switch(checked = settings.isUpdateEnabled, onCheckedChange = { setUpdate(it) })
|
||||
} // AutoUpdateEnabled(isChecked)
|
||||
Row(
|
||||
horizontalArrangement = Arrangement.SpaceBetween,
|
||||
|
@ -307,7 +349,7 @@ private fun OtherCard() {
|
|||
modifier = Modifier.fillMaxWidth()
|
||||
) {
|
||||
Text(text = stringResource(id = R.string.other_switch_sweep))
|
||||
Switch(checked = true, onCheckedChange = {})
|
||||
Switch(checked = settings.isSweepEnabled, onCheckedChange = { setSweep(it) })
|
||||
} // viewModel.setShowSweep(isChecked)
|
||||
Row(
|
||||
horizontalArrangement = Arrangement.SpaceBetween,
|
||||
|
@ -315,7 +357,7 @@ private fun OtherCard() {
|
|||
modifier = Modifier.fillMaxWidth()
|
||||
) {
|
||||
Text(text = stringResource(id = R.string.other_switch_sensors))
|
||||
Switch(checked = true, onCheckedChange = {})
|
||||
Switch(checked = settings.isSensorEnabled, onCheckedChange = { setSensor(it) })
|
||||
} // viewModel.setUseCompass(isChecked)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,9 +22,12 @@ import com.rtbishop.look4sat.domain.IDataRepository
|
|||
import com.rtbishop.look4sat.domain.ILocationManager
|
||||
import com.rtbishop.look4sat.domain.ISettingsManager
|
||||
import com.rtbishop.look4sat.domain.model.DataState
|
||||
import com.rtbishop.look4sat.domain.model.OtherSettings
|
||||
import com.rtbishop.look4sat.domain.predict.GeoPos
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.SharedFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import javax.inject.Inject
|
||||
|
||||
@HiltViewModel
|
||||
|
@ -34,6 +37,36 @@ class SettingsViewModel @Inject constructor(
|
|||
private val settings: ISettingsManager
|
||||
) : 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 radiosTotal = repository.getRadiosTotal()
|
||||
|
||||
|
@ -43,23 +76,15 @@ class SettingsViewModel @Inject constructor(
|
|||
|
||||
fun clearAllData() = repository.clearAllData()
|
||||
|
||||
fun getUseUTC(): Boolean = settings.getUseUTC()
|
||||
|
||||
fun setUseUTC(value: Boolean) = settings.setUseUTC(value)
|
||||
fun getUseUTC(): Boolean = settings.isUtcEnabled()
|
||||
|
||||
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 setUseCompass(value: Boolean) = settings.setUseCompass(value)
|
||||
|
||||
fun getShowSweep(): Boolean = settings.getShowSweep()
|
||||
|
||||
fun setShowSweep(value: Boolean) = settings.setShowSweep(value)
|
||||
fun getShowSweep(): Boolean = settings.isSweepEnabled()
|
||||
|
||||
fun getRotatorEnabled(): Boolean = settings.getRotatorEnabled()
|
||||
|
||||
|
@ -89,7 +114,7 @@ class SettingsViewModel @Inject constructor(
|
|||
|
||||
fun setBTDeviceAddr(value: String) = settings.setBTDeviceAddr(value)
|
||||
|
||||
fun getUpdateState() = repository.updateState
|
||||
fun getDataUpdateState() = repository.updateState
|
||||
|
||||
fun setUpdateHandled() = repository.setUpdateStateHandled()
|
||||
|
||||
|
@ -97,6 +122,8 @@ class SettingsViewModel @Inject constructor(
|
|||
|
||||
fun getStationPosition(): GeoPos = locationManager.getStationPosition()
|
||||
|
||||
fun getStationLocator(): String = settings.loadStationLocator()
|
||||
|
||||
fun setStationPosition(lat: Double, lon: Double) = locationManager.setStationPosition(lat, lon)
|
||||
|
||||
fun setPositionFromGps() = locationManager.setPositionFromGps()
|
||||
|
|
|
@ -67,25 +67,25 @@ interface ISettingsManager {
|
|||
|
||||
fun setMinElevation(minElevation: Double)
|
||||
|
||||
fun getUseUTC(): Boolean
|
||||
fun isUtcEnabled(): Boolean
|
||||
|
||||
fun setUseUTC(value: Boolean)
|
||||
fun setUtcState(value: Boolean)
|
||||
|
||||
fun getLastUpdateTime(): 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>)
|
||||
|
||||
|
|
|
@ -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
|
||||
)
|
Ładowanie…
Reference in New Issue