mirror of https://github.com/NekoX-Dev/NekoX.git
855 lines
45 KiB
Java
855 lines
45 KiB
Java
package tw.nekomimi.nekogram;
|
|
|
|
import android.animation.Animator;
|
|
import android.animation.AnimatorListenerAdapter;
|
|
import android.animation.AnimatorSet;
|
|
import android.annotation.SuppressLint;
|
|
import android.content.Context;
|
|
import android.content.SharedPreferences;
|
|
import android.graphics.Canvas;
|
|
import android.graphics.Paint;
|
|
import android.os.Build;
|
|
import android.text.TextPaint;
|
|
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.SharedConfig;
|
|
import org.telegram.messenger.UserConfig;
|
|
import org.telegram.tgnet.ConnectionsManager;
|
|
import org.telegram.tgnet.TLRPC;
|
|
import org.telegram.ui.ActionBar.ActionBar;
|
|
import org.telegram.ui.ActionBar.ActionBarMenuItem;
|
|
import org.telegram.ui.ActionBar.AlertDialog;
|
|
import org.telegram.ui.ActionBar.BaseFragment;
|
|
import org.telegram.ui.ActionBar.BottomSheet;
|
|
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.AlertsCreator;
|
|
import org.telegram.ui.Components.LayoutHelper;
|
|
import org.telegram.ui.Components.RecyclerListView;
|
|
import org.telegram.ui.Components.SeekBarView;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
public class NekoSettingsActivity extends BaseFragment {
|
|
|
|
private RecyclerListView listView;
|
|
private ListAdapter listAdapter;
|
|
private AnimatorSet animatorSet;
|
|
|
|
private boolean sensitiveCanChange = false;
|
|
private boolean sensitiveEnabled = false;
|
|
|
|
private int rowCount;
|
|
|
|
private int connectionRow;
|
|
private int ipv6Row;
|
|
private int connection2Row;
|
|
|
|
|
|
private int chatRow;
|
|
private int inappCameraRow;
|
|
private int useSystemEmojiRow;
|
|
private int ignoreBlockedRow;
|
|
private int mapPreviewRow;
|
|
private int stickerSizeRow;
|
|
private int messageMenuRow;
|
|
private int chat2Row;
|
|
|
|
private int settingsRow;
|
|
private int typefaceRow;
|
|
private int hidePhoneRow;
|
|
private int nameOrderRow;
|
|
private int transparentStatusBarRow;
|
|
private int hideProxySponsorChannelRow;
|
|
private int saveCacheToPrivateDirectoryRow;
|
|
private int forceTabletRow;
|
|
private int xmasRow;
|
|
private int newYearRow;
|
|
private int newYearEveRow;
|
|
private int fireworksRow;
|
|
private int needRestartRow;
|
|
|
|
private int experimentRow;
|
|
private int disableFilteringRow;
|
|
private int unlimitedFavedStickersRow;
|
|
private int experiment2Row;
|
|
|
|
@Override
|
|
public boolean onFragmentCreate() {
|
|
super.onFragmentCreate();
|
|
|
|
updateRows(false);
|
|
|
|
return true;
|
|
}
|
|
|
|
@SuppressLint("NewApi")
|
|
@Override
|
|
public View createView(Context context) {
|
|
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
|
|
actionBar.setTitle(LocaleController.getString("NekoSettings", R.string.NekoSettings));
|
|
|
|
if (AndroidUtilities.isTablet()) {
|
|
actionBar.setOccupyStatusBar(false);
|
|
}
|
|
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) {
|
|
@Override
|
|
public boolean supportsPredictiveItemAnimations() {
|
|
return false;
|
|
}
|
|
});
|
|
listView.setGlowColor(Theme.getColor(Theme.key_avatar_backgroundActionBarBlue));
|
|
listView.setAdapter(listAdapter);
|
|
listView.setItemAnimator(null);
|
|
listView.setLayoutAnimation(null);
|
|
frameLayout.addView(listView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT));
|
|
listView.setOnItemClickListener((view, position, x, y) -> {
|
|
if (position == ipv6Row) {
|
|
NekoConfig.toggleIPv6();
|
|
if (view instanceof TextCheckCell) {
|
|
((TextCheckCell) view).setChecked(NekoConfig.useIPv6);
|
|
}
|
|
for (int a = 0; a < UserConfig.MAX_ACCOUNT_COUNT; a++) {
|
|
if (UserConfig.getInstance(a).isClientActivated()) {
|
|
ConnectionsManager.native_setUseIpv6(a, NekoConfig.useIPv6);
|
|
}
|
|
}
|
|
} else if (position == hidePhoneRow) {
|
|
NekoConfig.toggleHidePhone();
|
|
if (view instanceof TextCheckCell) {
|
|
((TextCheckCell) view).setChecked(NekoConfig.hidePhone);
|
|
}
|
|
} else if (position == inappCameraRow) {
|
|
SharedConfig.toggleInappCamera();
|
|
if (view instanceof TextCheckCell) {
|
|
((TextCheckCell) view).setChecked(SharedConfig.inappCamera);
|
|
}
|
|
} else if (position == forceTabletRow) {
|
|
NekoConfig.toggleForceTablet();
|
|
if (view instanceof TextCheckCell) {
|
|
((TextCheckCell) view).setChecked(NekoConfig.forceTablet);
|
|
}
|
|
} else if (position == ignoreBlockedRow) {
|
|
NekoConfig.toggleIgnoreBlocked();
|
|
if (view instanceof TextCheckCell) {
|
|
((TextCheckCell) view).setChecked(NekoConfig.ignoreBlocked);
|
|
}
|
|
} else if (position == transparentStatusBarRow) {
|
|
NekoConfig.toggleTransparentStatusBar();
|
|
if (view instanceof TextCheckCell) {
|
|
((TextCheckCell) view).setChecked(NekoConfig.transparentStatusBar);
|
|
}
|
|
AndroidUtilities.runOnUIThread(() -> NotificationCenter.getGlobalInstance().postNotificationName(NotificationCenter.didSetNewTheme, false));
|
|
} else if (position == hideProxySponsorChannelRow) {
|
|
NekoConfig.toggleHideProxySponsorChannel();
|
|
if (view instanceof TextCheckCell) {
|
|
((TextCheckCell) view).setChecked(NekoConfig.hideProxySponsorChannel);
|
|
}
|
|
for (int a = 0; a < UserConfig.MAX_ACCOUNT_COUNT; a++) {
|
|
if (UserConfig.getInstance(a).isClientActivated()) {
|
|
MessagesController.getInstance(a).checkProxyInfo(true);
|
|
}
|
|
}
|
|
} else if (position == saveCacheToPrivateDirectoryRow) {
|
|
NekoConfig.toggleSaveCacheToPrivateDirectory();
|
|
if (view instanceof TextCheckCell) {
|
|
((TextCheckCell) view).setChecked(NekoConfig.saveCacheToPrivateDirectory);
|
|
}
|
|
} else if (position == useSystemEmojiRow) {
|
|
SharedConfig.useSystemEmoji = !SharedConfig.useSystemEmoji;
|
|
SharedPreferences.Editor editor = MessagesController.getGlobalMainSettings().edit();
|
|
editor.putBoolean("useSystemEmoji", SharedConfig.useSystemEmoji);
|
|
editor.commit();
|
|
if (view instanceof TextCheckCell) {
|
|
((TextCheckCell) view).setChecked(SharedConfig.useSystemEmoji);
|
|
}
|
|
} else if (position == typefaceRow) {
|
|
NekoConfig.toggleTypeface();
|
|
if (view instanceof TextCheckCell) {
|
|
((TextCheckCell) view).setChecked(NekoConfig.typeface == 1);
|
|
}
|
|
} else if (position == mapPreviewRow) {
|
|
ArrayList<String> arrayList = new ArrayList<>();
|
|
ArrayList<Integer> types = new ArrayList<>();
|
|
arrayList.add(LocaleController.getString("MapPreviewProviderTelegram", R.string.MapPreviewProviderTelegram));
|
|
types.add(0);
|
|
arrayList.add(LocaleController.getString("MapPreviewProviderYandex", R.string.MapPreviewProviderYandex));
|
|
types.add(1);
|
|
arrayList.add(LocaleController.getString("MapPreviewProviderNobody", R.string.MapPreviewProviderNobody));
|
|
types.add(2);
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
|
builder.setTitle(LocaleController.getString("MapPreviewProviderTitle", R.string.MapPreviewProviderTitle));
|
|
final LinearLayout linearLayout = new LinearLayout(context);
|
|
linearLayout.setOrientation(LinearLayout.VERTICAL);
|
|
builder.setView(linearLayout);
|
|
|
|
for (int a = 0; a < arrayList.size(); a++) {
|
|
RadioColorCell cell = new RadioColorCell(context);
|
|
cell.setPadding(AndroidUtilities.dp(4), 0, AndroidUtilities.dp(4), 0);
|
|
cell.setTag(a);
|
|
cell.setCheckColor(Theme.getColor(Theme.key_radioBackground), Theme.getColor(Theme.key_dialogRadioBackgroundChecked));
|
|
cell.setTextAndValue(arrayList.get(a), NekoConfig.mapPreviewProvider == types.get(a));
|
|
linearLayout.addView(cell);
|
|
cell.setOnClickListener(v -> {
|
|
Integer which = (Integer) v.getTag();
|
|
NekoConfig.setMapPreviewProvider(types.get(which));
|
|
listAdapter.notifyItemChanged(mapPreviewRow);
|
|
builder.getDismissRunnable().run();
|
|
});
|
|
}
|
|
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
|
|
showDialog(builder.create());
|
|
} else if (position == nameOrderRow) {
|
|
ArrayList<String> arrayList = new ArrayList<>();
|
|
ArrayList<Integer> types = new ArrayList<>();
|
|
arrayList.add(LocaleController.getString("FirstLast", R.string.FirstLast));
|
|
types.add(1);
|
|
arrayList.add(LocaleController.getString("LastFirst", R.string.LastFirst));
|
|
types.add(2);
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
|
builder.setTitle(LocaleController.getString("NameOrder", R.string.NameOrder));
|
|
final LinearLayout linearLayout = new LinearLayout(context);
|
|
linearLayout.setOrientation(LinearLayout.VERTICAL);
|
|
builder.setView(linearLayout);
|
|
|
|
for (int a = 0; a < arrayList.size(); a++) {
|
|
RadioColorCell cell = new RadioColorCell(context);
|
|
cell.setPadding(AndroidUtilities.dp(4), 0, AndroidUtilities.dp(4), 0);
|
|
cell.setTag(a);
|
|
cell.setCheckColor(Theme.getColor(Theme.key_radioBackground), Theme.getColor(Theme.key_dialogRadioBackgroundChecked));
|
|
cell.setTextAndValue(arrayList.get(a), NekoConfig.nameOrder == types.get(a));
|
|
linearLayout.addView(cell);
|
|
cell.setOnClickListener(v -> {
|
|
Integer which = (Integer) v.getTag();
|
|
NekoConfig.setNameOrder(types.get(which));
|
|
listAdapter.notifyItemChanged(nameOrderRow);
|
|
builder.getDismissRunnable().run();
|
|
});
|
|
}
|
|
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
|
|
showDialog(builder.create());
|
|
} else if (position == xmasRow) {
|
|
NekoConfig.toggleXmas();
|
|
if (view instanceof TextCheckCell) {
|
|
((TextCheckCell) view).setChecked(NekoConfig.xmas);
|
|
}
|
|
} else if (position == newYearRow) {
|
|
NekoConfig.toggleNewYear();
|
|
if (view instanceof TextCheckCell) {
|
|
((TextCheckCell) view).setChecked(NekoConfig.newYear);
|
|
}
|
|
} else if (position == newYearEveRow) {
|
|
NekoConfig.toggleNewYearEve();
|
|
if (view instanceof TextCheckCell) {
|
|
((TextCheckCell) view).setChecked(NekoConfig.newYearEve);
|
|
}
|
|
} else if (position == fireworksRow) {
|
|
NekoConfig.toggleFireworks();
|
|
if (view instanceof TextCheckCell) {
|
|
((TextCheckCell) view).setChecked(NekoConfig.fireworks);
|
|
}
|
|
} else if (position == disableFilteringRow) {
|
|
sensitiveEnabled = !sensitiveEnabled;
|
|
TLRPC.TL_account_setContentSettings req = new TLRPC.TL_account_setContentSettings();
|
|
req.sensitive_enabled = sensitiveEnabled;
|
|
AlertDialog progressDialog = new AlertDialog(getParentActivity(), 3);
|
|
progressDialog.show();
|
|
getConnectionsManager().sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
|
|
progressDialog.dismiss();
|
|
if (error == null) {
|
|
if (response instanceof TLRPC.TL_boolTrue && view instanceof TextCheckCell) {
|
|
((TextCheckCell) view).setChecked(sensitiveEnabled);
|
|
}
|
|
} else {
|
|
AndroidUtilities.runOnUIThread(() -> AlertsCreator.processError(currentAccount, error, this, req));
|
|
}
|
|
}));
|
|
} else if (position == stickerSizeRow) {
|
|
showStickerSizeAlert();
|
|
} else if (position == unlimitedFavedStickersRow) {
|
|
NekoConfig.toggleUnlimitedFavedStickers();
|
|
if (view instanceof TextCheckCell) {
|
|
((TextCheckCell) view).setChecked(NekoConfig.unlimitedFavedStickers);
|
|
}
|
|
} else if (position == messageMenuRow) {
|
|
showMessageMenuAlert();
|
|
}
|
|
});
|
|
|
|
return fragmentView;
|
|
}
|
|
|
|
@Override
|
|
public void onResume() {
|
|
super.onResume();
|
|
if (listAdapter != null) {
|
|
checkSensitive();
|
|
listAdapter.notifyDataSetChanged();
|
|
}
|
|
}
|
|
|
|
private void updateRows(boolean notify) {
|
|
rowCount = 0;
|
|
connectionRow = rowCount++;
|
|
ipv6Row = rowCount++;
|
|
connection2Row = rowCount++;
|
|
chatRow = rowCount++;
|
|
inappCameraRow = rowCount++;
|
|
useSystemEmojiRow = rowCount++;
|
|
ignoreBlockedRow = rowCount++;
|
|
hideProxySponsorChannelRow = rowCount++;
|
|
saveCacheToPrivateDirectoryRow = Build.VERSION.SDK_INT >= 24 ? rowCount++ : -1;
|
|
mapPreviewRow = rowCount++;
|
|
stickerSizeRow = rowCount++;
|
|
messageMenuRow = rowCount++;
|
|
chat2Row = rowCount++;
|
|
settingsRow = rowCount++;
|
|
hidePhoneRow = rowCount++;
|
|
typefaceRow = rowCount++;
|
|
transparentStatusBarRow = Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ? rowCount++ : -1;
|
|
forceTabletRow = rowCount++;
|
|
nameOrderRow = rowCount++;
|
|
xmasRow = rowCount++;
|
|
newYearRow = rowCount++;
|
|
newYearEveRow = rowCount++;
|
|
fireworksRow = rowCount++;
|
|
needRestartRow = rowCount++;
|
|
experimentRow = rowCount++;
|
|
disableFilteringRow = rowCount++;
|
|
unlimitedFavedStickersRow = rowCount++;
|
|
experiment2Row = rowCount++;
|
|
if (notify && listAdapter != null) {
|
|
listAdapter.notifyDataSetChanged();
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public ThemeDescription[] getThemeDescriptions() {
|
|
return new ThemeDescription[]{
|
|
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),
|
|
new ThemeDescription(fragmentView, ThemeDescription.FLAG_BACKGROUND, null, null, null, null, Theme.key_windowBackgroundGray),
|
|
|
|
new ThemeDescription(actionBar, ThemeDescription.FLAG_BACKGROUND, null, null, null, null, Theme.key_avatar_backgroundActionBarBlue),
|
|
new ThemeDescription(listView, ThemeDescription.FLAG_LISTGLOWCOLOR, null, null, null, null, Theme.key_avatar_backgroundActionBarBlue),
|
|
new ThemeDescription(actionBar, ThemeDescription.FLAG_AB_ITEMSCOLOR, null, null, null, null, Theme.key_avatar_actionBarIconBlue),
|
|
new ThemeDescription(actionBar, ThemeDescription.FLAG_AB_TITLECOLOR, null, null, null, null, Theme.key_actionBarDefaultTitle),
|
|
new ThemeDescription(actionBar, ThemeDescription.FLAG_AB_SELECTORCOLOR, null, null, null, null, Theme.key_avatar_actionBarSelectorBlue),
|
|
new ThemeDescription(actionBar, ThemeDescription.FLAG_AB_SUBMENUBACKGROUND, null, null, null, null, Theme.key_actionBarDefaultSubmenuBackground),
|
|
new ThemeDescription(actionBar, ThemeDescription.FLAG_AB_SUBMENUITEM, null, null, null, null, Theme.key_actionBarDefaultSubmenuItem),
|
|
|
|
new ThemeDescription(listView, ThemeDescription.FLAG_SELECTOR, null, null, null, null, Theme.key_listSelector),
|
|
|
|
new ThemeDescription(listView, 0, new Class[]{View.class}, Theme.dividerPaint, null, null, Theme.key_divider),
|
|
|
|
new ThemeDescription(listView, ThemeDescription.FLAG_BACKGROUNDFILTER, new Class[]{ShadowSectionCell.class}, null, null, null, Theme.key_windowBackgroundGrayShadow),
|
|
|
|
new ThemeDescription(listView, 0, new Class[]{TextSettingsCell.class}, new String[]{"textView"}, null, null, null, Theme.key_windowBackgroundWhiteBlackText),
|
|
new ThemeDescription(listView, 0, new Class[]{TextSettingsCell.class}, new String[]{"valueTextView"}, null, null, null, Theme.key_windowBackgroundWhiteValueText),
|
|
|
|
new ThemeDescription(listView, 0, new Class[]{NotificationsCheckCell.class}, new String[]{"textView"}, null, null, null, Theme.key_windowBackgroundWhiteBlackText),
|
|
new ThemeDescription(listView, 0, new Class[]{NotificationsCheckCell.class}, new String[]{"valueTextView"}, null, null, null, Theme.key_windowBackgroundWhiteGrayText2),
|
|
new ThemeDescription(listView, 0, new Class[]{NotificationsCheckCell.class}, new String[]{"checkBox"}, null, null, null, Theme.key_switchTrack),
|
|
new ThemeDescription(listView, 0, new Class[]{NotificationsCheckCell.class}, new String[]{"checkBox"}, null, null, null, Theme.key_switchTrackChecked),
|
|
|
|
new ThemeDescription(listView, 0, new Class[]{TextCheckCell.class}, new String[]{"textView"}, null, null, null, Theme.key_windowBackgroundWhiteBlackText),
|
|
new ThemeDescription(listView, 0, new Class[]{TextCheckCell.class}, new String[]{"valueTextView"}, null, null, null, Theme.key_windowBackgroundWhiteGrayText2),
|
|
new ThemeDescription(listView, 0, new Class[]{TextCheckCell.class}, new String[]{"checkBox"}, null, null, null, Theme.key_switchTrack),
|
|
new ThemeDescription(listView, 0, new Class[]{TextCheckCell.class}, new String[]{"checkBox"}, null, null, null, Theme.key_switchTrackChecked),
|
|
|
|
new ThemeDescription(listView, 0, new Class[]{HeaderCell.class}, new String[]{"textView"}, null, null, null, Theme.key_windowBackgroundWhiteBlueHeader),
|
|
|
|
new ThemeDescription(listView, 0, new Class[]{TextDetailSettingsCell.class}, new String[]{"textView"}, null, null, null, Theme.key_windowBackgroundWhiteBlackText),
|
|
new ThemeDescription(listView, 0, new Class[]{TextDetailSettingsCell.class}, new String[]{"valueTextView"}, null, null, null, Theme.key_windowBackgroundWhiteGrayText2),
|
|
};
|
|
}
|
|
|
|
private void checkSensitive() {
|
|
TLRPC.TL_account_getContentSettings req = new TLRPC.TL_account_getContentSettings();
|
|
getConnectionsManager().sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
|
|
if (error == null) {
|
|
TLRPC.TL_account_contentSettings settings = (TLRPC.TL_account_contentSettings) response;
|
|
sensitiveEnabled = settings.sensitive_enabled;
|
|
sensitiveCanChange = settings.sensitive_can_change;
|
|
int count = listView.getChildCount();
|
|
ArrayList<Animator> animators = new ArrayList<>();
|
|
for (int a = 0; a < count; a++) {
|
|
View child = listView.getChildAt(a);
|
|
RecyclerListView.Holder holder = (RecyclerListView.Holder) listView.getChildViewHolder(child);
|
|
int position = holder.getAdapterPosition();
|
|
if (position == disableFilteringRow) {
|
|
TextCheckCell checkCell = (TextCheckCell) holder.itemView;
|
|
checkCell.setChecked(sensitiveEnabled);
|
|
checkCell.setEnabled(sensitiveCanChange, animators);
|
|
if (sensitiveCanChange) {
|
|
if (!animators.isEmpty()) {
|
|
if (animatorSet != null) {
|
|
animatorSet.cancel();
|
|
}
|
|
animatorSet = new AnimatorSet();
|
|
animatorSet.playTogether(animators);
|
|
animatorSet.addListener(new AnimatorListenerAdapter() {
|
|
@Override
|
|
public void onAnimationEnd(Animator animator) {
|
|
if (animator.equals(animatorSet)) {
|
|
animatorSet = null;
|
|
}
|
|
}
|
|
});
|
|
animatorSet.setDuration(150);
|
|
animatorSet.start();
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
} else {
|
|
AndroidUtilities.runOnUIThread(() -> AlertsCreator.processError(currentAccount, error, this, req));
|
|
}
|
|
}));
|
|
}
|
|
|
|
private void showMessageMenuAlert() {
|
|
if (getParentActivity() == null) {
|
|
return;
|
|
}
|
|
Context context = getParentActivity();
|
|
BottomSheet.Builder builder = new BottomSheet.Builder(context);
|
|
builder.setApplyTopPadding(false);
|
|
builder.setApplyBottomPadding(false);
|
|
|
|
LinearLayout linearLayout = new LinearLayout(context);
|
|
linearLayout.setOrientation(LinearLayout.VERTICAL);
|
|
|
|
HeaderCell headerCell = new HeaderCell(context, true, 23, 15, false);
|
|
headerCell.setHeight(47);
|
|
headerCell.setText(LocaleController.getString("MessageMenu", R.string.MessageMenu));
|
|
linearLayout.addView(headerCell);
|
|
|
|
LinearLayout linearLayoutInviteContainer = new LinearLayout(context);
|
|
linearLayoutInviteContainer.setOrientation(LinearLayout.VERTICAL);
|
|
linearLayout.addView(linearLayoutInviteContainer, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
|
|
|
|
int count = 8;
|
|
for (int a = 0; a < count; a++) {
|
|
TextCheckCell textCell = new TextCheckCell(context);
|
|
switch (a) {
|
|
case 0: {
|
|
textCell.setTextAndCheck(LocaleController.getString("AddToSavedMessages", R.string.AddToSavedMessages), NekoConfig.showAddToSavedMessages, true);
|
|
break;
|
|
}
|
|
case 1: {
|
|
textCell.setTextAndCheck(LocaleController.getString("Prpr", R.string.Prpr), NekoConfig.showPrPr, true);
|
|
break;
|
|
}
|
|
case 2: {
|
|
textCell.setTextAndCheck(LocaleController.getString("ViewHistory", R.string.ViewHistory), NekoConfig.showViewHistory, true);
|
|
break;
|
|
}
|
|
case 3: {
|
|
textCell.setTextAndCheck(LocaleController.getString("ReportChat", R.string.ReportChat), NekoConfig.showReport, true);
|
|
break;
|
|
}
|
|
case 4: {
|
|
textCell.setTextAndCheck(LocaleController.getString("EditAdminRights", R.string.EditAdminRights), NekoConfig.showAdminActions, true);
|
|
break;
|
|
}
|
|
case 5: {
|
|
textCell.setTextAndCheck(LocaleController.getString("ChangePermissions", R.string.ChangePermissions), NekoConfig.showChangePermissions, true);
|
|
break;
|
|
}
|
|
case 6: {
|
|
textCell.setTextAndCheck(LocaleController.getString("DeleteDownloadedFile", R.string.DeleteDownloadedFile), NekoConfig.showDeleteDownloadedFile, true);
|
|
break;
|
|
}
|
|
case 7: {
|
|
textCell.setTextAndCheck(LocaleController.getString("MessageDetails", R.string.MessageDetails), NekoConfig.showMessageDetails, false);
|
|
break;
|
|
}
|
|
}
|
|
textCell.setTag(a);
|
|
textCell.setBackgroundDrawable(Theme.getSelectorDrawable(false));
|
|
linearLayoutInviteContainer.addView(textCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
|
|
textCell.setOnClickListener(v2 -> {
|
|
Integer tag = (Integer) v2.getTag();
|
|
switch (tag) {
|
|
case 0: {
|
|
NekoConfig.toggleShowAddToSavedMessages();
|
|
textCell.setChecked(NekoConfig.showAddToSavedMessages);
|
|
break;
|
|
}
|
|
case 1: {
|
|
NekoConfig.toggleShowPrPr();
|
|
textCell.setChecked(NekoConfig.showPrPr);
|
|
break;
|
|
}
|
|
case 2: {
|
|
NekoConfig.toggleShowViewHistory();
|
|
textCell.setChecked(NekoConfig.showViewHistory);
|
|
break;
|
|
}
|
|
case 3: {
|
|
NekoConfig.toggleShowReport();
|
|
textCell.setChecked(NekoConfig.showReport);
|
|
break;
|
|
}
|
|
case 4: {
|
|
NekoConfig.toggleShowAdminActions();
|
|
textCell.setChecked(NekoConfig.showAdminActions);
|
|
break;
|
|
}
|
|
case 5: {
|
|
NekoConfig.toggleShowChangePermissions();
|
|
textCell.setChecked(NekoConfig.showChangePermissions);
|
|
break;
|
|
}
|
|
case 6: {
|
|
NekoConfig.toggleShowDeleteDownloadedFile();
|
|
textCell.setChecked(NekoConfig.showDeleteDownloadedFile);
|
|
break;
|
|
}
|
|
case 7: {
|
|
NekoConfig.toggleShowMessageDetails();
|
|
textCell.setChecked(NekoConfig.showMessageDetails);
|
|
break;
|
|
}
|
|
}
|
|
});
|
|
}
|
|
builder.setCustomView(linearLayout);
|
|
showDialog(builder.create());
|
|
}
|
|
|
|
private void showStickerSizeAlert() {
|
|
if (getParentActivity() == null) {
|
|
return;
|
|
}
|
|
Context context = getParentActivity();
|
|
BottomSheet.Builder builder = new BottomSheet.Builder(context);
|
|
builder.setApplyTopPadding(false);
|
|
builder.setApplyBottomPadding(false);
|
|
|
|
LinearLayout linearLayout = new LinearLayout(context);
|
|
linearLayout.setOrientation(LinearLayout.VERTICAL);
|
|
|
|
FrameLayout titleLayout = new FrameLayout(context);
|
|
linearLayout.addView(titleLayout);
|
|
|
|
HeaderCell headerCell = new HeaderCell(context, true, 23, 15, false);
|
|
headerCell.setHeight(47);
|
|
headerCell.setText(LocaleController.getString("StickerSize", R.string.StickerSize));
|
|
titleLayout.addView(headerCell);
|
|
|
|
ActionBarMenuItem optionsButton = new ActionBarMenuItem(context, null, 0, Theme.getColor(Theme.key_sheet_other));
|
|
optionsButton.setLongClickEnabled(false);
|
|
optionsButton.setSubMenuOpenSide(2);
|
|
optionsButton.setIcon(R.drawable.ic_ab_other);
|
|
optionsButton.setBackgroundDrawable(Theme.createSelectorDrawable(Theme.getColor(Theme.key_player_actionBarSelector), 1));
|
|
optionsButton.addSubItem(1, R.drawable.msg_reset, LocaleController.getString("Reset", R.string.Reset));
|
|
optionsButton.setOnClickListener(v -> optionsButton.toggleSubMenu());
|
|
optionsButton.setContentDescription(LocaleController.getString("AccDescrMoreOptions", R.string.AccDescrMoreOptions));
|
|
titleLayout.addView(optionsButton, LayoutHelper.createFrame(40, 40, Gravity.TOP | Gravity.RIGHT, 0, 8, 5, 0));
|
|
|
|
LinearLayout linearLayoutInviteContainer = new LinearLayout(context);
|
|
linearLayoutInviteContainer.setOrientation(LinearLayout.VERTICAL);
|
|
linearLayout.addView(linearLayoutInviteContainer, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
|
|
StickerSizeCell stickerSizeCell = new StickerSizeCell(context);
|
|
optionsButton.setDelegate(id -> {
|
|
if (id == 1) {
|
|
NekoConfig.setStickerSize(14.0f);
|
|
stickerSizeCell.invalidate();
|
|
}
|
|
});
|
|
linearLayoutInviteContainer.addView(stickerSizeCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
|
|
builder.setCustomView(linearLayout);
|
|
showDialog(builder.create());
|
|
}
|
|
|
|
private class StickerSizeCell extends FrameLayout {
|
|
|
|
private StickerSizePreviewMessagesCell messagesCell;
|
|
private SeekBarView sizeBar;
|
|
private int startStickerSize = 2;
|
|
private int endStickerSize = 20;
|
|
|
|
private TextPaint textPaint;
|
|
|
|
public StickerSizeCell(Context context) {
|
|
super(context);
|
|
|
|
setWillNotDraw(false);
|
|
|
|
textPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
|
|
textPaint.setTextSize(AndroidUtilities.dp(16));
|
|
|
|
sizeBar = new SeekBarView(context);
|
|
sizeBar.setReportChanges(true);
|
|
sizeBar.setDelegate(new SeekBarView.SeekBarViewDelegate() {
|
|
@Override
|
|
public void onSeekBarDrag(boolean stop, float progress) {
|
|
NekoConfig.setStickerSize(startStickerSize + (endStickerSize - startStickerSize) * progress);
|
|
StickerSizeCell.this.invalidate();
|
|
}
|
|
|
|
@Override
|
|
public void onSeekBarPressed(boolean pressed) {
|
|
|
|
}
|
|
});
|
|
addView(sizeBar, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 38, Gravity.LEFT | Gravity.TOP, 9, 5, 43, 11));
|
|
|
|
messagesCell = new StickerSizePreviewMessagesCell(context, parentLayout);
|
|
addView(messagesCell, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.TOP, 0, 53, 0, 0));
|
|
}
|
|
|
|
@Override
|
|
protected void onDraw(Canvas canvas) {
|
|
textPaint.setColor(Theme.getColor(Theme.key_windowBackgroundWhiteValueText));
|
|
canvas.drawText("" + Math.round(NekoConfig.stickerSize), getMeasuredWidth() - AndroidUtilities.dp(39), AndroidUtilities.dp(28), textPaint);
|
|
}
|
|
|
|
@Override
|
|
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
|
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
|
sizeBar.setProgress((NekoConfig.stickerSize - startStickerSize) / (float) (endStickerSize - startStickerSize));
|
|
}
|
|
|
|
@Override
|
|
public void invalidate() {
|
|
super.invalidate();
|
|
listAdapter.notifyItemChanged(stickerSizeRow);
|
|
messagesCell.invalidate();
|
|
sizeBar.invalidate();
|
|
}
|
|
}
|
|
|
|
private class ListAdapter extends RecyclerListView.SelectionAdapter {
|
|
|
|
private Context mContext;
|
|
|
|
public ListAdapter(Context context) {
|
|
mContext = context;
|
|
}
|
|
|
|
@Override
|
|
public int getItemCount() {
|
|
return rowCount;
|
|
}
|
|
|
|
@Override
|
|
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
|
|
switch (holder.getItemViewType()) {
|
|
case 1: {
|
|
if (position == experiment2Row) {
|
|
holder.itemView.setBackgroundDrawable(Theme.getThemedDrawable(mContext, R.drawable.greydivider_bottom, Theme.key_windowBackgroundGrayShadow));
|
|
} else {
|
|
holder.itemView.setBackgroundDrawable(Theme.getThemedDrawable(mContext, R.drawable.greydivider, Theme.key_windowBackgroundGrayShadow));
|
|
}
|
|
break;
|
|
}
|
|
case 2: {
|
|
TextSettingsCell textCell = (TextSettingsCell) holder.itemView;
|
|
if (position == nameOrderRow) {
|
|
String value;
|
|
switch (NekoConfig.nameOrder) {
|
|
case 2:
|
|
value = LocaleController.getString("LastFirst", R.string.LastFirst);
|
|
break;
|
|
case 1:
|
|
default:
|
|
value = LocaleController.getString("FirstLast", R.string.FirstLast);
|
|
break;
|
|
}
|
|
textCell.setTextAndValue(LocaleController.getString("NameOrder", R.string.NameOrder), value, true);
|
|
} else if (position == mapPreviewRow) {
|
|
String value;
|
|
switch (NekoConfig.mapPreviewProvider) {
|
|
case 0:
|
|
value = LocaleController.getString("MapPreviewProviderTelegram", R.string.MapPreviewProviderTelegram);
|
|
break;
|
|
case 1:
|
|
value = LocaleController.getString("MapPreviewProviderYandex", R.string.MapPreviewProviderYandex);
|
|
break;
|
|
case 2:
|
|
default:
|
|
value = LocaleController.getString("MapPreviewProviderNobody", R.string.MapPreviewProviderNobody);
|
|
}
|
|
textCell.setTextAndValue(LocaleController.getString("MapPreviewProvider", R.string.MapPreviewProvider), value, true);
|
|
} else if (position == stickerSizeRow) {
|
|
textCell.setTextAndValue(LocaleController.getString("StickerSize", R.string.StickerSize), String.valueOf(Math.round(NekoConfig.stickerSize)), true);
|
|
} else if (position == messageMenuRow) {
|
|
textCell.setText(LocaleController.getString("MessageMenu", R.string.MessageMenu), false);
|
|
}
|
|
break;
|
|
}
|
|
case 3: {
|
|
TextCheckCell textCell = (TextCheckCell) holder.itemView;
|
|
if (position == ipv6Row) {
|
|
textCell.setTextAndCheck(LocaleController.getString("IPv6", R.string.IPv6), NekoConfig.useIPv6, false);
|
|
} else if (position == hidePhoneRow) {
|
|
textCell.setTextAndCheck(LocaleController.getString("HidePhone", R.string.HidePhone), NekoConfig.hidePhone, true);
|
|
} else if (position == inappCameraRow) {
|
|
textCell.setTextAndCheck(LocaleController.getString("DebugMenuEnableCamera", R.string.DebugMenuEnableCamera), SharedConfig.inappCamera, true);
|
|
} else if (position == transparentStatusBarRow) {
|
|
textCell.setTextAndCheck(LocaleController.getString("TransparentStatusBar", R.string.TransparentStatusBar), NekoConfig.transparentStatusBar, true);
|
|
} else if (position == hideProxySponsorChannelRow) {
|
|
textCell.setTextAndCheck(LocaleController.getString("HideProxySponsorChannel", R.string.HideProxySponsorChannel), NekoConfig.hideProxySponsorChannel, true);
|
|
} else if (position == saveCacheToPrivateDirectoryRow) {
|
|
textCell.setTextAndCheck(LocaleController.getString("SaveCacheToPrivateDirectory", R.string.SaveCacheToPrivateDirectory), NekoConfig.saveCacheToPrivateDirectory, true);
|
|
} else if (position == useSystemEmojiRow) {
|
|
textCell.setTextAndCheck(LocaleController.getString("EmojiUseDefault", R.string.EmojiUseDefault), SharedConfig.useSystemEmoji, true);
|
|
} else if (position == typefaceRow) {
|
|
textCell.setTextAndCheck(LocaleController.getString("TypefaceUseDefault", R.string.TypefaceUseDefault), NekoConfig.typeface == 1, true);
|
|
} else if (position == ignoreBlockedRow) {
|
|
textCell.setTextAndCheck(LocaleController.getString("IgnoreBlocked", R.string.IgnoreBlocked), NekoConfig.ignoreBlocked, true);
|
|
} else if (position == forceTabletRow) {
|
|
textCell.setTextAndCheck(LocaleController.getString("ForceTabletMode", R.string.ForceTabletMode), NekoConfig.forceTablet, true);
|
|
} else if (position == xmasRow) {
|
|
textCell.setTextAndCheck(LocaleController.getString("ChristmasEveryday", R.string.ChristmasEveryday), NekoConfig.xmas, true);
|
|
} else if (position == newYearRow) {
|
|
textCell.setTextAndCheck(LocaleController.getString("NewYearEveryday", R.string.NewYearEveryday), NekoConfig.newYear, true);
|
|
} else if (position == newYearEveRow) {
|
|
textCell.setTextAndCheck(LocaleController.getString("HappyNewYearEveryday", R.string.HappyNewYearEveryday), NekoConfig.newYearEve, true);
|
|
} else if (position == fireworksRow) {
|
|
textCell.setTextAndCheck(LocaleController.getString("ShowFireworks", R.string.ShowFireworks), NekoConfig.fireworks, false);
|
|
} else if (position == disableFilteringRow) {
|
|
textCell.setTextAndValueAndCheck(LocaleController.getString("SensitiveDisableFiltering", R.string.SensitiveDisableFiltering), LocaleController.getString("SensitiveAbout", R.string.SensitiveAbout), sensitiveEnabled, true, true);
|
|
textCell.setEnabled(sensitiveCanChange, null);
|
|
} else if (position == unlimitedFavedStickersRow) {
|
|
textCell.setTextAndValueAndCheck(LocaleController.getString("UnlimitedFavoredStickers", R.string.UnlimitedFavoredStickers), LocaleController.getString("UnlimitedFavoredStickersAbout", R.string.UnlimitedFavoredStickersAbout), NekoConfig.unlimitedFavedStickers, true, false);
|
|
}
|
|
break;
|
|
}
|
|
case 4: {
|
|
HeaderCell headerCell = (HeaderCell) holder.itemView;
|
|
if (position == settingsRow) {
|
|
headerCell.setText(LocaleController.getString("General", R.string.General));
|
|
} else if (position == connectionRow) {
|
|
headerCell.setText(LocaleController.getString("Connection", R.string.Connection));
|
|
} else if (position == chatRow) {
|
|
headerCell.setText(LocaleController.getString("Chat", R.string.Chat));
|
|
} else if (position == experimentRow) {
|
|
headerCell.setText(LocaleController.getString("Experiment", R.string.Experiment));
|
|
}
|
|
break;
|
|
}
|
|
case 7: {
|
|
TextInfoPrivacyCell cell = (TextInfoPrivacyCell) holder.itemView;
|
|
if (position == needRestartRow) {
|
|
cell.setText(LocaleController.getString("SomeItemsNeedRestart", R.string.SomeItemsNeedRestart));
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public boolean isEnabled(RecyclerView.ViewHolder holder) {
|
|
int position = holder.getAdapterPosition();
|
|
return position == hidePhoneRow || position == inappCameraRow || position == ignoreBlockedRow ||
|
|
position == useSystemEmojiRow || position == ipv6Row || position == typefaceRow || position == nameOrderRow ||
|
|
position == forceTabletRow || position == mapPreviewRow || position == xmasRow || position == newYearRow ||
|
|
position == newYearEveRow || position == fireworksRow || position == transparentStatusBarRow ||
|
|
position == hideProxySponsorChannelRow || position == saveCacheToPrivateDirectoryRow ||
|
|
(position == disableFilteringRow && sensitiveCanChange) || position == stickerSizeRow ||
|
|
position == unlimitedFavedStickersRow || position == messageMenuRow;
|
|
}
|
|
|
|
@Override
|
|
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
|
View view = null;
|
|
switch (viewType) {
|
|
case 1:
|
|
view = new ShadowSectionCell(mContext);
|
|
break;
|
|
case 2:
|
|
view = new TextSettingsCell(mContext);
|
|
view.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
|
|
break;
|
|
case 3:
|
|
view = new TextCheckCell(mContext);
|
|
view.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
|
|
break;
|
|
case 4:
|
|
view = new HeaderCell(mContext);
|
|
view.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
|
|
break;
|
|
case 5:
|
|
view = new NotificationsCheckCell(mContext);
|
|
view.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
|
|
break;
|
|
case 6:
|
|
view = new TextDetailSettingsCell(mContext);
|
|
view.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
|
|
break;
|
|
case 7:
|
|
view = new TextInfoPrivacyCell(mContext);
|
|
view.setBackgroundDrawable(Theme.getThemedDrawable(mContext, R.drawable.greydivider, Theme.key_windowBackgroundGrayShadow));
|
|
break;
|
|
}
|
|
view.setLayoutParams(new RecyclerView.LayoutParams(RecyclerView.LayoutParams.MATCH_PARENT, RecyclerView.LayoutParams.WRAP_CONTENT));
|
|
return new RecyclerListView.Holder(view);
|
|
}
|
|
|
|
@Override
|
|
public int getItemViewType(int position) {
|
|
if (position == connection2Row || position == chat2Row || position == experiment2Row) {
|
|
return 1;
|
|
} else if (position == nameOrderRow || position == mapPreviewRow || position == stickerSizeRow || position == messageMenuRow) {
|
|
return 2;
|
|
} else if (position == ipv6Row || position == hidePhoneRow || position == inappCameraRow ||
|
|
position == transparentStatusBarRow || position == hideProxySponsorChannelRow ||
|
|
position == ignoreBlockedRow || position == useSystemEmojiRow || position == typefaceRow ||
|
|
position == forceTabletRow || position == xmasRow || position == newYearRow || position == newYearEveRow ||
|
|
position == fireworksRow || position == saveCacheToPrivateDirectoryRow || position == unlimitedFavedStickersRow ||
|
|
position == disableFilteringRow) {
|
|
return 3;
|
|
} else if (position == settingsRow || position == connectionRow || position == chatRow || position == experimentRow) {
|
|
return 4;
|
|
} else if (position == needRestartRow) {
|
|
return 7;
|
|
}
|
|
return 6;
|
|
}
|
|
}
|
|
}
|