live WEB search
This commit is contained in:
parent
47945dbec7
commit
4ade7f1682
19 changed files with 503 additions and 59 deletions
|
@ -1,39 +1,80 @@
|
|||
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 '/features/core/data/extensions/random_extensions.dart';
|
||||
import '/features/core/services/logging_service.dart';
|
||||
import '/l10n/generated/l10n.dart';
|
||||
import '/locator.dart';
|
||||
import '../abstracts/images_api.dart';
|
||||
import '../data/models/image_model.dart';
|
||||
|
||||
class UnsplashImagesApi with LoggingService implements ImagesApi {
|
||||
class UnsplashImagesApi implements ImagesApi {
|
||||
final LoggingService _loggingService = LoggingService.locate;
|
||||
final random = Random();
|
||||
|
||||
@override
|
||||
FutureOr<Iterable<ImageModel>> fetchImageUri({required String token}) {
|
||||
final random = Random();
|
||||
FutureOr<Iterable<ImageModel>> fetchImageUri({required String token}) async {
|
||||
// Dummy fetching delay emulation
|
||||
await Future.delayed(const Duration(
|
||||
milliseconds: ConstValues.defaultEmulatedLatencyMillis * ConstValues.numberOfImages));
|
||||
|
||||
try {
|
||||
// Create fixed number of images
|
||||
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 imageSide =
|
||||
random.nextIntInRange(min: ConstValues.minImageSize, max: ConstValues.maxImageSize);
|
||||
|
||||
final imageUri = _imageUrlGenerator(imageSide: imageSide);
|
||||
|
||||
return ImageModel(
|
||||
imageIndex: imageIndex,
|
||||
uri: imageUri,
|
||||
imageName: '${Strings.current.image} ${imageIndex + 1}: size=$imageSide',
|
||||
// Custom dummy name for the image
|
||||
|
||||
imageName: Strings.current.imageNameFetch(imageIndex + 1, imageSide),
|
||||
);
|
||||
});
|
||||
} on Exception catch (ex, stackTrace) {
|
||||
handleException(ex, stackTrace);
|
||||
_loggingService.handleException(ex, stackTrace);
|
||||
return const Iterable.empty();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
FutureOr<List<ImageModel>> searchImages({
|
||||
required String searchStr,
|
||||
required String token,
|
||||
}) async {
|
||||
final numberOfResults = random.nextIntInRange(min: 0, max: ConstValues.numberOfImages);
|
||||
|
||||
// Dummy fetching delay emulation
|
||||
await Future.delayed(
|
||||
Duration(milliseconds: ConstValues.defaultEmulatedLatencyMillis * numberOfResults));
|
||||
|
||||
try {
|
||||
// Create (randomly-bounded) dummy number of images
|
||||
return Iterable<int>.generate(numberOfResults).map((final imageIndex) {
|
||||
// Drawing from a normal distribution
|
||||
final imageSide =
|
||||
random.nextIntInRange(min: ConstValues.minImageSize, max: ConstValues.maxImageSize);
|
||||
|
||||
final imageUri = _imageUrlGenerator(imageSide: imageSide);
|
||||
|
||||
return ImageModel(
|
||||
imageIndex: imageIndex,
|
||||
uri: imageUri,
|
||||
// Custom dummy name for the image
|
||||
imageName: Strings.current.imageNameSearch(searchStr, imageIndex + 1),
|
||||
);
|
||||
}).toList(growable: false);
|
||||
} on Exception catch (ex, stackTrace) {
|
||||
_loggingService.handleException(ex, stackTrace);
|
||||
return List.empty();
|
||||
}
|
||||
}
|
||||
|
||||
Uri _imageUrlGenerator({required int imageSide}) => Uri(
|
||||
scheme: ConstValues.httpsScheme,
|
||||
host: ConstValues.backendHost,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue