Skip to content

Instantly share code, notes, and snippets.

Avatar

Raul Hernandez Lopez raulh82vlc

View GitHub Profile
@raulh82vlc
raulh82vlc / SimpleTweetBoxWithCompatibleAndroidView.kt
Last active Mar 29, 2021
SimpleTweetBox with compatible AndroidView
View SimpleTweetBoxWithCompatibleAndroidView.kt
@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 Mar 29, 2021
SimpleTweetBox example
View SimpleTweetBox.kt
@Composable
fun SimpleTweetBox(
tweet: Tweet,
onClick: () -> Unit
) {
Box(
modifier = Modifier
.border(
width = 1.dp,
color = Color.LightGray,
@raulh82vlc
raulh82vlc / StateUIValue.kt
Last active Mar 1, 2021
StateUIValue with all other UI states
View StateUIValue.kt
@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 Apr 25, 2021
TweetBox composable
View TweetBox.kt
@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 Mar 1, 2021
TweetsList representation of a vertical list of tweets
View TweetsList.kt
@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 Mar 1, 2021
SearchUIStateHandler uses StateUIValue
View SearchUIStateHandler.kt
@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 Mar 1, 2021
SearchUIStateHandler uses collectAsState
View SearchUIStateHandler.kt
@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 Mar 1, 2021
TweetsListFragmentUI set of entities after declarative stable APIs migration
View TweetsListFragmentUI.java
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 Mar 1, 2021
StatesUI series of ui states
View StatesUI.kt
@Composable
fun StatesUI(uiState: TweetsUIState) {
when (uiState) {
is TweetsUIState.XXXXXState -> // TODO ...
}
}
@raulh82vlc
raulh82vlc / SearchComposablesUI.kt
Last active Mar 1, 2021
SearchComposablesUI::startComposingViews
View SearchComposablesUI.kt
@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
}