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
/* | |
* Copyright (C) 2020 Raul Hernandez Lopez | |
* | |
* Licensed under the Apache License, Version 2.0 (the "License"); | |
* you may not use this file except in compliance with the License. | |
* You may obtain a copy of the License at | |
* | |
* http://www.apache.org/licenses/LICENSE-2.0 | |
* | |
* Unless required by applicable law or agreed to in writing, software |
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 TweetBox(tweet: Tweet, onClick: () -> Unit ) { | |
Box( | |
modifier = Modifier | |
.border( | |
width = 1.dp, | |
color = Color.LightGray, | |
shape = RoundedCornerShape(16.dp) | |
) | |
.fillMaxWidth() |
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 SimpleTweetBox( | |
tweet: Tweet, | |
onClick: () -> Unit | |
) { | |
Box( // ... | |
) { | |
val user = tweet.user ?: "" | |
val imageUrl: String = tweet.images[0] | |
Column( // ... |
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 SimpleTweetBox( | |
tweet: Tweet, | |
onClick: () -> Unit | |
) { | |
Box( | |
modifier = Modifier | |
.border( | |
width = 1.dp, | |
color = Color.LightGray, |
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
/** | |
* Search tweets Use case implementation of [UseCaseStateFlow] | |
*/ | |
@RetainedScope | |
class SearchTweetUseCase @Inject constructor( | |
private val repository: TweetsRepository, | |
@Named("CoroutineScopeTransfer") val coroutineScope: CoroutineScope | |
) : UseCaseStateFlow<TweetsUIState> { | |
private val tweetsUIStateFlow = MutableStateFlow<TweetsUIState>(TweetsUIState.InitialIdleUIState) |
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 StateUIValue(uiState: TweetsUIState) { | |
when (uiState) { | |
is TweetsUIState.ListResultsUIState -> TweetList(tweets = uiState.tweets) | |
is TweetsUIState.LoadingUIState -> CenteredText(msg = stringResource(R.string.loading_feed)) | |
is TweetsUIState.EmptyUIState -> CenteredText(msg = stringResource(R.string.query, uiState.query)) | |
is TweetsUIState.ErrorUIState -> CenteredText(msg = ”Error happened: $uiState.msg”) | |
is TweetsUIState.InitialIdleUIState -> TopText() | |
} | |
} |
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
@ExperimentalFoundationApi | |
@Composable | |
@Preview | |
fun TweetsList(tweets: List<Tweet>) { | |
LazyVerticalGrid( | |
modifier = Modifier.fillMaxWidth(), | |
cells = GridCells.Fixed(2) | |
){ | |
items( | |
count = tweets.size, |
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
@ActivityScope | |
class SearchUIStateHandler @Inject constructor() { | |
// ... State UI code | |
@Composable | |
fun StateUIValue(uiState: TweetsUIState) { | |
when (uiState) { | |
is TweetsUIState.ListResultsUIState -> TweetsList(tweets = uiState.tweets) | |
// other UI states | |
} | |
} |
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
@ActivityScope | |
class SearchUIStateHandler @Inject constructor() { | |
private var composeView: ComposeView? = null | |
private lateinit var stateFlow: StateFlow<TweetsUIState> | |
fun initStateFlowAndViews(stateFlowUI: StateFlow<TweetsUIState>) { | |
stateFlow = stateFlowUI | |
composeView?.setContent { | |
TweetsWithSearchTheme { |
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
public class TweetsListFragmentUI extends BaseUI { | |
// SearchComposablesUI is renamed to SearchUIStateHandler | |
@Inject SearchUIStateHandler searchUIStateHandler; | |
@Inject SearchViewDelegate viewDelegate; | |
// Remove SearchStateHandler instance | |
public void initStateFlowAndViews() { | |
// just needs the dependency of the StateFlow | |
searchUIStateHandler.initStateFlowAndViews(viewDelegate.getStateFlow()); | |
} |
NewerOlder