Exemple #1
0
        public void LoadDataApi(int apiStatus, dynamic respond, string offset, string typeRun = "Add")
        {
            try
            {
                if (apiStatus != 200 || !(respond is PostObject result) || result.Data == null)
                {
                    WRecyclerView.MainScrollEvent.IsLoading = false;
                    Methods.DisplayReportResult(ActivityContext, respond);
                }
                else
                {
                    if (WRecyclerView.SwipeRefreshLayoutView != null && WRecyclerView.SwipeRefreshLayoutView.Refreshing)
                    {
                        WRecyclerView.SwipeRefreshLayoutView.Refreshing = false;
                    }

                    var countList = NativeFeedAdapter.ItemCount;
                    if (result.Data.Count > 0)
                    {
                        result.Data.RemoveAll(a => a.Publisher == null && a.UserData == null);

                        if (offset == "0" && countList > 10 && typeRun == "Insert" && NativeFeedAdapter.NativePostType == NativeFeedType.Global)
                        {
                            result.Data.Reverse();
                            bool add = false;

                            foreach (var post in from post in result.Data let check = NativeFeedAdapter.ListDiffer.FirstOrDefault(a => a?.PostData?.PostId == post.PostId && a.TypeView == PostFunctions.GetAdapterType(post)) where check == null select post)
                            {
                                add = true;
                                NativeFeedAdapter.NewPostList.Add(post);
                            }

                            ActivityContext.RunOnUiThread(() =>
                            {
                                try
                                {
                                    if (add && WRecyclerView.PopupBubbleView != null &&
                                        WRecyclerView.PopupBubbleView.Visibility != ViewStates.Visible &&
                                        AppSettings.ShowNewPostOnNewsFeed)
                                    {
                                        WRecyclerView.PopupBubbleView.Visibility = ViewStates.Visible;
                                    }
                                }
                                catch (Exception e)
                                {
                                    Methods.DisplayReportResultTrack(e);
                                }
                            });
                        }
                        else
                        {
                            bool add = false;
                            foreach (var post in from post in result.Data let check = NativeFeedAdapter.ListDiffer.FirstOrDefault(a => a?.PostData?.PostId == post.PostId && a?.TypeView == PostFunctions.GetAdapterType(post)) where check == null select post)
                            {
                                add = true;
                                var combiner = new FeedCombiner(null, NativeFeedAdapter.ListDiffer, ActivityContext);

                                if (NativeFeedAdapter.NativePostType == NativeFeedType.Global)
                                {
                                    if (result.Data.Count < 6 && NativeFeedAdapter.ListDiffer.Count < 6)
                                    {
                                        if (!ShowFindMoreAlert)
                                        {
                                            ShowFindMoreAlert = true;

                                            combiner.AddFindMoreAlertPostView("Pages");
                                            combiner.AddFindMoreAlertPostView("Groups");
                                        }
                                    }

                                    var check1 = NativeFeedAdapter.ListDiffer.FirstOrDefault(a => a.TypeView == PostModelType.SuggestedGroupsBox);
                                    if (check1 == null && AppSettings.ShowSuggestedGroup && NativeFeedAdapter.ListDiffer.Count > 0 && NativeFeedAdapter.ListDiffer.Count % AppSettings.ShowSuggestedGroupCount == 0 && ListUtils.SuggestedGroupList.Count > 0)
                                    {
                                        combiner.AddSuggestedBoxPostView(PostModelType.SuggestedGroupsBox);
                                    }

                                    var check2 = NativeFeedAdapter.ListDiffer.FirstOrDefault(a => a.TypeView == PostModelType.SuggestedUsersBox);
                                    if (check2 == null && AppSettings.ShowSuggestedUser && NativeFeedAdapter.ListDiffer.Count > 0 && NativeFeedAdapter.ListDiffer.Count % AppSettings.ShowSuggestedUserCount == 0 && ListUtils.SuggestedUserList.Count > 0)
                                    {
                                        combiner.AddSuggestedBoxPostView(PostModelType.SuggestedUsersBox);
                                    }
                                }

                                if (NativeFeedAdapter.ListDiffer.Count % AppSettings.ShowAdMobNativeCount == 0 && NativeFeedAdapter.ListDiffer.Count > 0 && AppSettings.ShowAdMobNativePost)
                                {
                                    switch (LastAdsType)
                                    {
                                    case PostModelType.AdMob1:
                                        LastAdsType = PostModelType.AdMob2;
                                        combiner.AddAdsPostView(PostModelType.AdMob1);
                                        break;

                                    case PostModelType.AdMob2:
                                        LastAdsType = PostModelType.AdMob3;
                                        combiner.AddAdsPostView(PostModelType.AdMob2);
                                        break;

                                    case PostModelType.AdMob3:
                                        LastAdsType = PostModelType.AdMob1;
                                        combiner.AddAdsPostView(PostModelType.AdMob3);
                                        break;
                                    }
                                }

                                var combine = new FeedCombiner(RegexFilterText(post), NativeFeedAdapter.ListDiffer, ActivityContext);
                                if (post.PostType == "ad")
                                {
                                    combine.AddAdsPost();
                                }
                                else
                                {
                                    bool isPromoted = post.IsPostBoosted == "1" || post.SharedInfo.SharedInfoClass != null && post.SharedInfo.SharedInfoClass?.IsPostBoosted == "1";
                                    if (isPromoted) //Promoted
                                    {
                                        combine.CombineDefaultPostSections("Top");
                                    }
                                    else
                                    {
                                        combine.CombineDefaultPostSections();
                                    }
                                }

                                if (NativeFeedAdapter.ListDiffer.Count % AppSettings.ShowFbNativeAdsCount == 0 && NativeFeedAdapter.ListDiffer.Count > 0 && AppSettings.ShowFbNativeAds)
                                {
                                    combiner.AddAdsPostView(PostModelType.FbAdNative);
                                }
                            }

                            if (add)
                            {
                                ActivityContext.RunOnUiThread(() =>
                                {
                                    try
                                    {
                                        NativeFeedAdapter.NotifyItemRangeInserted(countList, NativeFeedAdapter.ListDiffer.Count - countList);
                                        WRecyclerView.MainScrollEvent.IsLoading = false;
                                        GC.Collect();
                                    }
                                    catch (Exception e)
                                    {
                                        Methods.DisplayReportResultTrack(e);
                                    }
                                });
                            }

                            //else
                            //{
                            //    Toast.MakeText(ActivityContext, ActivityContext.GetText(Resource.String.Lbl_NoMorePost), ToastLength.Short)?.Show();
                            //}
                        }
                    }

                    ActivityContext.RunOnUiThread(ShowEmptyPage);

                    if (NativeFeedAdapter.NativePostType == NativeFeedType.Global)
                    {
                        WRecyclerView.DataPostJson = JsonConvert.SerializeObject(result);
                    }
                }

                WRecyclerView.MainScrollEvent.IsLoading = false;
            }
            catch (Exception e)
            {
                Methods.DisplayReportResultTrack(e);
                WRecyclerView.MainScrollEvent.IsLoading = false;
            }
        }