private void SwipeRefreshLayoutOnRefresh(object sender, EventArgs e)
        {
            try
            {
                //Get Data Api
                MAdapter.UsersDateList.Clear();
                MAdapter.NotifyDataSetChanged();

                MainScrollEvent.IsLoading = false;

                StartApiService();
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
            }
        }
Exemplo n.º 2
0
        private async Task LoadHotOrNotAsync(string offset = "0")
        {
            if (MainScrollEventHotOrNot.IsLoading)
            {
                return;
            }

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

                int countList = HotOrNotUserAdapter.UsersDateList.Count;
                var(apiStatus, respond) = await RequestsAsync.Users.HotOrNotAsync(UserDetails.Gender, "30", offset);

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

                        if (countList > 0)
                        {
                            Activity.RunOnUiThread(() => HotOrNotUserAdapter.NotifyItemRangeInserted(countList - 1, HotOrNotUserAdapter.UsersDateList.Count - countList));
                        }
                        else
                        {
                            Activity.RunOnUiThread(() => HotOrNotUserAdapter.NotifyDataSetChanged());
                        }
                    }
                    else
                    {
                        if (HotOrNotUserAdapter.UsersDateList.Count > 10 && !RecylerHotOrNot.CanScrollVertically(1))
                        {
                            Toast.MakeText(Context, Context.GetText(Resource.String.Lbl_NoMoreUsers), ToastLength.Short).Show();
                        }
                    }
                }

                Activity.RunOnUiThread(() =>
                {
                    try
                    {
                        if (HotOrNotUserAdapter?.UsersDateList?.Count > 0)
                        {
                            RecylerHotOrNot.Visibility  = ViewStates.Visible;
                            HotOrNotLinear.Visibility   = ViewStates.Visible;
                            EmptyStateLayout.Visibility = ViewStates.Gone;
                        }
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e);
                    }
                });
                MainScrollEventHotOrNot.IsLoading = false;
            }
            else
            {
                Toast.MakeText(Context, Context.GetString(Resource.String.Lbl_CheckYourInternetConnection), ToastLength.Short).Show();
            }

            MainScrollEventHotOrNot.IsLoading = false;
        }
        // Replace the contents of a view (invoked by the layout manager)
        public override void OnBindViewHolder(RecyclerView.ViewHolder viewHolder, int position)
        {
            try
            {
                Position = position;

                var item = TrendingList[viewHolder.AdapterPosition];
                if (item != null)
                {
                    if (item.Type == ItemType.ProUser || item.Type == ItemType.HotOrNot)
                    {
                        if (viewHolder is TrendingAdapterViewHolder holder)
                        {
                            if (item.Type == ItemType.ProUser)
                            {
                                if (ProUserAdapter == null)
                                {
                                    ProUserAdapter = new ProUserAdapter(ActivityContext)
                                    {
                                        ProUserList = new ObservableCollection <UserInfoObject>()
                                    };

                                    LinearLayoutManager layoutManager = new LinearLayoutManager(ActivityContext, LinearLayoutManager.Horizontal, false);
                                    holder.MRecycler.SetLayoutManager(layoutManager);
                                    holder.MRecycler.GetLayoutManager().ItemPrefetchEnabled = true;
                                    holder.MRecycler.NestedScrollingEnabled = false;

                                    var sizeProvider = new FixedPreloadSizeProvider(10, 10);
                                    var preLoader    = new RecyclerViewPreloader <UserInfoObject>(ActivityContext, ProUserAdapter, sizeProvider, 10);
                                    holder.MRecycler.AddOnScrollListener(preLoader);
                                    holder.MRecycler.SetAdapter(ProUserAdapter);
                                    ProUserAdapter.OnItemClick += ProUserAdapterOnOnItemClick;
                                }

                                int countList = item.ProUserList.Count;
                                if (item.ProUserList.Count > 0)
                                {
                                    if (countList > 0)
                                    {
                                        foreach (var user in from user in item.ProUserList let check = ProUserAdapter.ProUserList.FirstOrDefault(a => a.Id == user.Id) where check == null select user)
                                        {
                                            ProUserAdapter.ProUserList.Add(user);
                                        }

                                        ProUserAdapter.NotifyItemRangeInserted(countList - 1, ProUserAdapter.ProUserList.Count - countList);
                                    }
                                    else
                                    {
                                        ProUserAdapter.ProUserList = new ObservableCollection <UserInfoObject>(item.ProUserList);
                                        ProUserAdapter.NotifyDataSetChanged();
                                    }
                                }

                                holder.MainLinear.Visibility = ViewStates.Visible;
                                holder.MoreText.Visibility   = ViewStates.Invisible;
                                holder.TitleText.Text        = ActivityContext.GetText(Resource.String.Lbl_ProUser);
                            }
                            else if (item.Type == ItemType.HotOrNot)
                            {
                                if (HotOrNotUserAdapter == null)
                                {
                                    HotOrNotUserAdapter = new HotOrNotUserAdapter(ActivityContext)
                                    {
                                        UsersDateList = new ObservableCollection <UserInfoObject>()
                                    };

                                    LinearLayoutManager layoutManager = new LinearLayoutManager(ActivityContext, LinearLayoutManager.Horizontal, false);
                                    holder.MRecycler.SetLayoutManager(layoutManager);
                                    holder.MRecycler.GetLayoutManager().ItemPrefetchEnabled = true;
                                    holder.MRecycler.NestedScrollingEnabled = false;

                                    var sizeProvider = new FixedPreloadSizeProvider(10, 10);
                                    var preLoader    = new RecyclerViewPreloader <UserInfoObject>(ActivityContext, HotOrNotUserAdapter, sizeProvider, 10);
                                    holder.MRecycler.AddOnScrollListener(preLoader);
                                    holder.MRecycler.SetAdapter(HotOrNotUserAdapter);
                                    HotOrNotUserAdapter.HotItemClick   += HotOrNotUserAdapterOnHotItemClick;
                                    HotOrNotUserAdapter.NotItemClick   += HotOrNotUserAdapterOnNotItemClick;
                                    HotOrNotUserAdapter.ImageItemClick += HotOrNotUserAdapterOnImageItemClick;
                                }

                                int countList = item.HotOrNotList.Count;
                                if (item.HotOrNotList.Count > 0)
                                {
                                    if (countList > 0)
                                    {
                                        foreach (var user in from user in item.HotOrNotList let check = HotOrNotUserAdapter.UsersDateList.FirstOrDefault(a => a.Id == user.Id) where check == null select user)
                                        {
                                            HotOrNotUserAdapter.UsersDateList.Add(user);
                                        }

                                        HotOrNotUserAdapter.NotifyItemRangeInserted(countList - 1, HotOrNotUserAdapter.UsersDateList.Count - countList);
                                    }
                                    else
                                    {
                                        HotOrNotUserAdapter.UsersDateList = new ObservableCollection <UserInfoObject>(item.HotOrNotList);
                                        HotOrNotUserAdapter.NotifyDataSetChanged();
                                    }
                                }

                                holder.MainLinear.Visibility = ViewStates.Visible;
                                holder.MoreText.Visibility   = ProUserAdapter.ProUserList?.Count >= 5 ? ViewStates.Visible : ViewStates.Invisible;
                                holder.TitleText.Text        = ActivityContext.GetText(Resource.String.Lbl_HotORNot);
                            }
                        }
                    }
                    else if (item.Type == ItemType.Users)
                    {
                        if (viewHolder is NearByAdapterViewHolder nearByAdapter)
                        {
                            FullGlideRequestBuilder.Load(item.UsersData.Avater).Into(nearByAdapter.ImgUser);

                            nearByAdapter.TxtName.Text = Methods.FunString.SubStringCutOf(QuickDateTools.GetNameFinal(item.UsersData), 20);

                            nearByAdapter.TxtLastSeen.Text      = !string.IsNullOrEmpty(item.UsersData.LastseenTxt) ? item.UsersData.LastseenTxt : Methods.Time.TimeAgo(int.Parse(item.UsersData.Lastseen), false);
                            nearByAdapter.OnlineIcon.Visibility = QuickDateTools.GetStatusOnline(item.UsersData.Lastseen, item.UsersData.Online) ? ViewStates.Visible : ViewStates.Gone;

                            if (item.UsersData.IsLiked != null && item.UsersData.IsLiked.Value)
                            {
                                nearByAdapter.LottieAnimation.Visibility = ViewStates.Visible;
                                nearByAdapter.LottieAnimation.PlayAnimation();
                            }
                            else
                            {
                                nearByAdapter.LottieAnimation.Visibility = ViewStates.Gone;
                                nearByAdapter.LottieAnimation.CancelAnimation();
                                nearByAdapter.LottieAnimation.Progress = 0;
                            }
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
            }
        }