This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# gradlew alias | |
alias gw=./gradlew |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Composable function that aims to help the single event handing. | |
* Use it only for SideEffect event (one shot) and not for handling UI state changes. | |
* | |
* @param sideEffectFlow Flow | |
* @param lifeCycleState default [Lifecycle.State.STARTED] | |
* @param collector | |
*/ | |
@Composable | |
fun <T : Any> SingleEventEffect( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Change shadow color and style | |
* @param color shadow color | |
* @param alpha shadow alpha | |
* @param borderRadius shadow border radius | |
* @param shadowRadius shadow size | |
* @param offsetX X offset | |
* @param offsetY Y offset | |
*/ | |
@RequiresApi(Build.VERSION_CODES.P) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
fun `Test confirm upon a failure`() = coroutineTestRule.scope.runTest { | |
// Given | |
coEvery { githubRepository.repositoryByOwner(any()) } returns Either.Left(AppError.Network) | |
// When / Then | |
stateMachine.state.test { | |
stateMachine.dispatch(GithubAction.TypeOwner("mcatta")) | |
stateMachine.dispatch(GithubAction.Confirm) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
fun `Test typing`() = coroutineTestRule.scope.runTest { | |
// When / Then | |
stateMachine.state.test { | |
stateMachine.dispatch(GithubAction.TypeOwner("mcatta")) | |
assertEquals("", (awaitItem() as GithubState.ContentState).owner) | |
assertEquals("mcatta", (awaitItem() as GithubState.ContentState).owner) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Composable | |
fun RepoInfoScreen( | |
githubViewModel: GithubViewModel | |
) { | |
val uiState by githubViewModel.rememberState() | |
Column( | |
modifier = Modifier | |
.fillMaxSize() | |
.padding(16.dp) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@HiltViewModel | |
class GithubViewModel @Inject constructor( | |
githubStateMachine: GithubStateMachine | |
): AbsStateViewModel<GithubState, GithubAction>(githubStateMachine) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@OptIn(FlowPreview::class, ExperimentalCoroutinesApi::class) | |
abstract class AbsStateViewModel<State: Any, Action: Any>( | |
private val stateMachine: FlowReduxStateMachine<State, Action> | |
): BaseViewModel() { | |
@Composable | |
fun rememberState() = stateMachine.rememberState() | |
fun dispatch(action: Action) = viewModelScope.launch { | |
stateMachine.dispatch(action = action) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Error | |
inState<GithubState.Error> { | |
on { _: GithubAction.RetryLoadingAction, state: State<GithubState.Error> -> | |
state.override { GithubState.Load(owner = state.snapshot.owner) } | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
inState<GithubState.Load> { | |
onEnter { state: State<GithubState.Load> -> | |
val owner = state.snapshot.owner | |
githubRepository.repositoryByOwner(owner = owner).fold( | |
ifLeft = { | |
GithubState.Error(Throwable("Fail"), owner = owner) | |
}, | |
ifRight = { | |
GithubState.ContentState(repositories = it, owner = owner) | |
} |
NewerOlder