-
-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4f4e570
commit 689a353
Showing
4 changed files
with
64 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
...ain/java/com/kylecorry/trail_sense/tools/pedometer/receivers/SetPedometerStateReceiver.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.kylecorry.trail_sense.tools.pedometer.receivers | ||
|
||
import android.content.Context | ||
import android.os.Bundle | ||
import com.kylecorry.trail_sense.shared.UserPreferences | ||
import com.kylecorry.trail_sense.tools.pedometer.infrastructure.StepCounterService | ||
import com.kylecorry.trail_sense.tools.tools.infrastructure.Receiver | ||
|
||
// TODO: Add support for enable/disable pedometer | ||
class SetPedometerStateReceiver : Receiver { | ||
override fun onReceive(context: Context, data: Bundle) { | ||
val desiredState = data.getBoolean(PARAM_PEDOMETER_STATE, false) | ||
val prefs = UserPreferences(context) | ||
|
||
if (desiredState && prefs.pedometer.isEnabled) { | ||
StepCounterService.start(context) | ||
} else if (!desiredState) { | ||
StepCounterService.stop(context) | ||
} | ||
} | ||
|
||
companion object { | ||
const val PARAM_PEDOMETER_STATE = "state" | ||
} | ||
} |