Наследование: ViewModelBase
Пример #1
0
        private void ChangeSubreddit(SelectSubredditMessage message, bool fireSubredditsChanged = true)
        {
            int  indexToPosition;
            bool foundExisting = FindSubredditMessageIndex(message, out indexToPosition);

            if (!foundExisting)
            {
                var newReddit = new RedditViewModel(_baconProvider);
                newReddit.DetachSubredditMessage();
                newReddit.AssignSubreddit(message);
                if (PivotItems.Count > 0)
                {
                    PivotItems.Insert(PivotItems.Count - 1, newReddit);
                }
                else
                {
                    PivotItems.Add(newReddit);
                }
                _subreddits.Add(message.Subreddit);
                RaisePropertyChanged("PivotItems");
                indexToPosition = PivotItems.Count - 2;
            }

            if (fireSubredditsChanged)
            {
                RaisePropertyChanged("Subreddits");

                Messenger.Default.Send <SelectIndexMessage>(
                    new SelectIndexMessage
                {
                    TypeContext = typeof(MainPageViewModel),
                    Index       = indexToPosition
                }
                    );
            }
        }
 public NeverEndingRedditView(RedditViewModel context, int currentLinkPos, bool forward)
 {
     _context = context;
     _currentLinkPos = currentLinkPos;
     _forward = forward;
 }
Пример #3
0
        public async void NavigatedToView(Type viewType, bool forward)
        {
            _navId++;
            int myNavID = _navId;

            _cancelationTokenSource.Cancel();

            var currentContext = _viewModelContextService.Context;
            if (currentContext is CommentsViewModel && ((CommentsViewModel)currentContext).Link != null)
            {
                try
                {
                    await _suspendableWorkQueue.QueueLowImportanceRestartableWork(async (token) =>
                        {
                            await NavigatedToOfflineableThingImpl(((CommentsViewModel)currentContext).Link.LinkThing, true);
                        });
                }
                catch (TaskCanceledException)
                {
                }
            }

            if (myNavID != _navId)
            {
                _cancelationTokenSource.Cancel();
                return;
            }
            else
                _cancelationTokenSource = new CancellationTokenSource();


            if ((DateTime.Now - lastOppertunity).TotalSeconds < 10)
                return;
            else
                lastOppertunity = DateTime.Now;

            //determine if this is a good time to be caching things
            //and what should be our highest priority to be cached
            var viewModelContextStack = _viewModelContextService.ContextStack;
            _firstRedditViewModel = viewModelContextStack.OfType<RedditViewModel>().FirstOrDefault();
            _firstCommentsViewModel = viewModelContextStack.OfType<CommentsViewModel>().FirstOrDefault();

            var networkAvailable = System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable();

            //no network means there is no reason for us to do anything
            if (!networkAvailable)
                return;
            var onMeteredConnection = _systemServices.IsOnMeteredConnection;

            OffliningOpportunityPriority priority = OffliningOpportunityPriority.None;
            if (viewType == _dynamicViewLocator.LinkedPictureView && forward)
                priority = OffliningOpportunityPriority.Image;

            else if (viewType == _dynamicViewLocator.CommentsView && forward)
                priority = OffliningOpportunityPriority.Comments;

            else if (viewType == _dynamicViewLocator.RedditView)
                priority = OffliningOpportunityPriority.ImageAPI;

            OffliningOpportunity(priority, onMeteredConnection ? NetworkConnectivityStatus.Metered : NetworkConnectivityStatus.Unmetered, _cancelationTokenSource.Token);
        }
Пример #4
0
        private void ChangeSubreddit(SelectSubredditMessage message, bool fireSubredditsChanged = true)
        {
            int indexToPosition;
            bool foundExisting = FindSubredditMessageIndex(message, out indexToPosition);

            if (!foundExisting)
            {
                var newReddit = new RedditViewModel(_baconProvider);
                newReddit.DetachSubredditMessage();
                newReddit.AssignSubreddit(message);
                
                if (PivotItems.Count > 0)
                    PivotItems.Insert(PivotItems.Count, newReddit);
                else
                    PivotItems.Add(newReddit);
                _subreddits.Add(message.Subreddit);
                indexToPosition = PivotItems.Count - 1;
            }

            if (fireSubredditsChanged)
            {
                Messenger.Default.Send<SelectIndexMessage>(
                    new SelectIndexMessage
                    {
                        TypeContext = typeof(MainPageViewModel),
                        Index = indexToPosition
                    }
                );
            }
        }