Skip to content

Commit

Permalink
Merge pull request #124 from icerockdev/testing-support
Browse files Browse the repository at this point in the history
Release 0.10.0
  • Loading branch information
Alex009 committed Apr 6, 2021
2 parents 5972b09 + 53846a1 commit dc75994
Show file tree
Hide file tree
Showing 50 changed files with 923 additions and 84 deletions.
12 changes: 11 additions & 1 deletion .github/workflows/compilation-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,14 @@ jobs:
- name: Build K/N cache
run: ./gradlew :mvvm:runCommonizer
- name: Build and test
run: ./gradlew build publishToMavenLocal
run: ./gradlew build publishToMavenLocal syncMultiPlatformLibraryDebugFrameworkIosX64 -x linkMultiPlatformLibraryDebugFrameworkIosArm64 -x linkMultiPlatformLibraryReleaseFrameworkIosArm64 -x linkMultiPlatformLibraryReleaseFrameworkIosX64
- name: Install pods
run: cd sample/ios-app && pod install
- name: build ios sample
run: cd sample/ios-app && xcodebuild -scheme TestProj -workspace TestProj.xcworkspace -configuration Debug build CODE_SIGNING_REQUIRED=NO CODE_SIGNING_ALLOWED=NO
- name: Publish Test Report
uses: mikepenz/action-junit-report@v2
if: ${{ always() }}
with:
report_paths: '**/build/test-results/**/TEST-*.xml'
github_token: ${{ secrets.GITHUB_TOKEN }}
23 changes: 12 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ This is a Kotlin Multiplatform library that provides architecture components of
### mavenCentral
- kotlin 1.4.31
- 0.9.2
- 0.10.0

