Skip to content

Commit

Permalink
feat: search config
Browse files Browse the repository at this point in the history
  • Loading branch information
omg-xtao committed Feb 15, 2024
1 parent 9387057 commit 6d282ed
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 5 deletions.
22 changes: 21 additions & 1 deletion TMessagesProj/src/main/java/org/telegram/ui/ProfileActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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, () -> {
Expand Down Expand Up @@ -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<SettingsSearchResult> nagramSettings = SettingsHelper.onCreateSearchArray(
fragment -> {
AndroidUtilities.runOnUIThread(() -> presentFragment(fragment, false, false));
}
);
ArrayList<SearchResult> 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -91,4 +95,35 @@ public static void processDeepLink(Uri uri, Callback callback, Runnable unknown)
public interface Callback {
void presentFragment(BaseFragment fragment);
}

public static ArrayList<SettingsSearchResult> onCreateSearchArray(Callback callback) {
ArrayList<SettingsSearchResult> items = new ArrayList<>();
ArrayList<BaseNekoXSettingsActivity> fragments = new ArrayList<>();
fragments.add(new NekoGeneralSettingsActivity());
fragments.add(new NekoChatSettingsActivity());
fragments.add(new NekoExperimentalSettingsActivity());
for (BaseNekoXSettingsActivity fragment: fragments) {
for (Map.Entry<Integer, String> 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;
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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<Integer, String> getRowMapReverse() {
return rowMapReverse;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -386,6 +389,11 @@ protected void updateRows() {
}
}

@Override
public int getBaseGuid() {
return 10000;
}

@Override
public ArrayList<ThemeDescription> getThemeDescriptions() {
ArrayList<ThemeDescription> themeDescriptions = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -368,6 +371,11 @@ protected void updateRows() {
}
}

@Override
public int getBaseGuid() {
return 11000;
}

@Override
public ArrayList<ThemeDescription> getThemeDescriptions() {
ArrayList<ThemeDescription> themeDescriptions = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -659,6 +662,11 @@ protected void updateRows() {
}
}

@Override
public int getBaseGuid() {
return 12000;
}

@Override
public ArrayList<ThemeDescription> getThemeDescriptions() {
ArrayList<ThemeDescription> themeDescriptions = new ArrayList<>();
Expand Down

0 comments on commit 6d282ed

Please sign in to comment.