kopia lustrzana https://github.com/rt-bishop/Look4Sat
Converted LocatorDialog and PositionDialog
rodzic
2225c75d4c
commit
eab8a9a662
|
@ -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() }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,94 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
style="@style/SurfaceCard"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/locator_title"
|
||||
style="@style/DialogTitle"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="4dp"
|
||||
android:minHeight="48dp"
|
||||
android:text="@string/locator_title"
|
||||
app:layout_constraintBottom_toTopOf="@+id/locator_text"
|
||||
app:layout_constraintEnd_toEndOf="@+id/locator_btn_pos"
|
||||
app:layout_constraintHorizontal_bias="0.5"
|
||||
app:layout_constraintStart_toStartOf="@+id/locator_btn_neg"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/locator_text"
|
||||
style="@style/DialogText"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:text="@string/locator_text"
|
||||
app:layout_constraintBottom_toTopOf="@+id/locator_layout"
|
||||
app:layout_constraintEnd_toEndOf="@+id/locator_title"
|
||||
app:layout_constraintHorizontal_bias="0.5"
|
||||
app:layout_constraintStart_toStartOf="@+id/locator_title"
|
||||
app:layout_constraintTop_toBottomOf="@+id/locator_title" />
|
||||
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
android:id="@+id/locator_layout"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="8dp"
|
||||
android:hint="@string/locator_hint"
|
||||
android:importantForAutofill="no"
|
||||
android:inputType="number"
|
||||
android:minHeight="48dp"
|
||||
app:endIconMode="clear_text"
|
||||
app:layout_constraintBottom_toTopOf="@+id/locator_btn_neg"
|
||||
app:layout_constraintEnd_toEndOf="@+id/locator_text"
|
||||
app:layout_constraintHorizontal_bias="0.5"
|
||||
app:layout_constraintStart_toStartOf="@+id/locator_text"
|
||||
app:layout_constraintTop_toBottomOf="@+id/locator_text">
|
||||
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
android:id="@+id/locator_edit"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:inputType="textUri" />
|
||||
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
|
||||
<Button
|
||||
android:id="@+id/locator_btn_neg"
|
||||
style="@style/NormalButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="6dp"
|
||||
android:layout_marginTop="12dp"
|
||||
android:layout_marginBottom="6dp"
|
||||
android:text="@string/btn_cancel"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toStartOf="@+id/locator_btn_pos"
|
||||
app:layout_constraintHorizontal_bias="0.5"
|
||||
app:layout_constraintHorizontal_chainStyle="spread_inside"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/locator_layout" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/locator_btn_pos"
|
||||
style="@style/NormalButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="6dp"
|
||||
android:text="@string/btn_accept"
|
||||
app:layout_constraintBaseline_toBaselineOf="@+id/locator_btn_neg"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintHorizontal_bias="0.5"
|
||||
app:layout_constraintStart_toEndOf="@+id/locator_btn_neg" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
</androidx.cardview.widget.CardView>
|
|
@ -1,133 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
style="@style/SurfaceCard"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/position_title"
|
||||
style="@style/DialogTitle"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="4dp"
|
||||
android:minHeight="48dp"
|
||||
android:text="@string/position_title"
|
||||
app:layout_constraintBottom_toTopOf="@+id/position_lat_text"
|
||||
app:layout_constraintEnd_toEndOf="@+id/position_btn_pos"
|
||||
app:layout_constraintHorizontal_bias="0.5"
|
||||
app:layout_constraintStart_toStartOf="@+id/position_btn_neg"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/position_lat_text"
|
||||
style="@style/DialogText"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:text="@string/position_lat_text"
|
||||
app:layout_constraintBottom_toTopOf="@+id/position_lat_layout"
|
||||
app:layout_constraintEnd_toEndOf="@+id/position_title"
|
||||
app:layout_constraintHorizontal_bias="0.5"
|
||||
app:layout_constraintStart_toStartOf="@+id/position_title"
|
||||
app:layout_constraintTop_toBottomOf="@+id/position_title" />
|
||||
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
android:id="@+id/position_lat_layout"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="8dp"
|
||||
android:hint="@string/position_lat_hint"
|
||||
android:importantForAutofill="no"
|
||||
android:inputType="number"
|
||||
android:minHeight="48dp"
|
||||
app:endIconMode="clear_text"
|
||||
app:layout_constraintBottom_toTopOf="@+id/position_lon_text"
|
||||
app:layout_constraintEnd_toEndOf="@+id/position_lat_text"
|
||||
app:layout_constraintHorizontal_bias="0.5"
|
||||
app:layout_constraintStart_toStartOf="@+id/position_lat_text"
|
||||
app:layout_constraintTop_toBottomOf="@+id/position_lat_text">
|
||||
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
android:id="@+id/position_lat_edit"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:digits="0123456789.-"
|
||||
android:inputType="number" />
|
||||
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/position_lon_text"
|
||||
style="@style/DialogText"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="12dp"
|
||||
android:text="@string/position_lon_text"
|
||||
app:layout_constraintBottom_toTopOf="@+id/position_lon_layout"
|
||||
app:layout_constraintEnd_toEndOf="@+id/position_lat_text"
|
||||
app:layout_constraintHorizontal_bias="0.5"
|
||||
app:layout_constraintStart_toStartOf="@+id/position_lat_text"
|
||||
app:layout_constraintTop_toBottomOf="@+id/position_lat_layout" />
|
||||
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
android:id="@+id/position_lon_layout"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="8dp"
|
||||
android:hint="@string/position_lon_hint"
|
||||
android:importantForAutofill="no"
|
||||
android:inputType="number|numberDecimal"
|
||||
android:minHeight="48dp"
|
||||
app:endIconMode="clear_text"
|
||||
app:layout_constraintBottom_toTopOf="@+id/position_btn_neg"
|
||||
app:layout_constraintEnd_toEndOf="@+id/position_lat_layout"
|
||||
app:layout_constraintHorizontal_bias="0.5"
|
||||
app:layout_constraintStart_toStartOf="@+id/position_lat_layout"
|
||||
app:layout_constraintTop_toBottomOf="@+id/position_lon_text">
|
||||
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
android:id="@+id/position_lon_edit"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:digits="0123456789.-"
|
||||
android:inputType="number" />
|
||||
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
|
||||
<Button
|
||||
android:id="@+id/position_btn_neg"
|
||||
style="@style/NormalButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="6dp"
|
||||
android:layout_marginTop="12dp"
|
||||
android:layout_marginBottom="6dp"
|
||||
android:text="@string/btn_cancel"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toStartOf="@+id/position_btn_pos"
|
||||
app:layout_constraintHorizontal_bias="0.5"
|
||||
app:layout_constraintHorizontal_chainStyle="spread_inside"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/position_lon_layout" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/position_btn_pos"
|
||||
style="@style/NormalButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="6dp"
|
||||
android:text="@string/btn_accept"
|
||||
app:layout_constraintBaseline_toBaselineOf="@+id/position_btn_neg"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintHorizontal_bias="0.5"
|
||||
app:layout_constraintStart_toEndOf="@+id/position_btn_neg" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
</androidx.cardview.widget.CardView>
|
Ładowanie…
Reference in New Issue