From 624dc261e1e907cc47ca81bcc2111f40cff3d85e Mon Sep 17 00:00:00 2001 From: Hossain Khan Date: Mon, 20 Oct 2025 17:25:11 -0400 Subject: [PATCH] [ADDED] New rate limited models that needs to be used --- .../trmnl/android/work/ImageUpdateResult.kt | 47 +++++++++++++++++++ .../trmnl/android/work/RefreshWorkResult.kt | 1 + 2 files changed, 48 insertions(+) create mode 100644 app/src/main/java/ink/trmnl/android/work/ImageUpdateResult.kt diff --git a/app/src/main/java/ink/trmnl/android/work/ImageUpdateResult.kt b/app/src/main/java/ink/trmnl/android/work/ImageUpdateResult.kt new file mode 100644 index 0000000..c88e3d0 --- /dev/null +++ b/app/src/main/java/ink/trmnl/android/work/ImageUpdateResult.kt @@ -0,0 +1,47 @@ +package ink.trmnl.android.work + +import androidx.annotation.Keep +import ink.trmnl.android.data.ImageMetadata + +/** + * Sealed class representing the result of an image update operation. + * + * This provides a type-safe way to handle different outcomes of image refresh operations: + * - [Success]: New image was successfully fetched and should be displayed + * - [RateLimited]: Rate limit encountered, keep showing current image with notification + * - [Error]: Fatal error occurred, display error state + */ +@Keep +sealed class ImageUpdateResult { + /** + * Successfully fetched a new image to display. + * + * @param metadata The metadata for the new image including URL and refresh interval + */ + data class Success( + val metadata: ImageMetadata, + ) : ImageUpdateResult() + + /** + * Rate limit encountered (HTTP 429). + * Keep showing the current image and notify the user. + * + * NOTE: This usually happens for current display API. See details below: + * - https://discord.com/channels/1281055965508141100/1336424981495676978/1429827943902744618 + * + * @param message User-friendly message to display (e.g., "Rate limit (10s cooldown)") + */ + data class RateLimited( + val message: String, + ) : ImageUpdateResult() + + /** + * Fatal error occurred during image fetch. + * Display error state to the user. + * + * @param message Error message to display to the user + */ + data class Error( + val message: String, + ) : ImageUpdateResult() +} diff --git a/app/src/main/java/ink/trmnl/android/work/RefreshWorkResult.kt b/app/src/main/java/ink/trmnl/android/work/RefreshWorkResult.kt index 4b594e3..c1ad454 100644 --- a/app/src/main/java/ink/trmnl/android/work/RefreshWorkResult.kt +++ b/app/src/main/java/ink/trmnl/android/work/RefreshWorkResult.kt @@ -9,4 +9,5 @@ import androidx.annotation.Keep enum class RefreshWorkResult { SUCCESS, FAILURE, + RATE_LIMITED, }