Restored manual location input functionality #40
This commit is contained in:
1 parent
9d6dbc8d31
commit
ffd1fc1551
10 files changed
+196
-10
No files matched your search
@@ -59,13 +59,14 @@ class LocationHandler @Inject constructor(
|
||||
|
||||
override fun setStationPosition(latitude: Double, longitude: Double) {
|
||||
if (QthConverter.isValidPosition(latitude, longitude)) {
|
||||
val tempLon = if (longitude > 180.0) longitude - 180 else longitude
|
||||
val newLat = latitude.round(4)
|
||||
val newLon = longitude.round(4)
|
||||
val newLon = tempLon.round(4)
|
||||
currentPosition = GeoPos(newLat, newLon)
|
||||
settingsHandler.saveStationPosition(newLat, newLon)
|
||||
_stationPosition.value = DataState.Success(currentPosition)
|
||||
} else _stationPosition.value =
|
||||
DataState.Error(context.getString(R.string.pref_pos_gps_null))
|
||||
DataState.Error(context.getString(R.string.pref_pos_manual_error))
|
||||
}
|
||||
|
||||
override fun setPositionFromGps() {
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
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 com.rtbishop.look4sat.R
|
||||
import com.rtbishop.look4sat.databinding.DialogLocationBinding
|
||||
import com.rtbishop.look4sat.domain.ILocationHandler
|
||||
import com.rtbishop.look4sat.presentation.setNavResult
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import javax.inject.Inject
|
||||
|
||||
@AndroidEntryPoint
|
||||
class LocationDialog : AppCompatDialogFragment() {
|
||||
|
||||
@Inject
|
||||
lateinit var locationHandler: ILocationHandler
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, group: ViewGroup?, state: Bundle?): View? {
|
||||
return inflater.inflate(R.layout.dialog_location, group, false)
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, state: Bundle?) {
|
||||
super.onViewCreated(view, state)
|
||||
DialogLocationBinding.bind(view).run {
|
||||
dialog?.window?.setBackgroundDrawableResource(R.color.transparent)
|
||||
dialog?.window?.setLayout(
|
||||
(resources.displayMetrics.widthPixels * 0.94).toInt(),
|
||||
WindowManager.LayoutParams.WRAP_CONTENT
|
||||
)
|
||||
val location = locationHandler.getStationPosition()
|
||||
locationLatEdit.setText(location.latitude.toString())
|
||||
locationLonEdit.setText(location.longitude.toString())
|
||||
locationPosBtn.setOnClickListener {
|
||||
val latitude = try {
|
||||
locationLatEdit.text.toString().toDouble()
|
||||
} catch (exception: Exception) {
|
||||
180.0
|
||||
}
|
||||
val longitude = try {
|
||||
locationLonEdit.text.toString().toDouble()
|
||||
} catch (exception: Exception) {
|
||||
400.0
|
||||
}
|
||||
setNavResult("location", Pair(latitude, longitude))
|
||||
dismiss()
|
||||
}
|
||||
locationNegBtn.setOnClickListener { dismiss() }
|
||||
}
|
||||
}
|
||||
}
|
||||
+7
@@ -111,10 +111,17 @@ class SettingsFragment : Fragment(R.layout.fragment_settings) {
|
||||
binding.settingsLocation.locationBtnGps.setOnClickListener {
|
||||
locationRequest.launch(arrayOf(locationFine, locationCoarse))
|
||||
}
|
||||
binding.settingsLocation.locationBtnManual.setOnClickListener {
|
||||
val action = SettingsFragmentDirections.actionPrefsToLocation()
|
||||
findNavController().navigate(action)
|
||||
}
|
||||
binding.settingsLocation.locationBtnQth.setOnClickListener {
|
||||
val action = SettingsFragmentDirections.actionPrefsToLocator()
|
||||
findNavController().navigate(action)
|
||||
}
|
||||
getNavResult<Pair<Double, Double>>(R.id.nav_settings, "location") { location ->
|
||||
viewModel.setStationPosition(location.first, location.second)
|
||||
}
|
||||
getNavResult<String>(R.id.nav_settings, "locator") { locator ->
|
||||
viewModel.setPositionFromQth(locator)
|
||||
}
|
||||
|
||||
+2
@@ -61,6 +61,8 @@ class SettingsViewModel @Inject constructor(
|
||||
|
||||
fun getStationPosition(): GeoPos = locationHandler.getStationPosition()
|
||||
|
||||
fun setStationPosition(lat: Double, lon: Double) = locationHandler.setStationPosition(lat, lon)
|
||||
|
||||
fun setPositionFromGps() = locationHandler.setPositionFromGps()
|
||||
|
||||
fun setPositionFromNet() = locationHandler.setPositionFromNet()
|
||||
|
||||
@@ -59,30 +59,41 @@
|
||||
style="@style/NormalButton"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="4dp"
|
||||
android:layout_marginTop="4dp"
|
||||
android:layout_marginBottom="4dp"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:drawableStart="@drawable/ic_gps"
|
||||
android:text="@string/location_gps"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toStartOf="@+id/location_btn_qth"
|
||||
app:layout_constraintEnd_toStartOf="@+id/location_btn_manual"
|
||||
app:layout_constraintHorizontal_bias="0.5"
|
||||
app:layout_constraintHorizontal_chainStyle="spread_inside"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/location_lat" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/location_btn_manual"
|
||||
style="@style/NormalButton"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:drawableStart="@drawable/ic_gps"
|
||||
android:text="Manual"
|
||||
app:layout_constraintBaseline_toBaselineOf="@+id/location_btn_gps"
|
||||
app:layout_constraintEnd_toStartOf="@+id/location_btn_qth"
|
||||
app:layout_constraintHorizontal_bias="0.5"
|
||||
app:layout_constraintStart_toEndOf="@+id/location_btn_gps" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/location_btn_qth"
|
||||
style="@style/NormalButton"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="4dp"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:drawableStart="@drawable/ic_qth"
|
||||
android:text="@string/location_qth"
|
||||
app:layout_constraintBaseline_toBaselineOf="@+id/location_btn_gps"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintHorizontal_bias="0.5"
|
||||
app:layout_constraintStart_toEndOf="@+id/location_btn_gps" />
|
||||
app:layout_constraintStart_toEndOf="@+id/location_btn_manual" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
|
||||
@@ -0,0 +1,102 @@
|
||||
<?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/location_title"
|
||||
style="@style/DialogTitle"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="4dp"
|
||||
android:minHeight="48dp"
|
||||
android:text="@string/dialog_filter_passes"
|
||||
app:layout_constraintBottom_toTopOf="@+id/location_lat_layout"
|
||||
app:layout_constraintEnd_toEndOf="@+id/location_pos_btn"
|
||||
app:layout_constraintStart_toStartOf="@+id/location_neg_btn"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
android:id="@+id/location_lat_layout"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="4dp"
|
||||
android:layout_marginEnd="4dp"
|
||||
android:hint="@string/pref_hours_ahead_hint"
|
||||
android:importantForAutofill="no"
|
||||
android:inputType="number"
|
||||
android:minHeight="48dp"
|
||||
app:endIconMode="clear_text"
|
||||
app:layout_constraintBottom_toTopOf="@+id/location_lon_layout"
|
||||
app:layout_constraintEnd_toEndOf="@+id/location_title"
|
||||
app:layout_constraintStart_toStartOf="@+id/location_title"
|
||||
app:layout_constraintTop_toBottomOf="@+id/location_title">
|
||||
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
android:id="@+id/location_lat_edit"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:inputType="textUri" />
|
||||
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
android:id="@+id/location_lon_layout"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="8dp"
|
||||
android:hint="@string/pref_min_el_hint"
|
||||
android:importantForAutofill="no"
|
||||
android:inputType="number|numberDecimal"
|
||||
android:minHeight="48dp"
|
||||
app:endIconMode="clear_text"
|
||||
app:layout_constraintBottom_toTopOf="@+id/location_neg_btn"
|
||||
app:layout_constraintEnd_toEndOf="@+id/location_lat_layout"
|
||||
app:layout_constraintStart_toStartOf="@+id/location_lat_layout"
|
||||
app:layout_constraintTop_toBottomOf="@+id/location_lat_layout">
|
||||
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
android:id="@+id/location_lon_edit"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:inputType="textUri" />
|
||||
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
|
||||
<Button
|
||||
android:id="@+id/location_neg_btn"
|
||||
style="@style/NormalButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_marginTop="12dp"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:text="@string/btn_cancel"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toStartOf="@+id/location_pos_btn"
|
||||
app:layout_constraintHorizontal_bias="0.5"
|
||||
app:layout_constraintHorizontal_chainStyle="spread_inside"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/location_lon_layout" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/location_pos_btn"
|
||||
style="@style/NormalButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:text="@string/btn_accept"
|
||||
app:layout_constraintBaseline_toBaselineOf="@+id/location_neg_btn"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintHorizontal_bias="0.5"
|
||||
app:layout_constraintStart_toEndOf="@+id/location_neg_btn" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
</androidx.cardview.widget.CardView>
|
||||
@@ -53,6 +53,9 @@
|
||||
<action
|
||||
android:id="@+id/action_prefs_to_sources"
|
||||
app:destination="@id/nav_sources" />
|
||||
<action
|
||||
android:id="@+id/action_prefs_to_location"
|
||||
app:destination="@id/nav_location" />
|
||||
<action
|
||||
android:id="@+id/action_prefs_to_locator"
|
||||
app:destination="@id/nav_locator" />
|
||||
@@ -65,6 +68,10 @@
|
||||
android:id="@+id/nav_modes"
|
||||
android:name="com.rtbishop.look4sat.presentation.entriesScreen.ModesDialog"
|
||||
tools:layout="@layout/dialog_modes" />
|
||||
<dialog
|
||||
android:id="@+id/nav_location"
|
||||
android:name="com.rtbishop.look4sat.presentation.settingsScreen.LocationDialog"
|
||||
tools:layout="@layout/dialog_location" />
|
||||
<dialog
|
||||
android:id="@+id/nav_locator"
|
||||
android:name="com.rtbishop.look4sat.presentation.settingsScreen.LocatorDialog"
|
||||
|
||||
@@ -52,6 +52,7 @@
|
||||
<string name="pref_gsp_title">Местоположение наземной станции</string>
|
||||
<string name="pref_pos_gps">Установить позицию по данным GPS</string>
|
||||
<string name="pref_pos_gps_null">Нет данных геолокации</string>
|
||||
<string name="pref_pos_manual_error">Введены неверные данные</string>
|
||||
<string name="pref_pos_gps_error">Нет разрешения использовать геоданные</string>
|
||||
<string name="pref_pos_qth">Установить позицию по локатору QTH</string>
|
||||
<string name="pref_pos_qth_error">Неправильный локатор QTH</string>
|
||||
|
||||
@@ -68,6 +68,7 @@
|
||||
<string name="pref_gsp_title">Ground station position</string>
|
||||
<string name="pref_pos_gps">Set position from GPS data</string>
|
||||
<string name="pref_pos_gps_null">No geolocation data</string>
|
||||
<string name="pref_pos_manual_error">Invalid location entered</string>
|
||||
<string name="pref_pos_gps_error">Check your location permissions</string>
|
||||
<string name="pref_pos_qth">Set position from QTH locator</string>
|
||||
<string name="pref_pos_qth_error">Invalid QTH locator</string>
|
||||
|
||||
@@ -38,7 +38,7 @@ object QthConverter {
|
||||
|
||||
fun positionToQth(lat: Double, lon: Double): String? {
|
||||
if (!isValidPosition(lat, lon)) return null
|
||||
val tempLon = if (lon > 180.0) lon - 360 else lon
|
||||
val tempLon = if (lon > 180.0) lon - 180 else lon
|
||||
val upper = "ABCDEFGHIJKLMNOPQRSTUVWX"
|
||||
val lower = "abcdefghijklmnopqrstuvwx"
|
||||
val longitude = tempLon + 180
|
||||
|
||||
Reference in new issue
Block a user