Skip to content

Commit

Permalink
feat: User Nickname As Custom Title
Browse files Browse the repository at this point in the history
Co-authored-by: dic1911 <d69873@gmail.com>
  • Loading branch information
omg-xtao and dic1911 committed Dec 21, 2024
1 parent 66ea7e3 commit d5b4148
Showing 6 changed files with 36 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -3376,7 +3376,12 @@ public boolean canToggleSearch() {
} else {
statusDrawable = new AnimatedEmojiDrawable.SwapAnimatedEmojiDrawable(null, dp(26));
statusDrawable.center = true;
actionBar.setTitle(NaConfig.INSTANCE.getCustomTitle().String(), statusDrawable);
String title = NaConfig.INSTANCE.getCustomTitle().String();
if (NaConfig.INSTANCE.getCustomTitleUserName().Bool()) {
TLRPC.User self = UserConfig.getInstance(currentAccount).getCurrentUser();
if (self != null && self.first_name != null) title = self.first_name;
}
actionBar.setTitle(title, statusDrawable);
actionBar.setOnLongClickListener(v -> {
if (NekoConfig.hideAllTab.Bool() && filterTabsView != null && filterTabsView.getCurrentTabId() != Integer.MAX_VALUE) {
filterTabsView.toggleAllTabs(true);
Original file line number Diff line number Diff line change
@@ -23,6 +23,8 @@ public class ConfigCellTextInput extends AbstractConfigCell {
private final ConfigItem bindConfig;
private final String hint;
private final String title;
private boolean enabled = true;
public TextSettingsCell cell;
private final Runnable onClickCustom;
private final Function<String, String> inputChecker;

@@ -60,15 +62,25 @@ public String getKey() {
}

public boolean isEnabled() {
return true;
return enabled;
}

public void setEnabled(boolean enabled) {
this.enabled = enabled;
if (this.cell != null)
this.cell.setEnabled(this.enabled, null);
}

public void onBindViewHolder(RecyclerView.ViewHolder holder) {
TextSettingsCell cell = (TextSettingsCell) holder.itemView;
this.cell = cell;
cell.setTextAndValue(title, bindConfig.String(), cellGroup.needSetDivider(this));
cell.setCanDisable(true);
cell.setEnabled(enabled, null);
}

public void onClick() {
if (!enabled) return;
if (onClickCustom != null) {
try {
onClickCustom.run();
Original file line number Diff line number Diff line change
@@ -233,6 +233,7 @@ public class NekoGeneralSettingsActivity extends BaseNekoXSettingsActivity {
private final AbstractConfigCell customSavePathRow = cellGroup.appendCell(new ConfigCellTextInput(null, NekoConfig.customSavePath,
LocaleController.getString("customSavePathHint", R.string.customSavePathHint), null,
(input) -> input.matches("^[A-za-z0-9.]{1,255}$") || input.isEmpty() ? input : (String) NekoConfig.customSavePath.defaultValue));
private final AbstractConfigCell customTitleUserNameRow = cellGroup.appendCell(new ConfigCellTextCheck(NaConfig.INSTANCE.getCustomTitleUserName()));
private final AbstractConfigCell useSystemUnlockRow = cellGroup.appendCell(new ConfigCellTextCheck(NaConfig.INSTANCE.getUseSystemUnlock()));
private final AbstractConfigCell disableUndoRow = cellGroup.appendCell(new ConfigCellTextCheck(NekoConfig.disableUndo));
private final AbstractConfigCell showIdAndDcRow = cellGroup.appendCell(new ConfigCellTextCheck(NekoConfig.showIdAndDc));
@@ -503,6 +504,11 @@ public void onItemClick(int id) {
restartTooltip.showWithAction(0, UndoView.ACTION_NEED_RESATRT, null, null);
} else if (key.equals(NaConfig.INSTANCE.getSentryAnalytics().getKey())) {
restartTooltip.showWithAction(0, UndoView.ACTION_NEED_RESATRT, null, null);
} else if (key.equals(NaConfig.INSTANCE.getCustomTitleUserName().getKey())) {
boolean enabled = (Boolean) newValue;
((ConfigCellTextInput) customTitleRow).setEnabled(!enabled);
listAdapter.notifyItemChanged(cellGroup.rows.indexOf(customTitleRow));
restartTooltip.showWithAction(0, UndoView.ACTION_NEED_RESATRT, null, null);
}
};

@@ -891,6 +897,9 @@ private void setCanNotChange() {
if (NekoConfig.useOSMDroidMap.Bool())
((ConfigCellTextCheck) mapDriftingFixForGoogleMapsRow).setEnabled(false);

if (NaConfig.INSTANCE.getCustomTitleUserName().Bool())
((ConfigCellTextInput) customTitleRow).setEnabled(false);

if (NekoConfig.useTelegramTranslateInChat.Bool())
((ConfigCellCustom) translationProviderRow).setEnabled(false);

Original file line number Diff line number Diff line change
@@ -664,6 +664,12 @@ object NaConfig {
ConfigItem.configTypeBool,
false
)
val customTitleUserName =
addConfig(
"CustomTitleUserName",
ConfigItem.configTypeBool,
false
)

private fun addConfig(
k: String,
1 change: 1 addition & 0 deletions TMessagesProj/src/main/res/values-zh-rCN/strings_na.xml
Original file line number Diff line number Diff line change
@@ -167,4 +167,5 @@
<string name="SendWithoutPangu">不使用 Pangu 发送</string>
<string name="DefaultHlsVideoQuality">默认 Hls 视频质量</string>
<string name="DisableBotOpenButton">禁用 Bot 的打开小程序按钮</string>
<string name="CustomTitleUserName">使用用户昵称作为标题</string>
</resources>
1 change: 1 addition & 0 deletions TMessagesProj/src/main/res/values/strings_na.xml
Original file line number Diff line number Diff line change
@@ -168,4 +168,5 @@
<string name="SendWithoutPangu">Send without Pangu</string>
<string name="DefaultHlsVideoQuality">Default Hls Video Quality</string>
<string name="DisableBotOpenButton">Disable Bot Open Button</string>
<string name="CustomTitleUserName">Use user nickname as Title</string>
</resources>

0 comments on commit d5b4148

Please sign in to comment.