Skip to content

Commit

Permalink
fixed filtered main view tokens list
Browse files Browse the repository at this point in the history
  • Loading branch information
frankmer committed Oct 14, 2024
1 parent f7745e4 commit 0e9785f
Show file tree
Hide file tree
Showing 18 changed files with 244 additions and 177 deletions.
2 changes: 1 addition & 1 deletion lib/model/riverpod_states/token_container_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class TokenContainerState with _$TokenContainerState {
required List<TokenContainer> containerList,
}) = _TokenContainerState;

bool get hasFinalizedContainers => containerList.every((container) => container is TokenContainerFinalized);
bool get hasFinalizedContainers => containerList.any((container) => container is TokenContainerFinalized);

TokenContainer? containerOf(String containerSerial) => containerList.firstWhereOrNull((container) => container.serial == containerSerial);
static TokenContainerState fromJsonStringList(List<String> jsonStrings) {
Expand Down
27 changes: 27 additions & 0 deletions lib/model/riverpod_states/token_filter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import 'package:privacyidea_authenticator/model/mixins/sortable_mixin.dart';
import 'package:privacyidea_authenticator/model/token_folder.dart';

import '../tokens/push_token.dart';
import '../tokens/token.dart';

Expand All @@ -38,4 +41,28 @@ class TokenFilter {
}
return filteredTokens;
}

List<SortableMixin> filterSortables(List<SortableMixin> sortables) {
final filteredSortables = <SortableMixin>[];
final RegExp regExp;
try {
regExp = RegExp(searchQuery, caseSensitive: false);
} catch (e) {
return [];
}
for (final sortable in sortables) {
if (sortable is TokenFolder) {
filteredSortables.add(sortable);
continue;
}
if (sortable is Token &&
(regExp.hasMatch(sortable.label) ||
regExp.hasMatch(sortable.issuer) ||
sortable is PushToken && regExp.hasMatch(sortable.serial) ||
regExp.hasMatch(sortable.type))) {
filteredSortables.add(sortable);
}
}
return filteredSortables;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import 'dart:convert';
import 'dart:typed_data';

import 'package:file_selector/file_selector.dart';
import 'package:privacyidea_authenticator/model/extensions/enums/encodings_extension.dart';
import 'package:privacyidea_authenticator/model/enums/encodings.dart';
import 'package:privacyidea_authenticator/model/extensions/enums/encodings_extension.dart';

import '../../l10n/app_localizations.dart';
import '../../model/enums/token_origin_source_type.dart';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import '../../../../utils/riverpod/riverpod_providers/generated_providers/token_
import '../../../../widgets/dialog_widgets/default_dialog.dart';
import '../../../../widgets/elevated_delete_button.dart';
import '../../../main_view/main_view_widgets/token_widgets/slideable_action.dart';
import '../../../view_interface.dart';

class DeleteContainerAction extends ConsumerSlideableAction {
final TokenContainer container;
Expand Down
18 changes: 8 additions & 10 deletions lib/views/main_view/main_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ import '../view_interface.dart';
import 'main_view_widgets/app_bar_item.dart';
import 'main_view_widgets/connectivity_listener.dart';
import 'main_view_widgets/expandable_appbar.dart';
import 'main_view_widgets/main_view_background_image.dart';
import 'main_view_widgets/main_view_navigation_bar.dart';
import 'main_view_widgets/main_view_tokens_list.dart';
import 'main_view_widgets/main_view_tokens_list_filtered.dart';
import 'main_view_widgets/main_view_background_image.dart';

export '../../views/main_view/main_view.dart';

Expand Down Expand Up @@ -117,15 +117,13 @@ class _MainViewState extends ConsumerState<MainView> {
]),
body: ConnectivityListener(
child: StatusBar(
child: !hasFilter
? Stack(
children: [
MainViewBackgroundImage(appImage: widget.appImage),
MainViewTokensList(nestedScrollViewKey: globalKey),
MainViewNavigationBar(),
],
)
: const MainViewTokensListFiltered(),
child: Stack(
children: [
MainViewBackgroundImage(appImage: widget.appImage),
hasFilter ? const MainViewTokensListFiltered() : MainViewTokensList(nestedScrollViewKey: globalKey),
if (!hasFilter) MainViewNavigationBar(),
],
),
),
),
),
Expand Down
24 changes: 12 additions & 12 deletions lib/views/main_view/main_view_widgets/drag_target_divider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,20 @@ class DragTargetDivider<T extends SortableMixin> extends ConsumerStatefulWidget
final SortableMixin? nextSortable;
final double dividerBaseHeight;
final double dividerExpandedHeight;
final double bottomPaddingIfLast;
final double bottomPadding;
final double opacity;
final bool isExpandalbe;
final bool isLastDivider;

const DragTargetDivider({
super.key,
required this.dependingFolder,
required this.previousSortable,
required this.nextSortable,
this.bottomPaddingIfLast = 0,
this.bottomPadding = 0,
this.dividerBaseHeight = 1.5,
this.dividerExpandedHeight = 40,
this.opacity = 1,
this.isExpandalbe = true,
this.isLastDivider = false,
});

