示例#1
0
        private void MAdapterOnItemClick(object sender, BlockedUsersAdapterClickEventArgs adapterClickEvents)
        {
            try
            {
                var position = adapterClickEvents.Position;
                if (position >= 0)
                {
                    var item = MAdapter.GetItem(position);
                    if (item != null)
                    {
                        var local = MAdapter?.UserList?.FirstOrDefault(a => a.UserId == item.UserId);
                        if (local != null)
                        {
                            MAdapter?.UserList.Remove(local);
                            MAdapter?.NotifyItemRemoved(MAdapter.UserList.IndexOf(local));
                        }

                        if (MAdapter?.UserList?.Count == 0)
                        {
                            ShowEmptyPage();
                        }

                        Toast.MakeText(Application.Context, GetString(Resource.String.Lbl_Unblock_successfully), ToastLength.Short)?.Show();

                        PollyController.RunRetryPolicyFunction(new List <Func <Task> > {
                            () => RequestsAsync.Global.Block_User(item.UserId, false)
                        });                                                                                                                        //false >> "un-block"
                    }
                }
            }
            catch (Exception e)
            {
                Methods.DisplayReportResultTrack(e);
            }
        }
        public async void OnClick(MaterialDialog p0, DialogAction p1)
        {
            try
            {
                if (p1 == DialogAction.Positive)
                {
                    if (Methods.CheckConnectivity())
                    {
                        var itemUser = MAdapter.GetItem(Position);
                        if (itemUser != null)
                        {
                            var index = MAdapter.BlockedUsersList.IndexOf(itemUser);
                            if (index != -1)
                            {
                                MAdapter.BlockedUsersList.Remove(itemUser);
                                MAdapter.NotifyItemRemoved(index);
                            }

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

                            await RequestsAsync.User.BlockUnBlockUserAsync(itemUser.Id.ToString(), false).ConfigureAwait(false);
                        }
                    }
                    else
                    {
                        Toast.MakeText(this, GetText(Resource.String.Lbl_CheckYourInternetConnection), ToastLength.Short).Show();
                    }

                    if (MAdapter.BlockedUsersList.Count == 0)
                    {
                        MRecycler.Visibility = ViewStates.Gone;

                        if (Inflated == null)
                        {
                            Inflated = EmptyStateLayout.Inflate();
                        }

                        EmptyStateInflater x = new EmptyStateInflater();
                        x.InflateLayout(Inflated, EmptyStateInflater.Type.NoBlock);
                        if (x.EmptyStateButton.HasOnClickListeners)
                        {
                            x.EmptyStateButton.Click += null;
                        }
                        EmptyStateLayout.Visibility = ViewStates.Visible;
                    }
                }
                else if (p1 == DialogAction.Negative)
                {
                    p0.Dismiss();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }