Exemple #1
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());
        }
Exemple #2
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());
        }