Skip to content

Commit

Permalink
Add export color customization and refactor container dialog handling
Browse files Browse the repository at this point in the history
  • Loading branch information
frankmer committed Nov 11, 2024
1 parent 35bfc39 commit cffe36b
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 18 deletions.
2 changes: 2 additions & 0 deletions lib/utils/customization/theme_customization.dart
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ class ThemeCustomization {
deleteColor: json['deleteColor'] != null ? Color(json['deleteColor'] as int) : null,
renameColor: json['renameColor'] != null ? Color(json['renameColor'] as int) : null,
lockColor: json['lockColor'] != null ? Color(json['lockColor'] as int) : null,
exportColor: json['exportColor'] != null ? Color(json['exportColor'] as int) : null,
tileIconColor: json['tileIconColor'] != null ? Color(json['tileIconColor'] as int) : null,
navigationBarColor: json['navigationBarColor'] != null ? Color(json['navigationBarColor'] as int) : null,
pushAuthRequestAcceptColor: json['_pushAuthRequestAcceptColor'] != null ? Color(json['_pushAuthRequestAcceptColor'] as int) : null,
Expand All @@ -281,6 +282,7 @@ class ThemeCustomization {
deleteColor: json['deleteColor'] != null ? Color(json['deleteColor'] as int) : null,
renameColor: json['renameColor'] != null ? Color(json['renameColor'] as int) : null,
lockColor: json['lockColor'] != null ? Color(json['lockColor'] as int) : null,
exportColor: json['exportColor'] != null ? Color(json['exportColor'] as int) : null,
tileIconColor: json['tileIconColor'] != null ? Color(json['tileIconColor'] as int) : null,
navigationBarColor: json['navigationBarColor'] != null ? Color(json['navigationBarColor'] as int) : null,
pushAuthRequestAcceptColor: json['_pushAuthRequestAcceptColor'] != null ? Color(json['_pushAuthRequestAcceptColor'] as int) : null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,17 +347,17 @@ class TokenContainerNotifier extends _$TokenContainerNotifier with ResultHandler
@override
Future handleProcessorResults(List<ProcessorResult> results, Map<String, dynamic> args) async {
Logger.info('Handling processor results');
final unfinalizedContainers = results.getData().whereType<TokenContainerUnfinalized>().toList();
if (unfinalizedContainers.isEmpty) return null;
final newContainers = results.getData().whereType<TokenContainerUnfinalized>().toList();
if (newContainers.isEmpty) return null;
final currentState = await future;
final stateContainers = currentState.containerList;
final stateContainersSerials = stateContainers.map((e) => e.serial);
List<TokenContainerUnfinalized> newContainerList = unfinalizedContainers.where((element) => !stateContainersSerials.contains(element.serial)).toList();
final existingContainers = unfinalizedContainers.where((element) => stateContainersSerials.contains(element.serial)).toList();
List<TokenContainerUnfinalized> newContainerList = newContainers.where((element) => !stateContainersSerials.contains(element.serial)).toList();
final existingContainers = newContainers.where((element) => stateContainersSerials.contains(element.serial)).toList();
Logger.info('Handling processor results: adding Container');
final replaceContainers = <TokenContainerUnfinalized>[];
if (existingContainers.isNotEmpty) {
replaceContainers.addAll(await _showContainerAlreadyExistsDialog(existingContainers) ?? []);
replaceContainers.addAll(await ContainerAlreadyExistsDialog.showDialog(existingContainers) ?? []);
}

if (replaceContainers.isNotEmpty) {
Expand Down Expand Up @@ -460,10 +460,6 @@ class TokenContainerNotifier extends _$TokenContainerNotifier with ResultHandler
showAsyncDialog(builder: (context) => AddContainerProgressDialog(serials), barrierDismissible: false);
}

Future<List<T>?> _showContainerAlreadyExistsDialog<T extends TokenContainer>(List<T> containers) {
return showAsyncDialog<List<T>>(builder: (context) => ContainerAlreadyExistsDialog(containers), barrierDismissible: false);
}

/// Finalization substep 1: Generate key pair
Future<TokenContainerUnfinalized> _generateKeyPair(TokenContainerUnfinalized tokenContainer) async {
// generatingKeyPair,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:privacyidea_authenticator/utils/riverpod/riverpod_providers/generated_providers/token_notifier.dart';
import 'package:privacyidea_authenticator/widgets/elevated_delete_button.dart';

import '../../../../../../../model/token_container.dart';
import '../../../../../../../utils/view_utils.dart';
Expand Down Expand Up @@ -184,9 +185,9 @@ class _DeleteContainerAfterTransferDialogState extends ConsumerState<DeleteConta
onPressed: () => Navigator.of(context).pop(),
child: Text('Cancel'),
),
ElevatedButton(
ElevatedDeleteButton(
text: 'Remove from this device',
onPressed: () => onConfirm(context),
child: Text('Remove from this device'),
),
],
),
Expand Down
18 changes: 11 additions & 7 deletions lib/widgets/dialog_widgets/container_already_exists_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:privacyidea_authenticator/utils/view_utils.dart';

import '../../../../../../../l10n/app_localizations.dart';
import '../../../../../../../model/token_container.dart';
Expand All @@ -29,21 +30,24 @@ import '../../../../../../../widgets/dialog_widgets/default_dialog.dart';
import '../../utils/riverpod/riverpod_providers/generated_providers/token_container_notifier.dart';

class ContainerAlreadyExistsDialog extends ConsumerStatefulWidget {
final List<TokenContainer> containers;
final List<TokenContainerUnfinalized> newContainers;

const ContainerAlreadyExistsDialog(this.containers, {super.key});
static Future<List<TokenContainerUnfinalized>?> showDialog(List<TokenContainerUnfinalized> newContainers) =>
showAsyncDialog(builder: (context) => ContainerAlreadyExistsDialog(newContainers));

const ContainerAlreadyExistsDialog(this.newContainers, {super.key});

@override
ConsumerState<ContainerAlreadyExistsDialog> createState() => _ContainerAlreadyExistsDialogState();
}

class _ContainerAlreadyExistsDialogState extends ConsumerState<ContainerAlreadyExistsDialog> {
late final List<TokenContainer> unhandledContainers;
final List<TokenContainer> replaceContainers = [];
late final List<TokenContainerUnfinalized> unhandledContainers;
final List<TokenContainerUnfinalized> replaceContainers = [];

@override
void initState() {
unhandledContainers = widget.containers;
unhandledContainers = widget.newContainers;
super.initState();
}

Expand Down Expand Up @@ -75,9 +79,9 @@ class _ContainerAlreadyExistsDialogState extends ConsumerState<ContainerAlreadyE
if (unhandledContainers.isEmpty) Navigator.of(context).pop(replaceContainers);
}

Future<void> _replace(TokenContainer oldContainer, TokenContainer newContainer) async {
Future<void> _replace(TokenContainer oldContainer, TokenContainerUnfinalized newContainer) async {
setState(() {
unhandledContainers.remove(newContainer);
unhandledContainers.remove(oldContainer);
replaceContainers.add(newContainer);
});
if (unhandledContainers.isEmpty && mounted) Navigator.of(context).pop(replaceContainers);
Expand Down

0 comments on commit cffe36b

Please sign in to comment.