mirror of https://github.com/NekoX-Dev/NekoX.git
feat: add setAliasName (#739)
* feat: add setAliasName Signed-off-by: qwq233 <qwq233@qwq2333.top>
This commit is contained in:
parent
00ae420abf
commit
fd0ea5b158
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
|
|
@ -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<ConfigItem> 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));
|
||||
}
|
||||
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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));
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -141,5 +141,6 @@
|
|||
<string name="customSavePath">Custom Save Path</string>
|
||||
<string name="customSavePathHint">Leave blank to save directly</string>
|
||||
<string name="showBottomActionsWhenSelecting">Show bottom actions when selecting</string>
|
||||
<string name="channelLabel">channel</string>
|
||||
|
||||
</resources>
|
|
@ -266,4 +266,10 @@
|
|||
<string name="showSeconds">Show timestamp in seconds</string>
|
||||
<string name="AppUpdateNekoX">Update Nekogram X</string>
|
||||
<string name="NekoXUpdateTranslationHint">Press to translate the change log</string>
|
||||
<string name="Name">Name</string>
|
||||
<string name="channelAlias">Channel Alias</string>
|
||||
<string name="channelAliasDetails">Require label channel user enabled.</string>
|
||||
<string name="setChannelAliasName">Set Alias</string>
|
||||
<string name="labelChannelUser">Label Channel User</string>
|
||||
<string name="labelChannelUserDetails">If message sender is Channel,it will label it as \"Channel\"</string>
|
||||
</resources>
|
Loading…
Reference in New Issue