@override
Expand Down Expand Up @@ -105,7 +103,7 @@ class _DragTargetDividerState<T extends SortableMixin> extends ConsumerState<Dra
return DefaultDivider(
dividerHeight: dividerHeight,
opacity: widget.opacity,
padding: EdgeInsets.only(bottom: widget.isLastDivider ? max(widget.bottomPaddingIfLast - dividerHeight + widget.dividerBaseHeight, 0) : 0),
padding: EdgeInsets.only(bottom: max(widget.bottomPadding - dividerHeight + widget.dividerBaseHeight, 0.0)),
margin: EdgeInsets.symmetric(horizontal: 8 - expansionController.value * 2, vertical: 8),
);
},
Expand Down Expand Up @@ -134,14 +132,16 @@ class DefaultDivider extends StatelessWidget {
@override
Widget build(BuildContext context) => Opacity(
opacity: opacity,
child: Container(
height: dividerHeight,
decoration: BoxDecoration(
color: Theme.of(context).dividerColor,
borderRadius: BorderRadius.circular(dividerHeight / 4),
child: Padding(
padding: padding ?? EdgeInsets.zero,
child: Container(
height: dividerHeight,
decoration: BoxDecoration(
color: Theme.of(context).dividerColor,
borderRadius: BorderRadius.circular(dividerHeight / 4),
),
margin: margin,
),
padding: padding,
margin: margin,
),
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,26 @@
import 'package:expandable/expandable.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:privacyidea_authenticator/model/extensions/token_folder_extension.dart';
import 'package:privacyidea_authenticator/model/tokens/token.dart';

import '../../../../model/riverpod_states/token_filter.dart';
import '../../../../model/token_folder.dart';
import '../../../../model/tokens/push_token.dart';
import '../../../../utils/globals.dart';
import '../../../../utils/riverpod/riverpod_providers/generated_providers/settings_notifier.dart';
import '../../../../utils/riverpod/riverpod_providers/generated_providers/token_folder_notifier.dart';
import '../../../../utils/riverpod/riverpod_providers/generated_providers/token_notifier.dart';
import '../../../../utils/riverpod/riverpod_providers/state_providers/dragging_sortable_provider.dart';
import 'token_folder_expandable_widgets/token_folder_expandable_header.dart';
import 'token_folder_expandable_widgets/token_folder_expandable_body.dart';

class TokenFolderExpandable extends ConsumerStatefulWidget {
final TokenFolder folder;
final List<Token> folderTokens;
final TokenFilter? filter;
final bool? expandOverride;

const TokenFolderExpandable({
super.key,
required this.folder,
required this.folderTokens,
this.filter,
this.expandOverride,
});
Expand Down Expand Up @@ -87,10 +86,7 @@ class _TokenFolderExpandableState extends ConsumerState<TokenFolderExpandable> w

@override
Widget build(BuildContext context) {
final hidePushTokens = ref.watch(hidePushTokensProvider);
final folderTokens = ref.watch(tokenProvider.select((state) => state.tokensInFolder(widget.folder).whereNotType(hidePushTokens ? [PushToken] : [])));
final tokensFiltered = widget.filter?.filterTokens(folderTokens) ?? folderTokens;
if (tokensFiltered.isEmpty) return const SizedBox();
final tokensFiltered = widget.folderTokens;
tokensFiltered.sort((a, b) => a.compareTo(b));
final draggingSortable = ref.watch(draggingSortableProvider);
if (widget.expandOverride == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class TokenFolderExpandableBody extends StatelessWidget {
previousSortable: (i - 1) < 0 ? null : tokens[i - 1],
nextSortable: tokens[i],
),
TokenWidgetBuilder.fromToken(tokens[i]),
TokenWidgetBuilder.fromToken(token: tokens[i]),
],
if (tokens.isNotEmpty && draggingSortable is Token)
isFilterd
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,25 @@ import 'dart:math';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';

import '../../../../model/riverpod_states/token_filter.dart';
import '../../../../model/token_folder.dart';
import '../../../../model/tokens/token.dart';
import '../../../../utils/logger.dart';
import '../../../../utils/riverpod/riverpod_providers/state_providers/dragging_sortable_provider.dart';
import '../../../../utils/utils.dart';
import 'token_folder_expandable.dart';

class TokenFolderWidget extends ConsumerWidget {
final TokenFolder folder;
final List<Token> folderTokens;
final TokenFilter? filter;

const TokenFolderWidget(this.folder, {super.key});
const TokenFolderWidget({
required this.folder,
required this.folderTokens,
this.filter,
super.key,
});

@override
Widget build(BuildContext context, WidgetRef ref) {
Expand Down Expand Up @@ -80,12 +89,17 @@ class TokenFolderWidget extends ConsumerWidget {
padding: const EdgeInsets.only(top: 4),
child: TokenFolderExpandable(
folder: folder,
folderTokens: folderTokens,
key: Key('TokenFolderExpandable#${folder.folderId}'),
),
),
)
: (draggingFolder == folder)
? const SizedBox()
: TokenFolderExpandable(folder: folder);
: TokenFolderExpandable(
folder: folder,
folderTokens: folderTokens,
filter: filter,
);
}
}
Loading

0 comments on commit 0e9785f

Please sign in to comment.