diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/MessageObject.java b/TMessagesProj/src/main/java/org/telegram/messenger/MessageObject.java index 6148ab1d5..36e39a2df 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/MessageObject.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/MessageObject.java @@ -230,6 +230,10 @@ public class MessageObject { public boolean shouldDrawReactionsInLayout() { return getDialogId() < 0; } + + public boolean isSenderChannel() { + return messageOwner.from_id instanceof TLRPC.TL_peerChannel; + } public static class SendAnimationData { public float x; diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatMessageCell.java b/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatMessageCell.java index e97fe7516..48a890f1b 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatMessageCell.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatMessageCell.java @@ -64,7 +64,6 @@ import android.view.accessibility.AccessibilityManager; import android.view.accessibility.AccessibilityNodeInfo; import android.view.accessibility.AccessibilityNodeProvider; import android.view.animation.Interpolator; -import android.widget.TextView; import android.widget.Toast; import androidx.core.graphics.ColorUtils; @@ -153,6 +152,7 @@ import java.util.Stack; import java.util.concurrent.atomic.AtomicReference; import tw.nekomimi.nekogram.NekoConfig; +import tw.nekomimi.nekogram.NekoXConfig; public class ChatMessageCell extends BaseCell implements SeekBar.SeekBarDelegate, ImageReceiver.ImageReceiverDelegate, DownloadController.FileDownloadProgressListener, TextSelectionHelper.SelectableView, NotificationCenter.NotificationCenterDelegate { @@ -10370,6 +10370,20 @@ public class ChatMessageCell extends BaseCell implements SeekBar.SeekBarDelegate adminString = adminLabel; adminWidth = (int) Math.ceil(Theme.chat_adminPaint.measureText(adminString)); nameWidth -= adminWidth; + } else if (NekoConfig.labelChannelUser.Bool() && isMegagroup && currentChat != null && currentMessageObject.isSenderChannel()) { + final String channelStr = LocaleController.getString("channelLabel", R.string.channelLabel); + if (NekoConfig.channelAlias.Bool()) { + String aliasName = NekoXConfig.getChannelAlias(currentMessageObject.messageOwner.from_id.channel_id); + if (aliasName != null) { + adminString = aliasName + " | " + channelStr; + } else { + adminString = channelStr; + } + } else { + adminString = channelStr; + } + adminWidth = (int) Math.ceil(Theme.chat_adminPaint.measureText(adminString)); + nameWidth -= adminWidth; } else { adminString = null; adminWidth = 0; diff --git a/TMessagesProj/src/main/java/org/telegram/ui/ProfileActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/ProfileActivity.java index d899ba6fb..3ce4fc192 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/ProfileActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/ProfileActivity.java @@ -58,6 +58,7 @@ import android.view.WindowManager; import android.view.accessibility.AccessibilityNodeInfo; import android.view.animation.AccelerateInterpolator; import android.view.animation.DecelerateInterpolator; +import android.view.inputmethod.EditorInfo; import android.widget.EditText; import android.widget.FrameLayout; import android.widget.ImageView; @@ -146,6 +147,7 @@ import org.telegram.ui.Components.ChatAvatarContainer; import org.telegram.ui.Components.CombinedDrawable; import org.telegram.ui.Components.CrossfadeDrawable; import org.telegram.ui.Components.CubicBezierInterpolator; +import org.telegram.ui.Components.EditTextBoldCursor; import org.telegram.ui.Components.FragmentContextView; import org.telegram.ui.Components.HintView; import org.telegram.ui.Components.IdenticonDrawable; @@ -359,7 +361,7 @@ public class ProfileActivity extends BaseFragment implements NotificationCenter. private final static int gallery_menu_save = 21; private final static int event_log = 42; private final static int view_discussion = 22; - + private final static int aliasChannelName = 43; private final static int edit_name = 30; private final static int logout = 31; private final static int search_button = 32; @@ -1656,6 +1658,8 @@ public class ProfileActivity extends BaseFragment implements NotificationCenter. leaveChatPressed(); } else if (id == event_log) { presentFragment(new ChannelAdminLogActivity(currentChat)); + } else if ( id == aliasChannelName){ + setChannelAlias(); } else if (id == edit_channel) { Bundle args = new Bundle(); args.putLong("chat_id", chatId); @@ -4180,6 +4184,62 @@ public class ProfileActivity extends BaseFragment implements NotificationCenter. }); } + private void setChannelAlias() { + AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); + builder.setTitle(LocaleController.getString("setChannelAliasName", R.string.setChannelAliasName)); + + final EditTextBoldCursor editText = new EditTextBoldCursor(getParentActivity()) { + @Override + protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { + super.onMeasure(widthMeasureSpec, + MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(64), MeasureSpec.EXACTLY)); + } + }; + editText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18); + editText.setTextColor(getThemedColor(Theme.key_dialogTextBlack)); + editText.setHintText( + LocaleController.getString("Name", R.string.Name)); + if (NekoXConfig.getChannelAlias(getCurrentChat().id) != null) { + editText.setText(NekoXConfig.getChannelAlias(getCurrentChat().id)); + } + editText.setHeaderHintColor(getThemedColor(Theme.key_windowBackgroundWhiteBlueHeader)); + editText.setSingleLine(true); + editText.setFocusable(true); + editText.setTransformHintToHeader(true); + editText.setLineColors(getThemedColor(Theme.key_windowBackgroundWhiteInputField), + getThemedColor(Theme.key_windowBackgroundWhiteInputFieldActivated), + getThemedColor(Theme.key_windowBackgroundWhiteRedText3)); + editText.setImeOptions(EditorInfo.IME_ACTION_DONE); + editText.setBackgroundDrawable(null); + editText.requestFocus(); + editText.setPadding(0, 0, 0, 0); + builder.setView(editText); + + builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), + (dialogInterface, i) -> { + if (editText.getText().toString().trim().equals("")) { + NekoXConfig.emptyChannelAlias(getCurrentChat().id); + } else { + NekoXConfig.setChannelAlias(getCurrentChat().id, editText.getText().toString()); + } + }); + builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); + builder.show().setOnShowListener(dialog -> { + editText.requestFocus(); + AndroidUtilities.showKeyboard(editText); + }); + ViewGroup.MarginLayoutParams layoutParams = (ViewGroup.MarginLayoutParams) editText.getLayoutParams(); + if (layoutParams != null) { + if (layoutParams instanceof FrameLayout.LayoutParams) { + ((FrameLayout.LayoutParams) layoutParams).gravity = Gravity.CENTER_HORIZONTAL; + } + layoutParams.rightMargin = layoutParams.leftMargin = AndroidUtilities.dp(24); + layoutParams.height = AndroidUtilities.dp(36); + editText.setLayoutParams(layoutParams); + } + editText.setSelection(0, editText.getText().length()); + } + private void getChannelParticipants(boolean reload) { if (loadingUsers || participantsMap == null || chatInfo == null) { return; @@ -6580,6 +6640,9 @@ public class ProfileActivity extends BaseFragment implements NotificationCenter. if (!TextUtils.isEmpty(chat.username)) { otherItem.addSubItem(share, R.drawable.baseline_forward_24, LocaleController.getString("BotShare", R.string.BotShare)); } + if (NekoConfig.channelAlias.Bool()){ + otherItem.addSubItem(aliasChannelName, R.drawable.ic_ab_fave, LocaleController.getString("setChannelAliasName", R.string.setChannelAliasName)); + } if (!currentChat.creator && !currentChat.left && !currentChat.kicked) { otherItem.addSubItem(leave_group, R.drawable.baseline_exit_to_app_24, LocaleController.getString("LeaveChannelMenu", R.string.LeaveChannelMenu)); } diff --git a/TMessagesProj/src/main/java/tw/nekomimi/nekogram/NekoConfig.java b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/NekoConfig.java index 5f56490ef..ab69d1987 100644 --- a/TMessagesProj/src/main/java/tw/nekomimi/nekogram/NekoConfig.java +++ b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/NekoConfig.java @@ -26,6 +26,7 @@ public class NekoConfig { public static final SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nkmrcfg", Context.MODE_PRIVATE); public static final Object sync = new Object(); + public static final String channelAliasPrefix = "channelAliasPrefix_"; private static boolean configLoaded = false; private static final ArrayList configs = new ArrayList<>(); @@ -170,6 +171,9 @@ public class NekoConfig { public static ConfigItem reactions = addConfig("reactions", configTypeInt, 0); public static ConfigItem showBottomActionsWhenSelecting = addConfig("showBottomActionsWhenSelecting", configTypeBool, false); + public static ConfigItem labelChannelUser = addConfig("labelChannelUser", configTypeBool, false); + public static ConfigItem channelAlias = addConfig("channelAlias", configTypeBool, false); + public static ConfigItem disableAutoDownloadingWin32Executable = addConfig("Win32ExecutableFiles", configTypeBool, true); public static ConfigItem disableAutoDownloadingArchive = addConfig("ArchiveFiles", configTypeBool, true); @@ -463,4 +467,5 @@ public class NekoConfig { if (preferences.contains("disableGroupVoipAudioProcessing")) disableGroupVoipAudioProcessing.setConfigBool(preferences.getBoolean("disableGroupVoipAudioProcessing", false)); } + } \ No newline at end of file diff --git a/TMessagesProj/src/main/java/tw/nekomimi/nekogram/NekoXConfig.java b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/NekoXConfig.java index 808bf8273..04348325a 100644 --- a/TMessagesProj/src/main/java/tw/nekomimi/nekogram/NekoXConfig.java +++ b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/NekoXConfig.java @@ -23,6 +23,8 @@ import org.telegram.ui.ActionBar.Theme; import java.io.BufferedReader; import java.io.FileReader; import java.util.Locale; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -215,4 +217,17 @@ public class NekoXConfig { } return color; } + + + public static void setChannelAlias(long channelID, String name) { + preferences.edit().putString(NekoConfig.channelAliasPrefix + channelID, name).apply(); + } + + public static void emptyChannelAlias(long channelID) { + preferences.edit().remove(NekoConfig.channelAliasPrefix + channelID).apply(); + } + + public static String getChannelAlias(long channelID) { + return preferences.getString(NekoConfig.channelAliasPrefix + channelID, null); + } } \ No newline at end of file diff --git a/TMessagesProj/src/main/java/tw/nekomimi/nekogram/settings/NekoChatSettingsActivity.java b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/settings/NekoChatSettingsActivity.java index 42c9e2226..b7b99222d 100644 --- a/TMessagesProj/src/main/java/tw/nekomimi/nekogram/settings/NekoChatSettingsActivity.java +++ b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/settings/NekoChatSettingsActivity.java @@ -70,6 +70,7 @@ public class NekoChatSettingsActivity extends BaseFragment implements Notificati private final AbstractConfigCell unreadBadgeOnBackButton = cellGroup.appendCell(new ConfigCellTextCheck(NekoConfig.unreadBadgeOnBackButton)); private final AbstractConfigCell ignoreBlockedRow = cellGroup.appendCell(new ConfigCellTextCheck(NekoConfig.ignoreBlocked, LocaleController.getString("IgnoreBlockedAbout"))); private final AbstractConfigCell ignoreMutedCountRow = cellGroup.appendCell(new ConfigCellTextCheck(NekoConfig.ignoreMutedCount)); + private final AbstractConfigCell labelChannelUserRow = cellGroup.appendCell(new ConfigCellTextCheck(NekoConfig.labelChannelUser)); private final AbstractConfigCell disableChatActionRow = cellGroup.appendCell(new ConfigCellTextCheck(NekoConfig.disableChatAction)); private final AbstractConfigCell disableChoosingStickerRow = cellGroup.appendCell(new ConfigCellTextCheck(NekoConfig.disableChoosingSticker)); private final AbstractConfigCell disablePhotoSideActionRow = cellGroup.appendCell(new ConfigCellTextCheck(NekoConfig.disablePhotoSideAction)); diff --git a/TMessagesProj/src/main/java/tw/nekomimi/nekogram/settings/NekoExperimentalSettingsActivity.java b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/settings/NekoExperimentalSettingsActivity.java index 6943ae943..8bf0c51fc 100644 --- a/TMessagesProj/src/main/java/tw/nekomimi/nekogram/settings/NekoExperimentalSettingsActivity.java +++ b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/settings/NekoExperimentalSettingsActivity.java @@ -72,6 +72,8 @@ public class NekoExperimentalSettingsActivity extends BaseFragment { private final AbstractConfigCell header1 = cellGroup.appendCell(new ConfigCellHeader(LocaleController.getString("Experiment"))); private final AbstractConfigCell useSystemEmojiRow = cellGroup.appendCell(new ConfigCellTextCheck(NekoConfig.useSystemEmoji)); private final AbstractConfigCell useCustomEmojiRow = cellGroup.appendCell(new ConfigCellTextCheck(NekoConfig.useCustomEmoji)); + private final AbstractConfigCell channelAliasRow = cellGroup.appendCell(new ConfigCellTextCheck(NekoConfig.channelAlias)); + private final AbstractConfigCell smoothKeyboardRow = cellGroup.appendCell(new ConfigCellTextCheck(NekoConfig.smoothKeyboard)); private final AbstractConfigCell increaseVoiceMessageQualityRow = cellGroup.appendCell(new ConfigCellTextCheck(NekoConfig.increaseVoiceMessageQuality)); private final AbstractConfigCell mediaPreviewRow = cellGroup.appendCell(new ConfigCellTextCheck(NekoConfig.mediaPreview)); diff --git a/TMessagesProj/src/main/res/values/strings_neko.xml b/TMessagesProj/src/main/res/values/strings_neko.xml index a0a8add24..e6723e688 100644 --- a/TMessagesProj/src/main/res/values/strings_neko.xml +++ b/TMessagesProj/src/main/res/values/strings_neko.xml @@ -141,5 +141,6 @@ Custom Save Path Leave blank to save directly Show bottom actions when selecting + channel \ No newline at end of file diff --git a/TMessagesProj/src/main/res/values/strings_nekox.xml b/TMessagesProj/src/main/res/values/strings_nekox.xml index d26d9bbf6..9f8ed7199 100644 --- a/TMessagesProj/src/main/res/values/strings_nekox.xml +++ b/TMessagesProj/src/main/res/values/strings_nekox.xml @@ -266,4 +266,10 @@ Show timestamp in seconds Update Nekogram X Press to translate the change log + Name + Channel Alias + Require label channel user enabled. + Set Alias + Label Channel User + If message sender is Channel,it will label it as \"Channel\" \ No newline at end of file