diff --git a/lib/core/settings/settings.dart b/lib/core/settings/settings.dart index 76f51a47..95262074 100644 --- a/lib/core/settings/settings.dart +++ b/lib/core/settings/settings.dart @@ -45,6 +45,11 @@ class Settings extends StatelessWidget { value: settingsStore.videoEnabled, onChanged: (newValue) => settingsStore.videoEnabled = newValue, ), + SwitchListTile.adaptive( + title: const Text('Enable Video Overlay'), + value: settingsStore.overlayEnabled, + onChanged: (newValue) => settingsStore.overlayEnabled = newValue, + ), SwitchListTile.adaptive( title: const Text('Hide Banned Messages'), value: settingsStore.hideBannedMessages, diff --git a/lib/core/settings/settings_store.dart b/lib/core/settings/settings_store.dart index 7ba656d0..35ebb65f 100644 --- a/lib/core/settings/settings_store.dart +++ b/lib/core/settings/settings_store.dart @@ -10,6 +10,9 @@ abstract class _SettingsStoreBase with Store { @observable var videoEnabled = true; + @observable + var overlayEnabled = true; + @observable var messageLimit = 200.0; @@ -25,6 +28,7 @@ abstract class _SettingsStoreBase with Store { // Initialize settings from stored preferences if any. videoEnabled = prefs.getBool('video_enabled') ?? videoEnabled; + overlayEnabled = prefs.getBool('overlay_enabled') ?? overlayEnabled; messageLimit = prefs.getDouble('message_limit') ?? messageLimit; hideBannedMessages = prefs.getBool('hide_banned_messages') ?? hideBannedMessages; zeroWidthEnabled = prefs.getBool('zero_width_enabled') ?? zeroWidthEnabled; @@ -34,6 +38,7 @@ abstract class _SettingsStoreBase with Store { autorun((_) { debugPrint('settings changed'); prefs.setBool('video_enabled', videoEnabled); + prefs.setBool('overlay_enabled', overlayEnabled); prefs.setDouble('message_limit', messageLimit); prefs.setBool('hide_banned_messages', hideBannedMessages); prefs.setBool('zero_width_enabled', zeroWidthEnabled); diff --git a/lib/core/settings/settings_store.g.dart b/lib/core/settings/settings_store.g.dart index b18dac01..86b6054d 100644 --- a/lib/core/settings/settings_store.g.dart +++ b/lib/core/settings/settings_store.g.dart @@ -24,6 +24,21 @@ mixin _$SettingsStore on _SettingsStoreBase, Store { }); } + final _$overlayEnabledAtom = Atom(name: '_SettingsStoreBase.overlayEnabled'); + + @override + bool get overlayEnabled { + _$overlayEnabledAtom.reportRead(); + return super.overlayEnabled; + } + + @override + set overlayEnabled(bool value) { + _$overlayEnabledAtom.reportWrite(value, super.overlayEnabled, () { + super.overlayEnabled = value; + }); + } + final _$messageLimitAtom = Atom(name: '_SettingsStoreBase.messageLimit'); @override @@ -75,6 +90,7 @@ mixin _$SettingsStore on _SettingsStoreBase, Store { String toString() { return ''' videoEnabled: ${videoEnabled}, +overlayEnabled: ${overlayEnabled}, messageLimit: ${messageLimit}, hideBannedMessages: ${hideBannedMessages}, zeroWidthEnabled: ${zeroWidthEnabled} diff --git a/lib/screens/channel/video/video.dart b/lib/screens/channel/video/video.dart index ba31a9fb..8544d7e4 100644 --- a/lib/screens/channel/video/video.dart +++ b/lib/screens/channel/video/video.dart @@ -1,7 +1,10 @@ import 'package:flutter/material.dart'; import 'package:flutter/widgets.dart'; +import 'package:flutter_mobx/flutter_mobx.dart'; +import 'package:frosty/core/settings/settings_store.dart'; import 'package:frosty/screens/channel/video/video_overlay.dart'; import 'package:frosty/screens/channel/video/video_store.dart'; +import 'package:provider/provider.dart'; import 'package:webview_flutter/webview_flutter.dart'; class Video extends StatelessWidget { @@ -20,26 +23,39 @@ class Video extends StatelessWidget { @override Widget build(BuildContext context) { - return Stack( - children: [ - WebView( - initialUrl: 'https://player.twitch.tv/?channel=$userLogin&controls=false&muted=false&parent=frosty', - javascriptMode: JavascriptMode.unrestricted, - allowsInlineMediaPlayback: true, - initialMediaPlaybackPolicy: AutoMediaPlaybackPolicy.always_allow, - onWebViewCreated: (controller) { - videoStore.controller = controller; - }, - onPageFinished: (string) { - videoStore.initVideo(); - }, - ), - VideoOverlay( - title: title, - userName: userName, - videoStore: videoStore, - ), - ], + return Observer( + builder: (context) { + if (context.read().overlayEnabled) { + return Stack( + children: [ + WebView( + initialUrl: 'https://player.twitch.tv/?channel=$userLogin&controls=false&muted=false&parent=frosty', + javascriptMode: JavascriptMode.unrestricted, + allowsInlineMediaPlayback: true, + initialMediaPlaybackPolicy: AutoMediaPlaybackPolicy.always_allow, + onWebViewCreated: (controller) { + videoStore.controller = controller; + }, + onPageFinished: (string) { + videoStore.initVideo(); + }, + ), + VideoOverlay( + title: title, + userName: userName, + videoStore: videoStore, + ), + ], + ); + } else { + return WebView( + initialUrl: 'https://player.twitch.tv/?channel=$userLogin&muted=false&parent=frosty', + javascriptMode: JavascriptMode.unrestricted, + allowsInlineMediaPlayback: true, + initialMediaPlaybackPolicy: AutoMediaPlaybackPolicy.always_allow, + ); + } + }, ); } } diff --git a/lib/screens/channel/video_chat.dart b/lib/screens/channel/video_chat.dart index 638603b1..3a4ddd34 100644 --- a/lib/screens/channel/video_chat.dart +++ b/lib/screens/channel/video_chat.dart @@ -28,7 +28,7 @@ class VideoChat extends StatelessWidget { child: Column( children: [ Observer( - builder: (_) { + builder: (context) { if (context.read().videoEnabled) { return AspectRatio( aspectRatio: 16 / 9, @@ -51,17 +51,15 @@ class VideoChat extends StatelessWidget { actions: [ IconButton( icon: const Icon(Icons.settings), - onPressed: () { - Navigator.push( - context, - MaterialPageRoute( - fullscreenDialog: true, - builder: (context) { - return Settings(settingsStore: context.read()); - }, - ), - ); - }, + onPressed: () => Navigator.push( + context, + MaterialPageRoute( + fullscreenDialog: true, + builder: (context) { + return Settings(settingsStore: context.read()); + }, + ), + ), ), ], );