Added show text labels on the map switch to preference.xml

This commit is contained in:
Arty Bishop committed 2020-11-28 18:35:54 +00:00
1 parent f055d96e5a
commit c58997460c
6 files changed
+51 -15

No files matched your search

@@ -1,6 +1,5 @@
package com.rtbishop.look4sat.ui.mainScreen package com.rtbishop.look4sat.ui.mainScreen
import android.content.SharedPreferences
import android.graphics.Color import android.graphics.Color
import android.graphics.ColorMatrix import android.graphics.ColorMatrix
import android.graphics.ColorMatrixColorFilter import android.graphics.ColorMatrixColorFilter
@@ -17,6 +16,7 @@ import com.rtbishop.look4sat.data.Result
import com.rtbishop.look4sat.data.SatPass import com.rtbishop.look4sat.data.SatPass
import com.rtbishop.look4sat.data.SelectedSat import com.rtbishop.look4sat.data.SelectedSat
import com.rtbishop.look4sat.databinding.FragmentMapBinding import com.rtbishop.look4sat.databinding.FragmentMapBinding
import com.rtbishop.look4sat.utility.PrefsManager
import dagger.hilt.android.AndroidEntryPoint import dagger.hilt.android.AndroidEntryPoint
import org.osmdroid.config.Configuration import org.osmdroid.config.Configuration
import org.osmdroid.tileprovider.tilesource.ITileSource import org.osmdroid.tileprovider.tilesource.ITileSource
@@ -33,14 +33,14 @@ import javax.inject.Inject
class MapFragment : Fragment(R.layout.fragment_map) { class MapFragment : Fragment(R.layout.fragment_map) {
@Inject @Inject
lateinit var preferences: SharedPreferences lateinit var prefsManager: PrefsManager
private lateinit var binding: FragmentMapBinding private lateinit var binding: FragmentMapBinding
private val mapViewModel: MapViewModel by viewModels() private val mapViewModel: MapViewModel by viewModels()
private val sharedViewModel: SharedViewModel by activityViewModels() private val sharedViewModel: SharedViewModel by activityViewModels()
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
Configuration.getInstance().load(requireContext().applicationContext, preferences) Configuration.getInstance().load(requireContext(), prefsManager.preferences)
binding = FragmentMapBinding.bind(view).apply { binding = FragmentMapBinding.bind(view).apply {
mapView.apply { mapView.apply {
setMultiTouchControls(true) setMultiTouchControls(true)
@@ -106,16 +106,34 @@ class MapFragment : Fragment(R.layout.fragment_map) {
binding.apply { binding.apply {
val markers = FolderOverlay() val markers = FolderOverlay()
map.entries.forEach { map.entries.forEach {
Marker(mapView).apply { if (prefsManager.shouldUseTextLabels()) {
setInfoWindow(null) Marker(mapView).apply {
setAnchor(Marker.ANCHOR_CENTER, Marker.ANCHOR_CENTER) setInfoWindow(null)
icon = ContextCompat.getDrawable(requireContext(), R.drawable.ic_map_sat) textLabelFontSize = 24
position = GeoPoint(it.value.lat, it.value.lon) textLabelBackgroundColor = Color.TRANSPARENT
setOnMarkerClickListener { _, _ -> textLabelForegroundColor =
mapViewModel.selectSatellite(it.key) ContextCompat.getColor(requireContext(), R.color.themeLight)
return@setOnMarkerClickListener true setTextIcon(it.key.tle.name)
setAnchor(Marker.ANCHOR_CENTER, Marker.ANCHOR_CENTER)
position = GeoPoint(it.value.lat, it.value.lon)
setOnMarkerClickListener { _, _ ->
mapViewModel.selectSatellite(it.key)
return@setOnMarkerClickListener true
}
markers.add(this)
}
} else {
Marker(mapView).apply {
setInfoWindow(null)
setAnchor(Marker.ANCHOR_CENTER, Marker.ANCHOR_CENTER)
icon = ContextCompat.getDrawable(requireContext(), R.drawable.ic_map_sat)
position = GeoPoint(it.value.lat, it.value.lon)
setOnMarkerClickListener { _, _ ->
mapViewModel.selectSatellite(it.key)
return@setOnMarkerClickListener true
}
markers.add(this)
} }
markers.add(this)
} }
} }
mapView.overlays[3] = markers mapView.overlays[3] = markers
@@ -139,8 +139,8 @@ class MapViewModel @ViewModelInject constructor(val prefsManager: PrefsManager)
private fun getSatFootprint(satPos: SatPos): Overlay { private fun getSatFootprint(satPos: SatPos): Overlay {
val rangePoints = mutableListOf<GeoPoint>() val rangePoints = mutableListOf<GeoPoint>()
satPos.rangeCircle.withIndex().forEach { satPos.rangeCircle.forEach {
val osmPos = getOsmPosition(it.value.lat, it.value.lon, false) val osmPos = getOsmPosition(it.lat, it.lon, false)
rangePoints.add(GeoPoint(osmPos.lat, osmPos.lon)) rangePoints.add(GeoPoint(osmPos.lat, osmPos.lon))
} }
return Polygon().apply { return Polygon().apply {
@@ -26,12 +26,13 @@ import com.github.amsacode.predict4java.GroundStationPosition
import com.rtbishop.look4sat.data.PassPrefs import com.rtbishop.look4sat.data.PassPrefs
import javax.inject.Inject import javax.inject.Inject
class PrefsManager @Inject constructor(private val preferences: SharedPreferences) { class PrefsManager @Inject constructor(val preferences: SharedPreferences) {
companion object { companion object {
const val keyLatitude = "latitude" const val keyLatitude = "latitude"
const val keyLongitude = "longitude" const val keyLongitude = "longitude"
const val keyAltitude = "altitude" const val keyAltitude = "altitude"
const val keyCompass = "compass" const val keyCompass = "compass"
const val keyTextLabels = "shouldUseTextLabels"
const val keyTimeUTC = "timeUTC" const val keyTimeUTC = "timeUTC"
const val keyHoursAhead = "hoursAhead" const val keyHoursAhead = "hoursAhead"
const val keyMinElevation = "minElevation" const val keyMinElevation = "minElevation"
@@ -71,6 +72,10 @@ class PrefsManager @Inject constructor(private val preferences: SharedPreference
return GeomagneticField(lat, lon, alt, System.currentTimeMillis()).declination return GeomagneticField(lat, lon, alt, System.currentTimeMillis()).declination
} }
fun shouldUseTextLabels(): Boolean {
return preferences.getBoolean(keyTextLabels, false)
}
fun shouldUseUTC(): Boolean { fun shouldUseUTC(): Boolean {
return preferences.getBoolean(keyTimeUTC, false) return preferences.getBoolean(keyTimeUTC, false)
} }
+2
View File
@@ -68,6 +68,8 @@
<string name="pref_pass_title">Настройки пролетов спутников</string> <string name="pref_pass_title">Настройки пролетов спутников</string>
<string name="pref_hours_title">Количество часов</string> <string name="pref_hours_title">Количество часов</string>
<string name="pref_elev_title">Минимальная элевация</string> <string name="pref_elev_title">Минимальная элевация</string>
<string name="pref_map_labels_title">Настройки карты</string>
<string name="pref_map_labels">Использовать текстовые метки</string>
<string name="pref_other_title">Другие настройки</string> <string name="pref_other_title">Другие настройки</string>
<string name="pref_compass_title">Использовать компас</string> <string name="pref_compass_title">Использовать компас</string>
<string name="pref_time_utc_title">Показывать время пролета по UTC</string> <string name="pref_time_utc_title">Показывать время пролета по UTC</string>
+2
View File
@@ -85,6 +85,8 @@
<string name="pref_pass_title">Satellite pass preferences</string> <string name="pref_pass_title">Satellite pass preferences</string>
<string name="pref_hours_title">Hours ahead</string> <string name="pref_hours_title">Hours ahead</string>
<string name="pref_elev_title">Minimal elevation</string> <string name="pref_elev_title">Minimal elevation</string>
<string name="pref_map_labels_title">Map preferences</string>
<string name="pref_map_labels">Use text labels instead of icons</string>
<string name="pref_other_title">Other</string> <string name="pref_other_title">Other</string>
<string name="pref_time_utc_title">Show pass time in UTC</string> <string name="pref_time_utc_title">Show pass time in UTC</string>
<string name="pref_compass_title">Use sensors to rotate PolarView</string> <string name="pref_compass_title">Use sensors to rotate PolarView</string>
+9
View File
@@ -52,6 +52,15 @@
app:min="0" app:min="0"
app:showSeekBarValue="true" /> app:showSeekBarValue="true" />
</PreferenceCategory> </PreferenceCategory>
<PreferenceCategory
android:title="@string/pref_map_labels_title"
app:iconSpaceReserved="false">
<SwitchPreference
android:defaultValue="false"
android:key="shouldUseTextLabels"
android:title="@string/pref_map_labels"
app:iconSpaceReserved="false" />
</PreferenceCategory>
<PreferenceCategory <PreferenceCategory
android:title="@string/pref_other_title" android:title="@string/pref_other_title"
app:iconSpaceReserved="false"> app:iconSpaceReserved="false">