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:
Carlos Correia
2026-07-09 15:31:59 +01:00
parent 67b580778a
commit 9fb2840529
14 changed files with 1584 additions and 381 deletions

View 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();
}
}