Favourites
This commit is contained in:
parent
6a84a9bef0
commit
1747ab0245
23 changed files with 469 additions and 67 deletions
|
@ -3,6 +3,7 @@ import 'dart:async';
|
|||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_cache_manager/flutter_cache_manager.dart';
|
||||
import 'package:mc_gallery/features/core/data/extensions/value_notifier_extensions.dart';
|
||||
|
||||
import '/features/core/abstracts/base_view_model.dart';
|
||||
import '/features/core/services/logging_service.dart';
|
||||
|
@ -27,6 +28,7 @@ class GalleryViewModel extends BaseViewModel {
|
|||
|
||||
final ImagesService _imagesService;
|
||||
final NavigationService _navigationService;
|
||||
//todo(mehul): Use to implement pull-to-refresh or an extra widget
|
||||
final ImageCacheManagerService _imageCacheManagerService;
|
||||
final LoggingService _loggingService;
|
||||
|
||||
|
@ -40,6 +42,9 @@ class GalleryViewModel extends BaseViewModel {
|
|||
final ValueNotifier<List<ImageModel>> _imageSearchResultsNotifier = ValueNotifier([]);
|
||||
ValueListenable<List<ImageModel>> get imageSearchResultsListenable => _imageSearchResultsNotifier;
|
||||
|
||||
final ValueNotifier<bool> _isViewingFavouriteNotifier = ValueNotifier(false);
|
||||
ValueListenable<bool> get isViewingFavouriteListenable => _isViewingFavouriteNotifier;
|
||||
|
||||
@override
|
||||
Future<void> initialise(bool Function() mounted, [arguments]) async {
|
||||
super.initialise(mounted, arguments);
|
||||
|
@ -80,7 +85,7 @@ class GalleryViewModel extends BaseViewModel {
|
|||
_loggingService.info('Clearing of results on view mode change');
|
||||
}
|
||||
|
||||
_isSearchingNotifier.value = !_isSearchingNotifier.value;
|
||||
_isSearchingNotifier.flipValue();
|
||||
}
|
||||
|
||||
Future<void> get lastQueryResultDone => _imagesService.lastQueryIsCompleted;
|
||||
|
@ -92,9 +97,24 @@ class GalleryViewModel extends BaseViewModel {
|
|||
_imageSearchResultsNotifier.value = [];
|
||||
_loggingService.info('Cleared resultsw from view');
|
||||
|
||||
//todo(mehul): Either redo search or force user to type in by clearing field
|
||||
//todo(mehul): Either redo search or force user to type in new (trigger) by clearing field
|
||||
}
|
||||
|
||||
void onFavouriteViewChange(bool newValue) => _isViewingFavouriteNotifier.value = newValue;
|
||||
|
||||
void updateImageFavouriteStatus({
|
||||
required ImageModel imageModel,
|
||||
required bool newFavouriteStatus,
|
||||
}) {
|
||||
_imagesService.updateImageFavouriteStatus(
|
||||
imageModel: imageModel,
|
||||
newFavouriteStatus: newFavouriteStatus,
|
||||
);
|
||||
}
|
||||
|
||||
Iterable<ImageModel> get favouriteImageModels =>
|
||||
imageModels.where((final imageModel) => imageModel.isFavourite);
|
||||
|
||||
void onPromptPressed() => _isDisplayingPressingPrompt.value = false;
|
||||
|
||||
Iterable<ImageModel> get imageModels => _imagesService.imageModels;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue