Exemple #1
0
    public MainViewModel()
    {
        _windowState  = (WindowState)Enum.Parse(typeof(WindowState), Services.UiConfig.WindowState);
        _windowWidth  = Services.UiConfig.WindowWidth ?? 1280;
        _windowHeight = Services.UiConfig.WindowHeight ?? 960;

        var(x, y) = (Services.UiConfig.WindowX, Services.UiConfig.WindowY);
        if (x != null && y != null)
        {
            _windowPosition = new PixelPoint(x.Value, y.Value);
        }

        _dialogScreen = new DialogScreenViewModel();

        _fullScreen = new DialogScreenViewModel(NavigationTarget.FullScreen);

        _compactDialogScreen = new DialogScreenViewModel(NavigationTarget.CompactDialogScreen);

        MainScreen = new TargettedNavigationStack(NavigationTarget.HomeScreen);

        NavigationState.Register(MainScreen, DialogScreen, FullScreen, CompactDialogScreen);

        _isMainContentEnabled  = true;
        _isDialogScreenEnabled = true;
        _isFullScreenEnabled   = true;

        _statusBar = new StatusBarViewModel();

        UiServices.Initialize();

        _addWalletPage = new AddWalletPageViewModel();
        _settingsPage  = new SettingsPageViewModel();
        _privacyMode   = new PrivacyModeViewModel();
        _navBar        = new NavBarViewModel(MainScreen);

        MusicControls = new MusicControlsViewModel();

        NavigationManager.RegisterType(_navBar);
        RegisterViewModels();

        RxApp.MainThreadScheduler.Schedule(async() => await _navBar.InitialiseAsync());

        this.WhenAnyValue(x => x.WindowState, x => x.WindowPosition, x => x.WindowWidth, x => x.WindowHeight)
        .Where(x => x.Item1 != WindowState.Minimized)
        .Where(x => x.Item2 != new PixelPoint(-32000, -32000))                 // value when minimized
        .ObserveOn(RxApp.MainThreadScheduler)
        .Subscribe(t =>
        {
            var(state, position, width, height) = t;

            Services.UiConfig.WindowState = state.ToString();
            if (position is { })
            {
                Services.UiConfig.WindowX = position.Value.X;
                Services.UiConfig.WindowY = position.Value.Y;
            }

            Services.UiConfig.WindowWidth  = width;
            Services.UiConfig.WindowHeight = height;
        });
    public MainViewModel()
    {
        _windowState  = (WindowState)Enum.Parse(typeof(WindowState), Services.UiConfig.WindowState);
        _dialogScreen = new DialogScreenViewModel();

        _fullScreen = new DialogScreenViewModel(NavigationTarget.FullScreen);

        _compactDialogScreen = new DialogScreenViewModel(NavigationTarget.CompactDialogScreen);

        MainScreen = new TargettedNavigationStack(NavigationTarget.HomeScreen);

        NavigationState.Register(MainScreen, DialogScreen, FullScreen, CompactDialogScreen);

        _isMainContentEnabled  = true;
        _isDialogScreenEnabled = true;
        _isFullScreenEnabled   = true;

        _statusBar = new StatusBarViewModel();

        UiServices.Initialize();

        _addWalletPage = new AddWalletPageViewModel();
        _settingsPage  = new SettingsPageViewModel();
        _privacyMode   = new PrivacyModeViewModel();
        _searchPage    = new SearchPageViewModel();
        _navBar        = new NavBarViewModel(MainScreen);

        MusicControls = new MusicControlsViewModel();

        NavigationManager.RegisterType(_navBar);

        RegisterCategories(_searchPage);
        RegisterViewModels();

        RxApp.MainThreadScheduler.Schedule(async() => await _navBar.InitialiseAsync());

        _searchPage.Initialise();

        this.WhenAnyValue(x => x.WindowState)
        .Where(x => x != WindowState.Minimized)
        .ObserveOn(RxApp.MainThreadScheduler)
        .Subscribe(windowState => Services.UiConfig.WindowState = windowState.ToString());

        this.WhenAnyValue(
            x => x.DialogScreen !.IsDialogOpen,
            x => x.FullScreen !.IsDialogOpen,
            x => x.CompactDialogScreen !.IsDialogOpen)
        .ObserveOn(RxApp.MainThreadScheduler)
        .Subscribe(tup =>
        {
            var(dialogScreenIsOpen, fullScreenIsOpen, compactDialogScreenIsOpen) = tup;

            IsMainContentEnabled = !(dialogScreenIsOpen || fullScreenIsOpen || compactDialogScreenIsOpen);
        });

        this.WhenAnyValue(
            x => x.DialogScreen.CurrentPage,
            x => x.CompactDialogScreen.CurrentPage,
            x => x.FullScreen.CurrentPage,
            x => x.MainScreen.CurrentPage)
        .ObserveOn(RxApp.MainThreadScheduler)
        .Subscribe(tup =>
        {
            var(dialog, compactDialog, fullscreenDialog, mainsScreen) = tup;

            /*
             * Order is important.
             * Always the topmost content will be the active one.
             */

            if (compactDialog is { })
            {
                compactDialog.SetActive();
                return;
            }

            if (dialog is { })