Updated libraries

This commit is contained in:
y20k 2021-06-24 21:56:48 +02:00
parent 18a1164578
commit 36b891152c
No known key found for this signature in database
GPG key ID: 824D4259F41FAFF6
8 changed files with 35 additions and 43 deletions

View file

@ -59,16 +59,16 @@ dependencies {
// AndroidX
def navigationVersion = "2.3.5"
implementation "androidx.activity:activity-ktx:1.2.3"
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'androidx.core:core-ktx:1.3.2'
implementation 'androidx.core:core-ktx:1.5.0'
implementation "androidx.navigation:navigation-fragment-ktx:$navigationVersion"
implementation "androidx.navigation:navigation-ui-ktx:$navigationVersion"
implementation 'androidx.preference:preference-ktx:1.1.1'
implementation 'com.google.android.material:material:1.3.0'
// Gson
implementation 'com.google.code.gson:gson:2.8.6'
implementation 'com.google.code.gson:gson:2.8.7'
// OpenStreetMap
implementation 'org.osmdroid:osmdroid-android:6.1.10'

View file

@ -33,8 +33,11 @@ import androidx.core.content.ContextCompat
import androidx.fragment.app.Fragment
import androidx.navigation.fragment.findNavController
import androidx.preference.PreferenceManager
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.Dispatchers.Main
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import org.y20k.trackbook.core.Track
import org.y20k.trackbook.core.TracklistElement
import org.y20k.trackbook.helpers.*
@ -279,7 +282,7 @@ class MapFragment : Fragment(), YesNoDialog.YesNoDialogListener, MapOverlayHelpe
if (track.wayPoints.isEmpty()) {
YesNoDialog(this as YesNoDialog.YesNoDialogListener).show(activity as Context, type = Keys.DIALOG_EMPTY_RECORDING, title = R.string.dialog_error_empty_recording_title, message = R.string.dialog_error_empty_recording_message, yesButton = R.string.dialog_error_empty_recording_action_resume)
} else {
GlobalScope.launch {
CoroutineScope(IO).launch {
// step 1: create and store filenames for json and gpx files
track.trackUriString = FileHelper.getTrackFileUri(activity as Context, track).toString()
track.gpxUriString = FileHelper.getGpxFileUri(activity as Context, track).toString()
@ -290,10 +293,12 @@ class MapFragment : Fragment(), YesNoDialog.YesNoDialogListener, MapOverlayHelpe
// step 3: clear track
trackerService.clearTrack()
// step 4: open track in TrackFragement
withContext(Main) {
openTrack(track.toTracklistElement(activity as Context))
}
}
}
}
/* Opens a track in TrackFragment */

View file

@ -29,6 +29,7 @@ import android.view.View
import android.widget.Toast
import androidx.preference.*
import kotlinx.coroutines.*
import kotlinx.coroutines.Dispatchers.IO
import org.y20k.trackbook.core.Tracklist
import org.y20k.trackbook.helpers.*
@ -226,14 +227,11 @@ class SettingsFragment : PreferenceFragmentCompat(), YesNoDialog.YesNoDialogList
/* Removes track and track files for given position - used by TracklistFragment */
fun deleteNonStarred(context: Context) {
val backgroundJob = Job()
val uiScope = CoroutineScope(Dispatchers.Main + backgroundJob)
uiScope.launch {
CoroutineScope(IO).launch {
var tracklist: Tracklist = FileHelper.readTracklist(context)
val deferred: Deferred<Tracklist> = async { FileHelper.deleteNonStarredSuspended(context, tracklist) }
// wait for result and store in tracklist
tracklist = deferred.await()
backgroundJob.cancel()
}
}

View file

@ -34,7 +34,8 @@ import androidx.core.net.toFile
import androidx.core.os.bundleOf
import androidx.fragment.app.Fragment
import androidx.navigation.fragment.findNavController
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import org.y20k.trackbook.core.Track
import org.y20k.trackbook.dialogs.RenameTrackDialog
@ -122,7 +123,7 @@ class TrackFragment : Fragment(), RenameTrackDialog.RenameTrackListener, YesNoDi
val targetUri: Uri? = data.data
if (targetUri != null) {
// copy file async (= fire & forget - no return value needed)
GlobalScope.launch { FileHelper.saveCopyOfFileSuspended( activity as Context, originalFileUri = sourceUri, targetFileUri = targetUri) }
CoroutineScope(Dispatchers.IO).launch { FileHelper.saveCopyOfFileSuspended( activity as Context, originalFileUri = sourceUri, targetFileUri = targetUri) }
Toast.makeText(activity as Context, R.string.toast_message_save_gpx, Toast.LENGTH_LONG).show()
}
}
@ -136,7 +137,7 @@ class TrackFragment : Fragment(), RenameTrackDialog.RenameTrackListener, YesNoDi
/* Overrides onRenameTrackDialog from RenameTrackDialog */
override fun onRenameTrackDialog(textInput: String) {
// rename track async (= fire & forget - no return value needed)
GlobalScope.launch { FileHelper.renameTrackSuspended(activity as Context, layout.track, textInput) }
CoroutineScope(Dispatchers.IO).launch { FileHelper.renameTrackSuspended(activity as Context, layout.track, textInput) }
// update name in layout
layout.track.name = textInput
layout.trackNameView.text = textInput
@ -168,9 +169,7 @@ class TrackFragment : Fragment(), RenameTrackDialog.RenameTrackListener, YesNoDi
track = TrackHelper.toggleStarred(activity as Context, track, latitude, longitude)
layout.updateTrackOverlay(track)
// save track
GlobalScope.launch {
FileHelper.saveTrackSuspended(track, true)
}
CoroutineScope(Dispatchers.IO).launch { FileHelper.saveTrackSuspended(track, true) }
}

View file

@ -39,16 +39,16 @@ import android.os.IBinder
import androidx.core.content.ContextCompat
import androidx.preference.PreferenceManager
import kotlinx.coroutines.*
import kotlinx.coroutines.Dispatchers.IO
import org.y20k.trackbook.core.Track
import org.y20k.trackbook.helpers.*
import java.util.*
import kotlin.coroutines.CoroutineContext
/*
* TrackerService class
*/
class TrackerService: Service(), CoroutineScope, SensorEventListener {
class TrackerService: Service(), SensorEventListener {
/* Define log tag */
private val TAG: String = LogHelper.makeLogTag(TrackerService::class.java)
@ -78,11 +78,6 @@ class TrackerService: Service(), CoroutineScope, SensorEventListener {
private lateinit var notificationHelper: NotificationHelper
private lateinit var gpsLocationListener: LocationListener
private lateinit var networkLocationListener: LocationListener
private lateinit var backgroundJob: Job
/* Overrides coroutineContext variable */
override val coroutineContext: CoroutineContext get() = backgroundJob + Dispatchers.Main
/* Overrides onCreate from Service */
@ -103,7 +98,6 @@ class TrackerService: Service(), CoroutineScope, SensorEventListener {
trackingState = PreferencesHelper.loadTrackingState(this)
currentBestLocation = LocationHelper.getLastKnownLocation(this)
track = FileHelper.readTrack(this, FileHelper.getTempFileUri(this))
backgroundJob = Job()
altitudeValues.capacity = PreferencesHelper.loadAltitudeSmoothingValue(this)
PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(
sharedPreferenceChangeListener
@ -187,8 +181,6 @@ class TrackerService: Service(), CoroutineScope, SensorEventListener {
// stop receiving location updates
removeGpsLocationListener()
removeNetworkLocationListener()
// cancel background job
backgroundJob.cancel()
}
@ -260,7 +252,7 @@ class TrackerService: Service(), CoroutineScope, SensorEventListener {
fun stopTracking() {
// save temp track
track.recordingStop = GregorianCalendar.getInstance().time
GlobalScope.launch { FileHelper.saveTempTrackSuspended(this@TrackerService, track) }
CoroutineScope(IO).launch { FileHelper.saveTempTrackSuspended(this@TrackerService, track) }
// save state
trackingState = Keys.STATE_TRACKING_STOPPED
PreferencesHelper.saveTrackingState(this, trackingState)
@ -551,10 +543,7 @@ class TrackerService: Service(), CoroutineScope, SensorEventListener {
val now: Date = GregorianCalendar.getInstance().time
if (now.time - lastSave.time > Keys.SAVE_TEMP_TRACK_INTERVAL) {
lastSave = now
GlobalScope.launch { FileHelper.saveTempTrackSuspended(
this@TrackerService,
track
) }
CoroutineScope(IO).launch { FileHelper.saveTempTrackSuspended(this@TrackerService, track) }
}
}
// update notification

View file

@ -30,6 +30,8 @@ import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.RecyclerView
import kotlinx.coroutines.*
import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.Dispatchers.Main
import org.y20k.trackbook.R
import org.y20k.trackbook.core.Tracklist
import org.y20k.trackbook.core.TracklistElement
@ -113,14 +115,12 @@ class TracklistAdapter(private val fragment: Fragment) : RecyclerView.Adapter<Re
/* Removes track and track files for given position - used by TracklistFragment */
fun removeTrack(context: Context, position: Int) {
val backgroundJob = Job()
val uiScope = CoroutineScope(Dispatchers.Main + backgroundJob)
uiScope.launch {
CoroutineScope(IO).launch {
val deferred: Deferred<Tracklist> = async { FileHelper.deleteTrackSuspended(context, position, tracklist) }
// wait for result and store in tracklist
withContext(Main) {
tracklist = deferred.await()
notifyItemRemoved(position)
backgroundJob.cancel()
notifyItemRemoved(position) }
}
}
@ -147,7 +147,7 @@ class TracklistAdapter(private val fragment: Fragment) : RecyclerView.Adapter<Re
tracklist.tracklistElements[position].starred = true
}
}
GlobalScope.launch {
CoroutineScope(Dispatchers.IO).launch {
FileHelper.saveTracklistSuspended(context, tracklist, GregorianCalendar.getInstance().time)
}
}

View file

@ -30,7 +30,8 @@ import androidx.core.view.isVisible
import androidx.core.widget.NestedScrollView
import com.google.android.material.bottomsheet.BottomSheetBehavior
import com.google.android.material.textview.MaterialTextView
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import org.osmdroid.api.IGeoPoint
import org.osmdroid.api.IMapController
@ -196,7 +197,7 @@ data class TrackFragmentLayoutHolder(private var context: Context, private var m
/* Saves zoom level and center of this map */
fun saveViewStateToTrack() {
if (track.latitude != 0.0 && track.longitude != 0.0) {
GlobalScope.launch { FileHelper.saveTrackSuspended(track, false) }
CoroutineScope(Dispatchers.IO).launch { FileHelper.saveTrackSuspended(track, false) }
}
}

View file

@ -2,12 +2,12 @@
buildscript {
ext {
kotlin_version = '1.5.0'
kotlin_version = '1.5.20'
navigation_version = '2.3.3'
}
repositories {
google()
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.2.1'
@ -22,7 +22,7 @@ buildscript {
allprojects {
repositories {
google()
jcenter()
mavenCentral()
}
}