@@ -23,14 +23,13 @@ import android.widget.Toast
2323import androidx.activity.OnBackPressedCallback
2424import androidx.appcompat.app.AlertDialog
2525import androidx.core.content.ContextCompat
26+ import androidx.core.view.children
2627import androidx.documentfile.provider.DocumentFile
2728import de.storchp.opentracks.osmplugin.MapsActivity.OpenTracksContentObserver
2829import de.storchp.opentracks.osmplugin.dashboardapi.APIConstants
29- import de.storchp.opentracks.osmplugin.dashboardapi.Track
3030import de.storchp.opentracks.osmplugin.dashboardapi.TrackReader
3131import de.storchp.opentracks.osmplugin.dashboardapi.TrackpointReader
3232import de.storchp.opentracks.osmplugin.dashboardapi.TrackpointsBySegments
33- import de.storchp.opentracks.osmplugin.dashboardapi.Waypoint
3433import de.storchp.opentracks.osmplugin.dashboardapi.WaypointReader
3534import de.storchp.opentracks.osmplugin.databinding.ActivityMapsBinding
3635import de.storchp.opentracks.osmplugin.maps.MovementDirection
@@ -39,7 +38,6 @@ import de.storchp.opentracks.osmplugin.utils.DEFAULT_TRACK_COLOR_MORE
3938import de.storchp.opentracks.osmplugin.utils.MapMode
4039import de.storchp.opentracks.osmplugin.utils.MapUtils
4140import de.storchp.opentracks.osmplugin.utils.PreferencesUtils
42- import de.storchp.opentracks.osmplugin.utils.StatisticElement
4341import de.storchp.opentracks.osmplugin.utils.TrackColorMode
4442import de.storchp.opentracks.osmplugin.utils.TrackPointsDebug
4543import de.storchp.opentracks.osmplugin.utils.TrackStatistics
@@ -88,11 +86,8 @@ import java.lang.Exception
8886import java.lang.RuntimeException
8987import java.util.ArrayList
9088import java.util.Collections
91- import java.util.Comparator
9289import java.util.Objects
9390import java.util.concurrent.atomic.AtomicInteger
94- import java.util.function.Consumer
95- import java.util.function.ToIntFunction
9691import java.util.zip.ZipInputStream
9792
9893
@@ -219,35 +214,18 @@ open class MapsActivity : BaseActivity(), OnItemGestureListener<MarkerInterface?
219214 tracksUri = APIConstants .getTracksUri(uris)
220215 trackPointsUri = APIConstants .getTrackPointsUri(uris)
221216 waypointsUri = APIConstants .getWaypointsUri(uris)
222- keepScreenOn(
223- intent.getBooleanExtra(
224- EXTRAS_SHOULD_KEEP_SCREEN_ON ,
225- false
226- )
227- )
228- showOnLockScreen(
229- intent.getBooleanExtra(
230- EXTRAS_SHOW_WHEN_LOCKED ,
231- false
232- )
233- )
234- showFullscreen(
235- intent.getBooleanExtra(
236- EXTRAS_SHOW_FULLSCREEN ,
237- false
238- )
239- )
240- isOpenTracksRecordingThisTrack = intent.getBooleanExtra(
241- EXTRAS_OPENTRACKS_IS_RECORDING_THIS_TRACK ,
242- false
243- )
217+ keepScreenOn(intent.getBooleanExtra(EXTRAS_SHOULD_KEEP_SCREEN_ON , false ))
218+ showOnLockScreen(intent.getBooleanExtra(EXTRAS_SHOW_WHEN_LOCKED , false ))
219+ showFullscreen(intent.getBooleanExtra(EXTRAS_SHOW_FULLSCREEN , false ))
220+ isOpenTracksRecordingThisTrack =
221+ intent.getBooleanExtra(EXTRAS_OPENTRACKS_IS_RECORDING_THIS_TRACK , false )
244222
245223 trackPointsUri?.let { readTrackpoints(it, false , protocolVersion) }
246224 readTracks(tracksUri!! )
247225 waypointsUri?.let { readWaypoints(it) }
248226 } else if (" geo" == intent.scheme && intent.data != null ) {
249227 WaypointReader .fromGeoUri(intent.data.toString())
250- ?.let { waypoint: Waypoint ->
228+ ?.let { waypoint ->
251229 val marker = MapUtils .createTappableMarker(this , waypoint)
252230 waypointsLayer!! .addItem(marker)
253231 val pos = map.getMapPosition()
@@ -421,7 +399,7 @@ open class MapsActivity : BaseActivity(), OnItemGestureListener<MarkerInterface?
421399 .filter { file -> file.exists() }
422400 .forEach { file: File -> readMapFile(tileSource, mapsCount, file) }
423401
424- if (mapsCount.get() == 0 && ! mapFiles.isEmpty ()) {
402+ if (mapsCount.get() == 0 && mapFiles.isNotEmpty ()) {
425403 Toast .makeText(
426404 this ,
427405 R .string.error_loading_offline_map,
@@ -688,7 +666,7 @@ open class MapsActivity : BaseActivity(), OnItemGestureListener<MarkerInterface?
688666 if (update && endPos != null ) {
689667 myPos = endPos
690668 map.render()
691- } else if (! latLongs.isEmpty ()) {
669+ } else if (latLongs.isNotEmpty ()) {
692670 boundingBox = BoundingBox (latLongs).extendMargin(1.2f ).also {
693671 myPos = it.getCenterPoint()
694672 }
@@ -734,6 +712,7 @@ open class MapsActivity : BaseActivity(), OnItemGestureListener<MarkerInterface?
734712 if (waypointsLayer != null ) {
735713 layers.remove(waypointsLayer)
736714 }
715+
737716 waypointsLayer = createWaypointsLayer()
738717 map.layers().add(waypointsLayer)
739718 lastWaypointId = 0
@@ -828,44 +807,32 @@ open class MapsActivity : BaseActivity(), OnItemGestureListener<MarkerInterface?
828807 }
829808
830809 private fun readTracks (data : Uri ) {
831- val tracks: List < Track > = TrackReader .readTracks(contentResolver, data)
832- if (! tracks.isEmpty ()) {
810+ val tracks = TrackReader .readTracks(contentResolver, data)
811+ if (tracks.isNotEmpty ()) {
833812 val statistics = TrackStatistics (tracks)
834813 removeStatisticElements()
835814 PreferencesUtils .getStatisticElements()
836- .stream()
837- .sorted(Comparator .comparingInt<StatisticElement ?>(ToIntFunction { obj: StatisticElement ? -> obj!! .ordinal }))
838- .forEach { se: StatisticElement ? ->
839- addStatisticElement(
840- se!! .getText(
841- this ,
842- statistics
843- )
844- )
845- }
815+ .sortedBy { it.ordinal }
816+ .forEach { addStatisticElement(it.getText(this , statistics)) }
846817 }
847818 }
848819
849820 private fun removeStatisticElements () {
850- val childsToRemove = ArrayList < View ?>()
851- for (i in 0 until binding.map.statisticsLayout.childCount) {
852- val childView = binding.map.statisticsLayout.getChildAt(i)
853- if (childView is TextView ) {
854- childsToRemove.add(childView )
821+ binding.map.statisticsLayout.children
822+ .filterIsInstance< TextView >()
823+ .forEach { view ->
824+ binding.map.statisticsLayout.removeView(view)
825+ binding.map.statistics.removeView(view )
855826 }
856- }
857- childsToRemove.forEach((Consumer { view: View ? ->
858- binding.map.statisticsLayout.removeView(view)
859- binding.map.statistics.removeView(view)
860- }))
861827 }
862828
863829 private fun addStatisticElement (text : String? ) {
864- val textView = TextView (this )
865- textView.setId(View .generateViewId())
866- textView.text = Html .fromHtml(text, Html .FROM_HTML_MODE_COMPACT )
867- textView.setTextColor(getColor(R .color.track_statistic))
868- textView.setTextSize(TypedValue .COMPLEX_UNIT_PT , 10f )
830+ val textView = TextView (this ).apply {
831+ setId(View .generateViewId())
832+ this .text = Html .fromHtml(text, Html .FROM_HTML_MODE_COMPACT )
833+ setTextColor(getColor(R .color.track_statistic))
834+ setTextSize(TypedValue .COMPLEX_UNIT_PT , 10f )
835+ }
869836 binding.map.statisticsLayout.addView(textView)
870837 binding.map.statistics.addView(textView)
871838 }
@@ -935,11 +902,7 @@ open class MapsActivity : BaseActivity(), OnItemGestureListener<MarkerInterface?
935902 )
936903 }
937904 } catch (se: SecurityException ) {
938- Log .e(
939- TAG ,
940- " Error on registering OpenTracksContentObserver" ,
941- se
942- )
905+ Log .e(TAG , " Error on registering OpenTracksContentObserver" , se)
943906 Toast .makeText(
944907 this ,
945908 R .string.error_reg_content_observer,
0 commit comments