mirror of
https://github.com/Myzel394/Alibi.git
synced 2025-06-18 23:05:26 +02:00
fix: Fix AppSettings
This commit is contained in:
parent
8d7dd96110
commit
752901e5c4
@ -1,6 +1,7 @@
|
|||||||
plugins {
|
plugins {
|
||||||
id 'com.android.application'
|
id 'com.android.application'
|
||||||
id 'org.jetbrains.kotlin.android'
|
id 'org.jetbrains.kotlin.android'
|
||||||
|
id 'org.jetbrains.kotlin.plugin.serialization'
|
||||||
}
|
}
|
||||||
|
|
||||||
android {
|
android {
|
||||||
@ -49,7 +50,6 @@ android {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
|
||||||
implementation 'androidx.core:core-ktx:1.10.1'
|
implementation 'androidx.core:core-ktx:1.10.1'
|
||||||
implementation platform('org.jetbrains.kotlin:kotlin-bom:1.8.0')
|
implementation platform('org.jetbrains.kotlin:kotlin-bom:1.8.0')
|
||||||
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.6.1'
|
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.6.1'
|
||||||
@ -75,5 +75,8 @@ dependencies {
|
|||||||
|
|
||||||
implementation "androidx.datastore:datastore-preferences:1.0.0"
|
implementation "androidx.datastore:datastore-preferences:1.0.0"
|
||||||
|
|
||||||
|
implementation "androidx.navigation:navigation-compose:2.6.0"
|
||||||
|
implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:1.5.1"
|
||||||
|
|
||||||
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.0.3'
|
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.0.3'
|
||||||
}
|
}
|
@ -2,11 +2,25 @@ package app.myzel394.locationtest.db
|
|||||||
|
|
||||||
import android.media.MediaRecorder
|
import android.media.MediaRecorder
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
|
import kotlinx.serialization.Serializable
|
||||||
|
import kotlinx.serialization.json.Json
|
||||||
|
import kotlinx.serialization.json.decodeFromStream
|
||||||
|
|
||||||
|
@Serializable
|
||||||
data class AppSettings(
|
data class AppSettings(
|
||||||
val audioRecorderSettings: AudioRecorderSettings = AudioRecorderSettings(),
|
val audioRecorderSettings: AudioRecorderSettings = AudioRecorderSettings(),
|
||||||
)
|
val showAdvancedSettings: Boolean = false,
|
||||||
|
) {
|
||||||
|
fun setShowAdvancedSettings(showAdvancedSettings: Boolean): AppSettings {
|
||||||
|
return copy(showAdvancedSettings = showAdvancedSettings)
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
fun getDefaultInstance(): AppSettings = AppSettings()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Serializable
|
||||||
data class AudioRecorderSettings(
|
data class AudioRecorderSettings(
|
||||||
// 60 seconds
|
// 60 seconds
|
||||||
val intervalDuration: Long = 60 * 1000L,
|
val intervalDuration: Long = 60 * 1000L,
|
||||||
|
@ -0,0 +1,33 @@
|
|||||||
|
package app.myzel394.locationtest.db
|
||||||
|
|
||||||
|
import androidx.datastore.core.Serializer
|
||||||
|
import kotlinx.serialization.SerializationException
|
||||||
|
import kotlinx.serialization.json.Json
|
||||||
|
import java.io.InputStream
|
||||||
|
import java.io.OutputStream
|
||||||
|
|
||||||
|
class AppSettingsSerializer: Serializer<AppSettings> {
|
||||||
|
override val defaultValue: AppSettings = AppSettings.getDefaultInstance()
|
||||||
|
|
||||||
|
override suspend fun readFrom(input: InputStream): AppSettings {
|
||||||
|
return try {
|
||||||
|
Json.decodeFromString(
|
||||||
|
AppSettings.serializer(),
|
||||||
|
input.readBytes().decodeToString()
|
||||||
|
)
|
||||||
|
} catch (error: SerializationException) {
|
||||||
|
error.printStackTrace()
|
||||||
|
defaultValue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Suppress("BlockingMethodInNonBlockingContext")
|
||||||
|
override suspend fun writeTo(t: AppSettings, output: OutputStream) {
|
||||||
|
output.write(
|
||||||
|
Json.encodeToString(
|
||||||
|
AppSettings.serializer(),
|
||||||
|
t
|
||||||
|
).encodeToByteArray()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
@ -3,4 +3,6 @@ plugins {
|
|||||||
id 'com.android.application' version '8.0.2' apply false
|
id 'com.android.application' version '8.0.2' apply false
|
||||||
id 'com.android.library' version '8.0.2' apply false
|
id 'com.android.library' version '8.0.2' apply false
|
||||||
id 'org.jetbrains.kotlin.android' version '1.9.0' apply false
|
id 'org.jetbrains.kotlin.android' version '1.9.0' apply false
|
||||||
|
|
||||||
|
id 'org.jetbrains.kotlin.plugin.serialization' version '1.8.21'
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user