2 Commits 57f2b8b988 ... 6c7b380e04

Auteur SHA1 Bericht Datum
  yayan 6c7b380e04 feat: module data 1 maand geleden
  yayan 02c900e0b3 feat: room 1 maand geleden

+ 3 - 0
.idea/deploymentTargetSelector.xml

@@ -5,6 +5,9 @@
       <SelectionState runConfigName="app">
         <option name="selectionMode" value="DROPDOWN" />
       </SelectionState>
+      <SelectionState runConfigName="data">
+        <option name="selectionMode" value="DROPDOWN" />
+      </SelectionState>
     </selectionStates>
   </component>
 </project>

+ 1 - 0
.idea/gradle.xml

@@ -11,6 +11,7 @@
           <set>
             <option value="$PROJECT_DIR$" />
             <option value="$PROJECT_DIR$/app" />
+            <option value="$PROJECT_DIR$/data" />
           </set>
         </option>
       </GradleProjectSettings>

+ 6 - 0
.idea/vcs.xml

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="VcsDirectoryMappings">
+    <mapping directory="$PROJECT_DIR$" vcs="Git" />
+  </component>
+</project>

+ 7 - 0
app/build.gradle.kts

@@ -2,6 +2,7 @@ plugins {
     alias(libs.plugins.android.application)
     alias(libs.plugins.kotlin.android)
     alias(libs.plugins.hilt.android)
+    alias(libs.plugins.devtools.ksp)
     kotlin("kapt")
 }
 
@@ -41,6 +42,12 @@ android {
 }
 
 dependencies {
+    implementation(libs.androidx.room.runtime)
+    ksp(libs.androidx.room.compiler)
+    implementation(libs.android.database.sqlcipher)
+    implementation(libs.androidx.sqlite.framework)
+    implementation(libs.androidx.sqlite)
+    implementation(libs.androidx.room.ktx)
 
     implementation(libs.androidx.core.ktx)
     implementation(libs.androidx.appcompat)

+ 2 - 0
build.gradle.kts

@@ -3,4 +3,6 @@ plugins {
     alias(libs.plugins.android.application) apply false
     alias(libs.plugins.kotlin.android) apply false
     alias(libs.plugins.hilt.android) apply false
+    alias(libs.plugins.devtools.ksp) apply false
+    alias(libs.plugins.android.library) apply false
 }

+ 1 - 0
data/.gitignore

@@ -0,0 +1 @@
+/build

+ 57 - 0
data/build.gradle.kts

@@ -0,0 +1,57 @@
+plugins {
+    alias(libs.plugins.android.library)
+    alias(libs.plugins.kotlin.android)
+    alias(libs.plugins.hilt.android)
+    alias(libs.plugins.devtools.ksp)
+    kotlin("kapt")
+}
+
+android {
+    namespace = "io.nexilis.data"
+    compileSdk {
+        version = release(36)
+    }
+
+    defaultConfig {
+        minSdk = 26
+
+        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(libs.androidx.core.ktx)
+    implementation(libs.androidx.appcompat)
+    implementation(libs.material)
+
+    implementation(libs.androidx.room.runtime)
+    ksp(libs.androidx.room.compiler)
+    implementation(libs.android.database.sqlcipher)
+    implementation(libs.androidx.sqlite.framework)
+    implementation(libs.androidx.sqlite)
+    implementation(libs.androidx.room.ktx)
+
+    implementation(libs.hilt.android)
+    kapt(libs.hilt.compiler)
+    testImplementation(libs.junit)
+    androidTestImplementation(libs.androidx.junit)
+    androidTestImplementation(libs.androidx.espresso.core)
+}

+ 0 - 0
data/consumer-rules.pro


+ 21 - 0
data/proguard-rules.pro

@@ -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

+ 24 - 0
data/src/androidTest/java/io/nexilis/data/ExampleInstrumentedTest.kt

@@ -0,0 +1,24 @@
+package io.nexilis.data
+
+import androidx.test.platform.app.InstrumentationRegistry
+import androidx.test.ext.junit.runners.AndroidJUnit4
+
+import org.junit.Test
+import org.junit.runner.RunWith
+
+import org.junit.Assert.*
+
+/**
+ * Instrumented test, which will execute on an Android device.
+ *
+ * See [testing documentation](http://d.android.com/tools/testing).
+ */
+@RunWith(AndroidJUnit4::class)
+class ExampleInstrumentedTest {
+    @Test
+    fun useAppContext() {
+        // Context of the app under test.
+        val appContext = InstrumentationRegistry.getInstrumentation().targetContext
+        assertEquals("io.nexilis.data.test", appContext.packageName)
+    }
+}

+ 4 - 0
data/src/main/AndroidManifest.xml

@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android">
+
+</manifest>

+ 7 - 0
data/src/main/java/io/nexilis/data/db/Database.kt

@@ -0,0 +1,7 @@
+package io.nexilis.data.db
+
+import androidx.room.RoomDatabase
+
+abstract class Database : RoomDatabase() {
+
+}

+ 43 - 0
data/src/main/java/io/nexilis/data/db/DatabaseModule.kt

@@ -0,0 +1,43 @@
+package io.nexilis.data.db
+
+import android.content.Context
+import android.content.SharedPreferences
+import androidx.room.Room
+import dagger.Module
+import dagger.Provides
+import dagger.hilt.InstallIn
+import dagger.hilt.android.qualifiers.ApplicationContext
+import dagger.hilt.components.SingletonComponent
+import net.zetetic.database.sqlcipher.SupportOpenHelperFactory
+import java.nio.charset.StandardCharsets
+import javax.inject.Singleton
+
+@Module
+@InstallIn(SingletonComponent::class)
+object DatabaseModule {
+
+    @Provides
+    @Singleton
+    fun provideDatabase(@ApplicationContext context: Context): Database {
+        val factory = SupportOpenHelperFactory(
+            "password".toByteArray(StandardCharsets.UTF_8)
+        )
+        System.loadLibrary("sqlcipher")
+        return Room.databaseBuilder(
+            context,
+            Database::class.java,
+            "secure-db"
+        )
+            .openHelperFactory(factory)
+            .build()
+    }
+
+    @Provides
+    fun provideSharedPref(@ApplicationContext context: Context) : SharedPreferences {
+        return context.getSharedPreferences(
+            "shared-pref",
+            Context.MODE_PRIVATE
+        )
+    }
+
+}

+ 32 - 0
data/src/main/java/io/nexilis/data/db/Message.kt

@@ -0,0 +1,32 @@
+package io.nexilis.data.db
+
+import androidx.room.Dao
+import androidx.room.Entity
+import androidx.room.Insert
+import androidx.room.PrimaryKey
+import androidx.room.Query
+import androidx.room.Update
+import kotlinx.coroutines.flow.Flow
+
+@Entity
+internal data class Message(
+    @PrimaryKey val id: String,
+    val name: String
+)
+
+@Dao
+internal interface MessageDao {
+
+    @Insert
+    suspend fun insert(message: Message)
+
+    @Update
+    suspend fun delete(message: Message)
+
+    @Query("SELECT * FROM Message WHERE id = :id")
+    suspend fun getById(id: String): Flow<Message?>
+
+    @Query("SELECT * FROM Message")
+    suspend fun getAll(): Flow<List<Message>>
+
+}

+ 17 - 0
data/src/test/java/io/nexilis/data/ExampleUnitTest.kt

@@ -0,0 +1,17 @@
+package io.nexilis.data
+
+import org.junit.Test
+
+import org.junit.Assert.*
+
+/**
+ * Example local unit test, which will execute on the development machine (host).
+ *
+ * See [testing documentation](http://d.android.com/tools/testing).
+ */
+class ExampleUnitTest {
+    @Test
+    fun addition_isCorrect() {
+        assertEquals(4, 2 + 2)
+    }
+}

+ 13 - 1
gradle/libs.versions.toml

@@ -1,9 +1,10 @@
 [versions]
 agp = "8.13.0"
+androidDatabaseSqlcipher = "4.11.0"
 coreSplashscreen = "1.0.1"
 datastorePreferences = "1.1.7"
 hiltAndroid = "2.57.2"
-kotlin = "2.0.21"
+kotlin = "2.2.10"
 coreKtx = "1.17.0"
 junit = "4.13.2"
 junitVersion = "1.3.0"
@@ -15,11 +16,20 @@ lifecycleLivedataKtx = "2.9.4"
 lifecycleViewmodelKtx = "2.9.4"
 navigationFragmentKtx = "2.9.5"
 navigationUiKtx = "2.9.5"
+roomVersion = "2.8.2"
+sqliteFramework = "2.6.1"
+ksp = "2.2.10-2.0.2"
 
 [libraries]
+android-database-sqlcipher = { module = "net.zetetic:sqlcipher-android", version.ref = "androidDatabaseSqlcipher" }
 androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
 androidx-core-splashscreen = { module = "androidx.core:core-splashscreen", version.ref = "coreSplashscreen" }
 androidx-datastore-preferences = { module = "androidx.datastore:datastore-preferences", version.ref = "datastorePreferences" }
+androidx-room-compiler = { module = "androidx.room:room-compiler", version.ref = "roomVersion" }
+androidx-room-ktx = { module = "androidx.room:room-ktx", version.ref = "roomVersion" }
+androidx-room-runtime = { module = "androidx.room:room-runtime", version.ref = "roomVersion" }
+androidx-sqlite = { module = "androidx.sqlite:sqlite", version.ref = "sqliteFramework" }
+androidx-sqlite-framework = { module = "androidx.sqlite:sqlite-framework", version.ref = "sqliteFramework" }
 hilt-android = { module = "com.google.dagger:hilt-android", version.ref = "hiltAndroid" }
 hilt-compiler = { module = "com.google.dagger:hilt-compiler", version.ref = "hiltAndroid" }
 junit = { group = "junit", name = "junit", version.ref = "junit" }
@@ -37,4 +47,6 @@ androidx-navigation-ui-ktx = { group = "androidx.navigation", name = "navigation
 android-application = { id = "com.android.application", version.ref = "agp" }
 kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
 hilt-android = { id = "com.google.dagger.hilt.android", version.ref = "hiltAndroid" }
+devtools-ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" }
+android-library = { id = "com.android.library", version.ref = "agp" }
 

+ 1 - 1
settings.gradle.kts

@@ -21,4 +21,4 @@ dependencyResolutionManagement {
 
 rootProject.name = "SecureComsNative"
 include(":app")
- 
+include(":data")