From 590f723e2e68f0a7f378166ed041ce57b0d3521a Mon Sep 17 00:00:00 2001 From: tommyxchow Date: Thu, 31 Mar 2022 02:47:19 -0400 Subject: [PATCH] Add option to disable thumbnails --- lib/screens/home/top/category_streams.dart | 1 + lib/screens/home/widgets/stream_card.dart | 43 ++++++++++--------- lib/screens/home/widgets/streams_list.dart | 1 + .../settings/sections/general_settings.dart | 7 ++- .../settings/stores/settings_store.dart | 7 +++ .../settings/stores/settings_store.g.dart | 18 ++++++++ 6 files changed, 56 insertions(+), 21 deletions(-) diff --git a/lib/screens/home/top/category_streams.dart b/lib/screens/home/top/category_streams.dart index 6ff0f976..2efe098e 100644 --- a/lib/screens/home/top/category_streams.dart +++ b/lib/screens/home/top/category_streams.dart @@ -95,6 +95,7 @@ class CategoryStreams extends StatelessWidget { width: thumbnailWidth, height: thumbnailHeight, showUptime: context.read().showThumbnailUptime, + showThumbnail: context.read().showThumbnails, showCategory: false, ), ); diff --git a/lib/screens/home/widgets/stream_card.dart b/lib/screens/home/widgets/stream_card.dart index 8bd8927b..8189d932 100644 --- a/lib/screens/home/widgets/stream_card.dart +++ b/lib/screens/home/widgets/stream_card.dart @@ -20,6 +20,7 @@ class StreamCard extends StatelessWidget { final int width; final int height; final bool showUptime; + final bool showThumbnail; final bool showCategory; const StreamCard({ @@ -29,6 +30,7 @@ class StreamCard extends StatelessWidget { required this.width, required this.height, required this.showUptime, + required this.showThumbnail, this.showCategory = true, }) : super(key: key); @@ -69,28 +71,29 @@ class StreamCard extends StatelessWidget { ), ), child: Padding( - padding: const EdgeInsets.symmetric(vertical: 10.0, horizontal: 15.0), + padding: EdgeInsets.symmetric(vertical: 10.0, horizontal: showThumbnail ? 15.0 : 5.0), child: Row( children: [ - Flexible( - flex: 1, - child: showUptime - ? Stack( - alignment: AlignmentDirectional.bottomEnd, - children: [ - thumbnail, - Container( - color: const Color.fromRGBO(0, 0, 0, 0.5), - padding: const EdgeInsets.symmetric(horizontal: 2.0), - child: Text( - DateTime.now().difference(DateTime.parse(streamInfo.startedAt)).toString().split('.')[0], - style: const TextStyle(fontSize: 12, color: Colors.white), - ), - ) - ], - ) - : thumbnail, - ), + if (showThumbnail) + Flexible( + flex: 1, + child: showUptime + ? Stack( + alignment: AlignmentDirectional.bottomEnd, + children: [ + thumbnail, + Container( + color: const Color.fromRGBO(0, 0, 0, 0.5), + padding: const EdgeInsets.symmetric(horizontal: 2.0), + child: Text( + DateTime.now().difference(DateTime.parse(streamInfo.startedAt)).toString().split('.')[0], + style: const TextStyle(fontSize: 12, color: Colors.white), + ), + ) + ], + ) + : thumbnail, + ), Flexible( flex: 2, child: Padding( diff --git a/lib/screens/home/widgets/streams_list.dart b/lib/screens/home/widgets/streams_list.dart index 22d70576..7b9382aa 100644 --- a/lib/screens/home/widgets/streams_list.dart +++ b/lib/screens/home/widgets/streams_list.dart @@ -77,6 +77,7 @@ class _StreamsListState extends State with AutomaticKeepAliveClient streamInfo: _listStore.streams[index], width: thumbnailWidth, height: thumbnailHeight, + showThumbnail: context.read().showThumbnails, showUptime: context.read().showThumbnailUptime, ), ); diff --git a/lib/screens/settings/sections/general_settings.dart b/lib/screens/settings/sections/general_settings.dart index 7a474353..d7d8c344 100644 --- a/lib/screens/settings/sections/general_settings.dart +++ b/lib/screens/settings/sections/general_settings.dart @@ -35,12 +35,17 @@ class GeneralSettings extends StatelessWidget { .toList(), ), ), + SwitchListTile.adaptive( + title: const Text('Stream Card Thumbnails'), + value: settingsStore.showThumbnails, + onChanged: (newValue) => settingsStore.showThumbnails = newValue, + ), SwitchListTile.adaptive( isThreeLine: true, title: const Text('Stream Uptime on Thumbnails'), subtitle: const Text('Displays the uptime of the stream in the HH:MM:SS format.'), value: settingsStore.showThumbnailUptime, - onChanged: (newValue) => settingsStore.showThumbnailUptime = newValue, + onChanged: settingsStore.showThumbnails ? (newValue) => settingsStore.showThumbnailUptime = newValue : null, ), ], ), diff --git a/lib/screens/settings/stores/settings_store.dart b/lib/screens/settings/stores/settings_store.dart index de8197f9..8c32b454 100644 --- a/lib/screens/settings/stores/settings_store.dart +++ b/lib/screens/settings/stores/settings_store.dart @@ -17,6 +17,8 @@ abstract class _SettingsStoreBase with Store { static const defaultShowThumbnailUptime = false; + static const defaultShowThumbnails = true; + @JsonKey(defaultValue: defaultThemeType, unknownEnumValue: ThemeType.system) @observable var themeType = defaultThemeType; @@ -25,6 +27,10 @@ abstract class _SettingsStoreBase with Store { @observable var showThumbnailUptime = defaultShowThumbnailUptime; + @JsonKey(defaultValue: defaultShowThumbnails) + @observable + var showThumbnails = defaultShowThumbnails; + // * Video Settings static const defaultShowVideo = true; @@ -142,6 +148,7 @@ abstract class _SettingsStoreBase with Store { // * General Settings themeType = defaultThemeType; showThumbnailUptime = defaultShowThumbnailUptime; + showThumbnails = defaultShowThumbnails; // * Video Settings showVideo = defaultShowVideo; diff --git a/lib/screens/settings/stores/settings_store.g.dart b/lib/screens/settings/stores/settings_store.g.dart index ec3688ef..1de63102 100644 --- a/lib/screens/settings/stores/settings_store.g.dart +++ b/lib/screens/settings/stores/settings_store.g.dart @@ -12,6 +12,7 @@ SettingsStore _$SettingsStoreFromJson(Map json) => unknownValue: ThemeType.system) ?? ThemeType.system ..showThumbnailUptime = json['showThumbnailUptime'] as bool? ?? false + ..showThumbnails = json['showThumbnails'] as bool? ?? true ..showVideo = json['showVideo'] as bool? ?? true ..showOverlay = json['showOverlay'] as bool? ?? true ..toggleableOverlay = json['toggleableOverlay'] as bool? ?? false @@ -39,6 +40,7 @@ Map _$SettingsStoreToJson(SettingsStore instance) => { 'themeType': _$ThemeTypeEnumMap[instance.themeType], 'showThumbnailUptime': instance.showThumbnailUptime, + 'showThumbnails': instance.showThumbnails, 'showVideo': instance.showVideo, 'showOverlay': instance.showOverlay, 'toggleableOverlay': instance.toggleableOverlay, @@ -110,6 +112,21 @@ mixin _$SettingsStore on _SettingsStoreBase, Store { }); } + final _$showThumbnailsAtom = Atom(name: '_SettingsStoreBase.showThumbnails'); + + @override + bool get showThumbnails { + _$showThumbnailsAtom.reportRead(); + return super.showThumbnails; + } + + @override + set showThumbnails(bool value) { + _$showThumbnailsAtom.reportWrite(value, super.showThumbnails, () { + super.showThumbnails = value; + }); + } + final _$showVideoAtom = Atom(name: '_SettingsStoreBase.showVideo'); @override @@ -405,6 +422,7 @@ mixin _$SettingsStore on _SettingsStoreBase, Store { return ''' themeType: ${themeType}, showThumbnailUptime: ${showThumbnailUptime}, +showThumbnails: ${showThumbnails}, showVideo: ${showVideo}, showOverlay: ${showOverlay}, toggleableOverlay: ${toggleableOverlay},