private async Task LoadDataAsync(string offset = "")
        {
            if (MainScrollEvent.IsLoading)
            {
                return;
            }

            if (Methods.CheckConnectivity())
            {
                MainScrollEvent.IsLoading = true;

                int countList = MAdapter.NotificationsList.Count;
                (int apiStatus, var respond) = await RequestsAsync.User.FetchNotifications(offset, "15");

                if (apiStatus != 200 || !(respond is FetchNotificationsObject result) || result.data == null)
                {
                    Methods.DisplayReportResult(Activity, respond);
                }
                else
                {
                    var respondList = result.data.Count;
                    if (respondList > 0)
                    {
                        if (countList > 0)
                        {
                            foreach (var item in from item in result.data let check = MAdapter.NotificationsList.FirstOrDefault(a => a.Id == item.Id) where check == null select item)
                            {
                                MAdapter.NotificationsList.Add(item);
                            }

                            Activity.RunOnUiThread(() => { MAdapter.NotifyItemRangeInserted(countList - 1, MAdapter.NotificationsList.Count - countList); });
                        }
                        else
                        {
                            MAdapter.NotificationsList = new ObservableCollection <FetchNotificationsObject.Data>(result.data);
                            Activity.RunOnUiThread(() => { MAdapter.NotifyDataSetChanged(); });
                        }
                    }
                    else
                    {
                        if (MAdapter.NotificationsList.Count > 10 && !MRecycler.CanScrollVertically(1))
                        {
                            Toast.MakeText(Context, Context.GetText(Resource.String.Lbl_NoMoreNotifications), ToastLength.Short).Show();
                        }
                    }
                }

                Activity.RunOnUiThread(ShowEmptyPage);
            }
            else
            {
                Inflated = EmptyStateLayout.Inflate();
                EmptyStateInflater x = new EmptyStateInflater();
                x.InflateLayout(Inflated, EmptyStateInflater.Type.NoConnection);
                if (!x.EmptyStateButton.HasOnClickListeners)
                {
                    x.EmptyStateButton.Click += null;
                    x.EmptyStateButton.Click += EmptyStateButtonOnClick;
                }

                Toast.MakeText(Context, Context.GetString(Resource.String.Lbl_CheckYourInternetConnection), ToastLength.Short).Show();
                MainScrollEvent.IsLoading = false;
            }
            MainScrollEvent.IsLoading = false;
        }
Beispiel #2
0
        //Get General Data Using Api >> notifications , pro_users , promoted_pages , trending_hashTag
        public async Task <(string, string, string, string)> LoadGeneralData(bool seenNotifications, string offset = "")
        {
            try
            {
                if (MainScrollEvent.IsLoading)
                {
                    return("", "", "", "");
                }

                if (Methods.CheckConnectivity())
                {
                    MainScrollEvent.IsLoading = true;

                    var countNotificationsList = MAdapter.NotificationsList?.Count ?? 0;
                    var countPromotedPagesList = GlobalContext.ProPagesAdapter?.MProPagesList.Count ?? 0;

                    (int apiStatus, var respond) = await RequestsAsync.Global.Get_General_Data(seenNotifications, TabbedMainActivity.OnlineUsers, UserDetails.DeviceId, offset);

                    if (apiStatus == 200)
                    {
                        if (respond is GetGeneralDataObject result)
                        {
                            Activity.RunOnUiThread(() =>
                            {
                                try
                                {
                                    // Notifications
                                    var respondList = result.Notifications.Count;
                                    if (respondList > 0)
                                    {
                                        if (countNotificationsList > 0)
                                        {
                                            var listNew = result.Notifications?.Where(c => !MAdapter.NotificationsList.Select(fc => fc.Id).Contains(c.Id)).ToList();
                                            if (listNew.Count > 0)
                                            {
                                                foreach (var notification in listNew)
                                                {
                                                    MAdapter.NotificationsList.Insert(0, notification);
                                                }

                                                MAdapter.NotifyItemRangeInserted(countNotificationsList - 1, MAdapter.NotificationsList.Count - countNotificationsList);
                                            }
                                        }
                                        else
                                        {
                                            MAdapter.NotificationsList = new ObservableCollection <Notification>(result.Notifications);
                                            MAdapter.NotifyDataSetChanged();
                                        }
                                    }
                                    else
                                    {
                                        if (MAdapter.NotificationsList.Count > 10 && !MRecycler.CanScrollVertically(1))
                                        {
                                            Toast.MakeText(Context, Context.GetText(Resource.String.Lbl_NoMoreNotifications), ToastLength.Short).Show();
                                        }
                                    }

                                    if (AppSettings.ShowTrendingPage && GlobalContext.TrendingTab != null)
                                    {
                                        // Friend Requests
                                        if (result.FriendRequests.Count > 0)
                                        {
                                            GlobalContext.FriendRequestsList = new ObservableCollection <UserDataObject>(result.FriendRequests);

                                            GlobalContext.TrendingTab.LayoutFriendRequest.Visibility = ViewStates.Visible;
                                            try
                                            {
                                                for (var i = 0; i < 4; i++)
                                                {
                                                    switch (i)
                                                    {
                                                    case 0:
                                                        GlideImageLoader.LoadImage(Activity, GlobalContext.FriendRequestsList[i].Avatar, GlobalContext.TrendingTab.FriendRequestImage3, ImageStyle.CircleCrop, ImagePlaceholders.Drawable);
                                                        break;

                                                    case 1:
                                                        GlideImageLoader.LoadImage(Activity, GlobalContext.FriendRequestsList[i].Avatar, GlobalContext.TrendingTab.FriendRequestImage2, ImageStyle.CircleCrop, ImagePlaceholders.Drawable);
                                                        break;

                                                    case 2:
                                                        GlideImageLoader.LoadImage(Activity, GlobalContext.FriendRequestsList[i].Avatar, GlobalContext.TrendingTab.FriendRequestImage1, ImageStyle.CircleCrop, ImagePlaceholders.Drawable);
                                                        break;
                                                    }
                                                }
                                            }
                                            catch (Exception e)
                                            {
                                                Console.WriteLine(e);
                                            }
                                        }
                                        else if (GlobalContext.TrendingTab != null)
                                        {
                                            GlobalContext.TrendingTab.LayoutFriendRequest.Visibility = ViewStates.Gone;
                                        }

                                        if (GlobalContext.TrendingTab != null && AppSettings.ShowProUsersMembers)
                                        {
                                            var isPro = ListUtils.MyProfileList?.FirstOrDefault()?.IsPro ?? "0";
                                            if (isPro == "0" && ListUtils.SettingsSiteList?.Pro == "1" && AppSettings.ShowGoPro)
                                            {
                                                var dataOwner = GlobalContext.ProUsersAdapter.MProUsersList.FirstOrDefault(a => a.Type == "Your");
                                                if (dataOwner == null)
                                                {
                                                    GlobalContext.ProUsersAdapter.MProUsersList.Insert(0, new UserDataObject
                                                    {
                                                        Avatar   = UserDetails.Avatar,
                                                        Type     = "Your",
                                                        Username = Context.GetText(Resource.String.Lbl_AddMe),
                                                    });

                                                    GlobalContext.ProUsersAdapter.NotifyDataSetChanged();

                                                    if (GlobalContext.TrendingTab.LayoutSuggestionProUsers.Visibility != ViewStates.Visible)
                                                    {
                                                        GlobalContext.TrendingTab.LayoutSuggestionProUsers.Visibility = ViewStates.Visible;
                                                    }
                                                }
                                            }

                                            // Pro Users
                                            var countProUsersList   = GlobalContext.ProUsersAdapter.MProUsersList.Count;
                                            var respondListProUsers = result.ProUsers.Count;
                                            if (respondListProUsers > 0)
                                            {
                                                foreach (var item in from item in result.ProUsers let check = GlobalContext.ProUsersAdapter.MProUsersList.FirstOrDefault(a => a.UserId == item.UserId) where check == null select item)
                                                {
                                                    GlobalContext.ProUsersAdapter.MProUsersList.Add(item);
                                                }

                                                if (countProUsersList > 0)
                                                {
                                                    GlobalContext.ProUsersAdapter.NotifyItemRangeInserted(countProUsersList - 1, GlobalContext.ProUsersAdapter.MProUsersList.Count - countProUsersList);
                                                }
                                                else
                                                {
                                                    GlobalContext.ProUsersAdapter.NotifyDataSetChanged();
                                                }

                                                //Scroll Down >>
                                                GlobalContext.TrendingTab.ProUserRecyclerView.ScrollToPosition(0);

                                                if (GlobalContext.ProUsersAdapter.MProUsersList.Count > 0 && GlobalContext.TrendingTab.LayoutSuggestionProUsers.Visibility != ViewStates.Visible)
                                                {
                                                    GlobalContext.TrendingTab.LayoutSuggestionProUsers.Visibility = ViewStates.Visible;
                                                }
                                            }
                                            else
                                            {
                                                if (GlobalContext.ProUsersAdapter.MProUsersList.Count == 0 && GlobalContext.TrendingTab.LayoutSuggestionProUsers.Visibility != ViewStates.Gone)
                                                {
                                                    GlobalContext.TrendingTab.LayoutSuggestionProUsers.Visibility = ViewStates.Gone;
                                                }
                                            }
                                        }
                                        else
                                        {
                                            if (GlobalContext.TrendingTab != null && GlobalContext.ProUsersAdapter.MProUsersList.Count == 0 && GlobalContext.TrendingTab.LayoutSuggestionProUsers.Visibility != ViewStates.Gone)
                                            {
                                                GlobalContext.TrendingTab.LayoutSuggestionProUsers.Visibility = ViewStates.Gone;
                                            }
                                        }

                                        if (GlobalContext.TrendingTab != null && AppSettings.ShowPromotedPages)
                                        {
                                            // Pro Pages
                                            var respondListPromotedPages = result.PromotedPages.Count;
                                            if (respondListPromotedPages > 0)
                                            {
                                                if (countPromotedPagesList > 0)
                                                {
                                                    foreach (var item in from item in result.PromotedPages let check = GlobalContext.ProPagesAdapter.MProPagesList.FirstOrDefault(a => a.Id == item.Id) where check == null select item)
                                                    {
                                                        GlobalContext.ProPagesAdapter.MProPagesList.Add(item);
                                                    }

                                                    GlobalContext.ProPagesAdapter.NotifyItemRangeInserted(countPromotedPagesList - 1, GlobalContext.ProPagesAdapter.MProPagesList.Count - countPromotedPagesList);
                                                }
                                                else
                                                {
                                                    GlobalContext.ProPagesAdapter.MProPagesList = new ObservableCollection <PageClass>(result.PromotedPages);
                                                    GlobalContext.ProPagesAdapter.NotifyDataSetChanged();
                                                }

                                                GlobalContext.TrendingTab.LayoutSuggestionPromotedPage.Visibility = ViewStates.Visible;
                                            }
                                            else
                                            {
                                                GlobalContext.TrendingTab.LayoutSuggestionPromotedPage.Visibility = ViewStates.Gone;
                                            }
                                        }
                                        else
                                        {
                                            GlobalContext.TrendingTab.LayoutSuggestionPromotedPage.Visibility = ViewStates.Gone;
                                        }
                                    }

                                    if (AppSettings.ShowTrendingHashTags)
                                    {
                                        if (result.TrendingHashtag.Count > 0)
                                        {
                                            GlobalContext.HashTagUserAdapter.MHashtagList = new ObservableCollection <TrendingHashtag>(result.TrendingHashtag);
                                        }
                                    }

                                    MainScrollEvent.IsLoading = false;
                                    ShowEmptyPage();
                                }
                                catch (Exception e)
                                {
                                    Console.WriteLine(e);
                                }
                            });
                            return(result.NewNotificationsCount, result.NewFriendRequestsCount, result.CountNewMessages, result.Announcement?.AnnouncementClass?.TextDecode);
                        }
                    }
                    else
                    {
                        Methods.DisplayReportResult(Activity, respond);
                    }

                    Activity.RunOnUiThread(ShowEmptyPage);
                    MainScrollEvent.IsLoading = false;

                    return("", "", "", "");
                }
                else
                {
                    Inflated = EmptyStateLayout.Inflate();
                    EmptyStateInflater x = new EmptyStateInflater();
                    x.InflateLayout(Inflated, EmptyStateInflater.Type.NoConnection);
                    if (!x.EmptyStateButton.HasOnClickListeners)
                    {
                        x.EmptyStateButton.Click += null;
                        x.EmptyStateButton.Click += EmptyStateButtonOnClick;
                    }

                    Toast.MakeText(Context, Context.GetString(Resource.String.Lbl_CheckYourInternetConnection), ToastLength.Short).Show();
                }
            }
            catch (Exception e)
            {
                MainScrollEvent.IsLoading = false;
                Console.WriteLine(e);
            }
            MainScrollEvent.IsLoading = false;
            return("", "", "", "");
        }