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 d299726 commit b0c9279
Show file tree
Hide file tree
Showing 8 changed files with 157 additions and 11 deletions.
2 changes: 1 addition & 1 deletion TMessagesProj/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ apply plugin: "com.android.application"
apply plugin: "kotlin-android"

def verName = "10.6.4"
def verCode = 1158
def verCode = 1159


def officialVer = "10.6.4"
Expand Down
25 changes: 22 additions & 3 deletions 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,22 @@ 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, null, oldResult.path1, oldResult.path2, 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 Expand Up @@ -11937,12 +11955,13 @@ public void search(String text) {
for (int i = 0; i < searchArgs.length; i++) {
if (searchArgs[i].length() != 0) {
String searchString = searchArgs[i];
int index = title.indexOf(" " + searchString);
int index = title.indexOf(searchString);
if (index < 0 && translitArgs[i] != null) {
searchString = translitArgs[i];
index = title.indexOf(" " + searchString);
index = title.indexOf(searchString);
}
if (index >= 0) {
index -= 1;
if (stringBuilder == null) {
stringBuilder = new SpannableStringBuilder(result.searchTitle);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@
import android.text.TextUtils;

import org.telegram.messenger.AndroidUtilities;
import org.telegram.messenger.LocaleController;
import org.telegram.messenger.R;
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 +96,39 @@ 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());
String n_title = LocaleController.getString("NekoSettings", R.string.NekoSettings);
for (BaseNekoXSettingsActivity fragment: fragments) {
int uid = fragment.getBaseGuid();
int drawable = fragment.getDrawable();
String f_title = fragment.getTitle();
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 = uid + 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, n_title, f_title, drawable, open
);
items.add(result);
}
}
return items;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package tw.nekomimi.nekogram.helpers;

public class SettingsSearchResult {

public String searchTitle;
public Runnable openRunnable;
public String path1;
public String path2;
public int iconResId;
public int guid;

public SettingsSearchResult(int guid, String searchTitle,String path1, String path2, int iconResId, Runnable open) {
this.guid = guid;
this.searchTitle = searchTitle;
this.path1 = path1;
this.path2 = path2;
this.iconResId = iconResId;
this.openRunnable = open;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,18 @@ public class BaseNekoXSettingsActivity extends BaseFragment {
protected void updateRows() {
}

public int getBaseGuid() {
return 10000;
}

public int getDrawable() {
return 0;
}

public String getTitle() {
return "";
}

protected void addRowsToMap(CellGroup cellGroup) {
rowMap.clear();
rowMapReverse.clear();
Expand Down Expand Up @@ -68,6 +80,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 +178,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 All @@ -222,7 +226,7 @@ public boolean onFragmentCreate() {
@Override
public View createView(Context context) {
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setTitle(LocaleController.getString("Chat", R.string.Chat));
actionBar.setTitle(getTitle());

if (AndroidUtilities.isTablet()) {
actionBar.setOccupyStatusBar(false);
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,16 @@ protected void updateRows() {
}
}

@Override
public int getDrawable() {
return R.drawable.menu_chats;
}

@Override
public String getTitle() {
return LocaleController.getString("Chat", R.string.Chat);
}

@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 @@ -154,7 +158,7 @@ public boolean onFragmentCreate() {
@Override
public View createView(Context context) {
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setTitle(LocaleController.getString("Experiment", R.string.Experiment));
actionBar.setTitle(getTitle());

if (AndroidUtilities.isTablet()) {
actionBar.setOccupyStatusBar(false);
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,21 @@ protected void updateRows() {
}
}

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

@Override
public int getDrawable() {
return R.drawable.msg_fave;
}

@Override
public String getTitle() {
return LocaleController.getString("Experiment", R.string.Experiment);
}

@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 All @@ -257,7 +261,7 @@ public boolean onFragmentCreate() {
@Override
public View createView(Context context) {
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setTitle(LocaleController.getString("General", R.string.General));
actionBar.setTitle(getTitle());

if (AndroidUtilities.isTablet()) {
actionBar.setOccupyStatusBar(false);
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,21 @@ protected void updateRows() {
}
}

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

@Override
public int getDrawable() {
return R.drawable.msg_theme;
}

@Override
public String getTitle() {
return LocaleController.getString("General", R.string.General);
}

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

0 comments on commit b0c9279

Please sign in to comment.