Skip to content

Commit

Permalink
Merge pull request #525 from uber/ty/kotlin-1.7-upgrade
Browse files Browse the repository at this point in the history
Ty/kotlin 1.7 upgrade
  • Loading branch information
tyvsmith authored Oct 20, 2022
2 parents d30ffb7 + 0f69c2f commit 0149a48
Show file tree
Hide file tree
Showing 16 changed files with 111 additions and 152 deletions.
3 changes: 2 additions & 1 deletion android/demos/compose/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ android {
compose true
}
composeOptions {
kotlinCompilerExtensionVersion "${deps.versions.androidx.compose}"
kotlinCompilerExtensionVersion deps.versions.androidx.compose.compiler
}
compileOptions {
sourceCompatibility deps.build.javaVersion
Expand Down Expand Up @@ -47,6 +47,7 @@ dependencies {
implementation deps.androidx.composeUi
implementation deps.androidx.composeViewModel
implementation deps.androidx.composeUiTooling
implementation deps.androidx.savedState
implementation deps.external.rxandroid2
implementation deps.kotlin.coroutines
implementation deps.kotlin.coroutinesAndroid
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ package com.uber.rib.compose.root

import android.view.ViewGroup
import androidx.lifecycle.ViewTreeLifecycleOwner
import androidx.savedstate.ViewTreeSavedStateRegistryOwner
import androidx.savedstate.setViewTreeSavedStateRegistryOwner
import com.uber.rib.compose.root.main.MainScope
import com.uber.rib.compose.util.AnalyticsClient
import com.uber.rib.compose.util.AnalyticsClientImpl
Expand Down Expand Up @@ -46,7 +46,7 @@ interface RootScope {
fun view(parentViewGroup: ViewGroup, activity: RibActivity): RootView {
return RootView(parentViewGroup.context).apply {
ViewTreeLifecycleOwner.set(this, activity)
ViewTreeSavedStateRegistryOwner.set(this, activity)
setViewTreeSavedStateRegistryOwner(activity)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.MutableState
import androidx.compose.ui.platform.ComposeView
import androidx.lifecycle.ViewTreeLifecycleOwner
import androidx.savedstate.ViewTreeSavedStateRegistryOwner
import androidx.savedstate.setViewTreeSavedStateRegistryOwner
import com.uber.rib.compose.root.main.logged_in.LoggedInScope
import com.uber.rib.compose.root.main.logged_out.LoggedOutScope
import com.uber.rib.compose.util.AnalyticsClient
Expand Down Expand Up @@ -65,7 +65,7 @@ interface MainScope {
): ComposeView {
return ComposeView(parentViewGroup.context).apply {
ViewTreeLifecycleOwner.set(this, activity)
ViewTreeSavedStateRegistryOwner.set(this, activity)
setViewTreeSavedStateRegistryOwner(activity)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ import androidx.compose.foundation.layout.aspectRatio
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.GridCells
import androidx.compose.foundation.lazy.LazyVerticalGrid
import androidx.compose.foundation.lazy.grid.GridCells
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.State
Expand Down Expand Up @@ -56,7 +56,7 @@ fun TicTacToeView(viewModel: State<TicTacToeViewModel>, eventStream: EventStream
.aspectRatio(1f)
.fillMaxSize()
) {
LazyVerticalGrid(cells = GridCells.Fixed(3), modifier = Modifier.fillMaxSize()) {
LazyVerticalGrid(columns = GridCells.Fixed(3), modifier = Modifier.fillMaxSize()) {
val board = viewModel.value.board
items(9) { i ->
val row = i / 3
Expand Down
39 changes: 21 additions & 18 deletions android/gradle/dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,23 @@ def versions = [
androidx: [
annotations: '1.1.0',
appcompat: '1.3.0',
compose: '1.0.2',
percent: '1.0.0'
compose: [
compiler: "1.3.0",
libraries: "1.2.1"
],
percent: '1.0.0',
savedState: "1.2.0"
],
autodispose: '1.4.0',
coroutines: '1.5.1',
dagger: "2.34",
coroutines: '1.6.4',
dagger: "2.43.2",
errorProne: '2.3.3',
gjf: '1.7',
intellij: "2022.1",
kotlin: "1.5.21",
kotlin: "1.7.10",
ktfmt: '0.23',
ktlint: '0.41.0',
motif: '0.3.4',
rave: "2.0.0",
robolectric: "4.4",
spotless: '5.11.0'
]
Expand All @@ -47,13 +50,12 @@ def apt = [
javaxInject: "javax.inject:javax.inject:1",
autoValue: "com.google.auto.value:auto-value:1.7",
autoValueAnnotations: "com.google.auto.value:auto-value-annotations:1.7",
raveCompiler: "com.uber:rave-compiler:${versions.rave}",
errorProneAnnotations: "com.google.errorprone:error_prone_annotations:${versions.errorProne}",
]

def build = [
buildToolsVersion: '30.0.2',
compileSdkVersion: 30,
buildToolsVersion: '33.0.0',
compileSdkVersion: 33,
ci: 'true' == System.getenv('CI'),
minSdkVersion: 21,
targetSdkVersion: 28,
Expand All @@ -67,7 +69,7 @@ def build = [
errorProneTestHelpers: "com.google.errorprone:error_prone_test_helpers:${versions.errorProne}",
nullAway: 'com.uber.nullaway:nullaway:0.9.0',
gradlePlugins: [
android: 'com.android.tools.build:gradle:7.1.0',
android: 'com.android.tools.build:gradle:7.2.2',
apt: "net.ltgt.gradle:gradle-apt-plugin:0.21",
errorprone: "net.ltgt.gradle:gradle-errorprone-plugin:1.3.0",
gradleMavenPublish: "com.vanniktech:gradle-maven-publish-plugin:0.18.0",
Expand All @@ -85,15 +87,17 @@ def androidx = [
activityKtx: "androidx.activity:activity-ktx:1.3.0-beta02",
annotations: "androidx.annotation:annotation:${versions.androidx.annotations}",
appcompat: "androidx.appcompat:appcompat:${versions.androidx.appcompat}",
composeAnimation: "androidx.compose.animation:animation:${versions.androidx.compose}",
composeFoundation: "androidx.compose.foundation:foundation:${versions.androidx.compose}",
composeMaterial: "androidx.compose.material:material:${versions.androidx.compose}",
composeAnimation: "androidx.compose.animation:animation:${versions.androidx.compose.libraries}",
composeCompiler: "androidx.compose.compiler:compiler:${versions.androidx.compose.compiler}",
composeFoundation: "androidx.compose.foundation:foundation:${versions.androidx.compose.libraries}",
composeMaterial: "androidx.compose.material:material:${versions.androidx.compose.libraries}",
composeNavigation: "androidx.navigation:navigation-compose:2.4.0-alpha03",
composeRuntimeRxJava2: "androidx.compose.runtime:runtime-rxjava2:${versions.androidx.compose}",
composeUi: "androidx.compose.ui:ui:${versions.androidx.compose}",
composeUiTooling: "androidx.compose.ui:ui-tooling:${versions.androidx.compose}",
composeRuntimeRxJava2: "androidx.compose.runtime:runtime-rxjava2:${versions.androidx.compose.libraries}",
composeUi: "androidx.compose.ui:ui:${versions.androidx.compose.libraries}",
composeUiTooling: "androidx.compose.ui:ui-tooling:${versions.androidx.compose.libraries}",
composeViewModel: "androidx.lifecycle:lifecycle-viewmodel-compose:1.0.0-alpha05",
percent: "androidx.percentlayout:percentlayout:${versions.androidx.percent}"
percent: "androidx.percentlayout:percentlayout:${versions.androidx.percent}",
savedState: "androidx.savedstate:savedstate:${versions.androidx.savedState}"
]

def test = [
Expand Down Expand Up @@ -139,7 +143,6 @@ def uber = [
autodisposeErrorProne: "com.uber.autodispose:autodispose-error-prone:${versions.autodispose}",
motif: "com.uber.motif:motif:${versions.motif}",
motifCompiler: "com.uber.motif:motif-compiler:${versions.motif}",
rave: "com.uber:rave:${versions.rave}",
]

ext.deps = [
Expand Down
2 changes: 1 addition & 1 deletion android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-all.zip
2 changes: 1 addition & 1 deletion android/libraries/rib-android-compose/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ android {
compose true
}
composeOptions {
kotlinCompilerExtensionVersion deps.versions.androidx.compose
kotlinCompilerExtensionVersion deps.versions.androidx.compose.compiler
}

compileOptions {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ package com.uber.rib.core
* @param <R> the type of [Router].
*/
abstract class BasicInteractor<P : Any, R : Router<*>> protected constructor(
@JvmField protected open var presenter: P
protected open var presenter: P
) : Interactor<P, R>(presenter)
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,20 @@
package com.uber.rib.core

import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.TestCoroutineScope
import org.junit.rules.TestWatcher
import org.junit.runner.Description

/**
* RibCoroutinesRule is a Junit TestRule to act as a managed TestCoroutineScope in test and to facilitate install and cleanup of Test Dispatchers
*/
@ExperimentalCoroutinesApi
public class RibCoroutinesRule(public val ribDispatchers: TestRibDispatchers = TestRibDispatchers()) :
TestWatcher(),
TestCoroutineScope by TestCoroutineScope(ribDispatchers.Default) {
public class RibCoroutinesRule(public val ribDispatchers: TestRibDispatchers = TestRibDispatchers()) : TestWatcher() {

override fun starting(description: Description) {
ribDispatchers.installTestDispatchers()
}

override fun finished(description: Description) {
cleanupTestCoroutines()
ribDispatchers.cleanupTestDispatchers()
ribDispatchers.resetTestDispatchers()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,77 +23,77 @@ import io.reactivex.CompletableSource
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.cancel
import kotlinx.coroutines.test.TestCoroutineScope
import kotlinx.coroutines.test.TestScope
import kotlin.coroutines.CoroutineContext

@ExperimentalCoroutinesApi
/**
* returns the [TestCoroutineScope] override currently installed for testing.
* returns the [TestScope] override currently installed for testing.
*/
public val ScopeProvider.testCoroutineScopeOverride: TestCoroutineScope?
public val ScopeProvider.testScopeOverride: TestScope?
// Due to custom friend path usage, reference to LazyCoroutineScope will stay red in IDE
get() = synchronized(LazyCoroutineScope) {
val testScope = LazyCoroutineScope[this]
return if (testScope != null && testScope is TestCoroutineScope) testScope else null
return if (testScope != null && testScope is TestScope) testScope else null
}

/**
* Overrides [ScopeProvider.coroutineScope] with a [TestCoroutineScope] with lifecycle integration for testing.
* Accessible directly as [TestCoroutineScope] via [ScopeProvider.testCoroutineScopeOverride].
* Overrides [ScopeProvider.coroutineScope] with a [TestScope] with lifecycle integration for testing.
* Accessible directly as [TestScope] via [ScopeProvider.TestScopeOverride].
*/
@ExperimentalCoroutinesApi
public fun ScopeProvider.enableTestCoroutineScopeOverride(context: CoroutineContext = SupervisorJob()): Unit = synchronized(LazyCoroutineScope) {
LazyCoroutineScope[this] = asTestCoroutineScope(context)
public fun ScopeProvider.enableTestScopeOverride(context: CoroutineContext = SupervisorJob()): Unit = synchronized(LazyCoroutineScope) {
LazyCoroutineScope[this] = asTestScope(context)
}

/**
* Disables the [ScopeProvider.coroutineScope] override with [TestCoroutineScope]
* Disables the [ScopeProvider.coroutineScope] override with [TestScope]
*/
public fun ScopeProvider.disableTestCoroutineScopeOverride(): Unit = synchronized(LazyCoroutineScope) {
public fun ScopeProvider.disableTestScopeOverride(): Unit = synchronized(LazyCoroutineScope) {
LazyCoroutineScope[this] = null
}

/**
* returns the [TestCoroutineScope] override currently installed for testing.
* returns the [TestScope] override currently installed for testing.
*/
@ExperimentalCoroutinesApi
public val Application.testCoroutineScopeOverride: TestCoroutineScope?
public val Application.testScopeOverride: TestScope?
// Due to custom friend path usage, reference to LazyCoroutineScope will stay red in IDE
get() = synchronized(LazyCoroutineScope) {
val testScope = LazyCoroutineScope[this]
return if (testScope != null && testScope is TestCoroutineScope) testScope else null
return if (testScope != null && testScope is TestScope) testScope else null
}

/**
* Overrides [ScopeProvider.coroutineScope] with a [TestCoroutineScope] with lifecycle integration for testing.
* Accessible directly as [TestCoroutineScope] via [ScopeProvider.testCoroutineScopeOverride].
* Overrides [ScopeProvider.coroutineScope] with a [TestScope] with lifecycle integration for testing.
* Accessible directly as [TestScope] via [ScopeProvider.TestScopeOverride].
*/
@ExperimentalCoroutinesApi
public fun Application.enableTestCoroutineScopeOverride(context: CoroutineContext = SupervisorJob()): Unit = synchronized(LazyCoroutineScope) {
LazyCoroutineScope[this] = TestCoroutineScope(context)
public fun Application.enableTestScopeOverride(context: CoroutineContext = SupervisorJob()): Unit = synchronized(LazyCoroutineScope) {
LazyCoroutineScope[this] = TestScope(context)
}

/**
* Disables the [ScopeProvider.coroutineScope] override with [TestCoroutineScope]
* Disables the [ScopeProvider.coroutineScope] override with [TestScope]
*/
public fun Application.disableTestCoroutineScopeOverride(): Unit = synchronized(LazyCoroutineScope) {
public fun Application.disableTestScopeOverride(): Unit = synchronized(LazyCoroutineScope) {
LazyCoroutineScope[this] = null
}

/**
* Returns a new [TestCoroutineScope] from the [ScopeProvider]
* Returns a new [TestScope] from the [ScopeProvider]
*/
@ExperimentalCoroutinesApi
public fun ScopeProvider.asTestCoroutineScope(context: CoroutineContext = SupervisorJob()): TestCoroutineScope {
return requestScope().asTestCoroutineScope(context)
public fun ScopeProvider.asTestScope(context: CoroutineContext = SupervisorJob()): TestScope {
return requestScope().asTestScope(context)
}

/**
* Returns a new [TestCoroutineScope] from the [CompletableSource]
* Returns a new [TestScope] from the [CompletableSource]
*/
@ExperimentalCoroutinesApi
public fun CompletableSource.asTestCoroutineScope(context: CoroutineContext = SupervisorJob()): TestCoroutineScope {
val scope = TestCoroutineScope(context)
public fun CompletableSource.asTestScope(context: CoroutineContext = SupervisorJob()): TestScope {
val scope = TestScope(context)
Completable.wrap(this)
.autoDispose(scope)
.subscribe({ scope.cancel() }) { e -> scope.cancel("OnError", e) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,18 @@ package com.uber.rib.core
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.MainCoroutineDispatcher
import kotlinx.coroutines.test.TestCoroutineDispatcher
import kotlinx.coroutines.test.StandardTestDispatcher
import kotlinx.coroutines.test.TestDispatcher
import kotlinx.coroutines.test.UnconfinedTestDispatcher
import kotlinx.coroutines.test.resetMain
import kotlinx.coroutines.test.setMain

@ExperimentalCoroutinesApi
public data class TestRibDispatchers(
override val Default: TestCoroutineDispatcher = TestCoroutineDispatcher(),
override val IO: TestCoroutineDispatcher = TestCoroutineDispatcher(),
override val Unconfined: TestCoroutineDispatcher = TestCoroutineDispatcher(),
val MainTestDelegate: TestCoroutineDispatcher = TestCoroutineDispatcher()
override val Default: TestDispatcher = StandardTestDispatcher(),
override val IO: TestDispatcher = StandardTestDispatcher(),
override val Unconfined: TestDispatcher = UnconfinedTestDispatcher(),
val MainTestDelegate: TestDispatcher = StandardTestDispatcher()
) : RibDispatchersProvider {

public fun installTestDispatchers() {
Expand All @@ -36,13 +38,6 @@ public data class TestRibDispatchers(
RibCoroutinesConfig.dispatchers = this
}

public fun cleanupTestDispatchers() {
Default.cleanupTestCoroutines()
MainTestDelegate.cleanupTestCoroutines()
IO.cleanupTestCoroutines()
Unconfined.cleanupTestCoroutines()
}

public fun resetTestDispatchers() {
Dispatchers.resetMain()
RibCoroutinesConfig.dispatchers = DefaultRibDispatchers()
Expand Down
Loading

0 comments on commit 0149a48

Please sign in to comment.