diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 9c1e41e..f8d065b 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -3,9 +3,7 @@ package="org.y20k.trackbook"> - + @@ -38,8 +36,8 @@ + android:foregroundServiceType="location" + android:exported="false"> @@ -50,8 +48,8 @@ diff --git a/app/src/main/java/org/y20k/trackbook/helpers/NotificationHelper.kt b/app/src/main/java/org/y20k/trackbook/helpers/NotificationHelper.kt index 99398a2..23157bc 100644 --- a/app/src/main/java/org/y20k/trackbook/helpers/NotificationHelper.kt +++ b/app/src/main/java/org/y20k/trackbook/helpers/NotificationHelper.kt @@ -41,17 +41,11 @@ class NotificationHelper(private val trackerService: TrackerService) { /* Main class variables */ - private val notificationManager: NotificationManager = - trackerService.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager + private val notificationManager: NotificationManager = trackerService.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager /* Creates notification */ - fun createNotification( - trackingState: Int, - trackLength: Float, - duration: Long, - useImperial: Boolean - ): Notification { + fun createNotification(trackingState: Int, trackLength: Float, duration: Long, useImperial: Boolean): Notification { // create notification channel if necessary if (shouldCreateNotificationChannel()) { @@ -59,8 +53,7 @@ class NotificationHelper(private val trackerService: TrackerService) { } // Build notification - val builder = - NotificationCompat.Builder(trackerService, Keys.NOTIFICATION_CHANNEL_RECORDING) + val builder = NotificationCompat.Builder(trackerService, Keys.NOTIFICATION_CHANNEL_RECORDING) builder.setContentIntent(showActionPendingIntent) builder.setSmallIcon(R.drawable.ic_notification_icon_small_24dp) builder.setContentText(getContentString(trackerService, duration, trackLength, useImperial)) @@ -70,23 +63,13 @@ class NotificationHelper(private val trackerService: TrackerService) { Keys.STATE_TRACKING_ACTIVE -> { builder.setContentTitle(trackerService.getString(R.string.notification_title_trackbook_running)) builder.addAction(stopAction) - builder.setLargeIcon( - AppCompatResources.getDrawable( - trackerService, - R.drawable.ic_notification_icon_large_tracking_active_48dp - )!!.toBitmap() - ) + builder.setLargeIcon(AppCompatResources.getDrawable(trackerService, R.drawable.ic_notification_icon_large_tracking_active_48dp)!!.toBitmap()) } else -> { builder.setContentTitle(trackerService.getString(R.string.notification_title_trackbook_not_running)) builder.addAction(resumeAction) builder.addAction(showAction) - builder.setLargeIcon( - AppCompatResources.getDrawable( - trackerService, - R.drawable.ic_notification_icon_large_tracking_stopped_48dp - )!!.toBitmap() - ) + builder.setLargeIcon(AppCompatResources.getDrawable(trackerService, R.drawable.ic_notification_icon_large_tracking_stopped_48dp)!!.toBitmap()) } } @@ -96,77 +79,56 @@ class NotificationHelper(private val trackerService: TrackerService) { /* Build context text for notification builder */ - private fun getContentString( - context: Context, - duration: Long, - trackLength: Float, - useImperial: Boolean - ): String { - return "${LengthUnitHelper.convertDistanceToString( - trackLength, - useImperial - )} • ${DateTimeHelper.convertToReadableTime(context, duration)}" + private fun getContentString(context: Context, duration: Long, trackLength: Float, useImperial: Boolean): String { + return "${LengthUnitHelper.convertDistanceToString(trackLength, useImperial)} • ${DateTimeHelper.convertToReadableTime(context, duration)}" } /* Checks if notification channel should be created */ - private fun shouldCreateNotificationChannel() = - Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && !nowPlayingChannelExists() + private fun shouldCreateNotificationChannel() = Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && !nowPlayingChannelExists() /* Checks if notification channel exists */ @RequiresApi(Build.VERSION_CODES.O) - private fun nowPlayingChannelExists() = - notificationManager.getNotificationChannel(Keys.NOTIFICATION_CHANNEL_RECORDING) != null + private fun nowPlayingChannelExists() = notificationManager.getNotificationChannel(Keys.NOTIFICATION_CHANNEL_RECORDING) != null /* Create a notification channel */ @RequiresApi(Build.VERSION_CODES.O) private fun createNotificationChannel() { - val notificationChannel = NotificationChannel( - Keys.NOTIFICATION_CHANNEL_RECORDING, + val notificationChannel = NotificationChannel(Keys.NOTIFICATION_CHANNEL_RECORDING, trackerService.getString(R.string.notification_channel_recording_name), - NotificationManager.IMPORTANCE_LOW - ) - .apply { - description = - trackerService.getString(R.string.notification_channel_recording_description) - } + NotificationManager.IMPORTANCE_LOW) + .apply { description = trackerService.getString(R.string.notification_channel_recording_description) } notificationManager.createNotificationChannel(notificationChannel) } /* Notification pending intents */ private val stopActionPendingIntent = PendingIntent.getService( - trackerService, 14, - Intent(trackerService, TrackerService::class.java).setAction(Keys.ACTION_STOP), 0 - ) + trackerService,14, + Intent(trackerService, TrackerService::class.java).setAction(Keys.ACTION_STOP),0) private val resumeActionPendingIntent = PendingIntent.getService( trackerService, 16, - Intent(trackerService, TrackerService::class.java).setAction(Keys.ACTION_RESUME), 0 - ) - private val showActionPendingIntent: PendingIntent? = - TaskStackBuilder.create(trackerService).run { - addNextIntentWithParentStack(Intent(trackerService, MainActivity::class.java)) - getPendingIntent(10, PendingIntent.FLAG_UPDATE_CURRENT) - } + Intent(trackerService, TrackerService::class.java).setAction(Keys.ACTION_RESUME),0) + private val showActionPendingIntent: PendingIntent? = TaskStackBuilder.create(trackerService).run { + addNextIntentWithParentStack(Intent(trackerService, MainActivity::class.java)) + getPendingIntent(10, PendingIntent.FLAG_UPDATE_CURRENT) + } /* Notification actions */ private val stopAction = NotificationCompat.Action( R.drawable.ic_notification_action_stop_24dp, trackerService.getString(R.string.notification_stop), - stopActionPendingIntent - ) + stopActionPendingIntent) private val resumeAction = NotificationCompat.Action( R.drawable.ic_notification_action_resume_36dp, trackerService.getString(R.string.notification_resume), - resumeActionPendingIntent - ) + resumeActionPendingIntent) private val showAction = NotificationCompat.Action( R.drawable.ic_notification_action_show_36dp, trackerService.getString(R.string.notification_show), - showActionPendingIntent - ) + showActionPendingIntent) -} +} \ No newline at end of file diff --git a/app/src/main/java/org/y20k/trackbook/helpers/PreferencesHelper.kt b/app/src/main/java/org/y20k/trackbook/helpers/PreferencesHelper.kt index e2abe5d..8b07e5e 100644 --- a/app/src/main/java/org/y20k/trackbook/helpers/PreferencesHelper.kt +++ b/app/src/main/java/org/y20k/trackbook/helpers/PreferencesHelper.kt @@ -80,10 +80,7 @@ object PreferencesHelper { // get preferences val settings = PreferenceManager.getDefaultSharedPreferences(context) // load length unit system - return settings.getBoolean( - Keys.PREF_USE_IMPERIAL_UNITS, - LengthUnitHelper.useImperialUnits() - ) + return settings.getBoolean(Keys.PREF_USE_IMPERIAL_UNITS, LengthUnitHelper.useImperialUnits()) } @@ -100,10 +97,7 @@ object PreferencesHelper { // get preferences val settings = PreferenceManager.getDefaultSharedPreferences(context) // load tracking state - return settings.getInt( - Keys.PREF_LOCATION_ACCURACY_THRESHOLD, - Keys.DEFAULT_THRESHOLD_LOCATION_ACCURACY - ) + return settings.getInt(Keys.PREF_LOCATION_ACCURACY_THRESHOLD, Keys.DEFAULT_THRESHOLD_LOCATION_ACCURACY) } @@ -111,23 +105,15 @@ object PreferencesHelper { fun loadCurrentBestLocation(context: Context): Location { // get preferences val settings = PreferenceManager.getDefaultSharedPreferences(context) - val provider: String = settings.getString( - Keys.PREF_CURRENT_BEST_LOCATION_PROVIDER, - LocationManager.NETWORK_PROVIDER - ) ?: LocationManager.NETWORK_PROVIDER + val provider: String = settings.getString(Keys.PREF_CURRENT_BEST_LOCATION_PROVIDER, LocationManager.NETWORK_PROVIDER) ?: LocationManager.NETWORK_PROVIDER // create location val currentBestLocation = Location(provider) // load location attributes - currentBestLocation.latitude = - settings.getDouble(Keys.PREF_CURRENT_BEST_LOCATION_LATITUDE, Keys.DEFAULT_LATITUDE) - currentBestLocation.longitude = - settings.getDouble(Keys.PREF_CURRENT_BEST_LOCATION_LONGITUDE, Keys.DEFAULT_LONGITUDE) - currentBestLocation.accuracy = - settings.getFloat(Keys.PREF_CURRENT_BEST_LOCATION_ACCURACY, Keys.DEFAULT_ACCURACY) - currentBestLocation.altitude = - settings.getDouble(Keys.PREF_CURRENT_BEST_LOCATION_ALTITUDE, Keys.DEFAULT_ALTITUDE) - currentBestLocation.time = - settings.getLong(Keys.PREF_CURRENT_BEST_LOCATION_TIME, Keys.DEFAULT_TIME) + currentBestLocation.latitude = settings.getDouble(Keys.PREF_CURRENT_BEST_LOCATION_LATITUDE, Keys.DEFAULT_LATITUDE) + currentBestLocation.longitude = settings.getDouble(Keys.PREF_CURRENT_BEST_LOCATION_LONGITUDE, Keys.DEFAULT_LONGITUDE) + currentBestLocation.accuracy = settings.getFloat(Keys.PREF_CURRENT_BEST_LOCATION_ACCURACY, Keys.DEFAULT_ACCURACY) + currentBestLocation.altitude = settings.getDouble(Keys.PREF_CURRENT_BEST_LOCATION_ALTITUDE, Keys.DEFAULT_ALTITUDE) + currentBestLocation.time = settings.getLong(Keys.PREF_CURRENT_BEST_LOCATION_TIME, Keys.DEFAULT_TIME) return currentBestLocation } @@ -149,9 +135,7 @@ object PreferencesHelper { /* Load currently selected app theme */ fun loadThemeSelection(context: Context): String { - return PreferenceManager.getDefaultSharedPreferences(context) - .getString(Keys.PREF_THEME_SELECTION, Keys.STATE_THEME_FOLLOW_SYSTEM) - ?: Keys.STATE_THEME_FOLLOW_SYSTEM + return PreferenceManager.getDefaultSharedPreferences(context).getString(Keys.PREF_THEME_SELECTION, Keys.STATE_THEME_FOLLOW_SYSTEM) ?: Keys.STATE_THEME_FOLLOW_SYSTEM } @@ -170,4 +154,4 @@ object PreferencesHelper { editor.apply() } -} +} \ No newline at end of file diff --git a/app/src/main/java/org/y20k/trackbook/ui/MapFragmentLayoutHolder.kt b/app/src/main/java/org/y20k/trackbook/ui/MapFragmentLayoutHolder.kt index bf56c36..66bf9ab 100644 --- a/app/src/main/java/org/y20k/trackbook/ui/MapFragmentLayoutHolder.kt +++ b/app/src/main/java/org/y20k/trackbook/ui/MapFragmentLayoutHolder.kt @@ -51,25 +51,18 @@ import org.y20k.trackbook.helpers.PreferencesHelper /* * MapFragmentLayoutHolder class */ -data class MapFragmentLayoutHolder( - private var context: Context, - private var markerListener: MapOverlay.MarkerListener, - private var inflater: LayoutInflater, - private var container: ViewGroup?, - private val startLocation: Location, - private val trackingState: Int -) { +data class MapFragmentLayoutHolder(private var context: Context, private var markerListener: MapOverlay.MarkerListener, private var inflater: LayoutInflater, private var container: ViewGroup?, private val startLocation: Location, private val trackingState: Int) { /* Define log tag */ private val TAG: String = LogHelper.makeLogTag(MapFragmentLayoutHolder::class.java) /* Main class variables */ - val rootView: View = inflater.inflate(R.layout.fragment_map, container, false) - private val mapView: MapView + val rootView: View + val mapView: MapView val currentLocationButton: FloatingActionButton val recordingButton: FloatingActionButton - private val recordingButtonSubMenu: Group + val recordingButtonSubMenu: Group val saveButton: FloatingActionButton val clearButton: FloatingActionButton val resumeButton: FloatingActionButton @@ -84,6 +77,7 @@ data class MapFragmentLayoutHolder( /* Init block */ init { // find views + rootView = inflater.inflate(R.layout.fragment_map, container, false) mapView = rootView.findViewById(R.id.map) currentLocationButton = rootView.findViewById(R.id.fab_location_button) recordingButton = rootView.findViewById(R.id.fab_main_button) @@ -108,19 +102,14 @@ data class MapFragmentLayoutHolder( } // add compass to map - val compassOverlay = - CompassOverlay(context, InternalCompassOrientationProvider(context), mapView) + val compassOverlay = CompassOverlay(context, InternalCompassOrientationProvider(context), mapView) compassOverlay.enableCompass() compassOverlay.setCompassCenter(36f, 60f) mapView.overlays.add(compassOverlay) // add my location overlay - currentPositionOverlay = MapOverlay(markerListener).createMyLocationOverlay( - context, - startLocation, - trackingState - ) + currentPositionOverlay = MapOverlay(markerListener).createMyLocationOverlay(context, startLocation, trackingState) mapView.overlays.add(currentPositionOverlay) centerMap(startLocation) @@ -138,7 +127,7 @@ data class MapFragmentLayoutHolder( /* Listen for user interaction */ @SuppressLint("ClickableViewAccessibility") private fun addInteractionListener() { - mapView.setOnTouchListener { _, _ -> + mapView.setOnTouchListener { v, event -> userInteraction = true false } @@ -159,7 +148,7 @@ data class MapFragmentLayoutHolder( /* Save current best location and state of map to shared preferences */ fun saveState(currentBestLocation: Location) { PreferencesHelper.saveCurrentBestLocation(context, currentBestLocation) - PreferencesHelper.saveZoomLevel(context, mapView.zoomLevelDouble) + PreferencesHelper.saveZoomLevel(context, mapView.getZoomLevelDouble()) // reset user interaction state userInteraction = false } @@ -168,8 +157,7 @@ data class MapFragmentLayoutHolder( /* Mark current position on map */ fun markCurrentPosition(location: Location, trackingState: Int = Keys.STATE_TRACKING_NOT) { mapView.overlays.remove(currentPositionOverlay) - currentPositionOverlay = - MapOverlay(markerListener).createMyLocationOverlay(context, location, trackingState) + currentPositionOverlay = MapOverlay(markerListener).createMyLocationOverlay(context, location, trackingState) mapView.overlays.add(currentPositionOverlay) } @@ -180,8 +168,7 @@ data class MapFragmentLayoutHolder( mapView.overlays.remove(currentTrackOverlay) } if (track.wayPoints.isNotEmpty()) { - currentTrackOverlay = - MapOverlay(markerListener).createTrackOverlay(context, track, trackingState) + currentTrackOverlay = MapOverlay(markerListener).createTrackOverlay(context, track, trackingState) mapView.overlays.add(currentTrackOverlay) } } @@ -214,13 +201,10 @@ data class MapFragmentLayoutHolder( } + /* Toggles content and visibility of the location error snackbar */ fun toggleLocationErrorBar(gpsProviderActive: Boolean, networkProviderActive: Boolean) { - if (ContextCompat.checkSelfPermission( - context, - Manifest.permission.ACCESS_FINE_LOCATION - ) == PackageManager.PERMISSION_DENIED - ) { + if (ContextCompat.checkSelfPermission(context, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_DENIED) { // CASE: Location permission not granted locationErrorBar.setText(R.string.snackbar_message_location_permission_denied) locationErrorBar.show() @@ -234,4 +218,4 @@ data class MapFragmentLayoutHolder( } } -} +} \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_bug_report_24dp.xml b/app/src/main/res/drawable/ic_bug_report_24dp.xml index 8491cb2..d3767ca 100644 --- a/app/src/main/res/drawable/ic_bug_report_24dp.xml +++ b/app/src/main/res/drawable/ic_bug_report_24dp.xml @@ -3,7 +3,7 @@ android:height="24dp" android:viewportWidth="24" android:viewportHeight="24"> - + diff --git a/app/src/main/res/drawable/ic_marker_location_blue_24dp.xml b/app/src/main/res/drawable/ic_marker_location_blue_24dp.xml index de64c1f..730c19e 100755 --- a/app/src/main/res/drawable/ic_marker_location_blue_24dp.xml +++ b/app/src/main/res/drawable/ic_marker_location_blue_24dp.xml @@ -1,13 +1,13 @@ + android:height="24dp" + android:viewportHeight="96.0" + android:viewportWidth="96.0" + android:width="24dp"> + android:pathData="M48,48m-48,0a48,48 0,1 1,96 0a48,48 0,1 1,-96 0"/> + android:pathData="M48,48m-24,0a24,24 0,1 1,48 0a24,24 0,1 1,-48 0"/> diff --git a/app/src/main/res/drawable/ic_marker_track_location_red_24dp.xml b/app/src/main/res/drawable/ic_marker_track_location_red_24dp.xml index 4264365..29baa58 100755 --- a/app/src/main/res/drawable/ic_marker_track_location_red_24dp.xml +++ b/app/src/main/res/drawable/ic_marker_track_location_red_24dp.xml @@ -1,10 +1,10 @@ + android:height="24dp" + android:viewportHeight="96.0" + android:viewportWidth="96.0" + android:width="24dp"> + android:pathData="M48,48m-24,0a24,24 0,1 1,48 0a24,24 0,1 1,-48 0"/> diff --git a/app/src/main/res/drawable/ic_smartphone_24dp.xml b/app/src/main/res/drawable/ic_smartphone_24dp.xml index 465baa1..23254dc 100644 --- a/app/src/main/res/drawable/ic_smartphone_24dp.xml +++ b/app/src/main/res/drawable/ic_smartphone_24dp.xml @@ -1,9 +1,9 @@ + android:width="24dp" + android:height="24dp" + android:viewportWidth="24.0" + android:viewportHeight="24.0"> + android:pathData="M17,1.01L7,1c-1.1,0 -2,0.9 -2,2v18c0,1.1 0.9,2 2,2h10c1.1,0 2,-0.9 2,-2V3c0,-1.1 -0.9,-1.99 -2,-1.99zM17,19H7V5h10v14z"/> diff --git a/app/src/main/res/drawable/ic_star_blue_24dp.xml b/app/src/main/res/drawable/ic_star_blue_24dp.xml index 889e9f3..6ba138a 100644 --- a/app/src/main/res/drawable/ic_star_blue_24dp.xml +++ b/app/src/main/res/drawable/ic_star_blue_24dp.xml @@ -1,9 +1,9 @@ + android:width="24dp" + android:height="24dp" + android:viewportWidth="24.0" + android:viewportHeight="24.0"> + android:pathData="M12,17.27L18.18,21l-1.64,-7.03L22,9.24l-7.19,-0.61L12,2 9.19,8.63 2,9.24l5.46,4.73L5.82,21z"/> diff --git a/app/src/main/res/drawable/ic_star_filled_24dp.xml b/app/src/main/res/drawable/ic_star_filled_24dp.xml index feb34af..5e1387f 100644 --- a/app/src/main/res/drawable/ic_star_filled_24dp.xml +++ b/app/src/main/res/drawable/ic_star_filled_24dp.xml @@ -1,9 +1,9 @@ + android:width="24dp" + android:height="24dp" + android:viewportWidth="24.0" + android:viewportHeight="24.0"> + android:pathData="M12,17.27L18.18,21l-1.64,-7.03L22,9.24l-7.19,-0.61L12,2 9.19,8.63 2,9.24l5.46,4.73L5.82,21z"/> diff --git a/app/src/main/res/drawable/ic_star_red_24dp.xml b/app/src/main/res/drawable/ic_star_red_24dp.xml index 3fb5217..c30d723 100644 --- a/app/src/main/res/drawable/ic_star_red_24dp.xml +++ b/app/src/main/res/drawable/ic_star_red_24dp.xml @@ -1,9 +1,9 @@ + android:width="24dp" + android:height="24dp" + android:viewportWidth="24.0" + android:viewportHeight="24.0"> + android:pathData="M12,17.27L18.18,21l-1.64,-7.03L22,9.24l-7.19,-0.61L12,2 9.19,8.63 2,9.24l5.46,4.73L5.82,21z"/> diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index b6c1e47..e60c985 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -31,21 +31,17 @@ - - - #FF595959 + #FF595959 #FF7D7D7D #FFDADADA #FFF2F2F2 #FF414141 #FF2D2D2D - - #DC3D33 + #DC3D33 #FFCA2D23 - - #FF121212 + #FF121212 #FFFFFFFF #00ffffff