Skip to content

Commit

Permalink
chore: equalizer toggle tap to update button
Browse files Browse the repository at this point in the history
  • Loading branch information
MSOB7YY committed Feb 13, 2024
1 parent 47bc407 commit 3aa0956
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 6 deletions.
14 changes: 11 additions & 3 deletions lib/controller/equalizer_settings.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'package:get/get_rx/src/rx_types/rx_types.dart';

import 'package:namida/base/settings_file_writer.dart';
import 'package:namida/core/constants.dart';
import 'package:namida/core/extensions.dart';
Expand All @@ -12,19 +14,23 @@ class EqualizerSettings with SettingsFileWriter {
bool loudnessEnhancerEnabled = false;
double loudnessEnhancer = 0.0;

final uiTapToUpdate = true.obs;

void save({
int? preset,
bool resetPreset = false,
bool? equalizerEnabled,
MapEntry<double, double>? equalizerValue,
bool? loudnessEnhancerEnabled,
double? loudnessEnhancer,
bool? uiTapToUpdate,
}) {
if (preset != null || resetPreset) this.preset = preset;
if (equalizerEnabled != null) this.equalizerEnabled = equalizerEnabled;
if (equalizerValue != null) equalizer[equalizerValue.key] = equalizerValue.value;
if (loudnessEnhancerEnabled != null) this.loudnessEnhancerEnabled = loudnessEnhancerEnabled;
if (loudnessEnhancer != null) this.loudnessEnhancer = loudnessEnhancer;
if (uiTapToUpdate != null) this.uiTapToUpdate.value = uiTapToUpdate;
_writeToStorage();
}

Expand All @@ -33,15 +39,16 @@ class EqualizerSettings with SettingsFileWriter {
if (json == null) return;
try {
preset = json["preset"];
equalizerEnabled = json["equalizerEnabled"] ?? false;
equalizerEnabled = json["equalizerEnabled"] ?? equalizerEnabled;
final eqMap = json['equalizer'];
if (eqMap is Map) {
equalizer.clear();
final m = eqMap.cast<String, double>();
equalizer.addAll(m.map((key, value) => MapEntry(double.parse(key), value)));
}
loudnessEnhancerEnabled = json["loudnessEnhancerEnabled"] ?? false;
loudnessEnhancer = json["loudnessEnhancer"] ?? 0.0;
loudnessEnhancerEnabled = json["loudnessEnhancerEnabled"] ?? loudnessEnhancerEnabled;
loudnessEnhancer = json["loudnessEnhancer"] ?? loudnessEnhancer;
uiTapToUpdate.value = json["uiTapToUpdate"] ?? uiTapToUpdate.value;
} catch (e) {
printy(e, isError: true);
}
Expand All @@ -54,6 +61,7 @@ class EqualizerSettings with SettingsFileWriter {
"equalizer": equalizer.map((key, value) => MapEntry(key.toString(), value)),
"loudnessEnhancerEnabled": loudnessEnhancerEnabled,
"loudnessEnhancer": loudnessEnhancer,
"uiTapToUpdate": uiTapToUpdate.value,
};

Future<void> _writeToStorage() async => await writeToStorage();
Expand Down
33 changes: 30 additions & 3 deletions lib/ui/pages/equalizer_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,31 @@ class EqualizerPageState extends State<EqualizerPage> with WidgetsBindingObserve
displayValue: false,
trailing: Row(
children: [
const SizedBox(width: 4.0),
NamidaIconButton(
horizontalPadding: 8.0,
horizontalPadding: 0.0,
tooltip: lang.TAP_TO_SEEK,
icon: null,
iconSize: 20.0,
onPressed: () => EqualizerSettings.inst.save(uiTapToUpdate: !EqualizerSettings.inst.uiTapToUpdate.value),
child: Obx(
() => StackedIcon(
baseIcon: Broken.mouse_1,
secondaryIcon: EqualizerSettings.inst.uiTapToUpdate.value ? Broken.tick_circle : Broken.close_circle,
secondaryIconSize: 12.0,
),
),
),
const SizedBox(width: 12.0),
NamidaIconButton(
horizontalPadding: 0.0,
tooltip: lang.OPEN_APP,
icon: Broken.export_2,
iconColor: context.defaultIconColor(),
iconSize: 20.0,
onPressed: NamidaChannel.inst.openSystemEqualizer,
),
const SizedBox(width: 8.0),
const SizedBox(width: 16.0),
CustomSwitch(
active: enabled,
passedColor: null,
Expand All @@ -136,6 +153,7 @@ class EqualizerPageState extends State<EqualizerPage> with WidgetsBindingObserve
EqualizerControls(
equalizer: _equalizer,
onGainSetCallback: _resetPreset,
tapToUpdate: () => EqualizerSettings.inst.uiTapToUpdate.value,
),
const SizedBox(height: 12.0),
if (_equalizerPresets.isNotEmpty) ...[
Expand Down Expand Up @@ -397,11 +415,13 @@ Timer? _longPressTimer;
class EqualizerControls extends StatelessWidget {
final AndroidEqualizer equalizer;
final void Function() onGainSetCallback;
final bool Function() tapToUpdate;

const EqualizerControls({
Key? key,
required this.equalizer,
required this.onGainSetCallback,
required this.tapToUpdate,
}) : super(key: key);

Widget _getArrowIcon({required IconData icon, required VoidCallback callback}) {
Expand Down Expand Up @@ -477,6 +497,7 @@ class EqualizerControls extends StatelessWidget {
value: band.gain,
onChanged: (value) => _onGainSetNoClamp(band, parameters, value),
circleWidth: (context.width / allBands.length * 0.7).clamp(8.0, 24.0),
tapToUpdate: tapToUpdate,
),
),
const SizedBox(height: 8.0),
Expand Down Expand Up @@ -531,6 +552,7 @@ class VerticalSlider extends StatefulWidget {
final double max;
final double circleWidth;
final ValueChanged<double> onChanged;
final bool Function() tapToUpdate;

const VerticalSlider({
Key? key,
Expand All @@ -539,6 +561,7 @@ class VerticalSlider extends StatefulWidget {
this.max = 1.0,
required this.circleWidth,
required this.onChanged,
required this.tapToUpdate,
}) : super(key: key);

@override
Expand Down Expand Up @@ -570,7 +593,11 @@ class _VerticalSliderState extends State<VerticalSlider> {
final finalVal = (widget.value - widget.min) / (widget.max - widget.min);
final height = constraints.maxHeight * finalVal;
return GestureDetector(
onTapDown: (_) => _isPointerDown.value = true,
behavior: HitTestBehavior.translucent,
onTapDown: (details) {
if (widget.tapToUpdate()) _updateValue(constraints, total, details.localPosition.dy);
_isPointerDown.value = true;
},
onTapUp: (details) => _isPointerDown.value = false,
onVerticalDragEnd: (_) {
_isPointerDown.value = false;
Expand Down

0 comments on commit 3aa0956

Please sign in to comment.