Skip to content

Commit

Permalink
19 write all interfaces and classes for the core module (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuriisurzhykov authored May 24, 2024
2 parents 96dd7da + 481dbc0 commit def06bb
Show file tree
Hide file tree
Showing 13 changed files with 146 additions and 2 deletions.
1 change: 1 addition & 0 deletions core/android/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
38 changes: 38 additions & 0 deletions core/android/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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)
}
Empty file added core/android/consumer-rules.pro
Empty file.
21 changes: 21 additions & 0 deletions core/android/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
Original file line number Diff line number Diff line change
@@ -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)
}
}
5 changes: 4 additions & 1 deletion core/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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)
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
package com.github.yuriisurzhykov.purs.core

class Core {
interface Clear {

fun clear()
}
Original file line number Diff line number Diff line change
@@ -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
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.github.yuriisurzhykov.purs.core

interface Logger {
fun d(tag: String, message: String)

fun e(tag: String, message: String)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.github.yuriisurzhykov.purs.core

interface Mapper<S, R> {

fun map(source: S): R

interface Unit<T> : Mapper<T, Unit<T>>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.github.yuriisurzhykov.purs.core

interface Read<T> {

fun read(): T
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.github.yuriisurzhykov.purs.core

interface Save<T> {

fun save(data: T)
}
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit def06bb

Please sign in to comment.