コード例 #1
0
        private async Task LoadGroupChatAsync(string offset = "0")
        {
            if (MainScrollEvent.IsLoading)
            {
                return;
            }

            MainScrollEvent.IsLoading = true;

            var countList = MAdapter.LastChatsList.Count;

            var(apiStatus, respond) = await RequestsAsync.GroupChat.GetGroupChatListAsync("20", offset);

            if (apiStatus.Equals(200))
            {
                if (respond is GroupListObject result)
                {
                    var respondList = result.Data.Count;
                    if (respondList > 0)
                    {
                        foreach (var chatObject in from chatObject in result.Data let check = MAdapter?.LastChatsList.FirstOrDefault(a => a.LastChat?.GroupId == chatObject.GroupId) where check == null select chatObject)
                        {
                            chatObject.ChatType = "group";
                            var item = WoWonderTools.FilterDataLastChatNewV(chatObject);

                            MAdapter?.LastChatsList.Add(new Classes.LastChatsClass()
                            {
                                LastChat = item,
                                Type     = Classes.ItemType.LastChatNewV
                            });
                        }

                        if (countList > 0)
                        {
                            Activity?.RunOnUiThread(() => { MAdapter.NotifyItemRangeInserted(countList, MAdapter.LastChatsList.Count - countList); });
                        }
                        else
                        {
                            Activity?.RunOnUiThread(() => { MAdapter.NotifyDataSetChanged(); });
                        }
                    }
                    else
                    {
                        if (MAdapter?.LastChatsList.Count > 10 && !MRecycler.CanScrollVertically(1))
                        {
                            Toast.MakeText(Context, Context.GetText(Resource.String.Lbl_NoMoreGroup), ToastLength.Short)?.Show();
                        }
                    }
                }
            }
            else
            {
                Methods.DisplayReportResult(Activity, respond);
            }

            Activity?.RunOnUiThread(ShowEmptyPage);
        }