[APIv2/Librus] Use apply in getting lucky numbers

This commit is contained in:
Kacper Ziubryniewicz 2019-10-17 14:35:10 +02:00
parent f79263e628
commit c03eca3804

View File

@ -25,19 +25,19 @@ class LibrusApiLuckyNumber(override val data: DataLibrus,
if (json.isJsonNull) {
profile?.luckyNumberEnabled = false
} else {
profile?.also { profile ->
profile.luckyNumber = -1
profile.luckyNumberDate = Date.getToday()
profile?.apply {
luckyNumber = -1
luckyNumberDate = Date.getToday()
json.getJsonObject("LuckyNumber")?.also { luckyNumber ->
profile.luckyNumber = luckyNumber.getInt("LuckyNumber") ?: -1
profile.luckyNumberDate = Date.fromY_m_d(luckyNumber.getString("LuckyNumberDay"))
json.getJsonObject("LuckyNumber")?.also { luckyNumberEl ->
luckyNumber = luckyNumberEl.getInt("LuckyNumber") ?: -1
luckyNumberDate = Date.fromY_m_d(luckyNumberEl.getString("LuckyNumberDay"))
}
data.luckyNumberList.add(LuckyNumber(
profileId,
profile.luckyNumberDate ?: Date.getToday(),
profile.luckyNumber
luckyNumberDate ?: Date.getToday(),
luckyNumber
))
}
}