From 81d63a1dd9255e9aaaa2e9a0054a1e418f5c08bf Mon Sep 17 00:00:00 2001 From: xtaodada Date: Tue, 18 Oct 2022 20:57:23 +0800 Subject: [PATCH] feat: Allow Ban In Join Requests List --- .../telegram/ui/Cells/MemberRequestCell.java | 23 +++++++++++++++ .../ui/Delegates/MemberRequestsDelegate.java | 28 ++++++++++++++++++- 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Cells/MemberRequestCell.java b/TMessagesProj/src/main/java/org/telegram/ui/Cells/MemberRequestCell.java index 31faf8f37..a68fa6c35 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Cells/MemberRequestCell.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Cells/MemberRequestCell.java @@ -88,6 +88,27 @@ public class MemberRequestCell extends FrameLayout { dismissLayoutParams.leftMargin = LocaleController.isRTL ? 0 : (int)(addButtonWidth + AndroidUtilities.dp(73 + 6)); dismissLayoutParams.rightMargin = LocaleController.isRTL ? (int)(addButtonWidth + AndroidUtilities.dp(73 + 6)) : 0; addView(dismissButton, dismissLayoutParams); + + float dismissButtonWidth = dismissButton.getPaint().measureText(dismissButton.getText().toString()) + btnPadding * 2; + TextView banButton = new TextView(getContext()); + banButton.setBackground(Theme.AdaptiveRipple.filledRect(Theme.key_featuredStickers_addButton, 4)); + banButton.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.CENTER_VERTICAL); + banButton.setMaxLines(1); + banButton.setPadding(btnPadding, 0, btnPadding, 0); + banButton.setText(LocaleController.getString("KickFromGroup", R.string.KickFromGroup)); + banButton.setTextColor(Theme.getColor(Theme.key_featuredStickers_buttonText)); + banButton.setTextSize(14); + banButton.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf")); + banButton.setOnClickListener(v -> { + if (clickListener != null && importer != null) { + clickListener.onBanClicked(importer); + } + }); + FrameLayout.LayoutParams banLayoutParams = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, AndroidUtilities.dp(32), LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT); + banLayoutParams.topMargin = AndroidUtilities.dp(62); + banLayoutParams.leftMargin = LocaleController.isRTL ? 0 : (int)(addButtonWidth + dismissButtonWidth + AndroidUtilities.dp(73 + 6)); + banLayoutParams.rightMargin = LocaleController.isRTL ? (int)(addButtonWidth + dismissButtonWidth + AndroidUtilities.dp(73 + 6)) : 0; + addView(banButton, banLayoutParams); } public void setData(LongSparseArray users, TLRPC.TL_chatInviteImporter importer, boolean isNeedDivider) { @@ -143,5 +164,7 @@ public class MemberRequestCell extends FrameLayout { void onAddClicked(TLRPC.TL_chatInviteImporter importer); void onDismissClicked(TLRPC.TL_chatInviteImporter importer); + + void onBanClicked(TLRPC.TL_chatInviteImporter importer); } } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Delegates/MemberRequestsDelegate.java b/TMessagesProj/src/main/java/org/telegram/ui/Delegates/MemberRequestsDelegate.java index 9e506864c..c7d5e2370 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Delegates/MemberRequestsDelegate.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Delegates/MemberRequestsDelegate.java @@ -388,6 +388,20 @@ public class MemberRequestsDelegate implements MemberRequestCell.OnClickListener hideChatJoinRequest(importer, false); } + @Override + public void onBanClicked(TLRPC.TL_chatInviteImporter importer) { + kickUser(importer); + hideChatJoinRequest(importer, false); + } + + private void kickUser(TLRPC.TL_chatInviteImporter importer) { + TLRPC.User user = users.get(importer.user_id); + if (user == null) { + return; + } + fragment.getMessagesController().deleteParticipantFromChat(chatId, user); + } + public void setAdapterItemsEnabled(boolean adapterItemsEnabled) { if (recyclerView != null) { int position = adapter.extraFirstHolders(); @@ -735,7 +749,7 @@ public class MemberRequestsDelegate implements MemberRequestCell.OnClickListener }); popupLayout.addView(sendMsgCell); - ActionBarMenuSubItem dismissCell = new ActionBarMenuSubItem(context, false, true); + ActionBarMenuSubItem dismissCell = new ActionBarMenuSubItem(context, false, false); dismissCell.setColors(Theme.getColor(Theme.key_dialogTextRed2, resourcesProvider), Theme.getColor(Theme.key_dialogRedIcon, resourcesProvider)); dismissCell.setSelectorColor(Theme.getColor(Theme.key_dialogButtonSelector, resourcesProvider)); dismissCell.setTextAndIcon(LocaleController.getString("DismissRequest", R.string.DismissRequest), R.drawable.msg_remove); @@ -746,6 +760,18 @@ public class MemberRequestsDelegate implements MemberRequestCell.OnClickListener hidePreview(); }); popupLayout.addView(dismissCell); + + ActionBarMenuSubItem banCell = new ActionBarMenuSubItem(context, false, true); + banCell.setColors(Theme.getColor(Theme.key_dialogTextRed2, resourcesProvider), Theme.getColor(Theme.key_dialogRedIcon, resourcesProvider)); + banCell.setSelectorColor(Theme.getColor(Theme.key_dialogButtonSelector, resourcesProvider)); + banCell.setTextAndIcon(LocaleController.getString("KickFromGroup", R.string.KickFromGroup), R.drawable.profile_ban); + banCell.setOnClickListener((v) -> { + if (importer != null) { + onBanClicked(importer); + } + hidePreview(); + }); + popupLayout.addView(banCell); } @Override