19 feature notify users to change battery permission settings#22
Conversation
…dialog in string resources file.
…generic update function for UserPreferences.
| <activity | ||
| android:name=".MainActivity" | ||
| android:exported="true" | ||
| android:label="@string/app_name" |
There was a problem hiding this comment.
Redundant label removed
| val clockEnabled = clockPageViewModel.clockButtonEnabled | ||
| val isRunning = clockPageViewModel.isClockRunning | ||
| val dropdownExpanded = clockPageViewModel.dropdownExpanded | ||
| // observe changes on autofillTaskNames to allow filteredTaskNames to function properly | ||
| clockPageViewModel.autofillTaskNames.observeAsState() | ||
| val filteredTaskNames = clockPageViewModel.filteredEventNames | ||
| val taskTextFieldValue = clockPageViewModel.taskTextFieldValue | ||
| val currSeconds = clockPageViewModel.currSeconds | ||
| val onTaskNameChange = clockPageViewModel::onTaskNameChange | ||
| val onTaskNameDonePressed = clockPageViewModel::onTaskNameDonePressed | ||
| val onDismissDropdown = clockPageViewModel::onDismissDropdown | ||
| val onDropdownMenuItemClick = clockPageViewModel::onDropdownMenuItemClick | ||
| val startClock = clockPageViewModel::startClock | ||
| val stopClock = clockPageViewModel::stopClock | ||
| val onTimerAnimationFinished = clockPageViewModel::resetCurrSeconds | ||
| val countdownEnabled = clockPageViewModel.countDownTimerEnabled | ||
| val onCountdownIconClicked = clockPageViewModel::switchCountDownTimer | ||
| val hoursTextFieldValue = clockPageViewModel.hoursTextFieldValue | ||
| val minutesTextFieldValue = clockPageViewModel.minutesTextFieldValue | ||
| val secondsTextFieldValue = clockPageViewModel.secondsTextFieldValue |
There was a problem hiding this comment.
Want to only pass the ViewModel into components now, instead of a giant pile of parameters. However, this takes away the ability to view the ClockPage's compose mockup, which is not a big deal since I don't see it changing soon.
I am going to play around with different ways to pass state parameters and functions into these higher order components, to see how things will be tested the easiest.
| object PreferenceKeys { | ||
| val COUNT_DOWN_END_TIME = longPreferencesKey("count_down_end_time") | ||
| val COUNT_DOWN_ENABLED = booleanPreferencesKey("count_down_enabled") | ||
| } |
There was a problem hiding this comment.
I can move this back into the class for now if I want. For simplicity of testing, I wanted to see if I can make updating these preferences generic, which meant I moved these keys out of the class so I can reference them elsewhere.
app/src/main/java/com/nickspatties/timeclock/ui/viewmodel/ClockPageViewModel.kt
Outdated
Show resolved
Hide resolved
|
|
||
| <string name="battery_warning_dialog_title_2">Update battery usage settings</string> | ||
| <string name="battery_warning_dialog_body_2">The count down alarm may not work properly with the current settings.\n\nPlease set this app\'s battery usage settings to \"Unrestricted\" to ensure the alarm works as intended.</string> | ||
| <string name="battery_warning_dialog_action_2">Go to App Settings</string> |
There was a problem hiding this comment.
Kept these here in case I switch back to having the user set this battery permission themselves in the settings screen.
| fun goToBatterySettings() { | ||
| if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { | ||
| // modal appears asking user to ignore battery optimizations, but may violate Google Play Requirements | ||
| val intentBatteryUsage = Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS) |
There was a problem hiding this comment.
If this intent doesn't work in the future, try this one out instead to go to the setting screen for TimeClock:
val intentBatteryUsage = Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS)
Changes
Allow users to adjust their battery settings from within the app. When a user selects the count down icon, if their battery permissions are not "Unrestricted", then they are prompted with a dialog to grant the app access to those permissions.
Note that this change really effects android devices including and past API 23 (Marshmallow), since battery permissions can actually be adjusted. API versions are not effected by this change.
Related issues
#19 #12
Testing