Skip to content

Commit 3928828

Browse files
authored
Merge pull request #594 from MadridSquad/hot-fix/error-library-guest
fix: loading only as a guest
2 parents 390746c + 6c715dc commit 3928828

File tree

4 files changed

+42
-26
lines changed

4 files changed

+42
-26
lines changed

presentation/src/main/java/com/madrid/presentation/component/header/MovieDetailsHeader.kt

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -51,26 +51,32 @@ fun MovieDetailsHeader(
5151
modifier = Modifier.padding(vertical = 4.dp)
5252
) {
5353
rate?.let {
54-
DetailsChips(
55-
icon = painterResource(com.madrid.designSystem.R.drawable.bold_star),
56-
iconTint = Theme.color.system.warning,
57-
text = it,
58-
)
54+
if (it.isNotEmpty()) {
55+
DetailsChips(
56+
icon = painterResource(com.madrid.designSystem.R.drawable.bold_star),
57+
iconTint = Theme.color.system.warning,
58+
text = rate,
59+
)
60+
}
5961
}
6062

6163
time?.let {
64+
if (it.isNotEmpty()) {
65+
DetailsChips(
66+
icon = painterResource(com.madrid.designSystem.R.drawable.outline_clock_circle),
67+
iconTint = Theme.color.surfaces.onSurfaceVariant,
68+
text = time,
69+
)
70+
}
71+
}
72+
73+
if (date.isNotEmpty()) {
6274
DetailsChips(
63-
icon = painterResource(com.madrid.designSystem.R.drawable.outline_clock_circle),
75+
icon = painterResource(com.madrid.designSystem.R.drawable.outline_calendar),
6476
iconTint = Theme.color.surfaces.onSurfaceVariant,
65-
text = it,
77+
text = date,
6678
)
6779
}
68-
69-
DetailsChips(
70-
icon = painterResource(com.madrid.designSystem.R.drawable.outline_calendar),
71-
iconTint = Theme.color.surfaces.onSurfaceVariant,
72-
text = date,
73-
)
7480
}
7581
}
7682
}

presentation/src/main/java/com/madrid/presentation/screens/libraryScreen/LibraryScreen.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,13 @@ private fun LibraryScreenContent(
121121
enter = fadeIn(),
122122
exit = fadeOut()
123123
) {
124-
LibraryColumn(state, libraryInteractionListener)
124+
if (state.isGuest.not()) {
125+
LibraryColumn(state, libraryInteractionListener)
126+
}
125127
}
126128

127129
AnimatedVisibility(
128-
visible = state.errorMessage.isNullOrBlank().not(),
130+
visible = state.errorMessage.isNullOrBlank().not() && state.isGuest.not(),
129131
enter = fadeIn(),
130132
exit = fadeOut()
131133
) {

presentation/src/main/java/com/madrid/presentation/viewModel/libraryViewModel/LibraryViewModel.kt

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,14 @@ class LibraryViewModel @Inject constructor(
2828
), LibraryInteractionListener {
2929

3030
fun loadData() {
31+
getIsGuest()
3132
getWatchList()
3233
getFavoriteList()
3334
getHistoryList()
34-
getIsGuest()
3535
}
3636

3737
fun onRefresh() {
38+
getIsGuest()
3839
getWatchList()
3940
getFavoriteList()
4041
getHistoryList()
@@ -84,7 +85,6 @@ class LibraryViewModel @Inject constructor(
8485
fun getIsGuest() {
8586
updateState {
8687
it.copy(
87-
isLoading = true,
8888
errorMessage = null
8989
)
9090
}
@@ -94,7 +94,7 @@ class LibraryViewModel @Inject constructor(
9494
},
9595
onNewValue = { isGuest ->
9696
updateState {
97-
it.copy(isGuest = isGuest, isLoading = false)
97+
it.copy(isGuest = isGuest, isLoading = false , errorMessage = null)
9898
}
9999
},
100100
onError = { throwable -> onError(message = throwable.message) }
@@ -111,7 +111,8 @@ class LibraryViewModel @Inject constructor(
111111
updateState {
112112
it.copy(
113113
isWatchListLoading = false,
114-
watchList = watchList.map { it.toWatchListUiState() }
114+
watchList = watchList.map { it.toWatchListUiState() },
115+
errorMessage = null
115116
)
116117
}
117118
},
@@ -129,7 +130,8 @@ class LibraryViewModel @Inject constructor(
129130
updateState {
130131
it.copy(
131132
isFavouriteLoading = false,
132-
favoriteList = favoriteList.map { it.toMediaUiState() }
133+
favoriteList = favoriteList.map { it.toMediaUiState() },
134+
errorMessage = null
133135
)
134136
}
135137
},
@@ -153,7 +155,8 @@ class LibraryViewModel @Inject constructor(
153155
updateState {
154156
it.copy(
155157
isHistoryLoading = false,
156-
historyList = historyList
158+
historyList = historyList,
159+
errorMessage = null
157160
)
158161
}
159162
},

presentation/src/main/java/com/madrid/presentation/viewModel/shared/parser/formatDateKotlinx.kt

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,16 @@ import kotlinx.datetime.toLocalDate
55

66

77
fun formatDateKotlinx(dateString: String): String {
8-
val date: LocalDate = dateString.toLocalDate()
8+
try{
9+
val date: LocalDate = dateString.toLocalDate()
910

10-
val month = date.monthNumber.toString().padStart(2, '0')
11-
val day = date.dayOfMonth.toString().padStart(2, '0')
12-
val year = date.year.toString()
11+
val month = date.monthNumber.toString().padStart(2, '0')
12+
val day = date.dayOfMonth.toString().padStart(2, '0')
13+
val year = date.year.toString()
1314

14-
return "$month/$day/$year"
15+
return "$month/$day/$year"
16+
}
17+
catch (e: Exception) {
18+
return ""
19+
}
1520
}

0 commit comments

Comments
 (0)