diff --git a/core/android/.gitignore b/core/android/.gitignore new file mode 100644 index 0000000..42afabf --- /dev/null +++ b/core/android/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/core/android/build.gradle.kts b/core/android/build.gradle.kts new file mode 100644 index 0000000..aac484e --- /dev/null +++ b/core/android/build.gradle.kts @@ -0,0 +1,38 @@ +plugins { + alias(libs.plugins.android.library) + alias(libs.plugins.jetbrains.kotlin.android) +} + +android { + namespace = "com.github.yuriisurzhykov.purs.core.android" + compileSdk = ProjectProperties.compileSdkVersion + + defaultConfig { + minSdk = ProjectProperties.minSdkVersion + + testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" + consumerProguardFiles("consumer-rules.pro") + } + + buildTypes { + release { + isMinifyEnabled = false + proguardFiles( + getDefaultProguardFile("proguard-android-optimize.txt"), + "proguard-rules.pro" + ) + } + } + compileOptions { + sourceCompatibility = ProjectProperties.javaSourceCompatibility + targetCompatibility = ProjectProperties.javaTargetCompatibility + } + kotlinOptions { + jvmTarget = ProjectProperties.kotlinJvmTarget + } +} + +dependencies { + api(projects.core) + implementation(libs.androidx.core.ktx) +} \ No newline at end of file diff --git a/core/android/consumer-rules.pro b/core/android/consumer-rules.pro new file mode 100644 index 0000000..e69de29 diff --git a/core/android/proguard-rules.pro b/core/android/proguard-rules.pro new file mode 100644 index 0000000..481bb43 --- /dev/null +++ b/core/android/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 \ No newline at end of file diff --git a/core/android/src/main/kotlin/com/github/yuriisurzhykov/purs/core/android/AndroidLogger.kt b/core/android/src/main/kotlin/com/github/yuriisurzhykov/purs/core/android/AndroidLogger.kt new file mode 100644 index 0000000..510ba3c --- /dev/null +++ b/core/android/src/main/kotlin/com/github/yuriisurzhykov/purs/core/android/AndroidLogger.kt @@ -0,0 +1,14 @@ +package com.github.yuriisurzhykov.purs.core.android + +import android.util.Log +import com.github.yuriisurzhykov.purs.core.Logger + +fun AndroidLogcatLogger(): Logger = object : Logger { + override fun d(tag: String, message: String) { + Log.d(tag, message) + } + + override fun e(tag: String, message: String) { + Log.e(tag, message) + } +} \ No newline at end of file diff --git a/core/build.gradle.kts b/core/build.gradle.kts index fb5c45c..d8facf1 100644 --- a/core/build.gradle.kts +++ b/core/build.gradle.kts @@ -1,9 +1,12 @@ plugins { - id("java-library") alias(libs.plugins.jetbrains.kotlin.jvm) } java { sourceCompatibility = JavaVersion.VERSION_19 targetCompatibility = JavaVersion.VERSION_19 +} + +dependencies { + implementation(libs.kotlinx.coroutines.core) } \ No newline at end of file diff --git a/core/src/main/java/com/github/yuriisurzhykov/purs/core/Core.kt b/core/src/main/java/com/github/yuriisurzhykov/purs/core/Clear.kt similarity index 56% rename from core/src/main/java/com/github/yuriisurzhykov/purs/core/Core.kt rename to core/src/main/java/com/github/yuriisurzhykov/purs/core/Clear.kt index 5f13c71..7b2b212 100644 --- a/core/src/main/java/com/github/yuriisurzhykov/purs/core/Core.kt +++ b/core/src/main/java/com/github/yuriisurzhykov/purs/core/Clear.kt @@ -1,4 +1,6 @@ package com.github.yuriisurzhykov.purs.core -class Core { +interface Clear { + + fun clear() } \ No newline at end of file diff --git a/core/src/main/java/com/github/yuriisurzhykov/purs/core/Dispatchers.kt b/core/src/main/java/com/github/yuriisurzhykov/purs/core/Dispatchers.kt new file mode 100644 index 0000000..3c9aadf --- /dev/null +++ b/core/src/main/java/com/github/yuriisurzhykov/purs/core/Dispatchers.kt @@ -0,0 +1,37 @@ +package com.github.yuriisurzhykov.purs.core + +import kotlinx.coroutines.CoroutineDispatcher +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Job +import kotlinx.coroutines.launch +import kotlinx.coroutines.withContext + +interface Dispatchers { + + fun launchUi(scope: CoroutineScope, block: suspend CoroutineScope.() -> Unit): Job + fun launchBackground(scope: CoroutineScope, block: suspend CoroutineScope.() -> Unit): Job + suspend fun switchToUi(block: suspend CoroutineScope.() -> Unit) + + abstract class Abstract( + private val uiScope: CoroutineDispatcher, + private val backgroundScope: CoroutineDispatcher + ) : Dispatchers { + override fun launchUi( + scope: CoroutineScope, + block: suspend CoroutineScope.() -> Unit + ): Job = scope.launch(uiScope, block = block) + + override fun launchBackground( + scope: CoroutineScope, + block: suspend CoroutineScope.() -> Unit + ): Job = scope.launch(backgroundScope, block = block) + + override suspend fun switchToUi(block: suspend CoroutineScope.() -> Unit) = + withContext(uiScope, block) + } + + class Base : Abstract( + uiScope = kotlinx.coroutines.Dispatchers.Main, + backgroundScope = kotlinx.coroutines.Dispatchers.Default + ) +} diff --git a/core/src/main/java/com/github/yuriisurzhykov/purs/core/Logger.kt b/core/src/main/java/com/github/yuriisurzhykov/purs/core/Logger.kt new file mode 100644 index 0000000..7d2ec59 --- /dev/null +++ b/core/src/main/java/com/github/yuriisurzhykov/purs/core/Logger.kt @@ -0,0 +1,7 @@ +package com.github.yuriisurzhykov.purs.core + +interface Logger { + fun d(tag: String, message: String) + + fun e(tag: String, message: String) +} \ No newline at end of file diff --git a/core/src/main/java/com/github/yuriisurzhykov/purs/core/Mapper.kt b/core/src/main/java/com/github/yuriisurzhykov/purs/core/Mapper.kt new file mode 100644 index 0000000..ab528ce --- /dev/null +++ b/core/src/main/java/com/github/yuriisurzhykov/purs/core/Mapper.kt @@ -0,0 +1,8 @@ +package com.github.yuriisurzhykov.purs.core + +interface Mapper { + + fun map(source: S): R + + interface Unit : Mapper> +} \ No newline at end of file diff --git a/core/src/main/java/com/github/yuriisurzhykov/purs/core/Read.kt b/core/src/main/java/com/github/yuriisurzhykov/purs/core/Read.kt new file mode 100644 index 0000000..003c91c --- /dev/null +++ b/core/src/main/java/com/github/yuriisurzhykov/purs/core/Read.kt @@ -0,0 +1,6 @@ +package com.github.yuriisurzhykov.purs.core + +interface Read { + + fun read(): T +} \ No newline at end of file diff --git a/core/src/main/java/com/github/yuriisurzhykov/purs/core/Save.kt b/core/src/main/java/com/github/yuriisurzhykov/purs/core/Save.kt new file mode 100644 index 0000000..d541e47 --- /dev/null +++ b/core/src/main/java/com/github/yuriisurzhykov/purs/core/Save.kt @@ -0,0 +1,6 @@ +package com.github.yuriisurzhykov.purs.core + +interface Save { + + fun save(data: T) +} \ No newline at end of file diff --git a/settings.gradle.kts b/settings.gradle.kts index 4c347e2..2796614 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -24,6 +24,7 @@ dependencyResolutionManagement { rootProject.name = "Purs-Android" include(":app") include(":core") +include(":core:android") include(":data:cloud") include(":data:cache") include(":data:repository")