1
0
mirror of https://github.com/NekoX-Dev/NekoX.git synced 2024-12-16 10:29:50 +01:00

Add tgx style unpin

This commit is contained in:
世界 2020-11-18 04:55:54 +00:00
parent 6dce0743db
commit 1d9c2ae0bb
No known key found for this signature in database
GPG Key ID: CD109927C34A63C4
4 changed files with 72 additions and 22 deletions

View File

@ -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();
});
}

View File

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#000000"
android:pathData="M3,18h18v-2L3,16v2zM3,13h18v-2L3,11v2zM3,6v2h18L21,6L3,6z" />
</vector>

View File

@ -190,4 +190,7 @@
<string name="IgnoreContentRestrictions">忽略内容限制</string>
<string name="IgnoreContentRestrictionsNotice">忽略本地消息的 Android 限制。 这可能会在将来被服务器禁止,您需要自己评估此选项的本地合法性。</string>
<string name="SendCommentAfterForward">转发后发送评论</string>
<string name="UnpinMessageX">解除消息置顶</string>
<string name="UnpinMessagesAll">解除置顶所有消息</string>
<string name="DismissForYourself">暂时对自己隐藏</string>
</resources>

View File

@ -249,5 +249,9 @@
<string name="IgnoreContentRestrictionsNotice">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.</string>
<string name="SendCommentAfterForward">Send comment after forwarding</string>
<string name="UnpinMessageX">Unpin message</string>
<string name="UnpinMessagesAll">Unpin all messages</string>
<string name="DismissForYourself">Dismiss for yourself</string>
</resources>