Skip to content

Instantly share code, notes, and snippets.

View rygelouv's full-sized avatar

Rygel Louv rygelouv

View GitHub Profile
fun actions(): Flow<MoviesFlowAction> = merge(
actionChannel.consumeAsFlow(),
binding.refreshButton.clicks().map { MoviesAction.RefreshAction }
)
@Composable
private fun SearchField(
actionChannel: ActionChannel
) {
...
Button(
/*Send a new action in the actionChannel */
onClick = { actionChannel.trySend(MoviesAction.SearchMovieAction(query) },
...
) {
@Composable
fun MoviesScreenContent(
uiState: TransferScreenState,
actionChannel: ActionChannel
) {
...
}
...
@Composable
class MoviesActivity : ComponentActivity() {
private val viewModel by viewModels<MoviesViewModel>()
private val actionChannel = Channel<MoviesAction>()
private fun actions(): Flow<MoviesAction> = actionChannel.consumeAsFlow()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
@Composable
fun MoviesScreenContent(
uiState: TransferScreenState,
onSearchMovie: (String) -> Unit = { },
onCategoryChange: (String) -> Unit = { },
onFirstNameChange: (String) -> Unit = { },
onLastNameChange: (String) -> Unit = { },
onFavoriteChange: (String) -> Unit = { },
onDownloadClicked: (MovieUI) -> Unit = { },
onUploadClicked: () -> Unit = { },
class MoviesViewModel @Inject constructor(private val mapper: MoviesUIMapper) : ViewModel() {
private val _actionFlow =
MutableSharedFlow<MoviesAction>(extraBufferCapacity = 16)
init {
_actionFlow.process().launchIn(viewModelScope)
}
private fun Flow<MoviesAction>.process() = onEach {
when(it) {
sealed class MoviesAction {
data class SearchMovieAction(val query: String): MoviesAction()
data class AddToHistoryAction(val movieId: Int): MoviesAction()
object RefreshMoviesAction: MoviesAction()
}
data class TransactionUI(
val title: String = "",
val type: String = "",
val image: String = "",
val amount: String = "",
val date: String = "",
val color: Color = Color.Yellow
)
binding.title = transaction.title
binding.type = transaction.type
binding.image.load(transaction.image)
binding.amount = transaction.amount
binding.date = transaction.date
data class TransactionUI(
val title: String = "",
val type: String = "",
val image: String = "",
val amount: String = "",
val date: String = "",
@ColorRes val color: Int = R.color.yellow
)