From 488162a035d8776c9de1cc107b9564afc6ae8bbb Mon Sep 17 00:00:00 2001 From: Tommy Chow Date: Thu, 6 Jan 2022 23:06:25 -0500 Subject: [PATCH] Add clear image cache button & name tweaks (#33) Closes #33 --- lib/models/irc_message.dart | 8 +-- lib/screens/channel/chat/chat_message.dart | 8 +-- lib/screens/settings/chat_settings.dart | 20 +++---- lib/screens/settings/other_settings.dart | 49 ++++++++++++++++ lib/screens/settings/settings.dart | 19 ++----- .../settings/stores/settings_store.dart | 2 +- .../settings/stores/settings_store.g.dart | 57 ++++++++----------- 7 files changed, 98 insertions(+), 65 deletions(-) create mode 100644 lib/screens/settings/other_settings.dart diff --git a/lib/models/irc_message.dart b/lib/models/irc_message.dart index 970249de..0b10f4c6 100644 --- a/lib/models/irc_message.dart +++ b/lib/models/irc_message.dart @@ -82,8 +82,8 @@ class IRCMessage { Map>? sevenTVUserToBadges, Map? bttvUserToBadge, RoomFFZ? ffzRoomInfo, - bool hideMessage = false, - bool zeroWidthEnabled = false, + bool showMessage = true, + bool useZeroWidth = false, bool useReadableColors = false, Timestamp timestamp = Timestamp.none, }) { @@ -258,7 +258,7 @@ class IRCMessage { // Italicize the text it was called with an IRC Action i.e., "/me". final textStyle = action == true ? const TextStyle(fontStyle: FontStyle.italic) : style; - if (hideMessage) { + if (!showMessage) { span.add(const TextSpan(text: ' ')); } else { // Add the message and any emotes to the span. @@ -267,7 +267,7 @@ class IRCMessage { final words = chatMessage.split(' '); words.removeWhere((element) => element == ''); - if (zeroWidthEnabled) { + if (useZeroWidth) { final localSpan = []; var index = words.length - 1; diff --git a/lib/screens/channel/chat/chat_message.dart b/lib/screens/channel/chat/chat_message.dart index d09e5938..fbf9c93a 100644 --- a/lib/screens/channel/chat/chat_message.dart +++ b/lib/screens/channel/chat/chat_message.dart @@ -42,7 +42,7 @@ class ChatMessage extends StatelessWidget { sevenTVUserToBadges: assetsStore.userTo7TVBadges, bttvUserToBadge: assetsStore.userToBTTVBadges, ffzRoomInfo: assetsStore.ffzRoomInfo, - zeroWidthEnabled: settingsStore.showZeroWidth, + useZeroWidth: settingsStore.showZeroWidth, useReadableColors: settingsStore.useReadableColors, timestamp: timeStamps, ), @@ -81,8 +81,8 @@ class ChatMessage extends StatelessWidget { sevenTVUserToBadges: assetsStore.userTo7TVBadges, bttvUserToBadge: assetsStore.userToBTTVBadges, ffzRoomInfo: assetsStore.ffzRoomInfo, - hideMessage: settingsStore.hideBannedMessages, - zeroWidthEnabled: settingsStore.showZeroWidth, + showMessage: settingsStore.showDeletedMessages, + useZeroWidth: settingsStore.showZeroWidth, useReadableColors: settingsStore.useReadableColors, timestamp: timeStamps, ), @@ -135,7 +135,7 @@ class ChatMessage extends StatelessWidget { sevenTVUserToBadges: assetsStore.userTo7TVBadges, bttvUserToBadge: assetsStore.userToBTTVBadges, ffzRoomInfo: assetsStore.ffzRoomInfo, - zeroWidthEnabled: settingsStore.showZeroWidth, + useZeroWidth: settingsStore.showZeroWidth, useReadableColors: settingsStore.useReadableColors, timestamp: timeStamps, ), diff --git a/lib/screens/settings/chat_settings.dart b/lib/screens/settings/chat_settings.dart index 04f5f2e6..3db6098f 100644 --- a/lib/screens/settings/chat_settings.dart +++ b/lib/screens/settings/chat_settings.dart @@ -17,18 +17,16 @@ class ChatSettings extends StatelessWidget { children: [ const SectionHeader('Chat'), SwitchListTile.adaptive( - isThreeLine: true, - title: const Text('Use more readable colors for chat names'), - subtitle: const Text('Attempts to make names more readable by boosting the lightness of darker colors.'), - value: settingsStore.useReadableColors, - onChanged: (newValue) => settingsStore.useReadableColors = newValue, + title: const Text('Show deleted messages'), + value: settingsStore.showDeletedMessages, + onChanged: (newValue) => settingsStore.showDeletedMessages = newValue, ), SwitchListTile.adaptive( isThreeLine: true, - title: const Text('Hide banned and deleted messages'), - subtitle: const Text('Replaces deleted, timed-out, and banned user messages with "".'), - value: settingsStore.hideBannedMessages, - onChanged: (newValue) => settingsStore.hideBannedMessages = newValue, + title: const Text('Use readable colors for chat names'), + subtitle: const Text('Make chat names more readable by boosting the lightness of darker colors.'), + value: settingsStore.useReadableColors, + onChanged: (newValue) => settingsStore.useReadableColors = newValue, ), SwitchListTile.adaptive( isThreeLine: true, @@ -39,8 +37,8 @@ class ChatSettings extends StatelessWidget { ), SwitchListTile.adaptive( isThreeLine: true, - title: const Text('Show timestamps'), - subtitle: const Text('Displays 24-hour timestamps for when a chat message was sent.'), + title: const Text('Show message timestamps'), + subtitle: const Text('Displays timestamps for when a chat message was sent.'), value: settingsStore.showTimestamps, onChanged: (newValue) => settingsStore.showTimestamps = newValue, ), diff --git a/lib/screens/settings/other_settings.dart b/lib/screens/settings/other_settings.dart new file mode 100644 index 00000000..cb9357c8 --- /dev/null +++ b/lib/screens/settings/other_settings.dart @@ -0,0 +1,49 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_cache_manager/flutter_cache_manager.dart'; +import 'package:frosty/screens/settings/stores/settings_store.dart'; +import 'package:frosty/widgets/section_header.dart'; + +class OtherSettings extends StatelessWidget { + final SettingsStore settingsStore; + const OtherSettings({ + Key? key, + required this.settingsStore, + }) : super(key: key); + + @override + Widget build(BuildContext context) { + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + const SectionHeader('Other'), + ListTile( + leading: const Icon(Icons.info), + title: const Text('About'), + onTap: () => showAboutDialog( + context: context, + applicationName: 'Frosty for Twitch', + applicationVersion: '1.0.0', + applicationLegalese: '\u{a9} 2021 Tommy Chow', + ), + ), + Container( + padding: const EdgeInsets.all(10.0), + width: double.infinity, + child: OutlinedButton( + style: OutlinedButton.styleFrom(), + child: const Text('Clear Image Cache'), + onPressed: () async { + await DefaultCacheManager().emptyCache(); + ScaffoldMessenger.of(context).showSnackBar( + const SnackBar( + content: Text('Image cache cleared!'), + behavior: SnackBarBehavior.floating, + ), + ); + }, + ), + ), + ], + ); + } +} diff --git a/lib/screens/settings/settings.dart b/lib/screens/settings/settings.dart index 68e5e2d5..5929812e 100644 --- a/lib/screens/settings/settings.dart +++ b/lib/screens/settings/settings.dart @@ -3,9 +3,9 @@ import 'package:frosty/core/auth/auth_store.dart'; import 'package:frosty/screens/settings/account/account_settings.dart'; import 'package:frosty/screens/settings/chat_settings.dart'; import 'package:frosty/screens/settings/general_settings.dart'; +import 'package:frosty/screens/settings/other_settings.dart'; import 'package:frosty/screens/settings/stores/settings_store.dart'; import 'package:frosty/screens/settings/video_settings.dart'; -import 'package:frosty/widgets/section_header.dart'; import 'package:provider/provider.dart'; class Settings extends StatelessWidget { @@ -22,21 +22,14 @@ class Settings extends StatelessWidget { body: SafeArea( child: ListView( children: [ - AccountSettings(settingsStore: settingsStore, authStore: context.read()), + AccountSettings( + settingsStore: settingsStore, + authStore: context.read(), + ), GeneralSettings(settingsStore: settingsStore), VideoSettings(settingsStore: settingsStore), ChatSettings(settingsStore: settingsStore), - const SectionHeader('Other'), - ListTile( - leading: const Icon(Icons.info), - title: const Text('About'), - onTap: () => showAboutDialog( - context: context, - applicationName: 'Frosty for Twitch', - applicationVersion: '1.0.0', - applicationLegalese: '\u{a9} 2021 Tommy Chow', - ), - ) + OtherSettings(settingsStore: settingsStore), ], ), ), diff --git a/lib/screens/settings/stores/settings_store.dart b/lib/screens/settings/stores/settings_store.dart index c4398da7..a2f7ea75 100644 --- a/lib/screens/settings/stores/settings_store.dart +++ b/lib/screens/settings/stores/settings_store.dart @@ -32,7 +32,7 @@ abstract class _SettingsStoreBase with Store { var useReadableColors = false; @observable - var hideBannedMessages = false; + var showDeletedMessages = false; @observable var showZeroWidth = false; diff --git a/lib/screens/settings/stores/settings_store.g.dart b/lib/screens/settings/stores/settings_store.g.dart index c59ef127..2a73b5d5 100644 --- a/lib/screens/settings/stores/settings_store.g.dart +++ b/lib/screens/settings/stores/settings_store.g.dart @@ -6,28 +6,26 @@ part of 'settings_store.dart'; // JsonSerializableGenerator // ************************************************************************** -SettingsStore _$SettingsStoreFromJson(Map json) => - SettingsStore() - ..useOledTheme = json['useOledTheme'] as bool - ..showVideo = json['showVideo'] as bool - ..showOverlay = json['showOverlay'] as bool - ..showThumbnailUptime = json['showThumbnailUptime'] as bool - ..useReadableColors = json['useReadableColors'] as bool - ..hideBannedMessages = json['hideBannedMessages'] as bool - ..showZeroWidth = json['showZeroWidth'] as bool - ..showTimestamps = json['showTimestamps'] as bool - ..useTwelveHourTimestamps = json['useTwelveHourTimestamps'] as bool - ..fullScreen = json['fullScreen'] as bool - ..expandInfo = json['expandInfo'] as bool; +SettingsStore _$SettingsStoreFromJson(Map json) => SettingsStore() + ..useOledTheme = json['useOledTheme'] as bool + ..showVideo = json['showVideo'] as bool + ..showOverlay = json['showOverlay'] as bool + ..showThumbnailUptime = json['showThumbnailUptime'] as bool + ..useReadableColors = json['useReadableColors'] as bool + ..showDeletedMessages = json['hideBannedMessages'] as bool + ..showZeroWidth = json['showZeroWidth'] as bool + ..showTimestamps = json['showTimestamps'] as bool + ..useTwelveHourTimestamps = json['useTwelveHourTimestamps'] as bool + ..fullScreen = json['fullScreen'] as bool + ..expandInfo = json['expandInfo'] as bool; -Map _$SettingsStoreToJson(SettingsStore instance) => - { +Map _$SettingsStoreToJson(SettingsStore instance) => { 'useOledTheme': instance.useOledTheme, 'showVideo': instance.showVideo, 'showOverlay': instance.showOverlay, 'showThumbnailUptime': instance.showThumbnailUptime, 'useReadableColors': instance.useReadableColors, - 'hideBannedMessages': instance.hideBannedMessages, + 'hideBannedMessages': instance.showDeletedMessages, 'showZeroWidth': instance.showZeroWidth, 'showTimestamps': instance.showTimestamps, 'useTwelveHourTimestamps': instance.useTwelveHourTimestamps, @@ -87,8 +85,7 @@ mixin _$SettingsStore on _SettingsStoreBase, Store { }); } - final _$showThumbnailUptimeAtom = - Atom(name: '_SettingsStoreBase.showThumbnailUptime'); + final _$showThumbnailUptimeAtom = Atom(name: '_SettingsStoreBase.showThumbnailUptime'); @override bool get showThumbnailUptime { @@ -103,8 +100,7 @@ mixin _$SettingsStore on _SettingsStoreBase, Store { }); } - final _$useReadableColorsAtom = - Atom(name: '_SettingsStoreBase.useReadableColors'); + final _$useReadableColorsAtom = Atom(name: '_SettingsStoreBase.useReadableColors'); @override bool get useReadableColors { @@ -119,19 +115,18 @@ mixin _$SettingsStore on _SettingsStoreBase, Store { }); } - final _$hideBannedMessagesAtom = - Atom(name: '_SettingsStoreBase.hideBannedMessages'); + final _$hideBannedMessagesAtom = Atom(name: '_SettingsStoreBase.hideBannedMessages'); @override - bool get hideBannedMessages { + bool get showDeletedMessages { _$hideBannedMessagesAtom.reportRead(); - return super.hideBannedMessages; + return super.showDeletedMessages; } @override - set hideBannedMessages(bool value) { - _$hideBannedMessagesAtom.reportWrite(value, super.hideBannedMessages, () { - super.hideBannedMessages = value; + set showDeletedMessages(bool value) { + _$hideBannedMessagesAtom.reportWrite(value, super.showDeletedMessages, () { + super.showDeletedMessages = value; }); } @@ -165,8 +160,7 @@ mixin _$SettingsStore on _SettingsStoreBase, Store { }); } - final _$useTwelveHourTimestampsAtom = - Atom(name: '_SettingsStoreBase.useTwelveHourTimestamps'); + final _$useTwelveHourTimestampsAtom = Atom(name: '_SettingsStoreBase.useTwelveHourTimestamps'); @override bool get useTwelveHourTimestamps { @@ -176,8 +170,7 @@ mixin _$SettingsStore on _SettingsStoreBase, Store { @override set useTwelveHourTimestamps(bool value) { - _$useTwelveHourTimestampsAtom - .reportWrite(value, super.useTwelveHourTimestamps, () { + _$useTwelveHourTimestampsAtom.reportWrite(value, super.useTwelveHourTimestamps, () { super.useTwelveHourTimestamps = value; }); } @@ -220,7 +213,7 @@ showVideo: ${showVideo}, showOverlay: ${showOverlay}, showThumbnailUptime: ${showThumbnailUptime}, useReadableColors: ${useReadableColors}, -hideBannedMessages: ${hideBannedMessages}, +hideBannedMessages: ${showDeletedMessages}, showZeroWidth: ${showZeroWidth}, showTimestamps: ${showTimestamps}, useTwelveHourTimestamps: ${useTwelveHourTimestamps},