Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions FloconAndroid/datastores-no-op/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
88 changes: 88 additions & 0 deletions FloconAndroid/datastores-no-op/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
plugins {
alias(libs.plugins.android.library)
alias(libs.plugins.kotlin.android)
id("com.vanniktech.maven.publish") version "0.34.0"
}

android {
namespace = "io.github.openflocon.flocon.datastores"
compileSdk = 36

defaultConfig {
minSdk = 23

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles("consumer-rules.pro")
}

buildTypes {
release {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}

compileOptions {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
kotlinOptions {
jvmTarget = "11"
}
}

dependencies {

implementation(project(":flocon-base"))

implementation(platform(libs.kotlinx.coroutines.bom))
implementation(libs.jetbrains.kotlinx.coroutines.core)

implementation(libs.androidx.datastore.preferences)
}


mavenPublishing {
publishToMavenCentral(automaticRelease = true)

if (project.hasProperty("signing.required") && project.property("signing.required") == "false") {
// Skip signing
} else {
signAllPublications()
}

coordinates(
groupId = project.property("floconGroupId") as String,
artifactId = "flocon-datastores-no-op",
version = System.getenv("PROJECT_VERSION_NAME") ?: project.property("floconVersion") as String
)

pom {
name = "Flocon Datastores Integration No Op"
description = project.property("floconDescription") as String
inceptionYear = "2025"
url = "https://github.com/openflocon/Flocon"
licenses {
license {
name = "The Apache License, Version 2.0"
url = "https://www.apache.org/licenses/LICENSE-2.0.txt"
distribution = "https://www.apache.org/licenses/LICENSE-2.0.txt"
}
}
developers {
developer {
id = "openflocon"
name = "Open Flocon"
url = "https://github.com/openflocon"
}
}
scm {
url = "https://github.com/openflocon/Flocon"
connection = "scm:git:git://github.com/openflocon/Flocon.git"
developerConnection = "scm:git:ssh://git@github.com/openflocon/Flocon.git"
}
}
}
Empty file.
21 changes: 21 additions & 0 deletions FloconAndroid/datastores-no-op/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
3 changes: 3 additions & 0 deletions FloconAndroid/datastores-no-op/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package io.github.openflocon.flocon.preferences.datastores.model

import androidx.datastore.core.DataStore
import androidx.datastore.preferences.core.Preferences
import androidx.datastore.preferences.core.booleanPreferencesKey
import androidx.datastore.preferences.core.doublePreferencesKey
import androidx.datastore.preferences.core.edit
import androidx.datastore.preferences.core.floatPreferencesKey
import androidx.datastore.preferences.core.intPreferencesKey
import androidx.datastore.preferences.core.longPreferencesKey
import androidx.datastore.preferences.core.stringPreferencesKey
import io.github.openflocon.flocon.FloconLogger
import io.github.openflocon.flocon.plugins.sharedprefs.model.FloconPreference
import io.github.openflocon.flocon.plugins.sharedprefs.model.FloconPreferenceValue
import kotlinx.coroutines.flow.first

class FloconDatastorePreference(
override val name: String,
val dataStore: DataStore<Preferences>,
) : FloconPreference {

override suspend fun set(
columnName: String,
value: FloconPreferenceValue
) {
// no op
}

override suspend fun columns(): List<String> {
return emptyList() // no op
}

override suspend fun get(columnName: String): FloconPreferenceValue? {
return null // no op
}

}
1 change: 1 addition & 0 deletions FloconAndroid/datastores/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
89 changes: 89 additions & 0 deletions FloconAndroid/datastores/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
plugins {
alias(libs.plugins.android.library)
alias(libs.plugins.kotlin.android)
id("com.vanniktech.maven.publish") version "0.34.0"
}

android {
namespace = "io.github.openflocon.flocon.datastores"
compileSdk = 36

defaultConfig {
minSdk = 23

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles("consumer-rules.pro")
}

buildTypes {
release {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}

compileOptions {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
kotlinOptions {
jvmTarget = "11"
}
}

dependencies {

implementation(project(":flocon-base"))

implementation(platform(libs.kotlinx.coroutines.bom))
implementation(libs.jetbrains.kotlinx.coroutines.core)
implementation(libs.jetbrains.kotlinx.coroutines.android)

implementation(libs.androidx.datastore.preferences)
}


mavenPublishing {
publishToMavenCentral(automaticRelease = true)

if (project.hasProperty("signing.required") && project.property("signing.required") == "false") {
// Skip signing
} else {
signAllPublications()
}

coordinates(
groupId = project.property("floconGroupId") as String,
artifactId = "flocon-datastores",
version = System.getenv("PROJECT_VERSION_NAME") ?: project.property("floconVersion") as String
)

pom {
name = "Flocon Datastores Integration"
description = project.property("floconDescription") as String
inceptionYear = "2025"
url = "https://github.com/openflocon/Flocon"
licenses {
license {
name = "The Apache License, Version 2.0"
url = "https://www.apache.org/licenses/LICENSE-2.0.txt"
distribution = "https://www.apache.org/licenses/LICENSE-2.0.txt"
}
}
developers {
developer {
id = "openflocon"
name = "Open Flocon"
url = "https://github.com/openflocon"
}
}
scm {
url = "https://github.com/openflocon/Flocon"
connection = "scm:git:git://github.com/openflocon/Flocon.git"
developerConnection = "scm:git:ssh://git@github.com/openflocon/Flocon.git"
}
}
}
Empty file.
21 changes: 21 additions & 0 deletions FloconAndroid/datastores/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
3 changes: 3 additions & 0 deletions FloconAndroid/datastores/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package io.github.openflocon.flocon.preferences.datastores.model

import androidx.datastore.core.DataStore
import androidx.datastore.preferences.core.Preferences
import androidx.datastore.preferences.core.booleanPreferencesKey
import androidx.datastore.preferences.core.doublePreferencesKey
import androidx.datastore.preferences.core.edit
import androidx.datastore.preferences.core.floatPreferencesKey
import androidx.datastore.preferences.core.intPreferencesKey
import androidx.datastore.preferences.core.longPreferencesKey
import androidx.datastore.preferences.core.stringPreferencesKey
import io.github.openflocon.flocon.FloconLogger
import io.github.openflocon.flocon.plugins.sharedprefs.model.FloconPreference
import io.github.openflocon.flocon.plugins.sharedprefs.model.FloconPreferenceValue
import kotlinx.coroutines.flow.first

class FloconDatastorePreference(
override val name: String,
private val dataStore: DataStore<Preferences>,
) : FloconPreference {

override suspend fun set(
columnName: String,
value: FloconPreferenceValue
) {
try {
val data = dataStore.data.first().asMap()
val key = data.keys.find { it.name == columnName } ?: return

dataStore.edit {
try {
when (it[key]) {
is String -> it[stringPreferencesKey(columnName)] = value.stringValue!!
is Int -> it[intPreferencesKey(columnName)] = value.intValue!!
is Boolean -> it[booleanPreferencesKey(columnName)] = value.booleanValue!!
is Float -> it[floatPreferencesKey(columnName)] = value.floatValue!!
is Long -> it[longPreferencesKey(columnName)] = value.longValue!!
is Double -> it[doublePreferencesKey(columnName)] =
value.floatValue!!.toDouble()
}
} catch (t: Throwable) {
FloconLogger.logError("cannot update datastore preference", t)
}
}
} catch (t: Throwable) {
FloconLogger.logError(t.message ?: "cannot edit datastore preference columns", t)
}
}

override suspend fun columns(): List<String> {
return try {
dataStore.data.first().asMap().map { it.key.name }
} catch (t: Throwable) {
FloconLogger.logError(t.message ?: "cannot get datastore preference columns", t)
emptyList()
}
}

override suspend fun get(columnName: String): FloconPreferenceValue? {
return try {
val data = dataStore.data.first().asMap()
val key = data.keys.find { it.name == columnName } ?: return null
val value = data[key] ?: return null

return when (value) {
is String -> FloconPreferenceValue(stringValue = value)
is Int -> FloconPreferenceValue(intValue = value)
is Float -> FloconPreferenceValue(floatValue = value)
is Double -> FloconPreferenceValue(floatValue = value.toFloat())
is Boolean -> FloconPreferenceValue(booleanValue = value)
is Long -> FloconPreferenceValue(longValue = value)
else -> null
}
} catch (t: Throwable) {
FloconLogger.logError(t.message ?: "cannot get datastore preference value", t)
null
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ interface FloconPreference {
val name: String

suspend fun set(
rowName: String,
columnName: String,
value: FloconPreferenceValue,
)

Expand Down
2 changes: 1 addition & 1 deletion FloconAndroid/flocon-no-op/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ mavenPublishing {
)

pom {
name = "Flocon"
name = "Flocon No Op"
description = project.property("floconDescription") as String
inceptionYear = "2025"
url = "https://github.com/openflocon/Flocon"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.openflocon.flocon.sharedprefs
package io.github.openflocon.flocon.plugins.sharedprefs

import android.content.SharedPreferences
import io.github.openflocon.flocon.plugins.sharedprefs.model.FloconPreference
Expand All @@ -10,7 +10,7 @@ data class FloconSharedPreference(
) : FloconPreference {

override suspend fun set(
rowName: String,
columnName: String,
value: FloconPreferenceValue
) {
// no op
Expand Down
Loading