Reverts code style changes introduced in 4dcea979 and 66f4865d

master
y20k 2020-08-03 11:13:25 +02:00
parent 2944273a01
commit c4d6a0479b
No known key found for this signature in database
GPG Key ID: 824D4259F41FAFF6
12 changed files with 88 additions and 164 deletions

View File

@ -3,9 +3,7 @@
package="org.y20k.trackbook">
<!-- USE GPS AND NETWORK - EXCLUDE NON-GPS DEVICES -->
<uses-feature
android:name="android.hardware.location.gps"
android:required="true" />
<uses-feature android:name="android.hardware.location.gps" android:required="true" />
<uses-feature android:name="android.hardware.location.network" />
<!-- NORMAL PERMISSIONS, automatically granted -->
@ -38,8 +36,8 @@
<!-- TRACKER SERVICE -->
<service
android:name=".TrackerService"
android:exported="false"
android:foregroundServiceType="location">
android:foregroundServiceType="location"
android:exported="false">
<intent-filter>
<action android:name="org.y20k.trackbook.action.START" />
<action android:name="org.y20k.trackbook.action.STOP" />
@ -50,8 +48,8 @@
<!-- TRACKING TOGGLE SERVICE SYSTEM QUICK SETTINGS -->
<service
android:name=".TrackingToggleTileService"
android:icon="@drawable/ic_notification_icon_small_24dp"
android:label="@string/quick_settings_tile_title_default"
android:icon="@drawable/ic_notification_icon_small_24dp"
android:permission="android.permission.BIND_QUICK_SETTINGS_TILE">
<intent-filter>
<action android:name="android.service.quicksettings.action.QS_TILE" />

View File

@ -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,42 +79,27 @@ 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)
}
@ -139,14 +107,11 @@ class NotificationHelper(private val trackerService: TrackerService) {
/* Notification pending intents */
private val stopActionPendingIntent = PendingIntent.getService(
trackerService,14,
Intent(trackerService, TrackerService::class.java).setAction(Keys.ACTION_STOP), 0
)
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 {
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)
}
@ -156,17 +121,14 @@ class NotificationHelper(private val trackerService: TrackerService) {
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)
}

View File

@ -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
}

View File

@ -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()

View File

@ -1,8 +1,8 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportHeight="96.0"
android:viewportWidth="96.0"
android:viewportHeight="96.0">
android:width="24dp">
<path
android:fillAlpha="0.33"
android:fillColor="@color/trackbook_blue"

View File

@ -1,8 +1,8 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportHeight="96.0"
android:viewportWidth="96.0"
android:viewportHeight="96.0">
android:width="24dp">
<path
android:fillColor="@color/trackbook_red"

View File

@ -31,21 +31,17 @@
<!-- COLOR NAMES -->
<!-- derived from recommended dark theme surface color -->
<color name="trackbook_grey">#FF595959</color>
<color name="trackbook_grey">#FF595959</color> <!-- derived from recommended dark theme surface color -->
<color name="trackbook_grey_light">#FF7D7D7D</color>
<color name="trackbook_grey_lighter">#FFDADADA</color>
<color name="trackbook_grey_very_light">#FFF2F2F2</color>
<color name="trackbook_grey_dark">#FF414141</color>
<color name="trackbook_grey_darker">#FF2D2D2D</color>
<!-- Slightly muted variant of -> Material Design 2: Red 600 -->
<color name="trackbook_red">#DC3D33</color>
<color name="trackbook_red">#DC3D33</color> <!-- Slightly muted variant of -> Material Design 2: Red 600 -->
<color name="trackbook_red_dark">#FFCA2D23</color>
<!-- Material Design recommended dark theme surface color -->
<color name="trackbook_black">#FF121212</color>
<color name="trackbook_black">#FF121212</color> <!-- Material Design recommended dark theme surface color -->
<color name="trackbook_white">#FFFFFFFF</color>
<color name="trackbook_transparent">#00ffffff</color>