File tree Expand file tree Collapse file tree 5 files changed +17
-9
lines changed
app/src/main/java/com/prography/android/test/hyunjung Expand file tree Collapse file tree 5 files changed +17
-9
lines changed Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ import androidx.room.Database
44import androidx.room.RoomDatabase
55import androidx.room.TypeConverters
66
7- @Database(entities = [PhotoEntity ::class ], version = 2 , exportSchema = false )
7+ @Database(entities = [PhotoEntity ::class ], version = 3 , exportSchema = false )
88@TypeConverters(PhotoTypeConverters ::class )
99abstract class PhotoDatabase : RoomDatabase () {
1010 abstract fun photoDao (): PhotoDao
Original file line number Diff line number Diff line change @@ -21,7 +21,9 @@ data class PhotoEntity(
2121 val altDescription : String? = null ,
2222 val tags : List <Tag > = emptyList(),
2323 val urls : Urls ? = null ,
24- val user : User ? = null
24+ val user : User ? = null ,
25+ val width : Int? ,
26+ val height : Int?
2527)
2628
2729fun PhotoEntity.toDomain (): Photo {
@@ -33,7 +35,9 @@ fun PhotoEntity.toDomain(): Photo {
3335 tags = this .tags,
3436 urls = Urls (this .urls?.regular ? : " " ),
3537 user = this .user,
36- isBookmarked = true
38+ isBookmarked = true ,
39+ width = this .width,
40+ height = this .height
3741 )
3842}
3943
@@ -46,7 +50,9 @@ fun Photo.toEntity(): PhotoEntity {
4650 altDescription = this .altDescription,
4751 tags = this .tags,
4852 urls = this .urls,
49- user = this .user
53+ user = this .user,
54+ width = this .width,
55+ height = this .height
5056 )
5157}
5258
Original file line number Diff line number Diff line change @@ -14,10 +14,8 @@ data class Photo(
1414 val tags : List <Tag > = emptyList(),
1515 val urls : Urls ,
1616 val user : User ? = null ,
17+ val width : Int? = null ,
18+ val height : Int? = null ,
1719 @Transient
1820 var isBookmarked : Boolean = false ,
19- @Transient
20- var width : Long = 1 ,
21- @Transient
22- var height : Long = 1
2321)
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ import androidx.compose.foundation.layout.defaultMinSize
77import androidx.compose.foundation.layout.fillMaxWidth
88import androidx.compose.foundation.layout.height
99import androidx.compose.foundation.layout.padding
10+ import androidx.compose.foundation.layout.widthIn
1011import androidx.compose.foundation.shape.RoundedCornerShape
1112import androidx.compose.material3.Card
1213import androidx.compose.material3.Text
@@ -84,11 +85,14 @@ fun ImageItem(
8485 )
8586 }
8687 } else {
88+ val isPortrait = (photo.height ? : 1 ) > (photo.width ? : 1 )
89+
8790 AsyncImage (
8891 model = photo.urls.regular,
8992 contentDescription = null ,
9093 modifier = Modifier
9194 .height(128 .dp)
95+ .widthIn(max = if (isPortrait) 100 .dp else 160 .dp)
9296 .clip(RoundedCornerShape (10 .dp)),
9397 contentScale = ContentScale .Crop
9498 )
Original file line number Diff line number Diff line change @@ -47,7 +47,7 @@ fun PhotoDetailScreen(
4747 Box (
4848 modifier = Modifier
4949 .fillMaxSize()
50- .background(Black )
50+ .background(Black .copy(alpha = 0.9f ) )
5151 ) {
5252 when {
5353 isLoading -> {
You can’t perform that action at this time.
0 commit comments