Browse Source

Ensure that favorites are parsed from fetched collections

Vishnu Mohandas 4 năm trước cách đây
mục cha
commit
0c48d83384

+ 8 - 1
lib/services/favorites_service.dart

@@ -71,8 +71,15 @@ class FavoritesService {
     }
   }
 
-  Collection getFavoritesCollection() {
+  Future<Collection> getFavoritesCollection() async {
     if (!_preferences.containsKey(_favoritesCollectionIDKey)) {
+      final collections = _collectionsService.getOwnedCollections();
+      for (final collection in collections) {
+        if (collection.type == CollectionType.favorites) {
+          await _preferences.setInt(_favoritesCollectionIDKey, collection.id);
+          return collection;
+        }
+      }
       return null;
     }
     return _collectionsService

+ 2 - 1
lib/ui/collections_gallery_widget.dart

@@ -114,7 +114,8 @@ class _CollectionsGalleryWidgetState extends State<CollectionsGalleryWidget> {
     });
     if (favorites.length > 0) {
       collections.add(CollectionWithThumbnail(
-          FavoritesService.instance.getFavoritesCollection(), favorites[0]));
+          await FavoritesService.instance.getFavoritesCollection(),
+          favorites[0]));
     }
     return CollectionItems(folders, collections);
   }