NekoX/TMessagesProj/src/main/java/org/telegram/ui/LoginActivity.java

4864 lines
250 KiB
Java
Raw Normal View History

2013-10-25 17:19:00 +02:00
/*
2019-01-23 18:03:33 +01:00
* This is the source code of Telegram for Android v. 5.x.x.
2013-10-25 17:19:00 +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.
2013-10-25 17:19:00 +02:00
*/
package org.telegram.ui;
2016-03-16 13:26:32 +01:00
import android.Manifest;
2013-12-20 20:25:49 +01:00
import android.animation.Animator;
2019-01-23 18:03:33 +01:00
import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
2019-12-31 14:08:08 +01:00
import android.animation.StateListAnimator;
2015-05-21 23:27:27 +02:00
import android.annotation.SuppressLint;
2019-01-23 18:03:33 +01:00
import android.app.Activity;
2015-05-21 23:27:27 +02:00
import android.app.Dialog;
import android.content.Context;
2014-11-14 16:40:15 +01:00
import android.content.Intent;
import android.content.SharedPreferences;
2014-11-14 16:40:15 +01:00
import android.content.pm.PackageInfo;
2016-03-16 13:26:32 +01:00
import android.content.pm.PackageManager;
import android.graphics.Canvas;
2019-12-31 14:08:08 +01:00
import android.graphics.Outline;
2016-03-16 13:26:32 +01:00
import android.graphics.Paint;
2019-12-31 14:08:08 +01:00
import android.graphics.Path;
2019-01-23 18:03:33 +01:00
import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
import android.graphics.Rect;
2019-12-31 14:08:08 +01:00
import android.graphics.RectF;
2015-04-09 20:00:14 +02:00
import android.graphics.Typeface;
2019-01-23 18:03:33 +01:00
import android.graphics.drawable.Drawable;
2014-11-14 16:40:15 +01:00
import android.os.Build;
2013-10-25 17:19:00 +02:00
import android.os.Bundle;
2015-04-09 20:00:14 +02:00
import android.os.Vibrator;
2019-05-14 14:08:05 +02:00
import android.telephony.PhoneNumberUtils;
2014-11-14 16:40:15 +01:00
import android.telephony.TelephonyManager;
import android.text.Editable;
import android.text.InputFilter;
import android.text.InputType;
2018-07-30 04:07:02 +02:00
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.TextPaint;
2014-11-14 16:40:15 +01:00
import android.text.TextUtils;
import android.text.TextWatcher;
2015-04-09 20:00:14 +02:00
import android.text.method.PasswordTransformationMethod;
2018-07-30 04:07:02 +02:00
import android.text.style.ClickableSpan;
2014-11-14 16:40:15 +01:00
import android.util.TypedValue;
import android.view.Gravity;
2019-01-23 18:03:33 +01:00
import android.view.KeyEvent;
import android.view.MotionEvent;
2013-10-25 17:19:00 +02:00
import android.view.View;
2019-06-20 17:14:56 +02:00
import android.view.ViewGroup;
2019-12-31 14:08:08 +01:00
import android.view.ViewOutlineProvider;
2013-12-20 20:25:49 +01:00
import android.view.animation.AccelerateDecelerateInterpolator;
2019-12-31 14:08:08 +01:00
import android.view.animation.Interpolator;
2014-11-14 16:40:15 +01:00
import android.view.inputmethod.EditorInfo;
import android.widget.AdapterView;
2020-06-25 17:29:04 +02:00
import android.widget.EditText;
import android.widget.FrameLayout;
2016-03-16 13:26:32 +01:00
import android.widget.ImageView;
2014-11-14 16:40:15 +01:00
import android.widget.LinearLayout;
import android.widget.ScrollView;
2013-10-25 17:19:00 +02:00
import android.widget.TextView;
2018-07-30 04:07:02 +02:00
import android.widget.Toast;
2013-10-25 17:19:00 +02:00
2020-06-26 06:54:48 +02:00
import androidx.core.os.ConfigurationCompat;
2020-06-25 17:29:04 +02:00
import com.v2ray.ang.util.Utils;
2014-11-14 16:40:15 +01:00
import org.telegram.PhoneFormat.PhoneFormat;
2020-06-25 17:29:04 +02:00
import org.telegram.messenger.AccountInstance;
2015-09-24 22:52:02 +02:00
import org.telegram.messenger.AndroidUtilities;
2020-06-25 17:29:04 +02:00
import org.telegram.messenger.ApplicationLoader;
import org.telegram.messenger.BuildVars;
2015-09-24 22:52:02 +02:00
import org.telegram.messenger.ContactsController;
2020-06-25 17:29:04 +02:00
import org.telegram.messenger.FileLog;
2019-05-14 14:08:05 +02:00
import org.telegram.messenger.ImageLocation;
2020-06-25 17:29:04 +02:00
import org.telegram.messenger.LocaleController;
2018-07-30 04:07:02 +02:00
import org.telegram.messenger.MessageObject;
2015-09-24 22:52:02 +02:00
import org.telegram.messenger.MessagesController;
import org.telegram.messenger.MessagesStorage;
import org.telegram.messenger.NotificationCenter;
2013-10-25 17:19:00 +02:00
import org.telegram.messenger.R;
2018-08-27 10:33:11 +02:00
import org.telegram.messenger.SRPHelper;
2020-06-25 17:29:04 +02:00
import org.telegram.messenger.UserConfig;
import org.telegram.messenger.Utilities;
2015-09-24 22:52:02 +02:00
import org.telegram.tgnet.ConnectionsManager;
import org.telegram.tgnet.RequestDelegate;
2018-07-30 04:07:02 +02:00
import org.telegram.tgnet.SerializedData;
2015-09-24 22:52:02 +02:00
import org.telegram.tgnet.TLRPC;
2014-11-13 21:10:14 +01:00
import org.telegram.ui.ActionBar.ActionBar;
import org.telegram.ui.ActionBar.ActionBarMenu;
2019-01-23 18:03:33 +01:00
import org.telegram.ui.ActionBar.ActionBarMenuItem;
2017-03-31 01:58:05 +02:00
import org.telegram.ui.ActionBar.AlertDialog;
2014-11-13 21:10:14 +01:00
import org.telegram.ui.ActionBar.BaseFragment;
2017-03-31 01:58:05 +02:00
import org.telegram.ui.ActionBar.Theme;
import org.telegram.ui.ActionBar.ThemeDescription;
2018-07-30 04:07:02 +02:00
import org.telegram.ui.Cells.CheckBoxCell;
2018-08-27 10:33:11 +02:00
import org.telegram.ui.Components.AlertsCreator;
2019-01-23 18:03:33 +01:00
import org.telegram.ui.Components.AvatarDrawable;
import org.telegram.ui.Components.BackupImageView;
2019-12-31 14:08:08 +01:00
import org.telegram.ui.Components.CombinedDrawable;
2019-01-23 18:03:33 +01:00
import org.telegram.ui.Components.ContextProgressView;
2017-12-08 18:35:59 +01:00
import org.telegram.ui.Components.EditTextBoldCursor;
2015-11-26 22:04:02 +01:00
import org.telegram.ui.Components.HintEditText;
2019-01-23 18:03:33 +01:00
import org.telegram.ui.Components.ImageUpdater;
import org.telegram.ui.Components.LayoutHelper;
2020-06-25 17:29:04 +02:00
import org.telegram.ui.Components.ProxyDrawable;
2019-01-23 18:03:33 +01:00
import org.telegram.ui.Components.RadialProgressView;
import org.telegram.ui.Components.SlideView;
2013-12-20 20:25:49 +01:00
2014-11-14 16:40:15 +01:00
import java.io.BufferedReader;
import java.io.InputStreamReader;
2020-06-25 17:29:04 +02:00
import java.math.BigInteger;
2014-11-14 16:40:15 +01:00
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
2014-11-14 16:40:15 +01:00
import java.util.Timer;
import java.util.TimerTask;
2020-06-25 17:29:04 +02:00
import java.util.concurrent.atomic.AtomicInteger;
import cn.hutool.core.codec.Base64;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.StrUtil;
import kotlin.Unit;
import tw.nekomimi.nekogram.BottomBuilder;
import tw.nekomimi.nekogram.DataCenter;
import tw.nekomimi.nekogram.EditTextAutoFill;
2020-06-25 17:29:04 +02:00
import tw.nekomimi.nekogram.NekoXConfig;
import tw.nekomimi.nekogram.parts.PKCS1Pub;
import tw.nekomimi.nekogram.utils.AlertUtil;
2020-02-21 05:08:57 +01:00
2017-03-31 01:58:05 +02:00
@SuppressLint("HardwareIds")
2020-06-25 17:29:04 +02:00
public class LoginActivity extends BaseFragment implements NotificationCenter.NotificationCenterDelegate {
2017-03-31 01:58:05 +02:00
private int currentViewNum;
2016-10-11 13:57:01 +02:00
private SlideView[] views = new SlideView[9];
2019-12-31 14:08:08 +01:00
private boolean restoringState;
2016-03-16 13:26:32 +01:00
private Dialog permissionsDialog;
2017-03-31 01:58:05 +02:00
private Dialog permissionsShowDialog;
2016-03-16 13:26:32 +01:00
private ArrayList<String> permissionsItems = new ArrayList<>();
2017-03-31 01:58:05 +02:00
private ArrayList<String> permissionsShowItems = new ArrayList<>();
2016-03-16 13:26:32 +01:00
private boolean checkPermissions = true;
2017-03-31 01:58:05 +02:00
private boolean checkShowPermissions = true;
2018-07-30 04:07:02 +02:00
private boolean newAccount;
2020-06-25 17:29:04 +02:00
private boolean syncContacts;
2013-10-25 17:19:00 +02:00
2019-01-23 18:03:33 +01:00
private int scrollHeight;
2019-12-31 14:08:08 +01:00
private int currentDoneType;
private AnimatorSet[] showDoneAnimation = new AnimatorSet[2];
2019-01-23 18:03:33 +01:00
private ActionBarMenuItem doneItem;
private AnimatorSet doneItemAnimation;
private ContextProgressView doneProgressView;
2019-12-31 14:08:08 +01:00
private AnimatorSet pagesAnimation;
private ImageView floatingButtonIcon;
private FrameLayout floatingButtonContainer;
private RadialProgressView floatingProgressView;
2019-01-23 18:03:33 +01:00
private int progressRequestId;
2020-06-25 17:29:04 +02:00
private boolean[] doneButtonVisible = new boolean[]{true, false};
2019-12-31 14:08:08 +01:00
private static final int DONE_TYPE_FLOATING = 0;
private static final int DONE_TYPE_ACTION = 1;
2019-01-23 18:03:33 +01:00
private final static int done_button = 1;
2020-06-25 17:29:04 +02:00
private ActionBarMenuItem proxyItem;
private ProxyDrawable proxyDrawable;
2020-04-24 11:21:58 +02:00
private static class ProgressView extends View {
2017-03-31 01:58:05 +02:00
2019-12-31 14:08:08 +01:00
private final Path path = new Path();
private final RectF rect = new RectF();
private final RectF boundsRect = new RectF();
private final Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
private final Paint paint2 = new Paint(Paint.ANTI_ALIAS_FLAG);
private long startTime;
private long duration;
private boolean animating;
private float radius;
2017-03-31 01:58:05 +02:00
public ProgressView(Context context) {
super(context);
paint.setColor(Theme.getColor(Theme.key_login_progressInner));
paint2.setColor(Theme.getColor(Theme.key_login_progressOuter));
}
2019-12-31 14:08:08 +01:00
public void startProgressAnimation(long duration) {
this.animating = true;
this.duration = duration;
this.startTime = System.currentTimeMillis();
2017-03-31 01:58:05 +02:00
invalidate();
}
2019-12-31 14:08:08 +01:00
public void resetProgressAnimation() {
duration = 0;
startTime = 0;
animating = false;
invalidate();
}
public boolean isProgressAnimationRunning() {
return animating;
}
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
path.rewind();
radius = h / 2f;
boundsRect.set(0, 0, w, h);
rect.set(boundsRect);
path.addRoundRect(boundsRect, radius, radius, Path.Direction.CW);
}
2017-03-31 01:58:05 +02:00
@Override
protected void onDraw(Canvas canvas) {
2019-12-31 14:08:08 +01:00
final float progress;
if (duration > 0) {
progress = Math.min(1f, (System.currentTimeMillis() - startTime) / (float) duration);
} else {
progress = 0f;
}
canvas.clipPath(path);
canvas.drawRoundRect(boundsRect, radius, radius, paint);
rect.right = boundsRect.right * progress;
canvas.drawRoundRect(rect, radius, radius, paint2);
if (animating &= duration > 0 && progress < 1f) {
postInvalidateOnAnimation();
}
2017-03-31 01:58:05 +02:00
}
}
2018-07-30 04:07:02 +02:00
public LoginActivity() {
super();
}
public LoginActivity(int account) {
super();
currentAccount = account;
newAccount = true;
}
2013-10-25 17:19:00 +02:00
@Override
public void onFragmentDestroy() {
super.onFragmentDestroy();
2016-03-16 13:26:32 +01:00
for (int a = 0; a < views.length; a++) {
if (views[a] != null) {
views[a].onDestroyActivity();
}
}
2013-10-25 17:19:00 +02:00
}
2020-06-25 17:29:04 +02:00
@Override
public boolean onFragmentCreate() {
currentConnectionState = getConnectionsManager().getConnectionState();
getNotificationCenter().addObserver(this, NotificationCenter.didUpdateConnectionState);
return true;
}
private int menu_other = 5;
private int menu_custom_api = 6;
private int menu_custom_dc = 7;
2013-10-25 17:19:00 +02:00
@Override
2015-07-22 20:56:37 +02:00
public View createView(Context context) {
2020-01-08 18:08:16 +01:00
actionBar.setTitle(LocaleController.getString("NekogramWithEmoji", R.string.NekogramWithEmoji));
2015-04-09 20:00:14 +02:00
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@Override
public void onItemClick(int id) {
if (id == done_button) {
2019-12-31 14:08:08 +01:00
onDoneButtonPressed();
2015-04-09 20:00:14 +02:00
} else if (id == -1) {
2019-02-08 03:30:32 +01:00
if (onBackPressed()) {
finishFragment();
}
2019-06-20 17:14:56 +02:00
} else if (id == 2) {
2020-06-25 17:29:04 +02:00
presentFragment(new ProxyListActivity());
} else if (id == 3) {
presentFragment(new LanguageSelectActivity());
} else if (id == 4) {
2019-06-20 17:14:56 +02:00
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle(LocaleController.getString("BotLogin", R.string.BotLogin));
final EditTextBoldCursor editText = new EditTextBoldCursor(context) {
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(64), MeasureSpec.EXACTLY));
}
};
editText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
editText.setTextColor(Theme.getColor(Theme.key_dialogTextBlack));
2020-02-16 07:25:29 +01:00
editText.setHintText(LocaleController.getString("BotToken", R.string.BotToken));
2019-06-20 17:14:56 +02:00
editText.setHeaderHintColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlueHeader));
editText.setSingleLine(true);
editText.setFocusable(true);
editText.setTransformHintToHeader(true);
editText.setLineColors(Theme.getColor(Theme.key_windowBackgroundWhiteInputField), Theme.getColor(Theme.key_windowBackgroundWhiteInputFieldActivated), Theme.getColor(Theme.key_windowBackgroundWhiteRedText3));
editText.setImeOptions(EditorInfo.IME_ACTION_DONE);
editText.setBackgroundDrawable(null);
editText.requestFocus();
editText.setPadding(0, 0, 0, 0);
builder.setView(editText);
2020-02-16 07:25:29 +01:00
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), (dialogInterface, i) -> {
if (getParentActivity() == null) {
return;
}
String token = editText.getText().toString();
2019-06-20 17:14:56 +02:00
2020-02-16 07:25:29 +01:00
if (token.length() == 0) {
2020-06-25 17:29:04 +02:00
needShowAlert(LocaleController.getString("NekoX", R.string.NekoX), LocaleController.getString("InvalidAccessToken", R.string.InvalidAccessToken));
2020-02-16 07:25:29 +01:00
return;
}
2019-06-20 17:14:56 +02:00
2020-02-16 07:25:29 +01:00
ConnectionsManager.getInstance(currentAccount).cleanup(false);
2020-06-25 17:29:04 +02:00
final TLRPC.TL_auth_importBotAuthorization req = new TLRPC.TL_auth_importBotAuthorization();
2020-02-16 07:25:29 +01:00
2020-06-25 17:29:04 +02:00
req.api_hash = NekoXConfig.currentAppHash();
req.api_id = NekoXConfig.currentAppId();
2020-02-16 07:25:29 +01:00
req.bot_auth_token = token;
req.flags = 0;
int reqId = ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
if (error == null) {
TLRPC.TL_auth_authorization res = (TLRPC.TL_auth_authorization) response;
ConnectionsManager.getInstance(currentAccount).setUserId(res.user.id);
UserConfig.getInstance(currentAccount).clearConfig();
MessagesController.getInstance(currentAccount).cleanup();
UserConfig.getInstance(currentAccount).isBot = true;
UserConfig.getInstance(currentAccount).syncContacts = syncContacts;
UserConfig.getInstance(currentAccount).setCurrentUser(res.user);
UserConfig.getInstance(currentAccount).saveConfig(true);
MessagesStorage.getInstance(currentAccount).cleanup(true);
ArrayList<TLRPC.User> users = new ArrayList<>();
users.add(res.user);
MessagesStorage.getInstance(currentAccount).putUsersAndChats(users, null, true, true);
MessagesController.getInstance(currentAccount).putUser(res.user, false);
ContactsController.getInstance(currentAccount).checkAppAccount();
MessagesController.getInstance(currentAccount).getBlockedUsers(true);
MessagesController.getInstance(currentAccount).checkPromoInfo(true);
2020-02-16 07:25:29 +01:00
ConnectionsManager.getInstance(currentAccount).updateDcSettings();
needFinishActivity(false);
} else {
2020-06-25 17:29:04 +02:00
if (error.code == 401) {
ConnectionsManager.native_cleanUp(currentAccount,true);
}
2020-02-16 07:25:29 +01:00
if (error.text != null) {
if (error.text.contains("ACCESS_TOKEN_INVALID")) {
2020-06-25 17:29:04 +02:00
needShowAlert(LocaleController.getString("NekoX", R.string.NekoX), LocaleController.getString("InvalidAccessToken", R.string.InvalidAccessToken));
2020-02-16 07:25:29 +01:00
} else if (error.text.startsWith("FLOOD_WAIT")) {
2020-06-25 17:29:04 +02:00
needShowAlert(LocaleController.getString("NekoX", R.string.NekoX), LocaleController.getString("FloodWait", R.string.FloodWait));
2020-02-16 07:25:29 +01:00
} else if (error.code != -1000) {
2020-06-25 17:29:04 +02:00
needShowAlert(LocaleController.getString("NekoX", R.string.NekoX), error.code + ": " + error.text);
2019-06-20 17:14:56 +02:00
}
}
2020-02-16 07:25:29 +01:00
}
needHideProgress(false);
}), ConnectionsManager.RequestFlagFailOnServerErrors | ConnectionsManager.RequestFlagWithoutLogin | ConnectionsManager.RequestFlagTryDifferentDc | ConnectionsManager.RequestFlagEnableUnauthorized);
needShowProgress(reqId);
2019-06-20 17:14:56 +02:00
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
2020-02-16 07:25:29 +01:00
builder.show().setOnShowListener(dialog -> {
editText.requestFocus();
AndroidUtilities.showKeyboard(editText);
2019-06-20 17:14:56 +02:00
});
if (editText != null) {
ViewGroup.MarginLayoutParams layoutParams = (ViewGroup.MarginLayoutParams) editText.getLayoutParams();
if (layoutParams != null) {
if (layoutParams instanceof FrameLayout.LayoutParams) {
((FrameLayout.LayoutParams) layoutParams).gravity = Gravity.CENTER_HORIZONTAL;
}
layoutParams.rightMargin = layoutParams.leftMargin = AndroidUtilities.dp(24);
layoutParams.height = AndroidUtilities.dp(36);
editText.setLayoutParams(layoutParams);
}
}
2020-06-25 17:29:04 +02:00
} else if (id == menu_custom_api) {
AtomicInteger targetApi = new AtomicInteger(-1);
BottomBuilder builder = new BottomBuilder(getParentActivity());
EditText[] inputs = new EditText[2];
builder.addTitle(LocaleController.getString("CustomApi", R.string.CustomApi),
true,
LocaleController.getString("UseCustomApiNotice", R.string.UseCustomApiNotice));
builder.addRadioItem(LocaleController.getString("", R.string.CustomApiNo), NekoXConfig.customApi == 0, (cell) -> {
targetApi.set(0);
builder.doRadioCheck(cell);
for (EditText input : inputs) input.setVisibility(View.GONE);
return Unit.INSTANCE;
});
builder.addRadioItem(LocaleController.getString("CustomApiOfficial", R.string.CustomApiOfficial), NekoXConfig.customApi == 1, (cell) -> {
targetApi.set(1);
builder.doRadioCheck(cell);
for (EditText input : inputs) input.setVisibility(View.GONE);
return Unit.INSTANCE;
});
builder.addRadioItem(LocaleController.getString("CustomApiTGX", R.string.CustomApiTGX), NekoXConfig.customApi == 2, (cell) -> {
targetApi.set(2);
builder.doRadioCheck(cell);
for (EditText input : inputs) input.setVisibility(View.GONE);
return Unit.INSTANCE;
});
builder.addRadioItem(LocaleController.getString("CustomApiInput", R.string.CustomApiInput), NekoXConfig.customApi > 2, (cell) -> {
targetApi.set(3);
builder.doRadioCheck(cell);
for (EditText input : inputs) input.setVisibility(View.VISIBLE);
return Unit.INSTANCE;
});
inputs[0] = builder.addEditText("App Id");
inputs[0].setInputType(InputType.TYPE_CLASS_NUMBER);
if (NekoXConfig.customAppId != 0) {
inputs[0].setText(NekoXConfig.customAppId + "");
}
inputs[0].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) {
if (StrUtil.isBlank(s.toString())) {
NekoXConfig.customAppId = 0;
} else if (!NumberUtil.isInteger(s.toString())) {
inputs[0].setText("0");
} else {
NekoXConfig.customAppId = NumberUtil.parseInt(s.toString());
}
}
@Override
public void afterTextChanged(Editable s) {
}
});
inputs[1] = builder.addEditText("App Hash");
inputs[1].setFilters(new InputFilter[]{new InputFilter.LengthFilter(BuildVars.OFFICAL_APP_HASH.length())});
if (StrUtil.isNotBlank(NekoXConfig.customAppHash)) {
inputs[1].setText(NekoXConfig.customAppHash);
}
inputs[1].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) {
NekoXConfig.customAppHash = s.toString();
}
@Override
public void afterTextChanged(Editable s) {
}
});
if (NekoXConfig.customApi <= 2) {
for (EditText input : inputs) input.setVisibility(View.GONE);
}
builder.addCancelButton();
builder.addButton(LocaleController.getString("Set", R.string.Set), (it) -> {
int target = targetApi.get();
if (target > 2) {
if (NekoXConfig.customAppId == 0) {
inputs[0].requestFocus();
AndroidUtilities.showKeyboard(inputs[0]);
return Unit.INSTANCE;
} else if (StrUtil.isBlank(NekoXConfig.customAppHash)) {
inputs[1].requestFocus();
AndroidUtilities.showKeyboard(inputs[1]);
return Unit.INSTANCE;
}
}
NekoXConfig.customApi = target;
NekoXConfig.saveCustomApi();
builder.dismiss();
return Unit.INSTANCE;
});
builder.show();
} else if (id == menu_custom_dc) {
AtomicInteger targetDc = new AtomicInteger(-1);
BottomBuilder builder = new BottomBuilder(getParentActivity());
EditText[] inputs = new EditText[6];
builder.addTitle(LocaleController.getString("CustomBackend", R.string.CustomBackend),
true,
LocaleController.getString("CustomBackendNotice", R.string.CustomBackendNotice));
int dcType;
if (ConnectionsManager.native_isTestBackend(currentAccount) != 0) {
dcType = 1;
} else if (MessagesController.getMainSettings(currentAccount).getBoolean("custom_dc", false)) {
dcType = 2;
} else {
dcType = 0;
}
builder.addRadioItem(LocaleController.getString("CustomBackendProduction", R.string.CustomBackendProduction), dcType == 0, (cell) -> {
targetDc.set(0);
builder.doRadioCheck(cell);
for (EditText input : inputs) input.setVisibility(View.GONE);
return Unit.INSTANCE;
});
builder.addRadioItem(LocaleController.getString("CustomBackendTestDC", R.string.CustomBackendTestDC), dcType == 1, (cell) -> {
targetDc.set(1);
builder.doRadioCheck(cell);
for (EditText input : inputs) input.setVisibility(View.GONE);
return Unit.INSTANCE;
});
builder.addRadioItem(LocaleController.getString("CustomApiInput", R.string.CustomApiInput), dcType == 2, (cell) -> {
targetDc.set(2);
builder.doRadioCheck(cell);
for (EditText input : inputs) input.setVisibility(View.VISIBLE);
return Unit.INSTANCE;
});
inputs[0] = builder.addEditText(LocaleController.getString("CustomBackendIpv4", R.string.CustomBackendIpv4));
inputs[0].setFilters(new InputFilter[]{new InputFilter.LengthFilter(15)});
if (StrUtil.isNotBlank(NekoXConfig.customDcIpv4)) {
inputs[0].setText(NekoXConfig.customDcIpv4);
}
inputs[0].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) {
if (StrUtil.isBlank(s) || Utils.isIpv4Address(s.toString())) {
inputs[0].setError(null);
NekoXConfig.customDcIpv4 = s.toString();
} else {
inputs[0].setError("Invalid Ipv4 Address");
}
}
@Override
public void afterTextChanged(Editable s) {
}
});
inputs[1] = builder.addEditText(LocaleController.getString("CustomBackendIpv6", R.string.CustomBackendIpv6));
if (StrUtil.isNotBlank(NekoXConfig.customDcIpv6)) {
inputs[1].setText(NekoXConfig.customDcIpv6);
}
inputs[1].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) {
if (StrUtil.isBlank(s) || Utils.isIpv6Address(s.toString())) {
inputs[1].setError(null);
NekoXConfig.customDcIpv6 = s.toString();
} else {
inputs[1].setError("Invalid Ipv6 Address");
}
}
@Override
public void afterTextChanged(Editable s) {
}
});
inputs[2] = builder.addEditText(LocaleController.getString("UseProxyPort", R.string.UseProxyPort));
inputs[2].setInputType(InputType.TYPE_CLASS_NUMBER);
if (NekoXConfig.customDcPort != 0) {
inputs[2].setText(NekoXConfig.customDcPort + "");
}
inputs[2].setFilters(new InputFilter[]{new InputFilter.LengthFilter(5)});
inputs[2].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) {
if (StrUtil.isBlank(s.toString())) {
NekoXConfig.customDcPort = 0;
} else {
NekoXConfig.customDcPort = NumberUtil.parseInt(s.toString());
if (NekoXConfig.customDcPort <= 0 || NekoXConfig.customDcPort > 65535) {
NekoXConfig.customDcPort = 0;
inputs[2].setError("Invalid Port");
} else {
inputs[2].setError(null);
}
}
}
@Override
public void afterTextChanged(Editable s) {
}
});
inputs[3] = builder.addEditText(LocaleController.getString("CustomBackendLayer", R.string.CustomBackendLayer));
inputs[3].setInputType(InputType.TYPE_CLASS_NUMBER);
if (NekoXConfig.customDcLayer != 0) {
inputs[3].setText(NekoXConfig.customDcLayer + "");
}
inputs[3].setFilters(new InputFilter[]{new InputFilter.LengthFilter(3)});
inputs[3].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) {
if (StrUtil.isBlank(s.toString())) {
NekoXConfig.customDcLayer = 0;
} else {
NekoXConfig.customDcLayer = NumberUtil.parseInt(s.toString());
if (NekoXConfig.customDcLayer > TLRPC.LAYER || NekoXConfig.customDcLayer < 85) {
NekoXConfig.customDcLayer = 0;
inputs[3].setError("Layer not supported");
} else {
inputs[3].setError(null);
}
}
}
@Override
public void afterTextChanged(Editable s) {
}
});
inputs[4] = builder.addEditText(LocaleController.getString("CustomBackendPublicKey", R.string.CustomBackendPublicKey));
inputs[4].setInputType(InputType.TYPE_CLASS_TEXT);
inputs[4].setGravity(Gravity.TOP | LocaleController.generateFlagStart());
inputs[4].setSingleLine(false);
inputs[4].setMinLines(6);
if (StrUtil.isNotBlank(NekoXConfig.customDcPublicKey)) {
inputs[4].setText(NekoXConfig.customDcPublicKey);
}
inputs[4].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) {
if (StrUtil.isBlank(s.toString())) {
NekoXConfig.customDcPublicKey = "";
inputs[5].setText("");
} else {
try {
String publicKeyBase64 = s.toString()
.replace("-----BEGIN RSA PUBLIC KEY-----", "")
.replace("-----END RSA PUBLIC KEY-----", "");
PKCS1Pub.decodePKCS1PublicKey(Base64.decode(publicKeyBase64));
NekoXConfig.customDcPublicKey = s.toString();
inputs[4].setError(null);
} catch (Exception e) {
inputs[4].setError("Invalid PKCS1 Key");
NekoXConfig.customDcPublicKey = "";
}
}
}
@Override
public void afterTextChanged(Editable s) {
}
});
inputs[5] = builder.addEditText(LocaleController.getString("CustomBackendFingerprint", R.string.CustomBackendFingerprint));
if (NekoXConfig.customDcFingerprint != 0) {
inputs[5].setText("0x" + Long.toString(NekoXConfig.customDcFingerprint, 16));
}
inputs[5].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) {
if (StrUtil.isBlank(s.toString())) {
NekoXConfig.customDcFingerprint = 0;
inputs[5].setError(null);
} else {
String f = s.toString();
int r = 10;
if (f.startsWith("0x")) {
f = f.substring(2);
r = 16;
}
try {
NekoXConfig.customDcFingerprint = new BigInteger(f, r).longValue();
inputs[5].setError(null);
} catch (NumberFormatException e) {
NekoXConfig.customDcFingerprint = 0;
inputs[5].setError("Invalid Fingerprint");
}
}
}
@Override
public void afterTextChanged(Editable s) {
}
});
if (dcType < 2) {
for (EditText input : inputs) input.setVisibility(View.GONE);
}
builder.addCancelButton();
builder.addButton(LocaleController.getString("Set", R.string.Set), (it) -> {
int target = targetDc.get();
if (target >= 2) {
if (inputs[0].getError() != null) {
inputs[0].requestFocus();
AndroidUtilities.showKeyboard(inputs[0]);
return Unit.INSTANCE;
} else if (inputs[1].getError() != null) {
inputs[1].requestFocus();
AndroidUtilities.showKeyboard(inputs[1]);
return Unit.INSTANCE;
} else if (NekoXConfig.customDcPort == 0) {
AlertUtil.showToast("Input Port");
inputs[2].setError("Port required");
inputs[2].requestFocus();
AndroidUtilities.showKeyboard(inputs[2]);
return Unit.INSTANCE;
} else if (NekoXConfig.customDcLayer == 0) {
AlertUtil.showToast("Input Layer");
inputs[3].setError("Layer required");
inputs[3].requestFocus();
AndroidUtilities.showKeyboard(inputs[3]);
return Unit.INSTANCE;
} else if (StrUtil.isBlank(NekoXConfig.customDcPublicKey)) {
AlertUtil.showToast("Input PublicKey");
inputs[4].setError("PublicKey required");
inputs[4].requestFocus();
AndroidUtilities.showKeyboard(inputs[5]);
return Unit.INSTANCE;
} else if (NekoXConfig.customDcFingerprint == 0L) {
AlertUtil.showToast("Input Fingerprint");
inputs[5].setError("Fingerprint required");
inputs[5].requestFocus();
AndroidUtilities.showKeyboard(inputs[5]);
return Unit.INSTANCE;
} else if (StrUtil.isBlank(NekoXConfig.customDcIpv4) && StrUtil.isBlank(NekoXConfig.customDcIpv6)) {
AlertUtil.showToast("Input Address");
inputs[0].requestFocus();
AndroidUtilities.showKeyboard(inputs[0]);
return Unit.INSTANCE;
}
}
if (target == dcType) {
// do nothing
} else if (target == 0) {
DataCenter.applyOfficalDataCanter(currentAccount);
} else if (target == 1) {
DataCenter.applyTestDataCenter(currentAccount);
} else {
DataCenter.applyCustomDataCenter(currentAccount,
NekoXConfig.customDcIpv4,
NekoXConfig.customDcIpv6,
NekoXConfig.customDcPort,
NekoXConfig.customDcLayer,
NekoXConfig.customDcPublicKey,
NekoXConfig.customDcFingerprint);
NekoXConfig.saveCustomDc();
}
builder.dismiss();
return Unit.INSTANCE;
});
builder.show();
}
2020-06-25 17:29:04 +02:00
2015-04-09 20:00:14 +02:00
}
});
2019-12-31 14:08:08 +01:00
currentDoneType = DONE_TYPE_FLOATING;
doneButtonVisible[DONE_TYPE_FLOATING] = true;
doneButtonVisible[DONE_TYPE_ACTION] = false;
2015-04-09 20:00:14 +02:00
ActionBarMenu menu = actionBar.createMenu();
2020-06-25 17:29:04 +02:00
proxyDrawable = new ProxyDrawable(context);
proxyItem = menu.addItem(2, proxyDrawable);
proxyItem.setContentDescription(LocaleController.getString("ProxySettings", R.string.ProxySettings));
updateProxyButton(false);
menu.addItem(3, R.drawable.ic_translate);
ActionBarMenuItem otherItem = menu.addItem(menu_other, R.drawable.ic_ab_other);
2020-06-26 06:54:48 +02:00
Locale current = ConfigurationCompat.getLocales(getParentActivity().getResources().getConfiguration()).get(0);
if (NekoXConfig.developerMode || !"cn".equals(current.getCountry().toLowerCase())) {
2020-06-25 17:29:04 +02:00
otherItem.addSubItem(4, R.drawable.list_bot, LocaleController.getString("BotLogin", R.string.BotLogin));
}
otherItem.addSubItem(menu_custom_api, R.drawable.baseline_vpn_key_24, LocaleController.getString("CustomApi", R.string.CustomApi));
otherItem.addSubItem(menu_custom_dc, R.drawable.baseline_sync_24,LocaleController.getString("CustomBackend", R.string.CustomBackend));
2017-07-08 18:32:04 +02:00
actionBar.setAllowOverlayTitle(true);
2019-01-23 18:03:33 +01:00
doneItem = menu.addItemWithWidth(done_button, R.drawable.ic_done, AndroidUtilities.dp(56));
doneProgressView = new ContextProgressView(context, 1);
doneProgressView.setAlpha(0.0f);
doneProgressView.setScaleX(0.1f);
doneProgressView.setScaleY(0.1f);
doneProgressView.setVisibility(View.INVISIBLE);
2019-12-31 14:08:08 +01:00
doneItem.setAlpha(0.0f);
doneItem.setScaleX(0.1f);
doneItem.setScaleY(0.1f);
2019-01-23 18:03:33 +01:00
doneItem.addView(doneProgressView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
2019-05-14 14:08:05 +02:00
doneItem.setContentDescription(LocaleController.getString("Done", R.string.Done));
2019-12-31 14:08:08 +01:00
doneItem.setVisibility(doneButtonVisible[DONE_TYPE_ACTION] ? View.VISIBLE : View.GONE);
FrameLayout container = new FrameLayout(context) {
private ObjectAnimator floatingButtonAnimator;
private ObjectAnimator privacyViewAnimator;
@Override
public void onViewAdded(View child) {
if (child == floatingButtonContainer && floatingButtonAnimator == null) {
floatingButtonAnimator = ObjectAnimator.ofFloat(child, View.TRANSLATION_Y, 0f);
floatingButtonAnimator.setInterpolator(AndroidUtilities.decelerateInterpolator);
floatingButtonAnimator.setStartDelay(150);
floatingButtonAnimator.setDuration(200);
}
}
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
if (privacyViewAnimator == null) {
final TextView privacyView = ((LoginActivityRegisterView) views[5]).privacyView;
privacyViewAnimator = ObjectAnimator.ofFloat(privacyView, View.TRANSLATION_Y, 0f);
privacyViewAnimator.setInterpolator(AndroidUtilities.decelerateInterpolator);
privacyViewAnimator.setStartDelay(150);
privacyViewAnimator.setDuration(200);
}
if (oldh == 0 || h == oldh || pagesAnimation != null && pagesAnimation.isRunning()) {
return;
}
final float marginBottom = AndroidUtilities.dp(16f);
if (floatingButtonAnimator != null) {
final float yOffset = floatingButtonContainer.getTranslationY() + oldh - h;
final float viewHeight = floatingButtonContainer.getHeight() + marginBottom;
final float translationY = Math.min(yOffset, viewHeight);
floatingButtonAnimator.cancel();
floatingButtonContainer.setTranslationY(translationY);
floatingButtonAnimator.setFloatValues(translationY, 0f);
floatingButtonAnimator.start();
}
if (currentViewNum == 5) {
final TextView privacyView = ((LoginActivityRegisterView) views[5]).privacyView;
final float yOffset = privacyView.getTranslationY() + oldh - h;
final float viewHeight = privacyView.getHeight() + marginBottom;
final float translationY = Math.min(yOffset, viewHeight);
privacyViewAnimator.cancel();
privacyView.setTranslationY(translationY);
privacyViewAnimator.setFloatValues(translationY, 0f);
privacyViewAnimator.start();
}
}
};
fragmentView = container;
2019-01-23 18:03:33 +01:00
ScrollView scrollView = new ScrollView(context) {
@Override
public boolean requestChildRectangleOnScreen(View child, Rect rectangle, boolean immediate) {
if (currentViewNum == 1 || currentViewNum == 2 || currentViewNum == 4) {
rectangle.bottom += AndroidUtilities.dp(40);
}
return super.requestChildRectangleOnScreen(child, rectangle, immediate);
}
2015-04-09 20:00:14 +02:00
2019-01-23 18:03:33 +01:00
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
scrollHeight = MeasureSpec.getSize(heightMeasureSpec) - AndroidUtilities.dp(30);
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
};
2015-04-09 20:00:14 +02:00
scrollView.setFillViewport(true);
2019-12-31 14:08:08 +01:00
container.addView(scrollView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
2015-04-09 20:00:14 +02:00
FrameLayout frameLayout = new FrameLayout(context);
2015-11-26 22:04:02 +01:00
scrollView.addView(frameLayout, LayoutHelper.createScroll(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.TOP | Gravity.LEFT));
2015-04-09 20:00:14 +02:00
views[0] = new PhoneView(context);
2016-03-16 13:26:32 +01:00
views[1] = new LoginActivitySmsView(context, 1);
views[2] = new LoginActivitySmsView(context, 2);
views[3] = new LoginActivitySmsView(context, 3);
views[4] = new LoginActivitySmsView(context, 4);
views[5] = new LoginActivityRegisterView(context);
views[6] = new LoginActivityPasswordView(context);
views[7] = new LoginActivityRecoverView(context);
2016-10-11 13:57:01 +02:00
views[8] = new LoginActivityResetWaitView(context);
2015-04-09 20:00:14 +02:00
2016-03-16 13:26:32 +01:00
for (int a = 0; a < views.length; a++) {
2015-04-09 20:00:14 +02:00
views[a].setVisibility(a == 0 ? View.VISIBLE : View.GONE);
2018-07-30 04:07:02 +02:00
frameLayout.addView(views[a], LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT, AndroidUtilities.isTablet() ? 26 : 18, 30, AndroidUtilities.isTablet() ? 26 : 18, 0));
2015-04-09 20:00:14 +02:00
}
2015-04-09 20:00:14 +02:00
Bundle savedInstanceState = loadCurrentState();
if (savedInstanceState != null) {
currentViewNum = savedInstanceState.getInt("currentViewNum", 0);
2019-06-18 06:41:28 +02:00
syncContacts = savedInstanceState.getInt("syncContacts", 0) == 1;
2016-03-16 13:26:32 +01:00
if (currentViewNum >= 1 && currentViewNum <= 4) {
int time = savedInstanceState.getInt("open");
if (time != 0 && Math.abs(System.currentTimeMillis() / 1000 - time) >= 24 * 60 * 60) {
currentViewNum = 0;
savedInstanceState = null;
clearCurrentState();
}
2018-08-27 10:33:11 +02:00
} else if (currentViewNum == 6) {
LoginActivityPasswordView view = (LoginActivityPasswordView) views[6];
if (view.passwordType == 0 || view.current_salt1 == null || view.current_salt2 == null) {
currentViewNum = 0;
savedInstanceState = null;
clearCurrentState();
}
}
2015-04-09 20:00:14 +02:00
}
2019-12-31 14:08:08 +01:00
floatingButtonContainer = new FrameLayout(context);
floatingButtonContainer.setVisibility(doneButtonVisible[DONE_TYPE_FLOATING] ? View.VISIBLE : View.GONE);
Drawable drawable = Theme.createSimpleSelectorCircleDrawable(AndroidUtilities.dp(56), Theme.getColor(Theme.key_chats_actionBackground), Theme.getColor(Theme.key_chats_actionPressedBackground));
if (Build.VERSION.SDK_INT < 21) {
Drawable shadowDrawable = context.getResources().getDrawable(R.drawable.floating_shadow).mutate();
2020-06-25 17:29:04 +02:00
shadowDrawable.setColorFilter(new PorterDuffColorFilter(0xff000000, PorterDuff.Mode.SRC_IN));
2019-12-31 14:08:08 +01:00
CombinedDrawable combinedDrawable = new CombinedDrawable(shadowDrawable, drawable, 0, 0);
combinedDrawable.setIconSize(AndroidUtilities.dp(56), AndroidUtilities.dp(56));
drawable = combinedDrawable;
}
floatingButtonContainer.setBackgroundDrawable(drawable);
if (Build.VERSION.SDK_INT >= 21) {
StateListAnimator animator = new StateListAnimator();
animator.addState(new int[]{android.R.attr.state_pressed}, ObjectAnimator.ofFloat(floatingButtonIcon, "translationZ", AndroidUtilities.dp(2), AndroidUtilities.dp(4)).setDuration(200));
animator.addState(new int[]{}, ObjectAnimator.ofFloat(floatingButtonIcon, "translationZ", AndroidUtilities.dp(4), AndroidUtilities.dp(2)).setDuration(200));
floatingButtonContainer.setStateListAnimator(animator);
floatingButtonContainer.setOutlineProvider(new ViewOutlineProvider() {
@SuppressLint("NewApi")
@Override
public void getOutline(View view, Outline outline) {
outline.setOval(0, 0, AndroidUtilities.dp(56), AndroidUtilities.dp(56));
}
});
}
container.addView(floatingButtonContainer, LayoutHelper.createFrame(Build.VERSION.SDK_INT >= 21 ? 56 : 60, Build.VERSION.SDK_INT >= 21 ? 56 : 60, Gravity.RIGHT | Gravity.BOTTOM, 0, 0, 14, 14));
floatingButtonContainer.setOnClickListener(view -> onDoneButtonPressed());
floatingButtonIcon = new ImageView(context);
floatingButtonIcon.setScaleType(ImageView.ScaleType.CENTER);
2020-06-25 17:29:04 +02:00
floatingButtonIcon.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_chats_actionIcon), PorterDuff.Mode.SRC_IN));
2019-12-31 14:08:08 +01:00
floatingButtonIcon.setImageResource(R.drawable.actionbtn_next);
floatingButtonContainer.setContentDescription(LocaleController.getString("Done", R.string.Done));
floatingButtonContainer.addView(floatingButtonIcon, LayoutHelper.createFrame(Build.VERSION.SDK_INT >= 21 ? 56 : 60, Build.VERSION.SDK_INT >= 21 ? 56 : 60));
floatingProgressView = new RadialProgressView(context);
floatingProgressView.setSize(AndroidUtilities.dp(22));
floatingProgressView.setProgressColor(Theme.getColor(Theme.key_chats_actionIcon));
floatingProgressView.setAlpha(0.0f);
floatingProgressView.setScaleX(0.1f);
floatingProgressView.setScaleY(0.1f);
floatingProgressView.setVisibility(View.INVISIBLE);
floatingButtonContainer.addView(floatingProgressView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
if (savedInstanceState != null) {
restoringState = true;
}
2015-04-09 20:00:14 +02:00
for (int a = 0; a < views.length; a++) {
if (savedInstanceState != null) {
2016-03-16 13:26:32 +01:00
if (a >= 1 && a <= 4) {
if (a == currentViewNum) {
views[a].restoreStateParams(savedInstanceState);
}
} else {
views[a].restoreStateParams(savedInstanceState);
}
}
2015-04-09 20:00:14 +02:00
if (currentViewNum == a) {
2018-07-30 04:07:02 +02:00
actionBar.setBackButtonImage(views[a].needBackButton() || newAccount ? R.drawable.ic_ab_back : 0);
2015-04-09 20:00:14 +02:00
views[a].setVisibility(View.VISIBLE);
views[a].onShow();
2019-12-31 14:08:08 +01:00
currentDoneType = DONE_TYPE_FLOATING;
if (a == 1 || a == 2 || a == 3 || a == 4 || a == 8) {
showDoneButton(false, false);
} else {
showDoneButton(true, false);
}
if (a == 1 || a == 2 || a == 3 || a == 4) {
currentDoneType = DONE_TYPE_ACTION;
2016-03-16 13:26:32 +01:00
}
2015-04-09 20:00:14 +02:00
} else {
views[a].setVisibility(View.GONE);
}
}
2019-12-31 14:08:08 +01:00
restoringState = false;
2019-01-23 18:03:33 +01:00
actionBar.setTitle(views[currentViewNum].getHeaderName());
2015-04-09 20:00:14 +02:00
return fragmentView;
2013-10-25 17:19:00 +02:00
}
2020-06-25 17:29:04 +02:00
private int currentConnectionState;
@Override
public void didReceivedNotification(int id, int account, Object... args) {
if (id == NotificationCenter.didUpdateConnectionState) {
int state = AccountInstance.getInstance(account).getConnectionsManager().getConnectionState();
if (currentConnectionState != state) {
currentConnectionState = state;
updateProxyButton(true);
}
}
}
private void updateProxyButton(boolean animated) {
if (proxyDrawable == null) {
return;
}
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
String proxyAddress = preferences.getString("proxy_ip", "");
boolean proxyEnabled;
if (!actionBar.isSearchFieldVisible() && (doneItem == null || doneItem.getVisibility() != View.VISIBLE)) {
proxyItem.setVisibility(View.VISIBLE);
}
proxyDrawable.setConnected(true, currentConnectionState == ConnectionsManager.ConnectionStateConnected || currentConnectionState == ConnectionsManager.ConnectionStateUpdating, animated);
}
2014-11-07 11:23:17 +01:00
@Override
public void onPause() {
super.onPause();
2020-03-30 14:00:09 +02:00
AndroidUtilities.removeAdjustResize(getParentActivity(), classGuid, true);
2018-07-30 04:07:02 +02:00
if (newAccount) {
ConnectionsManager.getInstance(currentAccount).setAppPaused(true, false);
}
2014-11-07 11:23:17 +01:00
}
@Override
public void onResume() {
super.onResume();
2018-07-30 04:07:02 +02:00
if (newAccount) {
ConnectionsManager.getInstance(currentAccount).setAppPaused(false, false);
}
2020-03-30 14:00:09 +02:00
AndroidUtilities.requestAdjustResize(getParentActivity(), classGuid, true);
try {
2016-03-16 13:26:32 +01:00
if (currentViewNum >= 1 && currentViewNum <= 4 && views[currentViewNum] instanceof LoginActivitySmsView) {
int time = ((LoginActivitySmsView) views[currentViewNum]).openTime;
if (time != 0 && Math.abs(System.currentTimeMillis() / 1000 - time) >= 24 * 60 * 60) {
2019-01-23 18:03:33 +01:00
views[currentViewNum].onBackPressed(true);
setPage(0, false, null, true);
}
}
} catch (Exception e) {
2017-03-31 01:58:05 +02:00
FileLog.e(e);
}
2014-11-07 11:23:17 +01:00
}
2016-03-16 13:26:32 +01:00
@Override
public void onRequestPermissionsResultFragment(int requestCode, String[] permissions, int[] grantResults) {
if (requestCode == 6) {
checkPermissions = false;
if (currentViewNum == 0) {
views[currentViewNum].onNextPressed();
}
2017-03-31 01:58:05 +02:00
} else if (requestCode == 7) {
checkShowPermissions = false;
if (currentViewNum == 0) {
((PhoneView) views[currentViewNum]).fillNumber();
}
2016-03-16 13:26:32 +01:00
}
}
private Bundle loadCurrentState() {
2019-01-23 18:03:33 +01:00
if (newAccount) {
return null;
}
try {
Bundle bundle = new Bundle();
2016-03-16 13:26:32 +01:00
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("logininfo2", Context.MODE_PRIVATE);
Map<String, ?> params = preferences.getAll();
for (Map.Entry<String, ?> entry : params.entrySet()) {
String key = entry.getKey();
Object value = entry.getValue();
String[] args = key.split("_\\|_");
if (args.length == 1) {
if (value instanceof String) {
bundle.putString(key, (String) value);
} else if (value instanceof Integer) {
bundle.putInt(key, (Integer) value);
}
} else if (args.length == 2) {
Bundle inner = bundle.getBundle(args[0]);
if (inner == null) {
inner = new Bundle();
bundle.putBundle(args[0], inner);
}
if (value instanceof String) {
inner.putString(args[1], (String) value);
} else if (value instanceof Integer) {
inner.putInt(args[1], (Integer) value);
}
}
}
return bundle;
} catch (Exception e) {
2017-03-31 01:58:05 +02:00
FileLog.e(e);
}
return null;
}
private void clearCurrentState() {
2016-03-16 13:26:32 +01:00
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("logininfo2", Context.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
editor.clear();
2020-06-25 17:29:04 +02:00
editor.apply();
}
private void putBundleToEditor(Bundle bundle, SharedPreferences.Editor editor, String prefix) {
Set<String> keys = bundle.keySet();
for (String key : keys) {
Object obj = bundle.get(key);
if (obj instanceof String) {
if (prefix != null) {
editor.putString(prefix + "_|_" + key, (String) obj);
} else {
editor.putString(key, (String) obj);
}
} else if (obj instanceof Integer) {
if (prefix != null) {
editor.putInt(prefix + "_|_" + key, (Integer) obj);
} else {
editor.putInt(key, (Integer) obj);
}
} else if (obj instanceof Bundle) {
2015-04-09 20:00:14 +02:00
putBundleToEditor((Bundle) obj, editor, key);
}
}
}
2016-03-16 13:26:32 +01:00
@Override
protected void onDialogDismiss(Dialog dialog) {
2019-12-10 17:17:36 +01:00
/*if (Build.VERSION.SDK_INT >= 23) {
2017-03-31 01:58:05 +02:00
if (dialog == permissionsDialog && !permissionsItems.isEmpty() && getParentActivity() != null) {
try {
2019-05-14 14:08:05 +02:00
getParentActivity().requestPermissions(permissionsItems.toArray(new String[0]), 6);
2017-03-31 01:58:05 +02:00
} catch (Exception ignore) {
}
} else if (dialog == permissionsShowDialog && !permissionsShowItems.isEmpty() && getParentActivity() != null) {
try {
2019-05-14 14:08:05 +02:00
getParentActivity().requestPermissions(permissionsShowItems.toArray(new String[0]), 7);
2017-03-31 01:58:05 +02:00
} catch (Exception ignore) {
}
}
2019-12-10 17:17:36 +01:00
}*/
2016-03-16 13:26:32 +01:00
}
2013-10-25 17:19:00 +02:00
@Override
public boolean onBackPressed() {
2013-12-20 20:25:49 +01:00
if (currentViewNum == 0) {
2016-03-16 13:26:32 +01:00
for (int a = 0; a < views.length; a++) {
if (views[a] != null) {
views[a].onDestroyActivity();
2013-12-20 20:25:49 +01:00
}
2013-10-25 17:19:00 +02:00
}
2014-11-14 16:40:15 +01:00
clearCurrentState();
return true;
2016-03-16 13:26:32 +01:00
} else if (currentViewNum == 6) {
2019-01-23 18:03:33 +01:00
views[currentViewNum].onBackPressed(true);
2013-12-20 20:25:49 +01:00
setPage(0, true, null, true);
2016-10-11 13:57:01 +02:00
} else if (currentViewNum == 7 || currentViewNum == 8) {
2019-01-23 18:03:33 +01:00
views[currentViewNum].onBackPressed(true);
2016-03-16 13:26:32 +01:00
setPage(6, true, null, true);
2019-01-23 18:03:33 +01:00
} else if (currentViewNum >= 1 && currentViewNum <= 4) {
if (views[currentViewNum].onBackPressed(false)) {
setPage(0, true, null, true);
2018-07-30 04:07:02 +02:00
}
2019-01-23 18:03:33 +01:00
} else if (currentViewNum == 5) {
((LoginActivityRegisterView) views[currentViewNum]).wrongNumber.callOnClick();
2013-10-25 17:19:00 +02:00
}
return false;
2013-10-25 17:19:00 +02:00
}
2019-01-23 18:03:33 +01:00
@Override
public void onActivityResultFragment(int requestCode, int resultCode, Intent data) {
LoginActivityRegisterView registerView = (LoginActivityRegisterView) views[5];
if (registerView != null) {
registerView.imageUpdater.onActivityResult(requestCode, resultCode, data);
}
}
private void needShowAlert(String title, String text) {
2014-06-13 12:42:21 +02:00
if (text == null || getParentActivity() == null) {
2014-03-10 10:27:49 +01:00
return;
}
2014-06-13 12:42:21 +02:00
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
2015-04-09 20:00:14 +02:00
builder.setTitle(title);
2014-06-13 12:42:21 +02:00
builder.setMessage(text);
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
2015-05-21 23:27:27 +02:00
showDialog(builder.create());
2013-10-25 17:19:00 +02:00
}
2019-12-31 14:08:08 +01:00
private void onFieldError(View view) {
try {
Vibrator v = (Vibrator) getParentActivity().getSystemService(Context.VIBRATOR_SERVICE);
if (v != null) {
v.vibrate(200);
}
} catch (Throwable ignore) {
}
AndroidUtilities.shakeView(view, 2, 0);
}
2016-10-11 13:57:01 +02:00
private void needShowInvalidAlert(final String phoneNumber, final boolean banned) {
if (getParentActivity() == null) {
return;
}
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
2020-06-25 17:29:04 +02:00
builder.setTitle(LocaleController.getString("NekoX", R.string.NekoX));
2016-10-11 13:57:01 +02:00
if (banned) {
builder.setMessage(LocaleController.getString("BannedPhoneNumber", R.string.BannedPhoneNumber));
} else {
builder.setMessage(LocaleController.getString("InvalidPhoneNumber", R.string.InvalidPhoneNumber));
}
2018-08-27 10:33:11 +02:00
builder.setNeutralButton(LocaleController.getString("BotHelp", R.string.BotHelp), (dialog, which) -> {
try {
PackageInfo pInfo = ApplicationLoader.applicationContext.getPackageManager().getPackageInfo(ApplicationLoader.applicationContext.getPackageName(), 0);
String version = String.format(Locale.US, "%s (%d)", pInfo.versionName, pInfo.versionCode);
Intent mailer = new Intent(Intent.ACTION_SEND);
mailer.setType("message/rfc822");
mailer.putExtra(Intent.EXTRA_EMAIL, new String[]{"login@stel.com"});
if (banned) {
mailer.putExtra(Intent.EXTRA_SUBJECT, "Banned phone number: " + phoneNumber);
mailer.putExtra(Intent.EXTRA_TEXT, "I'm trying to use my mobile phone number: " + phoneNumber + "\nBut Telegram says it's banned. Please help.\n\nApp version: " + version + "\nOS version: SDK " + Build.VERSION.SDK_INT + "\nDevice Name: " + Build.MANUFACTURER + Build.MODEL + "\nLocale: " + Locale.getDefault());
} else {
mailer.putExtra(Intent.EXTRA_SUBJECT, "Invalid phone number: " + phoneNumber);
mailer.putExtra(Intent.EXTRA_TEXT, "I'm trying to use my mobile phone number: " + phoneNumber + "\nBut Telegram says it's invalid. Please help.\n\nApp version: " + version + "\nOS version: SDK " + Build.VERSION.SDK_INT + "\nDevice Name: " + Build.MANUFACTURER + Build.MODEL + "\nLocale: " + Locale.getDefault());
}
2018-08-27 10:33:11 +02:00
getParentActivity().startActivity(Intent.createChooser(mailer, "Send email..."));
} catch (Exception e) {
2020-06-25 17:29:04 +02:00
needShowAlert(LocaleController.getString("NekoX", R.string.NekoX), LocaleController.getString("NoMailInstalled", R.string.NoMailInstalled));
}
});
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
showDialog(builder.create());
}
2019-12-31 14:08:08 +01:00
private void showDoneButton(boolean show, boolean animated) {
final boolean floating = currentDoneType == 0;
if (doneButtonVisible[currentDoneType] == show) {
return;
}
if (showDoneAnimation[currentDoneType] != null) {
showDoneAnimation[currentDoneType].cancel();
}
doneButtonVisible[currentDoneType] = show;
if (animated) {
showDoneAnimation[currentDoneType] = new AnimatorSet();
if (show) {
if (floating) {
floatingButtonContainer.setVisibility(View.VISIBLE);
showDoneAnimation[currentDoneType].play(ObjectAnimator.ofFloat(floatingButtonContainer, View.TRANSLATION_Y, 0f));
} else {
doneItem.setVisibility(View.VISIBLE);
showDoneAnimation[currentDoneType].playTogether(
ObjectAnimator.ofFloat(doneItem, View.SCALE_X, 1.0f),
ObjectAnimator.ofFloat(doneItem, View.SCALE_Y, 1.0f),
ObjectAnimator.ofFloat(doneItem, View.ALPHA, 1.0f));
}
} else {
if (floating) {
showDoneAnimation[currentDoneType].play(ObjectAnimator.ofFloat(floatingButtonContainer, View.TRANSLATION_Y, AndroidUtilities.dpf2(70f)));
} else {
showDoneAnimation[currentDoneType].playTogether(
ObjectAnimator.ofFloat(doneItem, View.SCALE_X, 0.1f),
ObjectAnimator.ofFloat(doneItem, View.SCALE_Y, 0.1f),
ObjectAnimator.ofFloat(doneItem, View.ALPHA, 0.0f));
}
}
showDoneAnimation[currentDoneType].addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
if (showDoneAnimation[floating ? 0 : 1] != null && showDoneAnimation[floating ? 0 : 1].equals(animation)) {
if (!show) {
if (floating) {
floatingButtonContainer.setVisibility(View.GONE);
} else {
doneItem.setVisibility(View.GONE);
}
}
}
}
@Override
public void onAnimationCancel(Animator animation) {
if (showDoneAnimation[floating ? 0 : 1] != null && showDoneAnimation[floating ? 0 : 1].equals(animation)) {
showDoneAnimation[floating ? 0 : 1] = null;
}
}
});
final int duration;
final Interpolator interpolator;
if (floating) {
if (show) {
duration = 200;
interpolator = AndroidUtilities.decelerateInterpolator;
} else {
duration = 150;
interpolator = AndroidUtilities.accelerateInterpolator;
}
} else {
duration = 150;
interpolator = null;
}
showDoneAnimation[currentDoneType].setDuration(duration);
showDoneAnimation[currentDoneType].setInterpolator(interpolator);
showDoneAnimation[currentDoneType].start();
} else {
if (show) {
if (floating) {
floatingButtonContainer.setVisibility(View.VISIBLE);
floatingButtonContainer.setTranslationY(0f);
} else {
doneItem.setVisibility(View.VISIBLE);
doneItem.setScaleX(1.0f);
doneItem.setScaleY(1.0f);
doneItem.setAlpha(1.0f);
}
} else {
if (floating) {
floatingButtonContainer.setVisibility(View.GONE);
floatingButtonContainer.setTranslationY(AndroidUtilities.dpf2(70f));
} else {
doneItem.setVisibility(View.GONE);
doneItem.setScaleX(0.1f);
doneItem.setScaleY(0.1f);
doneItem.setAlpha(0.0f);
}
}
}
}
private void onDoneButtonPressed() {
if (!doneButtonVisible[currentDoneType]) {
return;
}
if (doneProgressView.getTag() != null) {
if (getParentActivity() == null) {
return;
}
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
2020-01-08 18:08:16 +01:00
builder.setTitle(LocaleController.getString("NekogramWithEmoji", R.string.NekogramWithEmoji));
2019-12-31 14:08:08 +01:00
builder.setMessage(LocaleController.getString("StopLoading", R.string.StopLoading));
builder.setPositiveButton(LocaleController.getString("WaitMore", R.string.WaitMore), null);
builder.setNegativeButton(LocaleController.getString("Stop", R.string.Stop), (dialogInterface, i) -> {
views[currentViewNum].onCancelPressed();
needHideProgress(true);
});
showDialog(builder.create());
} else {
views[currentViewNum].onNextPressed();
}
}
2020-06-25 17:29:04 +02:00
2019-12-31 14:08:08 +01:00
private void showEditDoneProgress(final boolean show, boolean animated) {
2019-01-23 18:03:33 +01:00
if (doneItemAnimation != null) {
doneItemAnimation.cancel();
}
2019-12-31 14:08:08 +01:00
final boolean floating = currentDoneType == 0;
if (animated) {
doneItemAnimation = new AnimatorSet();
if (show) {
doneProgressView.setTag(1);
if (floating) {
floatingProgressView.setVisibility(View.VISIBLE);
floatingButtonContainer.setEnabled(false);
doneItemAnimation.playTogether(
ObjectAnimator.ofFloat(floatingButtonIcon, View.SCALE_X, 0.1f),
ObjectAnimator.ofFloat(floatingButtonIcon, View.SCALE_Y, 0.1f),
ObjectAnimator.ofFloat(floatingButtonIcon, View.ALPHA, 0.0f),
ObjectAnimator.ofFloat(floatingProgressView, View.SCALE_X, 1.0f),
ObjectAnimator.ofFloat(floatingProgressView, View.SCALE_Y, 1.0f),
ObjectAnimator.ofFloat(floatingProgressView, View.ALPHA, 1.0f));
} else {
doneProgressView.setVisibility(View.VISIBLE);
doneItemAnimation.playTogether(
ObjectAnimator.ofFloat(doneItem.getContentView(), View.SCALE_X, 0.1f),
ObjectAnimator.ofFloat(doneItem.getContentView(), View.SCALE_Y, 0.1f),
ObjectAnimator.ofFloat(doneItem.getContentView(), View.ALPHA, 0.0f),
ObjectAnimator.ofFloat(doneProgressView, View.SCALE_X, 1.0f),
ObjectAnimator.ofFloat(doneProgressView, View.SCALE_Y, 1.0f),
ObjectAnimator.ofFloat(doneProgressView, View.ALPHA, 1.0f));
}
} else {
doneProgressView.setTag(null);
if (floating) {
floatingButtonIcon.setVisibility(View.VISIBLE);
floatingButtonContainer.setEnabled(true);
doneItemAnimation.playTogether(
ObjectAnimator.ofFloat(floatingProgressView, View.SCALE_X, 0.1f),
ObjectAnimator.ofFloat(floatingProgressView, View.SCALE_Y, 0.1f),
ObjectAnimator.ofFloat(floatingProgressView, View.ALPHA, 0.0f),
ObjectAnimator.ofFloat(floatingButtonIcon, View.SCALE_X, 1.0f),
ObjectAnimator.ofFloat(floatingButtonIcon, View.SCALE_Y, 1.0f),
ObjectAnimator.ofFloat(floatingButtonIcon, View.ALPHA, 1.0f));
} else {
doneItem.getContentView().setVisibility(View.VISIBLE);
doneItemAnimation.playTogether(
ObjectAnimator.ofFloat(doneProgressView, View.SCALE_X, 0.1f),
ObjectAnimator.ofFloat(doneProgressView, View.SCALE_Y, 0.1f),
ObjectAnimator.ofFloat(doneProgressView, View.ALPHA, 0.0f),
ObjectAnimator.ofFloat(doneItem.getContentView(), View.SCALE_X, 1.0f),
ObjectAnimator.ofFloat(doneItem.getContentView(), View.SCALE_Y, 1.0f),
ObjectAnimator.ofFloat(doneItem.getContentView(), View.ALPHA, 1.0f));
2019-01-23 18:03:33 +01:00
}
}
2019-12-31 14:08:08 +01:00
doneItemAnimation.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
if (doneItemAnimation != null && doneItemAnimation.equals(animation)) {
if (floating) {
if (!show) {
floatingProgressView.setVisibility(View.INVISIBLE);
} else {
floatingButtonIcon.setVisibility(View.INVISIBLE);
}
} else {
if (!show) {
doneProgressView.setVisibility(View.INVISIBLE);
} else {
doneItem.getContentView().setVisibility(View.INVISIBLE);
}
}
}
}
2019-01-23 18:03:33 +01:00
2019-12-31 14:08:08 +01:00
@Override
public void onAnimationCancel(Animator animation) {
if (doneItemAnimation != null && doneItemAnimation.equals(animation)) {
doneItemAnimation = null;
}
}
});
doneItemAnimation.setDuration(150);
doneItemAnimation.start();
} else {
if (show) {
if (floating) {
floatingProgressView.setVisibility(View.VISIBLE);
floatingButtonIcon.setVisibility(View.INVISIBLE);
floatingButtonContainer.setEnabled(false);
floatingButtonIcon.setScaleX(0.1f);
floatingButtonIcon.setScaleY(0.1f);
floatingButtonIcon.setAlpha(0.0f);
floatingProgressView.setScaleX(1.0f);
floatingProgressView.setScaleY(1.0f);
floatingProgressView.setAlpha(1.0f);
} else {
doneProgressView.setVisibility(View.VISIBLE);
doneItem.getContentView().setVisibility(View.INVISIBLE);
doneItem.getContentView().setScaleX(0.1f);
doneItem.getContentView().setScaleY(0.1f);
doneItem.getContentView().setAlpha(0.0f);
doneProgressView.setScaleX(1.0f);
doneProgressView.setScaleY(1.0f);
doneProgressView.setAlpha(1.0f);
}
} else {
doneProgressView.setTag(null);
if (floating) {
floatingProgressView.setVisibility(View.INVISIBLE);
floatingButtonIcon.setVisibility(View.VISIBLE);
floatingButtonContainer.setEnabled(true);
floatingProgressView.setScaleX(0.1f);
floatingProgressView.setScaleY(0.1f);
floatingProgressView.setAlpha(0.0f);
floatingButtonIcon.setScaleX(1.0f);
floatingButtonIcon.setScaleY(1.0f);
floatingButtonIcon.setAlpha(1.0f);
} else {
doneItem.getContentView().setVisibility(View.VISIBLE);
doneProgressView.setVisibility(View.INVISIBLE);
doneProgressView.setScaleX(0.1f);
doneProgressView.setScaleY(0.1f);
doneProgressView.setAlpha(0.0f);
doneItem.getContentView().setScaleX(1.0f);
doneItem.getContentView().setScaleY(1.0f);
doneItem.getContentView().setAlpha(1.0f);
2019-01-23 18:03:33 +01:00
}
}
2019-12-31 14:08:08 +01:00
}
2019-01-23 18:03:33 +01:00
}
2017-07-08 18:32:04 +02:00
private void needShowProgress(final int reqiestId) {
2019-12-31 14:08:08 +01:00
needShowProgress(reqiestId, true);
}
private void needShowProgress(final int reqiestId, boolean animated) {
2019-01-23 18:03:33 +01:00
progressRequestId = reqiestId;
2019-12-31 14:08:08 +01:00
showEditDoneProgress(true, animated);
2013-10-25 17:19:00 +02:00
}
2019-12-31 14:08:08 +01:00
private void needHideProgress(boolean cancel) {
needHideProgress(cancel, true);
}
private void needHideProgress(boolean cancel, boolean animated) {
2019-01-23 18:03:33 +01:00
if (progressRequestId != 0) {
if (cancel) {
ConnectionsManager.getInstance(currentAccount).cancelRequest(progressRequestId, true);
}
progressRequestId = 0;
2014-06-13 12:42:21 +02:00
}
2019-12-31 14:08:08 +01:00
showEditDoneProgress(false, animated);
2013-10-25 17:19:00 +02:00
}
2013-12-20 20:25:49 +01:00
public void setPage(int page, boolean animated, Bundle params, boolean back) {
2019-12-31 14:08:08 +01:00
final boolean needFloatingButton = page == 0 || page == 5 || page == 6 || page == 7;
if (needFloatingButton) {
2016-03-16 13:26:32 +01:00
if (page == 0) {
checkPermissions = true;
2017-03-31 01:58:05 +02:00
checkShowPermissions = true;
2016-03-16 13:26:32 +01:00
}
2019-12-31 14:08:08 +01:00
currentDoneType = DONE_TYPE_ACTION;
showDoneButton(false, animated);
currentDoneType = DONE_TYPE_FLOATING;
showEditDoneProgress(false, false);
if (!animated) {
showDoneButton(true, false);
}
} else {
currentDoneType = DONE_TYPE_FLOATING;
showDoneButton(false, animated);
if (page != 8) {
currentDoneType = DONE_TYPE_ACTION;
}
2016-03-16 13:26:32 +01:00
}
if (animated) {
2013-12-20 20:25:49 +01:00
final SlideView outView = views[currentViewNum];
final SlideView newView = views[page];
currentViewNum = page;
2018-07-30 04:07:02 +02:00
actionBar.setBackButtonImage(newView.needBackButton() || newAccount ? R.drawable.ic_ab_back : 0);
2013-12-20 20:25:49 +01:00
2017-03-31 01:58:05 +02:00
newView.setParams(params, false);
2014-11-11 23:16:17 +01:00
actionBar.setTitle(newView.getHeaderName());
2019-05-14 14:08:05 +02:00
setParentActivityTitle(newView.getHeaderName());
2013-12-20 20:25:49 +01:00
newView.onShow();
newView.setX(back ? -AndroidUtilities.displaySize.x : AndroidUtilities.displaySize.x);
2019-01-23 18:03:33 +01:00
newView.setVisibility(View.VISIBLE);
2013-12-20 20:25:49 +01:00
2019-12-31 14:08:08 +01:00
pagesAnimation = new AnimatorSet();
pagesAnimation.addListener(new AnimatorListenerAdapter() {
2013-12-20 20:25:49 +01:00
@Override
2019-01-23 18:03:33 +01:00
public void onAnimationEnd(Animator animation) {
2019-12-31 14:08:08 +01:00
if (currentDoneType == DONE_TYPE_FLOATING && needFloatingButton) {
showDoneButton(true, true);
}
2013-12-20 20:25:49 +01:00
outView.setVisibility(View.GONE);
outView.setX(0);
}
2019-01-23 18:03:33 +01:00
});
2019-12-31 14:08:08 +01:00
pagesAnimation.playTogether(
2019-01-23 18:03:33 +01:00
ObjectAnimator.ofFloat(outView, View.TRANSLATION_X, back ? AndroidUtilities.displaySize.x : -AndroidUtilities.displaySize.x),
ObjectAnimator.ofFloat(newView, View.TRANSLATION_X, 0));
2019-12-31 14:08:08 +01:00
pagesAnimation.setDuration(300);
pagesAnimation.setInterpolator(new AccelerateDecelerateInterpolator());
pagesAnimation.start();
2013-12-20 20:25:49 +01:00
} else {
2018-07-30 04:07:02 +02:00
actionBar.setBackButtonImage(views[page].needBackButton() || newAccount ? R.drawable.ic_ab_back : 0);
2013-12-20 20:25:49 +01:00
views[currentViewNum].setVisibility(View.GONE);
currentViewNum = page;
2017-03-31 01:58:05 +02:00
views[page].setParams(params, false);
2013-12-20 20:25:49 +01:00
views[page].setVisibility(View.VISIBLE);
2014-11-11 23:16:17 +01:00
actionBar.setTitle(views[page].getHeaderName());
2019-05-14 14:08:05 +02:00
setParentActivityTitle(views[page].getHeaderName());
2013-12-20 20:25:49 +01:00
views[page].onShow();
}
2013-10-25 17:19:00 +02:00
}
@Override
public void saveSelfArgs(Bundle outState) {
2014-11-14 16:40:15 +01:00
try {
Bundle bundle = new Bundle();
bundle.putInt("currentViewNum", currentViewNum);
2018-07-30 04:07:02 +02:00
bundle.putInt("syncContacts", syncContacts ? 1 : 0);
2014-11-14 16:40:15 +01:00
for (int a = 0; a <= currentViewNum; a++) {
SlideView v = views[a];
if (v != null) {
v.saveStateParams(bundle);
}
}
2016-03-16 13:26:32 +01:00
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("logininfo2", Context.MODE_PRIVATE);
2014-11-14 16:40:15 +01:00
SharedPreferences.Editor editor = preferences.edit();
editor.clear();
putBundleToEditor(bundle, editor, null);
2020-06-25 17:29:04 +02:00
editor.apply();
2014-11-14 16:40:15 +01:00
} catch (Exception e) {
2017-03-31 01:58:05 +02:00
FileLog.e(e);
2014-11-14 16:40:15 +01:00
}
2013-10-25 17:19:00 +02:00
}
2019-12-31 14:08:08 +01:00
private void needFinishActivity(boolean afterSignup) {
clearCurrentState();
2018-07-30 04:07:02 +02:00
if (getParentActivity() instanceof LaunchActivity) {
if (newAccount) {
newAccount = false;
2020-06-25 17:29:04 +02:00
((LaunchActivity) getParentActivity()).switchToAccount(currentAccount, false, true);
2018-07-30 04:07:02 +02:00
finishFragment();
} else {
2019-12-31 14:08:08 +01:00
final Bundle args = new Bundle();
args.putBoolean("afterSignup", afterSignup);
presentFragment(new DialogsActivity(args), true);
2018-07-30 04:07:02 +02:00
NotificationCenter.getInstance(currentAccount).postNotificationName(NotificationCenter.mainUserInfoChanged);
}
} else if (getParentActivity() instanceof ExternalActionActivity) {
((ExternalActionActivity) getParentActivity()).onFinishLogin();
}
}
private void onAuthSuccess(TLRPC.TL_auth_authorization res) {
2019-12-31 14:08:08 +01:00
onAuthSuccess(res, false);
}
private void onAuthSuccess(TLRPC.TL_auth_authorization res, boolean afterSignup) {
2018-07-30 04:07:02 +02:00
ConnectionsManager.getInstance(currentAccount).setUserId(res.user.id);
UserConfig.getInstance(currentAccount).clearConfig();
MessagesController.getInstance(currentAccount).cleanup();
UserConfig.getInstance(currentAccount).syncContacts = syncContacts;
UserConfig.getInstance(currentAccount).setCurrentUser(res.user);
UserConfig.getInstance(currentAccount).saveConfig(true);
MessagesStorage.getInstance(currentAccount).cleanup(true);
ArrayList<TLRPC.User> users = new ArrayList<>();
users.add(res.user);
MessagesStorage.getInstance(currentAccount).putUsersAndChats(users, null, true, true);
MessagesController.getInstance(currentAccount).putUser(res.user, false);
ContactsController.getInstance(currentAccount).checkAppAccount();
2020-04-30 21:07:00 +02:00
MessagesController.getInstance(currentAccount).checkPromoInfo(true);
2018-07-30 04:07:02 +02:00
ConnectionsManager.getInstance(currentAccount).updateDcSettings();
2019-12-31 14:08:08 +01:00
needFinishActivity(afterSignup);
2013-10-25 17:19:00 +02:00
}
2014-11-14 16:40:15 +01:00
2020-06-25 17:29:04 +02:00
private void fillNextCodeParamsSilent(Bundle params, TLRPC.TL_auth_sentCode res) {
params.putString("phoneHash", res.phone_code_hash);
if (res.next_type instanceof TLRPC.TL_auth_codeTypeCall) {
params.putInt("nextType", 4);
} else if (res.next_type instanceof TLRPC.TL_auth_codeTypeFlashCall) {
params.putInt("nextType", 3);
} else if (res.next_type instanceof TLRPC.TL_auth_codeTypeSms) {
params.putInt("nextType", 2);
}
if (res.type instanceof TLRPC.TL_auth_sentCodeTypeApp) {
params.putInt("type", 1);
params.putInt("length", res.type.length);
} else {
if (res.timeout == 0) {
res.timeout = 60;
}
params.putInt("timeout", res.timeout * 1000);
if (res.type instanceof TLRPC.TL_auth_sentCodeTypeCall) {
params.putInt("type", 4);
params.putInt("length", res.type.length);
} else if (res.type instanceof TLRPC.TL_auth_sentCodeTypeFlashCall) {
params.putInt("type", 3);
params.putString("pattern", res.type.pattern);
} else if (res.type instanceof TLRPC.TL_auth_sentCodeTypeSms) {
params.putInt("type", 2);
params.putInt("length", res.type.length);
}
}
}
2016-03-16 13:26:32 +01:00
private void fillNextCodeParams(Bundle params, TLRPC.TL_auth_sentCode res) {
params.putString("phoneHash", res.phone_code_hash);
if (res.next_type instanceof TLRPC.TL_auth_codeTypeCall) {
params.putInt("nextType", 4);
} else if (res.next_type instanceof TLRPC.TL_auth_codeTypeFlashCall) {
params.putInt("nextType", 3);
} else if (res.next_type instanceof TLRPC.TL_auth_codeTypeSms) {
params.putInt("nextType", 2);
}
if (res.type instanceof TLRPC.TL_auth_sentCodeTypeApp) {
params.putInt("type", 1);
params.putInt("length", res.type.length);
setPage(1, true, params, false);
} else {
if (res.timeout == 0) {
res.timeout = 60;
}
params.putInt("timeout", res.timeout * 1000);
if (res.type instanceof TLRPC.TL_auth_sentCodeTypeCall) {
params.putInt("type", 4);
params.putInt("length", res.type.length);
setPage(4, true, params, false);
} else if (res.type instanceof TLRPC.TL_auth_sentCodeTypeFlashCall) {
params.putInt("type", 3);
params.putString("pattern", res.type.pattern);
setPage(3, true, params, false);
} else if (res.type instanceof TLRPC.TL_auth_sentCodeTypeSms) {
params.putInt("type", 2);
params.putInt("length", res.type.length);
setPage(2, true, params, false);
}
}
}
2018-07-30 04:07:02 +02:00
private TLRPC.TL_help_termsOfService currentTermsOfService;
2020-06-25 17:29:04 +02:00
private boolean allowFlashCall;
2016-03-16 13:26:32 +01:00
public class PhoneView extends SlideView implements AdapterView.OnItemSelectedListener {
2014-11-14 16:40:15 +01:00
2017-12-08 18:35:59 +01:00
private EditTextBoldCursor codeField;
2015-11-26 22:04:02 +01:00
private HintEditText phoneField;
2014-11-14 16:40:15 +01:00
private TextView countryButton;
2017-03-31 01:58:05 +02:00
private View view;
private TextView textView;
private TextView textView2;
2018-07-30 04:07:02 +02:00
private CheckBoxCell checkBoxCell;
2020-06-25 17:29:04 +02:00
private CheckBoxCell allowFlashCallCell;
2014-11-14 16:40:15 +01:00
private int countryState = 0;
2015-01-02 23:15:07 +01:00
private ArrayList<String> countriesArray = new ArrayList<>();
private HashMap<String, String> countriesMap = new HashMap<>();
private HashMap<String, String> codesMap = new HashMap<>();
2015-11-26 22:04:02 +01:00
private HashMap<String, String> phoneFormatMap = new HashMap<>();
2014-11-14 16:40:15 +01:00
private boolean ignoreSelection = false;
private boolean ignoreOnTextChange = false;
private boolean ignoreOnPhoneChange = false;
private boolean nextPressed = false;
2016-03-16 13:26:32 +01:00
public PhoneView(Context context) {
2014-11-14 16:40:15 +01:00
super(context);
setOrientation(VERTICAL);
countryButton = new TextView(context);
countryButton.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
2019-12-31 14:08:08 +01:00
countryButton.setPadding(AndroidUtilities.dp(4), AndroidUtilities.dp(4), AndroidUtilities.dp(4), AndroidUtilities.dp(4));
2017-03-31 01:58:05 +02:00
countryButton.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
2014-11-14 16:40:15 +01:00
countryButton.setMaxLines(1);
countryButton.setSingleLine(true);
countryButton.setEllipsize(TextUtils.TruncateAt.END);
countryButton.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.CENTER_HORIZONTAL);
2019-12-31 14:08:08 +01:00
countryButton.setBackground(Theme.createSelectorDrawable(Theme.getColor(Theme.key_listSelector), 7));
2015-11-26 22:04:02 +01:00
addView(countryButton, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 36, 0, 0, 0, 14));
2018-08-27 10:33:11 +02:00
countryButton.setOnClickListener(view -> {
CountrySelectActivity fragment = new CountrySelectActivity(true);
fragment.setCountrySelectActivityDelegate((name, shortName) -> {
selectCountry(name, shortName);
AndroidUtilities.runOnUIThread(() -> AndroidUtilities.showKeyboard(phoneField), 300);
phoneField.requestFocus();
phoneField.setSelection(phoneField.length());
});
presentFragment(fragment);
2014-11-14 16:40:15 +01:00
});
2017-03-31 01:58:05 +02:00
view = new View(context);
2014-11-14 16:40:15 +01:00
view.setPadding(AndroidUtilities.dp(12), 0, AndroidUtilities.dp(12), 0);
2017-03-31 01:58:05 +02:00
view.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhiteGrayLine));
2015-11-26 22:04:02 +01:00
addView(view, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 1, 4, -17.5f, 4, 0));
2014-11-14 16:40:15 +01:00
LinearLayout linearLayout = new LinearLayout(context);
linearLayout.setOrientation(HORIZONTAL);
2015-11-26 22:04:02 +01:00
addView(linearLayout, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, 0, 20, 0, 0));
2014-11-14 16:40:15 +01:00
2017-03-31 01:58:05 +02:00
textView = new TextView(context);
2014-11-14 16:40:15 +01:00
textView.setText("+");
2017-03-31 01:58:05 +02:00
textView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
2015-11-26 22:04:02 +01:00
linearLayout.addView(textView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT));
2014-11-14 16:40:15 +01:00
2017-12-08 18:35:59 +01:00
codeField = new EditTextBoldCursor(context);
2014-11-14 16:40:15 +01:00
codeField.setInputType(InputType.TYPE_CLASS_PHONE);
2017-03-31 01:58:05 +02:00
codeField.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
codeField.setBackgroundDrawable(Theme.createEditTextDrawable(context, false));
2017-12-08 18:35:59 +01:00
codeField.setCursorColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
codeField.setCursorSize(AndroidUtilities.dp(20));
codeField.setCursorWidth(1.5f);
2014-11-14 16:40:15 +01:00
codeField.setPadding(AndroidUtilities.dp(10), 0, 0, 0);
codeField.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
2014-11-14 16:40:15 +01:00
codeField.setMaxLines(1);
codeField.setGravity(Gravity.LEFT | Gravity.CENTER_VERTICAL);
codeField.setImeOptions(EditorInfo.IME_ACTION_NEXT | EditorInfo.IME_FLAG_NO_EXTRACT_UI);
InputFilter[] inputFilters = new InputFilter[1];
2015-11-26 22:04:02 +01:00
inputFilters[0] = new InputFilter.LengthFilter(5);
2014-11-14 16:40:15 +01:00
codeField.setFilters(inputFilters);
2015-11-26 22:04:02 +01:00
linearLayout.addView(codeField, LayoutHelper.createLinear(55, 36, -9, 0, 16, 0));
2014-11-14 16:40:15 +01:00
codeField.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
}
@Override
public void afterTextChanged(Editable editable) {
if (ignoreOnTextChange) {
return;
}
ignoreOnTextChange = true;
String text = PhoneFormat.stripExceptNumbers(codeField.getText().toString());
codeField.setText(text);
if (text.length() == 0) {
countryButton.setText(LocaleController.getString("ChooseCountry", R.string.ChooseCountry));
2015-11-26 22:04:02 +01:00
phoneField.setHintText(null);
2014-11-14 16:40:15 +01:00
countryState = 1;
} else {
2015-11-26 22:04:02 +01:00
String country;
boolean ok = false;
String textToSet = null;
if (text.length() > 4) {
for (int a = 4; a >= 1; a--) {
String sub = text.substring(0, a);
country = codesMap.get(sub);
if (country != null) {
ok = true;
2019-05-14 14:08:05 +02:00
textToSet = text.substring(a) + phoneField.getText().toString();
2015-11-26 22:04:02 +01:00
codeField.setText(text = sub);
break;
}
}
if (!ok) {
2019-05-14 14:08:05 +02:00
textToSet = text.substring(1) + phoneField.getText().toString();
2015-11-26 22:04:02 +01:00
codeField.setText(text = text.substring(0, 1));
}
}
country = codesMap.get(text);
2014-11-14 16:40:15 +01:00
if (country != null) {
int index = countriesArray.indexOf(country);
if (index != -1) {
ignoreSelection = true;
countryButton.setText(countriesArray.get(index));
2015-11-26 22:04:02 +01:00
String hint = phoneFormatMap.get(text);
phoneField.setHintText(hint != null ? hint.replace('X', '') : null);
2014-11-14 16:40:15 +01:00
countryState = 0;
} else {
countryButton.setText(LocaleController.getString("WrongCountry", R.string.WrongCountry));
2015-11-26 22:04:02 +01:00
phoneField.setHintText(null);
2014-11-14 16:40:15 +01:00
countryState = 2;
}
} else {
countryButton.setText(LocaleController.getString("WrongCountry", R.string.WrongCountry));
2015-11-26 22:04:02 +01:00
phoneField.setHintText(null);
2014-11-14 16:40:15 +01:00
countryState = 2;
}
2015-11-26 22:04:02 +01:00
if (!ok) {
codeField.setSelection(codeField.getText().length());
}
if (textToSet != null) {
phoneField.requestFocus();
phoneField.setText(textToSet);
phoneField.setSelection(phoneField.length());
}
2014-11-14 16:40:15 +01:00
}
ignoreOnTextChange = false;
2014-11-14 16:40:15 +01:00
}
});
2018-08-27 10:33:11 +02:00
codeField.setOnEditorActionListener((textView, i, keyEvent) -> {
if (i == EditorInfo.IME_ACTION_NEXT) {
phoneField.requestFocus();
phoneField.setSelection(phoneField.length());
return true;
2014-11-14 16:40:15 +01:00
}
2018-08-27 10:33:11 +02:00
return false;
2014-11-14 16:40:15 +01:00
});
2019-01-23 18:03:33 +01:00
phoneField = new HintEditText(context) {
@Override
public boolean onTouchEvent(MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
if (!AndroidUtilities.showKeyboard(this)) {
clearFocus();
requestFocus();
}
}
return super.onTouchEvent(event);
}
};
2014-11-14 16:40:15 +01:00
phoneField.setInputType(InputType.TYPE_CLASS_PHONE);
2017-03-31 01:58:05 +02:00
phoneField.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
phoneField.setHintTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteHintText));
phoneField.setBackgroundDrawable(Theme.createEditTextDrawable(context, false));
2014-11-14 16:40:15 +01:00
phoneField.setPadding(0, 0, 0, 0);
2017-12-08 18:35:59 +01:00
phoneField.setCursorColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
phoneField.setCursorSize(AndroidUtilities.dp(20));
phoneField.setCursorWidth(1.5f);
phoneField.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
2014-11-14 16:40:15 +01:00
phoneField.setMaxLines(1);
phoneField.setGravity(Gravity.LEFT | Gravity.CENTER_VERTICAL);
phoneField.setImeOptions(EditorInfo.IME_ACTION_NEXT | EditorInfo.IME_FLAG_NO_EXTRACT_UI);
2015-11-26 22:04:02 +01:00
linearLayout.addView(phoneField, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 36));
2014-11-14 16:40:15 +01:00
phoneField.addTextChangedListener(new TextWatcher() {
2015-11-26 22:04:02 +01:00
private int characterAction = -1;
private int actionPosition;
2014-11-14 16:40:15 +01:00
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
2015-11-26 22:04:02 +01:00
if (count == 0 && after == 1) {
characterAction = 1;
} else if (count == 1 && after == 0) {
if (s.charAt(start) == ' ' && start > 0) {
characterAction = 3;
actionPosition = start - 1;
} else {
characterAction = 2;
2014-11-14 16:40:15 +01:00
}
2015-11-26 22:04:02 +01:00
} else {
characterAction = -1;
2014-11-14 16:40:15 +01:00
}
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
if (ignoreOnPhoneChange) {
return;
}
2015-11-26 22:04:02 +01:00
int start = phoneField.getSelectionStart();
String phoneChars = "0123456789";
String str = phoneField.getText().toString();
if (characterAction == 3) {
2019-05-14 14:08:05 +02:00
str = str.substring(0, actionPosition) + str.substring(actionPosition + 1);
2015-11-26 22:04:02 +01:00
start--;
}
StringBuilder builder = new StringBuilder(str.length());
for (int a = 0; a < str.length(); a++) {
String ch = str.substring(a, a + 1);
if (phoneChars.contains(ch)) {
builder.append(ch);
}
}
ignoreOnPhoneChange = true;
String hint = phoneField.getHintText();
if (hint != null) {
for (int a = 0; a < builder.length(); a++) {
if (a < hint.length()) {
if (hint.charAt(a) == ' ') {
builder.insert(a, ' ');
a++;
if (start == a && characterAction != 2 && characterAction != 3) {
start++;
}
}
} else {
builder.insert(a, ' ');
if (start == a + 1 && characterAction != 2 && characterAction != 3) {
start++;
}
break;
}
}
}
2018-07-30 04:07:02 +02:00
s.replace(0, s.length(), builder);
2015-11-26 22:04:02 +01:00
if (start >= 0) {
2020-04-24 11:21:58 +02:00
phoneField.setSelection(Math.min(start, phoneField.length()));
2015-11-26 22:04:02 +01:00
}
phoneField.onTextChange();
ignoreOnPhoneChange = false;
2014-11-14 16:40:15 +01:00
}
});
2018-08-27 10:33:11 +02:00
phoneField.setOnEditorActionListener((textView, i, keyEvent) -> {
if (i == EditorInfo.IME_ACTION_NEXT) {
onNextPressed();
return true;
2014-11-14 16:40:15 +01:00
}
2018-08-27 10:33:11 +02:00
return false;
2014-11-14 16:40:15 +01:00
});
2019-01-23 18:03:33 +01:00
phoneField.setOnKeyListener((v, keyCode, event) -> {
if (keyCode == KeyEvent.KEYCODE_DEL && phoneField.length() == 0) {
codeField.requestFocus();
codeField.setSelection(codeField.length());
codeField.dispatchKeyEvent(event);
return true;
}
return false;
});
2014-11-14 16:40:15 +01:00
2017-03-31 01:58:05 +02:00
textView2 = new TextView(context);
textView2.setText(LocaleController.getString("StartText", R.string.StartText));
textView2.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteGrayText6));
textView2.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
textView2.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);
textView2.setLineSpacing(AndroidUtilities.dp(2), 1.0f);
addView(textView2, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT, 0, 28, 0, 10));
2014-11-14 16:40:15 +01:00
2020-06-25 17:29:04 +02:00
checkBoxCell = new CheckBoxCell(context, 2);
checkBoxCell.setText(LocaleController.getString("SyncContacts", R.string.SyncContacts), "", syncContacts, false);
addView(checkBoxCell, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.MATCH_PARENT, Gravity.LEFT | Gravity.TOP));
checkBoxCell.setOnClickListener(new OnClickListener() {
2018-07-30 04:07:02 +02:00
2020-06-25 17:29:04 +02:00
private Toast visibleToast;
2018-07-30 04:07:02 +02:00
2020-06-25 17:29:04 +02:00
@Override
public void onClick(View v) {
if (getParentActivity() == null) {
return;
2018-07-30 04:07:02 +02:00
}
2020-06-25 17:29:04 +02:00
CheckBoxCell cell = (CheckBoxCell) v;
syncContacts = !syncContacts;
cell.setChecked(syncContacts, true);
try {
if (visibleToast != null) {
visibleToast.cancel();
2020-01-10 16:42:19 +01:00
}
2020-06-25 17:29:04 +02:00
} catch (Exception e) {
FileLog.e(e);
2020-01-10 16:42:19 +01:00
}
2020-06-25 17:29:04 +02:00
if (syncContacts) {
visibleToast = Toast.makeText(getParentActivity(), LocaleController.getString("SyncContactsOn", R.string.SyncContactsOn), Toast.LENGTH_SHORT);
visibleToast.show();
} else {
visibleToast = Toast.makeText(getParentActivity(), LocaleController.getString("SyncContactsOff", R.string.SyncContactsOff), Toast.LENGTH_SHORT);
visibleToast.show();
}
}
});
TelephonyManager tm = (TelephonyManager) ApplicationLoader.applicationContext.getSystemService(Context.TELEPHONY_SERVICE);
if (BuildVars.DEBUG_VERSION) {
FileLog.d("sim status = " + tm.getSimState());
}
int state = tm.getSimState();
boolean simcardAvailable = state != TelephonyManager.SIM_STATE_ABSENT && state != TelephonyManager.SIM_STATE_UNKNOWN && tm.getPhoneType() != TelephonyManager.PHONE_TYPE_NONE && !AndroidUtilities.isAirplaneModeOn();
boolean allowCall = true;
boolean allowCancelCall = true;
boolean allowReadCallLog = true;
if (Build.VERSION.SDK_INT >= 23 && simcardAvailable) {
allowCall = getParentActivity().checkSelfPermission(Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED;
allowCancelCall = getParentActivity().checkSelfPermission(Manifest.permission.CALL_PHONE) == PackageManager.PERMISSION_GRANTED;
allowReadCallLog = Build.VERSION.SDK_INT < 28 || getParentActivity().checkSelfPermission(Manifest.permission.READ_CALL_LOG) == PackageManager.PERMISSION_GRANTED;
2020-02-21 05:08:57 +01:00
}
2020-06-25 17:29:04 +02:00
allowFlashCall = simcardAvailable && allowCall && allowCancelCall && allowReadCallLog;
allowFlashCallCell = new CheckBoxCell(context, 2);
allowFlashCallCell.setText(LocaleController.getString("AllowFlashCall", R.string.AllowFlashCall), "", allowFlashCall, false);
addView(allowFlashCallCell, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.MATCH_PARENT, Gravity.LEFT | Gravity.TOP));
allowFlashCallCell.setOnClickListener(v -> {
if (getParentActivity() == null) {
return;
}
CheckBoxCell cell = (CheckBoxCell) v;
cell.setChecked(allowFlashCall = !allowFlashCall, true);
});
2020-01-10 16:42:19 +01:00
2015-01-02 23:15:07 +01:00
HashMap<String, String> languageMap = new HashMap<>();
2014-11-14 16:40:15 +01:00
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(getResources().getAssets().open("countries.txt")));
String line;
while ((line = reader.readLine()) != null) {
String[] args = line.split(";");
countriesArray.add(0, args[2]);
countriesMap.put(args[2], args[0]);
codesMap.put(args[0], args[2]);
2015-11-26 22:04:02 +01:00
if (args.length > 3) {
phoneFormatMap.put(args[0], args[3]);
}
2014-11-14 16:40:15 +01:00
languageMap.put(args[1], args[2]);
}
2015-02-27 20:57:58 +01:00
reader.close();
2014-11-14 16:40:15 +01:00
} catch (Exception e) {
2017-03-31 01:58:05 +02:00
FileLog.e(e);
2014-11-14 16:40:15 +01:00
}
2018-08-27 10:33:11 +02:00
Collections.sort(countriesArray, String::compareTo);
2014-11-14 16:40:15 +01:00
String country = null;
try {
2015-04-09 20:00:14 +02:00
TelephonyManager telephonyManager = (TelephonyManager) ApplicationLoader.applicationContext.getSystemService(Context.TELEPHONY_SERVICE);
2014-11-14 16:40:15 +01:00
if (telephonyManager != null) {
2019-08-22 01:53:26 +02:00
country = null;//telephonyManager.getSimCountryIso().toUpperCase();
2014-11-14 16:40:15 +01:00
}
} catch (Exception e) {
2017-03-31 01:58:05 +02:00
FileLog.e(e);
2014-11-14 16:40:15 +01:00
}
if (country != null) {
2019-08-22 01:53:26 +02:00
setCountry(languageMap, country.toUpperCase());
} else {
TLRPC.TL_help_getNearestDc req = new TLRPC.TL_help_getNearestDc();
getAccountInstance().getConnectionsManager().sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
if (response == null) {
return;
2014-11-14 16:40:15 +01:00
}
2019-08-22 01:53:26 +02:00
TLRPC.TL_nearestDc res = (TLRPC.TL_nearestDc) response;
if (codeField.length() == 0) {
setCountry(languageMap, res.country.toUpperCase());
}
}), ConnectionsManager.RequestFlagWithoutLogin | ConnectionsManager.RequestFlagFailOnServerErrors);
2014-11-14 16:40:15 +01:00
}
if (codeField.length() == 0) {
countryButton.setText(LocaleController.getString("ChooseCountry", R.string.ChooseCountry));
2015-11-26 22:04:02 +01:00
phoneField.setHintText(null);
2014-11-14 16:40:15 +01:00
countryState = 1;
}
if (codeField.length() != 0) {
phoneField.requestFocus();
2015-11-26 22:04:02 +01:00
phoneField.setSelection(phoneField.length());
2014-11-14 16:40:15 +01:00
} else {
codeField.requestFocus();
}
}
2018-07-30 04:07:02 +02:00
public void selectCountry(String name, String iso) {
2014-11-14 16:40:15 +01:00
int index = countriesArray.indexOf(name);
if (index != -1) {
ignoreOnTextChange = true;
2015-11-26 22:04:02 +01:00
String code = countriesMap.get(name);
codeField.setText(code);
2014-11-14 16:40:15 +01:00
countryButton.setText(name);
2015-11-26 22:04:02 +01:00
String hint = phoneFormatMap.get(code);
phoneField.setHintText(hint != null ? hint.replace('X', '') : null);
2014-11-14 16:40:15 +01:00
countryState = 0;
ignoreOnTextChange = false;
2014-11-14 16:40:15 +01:00
}
}
2019-08-22 01:53:26 +02:00
private void setCountry(HashMap<String, String> languageMap, String country) {
String countryName = languageMap.get(country);
if (countryName != null) {
int index = countriesArray.indexOf(countryName);
if (index != -1) {
codeField.setText(countriesMap.get(countryName));
countryState = 0;
}
}
}
2017-12-08 18:35:59 +01:00
@Override
public void onCancelPressed() {
nextPressed = false;
}
2014-11-14 16:40:15 +01:00
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
if (ignoreSelection) {
ignoreSelection = false;
return;
}
ignoreOnTextChange = true;
String str = countriesArray.get(i);
codeField.setText(countriesMap.get(str));
ignoreOnTextChange = false;
2014-11-14 16:40:15 +01:00
}
@Override
public void onNothingSelected(AdapterView<?> adapterView) {
}
@Override
public void onNextPressed() {
2016-03-16 13:26:32 +01:00
if (getParentActivity() == null || nextPressed) {
2014-11-14 16:40:15 +01:00
return;
}
if (countryState == 1) {
2020-01-08 18:08:16 +01:00
needShowAlert(LocaleController.getString("NekogramWithEmoji", R.string.NekogramWithEmoji), LocaleController.getString("ChooseCountry", R.string.ChooseCountry));
2014-11-14 16:40:15 +01:00
return;
2018-07-30 04:07:02 +02:00
} else if (countryState == 2 && !BuildVars.DEBUG_VERSION) {
2020-01-08 18:08:16 +01:00
needShowAlert(LocaleController.getString("NekogramWithEmoji", R.string.NekogramWithEmoji), LocaleController.getString("WrongCountry", R.string.WrongCountry));
2014-11-14 16:40:15 +01:00
return;
}
if (codeField.length() == 0) {
2020-06-25 17:29:04 +02:00
needShowAlert(LocaleController.getString("NekoX", R.string.NekoX), LocaleController.getString("InvalidPhoneNumber", R.string.InvalidPhoneNumber));
2014-11-14 16:40:15 +01:00
return;
}
2019-12-31 14:08:08 +01:00
if (phoneField.length() == 0) {
onFieldError(phoneField);
return;
}
2018-07-30 04:07:02 +02:00
String phone = PhoneFormat.stripExceptNumbers("" + codeField.getText() + phoneField.getText());
if (getParentActivity() instanceof LaunchActivity) {
for (int a = 0; a < UserConfig.MAX_ACCOUNT_COUNT; a++) {
UserConfig userConfig = UserConfig.getInstance(a);
if (!userConfig.isClientActivated()) {
continue;
}
String userPhone = userConfig.getCurrentUser().phone;
2020-01-10 16:42:19 +01:00
if (PhoneNumberUtils.compare(phone, userPhone) && ConnectionsManager.native_isTestBackend(currentAccount) == ConnectionsManager.native_isTestBackend(a)) {
2018-07-30 04:07:02 +02:00
final int num = a;
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
2020-01-08 18:08:16 +01:00
builder.setTitle(LocaleController.getString("NekogramWithEmoji", R.string.NekogramWithEmoji));
2018-07-30 04:07:02 +02:00
builder.setMessage(LocaleController.getString("AccountAlreadyLoggedIn", R.string.AccountAlreadyLoggedIn));
2018-08-27 10:33:11 +02:00
builder.setPositiveButton(LocaleController.getString("AccountSwitch", R.string.AccountSwitch), (dialog, which) -> {
if (UserConfig.selectedAccount != num) {
((LaunchActivity) getParentActivity()).switchToAccount(num, false);
2018-07-30 04:07:02 +02:00
}
2018-08-27 10:33:11 +02:00
finishFragment();
2018-07-30 04:07:02 +02:00
});
builder.setNegativeButton(LocaleController.getString("OK", R.string.OK), null);
showDialog(builder.create());
return;
}
}
}
2015-10-29 18:10:07 +01:00
2018-07-30 04:07:02 +02:00
ConnectionsManager.getInstance(currentAccount).cleanup(false);
final TLRPC.TL_auth_sendCode req = new TLRPC.TL_auth_sendCode();
2020-06-25 17:29:04 +02:00
req.api_hash = NekoXConfig.currentAppHash();
req.api_id = NekoXConfig.currentAppId();
2014-11-14 16:40:15 +01:00
req.phone_number = phone;
2019-01-23 18:03:33 +01:00
req.settings = new TLRPC.TL_codeSettings();
2020-06-25 17:29:04 +02:00
req.settings.allow_flashcall = allowFlashCall;
req.settings.allow_app_hash = false;
2014-11-14 16:40:15 +01:00
final Bundle params = new Bundle();
2019-01-23 18:03:33 +01:00
params.putString("phone", "+" + codeField.getText() + " " + phoneField.getText());
2015-03-26 18:34:47 +01:00
try {
params.putString("ephone", "+" + PhoneFormat.stripExceptNumbers(codeField.getText().toString()) + " " + PhoneFormat.stripExceptNumbers(phoneField.getText().toString()));
} catch (Exception e) {
2017-03-31 01:58:05 +02:00
FileLog.e(e);
2015-03-26 18:34:47 +01:00
params.putString("ephone", "+" + phone);
}
2014-11-14 16:40:15 +01:00
params.putString("phoneFormated", phone);
nextPressed = true;
2018-08-27 10:33:11 +02:00
int reqId = ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
nextPressed = false;
if (error == null) {
2020-06-25 17:29:04 +02:00
if (phone.startsWith("99966")) {
fillNextCodeParamsSilent(params, (TLRPC.TL_auth_sentCode) response);
String phoneHash = ((TLRPC.TL_auth_sentCode) response).phone_code_hash;
String dcId = phone.substring(5, 6);
final TLRPC.TL_auth_signIn reqI = new TLRPC.TL_auth_signIn();
reqI.phone_number = phone;
reqI.phone_code = dcId + dcId + dcId + dcId + dcId;
reqI.phone_code_hash = phoneHash;
int reqIdI = ConnectionsManager.getInstance(currentAccount).sendRequest(reqI, (responseI, errorI) -> AndroidUtilities.runOnUIThread(() -> {
boolean ok = false;
if (errorI == null) {
nextPressed = false;
ok = true;
showDoneButton(false, true);
if (responseI instanceof TLRPC.TL_auth_authorizationSignUpRequired) {
TLRPC.TL_auth_authorizationSignUpRequired authorization = (TLRPC.TL_auth_authorizationSignUpRequired) responseI;
if (authorization.terms_of_service != null) {
currentTermsOfService = authorization.terms_of_service;
}
Bundle paramsI = new Bundle();
paramsI.putString("phoneFormated", phone);
paramsI.putString("phoneHash", phoneHash);
paramsI.putString("code", reqI.phone_code);
setPage(5, true, params, false);
} else {
onAuthSuccess((TLRPC.TL_auth_authorization) responseI);
}
} else {
if (errorI.text.contains("SESSION_PASSWORD_NEEDED")) {
ok = true;
TLRPC.TL_account_getPassword req2 = new TLRPC.TL_account_getPassword();
ConnectionsManager.getInstance(currentAccount).sendRequest(req2, (response1, error1) -> AndroidUtilities.runOnUIThread(() -> {
nextPressed = false;
showDoneButton(false, true);
if (error1 == null) {
TLRPC.TL_account_password password = (TLRPC.TL_account_password) response1;
if (!TwoStepVerificationActivity.canHandleCurrentPassword(password, true)) {
AlertsCreator.showUpdateAppAlert(getParentActivity(), LocaleController.getString("UpdateAppAlert", R.string.UpdateAppAlert), true);
return;
}
Bundle bundle = new Bundle();
if (password.current_algo instanceof TLRPC.TL_passwordKdfAlgoSHA256SHA256PBKDF2HMACSHA512iter100000SHA256ModPow) {
TLRPC.TL_passwordKdfAlgoSHA256SHA256PBKDF2HMACSHA512iter100000SHA256ModPow algo = (TLRPC.TL_passwordKdfAlgoSHA256SHA256PBKDF2HMACSHA512iter100000SHA256ModPow) password.current_algo;
bundle.putString("current_salt1", Utilities.bytesToHex(algo.salt1));
bundle.putString("current_salt2", Utilities.bytesToHex(algo.salt2));
bundle.putString("current_p", Utilities.bytesToHex(algo.p));
bundle.putInt("current_g", algo.g);
bundle.putString("current_srp_B", Utilities.bytesToHex(password.srp_B));
bundle.putLong("current_srp_id", password.srp_id);
bundle.putInt("passwordType", 1);
}
bundle.putString("hint", password.hint != null ? password.hint : "");
bundle.putString("email_unconfirmed_pattern", password.email_unconfirmed_pattern != null ? password.email_unconfirmed_pattern : "");
bundle.putString("phoneFormated", phone);
bundle.putString("phoneHash", phoneHash);
bundle.putString("code", reqI.phone_code);
bundle.putInt("has_recovery", password.has_recovery ? 1 : 0);
setPage(6, true, bundle, false);
} else {
needShowAlert(LocaleController.getString("NekoX", R.string.NekoX), error1.text);
}
}), ConnectionsManager.RequestFlagFailOnServerErrors | ConnectionsManager.RequestFlagWithoutLogin);
} else {
nextPressed = false;
showDoneButton(false, true);
if (errorI.text.contains("PHONE_NUMBER_INVALID")) {
needShowAlert(LocaleController.getString("NekoX", R.string.NekoX), LocaleController.getString("InvalidPhoneNumber", R.string.InvalidPhoneNumber));
} else if (errorI.text.contains("PHONE_CODE_EMPTY") || errorI.text.contains("PHONE_CODE_INVALID")) {
needShowAlert(LocaleController.getString("NekoX", R.string.NekoX), LocaleController.getString("InvalidCode", R.string.InvalidCode));
} else if (errorI.text.contains("PHONE_CODE_EXPIRED")) {
onBackPressed(true);
setPage(0, true, null, true);
needShowAlert(LocaleController.getString("NekoX", R.string.NekoX), LocaleController.getString("CodeExpired", R.string.CodeExpired));
} else if (errorI.text.startsWith("FLOOD_WAIT")) {
needShowAlert(LocaleController.getString("NekoX", R.string.NekoX), LocaleController.getString("FloodWait", R.string.FloodWait));
} else {
needShowAlert(LocaleController.getString("NekoX", R.string.NekoX), LocaleController.getString("ErrorOccurred", R.string.ErrorOccurred) + "\n" + errorI.text);
}
}
}
}), ConnectionsManager.RequestFlagFailOnServerErrors | ConnectionsManager.RequestFlagWithoutLogin);
needShowProgress(reqIdI, false);
showDoneButton(true, true);
return;
}
2018-08-27 10:33:11 +02:00
fillNextCodeParams(params, (TLRPC.TL_auth_sentCode) response);
} else {
if (error.text != null) {
if (error.text.contains("PHONE_NUMBER_INVALID")) {
needShowInvalidAlert(req.phone_number, false);
} else if (error.text.contains("PHONE_PASSWORD_FLOOD")) {
2020-06-25 17:29:04 +02:00
needShowAlert(LocaleController.getString("NekoX", R.string.NekoX), LocaleController.getString("FloodWait", R.string.FloodWait));
2018-08-27 10:33:11 +02:00
} else if (error.text.contains("PHONE_NUMBER_FLOOD")) {
2020-06-25 17:29:04 +02:00
needShowAlert(LocaleController.getString("NekoX", R.string.NekoX), LocaleController.getString("PhoneNumberFlood", R.string.PhoneNumberFlood));
2018-08-27 10:33:11 +02:00
} else if (error.text.contains("PHONE_NUMBER_BANNED")) {
needShowInvalidAlert(req.phone_number, true);
} else if (error.text.contains("PHONE_CODE_EMPTY") || error.text.contains("PHONE_CODE_INVALID")) {
2020-06-25 17:29:04 +02:00
needShowAlert(LocaleController.getString("NekoX", R.string.NekoX), LocaleController.getString("InvalidCode", R.string.InvalidCode));
2018-08-27 10:33:11 +02:00
} else if (error.text.contains("PHONE_CODE_EXPIRED")) {
2020-06-25 17:29:04 +02:00
needShowAlert(LocaleController.getString("NekoX", R.string.NekoX), LocaleController.getString("CodeExpired", R.string.CodeExpired));
2018-08-27 10:33:11 +02:00
} else if (error.text.startsWith("FLOOD_WAIT")) {
2020-06-25 17:29:04 +02:00
needShowAlert(LocaleController.getString("NekoX", R.string.NekoX), LocaleController.getString("FloodWait", R.string.FloodWait));
2018-08-27 10:33:11 +02:00
} else if (error.code != -1000) {
2020-06-25 17:29:04 +02:00
needShowAlert(LocaleController.getString("NekoX", R.string.NekoX), error.text);
2014-11-14 16:40:15 +01:00
}
2018-08-27 10:33:11 +02:00
}
2014-11-14 16:40:15 +01:00
}
2019-01-23 18:03:33 +01:00
needHideProgress(false);
2018-08-27 10:33:11 +02:00
}), ConnectionsManager.RequestFlagFailOnServerErrors | ConnectionsManager.RequestFlagWithoutLogin | ConnectionsManager.RequestFlagTryDifferentDc | ConnectionsManager.RequestFlagEnableUnauthorized);
2017-07-08 18:32:04 +02:00
needShowProgress(reqId);
2014-11-14 16:40:15 +01:00
}
2017-03-31 01:58:05 +02:00
public void fillNumber() {
try {
TelephonyManager tm = (TelephonyManager) ApplicationLoader.applicationContext.getSystemService(Context.TELEPHONY_SERVICE);
if (tm.getSimState() != TelephonyManager.SIM_STATE_ABSENT && tm.getPhoneType() != TelephonyManager.PHONE_TYPE_NONE) {
boolean allowCall = true;
if (Build.VERSION.SDK_INT >= 23) {
allowCall = getParentActivity().checkSelfPermission(Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED;
2019-12-10 17:17:36 +01:00
/*if (checkShowPermissions && !allowCall) {
2017-03-31 01:58:05 +02:00
permissionsShowItems.clear();
if (!allowCall) {
permissionsShowItems.add(Manifest.permission.READ_PHONE_STATE);
}
if (!permissionsShowItems.isEmpty()) {
2018-07-30 04:07:02 +02:00
SharedPreferences preferences = MessagesController.getGlobalMainSettings();
2019-01-23 18:03:33 +01:00
if (preferences.getBoolean("firstloginshow", true) || getParentActivity().shouldShowRequestPermissionRationale(Manifest.permission.READ_PHONE_STATE)) {
2017-03-31 01:58:05 +02:00
preferences.edit().putBoolean("firstloginshow", false).commit();
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
2020-06-25 17:29:04 +02:00
builder.setTitle(LocaleController.getString("NekoX", R.string.NekoX));
2017-03-31 01:58:05 +02:00
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
builder.setMessage(LocaleController.getString("AllowFillNumber", R.string.AllowFillNumber));
permissionsShowDialog = showDialog(builder.create());
} else {
2019-05-14 14:08:05 +02:00
getParentActivity().requestPermissions(permissionsShowItems.toArray(new String[0]), 7);
2017-03-31 01:58:05 +02:00
}
}
return;
2019-12-10 17:17:36 +01:00
}*/
2017-03-31 01:58:05 +02:00
}
2019-01-23 18:03:33 +01:00
if (!newAccount && allowCall) {
2017-03-31 01:58:05 +02:00
String number = PhoneFormat.stripExceptNumbers(tm.getLine1Number());
String textToSet = null;
boolean ok = false;
if (!TextUtils.isEmpty(number)) {
if (number.length() > 4) {
for (int a = 4; a >= 1; a--) {
String sub = number.substring(0, a);
String country = codesMap.get(sub);
if (country != null) {
ok = true;
2019-05-14 14:08:05 +02:00
textToSet = number.substring(a);
2017-03-31 01:58:05 +02:00
codeField.setText(sub);
break;
}
}
if (!ok) {
2019-05-14 14:08:05 +02:00
textToSet = number.substring(1);
2017-03-31 01:58:05 +02:00
codeField.setText(number.substring(0, 1));
}
}
if (textToSet != null) {
phoneField.requestFocus();
phoneField.setText(textToSet);
phoneField.setSelection(phoneField.length());
}
}
}
}
} catch (Exception e) {
FileLog.e(e);
}
}
2014-11-14 16:40:15 +01:00
@Override
public void onShow() {
super.onShow();
2017-03-31 01:58:05 +02:00
fillNumber();
2018-07-30 04:07:02 +02:00
if (checkBoxCell != null) {
checkBoxCell.setChecked(syncContacts, false);
}
2018-08-27 10:33:11 +02:00
AndroidUtilities.runOnUIThread(() -> {
if (phoneField != null) {
if (codeField.length() != 0) {
phoneField.requestFocus();
phoneField.setSelection(phoneField.length());
2019-01-23 18:03:33 +01:00
AndroidUtilities.showKeyboard(phoneField);
2018-08-27 10:33:11 +02:00
} else {
codeField.requestFocus();
2019-01-23 18:03:33 +01:00
AndroidUtilities.showKeyboard(codeField);
2018-07-30 04:07:02 +02:00
}
}
}, 100);
2014-11-14 16:40:15 +01:00
}
@Override
public String getHeaderName() {
return LocaleController.getString("YourPhone", R.string.YourPhone);
}
@Override
public void saveStateParams(Bundle bundle) {
String code = codeField.getText().toString();
2015-09-24 22:52:02 +02:00
if (code.length() != 0) {
2014-11-14 16:40:15 +01:00
bundle.putString("phoneview_code", code);
}
String phone = phoneField.getText().toString();
2015-09-24 22:52:02 +02:00
if (phone.length() != 0) {
2014-11-14 16:40:15 +01:00
bundle.putString("phoneview_phone", phone);
}
}
@Override
public void restoreStateParams(Bundle bundle) {
String code = bundle.getString("phoneview_code");
if (code != null) {
codeField.setText(code);
}
String phone = bundle.getString("phoneview_phone");
if (phone != null) {
phoneField.setText(phone);
}
}
}
public class LoginActivitySmsView extends SlideView implements NotificationCenter.NotificationCenterDelegate {
2016-03-16 13:26:32 +01:00
private String phone;
2014-11-14 16:40:15 +01:00
private String phoneHash;
private String requestPhone;
2015-03-26 18:34:47 +01:00
private String emailPhone;
2019-01-23 18:03:33 +01:00
private LinearLayout codeFieldContainer;
private EditTextBoldCursor[] codeField;
2014-11-14 16:40:15 +01:00
private TextView confirmTextView;
2019-01-23 18:03:33 +01:00
private TextView titleTextView;
private ImageView blackImageView;
private ImageView blueImageView;
2014-11-14 16:40:15 +01:00
private TextView timeText;
private TextView problemText;
private Bundle currentParams;
2016-03-16 13:26:32 +01:00
private ProgressView progressView;
2014-11-14 16:40:15 +01:00
private Timer timeTimer;
private Timer codeTimer;
private int openTime;
2014-11-14 16:40:15 +01:00
private final Object timerSync = new Object();
2019-01-23 18:03:33 +01:00
private int time = 60000;
private int codeTime = 15000;
2014-11-14 16:40:15 +01:00
private double lastCurrentTime;
private double lastCodeTime;
2016-03-16 13:26:32 +01:00
private boolean ignoreOnTextChange;
private boolean waitingForEvent;
private boolean nextPressed;
2014-11-14 16:40:15 +01:00
private String lastError = "";
2016-03-16 13:26:32 +01:00
private int currentType;
private int nextType;
private String pattern = "*";
2017-03-31 01:58:05 +02:00
private String catchedPhone;
2016-03-16 13:26:32 +01:00
private int length;
2014-11-14 16:40:15 +01:00
2016-03-16 13:26:32 +01:00
public LoginActivitySmsView(Context context, final int type) {
2014-11-14 16:40:15 +01:00
super(context);
2016-03-16 13:26:32 +01:00
currentType = type;
2014-11-14 16:40:15 +01:00
setOrientation(VERTICAL);
confirmTextView = new TextView(context);
2017-03-31 01:58:05 +02:00
confirmTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteGrayText6));
2014-11-14 16:40:15 +01:00
confirmTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
confirmTextView.setLineSpacing(AndroidUtilities.dp(2), 1.0f);
2016-03-16 13:26:32 +01:00
2019-01-23 18:03:33 +01:00
titleTextView = new TextView(context);
titleTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
titleTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
titleTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
titleTextView.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);
titleTextView.setLineSpacing(AndroidUtilities.dp(2), 1.0f);
titleTextView.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL);
2016-03-16 13:26:32 +01:00
if (currentType == 3) {
2019-01-23 18:03:33 +01:00
confirmTextView.setGravity(Gravity.TOP | (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT));
2016-03-16 13:26:32 +01:00
FrameLayout frameLayout = new FrameLayout(context);
2019-01-23 18:03:33 +01:00
addView(frameLayout, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT));
2016-03-16 13:26:32 +01:00
ImageView imageView = new ImageView(context);
imageView.setImageResource(R.drawable.phone_activate);
if (LocaleController.isRTL) {
frameLayout.addView(imageView, LayoutHelper.createFrame(64, 76, Gravity.LEFT | Gravity.CENTER_VERTICAL, 2, 2, 0, 0));
frameLayout.addView(confirmTextView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT, 64 + 18, 0, 0, 0));
} else {
frameLayout.addView(confirmTextView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT, 0, 0, 64 + 18, 0));
frameLayout.addView(imageView, LayoutHelper.createFrame(64, 76, Gravity.RIGHT | Gravity.CENTER_VERTICAL, 0, 2, 0, 2));
}
} else {
2019-01-23 18:03:33 +01:00
confirmTextView.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL);
2014-11-14 16:40:15 +01:00
2019-01-23 18:03:33 +01:00
FrameLayout frameLayout = new FrameLayout(context);
addView(frameLayout, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.TOP | Gravity.CENTER_HORIZONTAL));
2015-11-26 22:04:02 +01:00
2019-01-23 18:03:33 +01:00
if (currentType == 1) {
blackImageView = new ImageView(context);
blackImageView.setImageResource(R.drawable.sms_devices);
2020-06-25 17:29:04 +02:00
blackImageView.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText), PorterDuff.Mode.SRC_IN));
2019-01-23 18:03:33 +01:00
frameLayout.addView(blackImageView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.TOP, 0, 0, 0, 0));
2015-11-26 22:04:02 +01:00
2019-01-23 18:03:33 +01:00
blueImageView = new ImageView(context);
blueImageView.setImageResource(R.drawable.sms_bubble);
2020-06-25 17:29:04 +02:00
blueImageView.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_chats_actionBackground), PorterDuff.Mode.SRC_IN));
2019-01-23 18:03:33 +01:00
frameLayout.addView(blueImageView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.TOP, 0, 0, 0, 0));
2015-11-26 22:04:02 +01:00
2019-01-23 18:03:33 +01:00
titleTextView.setText(LocaleController.getString("SentAppCodeTitle", R.string.SentAppCodeTitle));
} else {
blueImageView = new ImageView(context);
blueImageView.setImageResource(R.drawable.sms_code);
2020-06-25 17:29:04 +02:00
blueImageView.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_chats_actionBackground), PorterDuff.Mode.SRC_IN));
2019-01-23 18:03:33 +01:00
frameLayout.addView(blueImageView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.TOP, 0, 0, 0, 0));
2015-11-26 22:04:02 +01:00
2019-01-23 18:03:33 +01:00
titleTextView.setText(LocaleController.getString("SentSmsCodeTitle", R.string.SentSmsCodeTitle));
2015-11-26 22:04:02 +01:00
}
2019-01-23 18:03:33 +01:00
addView(titleTextView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER_HORIZONTAL | Gravity.TOP, 0, 18, 0, 0));
addView(confirmTextView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER_HORIZONTAL | Gravity.TOP, 0, 17, 0, 0));
}
codeFieldContainer = new LinearLayout(context);
codeFieldContainer.setOrientation(HORIZONTAL);
addView(codeFieldContainer, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, 36, Gravity.CENTER_HORIZONTAL));
2016-03-16 13:26:32 +01:00
if (currentType == 3) {
2019-01-23 18:03:33 +01:00
codeFieldContainer.setVisibility(GONE);
2016-03-16 13:26:32 +01:00
}
2014-11-14 16:40:15 +01:00
2019-01-23 18:03:33 +01:00
timeText = new TextView(context) {
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(100), MeasureSpec.AT_MOST));
}
};
2017-03-31 01:58:05 +02:00
timeText.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteGrayText6));
2014-11-14 16:40:15 +01:00
timeText.setLineSpacing(AndroidUtilities.dp(2), 1.0f);
2016-03-16 13:26:32 +01:00
if (currentType == 3) {
2019-01-23 18:03:33 +01:00
timeText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
addView(timeText, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT));
2016-03-16 13:26:32 +01:00
progressView = new ProgressView(context);
2019-01-23 18:03:33 +01:00
timeText.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);
2016-03-16 13:26:32 +01:00
addView(progressView, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 3, 0, 12, 0, 0));
2019-01-23 18:03:33 +01:00
} else {
timeText.setPadding(0, AndroidUtilities.dp(2), 0, AndroidUtilities.dp(10));
timeText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15);
timeText.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL);
addView(timeText, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.TOP | Gravity.CENTER_HORIZONTAL));
2016-03-16 13:26:32 +01:00
}
2019-01-23 18:03:33 +01:00
problemText = new TextView(context) {
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(100), MeasureSpec.AT_MOST));
}
};
2017-03-31 01:58:05 +02:00
problemText.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlueText4));
2014-11-14 16:40:15 +01:00
problemText.setLineSpacing(AndroidUtilities.dp(2), 1.0f);
2019-01-23 18:03:33 +01:00
problemText.setPadding(0, AndroidUtilities.dp(2), 0, AndroidUtilities.dp(10));
problemText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15);
problemText.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.TOP);
if (currentType == 1) {
problemText.setText(LocaleController.getString("DidNotGetTheCodeSms", R.string.DidNotGetTheCodeSms));
} else {
problemText.setText(LocaleController.getString("DidNotGetTheCode", R.string.DidNotGetTheCode));
}
addView(problemText, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER_HORIZONTAL | Gravity.TOP));
2018-08-27 10:33:11 +02:00
problemText.setOnClickListener(v -> {
if (nextPressed) {
return;
}
2019-01-23 18:03:33 +01:00
boolean email = nextType == 4 && currentType == 2 || nextType == 0;
if (!email) {
if (doneProgressView.getTag() != null) {
return;
}
2018-08-27 10:33:11 +02:00
resendCode();
} else {
try {
PackageInfo pInfo = ApplicationLoader.applicationContext.getPackageManager().getPackageInfo(ApplicationLoader.applicationContext.getPackageName(), 0);
String version = String.format(Locale.US, "%s (%d)", pInfo.versionName, pInfo.versionCode);
Intent mailer = new Intent(Intent.ACTION_SEND);
mailer.setType("message/rfc822");
mailer.putExtra(Intent.EXTRA_EMAIL, new String[]{"sms@stel.com"});
mailer.putExtra(Intent.EXTRA_SUBJECT, "Android registration/login issue " + version + " " + emailPhone);
mailer.putExtra(Intent.EXTRA_TEXT, "Phone: " + requestPhone + "\nApp version: " + version + "\nOS version: SDK " + Build.VERSION.SDK_INT + "\nDevice Name: " + Build.MANUFACTURER + Build.MODEL + "\nLocale: " + Locale.getDefault() + "\nError: " + lastError);
getContext().startActivity(Intent.createChooser(mailer, "Send email..."));
} catch (Exception e) {
2020-06-25 17:29:04 +02:00
needShowAlert(LocaleController.getString("NekoX", R.string.NekoX), LocaleController.getString("NoMailInstalled", R.string.NoMailInstalled));
2014-11-14 16:40:15 +01:00
}
}
});
2019-01-23 18:03:33 +01:00
}
2014-11-14 16:40:15 +01:00
2019-01-23 18:03:33 +01:00
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
if (currentType != 3 && blueImageView != null) {
int innerHeight = blueImageView.getMeasuredHeight() + titleTextView.getMeasuredHeight() + confirmTextView.getMeasuredHeight() + AndroidUtilities.dp(18 + 17);
int requiredHeight = AndroidUtilities.dp(80);
int maxHeight = AndroidUtilities.dp(291);
if (scrollHeight - innerHeight < requiredHeight) {
setMeasuredDimension(getMeasuredWidth(), innerHeight + requiredHeight);
} else if (scrollHeight > maxHeight) {
setMeasuredDimension(getMeasuredWidth(), maxHeight);
} else {
setMeasuredDimension(getMeasuredWidth(), scrollHeight);
}
}
}
2014-11-14 16:40:15 +01:00
2019-01-23 18:03:33 +01:00
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
super.onLayout(changed, l, t, r, b);
if (currentType != 3 && blueImageView != null) {
int bottom = confirmTextView.getBottom();
int height = getMeasuredHeight() - bottom;
int h;
if (problemText.getVisibility() == VISIBLE) {
h = problemText.getMeasuredHeight();
t = bottom + height - h;
problemText.layout(problemText.getLeft(), t, problemText.getRight(), t + h);
} else if (timeText.getVisibility() == VISIBLE) {
h = timeText.getMeasuredHeight();
t = bottom + height - h;
timeText.layout(timeText.getLeft(), t, timeText.getRight(), t + h);
} else {
t = bottom + height;
}
2018-08-27 10:33:11 +02:00
2019-01-23 18:03:33 +01:00
height = t - bottom;
h = codeFieldContainer.getMeasuredHeight();
t = (height - h) / 2 + bottom;
codeFieldContainer.layout(codeFieldContainer.getLeft(), t, codeFieldContainer.getRight(), t + h);
}
2014-11-14 16:40:15 +01:00
}
2017-12-08 18:35:59 +01:00
@Override
public void onCancelPressed() {
nextPressed = false;
}
2016-03-16 13:26:32 +01:00
private void resendCode() {
final Bundle params = new Bundle();
params.putString("phone", phone);
params.putString("ephone", emailPhone);
params.putString("phoneFormated", requestPhone);
nextPressed = true;
TLRPC.TL_auth_resendCode req = new TLRPC.TL_auth_resendCode();
req.phone_number = requestPhone;
req.phone_code_hash = phoneHash;
2018-08-27 10:33:11 +02:00
int reqId = ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
nextPressed = false;
if (error == null) {
fillNextCodeParams(params, (TLRPC.TL_auth_sentCode) response);
} else {
if (error.text != null) {
if (error.text.contains("PHONE_NUMBER_INVALID")) {
2020-06-25 17:29:04 +02:00
needShowAlert(LocaleController.getString("NekoX", R.string.NekoX), LocaleController.getString("InvalidPhoneNumber", R.string.InvalidPhoneNumber));
2018-08-27 10:33:11 +02:00
} else if (error.text.contains("PHONE_CODE_EMPTY") || error.text.contains("PHONE_CODE_INVALID")) {
2020-06-25 17:29:04 +02:00
needShowAlert(LocaleController.getString("NekoX", R.string.NekoX), LocaleController.getString("InvalidCode", R.string.InvalidCode));
2018-08-27 10:33:11 +02:00
} else if (error.text.contains("PHONE_CODE_EXPIRED")) {
2019-01-23 18:03:33 +01:00
onBackPressed(true);
2018-08-27 10:33:11 +02:00
setPage(0, true, null, true);
2020-06-25 17:29:04 +02:00
needShowAlert(LocaleController.getString("NekoX", R.string.NekoX), LocaleController.getString("CodeExpired", R.string.CodeExpired));
2018-08-27 10:33:11 +02:00
} else if (error.text.startsWith("FLOOD_WAIT")) {
2020-06-25 17:29:04 +02:00
needShowAlert(LocaleController.getString("NekoX", R.string.NekoX), LocaleController.getString("FloodWait", R.string.FloodWait));
2018-08-27 10:33:11 +02:00
} else if (error.code != -1000) {
2020-06-25 17:29:04 +02:00
needShowAlert(LocaleController.getString("NekoX", R.string.NekoX), LocaleController.getString("ErrorOccurred", R.string.ErrorOccurred) + "\n" + error.text);
2016-03-16 13:26:32 +01:00
}
2018-08-27 10:33:11 +02:00
}
2016-03-16 13:26:32 +01:00
}
2019-01-23 18:03:33 +01:00
needHideProgress(false);
2018-08-27 10:33:11 +02:00
}), ConnectionsManager.RequestFlagFailOnServerErrors | ConnectionsManager.RequestFlagWithoutLogin);
2017-07-08 18:32:04 +02:00
needShowProgress(0);
2016-03-16 13:26:32 +01:00
}
2014-11-14 16:40:15 +01:00
@Override
public String getHeaderName() {
2019-01-23 18:03:33 +01:00
if (currentType == 1) {
return phone;
} else {
return LocaleController.getString("YourCode", R.string.YourCode);
}
}
@Override
public boolean needBackButton() {
return true;
2014-11-14 16:40:15 +01:00
}
@Override
2017-03-31 01:58:05 +02:00
public void setParams(Bundle params, boolean restore) {
2014-11-14 16:40:15 +01:00
if (params == null) {
return;
}
2016-03-16 13:26:32 +01:00
waitingForEvent = true;
if (currentType == 2) {
AndroidUtilities.setWaitingForSms(true);
2018-07-30 04:07:02 +02:00
NotificationCenter.getGlobalInstance().addObserver(this, NotificationCenter.didReceiveSmsCode);
2016-03-16 13:26:32 +01:00
} else if (currentType == 3) {
AndroidUtilities.setWaitingForCall(true);
2018-07-30 04:07:02 +02:00
NotificationCenter.getGlobalInstance().addObserver(this, NotificationCenter.didReceiveCall);
2016-03-16 13:26:32 +01:00
}
2014-11-14 16:40:15 +01:00
currentParams = params;
2016-03-16 13:26:32 +01:00
phone = params.getString("phone");
2015-03-26 18:34:47 +01:00
emailPhone = params.getString("ephone");
2014-11-14 16:40:15 +01:00
requestPhone = params.getString("phoneFormated");
phoneHash = params.getString("phoneHash");
2019-12-31 14:08:08 +01:00
time = params.getInt("timeout");
openTime = (int) (System.currentTimeMillis() / 1000);
2016-03-16 13:26:32 +01:00
nextType = params.getInt("nextType");
pattern = params.getString("pattern");
length = params.getInt("length");
2019-01-23 18:03:33 +01:00
if (length == 0) {
length = 5;
}
if (codeField == null || codeField.length != length) {
codeField = new EditTextBoldCursor[length];
for (int a = 0; a < length; a++) {
final int num = a;
codeField[a] = new EditTextBoldCursor(getContext());
codeField[a].setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
codeField[a].setCursorColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
codeField[a].setCursorSize(AndroidUtilities.dp(20));
codeField[a].setCursorWidth(1.5f);
Drawable pressedDrawable = getResources().getDrawable(R.drawable.search_dark_activated).mutate();
2020-06-25 17:29:04 +02:00
pressedDrawable.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_windowBackgroundWhiteInputFieldActivated), PorterDuff.Mode.SRC_IN));
2019-01-23 18:03:33 +01:00
codeField[a].setBackgroundDrawable(pressedDrawable);
codeField[a].setImeOptions(EditorInfo.IME_ACTION_NEXT | EditorInfo.IME_FLAG_NO_EXTRACT_UI);
codeField[a].setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20);
codeField[a].setMaxLines(1);
codeField[a].setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
codeField[a].setPadding(0, 0, 0, 0);
codeField[a].setGravity(Gravity.CENTER_HORIZONTAL | Gravity.TOP);
if (currentType == 3) {
codeField[a].setEnabled(false);
codeField[a].setInputType(InputType.TYPE_NULL);
codeField[a].setVisibility(GONE);
} else {
codeField[a].setInputType(InputType.TYPE_CLASS_PHONE);
}
codeFieldContainer.addView(codeField[a], LayoutHelper.createLinear(34, 36, Gravity.CENTER_HORIZONTAL, 0, 0, a != length - 1 ? 7 : 0, 0));
codeField[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) {
}
2016-03-16 13:26:32 +01:00
2019-01-23 18:03:33 +01:00
@Override
public void afterTextChanged(Editable s) {
if (ignoreOnTextChange) {
return;
}
int len = s.length();
if (len >= 1) {
if (len > 1) {
String text = s.toString();
ignoreOnTextChange = true;
for (int a = 0; a < Math.min(length - num, len); a++) {
if (a == 0) {
s.replace(0, len, text.substring(a, a + 1));
} else {
codeField[num + a].setText(text.substring(a, a + 1));
}
}
ignoreOnTextChange = false;
}
if (num != length - 1) {
codeField[num + 1].setSelection(codeField[num + 1].length());
codeField[num + 1].requestFocus();
}
if ((num == length - 1 || num == length - 2 && len >= 2) && getCode().length() == length) {
onNextPressed();
}
}
}
});
codeField[a].setOnKeyListener((v, keyCode, event) -> {
if (keyCode == KeyEvent.KEYCODE_DEL && codeField[num].length() == 0 && num > 0) {
codeField[num - 1].setSelection(codeField[num - 1].length());
codeField[num - 1].requestFocus();
codeField[num - 1].dispatchKeyEvent(event);
return true;
}
return false;
});
codeField[a].setOnEditorActionListener((textView, i, keyEvent) -> {
if (i == EditorInfo.IME_ACTION_NEXT) {
onNextPressed();
return true;
}
return false;
});
}
2016-03-16 13:26:32 +01:00
} else {
2019-01-23 18:03:33 +01:00
for (int a = 0; a < codeField.length; a++) {
codeField[a].setText("");
}
2016-03-16 13:26:32 +01:00
}
2019-01-23 18:03:33 +01:00
2016-03-16 13:26:32 +01:00
if (progressView != null) {
progressView.setVisibility(nextType != 0 ? VISIBLE : GONE);
}
2014-11-14 16:40:15 +01:00
if (phone == null) {
return;
}
String number = PhoneFormat.getInstance().format(phone);
2016-03-16 13:26:32 +01:00
CharSequence str = "";
if (currentType == 1) {
str = AndroidUtilities.replaceTags(LocaleController.getString("SentAppCode", R.string.SentAppCode));
} else if (currentType == 2) {
2018-07-30 04:07:02 +02:00
str = AndroidUtilities.replaceTags(LocaleController.formatString("SentSmsCode", R.string.SentSmsCode, LocaleController.addNbsp(number)));
2016-03-16 13:26:32 +01:00
} else if (currentType == 3) {
2018-07-30 04:07:02 +02:00
str = AndroidUtilities.replaceTags(LocaleController.formatString("SentCallCode", R.string.SentCallCode, LocaleController.addNbsp(number)));
2016-03-16 13:26:32 +01:00
} else if (currentType == 4) {
2018-07-30 04:07:02 +02:00
str = AndroidUtilities.replaceTags(LocaleController.formatString("SentCallOnly", R.string.SentCallOnly, LocaleController.addNbsp(number)));
2014-11-14 16:40:15 +01:00
}
2016-03-16 13:26:32 +01:00
confirmTextView.setText(str);
2014-11-14 16:40:15 +01:00
2016-03-16 13:26:32 +01:00
if (currentType != 3) {
2019-01-23 18:03:33 +01:00
AndroidUtilities.showKeyboard(codeField[0]);
codeField[0].requestFocus();
2016-03-16 13:26:32 +01:00
} else {
2019-01-23 18:03:33 +01:00
AndroidUtilities.hideKeyboard(codeField[0]);
2016-03-16 13:26:32 +01:00
}
2014-11-14 16:40:15 +01:00
destroyTimer();
destroyCodeTimer();
2016-03-16 13:26:32 +01:00
lastCurrentTime = System.currentTimeMillis();
if (currentType == 1) {
problemText.setVisibility(VISIBLE);
2016-03-06 02:49:31 +01:00
timeText.setVisibility(GONE);
2016-03-16 13:26:32 +01:00
} else if (currentType == 3 && (nextType == 4 || nextType == 2)) {
2016-03-06 02:49:31 +01:00
problemText.setVisibility(GONE);
2016-03-16 13:26:32 +01:00
timeText.setVisibility(VISIBLE);
if (nextType == 4) {
timeText.setText(LocaleController.formatString("CallText", R.string.CallText, 1, 0));
} else if (nextType == 2) {
timeText.setText(LocaleController.formatString("SmsText", R.string.SmsText, 1, 0));
}
2019-12-31 14:08:08 +01:00
String callLogNumber = restore ? AndroidUtilities.obtainLoginPhoneCall(pattern) : null;
2017-03-31 01:58:05 +02:00
if (callLogNumber != null) {
ignoreOnTextChange = true;
2019-01-23 18:03:33 +01:00
codeField[0].setText(callLogNumber);
2017-03-31 01:58:05 +02:00
ignoreOnTextChange = false;
onNextPressed();
} else if (catchedPhone != null) {
ignoreOnTextChange = true;
2019-01-23 18:03:33 +01:00
codeField[0].setText(catchedPhone);
2017-03-31 01:58:05 +02:00
ignoreOnTextChange = false;
onNextPressed();
} else {
createTimer();
}
2016-04-22 15:49:00 +02:00
} else if (currentType == 2 && (nextType == 4 || nextType == 3)) {
2016-03-16 13:26:32 +01:00
timeText.setText(LocaleController.formatString("CallText", R.string.CallText, 2, 0));
2016-03-06 02:49:31 +01:00
problemText.setVisibility(time < 1000 ? VISIBLE : GONE);
2019-01-23 18:03:33 +01:00
timeText.setVisibility(time < 1000 ? GONE : VISIBLE);
2020-06-25 17:29:04 +02:00
createTimer();
2019-01-23 18:03:33 +01:00
} else if (currentType == 4 && nextType == 2) {
timeText.setText(LocaleController.formatString("SmsText", R.string.SmsText, 2, 0));
problemText.setVisibility(time < 1000 ? VISIBLE : GONE);
timeText.setVisibility(time < 1000 ? GONE : VISIBLE);
2016-03-16 13:26:32 +01:00
createTimer();
} else {
timeText.setVisibility(GONE);
problemText.setVisibility(GONE);
createCodeTimer();
2016-03-06 02:49:31 +01:00
}
2014-11-14 16:40:15 +01:00
}
private void createCodeTimer() {
if (codeTimer != null) {
return;
}
codeTime = 15000;
codeTimer = new Timer();
lastCodeTime = System.currentTimeMillis();
codeTimer.schedule(new TimerTask() {
@Override
public void run() {
2018-08-27 10:33:11 +02:00
AndroidUtilities.runOnUIThread(() -> {
2019-01-23 18:03:33 +01:00
double currentTime = System.currentTimeMillis();
double diff = currentTime - lastCodeTime;
lastCodeTime = currentTime;
codeTime -= diff;
2018-08-27 10:33:11 +02:00
if (codeTime <= 1000) {
problemText.setVisibility(VISIBLE);
2019-01-23 18:03:33 +01:00
timeText.setVisibility(GONE);
2018-08-27 10:33:11 +02:00
destroyCodeTimer();
2014-11-14 16:40:15 +01:00
}
});
}
}, 0, 1000);
}
private void destroyCodeTimer() {
try {
2015-04-09 20:00:14 +02:00
synchronized (timerSync) {
2014-11-14 16:40:15 +01:00
if (codeTimer != null) {
codeTimer.cancel();
codeTimer = null;
}
}
} catch (Exception e) {
2017-03-31 01:58:05 +02:00
FileLog.e(e);
2014-11-14 16:40:15 +01:00
}
}
private void createTimer() {
2016-03-16 13:26:32 +01:00
if (timeTimer != null) {
2014-11-14 16:40:15 +01:00
return;
}
2019-12-31 14:08:08 +01:00
if (progressView != null) {
progressView.resetProgressAnimation();
}
2014-11-14 16:40:15 +01:00
timeTimer = new Timer();
timeTimer.schedule(new TimerTask() {
@Override
public void run() {
2016-03-16 13:26:32 +01:00
if (timeTimer == null) {
return;
}
2018-08-27 10:33:11 +02:00
AndroidUtilities.runOnUIThread(() -> {
2019-01-23 18:03:33 +01:00
final double currentTime = System.currentTimeMillis();
double diff = currentTime - lastCurrentTime;
lastCurrentTime = currentTime;
time -= diff;
2018-08-27 10:33:11 +02:00
if (time >= 1000) {
int minutes = time / 1000 / 60;
int seconds = time / 1000 - minutes * 60;
if (nextType == 4 || nextType == 3) {
timeText.setText(LocaleController.formatString("CallText", R.string.CallText, minutes, seconds));
} else if (nextType == 2) {
timeText.setText(LocaleController.formatString("SmsText", R.string.SmsText, minutes, seconds));
}
2019-12-31 14:08:08 +01:00
if (progressView != null && !progressView.isProgressAnimationRunning()) {
progressView.startProgressAnimation(time - 1000L);
2018-08-27 10:33:11 +02:00
}
} else {
destroyTimer();
if (currentType == 3) {
AndroidUtilities.setWaitingForCall(false);
2019-12-31 14:08:08 +01:00
NotificationCenter.getGlobalInstance().removeObserver(LoginActivitySmsView.this, NotificationCenter.didReceiveCall);
2018-08-27 10:33:11 +02:00
waitingForEvent = false;
destroyCodeTimer();
resendCode();
2019-01-23 18:03:33 +01:00
} else if (currentType == 2 || currentType == 4) {
if (nextType == 4 || nextType == 2) {
if (nextType == 4) {
timeText.setText(LocaleController.getString("Calling", R.string.Calling));
} else {
timeText.setText(LocaleController.getString("SendingSms", R.string.SendingSms));
}
2018-08-27 10:33:11 +02:00
createCodeTimer();
TLRPC.TL_auth_resendCode req = new TLRPC.TL_auth_resendCode();
req.phone_number = requestPhone;
req.phone_code_hash = phoneHash;
ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> {
if (error != null && error.text != null) {
AndroidUtilities.runOnUIThread(() -> lastError = error.text);
}
}, ConnectionsManager.RequestFlagFailOnServerErrors | ConnectionsManager.RequestFlagWithoutLogin);
} else if (nextType == 3) {
AndroidUtilities.setWaitingForSms(false);
2019-12-31 14:08:08 +01:00
NotificationCenter.getGlobalInstance().removeObserver(LoginActivitySmsView.this, NotificationCenter.didReceiveSmsCode);
2016-03-16 13:26:32 +01:00
waitingForEvent = false;
destroyCodeTimer();
resendCode();
}
2014-11-14 16:40:15 +01:00
}
}
});
}
}, 0, 1000);
}
private void destroyTimer() {
try {
2015-04-09 20:00:14 +02:00
synchronized (timerSync) {
2014-11-14 16:40:15 +01:00
if (timeTimer != null) {
timeTimer.cancel();
timeTimer = null;
}
}
} catch (Exception e) {
2017-03-31 01:58:05 +02:00
FileLog.e(e);
2014-11-14 16:40:15 +01:00
}
}
2019-01-23 18:03:33 +01:00
private String getCode() {
if (codeField == null) {
return "";
}
StringBuilder codeBuilder = new StringBuilder();
for (int a = 0; a < codeField.length; a++) {
codeBuilder.append(PhoneFormat.stripExceptNumbers(codeField[a].getText().toString()));
}
return codeBuilder.toString();
}
2014-11-14 16:40:15 +01:00
@Override
public void onNextPressed() {
2019-09-10 12:56:11 +02:00
if (nextPressed || currentViewNum < 1 || currentViewNum > 4) {
2014-11-14 16:40:15 +01:00
return;
}
2019-01-23 18:03:33 +01:00
String code = getCode();
if (TextUtils.isEmpty(code)) {
2019-12-31 14:08:08 +01:00
onFieldError(codeFieldContainer);
2019-01-23 18:03:33 +01:00
return;
}
2014-11-14 16:40:15 +01:00
nextPressed = true;
2016-03-16 13:26:32 +01:00
if (currentType == 2) {
AndroidUtilities.setWaitingForSms(false);
2018-07-30 04:07:02 +02:00
NotificationCenter.getGlobalInstance().removeObserver(this, NotificationCenter.didReceiveSmsCode);
2016-03-16 13:26:32 +01:00
} else if (currentType == 3) {
AndroidUtilities.setWaitingForCall(false);
2018-07-30 04:07:02 +02:00
NotificationCenter.getGlobalInstance().removeObserver(this, NotificationCenter.didReceiveCall);
2016-03-16 13:26:32 +01:00
}
waitingForEvent = false;
2014-11-14 16:40:15 +01:00
final TLRPC.TL_auth_signIn req = new TLRPC.TL_auth_signIn();
req.phone_number = requestPhone;
2017-03-31 01:58:05 +02:00
req.phone_code = code;
2014-11-14 16:40:15 +01:00
req.phone_code_hash = phoneHash;
destroyTimer();
2018-08-27 10:33:11 +02:00
int reqId = ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
boolean ok = false;
if (error == null) {
2019-09-10 12:56:11 +02:00
nextPressed = false;
2018-08-27 10:33:11 +02:00
ok = true;
2019-12-31 14:08:08 +01:00
showDoneButton(false, true);
2018-08-27 10:33:11 +02:00
destroyTimer();
destroyCodeTimer();
2019-08-22 01:53:26 +02:00
if (response instanceof TLRPC.TL_auth_authorizationSignUpRequired) {
TLRPC.TL_auth_authorizationSignUpRequired authorization = (TLRPC.TL_auth_authorizationSignUpRequired) response;
if (authorization.terms_of_service != null) {
currentTermsOfService = authorization.terms_of_service;
}
2018-08-27 10:33:11 +02:00
Bundle params = new Bundle();
params.putString("phoneFormated", requestPhone);
params.putString("phoneHash", phoneHash);
params.putString("code", req.phone_code);
setPage(5, true, params, false);
2019-08-22 01:53:26 +02:00
} else {
onAuthSuccess((TLRPC.TL_auth_authorization) response);
}
} else {
lastError = error.text;
if (error.text.contains("SESSION_PASSWORD_NEEDED")) {
2018-08-27 10:33:11 +02:00
ok = true;
TLRPC.TL_account_getPassword req2 = new TLRPC.TL_account_getPassword();
ConnectionsManager.getInstance(currentAccount).sendRequest(req2, (response1, error1) -> AndroidUtilities.runOnUIThread(() -> {
2019-09-10 12:56:11 +02:00
nextPressed = false;
2019-12-31 14:08:08 +01:00
showDoneButton(false, true);
2018-08-27 10:33:11 +02:00
if (error1 == null) {
TLRPC.TL_account_password password = (TLRPC.TL_account_password) response1;
if (!TwoStepVerificationActivity.canHandleCurrentPassword(password, true)) {
AlertsCreator.showUpdateAppAlert(getParentActivity(), LocaleController.getString("UpdateAppAlert", R.string.UpdateAppAlert), true);
return;
2014-11-14 16:40:15 +01:00
}
2018-08-27 10:33:11 +02:00
Bundle bundle = new Bundle();
if (password.current_algo instanceof TLRPC.TL_passwordKdfAlgoSHA256SHA256PBKDF2HMACSHA512iter100000SHA256ModPow) {
TLRPC.TL_passwordKdfAlgoSHA256SHA256PBKDF2HMACSHA512iter100000SHA256ModPow algo = (TLRPC.TL_passwordKdfAlgoSHA256SHA256PBKDF2HMACSHA512iter100000SHA256ModPow) password.current_algo;
bundle.putString("current_salt1", Utilities.bytesToHex(algo.salt1));
bundle.putString("current_salt2", Utilities.bytesToHex(algo.salt2));
bundle.putString("current_p", Utilities.bytesToHex(algo.p));
bundle.putInt("current_g", algo.g);
bundle.putString("current_srp_B", Utilities.bytesToHex(password.srp_B));
bundle.putLong("current_srp_id", password.srp_id);
bundle.putInt("passwordType", 1);
2017-03-31 01:58:05 +02:00
}
2018-08-27 10:33:11 +02:00
bundle.putString("hint", password.hint != null ? password.hint : "");
bundle.putString("email_unconfirmed_pattern", password.email_unconfirmed_pattern != null ? password.email_unconfirmed_pattern : "");
bundle.putString("phoneFormated", requestPhone);
bundle.putString("phoneHash", phoneHash);
bundle.putString("code", req.phone_code);
bundle.putInt("has_recovery", password.has_recovery ? 1 : 0);
setPage(6, true, bundle, false);
} else {
2020-06-25 17:29:04 +02:00
needShowAlert(LocaleController.getString("NekoX", R.string.NekoX), error1.text);
2017-03-31 01:58:05 +02:00
}
2018-08-27 10:33:11 +02:00
}), ConnectionsManager.RequestFlagFailOnServerErrors | ConnectionsManager.RequestFlagWithoutLogin);
destroyTimer();
destroyCodeTimer();
} else {
2019-12-31 14:08:08 +01:00
nextPressed = false;
showDoneButton(false, true);
2019-01-23 18:03:33 +01:00
if (currentType == 3 && (nextType == 4 || nextType == 2) || currentType == 2 && (nextType == 4 || nextType == 3) || currentType == 4 && nextType == 2) {
2018-08-27 10:33:11 +02:00
createTimer();
2014-11-14 16:40:15 +01:00
}
2018-08-27 10:33:11 +02:00
if (currentType == 2) {
AndroidUtilities.setWaitingForSms(true);
NotificationCenter.getGlobalInstance().addObserver(LoginActivitySmsView.this, NotificationCenter.didReceiveSmsCode);
} else if (currentType == 3) {
AndroidUtilities.setWaitingForCall(true);
NotificationCenter.getGlobalInstance().addObserver(LoginActivitySmsView.this, NotificationCenter.didReceiveCall);
}
waitingForEvent = true;
if (currentType != 3) {
if (error.text.contains("PHONE_NUMBER_INVALID")) {
2020-06-25 17:29:04 +02:00
needShowAlert(LocaleController.getString("NekoX", R.string.NekoX), LocaleController.getString("InvalidPhoneNumber", R.string.InvalidPhoneNumber));
2018-08-27 10:33:11 +02:00
} else if (error.text.contains("PHONE_CODE_EMPTY") || error.text.contains("PHONE_CODE_INVALID")) {
2020-06-25 17:29:04 +02:00
needShowAlert(LocaleController.getString("NekoX", R.string.NekoX), LocaleController.getString("InvalidCode", R.string.InvalidCode));
2019-01-23 18:03:33 +01:00
for (int a = 0; a < codeField.length; a++) {
codeField[a].setText("");
}
codeField[0].requestFocus();
2018-08-27 10:33:11 +02:00
} else if (error.text.contains("PHONE_CODE_EXPIRED")) {
2019-01-23 18:03:33 +01:00
onBackPressed(true);
2018-08-27 10:33:11 +02:00
setPage(0, true, null, true);
2020-06-25 17:29:04 +02:00
needShowAlert(LocaleController.getString("NekoX", R.string.NekoX), LocaleController.getString("CodeExpired", R.string.CodeExpired));
2018-08-27 10:33:11 +02:00
} else if (error.text.startsWith("FLOOD_WAIT")) {
2020-06-25 17:29:04 +02:00
needShowAlert(LocaleController.getString("NekoX", R.string.NekoX), LocaleController.getString("FloodWait", R.string.FloodWait));
2018-08-27 10:33:11 +02:00
} else {
2020-06-25 17:29:04 +02:00
needShowAlert(LocaleController.getString("NekoX", R.string.NekoX), LocaleController.getString("ErrorOccurred", R.string.ErrorOccurred) + "\n" + error.text);
2018-08-27 10:33:11 +02:00
}
}
}
}
if (ok) {
if (currentType == 3) {
AndroidUtilities.endIncomingCall();
}
2014-11-14 16:40:15 +01:00
}
2018-08-27 10:33:11 +02:00
}), ConnectionsManager.RequestFlagFailOnServerErrors | ConnectionsManager.RequestFlagWithoutLogin);
2019-12-31 14:08:08 +01:00
needShowProgress(reqId, false);
showDoneButton(true, true);
2014-11-14 16:40:15 +01:00
}
@Override
2019-01-23 18:03:33 +01:00
public boolean onBackPressed(boolean force) {
if (!force) {
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
2020-01-08 18:08:16 +01:00
builder.setTitle(LocaleController.getString("NekogramWithEmoji", R.string.NekogramWithEmoji));
2019-01-23 18:03:33 +01:00
builder.setMessage(LocaleController.getString("StopVerification", R.string.StopVerification));
builder.setPositiveButton(LocaleController.getString("Continue", R.string.Continue), null);
builder.setNegativeButton(LocaleController.getString("Stop", R.string.Stop), (dialogInterface, i) -> {
onBackPressed(true);
setPage(0, true, null, true);
});
showDialog(builder.create());
return false;
}
nextPressed = false;
needHideProgress(true);
TLRPC.TL_auth_cancelCode req = new TLRPC.TL_auth_cancelCode();
req.phone_number = requestPhone;
req.phone_code_hash = phoneHash;
ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> {
}, ConnectionsManager.RequestFlagFailOnServerErrors | ConnectionsManager.RequestFlagWithoutLogin);
2014-11-14 16:40:15 +01:00
destroyTimer();
destroyCodeTimer();
currentParams = null;
2016-03-16 13:26:32 +01:00
if (currentType == 2) {
AndroidUtilities.setWaitingForSms(false);
2018-07-30 04:07:02 +02:00
NotificationCenter.getGlobalInstance().removeObserver(this, NotificationCenter.didReceiveSmsCode);
2016-03-16 13:26:32 +01:00
} else if (currentType == 3) {
AndroidUtilities.setWaitingForCall(false);
2018-07-30 04:07:02 +02:00
NotificationCenter.getGlobalInstance().removeObserver(this, NotificationCenter.didReceiveCall);
2016-03-16 13:26:32 +01:00
}
waitingForEvent = false;
2019-01-23 18:03:33 +01:00
return true;
2014-11-14 16:40:15 +01:00
}
@Override
public void onDestroyActivity() {
super.onDestroyActivity();
2016-03-16 13:26:32 +01:00
if (currentType == 2) {
AndroidUtilities.setWaitingForSms(false);
2018-07-30 04:07:02 +02:00
NotificationCenter.getGlobalInstance().removeObserver(this, NotificationCenter.didReceiveSmsCode);
2016-03-16 13:26:32 +01:00
} else if (currentType == 3) {
AndroidUtilities.setWaitingForCall(false);
2018-07-30 04:07:02 +02:00
NotificationCenter.getGlobalInstance().removeObserver(this, NotificationCenter.didReceiveCall);
2016-03-16 13:26:32 +01:00
}
waitingForEvent = false;
2014-11-14 16:40:15 +01:00
destroyTimer();
destroyCodeTimer();
}
@Override
public void onShow() {
super.onShow();
2018-07-30 04:07:02 +02:00
if (currentType == 3) {
return;
2014-11-14 16:40:15 +01:00
}
2018-08-27 10:33:11 +02:00
AndroidUtilities.runOnUIThread(() -> {
if (codeField != null) {
2019-01-23 18:03:33 +01:00
for (int a = codeField.length - 1; a >= 0; a--) {
if (a == 0 || codeField[a].length() != 0) {
codeField[a].requestFocus();
codeField[a].setSelection(codeField[a].length());
AndroidUtilities.showKeyboard(codeField[a]);
break;
}
}
2018-07-30 04:07:02 +02:00
}
}, 100);
2014-11-14 16:40:15 +01:00
}
@Override
2018-07-30 04:07:02 +02:00
public void didReceivedNotification(int id, int account, Object... args) {
2016-03-16 13:26:32 +01:00
if (!waitingForEvent || codeField == null) {
return;
}
2014-11-14 16:40:15 +01:00
if (id == NotificationCenter.didReceiveSmsCode) {
2019-01-23 18:03:33 +01:00
codeField[0].setText("" + args[0]);
2016-03-16 13:26:32 +01:00
onNextPressed();
} else if (id == NotificationCenter.didReceiveCall) {
String num = "" + args[0];
2017-03-31 01:58:05 +02:00
if (!AndroidUtilities.checkPhonePattern(pattern, num)) {
return;
}
2016-03-16 13:26:32 +01:00
if (!pattern.equals("*")) {
2017-03-31 01:58:05 +02:00
catchedPhone = num;
AndroidUtilities.endIncomingCall();
2015-05-21 23:27:27 +02:00
}
2016-03-16 13:26:32 +01:00
ignoreOnTextChange = true;
2019-01-23 18:03:33 +01:00
codeField[0].setText(num);
2016-03-16 13:26:32 +01:00
ignoreOnTextChange = false;
onNextPressed();
2014-11-14 16:40:15 +01:00
}
}
@Override
public void saveStateParams(Bundle bundle) {
2019-01-23 18:03:33 +01:00
String code = getCode();
2015-09-24 22:52:02 +02:00
if (code.length() != 0) {
2016-03-16 13:26:32 +01:00
bundle.putString("smsview_code_" + currentType, code);
2014-11-14 16:40:15 +01:00
}
2017-03-31 01:58:05 +02:00
if (catchedPhone != null) {
bundle.putString("catchedPhone", catchedPhone);
}
2014-11-14 16:40:15 +01:00
if (currentParams != null) {
2016-03-16 13:26:32 +01:00
bundle.putBundle("smsview_params_" + currentType, currentParams);
2014-11-14 16:40:15 +01:00
}
if (time != 0) {
bundle.putInt("time", time);
}
if (openTime != 0) {
bundle.putInt("open", openTime);
}
2014-11-14 16:40:15 +01:00
}
@Override
public void restoreStateParams(Bundle bundle) {
2016-03-16 13:26:32 +01:00
currentParams = bundle.getBundle("smsview_params_" + currentType);
2014-11-14 16:40:15 +01:00
if (currentParams != null) {
2017-03-31 01:58:05 +02:00
setParams(currentParams, true);
}
String catched = bundle.getString("catchedPhone");
if (catched != null) {
catchedPhone = catched;
2014-11-14 16:40:15 +01:00
}
2016-03-16 13:26:32 +01:00
String code = bundle.getString("smsview_code_" + currentType);
2019-01-23 18:03:33 +01:00
if (code != null && codeField != null) {
codeField[0].setText(code);
2014-11-14 16:40:15 +01:00
}
int t = bundle.getInt("time");
2014-11-14 16:40:15 +01:00
if (t != 0) {
time = t;
}
int t2 = bundle.getInt("open");
if (t2 != 0) {
openTime = t2;
}
2014-11-14 16:40:15 +01:00
}
}
2015-04-09 20:00:14 +02:00
public class LoginActivityPasswordView extends SlideView {
2017-12-08 18:35:59 +01:00
private EditTextBoldCursor codeField;
2015-04-09 20:00:14 +02:00
private TextView confirmTextView;
private TextView resetAccountButton;
private TextView resetAccountText;
2017-03-31 01:58:05 +02:00
private TextView cancelButton;
2015-04-09 20:00:14 +02:00
private Bundle currentParams;
private boolean nextPressed;
2018-08-27 10:33:11 +02:00
private byte[] current_salt1;
private byte[] current_salt2;
private int current_g;
private long current_srp_id;
private byte[] current_srp_B;
private byte[] current_p;
private int passwordType;
2015-04-09 20:00:14 +02:00
private boolean has_recovery;
private String requestPhone;
private String phoneHash;
private String phoneCode;
public LoginActivityPasswordView(Context context) {
super(context);
setOrientation(VERTICAL);
confirmTextView = new TextView(context);
2017-03-31 01:58:05 +02:00
confirmTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteGrayText6));
2015-04-09 20:00:14 +02:00
confirmTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
confirmTextView.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);
2015-04-09 20:00:14 +02:00
confirmTextView.setLineSpacing(AndroidUtilities.dp(2), 1.0f);
confirmTextView.setText(LocaleController.getString("LoginPasswordText", R.string.LoginPasswordText));
2015-11-26 22:04:02 +01:00
addView(confirmTextView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT));
2015-04-09 20:00:14 +02:00
codeField = new EditTextAutoFill(context);
2017-03-31 01:58:05 +02:00
codeField.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
2017-12-08 18:35:59 +01:00
codeField.setCursorColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
codeField.setCursorSize(AndroidUtilities.dp(20));
codeField.setCursorWidth(1.5f);
2017-03-31 01:58:05 +02:00
codeField.setHintTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteHintText));
codeField.setBackgroundDrawable(Theme.createEditTextDrawable(context, false));
2015-04-09 20:00:14 +02:00
codeField.setHint(LocaleController.getString("LoginPassword", R.string.LoginPassword));
codeField.setImeOptions(EditorInfo.IME_ACTION_NEXT | EditorInfo.IME_FLAG_NO_EXTRACT_UI);
codeField.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
codeField.setMaxLines(1);
codeField.setPadding(0, 0, 0, 0);
codeField.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
codeField.setTransformationMethod(PasswordTransformationMethod.getInstance());
codeField.setTypeface(Typeface.DEFAULT);
codeField.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);
2015-11-26 22:04:02 +01:00
addView(codeField, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 36, Gravity.CENTER_HORIZONTAL, 0, 20, 0, 0));
2018-08-27 10:33:11 +02:00
codeField.setOnEditorActionListener((textView, i, keyEvent) -> {
if (i == EditorInfo.IME_ACTION_NEXT) {
onNextPressed();
return true;
2015-04-09 20:00:14 +02:00
}
2018-08-27 10:33:11 +02:00
return false;
2015-04-09 20:00:14 +02:00
});
2017-03-31 01:58:05 +02:00
cancelButton = new TextView(context);
cancelButton.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP);
2017-03-31 01:58:05 +02:00
cancelButton.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlueText4));
2015-04-09 20:00:14 +02:00
cancelButton.setText(LocaleController.getString("ForgotPassword", R.string.ForgotPassword));
cancelButton.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
cancelButton.setLineSpacing(AndroidUtilities.dp(2), 1.0f);
cancelButton.setPadding(0, AndroidUtilities.dp(14), 0, 0);
2018-07-30 04:07:02 +02:00
addView(cancelButton, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.TOP | (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT)));
2018-08-27 10:33:11 +02:00
cancelButton.setOnClickListener(view -> {
2019-01-23 18:03:33 +01:00
if (doneProgressView.getTag() != null) {
return;
}
2018-08-27 10:33:11 +02:00
if (has_recovery) {
needShowProgress(0);
TLRPC.TL_auth_requestPasswordRecovery req = new TLRPC.TL_auth_requestPasswordRecovery();
ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
2019-01-23 18:03:33 +01:00
needHideProgress(false);
2018-08-27 10:33:11 +02:00
if (error == null) {
final TLRPC.TL_auth_passwordRecovery res = (TLRPC.TL_auth_passwordRecovery) response;
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setMessage(LocaleController.formatString("RestoreEmailSent", R.string.RestoreEmailSent, res.email_pattern));
2019-12-31 14:08:08 +01:00
builder.setTitle(LocaleController.getString("RestoreEmailSentTitle", R.string.RestoreEmailSentTitle));
2018-08-27 10:33:11 +02:00
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), (dialogInterface, i) -> {
Bundle bundle = new Bundle();
bundle.putString("email_unconfirmed_pattern", res.email_pattern);
setPage(7, true, bundle, false);
});
Dialog dialog = showDialog(builder.create());
if (dialog != null) {
dialog.setCanceledOnTouchOutside(false);
dialog.setCancelable(false);
2015-04-09 20:00:14 +02:00
}
2018-08-27 10:33:11 +02:00
} else {
if (error.text.startsWith("FLOOD_WAIT")) {
int time = Utilities.parseInt(error.text);
String timeString;
if (time < 60) {
timeString = LocaleController.formatPluralString("Seconds", time);
} else {
timeString = LocaleController.formatPluralString("Minutes", time / 60);
}
2020-06-25 17:29:04 +02:00
needShowAlert(LocaleController.getString("NekoX", R.string.NekoX), LocaleController.formatString("FloodWaitTime", R.string.FloodWaitTime, timeString));
2018-08-27 10:33:11 +02:00
} else {
2020-06-25 17:29:04 +02:00
needShowAlert(LocaleController.getString("NekoX", R.string.NekoX), error.text);
2018-08-27 10:33:11 +02:00
}
}
}), ConnectionsManager.RequestFlagFailOnServerErrors | ConnectionsManager.RequestFlagWithoutLogin);
} else {
resetAccountText.setVisibility(VISIBLE);
resetAccountButton.setVisibility(VISIBLE);
AndroidUtilities.hideKeyboard(codeField);
needShowAlert(LocaleController.getString("RestorePasswordNoEitle", R.string.RestorePasswordNoEmailTitle), LocaleController.getString("RestorePasswordNoEmailText", R.string.RestorePasswordNoEmailText));
2015-04-09 20:00:14 +02:00
}
});
resetAccountButton = new TextView(context);
resetAccountButton.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP);
2017-03-31 01:58:05 +02:00
resetAccountButton.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteRedText6));
2015-04-09 20:00:14 +02:00
resetAccountButton.setVisibility(GONE);
resetAccountButton.setText(LocaleController.getString("ResetMyAccount", R.string.ResetMyAccount));
resetAccountButton.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
resetAccountButton.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
resetAccountButton.setLineSpacing(AndroidUtilities.dp(2), 1.0f);
resetAccountButton.setPadding(0, AndroidUtilities.dp(14), 0, 0);
2015-11-26 22:04:02 +01:00
addView(resetAccountButton, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.TOP | (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT), 0, 34, 0, 0));
2018-08-27 10:33:11 +02:00
resetAccountButton.setOnClickListener(view -> {
2019-01-23 18:03:33 +01:00
if (doneProgressView.getTag() != null) {
return;
}
2018-08-27 10:33:11 +02:00
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setMessage(LocaleController.getString("ResetMyAccountWarningText", R.string.ResetMyAccountWarningText));
builder.setTitle(LocaleController.getString("ResetMyAccountWarning", R.string.ResetMyAccountWarning));
builder.setPositiveButton(LocaleController.getString("ResetMyAccountWarningReset", R.string.ResetMyAccountWarningReset), (dialogInterface, i) -> {
needShowProgress(0);
TLRPC.TL_account_deleteAccount req = new TLRPC.TL_account_deleteAccount();
req.reason = "Forgot password";
ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
2019-01-23 18:03:33 +01:00
needHideProgress(false);
2018-08-27 10:33:11 +02:00
if (error == null) {
Bundle params = new Bundle();
params.putString("phoneFormated", requestPhone);
params.putString("phoneHash", phoneHash);
params.putString("code", phoneCode);
setPage(5, true, params, false);
} else {
if (error.text.equals("2FA_RECENT_CONFIRM")) {
2020-06-25 17:29:04 +02:00
needShowAlert(LocaleController.getString("NekoX", R.string.NekoX), LocaleController.getString("ResetAccountCancelledAlert", R.string.ResetAccountCancelledAlert));
2018-08-27 10:33:11 +02:00
} else if (error.text.startsWith("2FA_CONFIRM_WAIT_")) {
Bundle params = new Bundle();
params.putString("phoneFormated", requestPhone);
params.putString("phoneHash", phoneHash);
params.putString("code", phoneCode);
params.putInt("startTime", ConnectionsManager.getInstance(currentAccount).getCurrentTime());
params.putInt("waitTime", Utilities.parseInt(error.text.replace("2FA_CONFIRM_WAIT_", "")));
setPage(8, true, params, false);
} else {
2020-06-25 17:29:04 +02:00
needShowAlert(LocaleController.getString("NekoX", R.string.NekoX), error.text);
2018-08-27 10:33:11 +02:00
}
2015-04-09 20:00:14 +02:00
}
2018-08-27 10:33:11 +02:00
}), ConnectionsManager.RequestFlagWithoutLogin | ConnectionsManager.RequestFlagFailOnServerErrors);
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
showDialog(builder.create());
2015-04-09 20:00:14 +02:00
});
resetAccountText = new TextView(context);
resetAccountText.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP);
2015-04-09 20:00:14 +02:00
resetAccountText.setVisibility(GONE);
2017-03-31 01:58:05 +02:00
resetAccountText.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteGrayText6));
2015-04-09 20:00:14 +02:00
resetAccountText.setText(LocaleController.getString("ResetMyAccountText", R.string.ResetMyAccountText));
resetAccountText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
resetAccountText.setLineSpacing(AndroidUtilities.dp(2), 1.0f);
2015-11-26 22:04:02 +01:00
addView(resetAccountText, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.TOP | (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT), 0, 7, 0, 14));
2015-04-09 20:00:14 +02:00
}
@Override
public String getHeaderName() {
return LocaleController.getString("LoginPassword", R.string.LoginPassword);
}
2017-12-08 18:35:59 +01:00
@Override
public void onCancelPressed() {
nextPressed = false;
}
2015-04-09 20:00:14 +02:00
@Override
2017-03-31 01:58:05 +02:00
public void setParams(Bundle params, boolean restore) {
2015-04-09 20:00:14 +02:00
if (params == null) {
return;
}
if (params.isEmpty()) {
resetAccountButton.setVisibility(VISIBLE);
resetAccountText.setVisibility(VISIBLE);
AndroidUtilities.hideKeyboard(codeField);
return;
}
resetAccountButton.setVisibility(GONE);
resetAccountText.setVisibility(GONE);
codeField.setText("");
currentParams = params;
2018-08-27 10:33:11 +02:00
current_salt1 = Utilities.hexToBytes(currentParams.getString("current_salt1"));
current_salt2 = Utilities.hexToBytes(currentParams.getString("current_salt2"));
current_p = Utilities.hexToBytes(currentParams.getString("current_p"));
current_g = currentParams.getInt("current_g");
current_srp_B = Utilities.hexToBytes(currentParams.getString("current_srp_B"));
current_srp_id = currentParams.getLong("current_srp_id");
passwordType = currentParams.getInt("passwordType");
2019-12-31 14:08:08 +01:00
String hint = currentParams.getString("hint");
2015-04-09 20:00:14 +02:00
has_recovery = currentParams.getInt("has_recovery") == 1;
requestPhone = params.getString("phoneFormated");
phoneHash = params.getString("phoneHash");
phoneCode = params.getString("code");
if (hint != null && hint.length() > 0) {
codeField.setHint(hint);
} else {
codeField.setHint(LocaleController.getString("LoginPassword", R.string.LoginPassword));
}
}
private void onPasscodeError(boolean clear) {
if (getParentActivity() == null) {
return;
}
if (clear) {
codeField.setText("");
}
2019-12-31 14:08:08 +01:00
onFieldError(confirmTextView);
2015-04-09 20:00:14 +02:00
}
@Override
public void onNextPressed() {
if (nextPressed) {
return;
}
String oldPassword = codeField.getText().toString();
if (oldPassword.length() == 0) {
onPasscodeError(false);
return;
}
nextPressed = true;
2017-07-08 18:32:04 +02:00
needShowProgress(0);
2018-08-27 10:33:11 +02:00
Utilities.globalQueue.postRunnable(() -> {
2019-07-18 15:01:39 +02:00
final byte[] x_bytes;
2018-08-27 10:33:11 +02:00
2019-12-31 14:08:08 +01:00
TLRPC.PasswordKdfAlgo current_algo;
2018-08-27 10:33:11 +02:00
if (passwordType == 1) {
TLRPC.TL_passwordKdfAlgoSHA256SHA256PBKDF2HMACSHA512iter100000SHA256ModPow algo = new TLRPC.TL_passwordKdfAlgoSHA256SHA256PBKDF2HMACSHA512iter100000SHA256ModPow();
algo.salt1 = current_salt1;
algo.salt2 = current_salt2;
algo.g = current_g;
algo.p = current_p;
current_algo = algo;
2019-12-31 14:08:08 +01:00
} else {
current_algo = new TLRPC.TL_passwordKdfAlgoUnknown();
2018-08-27 10:33:11 +02:00
}
if (current_algo instanceof TLRPC.TL_passwordKdfAlgoSHA256SHA256PBKDF2HMACSHA512iter100000SHA256ModPow) {
byte[] passwordBytes = AndroidUtilities.getStringBytes(oldPassword);
TLRPC.TL_passwordKdfAlgoSHA256SHA256PBKDF2HMACSHA512iter100000SHA256ModPow algo = (TLRPC.TL_passwordKdfAlgoSHA256SHA256PBKDF2HMACSHA512iter100000SHA256ModPow) current_algo;
x_bytes = SRPHelper.getX(passwordBytes, algo);
} else {
x_bytes = null;
}
final TLRPC.TL_auth_checkPassword req = new TLRPC.TL_auth_checkPassword();
RequestDelegate requestDelegate = (response, error) -> AndroidUtilities.runOnUIThread(() -> {
nextPressed = false;
if (error != null && "SRP_ID_INVALID".equals(error.text)) {
TLRPC.TL_account_getPassword getPasswordReq = new TLRPC.TL_account_getPassword();
ConnectionsManager.getInstance(currentAccount).sendRequest(getPasswordReq, (response2, error2) -> AndroidUtilities.runOnUIThread(() -> {
if (error2 == null) {
TLRPC.TL_account_password password = (TLRPC.TL_account_password) response2;
current_srp_B = password.srp_B;
current_srp_id = password.srp_id;
onNextPressed();
}
}), ConnectionsManager.RequestFlagWithoutLogin);
return;
}
2019-12-31 14:08:08 +01:00
2019-08-22 01:53:26 +02:00
if (response instanceof TLRPC.TL_auth_authorization) {
2019-12-31 14:08:08 +01:00
showDoneButton(false, true);
postDelayed(() -> {
needHideProgress(false, false);
AndroidUtilities.hideKeyboard(codeField);
onAuthSuccess((TLRPC.TL_auth_authorization) response);
}, 150);
2018-08-27 10:33:11 +02:00
} else {
2019-12-31 14:08:08 +01:00
needHideProgress(false);
2018-08-27 10:33:11 +02:00
if (error.text.equals("PASSWORD_HASH_INVALID")) {
onPasscodeError(true);
} else if (error.text.startsWith("FLOOD_WAIT")) {
int time = Utilities.parseInt(error.text);
String timeString;
if (time < 60) {
timeString = LocaleController.formatPluralString("Seconds", time);
2015-04-09 20:00:14 +02:00
} else {
2018-08-27 10:33:11 +02:00
timeString = LocaleController.formatPluralString("Minutes", time / 60);
2015-04-09 20:00:14 +02:00
}
2020-06-25 17:29:04 +02:00
needShowAlert(LocaleController.getString("NekoX", R.string.NekoX), LocaleController.formatString("FloodWaitTime", R.string.FloodWaitTime, timeString));
2018-08-27 10:33:11 +02:00
} else {
2020-06-25 17:29:04 +02:00
needShowAlert(LocaleController.getString("NekoX", R.string.NekoX), error.text);
2015-04-09 20:00:14 +02:00
}
2018-08-27 10:33:11 +02:00
}
});
if (current_algo instanceof TLRPC.TL_passwordKdfAlgoSHA256SHA256PBKDF2HMACSHA512iter100000SHA256ModPow) {
TLRPC.TL_passwordKdfAlgoSHA256SHA256PBKDF2HMACSHA512iter100000SHA256ModPow algo = (TLRPC.TL_passwordKdfAlgoSHA256SHA256PBKDF2HMACSHA512iter100000SHA256ModPow) current_algo;
algo.salt1 = current_salt1;
algo.salt2 = current_salt2;
algo.g = current_g;
algo.p = current_p;
req.password = SRPHelper.startCheck(x_bytes, current_srp_id, current_srp_B, algo);
if (req.password == null) {
TLRPC.TL_error error = new TLRPC.TL_error();
error.text = "PASSWORD_HASH_INVALID";
requestDelegate.run(null, error);
return;
}
ConnectionsManager.getInstance(currentAccount).sendRequest(req, requestDelegate, ConnectionsManager.RequestFlagFailOnServerErrors | ConnectionsManager.RequestFlagWithoutLogin);
2015-04-09 20:00:14 +02:00
}
2018-08-27 10:33:11 +02:00
});
2015-04-09 20:00:14 +02:00
}
@Override
public boolean needBackButton() {
return true;
}
@Override
2019-01-23 18:03:33 +01:00
public boolean onBackPressed(boolean force) {
nextPressed = false;
needHideProgress(true);
2015-04-09 20:00:14 +02:00
currentParams = null;
2019-01-23 18:03:33 +01:00
return true;
2015-04-09 20:00:14 +02:00
}
@Override
public void onShow() {
super.onShow();
2018-08-27 10:33:11 +02:00
AndroidUtilities.runOnUIThread(() -> {
if (codeField != null) {
codeField.requestFocus();
codeField.setSelection(codeField.length());
AndroidUtilities.showKeyboard(codeField);
2018-07-30 04:07:02 +02:00
}
}, 100);
2015-04-09 20:00:14 +02:00
}
@Override
public void saveStateParams(Bundle bundle) {
String code = codeField.getText().toString();
2015-09-24 22:52:02 +02:00
if (code.length() != 0) {
2015-04-09 20:00:14 +02:00
bundle.putString("passview_code", code);
}
if (currentParams != null) {
bundle.putBundle("passview_params", currentParams);
}
}
@Override
public void restoreStateParams(Bundle bundle) {
currentParams = bundle.getBundle("passview_params");
if (currentParams != null) {
2017-03-31 01:58:05 +02:00
setParams(currentParams, true);
2015-04-09 20:00:14 +02:00
}
String code = bundle.getString("passview_code");
if (code != null) {
codeField.setText(code);
}
}
}
2016-10-11 13:57:01 +02:00
public class LoginActivityResetWaitView extends SlideView {
private TextView confirmTextView;
private TextView resetAccountButton;
private TextView resetAccountTime;
2017-03-31 01:58:05 +02:00
private TextView resetAccountText;
2016-10-11 13:57:01 +02:00
private Runnable timeRunnable;
private Bundle currentParams;
private String requestPhone;
private String phoneHash;
private String phoneCode;
private int startTime;
private int waitTime;
public LoginActivityResetWaitView(Context context) {
super(context);
setOrientation(VERTICAL);
confirmTextView = new TextView(context);
2017-03-31 01:58:05 +02:00
confirmTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteGrayText6));
2016-10-11 13:57:01 +02:00
confirmTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
confirmTextView.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);
confirmTextView.setLineSpacing(AndroidUtilities.dp(2), 1.0f);
addView(confirmTextView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT));
2017-03-31 01:58:05 +02:00
resetAccountText = new TextView(context);
2016-10-11 13:57:01 +02:00
resetAccountText.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP);
2017-03-31 01:58:05 +02:00
resetAccountText.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteGrayText6));
2016-10-11 13:57:01 +02:00
resetAccountText.setText(LocaleController.getString("ResetAccountStatus", R.string.ResetAccountStatus));
resetAccountText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
resetAccountText.setLineSpacing(AndroidUtilities.dp(2), 1.0f);
addView(resetAccountText, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.TOP | (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT), 0, 24, 0, 0));
resetAccountTime = new TextView(context);
resetAccountTime.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP);
2017-03-31 01:58:05 +02:00
resetAccountTime.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteGrayText6));
2016-10-11 13:57:01 +02:00
resetAccountTime.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
resetAccountTime.setLineSpacing(AndroidUtilities.dp(2), 1.0f);
addView(resetAccountTime, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.TOP | (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT), 0, 2, 0, 0));
resetAccountButton = new TextView(context);
resetAccountButton.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP);
resetAccountButton.setText(LocaleController.getString("ResetAccountButton", R.string.ResetAccountButton));
resetAccountButton.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
resetAccountButton.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
resetAccountButton.setLineSpacing(AndroidUtilities.dp(2), 1.0f);
resetAccountButton.setPadding(0, AndroidUtilities.dp(14), 0, 0);
addView(resetAccountButton, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.TOP | (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT), 0, 7, 0, 0));
2018-08-27 10:33:11 +02:00
resetAccountButton.setOnClickListener(view -> {
2019-01-23 18:03:33 +01:00
if (doneProgressView.getTag() != null) {
return;
}
2018-08-27 10:33:11 +02:00
if (Math.abs(ConnectionsManager.getInstance(currentAccount).getCurrentTime() - startTime) < waitTime) {
return;
2016-10-11 13:57:01 +02:00
}
2018-08-27 10:33:11 +02:00
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setMessage(LocaleController.getString("ResetMyAccountWarningText", R.string.ResetMyAccountWarningText));
builder.setTitle(LocaleController.getString("ResetMyAccountWarning", R.string.ResetMyAccountWarning));
builder.setPositiveButton(LocaleController.getString("ResetMyAccountWarningReset", R.string.ResetMyAccountWarningReset), (dialogInterface, i) -> {
needShowProgress(0);
TLRPC.TL_account_deleteAccount req = new TLRPC.TL_account_deleteAccount();
req.reason = "Forgot password";
ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
2019-01-23 18:03:33 +01:00
needHideProgress(false);
2018-08-27 10:33:11 +02:00
if (error == null) {
Bundle params = new Bundle();
params.putString("phoneFormated", requestPhone);
params.putString("phoneHash", phoneHash);
params.putString("code", phoneCode);
setPage(5, true, params, false);
} else {
if (error.text.equals("2FA_RECENT_CONFIRM")) {
2020-06-25 17:29:04 +02:00
needShowAlert(LocaleController.getString("NekoX", R.string.NekoX), LocaleController.getString("ResetAccountCancelledAlert", R.string.ResetAccountCancelledAlert));
2018-08-27 10:33:11 +02:00
} else {
2020-06-25 17:29:04 +02:00
needShowAlert(LocaleController.getString("NekoX", R.string.NekoX), error.text);
2018-08-27 10:33:11 +02:00
}
}
}), ConnectionsManager.RequestFlagWithoutLogin | ConnectionsManager.RequestFlagFailOnServerErrors);
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
showDialog(builder.create());
2016-10-11 13:57:01 +02:00
});
}
@Override
public String getHeaderName() {
return LocaleController.getString("ResetAccount", R.string.ResetAccount);
}
private void updateTimeText() {
2018-07-30 04:07:02 +02:00
int timeLeft = Math.max(0, waitTime - (ConnectionsManager.getInstance(currentAccount).getCurrentTime() - startTime));
2016-10-11 13:57:01 +02:00
int days = timeLeft / 86400;
int hours = (timeLeft - days * 86400) / 3600;
int minutes = (timeLeft - days * 86400 - hours * 3600) / 60;
int seconds = timeLeft % 60;
if (days != 0) {
resetAccountTime.setText(AndroidUtilities.replaceTags(LocaleController.formatPluralString("DaysBold", days) + " " + LocaleController.formatPluralString("HoursBold", hours) + " " + LocaleController.formatPluralString("MinutesBold", minutes)));
} else {
resetAccountTime.setText(AndroidUtilities.replaceTags(LocaleController.formatPluralString("HoursBold", hours) + " " + LocaleController.formatPluralString("MinutesBold", minutes) + " " + LocaleController.formatPluralString("SecondsBold", seconds)));
}
if (timeLeft > 0) {
2017-03-31 01:58:05 +02:00
resetAccountButton.setTag(Theme.key_windowBackgroundWhiteGrayText6);
resetAccountButton.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteGrayText6));
2016-10-11 13:57:01 +02:00
} else {
2017-03-31 01:58:05 +02:00
resetAccountButton.setTag(Theme.key_windowBackgroundWhiteRedText6);
resetAccountButton.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteRedText6));
2016-10-11 13:57:01 +02:00
}
}
@Override
2017-03-31 01:58:05 +02:00
public void setParams(Bundle params, boolean restore) {
2016-10-11 13:57:01 +02:00
if (params == null) {
return;
}
currentParams = params;
requestPhone = params.getString("phoneFormated");
phoneHash = params.getString("phoneHash");
phoneCode = params.getString("code");
startTime = params.getInt("startTime");
waitTime = params.getInt("waitTime");
2018-07-30 04:07:02 +02:00
confirmTextView.setText(AndroidUtilities.replaceTags(LocaleController.formatString("ResetAccountInfo", R.string.ResetAccountInfo, LocaleController.addNbsp(PhoneFormat.getInstance().format("+" + requestPhone)))));
2016-10-11 13:57:01 +02:00
updateTimeText();
timeRunnable = new Runnable() {
@Override
public void run() {
if (timeRunnable != this) {
return;
}
updateTimeText();
AndroidUtilities.runOnUIThread(timeRunnable, 1000);
}
};
AndroidUtilities.runOnUIThread(timeRunnable, 1000);
}
@Override
public boolean needBackButton() {
return true;
}
@Override
2019-01-23 18:03:33 +01:00
public boolean onBackPressed(boolean force) {
needHideProgress(true);
2016-10-11 13:57:01 +02:00
AndroidUtilities.cancelRunOnUIThread(timeRunnable);
timeRunnable = null;
currentParams = null;
2019-01-23 18:03:33 +01:00
return true;
2016-10-11 13:57:01 +02:00
}
@Override
public void saveStateParams(Bundle bundle) {
if (currentParams != null) {
bundle.putBundle("resetview_params", currentParams);
}
}
@Override
public void restoreStateParams(Bundle bundle) {
currentParams = bundle.getBundle("resetview_params");
if (currentParams != null) {
2017-03-31 01:58:05 +02:00
setParams(currentParams, true);
2016-10-11 13:57:01 +02:00
}
}
}
2015-04-09 20:00:14 +02:00
public class LoginActivityRecoverView extends SlideView {
2017-12-08 18:35:59 +01:00
private EditTextBoldCursor codeField;
2015-04-09 20:00:14 +02:00
private TextView confirmTextView;
private TextView cancelButton;
private Bundle currentParams;
private boolean nextPressed;
public LoginActivityRecoverView(Context context) {
super(context);
setOrientation(VERTICAL);
confirmTextView = new TextView(context);
2017-03-31 01:58:05 +02:00
confirmTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteGrayText6));
2015-04-09 20:00:14 +02:00
confirmTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
confirmTextView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT));
2015-04-09 20:00:14 +02:00
confirmTextView.setLineSpacing(AndroidUtilities.dp(2), 1.0f);
confirmTextView.setText(LocaleController.getString("RestoreEmailSentInfo", R.string.RestoreEmailSentInfo));
2015-11-26 22:04:02 +01:00
addView(confirmTextView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT)));
2015-04-09 20:00:14 +02:00
2017-12-08 18:35:59 +01:00
codeField = new EditTextBoldCursor(context);
2017-03-31 01:58:05 +02:00
codeField.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
2017-12-08 18:35:59 +01:00
codeField.setCursorColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
codeField.setCursorSize(AndroidUtilities.dp(20));
codeField.setCursorWidth(1.5f);
2017-03-31 01:58:05 +02:00
codeField.setHintTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteHintText));
codeField.setBackgroundDrawable(Theme.createEditTextDrawable(context, false));
2015-04-09 20:00:14 +02:00
codeField.setHint(LocaleController.getString("PasswordCode", R.string.PasswordCode));
codeField.setImeOptions(EditorInfo.IME_ACTION_NEXT | EditorInfo.IME_FLAG_NO_EXTRACT_UI);
codeField.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
codeField.setMaxLines(1);
codeField.setPadding(0, 0, 0, 0);
codeField.setInputType(InputType.TYPE_CLASS_PHONE);
codeField.setTransformationMethod(PasswordTransformationMethod.getInstance());
codeField.setTypeface(Typeface.DEFAULT);
codeField.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);
2015-11-26 22:04:02 +01:00
addView(codeField, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 36, Gravity.CENTER_HORIZONTAL, 0, 20, 0, 0));
2018-08-27 10:33:11 +02:00
codeField.setOnEditorActionListener((textView, i, keyEvent) -> {
if (i == EditorInfo.IME_ACTION_NEXT) {
onNextPressed();
return true;
2015-04-09 20:00:14 +02:00
}
2018-08-27 10:33:11 +02:00
return false;
2015-04-09 20:00:14 +02:00
});
cancelButton = new TextView(context);
cancelButton.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.BOTTOM);
2017-03-31 01:58:05 +02:00
cancelButton.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlueText4));
2015-04-09 20:00:14 +02:00
cancelButton.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
cancelButton.setLineSpacing(AndroidUtilities.dp(2), 1.0f);
cancelButton.setPadding(0, AndroidUtilities.dp(14), 0, 0);
2015-11-26 22:04:02 +01:00
addView(cancelButton, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.BOTTOM | (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT), 0, 0, 0, 14));
2018-08-27 10:33:11 +02:00
cancelButton.setOnClickListener(view -> {
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setMessage(LocaleController.getString("RestoreEmailTroubleText", R.string.RestoreEmailTroubleText));
builder.setTitle(LocaleController.getString("RestorePasswordNoEmailTitle", R.string.RestorePasswordNoEmailTitle));
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), (dialogInterface, i) -> setPage(6, true, new Bundle(), true));
Dialog dialog = showDialog(builder.create());
if (dialog != null) {
dialog.setCanceledOnTouchOutside(false);
dialog.setCancelable(false);
2015-04-09 20:00:14 +02:00
}
});
}
@Override
public boolean needBackButton() {
return true;
}
2017-12-08 18:35:59 +01:00
@Override
public void onCancelPressed() {
nextPressed = false;
}
2015-04-09 20:00:14 +02:00
@Override
public String getHeaderName() {
return LocaleController.getString("LoginPassword", R.string.LoginPassword);
}
@Override
2017-03-31 01:58:05 +02:00
public void setParams(Bundle params, boolean restore) {
2015-04-09 20:00:14 +02:00
if (params == null) {
return;
}
codeField.setText("");
currentParams = params;
2019-12-31 14:08:08 +01:00
String email_unconfirmed_pattern = currentParams.getString("email_unconfirmed_pattern");
2015-04-09 20:00:14 +02:00
cancelButton.setText(LocaleController.formatString("RestoreEmailTrouble", R.string.RestoreEmailTrouble, email_unconfirmed_pattern));
AndroidUtilities.showKeyboard(codeField);
codeField.requestFocus();
}
private void onPasscodeError(boolean clear) {
if (getParentActivity() == null) {
return;
}
Vibrator v = (Vibrator) getParentActivity().getSystemService(Context.VIBRATOR_SERVICE);
if (v != null) {
v.vibrate(200);
}
if (clear) {
codeField.setText("");
}
2015-09-24 22:52:02 +02:00
AndroidUtilities.shakeView(confirmTextView, 2, 0);
2015-04-09 20:00:14 +02:00
}
@Override
public void onNextPressed() {
if (nextPressed) {
return;
}
String oldPassword = codeField.getText().toString();
if (oldPassword.length() == 0) {
onPasscodeError(false);
return;
}
nextPressed = true;
String code = codeField.getText().toString();
if (code.length() == 0) {
onPasscodeError(false);
return;
}
2017-07-08 18:32:04 +02:00
needShowProgress(0);
2015-04-09 20:00:14 +02:00
TLRPC.TL_auth_recoverPassword req = new TLRPC.TL_auth_recoverPassword();
req.code = code;
2018-08-27 10:33:11 +02:00
ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
2019-01-23 18:03:33 +01:00
needHideProgress(false);
2018-08-27 10:33:11 +02:00
nextPressed = false;
2019-08-22 01:53:26 +02:00
if (response instanceof TLRPC.TL_auth_authorization) {
2019-01-23 18:03:33 +01:00
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), (dialogInterface, i) -> onAuthSuccess((TLRPC.TL_auth_authorization) response));
builder.setMessage(LocaleController.getString("PasswordReset", R.string.PasswordReset));
2020-06-25 17:29:04 +02:00
builder.setTitle(LocaleController.getString("NekoX", R.string.NekoX));
2019-01-23 18:03:33 +01:00
Dialog dialog = showDialog(builder.create());
if (dialog != null) {
dialog.setCanceledOnTouchOutside(false);
dialog.setCancelable(false);
}
2018-08-27 10:33:11 +02:00
} else {
if (error.text.startsWith("CODE_INVALID")) {
onPasscodeError(true);
} else if (error.text.startsWith("FLOOD_WAIT")) {
int time = Utilities.parseInt(error.text);
String timeString;
if (time < 60) {
timeString = LocaleController.formatPluralString("Seconds", time);
} else {
timeString = LocaleController.formatPluralString("Minutes", time / 60);
2015-04-09 20:00:14 +02:00
}
2020-06-25 17:29:04 +02:00
needShowAlert(LocaleController.getString("NekoX", R.string.NekoX), LocaleController.formatString("FloodWaitTime", R.string.FloodWaitTime, timeString));
2018-08-27 10:33:11 +02:00
} else {
2020-06-25 17:29:04 +02:00
needShowAlert(LocaleController.getString("NekoX", R.string.NekoX), error.text);
2018-08-27 10:33:11 +02:00
}
2015-04-09 20:00:14 +02:00
}
2018-08-27 10:33:11 +02:00
}), ConnectionsManager.RequestFlagFailOnServerErrors | ConnectionsManager.RequestFlagWithoutLogin);
2015-04-09 20:00:14 +02:00
}
@Override
2019-01-23 18:03:33 +01:00
public boolean onBackPressed(boolean force) {
needHideProgress(true);
2015-04-09 20:00:14 +02:00
currentParams = null;
2019-01-23 18:03:33 +01:00
nextPressed = false;
return true;
2015-04-09 20:00:14 +02:00
}
@Override
public void onShow() {
super.onShow();
2018-08-27 10:33:11 +02:00
AndroidUtilities.runOnUIThread(() -> {
if (codeField != null) {
codeField.requestFocus();
codeField.setSelection(codeField.length());
2018-07-30 04:07:02 +02:00
}
}, 100);
2015-04-09 20:00:14 +02:00
}
@Override
public void saveStateParams(Bundle bundle) {
String code = codeField.getText().toString();
if (code != null && code.length() != 0) {
bundle.putString("recoveryview_code", code);
}
if (currentParams != null) {
bundle.putBundle("recoveryview_params", currentParams);
}
}
@Override
public void restoreStateParams(Bundle bundle) {
currentParams = bundle.getBundle("recoveryview_params");
if (currentParams != null) {
2017-03-31 01:58:05 +02:00
setParams(currentParams, true);
2015-04-09 20:00:14 +02:00
}
String code = bundle.getString("recoveryview_code");
if (code != null) {
codeField.setText(code);
}
}
}
2019-01-23 18:03:33 +01:00
public class LoginActivityRegisterView extends SlideView implements ImageUpdater.ImageUpdaterDelegate {
2014-11-14 16:40:15 +01:00
2017-12-08 18:35:59 +01:00
private EditTextBoldCursor firstNameField;
private EditTextBoldCursor lastNameField;
2019-01-23 18:03:33 +01:00
private BackupImageView avatarImage;
private AvatarDrawable avatarDrawable;
private View avatarOverlay;
private ImageView avatarEditor;
private RadialProgressView avatarProgressView;
private AnimatorSet avatarAnimation;
2017-03-31 01:58:05 +02:00
private TextView textView;
private TextView wrongNumber;
2018-07-30 04:07:02 +02:00
private TextView privacyView;
2014-11-14 16:40:15 +01:00
private String requestPhone;
private String phoneHash;
private Bundle currentParams;
private boolean nextPressed = false;
2019-01-23 18:03:33 +01:00
private ImageUpdater imageUpdater;
private TLRPC.FileLocation avatar;
private TLRPC.FileLocation avatarBig;
private TLRPC.InputFile uploadedAvatar;
private boolean createAfterUpload;
2018-07-30 04:07:02 +02:00
public class LinkSpan extends ClickableSpan {
@Override
public void updateDrawState(TextPaint ds) {
super.updateDrawState(ds);
ds.setUnderlineText(false);
}
@Override
public void onClick(View widget) {
showTermsOfService(false);
}
}
private void showTermsOfService(boolean needAccept) {
if (currentTermsOfService == null) {
return;
}
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setTitle(LocaleController.getString("TermsOfService", R.string.TermsOfService));
if (needAccept) {
2018-08-27 10:33:11 +02:00
builder.setPositiveButton(LocaleController.getString("Accept", R.string.Accept), (dialog, which) -> {
currentTermsOfService.popup = false;
onNextPressed();
});
builder.setNegativeButton(LocaleController.getString("Decline", R.string.Decline), (dialog, which) -> {
AlertDialog.Builder builder1 = new AlertDialog.Builder(getParentActivity());
builder1.setTitle(LocaleController.getString("TermsOfService", R.string.TermsOfService));
builder1.setMessage(LocaleController.getString("TosDecline", R.string.TosDecline));
builder1.setPositiveButton(LocaleController.getString("SignUp", R.string.SignUp), (dialog1, which1) -> {
2018-07-30 04:07:02 +02:00
currentTermsOfService.popup = false;
onNextPressed();
2018-08-27 10:33:11 +02:00
});
2019-01-23 18:03:33 +01:00
builder1.setNegativeButton(LocaleController.getString("Decline", R.string.Decline), (dialog12, which12) -> {
onBackPressed(true);
setPage(0, true, null, true);
});
2018-08-27 10:33:11 +02:00
showDialog(builder1.create());
2018-07-30 04:07:02 +02:00
});
} else {
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
}
SpannableStringBuilder text = new SpannableStringBuilder(currentTermsOfService.text);
2020-04-24 11:21:58 +02:00
MessageObject.addEntitiesToText(text, currentTermsOfService.entities, false, false, false, false);
2018-07-30 04:07:02 +02:00
builder.setMessage(text);
showDialog(builder.create());
}
2015-04-09 20:00:14 +02:00
public LoginActivityRegisterView(Context context) {
2014-11-14 16:40:15 +01:00
super(context);
setOrientation(VERTICAL);
2019-01-23 18:03:33 +01:00
imageUpdater = new ImageUpdater();
imageUpdater.setSearchAvailable(false);
imageUpdater.setUploadAfterSelect(false);
imageUpdater.parentFragment = LoginActivity.this;
imageUpdater.delegate = this;
2017-03-31 01:58:05 +02:00
textView = new TextView(context);
2019-01-23 18:03:33 +01:00
textView.setText(LocaleController.getString("RegisterText2", R.string.RegisterText2));
2017-03-31 01:58:05 +02:00
textView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteGrayText6));
textView.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);
2014-11-14 16:40:15 +01:00
textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
2019-01-23 18:03:33 +01:00
addView(textView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT, 0, 0, 0, 0));
FrameLayout editTextContainer = new FrameLayout(context);
addView(editTextContainer, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, 0, 21, 0, 0));
avatarDrawable = new AvatarDrawable();
avatarImage = new BackupImageView(context) {
@Override
public void invalidate() {
if (avatarOverlay != null) {
avatarOverlay.invalidate();
}
super.invalidate();
}
@Override
public void invalidate(int l, int t, int r, int b) {
if (avatarOverlay != null) {
avatarOverlay.invalidate();
}
super.invalidate(l, t, r, b);
}
};
avatarImage.setRoundRadius(AndroidUtilities.dp(32));
2019-09-10 12:56:11 +02:00
avatarDrawable.setInfo(5, null, null);
2019-01-23 18:03:33 +01:00
avatarImage.setImageDrawable(avatarDrawable);
editTextContainer.addView(avatarImage, LayoutHelper.createFrame(64, 64, Gravity.TOP | (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT), 0, 16, 0, 0));
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
paint.setColor(0x55000000);
avatarOverlay = new View(context) {
@Override
protected void onDraw(Canvas canvas) {
if (avatarImage != null && avatarProgressView.getVisibility() == VISIBLE) {
paint.setAlpha((int) (0x55 * avatarImage.getImageReceiver().getCurrentAlpha() * avatarProgressView.getAlpha()));
canvas.drawCircle(getMeasuredWidth() / 2, getMeasuredHeight() / 2, AndroidUtilities.dp(32), paint);
}
}
};
editTextContainer.addView(avatarOverlay, LayoutHelper.createFrame(64, 64, Gravity.TOP | (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT), 0, 16, 0, 0));
avatarOverlay.setOnClickListener(view -> imageUpdater.openMenu(avatar != null, () -> {
avatar = null;
avatarBig = null;
uploadedAvatar = null;
showAvatarProgress(false, true);
2019-05-14 14:08:05 +02:00
avatarImage.setImage(null, null, avatarDrawable, null);
2019-01-23 18:03:33 +01:00
avatarEditor.setImageResource(R.drawable.actions_setphoto);
}));
avatarEditor = new ImageView(context) {
@Override
public void invalidate(int l, int t, int r, int b) {
super.invalidate(l, t, r, b);
avatarOverlay.invalidate();
}
@Override
public void invalidate() {
super.invalidate();
avatarOverlay.invalidate();
}
};
avatarEditor.setScaleType(ImageView.ScaleType.CENTER);
avatarEditor.setImageResource(R.drawable.actions_setphoto);
avatarEditor.setEnabled(false);
avatarEditor.setClickable(false);
avatarEditor.setPadding(AndroidUtilities.dp(2), 0, 0, 0);
editTextContainer.addView(avatarEditor, LayoutHelper.createFrame(64, 64, Gravity.TOP | (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT), 0, 16, 0, 0));
avatarProgressView = new RadialProgressView(context) {
@Override
public void setAlpha(float alpha) {
super.setAlpha(alpha);
avatarOverlay.invalidate();
}
};
avatarProgressView.setSize(AndroidUtilities.dp(30));
avatarProgressView.setProgressColor(0xffffffff);
editTextContainer.addView(avatarProgressView, LayoutHelper.createFrame(64, 64, Gravity.TOP | (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT), 0, 16, 0, 0));
showAvatarProgress(false, false);
2014-11-14 16:40:15 +01:00
2017-12-08 18:35:59 +01:00
firstNameField = new EditTextBoldCursor(context);
2017-03-31 01:58:05 +02:00
firstNameField.setHintTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteHintText));
firstNameField.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
firstNameField.setBackgroundDrawable(Theme.createEditTextDrawable(context, false));
2017-12-08 18:35:59 +01:00
firstNameField.setCursorColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
firstNameField.setCursorSize(AndroidUtilities.dp(20));
firstNameField.setCursorWidth(1.5f);
2014-11-14 16:40:15 +01:00
firstNameField.setHint(LocaleController.getString("FirstName", R.string.FirstName));
firstNameField.setImeOptions(EditorInfo.IME_ACTION_NEXT | EditorInfo.IME_FLAG_NO_EXTRACT_UI);
2019-01-23 18:03:33 +01:00
firstNameField.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 17);
2014-11-14 16:40:15 +01:00
firstNameField.setMaxLines(1);
firstNameField.setInputType(InputType.TYPE_TEXT_FLAG_CAP_WORDS);
2019-01-23 18:03:33 +01:00
editTextContainer.addView(firstNameField, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 36, Gravity.TOP | (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT), LocaleController.isRTL ? 0 : 85, 0, LocaleController.isRTL ? 85 : 0, 0));
2018-08-27 10:33:11 +02:00
firstNameField.setOnEditorActionListener((textView, i, keyEvent) -> {
if (i == EditorInfo.IME_ACTION_NEXT) {
lastNameField.requestFocus();
return true;
2014-11-14 16:40:15 +01:00
}
2018-08-27 10:33:11 +02:00
return false;
2014-11-14 16:40:15 +01:00
});
2017-12-08 18:35:59 +01:00
lastNameField = new EditTextBoldCursor(context);
2014-11-14 16:40:15 +01:00
lastNameField.setHint(LocaleController.getString("LastName", R.string.LastName));
2017-03-31 01:58:05 +02:00
lastNameField.setHintTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteHintText));
lastNameField.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
lastNameField.setBackgroundDrawable(Theme.createEditTextDrawable(context, false));
2017-12-08 18:35:59 +01:00
lastNameField.setCursorColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
lastNameField.setCursorSize(AndroidUtilities.dp(20));
lastNameField.setCursorWidth(1.5f);
lastNameField.setImeOptions(EditorInfo.IME_ACTION_DONE | EditorInfo.IME_FLAG_NO_EXTRACT_UI);
2019-01-23 18:03:33 +01:00
lastNameField.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 17);
2014-11-14 16:40:15 +01:00
lastNameField.setMaxLines(1);
lastNameField.setInputType(InputType.TYPE_TEXT_FLAG_CAP_WORDS);
2019-01-23 18:03:33 +01:00
editTextContainer.addView(lastNameField, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 36, Gravity.TOP | (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT), LocaleController.isRTL ? 0 : 85, 51, LocaleController.isRTL ? 85 : 0, 0));
2018-08-27 10:33:11 +02:00
lastNameField.setOnEditorActionListener((textView, i, keyEvent) -> {
if (i == EditorInfo.IME_ACTION_DONE || i == EditorInfo.IME_ACTION_NEXT) {
onNextPressed();
return true;
2017-12-08 18:35:59 +01:00
}
2018-08-27 10:33:11 +02:00
return false;
2017-12-08 18:35:59 +01:00
});
2014-11-14 16:40:15 +01:00
2017-03-31 01:58:05 +02:00
wrongNumber = new TextView(context);
2014-11-14 16:40:15 +01:00
wrongNumber.setText(LocaleController.getString("CancelRegistration", R.string.CancelRegistration));
wrongNumber.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.CENTER_HORIZONTAL);
2017-03-31 01:58:05 +02:00
wrongNumber.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlueText4));
2014-11-14 16:40:15 +01:00
wrongNumber.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
wrongNumber.setLineSpacing(AndroidUtilities.dp(2), 1.0f);
wrongNumber.setPadding(0, AndroidUtilities.dp(24), 0, 0);
2018-07-30 04:07:02 +02:00
wrongNumber.setVisibility(GONE);
addView(wrongNumber, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.TOP | (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT), 0, 20, 0, 0));
2018-08-27 10:33:11 +02:00
wrongNumber.setOnClickListener(view -> {
2019-01-23 18:03:33 +01:00
if (doneProgressView.getTag() != null) {
return;
}
onBackPressed(false);
2014-11-14 16:40:15 +01:00
});
2018-07-30 04:07:02 +02:00
2019-12-31 14:08:08 +01:00
final FrameLayout privacyLayout = new FrameLayout(context);
privacyLayout.setClipToPadding(false);
privacyLayout.setPadding(0, AndroidUtilities.dp(28f), AndroidUtilities.dp(100f), AndroidUtilities.dp(16f));
addView(privacyLayout, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.LEFT | Gravity.BOTTOM));
2018-07-30 04:07:02 +02:00
privacyView = new TextView(context);
privacyView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteGrayText6));
privacyView.setMovementMethod(new AndroidUtilities.LinkMovementMethodMy());
privacyView.setLinkTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteLinkText));
privacyView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
privacyView.setLineSpacing(AndroidUtilities.dp(2), 1.0f);
2019-12-31 14:08:08 +01:00
privacyLayout.addView(privacyView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.BOTTOM));
2018-07-30 04:07:02 +02:00
String str = LocaleController.getString("TermsOfServiceLogin", R.string.TermsOfServiceLogin);
SpannableStringBuilder text = new SpannableStringBuilder(str);
int index1 = str.indexOf('*');
int index2 = str.lastIndexOf('*');
if (index1 != -1 && index2 != -1 && index1 != index2) {
text.replace(index2, index2 + 1, "");
text.replace(index1, index1 + 1, "");
text.setSpan(new LinkSpan(), index1, index2 - 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
privacyView.setText(text);
2014-11-14 16:40:15 +01:00
}
@Override
2019-01-23 18:03:33 +01:00
public void didUploadPhoto(final TLRPC.InputFile file, final TLRPC.PhotoSize bigSize, final TLRPC.PhotoSize smallSize) {
AndroidUtilities.runOnUIThread(() -> {
avatar = smallSize.location;
avatarBig = bigSize.location;
2019-05-14 14:08:05 +02:00
avatarImage.setImage(ImageLocation.getForLocal(avatar), "50_50", avatarDrawable, null);
2019-01-23 18:03:33 +01:00
});
}
private void showAvatarProgress(boolean show, boolean animated) {
if (avatarEditor == null) {
return;
}
if (avatarAnimation != null) {
avatarAnimation.cancel();
avatarAnimation = null;
}
if (animated) {
avatarAnimation = new AnimatorSet();
if (show) {
avatarProgressView.setVisibility(View.VISIBLE);
avatarAnimation.playTogether(ObjectAnimator.ofFloat(avatarEditor, View.ALPHA, 0.0f),
ObjectAnimator.ofFloat(avatarProgressView, View.ALPHA, 1.0f));
} else {
avatarEditor.setVisibility(View.VISIBLE);
avatarAnimation.playTogether(ObjectAnimator.ofFloat(avatarEditor, View.ALPHA, 1.0f),
ObjectAnimator.ofFloat(avatarProgressView, View.ALPHA, 0.0f));
}
avatarAnimation.setDuration(180);
avatarAnimation.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
if (avatarAnimation == null || avatarEditor == null) {
return;
}
if (show) {
avatarEditor.setVisibility(View.INVISIBLE);
} else {
avatarProgressView.setVisibility(View.INVISIBLE);
}
avatarAnimation = null;
}
@Override
public void onAnimationCancel(Animator animation) {
avatarAnimation = null;
}
});
avatarAnimation.start();
} else {
if (show) {
avatarEditor.setAlpha(1.0f);
avatarEditor.setVisibility(View.INVISIBLE);
avatarProgressView.setAlpha(1.0f);
avatarProgressView.setVisibility(View.VISIBLE);
} else {
avatarEditor.setAlpha(1.0f);
avatarEditor.setVisibility(View.VISIBLE);
avatarProgressView.setAlpha(0.0f);
avatarProgressView.setVisibility(View.INVISIBLE);
}
}
}
@Override
public boolean onBackPressed(boolean force) {
if (!force) {
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
2020-01-08 18:08:16 +01:00
builder.setTitle(LocaleController.getString("NekogramWithEmoji", R.string.NekogramWithEmoji));
2019-01-23 18:03:33 +01:00
builder.setMessage(LocaleController.getString("AreYouSureRegistration", R.string.AreYouSureRegistration));
builder.setNegativeButton(LocaleController.getString("Stop", R.string.Stop), (dialogInterface, i) -> {
onBackPressed(true);
setPage(0, true, null, true);
2019-12-31 14:08:08 +01:00
hidePrivacyView();
2019-01-23 18:03:33 +01:00
});
builder.setPositiveButton(LocaleController.getString("Continue", R.string.Continue), null);
showDialog(builder.create());
return false;
}
needHideProgress(true);
nextPressed = false;
2014-11-14 16:40:15 +01:00
currentParams = null;
2019-01-23 18:03:33 +01:00
return true;
2014-11-14 16:40:15 +01:00
}
@Override
public String getHeaderName() {
return LocaleController.getString("YourName", R.string.YourName);
}
2017-12-08 18:35:59 +01:00
@Override
public void onCancelPressed() {
nextPressed = false;
}
2019-01-23 18:03:33 +01:00
@Override
public boolean needBackButton() {
return true;
}
2014-11-14 16:40:15 +01:00
@Override
public void onShow() {
super.onShow();
2019-12-31 14:08:08 +01:00
if (privacyView != null) {
if (restoringState) {
privacyView.setAlpha(1f);
} else {
privacyView.setAlpha(0f);
privacyView.animate().alpha(1f).setDuration(200).setStartDelay(300).setInterpolator(AndroidUtilities.decelerateInterpolator).start();
}
}
if (firstNameField != null) {
firstNameField.requestFocus();
firstNameField.setSelection(firstNameField.length());
}
2018-08-27 10:33:11 +02:00
AndroidUtilities.runOnUIThread(() -> {
if (firstNameField != null) {
firstNameField.requestFocus();
firstNameField.setSelection(firstNameField.length());
2018-07-30 04:07:02 +02:00
}
}, 100);
2014-11-14 16:40:15 +01:00
}
@Override
2017-03-31 01:58:05 +02:00
public void setParams(Bundle params, boolean restore) {
2014-11-14 16:40:15 +01:00
if (params == null) {
return;
}
firstNameField.setText("");
lastNameField.setText("");
requestPhone = params.getString("phoneFormated");
phoneHash = params.getString("phoneHash");
currentParams = params;
}
@Override
public void onNextPressed() {
if (nextPressed) {
return;
}
2018-07-30 04:07:02 +02:00
if (currentTermsOfService != null && currentTermsOfService.popup) {
showTermsOfService(true);
return;
}
2019-12-31 14:08:08 +01:00
if (firstNameField.length() == 0) {
onFieldError(firstNameField);
return;
}
2014-11-14 16:40:15 +01:00
nextPressed = true;
TLRPC.TL_auth_signUp req = new TLRPC.TL_auth_signUp();
req.phone_code_hash = phoneHash;
req.phone_number = requestPhone;
req.first_name = firstNameField.getText().toString();
req.last_name = lastNameField.getText().toString();
2017-07-08 18:32:04 +02:00
needShowProgress(0);
2018-08-27 10:33:11 +02:00
ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
nextPressed = false;
2019-08-22 01:53:26 +02:00
if (response instanceof TLRPC.TL_auth_authorization) {
2019-12-31 14:08:08 +01:00
hidePrivacyView();
showDoneButton(false, true);
postDelayed(() -> {
needHideProgress(false, false);
AndroidUtilities.hideKeyboard(fragmentView.findFocus());
onAuthSuccess((TLRPC.TL_auth_authorization) response, true);
2020-04-24 11:21:58 +02:00
if (avatarBig != null) {
MessagesController.getInstance(currentAccount).uploadAndApplyUserAvatar(avatarBig);
}
2019-12-31 14:08:08 +01:00
}, 150);
2018-08-27 10:33:11 +02:00
} else {
2019-12-31 14:08:08 +01:00
needHideProgress(false);
2018-08-27 10:33:11 +02:00
if (error.text.contains("PHONE_NUMBER_INVALID")) {
2020-06-25 17:29:04 +02:00
needShowAlert(LocaleController.getString("NekoX", R.string.NekoX), LocaleController.getString("InvalidPhoneNumber", R.string.InvalidPhoneNumber));
2018-08-27 10:33:11 +02:00
} else if (error.text.contains("PHONE_CODE_EMPTY") || error.text.contains("PHONE_CODE_INVALID")) {
2020-06-25 17:29:04 +02:00
needShowAlert(LocaleController.getString("NekoX", R.string.NekoX), LocaleController.getString("InvalidCode", R.string.InvalidCode));
2018-08-27 10:33:11 +02:00
} else if (error.text.contains("PHONE_CODE_EXPIRED")) {
2020-06-25 17:29:04 +02:00
needShowAlert(LocaleController.getString("NekoX", R.string.NekoX), LocaleController.getString("CodeExpired", R.string.CodeExpired));
2018-08-27 10:33:11 +02:00
} else if (error.text.contains("FIRSTNAME_INVALID")) {
2020-06-25 17:29:04 +02:00
needShowAlert(LocaleController.getString("NekoX", R.string.NekoX), LocaleController.getString("InvalidFirstName", R.string.InvalidFirstName));
2018-08-27 10:33:11 +02:00
} else if (error.text.contains("LASTNAME_INVALID")) {
2020-06-25 17:29:04 +02:00
needShowAlert(LocaleController.getString("NekoX", R.string.NekoX), LocaleController.getString("InvalidLastName", R.string.InvalidLastName));
2018-08-27 10:33:11 +02:00
} else {
2020-06-25 17:29:04 +02:00
needShowAlert(LocaleController.getString("NekoX", R.string.NekoX), error.text);
2018-08-27 10:33:11 +02:00
}
2014-11-14 16:40:15 +01:00
}
2018-08-27 10:33:11 +02:00
}), ConnectionsManager.RequestFlagWithoutLogin | ConnectionsManager.RequestFlagFailOnServerErrors);
2014-11-14 16:40:15 +01:00
}
@Override
public void saveStateParams(Bundle bundle) {
String first = firstNameField.getText().toString();
2015-09-24 22:52:02 +02:00
if (first.length() != 0) {
2014-11-14 16:40:15 +01:00
bundle.putString("registerview_first", first);
}
String last = lastNameField.getText().toString();
2015-09-24 22:52:02 +02:00
if (last.length() != 0) {
2014-11-14 16:40:15 +01:00
bundle.putString("registerview_last", last);
}
2018-07-30 04:07:02 +02:00
if (currentTermsOfService != null) {
SerializedData data = new SerializedData(currentTermsOfService.getObjectSize());
currentTermsOfService.serializeToStream(data);
2020-06-25 17:29:04 +02:00
String str = Base64.encode(data.toByteArray());
2018-07-30 04:07:02 +02:00
bundle.putString("terms", str);
data.cleanup();
}
2014-11-14 16:40:15 +01:00
if (currentParams != null) {
bundle.putBundle("registerview_params", currentParams);
}
}
@Override
public void restoreStateParams(Bundle bundle) {
currentParams = bundle.getBundle("registerview_params");
if (currentParams != null) {
2017-03-31 01:58:05 +02:00
setParams(currentParams, true);
2014-11-14 16:40:15 +01:00
}
2018-07-30 04:07:02 +02:00
try {
String terms = bundle.getString("terms");
if (terms != null) {
2020-06-25 17:29:04 +02:00
byte[] arr = Base64.decode(terms);
2018-07-30 04:07:02 +02:00
if (arr != null) {
SerializedData data = new SerializedData(arr);
currentTermsOfService = TLRPC.TL_help_termsOfService.TLdeserialize(data, data.readInt32(false), false);
data.cleanup();
}
}
} catch (Exception e) {
FileLog.e(e);
}
2014-11-14 16:40:15 +01:00
String first = bundle.getString("registerview_first");
if (first != null) {
firstNameField.setText(first);
}
String last = bundle.getString("registerview_last");
if (last != null) {
lastNameField.setText(last);
}
}
2019-12-31 14:08:08 +01:00
private void hidePrivacyView() {
privacyView.animate().alpha(0f).setDuration(150).setStartDelay(0).setInterpolator(AndroidUtilities.accelerateInterpolator).start();
}
2014-11-14 16:40:15 +01:00
}
2017-03-31 01:58:05 +02:00
@Override
2020-04-24 11:21:58 +02:00
public ArrayList<ThemeDescription> getThemeDescriptions() {
2020-06-25 17:29:04 +02:00
for (int a = 0; a < views.length; a++) {
2019-05-14 14:08:05 +02:00
if (views[a] == null) {
2020-04-24 11:21:58 +02:00
return new ArrayList<>();
2019-05-14 14:08:05 +02:00
}
}
2017-03-31 01:58:05 +02:00
PhoneView phoneView = (PhoneView) views[0];
LoginActivitySmsView smsView1 = (LoginActivitySmsView) views[1];
LoginActivitySmsView smsView2 = (LoginActivitySmsView) views[2];
LoginActivitySmsView smsView3 = (LoginActivitySmsView) views[3];
LoginActivitySmsView smsView4 = (LoginActivitySmsView) views[4];
LoginActivityRegisterView registerView = (LoginActivityRegisterView) views[5];
LoginActivityPasswordView passwordView = (LoginActivityPasswordView) views[6];
LoginActivityRecoverView recoverView = (LoginActivityRecoverView) views[7];
LoginActivityResetWaitView waitView = (LoginActivityResetWaitView) views[8];
2019-01-23 18:03:33 +01:00
ArrayList<ThemeDescription> arrayList = new ArrayList<>();
arrayList.add(new ThemeDescription(fragmentView, ThemeDescription.FLAG_BACKGROUND, null, null, null, null, Theme.key_windowBackgroundWhite));
2019-12-31 14:08:08 +01:00
arrayList.add(new ThemeDescription(floatingButtonIcon, ThemeDescription.FLAG_IMAGECOLOR, null, null, null, null, Theme.key_chats_actionIcon));
arrayList.add(new ThemeDescription(floatingButtonIcon, ThemeDescription.FLAG_BACKGROUNDFILTER, null, null, null, null, Theme.key_chats_actionBackground));
arrayList.add(new ThemeDescription(floatingButtonIcon, ThemeDescription.FLAG_BACKGROUNDFILTER | ThemeDescription.FLAG_DRAWABLESELECTEDSTATE, null, null, null, null, Theme.key_chats_actionPressedBackground));
arrayList.add(new ThemeDescription(floatingProgressView, ThemeDescription.FLAG_PROGRESSBAR, null, null, null, null, Theme.key_chats_actionIcon));
2019-01-23 18:03:33 +01:00
arrayList.add(new ThemeDescription(actionBar, ThemeDescription.FLAG_BACKGROUND, null, null, null, null, Theme.key_actionBarDefault));
arrayList.add(new ThemeDescription(fragmentView, 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(phoneView.countryButton, ThemeDescription.FLAG_TEXTCOLOR, null, null, null, null, Theme.key_windowBackgroundWhiteBlackText));
2019-12-31 14:08:08 +01:00
arrayList.add(new ThemeDescription(phoneView.countryButton, ThemeDescription.FLAG_BACKGROUNDFILTER | ThemeDescription.FLAG_DRAWABLESELECTEDSTATE, null, null, null, null, Theme.key_listSelector));
2019-01-23 18:03:33 +01:00
arrayList.add(new ThemeDescription(phoneView.view, ThemeDescription.FLAG_BACKGROUND, null, null, null, null, Theme.key_windowBackgroundWhiteGrayLine));
arrayList.add(new ThemeDescription(phoneView.textView, ThemeDescription.FLAG_TEXTCOLOR, null, null, null, null, Theme.key_windowBackgroundWhiteBlackText));
arrayList.add(new ThemeDescription(phoneView.codeField, ThemeDescription.FLAG_TEXTCOLOR, null, null, null, null, Theme.key_windowBackgroundWhiteBlackText));
arrayList.add(new ThemeDescription(phoneView.codeField, ThemeDescription.FLAG_BACKGROUNDFILTER, null, null, null, null, Theme.key_windowBackgroundWhiteInputField));
arrayList.add(new ThemeDescription(phoneView.codeField, ThemeDescription.FLAG_BACKGROUNDFILTER | ThemeDescription.FLAG_DRAWABLESELECTEDSTATE, null, null, null, null, Theme.key_windowBackgroundWhiteInputFieldActivated));
arrayList.add(new ThemeDescription(phoneView.phoneField, ThemeDescription.FLAG_TEXTCOLOR, null, null, null, null, Theme.key_windowBackgroundWhiteBlackText));
arrayList.add(new ThemeDescription(phoneView.phoneField, ThemeDescription.FLAG_HINTTEXTCOLOR, null, null, null, null, Theme.key_windowBackgroundWhiteHintText));
arrayList.add(new ThemeDescription(phoneView.phoneField, ThemeDescription.FLAG_BACKGROUNDFILTER, null, null, null, null, Theme.key_windowBackgroundWhiteInputField));
arrayList.add(new ThemeDescription(phoneView.phoneField, ThemeDescription.FLAG_BACKGROUNDFILTER | ThemeDescription.FLAG_DRAWABLESELECTEDSTATE, null, null, null, null, Theme.key_windowBackgroundWhiteInputFieldActivated));
arrayList.add(new ThemeDescription(phoneView.textView2, ThemeDescription.FLAG_TEXTCOLOR, null, null, null, null, Theme.key_windowBackgroundWhiteGrayText6));
arrayList.add(new ThemeDescription(passwordView.confirmTextView, ThemeDescription.FLAG_TEXTCOLOR, null, null, null, null, Theme.key_windowBackgroundWhiteGrayText6));
arrayList.add(new ThemeDescription(passwordView.codeField, ThemeDescription.FLAG_TEXTCOLOR, null, null, null, null, Theme.key_windowBackgroundWhiteBlackText));
arrayList.add(new ThemeDescription(passwordView.codeField, ThemeDescription.FLAG_HINTTEXTCOLOR, null, null, null, null, Theme.key_windowBackgroundWhiteHintText));
arrayList.add(new ThemeDescription(passwordView.codeField, ThemeDescription.FLAG_BACKGROUNDFILTER, null, null, null, null, Theme.key_windowBackgroundWhiteInputField));
arrayList.add(new ThemeDescription(passwordView.codeField, ThemeDescription.FLAG_BACKGROUNDFILTER | ThemeDescription.FLAG_DRAWABLESELECTEDSTATE, null, null, null, null, Theme.key_windowBackgroundWhiteInputFieldActivated));
arrayList.add(new ThemeDescription(passwordView.cancelButton, ThemeDescription.FLAG_TEXTCOLOR, null, null, null, null, Theme.key_windowBackgroundWhiteBlueText4));
arrayList.add(new ThemeDescription(passwordView.resetAccountButton, ThemeDescription.FLAG_TEXTCOLOR, null, null, null, null, Theme.key_windowBackgroundWhiteRedText6));
arrayList.add(new ThemeDescription(passwordView.resetAccountText, ThemeDescription.FLAG_TEXTCOLOR, null, null, null, null, Theme.key_windowBackgroundWhiteGrayText6));
arrayList.add(new ThemeDescription(registerView.textView, ThemeDescription.FLAG_TEXTCOLOR, null, null, null, null, Theme.key_windowBackgroundWhiteGrayText6));
arrayList.add(new ThemeDescription(registerView.firstNameField, ThemeDescription.FLAG_HINTTEXTCOLOR, null, null, null, null, Theme.key_windowBackgroundWhiteHintText));
arrayList.add(new ThemeDescription(registerView.firstNameField, ThemeDescription.FLAG_TEXTCOLOR, null, null, null, null, Theme.key_windowBackgroundWhiteBlackText));
arrayList.add(new ThemeDescription(registerView.firstNameField, ThemeDescription.FLAG_BACKGROUNDFILTER, null, null, null, null, Theme.key_windowBackgroundWhiteInputField));
arrayList.add(new ThemeDescription(registerView.firstNameField, ThemeDescription.FLAG_BACKGROUNDFILTER | ThemeDescription.FLAG_DRAWABLESELECTEDSTATE, null, null, null, null, Theme.key_windowBackgroundWhiteInputFieldActivated));
arrayList.add(new ThemeDescription(registerView.lastNameField, ThemeDescription.FLAG_HINTTEXTCOLOR, null, null, null, null, Theme.key_windowBackgroundWhiteHintText));
arrayList.add(new ThemeDescription(registerView.lastNameField, ThemeDescription.FLAG_TEXTCOLOR, null, null, null, null, Theme.key_windowBackgroundWhiteBlackText));
arrayList.add(new ThemeDescription(registerView.lastNameField, ThemeDescription.FLAG_BACKGROUNDFILTER, null, null, null, null, Theme.key_windowBackgroundWhiteInputField));
arrayList.add(new ThemeDescription(registerView.lastNameField, ThemeDescription.FLAG_BACKGROUNDFILTER | ThemeDescription.FLAG_DRAWABLESELECTEDSTATE, null, null, null, null, Theme.key_windowBackgroundWhiteInputFieldActivated));
arrayList.add(new ThemeDescription(registerView.wrongNumber, ThemeDescription.FLAG_TEXTCOLOR, null, null, null, null, Theme.key_windowBackgroundWhiteBlueText4));
arrayList.add(new ThemeDescription(registerView.privacyView, ThemeDescription.FLAG_TEXTCOLOR, null, null, null, null, Theme.key_windowBackgroundWhiteGrayText6));
arrayList.add(new ThemeDescription(registerView.privacyView, ThemeDescription.FLAG_LINKCOLOR, null, null, null, null, Theme.key_windowBackgroundWhiteLinkText));
arrayList.add(new ThemeDescription(recoverView.confirmTextView, ThemeDescription.FLAG_TEXTCOLOR, null, null, null, null, Theme.key_windowBackgroundWhiteGrayText6));
arrayList.add(new ThemeDescription(recoverView.codeField, ThemeDescription.FLAG_TEXTCOLOR, null, null, null, null, Theme.key_windowBackgroundWhiteBlackText));
arrayList.add(new ThemeDescription(recoverView.codeField, ThemeDescription.FLAG_HINTTEXTCOLOR, null, null, null, null, Theme.key_windowBackgroundWhiteHintText));
arrayList.add(new ThemeDescription(recoverView.codeField, ThemeDescription.FLAG_BACKGROUNDFILTER, null, null, null, null, Theme.key_windowBackgroundWhiteInputField));
arrayList.add(new ThemeDescription(recoverView.codeField, ThemeDescription.FLAG_BACKGROUNDFILTER | ThemeDescription.FLAG_DRAWABLESELECTEDSTATE, null, null, null, null, Theme.key_windowBackgroundWhiteInputFieldActivated));
arrayList.add(new ThemeDescription(recoverView.cancelButton, ThemeDescription.FLAG_TEXTCOLOR, null, null, null, null, Theme.key_windowBackgroundWhiteBlueText4));
arrayList.add(new ThemeDescription(waitView.confirmTextView, ThemeDescription.FLAG_TEXTCOLOR, null, null, null, null, Theme.key_windowBackgroundWhiteGrayText6));
arrayList.add(new ThemeDescription(waitView.resetAccountText, ThemeDescription.FLAG_TEXTCOLOR, null, null, null, null, Theme.key_windowBackgroundWhiteGrayText6));
arrayList.add(new ThemeDescription(waitView.resetAccountTime, ThemeDescription.FLAG_TEXTCOLOR, null, null, null, null, Theme.key_windowBackgroundWhiteGrayText6));
arrayList.add(new ThemeDescription(waitView.resetAccountButton, ThemeDescription.FLAG_TEXTCOLOR | ThemeDescription.FLAG_CHECKTAG, null, null, null, null, Theme.key_windowBackgroundWhiteGrayText6));
arrayList.add(new ThemeDescription(waitView.resetAccountButton, ThemeDescription.FLAG_TEXTCOLOR | ThemeDescription.FLAG_CHECKTAG, null, null, null, null, Theme.key_windowBackgroundWhiteRedText6));
arrayList.add(new ThemeDescription(smsView1.confirmTextView, ThemeDescription.FLAG_TEXTCOLOR, null, null, null, null, Theme.key_windowBackgroundWhiteGrayText6));
arrayList.add(new ThemeDescription(smsView1.titleTextView, ThemeDescription.FLAG_TEXTCOLOR, null, null, null, null, Theme.key_windowBackgroundWhiteBlackText));
if (smsView1.codeField != null) {
for (int a = 0; a < smsView1.codeField.length; a++) {
arrayList.add(new ThemeDescription(smsView1.codeField[a], ThemeDescription.FLAG_TEXTCOLOR, null, null, null, null, Theme.key_windowBackgroundWhiteBlackText));
arrayList.add(new ThemeDescription(smsView1.codeField[a], ThemeDescription.FLAG_BACKGROUNDFILTER, null, null, null, null, Theme.key_windowBackgroundWhiteInputFieldActivated));
}
}
arrayList.add(new ThemeDescription(smsView1.timeText, ThemeDescription.FLAG_TEXTCOLOR, null, null, null, null, Theme.key_windowBackgroundWhiteGrayText6));
arrayList.add(new ThemeDescription(smsView1.problemText, ThemeDescription.FLAG_TEXTCOLOR, null, null, null, null, Theme.key_windowBackgroundWhiteBlueText4));
arrayList.add(new ThemeDescription(smsView1.progressView, 0, new Class[]{ProgressView.class}, new String[]{"paint"}, null, null, null, Theme.key_login_progressInner));
arrayList.add(new ThemeDescription(smsView1.progressView, 0, new Class[]{ProgressView.class}, new String[]{"paint"}, null, null, null, Theme.key_login_progressOuter));
arrayList.add(new ThemeDescription(smsView1.blackImageView, ThemeDescription.FLAG_IMAGECOLOR, null, null, null, null, Theme.key_windowBackgroundWhiteBlackText));
arrayList.add(new ThemeDescription(smsView1.blueImageView, ThemeDescription.FLAG_IMAGECOLOR, null, null, null, null, Theme.key_chats_actionBackground));
arrayList.add(new ThemeDescription(smsView2.confirmTextView, ThemeDescription.FLAG_TEXTCOLOR, null, null, null, null, Theme.key_windowBackgroundWhiteGrayText6));
arrayList.add(new ThemeDescription(smsView2.titleTextView, ThemeDescription.FLAG_TEXTCOLOR, null, null, null, null, Theme.key_windowBackgroundWhiteBlackText));
if (smsView2.codeField != null) {
for (int a = 0; a < smsView2.codeField.length; a++) {
arrayList.add(new ThemeDescription(smsView2.codeField[a], ThemeDescription.FLAG_TEXTCOLOR, null, null, null, null, Theme.key_windowBackgroundWhiteBlackText));
arrayList.add(new ThemeDescription(smsView2.codeField[a], ThemeDescription.FLAG_BACKGROUNDFILTER, null, null, null, null, Theme.key_windowBackgroundWhiteInputFieldActivated));
}
}
arrayList.add(new ThemeDescription(smsView2.timeText, ThemeDescription.FLAG_TEXTCOLOR, null, null, null, null, Theme.key_windowBackgroundWhiteGrayText6));
arrayList.add(new ThemeDescription(smsView2.problemText, ThemeDescription.FLAG_TEXTCOLOR, null, null, null, null, Theme.key_windowBackgroundWhiteBlueText4));
arrayList.add(new ThemeDescription(smsView2.progressView, 0, new Class[]{ProgressView.class}, new String[]{"paint"}, null, null, null, Theme.key_login_progressInner));
arrayList.add(new ThemeDescription(smsView2.progressView, 0, new Class[]{ProgressView.class}, new String[]{"paint"}, null, null, null, Theme.key_login_progressOuter));
arrayList.add(new ThemeDescription(smsView2.blackImageView, ThemeDescription.FLAG_IMAGECOLOR, null, null, null, null, Theme.key_windowBackgroundWhiteBlackText));
arrayList.add(new ThemeDescription(smsView2.blueImageView, ThemeDescription.FLAG_IMAGECOLOR, null, null, null, null, Theme.key_chats_actionBackground));
arrayList.add(new ThemeDescription(smsView3.confirmTextView, ThemeDescription.FLAG_TEXTCOLOR, null, null, null, null, Theme.key_windowBackgroundWhiteGrayText6));
arrayList.add(new ThemeDescription(smsView3.titleTextView, ThemeDescription.FLAG_TEXTCOLOR, null, null, null, null, Theme.key_windowBackgroundWhiteBlackText));
if (smsView3.codeField != null) {
for (int a = 0; a < smsView3.codeField.length; a++) {
arrayList.add(new ThemeDescription(smsView3.codeField[a], ThemeDescription.FLAG_TEXTCOLOR, null, null, null, null, Theme.key_windowBackgroundWhiteBlackText));
arrayList.add(new ThemeDescription(smsView3.codeField[a], ThemeDescription.FLAG_BACKGROUNDFILTER, null, null, null, null, Theme.key_windowBackgroundWhiteInputFieldActivated));
}
}
arrayList.add(new ThemeDescription(smsView3.timeText, ThemeDescription.FLAG_TEXTCOLOR, null, null, null, null, Theme.key_windowBackgroundWhiteGrayText6));
arrayList.add(new ThemeDescription(smsView3.problemText, ThemeDescription.FLAG_TEXTCOLOR, null, null, null, null, Theme.key_windowBackgroundWhiteBlueText4));
arrayList.add(new ThemeDescription(smsView3.progressView, 0, new Class[]{ProgressView.class}, new String[]{"paint"}, null, null, null, Theme.key_login_progressInner));
arrayList.add(new ThemeDescription(smsView3.progressView, 0, new Class[]{ProgressView.class}, new String[]{"paint"}, null, null, null, Theme.key_login_progressOuter));
arrayList.add(new ThemeDescription(smsView3.blackImageView, ThemeDescription.FLAG_IMAGECOLOR, null, null, null, null, Theme.key_windowBackgroundWhiteBlackText));
arrayList.add(new ThemeDescription(smsView3.blueImageView, ThemeDescription.FLAG_IMAGECOLOR, null, null, null, null, Theme.key_chats_actionBackground));
arrayList.add(new ThemeDescription(smsView4.confirmTextView, ThemeDescription.FLAG_TEXTCOLOR, null, null, null, null, Theme.key_windowBackgroundWhiteGrayText6));
arrayList.add(new ThemeDescription(smsView4.titleTextView, ThemeDescription.FLAG_TEXTCOLOR, null, null, null, null, Theme.key_windowBackgroundWhiteBlackText));
if (smsView4.codeField != null) {
for (int a = 0; a < smsView4.codeField.length; a++) {
arrayList.add(new ThemeDescription(smsView4.codeField[a], ThemeDescription.FLAG_TEXTCOLOR, null, null, null, null, Theme.key_windowBackgroundWhiteBlackText));
arrayList.add(new ThemeDescription(smsView4.codeField[a], ThemeDescription.FLAG_BACKGROUNDFILTER, null, null, null, null, Theme.key_windowBackgroundWhiteInputFieldActivated));
}
}
arrayList.add(new ThemeDescription(smsView4.timeText, ThemeDescription.FLAG_TEXTCOLOR, null, null, null, null, Theme.key_windowBackgroundWhiteGrayText6));
arrayList.add(new ThemeDescription(smsView4.problemText, ThemeDescription.FLAG_TEXTCOLOR, null, null, null, null, Theme.key_windowBackgroundWhiteBlueText4));
arrayList.add(new ThemeDescription(smsView4.progressView, 0, new Class[]{ProgressView.class}, new String[]{"paint"}, null, null, null, Theme.key_login_progressInner));
arrayList.add(new ThemeDescription(smsView4.progressView, 0, new Class[]{ProgressView.class}, new String[]{"paint"}, null, null, null, Theme.key_login_progressOuter));
arrayList.add(new ThemeDescription(smsView4.blackImageView, ThemeDescription.FLAG_IMAGECOLOR, null, null, null, null, Theme.key_windowBackgroundWhiteBlackText));
arrayList.add(new ThemeDescription(smsView4.blueImageView, ThemeDescription.FLAG_IMAGECOLOR, null, null, null, null, Theme.key_chats_actionBackground));
2020-04-24 11:21:58 +02:00
return arrayList;
2017-03-31 01:58:05 +02:00
}
2020-06-25 17:29:04 +02:00
2013-10-25 17:19:00 +02:00
}