Munça da UI de inicio | escovagem semanal adicionada | quantidade de videos assistidos | todos os videos na nuvem | possibilidade de continuar o video de onde parou
This commit is contained in:
36
lib/watched_videos_prefs.dart
Normal file
36
lib/watched_videos_prefs.dart
Normal file
@@ -0,0 +1,36 @@
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
/// Registo local (por criança) de episódios assistidos até ao fim.
|
||||
/// Segue o mesmo padrão de [QuizPrefs]: chaves com sufixo `_scopeId`,
|
||||
/// guardadas via [SharedPreferences], sem qualquer chamada ao Supabase.
|
||||
class WatchedVideosPrefs {
|
||||
static const String _kWatchedKey = 'watched_videos';
|
||||
|
||||
static String _key(String scopeId) => '${_kWatchedKey}_$scopeId';
|
||||
|
||||
static Future<void> markWatched(String scopeId, int videoId) async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
final key = _key(scopeId);
|
||||
final ids = (prefs.getStringList(key) ?? <String>[]).toSet();
|
||||
ids.add(videoId.toString());
|
||||
await prefs.setStringList(key, ids.toList());
|
||||
}
|
||||
|
||||
static Future<bool> isWatched(String scopeId, int videoId) async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
final ids = prefs.getStringList(_key(scopeId)) ?? const [];
|
||||
return ids.contains(videoId.toString());
|
||||
}
|
||||
|
||||
static Future<int> getWatchedCount(String scopeId) async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
final ids = prefs.getStringList(_key(scopeId)) ?? const [];
|
||||
return ids.length;
|
||||
}
|
||||
|
||||
static Future<Set<int>> getWatchedIds(String scopeId) async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
final ids = prefs.getStringList(_key(scopeId)) ?? const [];
|
||||
return ids.map((e) => int.tryParse(e) ?? -1).where((e) => e >= 0).toSet();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user