Skip to content

Commit

Permalink
feat: always expanded searchbar option
Browse files Browse the repository at this point in the history
  • Loading branch information
MSOB7YY committed Aug 1, 2024
1 parent ef65992 commit 51f4f6a
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 28 deletions.
5 changes: 5 additions & 0 deletions lib/controller/settings_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ class _SettingsController with SettingsFileWriter {
final artworkGestureDoubleTapLRC = true.obs;
final previousButtonReplays = false.obs;
final refreshOnStartup = false.obs;
final alwaysExpandedSearchbar = false.obs;
final RxList<TagField> tagFieldsToEdit = <TagField>[
TagField.trackNumber,
TagField.year,
Expand Down Expand Up @@ -431,6 +432,7 @@ class _SettingsController with SettingsFileWriter {
artworkGestureDoubleTapLRC.value = json['artworkGestureDoubleTapLRC'] ?? artworkGestureDoubleTapLRC.value;
previousButtonReplays.value = json['previousButtonReplays'] ?? previousButtonReplays.value;
refreshOnStartup.value = json['refreshOnStartup'] ?? refreshOnStartup.value;
alwaysExpandedSearchbar.value = json['alwaysExpandedSearchbar'] ?? alwaysExpandedSearchbar.value;

final tagFieldsToEditStorage = json['tagFieldsToEdit'];
if (tagFieldsToEditStorage is List) {
Expand Down Expand Up @@ -621,6 +623,7 @@ class _SettingsController with SettingsFileWriter {
'artworkGestureDoubleTapLRC': artworkGestureDoubleTapLRC.value,
'previousButtonReplays': previousButtonReplays.value,
'refreshOnStartup': refreshOnStartup.value,
'alwaysExpandedSearchbar': alwaysExpandedSearchbar.value,
'tagFieldsToEdit': tagFieldsToEdit.mapped((element) => element.convertToString),
'wakelockMode': wakelockMode.value.convertToString,
'localVideoMatchingType': localVideoMatchingType.value.convertToString,
Expand Down Expand Up @@ -793,6 +796,7 @@ class _SettingsController with SettingsFileWriter {
bool? artworkGestureDoubleTapLRC,
bool? previousButtonReplays,
bool? refreshOnStartup,
bool? alwaysExpandedSearchbar,
List<TagField>? tagFieldsToEdit,
WakelockMode? wakelockMode,
LocalVideoMatchingType? localVideoMatchingType,
Expand Down Expand Up @@ -1019,6 +1023,7 @@ class _SettingsController with SettingsFileWriter {
if (artworkGestureDoubleTapLRC != null) this.artworkGestureDoubleTapLRC.value = artworkGestureDoubleTapLRC;
if (previousButtonReplays != null) this.previousButtonReplays.value = previousButtonReplays;
if (refreshOnStartup != null) this.refreshOnStartup.value = refreshOnStartup;
if (alwaysExpandedSearchbar != null) this.alwaysExpandedSearchbar.value = alwaysExpandedSearchbar;
if (tagFieldsToEdit != null) {
tagFieldsToEdit.loop((d) {
if (!this.tagFieldsToEdit.contains(d)) {
Expand Down
1 change: 1 addition & 0 deletions lib/core/translations/keys.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ abstract class LanguageKeys {
String get ALL_TIME => _getKey('ALL_TIME');
String get ALWAYS => _getKey('ALWAYS');
String get ALWAYS_ASK => _getKey('ALWAYS_ASK');
String get ALWAYS_EXPANDED_SEARCHBAR => _getKey('ALWAYS_EXPANDED_SEARCHBAR');
String get ALWAYS_RESTORE => _getKey('ALWAYS_RESTORE');
String get ANIMATING_THUMBNAIL_INTENSITY => _getKey('ANIMATING_THUMBNAIL_INTENSITY');
String get ANIMATING_THUMBNAIL_INVERSED_SUBTITLE => _getKey('ANIMATING_THUMBNAIL_INVERSED_SUBTITLE');
Expand Down
62 changes: 35 additions & 27 deletions lib/packages/searchbar_animation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ class SearchBarAnimation extends StatefulWidget {
final double? cursorHeight;
final Radius? cursorRadius;

final bool initiallyAlwaysExpanded;

const SearchBarAnimation({
super.key,
required this.textEditingController,
Expand Down Expand Up @@ -155,19 +157,29 @@ class SearchBarAnimation extends StatefulWidget {
this.onTapOutside,
this.cursorHeight,
this.cursorRadius,
this.initiallyAlwaysExpanded = false,
});

@override
SearchBarAnimationState createState() => SearchBarAnimationState();
}

class SearchBarAnimationState extends State<SearchBarAnimation> with SingleTickerProviderStateMixin {
bool _alwaysExpanded = false;
void setAlwaysExpanded(bool val) {
_alwaysExpanded = val;
}

late AnimationController _animationController;
final FocusNode focusNode = FocusNode();
bool _isAnimationOn = false;
bool switcher = false;
bool get showBgColor => _switcher;
bool _switcher = false;
set switcher(bool val) {
if (_alwaysExpanded) return;
_switcher = val;
}

bool get isOpen => switcher;
bool get isOpen => _switcher;

final DecorationTween decorationTween = DecorationTween(
begin: BoxDecoration(
Expand All @@ -189,17 +201,19 @@ class SearchBarAnimationState extends State<SearchBarAnimation> with SingleTicke

@override
void initState() {
super.initState();
_alwaysExpanded = widget.initiallyAlwaysExpanded;
_switcher = _alwaysExpanded;
_animationController = AnimationController(
vsync: this,
value: _switcher ? 1.0 : 0.0,
duration: Duration(milliseconds: widget.durationInMilliSeconds),
);
super.initState();
}

@override
void dispose() {
_animationController.dispose();
// widget.textEditingController.dispose();
focusNode.dispose();
super.dispose();
}
Expand All @@ -213,15 +227,15 @@ class SearchBarAnimationState extends State<SearchBarAnimation> with SingleTicke
alignment: widget.isSearchBoxOnRightSide ? Alignment.centerRight : Alignment.centerLeft,
child: Container(
decoration: BoxDecoration(
color: _isAnimationOn ? widget.searchBoxColour : _SBColor.transparent,
color: showBgColor ? widget.searchBoxColour : _SBColor.transparent,
border: Border.all(
color: !widget.enableBoxBorder
? _SBColor.transparent
: _isAnimationOn
: showBgColor
? widget.searchBoxBorderColour!
: _SBColor.transparent),
borderRadius: BorderRadius.circular(_SBDimensions.d30),
boxShadow: (!_isAnimationOn)
boxShadow: (!showBgColor)
? null
: ((widget.enableBoxShadow)
? [
Expand All @@ -237,7 +251,7 @@ class SearchBarAnimationState extends State<SearchBarAnimation> with SingleTicke
child: AnimatedContainer(
duration: Duration(milliseconds: widget.durationInMilliSeconds),
height: _SBDimensions.d48,
width: (!switcher) ? _SBDimensions.d48 : (widget.searchBoxWidth ?? MediaQuery.sizeOf(context).width),
width: (!_switcher) ? _SBDimensions.d48 : (widget.searchBoxWidth ?? MediaQuery.sizeOf(context).width),
curve: Curves.easeOut,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(_SBDimensions.d30),
Expand All @@ -251,7 +265,7 @@ class SearchBarAnimationState extends State<SearchBarAnimation> with SingleTicke
right: !widget.isSearchBoxOnRightSide ? _SBDimensions.d6 : null,
curve: Curves.easeOut,
child: AnimatedOpacity(
opacity: (!switcher) ? _SBDimensions.d0 : _SBDimensions.d1,
opacity: (!_switcher) ? _SBDimensions.d0 : _SBDimensions.d1,
duration: const Duration(milliseconds: _SBDimensions.t700),
child: Container(
padding: const EdgeInsets.all(_SBDimensions.d8),
Expand All @@ -264,15 +278,15 @@ class SearchBarAnimationState extends State<SearchBarAnimation> with SingleTicke
),
AnimatedPositioned(
duration: Duration(milliseconds: widget.durationInMilliSeconds),
left: (!switcher)
left: (!_switcher)
? _SBDimensions.d20
: (!widget.textAlignToRight)
? _SBDimensions.d35
: _SBDimensions.d80,
curve: Curves.easeOut,
top: _SBDimensions.d11,
child: AnimatedOpacity(
opacity: (!switcher) ? _SBDimensions.d0 : _SBDimensions.d1,
opacity: (!_switcher) ? _SBDimensions.d0 : _SBDimensions.d1,
duration: const Duration(milliseconds: _SBDimensions.t200),
child: Container(
padding: const EdgeInsets.only(left: _SBDimensions.d10),
Expand All @@ -291,7 +305,7 @@ class SearchBarAnimationState extends State<SearchBarAnimation> with SingleTicke
child: AnimatedSwitcher(
duration: const Duration(milliseconds: _SBDimensions.t200),
child: AnimatedOpacity(
opacity: (!switcher) ? _SBDimensions.d0 : _SBDimensions.d1,
opacity: (!_switcher) ? _SBDimensions.d0 : _SBDimensions.d1,
duration: const Duration(milliseconds: _SBDimensions.t200),
child: widget.buttonWidgetSmall != null ? widget.buttonWidgetSmall! : const SizedBox(),
),
Expand All @@ -306,18 +320,18 @@ class SearchBarAnimationState extends State<SearchBarAnimation> with SingleTicke
child: Container(
decoration: BoxDecoration(
shape: BoxShape.circle,
border: _isAnimationOn ? null : Border.all(color: widget.buttonBorderColour!),
border: showBgColor ? null : Border.all(color: widget.buttonBorderColour!),
),
child: DecoratedBoxTransition(
decoration: decorationTween.animate(_animationController),
child: TapDetector(
onTap: () {
widget.onPressButton?.call(!switcher);
widget.onPressButton?.call(!_switcher);
_onTapFunctionOriginalAnim();
},
child: CircleAvatar(
backgroundColor: widget.buttonColour,
child: switcher ? widget.secondaryButtonWidget : widget.buttonWidget,
child: _switcher ? widget.secondaryButtonWidget : widget.buttonWidget,
),
),
),
Expand All @@ -341,12 +355,12 @@ class SearchBarAnimationState extends State<SearchBarAnimation> with SingleTicke
),
child: TapDetector(
onTap: () {
widget.onPressButton?.call(!switcher);
widget.onPressButton?.call(!_switcher);
_onTapFunction();
},
child: CircleAvatar(
backgroundColor: widget.buttonColour,
child: switcher ? widget.secondaryButtonWidget : widget.buttonWidget,
child: _switcher ? widget.secondaryButtonWidget : widget.buttonWidget,
),
),
),
Expand All @@ -369,18 +383,15 @@ class SearchBarAnimationState extends State<SearchBarAnimation> with SingleTicke

/// This is the tap function for the animation style not for the original animation style.
void _onTapFunction({bool forceOpen = false}) {
_isAnimationOn = true;
setState(
() {
if (forceOpen || !switcher) {
if (forceOpen || !_switcher) {
switcher = true;
if (widget.enableKeyboardFocus) {
FocusScope.of(context).requestFocus(focusNode);
}

_animationController.forward().then((value) {
_isAnimationOn = true;

widget.onExpansionComplete?.call();
});
} else {
Expand All @@ -391,20 +402,18 @@ class SearchBarAnimationState extends State<SearchBarAnimation> with SingleTicke
}

_animationController.reverse().then((value) {
_isAnimationOn = false;
widget.onCollapseComplete?.call();
});
widget.onCollapseComplete?.call();
}
},
);
}

/// This is the tap function for the original animation style.
void _onTapFunctionOriginalAnim({bool forceOpen = false}) {
_isAnimationOn = true;
setState(
() {
if (forceOpen || !switcher) {
if (forceOpen || !_switcher) {
switcher = true;
if (widget.enableKeyboardFocus) {
FocusScope.of(context).requestFocus(focusNode);
Expand All @@ -420,7 +429,6 @@ class SearchBarAnimationState extends State<SearchBarAnimation> with SingleTicke
}

_animationController.reverse().then((value) {
_isAnimationOn = false;
widget.onCollapseComplete?.call();
});
}
Expand Down
1 change: 1 addition & 0 deletions lib/ui/pages/main_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ class NamidaSearchBar extends StatelessWidget {
Widget build(BuildContext context) {
return SearchBarAnimation(
key: searchBarKey,
initiallyAlwaysExpanded: settings.alwaysExpandedSearchbar.value, // TODO:
isSearchBoxOnRightSide: true,
textAlignToRight: false,
durationInMilliSeconds: 300,
Expand Down
23 changes: 23 additions & 0 deletions lib/ui/widgets/settings/extra_settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'package:namida/controller/indexer_controller.dart';
import 'package:namida/controller/miniplayer_controller.dart';
import 'package:namida/controller/namida_channel.dart';
import 'package:namida/controller/navigator_controller.dart';
import 'package:namida/controller/scroll_search_controller.dart';
import 'package:namida/controller/settings_controller.dart';
import 'package:namida/core/constants.dart';
import 'package:namida/core/enums.dart';
Expand All @@ -32,6 +33,7 @@ enum _ExtraSettingsKeys {
lyricsSource,
immersiveMode,
swipeToOpenDrawer,
alwaysExpandedSearchbar,
enableClipboardMonitoring,
extractAllPalettes,
}
Expand All @@ -57,6 +59,7 @@ class ExtrasSettings extends SettingSubpageProvider {
_ExtraSettingsKeys.lyricsSource: [lang.LYRICS_SOURCE],
_ExtraSettingsKeys.immersiveMode: [lang.IMMERSIVE_MODE, lang.IMMERSIVE_MODE_SUBTITLE],
_ExtraSettingsKeys.swipeToOpenDrawer: [lang.SWIPE_TO_OPEN_DRAWER],
_ExtraSettingsKeys.alwaysExpandedSearchbar: [lang.ALWAYS_EXPANDED_SEARCHBAR],
_ExtraSettingsKeys.enableClipboardMonitoring: [lang.ENABLE_CLIPBOARD_MONITORING, lang.ENABLE_CLIPBOARD_MONITORING_SUBTITLE],
_ExtraSettingsKeys.extractAllPalettes: [lang.EXTRACT_ALL_COLOR_PALETTES],
};
Expand Down Expand Up @@ -375,6 +378,26 @@ class ExtrasSettings extends SettingSubpageProvider {
),
),
),
getItemWrapper(
key: _ExtraSettingsKeys.alwaysExpandedSearchbar,
child: Obx(
() => CustomSwitchListTile(
bgColor: getBgColor(_ExtraSettingsKeys.alwaysExpandedSearchbar),
// icon: Broken.scroll,
leading: const StackedIcon(
baseIcon: Broken.scroll,
secondaryIcon: Broken.search_normal,
secondaryIconSize: 12.0,
),
title: lang.ALWAYS_EXPANDED_SEARCHBAR,
value: settings.alwaysExpandedSearchbar.valueR,
onChanged: (isTrue) {
settings.save(alwaysExpandedSearchbar: !isTrue);
ScrollSearchController.inst.searchBarKey.currentState?.setAlwaysExpanded(!isTrue);
},
),
),
),
getItemWrapper(
key: _ExtraSettingsKeys.enableClipboardMonitoring,
child: Obx(
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: namida
description: A Beautiful and Feature-rich Music Player, With YouTube & Video Support Built in Flutter
publish_to: "none"
version: 3.7.55-beta+240801001
version: 3.7.6-beta+240801004

environment:
sdk: ">=3.4.0 <4.0.0"
Expand Down

0 comments on commit 51f4f6a

Please sign in to comment.