diff --git a/.idea/.name b/.idea/.name index 15cd3c2..8bd1e9e 100644 --- a/.idea/.name +++ b/.idea/.name @@ -1 +1 @@ -multiplatform-log \ No newline at end of file +multiplatform-livedata \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 7631aec..84da703 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,6 +1,6 @@ - + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml index 4d5aa81..7660df8 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -2,9 +2,9 @@ - - - + + + \ No newline at end of file diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 0000000..e96534f --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/build.gradle b/build.gradle index 7d4e274..8455e2f 100644 --- a/build.gradle +++ b/build.gradle @@ -54,6 +54,7 @@ allprojects { } apply plugin: 'maven' + apply plugin: 'idea' apply plugin: 'maven-publish' apply plugin: 'com.jfrog.bintray' @@ -148,7 +149,7 @@ configure(allprojects) { version project.version if (project.name.endsWith('android')) { - artifact("$buildDir/outputs/aar/multiplatform-log-android-debug.aar") + artifact("$buildDir/outputs/aar/$project.name-debug.aar") } artifact sourceJar diff --git a/gradle.properties b/gradle.properties index 02ba8eb..35ad405 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,6 +1,13 @@ group=com.github.florent37 -version=1.0.0 +version=0.0.2 +github_repo="Multiplatform-LiveData" +github_description="Multiplatform LiveData" +bintray_repo="maven" +bintray_name="multiplatform-livedata" kotlin_version=1.3.0 gradle_android_version = 3.2.1 kotlin_native_version=1.3.0 bintray_plugin_version=1.8.2-SNAPSHOT + +android.useAndroidX=true +android.enableJetifier=true \ No newline at end of file diff --git a/gradle/bintray.gradle b/gradle/bintray.gradle index e20f591..842d51d 100644 --- a/gradle/bintray.gradle +++ b/gradle/bintray.gradle @@ -6,9 +6,11 @@ bintray { override = true pkg { + publish = true + userOrg = 'florent37' repo = 'maven' - name = 'multiplatform-log' + name = "multiplatform-livedata" licenses = ['Apache-2.0'] publications = ['mavenProject'] diff --git a/gradle/publish.gradle b/gradle/publish.gradle index 436c7b3..bf60b57 100644 --- a/gradle/publish.gradle +++ b/gradle/publish.gradle @@ -1,7 +1,7 @@ publishing { repositories { maven { - url = 'https://dl.bintray.com/florent37/maven' + url = "https://dl.bintray.com/florent37/$bintray_repo" } } } diff --git a/multiplatform-log-android/.gitignore b/multiplatform-log-android/.gitignore deleted file mode 100644 index fc06611..0000000 --- a/multiplatform-log-android/.gitignore +++ /dev/null @@ -1,44 +0,0 @@ -# Built application files -*.apk -*.ap_ -*.aab - -# Files for the ART/Dalvik VM -*.dex - -# Java class files -*.class - -# Generated files -bin/ -gen/ -out/ - -# Gradle files -.gradle/ -build/ - -# Local configuration file (sdk path, etc) -local.properties - -# Proguard folder generated by Eclipse -proguard/ - -# Log Files -*.log - -# Android Studio Navigation editor temp files -.navigation/ - -# Android Studio captures folder -captures/ - -# IntelliJ -*.iml -.idea/workspace.xml -.idea/tasks.xml -.idea/gradle.xml -.idea/assetWizardSettings.xml -.idea/dictionaries -.idea/libraries -.idea/caches \ No newline at end of file diff --git a/multiplatform-log-android/build.gradle b/multiplatform-log-android/build.gradle deleted file mode 100644 index 4d8d973..0000000 --- a/multiplatform-log-android/build.gradle +++ /dev/null @@ -1,14 +0,0 @@ -apply plugin: 'com.android.library' -apply plugin: 'kotlin-platform-android' - -android { - compileSdkVersion 28 - defaultConfig { - minSdkVersion 15 - } -} - -dependencies { - expectedBy project(":") - implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" -} diff --git a/multiplatform-log-android/src/main/AndroidManifest.xml b/multiplatform-log-android/src/main/AndroidManifest.xml deleted file mode 100644 index 1430eef..0000000 --- a/multiplatform-log-android/src/main/AndroidManifest.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - diff --git a/multiplatform-log-android/src/main/java/com.github.florent37/log/Logger.kt b/multiplatform-log-android/src/main/java/com.github.florent37/log/Logger.kt deleted file mode 100644 index 012bac3..0000000 --- a/multiplatform-log-android/src/main/java/com.github.florent37/log/Logger.kt +++ /dev/null @@ -1,23 +0,0 @@ -package com.github.florent37.log - -import android.util.Log - -actual class PlatformLogger { - actual var enabled : Boolean = true - - actual fun logDebug(tag: String, message: String){ - if(enabled) { - Log.d(tag, message) - } - } - actual fun logError(tag: String, message: String){ - if(enabled) { - Log.e(tag, message) - } - } - actual fun logError(tag: String, message: String, exception: Throwable){ - if(enabled) { - Log.e(tag, message, exception) - } - } -} \ No newline at end of file diff --git a/multiplatform-log-ios/.gitignore b/multiplatform-log-ios/.gitignore deleted file mode 100644 index fc06611..0000000 --- a/multiplatform-log-ios/.gitignore +++ /dev/null @@ -1,44 +0,0 @@ -# Built application files -*.apk -*.ap_ -*.aab - -# Files for the ART/Dalvik VM -*.dex - -# Java class files -*.class - -# Generated files -bin/ -gen/ -out/ - -# Gradle files -.gradle/ -build/ - -# Local configuration file (sdk path, etc) -local.properties - -# Proguard folder generated by Eclipse -proguard/ - -# Log Files -*.log - -# Android Studio Navigation editor temp files -.navigation/ - -# Android Studio captures folder -captures/ - -# IntelliJ -*.iml -.idea/workspace.xml -.idea/tasks.xml -.idea/gradle.xml -.idea/assetWizardSettings.xml -.idea/dictionaries -.idea/libraries -.idea/caches \ No newline at end of file diff --git a/multiplatform-log-ios/build.gradle b/multiplatform-log-ios/build.gradle deleted file mode 100644 index 1dad77b..0000000 --- a/multiplatform-log-ios/build.gradle +++ /dev/null @@ -1,14 +0,0 @@ -dependencies { - expectedBy rootProject -} - -apply from: rootProject.file('gradle/bintray.gradle') -apply from: rootProject.file('gradle/publish.gradle') - -if (project.hasProperty("teamcity")) { - afterEvaluate { - tasks.withType(Class.forName("org.gradle.nativeplatform.test.tasks.RunTestExecutable_Decorated")) { - args '--ktest_logger=TEAMCITY' - } - } -} diff --git a/multiplatform-log-ios/src/main/kotlin/com/github/florent37/log/Logger.kt b/multiplatform-log-ios/src/main/kotlin/com/github/florent37/log/Logger.kt deleted file mode 100644 index c6969e6..0000000 --- a/multiplatform-log-ios/src/main/kotlin/com/github/florent37/log/Logger.kt +++ /dev/null @@ -1,22 +0,0 @@ -package com.github.florent37.log - -actual class PlatformLogger { - actual var enabled = true - - actual fun logDebug(tag: String, message: String){ - if(enabled) { - print("${tag} : ${message}") - } - } - actual fun logError(tag: String, message: String){ - if(enabled) { - println("${tag} : ${message}") - } - } - actual fun logError(tag: String, message: String, exception: Throwable){ - if(enabled) { - println("${tag} : ${message}") - println(exception) - } - } -} \ No newline at end of file diff --git a/pom.gradle b/pom.gradle index 6eff305..f5e2a36 100644 --- a/pom.gradle +++ b/pom.gradle @@ -16,7 +16,7 @@ def pomConfig = { } scm { - url "https://github.com/florent37/Multiplatform-Log" + url "https://github.com/florent37/Multiplatform-LiveData" } } @@ -24,8 +24,8 @@ def withPom = { pom -> pom.withXml { def root = asNode() root.appendNode('name', project.name) - root.appendNode('description', 'Multiplatform Log') - root.appendNode('url', 'https://github.com/florent37/Multiplatform-Log') + root.appendNode('description', github_description) + root.appendNode('url', "https://github.com/florent37/Multiplatform_Livedata") root.children().last() + pomConfig } } diff --git a/sample/app/build.gradle b/sample/app/build.gradle index bbda319..4aad679 100644 --- a/sample/app/build.gradle +++ b/sample/app/build.gradle @@ -28,9 +28,12 @@ android { dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) - implementation 'com.android.support:appcompat-v7:28.0.0' implementation 'com.android.support.constraint:constraint-layout:1.1.3' androidTestImplementation 'com.android.support.test:runner:1.0.2' + + implementation "androidx.appcompat:appcompat:1.0.0" + implementation "androidx.lifecycle:lifecycle-livedata:2.0.0" + implementation "androidx.constraintlayout:constraintlayout:1.1.2" } kotlin { @@ -47,6 +50,7 @@ kotlin { dependencies { implementation 'org.jetbrains.kotlin:kotlin-stdlib-common' implementation "com.github.florent37:multiplatform-log:1.0.0" + implementation "com.github.florent37:multiplatform-livedata:0.0.1" } } commonTest { @@ -59,6 +63,7 @@ kotlin { dependencies { implementation 'org.jetbrains.kotlin:kotlin-stdlib' implementation "com.github.florent37:multiplatform-log-android:1.0.0" + implementation "com.github.florent37:multiplatform-livedata-android:0.0.1" } } androidTest { @@ -70,6 +75,7 @@ kotlin { iosMain { dependencies { implementation "com.github.florent37:multiplatform-log-ios:1.0.0" + implementation "com.github.florent37:multiplatform-livedata-ios:0.0.1" } } iosTest { diff --git a/sample/app/src/commonMain/kotlin/sample/MainPresenter.kt b/sample/app/src/commonMain/kotlin/sample/MainPresenter.kt index 1577c65..6af107f 100644 --- a/sample/app/src/commonMain/kotlin/sample/MainPresenter.kt +++ b/sample/app/src/commonMain/kotlin/sample/MainPresenter.kt @@ -1,28 +1,36 @@ package sample +import com.github.florent37.livedata.KLiveData +import com.github.florent37.livedata.KMediatorLiveData import com.github.florent37.log.Logger -interface MainView { -} +class ViewState( + val userStatus: String +) -class MainPresenter { +class MainPresenter(val premiumManager: PremiumManager) { private val tag = "ErrorTag" - private var view: MainView? = null - - fun bind(view: MainView){ - this.view = view - } - - fun unbind(){ - this.view = null + private val viewState = KMediatorLiveData() + + init { + viewState.value = ViewState("not premium") + + viewState.addSource(premiumManager.premium()) { + Logger.d(tag, "add source called") + if(it) { + viewState.value = ViewState("premium") + } else { + viewState.value = ViewState("not premium") + } + } } - fun displayLogError(){ - Logger.e(tag, "my error message") + fun viewState() : KLiveData { + return viewState } - fun displayLogDebug(){ - Logger.e(tag, "my debug message") + fun becomePremium() { + premiumManager.becomePremium() } } \ No newline at end of file diff --git a/sample/app/src/commonMain/kotlin/sample/PremiumManager.kt b/sample/app/src/commonMain/kotlin/sample/PremiumManager.kt new file mode 100644 index 0000000..1a9822b --- /dev/null +++ b/sample/app/src/commonMain/kotlin/sample/PremiumManager.kt @@ -0,0 +1,20 @@ +package sample + +import com.github.florent37.livedata.KLiveData +import com.github.florent37.livedata.KMutableLiveData + +class PremiumManager { + private val premium = KMutableLiveData() + fun premium() : KLiveData { + return premium + } + + fun becomePremium() { + premium.value = true + } + + init { + //default value + premium.value = false + } +} \ No newline at end of file diff --git a/sample/app/src/commonMain/kotlin/sample/Sample.kt b/sample/app/src/commonMain/kotlin/sample/Sample.kt deleted file mode 100644 index 4079b78..0000000 --- a/sample/app/src/commonMain/kotlin/sample/Sample.kt +++ /dev/null @@ -1 +0,0 @@ -package sample diff --git a/sample/app/src/main/AndroidManifest.xml b/sample/app/src/main/AndroidManifest.xml index 2ef0dbe..5a9c360 100644 --- a/sample/app/src/main/AndroidManifest.xml +++ b/sample/app/src/main/AndroidManifest.xml @@ -6,6 +6,7 @@ android:allowBackup="true" android:label="@string/app_name" android:supportsRtl="true" + android:name=".MainApplication" android:theme="@style/AppTheme"> diff --git a/sample/app/src/main/java/sample/DependencyManager.kt b/sample/app/src/main/java/sample/DependencyManager.kt new file mode 100644 index 0000000..387590d --- /dev/null +++ b/sample/app/src/main/java/sample/DependencyManager.kt @@ -0,0 +1,9 @@ +package sample + +class DependencyManager(val application: MainApplication) { + + val premiumManager by lazy { PremiumManager() } + + val mainViewmodel by lazy { MainPresenter(dependencies.premiumManager) } + +} diff --git a/sample/app/src/main/java/sample/MainActivity.kt b/sample/app/src/main/java/sample/MainActivity.kt index dd31880..fa68405 100644 --- a/sample/app/src/main/java/sample/MainActivity.kt +++ b/sample/app/src/main/java/sample/MainActivity.kt @@ -1,29 +1,26 @@ package sample -import android.support.v7.app.AppCompatActivity import android.os.Bundle -import com.github.florent37.log.Logger +import androidx.appcompat.app.AppCompatActivity +import com.github.florent37.livedata.observe import kotlinx.android.synthetic.main.activity_main.* -class MainActivity : AppCompatActivity(), MainView { +class MainActivity : AppCompatActivity() { - private val presenter = MainPresenter() + private val viewmodel by lazy { dependencies.mainViewmodel } override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) - Logger.enabled = BuildConfig.DEBUG - - presenter.bind(this) - - debugButton.setOnClickListener { - presenter.displayLogDebug() + viewmodel.viewState().observe(this){ + userStatus.text = it.userStatus } - errorButton.setOnClickListener { - presenter.displayLogError() + + premiumButton.setOnClickListener { + viewmodel.becomePremium() } } -} \ No newline at end of file +} diff --git a/sample/app/src/main/java/sample/MainApplication.kt b/sample/app/src/main/java/sample/MainApplication.kt new file mode 100644 index 0000000..d3b9d3e --- /dev/null +++ b/sample/app/src/main/java/sample/MainApplication.kt @@ -0,0 +1,25 @@ +package sample + +import android.app.Application +import com.github.florent37.log.Logger + +class MainApplication : Application() { + + val dependencyManager by lazy { DependencyManager(this) } + + override fun onCreate() { + super.onCreate() + + Logger.enabled = BuildConfig.DEBUG + + _app = this + } +} + +private lateinit var _app: MainApplication + +val app: MainApplication + get() = _app + +val dependencies: DependencyManager + get() = app.dependencyManager \ No newline at end of file diff --git a/sample/app/src/main/res/layout/activity_main.xml b/sample/app/src/main/res/layout/activity_main.xml index 732887f..6d59ab3 100644 --- a/sample/app/src/main/res/layout/activity_main.xml +++ b/sample/app/src/main/res/layout/activity_main.xml @@ -1,16 +1,16 @@ - -