Last active
November 23, 2018 19:13
-
-
Save rootasjey/08c634e455755b8b2a3c5efdd2fa9382 to your computer and use it in GitHub Desktop.
Get the next allowed activity's number
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
// App | |
import { me } from "appbit"; | |
/** | |
* Return the next allowed activity's number | |
*/ | |
export function getNextAllowedActivity(activityNumber) { | |
const { granted } = me.permissions; | |
const grantedActivity = granted('access_activity'); | |
const grantedWeather = granted('access_location') && | |
granted('access_internet'); | |
const grantedPermissions = { | |
0: grantedActivity, // active minutes | |
1: grantedActivity, // calories | |
2: true, // clock | |
3: true, // date | |
4: grantedActivity, // distance | |
5: grantedActivity, // elevation gain | |
6: granted('access_heart_rate'), // heart rate | |
7: grantedActivity, // steps | |
8: grantedWeather, // weather | |
}; | |
const lengthPerm = Object.keys(grantedPermissions).length; | |
if (grantedPermissions[activityNumber]) { | |
return activityNumber; | |
} | |
let i = activityNumber; | |
while (!grantedPermissions[i]) { | |
i = (i + 1) % lengthPerm; | |
} | |
return i; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment