Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

19 feature notify users to change battery permission settings #22

Conversation

NicksPatties
Copy link
Owner

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

  • Manual testing

@NicksPatties NicksPatties linked an issue Aug 5, 2022 that may be closed by this pull request
@@ -15,7 +20,6 @@
<activity
android:name=".MainActivity"
android:exported="true"
android:label="@string/app_name"
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redundant label removed

Comment on lines -142 to -161
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
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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")
}
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@@ -28,4 +31,8 @@
<string name="alarm_channel_id" translatable="false">alarm_channel</string>
<string name="alarm_channel_name">Countdown Alarm</string>

<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>
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

@NicksPatties NicksPatties merged commit 1e6c236 into master Aug 5, 2022
@NicksPatties NicksPatties deleted the 19-feature-notify-users-to-change-battery-permission-settings branch August 29, 2022 19:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEATURE] Notify users to change battery permission settings
1 participant