Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump Spotless #645

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ plugins {

val libs = the<org.gradle.accessors.dm.LibrariesForLibs>()

configure<com.diffplug.gradle.spotless.SpotlessExtension> {
spotless {
format("misc") {
target("**/*.md", "**/.gitignore")
trimTrailingWhitespace()
Expand All @@ -31,6 +31,7 @@ configure<com.diffplug.gradle.spotless.SpotlessExtension> {
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()
Expand All @@ -40,7 +41,7 @@ configure<com.diffplug.gradle.spotless.SpotlessExtension> {
}
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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<NoDependencies> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<RootView, RootInteractor>(view, interactor) {
class RootRouter(view: RootView, interactor: RootInteractor, private val scope: RootScope) :
BasicViewRouter<RootView, RootInteractor>(view, interactor) {

private var mainRouter: MainRouter? = null

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,16 @@ 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)
addView(
TextView(context).apply {
text = "root (view)"
setTextColor(Color.WHITE)
},
}
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,16 @@ interface LoggedInScope {
fun presenter(
eventStream: EventStream<LoggedInEvent>,
childContent: LoggedInRouter.ChildContent,
): ComposePresenter {
return object : ComposePresenter() {
): ComposePresenter =
object : ComposePresenter() {
override val composable = @Composable { LoggedInView(eventStream, childContent) }
}
}

fun eventStream() = EventStream<LoggedInEvent>()

@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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class OffGameInteractor(
currentState.copy(
playerOneWins = it[currentState.playerOne] ?: 0,
playerTwoWins = it[currentState.playerTwo] ?: 0,
),
)
)
}
.launchIn(coroutineScope)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ interface OffGameScope {
fun presenter(
stateStream: StateStream<OffGameViewModel>,
eventStream: EventStream<OffGameEvent>,
): ComposePresenter {
return object : ComposePresenter() {
): ComposePresenter =
object : ComposePresenter() {
override val composable =
@Composable {
OffGameView(
Expand All @@ -45,16 +45,10 @@ interface OffGameScope {
)
}
}
}

fun eventStream() = EventStream<OffGameEvent>()

fun stateStream(authInfo: AuthInfo) =
StateStream(
OffGameViewModel(
playerOne = authInfo.playerOne,
playerTwo = authInfo.playerTwo,
),
)
StateStream(OffGameViewModel(playerOne = authInfo.playerOne, playerTwo = authInfo.playerTwo))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand All @@ -50,7 +50,6 @@ class Board @Inject constructor() {
cells[0][2] == theSeed &&
cells[1][1] == theSeed &&
cells[2][0] == theSeed)
}

enum class MarkerType {
CROSS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ interface TicTacToeScope {
fun presenter(
stateStream: StateStream<TicTacToeViewModel>,
eventStream: EventStream<TicTacToeEvent>,
): ComposePresenter {
return object : ComposePresenter() {
): ComposePresenter =
object : ComposePresenter() {
override val composable =
@Composable {
TicTacToeView(
Expand All @@ -45,7 +45,6 @@ interface TicTacToeScope {
)
}
}
}

fun eventStream() = EventStream<TicTacToeEvent>()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ fun TicTacToeView(viewModel: State<TicTacToeViewModel>, 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 ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
),
)
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ interface LoggedOutScope {
fun presenter(
stateStream: StateStream<LoggedOutViewModel>,
eventStream: EventStream<LoggedOutEvent>,
): ComposePresenter {
return object : ComposePresenter() {
): ComposePresenter =
object : ComposePresenter() {
override val composable =
@Composable {
LoggedOutView(
Expand All @@ -44,7 +44,6 @@ interface LoggedOutScope {
)
}
}
}

fun eventStream() = EventStream<LoggedOutEvent>()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,7 @@ fun LoggedOutView(viewModel: State<LoggedOutViewModel>, 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(),
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "")
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Loading
Loading