Skip to content

Commit

Permalink
customizer edits
Browse files Browse the repository at this point in the history
  • Loading branch information
frankmer committed Nov 21, 2024
1 parent 49b686a commit b25f95c
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 34 deletions.
6 changes: 3 additions & 3 deletions lib/mains/main_customizer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,13 @@ class CustomizationAuthenticator extends ConsumerWidget {
FeedbackView.routeName: (context) => const FeedbackView(),
ImportTokensView.routeName: (context) => const ImportTokensView(),
LicenseView.routeName: (context) => LicenseView(
appImage: applicationCustomizer.appImage.getWidget,
appImage: applicationCustomizer.licensesViewImage.getWidget,
appName: applicationCustomizer.appName,
websiteLink: applicationCustomizer.websiteLink,
),
MainView.routeName: (context) => MainView(
appIcon: applicationCustomizer.appIcon.getWidget,
appImage: applicationCustomizer.appImage.getWidget,
appIcon: applicationCustomizer.appbarIcon.getWidget,
appImage: applicationCustomizer.splashScreenImage.getWidget,
appName: applicationCustomizer.appName,
disablePatchNotes: applicationCustomizer.disabledFeatures.contains(AppFeature.patchNotes),
),
Expand Down
6 changes: 3 additions & 3 deletions lib/mains/main_netknights.dart
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,13 @@ class PrivacyIDEAAuthenticator extends ConsumerWidget {
FeedbackView.routeName: (context) => const FeedbackView(),
ImportTokensView.routeName: (context) => const ImportTokensView(),
LicenseView.routeName: (context) => LicenseView(
appImage: _customization.appImage.getWidget,
appImage: _customization.licensesViewImage.getWidget,
appName: _customization.appName,
websiteLink: _customization.websiteLink,
),
MainView.routeName: (context) => MainView(
appIcon: _customization.appIcon.getWidget,
appImage: _customization.appImage.getWidget,
appIcon: _customization.appbarIcon.getWidget,
appImage: _customization.splashScreenImage.getWidget,
appName: _customization.appName,
disablePatchNotes: _customization.disabledFeatures.contains(AppFeature.patchNotes),
),
Expand Down
31 changes: 27 additions & 4 deletions lib/model/extensions/enums/image_file_type_extension.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,18 @@ import 'package:image_picker/image_picker.dart';
import '../../enums/image_file_type.dart';

extension ImageFileTypeX on ImageFileType {
static ImageFileType fromExtensionString(String ex) => switch (ex) {
'svg' => ImageFileType.svg,
'svgz' => ImageFileType.svgz,
'png' => ImageFileType.png,
'jpg' => ImageFileType.jpg,
'jpeg' => ImageFileType.jpeg,
'gif' => ImageFileType.gif,
'bmp' => ImageFileType.bmp,
'webp' => ImageFileType.webp,
_ => throw Exception('Unknown extension: $ex'),
};

Widget buildImageWidget(Uint8List imageData) => switch (this) {
ImageFileType.svg => SvgPicture.memory(
imageData,
Expand Down Expand Up @@ -67,9 +79,9 @@ extension ImageFileTypeX on ImageFileType {
),
};

String get fileExtension => toString().split('.').last;
String get extension => toString().split('.').last;

String get fileType => switch (this) {
String get typeName => switch (this) {
ImageFileType.svg => 'Scalable Vector Graphic',
ImageFileType.svgz => 'Scalable Vector Graphic (compressed)',
ImageFileType.png => 'PNG',
Expand All @@ -80,8 +92,19 @@ extension ImageFileTypeX on ImageFileType {
ImageFileType.webp => 'WebP',
};

String get mimeType => switch (this) {
ImageFileType.svg => 'image/svg+xml',
ImageFileType.svgz => 'image/svg+xml',
ImageFileType.png => 'image/png',
ImageFileType.jpg => 'image/jpeg',
ImageFileType.jpeg => 'image/jpeg',
ImageFileType.gif => 'image/gif',
ImageFileType.bmp => 'image/bmp',
ImageFileType.webp => 'image/webp',
};

/// Builds an [XFile] from the given [imageData] and [fileName].
/// The [fileType] is used as the name of the file.
/// The [fileName] is used as the name of the file.
/// The file extension is determined by the [ImageFileType].
XFile buildXFile(Uint8List imageData, String fileName) => XFile.fromData(imageData, name: "$fileName.$fileExtension");
XFile buildXFile(Uint8List imageData, String fileName) => XFile.fromData(imageData, name: "$fileName.$extension");
}
4 changes: 2 additions & 2 deletions lib/model/widget_image.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class WidgetImage {
final Uint8List imageData;
final String fileName;

String get fullFileName => '$fileName.${fileType.fileType}';
String get fullFileName => '$fileName.${fileType.extension}';

WidgetImage({
required this.fileType,
Expand Down Expand Up @@ -77,7 +77,7 @@ class WidgetImage {
try {
return fileType.buildImageWidget(imageData);
} catch (e) {
Logger.error('Image is not an ${fileType.fileType}, or the image data is corrupted.', error: e);
Logger.error('Image is not an ${fileType.typeName}, or the image data is corrupted.', error: e);
rethrow;
}
}
Expand Down
83 changes: 62 additions & 21 deletions lib/utils/customization/application_customization.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,14 @@ class ApplicationCustomization {

final String appName;
final String websiteLink;
final WidgetImage appIcon;

final WidgetImage appImage;
final WidgetImage appbarIcon;
static const String appbarIconFileName = 'appbar_icon';
final WidgetImage splashScreenImage;
static const String splashScreenImageFileName = 'splash_screen_image';
final WidgetImage backgroundImage;
static const String backgroundImageFileName = 'background_image';
final WidgetImage licensesViewImage;
static const String licensesViewImageFileName = 'licenses_view_image';

final ThemeCustomization lightTheme;
final ThemeCustomization darkTheme;
Expand All @@ -77,28 +82,38 @@ class ApplicationCustomization {
this.websiteLink = 'https://netknights.it/',
this.fontFamilyName = _defaultFontName,
this.customFontBytes,
WidgetImage? appIcon,
WidgetImage? appImage,
WidgetImage? appbarIcon,
WidgetImage? splashScreenImage,
WidgetImage? backgroundImage,
WidgetImage? licensesViewImage,
this.lightTheme = ThemeCustomization.defaultLightTheme,
this.darkTheme = ThemeCustomization.defaultDarkTheme,
this.disabledFeatures = const {},
}) : appIcon = appIcon ?? WidgetImage(fileType: ImageFileType.png, imageData: defaultIconUint8List, fileName: 'appIcon'),
appImage = appImage ?? WidgetImage(fileType: ImageFileType.png, imageData: defaultImageUint8List, fileName: 'appImage');
}) : appbarIcon = appbarIcon ?? WidgetImage(fileType: ImageFileType.png, imageData: defaultIconUint8List, fileName: appbarIconFileName),
splashScreenImage =
splashScreenImage ?? WidgetImage(fileType: ImageFileType.png, imageData: defaultImageUint8List, fileName: splashScreenImageFileName),
backgroundImage = backgroundImage ?? WidgetImage(fileType: ImageFileType.png, imageData: defaultImageUint8List, fileName: backgroundImageFileName),
licensesViewImage =
licensesViewImage ?? WidgetImage(fileType: ImageFileType.png, imageData: defaultImageUint8List, fileName: licensesViewImageFileName);

ApplicationCustomization copyWith({
String? appName,
String? websiteLink,
WidgetImage? appIcon,
WidgetImage? appImage,
WidgetImage? appbarIcon,
WidgetImage? splashScreenImage,
WidgetImage? backgroundImage,
WidgetImage? licensesViewImage,
ThemeCustomization? lightTheme,
ThemeCustomization? darkTheme,
Set<AppFeature>? disabledFeatures,
}) =>
ApplicationCustomization(
appName: appName ?? this.appName,
websiteLink: websiteLink ?? this.websiteLink,
appIcon: appIcon ?? this.appIcon,
appImage: appImage ?? this.appImage,
appbarIcon: appbarIcon ?? this.appbarIcon,
splashScreenImage: splashScreenImage ?? this.splashScreenImage,
backgroundImage: backgroundImage ?? this.backgroundImage,
licensesViewImage: licensesViewImage ?? this.licensesViewImage,
lightTheme: lightTheme ?? this.lightTheme,
darkTheme: darkTheme ?? this.darkTheme,
disabledFeatures: disabledFeatures ?? this.disabledFeatures,
Expand All @@ -112,8 +127,10 @@ class ApplicationCustomization {
websiteLink == other.websiteLink &&
customFontBytes == other.customFontBytes &&
fontFamilyName == other.fontFamilyName &&
appIcon == other.appIcon &&
appImage == other.appImage &&
appbarIcon == other.appbarIcon &&
splashScreenImage == other.splashScreenImage &&
backgroundImage == other.backgroundImage &&
licensesViewImage == other.licensesViewImage &&
lightTheme == other.lightTheme &&
darkTheme == other.darkTheme &&
disabledFeatures == other.disabledFeatures;
Expand All @@ -124,8 +141,10 @@ class ApplicationCustomization {
websiteLink,
customFontBytes,
fontFamilyName,
appIcon,
appImage,
appbarIcon,
splashScreenImage,
backgroundImage,
licensesViewImage,
lightTheme,
darkTheme,
disabledFeatures,
Expand All @@ -137,8 +156,10 @@ class ApplicationCustomization {
websiteLink: websiteLink,
customFontBytes: fontBytes,
fontFamilyName: fontName,
appIcon: appIcon,
appImage: appImage,
appbarIcon: appbarIcon,
splashScreenImage: splashScreenImage,
backgroundImage: backgroundImage,
licensesViewImage: licensesViewImage,
lightTheme: lightTheme,
darkTheme: darkTheme,
disabledFeatures: disabledFeatures,
Expand All @@ -163,8 +184,26 @@ class ApplicationCustomization {
websiteLink: json['websiteLink'] as String? ?? 'https://netknights.it/',
customFontBytes: json['customFontBytes'] != null ? base64Decode(json['customFontBytes'] as String) : null,
fontFamilyName: json['fontFamilyName'] as String? ?? _defaultFontName,
appIcon: json['appIcon'] == null ? null : WidgetImage.fromJson(json['appIcon'] as Map<String, dynamic>),
appImage: json['appImage'] == null ? null : WidgetImage.fromJson(json['appImage'] as Map<String, dynamic>),
appbarIcon: json['appbarIcon'] != null
? WidgetImage.fromJson(json['appbarIcon'] as Map<String, dynamic>)
: json['appIcon'] != null
? WidgetImage.fromJson(json['appIcon'] as Map<String, dynamic>)
: null,
splashScreenImage: json['splashScreenImage'] != null
? WidgetImage.fromJson(json['splashScreenImage'] as Map<String, dynamic>)
: json['appImage'] != null
? WidgetImage.fromJson(json['appImage'] as Map<String, dynamic>)
: null,
backgroundImage: json['backgroundImage'] != null
? WidgetImage.fromJson(json['backgroundImage'] as Map<String, dynamic>)
: json['appImage'] != null
? WidgetImage.fromJson(json['appImage'] as Map<String, dynamic>)
: null,
licensesViewImage: json['licensesViewImage'] != null
? WidgetImage.fromJson(json['licensesViewImage'] as Map<String, dynamic>)
: json['appImage'] != null
? WidgetImage.fromJson(json['appImage'] as Map<String, dynamic>)
: null,
lightTheme: json['lightTheme'] != null ? ThemeCustomization.fromJson(json['lightTheme'] as Map<String, dynamic>) : ThemeCustomization.defaultLightTheme,
darkTheme: json['darkTheme'] != null ? ThemeCustomization.fromJson(json['darkTheme'] as Map<String, dynamic>) : ThemeCustomization.defaultDarkTheme,
disabledFeatures:
Expand All @@ -176,8 +215,10 @@ class ApplicationCustomization {
'websiteLink': websiteLink,
'customFontBytes': customFontBytes != null ? base64Encode(customFontBytes!) : null,
'fontFamilyName': fontFamilyName,
'appIcon': appIcon.toJson(),
'appImage': appImage.toJson(),
'appbarIcon': appbarIcon.toJson(),
'splashScreenImage': splashScreenImage.toJson(),
'backgroundImage': backgroundImage.toJson(),
'licensesViewImage': licensesViewImage.toJson(),
'lightTheme': lightTheme.toJson(),
'darkTheme': darkTheme.toJson(),
'disabledFeatures': disabledFeatures.map((e) => e.name).toList(),
Expand Down
2 changes: 1 addition & 1 deletion lib/views/splash_screen/splash_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ class _SplashScreenState extends ConsumerState<SplashScreen> {
child: SizedBox(
height: 99999,
width: 99999,
child: _customization.appImage.getWidget,
child: _customization.splashScreenImage.getWidget,
),
),
),
Expand Down

0 comments on commit b25f95c

Please sign in to comment.