2017-07-08 18:32:04 +02:00
|
|
|
/*
|
2019-01-23 18:03:33 +01:00
|
|
|
* This is the source code of Telegram for Android v. 5.x.x.
|
2017-07-08 18:32:04 +02:00
|
|
|
* It is licensed under GNU GPL v. 2 or later.
|
|
|
|
* You should have received a copy of the license in this archive (see LICENSE).
|
|
|
|
*
|
2019-01-23 18:03:33 +01:00
|
|
|
* Copyright Nikolai Kudashov, 2013-2018.
|
2017-07-08 18:32:04 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
package org.telegram.ui;
|
|
|
|
|
2019-12-31 14:08:08 +01:00
|
|
|
import android.animation.ValueAnimator;
|
|
|
|
import android.content.ClipData;
|
|
|
|
import android.content.ClipboardManager;
|
2017-07-08 18:32:04 +02:00
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.content.SharedPreferences;
|
2018-07-30 04:07:02 +02:00
|
|
|
import android.graphics.Canvas;
|
|
|
|
import android.graphics.PorterDuff;
|
|
|
|
import android.graphics.PorterDuffColorFilter;
|
2017-07-08 18:32:04 +02:00
|
|
|
import android.graphics.Typeface;
|
2019-12-31 14:08:08 +01:00
|
|
|
import android.os.Build;
|
2017-07-08 18:32:04 +02:00
|
|
|
import android.text.Editable;
|
|
|
|
import android.text.InputType;
|
|
|
|
import android.text.TextUtils;
|
|
|
|
import android.text.TextWatcher;
|
|
|
|
import android.text.method.PasswordTransformationMethod;
|
2019-12-31 14:08:08 +01:00
|
|
|
import android.transition.ChangeBounds;
|
|
|
|
import android.transition.Fade;
|
|
|
|
import android.transition.Transition;
|
|
|
|
import android.transition.TransitionManager;
|
|
|
|
import android.transition.TransitionSet;
|
2017-07-08 18:32:04 +02:00
|
|
|
import android.util.TypedValue;
|
|
|
|
import android.view.Gravity;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
import android.view.inputmethod.EditorInfo;
|
|
|
|
import android.widget.EditText;
|
|
|
|
import android.widget.FrameLayout;
|
2018-07-30 04:07:02 +02:00
|
|
|
import android.widget.ImageView;
|
2017-07-08 18:32:04 +02:00
|
|
|
import android.widget.LinearLayout;
|
|
|
|
import android.widget.ScrollView;
|
|
|
|
import android.widget.TextView;
|
|
|
|
|
2019-12-31 14:08:08 +01:00
|
|
|
import androidx.core.graphics.ColorUtils;
|
|
|
|
|
2017-07-08 18:32:04 +02:00
|
|
|
import org.telegram.messenger.AndroidUtilities;
|
|
|
|
import org.telegram.messenger.LocaleController;
|
2018-07-30 04:07:02 +02:00
|
|
|
import org.telegram.messenger.MessagesController;
|
2017-07-08 18:32:04 +02:00
|
|
|
import org.telegram.messenger.NotificationCenter;
|
|
|
|
import org.telegram.messenger.R;
|
2018-07-30 04:07:02 +02:00
|
|
|
import org.telegram.messenger.SharedConfig;
|
2017-07-08 18:32:04 +02:00
|
|
|
import org.telegram.messenger.Utilities;
|
|
|
|
import org.telegram.tgnet.ConnectionsManager;
|
|
|
|
import org.telegram.ui.ActionBar.ActionBar;
|
|
|
|
import org.telegram.ui.ActionBar.ActionBarMenuItem;
|
|
|
|
import org.telegram.ui.ActionBar.BaseFragment;
|
|
|
|
import org.telegram.ui.ActionBar.Theme;
|
|
|
|
import org.telegram.ui.ActionBar.ThemeDescription;
|
|
|
|
import org.telegram.ui.Cells.HeaderCell;
|
2019-12-31 14:08:08 +01:00
|
|
|
import org.telegram.ui.Cells.RadioCell;
|
2017-07-08 18:32:04 +02:00
|
|
|
import org.telegram.ui.Cells.ShadowSectionCell;
|
|
|
|
import org.telegram.ui.Cells.TextInfoPrivacyCell;
|
2018-07-30 04:07:02 +02:00
|
|
|
import org.telegram.ui.Cells.TextSettingsCell;
|
2019-12-31 14:08:08 +01:00
|
|
|
import org.telegram.ui.Components.CubicBezierInterpolator;
|
2017-12-08 18:35:59 +01:00
|
|
|
import org.telegram.ui.Components.EditTextBoldCursor;
|
2017-07-08 18:32:04 +02:00
|
|
|
import org.telegram.ui.Components.LayoutHelper;
|
|
|
|
|
2019-12-31 14:08:08 +01:00
|
|
|
import java.io.UnsupportedEncodingException;
|
|
|
|
import java.net.URLDecoder;
|
2017-07-08 18:32:04 +02:00
|
|
|
import java.net.URLEncoder;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
public class ProxySettingsActivity extends BaseFragment {
|
2017-07-08 18:32:04 +02:00
|
|
|
|
2019-12-31 14:08:08 +01:00
|
|
|
private final static int TYPE_SOCKS5 = 0;
|
|
|
|
private final static int TYPE_MTPROTO = 1;
|
|
|
|
|
2017-07-08 18:32:04 +02:00
|
|
|
private final static int FIELD_IP = 0;
|
|
|
|
private final static int FIELD_PORT = 1;
|
|
|
|
private final static int FIELD_USER = 2;
|
|
|
|
private final static int FIELD_PASSWORD = 3;
|
2018-07-30 04:07:02 +02:00
|
|
|
private final static int FIELD_SECRET = 4;
|
2017-07-08 18:32:04 +02:00
|
|
|
|
2017-12-08 18:35:59 +01:00
|
|
|
private EditTextBoldCursor[] inputFields;
|
2017-07-08 18:32:04 +02:00
|
|
|
private ScrollView scrollView;
|
|
|
|
private LinearLayout linearLayout2;
|
2019-12-31 14:08:08 +01:00
|
|
|
private LinearLayout inputFieldsContainer;
|
2017-07-08 18:32:04 +02:00
|
|
|
private HeaderCell headerCell;
|
2019-12-31 14:08:08 +01:00
|
|
|
private ShadowSectionCell[] sectionCell = new ShadowSectionCell[3];
|
|
|
|
private TextInfoPrivacyCell[] bottomCells = new TextInfoPrivacyCell[2];
|
2018-07-30 04:07:02 +02:00
|
|
|
private TextSettingsCell shareCell;
|
2019-12-31 14:08:08 +01:00
|
|
|
private TextSettingsCell pasteCell;
|
2018-07-30 04:07:02 +02:00
|
|
|
private ActionBarMenuItem doneItem;
|
2019-12-31 14:08:08 +01:00
|
|
|
private RadioCell[] typeCell = new RadioCell[2];
|
|
|
|
private int currentType = -1;
|
|
|
|
|
|
|
|
private int pasteType = -1;
|
|
|
|
private String pasteString;
|
|
|
|
private String[] pasteFields;
|
|
|
|
|
|
|
|
private float shareDoneProgress = 1f;
|
|
|
|
private float[] shareDoneProgressAnimValues = new float[2];
|
|
|
|
private boolean shareDoneEnabled = true;
|
|
|
|
private ValueAnimator shareDoneAnimator;
|
|
|
|
|
|
|
|
private ClipboardManager clipboardManager;
|
2017-07-08 18:32:04 +02:00
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
private boolean addingNewProxy;
|
|
|
|
|
|
|
|
private SharedConfig.ProxyInfo currentProxyInfo;
|
2017-07-08 18:32:04 +02:00
|
|
|
|
|
|
|
private boolean ignoreOnTextChange;
|
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
private static final int done_button = 1;
|
2017-07-08 18:32:04 +02:00
|
|
|
|
2021-09-20 07:54:41 +02:00
|
|
|
public static class TypeCell extends FrameLayout {
|
2018-07-30 04:07:02 +02:00
|
|
|
|
|
|
|
private TextView textView;
|
|
|
|
private ImageView checkImage;
|
|
|
|
private boolean needDivider;
|
|
|
|
|
|
|
|
public TypeCell(Context context) {
|
|
|
|
super(context);
|
|
|
|
|
|
|
|
setWillNotDraw(false);
|
|
|
|
|
|
|
|
textView = new TextView(context);
|
|
|
|
textView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
|
|
|
|
textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
|
|
|
|
textView.setLines(1);
|
|
|
|
textView.setMaxLines(1);
|
|
|
|
textView.setSingleLine(true);
|
|
|
|
textView.setEllipsize(TextUtils.TruncateAt.END);
|
|
|
|
textView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.CENTER_VERTICAL);
|
2019-01-23 18:03:33 +01:00
|
|
|
addView(textView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, LocaleController.isRTL ? 23 + 48 : 21, 0, LocaleController.isRTL ? 21 : 23, 0));
|
2018-07-30 04:07:02 +02:00
|
|
|
|
|
|
|
checkImage = new ImageView(context);
|
|
|
|
checkImage.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_featuredStickers_addedIcon), PorterDuff.Mode.MULTIPLY));
|
|
|
|
checkImage.setImageResource(R.drawable.sticker_added);
|
2019-01-23 18:03:33 +01:00
|
|
|
addView(checkImage, LayoutHelper.createFrame(19, 14, (LocaleController.isRTL ? Gravity.LEFT : Gravity.RIGHT) | Gravity.CENTER_VERTICAL, 21, 0, 21, 0));
|
2018-07-30 04:07:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
2019-01-23 18:03:33 +01:00
|
|
|
super.onMeasure(MeasureSpec.makeMeasureSpec(MeasureSpec.getSize(widthMeasureSpec), MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(50) + (needDivider ? 1 : 0), MeasureSpec.EXACTLY));
|
2018-07-30 04:07:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void setValue(String name, boolean checked, boolean divider) {
|
|
|
|
textView.setText(name);
|
|
|
|
checkImage.setVisibility(checked ? VISIBLE : INVISIBLE);
|
|
|
|
needDivider = divider;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setTypeChecked(boolean value) {
|
|
|
|
checkImage.setVisibility(value ? VISIBLE : INVISIBLE);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onDraw(Canvas canvas) {
|
|
|
|
if (needDivider) {
|
2019-01-23 18:03:33 +01:00
|
|
|
canvas.drawLine(LocaleController.isRTL ? 0 : AndroidUtilities.dp(20), getMeasuredHeight() - 1, getMeasuredWidth() - (LocaleController.isRTL ? AndroidUtilities.dp(20) : 0), getMeasuredHeight() - 1, Theme.dividerPaint);
|
2018-07-30 04:07:02 +02:00
|
|
|
}
|
|
|
|
}
|
2017-07-08 18:32:04 +02:00
|
|
|
}
|
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
public ProxySettingsActivity() {
|
|
|
|
super();
|
|
|
|
currentProxyInfo = new SharedConfig.ProxyInfo("", 1080, "", "", "");
|
|
|
|
addingNewProxy = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public ProxySettingsActivity(SharedConfig.ProxyInfo proxyInfo) {
|
|
|
|
super();
|
|
|
|
currentProxyInfo = proxyInfo;
|
2017-07-08 18:32:04 +02:00
|
|
|
}
|
|
|
|
|
2019-12-31 14:08:08 +01:00
|
|
|
private ClipboardManager.OnPrimaryClipChangedListener clipChangedListener = this::updatePasteCell;
|
|
|
|
|
2017-07-08 18:32:04 +02:00
|
|
|
@Override
|
2018-07-30 04:07:02 +02:00
|
|
|
public void onResume() {
|
|
|
|
super.onResume();
|
|
|
|
AndroidUtilities.requestAdjustResize(getParentActivity(), classGuid);
|
2019-12-31 14:08:08 +01:00
|
|
|
clipboardManager.addPrimaryClipChangedListener(clipChangedListener);
|
|
|
|
updatePasteCell();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onPause() {
|
|
|
|
super.onPause();
|
|
|
|
clipboardManager.removePrimaryClipChangedListener(clipChangedListener);
|
2017-07-08 18:32:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public View createView(Context context) {
|
2018-07-30 04:07:02 +02:00
|
|
|
actionBar.setTitle(LocaleController.getString("ProxyDetails", R.string.ProxyDetails));
|
2017-07-08 18:32:04 +02:00
|
|
|
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
|
2018-07-30 04:07:02 +02:00
|
|
|
actionBar.setAllowOverlayTitle(false);
|
|
|
|
if (AndroidUtilities.isTablet()) {
|
|
|
|
actionBar.setOccupyStatusBar(false);
|
|
|
|
}
|
2017-07-08 18:32:04 +02:00
|
|
|
|
|
|
|
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
|
|
|
|
@Override
|
|
|
|
public void onItemClick(int id) {
|
|
|
|
if (id == -1) {
|
|
|
|
finishFragment();
|
2018-07-30 04:07:02 +02:00
|
|
|
} else if (id == done_button) {
|
2017-07-08 18:32:04 +02:00
|
|
|
if (getParentActivity() == null) {
|
|
|
|
return;
|
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
currentProxyInfo.address = inputFields[FIELD_IP].getText().toString();
|
|
|
|
currentProxyInfo.port = Utilities.parseInt(inputFields[FIELD_PORT].getText().toString());
|
|
|
|
if (currentType == 0) {
|
|
|
|
currentProxyInfo.secret = "";
|
|
|
|
currentProxyInfo.username = inputFields[FIELD_USER].getText().toString();
|
|
|
|
currentProxyInfo.password = inputFields[FIELD_PASSWORD].getText().toString();
|
|
|
|
} else {
|
|
|
|
currentProxyInfo.secret = inputFields[FIELD_SECRET].getText().toString();
|
|
|
|
currentProxyInfo.username = "";
|
|
|
|
currentProxyInfo.password = "";
|
2017-07-08 18:32:04 +02:00
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
|
|
|
|
SharedPreferences preferences = MessagesController.getGlobalMainSettings();
|
|
|
|
SharedPreferences.Editor editor = preferences.edit();
|
|
|
|
boolean enabled;
|
|
|
|
if (addingNewProxy) {
|
|
|
|
SharedConfig.addProxy(currentProxyInfo);
|
|
|
|
SharedConfig.currentProxy = currentProxyInfo;
|
|
|
|
editor.putBoolean("proxy_enabled", true);
|
|
|
|
enabled = true;
|
|
|
|
} else {
|
|
|
|
enabled = preferences.getBoolean("proxy_enabled", false);
|
|
|
|
SharedConfig.saveProxyList();
|
|
|
|
}
|
|
|
|
if (addingNewProxy || SharedConfig.currentProxy == currentProxyInfo) {
|
|
|
|
editor.putString("proxy_ip", currentProxyInfo.address);
|
|
|
|
editor.putString("proxy_pass", currentProxyInfo.password);
|
|
|
|
editor.putString("proxy_user", currentProxyInfo.username);
|
|
|
|
editor.putInt("proxy_port", currentProxyInfo.port);
|
|
|
|
editor.putString("proxy_secret", currentProxyInfo.secret);
|
|
|
|
ConnectionsManager.setProxySettings(enabled, currentProxyInfo.address, currentProxyInfo.port, currentProxyInfo.username, currentProxyInfo.password, currentProxyInfo.secret);
|
2017-07-08 18:32:04 +02:00
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
editor.commit();
|
|
|
|
|
|
|
|
NotificationCenter.getGlobalInstance().postNotificationName(NotificationCenter.proxySettingsChanged);
|
|
|
|
|
|
|
|
finishFragment();
|
2017-07-08 18:32:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
doneItem = actionBar.createMenu().addItemWithWidth(done_button, R.drawable.ic_done, AndroidUtilities.dp(56));
|
2019-05-14 14:08:05 +02:00
|
|
|
doneItem.setContentDescription(LocaleController.getString("Done", R.string.Done));
|
2017-07-08 18:32:04 +02:00
|
|
|
|
|
|
|
fragmentView = new FrameLayout(context);
|
|
|
|
FrameLayout frameLayout = (FrameLayout) fragmentView;
|
|
|
|
fragmentView.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundGray));
|
|
|
|
|
|
|
|
scrollView = new ScrollView(context);
|
|
|
|
scrollView.setFillViewport(true);
|
|
|
|
AndroidUtilities.setScrollViewEdgeEffectColor(scrollView, Theme.getColor(Theme.key_actionBarDefault));
|
|
|
|
frameLayout.addView(scrollView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
|
|
|
|
|
|
|
|
linearLayout2 = new LinearLayout(context);
|
|
|
|
linearLayout2.setOrientation(LinearLayout.VERTICAL);
|
|
|
|
scrollView.addView(linearLayout2, new ScrollView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
|
|
|
|
|
2019-12-31 14:08:08 +01:00
|
|
|
final View.OnClickListener typeCellClickListener = view -> setProxyType((Integer) view.getTag(), true);
|
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
for (int a = 0; a < 2; a++) {
|
2019-12-31 14:08:08 +01:00
|
|
|
typeCell[a] = new RadioCell(context);
|
|
|
|
typeCell[a].setBackground(Theme.getSelectorDrawable(true));
|
2018-07-30 04:07:02 +02:00
|
|
|
typeCell[a].setTag(a);
|
|
|
|
if (a == 0) {
|
2019-12-31 14:08:08 +01:00
|
|
|
typeCell[a].setText(LocaleController.getString("UseProxySocks5", R.string.UseProxySocks5), a == currentType, true);
|
2021-09-20 07:54:41 +02:00
|
|
|
} else {
|
2019-12-31 14:08:08 +01:00
|
|
|
typeCell[a].setText(LocaleController.getString("UseProxyTelegram", R.string.UseProxyTelegram), a == currentType, false);
|
2017-07-08 18:32:04 +02:00
|
|
|
}
|
2019-01-23 18:03:33 +01:00
|
|
|
linearLayout2.addView(typeCell[a], LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 50));
|
2019-12-31 14:08:08 +01:00
|
|
|
typeCell[a].setOnClickListener(typeCellClickListener);
|
2018-07-30 04:07:02 +02:00
|
|
|
}
|
2017-07-08 18:32:04 +02:00
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
sectionCell[0] = new ShadowSectionCell(context);
|
|
|
|
linearLayout2.addView(sectionCell[0], LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
|
2017-07-08 18:32:04 +02:00
|
|
|
|
2019-12-31 14:08:08 +01:00
|
|
|
inputFieldsContainer = new LinearLayout(context);
|
|
|
|
inputFieldsContainer.setOrientation(LinearLayout.VERTICAL);
|
|
|
|
inputFieldsContainer.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
|
|
|
// bring to front for transitions
|
|
|
|
inputFieldsContainer.setElevation(AndroidUtilities.dp(1f));
|
|
|
|
inputFieldsContainer.setOutlineProvider(null);
|
|
|
|
}
|
|
|
|
linearLayout2.addView(inputFieldsContainer, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
|
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
inputFields = new EditTextBoldCursor[5];
|
|
|
|
for (int a = 0; a < 5; a++) {
|
2017-07-08 18:32:04 +02:00
|
|
|
FrameLayout container = new FrameLayout(context);
|
2019-12-31 14:08:08 +01:00
|
|
|
inputFieldsContainer.addView(container, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 64));
|
2017-07-08 18:32:04 +02:00
|
|
|
|
2017-12-08 18:35:59 +01:00
|
|
|
inputFields[a] = new EditTextBoldCursor(context);
|
2017-07-08 18:32:04 +02:00
|
|
|
inputFields[a].setTag(a);
|
|
|
|
inputFields[a].setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
|
2018-07-30 04:07:02 +02:00
|
|
|
inputFields[a].setHintColor(Theme.getColor(Theme.key_windowBackgroundWhiteHintText));
|
2017-07-08 18:32:04 +02:00
|
|
|
inputFields[a].setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
|
2019-12-31 14:08:08 +01:00
|
|
|
inputFields[a].setBackground(null);
|
2017-12-08 18:35:59 +01:00
|
|
|
inputFields[a].setCursorColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
|
|
|
|
inputFields[a].setCursorSize(AndroidUtilities.dp(20));
|
|
|
|
inputFields[a].setCursorWidth(1.5f);
|
2018-07-30 04:07:02 +02:00
|
|
|
inputFields[a].setSingleLine(true);
|
|
|
|
inputFields[a].setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.CENTER_VERTICAL);
|
|
|
|
inputFields[a].setHeaderHintColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlueHeader));
|
|
|
|
inputFields[a].setTransformHintToHeader(true);
|
|
|
|
inputFields[a].setLineColors(Theme.getColor(Theme.key_windowBackgroundWhiteInputField), Theme.getColor(Theme.key_windowBackgroundWhiteInputFieldActivated), Theme.getColor(Theme.key_windowBackgroundWhiteRedText3));
|
2017-07-08 18:32:04 +02:00
|
|
|
|
|
|
|
if (a == FIELD_IP) {
|
2018-07-30 04:07:02 +02:00
|
|
|
inputFields[a].setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS | InputType.TYPE_TEXT_VARIATION_URI);
|
2017-07-08 18:32:04 +02:00
|
|
|
inputFields[a].addTextChangedListener(new TextWatcher() {
|
|
|
|
@Override
|
|
|
|
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void afterTextChanged(Editable s) {
|
2019-12-31 14:08:08 +01:00
|
|
|
checkShareDone(true);
|
2017-07-08 18:32:04 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
} else if (a == FIELD_PORT) {
|
|
|
|
inputFields[a].setInputType(InputType.TYPE_CLASS_NUMBER);
|
|
|
|
inputFields[a].addTextChangedListener(new TextWatcher() {
|
|
|
|
@Override
|
|
|
|
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void afterTextChanged(Editable s) {
|
|
|
|
if (ignoreOnTextChange) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
EditText phoneField = inputFields[FIELD_PORT];
|
|
|
|
int start = phoneField.getSelectionStart();
|
|
|
|
String chars = "0123456789";
|
|
|
|
String str = phoneField.getText().toString();
|
|
|
|
StringBuilder builder = new StringBuilder(str.length());
|
|
|
|
for (int a = 0; a < str.length(); a++) {
|
|
|
|
String ch = str.substring(a, a + 1);
|
|
|
|
if (chars.contains(ch)) {
|
|
|
|
builder.append(ch);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ignoreOnTextChange = true;
|
|
|
|
boolean changed;
|
|
|
|
int port = Utilities.parseInt(builder.toString());
|
|
|
|
if (port < 0 || port > 65535 || !str.equals(builder.toString())) {
|
|
|
|
if (port < 0) {
|
|
|
|
phoneField.setText("0");
|
|
|
|
} else if (port > 65535) {
|
|
|
|
phoneField.setText("65535");
|
|
|
|
} else {
|
|
|
|
phoneField.setText(builder.toString());
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (start >= 0) {
|
2021-09-20 07:54:41 +02:00
|
|
|
phoneField.setSelection(Math.min(start, phoneField.length()));
|
2017-07-08 18:32:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
ignoreOnTextChange = false;
|
2019-12-31 14:08:08 +01:00
|
|
|
checkShareDone(true);
|
2017-07-08 18:32:04 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
} else if (a == FIELD_PASSWORD) {
|
|
|
|
inputFields[a].setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
|
|
|
|
inputFields[a].setTypeface(Typeface.DEFAULT);
|
|
|
|
inputFields[a].setTransformationMethod(PasswordTransformationMethod.getInstance());
|
|
|
|
} else {
|
2018-07-30 04:07:02 +02:00
|
|
|
inputFields[a].setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
|
2017-07-08 18:32:04 +02:00
|
|
|
}
|
|
|
|
inputFields[a].setImeOptions(EditorInfo.IME_ACTION_NEXT | EditorInfo.IME_FLAG_NO_EXTRACT_UI);
|
|
|
|
switch (a) {
|
|
|
|
case FIELD_IP:
|
2018-07-30 04:07:02 +02:00
|
|
|
inputFields[a].setHintText(LocaleController.getString("UseProxyAddress", R.string.UseProxyAddress));
|
|
|
|
inputFields[a].setText(currentProxyInfo.address);
|
2017-07-08 18:32:04 +02:00
|
|
|
break;
|
|
|
|
case FIELD_PASSWORD:
|
2018-07-30 04:07:02 +02:00
|
|
|
inputFields[a].setHintText(LocaleController.getString("UseProxyPassword", R.string.UseProxyPassword));
|
|
|
|
inputFields[a].setText(currentProxyInfo.password);
|
2017-07-08 18:32:04 +02:00
|
|
|
break;
|
|
|
|
case FIELD_PORT:
|
2018-07-30 04:07:02 +02:00
|
|
|
inputFields[a].setHintText(LocaleController.getString("UseProxyPort", R.string.UseProxyPort));
|
|
|
|
inputFields[a].setText("" + currentProxyInfo.port);
|
2017-07-08 18:32:04 +02:00
|
|
|
break;
|
|
|
|
case FIELD_USER:
|
2018-07-30 04:07:02 +02:00
|
|
|
inputFields[a].setHintText(LocaleController.getString("UseProxyUsername", R.string.UseProxyUsername));
|
|
|
|
inputFields[a].setText(currentProxyInfo.username);
|
|
|
|
break;
|
|
|
|
case FIELD_SECRET:
|
|
|
|
inputFields[a].setHintText(LocaleController.getString("UseProxySecret", R.string.UseProxySecret));
|
|
|
|
inputFields[a].setText(currentProxyInfo.secret);
|
2017-07-08 18:32:04 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
inputFields[a].setSelection(inputFields[a].length());
|
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
inputFields[a].setPadding(0, 0, 0, 0);
|
2019-12-31 14:08:08 +01:00
|
|
|
container.addView(inputFields[a], LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.LEFT | Gravity.TOP, 17, a == FIELD_IP ? 12 : 0, 17, 0));
|
2017-07-08 18:32:04 +02:00
|
|
|
|
2019-01-23 18:03:33 +01:00
|
|
|
inputFields[a].setOnEditorActionListener((textView, i, keyEvent) -> {
|
|
|
|
if (i == EditorInfo.IME_ACTION_NEXT) {
|
|
|
|
int num = (Integer) textView.getTag();
|
|
|
|
if (num + 1 < inputFields.length) {
|
|
|
|
num++;
|
|
|
|
inputFields[num].requestFocus();
|
2017-07-08 18:32:04 +02:00
|
|
|
}
|
2019-01-23 18:03:33 +01:00
|
|
|
return true;
|
|
|
|
} else if (i == EditorInfo.IME_ACTION_DONE) {
|
|
|
|
finishFragment();
|
|
|
|
return true;
|
2017-07-08 18:32:04 +02:00
|
|
|
}
|
2019-01-23 18:03:33 +01:00
|
|
|
return false;
|
2017-07-08 18:32:04 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-12-31 14:08:08 +01:00
|
|
|
for (int i = 0; i < 2; i++) {
|
|
|
|
bottomCells[i] = new TextInfoPrivacyCell(context);
|
|
|
|
bottomCells[i].setBackground(Theme.getThemedDrawable(context, R.drawable.greydivider_bottom, Theme.key_windowBackgroundGrayShadow));
|
|
|
|
if (i == 0) {
|
|
|
|
bottomCells[i].setText(LocaleController.getString("UseProxyInfo", R.string.UseProxyInfo));
|
2021-09-20 07:54:41 +02:00
|
|
|
} else {
|
2019-12-31 14:08:08 +01:00
|
|
|
bottomCells[i].setText(LocaleController.getString("UseProxyTelegramInfo", R.string.UseProxyTelegramInfo) + "\n\n" + LocaleController.getString("UseProxyTelegramInfo2", R.string.UseProxyTelegramInfo2));
|
|
|
|
bottomCells[i].setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
linearLayout2.addView(bottomCells[i], LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
|
|
|
|
}
|
|
|
|
|
|
|
|
pasteCell = new TextSettingsCell(fragmentView.getContext());
|
|
|
|
pasteCell.setBackground(Theme.getSelectorDrawable(true));
|
|
|
|
pasteCell.setText(LocaleController.getString("PasteFromClipboard", R.string.PasteFromClipboard), false);
|
|
|
|
pasteCell.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlueText4));
|
|
|
|
pasteCell.setOnClickListener(v -> {
|
|
|
|
if (pasteType != -1) {
|
|
|
|
for (int i = 0; i < pasteFields.length; i++) {
|
|
|
|
if (pasteType == TYPE_SOCKS5 && i == FIELD_SECRET) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (pasteType == TYPE_MTPROTO && (i == FIELD_USER || i == FIELD_PASSWORD)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (pasteFields[i] != null) {
|
|
|
|
try {
|
|
|
|
inputFields[i].setText(URLDecoder.decode(pasteFields[i], "UTF-8"));
|
|
|
|
} catch (UnsupportedEncodingException e) {
|
|
|
|
inputFields[i].setText(pasteFields[i]);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
inputFields[i].setText(null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
inputFields[0].setSelection(inputFields[0].length());
|
|
|
|
setProxyType(pasteType, true, () -> {
|
|
|
|
AndroidUtilities.hideKeyboard(inputFieldsContainer.findFocus());
|
|
|
|
for (int i = 0; i < pasteFields.length; i++) {
|
|
|
|
if (pasteType == TYPE_SOCKS5 && i != FIELD_SECRET) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (pasteType == TYPE_MTPROTO && i != FIELD_USER && i != FIELD_PASSWORD) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
inputFields[i].setText(null);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
linearLayout2.addView(pasteCell, 0, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
|
|
|
|
pasteCell.setVisibility(View.GONE);
|
|
|
|
sectionCell[2] = new ShadowSectionCell(fragmentView.getContext());
|
|
|
|
sectionCell[2].setBackground(Theme.getThemedDrawable(fragmentView.getContext(), R.drawable.greydivider_bottom, Theme.key_windowBackgroundGrayShadow));
|
|
|
|
linearLayout2.addView(sectionCell[2], 1, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
|
|
|
|
sectionCell[2].setVisibility(View.GONE);
|
2017-07-08 18:32:04 +02:00
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
shareCell = new TextSettingsCell(context);
|
|
|
|
shareCell.setBackgroundDrawable(Theme.getSelectorDrawable(true));
|
|
|
|
shareCell.setText(LocaleController.getString("ShareFile", R.string.ShareFile), false);
|
|
|
|
shareCell.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlueText4));
|
|
|
|
linearLayout2.addView(shareCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
|
2019-01-23 18:03:33 +01:00
|
|
|
shareCell.setOnClickListener(v -> {
|
2019-07-18 15:01:39 +02:00
|
|
|
StringBuilder params = new StringBuilder();
|
2019-01-23 18:03:33 +01:00
|
|
|
String address = inputFields[FIELD_IP].getText().toString();
|
|
|
|
String password = inputFields[FIELD_PASSWORD].getText().toString();
|
|
|
|
String user = inputFields[FIELD_USER].getText().toString();
|
|
|
|
String port = inputFields[FIELD_PORT].getText().toString();
|
|
|
|
String secret = inputFields[FIELD_SECRET].getText().toString();
|
|
|
|
String url;
|
|
|
|
try {
|
|
|
|
if (!TextUtils.isEmpty(address)) {
|
|
|
|
params.append("server=").append(URLEncoder.encode(address, "UTF-8"));
|
|
|
|
}
|
|
|
|
if (!TextUtils.isEmpty(port)) {
|
|
|
|
if (params.length() != 0) {
|
|
|
|
params.append("&");
|
|
|
|
}
|
|
|
|
params.append("port=").append(URLEncoder.encode(port, "UTF-8"));
|
|
|
|
}
|
|
|
|
if (currentType == 1) {
|
|
|
|
url = "https://t.me/proxy?";
|
|
|
|
if (params.length() != 0) {
|
|
|
|
params.append("&");
|
2018-07-30 04:07:02 +02:00
|
|
|
}
|
2019-01-23 18:03:33 +01:00
|
|
|
params.append("secret=").append(URLEncoder.encode(secret, "UTF-8"));
|
|
|
|
} else {
|
|
|
|
url = "https://t.me/socks?";
|
|
|
|
if (!TextUtils.isEmpty(user)) {
|
2018-07-30 04:07:02 +02:00
|
|
|
if (params.length() != 0) {
|
|
|
|
params.append("&");
|
|
|
|
}
|
2019-01-23 18:03:33 +01:00
|
|
|
params.append("user=").append(URLEncoder.encode(user, "UTF-8"));
|
2018-07-30 04:07:02 +02:00
|
|
|
}
|
2019-01-23 18:03:33 +01:00
|
|
|
if (!TextUtils.isEmpty(password)) {
|
2018-07-30 04:07:02 +02:00
|
|
|
if (params.length() != 0) {
|
|
|
|
params.append("&");
|
|
|
|
}
|
2019-01-23 18:03:33 +01:00
|
|
|
params.append("pass=").append(URLEncoder.encode(password, "UTF-8"));
|
2018-07-30 04:07:02 +02:00
|
|
|
}
|
|
|
|
}
|
2019-01-23 18:03:33 +01:00
|
|
|
} catch (Exception ignore) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (params.length() == 0) {
|
|
|
|
return;
|
2017-07-08 18:32:04 +02:00
|
|
|
}
|
2019-01-23 18:03:33 +01:00
|
|
|
Intent shareIntent = new Intent(Intent.ACTION_SEND);
|
|
|
|
shareIntent.setType("text/plain");
|
|
|
|
shareIntent.putExtra(Intent.EXTRA_TEXT, url + params.toString());
|
|
|
|
Intent chooserIntent = Intent.createChooser(shareIntent, LocaleController.getString("ShareLink", R.string.ShareLink));
|
|
|
|
chooserIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
|
|
getParentActivity().startActivity(chooserIntent);
|
2017-07-08 18:32:04 +02:00
|
|
|
});
|
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
sectionCell[1] = new ShadowSectionCell(context);
|
|
|
|
sectionCell[1].setBackgroundDrawable(Theme.getThemedDrawable(context, R.drawable.greydivider_bottom, Theme.key_windowBackgroundGrayShadow));
|
|
|
|
linearLayout2.addView(sectionCell[1], LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
|
2017-07-08 18:32:04 +02:00
|
|
|
|
2019-12-31 14:08:08 +01:00
|
|
|
clipboardManager = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
|
|
|
|
|
|
|
|
shareDoneEnabled = true;
|
|
|
|
shareDoneProgress = 1f;
|
|
|
|
checkShareDone(false);
|
|
|
|
|
|
|
|
currentType = -1;
|
|
|
|
setProxyType(TextUtils.isEmpty(currentProxyInfo.secret) ? 0 : 1, false);
|
|
|
|
|
|
|
|
pasteType = -1;
|
|
|
|
pasteString = null;
|
|
|
|
updatePasteCell();
|
2017-07-08 18:32:04 +02:00
|
|
|
|
|
|
|
return fragmentView;
|
|
|
|
}
|
|
|
|
|
2019-12-31 14:08:08 +01:00
|
|
|
private void updatePasteCell() {
|
|
|
|
final ClipData clip = clipboardManager.getPrimaryClip();
|
|
|
|
|
2019-12-31 20:46:59 +01:00
|
|
|
String clipText;
|
2019-12-31 14:08:08 +01:00
|
|
|
if (clip != null && clip.getItemCount() > 0) {
|
2019-12-31 20:46:59 +01:00
|
|
|
try {
|
|
|
|
clipText = clip.getItemAt(0).coerceToText(fragmentView.getContext()).toString();
|
|
|
|
} catch (Exception e) {
|
|
|
|
clipText = null;
|
|
|
|
}
|
2019-12-31 14:08:08 +01:00
|
|
|
} else {
|
|
|
|
clipText = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (TextUtils.equals(clipText, pasteString)) {
|
2017-07-08 18:32:04 +02:00
|
|
|
return;
|
|
|
|
}
|
2019-12-31 14:08:08 +01:00
|
|
|
|
|
|
|
pasteType = -1;
|
|
|
|
pasteString = clipText;
|
|
|
|
pasteFields = new String[inputFields.length];
|
|
|
|
if (clipText != null) {
|
|
|
|
String[] params = null;
|
|
|
|
|
|
|
|
final String[] socksStrings = {"t.me/socks?", "tg://socks?"};
|
|
|
|
for (int i = 0; i < socksStrings.length; i++) {
|
|
|
|
final int index = clipText.indexOf(socksStrings[i]);
|
|
|
|
if (index >= 0) {
|
|
|
|
pasteType = TYPE_SOCKS5;
|
|
|
|
params = clipText.substring(index + socksStrings[i].length()).split("&");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (params == null) {
|
|
|
|
final String[] proxyStrings = {"t.me/proxy?", "tg://proxy?"};
|
|
|
|
for (int i = 0; i < proxyStrings.length; i++) {
|
|
|
|
final int index = clipText.indexOf(proxyStrings[i]);
|
|
|
|
if (index >= 0) {
|
|
|
|
pasteType = TYPE_MTPROTO;
|
|
|
|
params = clipText.substring(index + proxyStrings[i].length()).split("&");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (params != null) {
|
|
|
|
for (int i = 0; i < params.length; i++) {
|
|
|
|
final String[] pair = params[i].split("=");
|
|
|
|
if (pair.length != 2) continue;
|
|
|
|
switch (pair[0].toLowerCase()) {
|
|
|
|
case "server":
|
|
|
|
pasteFields[FIELD_IP] = pair[1];
|
|
|
|
break;
|
|
|
|
case "port":
|
|
|
|
pasteFields[FIELD_PORT] = pair[1];
|
|
|
|
break;
|
|
|
|
case "user":
|
|
|
|
if (pasteType == TYPE_SOCKS5) {
|
|
|
|
pasteFields[FIELD_USER] = pair[1];
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case "pass":
|
|
|
|
if (pasteType == TYPE_SOCKS5) {
|
|
|
|
pasteFields[FIELD_PASSWORD] = pair[1];
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case "secret":
|
|
|
|
if (pasteType == TYPE_MTPROTO) {
|
|
|
|
pasteFields[FIELD_SECRET] = pair[1];
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pasteType != -1) {
|
|
|
|
if (pasteCell.getVisibility() != View.VISIBLE) {
|
|
|
|
pasteCell.setVisibility(View.VISIBLE);
|
|
|
|
sectionCell[2].setVisibility(View.VISIBLE);
|
|
|
|
}
|
2017-07-08 18:32:04 +02:00
|
|
|
} else {
|
2019-12-31 14:08:08 +01:00
|
|
|
if (pasteCell.getVisibility() != View.GONE) {
|
|
|
|
pasteCell.setVisibility(View.GONE);
|
|
|
|
sectionCell[2].setVisibility(View.GONE);
|
|
|
|
}
|
2017-07-08 18:32:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-31 14:08:08 +01:00
|
|
|
private void setShareDoneEnabled(boolean enabled, boolean animated) {
|
|
|
|
if (shareDoneEnabled != enabled) {
|
|
|
|
if (shareDoneAnimator != null) {
|
|
|
|
shareDoneAnimator.cancel();
|
|
|
|
} else if (animated) {
|
|
|
|
shareDoneAnimator = ValueAnimator.ofFloat(0f, 1f);
|
|
|
|
shareDoneAnimator.setDuration(200);
|
|
|
|
shareDoneAnimator.addUpdateListener(a -> {
|
|
|
|
shareDoneProgress = AndroidUtilities.lerp(shareDoneProgressAnimValues, a.getAnimatedFraction());
|
|
|
|
shareCell.setTextColor(ColorUtils.blendARGB(Theme.getColor(Theme.key_windowBackgroundWhiteGrayText2), Theme.getColor(Theme.key_windowBackgroundWhiteBlueText4), shareDoneProgress));
|
|
|
|
doneItem.setAlpha(shareDoneProgress / 2f + 0.5f);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
if (animated) {
|
|
|
|
shareDoneProgressAnimValues[0] = shareDoneProgress;
|
|
|
|
shareDoneProgressAnimValues[1] = enabled ? 1f : 0f;
|
|
|
|
shareDoneAnimator.start();
|
|
|
|
} else {
|
|
|
|
shareDoneProgress = enabled ? 1f : 0f;
|
|
|
|
shareCell.setTextColor(enabled ? Theme.getColor(Theme.key_windowBackgroundWhiteBlueText4) : Theme.getColor(Theme.key_windowBackgroundWhiteGrayText2));
|
|
|
|
doneItem.setAlpha(enabled ? 1f : .5f);
|
|
|
|
}
|
|
|
|
shareCell.setEnabled(enabled);
|
|
|
|
doneItem.setEnabled(enabled);
|
|
|
|
shareDoneEnabled = enabled;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void checkShareDone(boolean animated) {
|
|
|
|
if (shareCell == null || doneItem == null || inputFields[FIELD_IP] == null || inputFields[FIELD_PORT] == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
setShareDoneEnabled(inputFields[FIELD_IP].length() != 0 && Utilities.parseInt(inputFields[FIELD_PORT].getText().toString()) != 0, animated);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void setProxyType(int type, boolean animated) {
|
|
|
|
setProxyType(type, animated, null);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void setProxyType(int type, boolean animated, Runnable onTransitionEnd) {
|
|
|
|
if (currentType != type) {
|
|
|
|
currentType = type;
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
|
|
|
TransitionManager.endTransitions(linearLayout2);
|
|
|
|
}
|
|
|
|
if (animated && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
|
|
|
final TransitionSet transitionSet = new TransitionSet()
|
|
|
|
.addTransition(new Fade(Fade.OUT))
|
|
|
|
.addTransition(new ChangeBounds())
|
|
|
|
.addTransition(new Fade(Fade.IN))
|
|
|
|
.setInterpolator(CubicBezierInterpolator.DEFAULT)
|
|
|
|
.setDuration(250);
|
|
|
|
|
|
|
|
if (onTransitionEnd != null) {
|
|
|
|
transitionSet.addListener(new Transition.TransitionListener() {
|
|
|
|
@Override
|
|
|
|
public void onTransitionStart(Transition transition) {
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onTransitionEnd(Transition transition) {
|
|
|
|
onTransitionEnd.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onTransitionCancel(Transition transition) {
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onTransitionPause(Transition transition) {
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onTransitionResume(Transition transition) {
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
TransitionManager.beginDelayedTransition(linearLayout2, transitionSet);
|
|
|
|
}
|
|
|
|
if (currentType == 0) {
|
|
|
|
bottomCells[0].setVisibility(View.VISIBLE);
|
|
|
|
bottomCells[1].setVisibility(View.GONE);
|
|
|
|
((View) inputFields[FIELD_SECRET].getParent()).setVisibility(View.GONE);
|
|
|
|
((View) inputFields[FIELD_PASSWORD].getParent()).setVisibility(View.VISIBLE);
|
|
|
|
((View) inputFields[FIELD_USER].getParent()).setVisibility(View.VISIBLE);
|
|
|
|
} else if (currentType == 1) {
|
|
|
|
bottomCells[0].setVisibility(View.GONE);
|
|
|
|
bottomCells[1].setVisibility(View.VISIBLE);
|
|
|
|
((View) inputFields[FIELD_SECRET].getParent()).setVisibility(View.VISIBLE);
|
|
|
|
((View) inputFields[FIELD_PASSWORD].getParent()).setVisibility(View.GONE);
|
|
|
|
((View) inputFields[FIELD_USER].getParent()).setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
typeCell[0].setChecked(currentType == 0, animated);
|
|
|
|
typeCell[1].setChecked(currentType == 1, animated);
|
2017-07-08 18:32:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-07-30 04:07:02 +02:00
|
|
|
protected void onTransitionAnimationEnd(boolean isOpen, boolean backward) {
|
|
|
|
if (isOpen && !backward && addingNewProxy) {
|
|
|
|
inputFields[FIELD_IP].requestFocus();
|
|
|
|
AndroidUtilities.showKeyboard(inputFields[FIELD_IP]);
|
2017-07-08 18:32:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-04-24 11:21:58 +02:00
|
|
|
public ArrayList<ThemeDescription> getThemeDescriptions() {
|
2019-12-31 14:08:08 +01:00
|
|
|
final ThemeDescription.ThemeDescriptionDelegate delegate = () -> {
|
|
|
|
if (shareCell != null && (shareDoneAnimator == null || !shareDoneAnimator.isRunning())) {
|
|
|
|
shareCell.setTextColor(shareDoneEnabled ? Theme.getColor(Theme.key_windowBackgroundWhiteBlueText4) : Theme.getColor(Theme.key_windowBackgroundWhiteGrayText2));
|
|
|
|
}
|
|
|
|
if (inputFields != null) {
|
|
|
|
for (int i = 0; i < inputFields.length; i++) {
|
|
|
|
inputFields[i].setLineColors(Theme.getColor(Theme.key_windowBackgroundWhiteInputField),
|
|
|
|
Theme.getColor(Theme.key_windowBackgroundWhiteInputFieldActivated),
|
|
|
|
Theme.getColor(Theme.key_windowBackgroundWhiteRedText3));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2017-07-08 18:32:04 +02:00
|
|
|
ArrayList<ThemeDescription> arrayList = new ArrayList<>();
|
|
|
|
arrayList.add(new ThemeDescription(fragmentView, ThemeDescription.FLAG_BACKGROUND, null, null, null, null, Theme.key_windowBackgroundGray));
|
|
|
|
arrayList.add(new ThemeDescription(actionBar, ThemeDescription.FLAG_BACKGROUND, null, null, null, null, Theme.key_actionBarDefault));
|
|
|
|
arrayList.add(new ThemeDescription(scrollView, ThemeDescription.FLAG_LISTGLOWCOLOR, null, null, null, null, Theme.key_actionBarDefault));
|
|
|
|
arrayList.add(new ThemeDescription(actionBar, ThemeDescription.FLAG_AB_ITEMSCOLOR, null, null, null, null, Theme.key_actionBarDefaultIcon));
|
|
|
|
arrayList.add(new ThemeDescription(actionBar, ThemeDescription.FLAG_AB_TITLECOLOR, null, null, null, null, Theme.key_actionBarDefaultTitle));
|
|
|
|
arrayList.add(new ThemeDescription(actionBar, ThemeDescription.FLAG_AB_SELECTORCOLOR, null, null, null, null, Theme.key_actionBarDefaultSelector));
|
|
|
|
arrayList.add(new ThemeDescription(actionBar, ThemeDescription.FLAG_AB_SEARCH, null, null, null, null, Theme.key_actionBarDefaultSearch));
|
|
|
|
arrayList.add(new ThemeDescription(actionBar, ThemeDescription.FLAG_AB_SEARCHPLACEHOLDER, null, null, null, null, Theme.key_actionBarDefaultSearchPlaceholder));
|
2019-12-31 14:08:08 +01:00
|
|
|
arrayList.add(new ThemeDescription(inputFieldsContainer, ThemeDescription.FLAG_BACKGROUND, null, null, null, null, Theme.key_windowBackgroundWhite));
|
2017-07-08 18:32:04 +02:00
|
|
|
arrayList.add(new ThemeDescription(linearLayout2, 0, new Class[]{View.class}, Theme.dividerPaint, null, null, Theme.key_divider));
|
|
|
|
|
2019-12-31 14:08:08 +01:00
|
|
|
arrayList.add(new ThemeDescription(shareCell, ThemeDescription.FLAG_SELECTORWHITE, null, null, null, null, Theme.key_windowBackgroundWhite));
|
|
|
|
arrayList.add(new ThemeDescription(shareCell, ThemeDescription.FLAG_SELECTORWHITE, null, null, null, null, Theme.key_listSelector));
|
|
|
|
arrayList.add(new ThemeDescription(null, 0, null, null, null, null, delegate, Theme.key_windowBackgroundWhiteBlueText4));
|
|
|
|
arrayList.add(new ThemeDescription(null, 0, null, null, null, null, delegate, Theme.key_windowBackgroundWhiteGrayText2));
|
|
|
|
|
|
|
|
arrayList.add(new ThemeDescription(pasteCell, ThemeDescription.FLAG_SELECTORWHITE, null, null, null, null, Theme.key_windowBackgroundWhite));
|
|
|
|
arrayList.add(new ThemeDescription(pasteCell, ThemeDescription.FLAG_SELECTORWHITE, null, null, null, null, Theme.key_listSelector));
|
|
|
|
arrayList.add(new ThemeDescription(pasteCell, 0, new Class[]{TextSettingsCell.class}, new String[]{"textView"}, null, null, null, Theme.key_windowBackgroundWhiteBlueText4));
|
2018-07-30 04:07:02 +02:00
|
|
|
|
|
|
|
for (int a = 0; a < typeCell.length; a++) {
|
2019-12-31 14:08:08 +01:00
|
|
|
arrayList.add(new ThemeDescription(typeCell[a], ThemeDescription.FLAG_SELECTORWHITE, null, null, null, null, Theme.key_windowBackgroundWhite));
|
|
|
|
arrayList.add(new ThemeDescription(typeCell[a], ThemeDescription.FLAG_SELECTORWHITE, null, null, null, null, Theme.key_listSelector));
|
|
|
|
arrayList.add(new ThemeDescription(typeCell[a], 0, new Class[]{RadioCell.class}, new String[]{"textView"}, null, null, null, Theme.key_windowBackgroundWhiteBlackText));
|
|
|
|
arrayList.add(new ThemeDescription(typeCell[a], ThemeDescription.FLAG_CHECKBOX, new Class[]{RadioCell.class}, new String[]{"radioButton"}, null, null, null, Theme.key_radioBackground));
|
|
|
|
arrayList.add(new ThemeDescription(typeCell[a], ThemeDescription.FLAG_CHECKBOXCHECK, new Class[]{RadioCell.class}, new String[]{"radioButton"}, null, null, null, Theme.key_radioBackgroundChecked));
|
2018-07-30 04:07:02 +02:00
|
|
|
}
|
|
|
|
|
2017-07-08 18:32:04 +02:00
|
|
|
if (inputFields != null) {
|
|
|
|
for (int a = 0; a < inputFields.length; a++) {
|
|
|
|
arrayList.add(new ThemeDescription(inputFields[a], ThemeDescription.FLAG_TEXTCOLOR, null, null, null, null, Theme.key_windowBackgroundWhiteBlackText));
|
|
|
|
arrayList.add(new ThemeDescription(inputFields[a], ThemeDescription.FLAG_HINTTEXTCOLOR, null, null, null, null, Theme.key_windowBackgroundWhiteHintText));
|
2019-12-31 14:08:08 +01:00
|
|
|
arrayList.add(new ThemeDescription(inputFields[a], ThemeDescription.FLAG_HINTTEXTCOLOR | ThemeDescription.FLAG_PROGRESSBAR, null, null, null, null, Theme.key_windowBackgroundWhiteBlueHeader));
|
|
|
|
arrayList.add(new ThemeDescription(inputFields[a], ThemeDescription.FLAG_CURSORCOLOR, null, null, null, null, Theme.key_windowBackgroundWhiteBlackText));
|
|
|
|
arrayList.add(new ThemeDescription(null, 0, null, null, null, delegate, Theme.key_windowBackgroundWhiteInputField));
|
|
|
|
arrayList.add(new ThemeDescription(null, 0, null, null, null, delegate, Theme.key_windowBackgroundWhiteInputFieldActivated));
|
|
|
|
arrayList.add(new ThemeDescription(null, 0, null, null, null, delegate, Theme.key_windowBackgroundWhiteRedText3));
|
2017-07-08 18:32:04 +02:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
arrayList.add(new ThemeDescription(null, ThemeDescription.FLAG_TEXTCOLOR, null, null, null, null, Theme.key_windowBackgroundWhiteBlackText));
|
|
|
|
arrayList.add(new ThemeDescription(null, ThemeDescription.FLAG_HINTTEXTCOLOR, null, null, null, null, Theme.key_windowBackgroundWhiteHintText));
|
|
|
|
}
|
|
|
|
arrayList.add(new ThemeDescription(headerCell, ThemeDescription.FLAG_BACKGROUND, null, null, null, null, Theme.key_windowBackgroundWhite));
|
|
|
|
arrayList.add(new ThemeDescription(headerCell, 0, new Class[]{HeaderCell.class}, new String[]{"textView"}, null, null, null, Theme.key_windowBackgroundWhiteBlueHeader));
|
2019-12-31 14:08:08 +01:00
|
|
|
for (int a = 0; a < sectionCell.length; a++) {
|
|
|
|
if (sectionCell[a] != null) {
|
|
|
|
arrayList.add(new ThemeDescription(sectionCell[a], ThemeDescription.FLAG_BACKGROUNDFILTER, new Class[]{ShadowSectionCell.class}, null, null, null, Theme.key_windowBackgroundGrayShadow));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (int i = 0; i < bottomCells.length; i++) {
|
|
|
|
arrayList.add(new ThemeDescription(bottomCells[i], ThemeDescription.FLAG_BACKGROUNDFILTER, new Class[]{TextInfoPrivacyCell.class}, null, null, null, Theme.key_windowBackgroundGrayShadow));
|
|
|
|
arrayList.add(new ThemeDescription(bottomCells[i], 0, new Class[]{TextInfoPrivacyCell.class}, new String[]{"textView"}, null, null, null, Theme.key_windowBackgroundWhiteGrayText4));
|
|
|
|
arrayList.add(new ThemeDescription(bottomCells[i], ThemeDescription.FLAG_LINKCOLOR, new Class[]{TextInfoPrivacyCell.class}, new String[]{"textView"}, null, null, null, Theme.key_windowBackgroundWhiteLinkText));
|
2018-07-30 04:07:02 +02:00
|
|
|
}
|
2017-07-08 18:32:04 +02:00
|
|
|
|
2020-04-24 11:21:58 +02:00
|
|
|
return arrayList;
|
2017-07-08 18:32:04 +02:00
|
|
|
}
|
|
|
|
}
|