From 1d9c2ae0bb8f740db9963d035a74a2d59932b8b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=96=E7=95=8C?= Date: Wed, 18 Nov 2020 04:55:54 +0000 Subject: [PATCH] Add tgx style unpin --- .../java/org/telegram/ui/ChatActivity.java | 78 +++++++++++++------ .../main/res/drawable/baseline_menu_24.xml | 9 +++ .../main/res/values-zh-rCN/strings_nekox.xml | 3 + .../src/main/res/values/strings_nekox.xml | 4 + 4 files changed, 72 insertions(+), 22 deletions(-) create mode 100644 TMessagesProj/src/main/res/drawable/baseline_menu_24.xml diff --git a/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java index d0650180c..0c3f7c03e 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java @@ -236,6 +236,7 @@ import java.util.regex.Pattern; import cn.hutool.core.util.StrUtil; import kotlin.Unit; +import tw.nekomimi.nekogram.BottomBuilder; import tw.nekomimi.nekogram.JalaliCalendar; import tw.nekomimi.nekogram.MessageDetailsActivity; import tw.nekomimi.nekogram.NekoConfig; @@ -4817,8 +4818,8 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not } pinnedListButton = new ImageView(context); - pinnedListButton.setImageResource(R.drawable.menu_pinnedlist); - pinnedListButton.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_chat_topPanelClose), PorterDuff.Mode.MULTIPLY)); + pinnedListButton.setImageResource(R.drawable.baseline_menu_24); + pinnedListButton.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_chat_topPanelClose), PorterDuff.Mode.SRC_IN)); pinnedListButton.setScaleType(ImageView.ScaleType.CENTER); pinnedListButton.setContentDescription(LocaleController.getString("AccPinnedMessagesList", R.string.AccPinnedMessagesList)); pinnedListButton.setVisibility(View.INVISIBLE); @@ -4826,10 +4827,47 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not pinnedListButton.setScaleX(0.4f); pinnedListButton.setScaleY(0.4f); if (Build.VERSION.SDK_INT >= 21) { - pinnedListButton.setBackgroundDrawable(Theme.createSelectorDrawable(Theme.getColor(Theme.key_inappPlayerClose) & 0x19ffffff)); + pinnedListButton.setBackgroundDrawable(Theme.createSelectorDrawable(Theme.getColor(Theme.key_listSelector))); } pinnedMessageView.addView(pinnedListButton, LayoutHelper.createFrame(36, 48, Gravity.RIGHT | Gravity.TOP, 0, 0, 7, 0)); pinnedListButton.setOnClickListener(v -> openPinnedMessagesList(false)); + pinnedListButton.setOnLongClickListener(v -> { + if (getParentActivity() == null) { + return false; + } + boolean allowPin; + if (currentChat != null) { + allowPin = ChatObject.canPinMessages(currentChat); + } else if (currentEncryptedChat == null) { + if (userInfo != null) { + allowPin = userInfo.can_pin_message; + } else { + allowPin = false; + } + } else { + allowPin = false; + } + BottomBuilder builder = new BottomBuilder(getParentActivity()); + if (allowPin) { + builder.addItem(LocaleController.getString("UnpinMessagesAll", R.string.UnpinMessagesAll), R.drawable.deproko_baseline_pin_undo_24, true, c -> { + getMessagesController().unpinAllMessages(currentChat, currentUser); + return Unit.INSTANCE; + }); + } + builder.addItem(LocaleController.getString("DismissForYourself", R.string.DismissForYourself), R.drawable.baseline_close_24, c -> { + SharedPreferences preferences = MessagesController.getNotificationsSettings(currentAccount); + if (chatInfo != null) { + preferences.edit().putInt("pin_" + dialog_id, chatInfo.pinned_msg_id).apply(); + } else if (userInfo != null) { + preferences.edit().putInt("pin_" + dialog_id, userInfo.pinned_msg_id).apply(); + } + updatePinnedMessageView(true); + return Unit.INSTANCE; + }); + builder.addCancelItem(); + builder.show(); + return true; + }); closePinned = new ImageView(context); closePinned.setImageResource(R.drawable.miniplayer_close); @@ -4859,33 +4897,29 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not } else { allowPin = false; } + BottomBuilder builder = new BottomBuilder(getParentActivity()); if (allowPin) { - AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); - builder.setTitle(LocaleController.getString("UnpinMessageAlertTitle", R.string.UnpinMessageAlertTitle)); - builder.setMessage(LocaleController.getString("UnpinMessageAlert", R.string.UnpinMessageAlert)); - builder.setPositiveButton(LocaleController.getString("UnpinMessage", R.string.UnpinMessage), (dialogInterface, i) -> { + builder.addItem(LocaleController.getString("UnpinMessageX", R.string.UnpinMessageX), R.drawable.deproko_baseline_pin_undo_24, true, c -> { MessageObject messageObject = pinnedMessageObjects.get(currentPinnedMessageId); if (messageObject == null) { messageObject = messagesDict[0].get(currentPinnedMessageId); } unpinMessage(messageObject); + return Unit.INSTANCE; }); - builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); - builder.setNeutralButton(LocaleController.getString("Hide", R.string.Hide), (dialogInterface, i) -> { - SharedPreferences preferences = MessagesController.getNotificationsSettings(currentAccount); - if (chatInfo != null) { - preferences.edit().putInt("pin_" + dialog_id, chatInfo.pinned_msg_id).apply(); - } else if (userInfo != null) { - preferences.edit().putInt("pin_" + dialog_id, userInfo.pinned_msg_id).apply(); - } - updatePinnedMessageView(true); - }); - showDialog(builder.create()); - } else if (!pinnedMessageIds.isEmpty()) { - SharedPreferences preferences = MessagesController.getNotificationsSettings(currentAccount); - preferences.edit().putInt("pin_" + dialog_id, pinnedMessageIds.get(0)).commit(); - updatePinnedMessageView(true); } + builder.addItem(LocaleController.getString("DismissForYourself", R.string.DismissForYourself), R.drawable.baseline_close_24, c -> { + SharedPreferences preferences = MessagesController.getNotificationsSettings(currentAccount); + if (chatInfo != null) { + preferences.edit().putInt("pin_" + dialog_id, chatInfo.pinned_msg_id).apply(); + } else if (userInfo != null) { + preferences.edit().putInt("pin_" + dialog_id, userInfo.pinned_msg_id).apply(); + } + updatePinnedMessageView(true); + return Unit.INSTANCE; + }); + builder.addCancelItem(); + builder.show(); }); } diff --git a/TMessagesProj/src/main/res/drawable/baseline_menu_24.xml b/TMessagesProj/src/main/res/drawable/baseline_menu_24.xml new file mode 100644 index 000000000..e7c37491a --- /dev/null +++ b/TMessagesProj/src/main/res/drawable/baseline_menu_24.xml @@ -0,0 +1,9 @@ + + + diff --git a/TMessagesProj/src/main/res/values-zh-rCN/strings_nekox.xml b/TMessagesProj/src/main/res/values-zh-rCN/strings_nekox.xml index f53e68b54..97131b6da 100644 --- a/TMessagesProj/src/main/res/values-zh-rCN/strings_nekox.xml +++ b/TMessagesProj/src/main/res/values-zh-rCN/strings_nekox.xml @@ -190,4 +190,7 @@ 忽略内容限制 忽略本地消息的 Android 限制。 这可能会在将来被服务器禁止,您需要自己评估此选项的本地合法性。 转发后发送评论 + 解除消息置顶 + 解除置顶所有消息 + 暂时对自己隐藏 diff --git a/TMessagesProj/src/main/res/values/strings_nekox.xml b/TMessagesProj/src/main/res/values/strings_nekox.xml index 9fd46d495..d6ac985c8 100644 --- a/TMessagesProj/src/main/res/values/strings_nekox.xml +++ b/TMessagesProj/src/main/res/values/strings_nekox.xml @@ -249,5 +249,9 @@ Ignores android restrictions on messages locally. This may be banned by the server in the future, and you will need to evaluate the local legality of this option yourself. Send comment after forwarding + Unpin message + Unpin all messages + Dismiss for yourself + \ No newline at end of file