From d5a59d67c7b21fbd4e2093795b060382bce6cd96 Mon Sep 17 00:00:00 2001 From: DattatreyaReddy Panta <58727124+DattatreyaReddy@users.noreply.github.com> Date: Wed, 17 Jan 2024 03:19:31 +0530 Subject: [PATCH] added quick search toggle --- lib/src/constants/db_keys.dart | 1 + .../quick_search/quick_search_screen.dart | 2 ++ .../search_stack/search_stack_screen.dart | 8 +++-- .../presentation/general/general_screen.dart | 2 ++ .../quick_search_toggle_tile.dart | 36 +++++++++++++++++++ .../quick_search_toggle_tile.g.dart | 26 ++++++++++++++ .../reader_invert_tap_tile.g.dart | 25 +++++++++++++ lib/src/l10n/app_en.arb | 4 +++ 8 files changed, 102 insertions(+), 2 deletions(-) create mode 100644 lib/src/features/settings/presentation/general/quick_search_toggle/quick_search_toggle_tile.dart create mode 100644 lib/src/features/settings/presentation/general/quick_search_toggle/quick_search_toggle_tile.g.dart create mode 100644 lib/src/features/settings/presentation/general/quick_search_toggle/reader_invert_tap_tile.g.dart diff --git a/lib/src/constants/db_keys.dart b/lib/src/constants/db_keys.dart index 0e3e06f1..282702ea 100644 --- a/lib/src/constants/db_keys.dart +++ b/lib/src/constants/db_keys.dart @@ -25,6 +25,7 @@ enum DBKeys { readerMagnifierSize(1.0), readerNavigationLayout(ReaderNavigationLayout.disabled), invertTap(false), + quickSearchToggle(true), swipeToggle(true), scrollAnimation(true), showNSFW(true), diff --git a/lib/src/features/quick_open/presentation/quick_search/quick_search_screen.dart b/lib/src/features/quick_open/presentation/quick_search/quick_search_screen.dart index fd5fe1f9..207ac813 100644 --- a/lib/src/features/quick_open/presentation/quick_search/quick_search_screen.dart +++ b/lib/src/features/quick_open/presentation/quick_search/quick_search_screen.dart @@ -6,6 +6,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_hooks/flutter_hooks.dart'; +import 'package:gap/gap.dart'; import '../../../../utils/extensions/custom_extensions.dart'; import 'widgets/quick_query_result.dart'; @@ -38,6 +39,7 @@ class QuickSearchScreen extends HookWidget { child: Column( mainAxisSize: MainAxisSize.min, children: [ + const Gap(32), QuickSearchBar(controller: controller), Flexible( child: QuickQueryResult( diff --git a/lib/src/features/quick_open/presentation/search_stack/search_stack_screen.dart b/lib/src/features/quick_open/presentation/search_stack/search_stack_screen.dart index e197540d..10043843 100644 --- a/lib/src/features/quick_open/presentation/search_stack/search_stack_screen.dart +++ b/lib/src/features/quick_open/presentation/search_stack/search_stack_screen.dart @@ -11,20 +11,24 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_hooks/flutter_hooks.dart'; +import 'package:hooks_riverpod/hooks_riverpod.dart'; import '../../../../utils/extensions/custom_extensions.dart'; +import '../../../settings/presentation/general/quick_search_toggle/quick_search_toggle_tile.dart'; import '../quick_search/quick_search_screen.dart'; class ShowQuickOpenIntent extends Intent {} class HideQuickOpenIntent extends Intent {} -class SearchStackScreen extends HookWidget { +class SearchStackScreen extends HookConsumerWidget { const SearchStackScreen({super.key, this.child}); final Widget? child; @override - Widget build(BuildContext context) { + Widget build(context, ref) { final visible = useState(false); + final isQuickSearchEnabled = ref.watch(quickSearchToggleProvider).ifNull(); + if (!isQuickSearchEnabled) return child!; return QuickSearchShortcutWrapper( visible: visible, child: Stack( diff --git a/lib/src/features/settings/presentation/general/general_screen.dart b/lib/src/features/settings/presentation/general/general_screen.dart index ec5fff05..4f2d46bd 100644 --- a/lib/src/features/settings/presentation/general/general_screen.dart +++ b/lib/src/features/settings/presentation/general/general_screen.dart @@ -14,6 +14,7 @@ import '../../../../global_providers/global_providers.dart'; import '../../../../utils/extensions/custom_extensions.dart'; import '../../../../utils/misc/toast/toast.dart'; import '../../../../widgets/radio_list_popup.dart'; +import 'quick_search_toggle/quick_search_toggle_tile.dart'; class GeneralScreen extends ConsumerWidget { const GeneralScreen({super.key}); @@ -56,6 +57,7 @@ class GeneralScreen extends ConsumerWidget { } }, ), + const QuickSearchToggleTile(), ], ), ); diff --git a/lib/src/features/settings/presentation/general/quick_search_toggle/quick_search_toggle_tile.dart b/lib/src/features/settings/presentation/general/quick_search_toggle/quick_search_toggle_tile.dart new file mode 100644 index 00000000..e1c76583 --- /dev/null +++ b/lib/src/features/settings/presentation/general/quick_search_toggle/quick_search_toggle_tile.dart @@ -0,0 +1,36 @@ +// Copyright (c) 2022 Contributors to the Suwayomi project +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +import 'package:flutter/material.dart'; +import 'package:hooks_riverpod/hooks_riverpod.dart'; +import 'package:riverpod_annotation/riverpod_annotation.dart'; + +import '../../../../../constants/db_keys.dart'; +import '../../../../../utils/extensions/custom_extensions.dart'; +import '../../../../../utils/mixin/shared_preferences_client_mixin.dart'; + +part 'quick_search_toggle_tile.g.dart'; + +@riverpod +class QuickSearchToggle extends _$QuickSearchToggle + with SharedPreferenceClientMixin { + @override + bool? build() => initialize(DBKeys.quickSearchToggle); +} + +class QuickSearchToggleTile extends HookConsumerWidget { + const QuickSearchToggleTile({super.key}); + @override + Widget build(BuildContext context, WidgetRef ref) { + return SwitchListTile( + controlAffinity: ListTileControlAffinity.trailing, + secondary: const Icon(Icons.search_rounded), + title: Text(context.l10n!.quickSearch), + onChanged: ref.read(quickSearchToggleProvider.notifier).update, + value: ref.watch(quickSearchToggleProvider).ifNull(), + ); + } +} diff --git a/lib/src/features/settings/presentation/general/quick_search_toggle/quick_search_toggle_tile.g.dart b/lib/src/features/settings/presentation/general/quick_search_toggle/quick_search_toggle_tile.g.dart new file mode 100644 index 00000000..cb067edb --- /dev/null +++ b/lib/src/features/settings/presentation/general/quick_search_toggle/quick_search_toggle_tile.g.dart @@ -0,0 +1,26 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'quick_search_toggle_tile.dart'; + +// ************************************************************************** +// RiverpodGenerator +// ************************************************************************** + +String _$quickSearchToggleHash() => r'1805371cc00c16e3156bc431adf9e5e1cb604f10'; + +/// See also [QuickSearchToggle]. +@ProviderFor(QuickSearchToggle) +final quickSearchToggleProvider = + AutoDisposeNotifierProvider.internal( + QuickSearchToggle.new, + name: r'quickSearchToggleProvider', + debugGetCreateSourceHash: const bool.fromEnvironment('dart.vm.product') + ? null + : _$quickSearchToggleHash, + dependencies: null, + allTransitiveDependencies: null, +); + +typedef _$QuickSearchToggle = AutoDisposeNotifier; +// ignore_for_file: type=lint +// ignore_for_file: subtype_of_sealed_class, invalid_use_of_internal_member, invalid_use_of_visible_for_testing_member diff --git a/lib/src/features/settings/presentation/general/quick_search_toggle/reader_invert_tap_tile.g.dart b/lib/src/features/settings/presentation/general/quick_search_toggle/reader_invert_tap_tile.g.dart new file mode 100644 index 00000000..ba1770a3 --- /dev/null +++ b/lib/src/features/settings/presentation/general/quick_search_toggle/reader_invert_tap_tile.g.dart @@ -0,0 +1,25 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'reader_invert_tap_tile.dart'; + +// ************************************************************************** +// RiverpodGenerator +// ************************************************************************** + +String _$invertTapHash() => r'c4bde6eb87d0f7ede8eff109d63056af85a2fdc7'; + +/// See also [InvertTap]. +@ProviderFor(InvertTap) +final invertTapProvider = + AutoDisposeNotifierProvider.internal( + InvertTap.new, + name: r'invertTapProvider', + debugGetCreateSourceHash: + const bool.fromEnvironment('dart.vm.product') ? null : _$invertTapHash, + dependencies: null, + allTransitiveDependencies: null, +); + +typedef _$InvertTap = AutoDisposeNotifier; +// ignore_for_file: type=lint +// ignore_for_file: subtype_of_sealed_class, invalid_use_of_internal_member, invalid_use_of_visible_for_testing_member diff --git a/lib/src/l10n/app_en.arb b/lib/src/l10n/app_en.arb index 1af077d3..681db081 100644 --- a/lib/src/l10n/app_en.arb +++ b/lib/src/l10n/app_en.arb @@ -421,6 +421,9 @@ "@previousChapter": { "description": "Text for Previous Chapter button in Manga Reader Screen" }, + "@quickSearch": { + "description": "Screen title and Button text of Quick Search screen" + }, "@quickSearchCategory": { "description": "Quick Open Hint text for Category C with prefill '#C'" }, @@ -823,6 +826,7 @@ "pending": "Pending", "pinchToZoom": "Pinch to Zoom", "previousChapter": "Previous: {chapterTitle}", + "quickSearch": "Quick Search", "quickSearchCategory": "Go to Category 'C'", "quickSearchCategoryManga": "Go to Manga 'M' in Category 'C'", "quickSearchCategoryMangaChapter": "Go to Chapter Name 'CN' from Manga 'M' in Category 'C'",