示例#1
0
 public void OnClick(MaterialDialog p0, DialogAction p1)
 {
     try
     {
         if (p1 == DialogAction.Positive)
         {
             if (Methods.CheckConnectivity())
             {
                 var itemUser = MAdapter.GetItem(Position);
                 if (itemUser != null)
                 {
                     MAdapter.UserList.Remove(itemUser);
                     MAdapter.NotifyItemRemoved(Position);
                 }
             }
             else
             {
                 Toast.MakeText(this, GetText(Resource.String.Lbl_CheckYourInternetConnection), ToastLength.Short)?.Show();
             }
         }
         else if (p1 == DialogAction.Negative)
         {
             p0.Dismiss();
         }
     }
     catch (Exception e)
     {
         Methods.DisplayReportResultTrack(e);
     }
 }
        private async void MAdapterOnItemClick(object sender, ContactsAdapterClickEventArgs adapterClickEvents)
        {
            try
            {
                var position = adapterClickEvents.Position;
                if (position >= 0)
                {
                    var item = MAdapter.GetItem(position);
                    if (item != null)
                    {
                        var index = MAdapter.UserList.IndexOf(MAdapter.UserList.FirstOrDefault(a => a.UserId == item.UserId));
                        if (index != -1)
                        {
                            MAdapter.UserList.Remove(item);
                            MAdapter.NotifyItemRemoved(index);
                        }

                        Toast.MakeText(this, GetText(Resource.String.Lbl_Unblock_successfully), ToastLength.Short).Show();

                        await RequestsAsync.User.BlockUnblock(item.UserId.ToString()).ConfigureAwait(false);
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
        public async void OnClick(MaterialDialog p0, DialogAction p1)
        {
            try
            {
                if (p1 == DialogAction.Positive)
                {
                    if (!Methods.CheckConnectivity())
                    {
                        Toast.MakeText(this, GetString(Resource.String.Lbl_CheckYourInternetConnection),
                                       ToastLength.Short).Show();
                    }
                    else
                    {
                        if (Type == "Exit")
                        {
                            //Show a progress
                            AndHUD.Shared.Show(this, GetText(Resource.String.Lbl_Loading));

                            var(apiStatus, respond) = await RequestsAsync.GroupChat.ExitGroupChat(GroupId);

                            if (apiStatus == 200)
                            {
                                if (respond is AddOrRemoveUserToGroupObject result)
                                {
                                    Console.WriteLine(result.MessageData);

                                    Toast.MakeText(this, GetString(Resource.String.Lbl_GroupSuccessfullyLeaved), ToastLength.Short).Show();

                                    //remove new item to my Group list
                                    if (AppSettings.LastChatSystem == SystemApiGetLastChat.New)
                                    {
                                        var adapter = GlobalContext?.LastChatTab.MAdapter;
                                        var data    = adapter?.ChatList?.FirstOrDefault(a => a.GroupId == GroupId);
                                        if (data != null)
                                        {
                                            adapter.ChatList.Remove(data);
                                            adapter.NotifyItemRemoved(adapter.ChatList.IndexOf(data));
                                        }
                                    }
                                    else
                                    {
                                        var adapter = GlobalContext?.LastGroupChatsTab.MAdapter;
                                        var data    = adapter?.LastGroupList?.FirstOrDefault(a => a.GroupId == GroupId);
                                        if (data != null)
                                        {
                                            adapter.LastGroupList.Remove(data);
                                            adapter.NotifyItemRemoved(adapter.LastGroupList.IndexOf(data));
                                        }
                                    }

                                    AndHUD.Shared.ShowSuccess(this);
                                    Finish();
                                }
                            }
                            else
                            {
                                if (respond is ErrorObject error)
                                {
                                    var errorText = error.Error.ErrorText;
                                    //Show a Error
                                    AndHUD.Shared.ShowError(this, errorText, MaskType.Clear, TimeSpan.FromSeconds(2));
                                }
                                //Methods.DisplayReportResult(this, respond);
                            }
                        }
                        else if (Type == "Delete")
                        {
                            //Show a progress
                            AndHUD.Shared.Show(this, GetText(Resource.String.Lbl_Loading));

                            var(apiStatus, respond) = await RequestsAsync.GroupChat.DeleteGroupChat(GroupId);

                            if (apiStatus == 200)
                            {
                                if (respond is AddOrRemoveUserToGroupObject result)
                                {
                                    Console.WriteLine(result.MessageData);
                                    Toast.MakeText(this, GetString(Resource.String.Lbl_GroupSuccessfullyDeleted),
                                                   ToastLength.Short).Show();

                                    //remove item to my Group list
                                    if (AppSettings.LastChatSystem == SystemApiGetLastChat.New)
                                    {
                                        var adapter = GlobalContext?.LastChatTab.MAdapter;
                                        var data    = adapter?.ChatList?.FirstOrDefault(a => a.GroupId == GroupId);
                                        if (data != null)
                                        {
                                            adapter.ChatList.Remove(data);
                                            adapter.NotifyItemRemoved(adapter.ChatList.IndexOf(data));
                                        }
                                    }
                                    else
                                    {
                                        var adapter = GlobalContext?.LastGroupChatsTab.MAdapter;
                                        var data    = adapter?.LastGroupList?.FirstOrDefault(a => a.GroupId == GroupId);
                                        if (data != null)
                                        {
                                            adapter.LastGroupList.Remove(data);
                                            adapter.NotifyItemRemoved(adapter.LastGroupList.IndexOf(data));
                                        }
                                    }

                                    AndHUD.Shared.ShowSuccess(this);
                                    Finish();
                                }
                            }
                            else
                            {
                                if (respond is ErrorObject error)
                                {
                                    var errorText = error.Error.ErrorText;
                                    //Show a Error
                                    AndHUD.Shared.ShowError(this, errorText, MaskType.Clear, TimeSpan.FromSeconds(2));
                                }
                                //Methods.DisplayReportResult(this, respond);
                            }
                        }
                        else if (Type == "RemoveUser")
                        {
                            var itemUser = MAdapter.GetItem(Position);
                            if (itemUser != null)
                            {
                                MAdapter.UserList.Remove(itemUser);
                                MAdapter.NotifyItemRemoved(Position);

                                var(apiStatus, respond) = await RequestsAsync.GroupChat
                                                          .AddOrRemoveUserToGroup(GroupId, itemUser.UserId, "remove_user")
                                                          .ConfigureAwait(false);

                                if (apiStatus == 200)
                                {
                                }
                                else
                                {
                                    Methods.DisplayReportResult(this, respond);
                                }
                            }
                        }
                    }
                }
                else if (p1 == DialogAction.Negative)
                {
                    p0.Dismiss();
                }
            }
            catch (Exception e)
            {
                AndHUD.Shared.ShowSuccess(this);
                Console.WriteLine(e);
            }
        }