Skip to content

Commit ee06d84

Browse files
committed
Refactor code
1 parent ed42cad commit ee06d84

File tree

5 files changed

+47
-45
lines changed

5 files changed

+47
-45
lines changed

app/src/main/java/org/nsh07/wikireader/ui/AppScreen.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,6 @@ fun calculateGradientHeight(): () -> Float {
736736
return { statusBars.getTop(density).times(1.2f) }
737737
}
738738

739-
740739
@Serializable
741740
data class HomeScreen(
742741
val lang: String? = null,

app/src/main/java/org/nsh07/wikireader/ui/homeScreen/AppHomeScreen.kt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,10 +167,6 @@ fun AppHomeScreen(
167167

168168
var isRefreshing by remember { mutableStateOf(false) }
169169

170-
var s = homeScreenState.extract.size
171-
if (s > 1) s -= 2
172-
else s = 0
173-
174170
val sendIntent: Intent = remember(homeScreenState.title, preferencesState.lang) {
175171
Intent()
176172
.apply {

app/src/main/java/org/nsh07/wikireader/ui/homeScreen/ArticleFeed.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -328,9 +328,11 @@ fun SharedTransitionScope.ArticleFeed(
328328
Row(
329329
modifier = Modifier
330330
.clip(
331-
if (i == it * 5) topListItemShape
332-
else if (i == it * 5 + 4) bottomListItemShape
333-
else middleListItemShape
331+
when (i) {
332+
it * 5 -> topListItemShape
333+
it * 5 + 4 -> bottomListItemShape
334+
else -> middleListItemShape
335+
}
334336
)
335337
.background(colorScheme.surfaceContainer)
336338
.clickable(

app/src/main/java/org/nsh07/wikireader/ui/homeScreen/AsyncWikitable.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,7 @@ fun AsyncWikitable(
109109
Icon(Icons.Outlined.KeyboardArrowUp, contentDescription = null)
110110
}
111111
Text(
112-
if (rows.first.isNotEmpty()) rows.first
113-
else tableTitle,
112+
rows.first.ifEmpty { tableTitle },
114113
modifier = Modifier
115114
.weight(1f)
116115
.padding(vertical = 16.dp)

app/src/main/java/org/nsh07/wikireader/ui/image/PageImage.kt

Lines changed: 41 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -34,43 +34,49 @@ fun PageImage(
3434
contentScale: ContentScale,
3535
modifier: Modifier = Modifier
3636
) {
37-
if (painterState is AsyncImagePainter.State.Success) {
38-
Image(
39-
painter = painter,
40-
contentDescription = photoDesc,
41-
contentScale = contentScale,
42-
modifier = modifier
43-
.aspectRatio(photo.width.toFloat() / photo.height.toFloat())
44-
.background(if (background) Color.White else Color.Transparent)
45-
)
46-
} else if (painterState is AsyncImagePainter.State.Loading) {
47-
Box(
48-
contentAlignment = Alignment.Center,
49-
modifier = modifier
50-
.fillMaxWidth()
51-
.aspectRatio(
52-
photo.width.toFloat() / photo.height.toFloat()
53-
)
54-
) {
55-
CircularWavyProgressIndicator()
37+
when (painterState) {
38+
is AsyncImagePainter.State.Success -> {
39+
Image(
40+
painter = painter,
41+
contentDescription = photoDesc,
42+
contentScale = contentScale,
43+
modifier = modifier
44+
.aspectRatio(photo.width.toFloat() / photo.height.toFloat())
45+
.background(if (background) Color.White else Color.Transparent)
46+
)
5647
}
57-
} else {
58-
Box(
59-
contentAlignment = Alignment.Center,
60-
modifier = modifier
61-
.fillMaxWidth()
62-
.aspectRatio(
63-
photo.width.toFloat() / photo.height.toFloat()
48+
49+
is AsyncImagePainter.State.Loading -> {
50+
Box(
51+
contentAlignment = Alignment.Center,
52+
modifier = modifier
53+
.fillMaxWidth()
54+
.aspectRatio(
55+
photo.width.toFloat() / photo.height.toFloat()
56+
)
57+
) {
58+
CircularWavyProgressIndicator()
59+
}
60+
}
61+
62+
else -> {
63+
Box(
64+
contentAlignment = Alignment.Center,
65+
modifier = modifier
66+
.fillMaxWidth()
67+
.aspectRatio(
68+
photo.width.toFloat() / photo.height.toFloat()
69+
)
70+
) {
71+
Icon(
72+
painterResource(R.drawable.error),
73+
contentDescription = stringResource(R.string.errorLoadingImage),
74+
modifier = Modifier
75+
.padding(vertical = 16.dp)
76+
.size(64.dp),
77+
tint = colorScheme.error
6478
)
65-
) {
66-
Icon(
67-
painterResource(R.drawable.error),
68-
contentDescription = stringResource(R.string.errorLoadingImage),
69-
modifier = Modifier
70-
.padding(vertical = 16.dp)
71-
.size(64.dp),
72-
tint = colorScheme.error
73-
)
79+
}
7480
}
7581
}
7682
}

0 commit comments

Comments
 (0)