Inheritance: ViewModelBase, IMergableThing
コード例 #1
0
        public static async Task<ViewModelBase> Previous(LinkViewModel parentLink, ViewModelBase currentActual)
        {
            if (parentLink != null)
            {
                var viewModelContextService = ServiceLocator.Current.GetInstance<IViewModelContextService>();
                var firstRedditViewModel = viewModelContextService.ContextStack.FirstOrDefault(context => context is RedditViewModel) as RedditViewModel;
                if (firstRedditViewModel != null)
                {
                    RepositionContextScroll(parentLink);

                    var imagesService = ServiceLocator.Current.GetInstance<IImagesService>();
                    var offlineService = ServiceLocator.Current.GetInstance<IOfflineService>();
                    var settingsService = ServiceLocator.Current.GetInstance<ISettingsService>();
                    //need to go backwards in time, not paying attention to the unread rules
                    ViewModelBase stackPrevious = null;
                    var emptyForward = LinkHistory.EmptyForward;
                    if (settingsService.OnlyFlipViewUnread && (stackPrevious = LinkHistory.Backward()) != null)
                    {
                        if (emptyForward)
                            LinkHistory.Push(currentActual);

                        return stackPrevious;
                    }
                    else
                    {
                        var currentLinkPos = firstRedditViewModel.Links.IndexOf(parentLink);
                        var linksEnumerator = new NeverEndingRedditView(firstRedditViewModel, currentLinkPos, false);
                        return await MakeContextedTuple(imagesService, offlineService, settingsService, linksEnumerator);
                    }

                }
            }
            return null;
        }
コード例 #2
0
        public static async Task<ViewModelBase> Next(LinkViewModel parentLink, ViewModelBase currentActual)
        {
            if (parentLink != null)
            {
                var viewModelContextService = ServiceLocator.Current.GetInstance<IViewModelContextService>();
                var firstRedditViewModel = viewModelContextService.ContextStack.FirstOrDefault(context => context is RedditViewModel) as RedditViewModel;
                if (firstRedditViewModel != null)
                {
                    RepositionContextScroll(parentLink);

                    var imagesService = ServiceLocator.Current.GetInstance<IImagesService>();
                    var offlineService = ServiceLocator.Current.GetInstance<IOfflineService>();
                    var settingsService = ServiceLocator.Current.GetInstance<ISettingsService>();
                    ViewModelBase stackNext = null;
                    if (settingsService.OnlyFlipViewUnread && (stackNext = LinkHistory.Forward()) != null)
                    {
                        return stackNext;
                    }
                    else
                    {
                        var currentLinkPos = firstRedditViewModel.Links.IndexOf(parentLink);
                        var linksEnumerator = new NeverEndingRedditView(firstRedditViewModel, currentLinkPos, true);
                        var result = await MakeContextedTuple(imagesService, offlineService, settingsService, linksEnumerator);
                        LinkHistory.Push(currentActual);
                        return result;
                    }
                }
            }
            return null;
        }
コード例 #3
0
 public static void RepositionContextScroll(LinkViewModel parentLink)
 {
     var viewModelContextService = ServiceLocator.Current.GetInstance<IViewModelContextService>();
     var firstRedditViewModel = viewModelContextService.ContextStack.FirstOrDefault(context => context is RedditViewModel) as RedditViewModel;
     if (firstRedditViewModel != null)
     {
         firstRedditViewModel.TopVisibleLink = parentLink;
     }
 }
コード例 #4
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            if (e.NavigationMode == NavigationMode.Back)
            {

            }
            else if (e.NavigationMode == NavigationMode.Reset)
            {
                //do nothing we have everything we want already here
            }
            else
            {
                if (!string.IsNullOrWhiteSpace(this.NavigationContext.QueryString["data"]))
                {
                    var unescapedData = HttpUtility.UrlDecode(this.NavigationContext.QueryString["data"]);
                    var deserializedObject = JsonConvert.DeserializeObject<Tuple<Thing, bool>>(unescapedData);
                    if (deserializedObject != null && deserializedObject.Item1.Data is Link)
                    {
                        var vm = new LinkViewModel(deserializedObject.Item1, ServiceLocator.Current.GetInstance<IBaconProvider>(), deserializedObject.Item2);
                        DataContext = vm;
                        if (vm.ContentIsFocused)
                        {
                            FocusContent();
                        }
                        else
                            DefocusContent();
                    }
                }
                else
                {
                    var notificationService = ServiceLocator.Current.GetInstance<INotificationService>();
                    notificationService.CreateNotification("TLDR; something bad happened, send /u/hippiehunter a PM letting us know what you clicked on");
                }
            }
        }
コード例 #5
0
 private static void NavigateToCommentsImpl(LinkViewModel vm)
 {
     vm._navigationService.Navigate(vm._dynamicViewLocator.CommentsView, new SelectCommentTreeMessage {
         LinkThing = vm._linkThing
     });
 }
コード例 #6
0
 private static void GotoLinkImpl(LinkViewModel vm)
 {
     UtilityCommandImpl.GotoLinkImpl(vm.Url);
     vm.RaisePropertyChanged("Url");
 }
コード例 #7
0
 private static void GotoSubredditStatic(LinkViewModel vm)
 {
     vm.GotoSubredditImpl();
 }
コード例 #8
0
 private static void GotoUserStatic(LinkViewModel vm)
 {
     vm.GotoUserImpl();
 }
コード例 #9
0
        private static async void UpdateUsageStatistics(LinkViewModel vm, bool isLink)
        {
            if (vm._linkThing != null)
            {
                var offlineService = ServiceLocator.Current.GetInstance<IOfflineService>();

                await offlineService.IncrementDomainStatistic(vm._linkThing.Data.Domain, isLink);
                await offlineService.IncrementSubredditStatistic(vm._linkThing.Data.SubredditId, isLink);
            }
        }
コード例 #10
0
        private static void GotoLinkImpl(LinkViewModel vm)
        {
            if (vm.IsExtendedOptionsShown)
                vm.IsExtendedOptionsShown = false;

            if (vm.IsSelfPost && !vm._settingsService.OnlyFlipViewImages)
            {
                vm._navigationService.Navigate(vm._dynamicViewLocator.SelfPostView, Tuple.Create(vm.LinkThing, false));
            }
            else
            {
                UtilityCommandImpl.GotoLinkImpl(vm.Url, vm._linkThing);
            }
            vm.RaisePropertyChanged("Url");
        }
コード例 #11
0
        private static void NavigateToCommentsImpl(LinkViewModel vm)
        {
            if (vm.IsExtendedOptionsShown)
                vm.IsExtendedOptionsShown = false;

            if (vm == null || vm._linkThing == null || vm._linkThing.Data == null || string.IsNullOrWhiteSpace(vm._linkThing.Data.Url))
                vm._baconProvider.GetService<INotificationService>().CreateNotification("Invalid link data, please PM /u/hippiehunter with details");
            else
                vm._navigationService.Navigate(vm._dynamicViewLocator.CommentsView, new SelectCommentTreeMessage { LinkThing = vm._linkThing });
        }
コード例 #12
0
		private static void GotoUserStatic(LinkViewModel vm)
		{
            if (vm.IsExtendedOptionsShown)
                vm.IsExtendedOptionsShown = false;
			vm.GotoUserImpl();
		}
コード例 #13
0
 private static object MakeSerializable(LinkViewModel vm)
 {
     return Tuple.Create(vm.LinkThing, true);
 }