Skip to content

Commit

Permalink
Merge pull request #43 from rainbowcake/dev
Browse files Browse the repository at this point in the history
Release 1.6.0
  • Loading branch information
zsmb13 committed Sep 28, 2021
2 parents 8054c98 + 184eec5 commit 13f7080
Show file tree
Hide file tree
Showing 28 changed files with 882 additions and 783 deletions.
817 changes: 817 additions & 0 deletions CHANGELOG.md

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ It ships in several artifacts - feel free to pick and choose from them (for more

```groovy
dependencies {
implementation "co.zsmb:rainbow-cake-core:1.5.0" // Core library (required)
implementation "co.zsmb:rainbow-cake-dagger:1.5.0" // Dagger 2 support
implementation "co.zsmb:rainbow-cake-hilt:1.5.0" // Dagger Hilt support
implementation "co.zsmb:rainbow-cake-koin:1.5.0" // Koin support
implementation "co.zsmb:rainbow-cake-navigation:1.5.0" // Navigation features
implementation "co.zsmb:rainbow-cake-timber:1.5.0" // Internal logging through Timber
testImplementation "co.zsmb:rainbow-cake-test:1.5.0" // Testing utilities
implementation "co.zsmb:rainbow-cake-core:1.6.0" // Core library (required)
implementation "co.zsmb:rainbow-cake-dagger:1.6.0" // Dagger 2 support
implementation "co.zsmb:rainbow-cake-hilt:1.6.0" // Dagger Hilt support
implementation "co.zsmb:rainbow-cake-koin:1.6.0" // Koin support
implementation "co.zsmb:rainbow-cake-navigation:1.6.0" // Navigation features
implementation "co.zsmb:rainbow-cake-timber:1.6.0" // Internal logging through Timber
testImplementation "co.zsmb:rainbow-cake-test:1.6.0" // Testing utilities
}
```

Expand Down
8 changes: 4 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
buildscript {
ext.rainbowcake_version = '1.5.0'
ext.rainbowcake_version = '1.6.0'

ext.kotlin_version = '1.5.30'
ext.kotlin_version = '1.5.31'
ext.coroutines_version = '1.5.1'

ext.dagger_version = '2.38.1'
Expand All @@ -17,9 +17,9 @@ buildscript {
maven { url "https://plugins.gradle.org/m2/" }
}
dependencies {
classpath 'com.android.tools.build:gradle:7.0.1'
classpath 'com.android.tools.build:gradle:7.0.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'org.jetbrains.kotlinx:binary-compatibility-validator:0.6.0'
classpath 'org.jetbrains.kotlinx:binary-compatibility-validator:0.7.1'

classpath "com.google.dagger:hilt-android-gradle-plugin:$dagger_version"

Expand Down
3 changes: 3 additions & 0 deletions rainbow-cake-core/api/rainbow-cake-core.api
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public abstract class co/zsmb/rainbowcake/base/RainbowCakeDialogFragment : andro
public abstract class co/zsmb/rainbowcake/base/RainbowCakeFragment : androidx/fragment/app/Fragment {
protected field viewModel Lco/zsmb/rainbowcake/base/RainbowCakeViewModel;
public fun <init> ()V
public final fun getOverrideAnimation ()Ljava/lang/Integer;
protected final fun getViewModel ()Lco/zsmb/rainbowcake/base/RainbowCakeViewModel;
protected fun getViewResource ()I
public fun onCreate (Landroid/os/Bundle;)V
Expand All @@ -71,6 +72,7 @@ public abstract class co/zsmb/rainbowcake/base/RainbowCakeViewModel : androidx/l
protected final fun executeCancellable (ZLkotlin/jvm/functions/Function2;)Lkotlinx/coroutines/Job;
public static synthetic fun executeCancellable$default (Lco/zsmb/rainbowcake/base/RainbowCakeViewModel;ZLkotlin/jvm/functions/Function2;ILjava/lang/Object;)Lkotlinx/coroutines/Job;
protected final fun executeNonBlocking (Lkotlin/jvm/functions/Function2;)V
public final fun getCoroutineScope ()Lkotlinx/coroutines/CoroutineScope;
public final fun getEvents ()Lco/zsmb/rainbowcake/internal/livedata/LiveDataCollection;
public final fun getQueuedEvents ()Lco/zsmb/rainbowcake/internal/livedata/LiveDataCollection;
public final fun getState ()Landroidx/lifecycle/LiveData;
Expand Down Expand Up @@ -150,5 +152,6 @@ public abstract interface annotation class co/zsmb/rainbowcake/internal/Internal

public abstract interface class co/zsmb/rainbowcake/internal/livedata/LiveDataCollection {
public abstract fun observe (Landroidx/lifecycle/LifecycleOwner;Landroidx/lifecycle/Observer;)V
public abstract fun removeObserver (Landroidx/lifecycle/Observer;)V
}

Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import org.junit.Test
internal class MutableLiveDataCollectionImplTest : LifecycleTest() {

private val mutableLiveDataCollection: MutableLiveDataCollectionImpl<String> =
MutableLiveDataCollectionImpl(::MutableLiveData)
MutableLiveDataCollectionImpl(::MutableLiveData)

private val observer1 = MockObserver<String>()
private val observer2 = MockObserver<String>()
Expand Down Expand Up @@ -88,4 +88,25 @@ internal class MutableLiveDataCollectionImplTest : LifecycleTest() {
observer3.assertObserved("c")
}

@Test
fun manuallyRemoveObserver() {
mutableLiveDataCollection.observe(this, observer1)
observer1.assertObserved()

mutableLiveDataCollection.setValue("a")
lifecycle.handleLifecycleEvent(ON_START)
observer1.assertObserved("a")

mutableLiveDataCollection.removeObserver(observer1)
mutableLiveDataCollection.setValue("b")
observer1.assertObserved() // Nothing observed after removal
}

@Test
fun manuallyRemoveNonAttachedObserver() {
mutableLiveDataCollection.observe(this, observer1)

mutableLiveDataCollection.removeObserver(observer2)
mutableLiveDataCollection.removeObserver(observer3)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,7 @@ public abstract class RainbowCakeFragment<VS : Any, VM : RainbowCakeViewModel<VS
*/
@AnimRes
@AnimatorRes
@InternalRainbowCakeApi
public var overrideAnimation: Int? = null
@InternalRainbowCakeApi get
@InternalRainbowCakeApi set

@CallSuper
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ public abstract class RainbowCakeViewModel<VS : Any>(initialState: VS) : ViewMod
*/
@InternalRainbowCakeApi
public val coroutineScope: CoroutineScope = CoroutineScope(Dispatchers.Main + SupervisorJob())
@InternalRainbowCakeApi get

@CallSuper
override fun onCleared() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,8 @@ public interface LiveDataCollection<T : Any> {
*/
public fun observe(owner: LifecycleOwner, observer: Observer<T>)

/**
* Removes the given observer from this collection.
*/
public fun removeObserver(observer: Observer<T>)
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package co.zsmb.rainbowcake.internal.livedata

import androidx.annotation.VisibleForTesting
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleObserver
import androidx.lifecycle.LifecycleOwner
Expand All @@ -17,59 +18,63 @@ import androidx.lifecycle.OnLifecycleEvent
* if required by a new observer being added.
*/
internal class MutableLiveDataCollectionImpl<T : Any>(
private val factory: () -> MutableLiveData<T>
private val factory: () -> MutableLiveData<T>
) : MutableLiveDataCollection<T> {

/**
* The set of currently contained [LiveData] instances. Instances
* that are no longer observed are removed immediately, see [LiveDataRemover].
*
* Internal visibility only for testing.
*/
internal val activeLiveData: MutableSet<MutableLiveData<T>> = mutableSetOf()
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
internal val activeLiveData: MutableMap<Observer<T>, MutableLiveData<T>> = mutableMapOf()

override fun observe(owner: LifecycleOwner, observer: Observer<T>) {
val liveData = factory()
activeLiveData += liveData
attachRemover(owner, liveData)
activeLiveData[observer] = liveData
attachRemover(owner, observer)
liveData.observe(owner, observer)
}

override fun removeObserver(observer: Observer<T>) {
removeLiveData(observer)
}

override fun setValue(value: T?) {
activeLiveData.forEach { it.setValue(value) }
activeLiveData.forEach { (_, livedata) -> livedata.setValue(value) }
}

override fun postValue(value: T?) {
activeLiveData.forEach { it.postValue(value) }
activeLiveData.forEach { (_, livedata) -> livedata.postValue(value) }
}

/**
* Removes a given [LiveData] instance from the set of stored instances.
* Removes the [LiveData] instance belonging to the [observer] from the set of
* stored instances.
*/
private fun removeLiveData(liveData: LiveData<T>) {
activeLiveData.remove(liveData)
private fun removeLiveData(observer: Observer<T>) {
activeLiveData.remove(key = observer)
}

/**
* Creates a [LiveDataRemover] which will remove the given [liveData] from
* the set of contained instances when the [owner]'s lifecycle is destroyed.
* Creates a [LiveDataRemover] which will remove the given [observer]'s LiveData
* from the set of contained instances when the [owner]'s lifecycle is destroyed.
*/
private fun attachRemover(owner: LifecycleOwner, liveData: MutableLiveData<T>) {
val watcher = LiveDataRemover(liveData)
private fun attachRemover(owner: LifecycleOwner, observer: Observer<T>) {
val watcher = LiveDataRemover(observer)
owner.lifecycle.addObserver(watcher)
}

/**
* A [LifecycleObserver] that removes a given [liveData] from the collection
* when the lifecycle it observes is destroyed.
* A [LifecycleObserver] that removes the LiveData belonging to the [observer]
* from the collection when the lifecycle it observes in is destroyed.
*/
private inner class LiveDataRemover(private val liveData: MutableLiveData<T>) : LifecycleObserver {
private inner class LiveDataRemover(private val observer: Observer<T>) : LifecycleObserver {
/**
* Removes the [liveData] instance from the collection.
* Removes the [observer] instance from the collection.
*/
@OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
fun onDestroy() {
removeLiveData(liveData)
removeLiveData(observer)
}
}

Expand Down
104 changes: 0 additions & 104 deletions releases/0.1.0-SNAPSHOT.md

This file was deleted.

29 changes: 0 additions & 29 deletions releases/0.1.1-SNAPSHOT.md

This file was deleted.

34 changes: 0 additions & 34 deletions releases/0.1.2-SNAPSHOT.md

This file was deleted.

0 comments on commit 13f7080

Please sign in to comment.