Exemplo n.º 1
0
 public void ResetCache()
 {
     Pagination   = PaginationParameters.MaxPagesToLoad(1);
     IsLoading    = true;
     HasMoreItems = true;
     Items.Clear();
     CachedItems.Clear();
     FirstRun = true;
 }
Exemplo n.º 2
0
        public async void LoadCachedItems()
        {
            var fileList = await SaveFolder.GetFilesAsync();

            CachedItems.Clear();
            foreach (var file in fileList)
            {
                if (file.FileType == ".mp3" || file.FileType == ".mp4")
                {
                    CachedItems.Add(new CachedItem(file.Name, file.Path));
                }
            }
        }
Exemplo n.º 3
0
        async Task LoadMoreItemsAsync(bool refresh = false)
        {
            if (!HasMoreItems && !refresh)
            {
                IsLoading = false;
                return;
            }
            try
            {
                if (refresh)
                {
                    PageCount  = 1;
                    Pagination = PaginationParameters.MaxPagesToLoad(1);
                }
                Views.Main.ActivitiesView.Current?.ShowTopLoadingFollowers();
                var result = await InstaApi.UserProcessor.GetUserFollowingByIdAsync(CurrentUser.Pk, Pagination);

                PageCount++;
                FirstRun = false;
                Pagination.MaximumPagesToLoad = 2;
                if (!result.Succeeded)
                {
                    IsLoading = false;
                    if (result.Value == null || result.Value?.Count == 0)
                    {
                        Views.Main.ActivitiesView.Current?.HideTopLoadingFollowers();
                        return;
                    }
                }

                if (string.IsNullOrEmpty(result.Value.NextMaxId))
                {
                    HasMoreItems = false;
                }

                Pagination.NextMaxId = result.Value.NextMaxId;
                if (refresh)
                {
                    Items.Clear(); CachedItems.Clear();
                }
                var userIds = new List <long>();
                if (result.Value?.Count > 0)
                {
                    result.Value.ForEach(x =>
                    {
                        userIds.Add(x.Pk);
                        CachedItems.Add(x.ToUserShortFriendship());
                    });
                }
                try
                {
                    if (userIds.Count > 0)
                    {
                        await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() =>
                        {
                            var friendshipStatuses = await InstaApi.UserProcessor.GetFriendshipStatusesAsync(userIds.ToArray());
                            if (friendshipStatuses.Succeeded)
                            {
                                var friends = friendshipStatuses.Value;
                                friends.ForEach(x =>
                                {
                                    var t = CachedItems.FirstOrDefault(u => u.Pk == x.Pk);
                                    if (t != null)
                                    {
                                        t.FriendshipStatus = x;
                                    }
                                });
                            }
                            CachedItems.ForEach(x =>
                            {
                                if (x.FriendshipStatus != null)
                                {
                                    if (!x.FriendshipStatus.Following)
                                    {
                                        Items.Add(x);
                                    }
                                }
                            });

                            Views.Main.ActivitiesView.Current?.HideTopLoadingFollowers();
                        });
                    }
                }
                catch
                {
                    Views.Main.ActivitiesView.Current?.HideTopLoadingFollowers();
                }
                await Task.Delay(1000);

                IsLoading = false;
            }
            catch (Exception ex)
            {
                FirstRun      =
                    IsLoading = false;
                ex.PrintException("FollowingGenerator.LoadMoreItemsAsync");

                Views.Main.ActivitiesView.Current?.HideTopLoadingFollowers();
            }
        }