From 403d9a9a4ce58ce33a075900104b010cb8c00733 Mon Sep 17 00:00:00 2001 From: stonegate Date: Sat, 25 Jul 2020 18:32:05 +0800 Subject: [PATCH] Improve real dark theme. --- lib/home/audioplayer.dart | 40 ++++++++++++--------- lib/home/home_groups.dart | 12 +++---- lib/local_storage/sqflite_localpodcast.dart | 10 +++--- lib/main.dart | 7 ++-- lib/settings/theme.dart | 2 +- lib/state/audio_state.dart | 20 ++++++----- lib/state/setting_state.dart | 39 ++++++++++---------- lib/util/episodegrid.dart | 10 +++--- lib/util/extension_helper.dart | 1 + 9 files changed, 78 insertions(+), 63 deletions(-) diff --git a/lib/home/audioplayer.dart b/lib/home/audioplayer.dart index 3ff8d3a..04a835d 100644 --- a/lib/home/audioplayer.dart +++ b/lib/home/audioplayer.dart @@ -1187,13 +1187,12 @@ class _ControlPanelState extends State data: SliderTheme.of(context).copyWith( activeTrackColor: Theme.of(context).brightness == Brightness.dark - ? Colors.black38 + ? Colors.grey[900] : Colors.grey[400], - inactiveTrackColor: - Theme.of(context).primaryColorDark, + inactiveTrackColor: context.primaryColorDark, trackHeight: 20.0, trackShape: MyRectangularTrackShape(), - thumbColor: Theme.of(context).accentColor, + thumbColor: context.accentColor, thumbShape: MyRoundSliderThumpShape( enabledThumbRadius: 10.0, disabledThumbRadius: 10.0, @@ -1283,13 +1282,17 @@ class _ControlPanelState extends State color: Colors.grey[500]), Selector( selector: (_, audio) => audio.rewindSeconds, - builder: (_, seconds, __) => Text('$seconds s', - textAlign: TextAlign.center, - style: GoogleFonts.teko( - textStyle: TextStyle( - color: Colors.grey[500], - fontSize: 20), - ))), + builder: (_, seconds, __) => Padding( + padding: const EdgeInsets.only(top: 5.0), + child: Text('$seconds s', + style: GoogleFonts.teko( + textBaseline: + TextBaseline.ideographic, + textStyle: TextStyle( + color: Colors.grey[500], + fontSize: 20), + )), + )), Container( margin: EdgeInsets.symmetric(horizontal: 30), height: 60, @@ -1353,12 +1356,15 @@ class _ControlPanelState extends State Selector( selector: (_, audio) => audio.fastForwardSeconds, - builder: (_, seconds, __) => Text('$seconds s', - style: GoogleFonts.teko( - textStyle: TextStyle( - color: Colors.grey[500], - fontSize: 20), - ))), + builder: (_, seconds, __) => Padding( + padding: const EdgeInsets.only(top: 5.0), + child: Text('$seconds s', + style: GoogleFonts.teko( + textStyle: TextStyle( + color: Colors.grey[500], + fontSize: 20), + )), + )), IconButton( padding: EdgeInsets.symmetric(horizontal: 10.0), onPressed: diff --git a/lib/home/home_groups.dart b/lib/home/home_groups.dart index 21d986a..cb7579d 100644 --- a/lib/home/home_groups.dart +++ b/lib/home/home_groups.dart @@ -638,13 +638,13 @@ class ShowEpisode extends StatelessWidget { backgroundColor: context.brightness == Brightness.light ? context.primaryColor - : context.scaffoldBackgroundColor, + : context.dialogBackgroundColor, title: Text(data.item1 != episodes[index] ? s.play : s.playing), trailingIcon: Icon( LineIcons.play_circle_solid, - color: Theme.of(context).accentColor, + color: context.accentColor, ), onPressed: () { if (data.item1 != episodes[index]) @@ -655,7 +655,7 @@ class ShowEpisode extends StatelessWidget { backgroundColor: context.brightness == Brightness.light ? context.primaryColor - : context.scaffoldBackgroundColor, + : context.dialogBackgroundColor, title: data.item2.contains( episodes[index].enclosureUrl) ? Text(s.remove) @@ -688,7 +688,7 @@ class ShowEpisode extends StatelessWidget { backgroundColor: context.brightness == Brightness.light ? context.primaryColor - : context.scaffoldBackgroundColor, + : context.dialogBackgroundColor, title: isLiked ? Text(s.unlike) : Text(s.like), @@ -719,7 +719,7 @@ class ShowEpisode extends StatelessWidget { backgroundColor: context.brightness == Brightness.light ? context.primaryColor - : context.scaffoldBackgroundColor, + : context.dialogBackgroundColor, title: isListened > 0 ? Text(s.listened, style: TextStyle( @@ -755,7 +755,7 @@ class ShowEpisode extends StatelessWidget { backgroundColor: context.brightness == Brightness.light ? context.primaryColor - : context.scaffoldBackgroundColor, + : context.dialogBackgroundColor, title: isDownloaded ? Text(s.downloaded, style: TextStyle( diff --git a/lib/local_storage/sqflite_localpodcast.dart b/lib/local_storage/sqflite_localpodcast.dart index d30291b..baafc62 100644 --- a/lib/local_storage/sqflite_localpodcast.dart +++ b/lib/local_storage/sqflite_localpodcast.dart @@ -820,7 +820,7 @@ class DBHelper { var dbClient = await database; List episodes = []; List list = await dbClient.rawQuery( - """SELECT E.title, E.enclosure_url, E.enclosure_length, E.is_new, + """SELECT E.title, E.enclosure_url, E.enclosure_length, E.is_new, E.media_id, E.milliseconds, P.title as feed_title, E.duration, E.explicit, P.imagePath, P.primaryColor FROM Episodes E INNER JOIN PodcastLocal P ON E.feed_id = P.id WHERE is_new = 1 ORDER BY E.milliseconds DESC """, @@ -836,7 +836,8 @@ class DBHelper { i['duration'], i['explicit'], i['imagePath'], - i['is_new'])); + i['is_new'], + mediaId: i['media_id'])); } return episodes; } @@ -929,7 +930,7 @@ class DBHelper { if (group.length > 0) { List s = group.map((e) => "'$e'").toList(); List list = await dbClient.rawQuery( - """SELECT E.title, E.enclosure_url, E.enclosure_length, E.is_new, + """SELECT E.title, E.enclosure_url, E.enclosure_length, E.is_new, E.media_id, E.milliseconds, P.title as feed_title, E.duration, E.explicit, P.imagePath, P.primaryColor FROM Episodes E INNER JOIN PodcastLocal P ON E.feed_id = P.id WHERE P.id in (${s.join(',')}) AND is_new = 1 @@ -946,7 +947,8 @@ class DBHelper { i['duration'], i['explicit'], i['imagePath'], - i['is_new'])); + i['is_new'], + mediaId: i['media_id'])); } } return episodes; diff --git a/lib/main.dart b/lib/main.dart index 353b964..c465f6c 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -66,9 +66,12 @@ class MyApp extends StatelessWidget { scaffoldBackgroundColor: setting.realDark ? Colors.black87 : null, primaryColor: setting.realDark ? Colors.black : null, - popupMenuTheme: PopupMenuThemeData() - .copyWith(color: setting.realDark ? Colors.black87 : null), + popupMenuTheme: PopupMenuThemeData().copyWith( + color: setting.realDark ? Colors.grey[900] : null), appBarTheme: AppBarTheme(elevation: 0), + buttonTheme: ButtonThemeData(height: 32), + dialogBackgroundColor: + setting.realDark ? Colors.grey[900] : null, cursorColor: setting.accentSetColor), localizationsDelegates: [ S.delegate, diff --git a/lib/settings/theme.dart b/lib/settings/theme.dart index 4ffe906..b6495e6 100644 --- a/lib/settings/theme.dart +++ b/lib/settings/theme.dart @@ -163,7 +163,7 @@ class ThemeSetting extends StatelessWidget { context, title: Text.rich(TextSpan(text: s.chooseA, children: [ TextSpan( - text: s.color, + text: ' ${s.color}', style: TextStyle( fontWeight: FontWeight.bold, color: context.accentColor)) diff --git a/lib/state/audio_state.dart b/lib/state/audio_state.dart index abdc118..c31da99 100644 --- a/lib/state/audio_state.dart +++ b/lib/state/audio_state.dart @@ -348,8 +348,7 @@ class AudioPlayerNotifier extends ChangeNotifier { .where((event) => event != null) .listen((event) async { _current = DateTime.now(); - if (event.processingState != AudioProcessingState.none) - _audioState = event.processingState; + _audioState = event.processingState; _playing = event?.playing; _currentSpeed = event.speed; _currentPosition = event.currentPosition.inMilliseconds ?? 0; @@ -422,20 +421,22 @@ class AudioPlayerNotifier extends ChangeNotifier { } addToPlaylist(EpisodeBrief episode) async { - if (!_queue.playlist.contains(episode)) { + var episodeNew = await dbHelper.getRssItemWithUrl(episode.enclosureUrl); + if (!_queue.playlist.contains(episodeNew)) { if (playerRunning) { - await AudioService.addQueueItem(episode.toMediaItem()); + await AudioService.addQueueItem(episodeNew.toMediaItem()); } - await _queue.addToPlayList(episode); + await _queue.addToPlayList(episodeNew); notifyListeners(); } } addToPlaylistAt(EpisodeBrief episode, int index) async { + var episodeNew = await dbHelper.getRssItemWithUrl(episode.enclosureUrl); if (playerRunning) { - await AudioService.addQueueItemAt(episode.toMediaItem(), index); + await AudioService.addQueueItemAt(episodeNew.toMediaItem(), index); } - await _queue.addToPlayListAt(episode, index); + await _queue.addToPlayListAt(episodeNew, index); _queueUpdate = !_queueUpdate; notifyListeners(); } @@ -466,10 +467,11 @@ class AudioPlayerNotifier extends ChangeNotifier { } Future delFromPlaylist(EpisodeBrief episode) async { + var episodeNew = await dbHelper.getRssItemWithUrl(episode.enclosureUrl); if (playerRunning) { - await AudioService.removeQueueItem(episode.toMediaItem()); + await AudioService.removeQueueItem(episodeNew.toMediaItem()); } - int index = await _queue.delFromPlaylist(episode); + int index = await _queue.delFromPlaylist(episodeNew); _queueUpdate = !_queueUpdate; notifyListeners(); return index; diff --git a/lib/state/setting_state.dart b/lib/state/setting_state.dart index 5e345f7..764300a 100644 --- a/lib/state/setting_state.dart +++ b/lib/state/setting_state.dart @@ -56,25 +56,26 @@ void callbackDispatcher() { } ThemeData lightTheme = ThemeData( - accentColorBrightness: Brightness.dark, - primaryColor: Colors.grey[100], - // accentColor: _accentSetColor, - primaryColorLight: Colors.white, - primaryColorDark: Colors.grey[300], - dialogBackgroundColor: Colors.white, - backgroundColor: Colors.grey[100], - appBarTheme: AppBarTheme( - color: Colors.grey[100], - elevation: 0, - ), - textTheme: TextTheme( - bodyText2: TextStyle(fontSize: 15.0, fontWeight: FontWeight.normal), - ), - tabBarTheme: TabBarTheme( - labelColor: Colors.black, - unselectedLabelColor: Colors.grey[400], - ), - buttonTheme: ButtonThemeData(height: 32)); + accentColorBrightness: Brightness.dark, + primaryColor: Colors.grey[100], + // accentColor: _accentSetColor, + primaryColorLight: Colors.white, + primaryColorDark: Colors.grey[300], + dialogBackgroundColor: Colors.white, + backgroundColor: Colors.grey[100], + appBarTheme: AppBarTheme( + color: Colors.grey[100], + elevation: 0, + ), + textTheme: TextTheme( + bodyText2: TextStyle(fontSize: 15.0, fontWeight: FontWeight.normal), + ), + tabBarTheme: TabBarTheme( + labelColor: Colors.black, + unselectedLabelColor: Colors.grey[400], + ), + buttonTheme: ButtonThemeData(height: 32), +); class SettingState extends ChangeNotifier { var themeStorage = KeyValueStorage(themesKey); diff --git a/lib/util/episodegrid.dart b/lib/util/episodegrid.dart index 6da6fb2..48e1d7f 100644 --- a/lib/util/episodegrid.dart +++ b/lib/util/episodegrid.dart @@ -305,7 +305,7 @@ class EpisodeGrid extends StatelessWidget { backgroundColor: context.brightness == Brightness.light ? context.primaryColor - : context.scaffoldBackgroundColor, + : context.dialogBackgroundColor, title: Text(data.item1 != episodes[index] ? s.play : s.playing), @@ -322,7 +322,7 @@ class EpisodeGrid extends StatelessWidget { backgroundColor: context.brightness == Brightness.light ? context.primaryColor - : context.scaffoldBackgroundColor, + : context.dialogBackgroundColor, title: data.item2.contains( episodes[index].enclosureUrl) ? Text(s.remove) @@ -354,7 +354,7 @@ class EpisodeGrid extends StatelessWidget { backgroundColor: context.brightness == Brightness.light ? context.primaryColor - : context.scaffoldBackgroundColor, + : context.dialogBackgroundColor, title: isLiked ? Text(s.unlike) : Text(s.like), @@ -385,7 +385,7 @@ class EpisodeGrid extends StatelessWidget { backgroundColor: context.brightness == Brightness.light ? context.primaryColor - : context.scaffoldBackgroundColor, + : context.dialogBackgroundColor, title: isListened > 0 ? Text(s.listened, style: TextStyle( @@ -420,7 +420,7 @@ class EpisodeGrid extends StatelessWidget { backgroundColor: context.brightness == Brightness.light ? context.primaryColor - : context.scaffoldBackgroundColor, + : context.dialogBackgroundColor, title: isDownloaded ? Text(s.downloaded, style: TextStyle( diff --git a/lib/util/extension_helper.dart b/lib/util/extension_helper.dart index e62cc3d..9e6cb0a 100644 --- a/lib/util/extension_helper.dart +++ b/lib/util/extension_helper.dart @@ -12,6 +12,7 @@ extension ContextExtension on BuildContext { Color get scaffoldBackgroundColor => Theme.of(this).scaffoldBackgroundColor; Color get primaryColorDark => Theme.of(this).primaryColorDark; Color get textColor => Theme.of(this).textTheme.bodyText1.color; + Color get dialogBackgroundColor => Theme.of(this).dialogBackgroundColor; Brightness get brightness => Theme.of(this).brightness; double get width => MediaQuery.of(this).size.width; double get height => MediaQuery.of(this).size.height;