Fix offline support for Earn tab - prevent crashes and add caching
- What triggered this change? (PBI link, Email Subject, conversation + reason, etc)
Issue #1308 - Earn tab (Quiz page) crashed when offline and showed error dialogs on every "Next" button press during quiz submission.
- What was changed?
QuizViewModel - Implemented caching with offline support
- Migrated from
ObservableRangeCollectiontoAdvancedObservableCollectionwithIFileCacheService - Added
OnQuizzesError()callback distinguishingHttpRequestExceptionfor network-specific messaging - Added connectivity check in
OpenQuiz()before navigation - Added
QuizItemViewModel.IsEqual()for efficient cache comparison
QuizDetailsViewModel - Added network checks at critical points
- Connectivity check in
Initialise()with navigation fallback - Silent skip in
SubmitAnswer()when offline (prevents error spam on "Next") - Connectivity check in
SubmitResponses()before final submission - Null checks for API responses
QuizPage.xaml - Updated binding
- ItemsSource="{Binding Quizzes}"
+ ItemsSource="{Binding Quizzes.Collection}"
QuizPage.xaml.cs - Added resource cleanup
-
OnDisappearing()to dispose timer
QuizService - Improved error propagation
- Rethrow
HttpRequestExceptionto allow ViewModel-level handling
Pattern: Follows existing RedeemViewModel and ProfileViewModelBase offline patterns (cache-first loading, network-specific errors, silent failures with cached fallback).
- Did you do pair or mob programming?
No
Original prompt
This section details on the original issue you should resolve
<issue_title>🐛 Offline Support | Earn Tab [JK]</issue_title> <issue_description>Issues to fix on Mobile app:
- [ ] Prevent crash when going on earn tab
- [ ] Cache earn tab
- [ ] Gracefully handle when attempting to start a quiz
- [ ] Don't throw an error on each "Next" press in quiz when offline
Look at other pages how offline is supported.</issue_description>
Comments on the Issue (you are @copilot in this section)
- Fixes SSWConsulting/SSW.Rewards.Mobile#1308
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.
@zacharykeeping, needs more testing but looks ok.