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
import android.content.SharedPreferences
import android.graphics.Color
import android.graphics.ColorMatrix
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.SelectedSat
import com.rtbishop.look4sat.databinding.FragmentMapBinding
import com.rtbishop.look4sat.utility.PrefsManager
import dagger.hilt.android.AndroidEntryPoint
import org.osmdroid.config.Configuration
import org.osmdroid.tileprovider.tilesource.ITileSource
@@ -33,14 +33,14 @@ import javax.inject.Inject
class MapFragment : Fragment(R.layout.fragment_map) {
@Inject
lateinit var preferences: SharedPreferences
lateinit var prefsManager: PrefsManager
private lateinit var binding: FragmentMapBinding
private val mapViewModel: MapViewModel by viewModels()
private val sharedViewModel: SharedViewModel by activityViewModels()
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
Configuration.getInstance().load(requireContext().applicationContext, preferences)
Configuration.getInstance().load(requireContext(), prefsManager.preferences)
binding = FragmentMapBinding.bind(view).apply {
mapView.apply {
setMultiTouchControls(true)
@@ -106,16 +106,34 @@ class MapFragment : Fragment(R.layout.fragment_map) {
binding.apply {
val markers = FolderOverlay()
map.entries.forEach {
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
if (prefsManager.shouldUseTextLabels()) {
Marker(mapView).apply {
setInfoWindow(null)
textLabelFontSize = 24
textLabelBackgroundColor = Color.TRANSPARENT
textLabelForegroundColor =
ContextCompat.getColor(requireContext(), R.color.themeLight)
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
@@ -139,8 +139,8 @@ class MapViewModel @ViewModelInject constructor(val prefsManager: PrefsManager)
private fun getSatFootprint(satPos: SatPos): Overlay {
val rangePoints = mutableListOf<GeoPoint>()
satPos.rangeCircle.withIndex().forEach {
val osmPos = getOsmPosition(it.value.lat, it.value.lon, false)
satPos.rangeCircle.forEach {
val osmPos = getOsmPosition(it.lat, it.lon, false)
rangePoints.add(GeoPoint(osmPos.lat, osmPos.lon))
}
return Polygon().apply {
@@ -26,12 +26,13 @@ import com.github.amsacode.predict4java.GroundStationPosition
import com.rtbishop.look4sat.data.PassPrefs
import javax.inject.Inject
class PrefsManager @Inject constructor(private val preferences: SharedPreferences) {
class PrefsManager @Inject constructor(val preferences: SharedPreferences) {
companion object {
const val keyLatitude = "latitude"
const val keyLongitude = "longitude"
const val keyAltitude = "altitude"
const val keyCompass = "compass"
const val keyTextLabels = "shouldUseTextLabels"
const val keyTimeUTC = "timeUTC"
const val keyHoursAhead = "hoursAhead"
const val keyMinElevation = "minElevation"
@@ -71,6 +72,10 @@ class PrefsManager @Inject constructor(private val preferences: SharedPreference
return GeomagneticField(lat, lon, alt, System.currentTimeMillis()).declination
}
fun shouldUseTextLabels(): Boolean {
return preferences.getBoolean(keyTextLabels, false)
}
fun shouldUseUTC(): Boolean {
return preferences.getBoolean(keyTimeUTC, false)
}
+2
View File
@@ -68,6 +68,8 @@
<string name="pref_pass_title">Настройки пролетов спутников</string>
<string name="pref_hours_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_compass_title">Использовать компас</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_hours_title">Hours ahead</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_time_utc_title">Show pass time in UTC</string>
<string name="pref_compass_title">Use sensors to rotate PolarView</string>
+9
View File
@@ -52,6 +52,15 @@
app:min="0"
app:showSeekBarValue="true" />
</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
android:title="@string/pref_other_title"
app:iconSpaceReserved="false">