Skip to content

Commit

Permalink
Merge pull request #66 from babybuddy/new-timer-implementation
Browse files Browse the repository at this point in the history
New timer implementation
  • Loading branch information
MrApplejuice authored Sep 2, 2024
2 parents b08a0ec + bb9f6de commit 918a611
Show file tree
Hide file tree
Showing 86 changed files with 2,989 additions and 1,764 deletions.
28 changes: 17 additions & 11 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ android {
defaultConfig {
applicationId "eu.pkgsoftware.babybuddywidgets"
minSdkVersion 24
targetSdkVersion 33
versionCode 38
versionName "2.3.3"
targetSdk 34
versionCode 40
versionName "2.4.0b"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand All @@ -105,28 +105,34 @@ android {
namespace 'eu.pkgsoftware.babybuddywidgets'
}

ext.camerax_version = "1.3.1"
ext.camerax_version = "1.3.4"

dependencies {
implementation 'com.squareup.phrase:phrase:1.2.0'

// Retrofit and jackson need to be compatible. Maybe(?) the matching the major versions
// is enough, but I'm not sure. This version works.
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
implementation 'com.squareup.retrofit2:converter-jackson:2.9.0'

implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.11.0'
implementation 'com.fasterxml.jackson.core:jackson-core:2.10.1'
implementation 'com.fasterxml.jackson.core:jackson-annotations:2.10.1'
implementation 'com.fasterxml.jackson.module:jackson-module-kotlin:2.9.10'

implementation 'androidx.appcompat:appcompat:1.7.0'
implementation 'com.google.android.material:material:1.12.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.navigation:navigation-fragment-ktx:2.7.7'
implementation 'androidx.navigation:navigation-ui-ktx:2.7.7'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.concurrent:concurrent-futures:1.1.0'
implementation 'androidx.concurrent:concurrent-futures:1.2.0'

implementation "androidx.camera:camera-core:$camerax_version"
implementation "androidx.camera:camera-camera2:$camerax_version"
implementation "androidx.camera:camera-lifecycle:$camerax_version"
implementation "androidx.camera:camera-view:$camerax_version"

implementation 'androidx.core:core-ktx:1.12.0'
implementation 'androidx.core:core-ktx:1.13.1'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4"
Expand All @@ -136,9 +142,9 @@ dependencies {
testImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:1.6.4"
testImplementation 'org.json:json:20230618'

androidTestImplementation 'androidx.test:core-ktx:1.5.0'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
androidTestImplementation 'androidx.test:core-ktx:1.6.1'
androidTestImplementation 'androidx.test.ext:junit:1.2.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.6.1'
androidTestImplementation 'tools.fastlane:screengrab:2.1.1'

implementation project(':zxing-cpp')
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package eu.pkgsoftware.babybuddywidgets

import android.content.Context
import android.database.sqlite.SQLiteDatabase
import android.database.sqlite.SQLiteOpenHelper
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import eu.pkgsoftware.babybuddywidgets.debugging.GlobalDebugObject
import java.io.IOException

class ActivityDatabaseV1(context: Context) : SQLiteOpenHelper(
context, "store", null, 1
) {
override fun onCreate(db: SQLiteDatabase) {
db.execSQL("create table global_kv (key_name text primary key, value text)")
db.execSQL("create table login_kv (key_name text primary key, value text)")
db.execSQL("create table child_kv (child INTEGER, key_name text, value text, primary key (child, key_name))")
}

override fun onUpgrade(db: SQLiteDatabase?, oldVersion: Int, newVersion: Int) {
TODO("Not yet implemented")
}
}

class ActivityStore(context: Context) {
val openHelper = ActivityDatabaseV1(context)
val database = openHelper.writableDatabase
val jackOM = jacksonObjectMapper()

inline fun <reified K> genSet(table: String, value: K?, selectors: Map<String, String>) {
if (value == null) {
val query = "delete from $table where " + selectors.keys.joinToString(" and ") { "$it = ?" }
val args = selectors.values.toTypedArray()
database.execSQL(query, args)
} else {
val query = "insert or replace into $table (" +
selectors.keys.joinToString(", ") + ", value) values (" +
selectors.keys.joinToString(", ") { "?" } + ", ?)"
val valueString = jackOM.writeValueAsString(value)
database.execSQL(query, selectors.values.toTypedArray() + valueString)
}
}

inline fun <reified K> genGet(table: String, selectors: Map<String, String>): K? {
val query = "select value from $table where " + selectors.keys.joinToString(" and ") { "$it = ?" }
val cursor = database.rawQuery(query, selectors.values.toTypedArray())
var value = ""
try {
if (cursor.moveToNext()) {
value = cursor.getString(0)
cursor.close()
return jackOM.readValue(value, K::class.java)
}
}
catch (e: IOException) {
GlobalDebugObject.log("Failed to deserialize value from table $table: '$value'")
}
finally {
cursor.close()
}
return null
}

inline fun <reified K> globals(key: String): K? {
return genGet("global_kv", mapOf("key_name" to key))
}

inline fun <reified K> globals(key: String, value: K) {
genSet("global_kv", value, mapOf("key_name" to key))
}

inline fun <reified K> login(key: String): K? {
return genGet("login_kv", mapOf("key_name" to key))
}

inline fun <reified K> login(key: String, value: K) {
genSet("login_kv", value, mapOf("key_name" to key))
}

inline fun <reified K> child(child: Int, key: String): K? {
return genGet("child_kv", mapOf("child" to child.toString(), "key_name" to key))
}

inline fun <reified K> child(child: Int, key: String, value: K) {
genSet("child_kv", value, mapOf("child" to child.toString(), "key_name" to key))
}

fun close() {
database.close()
openHelper.close()
}

fun deleteAllData() {
database.delete("global_kv", "1", arrayOf())
database.delete("login_kv", "1", arrayOf())
database.delete("child_kv", "1", arrayOf())
}
}
Loading

0 comments on commit 918a611

Please sign in to comment.