diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/mobidziennik/data/web/MobidziennikLuckyNumberExtractor.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/mobidziennik/data/web/MobidziennikLuckyNumberExtractor.kt index 7aaf7474..bee916e7 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/mobidziennik/data/web/MobidziennikLuckyNumberExtractor.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/mobidziennik/data/web/MobidziennikLuckyNumberExtractor.kt @@ -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,27 +16,23 @@ 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(), + it + ) - val luckyNumberObject = LuckyNumber( - data.profileId, - Date.getToday(), - luckyNumber - ) - - data.luckyNumberList.add(luckyNumberObject) - data.metadataList.add( - Metadata( - data.profileId, - Metadata.TYPE_LUCKY_NUMBER, - luckyNumberObject.date.value.toLong(), - data.profile?.empty ?: false, - data.profile?.empty ?: false, - System.currentTimeMillis() - )) - } catch (_: Exception){} + data.luckyNumberList.add(luckyNumberObject) + data.metadataList.add( + Metadata( + data.profileId, + Metadata.TYPE_LUCKY_NUMBER, + luckyNumberObject.date.value.toLong(), + data.profile?.empty ?: false, + data.profile?.empty ?: false, + System.currentTimeMillis() + )) } } }