locale independent colors for known albums
This commit is contained in:
parent
b6367e391c
commit
2165a4e058
2 changed files with 37 additions and 14 deletions
|
@ -1,6 +1,7 @@
|
||||||
import 'package:aves/image_providers/app_icon_image_provider.dart';
|
import 'package:aves/image_providers/app_icon_image_provider.dart';
|
||||||
import 'package:aves/model/filters/filters.dart';
|
import 'package:aves/model/filters/filters.dart';
|
||||||
import 'package:aves/services/common/services.dart';
|
import 'package:aves/services/common/services.dart';
|
||||||
|
import 'package:aves/theme/colors.dart';
|
||||||
import 'package:aves/theme/icons.dart';
|
import 'package:aves/theme/icons.dart';
|
||||||
import 'package:aves/utils/android_file_utils.dart';
|
import 'package:aves/utils/android_file_utils.dart';
|
||||||
import 'package:aves/widgets/common/identity/aves_icons.dart';
|
import 'package:aves/widgets/common/identity/aves_icons.dart';
|
||||||
|
@ -57,21 +58,36 @@ class AlbumFilter extends CollectionFilter {
|
||||||
Future<Color> color(BuildContext context) {
|
Future<Color> color(BuildContext context) {
|
||||||
// do not use async/await and rely on `SynchronousFuture`
|
// do not use async/await and rely on `SynchronousFuture`
|
||||||
// to prevent rebuilding of the `FutureBuilder` listening on this future
|
// to prevent rebuilding of the `FutureBuilder` listening on this future
|
||||||
if (androidFileUtils.getAlbumType(album) == AlbumType.app) {
|
final albumType = androidFileUtils.getAlbumType(album);
|
||||||
if (_appColors.containsKey(album)) return SynchronousFuture(_appColors[album]!);
|
switch (albumType) {
|
||||||
|
case AlbumType.regular:
|
||||||
|
break;
|
||||||
|
case AlbumType.app:
|
||||||
|
if (_appColors.containsKey(album)) return SynchronousFuture(_appColors[album]!);
|
||||||
|
|
||||||
final packageName = androidFileUtils.getAlbumAppPackageName(album);
|
final packageName = androidFileUtils.getAlbumAppPackageName(album);
|
||||||
if (packageName != null) {
|
if (packageName != null) {
|
||||||
return PaletteGenerator.fromImageProvider(
|
return PaletteGenerator.fromImageProvider(
|
||||||
AppIconImage(packageName: packageName, size: 24),
|
AppIconImage(packageName: packageName, size: 24),
|
||||||
).then((palette) async {
|
).then((palette) async {
|
||||||
// `dominantColor` is most representative but can have low contrast with a dark background
|
// `dominantColor` is most representative but can have low contrast with a dark background
|
||||||
// `vibrantColor` is usually representative and has good contrast with a dark background
|
// `vibrantColor` is usually representative and has good contrast with a dark background
|
||||||
final color = palette.vibrantColor?.color ?? (await super.color(context));
|
final color = palette.vibrantColor?.color ?? (await super.color(context));
|
||||||
_appColors[album] = color;
|
_appColors[album] = color;
|
||||||
return color;
|
return color;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
case AlbumType.camera:
|
||||||
|
return SynchronousFuture(AColors.albumCamera);
|
||||||
|
case AlbumType.download:
|
||||||
|
return SynchronousFuture(AColors.albumDownload);
|
||||||
|
case AlbumType.screenRecordings:
|
||||||
|
return SynchronousFuture(AColors.albumScreenRecordings);
|
||||||
|
case AlbumType.screenshots:
|
||||||
|
return SynchronousFuture(AColors.albumScreenshots);
|
||||||
|
case AlbumType.videoCaptures:
|
||||||
|
return SynchronousFuture(AColors.albumVideoCaptures);
|
||||||
}
|
}
|
||||||
return super.color(context);
|
return super.color(context);
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,13 @@ class AColors {
|
||||||
static final raw = stringToColor('Raw');
|
static final raw = stringToColor('Raw');
|
||||||
static final sphericalVideo = stringToColor('360° Video');
|
static final sphericalVideo = stringToColor('360° Video');
|
||||||
|
|
||||||
|
// albums
|
||||||
|
static final albumCamera = stringToColor('Camera');
|
||||||
|
static final albumDownload = stringToColor('Download');
|
||||||
|
static final albumScreenshots = stringToColor('Screenshots');
|
||||||
|
static final albumScreenRecordings = stringToColor('Screen recordings');
|
||||||
|
static final albumVideoCaptures = stringToColor('Video Captures');
|
||||||
|
|
||||||
// info
|
// info
|
||||||
static final xmp = stringToColor('XMP');
|
static final xmp = stringToColor('XMP');
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue