/// <summary> /// Initializes a new instance of the <see cref="WatchListAndDetailViewModel"/> class. /// </summary> /// <param name="listViewModel">The list view model.</param> /// <param name="detailViewModel">The detail view model.</param> public WatchListAndDetailViewModel(WatchListViewModel listViewModel, WatchListItemDetailViewModel detailViewModel) { ListViewModel = listViewModel; DetailViewModel = detailViewModel; // Set Details OnItemClick _ItemClickSubscription = ListViewModel .ItemClick .Subscribe(i => { if (DetailViewModel.Symbol != i.Symbol) { DetailViewModel.SetWatchListItem(i); } }); }
/// <summary> /// Gets the detail view model. /// </summary> /// <param name="item">The item.</param> /// <returns></returns> public WatchListItemDetailViewModel GetDetailViewModel(WatchListItemViewModel item) { if (item == null) { return(null); } WatchListItemDetailViewModel detailModel = null; var detailViewModelPath = string.Format("/WatchList/Detail?symbol={0}", item.Symbol); if (ViewModelPool.ContainsKey(detailViewModelPath)) { this.Log().Debug("GetDetailViewModel({0}) => from pool", item.Symbol); detailModel = ViewModelPool[detailViewModelPath].Item1 as WatchListItemDetailViewModel; } else { // Create new this.Log().Debug("GetDetailViewModel({0}) => create new", item.Symbol); detailModel = new WatchListItemDetailViewModel(item); ViewModelPool.Add(detailViewModelPath, Tuple.Create <IRoutableViewModel, IRoutingParams>(detailModel, null)); } return(detailModel); }
/// <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> /// Gets the detail view model. /// </summary> /// <param name="item">The item.</param> /// <returns></returns> public WatchListItemDetailViewModel GetDetailViewModel(WatchListItemViewModel item) { if (item == null) return null; WatchListItemDetailViewModel detailModel = null; var detailViewModelPath = string.Format("/WatchList/Detail?symbol={0}", item.Symbol); if (ViewModelPool.ContainsKey(detailViewModelPath)) { this.Log().Debug("GetDetailViewModel({0}) => from pool", item.Symbol); detailModel = ViewModelPool[detailViewModelPath].Item1 as WatchListItemDetailViewModel; } else { // Create new this.Log().Debug("GetDetailViewModel({0}) => create new", item.Symbol); detailModel = new WatchListItemDetailViewModel(item); ViewModelPool.Add(detailViewModelPath, Tuple.Create<IRoutableViewModel, IRoutingParams>(detailModel, null)); } return detailModel; }