Skip to content

Commit

Permalink
Merge pull request #18 from rainbowcake/dev
Browse files Browse the repository at this point in the history
Release 1.1.0
  • Loading branch information
zsmb13 committed Aug 26, 2020
2 parents 0330d41 + 966ee6a commit e8d206e
Show file tree
Hide file tree
Showing 59 changed files with 232 additions and 162 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ It ships in several artifacts - feel free to pick and choose from them (for more

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

Expand Down
14 changes: 7 additions & 7 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
buildscript {
ext.rainbowcake_version = '1.0.0'
ext.rainbowcake_version = '1.1.0'

ext.kotlin_version = '1.3.72'
ext.coroutines_version = '1.3.0'
ext.kotlin_version = '1.4.0'
ext.coroutines_version = '1.3.9'

ext.dagger_version = '2.28'
ext.dagger_version = '2.28.3'
ext.koin_version = '2.1.6'

ext.target_sdk = 29
ext.target_sdk = 30
ext.min_sdk = 19
ext.compile_sdk = 29
ext.compile_sdk = 30

repositories {
google()
mavenCentral()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.0.0'
classpath 'com.android.tools.build:gradle:4.0.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "io.codearte.gradle.nexus:gradle-nexus-staging-plugin:0.21.0"
}
Expand Down
9 changes: 6 additions & 3 deletions demo/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ android {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
packagingOptions {
exclude 'META-INF/ASL2.0'
}
}

dependencies {
Expand All @@ -30,9 +33,9 @@ dependencies {
implementation project(':rainbow-cake-timber')

// Google libraries
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'com.google.android.material:material:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.0'

// Kotlin
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import co.zsmb.rainbowcake.demo.ui.sharedvmpager.pages.ScreenOneFragment
import co.zsmb.rainbowcake.demo.ui.sharedvmpager.pages.ScreenThreeFragment
import co.zsmb.rainbowcake.demo.ui.sharedvmpager.pages.ScreenTwoFragment

class SharedVMPagerPagerAdapter(fragmentManager: FragmentManager) : FragmentPagerAdapter(fragmentManager) {
class SharedVMPagerPagerAdapter(fragmentManager: FragmentManager) : FragmentPagerAdapter(fragmentManager, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT) {

class Page(
val title: String,
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.4.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.6-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
6 changes: 3 additions & 3 deletions rainbow-cake-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ apply plugin: 'kotlin-android'

dependencies {
// Google libraries
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'com.google.android.material:material:1.1.0'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.2.0'
implementation 'androidx.lifecycle:lifecycle-livedata-core:2.2.0'
implementation 'androidx.lifecycle:lifecycle-viewmodel:2.2.0'

Expand All @@ -28,7 +28,7 @@ tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
kotlinOptions {
freeCompilerArgs += [
'-progressive',
'-Xuse-experimental=kotlin.Experimental'
'-Xexplicit-api=strict',
]
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ package co.zsmb.rainbowcake.internal
import androidx.lifecycle.Lifecycle.Event.ON_START
import androidx.lifecycle.Lifecycle.Event.ON_STOP
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.Observer
import co.zsmb.rainbowcake.internal.livedata.ActiveOnlySingleShotLiveData
import co.zsmb.rainbowcake.util.LifecycleTest
import co.zsmb.rainbowcake.util.MockObserver
import org.junit.Before
import org.junit.Test

class ActiveOnlySingleShotLiveDataTest : LifecycleTest() {
internal class ActiveOnlySingleShotLiveDataTest : LifecycleTest() {

private val activeOnlyLiveData: MutableLiveData<String> = ActiveOnlySingleShotLiveData()

Expand All @@ -23,7 +22,7 @@ class ActiveOnlySingleShotLiveDataTest : LifecycleTest() {

@Test(expected = IllegalStateException::class)
fun multipleObservers() {
activeOnlyLiveData.observe(this, Observer { })
activeOnlyLiveData.observe(this) {}
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import org.junit.Assert.assertEquals
import org.junit.Test

@Suppress("UsePropertyAccessSyntax")
class ClairvoyantLiveDataTest {
internal class ClairvoyantLiveDataTest {

@Test
fun placeValueIsInstant() = runBlocking(Dispatchers.Main) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import org.junit.Before
import org.junit.Test


class MutableLiveDataCollectionImplTest : LifecycleTest() {
internal class MutableLiveDataCollectionImplTest : LifecycleTest() {

private val mutableLiveDataCollection: MutableLiveDataCollectionImpl<String> =
MutableLiveDataCollectionImpl(::MutableLiveData)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@ package co.zsmb.rainbowcake.internal
import androidx.lifecycle.Lifecycle.Event.ON_START
import androidx.lifecycle.Lifecycle.Event.ON_STOP
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.Observer
import co.zsmb.rainbowcake.internal.livedata.QueuedSingleShotLiveData
import co.zsmb.rainbowcake.util.LifecycleTest
import co.zsmb.rainbowcake.util.MockObserver
import org.junit.Before
import org.junit.Test

@Suppress("UsePropertyAccessSyntax")
class QueuedSingleShotLiveDataTest : LifecycleTest() {
internal class QueuedSingleShotLiveDataTest : LifecycleTest() {

private val queuedLiveData: MutableLiveData<String> = QueuedSingleShotLiveData()

Expand Down Expand Up @@ -54,7 +53,7 @@ class QueuedSingleShotLiveDataTest : LifecycleTest() {

@Test(expected = IllegalStateException::class)
fun multipleObservers() {
queuedLiveData.observe(this, Observer { })
queuedLiveData.observe(this) {}
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@ package co.zsmb.rainbowcake.internal

import androidx.lifecycle.Lifecycle
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.Observer
import co.zsmb.rainbowcake.internal.livedata.SingleShotLiveData
import co.zsmb.rainbowcake.util.LifecycleTest
import co.zsmb.rainbowcake.util.MockObserver
import org.junit.Assert.assertTrue
import org.junit.Test

@Suppress("UsePropertyAccessSyntax")
class SingleShotLiveDataTest : LifecycleTest() {
internal class SingleShotLiveDataTest : LifecycleTest() {

private val singleShotLiveData: MutableLiveData<String> = SingleShotLiveData()

Expand All @@ -19,7 +18,7 @@ class SingleShotLiveDataTest : LifecycleTest() {
@Test(expected = IllegalStateException::class)
fun multipleObservers() {
singleShotLiveData.observe(this, mockObserver)
singleShotLiveData.observe(this, Observer {})
singleShotLiveData.observe(this) {}
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import co.zsmb.rainbowcake.util.MockObserver
import org.junit.Before
import org.junit.Test

class DistinctTest : LifecycleTest() {
internal class DistinctTest : LifecycleTest() {

private val mutableLiveData: MutableLiveData<String> = MutableLiveData()
private val liveData: LiveData<String> = mutableLiveData.distinct()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import androidx.lifecycle.LifecycleRegistry
import org.junit.Rule
import org.junit.rules.TestRule

abstract class LifecycleTest : LifecycleOwner {
internal abstract class LifecycleTest : LifecycleOwner {

@JvmField
@Rule
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import org.junit.runner.Description
import org.junit.runners.model.Statement
import java.util.concurrent.Executor

class LiveDataTestRule : TestRule {
internal class LiveDataTestRule : TestRule {

override fun apply(base: Statement, description: Description?): Statement {
return object : Statement() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import androidx.lifecycle.Observer
import org.junit.Assert
import java.util.ArrayList

class MockObserver<T> : Observer<T> {
internal class MockObserver<T> : Observer<T> {
private val observed: MutableList<T?> = ArrayList()

override fun onChanged(t: T?) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import kotlin.coroutines.CoroutineContext
* For more details, see the [withContext] function that this function delegates to.
*/
@Suppress("DEPRECATION")
suspend inline fun <T> withIOContext(noinline block: suspend CoroutineScope.() -> T): T {
public suspend inline fun <T> withIOContext(noinline block: suspend CoroutineScope.() -> T): T {
return withContext(ioContext, block = block)
}

Expand All @@ -24,4 +24,4 @@ suspend inline fun <T> withIOContext(noinline block: suspend CoroutineScope.() -
*/
@VisibleForTesting
@Deprecated(message = "ioContext should only be used in tests", level = DeprecationLevel.WARNING)
var ioContext: CoroutineContext = Dispatchers.IO
public var ioContext: CoroutineContext = Dispatchers.IO
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ package co.zsmb.rainbowcake.base
* to be dispatched from a ViewModel are clearly identifiable and that the
* associated methods don't deal with the very broad [Any] type.
*/
interface OneShotEvent
public interface OneShotEvent

/**
* An additional marker interface for a more specific kind of [OneShotEvent].
Expand All @@ -15,4 +15,4 @@ interface OneShotEvent
* [queuedEvents][RainbowCakeViewModel.queuedEvents].
*
*/
interface QueuedOneShotEvent : OneShotEvent
public interface QueuedOneShotEvent : OneShotEvent
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ package co.zsmb.rainbowcake.base
import android.os.Bundle
import androidx.annotation.CallSuper
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.Observer
import co.zsmb.rainbowcake.internal.logging.log

/**
* Base class for Activities that connects them to the appropriate ViewModel instances.
*/
abstract class RainbowCakeActivity<VS : Any, VM : RainbowCakeViewModel<VS>> : AppCompatActivity() {
public abstract class RainbowCakeActivity<VS : Any, VM : RainbowCakeViewModel<VS>> : AppCompatActivity() {

private val logTag: String by lazy(mode = LazyThreadSafetyMode.NONE) { "RainbowCakeActivity ($this)" }

Expand All @@ -23,15 +22,15 @@ abstract class RainbowCakeActivity<VS : Any, VM : RainbowCakeViewModel<VS>> : Ap
super.onCreate(savedInstanceState)

viewModel = provideViewModel()
viewModel.state.observe(this, Observer { viewState ->
viewModel.state.observe(this) { viewState ->
viewState?.let { render(it) }
})
viewModel.events.observe(this, Observer { event ->
}
viewModel.events.observe(this) { event ->
event?.let { onEvent(it) }
})
viewModel.queuedEvents.observe(this, Observer { event ->
}
viewModel.queuedEvents.observe(this) { event ->
event?.let { onEvent(it) }
})
}
}

/**
Expand All @@ -40,7 +39,7 @@ abstract class RainbowCakeActivity<VS : Any, VM : RainbowCakeViewModel<VS>> : Ap
* If one of RainbowCake's own DI libraries are being used, this method should
* return the result of a [getViewModelFromFactory] call.
*/
abstract fun provideViewModel(): VM
public abstract fun provideViewModel(): VM

/**
* Renders the view state. Called when the view state changes and the UI should be
Expand All @@ -50,12 +49,12 @@ abstract class RainbowCakeActivity<VS : Any, VM : RainbowCakeViewModel<VS>> : Ap
* state of the UI. In other words, the same view state being set must always result
* in the same state for the displayed UI.
*/
abstract fun render(viewState: VS)
public abstract fun render(viewState: VS)

/**
* Handles one-time events emitted by the ViewModel.
*/
open fun onEvent(event: OneShotEvent) {
public open fun onEvent(event: OneShotEvent) {
log(logTag, "Unhandled event: $event")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@ import androidx.annotation.AnimatorRes
import androidx.annotation.CallSuper
import androidx.annotation.LayoutRes
import androidx.fragment.app.Fragment
import androidx.lifecycle.Observer
import co.zsmb.rainbowcake.internal.logging.log

/**
* Base class for Fragments that connects them to the appropriate ViewModel instances.
*/
abstract class RainbowCakeFragment<VS : Any, VM : RainbowCakeViewModel<VS>> : Fragment() {
public abstract class RainbowCakeFragment<VS : Any, VM : RainbowCakeViewModel<VS>> : Fragment() {

private val logTag: String by lazy(mode = LazyThreadSafetyMode.NONE) { "RainbowCakeFragment ($this)" }

Expand All @@ -31,12 +30,12 @@ abstract class RainbowCakeFragment<VS : Any, VM : RainbowCakeViewModel<VS>> : Fr
super.onCreate(savedInstanceState)
viewModel = provideViewModel()

viewModel.events.observe(this, Observer { event ->
viewModel.events.observe(this) { event ->
event?.let { onEvent(it) }
})
viewModel.queuedEvents.observe(this, Observer { event ->
}
viewModel.queuedEvents.observe(this) { event ->
event?.let { onEvent(it) }
})
}
}

/**
Expand All @@ -53,9 +52,9 @@ abstract class RainbowCakeFragment<VS : Any, VM : RainbowCakeViewModel<VS>> : Fr
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

viewModel.state.observe(viewLifecycleOwner, Observer { viewState ->
viewModel.state.observe(viewLifecycleOwner) { viewState ->
viewState?.let { render(it) }
})
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import kotlinx.coroutines.launch
* - one-time event support via [SingleShotLiveData] implementations,
* - the ability to easily start coroutines in a UI context via [execute].
*/
abstract class RainbowCakeViewModel<VS : Any>(initialState: VS) : ViewModel() {
public abstract class RainbowCakeViewModel<VS : Any>(initialState: VS) : ViewModel() {

//region Logging
private val logTag: String by lazy(mode = LazyThreadSafetyMode.NONE) { "RainbowCakeViewModel ($this)" }
Expand Down

0 comments on commit e8d206e

Please sign in to comment.