diff --git a/app/src/main/kotlin/com/hippo/ehviewer/Settings.kt b/app/src/main/kotlin/com/hippo/ehviewer/Settings.kt index 81e9bae2d..a6bcf2174 100644 --- a/app/src/main/kotlin/com/hippo/ehviewer/Settings.kt +++ b/app/src/main/kotlin/com/hippo/ehviewer/Settings.kt @@ -157,6 +157,7 @@ object Settings : DataStorePreferences(null) { var searchCategory by intPref("search_pref", EhUtils.ALL_CATEGORY) var requestNewsTime by intPref("request_news_time", 0).observed { updateWhenRequestNewsChanges() } var updateIntervalDays by intPref("update_interval_days", 7) + var lastDawnDays by intPref("last_dawn_days", 0) var recentToplist by stringPref("recent_toplist", "11") var userAgent by stringPref("user_agent", CHROME_USER_AGENT) var recentDownloadLabel by stringOrNullPref("recent_download_label", null) @@ -164,7 +165,6 @@ object Settings : DataStorePreferences(null) { var displayName by stringOrNullPref("display_name", null) var avatar by stringOrNullPref("avatar", null) var language by stringPref("app_language", "system").observed { updateWhenLocaleChanges() } - var lastDawnTime by longPref("last_dawn_time", 0) var lastUpdateTime by longPref("last_update_time", 0) var favDialogTheta by floatPref("fav_select_dialog_delta", 0F) diff --git a/app/src/main/kotlin/com/hippo/ehviewer/client/EhEngine.kt b/app/src/main/kotlin/com/hippo/ehviewer/client/EhEngine.kt index b28cd2b7f..9783daefd 100644 --- a/app/src/main/kotlin/com/hippo/ehviewer/client/EhEngine.kt +++ b/app/src/main/kotlin/com/hippo/ehviewer/client/EhEngine.kt @@ -50,6 +50,7 @@ import com.hippo.ehviewer.client.parser.TorrentResult import com.hippo.ehviewer.client.parser.VoteCommentResult import com.hippo.ehviewer.client.parser.VoteTagParser import com.hippo.ehviewer.dailycheck.showEventNotification +import com.hippo.ehviewer.dailycheck.today import com.hippo.ehviewer.util.AppConfig import com.hippo.ehviewer.util.ReadableTime import com.hippo.ehviewer.util.StatusCodeException @@ -68,7 +69,6 @@ import java.nio.channels.FileChannel import kotlin.math.ceil import kotlinx.coroutines.CancellationException import kotlinx.coroutines.delay -import kotlinx.datetime.Clock import kotlinx.serialization.SerializationException import kotlinx.serialization.json.add import kotlinx.serialization.json.addJsonArray @@ -217,7 +217,7 @@ object EhEngine { suspend fun getGalleryDetail(url: String) = ehRequest(url, EhUrl.referer).fetchUsingAsText { val eventPane = EventPaneParser.parse(this) if (eventPane != null) { - Settings.lastDawnTime = Clock.System.now().epochSeconds + Settings.lastDawnDays = today showEventNotification(eventPane) } GalleryDetailParser.parse(this) diff --git a/app/src/main/kotlin/com/hippo/ehviewer/dailycheck/DailyCheckWork.kt b/app/src/main/kotlin/com/hippo/ehviewer/dailycheck/DailyCheckWork.kt index 376103d06..1410b30c9 100644 --- a/app/src/main/kotlin/com/hippo/ehviewer/dailycheck/DailyCheckWork.kt +++ b/app/src/main/kotlin/com/hippo/ehviewer/dailycheck/DailyCheckWork.kt @@ -28,7 +28,6 @@ import java.time.Duration import java.util.concurrent.TimeUnit import kotlin.time.Duration.Companion.days import kotlinx.datetime.Clock -import kotlinx.datetime.Instant import kotlinx.datetime.LocalDateTime import kotlinx.datetime.LocalTime import kotlinx.datetime.TimeZone @@ -79,12 +78,13 @@ fun updateDailyCheckWork(context: Context) { } } +val today + get() = (Clock.System.now().epochSeconds / 86400).toInt() + suspend fun checkDawn() = runCatching { - val now = Clock.System.now() - val last = Instant.fromEpochSeconds(Settings.lastDawnTime) - if (EhCookieStore.hasSignedIn() && now > last + 1.days) { + if (EhCookieStore.hasSignedIn() && Settings.lastDawnDays != today) { EhEngine.getNews(true)?.let { - Settings.lastDawnTime = now.epochSeconds + Settings.lastDawnDays = today showEventNotification(it) } }