Skip to content

Instantly share code, notes, and snippets.

View rubenquadros's full-sized avatar

Ruben Quadros rubenquadros

  • Bangalore
View GitHub Profile
@rubenquadros
rubenquadros / HomeScreen.kt
Created August 19, 2021 17:28
Initial home screen
@Composable
fun HomeScreen(
openSearch: () -> Unit,
openFilters: () -> Unit,
homeViewModel: HomeViewModel = viewModel(),
) {
Scaffold(topBar = {
HomeAppBar(
title = "Epic World",
@rubenquadros
rubenquadros / GameItem.kt
Created August 19, 2021 18:18
Game Item composable
@Composable
fun GameItem(game: GameResultsEntity) {
Card(
elevation = 20.dp,
backgroundColor = Color.Black,
modifier =
Modifier.padding(16.dp)
.clip(RoundedCornerShape(10.dp))
.height(250.dp)
.fillMaxWidth()
@rubenquadros
rubenquadros / GameListingLoader.kt
Last active August 19, 2021 19:33
Game listing with loading
@Composable
fun GameListing(
games: Flow<PagingData<GameResultsEntity>>
) {
val lazyGameItems = games.collectAsLazyPagingItems()
LazyVerticalGrid(
cells = GridCells.Fixed(2),
content = {
items(lazyGameItems.itemCount) { index ->
lazyGameItems[index]?.let { GameItem(it) }
@rubenquadros
rubenquadros / AppBarTest.kt
Created August 19, 2021 19:39
App bar test
class AppBarTest {
@get:Rule val composeTestRule = createComposeRule()
@Test
fun given_title_should_be_displayed_in_home_app_bar() {
// Load our composable
composeTestRule.setContent {
EpicWorldTheme {
HomeAppBar(
@rubenquadros
rubenquadros / HomeScreenTest.kt
Last active August 20, 2021 18:04
Home screen test
class HomeScreenTest {
@get:Rule val composeTestRule = createComposeRule()
//Mock the viewmodel
private val homeViewModel = mockk<HomeViewModel>()
@Before
fun init() {
MockKAnnotations.init(this, true)
@rubenquadros
rubenquadros / GameDetailsScroll.kt
Created August 24, 2021 19:25
Adding scroll behaviour to game details screen
@Composable
fun GameDetails(
gameDetails: GameDetailsEntity,
openGameTrailer: () -> Unit
) {
val scrollState = rememberScrollState()
Column(
modifier =
Modifier.fillMaxSize()
@rubenquadros
rubenquadros / PlayTrailer.kt
Created August 24, 2021 19:44
Play button
@Composable
fun PlayTrailer(
modifier: Modifier = Modifier,
openGameTrailer: () -> Unit
) {
Box(modifier = modifier) {
IconButton(onClick = openGameTrailer) {
Image(
modifier =
Modifier.width(50.dp)
@Composable
fun GameDetails(
gameDetails: GameDetailsEntity,
openGameTrailer: () -> Unit
) {
val scrollState = rememberScrollState()
Column(
modifier =
Modifier.fillMaxSize()
@rubenquadros
rubenquadros / BottomRoundedArcShape.kt
Created August 25, 2021 17:47
Custom shape with rounded bottom
class BottomRoundedArcShape : Shape {
override fun createOutline(
size: Size,
layoutDirection: LayoutDirection,
density: Density
): Outline {
return Outline.Generic(
path = drawArcPath(size = size)
)
}
@rubenquadros
rubenquadros / CustomPath.kt
Created August 25, 2021 19:17
Custom path for the shape
fun drawArcPath(size: Size): Path {
return Path().apply {
reset()
// go from (0,0) to (width, 0)
lineTo(size.width, 0f)
// go from (width, 0) to (width, height)
lineTo(size.width, size.height)