-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implemented stopping recording on low battery if set in settings (sti…
…ll need to add notification)
- Loading branch information
1 parent
59ac9e4
commit 4d9ab7b
Showing
6 changed files
with
126 additions
and
29 deletions.
There are no files selected for viewing
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
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
51 changes: 51 additions & 0 deletions
51
app/src/main/java/io/github/leonidius20/recorder/data/settings/Settings.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package io.github.leonidius20.recorder.data.settings | ||
|
||
import android.content.Context | ||
import android.content.SharedPreferences | ||
import android.content.SharedPreferences.OnSharedPreferenceChangeListener | ||
import androidx.preference.PreferenceManager | ||
import dagger.hilt.android.qualifiers.ApplicationContext | ||
import io.github.leonidius20.recorder.R | ||
import kotlinx.coroutines.flow.MutableStateFlow | ||
import javax.inject.Inject | ||
import javax.inject.Singleton | ||
|
||
@Singleton | ||
class Settings @Inject constructor( | ||
@ApplicationContext private val context: Context, | ||
): OnSharedPreferenceChangeListener { | ||
|
||
data class SettingsState( | ||
val stopOnLowBattery: Boolean, | ||
val stopOnLowStorage: Boolean, | ||
val pauseOnCall: Boolean, | ||
) | ||
|
||
private val pref = PreferenceManager.getDefaultSharedPreferences(context) | ||
|
||
val state = MutableStateFlow(getCurrentSettingsState()) | ||
|
||
init { | ||
pref.registerOnSharedPreferenceChangeListener(this) | ||
} | ||
|
||
override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) { | ||
state.value = getCurrentSettingsState() | ||
} | ||
|
||
private fun getCurrentSettingsState(): SettingsState { | ||
return SettingsState( | ||
stopOnLowBattery = pref.getBoolean( | ||
context.getString(R.string.stop_on_low_battery_pref_key), | ||
context.resources.getBoolean(R.bool.stop_on_low_battery_default)), | ||
stopOnLowStorage = pref.getBoolean( | ||
context.getString(R.string.stop_on_low_storage_pref_key), | ||
context.resources.getBoolean(R.bool.stop_on_storage_default)), | ||
pauseOnCall = pref.getBoolean( | ||
context.getString(R.string.pause_on_call_pref_key), | ||
context.resources.getBoolean(R.bool.pause_on_call_default)), | ||
) | ||
} | ||
|
||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
<bool name="stop_on_low_battery_default">true</bool> | ||
<bool name="stop_on_storage_default">true</bool> | ||
<bool name="pause_on_call_default">false</bool> | ||
</resources> |
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
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