This file contains hidden or 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
<?xml version="1.0" encoding="utf-8"?> | |
<androidx.constraintlayout.widget.ConstraintLayout | |
xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:tools="http://schemas.android.com/tools" | |
xmlns:app="http://schemas.android.com/apk/res-auto" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
tools:context=".MainActivity"> | |
<androidx.appcompat.widget.AppCompatButton |
This file contains hidden or 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
<?xml version="1.0" encoding="utf-8"?> | |
<androidx.constraintlayout.widget.ConstraintLayout | |
xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:app="http://schemas.android.com/apk/res-auto" | |
xmlns:tools="http://schemas.android.com/tools" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
tools:context=".OtherActivity"> | |
<androidx.appcompat.widget.AppCompatButton |
This file contains hidden or 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
// Generated by view binder compiler. Do not edit! | |
package com.ruben.viewbindingexample.databinding; | |
import android.view.LayoutInflater; | |
import android.view.View; | |
import android.view.ViewGroup; | |
import androidx.annotation.NonNull; | |
import androidx.annotation.Nullable; | |
import androidx.appcompat.widget.AppCompatButton; | |
import androidx.constraintlayout.widget.ConstraintLayout; |
This file contains hidden or 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
class MainActivity : AppCompatActivity() { | |
private lateinit var binding: ActivityMainBinding | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
binding = ActivityMainBinding.inflate(layoutInflater) | |
setContentView(binding.root) | |
binding.button.text = "Click Me too!" | |
//do other stuff |
This file contains hidden or 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 HomeAppBar(title: String, openSearch: () -> Unit, openFilters: () -> Unit) { | |
TopAppBar( | |
title = { Text(text = title) }, | |
actions = { | |
IconButton(onClick = openSearch) { | |
Icon(imageVector = Icons.Filled.Search, contentDescription = "Search") | |
} | |
IconButton(onClick = openFilters) { |
This file contains hidden or 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
@Preview(showBackground = true) | |
@Composable | |
fun HomeAppBarPreview() { | |
HomeAppBar( | |
title = "EpicWorld", | |
openSearch = {}, | |
openFilters = {} | |
) | |
} |
This file contains hidden or 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 HomeAppBar(title: String, openSearch: () -> Unit, openFilters: () -> Unit) { | |
TopAppBar( | |
title = { Text(text = title, color = Color.White) }, | |
backgroundColor = Color(0xFFF50057), | |
actions = { | |
IconButton(onClick = openSearch) { | |
Icon( | |
imageVector = Icons.Filled.Search, | |
contentDescription = "Search", |
This file contains hidden or 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
class GamesSource( | |
private val gamesRepository: GamesRepository | |
) : PagingSource<Int, GameResultsEntity>() { | |
override suspend fun load( | |
params: LoadParams<Int> | |
): LoadResult<Int, GameResultsEntity> { | |
val nextPage = params.key ?: 1 | |
val gamesResponse = | |
gamesRepository.getAllGames(nextPage) |
This file contains hidden or 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
class HomeViewModel(private val gamesSource: GamesSource) : | |
ViewModel() { | |
fun getAllGames(): Flow<PagingData<GameResultsEntity>> { | |
return Pager(PagingConfig(50)) { gamesSource }.flow | |
} | |
} |
This file contains hidden or 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 GameListing( | |
games: Flow<PagingData<GameResultsEntity>> | |
) { | |
val lazyGameItems = games.collectAsLazyPagingItems() | |
LazyVerticalGrid( | |
cells = GridCells.Fixed(2), | |
content = { | |
items(lazyGameItems.itemCount) { index -> | |
lazyGameItems[index]?.let { |
OlderNewer