generated from android/android-dev-challenge-compose
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented Puppy Detail Screen, Puppy Repository
- Loading branch information
1 parent
75a54d6
commit 178bf8b
Showing
9 changed files
with
411 additions
and
172 deletions.
There are no files selected for viewing
This file contains 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
84 changes: 84 additions & 0 deletions
84
app/src/main/java/com/example/androiddevchallenge/data/PuppyRepository.kt
This file contains 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
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 } | ||
} | ||
|
||
} |
6 changes: 6 additions & 0 deletions
6
app/src/main/java/com/example/androiddevchallenge/data/model/Gender.kt
This file contains 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
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 | ||
} |
2 changes: 1 addition & 1 deletion
2
...xample/androiddevchallenge/model/Puppy.kt → ...e/androiddevchallenge/data/model/Puppy.kt
This file contains 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
6 changes: 0 additions & 6 deletions
6
app/src/main/java/com/example/androiddevchallenge/model/Gender.kt
This file was deleted.
Oops, something went wrong.
96 changes: 96 additions & 0 deletions
96
app/src/main/java/com/example/androiddevchallenge/ui/components/PuppyListItem.kt
This file contains 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
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 | ||
) | ||
} | ||
|
||
} | ||
} | ||
} | ||
} |
This file contains 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
Oops, something went wrong.