Miscellaneous code cleanup
This commit is contained in:
parent
4dcea97982
commit
66f4865de3
26 changed files with 177 additions and 193 deletions
|
@ -78,13 +78,13 @@ class MainActivity : AppCompatActivity() {
|
||||||
navHostFragment.navController.addOnDestinationChangedListener { _, destination, _ ->
|
navHostFragment.navController.addOnDestinationChangedListener { _, destination, _ ->
|
||||||
when (destination.id) {
|
when (destination.id) {
|
||||||
R.id.fragment_track -> {
|
R.id.fragment_track -> {
|
||||||
runOnUiThread(Runnable() {
|
runOnUiThread {
|
||||||
run() {
|
run {
|
||||||
// mark menu item "Tracks" as checked
|
// mark menu item "Tracks" as checked
|
||||||
bottomNavigationView.menu.findItem(R.id.tracklist_fragment)
|
bottomNavigationView.menu.findItem(R.id.tracklist_fragment)
|
||||||
.setChecked(true)
|
.setChecked(true)
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
else -> {
|
else -> {
|
||||||
// do nothing
|
// do nothing
|
||||||
|
@ -111,7 +111,7 @@ class MainActivity : AppCompatActivity() {
|
||||||
* Defines the listener for changes in shared preferences
|
* Defines the listener for changes in shared preferences
|
||||||
*/
|
*/
|
||||||
private val sharedPreferenceChangeListener =
|
private val sharedPreferenceChangeListener =
|
||||||
SharedPreferences.OnSharedPreferenceChangeListener { sharedPreferences, key ->
|
SharedPreferences.OnSharedPreferenceChangeListener { _, key ->
|
||||||
when (key) {
|
when (key) {
|
||||||
Keys.PREF_THEME_SELECTION -> {
|
Keys.PREF_THEME_SELECTION -> {
|
||||||
AppThemeHelper.setTheme(PreferencesHelper.loadThemeSelection(this@MainActivity))
|
AppThemeHelper.setTheme(PreferencesHelper.loadThemeSelection(this@MainActivity))
|
||||||
|
|
|
@ -281,7 +281,7 @@ class MapFragment : Fragment(), YesNoDialog.YesNoDialogListener, MapOverlay.Mark
|
||||||
|
|
||||||
/* Opens a track in TrackFragment */
|
/* Opens a track in TrackFragment */
|
||||||
private fun openTrack(tracklistElement: TracklistElement) {
|
private fun openTrack(tracklistElement: TracklistElement) {
|
||||||
val bundle: Bundle = Bundle()
|
val bundle = Bundle()
|
||||||
bundle.putString(Keys.ARG_TRACK_TITLE, tracklistElement.name)
|
bundle.putString(Keys.ARG_TRACK_TITLE, tracklistElement.name)
|
||||||
bundle.putString(Keys.ARG_TRACK_FILE_URI, tracklistElement.trackUriString)
|
bundle.putString(Keys.ARG_TRACK_FILE_URI, tracklistElement.trackUriString)
|
||||||
bundle.putString(Keys.ARG_GPX_FILE_URI, tracklistElement.gpxUriString)
|
bundle.putString(Keys.ARG_GPX_FILE_URI, tracklistElement.gpxUriString)
|
||||||
|
@ -294,7 +294,7 @@ class MapFragment : Fragment(), YesNoDialog.YesNoDialogListener, MapOverlay.Mark
|
||||||
* Defines the listener for changes in shared preferences
|
* Defines the listener for changes in shared preferences
|
||||||
*/
|
*/
|
||||||
private val sharedPreferenceChangeListener =
|
private val sharedPreferenceChangeListener =
|
||||||
SharedPreferences.OnSharedPreferenceChangeListener { sharedPreferences, key ->
|
SharedPreferences.OnSharedPreferenceChangeListener { _, key ->
|
||||||
when (key) {
|
when (key) {
|
||||||
Keys.PREF_TRACKING_STATE -> {
|
Keys.PREF_TRACKING_STATE -> {
|
||||||
if (activity != null) {
|
if (activity != null) {
|
||||||
|
|
|
@ -63,7 +63,7 @@ class SettingsFragment : PreferenceFragmentCompat(), YesNoDialog.YesNoDialogList
|
||||||
val screen = preferenceManager.createPreferenceScreen(context)
|
val screen = preferenceManager.createPreferenceScreen(context)
|
||||||
|
|
||||||
// set up "Restrict to GPS" preference
|
// set up "Restrict to GPS" preference
|
||||||
val preferenceGpsOnly: SwitchPreferenceCompat = SwitchPreferenceCompat(activity as Context)
|
val preferenceGpsOnly = SwitchPreferenceCompat(activity as Context)
|
||||||
preferenceGpsOnly.title = getString(R.string.pref_gps_only_title)
|
preferenceGpsOnly.title = getString(R.string.pref_gps_only_title)
|
||||||
preferenceGpsOnly.setIcon(R.drawable.ic_gps_24dp)
|
preferenceGpsOnly.setIcon(R.drawable.ic_gps_24dp)
|
||||||
preferenceGpsOnly.key = Keys.PREF_GPS_ONLY
|
preferenceGpsOnly.key = Keys.PREF_GPS_ONLY
|
||||||
|
@ -72,8 +72,7 @@ class SettingsFragment : PreferenceFragmentCompat(), YesNoDialog.YesNoDialogList
|
||||||
preferenceGpsOnly.setDefaultValue(false)
|
preferenceGpsOnly.setDefaultValue(false)
|
||||||
|
|
||||||
// set up "Use Imperial Measurements" preference
|
// set up "Use Imperial Measurements" preference
|
||||||
val preferenceImperialMeasurementUnits: SwitchPreferenceCompat =
|
val preferenceImperialMeasurementUnits = SwitchPreferenceCompat(activity as Context)
|
||||||
SwitchPreferenceCompat(activity as Context)
|
|
||||||
preferenceImperialMeasurementUnits.title =
|
preferenceImperialMeasurementUnits.title =
|
||||||
getString(R.string.pref_imperial_measurement_units_title)
|
getString(R.string.pref_imperial_measurement_units_title)
|
||||||
preferenceImperialMeasurementUnits.setIcon(R.drawable.ic_square_foot_24px)
|
preferenceImperialMeasurementUnits.setIcon(R.drawable.ic_square_foot_24px)
|
||||||
|
@ -85,7 +84,7 @@ class SettingsFragment : PreferenceFragmentCompat(), YesNoDialog.YesNoDialogList
|
||||||
preferenceImperialMeasurementUnits.setDefaultValue(LengthUnitHelper.useImperialUnits())
|
preferenceImperialMeasurementUnits.setDefaultValue(LengthUnitHelper.useImperialUnits())
|
||||||
|
|
||||||
// set up "App Theme" preference
|
// set up "App Theme" preference
|
||||||
val preferenceThemeSelection: ListPreference = ListPreference(activity as Context)
|
val preferenceThemeSelection = ListPreference(activity as Context)
|
||||||
preferenceThemeSelection.title = getString(R.string.pref_theme_selection_title)
|
preferenceThemeSelection.title = getString(R.string.pref_theme_selection_title)
|
||||||
preferenceThemeSelection.setIcon(R.drawable.ic_smartphone_24dp)
|
preferenceThemeSelection.setIcon(R.drawable.ic_smartphone_24dp)
|
||||||
preferenceThemeSelection.key = Keys.PREF_THEME_SELECTION
|
preferenceThemeSelection.key = Keys.PREF_THEME_SELECTION
|
||||||
|
@ -107,9 +106,7 @@ class SettingsFragment : PreferenceFragmentCompat(), YesNoDialog.YesNoDialogList
|
||||||
if (preference is ListPreference) {
|
if (preference is ListPreference) {
|
||||||
val index: Int = preference.entryValues.indexOf(newValue)
|
val index: Int = preference.entryValues.indexOf(newValue)
|
||||||
preferenceThemeSelection.summary =
|
preferenceThemeSelection.summary =
|
||||||
"${getString(R.string.pref_theme_selection_summary)} ${preference.entries.get(
|
"${getString(R.string.pref_theme_selection_summary)} ${preference.entries[index]}"
|
||||||
index
|
|
||||||
)}"
|
|
||||||
return@setOnPreferenceChangeListener true
|
return@setOnPreferenceChangeListener true
|
||||||
} else {
|
} else {
|
||||||
return@setOnPreferenceChangeListener false
|
return@setOnPreferenceChangeListener false
|
||||||
|
@ -117,7 +114,7 @@ class SettingsFragment : PreferenceFragmentCompat(), YesNoDialog.YesNoDialogList
|
||||||
}
|
}
|
||||||
|
|
||||||
// set up "Delete Non-Starred" preference
|
// set up "Delete Non-Starred" preference
|
||||||
val preferenceDeleteNonStarred: Preference = Preference(activity as Context)
|
val preferenceDeleteNonStarred = Preference(activity as Context)
|
||||||
preferenceDeleteNonStarred.title = getString(R.string.pref_delete_non_starred_title)
|
preferenceDeleteNonStarred.title = getString(R.string.pref_delete_non_starred_title)
|
||||||
preferenceDeleteNonStarred.setIcon(R.drawable.ic_delete_24dp)
|
preferenceDeleteNonStarred.setIcon(R.drawable.ic_delete_24dp)
|
||||||
preferenceDeleteNonStarred.summary = getString(R.string.pref_delete_non_starred_summary)
|
preferenceDeleteNonStarred.summary = getString(R.string.pref_delete_non_starred_summary)
|
||||||
|
@ -132,7 +129,7 @@ class SettingsFragment : PreferenceFragmentCompat(), YesNoDialog.YesNoDialogList
|
||||||
}
|
}
|
||||||
|
|
||||||
// set up "Accuracy Threshold" preference
|
// set up "Accuracy Threshold" preference
|
||||||
val preferenceAccuracyThreshold: SeekBarPreference = SeekBarPreference(activity as Context)
|
val preferenceAccuracyThreshold = SeekBarPreference(activity as Context)
|
||||||
preferenceAccuracyThreshold.title = getString(R.string.pref_accuracy_threshold_title)
|
preferenceAccuracyThreshold.title = getString(R.string.pref_accuracy_threshold_title)
|
||||||
preferenceAccuracyThreshold.setIcon(R.drawable.ic_timeline_24dp)
|
preferenceAccuracyThreshold.setIcon(R.drawable.ic_timeline_24dp)
|
||||||
preferenceAccuracyThreshold.key = Keys.PREF_LOCATION_ACCURACY_THRESHOLD
|
preferenceAccuracyThreshold.key = Keys.PREF_LOCATION_ACCURACY_THRESHOLD
|
||||||
|
@ -142,7 +139,7 @@ class SettingsFragment : PreferenceFragmentCompat(), YesNoDialog.YesNoDialogList
|
||||||
preferenceAccuracyThreshold.setDefaultValue(Keys.DEFAULT_THRESHOLD_LOCATION_ACCURACY)
|
preferenceAccuracyThreshold.setDefaultValue(Keys.DEFAULT_THRESHOLD_LOCATION_ACCURACY)
|
||||||
|
|
||||||
// set up "Reset" preference
|
// set up "Reset" preference
|
||||||
val preferenceResetAdvanced: Preference = Preference(activity as Context)
|
val preferenceResetAdvanced = Preference(activity as Context)
|
||||||
preferenceResetAdvanced.title = getString(R.string.pref_reset_advanced_title)
|
preferenceResetAdvanced.title = getString(R.string.pref_reset_advanced_title)
|
||||||
preferenceResetAdvanced.setIcon(R.drawable.ic_undo_24dp)
|
preferenceResetAdvanced.setIcon(R.drawable.ic_undo_24dp)
|
||||||
preferenceResetAdvanced.summary = getString(R.string.pref_reset_advanced_summary)
|
preferenceResetAdvanced.summary = getString(R.string.pref_reset_advanced_summary)
|
||||||
|
@ -152,7 +149,7 @@ class SettingsFragment : PreferenceFragmentCompat(), YesNoDialog.YesNoDialogList
|
||||||
}
|
}
|
||||||
|
|
||||||
// set up "App Version" preference
|
// set up "App Version" preference
|
||||||
val preferenceAppVersion: Preference = Preference(context)
|
val preferenceAppVersion = Preference(context)
|
||||||
preferenceAppVersion.title = getString(R.string.pref_app_version_title)
|
preferenceAppVersion.title = getString(R.string.pref_app_version_title)
|
||||||
preferenceAppVersion.setIcon(R.drawable.ic_info_24dp)
|
preferenceAppVersion.setIcon(R.drawable.ic_info_24dp)
|
||||||
preferenceAppVersion.summary =
|
preferenceAppVersion.summary =
|
||||||
|
@ -174,7 +171,7 @@ class SettingsFragment : PreferenceFragmentCompat(), YesNoDialog.YesNoDialogList
|
||||||
}
|
}
|
||||||
|
|
||||||
// set up "Report Issue" preference
|
// set up "Report Issue" preference
|
||||||
val preferenceReportIssue: Preference = Preference(context)
|
val preferenceReportIssue = Preference(context)
|
||||||
preferenceReportIssue.title = getString(R.string.pref_report_issue_title)
|
preferenceReportIssue.title = getString(R.string.pref_report_issue_title)
|
||||||
preferenceReportIssue.setIcon(R.drawable.ic_bug_report_24dp)
|
preferenceReportIssue.setIcon(R.drawable.ic_bug_report_24dp)
|
||||||
preferenceReportIssue.summary = getString(R.string.pref_report_issue_summary)
|
preferenceReportIssue.summary = getString(R.string.pref_report_issue_summary)
|
||||||
|
@ -189,21 +186,21 @@ class SettingsFragment : PreferenceFragmentCompat(), YesNoDialog.YesNoDialogList
|
||||||
}
|
}
|
||||||
|
|
||||||
// set preference categories
|
// set preference categories
|
||||||
val preferenceCategoryGeneral: PreferenceCategory = PreferenceCategory(activity as Context)
|
val preferenceCategoryGeneral = PreferenceCategory(activity as Context)
|
||||||
preferenceCategoryGeneral.title = getString(R.string.pref_general_title)
|
preferenceCategoryGeneral.title = getString(R.string.pref_general_title)
|
||||||
preferenceCategoryGeneral.contains(preferenceImperialMeasurementUnits)
|
preferenceCategoryGeneral.contains(preferenceImperialMeasurementUnits)
|
||||||
preferenceCategoryGeneral.contains(preferenceGpsOnly)
|
preferenceCategoryGeneral.contains(preferenceGpsOnly)
|
||||||
val preferenceCategoryMaintenance: PreferenceCategory =
|
val preferenceCategoryMaintenance =
|
||||||
PreferenceCategory(activity as Context)
|
PreferenceCategory(activity as Context)
|
||||||
preferenceCategoryMaintenance.title = getString(R.string.pref_maintenance_title)
|
preferenceCategoryMaintenance.title = getString(R.string.pref_maintenance_title)
|
||||||
preferenceCategoryMaintenance.contains(preferenceDeleteNonStarred)
|
preferenceCategoryMaintenance.contains(preferenceDeleteNonStarred)
|
||||||
|
|
||||||
val preferenceCategoryAdvanced: PreferenceCategory = PreferenceCategory(activity as Context)
|
val preferenceCategoryAdvanced = PreferenceCategory(activity as Context)
|
||||||
preferenceCategoryAdvanced.title = getString(R.string.pref_advanced_title)
|
preferenceCategoryAdvanced.title = getString(R.string.pref_advanced_title)
|
||||||
preferenceCategoryAdvanced.contains(preferenceAccuracyThreshold)
|
preferenceCategoryAdvanced.contains(preferenceAccuracyThreshold)
|
||||||
preferenceCategoryAdvanced.contains(preferenceResetAdvanced)
|
preferenceCategoryAdvanced.contains(preferenceResetAdvanced)
|
||||||
|
|
||||||
val preferenceCategoryAbout: PreferenceCategory = PreferenceCategory(context)
|
val preferenceCategoryAbout = PreferenceCategory(context)
|
||||||
preferenceCategoryAbout.title = getString(R.string.pref_about_title)
|
preferenceCategoryAbout.title = getString(R.string.pref_about_title)
|
||||||
preferenceCategoryAbout.contains(preferenceAppVersion)
|
preferenceCategoryAbout.contains(preferenceAppVersion)
|
||||||
preferenceCategoryAbout.contains(preferenceReportIssue)
|
preferenceCategoryAbout.contains(preferenceReportIssue)
|
||||||
|
@ -249,7 +246,7 @@ class SettingsFragment : PreferenceFragmentCompat(), YesNoDialog.YesNoDialogList
|
||||||
|
|
||||||
|
|
||||||
/* Removes track and track files for given position - used by TracklistFragment */
|
/* Removes track and track files for given position - used by TracklistFragment */
|
||||||
fun deleteNonStarred(context: Context) {
|
private fun deleteNonStarred(context: Context) {
|
||||||
val backgroundJob = Job()
|
val backgroundJob = Job()
|
||||||
val uiScope = CoroutineScope(Dispatchers.Main + backgroundJob)
|
val uiScope = CoroutineScope(Dispatchers.Main + backgroundJob)
|
||||||
uiScope.launch {
|
uiScope.launch {
|
||||||
|
|
|
@ -64,10 +64,10 @@ class TrackFragment : Fragment(), RenameTrackDialog.RenameTrackListener,
|
||||||
// get track
|
// get track
|
||||||
val fileUriString: String =
|
val fileUriString: String =
|
||||||
arguments?.getString(Keys.ARG_TRACK_FILE_URI, String()) ?: String()
|
arguments?.getString(Keys.ARG_TRACK_FILE_URI, String()) ?: String()
|
||||||
if (fileUriString.isNotBlank()) {
|
track = if (fileUriString.isNotBlank()) {
|
||||||
track = FileHelper.readTrack(activity as Context, Uri.parse(fileUriString))
|
FileHelper.readTrack(Uri.parse(fileUriString))
|
||||||
} else {
|
} else {
|
||||||
track = Track()
|
Track()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,7 +99,7 @@ class TrackFragment : Fragment(), RenameTrackDialog.RenameTrackListener,
|
||||||
}
|
}
|
||||||
// set up delete button
|
// set up delete button
|
||||||
layout.deleteButton.setOnClickListener {
|
layout.deleteButton.setOnClickListener {
|
||||||
val dialogMessage: String =
|
val dialogMessage =
|
||||||
"${getString(R.string.dialog_yes_no_message_delete_recording)}\n\n- ${layout.trackNameView.text}"
|
"${getString(R.string.dialog_yes_no_message_delete_recording)}\n\n- ${layout.trackNameView.text}"
|
||||||
YesNoDialog(this@TrackFragment as YesNoDialog.YesNoDialogListener).show(
|
YesNoDialog(this@TrackFragment as YesNoDialog.YesNoDialogListener).show(
|
||||||
context = activity as Context,
|
context = activity as Context,
|
||||||
|
|
|
@ -48,7 +48,7 @@ import kotlin.coroutines.CoroutineContext
|
||||||
/*
|
/*
|
||||||
* TrackerService class
|
* TrackerService class
|
||||||
*/
|
*/
|
||||||
class TrackerService() : Service(), CoroutineScope, SensorEventListener {
|
class TrackerService : Service(), CoroutineScope, SensorEventListener {
|
||||||
|
|
||||||
/* Define log tag */
|
/* Define log tag */
|
||||||
private val TAG: String = LogHelper.makeLogTag(TrackerService::class.java)
|
private val TAG: String = LogHelper.makeLogTag(TrackerService::class.java)
|
||||||
|
@ -58,16 +58,16 @@ class TrackerService() : Service(), CoroutineScope, SensorEventListener {
|
||||||
var trackingState: Int = Keys.STATE_TRACKING_NOT
|
var trackingState: Int = Keys.STATE_TRACKING_NOT
|
||||||
var gpsProviderActive: Boolean = false
|
var gpsProviderActive: Boolean = false
|
||||||
var networkProviderActive: Boolean = false
|
var networkProviderActive: Boolean = false
|
||||||
var useImperial: Boolean = false
|
private var useImperial: Boolean = false
|
||||||
var gpsOnly: Boolean = false
|
private var gpsOnly: Boolean = false
|
||||||
var locationAccuracyThreshold: Int = Keys.DEFAULT_THRESHOLD_LOCATION_ACCURACY
|
var locationAccuracyThreshold: Int = Keys.DEFAULT_THRESHOLD_LOCATION_ACCURACY
|
||||||
var currentBestLocation: Location = LocationHelper.getDefaultLocation()
|
var currentBestLocation: Location = LocationHelper.getDefaultLocation()
|
||||||
var stepCountOffset: Float = 0f
|
private var stepCountOffset: Float = 0f
|
||||||
var resumed: Boolean = false
|
var resumed: Boolean = false
|
||||||
var track: Track = Track()
|
var track: Track = Track()
|
||||||
var gpsLocationListenerRegistered: Boolean = false
|
private var gpsLocationListenerRegistered: Boolean = false
|
||||||
var networkLocationListenerRegistered: Boolean = false
|
private var networkLocationListenerRegistered: Boolean = false
|
||||||
var bound: Boolean = false
|
private var bound: Boolean = false
|
||||||
private val binder = LocalBinder()
|
private val binder = LocalBinder()
|
||||||
private val handler: Handler = Handler()
|
private val handler: Handler = Handler()
|
||||||
private lateinit var locationManager: LocationManager
|
private lateinit var locationManager: LocationManager
|
||||||
|
@ -99,7 +99,7 @@ class TrackerService() : Service(), CoroutineScope, SensorEventListener {
|
||||||
networkLocationListener = createLocationListener()
|
networkLocationListener = createLocationListener()
|
||||||
trackingState = PreferencesHelper.loadTrackingState(this)
|
trackingState = PreferencesHelper.loadTrackingState(this)
|
||||||
currentBestLocation = LocationHelper.getLastKnownLocation(this)
|
currentBestLocation = LocationHelper.getLastKnownLocation(this)
|
||||||
track = FileHelper.readTrack(this, FileHelper.getTempFileUri(this))
|
track = FileHelper.readTrack(FileHelper.getTempFileUri(this))
|
||||||
backgroundJob = Job()
|
backgroundJob = Job()
|
||||||
PreferenceManager.getDefaultSharedPreferences(this)
|
PreferenceManager.getDefaultSharedPreferences(this)
|
||||||
.registerOnSharedPreferenceChangeListener(sharedPreferenceChangeListener)
|
.registerOnSharedPreferenceChangeListener(sharedPreferenceChangeListener)
|
||||||
|
@ -194,7 +194,7 @@ class TrackerService() : Service(), CoroutineScope, SensorEventListener {
|
||||||
|
|
||||||
/* Overrides onSensorChanged from SensorEventListener */
|
/* Overrides onSensorChanged from SensorEventListener */
|
||||||
override fun onSensorChanged(sensorEvent: SensorEvent?) {
|
override fun onSensorChanged(sensorEvent: SensorEvent?) {
|
||||||
var steps: Float = 0f
|
var steps = 0f
|
||||||
if (sensorEvent != null) {
|
if (sensorEvent != null) {
|
||||||
if (stepCountOffset == 0f) {
|
if (stepCountOffset == 0f) {
|
||||||
// store steps previously recorded by the system
|
// store steps previously recorded by the system
|
||||||
|
@ -212,11 +212,11 @@ class TrackerService() : Service(), CoroutineScope, SensorEventListener {
|
||||||
/* Resume tracking after stop/pause */
|
/* Resume tracking after stop/pause */
|
||||||
fun resumeTracking() {
|
fun resumeTracking() {
|
||||||
// load temp track - returns an empty track if not available
|
// load temp track - returns an empty track if not available
|
||||||
track = FileHelper.readTrack(this, FileHelper.getTempFileUri(this))
|
track = FileHelper.readTrack(FileHelper.getTempFileUri(this))
|
||||||
// try to mark last waypoint as stopover
|
// try to mark last waypoint as stopover
|
||||||
if (track.wayPoints.size > 0) {
|
if (track.wayPoints.size > 0) {
|
||||||
val lastWayPointIndex = track.wayPoints.size - 1
|
val lastWayPointIndex = track.wayPoints.size - 1
|
||||||
track.wayPoints.get(lastWayPointIndex).isStopOver = true
|
track.wayPoints[lastWayPointIndex].isStopOver = true
|
||||||
}
|
}
|
||||||
// set resumed flag
|
// set resumed flag
|
||||||
resumed = true
|
resumed = true
|
||||||
|
@ -480,7 +480,7 @@ class TrackerService() : Service(), CoroutineScope, SensorEventListener {
|
||||||
* Defines the listener for changes in shared preferences
|
* Defines the listener for changes in shared preferences
|
||||||
*/
|
*/
|
||||||
private val sharedPreferenceChangeListener =
|
private val sharedPreferenceChangeListener =
|
||||||
SharedPreferences.OnSharedPreferenceChangeListener { sharedPreferences, key ->
|
SharedPreferences.OnSharedPreferenceChangeListener { _, key ->
|
||||||
when (key) {
|
when (key) {
|
||||||
// preference "Restrict to GPS"
|
// preference "Restrict to GPS"
|
||||||
Keys.PREF_GPS_ONLY -> {
|
Keys.PREF_GPS_ONLY -> {
|
||||||
|
@ -524,7 +524,6 @@ class TrackerService() : Service(), CoroutineScope, SensorEventListener {
|
||||||
override fun run() {
|
override fun run() {
|
||||||
// add waypoint to track - step count is continuously updated in onSensorChanged
|
// add waypoint to track - step count is continuously updated in onSensorChanged
|
||||||
val result: Pair<Track, Boolean> = TrackHelper.addWayPointToTrack(
|
val result: Pair<Track, Boolean> = TrackHelper.addWayPointToTrack(
|
||||||
this@TrackerService,
|
|
||||||
track,
|
track,
|
||||||
currentBestLocation,
|
currentBestLocation,
|
||||||
locationAccuracyThreshold,
|
locationAccuracyThreshold,
|
||||||
|
|
|
@ -31,7 +31,7 @@ import org.y20k.trackbook.helpers.PreferencesHelper
|
||||||
/*
|
/*
|
||||||
* TrackingToggleTileService class
|
* TrackingToggleTileService class
|
||||||
*/
|
*/
|
||||||
class TrackingToggleTileService() : TileService() {
|
class TrackingToggleTileService : TileService() {
|
||||||
|
|
||||||
/* Define log tag */
|
/* Define log tag */
|
||||||
private val TAG: String = LogHelper.makeLogTag(TrackingToggleTileService::class.java)
|
private val TAG: String = LogHelper.makeLogTag(TrackingToggleTileService::class.java)
|
||||||
|
@ -52,11 +52,6 @@ class TrackingToggleTileService() : TileService() {
|
||||||
updateTile()
|
updateTile()
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Overrides onTileRemoved from TileService */
|
|
||||||
override fun onTileRemoved() {
|
|
||||||
super.onTileRemoved()
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* Overrides onStartListening from TileService (tile becomes visible) */
|
/* Overrides onStartListening from TileService (tile becomes visible) */
|
||||||
override fun onStartListening() {
|
override fun onStartListening() {
|
||||||
|
@ -90,12 +85,6 @@ class TrackingToggleTileService() : TileService() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Overrides onDestroy from Service */
|
|
||||||
override fun onDestroy() {
|
|
||||||
super.onDestroy()
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* Update quick settings tile */
|
/* Update quick settings tile */
|
||||||
private fun updateTile() {
|
private fun updateTile() {
|
||||||
val tile: Tile = qsTile
|
val tile: Tile = qsTile
|
||||||
|
@ -141,7 +130,7 @@ class TrackingToggleTileService() : TileService() {
|
||||||
* Defines the listener for changes in shared preferences
|
* Defines the listener for changes in shared preferences
|
||||||
*/
|
*/
|
||||||
private val sharedPreferenceChangeListener =
|
private val sharedPreferenceChangeListener =
|
||||||
SharedPreferences.OnSharedPreferenceChangeListener { sharedPreferences, key ->
|
SharedPreferences.OnSharedPreferenceChangeListener { _, key ->
|
||||||
when (key) {
|
when (key) {
|
||||||
Keys.PREF_TRACKING_STATE -> {
|
Keys.PREF_TRACKING_STATE -> {
|
||||||
trackingState = PreferencesHelper.loadTrackingState(this)
|
trackingState = PreferencesHelper.loadTrackingState(this)
|
||||||
|
|
|
@ -82,7 +82,7 @@ class TracklistFragment : Fragment(), TracklistAdapter.TracklistAdapterListener,
|
||||||
override fun onSwiped(viewHolder: RecyclerView.ViewHolder, direction: Int) {
|
override fun onSwiped(viewHolder: RecyclerView.ViewHolder, direction: Int) {
|
||||||
// ask user
|
// ask user
|
||||||
val adapterPosition: Int = viewHolder.adapterPosition
|
val adapterPosition: Int = viewHolder.adapterPosition
|
||||||
val dialogMessage: String =
|
val dialogMessage =
|
||||||
"${getString(R.string.dialog_yes_no_message_delete_recording)}\n\n- ${tracklistAdapter.getTrackName(
|
"${getString(R.string.dialog_yes_no_message_delete_recording)}\n\n- ${tracklistAdapter.getTrackName(
|
||||||
adapterPosition
|
adapterPosition
|
||||||
)}"
|
)}"
|
||||||
|
@ -107,7 +107,7 @@ class TracklistFragment : Fragment(), TracklistAdapter.TracklistAdapterListener,
|
||||||
|
|
||||||
/* Overrides onTrackElementTapped from TracklistElementAdapterListener */
|
/* Overrides onTrackElementTapped from TracklistElementAdapterListener */
|
||||||
override fun onTrackElementTapped(tracklistElement: TracklistElement) {
|
override fun onTrackElementTapped(tracklistElement: TracklistElement) {
|
||||||
val bundle: Bundle = Bundle()
|
val bundle = Bundle()
|
||||||
bundle.putString(Keys.ARG_TRACK_TITLE, tracklistElement.name)
|
bundle.putString(Keys.ARG_TRACK_TITLE, tracklistElement.name)
|
||||||
bundle.putString(Keys.ARG_TRACK_FILE_URI, tracklistElement.trackUriString)
|
bundle.putString(Keys.ARG_TRACK_FILE_URI, tracklistElement.trackUriString)
|
||||||
bundle.putString(Keys.ARG_GPX_FILE_URI, tracklistElement.gpxUriString)
|
bundle.putString(Keys.ARG_GPX_FILE_URI, tracklistElement.gpxUriString)
|
||||||
|
|
|
@ -45,7 +45,7 @@ data class WayPoint(
|
||||||
|
|
||||||
/* Converts WayPoint into Location */
|
/* Converts WayPoint into Location */
|
||||||
fun toLocation(): Location {
|
fun toLocation(): Location {
|
||||||
val location: Location = Location(provider)
|
val location = Location(provider)
|
||||||
location.latitude = latitude
|
location.latitude = latitude
|
||||||
location.longitude = longitude
|
location.longitude = longitude
|
||||||
location.altitude = altitude
|
location.altitude = altitude
|
||||||
|
|
|
@ -18,7 +18,6 @@
|
||||||
package org.y20k.trackbook.dialogs
|
package org.y20k.trackbook.dialogs
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.DialogInterface
|
|
||||||
import android.text.method.ScrollingMovementMethod
|
import android.text.method.ScrollingMovementMethod
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
|
@ -45,8 +44,7 @@ object ErrorDialog {
|
||||||
errorDetails: String = String()
|
errorDetails: String = String()
|
||||||
) {
|
) {
|
||||||
// prepare dialog builder
|
// prepare dialog builder
|
||||||
val builder: MaterialAlertDialogBuilder =
|
val builder = MaterialAlertDialogBuilder(context, R.style.AlertDialogTheme)
|
||||||
MaterialAlertDialogBuilder(context, R.style.AlertDialogTheme)
|
|
||||||
|
|
||||||
// set title
|
// set title
|
||||||
builder.setTitle(context.getString(errorTitle))
|
builder.setTitle(context.getString(errorTitle))
|
||||||
|
@ -88,11 +86,11 @@ object ErrorDialog {
|
||||||
|
|
||||||
// add okay button
|
// add okay button
|
||||||
builder.setPositiveButton(
|
builder.setPositiveButton(
|
||||||
R.string.dialog_generic_button_okay,
|
R.string.dialog_generic_button_okay
|
||||||
DialogInterface.OnClickListener { _, _ ->
|
) { _, _ ->
|
||||||
// listen for click on okay button
|
// listen for click on okay button
|
||||||
// do nothing
|
// do nothing
|
||||||
})
|
}
|
||||||
|
|
||||||
// display error dialog
|
// display error dialog
|
||||||
builder.show()
|
builder.show()
|
||||||
|
|
|
@ -45,7 +45,7 @@ class RenameTrackDialog(private var renameTrackListener: RenameTrackListener) {
|
||||||
/* Construct and show dialog */
|
/* Construct and show dialog */
|
||||||
fun show(context: Context, trackName: String) {
|
fun show(context: Context, trackName: String) {
|
||||||
// prepare dialog builder
|
// prepare dialog builder
|
||||||
val builder: MaterialAlertDialogBuilder = MaterialAlertDialogBuilder(context)
|
val builder = MaterialAlertDialogBuilder(context)
|
||||||
|
|
||||||
// get input field
|
// get input field
|
||||||
val inflater = LayoutInflater.from(context)
|
val inflater = LayoutInflater.from(context)
|
||||||
|
|
|
@ -75,8 +75,7 @@ class YesNoDialog(private var yesNoDialogListener: YesNoDialogListener) {
|
||||||
) {
|
) {
|
||||||
|
|
||||||
// prepare dialog builder
|
// prepare dialog builder
|
||||||
val builder: MaterialAlertDialogBuilder =
|
val builder = MaterialAlertDialogBuilder(context, R.style.AlertDialogTheme)
|
||||||
MaterialAlertDialogBuilder(context, R.style.AlertDialogTheme)
|
|
||||||
|
|
||||||
// set title and message
|
// set title and message
|
||||||
builder.setMessage(messageString)
|
builder.setMessage(messageString)
|
||||||
|
@ -98,7 +97,7 @@ class YesNoDialog(private var yesNoDialogListener: YesNoDialogListener) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// handle outside-click as "no"
|
// handle outside-click as "no"
|
||||||
builder.setOnCancelListener() {
|
builder.setOnCancelListener {
|
||||||
yesNoDialogListener.onYesNoDialog(type, false, payload, payloadString)
|
yesNoDialogListener.onYesNoDialog(type, false, payload, payloadString)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,13 +19,15 @@ package org.y20k.trackbook.extensions
|
||||||
|
|
||||||
|
|
||||||
import android.content.SharedPreferences
|
import android.content.SharedPreferences
|
||||||
|
import java.lang.Double.doubleToRawLongBits
|
||||||
|
import java.lang.Double.longBitsToDouble
|
||||||
|
|
||||||
|
|
||||||
/* Puts a Double value in SharedPreferences */
|
/* Puts a Double value in SharedPreferences */
|
||||||
fun SharedPreferences.Editor.putDouble(key: String, double: Double) =
|
fun SharedPreferences.Editor.putDouble(key: String, double: Double) =
|
||||||
putLong(key, java.lang.Double.doubleToRawLongBits(double))
|
this.putLong(key, doubleToRawLongBits(double))
|
||||||
|
|
||||||
|
|
||||||
/* gets a Double value from SharedPreferences */
|
/* gets a Double value from SharedPreferences */
|
||||||
fun SharedPreferences.getDouble(key: String, default: Double) =
|
fun SharedPreferences.getDouble(key: String, default: Double) =
|
||||||
java.lang.Double.longBitsToDouble(getLong(key, java.lang.Double.doubleToRawLongBits(default)))
|
longBitsToDouble(getLong(key, doubleToRawLongBits(default)))
|
||||||
|
|
|
@ -34,7 +34,7 @@ object DateTimeHelper {
|
||||||
|
|
||||||
/* Converts milliseconds to mm:ss or hh:mm:ss */
|
/* Converts milliseconds to mm:ss or hh:mm:ss */
|
||||||
fun convertToReadableTime(context: Context, milliseconds: Long): String {
|
fun convertToReadableTime(context: Context, milliseconds: Long): String {
|
||||||
var timeString: String = String()
|
val timeString: String
|
||||||
val hours: Long = TimeUnit.MILLISECONDS.toHours(milliseconds)
|
val hours: Long = TimeUnit.MILLISECONDS.toHours(milliseconds)
|
||||||
val minutes: Long =
|
val minutes: Long =
|
||||||
TimeUnit.MILLISECONDS.toMinutes(milliseconds) % TimeUnit.HOURS.toMinutes(1)
|
TimeUnit.MILLISECONDS.toMinutes(milliseconds) % TimeUnit.HOURS.toMinutes(1)
|
||||||
|
@ -44,14 +44,14 @@ object DateTimeHelper {
|
||||||
val m: String = context.getString(R.string.abbreviation_minutes)
|
val m: String = context.getString(R.string.abbreviation_minutes)
|
||||||
val s: String = context.getString(R.string.abbreviation_seconds)
|
val s: String = context.getString(R.string.abbreviation_seconds)
|
||||||
|
|
||||||
when (milliseconds >= Keys.ONE_HOUR_IN_MILLISECONDS) {
|
timeString = when (milliseconds >= Keys.ONE_HOUR_IN_MILLISECONDS) {
|
||||||
// CASE: format hh:mm:ss
|
// CASE: format hh:mm:ss
|
||||||
true -> {
|
true -> {
|
||||||
timeString = "$hours $h $minutes $m $seconds $s"
|
"$hours $h $minutes $m $seconds $s"
|
||||||
}
|
}
|
||||||
// CASE: format mm:ss
|
// CASE: format mm:ss
|
||||||
false -> {
|
false -> {
|
||||||
timeString = "$minutes $m $seconds $s"
|
"$minutes $m $seconds $s"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return timeString
|
return timeString
|
||||||
|
@ -60,7 +60,7 @@ object DateTimeHelper {
|
||||||
|
|
||||||
/* Create sortable string for date - used for filenames */
|
/* Create sortable string for date - used for filenames */
|
||||||
fun convertToSortableDateString(date: Date): String {
|
fun convertToSortableDateString(date: Date): String {
|
||||||
val dateFormat: SimpleDateFormat = SimpleDateFormat("yyyy-MM-dd-HH-mm-ss", Locale.US)
|
val dateFormat = SimpleDateFormat("yyyy-MM-dd-HH-mm-ss", Locale.US)
|
||||||
return dateFormat.format(date)
|
return dateFormat.format(date)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,7 +85,7 @@ object DateTimeHelper {
|
||||||
|
|
||||||
/* Calculates time difference between two locations */
|
/* Calculates time difference between two locations */
|
||||||
fun calculateTimeDistance(previousLocation: Location?, location: Location): Long {
|
fun calculateTimeDistance(previousLocation: Location?, location: Location): Long {
|
||||||
var timeDifference: Long = 0L
|
var timeDifference = 0L
|
||||||
// two data points needed to calculate time difference
|
// two data points needed to calculate time difference
|
||||||
if (previousLocation != null) {
|
if (previousLocation != null) {
|
||||||
// get time difference
|
// get time difference
|
||||||
|
|
|
@ -35,6 +35,8 @@ import java.text.NumberFormat
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import kotlin.coroutines.resume
|
import kotlin.coroutines.resume
|
||||||
import kotlin.coroutines.suspendCoroutine
|
import kotlin.coroutines.suspendCoroutine
|
||||||
|
import kotlin.math.ln
|
||||||
|
import kotlin.math.pow
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -61,14 +63,14 @@ object FileHelper {
|
||||||
/* Get file size for given Uri */
|
/* Get file size for given Uri */
|
||||||
fun getFileSize(context: Context, uri: Uri): Long {
|
fun getFileSize(context: Context, uri: Uri): Long {
|
||||||
val cursor: Cursor? = context.contentResolver.query(uri, null, null, null, null)
|
val cursor: Cursor? = context.contentResolver.query(uri, null, null, null, null)
|
||||||
if (cursor != null) {
|
return if (cursor != null) {
|
||||||
val sizeIndex: Int = cursor.getColumnIndex(OpenableColumns.SIZE)
|
val sizeIndex: Int = cursor.getColumnIndex(OpenableColumns.SIZE)
|
||||||
cursor.moveToFirst()
|
cursor.moveToFirst()
|
||||||
val size: Long = cursor.getLong(sizeIndex)
|
val size: Long = cursor.getLong(sizeIndex)
|
||||||
cursor.close()
|
cursor.close()
|
||||||
return size
|
size
|
||||||
} else {
|
} else {
|
||||||
return 0L
|
0L
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,14 +78,14 @@ object FileHelper {
|
||||||
/* Get file name for given Uri */
|
/* Get file name for given Uri */
|
||||||
fun getFileName(context: Context, uri: Uri): String {
|
fun getFileName(context: Context, uri: Uri): String {
|
||||||
val cursor: Cursor? = context.contentResolver.query(uri, null, null, null, null)
|
val cursor: Cursor? = context.contentResolver.query(uri, null, null, null, null)
|
||||||
if (cursor != null) {
|
return if (cursor != null) {
|
||||||
val nameIndex: Int = cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME)
|
val nameIndex: Int = cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME)
|
||||||
cursor.moveToFirst()
|
cursor.moveToFirst()
|
||||||
val name: String = cursor.getString(nameIndex)
|
val name: String = cursor.getString(nameIndex)
|
||||||
cursor.close()
|
cursor.close()
|
||||||
return name
|
name
|
||||||
} else {
|
} else {
|
||||||
return String()
|
String()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,8 +112,8 @@ object FileHelper {
|
||||||
fun readTracklist(context: Context): Tracklist {
|
fun readTracklist(context: Context): Tracklist {
|
||||||
LogHelper.v(TAG, "Reading Tracklist - Thread: ${Thread.currentThread().name}")
|
LogHelper.v(TAG, "Reading Tracklist - Thread: ${Thread.currentThread().name}")
|
||||||
// get JSON from text file
|
// get JSON from text file
|
||||||
val json: String = readTextFile(context, getTracklistFileUri(context))
|
val json: String = readTextFile(getTracklistFileUri(context))
|
||||||
var tracklist: Tracklist = Tracklist()
|
var tracklist = Tracklist()
|
||||||
when (json.isNotBlank()) {
|
when (json.isNotBlank()) {
|
||||||
// convert JSON and return as tracklist
|
// convert JSON and return as tracklist
|
||||||
true -> try {
|
true -> try {
|
||||||
|
@ -125,10 +127,10 @@ object FileHelper {
|
||||||
|
|
||||||
|
|
||||||
/* Reads track from storage using GSON */
|
/* Reads track from storage using GSON */
|
||||||
fun readTrack(context: Context, fileUri: Uri): Track {
|
fun readTrack(fileUri: Uri): Track {
|
||||||
// get JSON from text file
|
// get JSON from text file
|
||||||
val json: String = readTextFile(context, fileUri)
|
val json: String = readTextFile(fileUri)
|
||||||
var track: Track = Track()
|
var track = Track()
|
||||||
when (json.isNotEmpty()) {
|
when (json.isNotEmpty()) {
|
||||||
// convert JSON and return as track
|
// convert JSON and return as track
|
||||||
true -> try {
|
true -> try {
|
||||||
|
@ -305,7 +307,7 @@ object FileHelper {
|
||||||
tracklist.modificationDate = modificationDate
|
tracklist.modificationDate = modificationDate
|
||||||
// convert to JSON
|
// convert to JSON
|
||||||
val gson: Gson = getCustomGson()
|
val gson: Gson = getCustomGson()
|
||||||
var json: String = String()
|
var json = String()
|
||||||
try {
|
try {
|
||||||
json = gson.toJson(tracklist)
|
json = gson.toJson(tracklist)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
|
@ -328,7 +330,7 @@ object FileHelper {
|
||||||
private fun renameTrack(context: Context, track: Track, newName: String) {
|
private fun renameTrack(context: Context, track: Track, newName: String) {
|
||||||
// search track in tracklist
|
// search track in tracklist
|
||||||
val tracklist: Tracklist = readTracklist(context)
|
val tracklist: Tracklist = readTracklist(context)
|
||||||
var trackUriString: String = String()
|
var trackUriString = String()
|
||||||
tracklist.tracklistElements.forEach { tracklistElement ->
|
tracklist.tracklistElements.forEach { tracklistElement ->
|
||||||
if (tracklistElement.getTrackId() == track.getTrackId()) {
|
if (tracklistElement.getTrackId() == track.getTrackId()) {
|
||||||
// rename tracklist element
|
// rename tracklist element
|
||||||
|
@ -402,7 +404,7 @@ object FileHelper {
|
||||||
/* Converts track to JSON */
|
/* Converts track to JSON */
|
||||||
private fun getTrackJsonString(track: Track): String {
|
private fun getTrackJsonString(track: Track): String {
|
||||||
val gson: Gson = getCustomGson()
|
val gson: Gson = getCustomGson()
|
||||||
var json: String = String()
|
var json = String()
|
||||||
try {
|
try {
|
||||||
json = gson.toJson(track)
|
json = gson.toJson(track)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
|
@ -432,13 +434,13 @@ object FileHelper {
|
||||||
if (bytes < unit) return "$bytes B"
|
if (bytes < unit) return "$bytes B"
|
||||||
|
|
||||||
// calculate exp
|
// calculate exp
|
||||||
val exp: Int = (Math.log(bytes.toDouble()) / Math.log(unit.toDouble())).toInt()
|
val exp: Int = (ln(bytes.toDouble()) / ln(unit.toDouble())).toInt()
|
||||||
|
|
||||||
// determine prefix symbol
|
// determine prefix symbol
|
||||||
val prefix: String = ((if (si) "kMGTPE" else "KMGTPE")[exp - 1] + if (si) "" else "i")
|
val prefix: String = ((if (si) "kMGTPE" else "KMGTPE")[exp - 1] + if (si) "" else "i")
|
||||||
|
|
||||||
// calculate result and set number format
|
// calculate result and set number format
|
||||||
val result: Double = bytes / Math.pow(unit.toDouble(), exp.toDouble())
|
val result: Double = bytes / unit.toDouble().pow(exp.toDouble())
|
||||||
val numberFormat = NumberFormat.getNumberInstance()
|
val numberFormat = NumberFormat.getNumberInstance()
|
||||||
numberFormat.maximumFractionDigits = 1
|
numberFormat.maximumFractionDigits = 1
|
||||||
|
|
||||||
|
@ -447,7 +449,7 @@ object FileHelper {
|
||||||
|
|
||||||
|
|
||||||
/* Reads InputStream from file uri and returns it as String */
|
/* Reads InputStream from file uri and returns it as String */
|
||||||
private fun readTextFile(context: Context, fileUri: Uri): String {
|
private fun readTextFile(fileUri: Uri): String {
|
||||||
// todo read https://commonsware.com/blog/2016/03/15/how-consume-content-uri.html
|
// todo read https://commonsware.com/blog/2016/03/15/how-consume-content-uri.html
|
||||||
// https://developer.android.com/training/secure-file-sharing/retrieve-info
|
// https://developer.android.com/training/secure-file-sharing/retrieve-info
|
||||||
val file: File = fileUri.toFile()
|
val file: File = fileUri.toFile()
|
||||||
|
@ -457,7 +459,7 @@ object FileHelper {
|
||||||
}
|
}
|
||||||
// read until last line reached
|
// read until last line reached
|
||||||
val stream: InputStream = file.inputStream()
|
val stream: InputStream = file.inputStream()
|
||||||
val reader: BufferedReader = BufferedReader(InputStreamReader(stream))
|
val reader = BufferedReader(InputStreamReader(stream))
|
||||||
val builder: StringBuilder = StringBuilder()
|
val builder: StringBuilder = StringBuilder()
|
||||||
reader.forEachLine {
|
reader.forEachLine {
|
||||||
builder.append(it)
|
builder.append(it)
|
||||||
|
@ -477,7 +479,6 @@ object FileHelper {
|
||||||
|
|
||||||
/* Writes given bitmap as image file to storage */
|
/* Writes given bitmap as image file to storage */
|
||||||
private fun writeImageFile(
|
private fun writeImageFile(
|
||||||
context: Context,
|
|
||||||
bitmap: Bitmap,
|
bitmap: Bitmap,
|
||||||
file: File,
|
file: File,
|
||||||
format: Bitmap.CompressFormat = Bitmap.CompressFormat.JPEG,
|
format: Bitmap.CompressFormat = Bitmap.CompressFormat.JPEG,
|
||||||
|
|
|
@ -89,7 +89,7 @@ object LengthUnitHelper {
|
||||||
/* Determines which unit system the device is using (metric or imperial) */
|
/* Determines which unit system the device is using (metric or imperial) */
|
||||||
fun useImperialUnits(): Boolean {
|
fun useImperialUnits(): Boolean {
|
||||||
// America (US), Liberia (LR), Myanmar(MM) use the imperial system
|
// America (US), Liberia (LR), Myanmar(MM) use the imperial system
|
||||||
val imperialSystemCountries = Arrays.asList("US", "LR", "MM")
|
val imperialSystemCountries = listOf("US", "LR", "MM")
|
||||||
val countryCode = Locale.getDefault().country
|
val countryCode = Locale.getDefault().country
|
||||||
return imperialSystemCountries.contains(countryCode)
|
return imperialSystemCountries.contains(countryCode)
|
||||||
}
|
}
|
||||||
|
@ -102,7 +102,7 @@ object LengthUnitHelper {
|
||||||
trackLength: Float,
|
trackLength: Float,
|
||||||
useImperialUnits: Boolean = false
|
useImperialUnits: Boolean = false
|
||||||
): String {
|
): String {
|
||||||
var speed: String = "0"
|
var speed = "0"
|
||||||
|
|
||||||
// duration minus pause in seconds
|
// duration minus pause in seconds
|
||||||
val duration: Long = (trackDuration - trackRecordingPause) / 1000L
|
val duration: Long = (trackDuration - trackRecordingPause) / 1000L
|
||||||
|
@ -117,21 +117,21 @@ object LengthUnitHelper {
|
||||||
speed = bd.toPlainString()
|
speed = bd.toPlainString()
|
||||||
}
|
}
|
||||||
|
|
||||||
when (useImperialUnits) {
|
return when (useImperialUnits) {
|
||||||
true -> return "$speed mph"
|
true -> "$speed mph"
|
||||||
false -> return "$speed km/h"
|
false -> "$speed km/h"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Coverts meters per second to either km/h or mph */
|
/* Coverts meters per second to either km/h or mph */
|
||||||
fun convertMetersPerSecond(metersPerSecond: Float, useImperial: Boolean = false): Double {
|
fun convertMetersPerSecond(metersPerSecond: Float, useImperial: Boolean = false): Double {
|
||||||
if (useImperial) {
|
return if (useImperial) {
|
||||||
// mph
|
// mph
|
||||||
return metersPerSecond * 2.2369362920544
|
metersPerSecond * 2.2369362920544
|
||||||
} else {
|
} else {
|
||||||
// km/h
|
// km/h
|
||||||
return metersPerSecond * 3.6
|
metersPerSecond * 3.6
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,7 @@ object LocationHelper {
|
||||||
|
|
||||||
/* Get default location */
|
/* Get default location */
|
||||||
fun getDefaultLocation(): Location {
|
fun getDefaultLocation(): Location {
|
||||||
val defaultLocation: Location = Location(LocationManager.NETWORK_PROVIDER)
|
val defaultLocation = Location(LocationManager.NETWORK_PROVIDER)
|
||||||
defaultLocation.latitude = Keys.DEFAULT_LATITUDE
|
defaultLocation.latitude = Keys.DEFAULT_LATITUDE
|
||||||
defaultLocation.longitude = Keys.DEFAULT_LONGITUDE
|
defaultLocation.longitude = Keys.DEFAULT_LONGITUDE
|
||||||
defaultLocation.accuracy = Keys.DEFAULT_ACCURACY
|
defaultLocation.accuracy = Keys.DEFAULT_ACCURACY
|
||||||
|
@ -75,10 +75,11 @@ object LocationHelper {
|
||||||
val lastKnownLocationNetwork: Location =
|
val lastKnownLocationNetwork: Location =
|
||||||
locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER)
|
locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER)
|
||||||
?: lastKnownLocation
|
?: lastKnownLocation
|
||||||
when (isBetterLocation(lastKnownLocationGps, lastKnownLocationNetwork)) {
|
lastKnownLocation =
|
||||||
true -> lastKnownLocation = lastKnownLocationGps
|
when (isBetterLocation(lastKnownLocationGps, lastKnownLocationNetwork)) {
|
||||||
false -> lastKnownLocation = lastKnownLocationNetwork
|
true -> lastKnownLocationGps
|
||||||
}
|
false -> lastKnownLocationNetwork
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return lastKnownLocation
|
return lastKnownLocation
|
||||||
}
|
}
|
||||||
|
@ -127,20 +128,20 @@ object LocationHelper {
|
||||||
|
|
||||||
/* Checks if GPS location provider is available and enabled */
|
/* Checks if GPS location provider is available and enabled */
|
||||||
fun isGpsEnabled(locationManager: LocationManager): Boolean {
|
fun isGpsEnabled(locationManager: LocationManager): Boolean {
|
||||||
if (locationManager.allProviders.contains(LocationManager.GPS_PROVIDER)) {
|
return if (locationManager.allProviders.contains(LocationManager.GPS_PROVIDER)) {
|
||||||
return locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)
|
locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)
|
||||||
} else {
|
} else {
|
||||||
return false
|
false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Checks if Network location provider is available and enabled */
|
/* Checks if Network location provider is available and enabled */
|
||||||
fun isNetworkEnabled(locationManager: LocationManager): Boolean {
|
fun isNetworkEnabled(locationManager: LocationManager): Boolean {
|
||||||
if (locationManager.allProviders.contains(LocationManager.NETWORK_PROVIDER)) {
|
return if (locationManager.allProviders.contains(LocationManager.NETWORK_PROVIDER)) {
|
||||||
return locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)
|
locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)
|
||||||
} else {
|
} else {
|
||||||
return false
|
false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -154,14 +155,10 @@ object LocationHelper {
|
||||||
|
|
||||||
/* Checks if given location is accurate */
|
/* Checks if given location is accurate */
|
||||||
fun isAccurateEnough(location: Location, locationAccuracyThreshold: Int): Boolean {
|
fun isAccurateEnough(location: Location, locationAccuracyThreshold: Int): Boolean {
|
||||||
val isAccurate: Boolean
|
return when (location.provider) {
|
||||||
when (location.provider) {
|
LocationManager.GPS_PROVIDER -> location.accuracy < locationAccuracyThreshold
|
||||||
LocationManager.GPS_PROVIDER -> isAccurate =
|
else -> location.accuracy < locationAccuracyThreshold + 10 // a bit more relaxed when location comes from network provider
|
||||||
location.accuracy < locationAccuracyThreshold
|
|
||||||
else -> isAccurate =
|
|
||||||
location.accuracy < locationAccuracyThreshold + 10 // a bit more relaxed when location comes from network provider
|
|
||||||
}
|
}
|
||||||
return isAccurate
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -204,10 +201,10 @@ object LocationHelper {
|
||||||
val distanceThreshold: Float
|
val distanceThreshold: Float
|
||||||
val averageAccuracy: Float = (previousLocation.accuracy + location.accuracy) / 2
|
val averageAccuracy: Float = (previousLocation.accuracy + location.accuracy) / 2
|
||||||
// increase the distance threshold if one or both locations are
|
// increase the distance threshold if one or both locations are
|
||||||
if (averageAccuracy > Keys.DEFAULT_THRESHOLD_DISTANCE) {
|
distanceThreshold = if (averageAccuracy > Keys.DEFAULT_THRESHOLD_DISTANCE) {
|
||||||
distanceThreshold = averageAccuracy
|
averageAccuracy
|
||||||
} else {
|
} else {
|
||||||
distanceThreshold = Keys.DEFAULT_THRESHOLD_DISTANCE
|
Keys.DEFAULT_THRESHOLD_DISTANCE
|
||||||
}
|
}
|
||||||
// location is different when far enough away from previous location
|
// location is different when far enough away from previous location
|
||||||
return calculateDistance(previousLocation, location) > distanceThreshold
|
return calculateDistance(previousLocation, location) > distanceThreshold
|
||||||
|
@ -216,7 +213,7 @@ object LocationHelper {
|
||||||
|
|
||||||
/* Calculates distance in meters between two locations */
|
/* Calculates distance in meters between two locations */
|
||||||
fun calculateDistance(previousLocation: Location?, location: Location): Float {
|
fun calculateDistance(previousLocation: Location?, location: Location): Float {
|
||||||
var distance: Float = 0f
|
var distance = 0f
|
||||||
// two data points needed to calculate distance
|
// two data points needed to calculate distance
|
||||||
if (previousLocation != null) {
|
if (previousLocation != null) {
|
||||||
// add up distance
|
// add up distance
|
||||||
|
|
|
@ -78,9 +78,9 @@ object LogHelper {
|
||||||
|
|
||||||
private fun log(tag: String, level: Int, t: Throwable?, vararg messages: Any) {
|
private fun log(tag: String, level: Int, t: Throwable?, vararg messages: Any) {
|
||||||
val message: String
|
val message: String
|
||||||
if (t == null && messages.size == 1) {
|
message = if (t == null && messages.size == 1) {
|
||||||
// handle this common case without the extra cost of creating a stringbuffer:
|
// handle this common case without the extra cost of creating a stringbuffer:
|
||||||
message = messages[0].toString()
|
messages[0].toString()
|
||||||
} else {
|
} else {
|
||||||
val sb = StringBuilder()
|
val sb = StringBuilder()
|
||||||
for (m in messages) {
|
for (m in messages) {
|
||||||
|
@ -89,7 +89,7 @@ object LogHelper {
|
||||||
if (t != null) {
|
if (t != null) {
|
||||||
sb.append("\n").append(Log.getStackTraceString(t))
|
sb.append("\n").append(Log.getStackTraceString(t))
|
||||||
}
|
}
|
||||||
message = sb.toString()
|
sb.toString()
|
||||||
}
|
}
|
||||||
Log.println(level, tag, message)
|
Log.println(level, tag, message)
|
||||||
|
|
||||||
|
|
|
@ -65,23 +65,25 @@ class MapOverlay(private var markerListener: MarkerListener) {
|
||||||
when (trackingState) {
|
when (trackingState) {
|
||||||
// CASE: Tracking active
|
// CASE: Tracking active
|
||||||
Keys.STATE_TRACKING_ACTIVE -> {
|
Keys.STATE_TRACKING_ACTIVE -> {
|
||||||
when (locationIsOld) {
|
newMarker = when (locationIsOld) {
|
||||||
true -> newMarker = ContextCompat.getDrawable(
|
true -> ContextCompat.getDrawable(
|
||||||
context,
|
context,
|
||||||
R.drawable.ic_marker_location_red_grey_24dp
|
R.drawable.ic_marker_location_red_grey_24dp
|
||||||
)!!
|
)!!
|
||||||
false -> newMarker =
|
false -> ContextCompat.getDrawable(
|
||||||
ContextCompat.getDrawable(context, R.drawable.ic_marker_location_red_24dp)!!
|
context,
|
||||||
|
R.drawable.ic_marker_location_red_24dp
|
||||||
|
)!!
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// CASE. Tracking is NOT active
|
// CASE. Tracking is NOT active
|
||||||
else -> {
|
else -> {
|
||||||
when (locationIsOld) {
|
newMarker = when (locationIsOld) {
|
||||||
true -> newMarker = ContextCompat.getDrawable(
|
true -> ContextCompat.getDrawable(
|
||||||
context,
|
context,
|
||||||
R.drawable.ic_marker_location_blue_grey_24dp
|
R.drawable.ic_marker_location_blue_grey_24dp
|
||||||
)!!
|
)!!
|
||||||
false -> newMarker = ContextCompat.getDrawable(
|
false -> ContextCompat.getDrawable(
|
||||||
context,
|
context,
|
||||||
R.drawable.ic_marker_location_blue_24dp
|
R.drawable.ic_marker_location_blue_24dp
|
||||||
)!!
|
)!!
|
||||||
|
@ -124,36 +126,42 @@ class MapOverlay(private var markerListener: MarkerListener) {
|
||||||
when (trackingState) {
|
when (trackingState) {
|
||||||
// CASE: Recording is active
|
// CASE: Recording is active
|
||||||
Keys.STATE_TRACKING_ACTIVE -> {
|
Keys.STATE_TRACKING_ACTIVE -> {
|
||||||
if (wayPoint.starred) {
|
newMarker = when {
|
||||||
newMarker =
|
wayPoint.starred -> {
|
||||||
ContextCompat.getDrawable(context, R.drawable.ic_star_red_24dp)!!
|
ContextCompat.getDrawable(context, R.drawable.ic_star_red_24dp)!!
|
||||||
} else if (wayPoint.isStopOver) {
|
}
|
||||||
newMarker = ContextCompat.getDrawable(
|
wayPoint.isStopOver -> {
|
||||||
context,
|
ContextCompat.getDrawable(
|
||||||
R.drawable.ic_marker_track_location_grey_24dp
|
context,
|
||||||
)!!
|
R.drawable.ic_marker_track_location_grey_24dp
|
||||||
} else {
|
)!!
|
||||||
newMarker = ContextCompat.getDrawable(
|
}
|
||||||
context,
|
else -> {
|
||||||
R.drawable.ic_marker_track_location_red_24dp
|
ContextCompat.getDrawable(
|
||||||
)!!
|
context,
|
||||||
|
R.drawable.ic_marker_track_location_red_24dp
|
||||||
|
)!!
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// CASE: Recording is paused/stopped
|
// CASE: Recording is paused/stopped
|
||||||
else -> {
|
else -> {
|
||||||
if (wayPoint.starred) {
|
newMarker = when {
|
||||||
newMarker =
|
wayPoint.starred -> {
|
||||||
ContextCompat.getDrawable(context, R.drawable.ic_star_blue_24dp)!!
|
ContextCompat.getDrawable(context, R.drawable.ic_star_blue_24dp)!!
|
||||||
} else if (wayPoint.isStopOver) {
|
}
|
||||||
newMarker = ContextCompat.getDrawable(
|
wayPoint.isStopOver -> {
|
||||||
context,
|
ContextCompat.getDrawable(
|
||||||
R.drawable.ic_marker_track_location_grey_24dp
|
context,
|
||||||
)!!
|
R.drawable.ic_marker_track_location_grey_24dp
|
||||||
} else {
|
)!!
|
||||||
newMarker = ContextCompat.getDrawable(
|
}
|
||||||
context,
|
else -> {
|
||||||
R.drawable.ic_marker_track_location_blue_24dp
|
ContextCompat.getDrawable(
|
||||||
)!!
|
context,
|
||||||
|
R.drawable.ic_marker_track_location_blue_24dp
|
||||||
|
)!!
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -185,13 +193,13 @@ class MapOverlay(private var markerListener: MarkerListener) {
|
||||||
provider: String,
|
provider: String,
|
||||||
time: Long
|
time: Long
|
||||||
): OverlayItem {
|
): OverlayItem {
|
||||||
val title: String =
|
val title =
|
||||||
"${context.getString(R.string.marker_description_time)}: ${SimpleDateFormat.getTimeInstance(
|
"${context.getString(R.string.marker_description_time)}: ${SimpleDateFormat.getTimeInstance(
|
||||||
SimpleDateFormat.MEDIUM,
|
SimpleDateFormat.MEDIUM,
|
||||||
Locale.getDefault()
|
Locale.getDefault()
|
||||||
).format(time)}"
|
).format(time)}"
|
||||||
//val description: String = "${context.getString(R.string.marker_description_accuracy)}: ${DecimalFormat("#0.00").format(accuracy)} (${provider})"
|
//val description: String = "${context.getString(R.string.marker_description_accuracy)}: ${DecimalFormat("#0.00").format(accuracy)} (${provider})"
|
||||||
val description: String =
|
val description =
|
||||||
"${context.getString(R.string.marker_description_time)}: ${SimpleDateFormat.getTimeInstance(
|
"${context.getString(R.string.marker_description_time)}: ${SimpleDateFormat.getTimeInstance(
|
||||||
SimpleDateFormat.MEDIUM,
|
SimpleDateFormat.MEDIUM,
|
||||||
Locale.getDefault()
|
Locale.getDefault()
|
||||||
|
@ -199,7 +207,7 @@ class MapOverlay(private var markerListener: MarkerListener) {
|
||||||
.format(time)} | ${context.getString(R.string.marker_description_accuracy)}: ${DecimalFormat(
|
.format(time)} | ${context.getString(R.string.marker_description_accuracy)}: ${DecimalFormat(
|
||||||
"#0.00"
|
"#0.00"
|
||||||
).format(accuracy)} (${provider})"
|
).format(accuracy)} (${provider})"
|
||||||
val position: GeoPoint = GeoPoint(latitude, longitude)
|
val position = GeoPoint(latitude, longitude)
|
||||||
return OverlayItem(title, description, position)
|
return OverlayItem(title, description, position)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -116,7 +116,7 @@ object PreferencesHelper {
|
||||||
LocationManager.NETWORK_PROVIDER
|
LocationManager.NETWORK_PROVIDER
|
||||||
) ?: LocationManager.NETWORK_PROVIDER
|
) ?: LocationManager.NETWORK_PROVIDER
|
||||||
// create location
|
// create location
|
||||||
val currentBestLocation: Location = Location(provider)
|
val currentBestLocation = Location(provider)
|
||||||
// load location attributes
|
// load location attributes
|
||||||
currentBestLocation.latitude =
|
currentBestLocation.latitude =
|
||||||
settings.getDouble(Keys.PREF_CURRENT_BEST_LOCATION_LATITUDE, Keys.DEFAULT_LATITUDE)
|
settings.getDouble(Keys.PREF_CURRENT_BEST_LOCATION_LATITUDE, Keys.DEFAULT_LATITUDE)
|
||||||
|
|
|
@ -47,9 +47,8 @@ object TrackHelper {
|
||||||
tracklistElement.date.time
|
tracklistElement.date.time
|
||||||
|
|
||||||
|
|
||||||
/* Adds given locatiom as waypoint to track */
|
/* Adds given location as waypoint to track */
|
||||||
fun addWayPointToTrack(
|
fun addWayPointToTrack(
|
||||||
context: Context,
|
|
||||||
track: Track,
|
track: Track,
|
||||||
location: Location,
|
location: Location,
|
||||||
locationAccuracyThreshold: Int,
|
locationAccuracyThreshold: Int,
|
||||||
|
@ -151,10 +150,10 @@ object TrackHelper {
|
||||||
// save number of satellites
|
// save number of satellites
|
||||||
val numberOfSatellites: Int
|
val numberOfSatellites: Int
|
||||||
val extras = location.extras
|
val extras = location.extras
|
||||||
if (extras != null && extras.containsKey("satellites")) {
|
numberOfSatellites = if (extras != null && extras.containsKey("satellites")) {
|
||||||
numberOfSatellites = extras.getInt("satellites", 0)
|
extras.getInt("satellites", 0)
|
||||||
} else {
|
} else {
|
||||||
numberOfSatellites = 0
|
0
|
||||||
}
|
}
|
||||||
|
|
||||||
// add current location as point to center on for later display
|
// add current location as point to center on for later display
|
||||||
|
@ -187,10 +186,9 @@ object TrackHelper {
|
||||||
|
|
||||||
/* Creates GPX string for given track */
|
/* Creates GPX string for given track */
|
||||||
fun createGpxString(track: Track): String {
|
fun createGpxString(track: Track): String {
|
||||||
var gpxString: String
|
|
||||||
|
|
||||||
// add header
|
// add header
|
||||||
gpxString = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\" ?>\n" +
|
var gpxString: String = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\" ?>\n" +
|
||||||
"<gpx version=\"1.1\" creator=\"Trackbook App (Android)\"\n" +
|
"<gpx version=\"1.1\" creator=\"Trackbook App (Android)\"\n" +
|
||||||
" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" +
|
" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" +
|
||||||
" xsi:schemaLocation=\"http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd\">\n"
|
" xsi:schemaLocation=\"http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd\">\n"
|
||||||
|
|
|
@ -41,7 +41,7 @@ object UiHelper {
|
||||||
|
|
||||||
|
|
||||||
/* Sets layout margins for given view in DP */
|
/* Sets layout margins for given view in DP */
|
||||||
fun setViewMargins(
|
private fun setViewMargins(
|
||||||
context: Context,
|
context: Context,
|
||||||
view: View,
|
view: View,
|
||||||
left: Int = 0,
|
left: Int = 0,
|
||||||
|
|
|
@ -158,18 +158,17 @@ class TracklistAdapter(private val fragment: Fragment) :
|
||||||
private fun createTrackDataString(position: Int): String {
|
private fun createTrackDataString(position: Int): String {
|
||||||
val tracklistElement: TracklistElement = tracklist.tracklistElements[position]
|
val tracklistElement: TracklistElement = tracklist.tracklistElements[position]
|
||||||
val trackDataString: String
|
val trackDataString: String
|
||||||
when (tracklistElement.name == tracklistElement.dateString) {
|
trackDataString = when (tracklistElement.name == tracklistElement.dateString) {
|
||||||
// CASE: no individual name set - exclude date
|
// CASE: no individual name set - exclude date
|
||||||
true -> trackDataString = "${LengthUnitHelper.convertDistanceToString(
|
true -> "${LengthUnitHelper.convertDistanceToString(
|
||||||
tracklistElement.length,
|
tracklistElement.length,
|
||||||
useImperial
|
useImperial
|
||||||
)} • ${tracklistElement.durationString}"
|
)} • ${tracklistElement.durationString}"
|
||||||
// CASE: no individual name set - include date
|
// CASE: no individual name set - include date
|
||||||
false -> trackDataString =
|
false -> "${tracklistElement.dateString} • ${LengthUnitHelper.convertDistanceToString(
|
||||||
"${tracklistElement.dateString} • ${LengthUnitHelper.convertDistanceToString(
|
tracklistElement.length,
|
||||||
tracklistElement.length,
|
useImperial
|
||||||
useImperial
|
)} • ${tracklistElement.durationString}"
|
||||||
)} • ${tracklistElement.durationString}"
|
|
||||||
}
|
}
|
||||||
return trackDataString
|
return trackDataString
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,11 +65,11 @@ data class MapFragmentLayoutHolder(
|
||||||
|
|
||||||
|
|
||||||
/* Main class variables */
|
/* Main class variables */
|
||||||
val rootView: View
|
val rootView: View = inflater.inflate(R.layout.fragment_map, container, false)
|
||||||
val mapView: MapView
|
private val mapView: MapView
|
||||||
val currentLocationButton: FloatingActionButton
|
val currentLocationButton: FloatingActionButton
|
||||||
val recordingButton: FloatingActionButton
|
val recordingButton: FloatingActionButton
|
||||||
val recordingButtonSubMenu: Group
|
private val recordingButtonSubMenu: Group
|
||||||
val saveButton: FloatingActionButton
|
val saveButton: FloatingActionButton
|
||||||
val clearButton: FloatingActionButton
|
val clearButton: FloatingActionButton
|
||||||
val resumeButton: FloatingActionButton
|
val resumeButton: FloatingActionButton
|
||||||
|
@ -84,7 +84,6 @@ data class MapFragmentLayoutHolder(
|
||||||
/* Init block */
|
/* Init block */
|
||||||
init {
|
init {
|
||||||
// find views
|
// find views
|
||||||
rootView = inflater.inflate(R.layout.fragment_map, container, false)
|
|
||||||
mapView = rootView.findViewById(R.id.map)
|
mapView = rootView.findViewById(R.id.map)
|
||||||
currentLocationButton = rootView.findViewById(R.id.fab_location_button)
|
currentLocationButton = rootView.findViewById(R.id.fab_location_button)
|
||||||
recordingButton = rootView.findViewById(R.id.fab_main_button)
|
recordingButton = rootView.findViewById(R.id.fab_main_button)
|
||||||
|
@ -139,7 +138,7 @@ data class MapFragmentLayoutHolder(
|
||||||
/* Listen for user interaction */
|
/* Listen for user interaction */
|
||||||
@SuppressLint("ClickableViewAccessibility")
|
@SuppressLint("ClickableViewAccessibility")
|
||||||
private fun addInteractionListener() {
|
private fun addInteractionListener() {
|
||||||
mapView.setOnTouchListener { v, event ->
|
mapView.setOnTouchListener { _, _ ->
|
||||||
userInteraction = true
|
userInteraction = true
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
@ -160,7 +159,7 @@ data class MapFragmentLayoutHolder(
|
||||||
/* Save current best location and state of map to shared preferences */
|
/* Save current best location and state of map to shared preferences */
|
||||||
fun saveState(currentBestLocation: Location) {
|
fun saveState(currentBestLocation: Location) {
|
||||||
PreferencesHelper.saveCurrentBestLocation(context, currentBestLocation)
|
PreferencesHelper.saveCurrentBestLocation(context, currentBestLocation)
|
||||||
PreferencesHelper.saveZoomLevel(context, mapView.getZoomLevelDouble())
|
PreferencesHelper.saveZoomLevel(context, mapView.zoomLevelDouble)
|
||||||
// reset user interaction state
|
// reset user interaction state
|
||||||
userInteraction = false
|
userInteraction = false
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,7 +63,7 @@ data class TrackFragmentLayoutHolder(
|
||||||
|
|
||||||
|
|
||||||
/* Main class variables */
|
/* Main class variables */
|
||||||
val rootView: View
|
val rootView: View = inflater.inflate(R.layout.fragment_track, container, false)
|
||||||
val shareButton: ImageButton
|
val shareButton: ImageButton
|
||||||
val deleteButton: ImageButton
|
val deleteButton: ImageButton
|
||||||
val editButton: ImageButton
|
val editButton: ImageButton
|
||||||
|
@ -96,7 +96,6 @@ data class TrackFragmentLayoutHolder(
|
||||||
/* Init block */
|
/* Init block */
|
||||||
init {
|
init {
|
||||||
// find views
|
// find views
|
||||||
rootView = inflater.inflate(R.layout.fragment_track, container, false)
|
|
||||||
mapView = rootView.findViewById(R.id.map)
|
mapView = rootView.findViewById(R.id.map)
|
||||||
shareButton = rootView.findViewById(R.id.save_button)
|
shareButton = rootView.findViewById(R.id.save_button)
|
||||||
deleteButton = rootView.findViewById(R.id.delete_button)
|
deleteButton = rootView.findViewById(R.id.delete_button)
|
||||||
|
@ -202,10 +201,9 @@ data class TrackFragmentLayoutHolder(
|
||||||
private fun setupStatisticsViews() {
|
private fun setupStatisticsViews() {
|
||||||
|
|
||||||
// get step count string
|
// get step count string
|
||||||
val steps: String
|
val steps: String =
|
||||||
if (track.stepCount == -1f) steps =
|
if (track.stepCount == -1f) context.getString(R.string.statistics_sheet_p_steps_no_pedometer)
|
||||||
context.getString(R.string.statistics_sheet_p_steps_no_pedometer)
|
else track.stepCount.roundToInt().toString()
|
||||||
else steps = track.stepCount.roundToInt().toString()
|
|
||||||
|
|
||||||
// populate views
|
// populate views
|
||||||
trackNameView.text = track.name
|
trackNameView.text = track.name
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:contentDescription="@string/descr_map_current_track"
|
android:contentDescription="@string/descr_map_current_track"
|
||||||
android:visibility="visible"></org.osmdroid.views.MapView>
|
android:visibility="visible" />
|
||||||
|
|
||||||
<androidx.constraintlayout.widget.ConstraintLayout
|
<androidx.constraintlayout.widget.ConstraintLayout
|
||||||
android:id="@+id/container"
|
android:id="@+id/container"
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<resources></resources>
|
<resources />
|
||||||
|
|
Loading…
Reference in a new issue