2017-07-08 18:32:04 +02:00
|
|
|
/*
|
|
|
|
* This is the source code of Telegram for Android v. 3.x.x.
|
|
|
|
* It is licensed under GNU GPL v. 2 or later.
|
|
|
|
* You should have received a copy of the license in this archive (see LICENSE).
|
|
|
|
*
|
|
|
|
* Copyright Nikolai Kudashov, 2013-2017.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package org.telegram.ui;
|
|
|
|
|
|
|
|
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;
|
|
|
|
import android.text.Editable;
|
|
|
|
import android.text.InputType;
|
|
|
|
import android.text.TextUtils;
|
|
|
|
import android.text.TextWatcher;
|
|
|
|
import android.text.method.PasswordTransformationMethod;
|
|
|
|
import android.util.TypedValue;
|
|
|
|
import android.view.Gravity;
|
|
|
|
import android.view.KeyEvent;
|
|
|
|
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;
|
|
|
|
|
|
|
|
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;
|
|
|
|
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;
|
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;
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
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;
|
|
|
|
private HeaderCell headerCell;
|
2018-07-30 04:07:02 +02:00
|
|
|
private ShadowSectionCell[] sectionCell = new ShadowSectionCell[2];
|
2017-07-08 18:32:04 +02:00
|
|
|
private TextInfoPrivacyCell bottomCell;
|
2018-07-30 04:07:02 +02:00
|
|
|
private TextSettingsCell shareCell;
|
|
|
|
private ActionBarMenuItem doneItem;
|
|
|
|
private TypeCell[] typeCell = new TypeCell[2];
|
|
|
|
private int currentType;
|
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
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
public class TypeCell extends FrameLayout {
|
|
|
|
|
|
|
|
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);
|
|
|
|
addView(textView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, LocaleController.isRTL ? 23 + 48 : 17, 0, LocaleController.isRTL ? 17 : 23, 0));
|
|
|
|
|
|
|
|
checkImage = new ImageView(context);
|
|
|
|
checkImage.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_featuredStickers_addedIcon), PorterDuff.Mode.MULTIPLY));
|
|
|
|
checkImage.setImageResource(R.drawable.sticker_added);
|
|
|
|
addView(checkImage, LayoutHelper.createFrame(19, 14, (LocaleController.isRTL ? Gravity.LEFT : Gravity.RIGHT) | Gravity.CENTER_VERTICAL, 18, 0, 18, 0));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
|
|
|
super.onMeasure(MeasureSpec.makeMeasureSpec(MeasureSpec.getSize(widthMeasureSpec), MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(48) + (needDivider ? 1 : 0), MeasureSpec.EXACTLY));
|
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
|
|
|
canvas.drawLine(getPaddingLeft(), getHeight() - 1, getWidth() - getPaddingRight(), getHeight() - 1, Theme.dividerPaint);
|
|
|
|
}
|
|
|
|
}
|
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;
|
|
|
|
currentType = TextUtils.isEmpty(proxyInfo.secret) ? 0 : 1;
|
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);
|
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));
|
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));
|
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
for (int a = 0; a < 2; a++) {
|
|
|
|
typeCell[a] = new TypeCell(context);
|
|
|
|
typeCell[a].setBackgroundDrawable(Theme.getSelectorDrawable(true));
|
|
|
|
typeCell[a].setTag(a);
|
|
|
|
if (a == 0) {
|
|
|
|
typeCell[a].setValue(LocaleController.getString("UseProxySocks5", R.string.UseProxySocks5), a == currentType, true);
|
|
|
|
} else if (a == 1) {
|
|
|
|
typeCell[a].setValue(LocaleController.getString("UseProxyTelegram", R.string.UseProxyTelegram), a == currentType, false);
|
2017-07-08 18:32:04 +02:00
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
linearLayout2.addView(typeCell[a], LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 48));
|
|
|
|
typeCell[a].setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View view) {
|
|
|
|
currentType = (Integer) view.getTag();
|
|
|
|
updateUiForType();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
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
|
|
|
|
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);
|
2018-07-30 04:07:02 +02:00
|
|
|
linearLayout2.addView(container, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 64));
|
2017-07-08 18:32:04 +02:00
|
|
|
container.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
|
|
|
|
|
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));
|
|
|
|
inputFields[a].setBackgroundDrawable(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) {
|
|
|
|
checkShareButton();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} 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) {
|
|
|
|
phoneField.setSelection(start <= phoneField.length() ? start : phoneField.length());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ignoreOnTextChange = false;
|
|
|
|
checkShareButton();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} 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);
|
|
|
|
container.addView(inputFields[a], LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.LEFT | Gravity.TOP, 17, 0, 17, 0));
|
2017-07-08 18:32:04 +02:00
|
|
|
|
|
|
|
inputFields[a].setOnEditorActionListener(new TextView.OnEditorActionListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
|
|
|
|
if (i == EditorInfo.IME_ACTION_NEXT) {
|
|
|
|
int num = (Integer) textView.getTag();
|
|
|
|
if (num + 1 < inputFields.length) {
|
|
|
|
num++;
|
|
|
|
inputFields[num].requestFocus();
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
} else if (i == EditorInfo.IME_ACTION_DONE) {
|
|
|
|
finishFragment();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
bottomCell = new TextInfoPrivacyCell(context);
|
|
|
|
bottomCell.setBackgroundDrawable(Theme.getThemedDrawable(context, R.drawable.greydivider_bottom, Theme.key_windowBackgroundGrayShadow));
|
|
|
|
bottomCell.setText(LocaleController.getString("UseProxyInfo", R.string.UseProxyInfo));
|
|
|
|
linearLayout2.addView(bottomCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
|
|
|
|
|
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));
|
|
|
|
shareCell.setOnClickListener(new View.OnClickListener() {
|
2017-07-08 18:32:04 +02:00
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
2018-07-30 04:07:02 +02:00
|
|
|
StringBuilder params = new StringBuilder("");
|
|
|
|
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("&");
|
|
|
|
}
|
|
|
|
params.append("secret=").append(URLEncoder.encode(secret, "UTF-8"));
|
|
|
|
} else {
|
|
|
|
url = "https://t.me/socks?";
|
|
|
|
if (!TextUtils.isEmpty(user)) {
|
|
|
|
if (params.length() != 0) {
|
|
|
|
params.append("&");
|
|
|
|
}
|
|
|
|
params.append("user=").append(URLEncoder.encode(user, "UTF-8"));
|
|
|
|
}
|
|
|
|
if (!TextUtils.isEmpty(password)) {
|
|
|
|
if (params.length() != 0) {
|
|
|
|
params.append("&");
|
|
|
|
}
|
|
|
|
params.append("pass=").append(URLEncoder.encode(password, "UTF-8"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (Exception ignore) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (params.length() == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
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
|
|
|
|
|
|
|
checkShareButton();
|
2018-07-30 04:07:02 +02:00
|
|
|
updateUiForType();
|
2017-07-08 18:32:04 +02:00
|
|
|
|
|
|
|
return fragmentView;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void checkShareButton() {
|
2018-07-30 04:07:02 +02:00
|
|
|
if (shareCell == null || doneItem == null || inputFields[FIELD_IP] == null || inputFields[FIELD_PORT] == null) {
|
2017-07-08 18:32:04 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (inputFields[FIELD_IP].length() != 0 && Utilities.parseInt(inputFields[FIELD_PORT].getText().toString()) != 0) {
|
2018-07-30 04:07:02 +02:00
|
|
|
shareCell.getTextView().setAlpha(1.0f);
|
|
|
|
doneItem.setAlpha(1.0f);
|
|
|
|
shareCell.setEnabled(true);
|
|
|
|
doneItem.setEnabled(true);
|
2017-07-08 18:32:04 +02:00
|
|
|
} else {
|
2018-07-30 04:07:02 +02:00
|
|
|
shareCell.getTextView().setAlpha(0.5f);
|
|
|
|
doneItem.setAlpha(0.5f);
|
|
|
|
shareCell.setEnabled(false);
|
|
|
|
doneItem.setEnabled(false);
|
2017-07-08 18:32:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
private void updateUiForType() {
|
|
|
|
if (currentType == 0) {
|
|
|
|
bottomCell.setText(LocaleController.getString("UseProxyInfo", R.string.UseProxyInfo));
|
|
|
|
((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) {
|
|
|
|
bottomCell.setText(LocaleController.getString("UseProxyTelegramInfo", R.string.UseProxyTelegramInfo) + "\n\n" + LocaleController.getString("UseProxyTelegramInfo2", R.string.UseProxyTelegramInfo2));
|
|
|
|
((View) inputFields[FIELD_SECRET].getParent()).setVisibility(View.VISIBLE);
|
|
|
|
((View) inputFields[FIELD_PASSWORD].getParent()).setVisibility(View.GONE);
|
|
|
|
((View) inputFields[FIELD_USER].getParent()).setVisibility(View.GONE);
|
2017-07-08 18:32:04 +02:00
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
typeCell[0].setTypeChecked(currentType == 0);
|
|
|
|
typeCell[1].setTypeChecked(currentType == 1);
|
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
|
|
|
|
public ThemeDescription[] getThemeDescriptions() {
|
|
|
|
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));
|
|
|
|
arrayList.add(new ThemeDescription(linearLayout2, 0, new Class[]{View.class}, Theme.dividerPaint, null, null, Theme.key_divider));
|
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
arrayList.add(new ThemeDescription(shareCell, ThemeDescription.FLAG_BACKGROUND, null, null, null, null, Theme.key_windowBackgroundWhite));
|
|
|
|
arrayList.add(new ThemeDescription(shareCell, 0, new Class[]{TextSettingsCell.class}, new String[]{"textView"}, null, null, null, Theme.key_windowBackgroundWhiteBlueText4));
|
|
|
|
arrayList.add(new ThemeDescription(shareCell, 0, new Class[]{TextSettingsCell.class}, new String[]{"valueTextView"}, null, null, null, Theme.key_windowBackgroundWhiteValueText));
|
|
|
|
|
|
|
|
for (int a = 0; a < typeCell.length; a++) {
|
|
|
|
arrayList.add(new ThemeDescription(typeCell[a], ThemeDescription.FLAG_BACKGROUND, null, null, null, null, Theme.key_windowBackgroundWhite));
|
|
|
|
arrayList.add(new ThemeDescription(typeCell[a], 0, new Class[]{TypeCell.class}, new String[]{"textView"}, null, null, null, Theme.key_windowBackgroundWhiteBlackText));
|
|
|
|
arrayList.add(new ThemeDescription(typeCell[a], ThemeDescription.FLAG_IMAGECOLOR, new Class[]{TypeCell.class}, new String[]{"checkImage"}, null, null, null, Theme.key_featuredStickers_addedIcon));
|
|
|
|
}
|
|
|
|
|
2017-07-08 18:32:04 +02:00
|
|
|
if (inputFields != null) {
|
|
|
|
for (int a = 0; a < inputFields.length; a++) {
|
|
|
|
arrayList.add(new ThemeDescription((View) inputFields[a].getParent(), ThemeDescription.FLAG_BACKGROUND, null, null, null, null, Theme.key_windowBackgroundWhite));
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
} 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));
|
2018-07-30 04:07:02 +02:00
|
|
|
for (int a = 0; a < 2; a++) {
|
|
|
|
arrayList.add(new ThemeDescription(sectionCell[a], ThemeDescription.FLAG_BACKGROUNDFILTER, new Class[]{ShadowSectionCell.class}, null, null, null, Theme.key_windowBackgroundGrayShadow));
|
|
|
|
}
|
2017-07-08 18:32:04 +02:00
|
|
|
arrayList.add(new ThemeDescription(bottomCell, ThemeDescription.FLAG_BACKGROUNDFILTER, new Class[]{TextInfoPrivacyCell.class}, null, null, null, Theme.key_windowBackgroundGrayShadow));
|
|
|
|
arrayList.add(new ThemeDescription(bottomCell, 0, new Class[]{TextInfoPrivacyCell.class}, new String[]{"textView"}, null, null, null, Theme.key_windowBackgroundWhiteGrayText4));
|
|
|
|
arrayList.add(new ThemeDescription(bottomCell, ThemeDescription.FLAG_LINKCOLOR, new Class[]{TextInfoPrivacyCell.class}, new String[]{"textView"}, null, null, null, Theme.key_windowBackgroundWhiteLinkText));
|
|
|
|
|
|
|
|
return arrayList.toArray(new ThemeDescription[arrayList.size()]);
|
|
|
|
}
|
|
|
|
}
|