Skip to content

Commit ad31fe1

Browse files
Merge pull request #20 from hyunjung-choi/feature/excessive-image-width-in-bookmark
Feature/excessive image width in bookmark
2 parents a4a912c + a6937f2 commit ad31fe1

File tree

5 files changed

+17
-9
lines changed

5 files changed

+17
-9
lines changed

app/src/main/java/com/prography/android/test/hyunjung/data/local/PhotoDatabase.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import androidx.room.Database
44
import androidx.room.RoomDatabase
55
import 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)
99
abstract class PhotoDatabase : RoomDatabase() {
1010
abstract fun photoDao(): PhotoDao

app/src/main/java/com/prography/android/test/hyunjung/data/local/PhotoEntity.kt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff 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

2729
fun 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

app/src/main/java/com/prography/android/test/hyunjung/data/model/Photo.kt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff 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
)

app/src/main/java/com/prography/android/test/hyunjung/ui/component/ImageItem.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import androidx.compose.foundation.layout.defaultMinSize
77
import androidx.compose.foundation.layout.fillMaxWidth
88
import androidx.compose.foundation.layout.height
99
import androidx.compose.foundation.layout.padding
10+
import androidx.compose.foundation.layout.widthIn
1011
import androidx.compose.foundation.shape.RoundedCornerShape
1112
import androidx.compose.material3.Card
1213
import 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
)

app/src/main/java/com/prography/android/test/hyunjung/ui/detail/PhotoDetailScreen.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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 -> {

0 commit comments

Comments
 (0)