Skip to content

Commit 8c7cbd7

Browse files
committed
save last used stroboscope frequency
1 parent 687dbe5 commit 8c7cbd7

File tree

4 files changed

+23
-9
lines changed

4 files changed

+23
-9
lines changed

app/src/main/kotlin/com/simplemobiletools/flashlight/activities/MainActivity.kt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ import com.squareup.otto.Subscribe
2323
import kotlinx.android.synthetic.main.activity_main.*
2424

2525
class MainActivity : SimpleActivity() {
26-
private val MAX_STROBO_DELAY = 2000
27-
private val MIN_STROBO_DELAY = 30
26+
private val MAX_STROBO_DELAY = 2000L
27+
private val MIN_STROBO_DELAY = 30L
2828
private val FLASHLIGHT_STATE = "flashlight_state"
2929
private val STROBOSCOPE_STATE = "stroboscope_state"
3030

@@ -148,12 +148,14 @@ class MainActivity : SimpleActivity() {
148148
toggleStroboscope()
149149
}
150150

151-
stroboscope_bar.max = MAX_STROBO_DELAY - MIN_STROBO_DELAY
152-
stroboscope_bar.progress = stroboscope_bar.max / 2
151+
stroboscope_bar.max = (MAX_STROBO_DELAY - MIN_STROBO_DELAY).toInt()
152+
stroboscope_bar.progress = config.stroboscopeProgress
153153
stroboscope_bar.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener {
154154
override fun onProgressChanged(seekBar: SeekBar, progress: Int, b: Boolean) {
155155
val frequency = stroboscope_bar.max - progress + MIN_STROBO_DELAY
156156
mCameraImpl?.stroboFrequency = frequency
157+
config.stroboscopeFrequency = frequency
158+
config.stroboscopeProgress = progress
157159
}
158160

159161
override fun onStartTrackingTouch(seekBar: SeekBar) {

app/src/main/kotlin/com/simplemobiletools/flashlight/helpers/Config.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,12 @@ class Config(context: Context) : BaseConfig(context) {
1919
var turnFlashlightOn: Boolean
2020
get() = prefs.getBoolean(TURN_FLASHLIGHT_ON, false)
2121
set(turnFlashlightOn) = prefs.edit().putBoolean(TURN_FLASHLIGHT_ON, turnFlashlightOn).apply()
22+
23+
var stroboscopeProgress: Int
24+
get() = prefs.getInt(STROBOSCOPE_PROGRESS, 1000)
25+
set(stroboscopeProgress) = prefs.edit().putInt(STROBOSCOPE_PROGRESS, stroboscopeProgress).apply()
26+
27+
var stroboscopeFrequency: Long
28+
get() = prefs.getLong(STROBOSCOPE_FREQUENCY, 1000L)
29+
set(stroboscopeFrequency) = prefs.edit().putLong(STROBOSCOPE_FREQUENCY, stroboscopeFrequency).apply()
2230
}

app/src/main/kotlin/com/simplemobiletools/flashlight/helpers/Constants.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@ const val TURN_FLASHLIGHT_ON = "turn_flashlight_on"
66
const val IS_ENABLED = "is_enabled"
77
const val TOGGLE = "toggle"
88
const val TOGGLE_WIDGET_UI = "toggle_widget_ui"
9+
const val STROBOSCOPE_FREQUENCY = "stroboscope_frequency"
10+
const val STROBOSCOPE_PROGRESS = "stroboscope_progress"

app/src/main/kotlin/com/simplemobiletools/flashlight/helpers/MyCameraImpl.kt

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@ import com.simplemobiletools.commons.extensions.toast
88
import com.simplemobiletools.commons.helpers.isMarshmallowPlus
99
import com.simplemobiletools.commons.helpers.isNougatPlus
1010
import com.simplemobiletools.flashlight.R
11+
import com.simplemobiletools.flashlight.extensions.config
1112
import com.simplemobiletools.flashlight.extensions.updateWidgets
1213
import com.simplemobiletools.flashlight.models.Events
1314
import com.squareup.otto.Bus
1415
import java.io.IOException
1516

1617
class MyCameraImpl(val context: Context) {
17-
var stroboFrequency = 1000
18+
var stroboFrequency = 1000L
1819

1920
companion object {
2021
var isFlashlightOn = false
@@ -43,6 +44,7 @@ class MyCameraImpl(val context: Context) {
4344
}
4445

4546
handleCameraSetup()
47+
stroboFrequency = context.config.stroboscopeFrequency
4648
}
4749

4850
fun toggleFlashlight() {
@@ -202,9 +204,9 @@ class MyCameraImpl(val context: Context) {
202204
while (!shouldStroboscopeStop) {
203205
try {
204206
marshmallowCamera!!.toggleMarshmallowFlashlight(bus!!, true)
205-
Thread.sleep(stroboFrequency.toLong())
207+
Thread.sleep(stroboFrequency)
206208
marshmallowCamera!!.toggleMarshmallowFlashlight(bus!!, false)
207-
Thread.sleep(stroboFrequency.toLong())
209+
Thread.sleep(stroboFrequency)
208210
} catch (e: Exception) {
209211
shouldStroboscopeStop = true
210212
}
@@ -231,9 +233,9 @@ class MyCameraImpl(val context: Context) {
231233
while (!shouldStroboscopeStop) {
232234
try {
233235
camera!!.parameters = torchOn
234-
Thread.sleep(stroboFrequency.toLong())
236+
Thread.sleep(stroboFrequency)
235237
camera!!.parameters = torchOff
236-
Thread.sleep(stroboFrequency.toLong())
238+
Thread.sleep(stroboFrequency)
237239
} catch (e: Exception) {
238240
}
239241
}

0 commit comments

Comments
 (0)