예제 #1
0
        /// <summary>
        /// Handels the navigate subscription and if nessesary transforms the viewmodel depending on the device / orientation
        /// </summary>
        /// <param name="routableView">The routable view.</param>
        public void OnNavigate(object routableView)
        {
            var viewModelWithParams = routableView.AsRoutableViewModel <IRoutableViewModel>();

            if (viewModelWithParams != null)
            {
                var viewModel = viewModelWithParams.Item1;
                this.Log().Debug("OnNavigate({0}) - {1}", viewModel, Platform.GetOrientationEnum());

                // Check if Tablet and ViewMode (Portrait or Landscapemode)
                if (Platform.DeviceType == DeviceType.Tablet && Platform.GetOrientationEnum() == DeviceOrientation.Landscape)
                {
                    if (typeof(WatchListItemDetailViewModel) == viewModel.GetType())
                    {
                        // View Detail in Landscapemode (List / Detail)
                        var listModel   = ViewModelPool["WatchList"].Item1 as WatchListViewModel; // we know that the model is there
                        var detailModel = viewModel as WatchListItemDetailViewModel;
                        if (ViewModelPool.ContainsKey(detailModel.UrlPathSegment))
                        {
                            detailModel = ViewModelPool[detailModel.UrlPathSegment].Item1 as WatchListItemDetailViewModel;
                        }
                        else
                        {
                            ViewModelPool.Add(detailModel.UrlPathSegment, viewModelWithParams);
                        }

                        viewModel = new WatchListAndDetailViewModel(listModel, detailModel);
                    }
                    if (typeof(WatchListViewModel) == viewModel.GetType())
                    {
                        // View Detail in Landscapemode (List / Detail)
                        var listModel = ViewModelPool["WatchList"].Item1 as WatchListViewModel; // we know that the model is there
                        WatchListItemDetailViewModel detailModel = null;
                        // Check SelectedItem
                        if (listModel.SelectedItem != null)
                        {
                            detailModel = GetDetailViewModel(listModel.SelectedItem);
                        }
                        else
                        {
                            detailModel = GetDetailViewModel(listModel.WatchList.FirstOrDefault());
                        }

                        viewModel = new WatchListAndDetailViewModel(listModel, detailModel);
                    }
                }

                // Set Tab active
                if (!String.IsNullOrEmpty(viewModel.UrlPathSegment))
                {
                    if (pathPattern.IsMatch(viewModel.UrlPathSegment))
                    {
                        var match   = pathPattern.Match(viewModel.UrlPathSegment);
                        var tabType = match.Groups["tab"].Value.ToLower();
                        if (String.Compare(tabType, "WatchList", StringComparison.OrdinalIgnoreCase) == 0)
                        {
                            RootView.ViewModel.SelectTab(TabType.WatchList, true);
                        }
                        else if (String.Compare(tabType, "Search", StringComparison.OrdinalIgnoreCase) == 0)
                        {
                            RootView.ViewModel.SelectTab(TabType.Search, true);
                        }
                        else if (String.Compare(tabType, "Profile", StringComparison.OrdinalIgnoreCase) == 0)
                        {
                            RootView.ViewModel.SelectTab(TabType.Settings, true);
                        }
                    }
                }

                RootView.OnNavigate(Tuple.Create <IRoutableViewModel, IRoutingParams>(viewModel, viewModelWithParams.Item2));
            }
        }
        /// <summary>
        /// Handels the navigate subscription and if nessesary transforms the viewmodel depending on the device / orientation
        /// </summary>
        /// <param name="routableView">The routable view.</param>
        public void OnNavigate(object routableView)
        {
            var viewModelWithParams = routableView.AsRoutableViewModel<IRoutableViewModel>();
            if (viewModelWithParams != null)
            {
                var viewModel = viewModelWithParams.Item1;
                this.Log().Debug("OnNavigate({0}) - {1}", viewModel, Platform.GetOrientationEnum());

                // Check if Tablet and ViewMode (Portrait or Landscapemode)
                if (Platform.DeviceType == DeviceType.Tablet && Platform.GetOrientationEnum() == DeviceOrientation.Landscape)
                {
                    if (typeof(WatchListItemDetailViewModel) == viewModel.GetType())
                    {
                        // View Detail in Landscapemode (List / Detail)
                        var listModel = ViewModelPool["WatchList"].Item1 as WatchListViewModel; // we know that the model is there
                        var detailModel = viewModel as WatchListItemDetailViewModel;
                        if (ViewModelPool.ContainsKey(detailModel.UrlPathSegment))
                        {
                            detailModel = ViewModelPool[detailModel.UrlPathSegment].Item1 as WatchListItemDetailViewModel;
                        }
                        else
                        {
                            ViewModelPool.Add(detailModel.UrlPathSegment, viewModelWithParams);
                        }

                        viewModel = new WatchListAndDetailViewModel(listModel, detailModel);
                    }
                    if (typeof(WatchListViewModel) == viewModel.GetType())
                    {
                        // View Detail in Landscapemode (List / Detail)
                        var listModel = ViewModelPool["WatchList"].Item1 as WatchListViewModel; // we know that the model is there
                        WatchListItemDetailViewModel detailModel = null;
                        // Check SelectedItem
                        if (listModel.SelectedItem != null)
                        {
                            detailModel = GetDetailViewModel(listModel.SelectedItem);
                        }
                        else
                        {
                            detailModel = GetDetailViewModel(listModel.WatchList.FirstOrDefault());
                        }

                        viewModel = new WatchListAndDetailViewModel(listModel, detailModel);
                    }
                }

                // Set Tab active
                if (!String.IsNullOrEmpty(viewModel.UrlPathSegment))
                {
                    if (pathPattern.IsMatch(viewModel.UrlPathSegment))
                    {
                        var match = pathPattern.Match(viewModel.UrlPathSegment);
                        var tabType = match.Groups["tab"].Value.ToLower();
                        if (String.Compare(tabType, "WatchList", StringComparison.OrdinalIgnoreCase) == 0)
                        {
                            RootView.ViewModel.SelectTab(TabType.WatchList, true);
                        }
                        else if (String.Compare(tabType, "Search", StringComparison.OrdinalIgnoreCase) == 0)
                        {
                            RootView.ViewModel.SelectTab(TabType.Search, true);
                        }
                        else if (String.Compare(tabType, "Profile", StringComparison.OrdinalIgnoreCase) == 0)
                        {
                            RootView.ViewModel.SelectTab(TabType.Settings, true);
                        }
                    }
                }

                RootView.OnNavigate(Tuple.Create<IRoutableViewModel, IRoutingParams>(viewModel, viewModelWithParams.Item2));

            }
        }