Converted LocatorDialog and PositionDialog

This commit is contained in:
Arty Bishop committed 2025-12-27 15:01:33 +00:00
1 parent 39959c7a10
commit 68d35f0104
4 files changed
+125 -337

No files matched your search

@@ -1,58 +1,67 @@
/*
* Look4Sat. Amateur radio satellite tracker and pass predictor.
* Copyright (C) 2019-2022 Arty Bishop (bishop.arty@gmail.com)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.rtbishop.look4sat.presentation.settingsScreen
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.WindowManager
import androidx.appcompat.app.AppCompatDialogFragment
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.material3.*
import androidx.compose.runtime.Composable
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.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.window.Dialog
import com.rtbishop.look4sat.R
import com.rtbishop.look4sat.databinding.DialogLocatorBinding
import com.rtbishop.look4sat.domain.ISettingsManager
import dagger.hilt.android.AndroidEntryPoint
import javax.inject.Inject
import com.rtbishop.look4sat.presentation.CardButton
import com.rtbishop.look4sat.presentation.MainTheme
@AndroidEntryPoint
class LocatorDialog : AppCompatDialogFragment() {
@Preview(showBackground = true)
@Composable
private fun LocatorDialogPreview() {
MainTheme { LocatorDialog(8, 16.0, {}) { _, _ -> } }
}
@Inject
lateinit var preferences: ISettingsManager
override fun onCreateView(inflater: LayoutInflater, group: ViewGroup?, state: Bundle?): View? {
return inflater.inflate(R.layout.dialog_locator, group, false)
}
override fun onViewCreated(view: View, state: Bundle?) {
super.onViewCreated(view, state)
DialogLocatorBinding.bind(view).run {
dialog?.window?.setBackgroundDrawableResource(R.color.transparent)
dialog?.window?.setLayout(
(resources.displayMetrics.widthPixels * 0.94).toInt(),
WindowManager.LayoutParams.WRAP_CONTENT
)
locatorEdit.setText(preferences.loadStationLocator())
locatorBtnPos.setOnClickListener {
// setNavResult("locator", locatorEdit.text.toString())
dismiss()
@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() }) {
ElevatedCard {
Column(
horizontalAlignment = Alignment.CenterHorizontally,
modifier = Modifier.fillMaxWidth(1f)
) {
Text(
text = stringResource(id = R.string.locator_title),
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
})
Row(
horizontalArrangement = Arrangement.SpaceBetween,
modifier = Modifier.fillMaxWidth()
) {
CardButton(onClick = { toggle() }, text = "Cancel")
CardButton(
onClick = {
save(hoursValue.value, elevValue.value)
toggle()
}, text = "Accept"
)
}
}
locatorBtnNeg.setOnClickListener { dismiss() }
}
}
}
@@ -1,70 +1,76 @@
/*
* Look4Sat. Amateur radio satellite tracker and pass predictor.
* Copyright (C) 2019-2022 Arty Bishop (bishop.arty@gmail.com)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.rtbishop.look4sat.presentation.settingsScreen
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.WindowManager
import androidx.appcompat.app.AppCompatDialogFragment
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.material3.*
import androidx.compose.runtime.Composable
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.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.window.Dialog
import com.rtbishop.look4sat.R
import com.rtbishop.look4sat.databinding.DialogPositionBinding
import com.rtbishop.look4sat.domain.ISettingsManager
import dagger.hilt.android.AndroidEntryPoint
import javax.inject.Inject
import com.rtbishop.look4sat.presentation.CardButton
import com.rtbishop.look4sat.presentation.MainTheme
@AndroidEntryPoint
class PositionDialog : AppCompatDialogFragment() {
@Preview(showBackground = true)
@Composable
private fun PositionDialogPreview() {
MainTheme { PositionDialog(8, 16.0, {}) { _, _ -> } }
}
@Inject
lateinit var preferences: ISettingsManager
override fun onCreateView(inflater: LayoutInflater, group: ViewGroup?, state: Bundle?): View? {
return inflater.inflate(R.layout.dialog_position, group, false)
}
override fun onViewCreated(view: View, state: Bundle?) {
super.onViewCreated(view, state)
DialogPositionBinding.bind(view).run {
dialog?.window?.setBackgroundDrawableResource(R.color.transparent)
dialog?.window?.setLayout(
(resources.displayMetrics.widthPixels * 0.94).toInt(),
WindowManager.LayoutParams.WRAP_CONTENT
)
val location = preferences.loadStationPosition()
positionLatEdit.setText(location.lat.toString())
positionLonEdit.setText(location.lon.toString())
positionBtnPos.setOnClickListener {
// val latitude = try {
// positionLatEdit.text.toString().toDouble()
// } catch (exception: Exception) {
// 180.0
// }
// val longitude = try {
// positionLonEdit.text.toString().toDouble()
// } catch (exception: Exception) {
// 400.0
// }
// setNavResult("position", Pair(latitude, longitude))
dismiss()
@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() }) {
ElevatedCard {
Column(
horizontalAlignment = Alignment.CenterHorizontally,
modifier = Modifier.fillMaxWidth(1f)
) {
Text(
text = stringResource(id = R.string.position_title),
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
})
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
})
Row(
horizontalArrangement = Arrangement.SpaceBetween,
modifier = Modifier.fillMaxWidth()
) {
CardButton(onClick = { toggle() }, text = "Cancel")
CardButton(
onClick = {
save(hoursValue.value, elevValue.value)
toggle()
}, text = "Accept"
)
}
}
positionBtnNeg.setOnClickListener { dismiss() }
}
}
}