상속: 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;
     }
 }
        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);
 }