-
-
Notifications
You must be signed in to change notification settings - Fork 151
Fix/flashlight intensity issue #3733
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,8 +39,6 @@ class FragmentToolFlashlight : BoundFragment<FragmentToolFlashlightBinding>() { | |
| turnOn() | ||
| } | ||
|
|
||
| private var selectedMode = FlashlightMode.Torch | ||
|
|
||
| private val cache by lazy { PreferencesSubsystem.getInstance(requireContext()).preferences } | ||
| private val prefs by lazy { UserPreferences(requireContext()) } | ||
| private val formatter by lazy { FormatService.getInstance(requireContext()) } | ||
|
|
@@ -107,23 +105,40 @@ class FragmentToolFlashlight : BoundFragment<FragmentToolFlashlightBinding>() { | |
| considerShownIfCancelled = false, | ||
| ) { _, agreed -> | ||
| val frequency = if (it == 10) 200 else it | ||
| selectedMode = if (agreed) { | ||
| val mode = if (agreed) { | ||
| getStrobeMode(frequency) | ||
| } else { | ||
| FlashlightMode.Torch | ||
| } | ||
| turnOn() | ||
| flashlight.set(mode) | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would like both of these flashlight.set lines in this function to be restored to turnOn - that way there's a single point where it is handling that. I think my other comment about the selectedMode bug and bringing back the selectedMode state will allow this to be function to be restored while retaining the behavior we want |
||
| } | ||
| } else { | ||
| selectedMode = when (it) { | ||
| val mode = when (it) { | ||
| 11 -> FlashlightMode.Sos | ||
| else -> FlashlightMode.Torch | ||
| } | ||
| turnOn() | ||
| flashlight.set(mode) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private fun getDialIndex(mode: FlashlightMode): Int { | ||
| return when (mode) { | ||
| FlashlightMode.Strobe1 -> 1 | ||
| FlashlightMode.Strobe2 -> 2 | ||
| FlashlightMode.Strobe3 -> 3 | ||
| FlashlightMode.Strobe4 -> 4 | ||
| FlashlightMode.Strobe5 -> 5 | ||
| FlashlightMode.Strobe6 -> 6 | ||
| FlashlightMode.Strobe7 -> 7 | ||
| FlashlightMode.Strobe8 -> 8 | ||
| FlashlightMode.Strobe9 -> 9 | ||
| FlashlightMode.Strobe200 -> 10 | ||
| FlashlightMode.Sos -> 11 | ||
| else -> 0 | ||
| } | ||
| } | ||
|
|
||
| private fun getStrobeMode(frequency: Int): FlashlightMode { | ||
| return when (frequency) { | ||
| 1 -> FlashlightMode.Strobe1 | ||
|
|
@@ -143,6 +158,9 @@ class FragmentToolFlashlight : BoundFragment<FragmentToolFlashlightBinding>() { | |
| override fun onResume() { | ||
| super.onResume() | ||
| flashlightMode = flashlight.getMode() | ||
| val index = getDialIndex(flashlightMode) | ||
| binding.flashlightDial.selected = index | ||
| binding.flashlightDial.scrollToOption(index) | ||
| updateFlashlightUI() | ||
| intervalometer.interval(20) | ||
| binding.flashlightDial.areHapticsEnabled = true | ||
|
|
@@ -181,16 +199,22 @@ class FragmentToolFlashlight : BoundFragment<FragmentToolFlashlightBinding>() { | |
| } | ||
|
|
||
| private fun turnOn() { | ||
| flashlight.set(selectedMode) | ||
| flashlight.set(flashlight.selectedMode) | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this should maintain a local selectedMode state (like it did before), and sync that with the flashlight subsystem's mode on resume. This technique is causing a bug in which when I change the mode and then turn off the flashlight it switches back to 0 without me leaving the page. I would like it to only default back to 0 when I come back to the page and the flashlight is off. Potentially just the code you have in onResume will do the job, but that will need to be verified. |
||
| } | ||
|
|
||
| private fun turnOff() { | ||
| flashlight.set(FlashlightMode.Off) | ||
| } | ||
|
|
||
| private fun update() { | ||
| flashlightMode = flashlight.getMode() | ||
| updateFlashlightUI() | ||
| val newMode = flashlight.getMode() | ||
| if (newMode != flashlightMode) { | ||
| flashlightMode = newMode | ||
| updateFlashlightUI() | ||
| val index = getDialIndex(flashlightMode) | ||
| binding.flashlightDial.selected = index | ||
| binding.flashlightDial.scrollToOption(index) | ||
| } | ||
| } | ||
|
|
||
| private fun updateTimer() { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to move this to within the
onmethod so that it is wrapped by the synchronized block?Moving it there would also allow it to be removed on line 182 as well