Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

4.4.3 #427

Merged
merged 5 commits into from
Nov 26, 2024
Merged

4.4.3 #427

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/mains/main_customizer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,12 @@ 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,
appIcon: applicationCustomizer.appbarIcon.getWidget,
appName: applicationCustomizer.appName,
disablePatchNotes: applicationCustomizer.disabledFeatures.contains(AppFeature.patchNotes),
),
Expand Down
4 changes: 2 additions & 2 deletions lib/mains/main_netknights.dart
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,12 @@ 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,
appIcon: _customization.appbarIcon.getWidget,
appName: _customization.appName,
disablePatchNotes: _customization.disabledFeatures.contains(AppFeature.patchNotes),
),
Expand Down
42 changes: 42 additions & 0 deletions lib/model/extensions/enums/image_file_type_extension.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,23 @@ import 'dart:typed_data';

import 'package:flutter/material.dart';
import 'package:flutter_svg/svg.dart';
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 @@ -65,4 +78,33 @@ extension ImageFileTypeX on ImageFileType {
colorBlendMode: BlendMode.srcOver,
),
};

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

String get typeName => switch (this) {
ImageFileType.svg => 'Scalable Vector Graphic',
ImageFileType.svgz => 'Scalable Vector Graphic (compressed)',
ImageFileType.png => 'PNG',
ImageFileType.jpg => 'JPEG',
ImageFileType.jpeg => 'JPEG',
ImageFileType.gif => 'GIF',
ImageFileType.bmp => 'Bitmap',
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 [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.$extension");
}
23 changes: 21 additions & 2 deletions lib/model/widget_image.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@
import 'dart:convert';
import 'dart:typed_data';

import 'package:file_selector/file_selector.dart';
import 'package:flutter/material.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:privacyidea_authenticator/model/extensions/enums/image_file_type_extension.dart';

import '../../../../../../../model/extensions/enums/image_file_type_extension.dart';
import '../utils/logger.dart';
import 'enums/image_file_type.dart';

Expand All @@ -45,12 +46,26 @@ class Uint8ListConverter implements JsonConverter<Uint8List, String> {
class WidgetImage {
final ImageFileType fileType;
final Uint8List imageData;
final String fileName;

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

WidgetImage({
required this.fileType,
required this.imageData,
required this.fileName,
});

@override
String toString() {
return 'WidgetImage{fileType: $fileType, imageData: $imageData}';
}

@override
bool operator ==(Object other) => other is WidgetImage && other.fileType == fileType && other.imageData == imageData;
@override
int get hashCode => Object.hash(runtimeType, fileType, imageData);

Widget? _widget;
Widget get getWidget {
if (_widget != null) return _widget!;
Expand All @@ -62,11 +77,15 @@ class WidgetImage {
try {
return fileType.buildImageWidget(imageData);
} catch (e) {
Logger.error('File type $fileType is not supported or does not match the image data.', name: 'WidgetImage#_buildImageWidget');
Logger.error('Image is not an ${fileType.typeName}, or the image data is corrupted.', error: e);
rethrow;
}
}

factory WidgetImage.fromJson(Map<String, dynamic> json) => _$WidgetImageFromJson(json);
Map<String, dynamic> toJson() => _$WidgetImageToJson(this);

XFile? toXFile() {
return fileType.buildXFile(imageData, fileName);
}
}
2 changes: 2 additions & 0 deletions lib/model/widget_image.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions lib/state_notifiers/token_notifier.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:http/http.dart';
import 'package:mutex/mutex.dart';
import 'package:pointycastle/asymmetric/api.dart';
import '../model/enums/token_import_type.dart';

import '../interfaces/repo/token_repository.dart';
import '../l10n/app_localizations.dart';
import '../model/enums/push_token_rollout_state.dart';
import '../model/enums/token_import_type.dart';
import '../model/enums/token_origin_source_type.dart';
import '../model/extensions/enums/push_token_rollout_state_extension.dart';
import '../model/extensions/enums/token_origin_source_type.dart';
Expand Down Expand Up @@ -375,7 +375,7 @@ class TokenNotifier extends StateNotifier<TokenState> {
hideLockedTokens.add(token);
}
}
return await updateTokens(hideLockedTokens, (p0) => p0.copyWith(isHidden: true));
return await _updateTokens(hideLockedTokens, (p0) => p0.copyWith(isHidden: true));
}

Future<void> removeToken(Token token) async {
Expand Down
Loading
Loading