Line data Source code
1 : import 'dart:async'; 2 : 3 : import 'package:cwtch/config.dart'; 4 : import 'package:flutter/widgets.dart'; 5 : 6 : enum ModalState { none, storageMigration, shutdown } 7 : 8 : class AppState extends ChangeNotifier { 9 : bool cwtchInit = false; 10 : ModalState modalState = ModalState.none; 11 : bool cwtchIsClosing = false; 12 : String appError = ""; 13 : String? _selectedProfile; 14 : int? _selectedConversation; 15 : int? _selectedSearchMessage; 16 : int _initialScrollIndex = 0; 17 : bool _unreadMessagesBelow = false; 18 : bool _disableFilePicker = false; 19 : bool _focus = true; 20 : 21 : StreamController<bool> _profilesUnreadNotifyControler = StreamController<bool>(); 22 : late Stream<bool> profilesUnreadNotify; 23 : 24 0 : AppState() { 25 0 : profilesUnreadNotify = _profilesUnreadNotifyControler.stream.asBroadcastStream(); 26 : } 27 : 28 0 : void SetCwtchInit() { 29 0 : cwtchInit = true; 30 0 : notifyListeners(); 31 : } 32 : 33 0 : void SetAppError(String error) { 34 0 : appError = error; 35 0 : EnvironmentConfig.debugLog("App Error: $appError"); 36 0 : notifyListeners(); 37 : } 38 : 39 0 : void SetModalState(ModalState newState) { 40 0 : modalState = newState; 41 0 : EnvironmentConfig.debugLog("Modal State: $newState"); 42 0 : notifyListeners(); 43 : } 44 : 45 0 : String? get selectedProfile => _selectedProfile; 46 0 : set selectedProfile(String? newVal) { 47 0 : this._selectedConversation = null; 48 0 : this._selectedProfile = newVal; 49 0 : notifyListeners(); 50 : } 51 : 52 0 : int? get selectedConversation => _selectedConversation; 53 0 : set selectedConversation(int? newVal) { 54 0 : this._selectedConversation = newVal; 55 0 : notifyListeners(); 56 : } 57 : 58 0 : int? get selectedSearchMessage => _selectedSearchMessage; 59 0 : set selectedSearchMessage(int? newVal) { 60 0 : this._selectedSearchMessage = newVal; 61 0 : notifyListeners(); 62 : } 63 : 64 0 : bool get disableFilePicker => _disableFilePicker; 65 0 : set disableFilePicker(bool newVal) { 66 0 : this._disableFilePicker = newVal; 67 0 : notifyListeners(); 68 : } 69 : 70 0 : bool get unreadMessagesBelow => _unreadMessagesBelow; 71 0 : set unreadMessagesBelow(bool newVal) { 72 0 : this._unreadMessagesBelow = newVal; 73 0 : notifyListeners(); 74 : } 75 : 76 0 : int get initialScrollIndex => _initialScrollIndex; 77 0 : set initialScrollIndex(int newVal) { 78 0 : this._initialScrollIndex = newVal; 79 0 : notifyListeners(); 80 : } 81 : 82 0 : bool get focus => _focus; 83 0 : set focus(bool newVal) { 84 0 : _focus = newVal; 85 0 : notifyListeners(); 86 : } 87 : 88 0 : bool isLandscape(BuildContext c) => MediaQuery.of(c).size.width > MediaQuery.of(c).size.height; 89 : 90 0 : void notifyProfileUnread() { 91 0 : _profilesUnreadNotifyControler.add(true); 92 : } 93 : 94 0 : Stream<bool> getUnreadProfileNotifyStream() { 95 0 : return profilesUnreadNotify; 96 : } 97 : }