public MainWindowViewModel(ConfigurationManager cfg, ServerStatusCache statusCache, Updater updater)
        {
            _cfg     = cfg;
            _updater = updater;

            var servers = new ServerListTabViewModel(cfg, statusCache, updater);
            var news    = new NewsTabViewModel();
            var options = new OptionsTabViewModel(cfg);
            var home    = new HomePageViewModel(cfg, statusCache, updater);

            Tabs = new MainWindowTabViewModel[]
            {
                home,
                servers,
                news,
                options
            };

            this.WhenAnyValue(x => x.SelectedIndex).Subscribe(i => Tabs[i].Selected());

            this.WhenAnyValue(x => x._cfg.UserName)
            .Subscribe(_ =>
            {
                this.RaisePropertyChanged(nameof(Username));
                this.RaisePropertyChanged(nameof(LoggedIn));
                this.RaisePropertyChanged(nameof(LoginText));
                this.RaisePropertyChanged(nameof(ManageAccountText));
            });

            AccountDropDown = new AccountDropDownViewModel(cfg);
            LoginViewModel  = new MainWindowLoginViewModel(cfg);
        }
Example #2
0
        public MainWindowViewModel(DataManager cfg, ServerStatusCache statusCache, Updater updater)
        {
            _cfg = cfg;
            var authApi = new AuthApi(cfg);

            _loginMgr = new LoginManager(cfg, authApi);

            ServersTab = new ServerListTabViewModel(cfg, statusCache, updater, _loginMgr);
            NewsTab    = new NewsTabViewModel();
            HomeTab    = new HomePageViewModel(this, cfg, statusCache, updater, _loginMgr);
            OptionsTab = new OptionsTabViewModel(cfg);

            Tabs = new MainWindowTabViewModel[]
            {
                HomeTab,
                ServersTab,
                NewsTab,
                OptionsTab
            };

            AccountDropDown = new AccountDropDownViewModel(this, cfg, authApi, _loginMgr);
            LoginViewModel  = new MainWindowLoginViewModel(cfg, authApi, _loginMgr);

            this.WhenAnyValue(x => x.SelectedIndex).Subscribe(i => Tabs[i].Selected());

            this.WhenAnyValue(x => x._loginMgr.ActiveAccount)
            .Subscribe(s =>
            {
                this.RaisePropertyChanged(nameof(Username));
                this.RaisePropertyChanged(nameof(LoggedIn));
                this.RaisePropertyChanged(nameof(LoginText));
                this.RaisePropertyChanged(nameof(ManageAccountText));
            });

            _cfg.Logins.Connect()
            .Subscribe(_ => { this.RaisePropertyChanged(nameof(AccountDropDownVisible)); });

            // If we leave the login view model (by an account getting selected)
            // we reset it to login state
            this.WhenAnyValue(x => x.LoggedIn)
            .DistinctUntilChanged()     // Only when change.
            .Where(p => !p)
            .Subscribe(x => LoginViewModel.SwitchToLogin());
        }
Example #3
0
        public MainWindowViewModel()
        {
            _cfg      = Locator.Current.GetService <DataManager>();
            _loginMgr = Locator.Current.GetService <LoginManager>();
            _http     = Locator.Current.GetService <HttpClient>();

            ServersTab = new ServerListTabViewModel(this);
            NewsTab    = new NewsTabViewModel();
            HomeTab    = new HomePageViewModel(this);
            OptionsTab = new OptionsTabViewModel();

            Tabs = new MainWindowTabViewModel[]
            {
                HomeTab,
                ServersTab,
                NewsTab,
                OptionsTab
            };

            AccountDropDown = new AccountDropDownViewModel(this);
            LoginViewModel  = new MainWindowLoginViewModel();

            this.WhenAnyValue(x => x.SelectedIndex).Subscribe(i => Tabs[i].Selected());

            this.WhenAnyValue(x => x._loginMgr.ActiveAccount)
            .Subscribe(s =>
            {
                this.RaisePropertyChanged(nameof(Username));
                this.RaisePropertyChanged(nameof(LoggedIn));
                this.RaisePropertyChanged(nameof(LoginText));
                this.RaisePropertyChanged(nameof(ManageAccountText));
            });

            _cfg.Logins.Connect()
            .Subscribe(_ => { this.RaisePropertyChanged(nameof(AccountDropDownVisible)); });

            // If we leave the login view model (by an account getting selected)
            // we reset it to login state
            this.WhenAnyValue(x => x.LoggedIn)
            .DistinctUntilChanged()     // Only when change.
            .Where(p => !p)
            .Subscribe(x => LoginViewModel.SwitchToLogin());
        }