Skip to content

Instantly share code, notes, and snippets.

View raulh82vlc's full-sized avatar

Raul Hernandez raulh82vlc

View GitHub Profile
@raulh82vlc
raulh82vlc / SimpleTweetBoxWithCompatibleAndroidView.kt
Last active March 29, 2021 19:42
SimpleTweetBox with compatible AndroidView
@Composable
fun SimpleTweetBox(
tweet: Tweet,
onClick: () -> Unit
) {
Box( // ...
) {
val user = tweet.user ?: ""
val imageUrl: String = tweet.images[0]
Column( // ...
@raulh82vlc
raulh82vlc / SimpleTweetBox.kt
Last active March 29, 2021 19:42
SimpleTweetBox example
@Composable
fun SimpleTweetBox(
tweet: Tweet,
onClick: () -> Unit
) {
Box(
modifier = Modifier
.border(
width = 1.dp,
color = Color.LightGray,
@raulh82vlc
raulh82vlc / StateUIValue.kt
Last active March 1, 2021 15:47
StateUIValue with all other UI states
@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()
}
}
@raulh82vlc
raulh82vlc / TweetBox.kt
Last active April 25, 2021 13:30
TweetBox composable
@Composable
fun TweetBox(tweet: Tweet, onClick: () -> Unit ) {
Box(
modifier = Modifier
.border(
width = 1.dp,
color = Color.LightGray,
shape = RoundedCornerShape(16.dp)
)
.fillMaxWidth()
@raulh82vlc
raulh82vlc / TweetsList.kt
Last active March 1, 2021 13:44
TweetsList representation of a vertical list of tweets
@ExperimentalFoundationApi
@Composable
@Preview
fun TweetsList(tweets: List<Tweet>) {
LazyVerticalGrid(
modifier = Modifier.fillMaxWidth(),
cells = GridCells.Fixed(2)
){
items(
count = tweets.size,
@raulh82vlc
raulh82vlc / SearchUIStateHandler.kt
Created March 1, 2021 12:17
SearchUIStateHandler uses StateUIValue
@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
}
}
@raulh82vlc
raulh82vlc / SearchUIStateHandler.kt
Created March 1, 2021 12:05
SearchUIStateHandler uses collectAsState
@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 {
@raulh82vlc
raulh82vlc / TweetsListFragmentUI.java
Created March 1, 2021 12:01
TweetsListFragmentUI set of entities after declarative stable APIs migration
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());
}
@raulh82vlc
raulh82vlc / StatesUI.kt
Created March 1, 2021 11:37
StatesUI series of ui states
@Composable
fun StatesUI(uiState: TweetsUIState) {
when (uiState) {
is TweetsUIState.XXXXXState -> // TODO ...
}
}
@raulh82vlc
raulh82vlc / SearchComposablesUI.kt
Last active March 1, 2021 11:29
SearchComposablesUI::startComposingViews
@ActivityScope
class SearchComposablesUI @Inject constructor() {
private var composeView: ComposeView? = null
private var activity: SearchTweetActivity? = null
fun setComposeView(composeView: ComposeView, activity: SearchTweetActivity) {
this.composeView = composeView
this.activity = activity
}