Ejemplo n.º 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;
        });
Ejemplo n.º 2
0
    public WelcomePageViewModel(AddWalletPageViewModel addWalletPage)
    {
        _addWalletPage = addWalletPage;

        SetupCancel(enableCancel: false, enableCancelOnEscape: false, enableCancelOnPressed: false);

        SelectedIndex = 0;
        NextCommand   = ReactiveCommand.Create(OnNext);

        this.WhenAnyValue(x => x.SelectedIndex)
        .Subscribe(x =>
        {
            NextLabel     = x < NumberOfPages - 1 ? "Continue" : "Get Started";
            EnableNextKey = x < NumberOfPages - 1;
        });

        this.WhenAnyValue(x => x.IsActive)
        .Skip(1)
        .Where(x => !x)
        .Subscribe(x => EnableNextKey = false);
    }
Ejemplo n.º 3
0
    public WelcomePageViewModel(AddWalletPageViewModel addWalletPage)
    {
        SetupCancel(enableCancel: false, enableCancelOnEscape: false, enableCancelOnPressed: false);
        EnableBack = false;

        GetStartedCommand = ReactiveCommand.Create(() =>
        {
            if (!Services.WalletManager.HasWallet())
            {
                Navigate().To(addWalletPage);
            }
            else
            {
                Close();
            }
        });

        SelectedIndex = 0;

        NextCommand = ReactiveCommand.Create(() => SelectedIndex++, this.WhenAnyValue(x => x.SelectedIndex).Select(c => c < NumberOfPages - 1));
        PrevCommand = ReactiveCommand.Create(() => SelectedIndex--, this.WhenAnyValue(x => x.SelectedIndex).Select(c => c > 0));
    }
Ejemplo n.º 4
0
        public NavBarViewModel(NavigationStateViewModel navigationState, RoutingState router, WalletManagerViewModel walletManager, AddWalletPageViewModel addWalletPage)
        {
            Router         = router;
            _walletManager = walletManager;
            _topItems      = new ObservableCollection <NavBarItemViewModel>();
            _bottomItems   = new ObservableCollection <NavBarItemViewModel>();


            SelectedItem = new HomePageViewModel(navigationState, walletManager, addWalletPage);
            _topItems.Add(SelectedItem);
            _bottomItems.Add(addWalletPage);
            _bottomItems.Add(new SettingsPageViewModel(navigationState));

            Router.CurrentViewModel
            .OfType <NavBarItemViewModel>()
            .Subscribe(
                x =>
            {
                if (walletManager.Items.Contains(x) || _topItems.Contains(x) || _bottomItems.Contains(x))
                {
                    if (!_isNavigating)
                    {
                        _isNavigating = true;
                        SelectedItem  = x;
                        _isNavigating = false;
                    }
                }
            });

            this.WhenAnyValue(x => x.SelectedItem)
            .OfType <NavBarItemViewModel>()
            .Subscribe(
                x =>
            {
                if (!_isNavigating)
                {
                    _isNavigating = true;
                    x.NavigateToSelfAndReset();
                    CollapseOnClickAction?.Invoke();

                    _isNavigating = false;
                }
            });

            Observable.FromEventPattern(Router.NavigationStack, nameof(Router.NavigationStack.CollectionChanged))
            .ObserveOn(RxApp.MainThreadScheduler)
            .Subscribe(_ => IsBackButtonVisible = Router.NavigationStack.Count > 1);

            this.WhenAnyValue(x => x.IsOpen)
            .Subscribe(x => SelectedItem.IsExpanded = x);
        }
Ejemplo n.º 5
0
        public SearchPageViewModel(NavigationStateViewModel navigationState, WalletManagerViewModel walletManager, AddWalletPageViewModel addWalletPage, SettingsPageViewModel settingsPage, HomePageViewModel homePage) : base(navigationState)
        {
            Title = "Search";

            _showSettings = true;
            _showWallets  = false;

            var generalCategory       = new SearchCategory("General", 0);
            var generalCategorySource = new SourceList <SearchItemViewModel>();

            generalCategorySource.Add(CreateHomeSearchItem(generalCategory, 0, homePage));
            generalCategorySource.Add(CreateSettingsSearchItem(generalCategory, 1, settingsPage));
            generalCategorySource.Add(CreateAddWalletSearchItem(generalCategory, 2, addWalletPage));

            var settingsCategory       = new SearchCategory("Settings", 1);
            var settingsCategorySource = new SourceList <SearchItemViewModel>();

            settingsCategorySource.AddRange(CreateSettingsSearchItems(settingsCategory, settingsPage));

            var walletCategory = new SearchCategory("Wallets", 2);
            var wallets        = walletManager.Items
                                 .ToObservableChangeSet()
                                 .Transform(x => CreateWalletSearchItem(walletCategory, 0, x))
                                 .Sort(SortExpressionComparer <SearchItemViewModel> .Ascending(i => i.Title));

            var searchItems = generalCategorySource.Connect();

            if (_showSettings)
            {
                searchItems = searchItems.Merge(settingsCategorySource.Connect());
            }

            if (_showWallets)
            {
                searchItems = searchItems.Merge(wallets);
            }

            var queryFilter = this.WhenValueChanged(t => t.SearchQuery)
                              .Throttle(TimeSpan.FromMilliseconds(100))
                              .Select(SearchQueryFilter)
                              .DistinctUntilChanged();

            searchItems
            .Filter(queryFilter)
            .GroupWithImmutableState(x => x.Category)
            .Transform(grouping => new SearchResult(grouping.Key, grouping.Items.OrderBy(x => x.Order).ThenBy(x => x.Title)))
            .Sort(SortExpressionComparer <SearchResult> .Ascending(i => i.Category.Order).ThenByAscending(i => i.Category.Title))
            .ObserveOn(RxApp.MainThreadScheduler)
            .Bind(out _searchResults)
            .AsObservableList();
        }
Ejemplo n.º 6
0
    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);

        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 { })