[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) { if (json.isJsonNull) {
profile?.luckyNumberEnabled = false profile?.luckyNumberEnabled = false
} else { } else {
profile?.also { profile -> profile?.apply {
profile.luckyNumber = -1 luckyNumber = -1
profile.luckyNumberDate = Date.getToday() luckyNumberDate = Date.getToday()
json.getJsonObject("LuckyNumber")?.also { luckyNumber -> json.getJsonObject("LuckyNumber")?.also { luckyNumberEl ->
profile.luckyNumber = luckyNumber.getInt("LuckyNumber") ?: -1 luckyNumber = luckyNumberEl.getInt("LuckyNumber") ?: -1
profile.luckyNumberDate = Date.fromY_m_d(luckyNumber.getString("LuckyNumberDay")) luckyNumberDate = Date.fromY_m_d(luckyNumberEl.getString("LuckyNumberDay"))
} }
data.luckyNumberList.add(LuckyNumber( data.luckyNumberList.add(LuckyNumber(
profileId, profileId,
profile.luckyNumberDate ?: Date.getToday(), luckyNumberDate ?: Date.getToday(),
profile.luckyNumber luckyNumber
)) ))
} }
} }