added image cache managing
This commit is contained in:
parent
b7045fc242
commit
2ff4d44d25
14 changed files with 188 additions and 80 deletions
|
@ -1,29 +1,37 @@
|
|||
import 'dart:async';
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:mc_gallery/features/core/services/logging_service.dart';
|
||||
import 'package:mc_gallery/locator.dart';
|
||||
|
||||
import '/features/core/data/constants/const_values.dart';
|
||||
import '/l10n/generated/l10n.dart';
|
||||
import '../abstracts/images_api.dart';
|
||||
import '../data/models/image_model.dart';
|
||||
|
||||
class UnsplashImagesApi implements ImagesApi {
|
||||
class UnsplashImagesApi with LoggingService implements ImagesApi {
|
||||
@override
|
||||
FutureOr<Iterable<ImageModel>> fetchImageUri({required String token}) {
|
||||
final random = Random();
|
||||
|
||||
return Iterable<int>.generate(ConstValues.numberOfImages).map((final imageIndex) {
|
||||
// Drawing from a normal distribution
|
||||
final imageSide = ConstValues.minImageSize +
|
||||
random.nextInt((ConstValues.maxImageSize + 1) - ConstValues.minImageSize);
|
||||
try {
|
||||
return Iterable<int>.generate(ConstValues.numberOfImages).map((final imageIndex) {
|
||||
// Drawing from a normal distribution
|
||||
final imageSide = ConstValues.minImageSize +
|
||||
random.nextInt((ConstValues.maxImageSize + 1) - ConstValues.minImageSize);
|
||||
|
||||
final imageUri = _imageUrlGenerator(imageSide: imageSide);
|
||||
final imageUri = _imageUrlGenerator(imageSide: imageSide);
|
||||
|
||||
return ImageModel(
|
||||
imageIndex: imageIndex,
|
||||
uri: imageUri,
|
||||
imageName: Strings.current.image,
|
||||
);
|
||||
});
|
||||
return ImageModel(
|
||||
imageIndex: imageIndex,
|
||||
uri: imageUri,
|
||||
imageName: '${Strings.current.image} $imageIndex: size=$imageSide',
|
||||
);
|
||||
});
|
||||
} on Exception catch (ex, stackTrace) {
|
||||
handleException(ex, stackTrace);
|
||||
return const Iterable.empty();
|
||||
}
|
||||
}
|
||||
|
||||
Uri _imageUrlGenerator({required int imageSide}) => Uri(
|
||||
|
@ -31,4 +39,6 @@ class UnsplashImagesApi implements ImagesApi {
|
|||
host: ConstValues.backendHost,
|
||||
pathSegments: [...ConstValues.backendUrlPathSegments, '${imageSide}x$imageSide'],
|
||||
);
|
||||
|
||||
static UnsplashImagesApi get locate => Locator.locate();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue