-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bundle implemented
- Loading branch information
Showing
17 changed files
with
348 additions
and
10 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
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
object AppInfo { | ||
const val PACKAGE = "fun.kotlingang.kds" | ||
const val VERSION = "5.3.0" | ||
const val VERSION = "1.0.0" | ||
const val NAME = "Kotlin Data Storage" | ||
const val DESCRIPTION = "Multiplatform Coroutine-Based Kotlin Library for storing data via kotlinx.serialization" | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import `fun`.kotlingang.deploy.DeployEntity | ||
|
||
plugins { | ||
id(plugin.androidLibrary) | ||
kotlin(plugin.android) | ||
} | ||
|
||
configure<DeployEntity> { | ||
componentName = "release" | ||
} | ||
|
||
android { | ||
// Workaround since explicitApi() does not work for android | ||
kotlinOptions.freeCompilerArgs += "-Xexplicit-api=strict" | ||
kotlinOptions.freeCompilerArgs += "-Xopt-in=kotlin.RequiresOptIn" | ||
|
||
compileSdk = Version.COMPILE_SDK | ||
|
||
defaultConfig { | ||
targetSdk = Version.COMPILE_SDK | ||
minSdk = Version.MIN_SDK | ||
} | ||
|
||
buildFeatures { | ||
buildConfig = false | ||
} | ||
} | ||
|
||
dependencies { | ||
api(core) | ||
} |
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 @@ | ||
<manifest package="fun.kotlingang.kds"/> |
9 changes: 9 additions & 0 deletions
9
bundle/src/main/java/fun/kotlingang/kds/InstanceStateManager.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,9 @@ | ||
package `fun`.kotlingang.kds | ||
|
||
import android.os.Bundle | ||
|
||
|
||
public interface InstanceStateManager { | ||
public fun restoreInstanceState(bundle: Bundle?) | ||
public fun saveInstanceState(bundle: Bundle) | ||
} |
91 changes: 91 additions & 0 deletions
91
bundle/src/main/java/fun/kotlingang/kds/KPrimitiveBundleDataStorage.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,91 @@ | ||
package `fun`.kotlingang.kds | ||
|
||
import `fun`.kotlingang.kds.annotation.RawSetterGetter | ||
import `fun`.kotlingang.kds.extensions.bundle.contains | ||
import `fun`.kotlingang.kds.storage.PrimitiveDataStorage | ||
import android.os.Bundle | ||
|
||
|
||
public open class KPrimitiveBundleDataStorage : PrimitiveDataStorage, InstanceStateManager { | ||
private val bundle = Bundle() | ||
|
||
override fun restoreInstanceState(bundle: Bundle?) { | ||
if(bundle != null) | ||
this.bundle.putAll(bundle) | ||
} | ||
override fun saveInstanceState(bundle: Bundle) { | ||
bundle.putAll(this.bundle) | ||
} | ||
|
||
@RawSetterGetter | ||
final override fun putString(key: String, value: String) { | ||
bundle.putString(key, value) | ||
} | ||
|
||
@RawSetterGetter | ||
final override fun putInt(key: String, value: Int) { | ||
bundle.putInt(key, value) | ||
} | ||
|
||
@RawSetterGetter | ||
final override fun putLong(key: String, value: Long) { | ||
bundle.putLong(key, value) | ||
} | ||
|
||
@RawSetterGetter | ||
final override fun putFloat(key: String, value: Float) { | ||
bundle.putFloat(key, value) | ||
} | ||
|
||
@RawSetterGetter | ||
final override fun putDouble(key: String, value: Double) { | ||
bundle.putDouble(key, value) | ||
} | ||
|
||
@RawSetterGetter | ||
final override fun putBoolean(key: String, value: Boolean) { | ||
bundle.putBoolean(key, value) | ||
} | ||
|
||
@RawSetterGetter | ||
final override fun getString(key: String): String? = | ||
if(key in bundle) | ||
bundle.getString(key) | ||
else | ||
null | ||
|
||
@RawSetterGetter | ||
final override fun getInt(key: String): Int? = | ||
if(key in bundle) | ||
bundle.getInt(key) | ||
else | ||
null | ||
|
||
@RawSetterGetter | ||
final override fun getLong(key: String): Long? = | ||
if(key in bundle) | ||
bundle.getLong(key) | ||
else | ||
null | ||
|
||
@RawSetterGetter | ||
final override fun getFloat(key: String): Float? = | ||
if(key in bundle) | ||
bundle.getFloat(key) | ||
else | ||
null | ||
|
||
@RawSetterGetter | ||
final override fun getDouble(key: String): Double? = | ||
if(key in bundle) | ||
bundle.getDouble(key) | ||
else | ||
null | ||
|
||
@RawSetterGetter | ||
final override fun getBoolean(key: String): Boolean? = | ||
if(key in bundle) | ||
bundle.getBoolean(key) | ||
else | ||
null | ||
} |
6 changes: 6 additions & 0 deletions
6
bundle/src/main/java/fun/kotlingang/kds/extensions/bundle/in.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,6 @@ | ||
package `fun`.kotlingang.kds.extensions.bundle | ||
|
||
import android.os.Bundle | ||
|
||
|
||
internal operator fun Bundle.contains(key: String) = containsKey(key) |
10 changes: 10 additions & 0 deletions
10
bundle/src/main/java/fun/kotlingang/kds/extensions/instance_state_manager/fillState.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,10 @@ | ||
package `fun`.kotlingang.kds.extensions.instance_state_manager | ||
|
||
import `fun`.kotlingang.kds.InstanceStateManager | ||
import android.os.Bundle | ||
|
||
|
||
public inline fun InstanceStateManager.fillState(bundle: Bundle?, block: () -> Unit) { | ||
restoreInstanceState(bundle) | ||
block() | ||
} |
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,32 @@ | ||
import `fun`.kotlingang.deploy.DeployEntity | ||
|
||
plugins { | ||
id(plugin.androidLibrary) | ||
kotlin(plugin.android) | ||
} | ||
|
||
configure<DeployEntity> { | ||
componentName = "release" | ||
} | ||
|
||
android { | ||
// Workaround since explicitApi() does not work for android | ||
kotlinOptions.freeCompilerArgs += "-Xexplicit-api=strict" | ||
kotlinOptions.freeCompilerArgs += "-Xopt-in=kotlin.RequiresOptIn" | ||
|
||
compileSdk = Version.COMPILE_SDK | ||
|
||
defaultConfig { | ||
targetSdk = Version.COMPILE_SDK | ||
minSdk = Version.MIN_SDK | ||
} | ||
|
||
buildFeatures { | ||
buildConfig = false | ||
} | ||
} | ||
|
||
dependencies { | ||
api(json) | ||
api(bundle) | ||
} |
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 @@ | ||
<manifest package="fun.kotlingang.kds"/> |
95 changes: 95 additions & 0 deletions
95
json/json-bundle/src/main/java/fun/kotlingang/kds/KBundleDataStorage.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,95 @@ | ||
package `fun`.kotlingang.kds | ||
|
||
import `fun`.kotlingang.kds.annotation.DelicateKDSApi | ||
import `fun`.kotlingang.kds.annotation.RawSetterGetter | ||
import `fun`.kotlingang.kds.storage.PrimitiveDataStorage | ||
import android.os.Bundle | ||
import kotlinx.serialization.json.Json | ||
|
||
|
||
public open class KBundleDataStorage private constructor ( | ||
json: Json, | ||
private val storage: KJsonElementDataStorage | ||
): KJsonDataStorage(json, storage), PrimitiveDataStorage, InstanceStateManager { | ||
public constructor ( | ||
json: Json = Json | ||
) : this(json, KJsonElementDataStorage(json)) | ||
|
||
final override fun restoreInstanceState(bundle: Bundle?) { | ||
storage.restoreInstanceState(bundle) | ||
} | ||
final override fun saveInstanceState(bundle: Bundle) { | ||
storage.saveInstanceState(bundle) | ||
} | ||
|
||
@RawSetterGetter | ||
final override fun putString(key: String, value: String) { | ||
storage.putString(key, value) | ||
} | ||
|
||
@RawSetterGetter | ||
final override fun putInt(key: String, value: Int) { | ||
storage.putInt(key, value) | ||
} | ||
|
||
@RawSetterGetter | ||
final override fun putLong(key: String, value: Long) { | ||
storage.putLong(key, value) | ||
} | ||
|
||
@RawSetterGetter | ||
final override fun putFloat(key: String, value: Float) { | ||
storage.putFloat(key, value) | ||
} | ||
|
||
@RawSetterGetter | ||
final override fun putDouble(key: String, value: Double) { | ||
storage.putDouble(key, value) | ||
} | ||
|
||
@RawSetterGetter | ||
final override fun putBoolean(key: String, value: Boolean) { | ||
storage.putBoolean(key, value) | ||
} | ||
|
||
@RawSetterGetter | ||
final override fun getString(key: String): String? { | ||
return storage.getString(key) | ||
} | ||
|
||
@RawSetterGetter | ||
final override fun getInt(key: String): Int? { | ||
return storage.getInt(key) | ||
} | ||
|
||
@RawSetterGetter | ||
final override fun getLong(key: String): Long? { | ||
return storage.getLong(key) | ||
} | ||
|
||
@RawSetterGetter | ||
final override fun getFloat(key: String): Float? { | ||
return storage.getFloat(key) | ||
} | ||
|
||
@RawSetterGetter | ||
final override fun getDouble(key: String): Double? { | ||
return storage.getDouble(key) | ||
} | ||
|
||
@RawSetterGetter | ||
final override fun getBoolean(key: String): Boolean? { | ||
return storage.getBoolean(key) | ||
} | ||
|
||
@OptIn(DelicateKDSApi::class, RawSetterGetter::class) | ||
override fun commitBlocking() { | ||
encodeReferences().forEach { (k, v) -> | ||
storage.putJsonElement(k, v) | ||
} | ||
} | ||
|
||
final override fun setupBlocking() { | ||
super.setupBlocking() | ||
} | ||
} |
Oops, something went wrong.