fix: set boost valumn

This commit is contained in:
xijieyin 2022-07-31 18:33:22 +08:00
parent 199f3e8a28
commit 1df6ed6116
15 changed files with 144 additions and 122 deletions

View File

@ -25,17 +25,17 @@ import 'messages_ru.dart' as messages_ru;
import 'messages_tr.dart' as messages_tr;
import 'messages_zh-Hans.dart' as messages_zh_hans;
typedef LibraryLoader = Future<dynamic> Function();
typedef Future<dynamic> LibraryLoader();
Map<String, LibraryLoader> _deferredLibraries = {
'el': () => Future.value(null),
'en': () => Future.value(null),
'es': () => Future.value(null),
'fr': () => Future.value(null),
'it': () => Future.value(null),
'pt': () => Future.value(null),
'ru': () => Future.value(null),
'tr': () => Future.value(null),
'zh_Hans': () => Future.value(null),
'el': () => new Future.value(null),
'en': () => new Future.value(null),
'es': () => new Future.value(null),
'fr': () => new Future.value(null),
'it': () => new Future.value(null),
'pt': () => new Future.value(null),
'ru': () => new Future.value(null),
'tr': () => new Future.value(null),
'zh_Hans': () => new Future.value(null),
};
MessageLookupByLibrary? _findExact(String localeName) {
@ -69,13 +69,13 @@ Future<bool> initializeMessages(String localeName) async {
localeName, (locale) => _deferredLibraries[locale] != null,
onFailure: (_) => null);
if (availableLocale == null) {
return Future.value(false);
return new Future.value(false);
}
var lib = _deferredLibraries[availableLocale];
await (lib == null ? Future.value(false) : lib());
initializeInternalMessageLookup(() => CompositeMessageLookup());
await (lib == null ? new Future.value(false) : lib());
initializeInternalMessageLookup(() => new CompositeMessageLookup());
messageLookup.addLocale(availableLocale, _findGeneratedMessagesFor);
return Future.value(true);
return new Future.value(true);
}
bool _messagesExistFor(String locale) {

View File

@ -13,10 +13,9 @@
import 'package:intl/intl.dart';
import 'package:intl/message_lookup_by_library.dart';
final messages = MessageLookup();
final messages = new MessageLookup();
typedef MessageIfAbsent = String Function(
String messageStr, List<dynamic> args);
typedef String MessageIfAbsent(String messageStr, List<dynamic> args);
class MessageLookup extends MessageLookupByLibrary {
String get localeName => 'el';

View File

@ -13,10 +13,9 @@
import 'package:intl/intl.dart';
import 'package:intl/message_lookup_by_library.dart';
final messages = MessageLookup();
final messages = new MessageLookup();
typedef MessageIfAbsent = String Function(
String messageStr, List<dynamic> args);
typedef String MessageIfAbsent(String messageStr, List<dynamic> args);
class MessageLookup extends MessageLookupByLibrary {
String get localeName => 'en';

View File

@ -13,10 +13,9 @@
import 'package:intl/intl.dart';
import 'package:intl/message_lookup_by_library.dart';
final messages = MessageLookup();
final messages = new MessageLookup();
typedef MessageIfAbsent = String Function(
String messageStr, List<dynamic> args);
typedef String MessageIfAbsent(String messageStr, List<dynamic> args);
class MessageLookup extends MessageLookupByLibrary {
String get localeName => 'es';

View File

@ -13,10 +13,9 @@
import 'package:intl/intl.dart';
import 'package:intl/message_lookup_by_library.dart';
final messages = MessageLookup();
final messages = new MessageLookup();
typedef MessageIfAbsent = String Function(
String messageStr, List<dynamic> args);
typedef String MessageIfAbsent(String messageStr, List<dynamic> args);
class MessageLookup extends MessageLookupByLibrary {
String get localeName => 'fr';

View File

@ -13,10 +13,9 @@
import 'package:intl/intl.dart';
import 'package:intl/message_lookup_by_library.dart';
final messages = MessageLookup();
final messages = new MessageLookup();
typedef MessageIfAbsent = String Function(
String messageStr, List<dynamic> args);
typedef String MessageIfAbsent(String messageStr, List<dynamic> args);
class MessageLookup extends MessageLookupByLibrary {
String get localeName => 'it';

View File

@ -13,10 +13,9 @@
import 'package:intl/intl.dart';
import 'package:intl/message_lookup_by_library.dart';
final messages = MessageLookup();
final messages = new MessageLookup();
typedef MessageIfAbsent = String Function(
String messageStr, List<dynamic> args);
typedef String MessageIfAbsent(String messageStr, List<dynamic> args);
class MessageLookup extends MessageLookupByLibrary {
String get localeName => 'pt';

View File

@ -13,10 +13,9 @@
import 'package:intl/intl.dart';
import 'package:intl/message_lookup_by_library.dart';
final messages = MessageLookup();
final messages = new MessageLookup();
typedef MessageIfAbsent = String Function(
String messageStr, List<dynamic> args);
typedef String MessageIfAbsent(String messageStr, List<dynamic> args);
class MessageLookup extends MessageLookupByLibrary {
String get localeName => 'ru';

View File

@ -13,10 +13,9 @@
import 'package:intl/intl.dart';
import 'package:intl/message_lookup_by_library.dart';
final messages = MessageLookup();
final messages = new MessageLookup();
typedef MessageIfAbsent = String Function(
String messageStr, List<dynamic> args);
typedef String MessageIfAbsent(String messageStr, List<dynamic> args);
class MessageLookup extends MessageLookupByLibrary {
String get localeName => 'tr';

View File

@ -13,10 +13,9 @@
import 'package:intl/intl.dart';
import 'package:intl/message_lookup_by_library.dart';
final messages = MessageLookup();
final messages = new MessageLookup();
typedef MessageIfAbsent = String Function(
String messageStr, List<dynamic> args);
typedef String MessageIfAbsent(String messageStr, List<dynamic> args);
class MessageLookup extends MessageLookupByLibrary {
String get localeName => 'zh_Hans';

View File

@ -54,11 +54,54 @@ class PlayerWidget extends StatelessWidget {
PlayerWidget({this.playerKey, this.isPlayingPage = false});
final GlobalKey<AudioPanelState>? playerKey;
final bool isPlayingPage;
Widget _miniPanel(BuildContext context) {
var audio = Provider.of<AudioPlayerNotifier>(context, listen: false);
@override
Widget build(BuildContext context) {
return Selector<AudioPlayerNotifier, Tuple2<bool, PlayerHeight?>>(
selector: (_, audio) => Tuple2(audio.playerRunning, audio.playerHeight),
builder: (_, data, __) {
if (!data.item1) {
return Center();
} else {
final minHeight = kMinPlayerHeight[data.item2!.index];
final maxHeight = math.min(
kMaxPlayerHeight[data.item2!.index] as double,
context.height - 20);
return AudioPanel(
minHeight: minHeight,
maxHeight: maxHeight,
expandHeight: context.height - context.paddingTop - 20,
key: playerKey,
miniPanel: _MiniPanel(),
expandedPanel: ControlPanel(
maxHeight: maxHeight,
isPlayingPage: isPlayingPage,
onExpand: () {
playerKey!.currentState!.scrollToTop();
},
onClose: () {
playerKey!.currentState!.backToMini();
},
),
);
}
},
);
}
}
class _MiniPanel extends StatelessWidget {
const _MiniPanel({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
final audio = Provider.of<AudioPlayerNotifier>(context, listen: false);
final s = context.s;
final bgColor = audio.episode == null
? context.primaryColor
: audio.episode!.cardColor(context);
return Container(
color: context.primaryColor,
color: bgColor,
height: 60,
child:
Column(mainAxisAlignment: MainAxisAlignment.start, children: <Widget>[
@ -70,7 +113,7 @@ class PlayerWidget extends StatelessWidget {
height: 2,
child: LinearProgressIndicator(
value: data.item2,
backgroundColor: context.primaryColor,
backgroundColor: bgColor,
valueColor: AlwaysStoppedAnimation<Color>(c),
),
);
@ -223,40 +266,6 @@ class PlayerWidget extends StatelessWidget {
]),
);
}
@override
Widget build(BuildContext context) {
return Selector<AudioPlayerNotifier, Tuple2<bool, PlayerHeight?>>(
selector: (_, audio) => Tuple2(audio.playerRunning, audio.playerHeight),
builder: (_, data, __) {
if (!data.item1) {
return Center();
} else {
final minHeight = kMinPlayerHeight[data.item2!.index];
final maxHeight = math.min(
kMaxPlayerHeight[data.item2!.index] as double,
context.height - 20);
return AudioPanel(
minHeight: minHeight,
maxHeight: maxHeight,
expandHeight: context.height - context.paddingTop - 20,
key: playerKey,
miniPanel: _miniPanel(context),
expandedPanel: ControlPanel(
maxHeight: maxHeight,
isPlayingPage: isPlayingPage,
onExpand: () {
playerKey!.currentState!.scrollToTop();
},
onClose: () {
playerKey!.currentState!.backToMini();
},
),
);
}
},
);
}
}
class LastPosition extends StatelessWidget {
@ -285,9 +294,19 @@ class LastPosition extends StatelessWidget {
builder: (_, data, __) => TextButton(
child: Row(
children: [
Icon(Icons.flash_on, size: 18),
Icon(Icons.flash_on,
size: 18,
color: data!
? context.accentColor
: context.textColor),
SizedBox(width: 5),
Text(s.skipSilence),
Text(
s.skipSilence,
style: TextStyle(
color: data
? context.accentColor
: context.textColor),
),
],
),
style: TextButton.styleFrom(
@ -308,26 +327,38 @@ class LastPosition extends StatelessWidget {
SizedBox(width: 10),
Selector<AudioPlayerNotifier, bool?>(
selector: (_, audio) => audio.boostVolume,
builder: (_, data, __) => FlatButton(
builder: (_, data, __) => TextButton(
child: Row(
children: [
Icon(Icons.volume_up, size: 18),
Icon(Icons.volume_up,
size: 18,
color: data!
? context.accentColor
: context.textColor),
SizedBox(width: 5),
Text(s.boostVolume),
Text(
s.boostVolume,
style: TextStyle(
color: data
? context.accentColor
: context.textColor),
),
],
),
color: data! ? context.accentColor : Colors.transparent,
padding: EdgeInsets.symmetric(horizontal: 10),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(100.0),
side: BorderSide(
color: data
? context.accentColor
: Theme.of(context)
.colorScheme
.onSurface
.withOpacity(0.12))),
textColor: data ? Colors.white : null,
style: TextButton.styleFrom(
primary:
data ? context.accentColor : Colors.transparent,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(100.0),
side: BorderSide(
color: data
? context.accentColor
: Theme.of(context)
.colorScheme
.onSurface
.withOpacity(0.12))),
padding: EdgeInsets.symmetric(horizontal: 10),
),
onPressed: () =>
audio.setBoostVolume(boostVolume: !data))),
SizedBox(width: 10),
@ -1268,10 +1299,10 @@ class _ControlPanelState extends State<ControlPanel>
@override
Widget build(BuildContext context) {
var audio = Provider.of<AudioPlayerNotifier>(context, listen: false);
final audio = Provider.of<AudioPlayerNotifier>(context, listen: false);
return LayoutBuilder(
builder: (context, constraints) {
var height = constraints.maxHeight;
final height = constraints.maxHeight;
return Container(
color: context.primaryColor,
height: 300,
@ -1499,12 +1530,12 @@ class _ControlPanelState extends State<ControlPanel>
padding: EdgeInsets.only(left: 60, right: 60),
child: LayoutBuilder(
builder: (context, size) {
var span = TextSpan(
final span = TextSpan(
text: title,
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 20));
var tp = TextPainter(
final tp = TextPainter(
text: span,
maxLines: 1,
textDirection: TextDirection.ltr);

View File

@ -58,6 +58,7 @@ class _HomeState extends State<Home> with SingleTickerProviderStateMixin {
final _androidAppRetain = MethodChannel("android_app_retain");
var feature1OverflowMode = OverflowMode.clipContent;
var feature1EnablePulsingAnimation = false;
double top = 0;
@override
void initState() {
@ -87,7 +88,6 @@ class _HomeState extends State<Home> with SingleTickerProviderStateMixin {
super.dispose();
}
double top = 0;
@override
Widget build(BuildContext context) {
final height = (context.width - 20) / 3 + 140;

View File

@ -180,7 +180,7 @@ class _PlaySettingState extends State<PlaySetting> {
EdgeInsets.only(left: 70.0, right: 20, bottom: 10, top: 10),
title: Text(s.settingsBoostVolume),
subtitle: Text(s.settingsBoostVolumeDes),
trailing: Selector<AudioPlayerNotifier, int?>(
trailing: Selector<AudioPlayerNotifier, int>(
selector: (_, audio) => audio.volumeGain,
builder: (_, volumeGain, __) => MyDropdownButton(
hint: Text(_volumeEffect(context, volumeGain)),
@ -189,7 +189,7 @@ class _PlaySettingState extends State<PlaySetting> {
displayItemCount: 5,
isDense: true,
value: volumeGain,
onChanged: (dynamic value) => audio.setVolumeGain = value,
onChanged: (int value) => audio.setVolumeGain = value,
items: [2000, 3000, 4000].map<DropdownMenuItem<int>>((e) {
return DropdownMenuItem<int>(
value: e, child: Text(_volumeEffect(context, e)));

View File

@ -165,7 +165,7 @@ class AudioPlayerNotifier extends ChangeNotifier {
bool? _boostVolume;
/// Boost volume gain.
int? _volumeGain;
late int _volumeGain;
// ignore: prefer_final_fields
bool _playerRunning = false;
@ -241,7 +241,7 @@ class AudioPlayerNotifier extends ChangeNotifier {
PlayerHeight? get playerHeight => _playerHeight;
bool? get skipSilence => _skipSilence;
bool? get boostVolume => _boostVolume;
int? get volumeGain => _volumeGain;
int get volumeGain => _volumeGain;
set setSwitchValue(double value) {
_switchValue = value;
@ -303,7 +303,7 @@ class AudioPlayerNotifier extends ChangeNotifier {
);
await _playlist!.getPlaylist();
if (state[1] != '') {
var episode = await _dbHelper.getRssItemWithUrl(state[1]);
final episode = await _dbHelper.getRssItemWithUrl(state[1]);
if (episode != null &&
((!_playlist!.isQueue && _playlist!.contains(episode)) ||
(_playlist!.isQueue &&
@ -476,18 +476,18 @@ class AudioPlayerNotifier extends ChangeNotifier {
//Check auto sleep timer setting
await _getAutoSleepTimer();
if (_autoSleepTimer!) {
var startTime = await (_autoSleepTimerStartStorage.getInt(
defaultValue: 1380) as FutureOr<int>);
var endTime = await (_autoSleepTimerEndStorage.getInt(defaultValue: 360)
as FutureOr<int>);
var currentTime = DateTime.now().hour * 60 + DateTime.now().minute;
final startTime =
await (_autoSleepTimerStartStorage.getInt(defaultValue: 1380));
final endTime =
await (_autoSleepTimerEndStorage.getInt(defaultValue: 360));
final currentTime = DateTime.now().hour * 60 + DateTime.now().minute;
if ((startTime > endTime &&
(currentTime > startTime || currentTime < endTime)) ||
((startTime < endTime) &&
(currentTime > startTime && currentTime < endTime))) {
var mode = await (_autoSleepTimerModeStorage.getInt() as FutureOr<int>);
final mode = await (_autoSleepTimerModeStorage.getInt());
_sleepTimerMode = SleepTimerMode.values[mode];
var defaultTimer =
final defaultTimer =
await _defaultSleepTimerStorage.getInt(defaultValue: 30);
sleepTimer(defaultTimer);
}
@ -619,7 +619,7 @@ class AudioPlayerNotifier extends ChangeNotifier {
/// Queue management
Future<void> addToPlaylist(EpisodeBrief episode) async {
var episodeNew = await (_dbHelper.getRssItemWithUrl(episode.enclosureUrl)
final episodeNew = await (_dbHelper.getRssItemWithUrl(episode.enclosureUrl)
as FutureOr<EpisodeBrief>);
if (episodeNew.isNew == 1) {
await _dbHelper.removeEpisodeNewMark(episodeNew.enclosureUrl);
@ -635,7 +635,7 @@ class AudioPlayerNotifier extends ChangeNotifier {
}
Future<void> addToPlaylistAt(EpisodeBrief episode, int index) async {
var episodeNew = await (_dbHelper.getRssItemWithUrl(episode.enclosureUrl)
final episodeNew = await (_dbHelper.getRssItemWithUrl(episode.enclosureUrl)
as FutureOr<EpisodeBrief>);
if (episodeNew.isNew == 1) {
await _dbHelper.removeEpisodeNewMark(episodeNew.enclosureUrl);
@ -680,11 +680,11 @@ class AudioPlayerNotifier extends ChangeNotifier {
}
Future<int> delFromPlaylist(EpisodeBrief episode) async {
var episodeNew = await _dbHelper.getRssItemWithUrl(episode.enclosureUrl);
final episodeNew = await _dbHelper.getRssItemWithUrl(episode.enclosureUrl);
if (playerRunning && _playlist!.isQueue) {
await _audioHandler.removeQueueItem(episodeNew!.toMediaItem());
}
var index = _queue.delFromPlaylist(episodeNew);
final index = _queue.delFromPlaylist(episodeNew);
if (index == 0) {
_lastPosition = 0;
await _positionStorage.saveInt(0);
@ -697,7 +697,7 @@ class AudioPlayerNotifier extends ChangeNotifier {
if (newIndex > oldIndex) {
newIndex -= 1;
}
var episode = _queue.episodes[oldIndex]!;
final episode = _queue.episodes[oldIndex]!;
_queue.addToPlayListAt(episode, newIndex);
updatePlaylist(_queue, updateEpisodes: false);
if (playerRunning && _playlist!.name == 'Queue') {
@ -910,13 +910,13 @@ class AudioPlayerNotifier extends ChangeNotifier {
set setVolumeGain(int volumeGain) {
_volumeGain = volumeGain;
if (_playerRunning && _boostVolume!) {
setBoostVolume(boostVolume: _boostVolume, gain: _volumeGain);
setBoostVolume(boostVolume: _boostVolume!, gain: _volumeGain);
}
notifyListeners();
_volumeGainStorage.saveInt(volumeGain);
}
Future<void> setBoostVolume({required bool? boostVolume, int? gain}) async {
Future<void> setBoostVolume({required bool boostVolume, int? gain}) async {
await _audioHandler.customAction(
'setBoostVolume', {'boostVolume': boostVolume, 'gain': _volumeGain});
_boostVolume = boostVolume;
@ -1297,7 +1297,7 @@ class CustomAudioHandler extends BaseAudioHandler
Future _setBoostVolume(bool enabled, int gain) async {
await _loudnessEnhancer.setEnabled(enabled);
await _loudnessEnhancer.setTargetGain(1.5);
await _loudnessEnhancer.setTargetGain(gain / 2000);
}
List<MediaControl> _getControls(int? index) {

View File

@ -150,7 +150,7 @@ class _DropdownMenuItemButtonState<T>
Navigator.pop(
context,
_DropdownRouteResult<T?>(dropdownMenuItem.value),
_DropdownRouteResult<T>(dropdownMenuItem.value!),
);
}