forked from github/szkolny
[Home/LuckyNumberCard] Fix crashing because of invalid argument type.
This commit is contained in:
parent
5991ef820f
commit
fe40ab0ab4
@ -51,6 +51,9 @@ class HomeLuckyNumberCard(
|
|||||||
val today = Date.getToday()
|
val today = Date.getToday()
|
||||||
val todayValue = today.value
|
val todayValue = today.value
|
||||||
|
|
||||||
|
val tomorrow = Date.getToday().stepForward(0, 0, 1)
|
||||||
|
val tomorrowValue = tomorrow.value
|
||||||
|
|
||||||
val subTextRes = if (profile.studentNumber == -1)
|
val subTextRes = if (profile.studentNumber == -1)
|
||||||
R.string.home_lucky_number_details_click_to_set
|
R.string.home_lucky_number_details_click_to_set
|
||||||
else
|
else
|
||||||
@ -59,28 +62,26 @@ class HomeLuckyNumberCard(
|
|||||||
|
|
||||||
app.db.luckyNumberDao().getNearestFuture(App.profileId, todayValue).observe(fragment, Observer { luckyNumber ->
|
app.db.luckyNumberDao().getNearestFuture(App.profileId, todayValue).observe(fragment, Observer { luckyNumber ->
|
||||||
val isYours = luckyNumber?.number == profile.studentNumber
|
val isYours = luckyNumber?.number == profile.studentNumber
|
||||||
val titleRes = when {
|
val res: Pair<Int, Array<out Any>> = when {
|
||||||
luckyNumber == null -> R.string.home_lucky_number_no_info
|
luckyNumber == null -> R.string.home_lucky_number_no_info to emptyArray()
|
||||||
luckyNumber.number == -1 -> R.string.home_lucky_number_no_number
|
luckyNumber.number == -1 -> R.string.home_lucky_number_no_number to emptyArray()
|
||||||
else -> when (isYours) {
|
else -> when (isYours) {
|
||||||
true -> when (luckyNumber.date.value) {
|
true -> when (luckyNumber.date.value) {
|
||||||
todayValue -> R.string.home_lucky_number_yours_today
|
todayValue -> R.string.home_lucky_number_yours_today to emptyArray()
|
||||||
todayValue + 1 -> R.string.home_lucky_number_yours_tomorrow
|
tomorrowValue -> R.string.home_lucky_number_yours_tomorrow to emptyArray()
|
||||||
else -> R.string.home_lucky_number_yours_later
|
else -> R.string.home_lucky_number_yours_later to arrayOf(luckyNumber.date.formattedString)
|
||||||
}
|
}
|
||||||
false -> when (luckyNumber.date.value) {
|
false -> when (luckyNumber.date.value) {
|
||||||
todayValue -> R.string.home_lucky_number_today
|
todayValue -> R.string.home_lucky_number_today to arrayOf(luckyNumber.number)
|
||||||
todayValue + 1 -> R.string.home_lucky_number_tomorrow
|
tomorrowValue -> R.string.home_lucky_number_tomorrow to arrayOf(luckyNumber.number)
|
||||||
else -> R.string.home_lucky_number_later
|
else -> R.string.home_lucky_number_later to arrayOf(luckyNumber.date.formattedString, luckyNumber.number)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
b.title.setText(
|
val (titleRes, resArguments) = res
|
||||||
titleRes,
|
|
||||||
luckyNumber?.number ?: 0,
|
b.title.setText(titleRes, *resArguments)
|
||||||
luckyNumber?.date?.formattedString ?: ""
|
|
||||||
)
|
|
||||||
|
|
||||||
val drawableRes = when {
|
val drawableRes = when {
|
||||||
luckyNumber == null || luckyNumber.number == -1 -> R.drawable.emoji_sad
|
luckyNumber == null || luckyNumber.number == -1 -> R.drawable.emoji_sad
|
||||||
|
Loading…
x
Reference in New Issue
Block a user