Browse Source

Resume from the last seen memories for seen memories

Vishnu Mohandas 5 years ago
parent
commit
9f91c83f77
4 changed files with 24 additions and 13 deletions
  1. 6 6
      lib/db/memories_db.dart
  2. 4 2
      lib/memories_service.dart
  3. 9 5
      lib/models/memory.dart
  4. 5 0
      lib/ui/memories_widget.dart

+ 6 - 6
lib/db/memories_db.dart

@@ -59,9 +59,9 @@ class MemoriesDB {
         conflictAlgorithm: ConflictAlgorithm.replace);
         conflictAlgorithm: ConflictAlgorithm.replace);
   }
   }
 
 
-  Future<Set<int>> getSeenFileIDs() async {
+  Future<Map<int, int>> getSeenTimes() async {
     final db = await instance.database;
     final db = await instance.database;
-    return _convertToFileIDs(await db.query(table));
+    return _convertToSeenTimes(await db.query(table));
   }
   }
 
 
   Map<String, dynamic> _getRowForSeenMemory(Memory memory, int timestamp) {
   Map<String, dynamic> _getRowForSeenMemory(Memory memory, int timestamp) {
@@ -71,11 +71,11 @@ class MemoriesDB {
     return row;
     return row;
   }
   }
 
 
-  Set<int> _convertToFileIDs(List<Map<String, dynamic>> rows) {
-    final fileIDs = Set<int>();
+  Map<int, int> _convertToSeenTimes(List<Map<String, dynamic>> rows) {
+    final seenTimes = Map<int, int>();
     for (final row in rows) {
     for (final row in rows) {
-      fileIDs.add(row[columnFileID]);
+      seenTimes[row[columnFileID]] = int.parse(row[columnSeenTime]);
     }
     }
-    return fileIDs;
+    return seenTimes;
   }
   }
 }
 }

+ 4 - 2
lib/memories_service.dart

@@ -53,11 +53,12 @@ class MemoriesService extends ChangeNotifier {
                 DateTime.fromMicrosecondsSinceEpoch(endCreationTime)));
                 DateTime.fromMicrosecondsSinceEpoch(endCreationTime)));
       files.addAll(filesInYear);
       files.addAll(filesInYear);
     }
     }
-    final seenFileIDs = await _memoriesDB.getSeenFileIDs();
+    final seenTimes = await _memoriesDB.getSeenTimes();
     final memories = List<Memory>();
     final memories = List<Memory>();
     for (final file in files) {
     for (final file in files) {
       if (filter.shouldInclude(file)) {
       if (filter.shouldInclude(file)) {
-        memories.add(Memory(file, seenFileIDs.contains(file.generatedId)));
+        final seenTime = seenTimes[file.generatedId] ?? -1;
+        memories.add(Memory(file, seenTime));
       }
       }
     }
     }
     _logger.info("Number of memories: " + memories.length.toString());
     _logger.info("Number of memories: " + memories.length.toString());
@@ -76,6 +77,7 @@ class MemoriesService extends ChangeNotifier {
   }
   }
 
 
   Future markMemoryAsSeen(Memory memory) async {
   Future markMemoryAsSeen(Memory memory) async {
+    _logger.info("Marking memory " + memory.file.title + " as seen");
     await _memoriesDB.markMemoryAsSeen(
     await _memoriesDB.markMemoryAsSeen(
         memory, DateTime.now().microsecondsSinceEpoch);
         memory, DateTime.now().microsecondsSinceEpoch);
     notifyListeners();
     notifyListeners();

+ 9 - 5
lib/models/memory.dart

@@ -2,15 +2,19 @@ import 'package:photos/models/file.dart';
 
 
 class Memory {
 class Memory {
   final File file;
   final File file;
-  bool _isSeen;
+  int _seenTime;
 
 
-  Memory(this.file, this._isSeen);
+  Memory(this.file, this._seenTime);
 
 
   bool isSeen() {
   bool isSeen() {
-    return _isSeen;
+    return _seenTime != -1;
   }
   }
 
 
-  bool markSeen() {
-    _isSeen = true;
+  int seenTime() {
+    return _seenTime;
+  }
+
+  void markSeen() {
+    _seenTime = DateTime.now().microsecondsSinceEpoch;
   }
   }
 }
 }

+ 5 - 0
lib/ui/memories_widget.dart

@@ -152,6 +152,10 @@ class MemoryWidget extends StatelessWidget {
       if (!memories[index].isSeen()) {
       if (!memories[index].isSeen()) {
         return index;
         return index;
       }
       }
+      if (index > 0 &&
+          memories[index - 1].seenTime() > memories[index].seenTime()) {
+        return index;
+      }
     }
     }
     return 0;
     return 0;
   }
   }
@@ -273,6 +277,7 @@ class _FullScreenMemoryState extends State<FullScreenMemory> {
       control: SwiperControl(
       control: SwiperControl(
         color: _opacity == 1 ? Colors.white54 : Colors.transparent,
         color: _opacity == 1 ? Colors.white54 : Colors.transparent,
       ),
       ),
+      index: _index,
       onIndexChanged: (index) async {
       onIndexChanged: (index) async {
         await MemoriesService.instance.markMemoryAsSeen(widget.memories[index]);
         await MemoriesService.instance.markMemoryAsSeen(widget.memories[index]);
         setState(() {
         setState(() {