From 6d282edc6f107c6bf9106c090ed77b4c48142929 Mon Sep 17 00:00:00 2001 From: xtaodada Date: Thu, 15 Feb 2024 14:57:42 +0800 Subject: [PATCH] feat: search config --- .../java/org/telegram/ui/ProfileActivity.java | 22 +++++++++++- .../nekogram/helpers/SettingsHelper.java | 35 +++++++++++++++++++ .../helpers/SettingsSearchResult.java | 17 +++++++++ .../settings/BaseNekoXSettingsActivity.java | 12 ++++++- .../settings/NekoChatSettingsActivity.java | 10 +++++- .../NekoExperimentalSettingsActivity.java | 10 +++++- .../settings/NekoGeneralSettingsActivity.java | 10 +++++- 7 files changed, 111 insertions(+), 5 deletions(-) create mode 100644 TMessagesProj/src/main/java/tw/nekomimi/nekogram/helpers/SettingsSearchResult.java diff --git a/TMessagesProj/src/main/java/org/telegram/ui/ProfileActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/ProfileActivity.java index 2309ddca9f..ce0d6a456a 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/ProfileActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/ProfileActivity.java @@ -285,6 +285,8 @@ import kotlin.Unit; import libv2ray.Libv2ray; import tw.nekomimi.nekogram.BackButtonMenuRecent; +import tw.nekomimi.nekogram.helpers.SettingsHelper; +import tw.nekomimi.nekogram.helpers.SettingsSearchResult; import tw.nekomimi.nekogram.transtale.popupwrapper.AutoTranslatePopupWrapper; import tw.nekomimi.nekogram.ui.BottomBuilder; import tw.nekomimi.nekogram.InternalUpdater; @@ -11401,7 +11403,7 @@ private void updateSearchArray() { } private SearchResult[] onCreateSearchArray() { - return new SearchResult[]{ + SearchResult[] arr = new SearchResult[]{ new SearchResult(500, LocaleController.getString("EditName", R.string.EditName), 0, () -> presentFragment(new ChangeNameActivity(resourcesProvider))), new SearchResult(501, LocaleController.getString("ChangePhoneNumber", R.string.ChangePhoneNumber), 0, () -> presentFragment(new ActionIntroActivity(ActionIntroActivity.ACTION_TYPE_CHANGE_PHONE_NUMBER))), new SearchResult(502, LocaleController.getString("AddAnotherAccount", R.string.AddAnotherAccount), 0, () -> { @@ -11664,6 +11666,24 @@ private SearchResult[] onCreateSearchArray() { new SearchResult(403, LocaleController.getString("TelegramFAQ", R.string.TelegramFAQ), LocaleController.getString("SettingsHelp", R.string.SettingsHelp), R.drawable.msg2_help, () -> Browser.openUrl(getParentActivity(), LocaleController.getString("TelegramFaqUrl", R.string.TelegramFaqUrl))), new SearchResult(404, LocaleController.getString("PrivacyPolicy", R.string.PrivacyPolicy), LocaleController.getString("SettingsHelp", R.string.SettingsHelp), R.drawable.msg2_help, () -> Browser.openUrl(getParentActivity(), LocaleController.getString("PrivacyPolicyUrl", R.string.PrivacyPolicyUrl))), }; + ArrayList nagramSettings = SettingsHelper.onCreateSearchArray( + fragment -> { + AndroidUtilities.runOnUIThread(() -> presentFragment(fragment, false, false)); + } + ); + ArrayList list = new ArrayList<>(); + for (SettingsSearchResult oldResult: nagramSettings) { + SearchResult result = new SearchResult( + oldResult.guid, oldResult.searchTitle, oldResult.iconResId, oldResult.openRunnable + ); + list.add(result); + } + // combine + SearchResult[] result = Arrays.copyOf(arr, arr.length + list.size()); + for (int i = 0; i < list.size(); i++) { + result[arr.length + i] = list.get(i); + } + return result; } private boolean isPremiumFeatureAvailable(int feature) { diff --git a/TMessagesProj/src/main/java/tw/nekomimi/nekogram/helpers/SettingsHelper.java b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/helpers/SettingsHelper.java index e2d8f3a78d..fded381b08 100644 --- a/TMessagesProj/src/main/java/tw/nekomimi/nekogram/helpers/SettingsHelper.java +++ b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/helpers/SettingsHelper.java @@ -4,8 +4,12 @@ import android.text.TextUtils; import org.telegram.messenger.AndroidUtilities; +import org.telegram.messenger.LocaleController; import org.telegram.ui.ActionBar.BaseFragment; +import java.util.ArrayList; +import java.util.Map; + import tw.nekomimi.nekogram.settings.BaseNekoSettingsActivity; import tw.nekomimi.nekogram.settings.BaseNekoXSettingsActivity; import tw.nekomimi.nekogram.settings.NekoChatSettingsActivity; @@ -91,4 +95,35 @@ public static void processDeepLink(Uri uri, Callback callback, Runnable unknown) public interface Callback { void presentFragment(BaseFragment fragment); } + + public static ArrayList onCreateSearchArray(Callback callback) { + ArrayList items = new ArrayList<>(); + ArrayList fragments = new ArrayList<>(); + fragments.add(new NekoGeneralSettingsActivity()); + fragments.add(new NekoChatSettingsActivity()); + fragments.add(new NekoExperimentalSettingsActivity()); + for (BaseNekoXSettingsActivity fragment: fragments) { + for (Map.Entry entry : fragment.getRowMapReverse().entrySet()) { + Integer i = entry.getKey(); + String key = entry.getValue(); + if (key.equals(String.valueOf(i))) { + continue; + } + int guid = fragment.getBaseGuid() + i; + String title = LocaleController.getString(key); + if (title == null || title.isEmpty()) { + continue; + } + Runnable open = () -> { + callback.presentFragment(fragment); + AndroidUtilities.runOnUIThread(() -> fragment.scrollToRow(key, null)); + }; + SettingsSearchResult result = new SettingsSearchResult( + guid, title, 0, open + ); + items.add(result); + } + } + return items; + } } diff --git a/TMessagesProj/src/main/java/tw/nekomimi/nekogram/helpers/SettingsSearchResult.java b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/helpers/SettingsSearchResult.java new file mode 100644 index 0000000000..342b5dd1b2 --- /dev/null +++ b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/helpers/SettingsSearchResult.java @@ -0,0 +1,17 @@ +package tw.nekomimi.nekogram.helpers; + +public class SettingsSearchResult { + + public String searchTitle; + public Runnable openRunnable; + public String[] path; + public int iconResId; + public int guid; + + public SettingsSearchResult(int guid, String searchTitle, int iconResId, Runnable open) { + this.guid = guid; + this.searchTitle = searchTitle; + this.iconResId = iconResId; + this.openRunnable = open; + } +} diff --git a/TMessagesProj/src/main/java/tw/nekomimi/nekogram/settings/BaseNekoXSettingsActivity.java b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/settings/BaseNekoXSettingsActivity.java index cc117130c7..e60d4804e4 100644 --- a/TMessagesProj/src/main/java/tw/nekomimi/nekogram/settings/BaseNekoXSettingsActivity.java +++ b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/settings/BaseNekoXSettingsActivity.java @@ -30,6 +30,10 @@ public class BaseNekoXSettingsActivity extends BaseFragment { protected void updateRows() { } + public int getBaseGuid() { + return 10000; + } + protected void addRowsToMap(CellGroup cellGroup) { rowMap.clear(); rowMapReverse.clear(); @@ -68,6 +72,8 @@ protected ConfigItem getBindConfig(AbstractConfigCell row) { return ((ConfigCellTextDetail) row).getBindConfig(); } else if (row instanceof ConfigCellTextInput) { return ((ConfigCellTextInput) row).getBindConfig(); + } else if (row instanceof ConfigCellAutoTextCheck) { + return ((ConfigCellAutoTextCheck) row).getBindConfig(); } return null; } @@ -164,8 +170,12 @@ public void scrollToRow(String key, Runnable unknown) { layoutManager.scrollToPositionWithOffset(finalPosition, AndroidUtilities.dp(60)); return finalPosition; }); - } else { + } else if (unknown != null) { unknown.run(); } } + + public HashMap getRowMapReverse() { + return rowMapReverse; + } } 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 1620fb82cf..460b3e0751 100644 --- a/TMessagesProj/src/main/java/tw/nekomimi/nekogram/settings/NekoChatSettingsActivity.java +++ b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/settings/NekoChatSettingsActivity.java @@ -205,6 +205,10 @@ public class NekoChatSettingsActivity extends BaseNekoXSettingsActivity implemen private EmojiSetCell emojiSetCell; private UndoView tooltip; + public NekoChatSettingsActivity() { + addRowsToMap(cellGroup); + } + @Override public boolean onFragmentCreate() { EmojiHelper.getInstance().loadEmojisInfo(this); @@ -339,7 +343,6 @@ public void onItemClick(int id) { } } }); - addRowsToMap(cellGroup); listView.setOnItemLongClickListener((view, position, x, y) -> { var holder = listView.findViewHolderForAdapterPosition(position); if (holder != null && listAdapter.isEnabled(holder)) { @@ -386,6 +389,11 @@ protected void updateRows() { } } + @Override + public int getBaseGuid() { + return 10000; + } + @Override public ArrayList getThemeDescriptions() { ArrayList themeDescriptions = new ArrayList<>(); 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 c34065ef2c..f98fed0b51 100644 --- a/TMessagesProj/src/main/java/tw/nekomimi/nekogram/settings/NekoExperimentalSettingsActivity.java +++ b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/settings/NekoExperimentalSettingsActivity.java @@ -116,6 +116,10 @@ public class NekoExperimentalSettingsActivity extends BaseNekoXSettingsActivity private static final int INTENT_PICK_CUSTOM_EMOJI_PACK = 114; private static final int INTENT_PICK_EXTERNAL_STICKER_DIRECTORY = 514; + public NekoExperimentalSettingsActivity() { + addRowsToMap(cellGroup); + } + private void setExternalStickerCacheCellsEnabled(boolean enabled) { ((ConfigCellText) externalStickerCacheSyncAllRow).setEnabled(enabled); ((ConfigCellText) externalStickerCacheDeleteAllRow).setEnabled(enabled); @@ -257,7 +261,6 @@ public void onItemClick(int id) { } } }); - addRowsToMap(cellGroup); listView.setOnItemLongClickListener((view, position, x, y) -> { var holder = listView.findViewHolderForAdapterPosition(position); if (holder != null && listAdapter.isEnabled(holder)) { @@ -368,6 +371,11 @@ protected void updateRows() { } } + @Override + public int getBaseGuid() { + return 11000; + } + @Override public ArrayList getThemeDescriptions() { ArrayList themeDescriptions = new ArrayList<>(); diff --git a/TMessagesProj/src/main/java/tw/nekomimi/nekogram/settings/NekoGeneralSettingsActivity.java b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/settings/NekoGeneralSettingsActivity.java index 92b583cac0..2a854a7b78 100644 --- a/TMessagesProj/src/main/java/tw/nekomimi/nekogram/settings/NekoGeneralSettingsActivity.java +++ b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/settings/NekoGeneralSettingsActivity.java @@ -244,6 +244,10 @@ public class NekoGeneralSettingsActivity extends BaseNekoXSettingsActivity { private ChatBlurAlphaSeekBar chatBlurAlphaSeekbar; private UndoView restartTooltip; + public NekoGeneralSettingsActivity() { + addRowsToMap(cellGroup); + } + @Override public boolean onFragmentCreate() { super.onFragmentCreate(); @@ -382,7 +386,6 @@ public void onItemClick(int id) { } } }); - addRowsToMap(cellGroup); listView.setOnItemLongClickListener((view, position, x, y) -> { var holder = listView.findViewHolderForAdapterPosition(position); if (holder != null && listAdapter.isEnabled(holder)) { @@ -659,6 +662,11 @@ protected void updateRows() { } } + @Override + public int getBaseGuid() { + return 12000; + } + @Override public ArrayList getThemeDescriptions() { ArrayList themeDescriptions = new ArrayList<>();