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
99 changes: 99 additions & 0 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -364,3 +364,102 @@ dependencies {
implementation("io.github.kdroidfilter.database:localization:<version>")
}
```

### Downloader Module

The downloader module provides functionality to download the latest store and policies databases from GitHub releases. It includes methods to download databases for multiple languages.

```kotlin
dependencies {
implementation("io.github.kdroidfilter.database.downloader:core:<version>")
}
```

#### Usage Example

```kotlin
// Create a DatabaseDownloader instance
val databaseDownloader = DatabaseDownloader()

// Download store databases for all languages (en, fr, he)
val outputDir = "path/to/output/directory"
val storeResults = databaseDownloader.downloadLatestStoreDatabases(outputDir)

// Check download results
storeResults.forEach { (language, success) ->
if (success) {
println("Successfully downloaded store database for $language")
} else {
println("Failed to download store database for $language")
}
}

// Download policies database
val policiesResult = databaseDownloader.downloadLatestPoliciesDatabase(outputDir)
if (policiesResult) {
println("Successfully downloaded policies database")
} else {
println("Failed to download policies database")
}
```

### DAO Module

The DAO (Data Access Object) module provides a clean interface for database operations, abstracting away direct SQL queries. It includes DAOs for accessing application data and version information, as well as utility classes for working with the data.

```kotlin
dependencies {
implementation("io.github.kdroidfilter.database.dao:core:<version>")
}
```

#### Key Components

- **ApplicationsDao**: Provides methods for loading and searching applications in the database
- **VersionDao**: Handles database version management operations
- **AppInfoWithExtras**: A data class that extends the GooglePlayApplicationInfo model with additional information

#### Usage Example

```kotlin
// Load applications from the database
val applications = ApplicationsDao.loadApplicationsFromDatabase(
database = database,
deviceLanguage = "en",
creator = { id, categoryLocalizedName, appInfo ->
AppInfoWithExtras(
id = id,
categoryLocalizedName = categoryLocalizedName,
app = appInfo
)
}
)

// Search for applications in the database
val searchResults = ApplicationsDao.searchApplicationsInDatabase(
database = database,
query = "calculator",
deviceLanguage = "en",
creator = { id, categoryLocalizedName, appInfo ->
AppInfoWithExtras(
id = id,
categoryLocalizedName = categoryLocalizedName,
app = appInfo
)
}
)

// Get the current database version
val currentVersion = VersionDao.getCurrentVersion(database)

// Update the database version
val updateSuccess = VersionDao.updateVersion(database, "NEWVERSION")
```

#### Note on Sample Code

For a simplified overview of how to use the database, please consult the example in the `sample` directory. The sample demonstrates basic database operations including downloading, querying, and displaying data.

> ⚠️ **Important Warning**: The sample code uses `runBlocking` for database downloads, which is **prohibited** in production code. This is only done for demonstration purposes. In real applications, always use proper coroutine scopes and avoid blocking the main thread.

The DAO module is actively evolving to satisfy more needs and use cases. Contributions and pull requests are welcome to enhance its functionality and performance.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ object ApplicationsDao {
score = app.score ?: 0.0,
ratings = app.ratings ?: 0L,
reviews = app.reviews ?: 0L,
histogram = app.histogram?.removeSurrounding("[", "]")?.split(", ")?.map { it.toLongOrNull() ?: 0L } ?: emptyList(),
histogram = app.histogram?.removeSurrounding("[", "]")?.split(", ")?.map {
it.toLongOrNull() ?: 0L
} ?: emptyList(),
price = app.price ?: 0.0,
free = app.free == 1L,
currency = app.currency ?: "",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package io.github.kdroidfilter.database.dao

import co.touchlab.kermit.Logger
import io.github.kdroidfilter.database.store.Database

/**
* Data Access Object for Version
* Contains functions for database operations related to version information
*/
object VersionDao {
private val logger = Logger.withTag("VersionDao")

/**
* Gets the current version from the database
* @param database The database instance
* @return The version string or null if no version is found
*/
fun getCurrentVersion(database: Database): String? {
try {
val versionQueries = database.versionQueries
val version = versionQueries.getVersion().executeAsOneOrNull()
return version?.release_name
} catch (e: Exception) {
logger.e(e) { "Failed to get current version: ${e.message}" }
return null
}
}

/**
* Updates the version in the database
* @param database The database instance
* @param versionName The new version name
* @return Boolean indicating whether the update was successful
*/
fun updateVersion(database: Database, versionName: String): Boolean {
return try {
val versionQueries = database.versionQueries

// Clear existing versions
versionQueries.clearVersions()

// Insert new version
versionQueries.insertVersion(versionName)

logger.i { "Version updated to $versionName" }
true
} catch (e: Exception) {
logger.e(e) { "Failed to update version: ${e.message}" }
false
}
}
}
108 changes: 108 additions & 0 deletions downloader/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
import com.vanniktech.maven.publish.SonatypeHost

plugins {
alias(libs.plugins.multiplatform)
alias(libs.plugins.android.library)
alias(libs.plugins.vannitktech.maven.publish)
}

val ref = System.getenv("GITHUB_REF") ?: ""
version = if (ref.startsWith("refs/tags/")) {
val tag = ref.removePrefix("refs/tags/")
if (tag.startsWith("v")) tag.substring(1) else tag
} else "dev"


kotlin {
jvmToolchain(17)
androidTarget { publishLibraryVariants("release") }
jvm()


sourceSets {

androidMain.dependencies {
implementation(libs.kotlinx.coroutines.android)
}

jvmMain.dependencies {
implementation(libs.maven.slf4j.provider)
implementation(libs.kotlinx.coroutines.swing)
}

jvmTest.dependencies {
implementation(kotlin("test"))
implementation(libs.kotlinx.coroutines.test)

}

commonMain.dependencies {
api(project(":core"))
api(libs.gplay.scrapper)
implementation(libs.kotlinx.coroutines.core)
implementation(libs.kermit)
implementation(libs.platform.tools.release.fetcher)
}

}

//https://kotlinlang.org/docs/native-objc-interop.html#export-of-kdoc-comments-to-generated-objective-c-headers
targets.withType<org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget> {
compilations["main"].compileTaskProvider.configure {
compilerOptions {
freeCompilerArgs.add("-Xexport-kdoc")
}
}
}

}

android {
namespace = "io.github.kdroidfilter.database.downloader"
compileSdk = 35

defaultConfig {
minSdk = 24
}
}


mavenPublishing {
coordinates(
groupId = "io.github.kdroidfilter.database.downloader",
artifactId = "core",
version = version.toString()
)

pom {
name.set("KDroid Database Downloader")
description.set("Downloader of the Kdroid Database")
inceptionYear.set("2025")
url.set("https://github.com/kdroidFilter/KDroidDatabase")

licenses {
license {
name.set("MIT License")
url.set("https://opensource.org/licenses/MIT")
}
}

developers {
developer {
id.set("kdroidfilter")
name.set("Elie Gambache")
email.set("elyahou.hadass@gmail.com")
}
}

scm {
connection.set("scm:git:git://github.com/kdroidFilter/KDroidDatabase.git")
developerConnection.set("scm:git:ssh://git@github.com/kdroidFilter/KDroidDatabase.git")
url.set("https://github.com/kdroidFilter/KDroidDatabase")
}
}

publishToMavenCentral(SonatypeHost.CENTRAL_PORTAL)

signAllPublications()
}
Loading