New Config

This commit is contained in:
arm64v8a 2021-10-28 20:09:56 +08:00
parent 81c43686ca
commit edb9fc5501
4 changed files with 680 additions and 2 deletions

View File

@ -63,6 +63,7 @@ import tw.nekomimi.nekogram.utils.AlertUtil;
import tw.nekomimi.nekogram.utils.FileUtil;
import tw.nekomimi.nekogram.utils.GsonUtil;
import tw.nekomimi.nekogram.utils.ShareUtil;
import tw.nekomimi.nkmr.NekomuraSettingsFragment;
@SuppressLint("RtlHardcoded")
public class NekoSettingsActivity extends BaseFragment {
@ -76,6 +77,7 @@ public class NekoSettingsActivity extends BaseFragment {
private int accountRow;
private int chatRow;
private int experimentRow;
private int nekomuraSettingsRow;
private int categories2Row;
private int aboutRow;
@ -171,6 +173,8 @@ public class NekoSettingsActivity extends BaseFragment {
presentFragment(new NekoAccountSettingsActivity());
} else if (position == experimentRow) {
presentFragment(new NekoExperimentalSettingsActivity());
} else if (position == nekomuraSettingsRow) {
presentFragment(new NekomuraSettingsFragment());
} else if (position == channelRow) {
MessagesController.getInstance(currentAccount).openByUserName("NekogramX", this, 1);
} else if (position == translationRow) {
@ -199,6 +203,7 @@ public class NekoSettingsActivity extends BaseFragment {
}
//TODO save NekomuraConfig
private String backupSettingsJson() throws JSONException {
JSONObject configJson = new JSONObject();
@ -376,6 +381,7 @@ public class NekoSettingsActivity extends BaseFragment {
accountRow = rowCount++;
chatRow = rowCount++;
experimentRow = rowCount++;
nekomuraSettingsRow = rowCount++;
categories2Row = rowCount++;
aboutRow = rowCount++;
@ -467,9 +473,11 @@ public class NekoSettingsActivity extends BaseFragment {
} else if (position == generalRow) {
textCell.setTextAndIcon(LocaleController.getString("General", R.string.General), R.drawable.baseline_palette_24, true);
} else if (position == experimentRow) {
textCell.setTextAndIcon(LocaleController.getString("Experiment", R.string.Experiment), R.drawable.baseline_star_24, false);
textCell.setTextAndIcon(LocaleController.getString("Experiment", R.string.Experiment), R.drawable.baseline_star_24, true);
} else if (position == accountRow) {
textCell.setTextAndIcon(LocaleController.getString("Account", R.string.Account), R.drawable.baseline_person_24, true);
} else if (position == nekomuraSettingsRow) {
textCell.setTextAndIcon(LocaleController.getString("NekomuraSettings", R.string.NekomuraSettings), R.drawable.notification, false);
}
break;
}
@ -547,7 +555,7 @@ public class NekoSettingsActivity extends BaseFragment {
public int getItemViewType(int position) {
if (position == categories2Row || position == about2Row) {
return 1;
} else if (position == chatRow || position == accountRow || position == generalRow || position == experimentRow) {
} else if (position == chatRow || position == accountRow || position == generalRow || position == experimentRow || position == nekomuraSettingsRow) {
return 2;
} else if (position == categoriesRow || position == aboutRow) {
return 4;

View File

@ -0,0 +1,252 @@
package tw.nekomimi.nkmr;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import org.telegram.messenger.ApplicationLoader;
import org.telegram.messenger.FileLog;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import android.util.Base64;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
@SuppressLint("ApplySharedPref")
public class NekomuraConfig {
private static final int configTypeBool = 0;
private static final int configTypeInt = 1;
private static final int configTypeString = 2;
private static final int configTypeSetInt = 3;
private static final int configTypeMapIntInt = 4;
public static class ConfigItem {
private String key;
private int type;
private Object defaultValue;
private Object value;
private boolean forceDefault;//针对某些人的垃圾选项应该不允许改变默认值
private ConfigItem(String k, int t, Object d) {
key = k;
type = t;
defaultValue = d;
}
public String getKey() {
return key;
}
// 读配置
public boolean Bool() {
return (boolean) value;
}
public int Int() {
return (int) value;
}
public String String() {
return value.toString();
}
public HashSet<Integer> SetInt() {
return (HashSet<Integer>) value;
}
public HashMap<Integer, Integer> MapIntInt() {
return (HashMap<Integer, Integer>) value;
}
public boolean SetIntContains(Integer v) {
return ((HashSet<Integer>) value).contains(v);
}
public void changed(Object o) {
value = o;
}
//写配置
//这里没有检查类型哦
public boolean toggleConfigBool() {
value = !this.Bool();
if (forceDefault) {
value = defaultValue;
}
saveConfig();
return this.Bool();//返回toggle之后的
}
public void setConfigBool(boolean v) {
value = v;
if (forceDefault) {
value = defaultValue;
}
saveConfig();
}
public void setConfigInt(int v) {
if (forceDefault) {
value = defaultValue;
}
value = v;
saveConfig();
}
public void setConfigString(String v) {
value = v;
if (forceDefault) {
value = defaultValue;
}
saveConfig();
}
public void setConfigSetInt(HashSet<Integer> v) {
value = v;
if (forceDefault) {
value = defaultValue;
}
saveConfig();
}
public void setConfigMapInt(HashMap<Integer, Integer> v) {
value = v;
saveConfig();
}
}
private static boolean configLoaded;
private static final Object sync = new Object();
private static ArrayList<ConfigItem> configs = new ArrayList<>();
// Configs
public static ConfigItem largeAvatarInDrawer = addConfig("largeAvatarInDrawer", configTypeInt, 0); // 0:TG Default 1:NekoX Default 2:Large Avatar
//TODO NekoConfig 那个 useAvatar 还没有迁移过来所以只实现了 largeAvatarInDrawer=2 的情况
public static ConfigItem unreadBadgeOnBackButton = addConfig("unreadBadgeOnBackButton", configTypeBool, false);
static {
loadConfig(false);
}
public static ConfigItem addConfig(String k, int t, Object d) {
ConfigItem a = new ConfigItem(k, t, d);
configs.add(a);
return a;
}
public static ConfigItem findOne(String key) {
for (int i = 0; i < configs.size(); i++) {
ConfigItem o = configs.get(i);
if (key.equals(o.key)) {
return o;
}
}
return null;
}
public static void loadConfig(boolean force) {
synchronized (sync) {
if (configLoaded && !force) {
return;
}
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nkmrcfg", Activity.MODE_PRIVATE);
for (int i = 0; i < configs.size(); i++) {
ConfigItem o = configs.get(i);
if (o.forceDefault) {
o.value = o.defaultValue;
continue;
}
if (o.type == configTypeBool) {
o.value = preferences.getBoolean(o.key, (boolean) o.defaultValue);
}
if (o.type == configTypeInt) {
o.value = preferences.getInt(o.key, (int) o.defaultValue);
}
if (o.type == configTypeString) {
o.value = preferences.getString(o.key, (String) o.defaultValue);
}
if (o.type == configTypeSetInt) {
Set<String> ss = preferences.getStringSet(o.key, new HashSet<>());
HashSet<Integer> si = new HashSet<>();
for (String s : ss) {
si.add(Integer.parseInt(s));
}
o.value = si;
}
if (o.type == configTypeMapIntInt) {
String cv = preferences.getString(o.key, "");
// Log.e("NC", String.format("Getting pref %s val %s", o.key, cv));
if (cv.length() == 0) {
o.value = new HashMap<Integer, Integer>();
} else {
try {
byte[] data = Base64.decode(cv, Base64.DEFAULT);
ObjectInputStream ois = new ObjectInputStream(
new ByteArrayInputStream(data));
o.value = (HashMap<Integer, Integer>) ois.readObject();
if (o.value == null) {
o.value = new HashMap<Integer, Integer>();
}
ois.close();
} catch (Exception e) {
o.value = new HashMap<Integer, Integer>();
}
}
}
}
configLoaded = true;
}
}
public static void saveConfig() {
synchronized (sync) {
try {
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nkmrcfg", Context.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
for (int i = 0; i < configs.size(); i++) {
ConfigItem o = configs.get(i);
if (o.type == configTypeBool) {
editor.putBoolean(o.key, (boolean) o.value);
}
if (o.type == configTypeInt) {
editor.putInt(o.key, (int) o.value);
}
if (o.type == configTypeString) {
editor.putString(o.key, o.value.toString());
}
if (o.type == configTypeSetInt) {
HashSet<String> ss = new HashSet<>();
for (Integer n : (Set<Integer>) o.value) {
ss.add(Integer.toString(n));
}
editor.putStringSet(o.key, ss);
}
if (o.type == configTypeMapIntInt) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(o.value);
oos.close();
editor.putString(o.key, Base64.encodeToString(baos.toByteArray(), Base64.DEFAULT));
}
}
editor.commit();
} catch (Exception e) {
FileLog.e(e);
}
}
}
}

View File

@ -0,0 +1,411 @@
package tw.nekomimi.nkmr;
import android.annotation.SuppressLint;
import android.content.Context;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import org.telegram.messenger.AndroidUtilities;
import org.telegram.messenger.LocaleController;
import org.telegram.messenger.MessagesController;
import org.telegram.messenger.NotificationCenter;
import org.telegram.messenger.R;
import org.telegram.messenger.UserConfig;
import org.telegram.messenger.UserObject;
import org.telegram.tgnet.TLRPC;
import org.telegram.ui.ActionBar.ActionBar;
import org.telegram.ui.ActionBar.AlertDialog;
import org.telegram.ui.ActionBar.BaseFragment;
import org.telegram.ui.ActionBar.Theme;
import org.telegram.ui.ActionBar.ThemeDescription;
import org.telegram.ui.Cells.EmptyCell;
import org.telegram.ui.Cells.HeaderCell;
import org.telegram.ui.Cells.NotificationsCheckCell;
import org.telegram.ui.Cells.RadioColorCell;
import org.telegram.ui.Cells.ShadowSectionCell;
import org.telegram.ui.Cells.TextCheckCell;
import org.telegram.ui.Cells.TextDetailSettingsCell;
import org.telegram.ui.Cells.TextInfoPrivacyCell;
import org.telegram.ui.Cells.TextSettingsCell;
import org.telegram.ui.Components.LayoutHelper;
import org.telegram.ui.Components.RecyclerListView;
import java.util.ArrayList;
@SuppressLint("RtlHardcoded")
public class NekomuraSettingsFragment extends BaseFragment {
private RecyclerListView listView;
private ListAdapter listAdapter;
private ArrayList<NekomuraTGCell> rows = new ArrayList<>();
//添加设置行
private final NekomuraTGCell header1 = addNekomuraTGCell(new NekomuraTGHeader(LocaleController.getString("General")));
private final NekomuraTGCell largeAvatarInDrawer = addNekomuraTGCell(new NekomuraTGTextSettings(null, NekomuraConfig.largeAvatarInDrawer, LocaleController.getString("valuesLargeAvatarInDrawer"), null));
private final NekomuraTGCell unreadBadgeOnBackButton = addNekomuraTGCell(new NekomuraTGTextCheck(NekomuraConfig.unreadBadgeOnBackButton));
private final NekomuraTGCell divider1 = addNekomuraTGCell(new NekomuraTGDivider());
private static final int ITEM_TYPE_DIVIDER = 1;
private static final int ITEM_TYPE_TEXT_SETTINGS = 2; //可以在右边设置文字
private static final int ITEM_TYPE_TEXT_CHECK = 3;
private static final int ITEM_TYPE_HEADER = 4;
private static final int ITEM_TYPE_TEXT_DETAIL = 6;
private static final int ITEM_TYPE_TEXT = 7;
public NekomuraTGCell addNekomuraTGCell(NekomuraTGCell a) {
rows.add(a);
return a;
}
@Override
public boolean onFragmentCreate() {
super.onFragmentCreate();
updateRows();
return true;
}
@SuppressLint("NewApi")
@Override
public View createView(Context context) {
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setTitle(LocaleController.getString("NekomuraSettings", R.string.NekomuraSettings));
actionBar.setOccupyStatusBar(!AndroidUtilities.isTablet());
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@Override
public void onItemClick(int id) {
if (id == -1) {
finishFragment();
}
}
});
listAdapter = new ListAdapter(context);
fragmentView = new FrameLayout(context);
fragmentView.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundGray));
FrameLayout frameLayout = (FrameLayout) fragmentView;
listView = new RecyclerListView(context);
listView.setVerticalScrollBarEnabled(false);
listView.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false));
frameLayout.addView(listView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT));
listView.setAdapter(listAdapter);
// 上面是各种窗口初始化
// 设置回调事件
listView.setOnItemClickListener((view, position, x, y) -> {
NekomuraTGCell a = rows.get(position);
if (a instanceof NekomuraTGTextCheck) {
((NekomuraTGTextCheck) a).onClick((TextCheckCell) view);
} else if (a instanceof NekomuraTGTextSettings) {
((NekomuraTGTextSettings) a).onClick();
}
});
listView.setOnItemLongClickListener((view, position) -> {
return true;
});
return fragmentView;
}
@Override
public void onResume() {
super.onResume();
if (listAdapter != null) {
listAdapter.notifyDataSetChanged();
}
}
private void updateRows() {
if (listAdapter != null) {
listAdapter.notifyDataSetChanged();
}
}
@Override
public ArrayList<ThemeDescription> getThemeDescriptions() {
ArrayList<ThemeDescription> themeDescriptions = new ArrayList<>();
themeDescriptions.add(new ThemeDescription(listView, ThemeDescription.FLAG_CELLBACKGROUNDCOLOR, new Class[]{EmptyCell.class, TextSettingsCell.class, TextCheckCell.class, HeaderCell.class, TextDetailSettingsCell.class, NotificationsCheckCell.class}, null, null, null, Theme.key_windowBackgroundWhite));
themeDescriptions.add(new ThemeDescription(fragmentView, ThemeDescription.FLAG_BACKGROUND, null, null, null, null, Theme.key_windowBackgroundGray));
themeDescriptions.add(new ThemeDescription(actionBar, ThemeDescription.FLAG_BACKGROUND, null, null, null, null, Theme.key_avatar_backgroundActionBarBlue));
themeDescriptions.add(new ThemeDescription(listView, ThemeDescription.FLAG_LISTGLOWCOLOR, null, null, null, null, Theme.key_avatar_backgroundActionBarBlue));
themeDescriptions.add(new ThemeDescription(actionBar, ThemeDescription.FLAG_AB_ITEMSCOLOR, null, null, null, null, Theme.key_avatar_actionBarIconBlue));
themeDescriptions.add(new ThemeDescription(actionBar, ThemeDescription.FLAG_AB_TITLECOLOR, null, null, null, null, Theme.key_actionBarDefaultTitle));
themeDescriptions.add(new ThemeDescription(actionBar, ThemeDescription.FLAG_AB_SELECTORCOLOR, null, null, null, null, Theme.key_avatar_actionBarSelectorBlue));
themeDescriptions.add(new ThemeDescription(actionBar, ThemeDescription.FLAG_AB_SUBMENUBACKGROUND, null, null, null, null, Theme.key_actionBarDefaultSubmenuBackground));
themeDescriptions.add(new ThemeDescription(actionBar, ThemeDescription.FLAG_AB_SUBMENUITEM, null, null, null, null, Theme.key_actionBarDefaultSubmenuItem));
themeDescriptions.add(new ThemeDescription(listView, ThemeDescription.FLAG_SELECTOR, null, null, null, null, Theme.key_listSelector));
themeDescriptions.add(new ThemeDescription(listView, 0, new Class[]{View.class}, Theme.dividerPaint, null, null, Theme.key_divider));
themeDescriptions.add(new ThemeDescription(listView, ThemeDescription.FLAG_BACKGROUNDFILTER, new Class[]{ShadowSectionCell.class}, null, null, null, Theme.key_windowBackgroundGrayShadow));
themeDescriptions.add(new ThemeDescription(listView, 0, new Class[]{TextSettingsCell.class}, new String[]{"textView"}, null, null, null, Theme.key_windowBackgroundWhiteBlackText));
themeDescriptions.add(new ThemeDescription(listView, 0, new Class[]{TextSettingsCell.class}, new String[]{"valueTextView"}, null, null, null, Theme.key_windowBackgroundWhiteValueText));
themeDescriptions.add(new ThemeDescription(listView, 0, new Class[]{NotificationsCheckCell.class}, new String[]{"textView"}, null, null, null, Theme.key_windowBackgroundWhiteBlackText));
themeDescriptions.add(new ThemeDescription(listView, 0, new Class[]{NotificationsCheckCell.class}, new String[]{"valueTextView"}, null, null, null, Theme.key_windowBackgroundWhiteGrayText2));
themeDescriptions.add(new ThemeDescription(listView, 0, new Class[]{NotificationsCheckCell.class}, new String[]{"checkBox"}, null, null, null, Theme.key_switchTrack));
themeDescriptions.add(new ThemeDescription(listView, 0, new Class[]{NotificationsCheckCell.class}, new String[]{"checkBox"}, null, null, null, Theme.key_switchTrackChecked));
themeDescriptions.add(new ThemeDescription(listView, 0, new Class[]{TextCheckCell.class}, new String[]{"textView"}, null, null, null, Theme.key_windowBackgroundWhiteBlackText));
themeDescriptions.add(new ThemeDescription(listView, 0, new Class[]{TextCheckCell.class}, new String[]{"valueTextView"}, null, null, null, Theme.key_windowBackgroundWhiteGrayText2));
themeDescriptions.add(new ThemeDescription(listView, 0, new Class[]{TextCheckCell.class}, new String[]{"checkBox"}, null, null, null, Theme.key_switchTrack));
themeDescriptions.add(new ThemeDescription(listView, 0, new Class[]{TextCheckCell.class}, new String[]{"checkBox"}, null, null, null, Theme.key_switchTrackChecked));
themeDescriptions.add(new ThemeDescription(listView, 0, new Class[]{HeaderCell.class}, new String[]{"textView"}, null, null, null, Theme.key_windowBackgroundWhiteBlueHeader));
themeDescriptions.add(new ThemeDescription(listView, 0, new Class[]{TextDetailSettingsCell.class}, new String[]{"textView"}, null, null, null, Theme.key_windowBackgroundWhiteBlackText));
themeDescriptions.add(new ThemeDescription(listView, 0, new Class[]{TextDetailSettingsCell.class}, new String[]{"valueTextView"}, null, null, null, Theme.key_windowBackgroundWhiteGrayText2));
return themeDescriptions;
}
private class ListAdapter extends RecyclerListView.SelectionAdapter {
private Context mContext;
public ListAdapter(Context context) {
mContext = context;
}
@Override
public int getItemCount() {
return rows.size();
}
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
// onBindViewHolder 一般设置文字是否打勾什么的
NekomuraTGCell a = rows.get(position);
if (a != null) {
a.onBindViewHolder(holder);
}
}
@Override
public boolean isEnabled(RecyclerView.ViewHolder holder) {
int position = holder.getAdapterPosition();
NekomuraTGCell a = rows.get(position);
if (a != null) {
return a.isEnabled();
}
return true;
}
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = null;
switch (viewType) {
case ITEM_TYPE_DIVIDER:
view = new ShadowSectionCell(mContext);
break;
case ITEM_TYPE_TEXT_SETTINGS:
view = new TextSettingsCell(mContext);
view.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
break;
case ITEM_TYPE_TEXT_CHECK:
view = new TextCheckCell(mContext);
view.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
break;
case ITEM_TYPE_HEADER:
view = new HeaderCell(mContext);
view.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
break;
case ITEM_TYPE_TEXT_DETAIL:
view = new TextDetailSettingsCell(mContext);
view.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
break;
case ITEM_TYPE_TEXT:
view = new TextInfoPrivacyCell(mContext);
// view.setBackground(Theme.getThemedDrawable(mContext, R.drawable.greydivider, Theme.key_windowBackgroundGrayShadow));
break;
}
//noinspection ConstantConditions
view.setLayoutParams(new RecyclerView.LayoutParams(RecyclerView.LayoutParams.MATCH_PARENT, RecyclerView.LayoutParams.WRAP_CONTENT));
return new RecyclerListView.Holder(view);
}
@Override
public int getItemViewType(int position) {
NekomuraTGCell a = rows.get(position);
if (a != null) {
return a.getType();
}
return 6;
}
}
//设置对象
public interface NekomuraTGCell {
int getType();
boolean isEnabled();
void onBindViewHolder(RecyclerView.ViewHolder holder);
}
public class NekomuraTGDivider implements NekomuraTGCell {
public int getType() {
return ITEM_TYPE_DIVIDER;
}
public boolean isEnabled() {
return false;
}
public void onBindViewHolder(RecyclerView.ViewHolder holder) {
}
}
public class NekomuraTGHeader implements NekomuraTGCell {
private final String title;
public NekomuraTGHeader(String title) {
this.title = title;
}
public int getType() {
return ITEM_TYPE_HEADER;
}
public boolean isEnabled() {
return false;
//还有特殊情况哦
}
public void onBindViewHolder(RecyclerView.ViewHolder holder) {
HeaderCell headerCell = (HeaderCell) holder.itemView;
headerCell.setText(title);
}
}
public class NekomuraTGTextCheck implements NekomuraTGCell {
private final NekomuraConfig.ConfigItem bindConfig;
private final String title;
public NekomuraTGTextCheck(NekomuraConfig.ConfigItem bind) {
this.bindConfig = bind;
this.title = LocaleController.getString(bindConfig.getKey());
}
public NekomuraTGTextCheck(String customTitle, NekomuraConfig.ConfigItem bind) {
this.bindConfig = bind;
if (customTitle == null) {
title = LocaleController.getString(bindConfig.getKey());
} else {
title = customTitle;
}
}
public int getType() {
return ITEM_TYPE_TEXT_CHECK;
}
public boolean isEnabled() {
return true;
}
public void onBindViewHolder(RecyclerView.ViewHolder holder) {
TextCheckCell cell = (TextCheckCell) holder.itemView;
cell.setTextAndCheck(title, bindConfig.Bool(), !(rows.get(rows.indexOf(this) + 1) instanceof NekomuraTGDivider));
}
public void onClick(TextCheckCell cell) {
cell.setChecked(bindConfig.toggleConfigBool());
}
}
public class NekomuraTGTextSettings implements NekomuraTGCell {
private final NekomuraConfig.ConfigItem bindConfig;
private final String[] selectList;//实际上是int类型的设置
private final String title;
private Runnable onClickCustom;
//不需要的custom就填null
public NekomuraTGTextSettings(String customTitle, NekomuraConfig.ConfigItem bind, String selectList_s, Runnable customOnClick) {
this.bindConfig = bind;
if (selectList_s == null) {
this.selectList = null;
} else {
this.selectList = selectList_s.split("\n");
}
if (customTitle == null) {
title = LocaleController.getString(bindConfig.getKey());
} else {
title = customTitle;
}
this.onClickCustom = customOnClick;
}
public int getType() {
return ITEM_TYPE_TEXT_SETTINGS;
}
public boolean isEnabled() {
return true;
}
public void onBindViewHolder(RecyclerView.ViewHolder holder) {
TextSettingsCell cell = (TextSettingsCell) holder.itemView;
cell.setTextAndValue(title, selectList == null ? "" : selectList[bindConfig.Int()], !(rows.get(rows.indexOf(this) + 1) instanceof NekomuraTGDivider));
}
public void onClick() {
if (onClickCustom != null) {
try {
onClickCustom.run();
} catch (Exception e) {
}
return;
}
Context context = getParentActivity();
if (context == null) {
return;
}
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle(LocaleController.getString(bindConfig.getKey()));
final LinearLayout linearLayout = new LinearLayout(context);
linearLayout.setOrientation(LinearLayout.VERTICAL);
builder.setView(linearLayout);
for (int i = 0; i < selectList.length; i++) {
RadioColorCell cell = new RadioColorCell(context);
cell.setPadding(AndroidUtilities.dp(4), 0, AndroidUtilities.dp(4), 0);
cell.setTag(i);
cell.setCheckColor(Theme.getColor(Theme.key_radioBackground), Theme.getColor(Theme.key_dialogRadioBackgroundChecked));
cell.setTextAndValue(selectList[i], bindConfig.Int() == i);
linearLayout.addView(cell);
cell.setOnClickListener(v -> {
Integer which = (Integer) v.getTag();
bindConfig.setConfigInt(which);
listAdapter.notifyItemChanged(rows.indexOf(this));
builder.getDismissRunnable().run();
parentLayout.rebuildAllFragmentViews(false, false);
});
}
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
showDialog(builder.create());
}
}
}

View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="NekomuraSettings">New Settings</string>
<string name="largeAvatarInDrawer">Large avatar in drawer</string>
<string name="unreadBadgeOnBackButton">Unread badge on back button</string>
<string name="valuesLargeAvatarInDrawer">Telegram Default\nAvatar as background\nBig avatar as background</string>
</resources>