@@ -29,7 +29,7 @@ import kotlinx.coroutines.delay
29
29
class RunningWorker @AssistedInject constructor(
30
30
@Assisted private val context : Context ,
31
31
@Assisted params : WorkerParameters ,
32
- private val runningRepository : RunningRepository
32
+ private val runningDataManager : RunningDataManager
33
33
) : CoroutineWorker(context, params) {
34
34
35
35
private val fusedLocationClient = LocationServices .getFusedLocationProviderClient(context)
@@ -39,18 +39,18 @@ class RunningWorker @AssistedInject constructor(
39
39
40
40
override suspend fun doWork (): Result {
41
41
if (startTracking().not ()) {
42
- runningRepository .finishRunning()
42
+ runningDataManager .finishRunning()
43
43
return Result .failure()
44
44
}
45
45
46
46
setForeground(createForegroundInfo(context.getString(R .string.running_notification_content)))
47
47
48
- while ((runningRepository .runningState.value is RunningState .NotRunning ).not ()) {
48
+ while ((runningDataManager .runningState.value is RunningState .NotRunning ).not ()) {
49
49
delay(UPDATE_INTERVAL_MS )
50
- when (runningRepository .runningState.value) {
50
+ when (runningDataManager .runningState.value) {
51
51
is RunningState .NotRunning -> break
52
52
is RunningState .Paused -> continue
53
- is RunningState .Running -> runningRepository .tick()
53
+ is RunningState .Running -> runningDataManager .tick()
54
54
}
55
55
}
56
56
fusedLocationClient.removeLocationUpdates(locationCallback)
@@ -100,9 +100,9 @@ class RunningWorker @AssistedInject constructor(
100
100
locationCallback = object : LocationCallback () {
101
101
override fun onLocationResult (locationResult : LocationResult ) {
102
102
locationResult.lastLocation?.let { location ->
103
- runningRepository .setRunningState(location)
103
+ runningDataManager .setRunningState(location)
104
104
} ? : run {
105
- runningRepository .pauseRunning()
105
+ runningDataManager .pauseRunning()
106
106
}
107
107
}
108
108
}
@@ -113,12 +113,12 @@ class RunningWorker @AssistedInject constructor(
113
113
locationCallback,
114
114
Looper .getMainLooper()
115
115
)
116
- runningRepository .startRunning()
116
+ runningDataManager .startRunning()
117
117
return true
118
118
} catch (e: SecurityException ) {
119
- runningRepository .pauseRunning()
119
+ runningDataManager .pauseRunning()
120
120
} catch (e: Exception ) {
121
- runningRepository .pauseRunning()
121
+ runningDataManager .pauseRunning()
122
122
}
123
123
return false
124
124
}
0 commit comments