[API/Mobidziennik] Use toIntOrNull instead of try catch in the lucky number extractor.

This commit is contained in:
Kacper Ziubryniewicz 2020-01-04 00:15:56 +01:00
parent a96fcabba5
commit d735dcea05

View File

@ -8,6 +8,7 @@ import pl.szczodrzynski.edziennik.data.api.Regexes
import pl.szczodrzynski.edziennik.data.api.edziennik.mobidziennik.DataMobidziennik
import pl.szczodrzynski.edziennik.data.db.modules.luckynumber.LuckyNumber
import pl.szczodrzynski.edziennik.data.db.modules.metadata.Metadata
import pl.szczodrzynski.edziennik.get
import pl.szczodrzynski.edziennik.utils.models.Date
class MobidziennikLuckyNumberExtractor(val data: DataMobidziennik, text: String) {
@ -15,14 +16,11 @@ class MobidziennikLuckyNumberExtractor(val data: DataMobidziennik, text: String)
data.profile?.luckyNumber = -1
data.profile?.luckyNumberDate = null
Regexes.MOBIDZIENNIK_LUCKY_NUMBER.find(text)?.let {
try {
val luckyNumber = it.groupValues[1].toInt()
Regexes.MOBIDZIENNIK_LUCKY_NUMBER.find(text)?.get(1)?.toIntOrNull()?.let {
val luckyNumberObject = LuckyNumber(
data.profileId,
Date.getToday(),
luckyNumber
it
)
data.luckyNumberList.add(luckyNumberObject)
@ -35,7 +33,6 @@ class MobidziennikLuckyNumberExtractor(val data: DataMobidziennik, text: String)
data.profile?.empty ?: false,
System.currentTimeMillis()
))
} catch (_: Exception){}
}
}
}