added image cache managing
This commit is contained in:
parent
b7045fc242
commit
2ff4d44d25
14 changed files with 188 additions and 80 deletions
|
@ -1,3 +1,4 @@
|
|||
import 'package:mc_gallery/features/core/services/logging_service.dart';
|
||||
import 'package:mc_gallery/features/home/data/models/image_model.dart';
|
||||
import 'package:mc_gallery/locator.dart';
|
||||
|
||||
|
@ -8,20 +9,33 @@ import '../abstracts/images_api.dart';
|
|||
/// Since this is very simple use-case, this is the only interface. For complex (actual CRUD-based) I/O,
|
||||
/// an additional Repository layer interface can be used between [ImagesService] and [ImagesApi].
|
||||
class ImagesService {
|
||||
ImagesService({required ImagesApi imagesApi}) : _imagesApi = imagesApi {
|
||||
ImagesService({
|
||||
required ImagesApi imagesApi,
|
||||
required LoggingService loggingService,
|
||||
}) : _imagesApi = imagesApi,
|
||||
_loggingService = loggingService {
|
||||
_init();
|
||||
}
|
||||
|
||||
final ImagesApi _imagesApi;
|
||||
final LoggingService _loggingService;
|
||||
|
||||
late final Iterable<ImageModel> _imageModels;
|
||||
Iterable<ImageModel> get imageModels => _imageModels;
|
||||
|
||||
Future<void> _init() async {
|
||||
_loggingService.info('Fetching and creating image models...');
|
||||
_imageModels = await _imagesApi.fetchImageUri(token: '');
|
||||
|
||||
_imageModels.isNotEmpty
|
||||
? _loggingService.good("Created ${_imageModels.length} images' models")
|
||||
: _loggingService.warning('No images found');
|
||||
|
||||
Locator.instance().signalReady(this);
|
||||
}
|
||||
|
||||
int get firstAvailableImageIndex => 0;
|
||||
int get lastAvailableImageIndex => _imageModels.length - 1;
|
||||
|
||||
static ImagesService get locate => Locator.locate();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue