Skip to content

Commit

Permalink
Implemented Puppy Detail Screen, Puppy Repository
Browse files Browse the repository at this point in the history
  • Loading branch information
KwabenBerko committed Feb 28, 2021
1 parent 75a54d6 commit 178bf8b
Show file tree
Hide file tree
Showing 9 changed files with 411 additions and 172 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,14 @@ import android.os.Bundle
import androidx.activity.compose.setContent
import androidx.appcompat.app.AppCompatActivity
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.navigation.NavType
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.navArgument
import androidx.navigation.compose.rememberNavController
import com.example.androiddevchallenge.data.PuppyRepository
import com.example.androiddevchallenge.ui.screens.IntroScreen
import com.example.androiddevchallenge.ui.screens.PuppyDetailScreen
import com.example.androiddevchallenge.ui.screens.PuppyListScreen
import com.example.androiddevchallenge.ui.theme.BuddyTheme

Expand All @@ -34,6 +38,7 @@ class MainActivity : AppCompatActivity() {

setContent {
BuddyTheme {
val puppyRepository = PuppyRepository()
val navController = rememberNavController()

NavHost(navController = navController, startDestination = "intro") {
Expand All @@ -43,7 +48,24 @@ class MainActivity : AppCompatActivity() {
navController = navController
)
}
composable("puppiesList") { PuppyListScreen(navController = navController) }
composable("puppies") {
PuppyListScreen(
puppies = puppyRepository.findAllPuppies(),
navController = navController
)
}

composable(
"puppies/{puppyId}",
arguments = listOf(navArgument("puppyId") { type = NavType.IntType })
) { backStackEntry ->
val puppyId = backStackEntry.arguments!!.getInt("puppyId")
PuppyDetailScreen(
puppy = puppyRepository.findPuppyById(puppyId),
window = window,
navController = navController
)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package com.example.androiddevchallenge.data

import com.example.androiddevchallenge.R
import com.example.androiddevchallenge.data.model.Gender
import com.example.androiddevchallenge.data.model.Puppy


class PuppyRepository {

private companion object {
const val DESCRIPTION =
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed tempus eu nunc nec dapibus. Cras sit amet rhoncus ex, quis pharetra odio. Vivamus quis egestas lectus. Proin at elementum libero. Curabitur quam libero, semper placerat vestibulum ac, sollicitudin eu elit. Donec eu mi in leo laoreet rhoncus ut ullamcorper nisi."
val PUPPIES = listOf(
Puppy(
id = 1,
name = "Archie",
breed = "Havanese",
description = DESCRIPTION,
gender = Gender.MALE,
image = R.drawable.archie
),
Puppy(
id = 2,
name = "Ariel",
breed = "Poodle",
description = DESCRIPTION,
gender = Gender.FEMALE,
image = R.drawable.ariel
),

Puppy(
id = 3,
name = "Coco",
breed = "Rottweiler",
description = DESCRIPTION,
gender = Gender.FEMALE,
image = R.drawable.coco
),
Puppy(
id = 4,
name = "Roxy",
breed = "Pomeranian",
description = DESCRIPTION,
gender = Gender.FEMALE,
image = R.drawable.roxy
),

Puppy(
id = 5,
name = "Mika",
breed = "Labrador",
description = DESCRIPTION,
gender = Gender.MALE,
image = R.drawable.mika
),
Puppy(
id = 6,
name = "Rocky",
breed = "Bulldog",
description = DESCRIPTION,
gender = Gender.MALE,
image = R.drawable.rocky
),

Puppy(
id = 7,
name = "Finn",
breed = "Chihuahua",
description = DESCRIPTION,
gender = Gender.MALE,
image = R.drawable.finn
),
)
}

fun findAllPuppies(): List<Puppy> {
return PUPPIES
}

fun findPuppyById(id: Int): Puppy {
return PUPPIES.first { it.id == id }
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.example.androiddevchallenge.data.model

enum class Gender {
MALE,
FEMALE
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.androiddevchallenge.model
package com.example.androiddevchallenge.data.model

import androidx.annotation.DrawableRes

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package com.example.androiddevchallenge.ui.components

import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.Card
import androidx.compose.material.Icon
import androidx.compose.material.Text
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Female
import androidx.compose.material.icons.filled.Male
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.example.androiddevchallenge.data.model.Gender
import com.example.androiddevchallenge.data.model.Puppy
import com.example.androiddevchallenge.ui.theme.Rubik

@Composable
fun PuppyListItem(puppy: Puppy, onPuppyClicked: (puppy: Puppy) -> Unit) {
Card(
shape = RoundedCornerShape(3.dp),
elevation = 2.dp,
backgroundColor = Color.White,
modifier = Modifier
.height(240.dp)
.padding(6.dp)
.fillMaxSize()
.clickable { onPuppyClicked(puppy) }
) {
Column(modifier = Modifier.padding(0.dp)) {
Image(
painter = painterResource(id = puppy.image),
contentDescription = null,
contentScale = ContentScale.Crop,
modifier = Modifier
.height(170.dp)
.fillMaxWidth()
)
Row(
horizontalArrangement = Arrangement.SpaceBetween,
modifier = Modifier
.fillMaxWidth()
.padding(8.dp)
) {
Column {
Text(
text = puppy.name,
style = TextStyle(
fontSize = 16.sp,
fontFamily = Rubik,
fontWeight = FontWeight.W600,
color = Color(0xFF575757),
)
)

Text(
text = puppy.breed,
style = TextStyle(
fontSize = 12.sp,
fontFamily = Rubik,
color = Color(0xFF575757),
)
)
}

Box(
modifier = Modifier
.background(
Color(color = if (puppy.gender == Gender.FEMALE) 0xFFFF087E else 0xFF03A9F4),
shape = CircleShape
)
.padding(2.dp)
) {
Icon(
modifier = Modifier
.size(17.dp),
imageVector = if (puppy.gender == Gender.FEMALE) Icons.Default.Female else Icons.Default.Male,
contentDescription = null,
tint = Color.White
)
}

}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.Text
import androidx.compose.material.TextButton
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.SideEffect
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.ContentScale
Expand All @@ -26,11 +28,25 @@ import com.example.androiddevchallenge.ui.theme.Rubik
@Composable
fun IntroScreen(window: Window, navController: NavController) {

@Suppress("DEPRECATION")
window.setFlags(
WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN
)
SideEffect(effect = {
@Suppress("DEPRECATION")
window.setFlags(
WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN
)
})

DisposableEffect(Unit) {
onDispose {
@Suppress("DEPRECATION")
window.clearFlags(
WindowManager.LayoutParams.FLAG_FULLSCREEN
)
}
}




Box {

Expand Down Expand Up @@ -71,11 +87,7 @@ fun IntroScreen(window: Window, navController: NavController) {

TextButton(
onClick = {
@Suppress("DEPRECATION")
window.clearFlags(
WindowManager.LayoutParams.FLAG_FULLSCREEN
)
navController.navigate("puppiesList")
navController.navigate("puppies")
},
modifier = Modifier
.padding(12.dp)
Expand Down
Loading

0 comments on commit 178bf8b

Please sign in to comment.