aboutsummaryrefslogtreecommitdiff
path: root/androidApp/src/main/java/mx/trackermap/TrackerMap/android
diff options
context:
space:
mode:
Diffstat (limited to 'androidApp/src/main/java/mx/trackermap/TrackerMap/android')
-rw-r--r--androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/DetailsActivity.kt7
-rw-r--r--androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/MapFragment.kt17
-rw-r--r--androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/UnitMapFragment.kt8
-rw-r--r--androidApp/src/main/java/mx/trackermap/TrackerMap/android/units/UnitsActivity.kt30
-rw-r--r--androidApp/src/main/java/mx/trackermap/TrackerMap/android/units/UnitsViewModel.kt9
5 files changed, 60 insertions, 11 deletions
diff --git a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/DetailsActivity.kt b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/DetailsActivity.kt
index 27d8756..504cac8 100644
--- a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/DetailsActivity.kt
+++ b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/DetailsActivity.kt
@@ -4,6 +4,7 @@ import android.os.Bundle
import android.util.Log
import androidx.appcompat.app.AppCompatActivity
import com.google.android.material.tabs.TabLayoutMediator
+import mx.trackermap.TrackerMap.android.R
import mx.trackermap.TrackerMap.android.databinding.DetailsActivityBinding
import mx.trackermap.TrackerMap.android.devices.Action
@@ -44,9 +45,9 @@ class DetailsActivity : AppCompatActivity() {
binding.detailsPager.adapter = adapter
TabLayoutMediator(binding.detailsTabs, binding.detailsPager) { tab, position ->
tab.text = when (position) {
- 0 -> "Details"
- 1 -> "Reports"
- else -> "Commands"
+ 0 -> getString(R.string.unit_details)
+ 1 -> getString(R.string.unit_reports)
+ else -> getString(R.string.unit_commands)
}
}.attach()
binding.detailsPager.setCurrentItem(
diff --git a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/MapFragment.kt b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/MapFragment.kt
index 5714aae..9b4d24a 100644
--- a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/MapFragment.kt
+++ b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/MapFragment.kt
@@ -23,6 +23,8 @@ typealias MarkerCallback = (Int?) -> Unit
class MapFragment : GlobeMapFragment() {
+ private var loader: QuadImageLoader? = null
+
data class Marker(
val id: Int,
val latitude: Double,
@@ -54,7 +56,7 @@ class MapFragment : GlobeMapFragment() {
cacheDir.mkdir()
val tileInfo = RemoteTileInfoNew(
- getString(R.string.maps_tile_url),
+ getString(R.string.maps_streets_tile_url),
0,
21
)
@@ -69,8 +71,8 @@ class MapFragment : GlobeMapFragment() {
params.singleLevel = true
params.maxTiles = 25
- val loader = QuadImageLoader(params, tileInfo, baseControl)
- loader.setImageFormat(RenderController.ImageFormat.MaplyImageUShort565)
+ loader = QuadImageLoader(params, tileInfo, baseControl)
+ loader?.setImageFormat(RenderController.ImageFormat.MaplyImageUShort565)
val clusterGenerator = BasicClusterGenerator(
intArrayOf(
@@ -232,7 +234,6 @@ class MapFragment : GlobeMapFragment() {
geofences.forEach { geofence ->
geofence.area?.let { area ->
- Log.d("MainFragment", "Geofence ${geofence.name} = ${geofence.area}")
try {
val geometry = GeometryReader.readGeometry(area)
if (!geometry.isEmpty) {
@@ -254,9 +255,7 @@ class MapFragment : GlobeMapFragment() {
}
}
}
- } catch (e: SFException) {
- e.printStackTrace()
- }
+ } catch (e: SFException) {}
}
}
@@ -289,6 +288,10 @@ class MapFragment : GlobeMapFragment() {
}
}
+ fun setTileInfo(tileInfo: TileInfoNew) {
+ loader?.changeTileInfo(tileInfo)
+ }
+
private fun getIcon(markerType: MarkerType): Bitmap {
return ResourcesCompat.getDrawable(
activity!!.resources,
diff --git a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/UnitMapFragment.kt b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/UnitMapFragment.kt
index 30e3cea..06e5713 100644
--- a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/UnitMapFragment.kt
+++ b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/UnitMapFragment.kt
@@ -93,15 +93,21 @@ class UnitMapFragment(private val unitsViewModel: UnitsViewModel) : UnitFragment
}
}
+ unitsViewModel.mapTileInfo.observe(viewLifecycleOwner) { tileInfo ->
+ Log.d("UnitMapFragment", "Loading layer!")
+ unitsMapFragment.setTileInfo(tileInfo)
+ }
+
unitsViewModel.geofences.observe(viewLifecycleOwner) { geofences ->
unitsMapFragment.displayGeofences(geofences.values.toTypedArray())
}
}
private fun removeObservers() {
- Log.d("MapFragment", "removeObservers()")
+ Log.d("UnitMapFragment", "removeObservers()")
unitsViewModel.units.removeObservers(viewLifecycleOwner)
unitsViewModel.selectedUnit.removeObservers(viewLifecycleOwner)
+ unitsViewModel.mapTileInfo.removeObservers(viewLifecycleOwner)
unitsViewModel.geofences.removeObservers(viewLifecycleOwner)
}
diff --git a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/units/UnitsActivity.kt b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/units/UnitsActivity.kt
index 5213577..5a9f9ad 100644
--- a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/units/UnitsActivity.kt
+++ b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/units/UnitsActivity.kt
@@ -3,7 +3,9 @@ package mx.trackermap.TrackerMap.android.units
import android.content.Intent
import android.os.Bundle
import android.util.Log
+import android.view.View
import androidx.appcompat.app.AppCompatActivity
+import androidx.appcompat.widget.PopupMenu
import androidx.core.widget.doAfterTextChanged
import androidx.fragment.app.commit
import kotlinx.coroutines.DelicateCoroutinesApi
@@ -62,12 +64,32 @@ class UnitsActivity : AppCompatActivity() {
binding.displayModeToggle.setOnClickListener {
unitsViewModel.toggleDisplayMode()
}
+ binding.mapLayerToggle.setOnClickListener {
+ showLayersPopUp(it)
+ }
binding.searchInput.doAfterTextChanged {
Log.d("UnitsActivity", "Search changed to ${it.toString()}")
unitsViewModel.search(it.toString())
}
}
+ private fun showLayersPopUp(view: View) {
+ val popOver = PopupMenu(this, view)
+ popOver.menuInflater.inflate(R.menu.map_layers, popOver.menu)
+ popOver.setOnMenuItemClickListener { item ->
+ unitsViewModel.setMapLayer(
+ when (item.itemId) {
+ R.id.layerStreets -> getString(R.string.maps_streets_tile_url)
+ R.id.layerSatellite -> getString(R.string.maps_satellite_url)
+ R.id.layerHybrid -> getString(R.string.maps_hybrid_url)
+ else -> getString(R.string.maps_streets_tile_url)
+ }
+ )
+ true
+ }
+ popOver.show()
+ }
+
private fun setupObservers() {
unitsViewModel.unitsDisplayMode.observe(this) { displayMode ->
binding.displayModeToggle.setImageResource(
@@ -85,10 +107,18 @@ class UnitsActivity : AppCompatActivity() {
}
)
+ binding.mapLayerToggle.visibility =
+ when (displayMode) {
+ UnitsViewModel.UnitsDisplayMode.LIST -> View.GONE
+ UnitsViewModel.UnitsDisplayMode.MAP -> View.VISIBLE
+ else -> View.GONE
+ }
+
val newFragment =
when (displayMode) {
UnitsViewModel.UnitsDisplayMode.LIST -> devicesFragment
UnitsViewModel.UnitsDisplayMode.MAP -> mapFragment
+ else -> devicesFragment
}
supportFragmentManager.commit {
replace(R.id.displayContainer, newFragment)
diff --git a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/units/UnitsViewModel.kt b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/units/UnitsViewModel.kt
index c0dc7c6..6a04cf4 100644
--- a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/units/UnitsViewModel.kt
+++ b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/units/UnitsViewModel.kt
@@ -2,6 +2,8 @@ package mx.trackermap.TrackerMap.android.units
import android.util.Log
import androidx.lifecycle.*
+import com.mousebird.maply.RemoteTileInfoNew
+import com.mousebird.maply.TileInfoNew
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.launch
@@ -28,12 +30,14 @@ class UnitsViewModel(
private var _unitsDisplayMode = MutableLiveData(UnitsDisplayMode.LIST)
private var _units = MutableLiveData<List<UnitInformation>>()
private var _selectedUnit = MutableLiveData<UnitInformation?>()
+ private var _mapTileInfo = MutableLiveData<TileInfoNew>()
private var _geofences = MutableLiveData<Map<Int, Geofence>>()
val searchQuery: LiveData<String> get() = _searchQuery
val unitsDisplayMode: LiveData<UnitsDisplayMode> get() = _unitsDisplayMode
val units: LiveData<List<UnitInformation>> get() = _units
val selectedUnit: LiveData<UnitInformation?> get() = _selectedUnit
+ val mapTileInfo: LiveData<TileInfoNew> get() = _mapTileInfo
val geofences: LiveData<Map<Int, Geofence>> get() = _geofences
init {
@@ -82,6 +86,11 @@ class UnitsViewModel(
_unitsDisplayMode.postValue(displayMode)
}
+ fun setMapLayer(url: String, minZoom: Int = 0, maxZoom: Int = 21) {
+ val tileInfo = RemoteTileInfoNew(url, minZoom, maxZoom)
+ _mapTileInfo.postValue(tileInfo)
+ }
+
fun toggleDisplayMode() {
Log.d("UnitsViewModel", "Toggling Display mode")
val newDisplayMode =