## Installation
root build.gradle
Expand All @@ -66,15 +67,15 @@ allprojects {
project build.gradle
```groovy
dependencies {
commonMainApi("dev.icerock.moko:mvvm-core:0.9.2") // only ViewModel, EventsDispatcher, Dispatchers.UI
commonMainApi("dev.icerock.moko:mvvm-livedata:0.9.2") // api mvvm-core, LiveData and extensions
androidMainApi("dev.icerock.moko:mvvm-livedata-material:0.9.2") // api mvvm-livedata, Material library android extensions
androidMainApi("dev.icerock.moko:mvvm-livedata-glide:0.9.2") // api mvvm-livedata, Glide library android extensions
androidMainApi("dev.icerock.moko:mvvm-livedata-swiperefresh:0.9.2") // api mvvm-livedata, SwipeRefreshLayout library android extensions
commonMainApi("dev.icerock.moko:mvvm-state:0.9.2") // api mvvm-livedata, ResourceState class and extensions
androidMainApi("dev.icerock.moko:mvvm-databinding:0.9.2") // api mvvm-livedata, DataBinding support for Android
androidMainApi("dev.icerock.moko:mvvm-viewbinding:0.9.2") // api mvvm-livedata, ViewBinding support for Android
commonTestImplementation("dev.icerock.moko:mvvm-test:0.9.2") // test utilities
commonMainApi("dev.icerock.moko:mvvm-core:0.10.0") // only ViewModel, EventsDispatcher, Dispatchers.UI
commonMainApi("dev.icerock.moko:mvvm-livedata:0.10.0") // api mvvm-core, LiveData and extensions
androidMainApi("dev.icerock.moko:mvvm-livedata-material:0.10.0") // api mvvm-livedata, Material library android extensions
androidMainApi("dev.icerock.moko:mvvm-livedata-glide:0.10.0") // api mvvm-livedata, Glide library android extensions
androidMainApi("dev.icerock.moko:mvvm-livedata-swiperefresh:0.10.0") // api mvvm-livedata, SwipeRefreshLayout library android extensions
commonMainApi("dev.icerock.moko:mvvm-state:0.10.0") // api mvvm-livedata, ResourceState class and extensions
androidMainApi("dev.icerock.moko:mvvm-databinding:0.10.0") // api mvvm-livedata, DataBinding support for Android
androidMainApi("dev.icerock.moko:mvvm-viewbinding:0.10.0") // api mvvm-livedata, ViewBinding support for Android
commonTestImplementation("dev.icerock.moko:mvvm-test:0.10.0") // test utilities
}
```

Expand All @@ -89,15 +90,15 @@ kotlin {
else -> throw IllegalArgumentException()
}
binaries.withType(org.jetbrains.kotlin.gradle.plugin.mpp.Framework::class.java).all {
export("dev.icerock.moko:mvvm-$arch:0.8.1")
export("dev.icerock.moko:mvvm-$arch:0.10.0")
}
}
}
```

On iOS, in addition to the Kotlin library add in Podfile
```ruby
pod 'MultiPlatformLibraryMvvm', :git => 'https://github.com/icerockdev/moko-mvvm.git', :tag => 'release/0.9.1'
pod 'MultiPlatformLibraryMvvm', :git => 'https://github.com/icerockdev/moko-mvvm.git', :tag => 'release/0.10.0'
```
**`MultiPlatformLibraryMvvm` CocoaPod requires that the framework compiled from Kotlin be named
`MultiPlatformLibrary` and be connected as a CocoaPod `MultiPlatformLibrary`.
Expand Down
26 changes: 18 additions & 8 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import java.util.Base64
plugins {
plugin(Deps.Plugins.detekt) apply false
plugin(Deps.Plugins.dokka) apply false
id("org.jetbrains.kotlinx.binary-compatibility-validator") version "0.5.0"
}

buildscript {
Expand All @@ -17,6 +18,7 @@ buildscript {

allprojects {
repositories {
mavenCentral()
google()
mavenCentral()

Expand Down Expand Up @@ -121,18 +123,26 @@ allprojects {
}
}

val sampleProjects: Set<Project> = project(":sample").allprojects

apiValidation {
ignoredPackages.add("dev.icerock.moko.mvvm.internal")

ignoredProjects.addAll(sampleProjects.map { it.name })
}

tasks.register("clean", Delete::class).configure {
group = "build"
delete(rootProject.buildDir)
}

tasks.withType<org.jetbrains.dokka.gradle.DokkaMultiModuleTask>().all {
removeChildTasks(listOf(
":mvvm",
":sample",
":sample:android-app",
":sample:mpp-library"
).map { project(it) })
removeChildTasks(sampleProjects.plus(project(":mvvm")))

doLast {
val dir = outputDirectory.get()
val from = File(dir,"-modules.html")
val to = File(dir,"index.html")
val from = File(dir, "-modules.html")
val to = File(dir, "index.html")

from.renameTo(to)

Expand Down
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/Deps.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ object Deps {
private const val coroutinesVersion = "1.4.2"
private const val mokoResourcesVersion = "0.15.1"
private const val mokoTestVersion = "0.2.1"
const val mokoMvvmVersion = "0.9.2"
const val mokoMvvmVersion = "0.10.0"

object Android {
const val compileSdk = 29
Expand Down
38 changes: 38 additions & 0 deletions mvvm-core/api/mvvm-core.api
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
public final class dev/icerock/moko/mvvm/UIKt {
public static final fun getUI (Lkotlinx/coroutines/Dispatchers;)Lkotlinx/coroutines/CoroutineDispatcher;
}

public final class dev/icerock/moko/mvvm/ViewModelFactory : androidx/lifecycle/ViewModelProvider$Factory {
public fun <init> (Lkotlin/jvm/functions/Function0;)V
public fun create (Ljava/lang/Class;)Landroidx/lifecycle/ViewModel;
}

public final class dev/icerock/moko/mvvm/core/BuildConfig {
public static final field BUILD_TYPE Ljava/lang/String;
public static final field DEBUG Z
public static final field LIBRARY_PACKAGE_NAME Ljava/lang/String;
public fun <init> ()V
}

public final class dev/icerock/moko/mvvm/dispatcher/EventsDispatcher {
public fun <init> ()V
public fun <init> (Ljava/util/concurrent/Executor;)V
public fun <init> (Ljava/util/concurrent/Executor;Ljava/lang/Object;)V
public final fun bind (Landroidx/lifecycle/LifecycleOwner;Ljava/lang/Object;)V
public final fun dispatchEvent (Lkotlin/jvm/functions/Function1;)V
}

public final class dev/icerock/moko/mvvm/dispatcher/EventsDispatcherExtKt {
public static final fun createExecutorOnMainLooper ()Ljava/util/concurrent/Executor;
}

public abstract interface class dev/icerock/moko/mvvm/dispatcher/EventsDispatcherOwner {
public abstract fun getEventsDispatcher ()Ldev/icerock/moko/mvvm/dispatcher/EventsDispatcher;
}

public class dev/icerock/moko/mvvm/viewmodel/ViewModel : androidx/lifecycle/ViewModel {
public fun <init> ()V
protected final fun getViewModelScope ()Lkotlinx/coroutines/CoroutineScope;
public fun onCleared ()V
}

2 changes: 2 additions & 0 deletions mvvm-core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ plugins {
dependencies {
commonMainImplementation(Deps.Libs.MultiPlatform.coroutines)

commonMainImplementation(project(":mvvm-internal"))

androidMainApi(Deps.Libs.Android.appCompat)
androidMainApi(Deps.Libs.Android.androidViewModel)

Expand Down
11 changes: 0 additions & 11 deletions mvvm-core/src/androidMain/kotlin/dev/icerock/moko/mvvm/UI.kt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ actual class EventsDispatcher<ListenerType : Any> {
this.executor = executor
}

/**
* Constructor without lifecycle connection. Used for tests
*/
constructor(executor: Executor, listener: ListenerType) {
this.executor = executor
this.eventsListener = listener
}

fun bind(lifecycleOwner: LifecycleOwner, listener: ListenerType) {
val observer = object : LifecycleObserver {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@
package dev.icerock.moko.mvvm.viewmodel

import androidx.lifecycle.ViewModel
import dev.icerock.moko.mvvm.UI
import dev.icerock.moko.mvvm.internal.createViewModelScope
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.cancel

@Suppress("EmptyDefaultConstructor")
actual open class ViewModel actual constructor() : ViewModel() {
// for now dispatcher fixed on Main. after implementing multithread coroutines on native - we can change it
protected actual val viewModelScope: CoroutineScope = CoroutineScope(Dispatchers.UI)
protected actual val viewModelScope: CoroutineScope = createViewModelScope()

public actual override fun onCleared() {
super.onCleared()
Expand Down
4 changes: 3 additions & 1 deletion mvvm-core/src/commonMain/kotlin/dev/icerock/moko/mvvm/UI.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

package dev.icerock.moko.mvvm

import dev.icerock.moko.mvvm.internal.createUIDispatcher
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.Dispatchers

expect val Dispatchers.UI: CoroutineDispatcher
val Dispatchers.UI: CoroutineDispatcher
get() = createUIDispatcher()
1 change: 1 addition & 0 deletions mvvm-core/src/iosArm64Main
12 changes: 0 additions & 12 deletions mvvm-core/src/iosMain/kotlin/dev/icerock/moko/mvvm/UI.kt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package dev.icerock.moko.mvvm.dispatcher

import platform.darwin.dispatch_async
import platform.darwin.dispatch_get_current_queue
import platform.darwin.dispatch_get_main_queue
import platform.darwin.dispatch_queue_t
import kotlin.native.ref.WeakReference
Expand Down Expand Up @@ -44,8 +45,10 @@ actual class EventsDispatcher<ListenerType : Any> {
return
}

dispatch_async(queue) {
if (dispatch_get_current_queue() == queue) {
block(listener)
} else {
dispatch_async(queue) { block(listener) }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,20 @@

package dev.icerock.moko.mvvm.viewmodel

import dev.icerock.moko.mvvm.UI
import dev.icerock.moko.mvvm.internal.createViewModelScope
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.cancel
import platform.darwin.dispatch_async
import platform.darwin.dispatch_get_main_queue
import kotlin.native.internal.GC

@ThreadLocal
private var isGCWorking = false

@Suppress("EmptyDefaultConstructor")
actual open class ViewModel actual constructor() {
// for now dispatcher fixed on Main. after implementing multithread coroutines on native - we can change it
protected actual val viewModelScope: CoroutineScope = CoroutineScope(Dispatchers.UI)
protected actual val viewModelScope: CoroutineScope = createViewModelScope()

actual open fun onCleared() {
viewModelScope.cancel()
// run Kotlin/Native GC
if (!isGCWorking) {
isGCWorking = true
GC.collect()
isGCWorking = false
}

dispatch_async(dispatch_get_main_queue()) { GC.collect() }
}
}
89 changes: 89 additions & 0 deletions mvvm-databinding/api/mvvm-databinding.api
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
public abstract interface class androidx/databinding/DataBindingComponent {
}

public class androidx/databinding/library/baseAdapters/BR {
public static field _all I
public fun <init> ()V
}

public abstract class dev/icerock/moko/mvvm/MvvmActivity : androidx/appcompat/app/AppCompatActivity {
protected field binding Landroidx/databinding/ViewDataBinding;
protected field viewModel Ldev/icerock/moko/mvvm/viewmodel/ViewModel;
public fun <init> ()V
protected final fun getBinding ()Landroidx/databinding/ViewDataBinding;
protected abstract fun getLayoutId ()I
protected final fun getViewModel ()Ldev/icerock/moko/mvvm/viewmodel/ViewModel;
protected abstract fun getViewModelClass ()Ljava/lang/Class;
protected abstract fun getViewModelVariableId ()I
protected fun onCreate (Landroid/os/Bundle;)V
protected final fun setBinding (Landroidx/databinding/ViewDataBinding;)V
protected final fun setViewModel (Ldev/icerock/moko/mvvm/viewmodel/ViewModel;)V
protected abstract fun viewModelFactory ()Landroidx/lifecycle/ViewModelProvider$Factory;
}

public abstract class dev/icerock/moko/mvvm/MvvmEventsActivity : dev/icerock/moko/mvvm/MvvmActivity {
public fun <init> ()V
protected fun onCreate (Landroid/os/Bundle;)V
}

public abstract class dev/icerock/moko/mvvm/MvvmEventsFragment : dev/icerock/moko/mvvm/MvvmFragment {
public fun <init> ()V
public fun onCreate (Landroid/os/Bundle;)V
}

public abstract class dev/icerock/moko/mvvm/MvvmFragment : androidx/fragment/app/Fragment {
protected field viewModel Ldev/icerock/moko/mvvm/viewmodel/ViewModel;
public fun <init> ()V
protected final fun getBinding ()Landroidx/databinding/ViewDataBinding;
protected abstract fun getLayoutId ()I
protected final fun getViewModel ()Ldev/icerock/moko/mvvm/viewmodel/ViewModel;
protected abstract fun getViewModelClass ()Ljava/lang/Class;
protected abstract fun getViewModelVariableId ()I
public fun onCreate (Landroid/os/Bundle;)V
public fun onCreateView (Landroid/view/LayoutInflater;Landroid/view/ViewGroup;Landroid/os/Bundle;)Landroid/view/View;
public fun onDestroyView ()V
public fun onViewCreated (Landroid/view/View;Landroid/os/Bundle;)V
protected final fun setViewModel (Ldev/icerock/moko/mvvm/viewmodel/ViewModel;)V
protected abstract fun viewModelFactory ()Landroidx/lifecycle/ViewModelProvider$Factory;
protected fun viewModelStoreOwner ()Landroidx/lifecycle/ViewModelStoreOwner;
}

public class dev/icerock/moko/mvvm/databinding/BR {
public static field _all I
public fun <init> ()V
}

public final class dev/icerock/moko/mvvm/databinding/BuildConfig {
public static final field BUILD_TYPE Ljava/lang/String;
public static final field DEBUG Z
public static final field LIBRARY_PACKAGE_NAME Ljava/lang/String;
public fun <init> ()V
}

public class dev/icerock/moko/mvvm/databinding/DataBinderMapperImpl : androidx/databinding/DataBinderMapper {
public fun <init> ()V
public fun collectDependencies ()Ljava/util/List;
public fun convertBrIdToString (I)Ljava/lang/String;
public fun getDataBinder (Landroidx/databinding/DataBindingComponent;Landroid/view/View;I)Landroidx/databinding/ViewDataBinding;
public fun getDataBinder (Landroidx/databinding/DataBindingComponent;[Landroid/view/View;I)Landroidx/databinding/ViewDataBinding;
public fun getLayoutId (Ljava/lang/String;)I
}

public class dev/icerock/moko/mvvm/databinding/DataBindingTriggerClass {
public fun <init> ()V
}

public final class dev/icerock/moko/mvvm/databinding/StringDescAdapters {
public static final field INSTANCE Ldev/icerock/moko/mvvm/databinding/StringDescAdapters;
public static final fun setError (Lcom/google/android/material/textfield/TextInputLayout;Ldev/icerock/moko/resources/desc/StringDesc;)V
public static final fun setText (Landroid/widget/Button;Ldev/icerock/moko/resources/desc/StringDesc;)V
public static final fun setText (Landroid/widget/TextView;Ldev/icerock/moko/resources/desc/StringDesc;)V
}

public final class dev/icerock/moko/mvvm/databinding/ViewBindingAdapters {
public static final field INSTANCE Ldev/icerock/moko/mvvm/databinding/ViewBindingAdapters;
public static final fun setInvisibleOrGone (Landroid/view/View;Z)V
public static final fun setVisibleOrGone (Landroid/view/View;Z)V
public static final fun setVisibleOrInvisible (Landroid/view/View;Z)V
}

Empty file.
Loading

0 comments on commit dc75994

Please sign in to comment.