From fcd87cc7b3d48c7c077fe795bb7394dc2ff0834d Mon Sep 17 00:00:00 2001 From: PWRxPSYCHO Date: Sun, 9 Oct 2022 18:42:25 -0400 Subject: [PATCH 01/12] added new map source and updated tile server for clarity maps --- app/src/main/res/values/arrays.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml index 00cf441a..f9b5b297 100644 --- a/app/src/main/res/values/arrays.xml +++ b/app/src/main/res/values/arrays.xml @@ -90,6 +90,7 @@ OpenStreetMap USGS TOPO Open TOPO + ESRI World TOPO USGS Satellite ESRI World Overview From 50cbc262f2194377abc35aa39e2c4be4a4d91937 Mon Sep 17 00:00:00 2001 From: PWRxPSYCHO Date: Mon, 10 Oct 2022 08:50:02 -0400 Subject: [PATCH 02/12] added new map source and updated tile server for clarity maps --- .../mesh/model/map/CustomTileSource.kt | 26 +++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/geeksville/mesh/model/map/CustomTileSource.kt b/app/src/main/java/com/geeksville/mesh/model/map/CustomTileSource.kt index d9b9e5ee..539f410f 100644 --- a/app/src/main/java/com/geeksville/mesh/model/map/CustomTileSource.kt +++ b/app/src/main/java/com/geeksville/mesh/model/map/CustomTileSource.kt @@ -11,10 +11,11 @@ class CustomTileSource { companion object { // Map Server information: https://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer + //"https://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/" // Arcgis Information: https://www.arcgis.com/home/item.html?id=10df2279f9684e4a9f6a7f08febac2a9 private val ESRI_IMAGERY = object : OnlineTileSourceBase( - "ESRI World Overview", 0, 18, 256, ".jpg", arrayOf( - "https://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/" + "ESRI World Overview", 1, 20, 256, ".jpg", arrayOf( + "https://clarity.maptiles.arcgis.com/arcgis/rest/services/World_Imagery/MapServer/tile/" ), "Esri, Maxar, Earthstar Geographics, and the GIS User Community", TileSourcePolicy( 4, @@ -32,6 +33,26 @@ class CustomTileSource { } } + private val ESRI_WORLD_TOPO = object : OnlineTileSourceBase( + "ESRI World TOPO", 1, 20, 256, ".jpg", arrayOf( + "https://server.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer/tile/" + ), "Esri, HERE, Garmin, FAO, NOAA, USGS, © OpenStreetMap contributors, and the GIS User Community ", + TileSourcePolicy( + 4, + TileSourcePolicy.FLAG_NO_BULK + or TileSourcePolicy.FLAG_NO_PREVENTIVE + or TileSourcePolicy.FLAG_USER_AGENT_MEANINGFUL + or TileSourcePolicy.FLAG_USER_AGENT_NORMALIZED + ) + ) { + override fun getTileURLString(pMapTileIndex: Long): String { + return baseUrl + (MapTileIndex.getZoom(pMapTileIndex) + .toString() + "/" + MapTileIndex.getY(pMapTileIndex) + + "/" + MapTileIndex.getX(pMapTileIndex) + + mImageFilenameEnding) + } + } + //Transparent Background //https://earthlive.maptiles.arcgis.com/arcgis/rest/services/GOES/GOES31D/MapServer/tile/ private val NOAA_RADAR = object : OnlineTileSourceBase( @@ -153,6 +174,7 @@ class CustomTileSource { MAPNIK, USGS_TOPO, OPEN_TOPO, + ESRI_WORLD_TOPO, USGS_SAT, ESRI_IMAGERY, ) From 2c08dd7cd0d7cf0020c5baca130ee388ddb5e625 Mon Sep 17 00:00:00 2001 From: PWRxPSYCHO Date: Mon, 10 Oct 2022 22:41:02 -0400 Subject: [PATCH 03/12] Working on overlays --- .../mesh/model/map/CustomTileSource.kt | 73 ++++++++++++++----- .../mesh/model/map/NOAAWmsTileSource.kt | 22 ++++-- .../com/geeksville/mesh/ui/MapFragment.kt | 20 +++++ 3 files changed, 88 insertions(+), 27 deletions(-) diff --git a/app/src/main/java/com/geeksville/mesh/model/map/CustomTileSource.kt b/app/src/main/java/com/geeksville/mesh/model/map/CustomTileSource.kt index 539f410f..b283e974 100644 --- a/app/src/main/java/com/geeksville/mesh/model/map/CustomTileSource.kt +++ b/app/src/main/java/com/geeksville/mesh/model/map/CustomTileSource.kt @@ -8,11 +8,51 @@ import org.osmdroid.util.MapTileIndex class CustomTileSource { - companion object { - // Map Server information: https://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer - //"https://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/" - // Arcgis Information: https://www.arcgis.com/home/item.html?id=10df2279f9684e4a9f6a7f08febac2a9 + //https://tile.openweathermap.org/map/{layer}/{z}/{x}/{y}.png?appid={API key} + companion object { + val OPENWEATHER_RADAR = object : OnlineTileSourceBase( + "Open Weather Map", 1, 15, 256, ".png", arrayOf( + "https://tile.openweathermap.org/map/" + ), "Openweathermap", + TileSourcePolicy( + 4, + TileSourcePolicy.FLAG_NO_BULK + or TileSourcePolicy.FLAG_NO_PREVENTIVE + or TileSourcePolicy.FLAG_USER_AGENT_MEANINGFUL + or TileSourcePolicy.FLAG_USER_AGENT_NORMALIZED + ) + ) { + //{layer}/{z}/{x}/{y}.png?appid={API key} + override fun getTileURLString(pMapTileIndex: Long): String { + return baseUrl + "precipitation/" + (MapTileIndex.getZoom(pMapTileIndex) + .toString() + "/" + MapTileIndex.getX(pMapTileIndex) + + "/" + MapTileIndex.getY(pMapTileIndex) + + mImageFilenameEnding + "?appid=") + } + } + // +// val RAIN_VIEWER = object : OnlineTileSourceBase( +// "RainViewer", 1, 15, 256, ".png", arrayOf( +// "https://tilecache.rainviewer.com/v2/coverage/" +// ), "RainViewer", +// TileSourcePolicy( +// 4, +// TileSourcePolicy.FLAG_NO_BULK +// or TileSourcePolicy.FLAG_NO_PREVENTIVE +// or TileSourcePolicy.FLAG_USER_AGENT_MEANINGFUL +// or TileSourcePolicy.FLAG_USER_AGENT_NORMALIZED +// ) +// ) { +// override fun getTileURLString(pMapTileIndex: Long): String { +// return baseUrl + (MapTileIndex.getZoom(pMapTileIndex) +// .toString() + "/" + MapTileIndex.getY(pMapTileIndex) +// + "/" + MapTileIndex.getX(pMapTileIndex) +// + mImageFilenameEnding) +// } +// } + + private val ESRI_IMAGERY = object : OnlineTileSourceBase( "ESRI World Overview", 1, 20, 256, ".jpg", arrayOf( "https://clarity.maptiles.arcgis.com/arcgis/rest/services/World_Imagery/MapServer/tile/" @@ -34,9 +74,15 @@ class CustomTileSource { } private val ESRI_WORLD_TOPO = object : OnlineTileSourceBase( - "ESRI World TOPO", 1, 20, 256, ".jpg", arrayOf( + "ESRI World TOPO", + 1, + 20, + 256, + ".jpg", + arrayOf( "https://server.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer/tile/" - ), "Esri, HERE, Garmin, FAO, NOAA, USGS, © OpenStreetMap contributors, and the GIS User Community ", + ), + "Esri, HERE, Garmin, FAO, NOAA, USGS, © OpenStreetMap contributors, and the GIS User Community ", TileSourcePolicy( 4, TileSourcePolicy.FLAG_NO_BULK @@ -62,7 +108,7 @@ class CustomTileSource { 256, "", arrayOf( - "https://earthlive.maptiles.arcgis.com/arcgis/rest/services/GOES/GOES31C/MapServer/tile/" + "https://earthlive.maptiles.arcgis.com/arcgis/rest/services/GOES/GOES31D/MapServer/tile/" ), "Dataset Citation: GOES-R Calibration Working Group and GOES-R Series Program, (2017): NOAA GOES-R Series Advanced Baseline Imager (ABI) Level 1b Radiances Band 13. NOAA National Centers for Environmental Information. doi:10.7289/V5BV7DSR", TileSourcePolicy( @@ -137,18 +183,7 @@ class CustomTileSource { "Recent Weather Radar", arrayOf("https://new.nowcoast.noaa.gov/arcgis/services/nowcoast/radar_meteo_imagery_nexrad_time/MapServer/WmsServer?"), "1", - "1.3.0", - "", - "EPSG%3A3857", - "", - "image/png" - ) - - val NOAA_SATELLITE_RADAR_WMS = NOAAWmsTileSource( - "Weather Satellite Imagery", - arrayOf("https://new.nowcoast.noaa.gov/arcgis/services/nowcoast/sat_meteo_imagery_time/MapServer/WmsServer?"), - "1,5,9,13,17,21,25", - "1.3.0", + "1.1.0", "", "EPSG%3A3857", "", diff --git a/app/src/main/java/com/geeksville/mesh/model/map/NOAAWmsTileSource.kt b/app/src/main/java/com/geeksville/mesh/model/map/NOAAWmsTileSource.kt index 434a929e..221ce943 100644 --- a/app/src/main/java/com/geeksville/mesh/model/map/NOAAWmsTileSource.kt +++ b/app/src/main/java/com/geeksville/mesh/model/map/NOAAWmsTileSource.kt @@ -15,10 +15,10 @@ open class NOAAWmsTileSource( layername: String, version: String, time: String?, - crs: String, + srs: String, style: String?, - format: String -) : OnlineTileSourceBase(aName, 0, 22, 256, "png", aBaseUrl) { + format: String, +) : OnlineTileSourceBase(aName, 0, 9, 256, "png", aBaseUrl) { // array indexes for array to hold bounding boxes. private val MINX = 0 @@ -37,8 +37,7 @@ open class NOAAWmsTileSource( private val MAP_SIZE = 20037508.34789244 * 2 private var layer = "" private var version = "1.1.0" - private var crs = "EPSG:3A3857" //used by geo server - private var size = "" + private var srs = "EPSG%3A3857" //used by geo server private var format = "" private var time = "" private var style: String? = null @@ -49,7 +48,7 @@ open class NOAAWmsTileSource( Log.i(IMapView.LOGTAG, "WMS support is BETA. Please report any issues") layer = layername this.version = version - this.crs = crs + this.srs = srs this.style = style this.format = format if (time != null) this.time = time @@ -128,7 +127,8 @@ open class NOAAWmsTileSource( sb.append("&transparent=true") sb.append("&height=").append(Resources.getSystem().displayMetrics.heightPixels) sb.append("&width=").append(Resources.getSystem().displayMetrics.widthPixels) - sb.append("&crs=").append(crs) + sb.append("&srs=").append(srs) + sb.append("&size=").append(getSize()) sb.append("&bbox=") val bbox = getBoundingBox( MapTileIndex.getX(pMapTileIndex), @@ -139,8 +139,14 @@ open class NOAAWmsTileSource( sb.append(bbox[MINY]).append(",") sb.append(bbox[MAXX]).append(",") sb.append(bbox[MAXY]) - Log.i(IMapView.LOGTAG, sb.toString()) return sb.toString() } + + private fun getSize(): String { + val height = Resources.getSystem().displayMetrics.heightPixels + val width = Resources.getSystem().displayMetrics.widthPixels + return "$width,$height" + + } } \ No newline at end of file diff --git a/app/src/main/java/com/geeksville/mesh/ui/MapFragment.kt b/app/src/main/java/com/geeksville/mesh/ui/MapFragment.kt index 4b44917a..e745e44d 100644 --- a/app/src/main/java/com/geeksville/mesh/ui/MapFragment.kt +++ b/app/src/main/java/com/geeksville/mesh/ui/MapFragment.kt @@ -3,6 +3,7 @@ package com.geeksville.mesh.ui import android.app.AlertDialog import android.content.Context import android.content.SharedPreferences +import android.content.res.Resources import android.graphics.Canvas import android.graphics.Color import android.graphics.Paint @@ -22,6 +23,7 @@ import com.geeksville.mesh.databinding.MapViewBinding import com.geeksville.mesh.model.UIViewModel import com.geeksville.mesh.model.map.CustomOverlayManager import com.geeksville.mesh.model.map.CustomTileSource +import com.geeksville.mesh.model.map.NOAAWmsTileSource import com.geeksville.mesh.util.formatAgo import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.google.android.material.floatingactionbutton.FloatingActionButton @@ -31,6 +33,7 @@ import org.osmdroid.config.Configuration import org.osmdroid.events.MapListener import org.osmdroid.events.ScrollEvent import org.osmdroid.events.ZoomEvent +import org.osmdroid.tileprovider.MapTileProviderBasic import org.osmdroid.tileprovider.cachemanager.CacheManager import org.osmdroid.tileprovider.cachemanager.CacheManager.CacheManagerCallback import org.osmdroid.tileprovider.modules.SqlTileWriter @@ -46,6 +49,7 @@ import org.osmdroid.views.overlay.* import org.osmdroid.views.overlay.gridlines.LatLonGridlineOverlay2 import java.io.File import kotlin.math.pow +import android.util.DisplayMetrics @AndroidEntryPoint @@ -377,6 +381,7 @@ class MapFragment : ScreenFragment("Map"), Logging, View.OnClickListener { dialog.dismiss() map.setTileSource(loadOnlineTileSourceBase()) renderDownloadButton() + drawOverlays() } val dialog = builder.create() dialog.show() @@ -479,6 +484,21 @@ class MapFragment : ScreenFragment("Map"), Logging, View.OnClickListener { createLatLongGrid(false) map.overlayManager.addAll(nodeLayer, nodePositions) map.overlayManager.addAll(nodeLayer, wayPoints) + if (map.tileProvider.tileSource.name() + .equals(CustomTileSource.getTileSource("ESRI World TOPO").name()) + ) { + val layer = TilesOverlay( + MapTileProviderBasic( + activity, + CustomTileSource.NOAA_RADAR_WMS + ), context + ) + layer.loadingBackgroundColor = Color.TRANSPARENT + layer.loadingLineColor = Color.TRANSPARENT + map.overlayManager.add(layer) + } else { + map.overlays.clear() + } map.invalidate() } From 42cba353fa220306bdabfbf4eb5ac6843356bbbe Mon Sep 17 00:00:00 2001 From: PWRxPSYCHO Date: Tue, 11 Oct 2022 18:36:44 -0400 Subject: [PATCH 04/12] Setup new class to handle "auth" urls --- .../mesh/model/map/CustomTileSource.kt | 47 +++---------------- .../mesh/model/map/NOAAWmsTileSource.kt | 11 ++++- .../mesh/model/map/OnlineTileSourceAuth.kt | 47 +++++++++++++++++++ .../com/geeksville/mesh/ui/MapFragment.kt | 2 +- 4 files changed, 64 insertions(+), 43 deletions(-) create mode 100644 app/src/main/java/com/geeksville/mesh/model/map/OnlineTileSourceAuth.kt diff --git a/app/src/main/java/com/geeksville/mesh/model/map/CustomTileSource.kt b/app/src/main/java/com/geeksville/mesh/model/map/CustomTileSource.kt index b283e974..bcfaecd1 100644 --- a/app/src/main/java/com/geeksville/mesh/model/map/CustomTileSource.kt +++ b/app/src/main/java/com/geeksville/mesh/model/map/CustomTileSource.kt @@ -9,10 +9,9 @@ import org.osmdroid.util.MapTileIndex class CustomTileSource { - //https://tile.openweathermap.org/map/{layer}/{z}/{x}/{y}.png?appid={API key} companion object { - val OPENWEATHER_RADAR = object : OnlineTileSourceBase( - "Open Weather Map", 1, 15, 256, ".png", arrayOf( + val OPENWEATHER_RADAR = OnlineTileSourceAuth( + "Open Weather Map", 1, 22, 256, ".png", arrayOf( "https://tile.openweathermap.org/map/" ), "Openweathermap", TileSourcePolicy( @@ -21,16 +20,10 @@ class CustomTileSource { or TileSourcePolicy.FLAG_NO_PREVENTIVE or TileSourcePolicy.FLAG_USER_AGENT_MEANINGFUL or TileSourcePolicy.FLAG_USER_AGENT_NORMALIZED - ) - ) { - //{layer}/{z}/{x}/{y}.png?appid={API key} - override fun getTileURLString(pMapTileIndex: Long): String { - return baseUrl + "precipitation/" + (MapTileIndex.getZoom(pMapTileIndex) - .toString() + "/" + MapTileIndex.getX(pMapTileIndex) - + "/" + MapTileIndex.getY(pMapTileIndex) - + mImageFilenameEnding + "?appid=") - } - } + ), + "precipitation", + "" + ) // // val RAIN_VIEWER = object : OnlineTileSourceBase( // "RainViewer", 1, 15, 256, ".png", arrayOf( @@ -98,34 +91,6 @@ class CustomTileSource { + mImageFilenameEnding) } } - - //Transparent Background - //https://earthlive.maptiles.arcgis.com/arcgis/rest/services/GOES/GOES31D/MapServer/tile/ - private val NOAA_RADAR = object : OnlineTileSourceBase( - "NOAA GOES Radar", - 0, - 18, - 256, - "", - arrayOf( - "https://earthlive.maptiles.arcgis.com/arcgis/rest/services/GOES/GOES31D/MapServer/tile/" - ), - "Dataset Citation: GOES-R Calibration Working Group and GOES-R Series Program, (2017): NOAA GOES-R Series Advanced Baseline Imager (ABI) Level 1b Radiances Band 13. NOAA National Centers for Environmental Information. doi:10.7289/V5BV7DSR", - TileSourcePolicy( - 2, - TileSourcePolicy.FLAG_NO_BULK - or TileSourcePolicy.FLAG_NO_PREVENTIVE - or TileSourcePolicy.FLAG_USER_AGENT_MEANINGFUL - or TileSourcePolicy.FLAG_USER_AGENT_NORMALIZED - ) - ) { - override fun getTileURLString(pMapTileIndex: Long): String { - return baseUrl + (MapTileIndex.getZoom(pMapTileIndex) - .toString() + "/" + MapTileIndex.getY(pMapTileIndex) - + "/" + MapTileIndex.getX(pMapTileIndex) - + mImageFilenameEnding) - } - } private val USGS_HYDRO_CACHE = object : OnlineTileSourceBase( "USGS Hydro Cache", 0, diff --git a/app/src/main/java/com/geeksville/mesh/model/map/NOAAWmsTileSource.kt b/app/src/main/java/com/geeksville/mesh/model/map/NOAAWmsTileSource.kt index 221ce943..a99cf1f9 100644 --- a/app/src/main/java/com/geeksville/mesh/model/map/NOAAWmsTileSource.kt +++ b/app/src/main/java/com/geeksville/mesh/model/map/NOAAWmsTileSource.kt @@ -4,6 +4,7 @@ import android.content.res.Resources import android.util.Log import org.osmdroid.api.IMapView import org.osmdroid.tileprovider.tilesource.OnlineTileSourceBase +import org.osmdroid.tileprovider.tilesource.TileSourcePolicy import org.osmdroid.util.MapTileIndex import kotlin.math.atan import kotlin.math.pow @@ -18,7 +19,15 @@ open class NOAAWmsTileSource( srs: String, style: String?, format: String, -) : OnlineTileSourceBase(aName, 0, 9, 256, "png", aBaseUrl) { +) : OnlineTileSourceBase( + aName, 0, 5, 256, "png", aBaseUrl, "", TileSourcePolicy( + 2, + TileSourcePolicy.FLAG_NO_BULK + or TileSourcePolicy.FLAG_NO_PREVENTIVE + or TileSourcePolicy.FLAG_USER_AGENT_MEANINGFUL + or TileSourcePolicy.FLAG_USER_AGENT_NORMALIZED + ) +) { // array indexes for array to hold bounding boxes. private val MINX = 0 diff --git a/app/src/main/java/com/geeksville/mesh/model/map/OnlineTileSourceAuth.kt b/app/src/main/java/com/geeksville/mesh/model/map/OnlineTileSourceAuth.kt new file mode 100644 index 00000000..1e4e37a3 --- /dev/null +++ b/app/src/main/java/com/geeksville/mesh/model/map/OnlineTileSourceAuth.kt @@ -0,0 +1,47 @@ +package com.geeksville.mesh.model.map + +import org.osmdroid.tileprovider.tilesource.OnlineTileSourceBase +import org.osmdroid.tileprovider.tilesource.TileSourcePolicy +import org.osmdroid.util.MapTileIndex + +open class OnlineTileSourceAuth( + aName: String, + aZoomLevel: Int, + aZoomMaxLevel: Int, + aTileSizePixels: Int, + aImageFileNameEnding: String, + aBaseUrl: Array, + pCopyright: String, + tileSourcePolicy: TileSourcePolicy, + layerName: String?, + apiKey: String +) : + OnlineTileSourceBase( + aName, + aZoomLevel, + aZoomMaxLevel, + aTileSizePixels, + aImageFileNameEnding, + aBaseUrl, + pCopyright, + tileSourcePolicy + + ) { + private var layerName = "" + private var apiKey = "" + + init { + if (layerName != null) { + this.layerName = layerName + } + this.apiKey = apiKey + + } + + override fun getTileURLString(pMapTileIndex: Long): String { + return "$baseUrl$layerName/" + (MapTileIndex.getZoom(pMapTileIndex) + .toString() + "/" + MapTileIndex.getX(pMapTileIndex) + .toString() + "/" + MapTileIndex.getY(pMapTileIndex) + .toString()) + mImageFilenameEnding + "?appId=$apiKey" + } +} \ No newline at end of file diff --git a/app/src/main/java/com/geeksville/mesh/ui/MapFragment.kt b/app/src/main/java/com/geeksville/mesh/ui/MapFragment.kt index e745e44d..4e7413fd 100644 --- a/app/src/main/java/com/geeksville/mesh/ui/MapFragment.kt +++ b/app/src/main/java/com/geeksville/mesh/ui/MapFragment.kt @@ -490,7 +490,7 @@ class MapFragment : ScreenFragment("Map"), Logging, View.OnClickListener { val layer = TilesOverlay( MapTileProviderBasic( activity, - CustomTileSource.NOAA_RADAR_WMS + CustomTileSource.OPENWEATHER_RADAR ), context ) layer.loadingBackgroundColor = Color.TRANSPARENT From e22c7f8c35852ad159629e439e56271ebe6a3333 Mon Sep 17 00:00:00 2001 From: PWRxPSYCHO Date: Tue, 18 Oct 2022 21:48:14 -0400 Subject: [PATCH 05/12] Trying to update map style menu --- .../com/geeksville/mesh/ui/MapFragment.kt | 6 --- .../com/geeksville/mesh/ui/MapStyleAdapter.kt | 39 ++++++++++++++++ .../res/layout/adapter_map_style_menu.xml | 46 +++++++++++++++++++ app/src/main/res/layout/horizontal_item.xml | 24 ++++++++++ 4 files changed, 109 insertions(+), 6 deletions(-) create mode 100644 app/src/main/java/com/geeksville/mesh/ui/MapStyleAdapter.kt create mode 100644 app/src/main/res/layout/adapter_map_style_menu.xml create mode 100644 app/src/main/res/layout/horizontal_item.xml diff --git a/app/src/main/java/com/geeksville/mesh/ui/MapFragment.kt b/app/src/main/java/com/geeksville/mesh/ui/MapFragment.kt index 4e7413fd..a910cef7 100644 --- a/app/src/main/java/com/geeksville/mesh/ui/MapFragment.kt +++ b/app/src/main/java/com/geeksville/mesh/ui/MapFragment.kt @@ -3,7 +3,6 @@ package com.geeksville.mesh.ui import android.app.AlertDialog import android.content.Context import android.content.SharedPreferences -import android.content.res.Resources import android.graphics.Canvas import android.graphics.Color import android.graphics.Paint @@ -23,7 +22,6 @@ import com.geeksville.mesh.databinding.MapViewBinding import com.geeksville.mesh.model.UIViewModel import com.geeksville.mesh.model.map.CustomOverlayManager import com.geeksville.mesh.model.map.CustomTileSource -import com.geeksville.mesh.model.map.NOAAWmsTileSource import com.geeksville.mesh.util.formatAgo import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.google.android.material.floatingactionbutton.FloatingActionButton @@ -49,7 +47,6 @@ import org.osmdroid.views.overlay.* import org.osmdroid.views.overlay.gridlines.LatLonGridlineOverlay2 import java.io.File import kotlin.math.pow -import android.util.DisplayMetrics @AndroidEntryPoint @@ -184,7 +181,6 @@ class MapFragment : ScreenFragment("Map"), Logging, View.OnClickListener { alertDialog!!.show() } - /** * Clears active tile source cache */ @@ -496,8 +492,6 @@ class MapFragment : ScreenFragment("Map"), Logging, View.OnClickListener { layer.loadingBackgroundColor = Color.TRANSPARENT layer.loadingLineColor = Color.TRANSPARENT map.overlayManager.add(layer) - } else { - map.overlays.clear() } map.invalidate() } diff --git a/app/src/main/java/com/geeksville/mesh/ui/MapStyleAdapter.kt b/app/src/main/java/com/geeksville/mesh/ui/MapStyleAdapter.kt new file mode 100644 index 00000000..a4131ed3 --- /dev/null +++ b/app/src/main/java/com/geeksville/mesh/ui/MapStyleAdapter.kt @@ -0,0 +1,39 @@ +package com.geeksville.mesh.ui + +import android.R +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.TextView +import androidx.recyclerview.widget.RecyclerView +import com.geeksville.mesh.databinding.AdapterMapStyleMenuBinding + + +class MapStyleAdapter(itemView: AdapterMapStyleMenuBinding) { + var list = mutableListOf() + + inner class MyView(view: View) : RecyclerView.ViewHolder(view) { + var textView: TextView + + init { + textView = view.findViewById(R.id.text1) as TextView + } + } + + fun onCreateViewHolder( + parent: ViewGroup, + viewType: Int + ): MapStyleAdapter { + val inflater = LayoutInflater.from(parent.context) + val mapStyleMenuBinding = AdapterMapStyleMenuBinding.inflate(inflater, parent, false) + return MapStyleAdapter(mapStyleMenuBinding) + } + + fun onBindViewHolder(holder: MyView, position: Int) { + holder.textView.text = list[position] + } + + fun getItemCount(): Int { + return list.size + } +} \ No newline at end of file diff --git a/app/src/main/res/layout/adapter_map_style_menu.xml b/app/src/main/res/layout/adapter_map_style_menu.xml new file mode 100644 index 00000000..7067e931 --- /dev/null +++ b/app/src/main/res/layout/adapter_map_style_menu.xml @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/horizontal_item.xml b/app/src/main/res/layout/horizontal_item.xml new file mode 100644 index 00000000..3fe53189 --- /dev/null +++ b/app/src/main/res/layout/horizontal_item.xml @@ -0,0 +1,24 @@ + + + + + \ No newline at end of file From ee388db49186a093754d60f23c8a575871c9a756 Mon Sep 17 00:00:00 2001 From: PWRxPSYCHO Date: Wed, 19 Oct 2022 09:36:16 -0400 Subject: [PATCH 06/12] Clear cache based on tile source --- .../com/geeksville/mesh/ui/MapFragment.kt | 36 ++++++++- .../geeksville/mesh/util/SqlTileWriterExt.kt | 81 +++++++++++++++++++ 2 files changed, 116 insertions(+), 1 deletion(-) create mode 100644 app/src/main/java/com/geeksville/mesh/util/SqlTileWriterExt.kt diff --git a/app/src/main/java/com/geeksville/mesh/ui/MapFragment.kt b/app/src/main/java/com/geeksville/mesh/ui/MapFragment.kt index a910cef7..e3d334fb 100644 --- a/app/src/main/java/com/geeksville/mesh/ui/MapFragment.kt +++ b/app/src/main/java/com/geeksville/mesh/ui/MapFragment.kt @@ -22,6 +22,8 @@ import com.geeksville.mesh.databinding.MapViewBinding import com.geeksville.mesh.model.UIViewModel import com.geeksville.mesh.model.map.CustomOverlayManager import com.geeksville.mesh.model.map.CustomTileSource +import com.geeksville.mesh.util.SqlTileWriterExt +import com.geeksville.mesh.util.SqlTileWriterExt.SourceCount import com.geeksville.mesh.util.formatAgo import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.google.android.material.floatingactionbutton.FloatingActionButton @@ -60,6 +62,7 @@ class MapFragment : ScreenFragment("Map"), Logging, View.OnClickListener { private lateinit var executeJob: Button private var downloadPrompt: AlertDialog? = null private var alertDialog: AlertDialog? = null + private var cache: SqlTileWriterExt? = null // constants private val defaultMinZoom = 1.5 @@ -170,7 +173,7 @@ class MapFragment : ScreenFragment("Map"), Logging, View.OnClickListener { downloadJobAlert() dialog.dismiss() } - 2 -> clearCache() + 2 -> purgeTileSource() else -> dialog.dismiss() } } @@ -181,6 +184,7 @@ class MapFragment : ScreenFragment("Map"), Logging, View.OnClickListener { alertDialog!!.show() } + /** * Clears active tile source cache */ @@ -193,6 +197,36 @@ class MapFragment : ScreenFragment("Map"), Logging, View.OnClickListener { alertDialog!!.dismiss() } + private fun purgeTileSource() { + cache = SqlTileWriterExt() + val builder = AlertDialog.Builder(context) + builder.setTitle("Tile Source") + val arrayAdapter: ArrayAdapter = + ArrayAdapter(context!!, android.R.layout.select_dialog_singlechoice) + val sources = cache!!.sources + for (i in sources.indices) { + arrayAdapter.add(sources[i].source) + } + builder.setAdapter(arrayAdapter) { dialog, which -> + val item = arrayAdapter.getItem(which) + val b = cache!!.purgeCache(item) + if (b) Toast.makeText( + context, + "SQL Cache purged", + Toast.LENGTH_SHORT + ) + .show() else Toast.makeText( + context, + "SQL Cache purge failed, see logcat for details", + Toast.LENGTH_LONG + ).show() + } + builder.setNegativeButton( + "Cancel" + ) { dialog, which -> dialog.cancel() } + builder.show() + } + private fun showCurrentCacheInfo() { Toast.makeText(activity, "Calculating...", Toast.LENGTH_SHORT).show() diff --git a/app/src/main/java/com/geeksville/mesh/util/SqlTileWriterExt.kt b/app/src/main/java/com/geeksville/mesh/util/SqlTileWriterExt.kt new file mode 100644 index 00000000..edeea830 --- /dev/null +++ b/app/src/main/java/com/geeksville/mesh/util/SqlTileWriterExt.kt @@ -0,0 +1,81 @@ +package com.geeksville.mesh.util + +import android.database.Cursor +import org.osmdroid.tileprovider.modules.DatabaseFileArchive +import org.osmdroid.tileprovider.modules.SqlTileWriter + + +/** + * Extended the sqlite tile writer to have some additional query functions. A this point + * it's unclear if there is a need to put these with the osmdroid-android library, thus they were + * put here as more of an example. + * + * + * created on 12/21/2016. + * + * @author Alex O'Ree + * @since 5.6.2 + */ +class SqlTileWriterExt() : SqlTileWriter() { + fun select(rows: Int, offset: Int): Cursor? { + return this.db?.rawQuery( + "select " + DatabaseFileArchive.COLUMN_KEY + "," + COLUMN_EXPIRES + "," + DatabaseFileArchive.COLUMN_PROVIDER + " from " + DatabaseFileArchive.TABLE + " limit ? offset ?", + arrayOf(rows.toString() + "", offset.toString() + "") + ) + } + + /** + * gets all the tiles sources that we have tiles for in the cache database and their counts + * + * @return + */ + val sources: List + get() { + val db = db + val ret: MutableList = ArrayList() + if (db == null) { + return ret + } + var cur: Cursor? = null + try { + cur = db.rawQuery( + "select " + + DatabaseFileArchive.COLUMN_PROVIDER + + ",count(*) " + + ",min(length(" + DatabaseFileArchive.COLUMN_TILE + ")) " + + ",max(length(" + DatabaseFileArchive.COLUMN_TILE + ")) " + + ",sum(length(" + DatabaseFileArchive.COLUMN_TILE + ")) " + + "from " + DatabaseFileArchive.TABLE + " " + + "group by " + DatabaseFileArchive.COLUMN_PROVIDER, null + ) + while (cur.moveToNext()) { + val c = SourceCount() + c.source = cur.getString(0) + c.rowCount = cur.getLong(1) + c.sizeMin = cur.getLong(2) + c.sizeMax = cur.getLong(3) + c.sizeTotal = cur.getLong(4) + c.sizeAvg = c.sizeTotal / c.rowCount + ret.add(c) + } + } catch (e: Exception) { + catchException(e) + } finally { + cur?.close() + } + return ret + } + val rowCountExpired: Long + get() = getRowCount( + "$COLUMN_EXPIRES Date: Wed, 19 Oct 2022 09:38:07 -0400 Subject: [PATCH 07/12] working on menu changes --- .../com/geeksville/mesh/ui/MapStyleAdapter.kt | 54 ++++++++++--------- ...tem.xml => adapter_map_menu_selection.xml} | 0 .../res/layout/adapter_map_style_menu.xml | 46 ---------------- app/src/main/res/layout/map_menu.xml | 40 ++++++++++++++ 4 files changed, 69 insertions(+), 71 deletions(-) rename app/src/main/res/layout/{horizontal_item.xml => adapter_map_menu_selection.xml} (100%) delete mode 100644 app/src/main/res/layout/adapter_map_style_menu.xml create mode 100644 app/src/main/res/layout/map_menu.xml diff --git a/app/src/main/java/com/geeksville/mesh/ui/MapStyleAdapter.kt b/app/src/main/java/com/geeksville/mesh/ui/MapStyleAdapter.kt index a4131ed3..912b433c 100644 --- a/app/src/main/java/com/geeksville/mesh/ui/MapStyleAdapter.kt +++ b/app/src/main/java/com/geeksville/mesh/ui/MapStyleAdapter.kt @@ -1,39 +1,43 @@ package com.geeksville.mesh.ui -import android.R import android.view.LayoutInflater -import android.view.View import android.view.ViewGroup -import android.widget.TextView import androidx.recyclerview.widget.RecyclerView -import com.geeksville.mesh.databinding.AdapterMapStyleMenuBinding +import com.geeksville.mesh.databinding.AdapterMapMenuSelectionBinding +class MapStyleAdapter(itemView: AdapterMapMenuSelectionBinding) : + RecyclerView.ViewHolder(itemView.root) { + val card = itemView.cardview + val text = itemView.textview1 +} -class MapStyleAdapter(itemView: AdapterMapStyleMenuBinding) { - var list = mutableListOf() - - inner class MyView(view: View) : RecyclerView.ViewHolder(view) { - var textView: TextView - - init { - textView = view.findViewById(R.id.text1) as TextView - } - } - - fun onCreateViewHolder( - parent: ViewGroup, - viewType: Int - ): MapStyleAdapter { +private val mapStyleAdapater = object : RecyclerView.Adapter() { + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MapStyleAdapter { val inflater = LayoutInflater.from(parent.context) - val mapStyleMenuBinding = AdapterMapStyleMenuBinding.inflate(inflater, parent, false) - return MapStyleAdapter(mapStyleMenuBinding) + val mapMenuBinding = AdapterMapMenuSelectionBinding.inflate(inflater, parent, false) + return MapStyleAdapter(mapMenuBinding) } - fun onBindViewHolder(holder: MyView, position: Int) { - holder.textView.text = list[position] + override fun onBindViewHolder(holder: MapStyleAdapter, position: Int) { + TODO("Not yet implemented") } - fun getItemCount(): Int { - return list.size + val list = listOf() + override fun getItemCount() = list.size + +} + +private val mapLayerAdapater = object : RecyclerView.Adapter() { + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MapStyleAdapter { + val inflater = LayoutInflater.from(parent.context) + val mapMenuBinding = AdapterMapMenuSelectionBinding.inflate(inflater, parent, false) + return MapStyleAdapter(mapMenuBinding) } + + override fun onBindViewHolder(holder: MapStyleAdapter, position: Int) { + TODO("Not yet implemented") + } + + val list = listOf() + override fun getItemCount() = list.size } \ No newline at end of file diff --git a/app/src/main/res/layout/horizontal_item.xml b/app/src/main/res/layout/adapter_map_menu_selection.xml similarity index 100% rename from app/src/main/res/layout/horizontal_item.xml rename to app/src/main/res/layout/adapter_map_menu_selection.xml diff --git a/app/src/main/res/layout/adapter_map_style_menu.xml b/app/src/main/res/layout/adapter_map_style_menu.xml deleted file mode 100644 index 7067e931..00000000 --- a/app/src/main/res/layout/adapter_map_style_menu.xml +++ /dev/null @@ -1,46 +0,0 @@ - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/map_menu.xml b/app/src/main/res/layout/map_menu.xml new file mode 100644 index 00000000..90f2a662 --- /dev/null +++ b/app/src/main/res/layout/map_menu.xml @@ -0,0 +1,40 @@ + + + + + + + + + + + + + From 11ea26a22e4a3d6ab167cb195115823ed2dd5cc8 Mon Sep 17 00:00:00 2001 From: PWRxPSYCHO Date: Wed, 19 Oct 2022 11:13:37 -0400 Subject: [PATCH 08/12] Updated UI for cache deletion --- .../com/geeksville/mesh/ui/MapFragment.kt | 47 ++++++++++++------- 1 file changed, 31 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/com/geeksville/mesh/ui/MapFragment.kt b/app/src/main/java/com/geeksville/mesh/ui/MapFragment.kt index db27d280..6f0daa98 100644 --- a/app/src/main/java/com/geeksville/mesh/ui/MapFragment.kt +++ b/app/src/main/java/com/geeksville/mesh/ui/MapFragment.kt @@ -2,6 +2,7 @@ package com.geeksville.mesh.ui import android.app.AlertDialog import android.content.Context +import android.content.DialogInterface import android.content.SharedPreferences import android.graphics.Canvas import android.graphics.Color @@ -197,25 +198,39 @@ class MapFragment : ScreenFragment("Map"), Logging, View.OnClickListener { cache = SqlTileWriterExt() val builder = AlertDialog.Builder(context) builder.setTitle("Tile Source") - val arrayAdapter: ArrayAdapter = - ArrayAdapter(context!!, android.R.layout.select_dialog_singlechoice) val sources = cache!!.sources + val sourceList = mutableListOf() for (i in sources.indices) { - arrayAdapter.add(sources[i].source) + sourceList.add(sources[i].source as String) } - builder.setAdapter(arrayAdapter) { dialog, which -> - val item = arrayAdapter.getItem(which) - val b = cache!!.purgeCache(item) - if (b) Toast.makeText( - context, - "SQL Cache purged", - Toast.LENGTH_SHORT - ) - .show() else Toast.makeText( - context, - "SQL Cache purge failed, see logcat for details", - Toast.LENGTH_LONG - ).show() + val selected: BooleanArray? = null + val selectedList = mutableListOf() + builder.setMultiChoiceItems( + sourceList.toTypedArray(), + selected + ) { dialogInterface, i, b -> + if (b) { + selectedList.add(i) + } else { + selectedList.remove(i) + } + + } + builder.setPositiveButton("Clear") { dialogInterface, i -> + for (x in selectedList) { + val item = sources[x] + val b = cache!!.purgeCache(item.source) + if (b) Toast.makeText( + context, + "SQL Cache purged for ${item.source}", + Toast.LENGTH_SHORT + ) + .show() else Toast.makeText( + context, + "SQL Cache purge failed, see logcat for details", + Toast.LENGTH_LONG + ).show() + } } builder.setNegativeButton( "Cancel" From 87cc38241655c4e322d9d8a6eb7e828b5064ea38 Mon Sep 17 00:00:00 2001 From: PWRxPSYCHO Date: Wed, 19 Oct 2022 16:52:44 -0400 Subject: [PATCH 09/12] Getting closer. Just need to populate the recycler & wrap the menu into constrained box --- .../com/geeksville/mesh/ui/MapFragment.kt | 57 ++++++++++++------- .../com/geeksville/mesh/ui/MapStyleAdapter.kt | 54 +++++++++--------- 2 files changed, 62 insertions(+), 49 deletions(-) diff --git a/app/src/main/java/com/geeksville/mesh/ui/MapFragment.kt b/app/src/main/java/com/geeksville/mesh/ui/MapFragment.kt index 6f0daa98..5090054f 100644 --- a/app/src/main/java/com/geeksville/mesh/ui/MapFragment.kt +++ b/app/src/main/java/com/geeksville/mesh/ui/MapFragment.kt @@ -14,11 +14,14 @@ import android.view.* import android.widget.* import androidx.core.content.ContextCompat import androidx.fragment.app.activityViewModels +import androidx.recyclerview.widget.LinearLayoutManager import com.geeksville.mesh.BuildConfig import com.geeksville.mesh.NodeInfo import com.geeksville.mesh.R import com.geeksville.mesh.android.Logging import com.geeksville.mesh.database.entity.Packet +import com.geeksville.mesh.databinding.AdapterMapMenuSelectionBinding +import com.geeksville.mesh.databinding.MapMenuBinding import com.geeksville.mesh.databinding.MapViewBinding import com.geeksville.mesh.model.UIViewModel import com.geeksville.mesh.model.map.CustomOverlayManager @@ -208,7 +211,7 @@ class MapFragment : ScreenFragment("Map"), Logging, View.OnClickListener { builder.setMultiChoiceItems( sourceList.toTypedArray(), selected - ) { dialogInterface, i, b -> + ) { _, i, b -> if (b) { selectedList.add(i) } else { @@ -216,7 +219,7 @@ class MapFragment : ScreenFragment("Map"), Logging, View.OnClickListener { } } - builder.setPositiveButton("Clear") { dialogInterface, i -> + builder.setPositiveButton("Clear") { _, _ -> for (x in selectedList) { val item = sources[x] val b = cache!!.purgeCache(item.source) @@ -234,7 +237,7 @@ class MapFragment : ScreenFragment("Map"), Logging, View.OnClickListener { } builder.setNegativeButton( "Cancel" - ) { dialog, which -> dialog.cancel() } + ) { dialog, _ -> dialog.cancel() } builder.show() } @@ -405,27 +408,37 @@ class MapFragment : ScreenFragment("Map"), Logging, View.OnClickListener { } private fun chooseMapStyle() { - /// Prepare dialog and its items - val builder = MaterialAlertDialogBuilder(context!!) - builder.setTitle(getString(R.string.preferences_map_style)) - val mapStyles by lazy { resources.getStringArray(R.array.map_styles) } + val mapMenu = MapMenuBinding.inflate(layoutInflater, view as ViewGroup, true) + val layoutManager = LinearLayoutManager(requireContext()) + val adapterMenuSelection = AdapterMapMenuSelectionBinding.inflate(layoutInflater) + val adapter = MapStyleAdapter(adapterMenuSelection) + mapMenu.mapLayerRecyclerView.adapter = + adapter.mapStyleAdapater + mapMenu.mapTypeRecyclerView.layoutManager = layoutManager + mapMenu.mapTypeRecyclerView.adapter = adapter.mapLayerAdapater - /// Load preferences and its value - val editor: SharedPreferences.Editor = mPrefs.edit() - val mapStyleInt = mPrefs.getInt(mapStyleId, 1) - debug("mapStyleId from prefs: $mapStyleInt") - builder.setSingleChoiceItems(mapStyles, mapStyleInt) { dialog, which -> - debug("Set mapStyleId pref to $which") - editor.putInt(mapStyleId, which) - editor.apply() - dialog.dismiss() - map.setTileSource(loadOnlineTileSourceBase()) - renderDownloadButton() - drawOverlays() - } - val dialog = builder.create() - dialog.show() +// /// Prepare dialog and its items +// val builder = MaterialAlertDialogBuilder(context!!) +// builder.setTitle(getString(R.string.preferences_map_style)) +// val mapStyles by lazy { resources.getStringArray(R.array.map_styles) } +// +// /// Load preferences and its value +// val editor: SharedPreferences.Editor = mPrefs.edit() +// val mapStyleInt = mPrefs.getInt(mapStyleId, 1) +// debug("mapStyleId from prefs: $mapStyleInt") +// +// builder.setSingleChoiceItems(mapStyles, mapStyleInt) { dialog, which -> +// debug("Set mapStyleId pref to $which") +// editor.putInt(mapStyleId, which) +// editor.apply() +// dialog.dismiss() +// map.setTileSource(loadOnlineTileSourceBase()) +// renderDownloadButton() +// drawOverlays() +// } +// val dialog = builder.create() +// dialog.show() } private fun renderDownloadButton() { diff --git a/app/src/main/java/com/geeksville/mesh/ui/MapStyleAdapter.kt b/app/src/main/java/com/geeksville/mesh/ui/MapStyleAdapter.kt index 912b433c..9137bfd3 100644 --- a/app/src/main/java/com/geeksville/mesh/ui/MapStyleAdapter.kt +++ b/app/src/main/java/com/geeksville/mesh/ui/MapStyleAdapter.kt @@ -9,35 +9,35 @@ class MapStyleAdapter(itemView: AdapterMapMenuSelectionBinding) : RecyclerView.ViewHolder(itemView.root) { val card = itemView.cardview val text = itemView.textview1 -} -private val mapStyleAdapater = object : RecyclerView.Adapter() { - override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MapStyleAdapter { - val inflater = LayoutInflater.from(parent.context) - val mapMenuBinding = AdapterMapMenuSelectionBinding.inflate(inflater, parent, false) - return MapStyleAdapter(mapMenuBinding) + val mapStyleAdapater = object : RecyclerView.Adapter() { + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MapStyleAdapter { + val inflater = LayoutInflater.from(parent.context) + val mapMenuBinding = AdapterMapMenuSelectionBinding.inflate(inflater, parent, false) + return MapStyleAdapter(mapMenuBinding) + } + + override fun onBindViewHolder(holder: MapStyleAdapter, position: Int) { + TODO("Not yet implemented") + } + + val list = listOf() + override fun getItemCount() = list.size + } - override fun onBindViewHolder(holder: MapStyleAdapter, position: Int) { - TODO("Not yet implemented") + val mapLayerAdapater = object : RecyclerView.Adapter() { + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MapStyleAdapter { + val inflater = LayoutInflater.from(parent.context) + val mapMenuBinding = AdapterMapMenuSelectionBinding.inflate(inflater, parent, false) + return MapStyleAdapter(mapMenuBinding) + } + + override fun onBindViewHolder(holder: MapStyleAdapter, position: Int) { + TODO("Not yet implemented") + } + + val list = listOf() + override fun getItemCount() = list.size } - - val list = listOf() - override fun getItemCount() = list.size - -} - -private val mapLayerAdapater = object : RecyclerView.Adapter() { - override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MapStyleAdapter { - val inflater = LayoutInflater.from(parent.context) - val mapMenuBinding = AdapterMapMenuSelectionBinding.inflate(inflater, parent, false) - return MapStyleAdapter(mapMenuBinding) - } - - override fun onBindViewHolder(holder: MapStyleAdapter, position: Int) { - TODO("Not yet implemented") - } - - val list = listOf() - override fun getItemCount() = list.size } \ No newline at end of file From 07cc8ce7015a765a961181f6ee351a65220590eb Mon Sep 17 00:00:00 2001 From: PWRxPSYCHO Date: Thu, 20 Oct 2022 08:50:21 -0400 Subject: [PATCH 10/12] Updated UI for Map Layers & Style. Still need on Click listener --- .../geeksville/mesh/model/map/ChildData.kt | 3 + .../geeksville/mesh/model/map/Constants.kt | 6 + .../mesh/model/map/MapParentData.kt | 8 ++ .../com/geeksville/mesh/ui/MapFragment.kt | 65 +++++------ .../mesh/ui/MapMenuRecyclerAdapter.kt | 109 ++++++++++++++++++ .../com/geeksville/mesh/ui/MapStyleAdapter.kt | 43 ------- .../res/layout/adapter_map_menu_selection.xml | 24 ---- app/src/main/res/layout/child_row.xml | 22 ++++ app/src/main/res/layout/map_menu.xml | 40 ------- app/src/main/res/layout/map_menu_layout.xml | 12 ++ app/src/main/res/layout/parent_row.xml | 34 ++++++ 11 files changed, 223 insertions(+), 143 deletions(-) create mode 100644 app/src/main/java/com/geeksville/mesh/model/map/ChildData.kt create mode 100644 app/src/main/java/com/geeksville/mesh/model/map/Constants.kt create mode 100644 app/src/main/java/com/geeksville/mesh/model/map/MapParentData.kt create mode 100644 app/src/main/java/com/geeksville/mesh/ui/MapMenuRecyclerAdapter.kt delete mode 100644 app/src/main/java/com/geeksville/mesh/ui/MapStyleAdapter.kt delete mode 100644 app/src/main/res/layout/adapter_map_menu_selection.xml create mode 100644 app/src/main/res/layout/child_row.xml delete mode 100644 app/src/main/res/layout/map_menu.xml create mode 100644 app/src/main/res/layout/map_menu_layout.xml create mode 100644 app/src/main/res/layout/parent_row.xml diff --git a/app/src/main/java/com/geeksville/mesh/model/map/ChildData.kt b/app/src/main/java/com/geeksville/mesh/model/map/ChildData.kt new file mode 100644 index 00000000..136c5e8e --- /dev/null +++ b/app/src/main/java/com/geeksville/mesh/model/map/ChildData.kt @@ -0,0 +1,3 @@ +package com.geeksville.mesh.model.map + +data class ChildData(val childTitle: String) diff --git a/app/src/main/java/com/geeksville/mesh/model/map/Constants.kt b/app/src/main/java/com/geeksville/mesh/model/map/Constants.kt new file mode 100644 index 00000000..4ce04c5c --- /dev/null +++ b/app/src/main/java/com/geeksville/mesh/model/map/Constants.kt @@ -0,0 +1,6 @@ +package com.geeksville.mesh.model.map + +object Constants { + const val PARENT = 0 + const val CHILD = 1 +} \ No newline at end of file diff --git a/app/src/main/java/com/geeksville/mesh/model/map/MapParentData.kt b/app/src/main/java/com/geeksville/mesh/model/map/MapParentData.kt new file mode 100644 index 00000000..e99a28af --- /dev/null +++ b/app/src/main/java/com/geeksville/mesh/model/map/MapParentData.kt @@ -0,0 +1,8 @@ +package com.geeksville.mesh.model.map + +data class MapParentData( + val title: String? = null, + var type:Int = Constants.PARENT, + var subList: MutableList = ArrayList(), + var isExpanded: Boolean = false +) diff --git a/app/src/main/java/com/geeksville/mesh/ui/MapFragment.kt b/app/src/main/java/com/geeksville/mesh/ui/MapFragment.kt index 5090054f..9da27e27 100644 --- a/app/src/main/java/com/geeksville/mesh/ui/MapFragment.kt +++ b/app/src/main/java/com/geeksville/mesh/ui/MapFragment.kt @@ -15,19 +15,20 @@ import android.widget.* import androidx.core.content.ContextCompat import androidx.fragment.app.activityViewModels import androidx.recyclerview.widget.LinearLayoutManager +import androidx.recyclerview.widget.RecyclerView import com.geeksville.mesh.BuildConfig import com.geeksville.mesh.NodeInfo import com.geeksville.mesh.R import com.geeksville.mesh.android.Logging import com.geeksville.mesh.database.entity.Packet -import com.geeksville.mesh.databinding.AdapterMapMenuSelectionBinding -import com.geeksville.mesh.databinding.MapMenuBinding +import com.geeksville.mesh.databinding.MapMenuLayoutBinding import com.geeksville.mesh.databinding.MapViewBinding import com.geeksville.mesh.model.UIViewModel +import com.geeksville.mesh.model.map.ChildData import com.geeksville.mesh.model.map.CustomOverlayManager import com.geeksville.mesh.model.map.CustomTileSource +import com.geeksville.mesh.model.map.MapParentData import com.geeksville.mesh.util.SqlTileWriterExt -import com.geeksville.mesh.util.SqlTileWriterExt.SourceCount import com.geeksville.mesh.util.formatAgo import com.google.android.material.dialog.MaterialAlertDialogBuilder import dagger.hilt.android.AndroidEntryPoint @@ -93,7 +94,6 @@ class MapFragment : ScreenFragment("Map"), Logging, View.OnClickListener { private lateinit var cacheManager: CacheManager private lateinit var downloadRegionBoundingBox: BoundingBox - override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? ): View { @@ -185,18 +185,6 @@ class MapFragment : ScreenFragment("Map"), Logging, View.OnClickListener { } - /** - * Clears active tile source cache - */ - private fun clearCache() { - val b: Boolean = SqlTileWriter().purgeCache() - SqlTileWriter().onDetach() - val title = if (b) "SQL Cache purged" else "SQL Cache purge failed, see logcat for details" - val length = if (b) Toast.LENGTH_SHORT else Toast.LENGTH_LONG - Toast.makeText(activity, title, length).show() - alertDialog!!.dismiss() - } - private fun purgeTileSource() { cache = SqlTileWriterExt() val builder = AlertDialog.Builder(context) @@ -408,26 +396,31 @@ class MapFragment : ScreenFragment("Map"), Logging, View.OnClickListener { } private fun chooseMapStyle() { - val mapMenu = MapMenuBinding.inflate(layoutInflater, view as ViewGroup, true) - val layoutManager = LinearLayoutManager(requireContext()) - val adapterMenuSelection = AdapterMapMenuSelectionBinding.inflate(layoutInflater) - val adapter = MapStyleAdapter(adapterMenuSelection) - mapMenu.mapLayerRecyclerView.adapter = - adapter.mapStyleAdapater - mapMenu.mapTypeRecyclerView.layoutManager = layoutManager - mapMenu.mapTypeRecyclerView.adapter = adapter.mapLayerAdapater + /// Prepare dialog and its items + val mapStyles by lazy { resources.getStringArray(R.array.map_styles) } + val builder = MaterialAlertDialogBuilder(context!!) + val listData: MutableList = ArrayList() + val parentData: Array = arrayOf("Map Source", "Map Layer") + val mapStyleData: MutableList = mutableListOf() + mapStyles.forEach { style -> + mapStyleData.add(ChildData(style)) + } + val mapLayerData: MutableList = mutableListOf(ChildData("test")) -// /// Prepare dialog and its items -// val builder = MaterialAlertDialogBuilder(context!!) -// builder.setTitle(getString(R.string.preferences_map_style)) -// val mapStyles by lazy { resources.getStringArray(R.array.map_styles) } -// -// /// Load preferences and its value -// val editor: SharedPreferences.Editor = mPrefs.edit() -// val mapStyleInt = mPrefs.getInt(mapStyleId, 1) -// debug("mapStyleId from prefs: $mapStyleInt") -// + val mapStyleObj = MapParentData(title = parentData[0], subList = mapStyleData) + val mapLayerObj = MapParentData(title = parentData[1], subList = mapLayerData) + listData.add(mapStyleObj) + listData.add(mapLayerObj) + val exRecycleView = MapMenuLayoutBinding.inflate(layoutInflater) + exRecycleView.exRecycle.layoutManager = LinearLayoutManager(context) + exRecycleView.exRecycle.adapter = MapMenuRecyclerAdapter(context!!, listData) + + builder.setView(exRecycleView.root) + /// Load preferences and its value + val editor: SharedPreferences.Editor = mPrefs.edit() + val mapStyleInt = mPrefs.getInt(mapStyleId, 1) + debug("mapStyleId from prefs: $mapStyleInt") // builder.setSingleChoiceItems(mapStyles, mapStyleInt) { dialog, which -> // debug("Set mapStyleId pref to $which") // editor.putInt(mapStyleId, which) @@ -437,8 +430,8 @@ class MapFragment : ScreenFragment("Map"), Logging, View.OnClickListener { // renderDownloadButton() // drawOverlays() // } -// val dialog = builder.create() -// dialog.show() + val dialog = builder.create() + dialog.show() } private fun renderDownloadButton() { diff --git a/app/src/main/java/com/geeksville/mesh/ui/MapMenuRecyclerAdapter.kt b/app/src/main/java/com/geeksville/mesh/ui/MapMenuRecyclerAdapter.kt new file mode 100644 index 00000000..7290b467 --- /dev/null +++ b/app/src/main/java/com/geeksville/mesh/ui/MapMenuRecyclerAdapter.kt @@ -0,0 +1,109 @@ +package com.geeksville.mesh.ui + +import android.content.Context +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import android.widget.TextView +import androidx.recyclerview.widget.RecyclerView +import com.geeksville.mesh.R +import com.geeksville.mesh.model.map.ChildData +import com.geeksville.mesh.model.map.Constants +import com.geeksville.mesh.model.map.MapParentData + +class MapMenuRecyclerAdapter(var mContext: Context, val list: MutableList) : + RecyclerView.Adapter() { + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder { + + return if (viewType == Constants.PARENT) { + val rowView: View = + LayoutInflater.from(parent.context).inflate(R.layout.parent_row, parent, false) + GroupViewHolder(rowView) + } else { + val rowView: View = + LayoutInflater.from(parent.context).inflate(R.layout.child_row, parent, false) + ChildViewHolder(rowView) + } + } + + override fun getItemCount(): Int = list.size + + override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) { + + val dataList = list[position] + if (dataList.type == Constants.PARENT) { + holder as GroupViewHolder + holder.apply { + parentTV?.text = dataList.title + downIV?.setOnClickListener { + expandOrCollapseParentItem(dataList, position) + } + } + } else { + holder as ChildViewHolder + + holder.apply { + val singleService = dataList.subList.first() + childTV?.text = singleService.childTitle + } + } + } + + private fun expandOrCollapseParentItem(singleBoarding: MapParentData, position: Int) { + + if (singleBoarding.isExpanded) { + collapseParentRow(position) + } else { + expandParentRow(position) + } + } + + private fun expandParentRow(position: Int) { + val currentBoardingRow = list[position] + val services = currentBoardingRow.subList + currentBoardingRow.isExpanded = true + var nextPosition = position + if (currentBoardingRow.type == Constants.PARENT) { + + services.forEach { service -> + val parentModel = MapParentData() + parentModel.type = Constants.CHILD + val subList: ArrayList = ArrayList() + subList.add(service) + parentModel.subList = subList + list.add(++nextPosition, parentModel) + } + notifyDataSetChanged() + } + } + + private fun collapseParentRow(position: Int) { + val currentBoardingRow = list[position] + val services = currentBoardingRow.subList + list[position].isExpanded = false + if (list[position].type == Constants.PARENT) { + services.forEach { _ -> + list.removeAt(position + 1) + } + notifyDataSetChanged() + } + } + + override fun getItemViewType(position: Int): Int = list[position].type + + override fun getItemId(position: Int): Long { + return position.toLong() + } + + class GroupViewHolder(row: View) : RecyclerView.ViewHolder(row) { + val parentTV = row.findViewById(R.id.parent_Title) as TextView? + val downIV = row.findViewById(R.id.down_iv) as ImageView? + } + + class ChildViewHolder(row: View) : RecyclerView.ViewHolder(row) { + val childTV = row.findViewById(R.id.child_Title) as TextView? + + } +} diff --git a/app/src/main/java/com/geeksville/mesh/ui/MapStyleAdapter.kt b/app/src/main/java/com/geeksville/mesh/ui/MapStyleAdapter.kt deleted file mode 100644 index 9137bfd3..00000000 --- a/app/src/main/java/com/geeksville/mesh/ui/MapStyleAdapter.kt +++ /dev/null @@ -1,43 +0,0 @@ -package com.geeksville.mesh.ui - -import android.view.LayoutInflater -import android.view.ViewGroup -import androidx.recyclerview.widget.RecyclerView -import com.geeksville.mesh.databinding.AdapterMapMenuSelectionBinding - -class MapStyleAdapter(itemView: AdapterMapMenuSelectionBinding) : - RecyclerView.ViewHolder(itemView.root) { - val card = itemView.cardview - val text = itemView.textview1 - - val mapStyleAdapater = object : RecyclerView.Adapter() { - override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MapStyleAdapter { - val inflater = LayoutInflater.from(parent.context) - val mapMenuBinding = AdapterMapMenuSelectionBinding.inflate(inflater, parent, false) - return MapStyleAdapter(mapMenuBinding) - } - - override fun onBindViewHolder(holder: MapStyleAdapter, position: Int) { - TODO("Not yet implemented") - } - - val list = listOf() - override fun getItemCount() = list.size - - } - - val mapLayerAdapater = object : RecyclerView.Adapter() { - override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MapStyleAdapter { - val inflater = LayoutInflater.from(parent.context) - val mapMenuBinding = AdapterMapMenuSelectionBinding.inflate(inflater, parent, false) - return MapStyleAdapter(mapMenuBinding) - } - - override fun onBindViewHolder(holder: MapStyleAdapter, position: Int) { - TODO("Not yet implemented") - } - - val list = listOf() - override fun getItemCount() = list.size - } -} \ No newline at end of file diff --git a/app/src/main/res/layout/adapter_map_menu_selection.xml b/app/src/main/res/layout/adapter_map_menu_selection.xml deleted file mode 100644 index 3fe53189..00000000 --- a/app/src/main/res/layout/adapter_map_menu_selection.xml +++ /dev/null @@ -1,24 +0,0 @@ - - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/child_row.xml b/app/src/main/res/layout/child_row.xml new file mode 100644 index 00000000..3026a287 --- /dev/null +++ b/app/src/main/res/layout/child_row.xml @@ -0,0 +1,22 @@ + + + + + + + diff --git a/app/src/main/res/layout/map_menu.xml b/app/src/main/res/layout/map_menu.xml deleted file mode 100644 index 90f2a662..00000000 --- a/app/src/main/res/layout/map_menu.xml +++ /dev/null @@ -1,40 +0,0 @@ - - - - - - - - - - - - - diff --git a/app/src/main/res/layout/map_menu_layout.xml b/app/src/main/res/layout/map_menu_layout.xml new file mode 100644 index 00000000..7897978b --- /dev/null +++ b/app/src/main/res/layout/map_menu_layout.xml @@ -0,0 +1,12 @@ + + + + + + + diff --git a/app/src/main/res/layout/parent_row.xml b/app/src/main/res/layout/parent_row.xml new file mode 100644 index 00000000..fb7f5eb1 --- /dev/null +++ b/app/src/main/res/layout/parent_row.xml @@ -0,0 +1,34 @@ + + + + + + + + From b9ae181ee4350cd42e48c3f32d00b0d95f7808ad Mon Sep 17 00:00:00 2001 From: PWRxPSYCHO Date: Thu, 20 Oct 2022 21:43:27 -0400 Subject: [PATCH 11/12] revert back to old map style UI --- .../geeksville/mesh/model/map/ChildData.kt | 3 - .../geeksville/mesh/model/map/Constants.kt | 6 - .../mesh/model/map/MapParentData.kt | 8 -- .../com/geeksville/mesh/ui/MapFragment.kt | 45 ++------ .../mesh/ui/MapMenuRecyclerAdapter.kt | 109 ------------------ app/src/main/res/layout/child_row.xml | 22 ---- app/src/main/res/layout/map_menu_layout.xml | 12 -- app/src/main/res/layout/parent_row.xml | 34 ------ 8 files changed, 10 insertions(+), 229 deletions(-) delete mode 100644 app/src/main/java/com/geeksville/mesh/model/map/ChildData.kt delete mode 100644 app/src/main/java/com/geeksville/mesh/model/map/Constants.kt delete mode 100644 app/src/main/java/com/geeksville/mesh/model/map/MapParentData.kt delete mode 100644 app/src/main/java/com/geeksville/mesh/ui/MapMenuRecyclerAdapter.kt delete mode 100644 app/src/main/res/layout/child_row.xml delete mode 100644 app/src/main/res/layout/map_menu_layout.xml delete mode 100644 app/src/main/res/layout/parent_row.xml diff --git a/app/src/main/java/com/geeksville/mesh/model/map/ChildData.kt b/app/src/main/java/com/geeksville/mesh/model/map/ChildData.kt deleted file mode 100644 index 136c5e8e..00000000 --- a/app/src/main/java/com/geeksville/mesh/model/map/ChildData.kt +++ /dev/null @@ -1,3 +0,0 @@ -package com.geeksville.mesh.model.map - -data class ChildData(val childTitle: String) diff --git a/app/src/main/java/com/geeksville/mesh/model/map/Constants.kt b/app/src/main/java/com/geeksville/mesh/model/map/Constants.kt deleted file mode 100644 index 4ce04c5c..00000000 --- a/app/src/main/java/com/geeksville/mesh/model/map/Constants.kt +++ /dev/null @@ -1,6 +0,0 @@ -package com.geeksville.mesh.model.map - -object Constants { - const val PARENT = 0 - const val CHILD = 1 -} \ No newline at end of file diff --git a/app/src/main/java/com/geeksville/mesh/model/map/MapParentData.kt b/app/src/main/java/com/geeksville/mesh/model/map/MapParentData.kt deleted file mode 100644 index e99a28af..00000000 --- a/app/src/main/java/com/geeksville/mesh/model/map/MapParentData.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.geeksville.mesh.model.map - -data class MapParentData( - val title: String? = null, - var type:Int = Constants.PARENT, - var subList: MutableList = ArrayList(), - var isExpanded: Boolean = false -) diff --git a/app/src/main/java/com/geeksville/mesh/ui/MapFragment.kt b/app/src/main/java/com/geeksville/mesh/ui/MapFragment.kt index 9da27e27..829fb636 100644 --- a/app/src/main/java/com/geeksville/mesh/ui/MapFragment.kt +++ b/app/src/main/java/com/geeksville/mesh/ui/MapFragment.kt @@ -2,7 +2,6 @@ package com.geeksville.mesh.ui import android.app.AlertDialog import android.content.Context -import android.content.DialogInterface import android.content.SharedPreferences import android.graphics.Canvas import android.graphics.Color @@ -14,20 +13,15 @@ import android.view.* import android.widget.* import androidx.core.content.ContextCompat import androidx.fragment.app.activityViewModels -import androidx.recyclerview.widget.LinearLayoutManager -import androidx.recyclerview.widget.RecyclerView import com.geeksville.mesh.BuildConfig import com.geeksville.mesh.NodeInfo import com.geeksville.mesh.R import com.geeksville.mesh.android.Logging import com.geeksville.mesh.database.entity.Packet -import com.geeksville.mesh.databinding.MapMenuLayoutBinding import com.geeksville.mesh.databinding.MapViewBinding import com.geeksville.mesh.model.UIViewModel -import com.geeksville.mesh.model.map.ChildData import com.geeksville.mesh.model.map.CustomOverlayManager import com.geeksville.mesh.model.map.CustomTileSource -import com.geeksville.mesh.model.map.MapParentData import com.geeksville.mesh.util.SqlTileWriterExt import com.geeksville.mesh.util.formatAgo import com.google.android.material.dialog.MaterialAlertDialogBuilder @@ -40,7 +34,6 @@ import org.osmdroid.events.ZoomEvent import org.osmdroid.tileprovider.MapTileProviderBasic import org.osmdroid.tileprovider.cachemanager.CacheManager import org.osmdroid.tileprovider.cachemanager.CacheManager.CacheManagerCallback -import org.osmdroid.tileprovider.modules.SqlTileWriter import org.osmdroid.tileprovider.modules.SqliteArchiveTileWriter import org.osmdroid.tileprovider.tilesource.ITileSource import org.osmdroid.tileprovider.tilesource.OnlineTileSourceBase @@ -400,36 +393,18 @@ class MapFragment : ScreenFragment("Map"), Logging, View.OnClickListener { val mapStyles by lazy { resources.getStringArray(R.array.map_styles) } val builder = MaterialAlertDialogBuilder(context!!) - val listData: MutableList = ArrayList() - val parentData: Array = arrayOf("Map Source", "Map Layer") - val mapStyleData: MutableList = mutableListOf() - mapStyles.forEach { style -> - mapStyleData.add(ChildData(style)) - } - val mapLayerData: MutableList = mutableListOf(ChildData("test")) - - val mapStyleObj = MapParentData(title = parentData[0], subList = mapStyleData) - val mapLayerObj = MapParentData(title = parentData[1], subList = mapLayerData) - listData.add(mapStyleObj) - listData.add(mapLayerObj) - val exRecycleView = MapMenuLayoutBinding.inflate(layoutInflater) - exRecycleView.exRecycle.layoutManager = LinearLayoutManager(context) - exRecycleView.exRecycle.adapter = MapMenuRecyclerAdapter(context!!, listData) - - builder.setView(exRecycleView.root) /// Load preferences and its value - val editor: SharedPreferences.Editor = mPrefs.edit() val mapStyleInt = mPrefs.getInt(mapStyleId, 1) - debug("mapStyleId from prefs: $mapStyleInt") -// builder.setSingleChoiceItems(mapStyles, mapStyleInt) { dialog, which -> -// debug("Set mapStyleId pref to $which") -// editor.putInt(mapStyleId, which) -// editor.apply() -// dialog.dismiss() -// map.setTileSource(loadOnlineTileSourceBase()) -// renderDownloadButton() -// drawOverlays() -// } + builder.setSingleChoiceItems(mapStyles, mapStyleInt) { dialog, which -> + debug("Set mapStyleId pref to $which") + val editor: SharedPreferences.Editor = mPrefs.edit() + editor.putInt(mapStyleId, which) + editor.apply() + dialog.dismiss() + map.setTileSource(loadOnlineTileSourceBase()) + renderDownloadButton() + drawOverlays() + } val dialog = builder.create() dialog.show() } diff --git a/app/src/main/java/com/geeksville/mesh/ui/MapMenuRecyclerAdapter.kt b/app/src/main/java/com/geeksville/mesh/ui/MapMenuRecyclerAdapter.kt deleted file mode 100644 index 7290b467..00000000 --- a/app/src/main/java/com/geeksville/mesh/ui/MapMenuRecyclerAdapter.kt +++ /dev/null @@ -1,109 +0,0 @@ -package com.geeksville.mesh.ui - -import android.content.Context -import android.view.LayoutInflater -import android.view.View -import android.view.ViewGroup -import android.widget.ImageView -import android.widget.TextView -import androidx.recyclerview.widget.RecyclerView -import com.geeksville.mesh.R -import com.geeksville.mesh.model.map.ChildData -import com.geeksville.mesh.model.map.Constants -import com.geeksville.mesh.model.map.MapParentData - -class MapMenuRecyclerAdapter(var mContext: Context, val list: MutableList) : - RecyclerView.Adapter() { - - override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder { - - return if (viewType == Constants.PARENT) { - val rowView: View = - LayoutInflater.from(parent.context).inflate(R.layout.parent_row, parent, false) - GroupViewHolder(rowView) - } else { - val rowView: View = - LayoutInflater.from(parent.context).inflate(R.layout.child_row, parent, false) - ChildViewHolder(rowView) - } - } - - override fun getItemCount(): Int = list.size - - override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) { - - val dataList = list[position] - if (dataList.type == Constants.PARENT) { - holder as GroupViewHolder - holder.apply { - parentTV?.text = dataList.title - downIV?.setOnClickListener { - expandOrCollapseParentItem(dataList, position) - } - } - } else { - holder as ChildViewHolder - - holder.apply { - val singleService = dataList.subList.first() - childTV?.text = singleService.childTitle - } - } - } - - private fun expandOrCollapseParentItem(singleBoarding: MapParentData, position: Int) { - - if (singleBoarding.isExpanded) { - collapseParentRow(position) - } else { - expandParentRow(position) - } - } - - private fun expandParentRow(position: Int) { - val currentBoardingRow = list[position] - val services = currentBoardingRow.subList - currentBoardingRow.isExpanded = true - var nextPosition = position - if (currentBoardingRow.type == Constants.PARENT) { - - services.forEach { service -> - val parentModel = MapParentData() - parentModel.type = Constants.CHILD - val subList: ArrayList = ArrayList() - subList.add(service) - parentModel.subList = subList - list.add(++nextPosition, parentModel) - } - notifyDataSetChanged() - } - } - - private fun collapseParentRow(position: Int) { - val currentBoardingRow = list[position] - val services = currentBoardingRow.subList - list[position].isExpanded = false - if (list[position].type == Constants.PARENT) { - services.forEach { _ -> - list.removeAt(position + 1) - } - notifyDataSetChanged() - } - } - - override fun getItemViewType(position: Int): Int = list[position].type - - override fun getItemId(position: Int): Long { - return position.toLong() - } - - class GroupViewHolder(row: View) : RecyclerView.ViewHolder(row) { - val parentTV = row.findViewById(R.id.parent_Title) as TextView? - val downIV = row.findViewById(R.id.down_iv) as ImageView? - } - - class ChildViewHolder(row: View) : RecyclerView.ViewHolder(row) { - val childTV = row.findViewById(R.id.child_Title) as TextView? - - } -} diff --git a/app/src/main/res/layout/child_row.xml b/app/src/main/res/layout/child_row.xml deleted file mode 100644 index 3026a287..00000000 --- a/app/src/main/res/layout/child_row.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - diff --git a/app/src/main/res/layout/map_menu_layout.xml b/app/src/main/res/layout/map_menu_layout.xml deleted file mode 100644 index 7897978b..00000000 --- a/app/src/main/res/layout/map_menu_layout.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - diff --git a/app/src/main/res/layout/parent_row.xml b/app/src/main/res/layout/parent_row.xml deleted file mode 100644 index fb7f5eb1..00000000 --- a/app/src/main/res/layout/parent_row.xml +++ /dev/null @@ -1,34 +0,0 @@ - - - - - - - - From 3c701ea17aab5e3a0f9581fb43a6e1008086030a Mon Sep 17 00:00:00 2001 From: PWRxPSYCHO Date: Thu, 27 Oct 2022 09:26:16 -0400 Subject: [PATCH 12/12] removed unused weather layer for future use --- .../com/geeksville/mesh/ui/MapFragment.kt | 29 ++++++++++--------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/com/geeksville/mesh/ui/MapFragment.kt b/app/src/main/java/com/geeksville/mesh/ui/MapFragment.kt index 829fb636..46df1652 100644 --- a/app/src/main/java/com/geeksville/mesh/ui/MapFragment.kt +++ b/app/src/main/java/com/geeksville/mesh/ui/MapFragment.kt @@ -506,22 +506,25 @@ class MapFragment : ScreenFragment("Map"), Logging, View.OnClickListener { createLatLongGrid(false) map.overlayManager.addAll(nodeLayer, nodePositions) map.overlayManager.addAll(nodeLayer, wayPoints) - if (map.tileProvider.tileSource.name() - .equals(CustomTileSource.getTileSource("ESRI World TOPO").name()) - ) { - val layer = TilesOverlay( - MapTileProviderBasic( - activity, - CustomTileSource.OPENWEATHER_RADAR - ), context - ) - layer.loadingBackgroundColor = Color.TRANSPARENT - layer.loadingLineColor = Color.TRANSPARENT - map.overlayManager.add(layer) - } map.invalidate() } +// private fun addWeatherLayer() { + // if (map.tileProvider.tileSource.name() +// .equals(CustomTileSource.getTileSource("ESRI World TOPO").name()) +// ) { +// val layer = TilesOverlay( +// MapTileProviderBasic( +// activity, +// CustomTileSource.OPENWEATHER_RADAR +// ), context +// ) +// layer.loadingBackgroundColor = Color.TRANSPARENT +// layer.loadingLineColor = Color.TRANSPARENT +// map.overlayManager.add(layer) +// } +// } + /** * Adds copyright to map depending on what source is showing */