import '../state/app_interaction_state.dart'; abstract class UserStateRepository { Future isLoggedIn(); Future login(LoginMethod method); Future logout(); Future> getFavorites(); Future toggleFavorite(String reportId); Future> getSavedListens(); Future toggleSavedListen(String reportId); Future> getHistory(); Future addHistory(String reportId); Future> getAudioProgress(); Future saveAudioProgress(String audioId, double seconds); } class MemoryUserStateRepository implements UserStateRepository { bool _loggedIn = false; final Set _favorites = {}; final Set _savedListens = {}; final List _history = []; final Map _audioProgress = {}; @override Future isLoggedIn() async => _loggedIn; @override Future login(LoginMethod method) async { _loggedIn = true; } @override Future logout() async { _loggedIn = false; } @override Future> getFavorites() async => {..._favorites}; @override Future toggleFavorite(String reportId) async { if (!_favorites.add(reportId)) { _favorites.remove(reportId); } } @override Future> getSavedListens() async => {..._savedListens}; @override Future toggleSavedListen(String reportId) async { if (!_savedListens.add(reportId)) { _savedListens.remove(reportId); } } @override Future> getHistory() async => [..._history]; @override Future addHistory(String reportId) async { _history.remove(reportId); _history.insert(0, reportId); if (_history.length > 40) { _history.removeRange(40, _history.length); } } @override Future> getAudioProgress() async => {..._audioProgress}; @override Future saveAudioProgress(String audioId, double seconds) async { _audioProgress[audioId] = seconds < 0 ? 0 : seconds; } }