diff --git a/android/conventions/src/main/kotlin/ribs.spotless-convention.gradle.kts b/android/conventions/src/main/kotlin/ribs.spotless-convention.gradle.kts index bf1fbe417..61404c8c7 100644 --- a/android/conventions/src/main/kotlin/ribs.spotless-convention.gradle.kts +++ b/android/conventions/src/main/kotlin/ribs.spotless-convention.gradle.kts @@ -19,7 +19,7 @@ plugins { val libs = the() -configure { +spotless { format("misc") { target("**/*.md", "**/.gitignore") trimTrailingWhitespace() @@ -31,6 +31,7 @@ configure { mapOf( "indent_size" to "2", "continuation_indent_size" to "4", + "ktlint_function_naming_ignore_when_annotated_with" to "Composable", ) ) ktfmt(libs.versions.ktfmt.get()).googleStyle() @@ -40,7 +41,7 @@ configure { } java { target("src/*/java/**/*.java") - googleJavaFormat(libs.versions.gjf.get()) + googleJavaFormat(libs.versions.google.java.format.get()) licenseHeaderFile(rootProject.file("config/spotless/copyright.java")) removeUnusedImports() trimTrailingWhitespace() diff --git a/android/demos/compose/src/main/kotlin/com/uber/rib/compose/root/RootActivity.kt b/android/demos/compose/src/main/kotlin/com/uber/rib/compose/root/RootActivity.kt index d3352d77b..a4a393aee 100644 --- a/android/demos/compose/src/main/kotlin/com/uber/rib/compose/root/RootActivity.kt +++ b/android/demos/compose/src/main/kotlin/com/uber/rib/compose/root/RootActivity.kt @@ -25,11 +25,10 @@ import motif.ScopeFactory class RootActivity : RibActivity() { - override fun createRouter(parentViewGroup: ViewGroup): ViewRouter<*, *> { - return ScopeFactory.create(Parent::class.java) + override fun createRouter(parentViewGroup: ViewGroup): ViewRouter<*, *> = + ScopeFactory.create(Parent::class.java) .rootScope(this, findViewById(android.R.id.content)) .router() - } @motif.Scope interface Parent : Creatable { diff --git a/android/demos/compose/src/main/kotlin/com/uber/rib/compose/root/RootRouter.kt b/android/demos/compose/src/main/kotlin/com/uber/rib/compose/root/RootRouter.kt index 0163591e3..ddd8d0821 100644 --- a/android/demos/compose/src/main/kotlin/com/uber/rib/compose/root/RootRouter.kt +++ b/android/demos/compose/src/main/kotlin/com/uber/rib/compose/root/RootRouter.kt @@ -18,11 +18,8 @@ package com.uber.rib.compose.root import com.uber.rib.compose.root.main.MainRouter import com.uber.rib.core.BasicViewRouter -class RootRouter( - view: RootView, - interactor: RootInteractor, - private val scope: RootScope, -) : BasicViewRouter(view, interactor) { +class RootRouter(view: RootView, interactor: RootInteractor, private val scope: RootScope) : + BasicViewRouter(view, interactor) { private var mainRouter: MainRouter? = null diff --git a/android/demos/compose/src/main/kotlin/com/uber/rib/compose/root/RootScope.kt b/android/demos/compose/src/main/kotlin/com/uber/rib/compose/root/RootScope.kt index 8cb96553c..79c440de0 100644 --- a/android/demos/compose/src/main/kotlin/com/uber/rib/compose/root/RootScope.kt +++ b/android/demos/compose/src/main/kotlin/com/uber/rib/compose/root/RootScope.kt @@ -41,23 +41,17 @@ interface RootScope { abstract fun presenter(): EmptyPresenter - fun view(parentViewGroup: ViewGroup): RootView { - return RootView(parentViewGroup.context) - } + fun view(parentViewGroup: ViewGroup): RootView = RootView(parentViewGroup.context) @Expose - fun analyticsClient(activity: RibActivity): AnalyticsClient { - return AnalyticsClientImpl(activity.application) - } + fun analyticsClient(activity: RibActivity): AnalyticsClient = + AnalyticsClientImpl(activity.application) @Expose - fun experimentClient(activity: RibActivity): ExperimentClient { - return ExperimentClientImpl(activity.application) - } + fun experimentClient(activity: RibActivity): ExperimentClient = + ExperimentClientImpl(activity.application) @Expose - fun loggerClient(activity: RibActivity): LoggerClient { - return LoggerClientImpl(activity.application) - } + fun loggerClient(activity: RibActivity): LoggerClient = LoggerClientImpl(activity.application) } } diff --git a/android/demos/compose/src/main/kotlin/com/uber/rib/compose/root/RootView.kt b/android/demos/compose/src/main/kotlin/com/uber/rib/compose/root/RootView.kt index 91cc8a0f5..92e11a439 100644 --- a/android/demos/compose/src/main/kotlin/com/uber/rib/compose/root/RootView.kt +++ b/android/demos/compose/src/main/kotlin/com/uber/rib/compose/root/RootView.kt @@ -23,11 +23,8 @@ import android.widget.TextView class RootView @JvmOverloads -constructor( - context: Context, - attrs: AttributeSet? = null, - defStyle: Int = 0, -) : FrameLayout(context, attrs, defStyle) { +constructor(context: Context, attrs: AttributeSet? = null, defStyle: Int = 0) : + FrameLayout(context, attrs, defStyle) { init { setBackgroundColor(Color.RED) @@ -35,7 +32,7 @@ constructor( TextView(context).apply { text = "root (view)" setTextColor(Color.WHITE) - }, + } ) } } diff --git a/android/demos/compose/src/main/kotlin/com/uber/rib/compose/root/main/AuthStream.kt b/android/demos/compose/src/main/kotlin/com/uber/rib/compose/root/main/AuthStream.kt index a39eacd55..7780eeef4 100644 --- a/android/demos/compose/src/main/kotlin/com/uber/rib/compose/root/main/AuthStream.kt +++ b/android/demos/compose/src/main/kotlin/com/uber/rib/compose/root/main/AuthStream.kt @@ -20,13 +20,13 @@ import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.flow.update class AuthStream { - private val _authFlow = MutableStateFlow(AuthInfo(false, "", "")) - private val authFlow = _authFlow.asStateFlow() + private val mutableAuthFlow = MutableStateFlow(AuthInfo(false, "", "")) + private val authFlow = mutableAuthFlow.asStateFlow() fun observe() = authFlow fun accept(value: AuthInfo) { - _authFlow.update { value } + mutableAuthFlow.update { value } } } diff --git a/android/demos/compose/src/main/kotlin/com/uber/rib/compose/root/main/MainScope.kt b/android/demos/compose/src/main/kotlin/com/uber/rib/compose/root/main/MainScope.kt index c167261e6..1c04d6e6f 100644 --- a/android/demos/compose/src/main/kotlin/com/uber/rib/compose/root/main/MainScope.kt +++ b/android/demos/compose/src/main/kotlin/com/uber/rib/compose/root/main/MainScope.kt @@ -46,15 +46,12 @@ interface MainScope { analyticsClient: AnalyticsClient, experimentClient: ExperimentClient, loggerClient: LoggerClient, - ): ComposePresenter { - return object : ComposePresenter() { + ): ComposePresenter = + object : ComposePresenter() { override val composable = @Composable { MainView(childContent) } } - } - fun view(parentViewGroup: ViewGroup): ComposeView { - return ComposeView(parentViewGroup.context) - } + fun view(parentViewGroup: ViewGroup): ComposeView = ComposeView(parentViewGroup.context) abstract fun childContent(): MainRouter.ChildContent diff --git a/android/demos/compose/src/main/kotlin/com/uber/rib/compose/root/main/MainView.kt b/android/demos/compose/src/main/kotlin/com/uber/rib/compose/root/main/MainView.kt index fdb483787..89dace8c2 100644 --- a/android/demos/compose/src/main/kotlin/com/uber/rib/compose/root/main/MainView.kt +++ b/android/demos/compose/src/main/kotlin/com/uber/rib/compose/root/main/MainView.kt @@ -39,9 +39,7 @@ fun MainView(childContent: MainRouter.ChildContent) { Modifier.fillMaxSize().padding(all = 4.dp).padding(top = 14.dp).background(Color(0xFFFFA500)), ) { Text("Main RIB (Compose w/ CompView)") - Box( - modifier = Modifier.fillMaxWidth().weight(1.0f).padding(4.dp).background(Color.Yellow), - ) { + Box(modifier = Modifier.fillMaxWidth().weight(1.0f).padding(4.dp).background(Color.Yellow)) { childContent.fullScreenSlot.value.invoke() } } diff --git a/android/demos/compose/src/main/kotlin/com/uber/rib/compose/root/main/loggedin/LoggedInScope.kt b/android/demos/compose/src/main/kotlin/com/uber/rib/compose/root/main/loggedin/LoggedInScope.kt index 8661adc18..a5abb71ab 100644 --- a/android/demos/compose/src/main/kotlin/com/uber/rib/compose/root/main/loggedin/LoggedInScope.kt +++ b/android/demos/compose/src/main/kotlin/com/uber/rib/compose/root/main/loggedin/LoggedInScope.kt @@ -48,18 +48,16 @@ interface LoggedInScope { fun presenter( eventStream: EventStream, childContent: LoggedInRouter.ChildContent, - ): ComposePresenter { - return object : ComposePresenter() { + ): ComposePresenter = + object : ComposePresenter() { override val composable = @Composable { LoggedInView(eventStream, childContent) } } - } fun eventStream() = EventStream() @Expose - fun scoreSteam(authInfo: AuthInfo): ScoreStream { - return ScoreStream(authInfo.playerOne, authInfo.playerTwo) - } + fun scoreSteam(authInfo: AuthInfo): ScoreStream = + ScoreStream(authInfo.playerOne, authInfo.playerTwo) @Expose abstract fun startGameListener(interactor: LoggedInInteractor): OffGameInteractor.Listener diff --git a/android/demos/compose/src/main/kotlin/com/uber/rib/compose/root/main/loggedin/LoggedInView.kt b/android/demos/compose/src/main/kotlin/com/uber/rib/compose/root/main/loggedin/LoggedInView.kt index 0e34472c4..09516bb99 100644 --- a/android/demos/compose/src/main/kotlin/com/uber/rib/compose/root/main/loggedin/LoggedInView.kt +++ b/android/demos/compose/src/main/kotlin/com/uber/rib/compose/root/main/loggedin/LoggedInView.kt @@ -46,9 +46,7 @@ fun LoggedInView( ) { Text("Logged In! (Compose RIB)") Spacer(Modifier.height(16.dp)) - Box( - modifier = Modifier.fillMaxWidth().weight(1.0f).padding(4.dp).background(Color.LightGray), - ) { + Box(modifier = Modifier.fillMaxWidth().weight(1.0f).padding(4.dp).background(Color.LightGray)) { childContent.fullScreenSlot.value.invoke() } CustomButton( diff --git a/android/demos/compose/src/main/kotlin/com/uber/rib/compose/root/main/loggedin/ScoreStream.kt b/android/demos/compose/src/main/kotlin/com/uber/rib/compose/root/main/loggedin/ScoreStream.kt index 0a4b0e7ce..413a270ba 100644 --- a/android/demos/compose/src/main/kotlin/com/uber/rib/compose/root/main/loggedin/ScoreStream.kt +++ b/android/demos/compose/src/main/kotlin/com/uber/rib/compose/root/main/loggedin/ScoreStream.kt @@ -23,18 +23,12 @@ import kotlinx.coroutines.withContext class ScoreStream(playerOne: String, playerTwo: String) { - private val _scoresFlow = - MutableStateFlow( - mapOf( - playerOne to 0, - playerTwo to 0, - ), - ) - private val scoresFlow = _scoresFlow.asStateFlow() + private val mutableScoresFlow = MutableStateFlow(mapOf(playerOne to 0, playerTwo to 0)) + private val scoresFlow = mutableScoresFlow.asStateFlow() suspend fun addVictory(userName: String) = withContext(RibDispatchers.Default) { - _scoresFlow.update { scores -> + mutableScoresFlow.update { scores -> scores .toMutableMap() .apply { diff --git a/android/demos/compose/src/main/kotlin/com/uber/rib/compose/root/main/loggedin/offgame/OffGameInteractor.kt b/android/demos/compose/src/main/kotlin/com/uber/rib/compose/root/main/loggedin/offgame/OffGameInteractor.kt index 687af4a80..3fc48b4c4 100644 --- a/android/demos/compose/src/main/kotlin/com/uber/rib/compose/root/main/loggedin/offgame/OffGameInteractor.kt +++ b/android/demos/compose/src/main/kotlin/com/uber/rib/compose/root/main/loggedin/offgame/OffGameInteractor.kt @@ -55,7 +55,7 @@ class OffGameInteractor( currentState.copy( playerOneWins = it[currentState.playerOne] ?: 0, playerTwoWins = it[currentState.playerTwo] ?: 0, - ), + ) ) } .launchIn(coroutineScope) diff --git a/android/demos/compose/src/main/kotlin/com/uber/rib/compose/root/main/loggedin/offgame/OffGameScope.kt b/android/demos/compose/src/main/kotlin/com/uber/rib/compose/root/main/loggedin/offgame/OffGameScope.kt index 7b5f2423e..831a89396 100644 --- a/android/demos/compose/src/main/kotlin/com/uber/rib/compose/root/main/loggedin/offgame/OffGameScope.kt +++ b/android/demos/compose/src/main/kotlin/com/uber/rib/compose/root/main/loggedin/offgame/OffGameScope.kt @@ -35,8 +35,8 @@ interface OffGameScope { fun presenter( stateStream: StateStream, eventStream: EventStream, - ): ComposePresenter { - return object : ComposePresenter() { + ): ComposePresenter = + object : ComposePresenter() { override val composable = @Composable { OffGameView( @@ -45,16 +45,10 @@ interface OffGameScope { ) } } - } fun eventStream() = EventStream() fun stateStream(authInfo: AuthInfo) = - StateStream( - OffGameViewModel( - playerOne = authInfo.playerOne, - playerTwo = authInfo.playerTwo, - ), - ) + StateStream(OffGameViewModel(playerOne = authInfo.playerOne, playerTwo = authInfo.playerTwo)) } } diff --git a/android/demos/compose/src/main/kotlin/com/uber/rib/compose/root/main/loggedin/tictactoe/Board.kt b/android/demos/compose/src/main/kotlin/com/uber/rib/compose/root/main/loggedin/tictactoe/Board.kt index dea8f8b9e..990427568 100644 --- a/android/demos/compose/src/main/kotlin/com/uber/rib/compose/root/main/loggedin/tictactoe/Board.kt +++ b/android/demos/compose/src/main/kotlin/com/uber/rib/compose/root/main/loggedin/tictactoe/Board.kt @@ -35,8 +35,8 @@ class Board @Inject constructor() { } /** Return true if the player with "theSeed" has won after placing at (currentRow, currentCol) */ - fun hasWon(theSeed: MarkerType): Boolean { - return (cells[currentRow][0] == theSeed && + fun hasWon(theSeed: MarkerType): Boolean = + (cells[currentRow][0] == theSeed && cells[currentRow][1] == theSeed && cells[currentRow][2] == theSeed || cells[0][currentCol] == theSeed && @@ -50,7 +50,6 @@ class Board @Inject constructor() { cells[0][2] == theSeed && cells[1][1] == theSeed && cells[2][0] == theSeed) - } enum class MarkerType { CROSS, diff --git a/android/demos/compose/src/main/kotlin/com/uber/rib/compose/root/main/loggedin/tictactoe/TicTacToeEvent.kt b/android/demos/compose/src/main/kotlin/com/uber/rib/compose/root/main/loggedin/tictactoe/TicTacToeEvent.kt index aaf55c55a..129d47c93 100644 --- a/android/demos/compose/src/main/kotlin/com/uber/rib/compose/root/main/loggedin/tictactoe/TicTacToeEvent.kt +++ b/android/demos/compose/src/main/kotlin/com/uber/rib/compose/root/main/loggedin/tictactoe/TicTacToeEvent.kt @@ -17,5 +17,6 @@ package com.uber.rib.compose.root.main.loggedin.tictactoe sealed class TicTacToeEvent { object XpButtonClick : TicTacToeEvent() + class BoardClick(val coordinate: BoardCoordinate) : TicTacToeEvent() } diff --git a/android/demos/compose/src/main/kotlin/com/uber/rib/compose/root/main/loggedin/tictactoe/TicTacToeInteractor.kt b/android/demos/compose/src/main/kotlin/com/uber/rib/compose/root/main/loggedin/tictactoe/TicTacToeInteractor.kt index b398c8d9e..5356a9cf1 100644 --- a/android/demos/compose/src/main/kotlin/com/uber/rib/compose/root/main/loggedin/tictactoe/TicTacToeInteractor.kt +++ b/android/demos/compose/src/main/kotlin/com/uber/rib/compose/root/main/loggedin/tictactoe/TicTacToeInteractor.kt @@ -76,12 +76,7 @@ class TicTacToeInteractor( } stateStream.dispatch( - stateStream - .current() - .copy( - board = board, - currentPlayer = newPlayerName, - ), + stateStream.current().copy(board = board, currentPlayer = newPlayerName) ) } TicTacToeEvent.XpButtonClick -> TODO("Go somewhere") diff --git a/android/demos/compose/src/main/kotlin/com/uber/rib/compose/root/main/loggedin/tictactoe/TicTacToeScope.kt b/android/demos/compose/src/main/kotlin/com/uber/rib/compose/root/main/loggedin/tictactoe/TicTacToeScope.kt index 354c36837..a30f4a0c7 100644 --- a/android/demos/compose/src/main/kotlin/com/uber/rib/compose/root/main/loggedin/tictactoe/TicTacToeScope.kt +++ b/android/demos/compose/src/main/kotlin/com/uber/rib/compose/root/main/loggedin/tictactoe/TicTacToeScope.kt @@ -35,8 +35,8 @@ interface TicTacToeScope { fun presenter( stateStream: StateStream, eventStream: EventStream, - ): ComposePresenter { - return object : ComposePresenter() { + ): ComposePresenter = + object : ComposePresenter() { override val composable = @Composable { TicTacToeView( @@ -45,7 +45,6 @@ interface TicTacToeScope { ) } } - } fun eventStream() = EventStream() diff --git a/android/demos/compose/src/main/kotlin/com/uber/rib/compose/root/main/loggedin/tictactoe/TicTacToeView.kt b/android/demos/compose/src/main/kotlin/com/uber/rib/compose/root/main/loggedin/tictactoe/TicTacToeView.kt index 7630ae797..a7dfcc6f7 100644 --- a/android/demos/compose/src/main/kotlin/com/uber/rib/compose/root/main/loggedin/tictactoe/TicTacToeView.kt +++ b/android/demos/compose/src/main/kotlin/com/uber/rib/compose/root/main/loggedin/tictactoe/TicTacToeView.kt @@ -49,9 +49,7 @@ fun TicTacToeView(viewModel: State, eventStream: EventStream modifier = Modifier.fillMaxSize().background(Color.Blue), ) { Text("Current Player: ${viewModel.value.currentPlayer}", color = Color.White) - Box( - modifier = Modifier.aspectRatio(1f).fillMaxSize(), - ) { + Box(modifier = Modifier.aspectRatio(1f).fillMaxSize()) { LazyVerticalGrid(columns = GridCells.Fixed(3), modifier = Modifier.fillMaxSize()) { val board = viewModel.value.board items(9) { i -> diff --git a/android/demos/compose/src/main/kotlin/com/uber/rib/compose/root/main/loggedin/tictactoe/TicTacToeViewModel.kt b/android/demos/compose/src/main/kotlin/com/uber/rib/compose/root/main/loggedin/tictactoe/TicTacToeViewModel.kt index 0b4518666..9ef75726a 100644 --- a/android/demos/compose/src/main/kotlin/com/uber/rib/compose/root/main/loggedin/tictactoe/TicTacToeViewModel.kt +++ b/android/demos/compose/src/main/kotlin/com/uber/rib/compose/root/main/loggedin/tictactoe/TicTacToeViewModel.kt @@ -15,7 +15,4 @@ */ package com.uber.rib.compose.root.main.loggedin.tictactoe -data class TicTacToeViewModel( - val currentPlayer: String, - val board: Board, -) +data class TicTacToeViewModel(val currentPlayer: String, val board: Board) diff --git a/android/demos/compose/src/main/kotlin/com/uber/rib/compose/root/main/loggedout/LoggedOutEvent.kt b/android/demos/compose/src/main/kotlin/com/uber/rib/compose/root/main/loggedout/LoggedOutEvent.kt index 19932a67f..444a9071f 100644 --- a/android/demos/compose/src/main/kotlin/com/uber/rib/compose/root/main/loggedout/LoggedOutEvent.kt +++ b/android/demos/compose/src/main/kotlin/com/uber/rib/compose/root/main/loggedout/LoggedOutEvent.kt @@ -17,5 +17,6 @@ package com.uber.rib.compose.root.main.loggedout sealed class LoggedOutEvent { class PlayerNameChanged(val name: String, val num: Int) : LoggedOutEvent() + object LogInClick : LoggedOutEvent() } diff --git a/android/demos/compose/src/main/kotlin/com/uber/rib/compose/root/main/loggedout/LoggedOutInteractor.kt b/android/demos/compose/src/main/kotlin/com/uber/rib/compose/root/main/loggedout/LoggedOutInteractor.kt index d0d479df5..d2cc275de 100644 --- a/android/demos/compose/src/main/kotlin/com/uber/rib/compose/root/main/loggedout/LoggedOutInteractor.kt +++ b/android/demos/compose/src/main/kotlin/com/uber/rib/compose/root/main/loggedout/LoggedOutInteractor.kt @@ -45,7 +45,7 @@ class LoggedOutInteractor( .copy( playerOne = if (it.num == 1) it.name else current().playerOne, playerTwo = if (it.num == 2) it.name else current().playerTwo, - ), + ) ) } } diff --git a/android/demos/compose/src/main/kotlin/com/uber/rib/compose/root/main/loggedout/LoggedOutScope.kt b/android/demos/compose/src/main/kotlin/com/uber/rib/compose/root/main/loggedout/LoggedOutScope.kt index 900f07d50..7867b3a7c 100644 --- a/android/demos/compose/src/main/kotlin/com/uber/rib/compose/root/main/loggedout/LoggedOutScope.kt +++ b/android/demos/compose/src/main/kotlin/com/uber/rib/compose/root/main/loggedout/LoggedOutScope.kt @@ -34,8 +34,8 @@ interface LoggedOutScope { fun presenter( stateStream: StateStream, eventStream: EventStream, - ): ComposePresenter { - return object : ComposePresenter() { + ): ComposePresenter = + object : ComposePresenter() { override val composable = @Composable { LoggedOutView( @@ -44,7 +44,6 @@ interface LoggedOutScope { ) } } - } fun eventStream() = EventStream() diff --git a/android/demos/compose/src/main/kotlin/com/uber/rib/compose/root/main/loggedout/LoggedOutView.kt b/android/demos/compose/src/main/kotlin/com/uber/rib/compose/root/main/loggedout/LoggedOutView.kt index 82f479a10..e7d4ee5dd 100644 --- a/android/demos/compose/src/main/kotlin/com/uber/rib/compose/root/main/loggedout/LoggedOutView.kt +++ b/android/demos/compose/src/main/kotlin/com/uber/rib/compose/root/main/loggedout/LoggedOutView.kt @@ -55,10 +55,7 @@ fun LoggedOutView(viewModel: State, eventStream: EventStream ) Button( colors = - ButtonDefaults.buttonColors( - backgroundColor = Color.Black, - contentColor = Color.White, - ), + ButtonDefaults.buttonColors(backgroundColor = Color.Black, contentColor = Color.White), onClick = { eventStream.notify(LoggedOutEvent.LogInClick) }, modifier = Modifier.fillMaxWidth(), ) { diff --git a/android/demos/compose/src/main/kotlin/com/uber/rib/compose/root/main/loggedout/LoggedOutViewModel.kt b/android/demos/compose/src/main/kotlin/com/uber/rib/compose/root/main/loggedout/LoggedOutViewModel.kt index e98444537..ae45a01d0 100644 --- a/android/demos/compose/src/main/kotlin/com/uber/rib/compose/root/main/loggedout/LoggedOutViewModel.kt +++ b/android/demos/compose/src/main/kotlin/com/uber/rib/compose/root/main/loggedout/LoggedOutViewModel.kt @@ -15,7 +15,4 @@ */ package com.uber.rib.compose.root.main.loggedout -data class LoggedOutViewModel( - val playerOne: String = "", - val playerTwo: String = "", -) +data class LoggedOutViewModel(val playerOne: String = "", val playerTwo: String = "") diff --git a/android/demos/compose/src/main/kotlin/com/uber/rib/compose/util/AnalyticsClient.kt b/android/demos/compose/src/main/kotlin/com/uber/rib/compose/util/AnalyticsClient.kt index fa6d47bcd..b8f4d3bd9 100644 --- a/android/demos/compose/src/main/kotlin/com/uber/rib/compose/util/AnalyticsClient.kt +++ b/android/demos/compose/src/main/kotlin/com/uber/rib/compose/util/AnalyticsClient.kt @@ -42,10 +42,12 @@ class AnalyticsClientImpl(private val application: Application) : AnalyticsClien object NoOpAnalyticsClient : AnalyticsClient { override fun trackClick(id: String) = Unit + override fun trackImpression(id: String) = Unit } interface AnalyticsClient { fun trackClick(id: String) + fun trackImpression(id: String) } diff --git a/android/demos/compose/src/main/kotlin/com/uber/rib/compose/util/EventStream.kt b/android/demos/compose/src/main/kotlin/com/uber/rib/compose/util/EventStream.kt index aad65b83b..d7234a83e 100644 --- a/android/demos/compose/src/main/kotlin/com/uber/rib/compose/util/EventStream.kt +++ b/android/demos/compose/src/main/kotlin/com/uber/rib/compose/util/EventStream.kt @@ -19,10 +19,10 @@ import kotlinx.coroutines.flow.MutableSharedFlow import kotlinx.coroutines.flow.asSharedFlow class EventStream { - private val _sharedFlow = MutableSharedFlow(extraBufferCapacity = 1) - private val sharedFlow = _sharedFlow.asSharedFlow() + private val mutableEventFlow = MutableSharedFlow(extraBufferCapacity = 1) + private val eventFlow = mutableEventFlow.asSharedFlow() - fun notify(event: T) = _sharedFlow.tryEmit(event) + fun notify(event: T) = mutableEventFlow.tryEmit(event) - fun observe() = sharedFlow + fun observe() = eventFlow } diff --git a/android/demos/compose/src/main/kotlin/com/uber/rib/compose/util/StateStream.kt b/android/demos/compose/src/main/kotlin/com/uber/rib/compose/util/StateStream.kt index c3039c1e5..70cbba316 100644 --- a/android/demos/compose/src/main/kotlin/com/uber/rib/compose/util/StateStream.kt +++ b/android/demos/compose/src/main/kotlin/com/uber/rib/compose/util/StateStream.kt @@ -20,10 +20,10 @@ import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.flow.update class StateStream(default: T) { - private val _stateFlow = MutableStateFlow(default) - private val stateFlow = _stateFlow.asStateFlow() + private val mutableStateFlow = MutableStateFlow(default) + private val stateFlow = mutableStateFlow.asStateFlow() - fun dispatch(viewModel: T) = _stateFlow.update { viewModel } + fun dispatch(viewModel: T) = mutableStateFlow.update { viewModel } fun observe() = stateFlow diff --git a/android/demos/rib-workers/src/main/kotlin/com/uber/rib/workers/root/RootActivity.kt b/android/demos/rib-workers/src/main/kotlin/com/uber/rib/workers/root/RootActivity.kt index 2d9b08e8e..a3c07a005 100644 --- a/android/demos/rib-workers/src/main/kotlin/com/uber/rib/workers/root/RootActivity.kt +++ b/android/demos/rib-workers/src/main/kotlin/com/uber/rib/workers/root/RootActivity.kt @@ -26,11 +26,10 @@ import motif.ScopeFactory class RootActivity : RibActivity() { - override fun createRouter(parentViewGroup: ViewGroup): ViewRouter<*, *> { - return ScopeFactory.create(Parent::class.java) + override fun createRouter(parentViewGroup: ViewGroup): ViewRouter<*, *> = + ScopeFactory.create(Parent::class.java) .rootScope(application, this, findViewById(android.R.id.content)) .router() - } @motif.Scope interface Parent : Creatable { diff --git a/android/demos/rib-workers/src/main/kotlin/com/uber/rib/workers/root/RootInteractor.kt b/android/demos/rib-workers/src/main/kotlin/com/uber/rib/workers/root/RootInteractor.kt index a5d310f58..2d032d39a 100644 --- a/android/demos/rib-workers/src/main/kotlin/com/uber/rib/workers/root/RootInteractor.kt +++ b/android/demos/rib-workers/src/main/kotlin/com/uber/rib/workers/root/RootInteractor.kt @@ -18,6 +18,5 @@ package com.uber.rib.workers.root import com.uber.rib.core.BasicInteractor import com.uber.rib.core.EmptyPresenter -class RootInteractor( - presenter: EmptyPresenter, -) : BasicInteractor(presenter) +class RootInteractor(presenter: EmptyPresenter) : + BasicInteractor(presenter) diff --git a/android/demos/rib-workers/src/main/kotlin/com/uber/rib/workers/root/RootRouter.kt b/android/demos/rib-workers/src/main/kotlin/com/uber/rib/workers/root/RootRouter.kt index ecf3ac1fb..a1676242b 100644 --- a/android/demos/rib-workers/src/main/kotlin/com/uber/rib/workers/root/RootRouter.kt +++ b/android/demos/rib-workers/src/main/kotlin/com/uber/rib/workers/root/RootRouter.kt @@ -18,11 +18,8 @@ package com.uber.rib.workers.root import com.uber.rib.core.BasicViewRouter import com.uber.rib.workers.root.main.MainRouter -class RootRouter( - view: RootView, - interactor: RootInteractor, - private val scope: RootScope, -) : BasicViewRouter(view, interactor) { +class RootRouter(view: RootView, interactor: RootInteractor, private val scope: RootScope) : + BasicViewRouter(view, interactor) { private var mainRouter: MainRouter? = null diff --git a/android/demos/rib-workers/src/main/kotlin/com/uber/rib/workers/root/RootScope.kt b/android/demos/rib-workers/src/main/kotlin/com/uber/rib/workers/root/RootScope.kt index e7228f698..e4118ee46 100644 --- a/android/demos/rib-workers/src/main/kotlin/com/uber/rib/workers/root/RootScope.kt +++ b/android/demos/rib-workers/src/main/kotlin/com/uber/rib/workers/root/RootScope.kt @@ -33,8 +33,6 @@ interface RootScope { abstract fun presenter(): EmptyPresenter - fun view(parentViewGroup: ViewGroup): RootView { - return RootView(parentViewGroup.context) - } + fun view(parentViewGroup: ViewGroup): RootView = RootView(parentViewGroup.context) } } diff --git a/android/demos/rib-workers/src/main/kotlin/com/uber/rib/workers/root/RootView.kt b/android/demos/rib-workers/src/main/kotlin/com/uber/rib/workers/root/RootView.kt index 85a594596..5ac77199e 100644 --- a/android/demos/rib-workers/src/main/kotlin/com/uber/rib/workers/root/RootView.kt +++ b/android/demos/rib-workers/src/main/kotlin/com/uber/rib/workers/root/RootView.kt @@ -21,8 +21,5 @@ import android.widget.FrameLayout class RootView @JvmOverloads -constructor( - context: Context, - attrs: AttributeSet? = null, - defStyle: Int = 0, -) : FrameLayout(context, attrs, defStyle) +constructor(context: Context, attrs: AttributeSet? = null, defStyle: Int = 0) : + FrameLayout(context, attrs, defStyle) diff --git a/android/demos/rib-workers/src/main/kotlin/com/uber/rib/workers/root/main/MainScope.kt b/android/demos/rib-workers/src/main/kotlin/com/uber/rib/workers/root/main/MainScope.kt index 08b05822b..6f072e7aa 100644 --- a/android/demos/rib-workers/src/main/kotlin/com/uber/rib/workers/root/main/MainScope.kt +++ b/android/demos/rib-workers/src/main/kotlin/com/uber/rib/workers/root/main/MainScope.kt @@ -34,17 +34,12 @@ interface MainScope { abstract fun interactor(): MainInteractor - fun presenter( - childContent: MainRouter.ChildContent, - ): ComposePresenter { - return object : ComposePresenter() { + fun presenter(childContent: MainRouter.ChildContent): ComposePresenter = + object : ComposePresenter() { override val composable = @Composable { MainView(childContent) } } - } - fun view(parentViewGroup: ViewGroup): ComposeView { - return ComposeView(parentViewGroup.context) - } + fun view(parentViewGroup: ViewGroup): ComposeView = ComposeView(parentViewGroup.context) abstract fun childContent(): MainRouter.ChildContent } diff --git a/android/demos/rib-workers/src/main/kotlin/com/uber/rib/workers/root/main/MainView.kt b/android/demos/rib-workers/src/main/kotlin/com/uber/rib/workers/root/main/MainView.kt index b1ceaad6d..d3cb9d89a 100644 --- a/android/demos/rib-workers/src/main/kotlin/com/uber/rib/workers/root/main/MainView.kt +++ b/android/demos/rib-workers/src/main/kotlin/com/uber/rib/workers/root/main/MainView.kt @@ -36,9 +36,7 @@ fun MainView(childContent: MainRouter.ChildContent) { verticalArrangement = Arrangement.Top, modifier = Modifier.fillMaxSize().padding(all = 4.dp).padding(top = 14.dp), ) { - Box( - modifier = Modifier.fillMaxWidth().weight(1.0f).padding(4.dp).background(Color.White), - ) { + Box(modifier = Modifier.fillMaxWidth().weight(1.0f).padding(4.dp).background(Color.White)) { childContent.fullScreenSlot.value.invoke() } } diff --git a/android/demos/rib-workers/src/main/kotlin/com/uber/rib/workers/root/main/ribworkerselection/RibWorkerSelectionInteractor.kt b/android/demos/rib-workers/src/main/kotlin/com/uber/rib/workers/root/main/ribworkerselection/RibWorkerSelectionInteractor.kt index 4a94dfa08..281bc0e30 100644 --- a/android/demos/rib-workers/src/main/kotlin/com/uber/rib/workers/root/main/ribworkerselection/RibWorkerSelectionInteractor.kt +++ b/android/demos/rib-workers/src/main/kotlin/com/uber/rib/workers/root/main/ribworkerselection/RibWorkerSelectionInteractor.kt @@ -93,14 +93,7 @@ class RibWorkerSelectionInteractor( } private fun updateViewModel(workerBound: String?) { - with(stateStream) { - dispatch( - current() - .copy( - workerInfo = workerBound + WORKER_BOUND_MESSAGE, - ), - ) - } + with(stateStream) { dispatch(current().copy(workerInfo = workerBound + WORKER_BOUND_MESSAGE)) } } private companion object { diff --git a/android/demos/rib-workers/src/main/kotlin/com/uber/rib/workers/root/main/ribworkerselection/RibWorkerSelectionScope.kt b/android/demos/rib-workers/src/main/kotlin/com/uber/rib/workers/root/main/ribworkerselection/RibWorkerSelectionScope.kt index 2ea258f14..2edfc1fda 100644 --- a/android/demos/rib-workers/src/main/kotlin/com/uber/rib/workers/root/main/ribworkerselection/RibWorkerSelectionScope.kt +++ b/android/demos/rib-workers/src/main/kotlin/com/uber/rib/workers/root/main/ribworkerselection/RibWorkerSelectionScope.kt @@ -40,8 +40,8 @@ interface RibWorkerSelectionScope { fun presenter( stateStream: StateStream, eventStream: EventStream, - ): ComposePresenter { - return object : ComposePresenter() { + ): ComposePresenter = + object : ComposePresenter() { override val composable = @Composable { RibWorkerSelectionView( @@ -50,7 +50,6 @@ interface RibWorkerSelectionScope { ) } } - } fun eventStream() = EventStream() diff --git a/android/demos/rib-workers/src/main/kotlin/com/uber/rib/workers/root/main/ribworkerselection/RibWorkerSelectionView.kt b/android/demos/rib-workers/src/main/kotlin/com/uber/rib/workers/root/main/ribworkerselection/RibWorkerSelectionView.kt index a1b55db5e..4a1f9f846 100644 --- a/android/demos/rib-workers/src/main/kotlin/com/uber/rib/workers/root/main/ribworkerselection/RibWorkerSelectionView.kt +++ b/android/demos/rib-workers/src/main/kotlin/com/uber/rib/workers/root/main/ribworkerselection/RibWorkerSelectionView.kt @@ -85,10 +85,7 @@ fun RibWorkerSelectionView( "RibCoroutineWorker <> Worker", ) - Text( - viewModel.value.workerInfo, - modifier = Modifier.fillMaxSize(), - ) + Text(viewModel.value.workerInfo, modifier = Modifier.fillMaxSize()) } } @@ -99,11 +96,7 @@ fun AddButton( buttonText: String, ) { Button( - colors = - ButtonDefaults.buttonColors( - backgroundColor = Color.Black, - contentColor = Color.White, - ), + colors = ButtonDefaults.buttonColors(backgroundColor = Color.Black, contentColor = Color.White), onClick = { eventStream.notify(ribWorkerBindTypeClickType) }, modifier = Modifier.fillMaxWidth(), ) { diff --git a/android/demos/rib-workers/src/main/kotlin/com/uber/rib/workers/root/main/ribworkerselection/RibWorkerSelectionViewModel.kt b/android/demos/rib-workers/src/main/kotlin/com/uber/rib/workers/root/main/ribworkerselection/RibWorkerSelectionViewModel.kt index bd63a9ff9..008a064c5 100644 --- a/android/demos/rib-workers/src/main/kotlin/com/uber/rib/workers/root/main/ribworkerselection/RibWorkerSelectionViewModel.kt +++ b/android/demos/rib-workers/src/main/kotlin/com/uber/rib/workers/root/main/ribworkerselection/RibWorkerSelectionViewModel.kt @@ -15,6 +15,4 @@ */ package com.uber.rib.workers.root.main.ribworkerselection -data class RibWorkerSelectionViewModel( - val workerInfo: String = "", -) +data class RibWorkerSelectionViewModel(val workerInfo: String = "") diff --git a/android/demos/rib-workers/src/main/kotlin/com/uber/rib/workers/root/main/workers/BackgroundWorker.kt b/android/demos/rib-workers/src/main/kotlin/com/uber/rib/workers/root/main/workers/BackgroundWorker.kt index 5a53d0c57..e89eaab96 100644 --- a/android/demos/rib-workers/src/main/kotlin/com/uber/rib/workers/root/main/workers/BackgroundWorker.kt +++ b/android/demos/rib-workers/src/main/kotlin/com/uber/rib/workers/root/main/workers/BackgroundWorker.kt @@ -21,7 +21,7 @@ import kotlin.coroutines.CoroutineContext import kotlinx.coroutines.asCoroutineDispatcher /** A Rib Worker to be guaranteed on a background thread with a limited pool size of 1 */ -class BackgroundWorker() : Worker { +class BackgroundWorker : Worker { override val coroutineContext: CoroutineContext = Executors.newFixedThreadPool(1).asCoroutineDispatcher() diff --git a/android/demos/rib-workers/src/main/kotlin/com/uber/rib/workers/root/main/workers/UiWorker.kt b/android/demos/rib-workers/src/main/kotlin/com/uber/rib/workers/root/main/workers/UiWorker.kt index cbaee3408..ee3d653b4 100644 --- a/android/demos/rib-workers/src/main/kotlin/com/uber/rib/workers/root/main/workers/UiWorker.kt +++ b/android/demos/rib-workers/src/main/kotlin/com/uber/rib/workers/root/main/workers/UiWorker.kt @@ -31,11 +31,6 @@ class UiWorker(private val activityContext: Application) : Worker { override val coroutineContext: CoroutineContext = RibDispatchers.Main override fun onStart(lifecycle: WorkerScopeProvider) { - Toast.makeText( - activityContext, - "Ui Worker (onStart) call", - Toast.LENGTH_LONG, - ) - .show() + Toast.makeText(activityContext, "Ui Worker (onStart) call", Toast.LENGTH_LONG).show() } } diff --git a/android/demos/rib-workers/src/main/kotlin/com/uber/rib/workers/util/EventStream.kt b/android/demos/rib-workers/src/main/kotlin/com/uber/rib/workers/util/EventStream.kt index 0e7d6496f..98a7916c0 100644 --- a/android/demos/rib-workers/src/main/kotlin/com/uber/rib/workers/util/EventStream.kt +++ b/android/demos/rib-workers/src/main/kotlin/com/uber/rib/workers/util/EventStream.kt @@ -19,10 +19,10 @@ import kotlinx.coroutines.flow.MutableSharedFlow import kotlinx.coroutines.flow.asSharedFlow class EventStream { - private val _sharedFlow = MutableSharedFlow(extraBufferCapacity = 1) - private val sharedFlow = _sharedFlow.asSharedFlow() + private val mutableEventFlow = MutableSharedFlow(extraBufferCapacity = 1) + private val eventFlow = mutableEventFlow.asSharedFlow() - fun notify(event: T) = _sharedFlow.tryEmit(event) + fun notify(event: T) = mutableEventFlow.tryEmit(event) - fun observe() = sharedFlow + fun observe() = eventFlow } diff --git a/android/demos/rib-workers/src/main/kotlin/com/uber/rib/workers/util/StateStream.kt b/android/demos/rib-workers/src/main/kotlin/com/uber/rib/workers/util/StateStream.kt index 627efbcbc..bae32027a 100644 --- a/android/demos/rib-workers/src/main/kotlin/com/uber/rib/workers/util/StateStream.kt +++ b/android/demos/rib-workers/src/main/kotlin/com/uber/rib/workers/util/StateStream.kt @@ -20,10 +20,10 @@ import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.flow.update class StateStream(default: T) { - private val _stateFlow = MutableStateFlow(default) - private val stateFlow = _stateFlow.asStateFlow() + private val mutableStateFlow = MutableStateFlow(default) + private val stateFlow = mutableStateFlow.asStateFlow() - fun dispatch(viewModel: T) = _stateFlow.update { viewModel } + fun dispatch(viewModel: T) = mutableStateFlow.update { viewModel } fun observe() = stateFlow diff --git a/android/gradle/libs.versions.toml b/android/gradle/libs.versions.toml index 3004d9c4e..a85a57ca1 100644 --- a/android/gradle/libs.versions.toml +++ b/android/gradle/libs.versions.toml @@ -18,13 +18,13 @@ dagger = "2.43.2" errorprone = "2.3.3" errorprone-javac = "9+181-r4173-1" flipper = "0.93.0" -gjf = "1.16.0" +google-java-format = "1.24.0" gradle-android-plugin = "7.4.2" gradle-errorprone-plugin = "1.3.0" gradle-intellij-plugin = "1.15.0" gradle-maven-publish-plugin = "0.25.2" gradle-nullaway-plugin = "1.0.2" -gradle-spotless-plugin = "6.18.0" +gradle-spotless-plugin = "6.25.0" gson = "2.8.7" guava-android = "27.1-android" guava-jre = "27.1-jre" @@ -34,8 +34,8 @@ jsr250 = "1.0" junit = "4.12" kotlin = "1.8.20" kotlinx-coroutines = "1.7.3" -ktfmt = "0.43" -ktlint = "0.48.2" +ktfmt = "0.52" +ktlint = "1.3.1" leakcanary = "1.5.4" mockito = "4.6.1" mockito-kotlin = "4.0.0" diff --git a/android/libraries/rib-android-core/src/main/kotlin/com/uber/rib/core/ActivityDelegate.kt b/android/libraries/rib-android-core/src/main/kotlin/com/uber/rib/core/ActivityDelegate.kt index c2b391621..bc20f1f73 100644 --- a/android/libraries/rib-android-core/src/main/kotlin/com/uber/rib/core/ActivityDelegate.kt +++ b/android/libraries/rib-android-core/src/main/kotlin/com/uber/rib/core/ActivityDelegate.kt @@ -45,12 +45,7 @@ interface ActivityDelegate { fun onDestroy() {} /** @see [Activity.onActivityResult] */ - fun onActivityResult( - activity: Activity, - requestCode: Int, - resultCode: Int, - data: Intent?, - ) {} + fun onActivityResult(activity: Activity, requestCode: Int, resultCode: Int, data: Intent?) {} /** @see [Activity.onRequestPermissionsResult] */ fun onRequestPermissionsResult( diff --git a/android/libraries/rib-android/src/main/kotlin/com/uber/rib/core/BasicViewRouter.kt b/android/libraries/rib-android/src/main/kotlin/com/uber/rib/core/BasicViewRouter.kt index bfd1ec88a..a59ceace0 100644 --- a/android/libraries/rib-android/src/main/kotlin/com/uber/rib/core/BasicViewRouter.kt +++ b/android/libraries/rib-android/src/main/kotlin/com/uber/rib/core/BasicViewRouter.kt @@ -22,7 +22,5 @@ import android.view.View * * @param type of interactor. */ -abstract class BasicViewRouter>( - view: V, - interactor: I, -) : ViewRouter(view, interactor) +abstract class BasicViewRouter>(view: V, interactor: I) : + ViewRouter(view, interactor) diff --git a/android/libraries/rib-android/src/main/kotlin/com/uber/rib/core/RibActivity.kt b/android/libraries/rib-android/src/main/kotlin/com/uber/rib/core/RibActivity.kt index cdec97e19..1d4ea6f20 100644 --- a/android/libraries/rib-android/src/main/kotlin/com/uber/rib/core/RibActivity.kt +++ b/android/libraries/rib-android/src/main/kotlin/com/uber/rib/core/RibActivity.kt @@ -15,6 +15,7 @@ */ package com.uber.rib.core +import android.annotation.SuppressLint import android.content.Intent import android.content.res.Configuration import android.os.Build @@ -50,24 +51,24 @@ public abstract class RibActivity : RxActivityEvents { private var router: ViewRouter<*, *>? = null - private val _lifecycleFlow = + private val mutableLifecycleFlow = MutableSharedFlow(1, 0, BufferOverflow.DROP_OLDEST) public open val lifecycleFlow: SharedFlow - get() = _lifecycleFlow + get() = mutableLifecycleFlow - @Volatile private var _lifecycleObservable: Observable? = null + @Volatile private var mutableLifecycleObservable: Observable? = null private val lifecycleObservable - get() = ::_lifecycleObservable.setIfNullAndGet { lifecycleFlow.asObservable() } + get() = ::mutableLifecycleObservable.setIfNullAndGet { lifecycleFlow.asObservable() } - private val _callbacksFlow = + private val mutableCallbacksFlow = MutableSharedFlow(0, 1, BufferOverflow.DROP_OLDEST) public open val callbacksFlow: SharedFlow - get() = _callbacksFlow + get() = mutableCallbacksFlow - @Volatile private var _callbacksObservable: Observable? = null + @Volatile private var mutableCallbacksObservable: Observable? = null private val callbacksObservable - get() = ::_callbacksObservable.setIfNullAndGet { callbacksFlow.asObservable() } + get() = ::mutableCallbacksObservable.setIfNullAndGet { callbacksFlow.asObservable() } /** @return an observable of this activity's lifecycle events. */ final override fun lifecycle(): Observable = lifecycleObservable @@ -89,7 +90,7 @@ public abstract class RibActivity : override fun onCreate(savedInstanceState: android.os.Bundle?) { super.onCreate(savedInstanceState) val rootViewGroup = findViewById(android.R.id.content) - _lifecycleFlow.tryEmit(createOnCreateEvent(savedInstanceState)) + mutableLifecycleFlow.tryEmit(createOnCreateEvent(savedInstanceState)) val wrappedBundle: Bundle? = if (savedInstanceState != null) Bundle(savedInstanceState) else null router = createRouter(rootViewGroup) @@ -103,7 +104,7 @@ public abstract class RibActivity : @CallSuper override fun onSaveInstanceState(outState: android.os.Bundle) { super.onSaveInstanceState(outState) - _callbacksFlow.tryEmit(createOnSaveInstanceStateEvent(outState)) + mutableCallbacksFlow.tryEmit(createOnSaveInstanceStateEvent(outState)) router?.saveInstanceStateInternal(Bundle(outState)) ?: throw NullPointerException("Router should not be null") } @@ -111,42 +112,42 @@ public abstract class RibActivity : @CallSuper override fun onStart() { super.onStart() - _lifecycleFlow.tryEmit(create(ActivityLifecycleEvent.Type.START)) + mutableLifecycleFlow.tryEmit(create(ActivityLifecycleEvent.Type.START)) } @CallSuper override fun onResume() { super.onResume() - _lifecycleFlow.tryEmit(create(ActivityLifecycleEvent.Type.RESUME)) + mutableLifecycleFlow.tryEmit(create(ActivityLifecycleEvent.Type.RESUME)) } @CallSuper override fun onNewIntent(intent: Intent) { super.onNewIntent(intent) - _callbacksFlow.tryEmit(createNewIntent(intent)) + mutableCallbacksFlow.tryEmit(createNewIntent(intent)) } @CallSuper override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { super.onActivityResult(requestCode, resultCode, data) - _callbacksFlow.tryEmit(createOnActivityResultEvent(requestCode, resultCode, data)) + mutableCallbacksFlow.tryEmit(createOnActivityResultEvent(requestCode, resultCode, data)) } @CallSuper override fun onPause() { - _lifecycleFlow.tryEmit(create(ActivityLifecycleEvent.Type.PAUSE)) + mutableLifecycleFlow.tryEmit(create(ActivityLifecycleEvent.Type.PAUSE)) super.onPause() } @CallSuper override fun onStop() { - _lifecycleFlow.tryEmit(create(ActivityLifecycleEvent.Type.STOP)) + mutableLifecycleFlow.tryEmit(create(ActivityLifecycleEvent.Type.STOP)) super.onStop() } @CallSuper override fun onDestroy() { - _lifecycleFlow.tryEmit(create(ActivityLifecycleEvent.Type.DESTROY)) + mutableLifecycleFlow.tryEmit(create(ActivityLifecycleEvent.Type.DESTROY)) router?.let { it.dispatchDetach() RibEvents.emitRouterEvent(RibEventType.DETACHED, it, null) @@ -158,22 +159,21 @@ public abstract class RibActivity : @CallSuper override fun onLowMemory() { super.onLowMemory() - _callbacksFlow.tryEmit(create(ActivityCallbackEvent.Type.LOW_MEMORY)) + mutableCallbacksFlow.tryEmit(create(ActivityCallbackEvent.Type.LOW_MEMORY)) } @CallSuper override fun onTrimMemory(level: Int) { super.onTrimMemory(level) - _callbacksFlow.tryEmit(createTrimMemoryEvent(level)) + mutableCallbacksFlow.tryEmit(createTrimMemoryEvent(level)) } + @SuppressLint("MissingSuperCall") override fun onPictureInPictureModeChanged( isInPictureInPictureMode: Boolean, newConfig: Configuration, ) { - _callbacksFlow.tryEmit( - createPictureInPictureMode(isInPictureInPictureMode), - ) + mutableCallbacksFlow.tryEmit(createPictureInPictureMode(isInPictureInPictureMode)) } override fun onBackPressed() { @@ -194,13 +194,13 @@ public abstract class RibActivity : } override fun onUserLeaveHint() { - _lifecycleFlow.tryEmit(create(ActivityLifecycleEvent.Type.USER_LEAVING)) + mutableLifecycleFlow.tryEmit(create(ActivityLifecycleEvent.Type.USER_LEAVING)) super.onUserLeaveHint() } override fun onWindowFocusChanged(hasFocus: Boolean) { super.onWindowFocusChanged(hasFocus) - _callbacksFlow.tryEmit(createWindowFocusEvent(hasFocus)) + mutableCallbacksFlow.tryEmit(createWindowFocusEvent(hasFocus)) } /** @@ -219,7 +219,7 @@ public abstract class RibActivity : router?.interactor as Interactor<*, *> } else { throw IllegalStateException( - "Attempting to get a router when activity is not created or has been destroyed.", + "Attempting to get a router when activity is not created or has been destroyed." ) } @@ -244,9 +244,7 @@ public abstract class RibActivity : ActivityLifecycleEvent.Type.PAUSE -> create(ActivityLifecycleEvent.Type.STOP) ActivityLifecycleEvent.Type.STOP -> create(ActivityLifecycleEvent.Type.DESTROY) ActivityLifecycleEvent.Type.DESTROY -> - throw LifecycleEndedException( - "Cannot bind to Activity lifecycle when outside of it.", - ) + throw LifecycleEndedException("Cannot bind to Activity lifecycle when outside of it.") } } } diff --git a/android/libraries/rib-android/src/main/kotlin/com/uber/rib/core/RxActivityEvents.kt b/android/libraries/rib-android/src/main/kotlin/com/uber/rib/core/RxActivityEvents.kt index 1e83cdfd3..625f48a22 100644 --- a/android/libraries/rib-android/src/main/kotlin/com/uber/rib/core/RxActivityEvents.kt +++ b/android/libraries/rib-android/src/main/kotlin/com/uber/rib/core/RxActivityEvents.kt @@ -32,20 +32,18 @@ interface RxActivityEvents { * @param clazz The [ActivityLifecycleEvent] subclass you want. * @return an observable of this activity's lifecycle events. */ - fun lifecycle(clazz: Class): Observable { - return lifecycle() + fun lifecycle(clazz: Class): Observable = + lifecycle() .filter { activityEvent -> clazz.isAssignableFrom(activityEvent.javaClass) } .cast(clazz) - } /** * @param The type of [ActivityCallbackEvent] subclass you want. * @param clazz The [ActivityCallbackEvent] subclass you want. * @return an observable of this activity's callbacks events. */ - fun callbacks(clazz: Class): Observable { - return callbacks() + fun callbacks(clazz: Class): Observable = + callbacks() .filter { activityEvent -> clazz.isAssignableFrom(activityEvent.javaClass) } .cast(clazz) - } } diff --git a/android/libraries/rib-android/src/main/kotlin/com/uber/rib/core/ViewBuilder.kt b/android/libraries/rib-android/src/main/kotlin/com/uber/rib/core/ViewBuilder.kt index 6c236599e..4d194fcf1 100644 --- a/android/libraries/rib-android/src/main/kotlin/com/uber/rib/core/ViewBuilder.kt +++ b/android/libraries/rib-android/src/main/kotlin/com/uber/rib/core/ViewBuilder.kt @@ -28,7 +28,7 @@ import android.view.ViewGroup * @param dependency required to create this router. */ abstract class ViewBuilder, DependencyT>( - dependency: DependencyT, + dependency: DependencyT ) : Builder(dependency) { /** * Utility method to create the view for this router. @@ -59,7 +59,5 @@ abstract class ViewBuilder, DependencyT>( * overridden. * @return the possibly themed context. */ - protected open fun onThemeContext(parentContext: Context): Context { - return parentContext - } + protected open fun onThemeContext(parentContext: Context): Context = parentContext } diff --git a/android/libraries/rib-android/src/main/kotlin/com/uber/rib/core/ViewPresenter.kt b/android/libraries/rib-android/src/main/kotlin/com/uber/rib/core/ViewPresenter.kt index 8fd9d4f92..2edd7a81e 100644 --- a/android/libraries/rib-android/src/main/kotlin/com/uber/rib/core/ViewPresenter.kt +++ b/android/libraries/rib-android/src/main/kotlin/com/uber/rib/core/ViewPresenter.kt @@ -24,5 +24,5 @@ import android.view.View */ abstract class ViewPresenter( /** @return the view fronted by the page. */ - val view: V, + val view: V ) : Presenter() diff --git a/android/libraries/rib-android/src/main/kotlin/com/uber/rib/core/XRay.kt b/android/libraries/rib-android/src/main/kotlin/com/uber/rib/core/XRay.kt index 3e545702e..50ebfcccb 100644 --- a/android/libraries/rib-android/src/main/kotlin/com/uber/rib/core/XRay.kt +++ b/android/libraries/rib-android/src/main/kotlin/com/uber/rib/core/XRay.kt @@ -28,6 +28,7 @@ import android.view.View class XRay private constructor() { private var isEnabled = false private var textPaint: Paint? = null + private fun writeOnBitmap(bitmap: Bitmap, text: String) { val canvas = Canvas(bitmap) val textPaint = getTextPaint() @@ -62,10 +63,7 @@ class XRay private constructor() { } /** @return `true` if XRay is enabled, `false` otherwise. */ - @JvmStatic - fun isEnabled(): Boolean { - return INSTANCE.isEnabled - } + @JvmStatic fun isEnabled(): Boolean = INSTANCE.isEnabled /** * Puts [ViewBuilder]s riblet name in the background of the [View] @@ -110,8 +108,7 @@ class XRay private constructor() { return bitmap } - private fun getRibletName(viewRouter: ViewRouter<*, *>): String { - return viewRouter.javaClass.simpleName.replace("Router", "") - } + private fun getRibletName(viewRouter: ViewRouter<*, *>): String = + viewRouter.javaClass.simpleName.replace("Router", "") } } diff --git a/android/libraries/rib-android/src/main/kotlin/com/uber/rib/core/lifecycle/ActivityCallbackEvent.kt b/android/libraries/rib-android/src/main/kotlin/com/uber/rib/core/lifecycle/ActivityCallbackEvent.kt index f854bc315..9d199bf16 100644 --- a/android/libraries/rib-android/src/main/kotlin/com/uber/rib/core/lifecycle/ActivityCallbackEvent.kt +++ b/android/libraries/rib-android/src/main/kotlin/com/uber/rib/core/lifecycle/ActivityCallbackEvent.kt @@ -22,7 +22,7 @@ import android.os.Bundle open class ActivityCallbackEvent private constructor( /** @return this event's type. */ - override val type: Type, + override val type: Type ) : ActivityEvent { /** Types of activity events that can occur. */ @@ -38,6 +38,7 @@ private constructor( /** An [ActivityCallbackEvent] that represents [Activity.onNewIntent] event */ open class NewIntent(open val intent: Intent) : ActivityCallbackEvent(Type.NEW_INTENT) + open class PictureInPictureMode(open val isInPictureInPictureMode: Boolean) : ActivityCallbackEvent(Type.PICTURE_IN_PICTURE_MODE) @@ -63,7 +64,7 @@ private constructor( */ open class SaveInstanceState( /** @return this event's outState data. */ - open val outState: Bundle?, + open val outState: Bundle? ) : ActivityCallbackEvent(Type.SAVE_INSTANCE_STATE) companion object { @@ -82,9 +83,7 @@ private constructor( requestCode: Int, resultCode: Int, resultData: Intent?, - ): ActivityResult { - return ActivityResult(resultData, requestCode, resultCode) - } + ): ActivityResult = ActivityResult(resultData, requestCode, resultCode) /** * Creates an activity event for a given type. @@ -93,15 +92,14 @@ private constructor( * @return The corresponding ActivityEvent. */ @JvmStatic - fun create(type: Type): ActivityCallbackEvent { - return when (type) { + fun create(type: Type): ActivityCallbackEvent = + when (type) { Type.LOW_MEMORY -> LOW_MEMORY_EVENT else -> throw IllegalArgumentException( - "Use the createOn${type.name.toLowerCase().capitalize()}Event() method for this type!", + "Use the createOn${type.name.toLowerCase().capitalize()}Event() method for this type!" ) } - } /** * Creates an event for onSaveInstanceState. @@ -110,9 +108,8 @@ private constructor( * @return the created ActivityEvent. */ @JvmStatic - fun createOnSaveInstanceStateEvent(outState: Bundle?): ActivityCallbackEvent { - return SaveInstanceState(outState) - } + fun createOnSaveInstanceStateEvent(outState: Bundle?): ActivityCallbackEvent = + SaveInstanceState(outState) /** * Creates an event for [Activity.onTrimMemory] @@ -121,14 +118,11 @@ private constructor( * @return the created [TrimMemory] */ @JvmStatic - fun createTrimMemoryEvent(trimMemoryType: Int): TrimMemory { - return TrimMemory(trimMemoryType) - } + fun createTrimMemoryEvent(trimMemoryType: Int): TrimMemory = TrimMemory(trimMemoryType) @JvmStatic - fun createPictureInPictureMode(isInPictureInPictureMode: Boolean): PictureInPictureMode { - return PictureInPictureMode(isInPictureInPictureMode) - } + fun createPictureInPictureMode(isInPictureInPictureMode: Boolean): PictureInPictureMode = + PictureInPictureMode(isInPictureInPictureMode) /** * Creates an event for onNewIntent. @@ -136,10 +130,7 @@ private constructor( * @param intent is the new intent received * @return the created [NewIntent]. */ - @JvmStatic - fun createNewIntent(intent: Intent): NewIntent { - return NewIntent(intent) - } + @JvmStatic fun createNewIntent(intent: Intent): NewIntent = NewIntent(intent) /** * Creates an event for onWindowFocusChanged @@ -147,9 +138,6 @@ private constructor( * @param hasFocus determines whether the window of this activity got focus or not * @return the newly created [WindowFocus] */ - @JvmStatic - fun createWindowFocusEvent(hasFocus: Boolean): WindowFocus { - return WindowFocus(hasFocus) - } + @JvmStatic fun createWindowFocusEvent(hasFocus: Boolean): WindowFocus = WindowFocus(hasFocus) } } diff --git a/android/libraries/rib-android/src/main/kotlin/com/uber/rib/core/lifecycle/ActivityLifecycleEvent.kt b/android/libraries/rib-android/src/main/kotlin/com/uber/rib/core/lifecycle/ActivityLifecycleEvent.kt index c1cd2cf38..c11a7e852 100644 --- a/android/libraries/rib-android/src/main/kotlin/com/uber/rib/core/lifecycle/ActivityLifecycleEvent.kt +++ b/android/libraries/rib-android/src/main/kotlin/com/uber/rib/core/lifecycle/ActivityLifecycleEvent.kt @@ -48,7 +48,7 @@ import android.os.Bundle open class ActivityLifecycleEvent private constructor( /** @return this event's type. */ - override val type: Type, + override val type: Type ) : ActivityEvent, Comparable { /** Types of activity events that can occur. */ @@ -70,7 +70,7 @@ private constructor( */ open class Create( /** @return this event's savedInstanceState data. */ - open val savedInstanceState: Bundle?, + open val savedInstanceState: Bundle? ) : ActivityLifecycleEvent(Type.CREATE) companion object { @@ -87,10 +87,7 @@ private constructor( * @param stateData the instate bundle. * @return the created ActivityEvent. */ - @JvmStatic - fun createOnCreateEvent(stateData: Bundle?): Create { - return Create(stateData) - } + @JvmStatic fun createOnCreateEvent(stateData: Bundle?): Create = Create(stateData) /** * Creates an activity event for a given type. @@ -99,8 +96,8 @@ private constructor( * @return The corresponding ActivityEvent. */ @JvmStatic - fun create(type: Type): ActivityLifecycleEvent { - return when (type) { + fun create(type: Type): ActivityLifecycleEvent = + when (type) { Type.START -> START_EVENT Type.RESUME -> RESUME_EVENT Type.USER_LEAVING -> USER_LEAVING_EVENT @@ -109,9 +106,8 @@ private constructor( Type.DESTROY -> DESTROY_EVENT else -> throw IllegalArgumentException( - "Use the createOn${type.name.lowercase().replaceFirstChar(Char::titlecase)}Event() method for this type!", + "Use the createOn${type.name.lowercase().replaceFirstChar(Char::titlecase)}Event() method for this type!" ) } - } } } diff --git a/android/libraries/rib-android/src/test/kotlin/com/uber/rib/core/RibActivityTest.kt b/android/libraries/rib-android/src/test/kotlin/com/uber/rib/core/RibActivityTest.kt index 87f7ddc2f..47a138f09 100644 --- a/android/libraries/rib-android/src/test/kotlin/com/uber/rib/core/RibActivityTest.kt +++ b/android/libraries/rib-android/src/test/kotlin/com/uber/rib/core/RibActivityTest.kt @@ -56,7 +56,7 @@ class RibActivityTest { Robolectric.buildActivity(EmptyActivity::class.java) activityController.create(testBundle) assertThat( - activityController.get().testInteractor.savedInstanceState?.getString(TEST_BUNDLE_KEY), + activityController.get().testInteractor.savedInstanceState?.getString(TEST_BUNDLE_KEY) ) .isEqualTo(TEST_BUNDLE_VALUE) } @@ -131,7 +131,7 @@ class RibActivityTest { .delaySubscription( activity.lifecycle().filter { activityEvent -> activityEvent.type === ActivityLifecycleEvent.Type.RESUME - }, + } ) .subscribe(o) subject.onNext(Any()) @@ -246,9 +246,8 @@ class RibActivityTest { component: InteractorComponent, *>, ) : ViewRouter, *>>(view, interactor, component) - private class TestInteractor( - presenter: ViewPresenter<*>, - ) : Interactor, FakeRouter<*>>(presenter) { + private class TestInteractor(presenter: ViewPresenter<*>) : + Interactor, FakeRouter<*>>(presenter) { var savedInstanceState: Bundle? = null private set diff --git a/android/libraries/rib-android/src/test/kotlin/com/uber/rib/core/ViewBuilderTest.kt b/android/libraries/rib-android/src/test/kotlin/com/uber/rib/core/ViewBuilderTest.kt index ce576d053..eaf28eb89 100644 --- a/android/libraries/rib-android/src/test/kotlin/com/uber/rib/core/ViewBuilderTest.kt +++ b/android/libraries/rib-android/src/test/kotlin/com/uber/rib/core/ViewBuilderTest.kt @@ -61,9 +61,7 @@ class ViewBuilderTest { return mock() } - override fun onThemeContext(parentContext: Context): Context { - return customContext - } + override fun onThemeContext(parentContext: Context): Context = customContext } viewBuilder.createView(parentViewGroup) Truth.assertThat(holder.inflaterContext).isEqualTo(customContext) diff --git a/android/libraries/rib-base/src/main/kotlin/com/uber/rib/core/BasicInteractor.kt b/android/libraries/rib-base/src/main/kotlin/com/uber/rib/core/BasicInteractor.kt index 3c082c698..dfa74e8f7 100644 --- a/android/libraries/rib-base/src/main/kotlin/com/uber/rib/core/BasicInteractor.kt +++ b/android/libraries/rib-base/src/main/kotlin/com/uber/rib/core/BasicInteractor.kt @@ -22,6 +22,4 @@ package com.uber.rib.core * @param the type of [Router]. */ public abstract class BasicInteractor

> -protected constructor( - @JvmField protected var presenter: P, -) : Interactor(presenter) +protected constructor(@JvmField protected var presenter: P) : Interactor(presenter) diff --git a/android/libraries/rib-base/src/main/kotlin/com/uber/rib/core/Bundle.kt b/android/libraries/rib-base/src/main/kotlin/com/uber/rib/core/Bundle.kt index c79b4ef73..988e4a11d 100644 --- a/android/libraries/rib-base/src/main/kotlin/com/uber/rib/core/Bundle.kt +++ b/android/libraries/rib-base/src/main/kotlin/com/uber/rib/core/Bundle.kt @@ -20,9 +20,7 @@ import android.os.Parcelable /** Uber wrapper around Android Bundle to avoid Android and Robolectric dependencies. */ public open class Bundle @JvmOverloads -constructor( - private val androidBundle: android.os.Bundle = android.os.Bundle(), -) { +constructor(private val androidBundle: android.os.Bundle = android.os.Bundle()) { /** * Returns the value associated with the given key, or defaultValue if no mapping of the desired @@ -33,9 +31,8 @@ constructor( * @return the boolean value associated with the given key or null if there is no string value in * the bundle. */ - public open fun getBoolean(key: String, defaultValue: Boolean): Boolean { - return androidBundle.getBoolean(key, defaultValue) - } + public open fun getBoolean(key: String, defaultValue: Boolean): Boolean = + androidBundle.getBoolean(key, defaultValue) /** * Inserts a boolean value into the mapping of this Bundle, replacing any existing value for the @@ -85,9 +82,7 @@ constructor( * @param key to get. * @return the value, or `null`. */ - public open fun getParcelable(key: String): Parcelable? { - return androidBundle.getParcelable(key) - } + public open fun getParcelable(key: String): Parcelable? = androidBundle.getParcelable(key) /** * Inserts a Parcelable value into the mapping of this Bundle, replacing any existing value for @@ -108,9 +103,7 @@ constructor( * @return the String value associated with the given key or null if there is no string value in * the bundle. */ - public open fun getString(key: String): String? { - return androidBundle.getString(key) - } + public open fun getString(key: String): String? = androidBundle.getString(key) /** * Inserts a String value into the mapping of this Bundle, replacing any existing value for the @@ -142,7 +135,6 @@ constructor( * @return the int value associated with the given key or defaultValue if there is no int value in * the bundle. */ - public open fun getInt(key: String, defaultValue: Int): Int { - return androidBundle.getInt(key, defaultValue) - } + public open fun getInt(key: String, defaultValue: Int): Int = + androidBundle.getInt(key, defaultValue) } diff --git a/android/libraries/rib-base/src/main/kotlin/com/uber/rib/core/Interactor.kt b/android/libraries/rib-base/src/main/kotlin/com/uber/rib/core/Interactor.kt index 4301bae42..41ff452d1 100644 --- a/android/libraries/rib-base/src/main/kotlin/com/uber/rib/core/Interactor.kt +++ b/android/libraries/rib-base/src/main/kotlin/com/uber/rib/core/Interactor.kt @@ -42,15 +42,16 @@ public abstract class Interactor

>() : InteractorType, Rib @Inject public lateinit var injectedPresenter: P @CoreFriendModuleApi public var actualPresenter: P? = null - private val _lifecycleFlow = MutableSharedFlow(1, 0, BufferOverflow.DROP_OLDEST) + private val mutableLifecycleFlow = + MutableSharedFlow(1, 0, BufferOverflow.DROP_OLDEST) public open val lifecycleFlow: SharedFlow - get() = _lifecycleFlow + get() = mutableLifecycleFlow - @Volatile private var _lifecycleObservable: Observable? = null + @Volatile private var lifecycleObservableField: Observable? = null @OptIn(CoreFriendModuleApi::class) private val lifecycleObservable - get() = ::_lifecycleObservable.setIfNullAndGet { lifecycleFlow.asObservable() } + get() = ::lifecycleObservableField.setIfNullAndGet { lifecycleFlow.asObservable() } private val routerDelegate = InitOnceProperty() @@ -79,7 +80,7 @@ public abstract class Interactor

>() : InteractorType, Rib // ---- InteractorType overrides ---- // override fun isAttached(): Boolean = - _lifecycleFlow.replayCache.lastOrNull() == InteractorEvent.ACTIVE + mutableLifecycleFlow.replayCache.lastOrNull() == InteractorEvent.ACTIVE override fun handleBackPress(): Boolean = false @@ -108,24 +109,16 @@ public abstract class Interactor

>() : InteractorType, Rib protected open fun onSaveInstanceState(outState: Bundle) {} public open fun dispatchAttach(savedInstanceState: Bundle?) { - _lifecycleFlow.tryEmit(InteractorEvent.ACTIVE) + mutableLifecycleFlow.tryEmit(InteractorEvent.ACTIVE) val presenter = (getPresenter() as? Presenter) presenter?.let { - triggerRibActionAndEmitEvents( - it, - RibActionEmitterType.PRESENTER, - RibEventType.ATTACHED, - ) { + triggerRibActionAndEmitEvents(it, RibActionEmitterType.PRESENTER, RibEventType.ATTACHED) { it.dispatchLoad() } } - triggerRibActionAndEmitEvents( - this, - RibActionEmitterType.INTERACTOR, - RibEventType.ATTACHED, - ) { + triggerRibActionAndEmitEvents(this, RibActionEmitterType.INTERACTOR, RibEventType.ATTACHED) { didBecomeActive(savedInstanceState) } } @@ -133,24 +126,16 @@ public abstract class Interactor

>() : InteractorType, Rib public open fun dispatchDetach(): P { val presenter = (getPresenter() as? Presenter) presenter?.let { - triggerRibActionAndEmitEvents( - it, - RibActionEmitterType.PRESENTER, - RibEventType.DETACHED, - ) { + triggerRibActionAndEmitEvents(it, RibActionEmitterType.PRESENTER, RibEventType.DETACHED) { it.dispatchUnload() } } - triggerRibActionAndEmitEvents( - this, - RibActionEmitterType.INTERACTOR, - RibEventType.DETACHED, - ) { + triggerRibActionAndEmitEvents(this, RibActionEmitterType.INTERACTOR, RibEventType.DETACHED) { willResignActive() } - _lifecycleFlow.tryEmit(InteractorEvent.INACTIVE) + mutableLifecycleFlow.tryEmit(InteractorEvent.INACTIVE) return getPresenter() } diff --git a/android/libraries/rib-base/src/main/kotlin/com/uber/rib/core/LazyBackingProperty.kt b/android/libraries/rib-base/src/main/kotlin/com/uber/rib/core/LazyBackingProperty.kt index 5da67a8f1..141f1c0d0 100644 --- a/android/libraries/rib-base/src/main/kotlin/com/uber/rib/core/LazyBackingProperty.kt +++ b/android/libraries/rib-base/src/main/kotlin/com/uber/rib/core/LazyBackingProperty.kt @@ -32,8 +32,7 @@ import kotlin.reflect.KMutableProperty0 * To properly support concurrency, the backing mutable property should be [Volatile]. */ @CoreFriendModuleApi -public inline fun KMutableProperty0.setIfNullAndGet( - initializer: () -> T, -): T = get() ?: synchronized(Lock) { get() ?: initializer().also { set(it) } } +public inline fun KMutableProperty0.setIfNullAndGet(initializer: () -> T): T = + get() ?: synchronized(Lock) { get() ?: initializer().also { set(it) } } @CoreFriendModuleApi public object Lock diff --git a/android/libraries/rib-base/src/main/kotlin/com/uber/rib/core/Presenter.kt b/android/libraries/rib-base/src/main/kotlin/com/uber/rib/core/Presenter.kt index da804916f..7c8d64eb1 100644 --- a/android/libraries/rib-base/src/main/kotlin/com/uber/rib/core/Presenter.kt +++ b/android/libraries/rib-base/src/main/kotlin/com/uber/rib/core/Presenter.kt @@ -39,11 +39,11 @@ public abstract class Presenter : ScopeProvider, RibActionEmitter { public open val lifecycleFlow: SharedFlow get() = _lifecycleFlow - @Volatile private var _lifecycleObservable: Observable? = null + @Volatile private var lifecycleObservableField: Observable? = null @OptIn(CoreFriendModuleApi::class) private val lifecycleObservable - get() = ::_lifecycleObservable.setIfNullAndGet { lifecycleFlow.asObservable() } + get() = ::lifecycleObservableField.setIfNullAndGet { lifecycleFlow.asObservable() } /** @return `true` if the presenter is loaded, `false` if not. */ protected var isLoaded: Boolean = false diff --git a/android/libraries/rib-base/src/main/kotlin/com/uber/rib/core/Rib.kt b/android/libraries/rib-base/src/main/kotlin/com/uber/rib/core/Rib.kt index d59e03142..42e0c7608 100644 --- a/android/libraries/rib-base/src/main/kotlin/com/uber/rib/core/Rib.kt +++ b/android/libraries/rib-base/src/main/kotlin/com/uber/rib/core/Rib.kt @@ -59,11 +59,11 @@ public open class Rib { /** Default, internal implementation that is used when host app does not set a configuration. */ private class DefaultConfiguration : Configuration { - override fun handleNonFatalError(errorMessage: String, throwable: Throwable?) { + override fun handleNonFatalError(errorMessage: String, throwable: Throwable?): Unit = throw RuntimeException(errorMessage, throwable) - } override fun handleNonFatalWarning(warningMessage: String, throwable: Throwable?) {} + override fun handleDebugMessage(format: String, vararg args: Any?) {} } @@ -85,7 +85,7 @@ public open class Rib { throw IllegalStateException("Attempting to set a configuration after using RIB code.") } else { throw IllegalStateException( - "Attempting to set a configuration after one has previously been set.", + "Attempting to set a configuration after one has previously been set." ) } } diff --git a/android/libraries/rib-base/src/main/kotlin/com/uber/rib/core/RibCoroutineWorker.kt b/android/libraries/rib-base/src/main/kotlin/com/uber/rib/core/RibCoroutineWorker.kt index cdb173951..0848f4b48 100644 --- a/android/libraries/rib-base/src/main/kotlin/com/uber/rib/core/RibCoroutineWorker.kt +++ b/android/libraries/rib-base/src/main/kotlin/com/uber/rib/core/RibCoroutineWorker.kt @@ -44,7 +44,7 @@ public fun interface RibCoroutineWorker : RibActionEmitter { /** A manager or helper class bound to a [CoroutineScope] by using a binder like [bind]. */ public inline fun RibCoroutineWorker( - crossinline onStart: suspend CoroutineScope.() -> Unit, + crossinline onStart: suspend CoroutineScope.() -> Unit ): RibCoroutineWorker { /* * 'RibCoroutineWorker' is already a functional interface; the purpose of this builder is to allow consumers @@ -76,10 +76,8 @@ public sealed interface BindWorkerHandle : Job { public fun unbind(): Job } -private class BindWorkerHandleImpl( - bindJob: Job, - private val unbindJob: Job, -) : BindWorkerHandle, Job by bindJob { +private class BindWorkerHandleImpl(bindJob: Job, private val unbindJob: Job) : + BindWorkerHandle, Job by bindJob { override fun unbind(): Job { unbindJob.cancel("Worker was manually unbound.") return unbindJob @@ -193,12 +191,11 @@ public fun Worker.asRibCoroutineWorker(): RibCoroutineWorker = */ @JvmOverloads public fun RibCoroutineWorker.asWorker( - coroutineContext: CoroutineContext = RibDispatchers.Default, + coroutineContext: CoroutineContext = RibDispatchers.Default ): Worker = this as? Worker ?: RibCoroutineWorkerToWorkerAdapter(this, coroutineContext) -internal open class WorkerToRibCoroutineWorkerAdapter( - private val worker: Worker, -) : RibCoroutineWorker { +internal open class WorkerToRibCoroutineWorkerAdapter(private val worker: Worker) : + RibCoroutineWorker { override suspend fun onStart(scope: CoroutineScope) { withContext(worker.coroutineContext ?: EmptyCoroutineContext) { worker.onStart(scope.asWorkerScopeProvider()) diff --git a/android/libraries/rib-base/src/main/kotlin/com/uber/rib/core/RibRefWatcher.kt b/android/libraries/rib-base/src/main/kotlin/com/uber/rib/core/RibRefWatcher.kt index 8ed91004a..2676b065c 100644 --- a/android/libraries/rib-base/src/main/kotlin/com/uber/rib/core/RibRefWatcher.kt +++ b/android/libraries/rib-base/src/main/kotlin/com/uber/rib/core/RibRefWatcher.kt @@ -133,6 +133,7 @@ public open class RibRefWatcher { @JvmStatic public var isLeakCanaryEnabled: Boolean = false private set + private var uLeakEnabled = false private var breadcrumbsEnabled = false } diff --git a/android/libraries/rib-base/src/main/kotlin/com/uber/rib/core/Router.kt b/android/libraries/rib-base/src/main/kotlin/com/uber/rib/core/Router.kt index 948d2441c..807a2e063 100644 --- a/android/libraries/rib-base/src/main/kotlin/com/uber/rib/core/Router.kt +++ b/android/libraries/rib-base/src/main/kotlin/com/uber/rib/core/Router.kt @@ -44,6 +44,7 @@ protected constructor( @CoreFriendModuleApi public var tag: String? = null private set + private var savedInstanceState: Bundle? = null private var isLoaded = false @@ -51,8 +52,9 @@ protected constructor( interactor: I, component: InteractorBaseComponent<*>?, ) : this(component, interactor, RibRefWatcher.getInstance(), getMainThread()) + protected constructor( - interactor: I, + interactor: I ) : this(null, interactor, RibRefWatcher.getInstance(), getMainThread()) @Suppress("UNCHECKED_CAST") @@ -109,21 +111,13 @@ protected constructor( if (tag == child.tag) { Rib.getConfiguration() .handleNonFatalWarning( - String.format( - Locale.getDefault(), - "There is already a child router with tag: %s", - tag, - ), + String.format(Locale.getDefault(), "There is already a child router with tag: %s", tag), null, ) } } - triggerRibActionAndEmitEvents( - childRouter, - RibActionEmitterType.ROUTER, - RibEventType.ATTACHED, - ) { + triggerRibActionAndEmitEvents(childRouter, RibActionEmitterType.ROUTER, RibEventType.ATTACHED) { children.add(childRouter) } @@ -172,11 +166,7 @@ protected constructor( } } - triggerRibActionAndEmitEvents( - childRouter, - RibActionEmitterType.ROUTER, - RibEventType.DETACHED, - ) { + triggerRibActionAndEmitEvents(childRouter, RibActionEmitterType.ROUTER, RibEventType.DETACHED) { childRouter.dispatchDetach() } @@ -224,10 +214,7 @@ protected constructor( * * @return Children. */ - @CoreFriendModuleApi - public open fun getChildren(): List> { - return children - } + @CoreFriendModuleApi public open fun getChildren(): List> = children @CoreFriendModuleApi public fun saveInstanceStateInternal(outState: Bundle) { @@ -262,13 +249,12 @@ protected constructor( @JvmField @VisibleForTesting public val KEY_INTERACTOR: String = "Router.interactor" @JvmStatic - public fun getMainThread(): Thread { - return try { + public fun getMainThread(): Thread = + try { Looper.getMainLooper().thread } catch (e: Exception) { Thread.currentThread() } - } } init { diff --git a/android/libraries/rib-base/src/main/kotlin/com/uber/rib/core/WorkerBinder.kt b/android/libraries/rib-base/src/main/kotlin/com/uber/rib/core/WorkerBinder.kt index 7373c3de1..88e21946b 100644 --- a/android/libraries/rib-base/src/main/kotlin/com/uber/rib/core/WorkerBinder.kt +++ b/android/libraries/rib-base/src/main/kotlin/com/uber/rib/core/WorkerBinder.kt @@ -63,14 +63,8 @@ public object WorkerBinder { * @return [WorkerUnbinder] to unbind [Worker]'s lifecycle. */ @JvmStatic - public fun bind( - interactor: Interactor<*, *>, - worker: Worker, - ): WorkerUnbinder = - worker.bind( - interactor.lifecycleFlow, - Interactor.lifecycleRange, - ) + public fun bind(interactor: Interactor<*, *>, worker: Worker): WorkerUnbinder = + worker.bind(interactor.lifecycleFlow, Interactor.lifecycleRange) /** * Bind a list of workers (ie. a manager or any other class that needs an interactor's lifecycle) @@ -81,10 +75,7 @@ public object WorkerBinder { * @param workers A list of classes that want to be informed when to start and stop doing work. */ @JvmStatic - public fun bind( - interactor: Interactor<*, *>, - workers: List, - ) { + public fun bind(interactor: Interactor<*, *>, workers: List) { bind(interactor, workers as Iterable) } @@ -97,10 +88,7 @@ public object WorkerBinder { * @param workers A list of classes that want to be informed when to start and stop doing work. */ @JvmStatic - public fun bind( - interactor: Interactor<*, *>, - workers: Iterable, - ) { + public fun bind(interactor: Interactor<*, *>, workers: Iterable) { for (interactorWorker in workers) { bind(interactor, interactorWorker) } @@ -115,14 +103,8 @@ public object WorkerBinder { * @return [WorkerUnbinder] to unbind [Worker]'s lifecycle. */ @JvmStatic - public fun bind( - presenter: Presenter, - worker: Worker, - ): WorkerUnbinder = - worker.bind( - presenter.lifecycleFlow, - Presenter.lifecycleRange, - ) + public fun bind(presenter: Presenter, worker: Worker): WorkerUnbinder = + worker.bind(presenter.lifecycleFlow, Presenter.lifecycleRange) /** * Bind a list of workers (ie. a manager or any other class that needs an presenter's lifecycle) @@ -133,10 +115,7 @@ public object WorkerBinder { * @param workers A list of classes that want to be informed when to start and stop doing work. */ @JvmStatic - public fun bind( - presenter: Presenter, - workers: List, - ) { + public fun bind(presenter: Presenter, workers: List) { bind(presenter, workers as Iterable) } @@ -149,10 +128,7 @@ public object WorkerBinder { * @param workers A list of classes that want to be informed when to start and stop doing work. */ @JvmStatic - public fun bind( - presenter: Presenter, - workers: Iterable, - ) { + public fun bind(presenter: Presenter, workers: Iterable) { for (worker in workers) { bind(presenter, worker) } @@ -181,7 +157,7 @@ public object WorkerBinder { @JvmStatic public fun mapInteractorLifecycleToWorker( - interactorEventObservable: Observable, + interactorEventObservable: Observable ): Observable { return interactorEventObservable.map { interactorEvent: InteractorEvent -> when (interactorEvent) { @@ -193,7 +169,7 @@ public object WorkerBinder { @JvmStatic public fun mapPresenterLifecycleToWorker( - presenterEventObservable: Observable, + presenterEventObservable: Observable ): Observable { return presenterEventObservable.map { presenterEvent: PresenterEvent -> when (presenterEvent) { @@ -213,12 +189,9 @@ public object WorkerBinder { @JvmStatic @Deprecated( """this method uses {@code LifecycleScopeProvider} for purposes other than - AutoDispose. Usage is strongly discouraged as this method may be removed in the future.""", + AutoDispose. Usage is strongly discouraged as this method may be removed in the future.""" ) - public fun bindTo( - lifecycle: LifecycleScopeProvider, - worker: Worker, - ) { + public fun bindTo(lifecycle: LifecycleScopeProvider, worker: Worker) { bind(mapInteractorLifecycleToWorker(lifecycle.lifecycle()), worker) } @@ -238,10 +211,7 @@ public object WorkerBinder { """, replaceWith = ReplaceWith("bind(workerLifecycle, worker)"), ) - public fun bindToWorkerLifecycle( - workerLifecycle: Observable, - worker: Worker, - ) { + public fun bindToWorkerLifecycle(workerLifecycle: Observable, worker: Worker) { workerLifecycle.subscribe { workerEvent: WorkerEvent -> when (workerEvent) { WorkerEvent.START -> worker.onStart(WorkerScopeProvider(workerLifecycle.hide())) @@ -268,11 +238,7 @@ private fun > Worker.bind( lifecycleRange: ClosedRange, ): WorkerUnbinder { val dispatcherAtBinder = RibCoroutinesConfig.deprecatedWorkerDispatcher - val coroutineContext = - getJobCoroutineContext( - dispatcherAtBinder, - worker = this, - ) + val coroutineContext = getJobCoroutineContext(dispatcherAtBinder, worker = this) val coroutineStart = if (coroutineContext == RibDispatchers.Unconfined) { CoroutineStart.UNDISPATCHED @@ -293,10 +259,7 @@ private fun > Worker.bind( */ @OptIn(DelicateCoroutinesApi::class) val job = - GlobalScope.launch( - coroutineContext, - start = coroutineStart, - ) { + GlobalScope.launch(coroutineContext, start = coroutineStart) { lifecycle .takeWhile { it < lifecycleRange.endInclusive } .onCompletion { diff --git a/android/libraries/rib-base/src/main/kotlin/com/uber/rib/core/WorkerUnbinder.kt b/android/libraries/rib-base/src/main/kotlin/com/uber/rib/core/WorkerUnbinder.kt index dec0a46c7..3defdd3a8 100644 --- a/android/libraries/rib-base/src/main/kotlin/com/uber/rib/core/WorkerUnbinder.kt +++ b/android/libraries/rib-base/src/main/kotlin/com/uber/rib/core/WorkerUnbinder.kt @@ -23,7 +23,7 @@ package com.uber.rib.core message = """ com.uber.rib.core.Worker is deprecated in favor of com.uber.rib.core.RibCoroutineWorker - """, + """ ) public fun interface WorkerUnbinder { /** Unbind from bound lifecycle and end worker's lifecycle. */ diff --git a/android/libraries/rib-base/src/test/kotlin/android/os/Bundle.kt b/android/libraries/rib-base/src/test/kotlin/android/os/Bundle.kt index c6e32bcd4..e0e089423 100644 --- a/android/libraries/rib-base/src/test/kotlin/android/os/Bundle.kt +++ b/android/libraries/rib-base/src/test/kotlin/android/os/Bundle.kt @@ -19,13 +19,9 @@ package android.os class Bundle : Parcelable { private val testData: MutableMap = mutableMapOf() - fun getString(key: String): String? { - return testData[key] as String? - } + fun getString(key: String): String? = testData[key] as String? - fun getParcelable(key: String): T? { - return testData[key] as T? - } + fun getParcelable(key: String): T? = testData[key] as T? fun putParcelable(key: String, value: Parcelable) { testData[key] = value diff --git a/android/libraries/rib-base/src/test/kotlin/com/uber/rib/core/InteractorAndRouterTest.kt b/android/libraries/rib-base/src/test/kotlin/com/uber/rib/core/InteractorAndRouterTest.kt index a23c365d2..1bc143fbe 100644 --- a/android/libraries/rib-base/src/test/kotlin/com/uber/rib/core/InteractorAndRouterTest.kt +++ b/android/libraries/rib-base/src/test/kotlin/com/uber/rib/core/InteractorAndRouterTest.kt @@ -138,9 +138,8 @@ class InteractorAndRouterTest { val component: InteractorComponent = object : InteractorComponent { override fun inject(interactor: TestInteractorA) {} - override fun presenter(): TestPresenter { - return TestPresenter() - } + + override fun presenter(): TestPresenter = TestPresenter() } val router = TestRouterA(parentInteractor, component) val parentObserver = RecordingObserver() @@ -151,9 +150,8 @@ class InteractorAndRouterTest { val childComponent: InteractorComponent = object : InteractorComponent { override fun inject(interactor: TestChildInteractor) {} - override fun presenter(): TestPresenter { - return TestPresenter() - } + + override fun presenter(): TestPresenter = TestPresenter() } val childRouter = TestChildRouter(childA, childComponent) val childObserverA = RecordingObserver() @@ -178,9 +176,8 @@ class InteractorAndRouterTest { val component: InteractorComponent = object : InteractorComponent { override fun inject(interactor: TestInteractorB) {} - override fun presenter(): TestPresenter { - return TestPresenter() - } + + override fun presenter(): TestPresenter = TestPresenter() } val router = TestRouterB(component, rootInteractor, ribRefWatcher) router.dispatchAttach(null) @@ -201,9 +198,8 @@ class InteractorAndRouterTest { val component: InteractorComponent = object : InteractorComponent { override fun inject(interactor: TestInteractorB) {} - override fun presenter(): TestPresenter { - return TestPresenter() - } + + override fun presenter(): TestPresenter = TestPresenter() } val rootRouter = TestRouterB(component, TestInteractorB(), ribRefWatcher) val child = addTwoNestedChildInteractors() @@ -220,9 +216,8 @@ class InteractorAndRouterTest { val component: InteractorComponent = object : InteractorComponent { override fun inject(interactor: TestInteractorB) {} - override fun presenter(): TestPresenter { - return TestPresenter() - } + + override fun presenter(): TestPresenter = TestPresenter() } router.dispatchAttach(null) val childRouter1 = TestRouterB(component, TestInteractorB(), ribRefWatcher) @@ -235,6 +230,7 @@ class InteractorAndRouterTest { private class TestInteractor(private val mChildInteractor: Interactor<*, *>) : Interactor>() { val mockedWorker: Worker = mock() + override fun didBecomeActive(savedInstanceState: Bundle?) { super.didBecomeActive(savedInstanceState) val router: Router<*> = FakeRouter(mChildInteractor, getInstance(), Thread.currentThread()) @@ -264,6 +260,7 @@ class InteractorAndRouterTest { component: InteractorComponent, ) : Router(component, interactor, getInstance(), Thread.currentThread()) { private var savedInstanceState: Bundle? = null + override fun dispatchAttach(savedInstanceState: Bundle?, tag: String) { super.dispatchAttach(savedInstanceState, tag) this.savedInstanceState = savedInstanceState @@ -275,7 +272,9 @@ class InteractorAndRouterTest { } private class TestInteractorA : Interactor>() + private class TestInteractorB : Interactor>() + private class TestRouterB : Router { constructor( interactor: TestInteractorB, @@ -294,6 +293,7 @@ class InteractorAndRouterTest { } private class TestChildInteractor : Interactor>() + private class TestChildRouter( interactor: TestChildInteractor, component: InteractorComponent, diff --git a/android/libraries/rib-base/src/test/kotlin/com/uber/rib/core/LazyBackingPropertyTest.kt b/android/libraries/rib-base/src/test/kotlin/com/uber/rib/core/LazyBackingPropertyTest.kt index d0846d365..935b72dcf 100644 --- a/android/libraries/rib-base/src/test/kotlin/com/uber/rib/core/LazyBackingPropertyTest.kt +++ b/android/libraries/rib-base/src/test/kotlin/com/uber/rib/core/LazyBackingPropertyTest.kt @@ -18,6 +18,7 @@ package com.uber.rib.core import com.google.common.truth.Truth.assertThat import com.uber.rib.core.internal.CoreFriendModuleApi import io.reactivex.Observable +import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.channels.produce import kotlinx.coroutines.channels.toList import kotlinx.coroutines.launch @@ -26,12 +27,13 @@ import org.junit.Test import org.mockito.kotlin.mock class LazyBackingPropertyTest { - @Volatile private var _expensiveObject: ExpensiveObject? = null + @Volatile private var expensiveObjectField: ExpensiveObject? = null @OptIn(CoreFriendModuleApi::class) private val expensiveObject - get() = ::_expensiveObject.setIfNullAndGet { ExpensiveObject() } + get() = ::expensiveObjectField.setIfNullAndGet { ExpensiveObject() } + @OptIn(ExperimentalCoroutinesApi::class) @Test fun `Stress test fetching a LazyBackingProperty from multiple concurrent coroutines`() = runTest { val set = diff --git a/android/libraries/rib-base/src/test/kotlin/com/uber/rib/core/RibCoroutineWorkerTest.kt b/android/libraries/rib-base/src/test/kotlin/com/uber/rib/core/RibCoroutineWorkerTest.kt index 8d9b7e065..e19828948 100644 --- a/android/libraries/rib-base/src/test/kotlin/com/uber/rib/core/RibCoroutineWorkerTest.kt +++ b/android/libraries/rib-base/src/test/kotlin/com/uber/rib/core/RibCoroutineWorkerTest.kt @@ -336,15 +336,15 @@ private class TestWorker : RibCoroutineWorker { var innerCoroutineIdle = false var innerCoroutineCompleted = false - private var _doOnStart: suspend () -> Unit = {} - private var _doOnStop: () -> Unit = {} + private var doOnStartField: suspend () -> Unit = {} + private var doOnStopField: () -> Unit = {} fun doOnStart(block: suspend () -> Unit) { - _doOnStart = block + doOnStartField = block } fun doOnStop(block: () -> Unit) { - _doOnStop = block + doOnStopField = block } override suspend fun onStart(scope: CoroutineScope) { @@ -362,7 +362,7 @@ private class TestWorker : RibCoroutineWorker { } } delay(ON_START_DELAY_DURATION_MILLIS) - _doOnStart() + doOnStartField() } finally { onStartFinished = true } @@ -372,7 +372,7 @@ private class TestWorker : RibCoroutineWorker { onStopThread = Thread.currentThread() onStopCause = cause try { - _doOnStop() + doOnStopField() } finally { onStopRan = true } @@ -393,9 +393,11 @@ private class WorkerAndRibCoroutineWorker( ) : Worker, RibCoroutineWorker { // Worker impl override fun onStart(lifecycle: WorkerScopeProvider) = workerOnStart(lifecycle) + override fun onStop() = workerOnStop() // RibCoroutineWorker impl override suspend fun onStart(scope: CoroutineScope) = ribCoroutineWorkerOnStart(scope) + override fun onStop(cause: Throwable) = ribCoroutineWorkerOnStop(cause) } diff --git a/android/libraries/rib-base/src/test/kotlin/com/uber/rib/core/RouterTest.kt b/android/libraries/rib-base/src/test/kotlin/com/uber/rib/core/RouterTest.kt index 4a7e650a6..7afd1a274 100644 --- a/android/libraries/rib-base/src/test/kotlin/com/uber/rib/core/RouterTest.kt +++ b/android/libraries/rib-base/src/test/kotlin/com/uber/rib/core/RouterTest.kt @@ -31,12 +31,7 @@ class RouterTest { val didLoad = AtomicBoolean(false) val router: Router<*> = object : - Router>( - component, - interactor, - ribRefWatcher, - Thread.currentThread(), - ) { + Router>(component, interactor, ribRefWatcher, Thread.currentThread()) { override fun attachToInteractor() { // ignore the Interactor since we're only testing the Router } diff --git a/android/libraries/rib-base/src/test/kotlin/com/uber/rib/core/WorkerBinderTest.kt b/android/libraries/rib-base/src/test/kotlin/com/uber/rib/core/WorkerBinderTest.kt index a75f0983c..0968e58df 100644 --- a/android/libraries/rib-base/src/test/kotlin/com/uber/rib/core/WorkerBinderTest.kt +++ b/android/libraries/rib-base/src/test/kotlin/com/uber/rib/core/WorkerBinderTest.kt @@ -253,7 +253,7 @@ class WorkerBinderTest(private val adaptFromRibCoroutineWorker: Boolean) { } } -private fun Worker(onStartBlock: (WorkerScopeProvider) -> Unit) = +private fun Worker(onStartBlock: (WorkerScopeProvider) -> Unit): Worker = object : Worker { override fun onStart(lifecycle: WorkerScopeProvider) { onStartBlock(lifecycle) diff --git a/android/libraries/rib-compiler-app/src/main/kotlin/com/uber/rib/compiler/AnnotatedClass.kt b/android/libraries/rib-compiler-app/src/main/kotlin/com/uber/rib/compiler/AnnotatedClass.kt index 75e863d2f..279aa8e12 100644 --- a/android/libraries/rib-compiler-app/src/main/kotlin/com/uber/rib/compiler/AnnotatedClass.kt +++ b/android/libraries/rib-compiler-app/src/main/kotlin/com/uber/rib/compiler/AnnotatedClass.kt @@ -20,7 +20,7 @@ import javax.lang.model.element.TypeElement /** Information to a class. */ public abstract class AnnotatedClass( /** @return the type element that this wraps. */ - public open val typeElement: TypeElement, + public open val typeElement: TypeElement ) { /** diff --git a/android/libraries/rib-compiler-app/src/main/kotlin/com/uber/rib/compiler/InteractorAnnotationVerifier.kt b/android/libraries/rib-compiler-app/src/main/kotlin/com/uber/rib/compiler/InteractorAnnotationVerifier.kt index 78ef3d961..0451b42a0 100644 --- a/android/libraries/rib-compiler-app/src/main/kotlin/com/uber/rib/compiler/InteractorAnnotationVerifier.kt +++ b/android/libraries/rib-compiler-app/src/main/kotlin/com/uber/rib/compiler/InteractorAnnotationVerifier.kt @@ -75,14 +75,13 @@ internal open class InteractorAnnotationVerifier( * @param type * @return if given type element is valid. */ - private fun validateInteractorSuffix(type: TypeElement): Boolean { - return if (!type.simpleName.toString().endsWith(Constants.INTERACTOR_SUFFIX)) { + private fun validateInteractorSuffix(type: TypeElement): Boolean = + if (!type.simpleName.toString().endsWith(Constants.INTERACTOR_SUFFIX)) { errorReporter.reportError("$type does not end in Interactor.") false } else { true } - } /** * Validate if current class is a subclass of Interactor. diff --git a/android/libraries/rib-compiler-app/src/main/kotlin/com/uber/rib/compiler/RibProcessor.kt b/android/libraries/rib-compiler-app/src/main/kotlin/com/uber/rib/compiler/RibProcessor.kt index 674ff1d17..67b12290d 100644 --- a/android/libraries/rib-compiler-app/src/main/kotlin/com/uber/rib/compiler/RibProcessor.kt +++ b/android/libraries/rib-compiler-app/src/main/kotlin/com/uber/rib/compiler/RibProcessor.kt @@ -29,8 +29,10 @@ public abstract class RibProcessor : AbstractProcessor(), ProcessContext { override var errorReporter: ErrorReporter? = null protected set + override var elementUtils: Elements? = null protected set + override var typesUtils: Types? = null protected set @@ -45,9 +47,7 @@ public abstract class RibProcessor : AbstractProcessor(), ProcessContext { processorPipelines.addAll(getProcessorPipelines(this)) } - override fun getSupportedSourceVersion(): SourceVersion { - return SourceVersion.latestSupported() - } + override fun getSupportedSourceVersion(): SourceVersion = SourceVersion.latestSupported() override fun process(annotations: Set, roundEnv: RoundEnvironment): Boolean { if (roundEnv.processingOver()) { @@ -58,7 +58,7 @@ public abstract class RibProcessor : AbstractProcessor(), ProcessContext { processorPipeline.process(annotations, roundEnv) } catch (e: Throwable) { errorReporter?.reportError( - "Fatal error running ${processorPipeline.annotationType.simpleName} processor: ${e.message}", + "Fatal error running ${processorPipeline.annotationType.simpleName} processor: ${e.message}" ) } } @@ -72,6 +72,6 @@ public abstract class RibProcessor : AbstractProcessor(), ProcessContext { * @return the list of processor pipelines. */ protected abstract fun getProcessorPipelines( - processContext: ProcessContext, + processContext: ProcessContext ): List } diff --git a/android/libraries/rib-compiler-app/src/main/kotlin/com/uber/rib/compiler/TypeProcessorPipeline.kt b/android/libraries/rib-compiler-app/src/main/kotlin/com/uber/rib/compiler/TypeProcessorPipeline.kt index 23016cd0c..63491c148 100644 --- a/android/libraries/rib-compiler-app/src/main/kotlin/com/uber/rib/compiler/TypeProcessorPipeline.kt +++ b/android/libraries/rib-compiler-app/src/main/kotlin/com/uber/rib/compiler/TypeProcessorPipeline.kt @@ -21,9 +21,8 @@ import javax.lang.model.element.Element import javax.lang.model.element.TypeElement /** Base ProcessorPipeline that parses the annotated elements as type element. */ -public abstract class TypeProcessorPipeline( - processContext: ProcessContext, -) : ProcessorPipeline(processContext) { +public abstract class TypeProcessorPipeline(processContext: ProcessContext) : + ProcessorPipeline(processContext) { /** * Process the annotations. * diff --git a/android/libraries/rib-compiler-app/src/test/kotlin/com/uber/rib/compiler/InteractorAnnotationVerifierTest.kt b/android/libraries/rib-compiler-app/src/test/kotlin/com/uber/rib/compiler/InteractorAnnotationVerifierTest.kt index e82d6a0d4..94f426949 100644 --- a/android/libraries/rib-compiler-app/src/test/kotlin/com/uber/rib/compiler/InteractorAnnotationVerifierTest.kt +++ b/android/libraries/rib-compiler-app/src/test/kotlin/com/uber/rib/compiler/InteractorAnnotationVerifierTest.kt @@ -43,7 +43,7 @@ class InteractorAnnotationVerifierTest : InteractorProcessorTestBase() { fun verify_whenTypeElementIsNotInteractor_shouldWriteErrorMessage() { addResourceToSources("fixtures/AnnotatedNonInteractor.java") assertFailsWithError( - "test.AnnotatedNonInteractor is annotated with @RibInteractor but is not an Interactor subclass", + "test.AnnotatedNonInteractor is annotated with @RibInteractor but is not an Interactor subclass" ) } diff --git a/android/libraries/rib-compiler-app/src/test/kotlin/com/uber/rib/compiler/InteractorProcessorTestBase.kt b/android/libraries/rib-compiler-app/src/test/kotlin/com/uber/rib/compiler/InteractorProcessorTestBase.kt index d3a9967bd..5abc3eca6 100644 --- a/android/libraries/rib-compiler-app/src/test/kotlin/com/uber/rib/compiler/InteractorProcessorTestBase.kt +++ b/android/libraries/rib-compiler-app/src/test/kotlin/com/uber/rib/compiler/InteractorProcessorTestBase.kt @@ -30,18 +30,11 @@ abstract class InteractorProcessorTestBase { ribProcessor = object : RibProcessor() { override fun getProcessorPipelines( - processContext: ProcessContext, - ): List { - return listOf( - RibInteractorProcessorPipeline(processContext, null), - ) - } + processContext: ProcessContext + ): List = listOf(RibInteractorProcessorPipeline(processContext, null)) - override fun getSupportedAnnotationTypes(): Set { - return ImmutableSet.of( - RibInteractorProcessorPipeline.SUPPORT_ANNOTATION_TYPE.canonicalName, - ) - } + override fun getSupportedAnnotationTypes(): Set = + ImmutableSet.of(RibInteractorProcessorPipeline.SUPPORT_ANNOTATION_TYPE.canonicalName) } sources = ArrayList() } diff --git a/android/libraries/rib-compiler-test/src/main/kotlin/com/uber/rib/compiler/RibTestProcessor.kt b/android/libraries/rib-compiler-test/src/main/kotlin/com/uber/rib/compiler/RibTestProcessor.kt index e982f7c86..05942e8c0 100644 --- a/android/libraries/rib-compiler-test/src/main/kotlin/com/uber/rib/compiler/RibTestProcessor.kt +++ b/android/libraries/rib-compiler-test/src/main/kotlin/com/uber/rib/compiler/RibTestProcessor.kt @@ -33,13 +33,11 @@ public open class RibTestProcessor : RibProcessor() { super.init(processingEnv) } - override fun getSupportedAnnotationTypes(): Set { - return ImmutableSet.of(RibInteractorProcessorPipeline.SUPPORT_ANNOTATION_TYPE.canonicalName) - } + override fun getSupportedAnnotationTypes(): Set = + ImmutableSet.of(RibInteractorProcessorPipeline.SUPPORT_ANNOTATION_TYPE.canonicalName) - override fun getProcessorPipelines(processContext: ProcessContext): List { - return ImmutableList.of( - RibInteractorProcessorPipeline(processContext, interactorTestGenerator), + override fun getProcessorPipelines(processContext: ProcessContext): List = + ImmutableList.of( + RibInteractorProcessorPipeline(processContext, interactorTestGenerator) ) - } } diff --git a/android/libraries/rib-compiler-test/src/test/kotlin/com/uber/rib/compiler/InteractorTestGeneratorProcessorTestBase.kt b/android/libraries/rib-compiler-test/src/test/kotlin/com/uber/rib/compiler/InteractorTestGeneratorProcessorTestBase.kt index 78ca5f81c..3bb328b69 100644 --- a/android/libraries/rib-compiler-test/src/test/kotlin/com/uber/rib/compiler/InteractorTestGeneratorProcessorTestBase.kt +++ b/android/libraries/rib-compiler-test/src/test/kotlin/com/uber/rib/compiler/InteractorTestGeneratorProcessorTestBase.kt @@ -40,18 +40,12 @@ abstract class InteractorTestGeneratorProcessorTestBase { } override fun getProcessorPipelines( - processContext: ProcessContext, - ): List { - return listOf( - RibInteractorProcessorPipeline(processContext, interactorTestGenerator), - ) - } + processContext: ProcessContext + ): List = + listOf(RibInteractorProcessorPipeline(processContext, interactorTestGenerator)) - override fun getSupportedAnnotationTypes(): Set { - return ImmutableSet.of( - RibInteractorProcessorPipeline.SUPPORT_ANNOTATION_TYPE.canonicalName, - ) - } + override fun getSupportedAnnotationTypes(): Set = + ImmutableSet.of(RibInteractorProcessorPipeline.SUPPORT_ANNOTATION_TYPE.canonicalName) } sources = ArrayList() } @@ -60,7 +54,5 @@ abstract class InteractorTestGeneratorProcessorTestBase { sources.add(getResourceFile(file)) } - protected fun getResourceFile(file: String): JavaFileObject { - return JavaFileObjects.forResource(file) - } + protected fun getResourceFile(file: String): JavaFileObject = JavaFileObjects.forResource(file) } diff --git a/android/libraries/rib-coroutines-test/src/main/kotlin/com/uber/rib/core/RibCoroutinesRule.kt b/android/libraries/rib-coroutines-test/src/main/kotlin/com/uber/rib/core/RibCoroutinesRule.kt index af0671684..55945223b 100644 --- a/android/libraries/rib-coroutines-test/src/main/kotlin/com/uber/rib/core/RibCoroutinesRule.kt +++ b/android/libraries/rib-coroutines-test/src/main/kotlin/com/uber/rib/core/RibCoroutinesRule.kt @@ -24,10 +24,11 @@ import org.junit.runner.Description * facilitate install and cleanup of Test Dispatchers */ public class RibCoroutinesRule( - public val ribDispatchers: TestRibDispatchers = TestRibDispatchers(), + public val ribDispatchers: TestRibDispatchers = TestRibDispatchers() ) : TestWatcher() { private var originalDeprecatedWorkerDispatcher: CoroutineDispatcher? = null + override fun starting(description: Description) { ribDispatchers.installTestDispatchers() originalDeprecatedWorkerDispatcher = RibCoroutinesConfig.deprecatedWorkerDispatcher diff --git a/android/libraries/rib-coroutines-test/src/main/kotlin/com/uber/rib/core/TestRibCoroutineScopes.kt b/android/libraries/rib-coroutines-test/src/main/kotlin/com/uber/rib/core/TestRibCoroutineScopes.kt index c0b79485b..2af5d2ec6 100644 --- a/android/libraries/rib-coroutines-test/src/main/kotlin/com/uber/rib/core/TestRibCoroutineScopes.kt +++ b/android/libraries/rib-coroutines-test/src/main/kotlin/com/uber/rib/core/TestRibCoroutineScopes.kt @@ -39,7 +39,7 @@ public val ScopeProvider.testScopeOverride: TestScope? * testing. Accessible directly as [TestScope] via [ScopeProvider.TestScopeOverride]. */ public fun ScopeProvider.enableTestScopeOverride( - context: CoroutineContext = SupervisorJob(), + context: CoroutineContext = SupervisorJob() ): Unit = synchronized(LazyCoroutineScope) { LazyCoroutineScope[this] = asTestScope(context) } /** Disables the [ScopeProvider.coroutineScope] override with [TestScope] */ @@ -67,9 +67,8 @@ public fun Application.disableTestScopeOverride(): Unit = synchronized(LazyCoroutineScope) { LazyCoroutineScope[this] = null } /** Returns a new [TestScope] from the [ScopeProvider] */ -public fun ScopeProvider.asTestScope(context: CoroutineContext = SupervisorJob()): TestScope { - return requestScope().asTestScope(context) -} +public fun ScopeProvider.asTestScope(context: CoroutineContext = SupervisorJob()): TestScope = + requestScope().asTestScope(context) /** Returns a new [TestScope] from the [CompletableSource] */ public fun CompletableSource.asTestScope(context: CoroutineContext = SupervisorJob()): TestScope { diff --git a/android/libraries/rib-coroutines-test/src/test/kotlin/com/uber/rib/core/RibScopesTest.kt b/android/libraries/rib-coroutines-test/src/test/kotlin/com/uber/rib/core/RibScopesTest.kt index 16917843f..6ed9cc1a0 100644 --- a/android/libraries/rib-coroutines-test/src/test/kotlin/com/uber/rib/core/RibScopesTest.kt +++ b/android/libraries/rib-coroutines-test/src/test/kotlin/com/uber/rib/core/RibScopesTest.kt @@ -165,6 +165,7 @@ internal class RibScopesTest { var exceptions = mutableListOf() override val key: CoroutineContext.Key<*> = CoroutineExceptionHandler + override fun handleException(context: CoroutineContext, exception: Throwable) { exceptions.add(exception) } diff --git a/android/libraries/rib-coroutines/src/main/kotlin/com/uber/rib/core/RibCoroutineScopes.kt b/android/libraries/rib-coroutines/src/main/kotlin/com/uber/rib/core/RibCoroutineScopes.kt index 6d67979d8..4af539b35 100755 --- a/android/libraries/rib-coroutines/src/main/kotlin/com/uber/rib/core/RibCoroutineScopes.kt +++ b/android/libraries/rib-coroutines/src/main/kotlin/com/uber/rib/core/RibCoroutineScopes.kt @@ -73,10 +73,12 @@ public class LazyCoroutineScope(private val initializer: This.() -> // Used to get and set Test overrides from rib-coroutines-test utils public operator fun get(provider: Any): CoroutineScope? = values[provider] + public operator fun set(provider: Any, scope: CoroutineScope?) { values[provider] = scope } } + public operator fun getValue(thisRef: This, property: KProperty<*>): CoroutineScope = synchronized(LazyCoroutineScope) { return values.getOrPut(thisRef) { diff --git a/android/libraries/rib-coroutines/src/main/kotlin/com/uber/rib/core/RibCoroutinesConfig.kt b/android/libraries/rib-coroutines/src/main/kotlin/com/uber/rib/core/RibCoroutinesConfig.kt index 887bcf4ca..665a9f3fe 100644 --- a/android/libraries/rib-coroutines/src/main/kotlin/com/uber/rib/core/RibCoroutinesConfig.kt +++ b/android/libraries/rib-coroutines/src/main/kotlin/com/uber/rib/core/RibCoroutinesConfig.kt @@ -50,7 +50,7 @@ public object RibCoroutinesConfig { """ This dispatcher is only intended to be used within the [com.uber.rib.core.WorkerBinder]. For adding and binding new RIB workers please use [RibCoroutineWorker] - """, + """ ) @JvmStatic public var deprecatedWorkerDispatcher: CoroutineDispatcher = RibDispatchers.Unconfined diff --git a/android/libraries/rib-coroutines/src/main/kotlin/com/uber/rib/core/RibDispatchers.kt b/android/libraries/rib-coroutines/src/main/kotlin/com/uber/rib/core/RibDispatchers.kt index 02ebf1b9d..740c4a7ba 100644 --- a/android/libraries/rib-coroutines/src/main/kotlin/com/uber/rib/core/RibDispatchers.kt +++ b/android/libraries/rib-coroutines/src/main/kotlin/com/uber/rib/core/RibDispatchers.kt @@ -27,10 +27,13 @@ import kotlinx.coroutines.MainScope public object RibDispatchers : RibDispatchersProvider { override val Default: CoroutineDispatcher get() = RibCoroutinesConfig.dispatchers.Default + override val Main: MainCoroutineDispatcher get() = RibCoroutinesConfig.dispatchers.Main + override val IO: CoroutineDispatcher get() = RibCoroutinesConfig.dispatchers.IO + override val Unconfined: CoroutineDispatcher get() = RibCoroutinesConfig.dispatchers.Unconfined } @@ -43,6 +46,7 @@ public data class DefaultRibDispatchers( ) : RibDispatchersProvider /** Allows providing default Dispatchers used for Rib CoroutineScopes */ +@Suppress("PropertyName") public interface RibDispatchersProvider { /** diff --git a/android/libraries/rib-router-navigator/src/main/kotlin/com/uber/rib/core/RouterAndState.kt b/android/libraries/rib-router-navigator/src/main/kotlin/com/uber/rib/core/RouterAndState.kt index 2a009994b..1e678af6d 100644 --- a/android/libraries/rib-router-navigator/src/main/kotlin/com/uber/rib/core/RouterAndState.kt +++ b/android/libraries/rib-router-navigator/src/main/kotlin/com/uber/rib/core/RouterAndState.kt @@ -66,18 +66,17 @@ internal class RouterAndState, StateT : RouterNavigatorState>( } private fun wrapDetachTransitionIfNeed( - detachTransition: RouterNavigator.DetachTransition?, - ): RouterNavigator.DetachCallback? { - return (detachTransition as? RouterNavigator.DetachCallback) + detachTransition: RouterNavigator.DetachTransition? + ): RouterNavigator.DetachCallback? = + (detachTransition as? RouterNavigator.DetachCallback) ?: detachTransition?.let { DetachCallbackWrapper(it) } - } /** * Wrapper class to wrap [transitionCallback] calls into the new [RouterNavigator.DetachCallback] * format. */ private inner class DetachCallbackWrapper( - private val transitionCallback: RouterNavigator.DetachTransition, + private val transitionCallback: RouterNavigator.DetachTransition ) : RouterNavigator.DetachCallback() { override fun willDetachFromHost( @@ -112,9 +111,7 @@ internal class RouterAndState, StateT : RouterNavigatorState>( } } - private class SafeRouterAccessor>( - private val routerBuilder: () -> R, - ) { + private class SafeRouterAccessor>(private val routerBuilder: () -> R) { private val lock = ReentrantLock() private var _router: R? = null @@ -137,8 +134,7 @@ internal class RouterAndState, StateT : RouterNavigatorState>( _router?.javaClass?.simpleName?.let { routerName -> log("Destroying router $routerName was destroyed") _router = null - } - ?: run { log("Router of ${state.stateName()} state already destroyed") } + } ?: run { log("Router of ${state.stateName()} state already destroyed") } } } } diff --git a/android/libraries/rib-router-navigator/src/main/kotlin/com/uber/rib/core/RouterNavigatorEventType.kt b/android/libraries/rib-router-navigator/src/main/kotlin/com/uber/rib/core/RouterNavigatorEventType.kt index 9742e925d..7561f8cc5 100644 --- a/android/libraries/rib-router-navigator/src/main/kotlin/com/uber/rib/core/RouterNavigatorEventType.kt +++ b/android/libraries/rib-router-navigator/src/main/kotlin/com/uber/rib/core/RouterNavigatorEventType.kt @@ -17,5 +17,5 @@ package com.uber.rib.core /** Enum consisting of event types that occur when [RouterNavigator] is used for transition. */ public enum class RouterNavigatorEventType { - WILL_ATTACH_TO_HOST, + WILL_ATTACH_TO_HOST } diff --git a/android/libraries/rib-router-navigator/src/main/kotlin/com/uber/rib/core/RouterNavigatorFactory.kt b/android/libraries/rib-router-navigator/src/main/kotlin/com/uber/rib/core/RouterNavigatorFactory.kt index 1503d4007..57afef5e8 100644 --- a/android/libraries/rib-router-navigator/src/main/kotlin/com/uber/rib/core/RouterNavigatorFactory.kt +++ b/android/libraries/rib-router-navigator/src/main/kotlin/com/uber/rib/core/RouterNavigatorFactory.kt @@ -33,10 +33,9 @@ public class RouterNavigatorFactory(private val creationStrategy: Strategy?) { * @return A new [RouterNavigator] */ public open fun create( - hostRouter: Router<*>, - ): RouterNavigator { - return creationStrategy?.create(hostRouter) ?: StackRouterNavigator(hostRouter) - } + hostRouter: Router<*> + ): RouterNavigator = + creationStrategy?.create(hostRouter) ?: StackRouterNavigator(hostRouter) /** Strategy to employ when using this factory to generate new [RouterNavigator]s. */ public interface Strategy { @@ -48,7 +47,7 @@ public class RouterNavigatorFactory(private val creationStrategy: Strategy?) { * @return A new [RouterNavigator] */ public fun create( - hostRouter: Router<*>, + hostRouter: Router<*> ): RouterNavigator } } diff --git a/android/libraries/rib-router-navigator/src/main/kotlin/com/uber/rib/core/RouterNavigatorState.kt b/android/libraries/rib-router-navigator/src/main/kotlin/com/uber/rib/core/RouterNavigatorState.kt index 9dd80a4b8..c93821f13 100644 --- a/android/libraries/rib-router-navigator/src/main/kotlin/com/uber/rib/core/RouterNavigatorState.kt +++ b/android/libraries/rib-router-navigator/src/main/kotlin/com/uber/rib/core/RouterNavigatorState.kt @@ -19,13 +19,12 @@ package com.uber.rib.core public interface RouterNavigatorState { /** @return identifier for a [StackRouterNavigator] state. */ - public fun stateName(): String { - return if (this.javaClass.isEnum) { + public fun stateName(): String = + if (this.javaClass.isEnum) { (this as Enum<*>).name } else { throw java.lang.AssertionError("Must be implemented by enum or override stateName()") } - } /** * @return Boolean flag configure router caching behavior between transactions. diff --git a/android/libraries/rib-router-navigator/src/main/kotlin/com/uber/rib/core/StackRouterNavigator.kt b/android/libraries/rib-router-navigator/src/main/kotlin/com/uber/rib/core/StackRouterNavigator.kt index 937a93832..933ad9458 100644 --- a/android/libraries/rib-router-navigator/src/main/kotlin/com/uber/rib/core/StackRouterNavigator.kt +++ b/android/libraries/rib-router-navigator/src/main/kotlin/com/uber/rib/core/StackRouterNavigator.kt @@ -51,7 +51,7 @@ constructor( Locale.getDefault(), "Preparing to pop existing transient state for router: %s", fromRouterName, - ), + ) ) } else { if (!navigationStack.isEmpty()) { @@ -62,7 +62,7 @@ constructor( Locale.getDefault(), "Preparing to pop existing state for router: %s", fromRouterName, - ), + ) ) } } @@ -184,10 +184,7 @@ constructor( return top.state } - @IntRange(from = 0) - override fun size(): Int { - return navigationStack.size - } + @IntRange(from = 0) override fun size(): Int = navigationStack.size /** * This will pop the current active router and clear the entire stack. @@ -200,7 +197,7 @@ constructor( Locale.getDefault(), "Detaching RouterNavigator from host -> %s", hostRouterName, - ), + ) ) val currentRouterAndState = peekCurrentRouterAndState() detachInternal(currentRouterAndState, null as StateT?, false) @@ -212,14 +209,13 @@ constructor( newState: StateT, attachTransition: RouterNavigator.AttachTransition, detachTransition: RouterNavigator.DetachTransition?, - ): RouterAndState { - return RouterAndState( + ): RouterAndState = + RouterAndState( newState, attachTransition, detachTransition, forceRouterCaching = forceRouterCaching, ) - } /** * Handles the attachment logic for a router. @@ -247,7 +243,7 @@ constructor( "Attaching %s as a child of %s", toRouterName, hostRouterName, - ), + ) ) hostRouter.attachChild(toRouterState.router) } @@ -279,13 +275,12 @@ constructor( fromRouterState.onPostDetachFromHost(toState, isPush) } - private fun peekCurrentRouterAndState(): RouterAndState<*, StateT>? { - return if (currentTransientRouterAndState != null) { + private fun peekCurrentRouterAndState(): RouterAndState<*, StateT>? = + if (currentTransientRouterAndState != null) { currentTransientRouterAndState } else { navigationStack.peek() } - } private fun > clearTop( currentRouterAndState: RouterAndState<*, StateT>?, @@ -413,7 +408,7 @@ constructor( Locale.getDefault(), "Installed new RouterNavigator: Hosting Router -> %s", hostRouterName, - ), + ) ) } } diff --git a/android/libraries/rib-router-navigator/src/test/kotlin/com/uber/rib/core/RouterAndStateTest.kt b/android/libraries/rib-router-navigator/src/test/kotlin/com/uber/rib/core/RouterAndStateTest.kt index e538f0f9a..38246b0e5 100644 --- a/android/libraries/rib-router-navigator/src/test/kotlin/com/uber/rib/core/RouterAndStateTest.kt +++ b/android/libraries/rib-router-navigator/src/test/kotlin/com/uber/rib/core/RouterAndStateTest.kt @@ -159,12 +159,7 @@ class RouterAndStateTest { destroyedRouters.add(it.arguments[0] as Router<*>) } - val routerAndState = - RouterAndState( - state, - attachTransition, - detachCallback, - ) + val routerAndState = RouterAndState(state, attachTransition, detachCallback) val threadsCount = 10 val latch = CountDownLatch(threadsCount) diff --git a/android/libraries/rib-screen-stack-base/src/main/kotlin/com/uber/rib/core/screenstack/ViewProvider.kt b/android/libraries/rib-screen-stack-base/src/main/kotlin/com/uber/rib/core/screenstack/ViewProvider.kt index 848bebcf3..b8183a06a 100644 --- a/android/libraries/rib-screen-stack-base/src/main/kotlin/com/uber/rib/core/screenstack/ViewProvider.kt +++ b/android/libraries/rib-screen-stack-base/src/main/kotlin/com/uber/rib/core/screenstack/ViewProvider.kt @@ -64,9 +64,7 @@ abstract class ViewProvider { * * @return TRUE if the provider handled the back press. */ - open fun onBackPress(): Boolean { - return false - } + open fun onBackPress(): Boolean = false /** Notifies the view provider that view is at the top of the stack and visible. */ @CallSuper diff --git a/android/libraries/rib-test/src/main/kotlin/com/uber/rib/core/FakeComponent.kt b/android/libraries/rib-test/src/main/kotlin/com/uber/rib/core/FakeComponent.kt index 5a99c0ffe..ce28be232 100644 --- a/android/libraries/rib-test/src/main/kotlin/com/uber/rib/core/FakeComponent.kt +++ b/android/libraries/rib-test/src/main/kotlin/com/uber/rib/core/FakeComponent.kt @@ -16,22 +16,16 @@ package com.uber.rib.core public class FakeComponent

> -private constructor( - private val presenter: P, -) : InteractorComponent { +private constructor(private val presenter: P) : InteractorComponent { override fun inject(interactor: T) {} - override fun presenter(): P { - return presenter - } + override fun presenter(): P = presenter public companion object { @JvmStatic public fun > withFakePresenterFor( - interactorClass: Class, - ): FakeComponent { - return FakeComponent(FakePresenter()) - } + interactorClass: Class + ): FakeComponent = FakeComponent(FakePresenter()) } } diff --git a/android/libraries/rib-test/src/main/kotlin/com/uber/rib/core/FakeRouter.kt b/android/libraries/rib-test/src/main/kotlin/com/uber/rib/core/FakeRouter.kt index eae9c50d7..8c41c9f37 100644 --- a/android/libraries/rib-test/src/main/kotlin/com/uber/rib/core/FakeRouter.kt +++ b/android/libraries/rib-test/src/main/kotlin/com/uber/rib/core/FakeRouter.kt @@ -22,6 +22,7 @@ package com.uber.rib.core */ public class FakeRouter> : Router { public constructor(interactor: I) : super(interactor) + public constructor( interactor: I, ribRefWatcher: RibRefWatcher, diff --git a/android/libraries/rib-test/src/main/kotlin/com/uber/rib/core/WorkerHelper.kt b/android/libraries/rib-test/src/main/kotlin/com/uber/rib/core/WorkerHelper.kt index 5c54ea98a..7457cc097 100644 --- a/android/libraries/rib-test/src/main/kotlin/com/uber/rib/core/WorkerHelper.kt +++ b/android/libraries/rib-test/src/main/kotlin/com/uber/rib/core/WorkerHelper.kt @@ -27,7 +27,6 @@ public object WorkerHelper { * @return a [WorkerScopeProvider]. */ @JvmStatic - public fun createScopeProvider(lifecycle: Observable): WorkerScopeProvider { - return WorkerScopeProvider(lifecycle) - } + public fun createScopeProvider(lifecycle: Observable): WorkerScopeProvider = + WorkerScopeProvider(lifecycle) } diff --git a/android/libraries/rib-workflow-test/src/main/kotlin/com/uber/rib/workflow/core/StepTester.kt b/android/libraries/rib-workflow-test/src/main/kotlin/com/uber/rib/workflow/core/StepTester.kt index 20f4f138c..bd6781633 100644 --- a/android/libraries/rib-workflow-test/src/main/kotlin/com/uber/rib/workflow/core/StepTester.kt +++ b/android/libraries/rib-workflow-test/src/main/kotlin/com/uber/rib/workflow/core/StepTester.kt @@ -32,10 +32,8 @@ public object StepTester { */ @JvmStatic public fun exposeObservable( - step: Step, - ): Observable>> { - return step.asObservable() - } + step: Step + ): Observable>> = step.asObservable() /** * Exposes the [com.uber.rib.workflow.core.Step.Data] of a [Step] @@ -46,9 +44,7 @@ public object StepTester { * @return the data of the step */ @JvmStatic - public fun exposeStepData(step: Step.Data): T? { - return step.getValue() - } + public fun exposeStepData(step: Step.Data): T? = step.getValue() /** * Asserts that no [Step] has been emitted from the [TestObserver] @@ -59,7 +55,7 @@ public object StepTester { */ @JvmStatic public fun assertStepNotYetEmitted( - testSubscriber: TestObserver>>, + testSubscriber: TestObserver>> ) { testSubscriber.run { assertNoValues() @@ -77,7 +73,7 @@ public object StepTester { */ @JvmStatic public fun assertStepEmitted( - testSubscriber: TestObserver>>, + testSubscriber: TestObserver>> ) { testSubscriber.assertValueCount(1) val stepData: Optional> = testSubscriber.values()[0] diff --git a/android/libraries/rib-workflow/src/main/kotlin/com/uber/rib/workflow/core/Step.kt b/android/libraries/rib-workflow/src/main/kotlin/com/uber/rib/workflow/core/Step.kt index e3a460969..b85a2b6cc 100644 --- a/android/libraries/rib-workflow/src/main/kotlin/com/uber/rib/workflow/core/Step.kt +++ b/android/libraries/rib-workflow/src/main/kotlin/com/uber/rib/workflow/core/Step.kt @@ -30,9 +30,7 @@ import io.reactivex.functions.BiFunction * @param type of [ActionableItem] this step returns when finished. */ open class Step -private constructor( - private val stepDataSingle: Single>>, -) { +private constructor(private val stepDataSingle: Single>>) { /** * Chains another step to be performed after this step completes. If the previous step results in @@ -48,9 +46,9 @@ private constructor( @OptIn(WorkflowFriendModuleApi::class) @SuppressWarnings("RxJavaToSingle") // Replace singleOrError() with firstOrError() public open fun onStep( - func: BiFunction>, - ): Step { - return Step( + func: BiFunction> + ): Step = + Step( asObservable() .flatMap { data: Optional> -> if (data.isPresent) { @@ -59,14 +57,12 @@ private constructor( Observable.just(Optional.absent()) } } - .singleOrError(), + .singleOrError() ) - } @OptIn(WorkflowFriendModuleApi::class) - internal open fun asResultObservable(): Observable> { - return asObservable().map { data -> Optional.fromNullable(data.orNull()?.getValue()) } - } + internal open fun asResultObservable(): Observable> = + asObservable().map { data -> Optional.fromNullable(data.orNull()?.getValue()) } @WorkflowFriendModuleApi public open fun asObservable(): Observable>> { @@ -111,9 +107,8 @@ private constructor( * @return a new [Step.Data] instance. */ @JvmStatic - public fun toActionableItem(actionableItem: A): Data { - return Data(NoValueHolder.INSTANCE, actionableItem) - } + public fun toActionableItem(actionableItem: A): Data = + Data(NoValueHolder.INSTANCE, actionableItem) } } @@ -135,9 +130,8 @@ private constructor( * @return a new [Step]. */ @JvmStatic - fun from(stepDataSingle: Single>): Step { - return Step(stepDataSingle.map { Optional.of(it) }) - } + fun from(stepDataSingle: Single>): Step = + Step(stepDataSingle.map { Optional.of(it) }) /** * Create a new step with a single that can emit an absent result. @@ -152,7 +146,7 @@ private constructor( */ @JvmStatic fun fromOptional( - stepDataSingle: Single>>, + stepDataSingle: Single>> ): Step = Step(stepDataSingle) } } diff --git a/android/libraries/rib-workflow/src/main/kotlin/com/uber/rib/workflow/core/Workflow.kt b/android/libraries/rib-workflow/src/main/kotlin/com/uber/rib/workflow/core/Workflow.kt index 862fdc121..f4e8f56b6 100644 --- a/android/libraries/rib-workflow/src/main/kotlin/com/uber/rib/workflow/core/Workflow.kt +++ b/android/libraries/rib-workflow/src/main/kotlin/com/uber/rib/workflow/core/Workflow.kt @@ -33,15 +33,14 @@ abstract class Workflow { * @return an Rx [Single] that will return the workflow when subscribed to. */ @SuppressWarnings("RxJavaToSingle") // Replace singleOrError() with firstOrError() - open fun createSingle(rootActionableItem: TRootActionableItem): Single> { - return getSteps(rootActionableItem).asResultObservable().singleOrError() - } + open fun createSingle(rootActionableItem: TRootActionableItem): Single> = + getSteps(rootActionableItem).asResultObservable().singleOrError() /** * @param rootActionableItem to create steps from. * @return steps to be performed for this workflow. */ protected abstract fun getSteps( - rootActionableItem: TRootActionableItem, + rootActionableItem: TRootActionableItem ): Step } diff --git a/android/libraries/rib-workflow/src/test/kotlin/com/uber/rib/workflow/core/AndroidSchedulersRule.kt b/android/libraries/rib-workflow/src/test/kotlin/com/uber/rib/workflow/core/AndroidSchedulersRule.kt index 4244d3c75..cae6b9c63 100644 --- a/android/libraries/rib-workflow/src/test/kotlin/com/uber/rib/workflow/core/AndroidSchedulersRule.kt +++ b/android/libraries/rib-workflow/src/test/kotlin/com/uber/rib/workflow/core/AndroidSchedulersRule.kt @@ -30,9 +30,7 @@ import org.junit.runner.Description */ class AndroidSchedulersRule @JvmOverloads -constructor( - private val restoreHandlers: Boolean = false, -) : TestWatcher() { +constructor(private val restoreHandlers: Boolean = false) : TestWatcher() { private val delegatingMainThreadScheduler = DelegatingScheduler.forType(DelegatingScheduler.SchedulerType.MAIN_THREAD) diff --git a/android/libraries/rib-workflow/src/test/kotlin/com/uber/rib/workflow/core/DelegatingScheduler.kt b/android/libraries/rib-workflow/src/test/kotlin/com/uber/rib/workflow/core/DelegatingScheduler.kt index f8ec4031b..46ad9ee84 100644 --- a/android/libraries/rib-workflow/src/test/kotlin/com/uber/rib/workflow/core/DelegatingScheduler.kt +++ b/android/libraries/rib-workflow/src/test/kotlin/com/uber/rib/workflow/core/DelegatingScheduler.kt @@ -22,30 +22,20 @@ import java.util.concurrent.TimeUnit import java.util.concurrent.atomic.AtomicReference class DelegatingScheduler -private constructor( - @get:VisibleForTesting val schedulerType: SchedulerType, -) : Scheduler() { +private constructor(@get:VisibleForTesting val schedulerType: SchedulerType) : Scheduler() { private val activeScheduler = AtomicReference(Schedulers.trampoline()) @VisibleForTesting enum class SchedulerType { - MAIN_THREAD, + MAIN_THREAD } - override fun createWorker(): Worker { - return activeScheduler().createWorker() - } + override fun createWorker(): Worker = activeScheduler().createWorker() - override fun now(unit: TimeUnit): Long { - return activeScheduler().now(unit) - } + override fun now(unit: TimeUnit): Long = activeScheduler().now(unit) - @VisibleForTesting - @Synchronized - fun activeScheduler(): Scheduler { - return activeScheduler.get() - } + @VisibleForTesting @Synchronized fun activeScheduler(): Scheduler = activeScheduler.get() @Synchronized fun setActiveScheduler(activeScheduler: Scheduler) { diff --git a/android/libraries/rib-workflow/src/test/kotlin/com/uber/rib/workflow/core/StepTest.kt b/android/libraries/rib-workflow/src/test/kotlin/com/uber/rib/workflow/core/StepTest.kt index aac739847..35811c0da 100644 --- a/android/libraries/rib-workflow/src/test/kotlin/com/uber/rib/workflow/core/StepTest.kt +++ b/android/libraries/rib-workflow/src/test/kotlin/com/uber/rib/workflow/core/StepTest.kt @@ -53,7 +53,7 @@ class StepTest { testSubscriber.assertNoErrors() testSubscriber.assertNotComplete() returnValueSubject.onNext( - Optional.of(Data(returnValue, ActionableItem { interactorLifecycleSubject.hide() })), + Optional.of(Data(returnValue, ActionableItem { interactorLifecycleSubject.hide() })) ) returnValueSubject.onComplete() testSubscriber.assertNoValues() @@ -77,7 +77,7 @@ class StepTest { testSubscriber.assertNoErrors() testSubscriber.assertNotComplete() returnValueSubject.onNext( - Optional.of(Data(returnValue, ActionableItem { interactorLifecycleSubject.hide() })), + Optional.of(Data(returnValue, ActionableItem { interactorLifecycleSubject.hide() })) ) returnValueSubject.onComplete() testSubscriber.assertValueCount(1) @@ -95,14 +95,12 @@ class StepTest { interactorLifecycleSubject.onNext(InteractorEvent.ACTIVE) step .onStep { o, actionableItem -> - Step.from( - Observable.just(Data(secondReturnValue, actionableItem)).singleOrError(), - ) + Step.from(Observable.just(Data(secondReturnValue, actionableItem)).singleOrError()) } .asObservable() .subscribe(testSubscriber) returnValueSubject.onNext( - Optional.of(Data(returnValue, ActionableItem { interactorLifecycleSubject.hide() })), + Optional.of(Data(returnValue, ActionableItem { interactorLifecycleSubject.hide() })) ) returnValueSubject.onComplete() testSubscriber.assertValueCount(1) @@ -119,9 +117,7 @@ class StepTest { interactorLifecycleSubject.onNext(InteractorEvent.ACTIVE) step .onStep { _, actionableItem -> - Step.from( - Observable.just(Data(secondReturnValue, actionableItem)).singleOrError(), - ) + Step.from(Observable.just(Data(secondReturnValue, actionableItem)).singleOrError()) } .asObservable() .subscribe(testSubscriber) diff --git a/android/libraries/rib-workflow/src/test/kotlin/com/uber/rib/workflow/core/WorkflowTest.kt b/android/libraries/rib-workflow/src/test/kotlin/com/uber/rib/workflow/core/WorkflowTest.kt index 0942296b4..4d0e23c39 100644 --- a/android/libraries/rib-workflow/src/test/kotlin/com/uber/rib/workflow/core/WorkflowTest.kt +++ b/android/libraries/rib-workflow/src/test/kotlin/com/uber/rib/workflow/core/WorkflowTest.kt @@ -53,9 +53,8 @@ class WorkflowTest { val workflow: Workflow = object : Workflow() { - override fun getSteps(rootActionableItem: ActionableItem): Step { - return from(returnValueSubject.singleOrError()) - } + override fun getSteps(rootActionableItem: ActionableItem): Step = + from(returnValueSubject.singleOrError()) } val testSubscriber = TestObserver>() diff --git a/android/tooling/rib-flipper-plugin/src/main/kotlin/com/uber/rib/flipper/RibEventPayload.kt b/android/tooling/rib-flipper-plugin/src/main/kotlin/com/uber/rib/flipper/RibEventPayload.kt index 80fcbd790..6d9c6c3c7 100644 --- a/android/tooling/rib-flipper-plugin/src/main/kotlin/com/uber/rib/flipper/RibEventPayload.kt +++ b/android/tooling/rib-flipper-plugin/src/main/kotlin/com/uber/rib/flipper/RibEventPayload.kt @@ -46,13 +46,12 @@ internal class RibEventPayload( val eventName: String get() = eventType.toString() - fun toFlipperPayload(): FlipperObject { - return FlipperObject.Builder() + fun toFlipperPayload(): FlipperObject = + FlipperObject.Builder() .put(EVENT_PARAMETER_SESSION_ID, sessionId) .put(EVENT_PARAMETER_ROUTER, routerInfo.toFlipperPayload()) .put(EVENT_PARAMETER_PARENT, parentRouterInfo.toFlipperPayload()) .build() - } internal class RouterInfo( val id: String, @@ -86,14 +85,13 @@ internal class RibEventPayload( } } - fun toFlipperPayload(): FlipperObject { - return FlipperObject.Builder() + fun toFlipperPayload(): FlipperObject = + FlipperObject.Builder() .put(EVENT_PARAMETER_ID, id) .put(EVENT_PARAMETER_NAME, name) .put(EVENT_PARAMETER_ROUTER_CLASSNAME, className) .put(EVENT_PARAMETER_HAS_VIEW, hasView) .put(EVENT_PARAMETER_HOST_CLASSNAME, activityClassName) .build() - } } } diff --git a/android/tooling/rib-flipper-plugin/src/main/kotlin/com/uber/rib/flipper/RibTreePlugin.kt b/android/tooling/rib-flipper-plugin/src/main/kotlin/com/uber/rib/flipper/RibTreePlugin.kt index db990105c..645ad73ab 100644 --- a/android/tooling/rib-flipper-plugin/src/main/kotlin/com/uber/rib/flipper/RibTreePlugin.kt +++ b/android/tooling/rib-flipper-plugin/src/main/kotlin/com/uber/rib/flipper/RibTreePlugin.kt @@ -67,9 +67,7 @@ class RibTreePlugin : FlipperPlugin { .subscribe(events) } - override fun getId(): String { - return "ribtree" - } + override fun getId(): String = "ribtree" override fun onConnect(connection: FlipperConnection) { android.util.Log.d("RibTreeFlipperPlugin", "onConnect()") @@ -110,9 +108,7 @@ class RibTreePlugin : FlipperPlugin { connection = null } - override fun runInBackground(): Boolean { - return true - } + override fun runInBackground(): Boolean = true @Synchronized private fun getRouterById(id: String): Router<*>? { diff --git a/android/tooling/rib-intellij-plugin/src/main/kotlin/com/uber/intellij/plugin/android/rib/CommandLineUtils.kt b/android/tooling/rib-intellij-plugin/src/main/kotlin/com/uber/intellij/plugin/android/rib/CommandLineUtils.kt index 49f9d79ff..8b1a976fa 100644 --- a/android/tooling/rib-intellij-plugin/src/main/kotlin/com/uber/intellij/plugin/android/rib/CommandLineUtils.kt +++ b/android/tooling/rib-intellij-plugin/src/main/kotlin/com/uber/intellij/plugin/android/rib/CommandLineUtils.kt @@ -38,9 +38,8 @@ public object CommandLineUtils { * @throws ExecutionException * @throws IOException */ - public fun which(project: Project, command: String): String { - return executeWithLineOutput(project, "which", command).output()[0] - } + public fun which(project: Project, command: String): String = + executeWithLineOutput(project, "which", command).output()[0] /** * Executes the given `command` appending the given `params` and returns the output. @@ -96,13 +95,9 @@ public object CommandLineUtils { public class ProcessOutput(private val output: List, private val error: List) { /** Returns the process std output */ - public fun output(): List { - return output - } + public fun output(): List = output /** Returns the process error output */ - public fun error(): List { - return error - } + public fun error(): List = error } } diff --git a/android/tooling/rib-intellij-plugin/src/main/kotlin/com/uber/intellij/plugin/android/rib/RibHierarchyBrowser.kt b/android/tooling/rib-intellij-plugin/src/main/kotlin/com/uber/intellij/plugin/android/rib/RibHierarchyBrowser.kt index e402dcc84..6fbf3ad4c 100644 --- a/android/tooling/rib-intellij-plugin/src/main/kotlin/com/uber/intellij/plugin/android/rib/RibHierarchyBrowser.kt +++ b/android/tooling/rib-intellij-plugin/src/main/kotlin/com/uber/intellij/plugin/android/rib/RibHierarchyBrowser.kt @@ -108,21 +108,14 @@ public class RibHierarchyBrowser( private var refreshComplete: Boolean = false - private fun isUpdating(): Boolean { - return status == Status.INITIALIZING || status == Status.REFRESHING - } + private fun isUpdating(): Boolean = status == Status.INITIALIZING || status == Status.REFRESHING - override fun isApplicableElement(element: PsiElement): Boolean { - return element is PsiClass - } + override fun isApplicableElement(element: PsiElement): Boolean = element is PsiClass - override fun getActionPlace(): String { - return ActionPlaces.METHOD_HIERARCHY_VIEW_TOOLBAR - } + override fun getActionPlace(): String = ActionPlaces.METHOD_HIERARCHY_VIEW_TOOLBAR - override fun getComparator(): Comparator> { - return JavaHierarchyUtil.getComparator(myProject) - } + override fun getComparator(): Comparator> = + JavaHierarchyUtil.getComparator(myProject) override fun getElementFromDescriptor(descriptor: HierarchyNodeDescriptor): PsiElement? { if (isRootElement(descriptor.psiElement)) { @@ -131,17 +124,12 @@ public class RibHierarchyBrowser( return descriptor.psiElement } - override fun getPrevOccurenceActionNameImpl(): String { - return LABEL_GO_PREVIOUS_RIB - } + override fun getPrevOccurenceActionNameImpl(): String = LABEL_GO_PREVIOUS_RIB - override fun createLegendPanel(): JPanel? { - return null - } + override fun createLegendPanel(): JPanel? = null + + override fun getNextOccurenceActionNameImpl(): String = LABEL_GO_NEXT_RIB - override fun getNextOccurenceActionNameImpl(): String { - return LABEL_GO_NEXT_RIB - } override fun createTrees(trees: MutableMap) { trees[TYPE_HIERARCHY_TYPE] = createTree(true) } @@ -286,7 +274,7 @@ public class RibHierarchyBrowser( override fun actionPerformed(e: AnActionEvent) { BrowserUtil.open( - "https://github.com/uber/RIBs/wiki/Android-Tooling#ribs-intellij-plugin-for-android", + "https://github.com/uber/RIBs/wiki/Android-Tooling#ribs-intellij-plugin-for-android" ) } diff --git a/android/tooling/rib-intellij-plugin/src/main/kotlin/com/uber/intellij/plugin/android/rib/RibHierarchyUtils.kt b/android/tooling/rib-intellij-plugin/src/main/kotlin/com/uber/intellij/plugin/android/rib/RibHierarchyUtils.kt index 70640aaca..0e4e26f14 100644 --- a/android/tooling/rib-intellij-plugin/src/main/kotlin/com/uber/intellij/plugin/android/rib/RibHierarchyUtils.kt +++ b/android/tooling/rib-intellij-plugin/src/main/kotlin/com/uber/intellij/plugin/android/rib/RibHierarchyUtils.kt @@ -88,9 +88,8 @@ public class RibHierarchyUtils { } /** Check if the element supplied is a root element. */ - public fun isRootElement(element: PsiElement?): Boolean { - return element is PsiClass && element.qualifiedName == Object::class.java.name - } + public fun isRootElement(element: PsiElement?): Boolean = + element is PsiClass && element.qualifiedName == Object::class.java.name /** Format fully qualified class name. */ public fun formatQualifiedName(qualifiedName: String): String { @@ -158,11 +157,10 @@ public class RibHierarchyUtils { } /** Returns whether virtual file belongs to project and appears to be a layout file */ - public fun isProjectLayoutFile(project: Project, file: VirtualFile): Boolean { - return ProjectRootManager.getInstance(project).fileIndex.isInContent(file) && + public fun isProjectLayoutFile(project: Project, file: VirtualFile): Boolean = + ProjectRootManager.getInstance(project).fileIndex.isInContent(file) && file.fileType is XmlFileType && file.path.contains("/$LAYOUT_FOLDER_NAME/") - } /** Display popup balloon. */ public fun displayPopup( diff --git a/android/tooling/rib-intellij-plugin/src/main/kotlin/com/uber/intellij/plugin/android/rib/RibProjectService.kt b/android/tooling/rib-intellij-plugin/src/main/kotlin/com/uber/intellij/plugin/android/rib/RibProjectService.kt index 08e0d3b7c..c7c374723 100644 --- a/android/tooling/rib-intellij-plugin/src/main/kotlin/com/uber/intellij/plugin/android/rib/RibProjectService.kt +++ b/android/tooling/rib-intellij-plugin/src/main/kotlin/com/uber/intellij/plugin/android/rib/RibProjectService.kt @@ -114,7 +114,7 @@ public class RibProjectService(public val project: Project) : ) } } - }, + } ) } } @@ -129,9 +129,7 @@ public class RibProjectService(public val project: Project) : LogcatRequestProcessor().execute(RibHighlightRequest(device, id)) } - public fun isLocating(): Boolean { - return isLocating - } + public fun isLocating(): Boolean = isLocating public fun enableLocateMode() { if (isLocating) { @@ -172,7 +170,7 @@ public class RibProjectService(public val project: Project) : ) } } - }, + } ) } @@ -190,9 +188,7 @@ public class RibProjectService(public val project: Project) : refreshRibHierarchy() } - public fun hasSelectedDevice(): Boolean { - return selectedDevice != null - } + public fun hasSelectedDevice(): Boolean = selectedDevice != null override fun onAvailableDevicesChanged(devices: List) { this.devices = devices diff --git a/android/tooling/rib-intellij-plugin/src/main/kotlin/com/uber/intellij/plugin/android/rib/RibViewBrowser.kt b/android/tooling/rib-intellij-plugin/src/main/kotlin/com/uber/intellij/plugin/android/rib/RibViewBrowser.kt index b9d728d05..004487bea 100644 --- a/android/tooling/rib-intellij-plugin/src/main/kotlin/com/uber/intellij/plugin/android/rib/RibViewBrowser.kt +++ b/android/tooling/rib-intellij-plugin/src/main/kotlin/com/uber/intellij/plugin/android/rib/RibViewBrowser.kt @@ -82,17 +82,12 @@ public class RibViewBrowser( private var hasFocus: Boolean = false - override fun isApplicableElement(element: PsiElement): Boolean { - return element is PsiClass - } + override fun isApplicableElement(element: PsiElement): Boolean = element is PsiClass - override fun getActionPlace(): String { - return ActionPlaces.METHOD_HIERARCHY_VIEW_TOOLBAR - } + override fun getActionPlace(): String = ActionPlaces.METHOD_HIERARCHY_VIEW_TOOLBAR - override fun getComparator(): Comparator> { - return JavaHierarchyUtil.getComparator(myProject) - } + override fun getComparator(): Comparator> = + JavaHierarchyUtil.getComparator(myProject) override fun getElementFromDescriptor(descriptor: HierarchyNodeDescriptor): PsiElement? { if (isRootElement(descriptor.psiElement)) { @@ -101,21 +96,15 @@ public class RibViewBrowser( return descriptor.psiElement } - override fun getPrevOccurenceActionNameImpl(): String { - return LABEL_GO_PREVIOUS_RIB - } + override fun getPrevOccurenceActionNameImpl(): String = LABEL_GO_PREVIOUS_RIB - override fun createLegendPanel(): JPanel? { - return null - } + override fun createLegendPanel(): JPanel? = null override fun createTrees(trees: MutableMap) { trees[TYPE_HIERARCHY_TYPE] = createTree(true) } - override fun getNextOccurenceActionNameImpl(): String { - return LABEL_GO_NEXT_RIB - } + override fun getNextOccurenceActionNameImpl(): String = LABEL_GO_NEXT_RIB override fun getContentDisplayName(typeName: String, element: PsiElement): String? { if (element !is PsiClass) { @@ -150,7 +139,7 @@ public class RibViewBrowser( hasFocus = true notifySelectedViewChanged() } - }, + } ) tree.addTreeSelectionListener { notifySelectedViewChanged() } @@ -163,8 +152,7 @@ public class RibViewBrowser( RibHierarchyUtils.findRibViewRecursive( this.model.rootRib.view, UUID.fromString(model.selectedViewId), - ) - ?: return@invokeLater + ) ?: return@invokeLater selectionListener?.onSelectedViewChanged(ribView) ApplicationManager.getApplication().invokeLater { selectById(model.selectedViewId) } diff --git a/android/tooling/rib-intellij-plugin/src/main/kotlin/com/uber/intellij/plugin/android/rib/io/LogcatMessageDecoder.kt b/android/tooling/rib-intellij-plugin/src/main/kotlin/com/uber/intellij/plugin/android/rib/io/LogcatMessageDecoder.kt index b95662fea..8fa1fcfb6 100644 --- a/android/tooling/rib-intellij-plugin/src/main/kotlin/com/uber/intellij/plugin/android/rib/io/LogcatMessageDecoder.kt +++ b/android/tooling/rib-intellij-plugin/src/main/kotlin/com/uber/intellij/plugin/android/rib/io/LogcatMessageDecoder.kt @@ -34,13 +34,9 @@ public class LogcatMessageDecoder { part = message.substring(spaceIndex + 1) } - override fun compareTo(other: MessagePart): Int { - return partNumber.compareTo(other.partNumber) - } + override fun compareTo(other: MessagePart): Int = partNumber.compareTo(other.partNumber) - override fun toString(): String { - return part - } + override fun toString(): String = part } private var partCount: Int = 0 diff --git a/android/tooling/rib-intellij-plugin/src/main/kotlin/com/uber/intellij/plugin/android/rib/io/LogcatRequestProcessor.kt b/android/tooling/rib-intellij-plugin/src/main/kotlin/com/uber/intellij/plugin/android/rib/io/LogcatRequestProcessor.kt index c6f48f8f6..8543b5a83 100644 --- a/android/tooling/rib-intellij-plugin/src/main/kotlin/com/uber/intellij/plugin/android/rib/io/LogcatRequestProcessor.kt +++ b/android/tooling/rib-intellij-plugin/src/main/kotlin/com/uber/intellij/plugin/android/rib/io/LogcatRequestProcessor.kt @@ -51,8 +51,8 @@ public class LogcatRequestProcessor : RequestProcessor { private var result: Any? = null private var error: String? = null - override fun execute(request: Request): ListenableFuture { - return service.submit( + override fun execute(request: Request): ListenableFuture = + service.submit( Callable { val sequence: Int = counter.getAndIncrement() % MAX_SEQUENCE @@ -97,9 +97,8 @@ public class LogcatRequestProcessor : RequestProcessor { error("Command failed: ${response.errorDescription}") } result as T - }, + } ) - } private inner class LogCatOutputReceiver( private val device: IDevice, @@ -113,9 +112,7 @@ public class LogcatRequestProcessor : RequestProcessor { setTrimLine(false) } - override fun isCancelled(): Boolean { - return false - } + override fun isCancelled(): Boolean = false @SuppressWarnings("TooGenericExceptionCaught") override fun processNewLines(lines: Array) { @@ -147,8 +144,6 @@ public class LogcatRequestProcessor : RequestProcessor { } } - override fun isCancelled(): Boolean { - return false - } + override fun isCancelled(): Boolean = false } } diff --git a/android/tooling/rib-intellij-plugin/src/main/kotlin/com/uber/intellij/plugin/android/rib/ui/HierarchyBrowserBase.kt b/android/tooling/rib-intellij-plugin/src/main/kotlin/com/uber/intellij/plugin/android/rib/ui/HierarchyBrowserBase.kt index c0e5fe76b..bf207cf27 100644 --- a/android/tooling/rib-intellij-plugin/src/main/kotlin/com/uber/intellij/plugin/android/rib/ui/HierarchyBrowserBase.kt +++ b/android/tooling/rib-intellij-plugin/src/main/kotlin/com/uber/intellij/plugin/android/rib/ui/HierarchyBrowserBase.kt @@ -57,9 +57,8 @@ public abstract class HierarchyBrowserBase( TreeSpeedSearch(tree, { path -> path.lastPathComponent.toString() }, true) TreeUtil.installActions(tree) object : AutoScrollToSourceHandler() { - override fun isAutoScrollMode(): Boolean { - return HierarchyBrowserManager.getSettings(myProject).IS_AUTOSCROLL_TO_SOURCE - } + override fun isAutoScrollMode(): Boolean = + HierarchyBrowserManager.getSettings(myProject).IS_AUTOSCROLL_TO_SOURCE override fun setAutoScrollMode(state: Boolean) { HierarchyBrowserManager.getSettings(myProject).IS_AUTOSCROLL_TO_SOURCE = state diff --git a/android/tooling/rib-intellij-plugin/src/main/kotlin/com/uber/intellij/plugin/android/rib/ui/RibHierarchyActivityDescriptor.kt b/android/tooling/rib-intellij-plugin/src/main/kotlin/com/uber/intellij/plugin/android/rib/ui/RibHierarchyActivityDescriptor.kt index 1f612891d..4208a4372 100644 --- a/android/tooling/rib-intellij-plugin/src/main/kotlin/com/uber/intellij/plugin/android/rib/ui/RibHierarchyActivityDescriptor.kt +++ b/android/tooling/rib-intellij-plugin/src/main/kotlin/com/uber/intellij/plugin/android/rib/ui/RibHierarchyActivityDescriptor.kt @@ -39,7 +39,5 @@ public class RibHierarchyActivityDescriptor( text.ending.addText(" (${formatQualifiedName(ribActivity.name)})", getPackageNameAttributes()) } - override fun getIcon(element: PsiElement): Icon? { - return AllIcons.Actions.Execute - } + override fun getIcon(element: PsiElement): Icon? = AllIcons.Actions.Execute } diff --git a/android/tooling/rib-intellij-plugin/src/main/kotlin/com/uber/intellij/plugin/android/rib/ui/RibHierarchyApplicationDescriptor.kt b/android/tooling/rib-intellij-plugin/src/main/kotlin/com/uber/intellij/plugin/android/rib/ui/RibHierarchyApplicationDescriptor.kt index 9f7e92329..e34c1b49f 100644 --- a/android/tooling/rib-intellij-plugin/src/main/kotlin/com/uber/intellij/plugin/android/rib/ui/RibHierarchyApplicationDescriptor.kt +++ b/android/tooling/rib-intellij-plugin/src/main/kotlin/com/uber/intellij/plugin/android/rib/ui/RibHierarchyApplicationDescriptor.kt @@ -36,7 +36,5 @@ public class RibHierarchyApplicationDescriptor( text.ending.addText(ribApplication.name, getDefaultTextAttributes()) } - override fun getIcon(element: PsiElement): Icon? { - return AllIcons.Nodes.Parameter - } + override fun getIcon(element: PsiElement): Icon? = AllIcons.Nodes.Parameter } diff --git a/android/tooling/rib-intellij-plugin/src/main/kotlin/com/uber/intellij/plugin/android/rib/ui/RibHierarchyDescriptor.kt b/android/tooling/rib-intellij-plugin/src/main/kotlin/com/uber/intellij/plugin/android/rib/ui/RibHierarchyDescriptor.kt index 7dd283c61..6d2388f24 100644 --- a/android/tooling/rib-intellij-plugin/src/main/kotlin/com/uber/intellij/plugin/android/rib/ui/RibHierarchyDescriptor.kt +++ b/android/tooling/rib-intellij-plugin/src/main/kotlin/com/uber/intellij/plugin/android/rib/ui/RibHierarchyDescriptor.kt @@ -38,9 +38,7 @@ public open class RibHierarchyDescriptor( public open fun updateText(text: CompositeAppearance) {} /** Method used to get the unique id of descriptor. Used for programmatic selection. */ - public open fun getUniqueId(): String? { - return null - } + public open fun getUniqueId(): String? = null override fun update(): Boolean { val changes = super.update() @@ -67,12 +65,9 @@ public open class RibHierarchyDescriptor( } /** Return icon to display. */ - override fun getIcon(element: PsiElement): Icon? { - return null - } + override fun getIcon(element: PsiElement): Icon? = null /** Compare 2 instances of text appearance. */ - public fun CompositeAppearance.compareTo(another: CompositeAppearance): Boolean { - return Comparing.equal(this, another) - } + public fun CompositeAppearance.compareTo(another: CompositeAppearance): Boolean = + Comparing.equal(this, another) } diff --git a/android/tooling/rib-intellij-plugin/src/main/kotlin/com/uber/intellij/plugin/android/rib/ui/RibHierarchyNodeDescriptor.kt b/android/tooling/rib-intellij-plugin/src/main/kotlin/com/uber/intellij/plugin/android/rib/ui/RibHierarchyNodeDescriptor.kt index 9af94f0ef..a881af431 100644 --- a/android/tooling/rib-intellij-plugin/src/main/kotlin/com/uber/intellij/plugin/android/rib/ui/RibHierarchyNodeDescriptor.kt +++ b/android/tooling/rib-intellij-plugin/src/main/kotlin/com/uber/intellij/plugin/android/rib/ui/RibHierarchyNodeDescriptor.kt @@ -37,11 +37,7 @@ public class RibHierarchyNodeDescriptor( } /** Method used to get the unique id of descriptor. Used for programmatic selection. */ - override fun getUniqueId(): String? { - return ribNode.id - } + override fun getUniqueId(): String? = ribNode.id - override fun toString(): String { - return ribNode.name - } + override fun toString(): String = ribNode.name } diff --git a/android/tooling/rib-intellij-plugin/src/main/kotlin/com/uber/intellij/plugin/android/rib/ui/RibHierarchyTreeStructure.kt b/android/tooling/rib-intellij-plugin/src/main/kotlin/com/uber/intellij/plugin/android/rib/ui/RibHierarchyTreeStructure.kt index fd5e30e0c..7fdb68b0c 100644 --- a/android/tooling/rib-intellij-plugin/src/main/kotlin/com/uber/intellij/plugin/android/rib/ui/RibHierarchyTreeStructure.kt +++ b/android/tooling/rib-intellij-plugin/src/main/kotlin/com/uber/intellij/plugin/android/rib/ui/RibHierarchyTreeStructure.kt @@ -41,7 +41,7 @@ public class RibHierarchyTreeStructure( descriptor, RibHierarchyUtils.getPsiClass(project, descriptor.ribHost.name), it, - ), + ) ) } } @@ -53,7 +53,7 @@ public class RibHierarchyTreeStructure( descriptor, RibHierarchyUtils.getPsiClass(project, activity.name), activity, - ), + ) ) } } @@ -64,7 +64,7 @@ public class RibHierarchyTreeStructure( descriptor, RibHierarchyUtils.getPsiClass(project, descriptor.ribActivity.name), descriptor.ribActivity.rootRib, - ), + ) ) } is RibHierarchyNodeDescriptor -> { @@ -75,7 +75,7 @@ public class RibHierarchyTreeStructure( descriptor, RibHierarchyUtils.getPsiClass(project, childRibNode.name), childRibNode, - ), + ) ) } } @@ -87,7 +87,7 @@ public class RibHierarchyTreeStructure( RibHierarchyUtils.getPsiClass(project, view.id), descriptor.ribNode, view, - ), + ) ) } } @@ -99,7 +99,7 @@ public class RibHierarchyTreeStructure( RibHierarchyUtils.getPsiClass(project, view.id), descriptor.ribNode, view, - ), + ) ) } } diff --git a/android/tooling/rib-intellij-plugin/src/main/kotlin/com/uber/intellij/plugin/android/rib/ui/RibViewNodeDescriptor.kt b/android/tooling/rib-intellij-plugin/src/main/kotlin/com/uber/intellij/plugin/android/rib/ui/RibViewNodeDescriptor.kt index ca999c083..4c1305dde 100644 --- a/android/tooling/rib-intellij-plugin/src/main/kotlin/com/uber/intellij/plugin/android/rib/ui/RibViewNodeDescriptor.kt +++ b/android/tooling/rib-intellij-plugin/src/main/kotlin/com/uber/intellij/plugin/android/rib/ui/RibViewNodeDescriptor.kt @@ -63,13 +63,9 @@ public open class RibViewNodeDescriptor( } /** Method used to get the unique id of descriptor. Used for programmatic selection. */ - override fun getUniqueId(): String? { - return ribView?.id ?: null - } + override fun getUniqueId(): String? = ribView?.id ?: null - override fun toString(): String { - return ribView?.viewId ?: "" - } + override fun toString(): String = ribView?.viewId ?: "" @SuppressWarnings("ReturnCount") override fun getIcon(element: PsiElement): Icon? { @@ -87,7 +83,5 @@ public open class RibViewNodeDescriptor( return AllIcons.General.InspectionsEye } - private fun hasLayoutId(): Boolean { - return ribView != null && ribView.layoutId.isNotEmpty() - } + private fun hasLayoutId(): Boolean = ribView != null && ribView.layoutId.isNotEmpty() }