2016-10-11 13:57:01 +02:00
|
|
|
|
/*
|
2019-01-23 18:03:33 +01:00
|
|
|
|
* This is the source code of Telegram for Android v. 5.x.x.
|
2016-10-11 13:57:01 +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.
|
2016-10-11 13:57:01 +02:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
package org.telegram.ui;
|
|
|
|
|
|
2022-03-11 17:49:54 +01:00
|
|
|
|
import static android.widget.LinearLayout.HORIZONTAL;
|
|
|
|
|
|
2016-10-11 13:57:01 +02:00
|
|
|
|
import android.animation.Animator;
|
2017-03-31 01:58:05 +02:00
|
|
|
|
import android.animation.AnimatorListenerAdapter;
|
2016-10-11 13:57:01 +02:00
|
|
|
|
import android.animation.AnimatorSet;
|
|
|
|
|
import android.animation.ObjectAnimator;
|
|
|
|
|
import android.content.Context;
|
|
|
|
|
import android.content.Intent;
|
|
|
|
|
import android.net.Uri;
|
|
|
|
|
import android.telephony.TelephonyManager;
|
|
|
|
|
import android.text.Editable;
|
|
|
|
|
import android.text.InputType;
|
|
|
|
|
import android.text.TextUtils;
|
|
|
|
|
import android.text.TextWatcher;
|
|
|
|
|
import android.util.TypedValue;
|
|
|
|
|
import android.view.Gravity;
|
2019-02-08 03:30:32 +01:00
|
|
|
|
import android.view.KeyEvent;
|
2016-10-11 13:57:01 +02:00
|
|
|
|
import android.view.View;
|
|
|
|
|
import android.view.inputmethod.EditorInfo;
|
|
|
|
|
import android.widget.AdapterView;
|
|
|
|
|
import android.widget.FrameLayout;
|
|
|
|
|
import android.widget.LinearLayout;
|
|
|
|
|
import android.widget.ScrollView;
|
|
|
|
|
import android.widget.TextView;
|
|
|
|
|
|
|
|
|
|
import org.telegram.PhoneFormat.PhoneFormat;
|
|
|
|
|
import org.telegram.messenger.AndroidUtilities;
|
|
|
|
|
import org.telegram.messenger.ApplicationLoader;
|
|
|
|
|
import org.telegram.messenger.ContactsController;
|
|
|
|
|
import org.telegram.messenger.FileLog;
|
|
|
|
|
import org.telegram.messenger.LocaleController;
|
|
|
|
|
import org.telegram.messenger.MessagesController;
|
|
|
|
|
import org.telegram.messenger.R;
|
|
|
|
|
import org.telegram.tgnet.ConnectionsManager;
|
|
|
|
|
import org.telegram.tgnet.TLRPC;
|
|
|
|
|
import org.telegram.ui.ActionBar.ActionBar;
|
|
|
|
|
import org.telegram.ui.ActionBar.ActionBarMenu;
|
|
|
|
|
import org.telegram.ui.ActionBar.ActionBarMenuItem;
|
2017-03-31 01:58:05 +02:00
|
|
|
|
import org.telegram.ui.ActionBar.AlertDialog;
|
2016-10-11 13:57:01 +02: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;
|
|
|
|
|
import org.telegram.ui.Components.AlertsCreator;
|
2016-10-11 13:57:01 +02:00
|
|
|
|
import org.telegram.ui.Components.AvatarDrawable;
|
|
|
|
|
import org.telegram.ui.Components.BackupImageView;
|
|
|
|
|
import org.telegram.ui.Components.ContextProgressView;
|
2017-12-08 18:35:59 +01:00
|
|
|
|
import org.telegram.ui.Components.EditTextBoldCursor;
|
2016-10-11 13:57:01 +02:00
|
|
|
|
import org.telegram.ui.Components.HintEditText;
|
|
|
|
|
import org.telegram.ui.Components.LayoutHelper;
|
|
|
|
|
|
|
|
|
|
import java.io.BufferedReader;
|
|
|
|
|
import java.io.InputStreamReader;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.Collections;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
|
2020-07-26 18:07:20 +02:00
|
|
|
|
import tw.nekomimi.nekogram.utils.VibrateUtil;
|
|
|
|
|
|
2016-10-11 13:57:01 +02:00
|
|
|
|
public class NewContactActivity extends BaseFragment implements AdapterView.OnItemSelectedListener {
|
|
|
|
|
|
2019-12-31 14:08:08 +01:00
|
|
|
|
private LinearLayout contentLayout;
|
2016-10-11 13:57:01 +02:00
|
|
|
|
private ActionBarMenuItem editDoneItem;
|
|
|
|
|
private ContextProgressView editDoneItemProgress;
|
2017-12-08 18:35:59 +01:00
|
|
|
|
private EditTextBoldCursor firstNameField;
|
|
|
|
|
private EditTextBoldCursor lastNameField;
|
|
|
|
|
private EditTextBoldCursor codeField;
|
2016-10-11 13:57:01 +02:00
|
|
|
|
private HintEditText phoneField;
|
|
|
|
|
private BackupImageView avatarImage;
|
|
|
|
|
private TextView countryButton;
|
|
|
|
|
private AvatarDrawable avatarDrawable;
|
|
|
|
|
private AnimatorSet editDoneItemAnimation;
|
2017-03-31 01:58:05 +02:00
|
|
|
|
private TextView textView;
|
|
|
|
|
private View lineView;
|
2016-10-11 13:57:01 +02:00
|
|
|
|
|
|
|
|
|
private ArrayList<String> countriesArray = new ArrayList<>();
|
|
|
|
|
private HashMap<String, String> countriesMap = new HashMap<>();
|
|
|
|
|
private HashMap<String, String> codesMap = new HashMap<>();
|
|
|
|
|
private HashMap<String, String> phoneFormatMap = new HashMap<>();
|
|
|
|
|
|
|
|
|
|
private boolean ignoreOnTextChange;
|
|
|
|
|
private boolean ignoreOnPhoneChange;
|
|
|
|
|
private int countryState;
|
|
|
|
|
private boolean ignoreSelection;
|
|
|
|
|
private boolean donePressed;
|
2019-07-18 15:01:39 +02:00
|
|
|
|
private String initialPhoneNumber;
|
2020-10-02 23:48:16 +02:00
|
|
|
|
private boolean initialPhoneNumberWithCountryCode;
|
2020-09-30 15:48:47 +02:00
|
|
|
|
private String initialFirstName;
|
|
|
|
|
private String initialLastName;
|
2016-10-11 13:57:01 +02:00
|
|
|
|
|
|
|
|
|
private final static int done_button = 1;
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public View createView(Context context) {
|
|
|
|
|
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
|
|
|
|
|
actionBar.setAllowOverlayTitle(true);
|
|
|
|
|
actionBar.setTitle(LocaleController.getString("AddContactTitle", R.string.AddContactTitle));
|
|
|
|
|
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onItemClick(int id) {
|
|
|
|
|
if (id == -1) {
|
|
|
|
|
finishFragment();
|
|
|
|
|
} else if (id == done_button) {
|
|
|
|
|
if (donePressed) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (firstNameField.length() == 0) {
|
2020-07-26 18:07:20 +02:00
|
|
|
|
VibrateUtil.vibrate();
|
2016-10-11 13:57:01 +02:00
|
|
|
|
AndroidUtilities.shakeView(firstNameField, 2, 0);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (codeField.length() == 0) {
|
2020-07-26 18:07:20 +02:00
|
|
|
|
VibrateUtil.vibrate();
|
2016-10-11 13:57:01 +02:00
|
|
|
|
AndroidUtilities.shakeView(codeField, 2, 0);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (phoneField.length() == 0) {
|
2020-07-26 18:07:20 +02:00
|
|
|
|
VibrateUtil.vibrate();
|
2016-10-11 13:57:01 +02:00
|
|
|
|
AndroidUtilities.shakeView(phoneField, 2, 0);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
donePressed = true;
|
|
|
|
|
showEditDoneProgress(true, true);
|
2017-03-31 01:58:05 +02:00
|
|
|
|
final TLRPC.TL_contacts_importContacts req = new TLRPC.TL_contacts_importContacts();
|
2016-10-11 13:57:01 +02:00
|
|
|
|
final TLRPC.TL_inputPhoneContact inputPhoneContact = new TLRPC.TL_inputPhoneContact();
|
|
|
|
|
inputPhoneContact.first_name = firstNameField.getText().toString();
|
|
|
|
|
inputPhoneContact.last_name = lastNameField.getText().toString();
|
|
|
|
|
inputPhoneContact.phone = "+" + codeField.getText().toString() + phoneField.getText().toString();
|
|
|
|
|
req.contacts.add(inputPhoneContact);
|
2019-01-23 18:03:33 +01:00
|
|
|
|
int reqId = ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> {
|
|
|
|
|
final TLRPC.TL_contacts_importedContacts res = (TLRPC.TL_contacts_importedContacts) response;
|
|
|
|
|
AndroidUtilities.runOnUIThread(() -> {
|
|
|
|
|
donePressed = false;
|
|
|
|
|
if (res != null) {
|
|
|
|
|
if (!res.users.isEmpty()) {
|
|
|
|
|
MessagesController.getInstance(currentAccount).putUsers(res.users, false);
|
|
|
|
|
MessagesController.openChatOrProfileWith(res.users.get(0), null, NewContactActivity.this, 1, true);
|
|
|
|
|
} else {
|
|
|
|
|
if (getParentActivity() == null) {
|
|
|
|
|
return;
|
2016-10-11 13:57:01 +02:00
|
|
|
|
}
|
2019-01-23 18:03:33 +01:00
|
|
|
|
showEditDoneProgress(false, true);
|
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
|
2019-12-31 14:08:08 +01:00
|
|
|
|
builder.setTitle(LocaleController.getString("ContactNotRegisteredTitle", R.string.ContactNotRegisteredTitle));
|
2019-01-23 18:03:33 +01:00
|
|
|
|
builder.setMessage(LocaleController.formatString("ContactNotRegistered", R.string.ContactNotRegistered, ContactsController.formatName(inputPhoneContact.first_name, inputPhoneContact.last_name)));
|
|
|
|
|
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
|
|
|
|
|
builder.setPositiveButton(LocaleController.getString("Invite", R.string.Invite), (dialog, which) -> {
|
|
|
|
|
try {
|
|
|
|
|
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.fromParts("sms", inputPhoneContact.phone, null));
|
|
|
|
|
intent.putExtra("sms_body", ContactsController.getInstance(currentAccount).getInviteText(1));
|
|
|
|
|
getParentActivity().startActivityForResult(intent, 500);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
FileLog.e(e);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
showDialog(builder.create());
|
2016-10-11 13:57:01 +02:00
|
|
|
|
}
|
2019-01-23 18:03:33 +01:00
|
|
|
|
} else {
|
|
|
|
|
showEditDoneProgress(false, true);
|
|
|
|
|
AlertsCreator.processError(currentAccount, error, NewContactActivity.this, req);
|
|
|
|
|
}
|
|
|
|
|
});
|
2016-10-11 13:57:01 +02:00
|
|
|
|
}, ConnectionsManager.RequestFlagFailOnServerErrors);
|
2018-07-30 04:07:02 +02:00
|
|
|
|
ConnectionsManager.getInstance(currentAccount).bindRequestToGuid(reqId, classGuid);
|
2016-10-11 13:57:01 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
avatarDrawable = new AvatarDrawable();
|
2019-09-10 12:56:11 +02:00
|
|
|
|
avatarDrawable.setInfo(5, "", "");
|
2016-10-11 13:57:01 +02:00
|
|
|
|
|
|
|
|
|
ActionBarMenu menu = actionBar.createMenu();
|
2022-06-21 04:51:00 +02:00
|
|
|
|
editDoneItem = menu.addItemWithWidth(done_button, R.drawable.ic_ab_done, AndroidUtilities.dp(56));
|
2019-05-14 14:08:05 +02:00
|
|
|
|
editDoneItem.setContentDescription(LocaleController.getString("Done", R.string.Done));
|
2016-10-11 13:57:01 +02:00
|
|
|
|
|
|
|
|
|
editDoneItemProgress = new ContextProgressView(context, 1);
|
|
|
|
|
editDoneItem.addView(editDoneItemProgress, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
|
|
|
|
|
editDoneItemProgress.setVisibility(View.INVISIBLE);
|
|
|
|
|
|
|
|
|
|
fragmentView = new ScrollView(context);
|
|
|
|
|
|
2019-12-31 14:08:08 +01:00
|
|
|
|
contentLayout = new LinearLayout(context);
|
|
|
|
|
contentLayout.setPadding(AndroidUtilities.dp(24), 0, AndroidUtilities.dp(24), 0);
|
|
|
|
|
contentLayout.setOrientation(LinearLayout.VERTICAL);
|
|
|
|
|
((ScrollView) fragmentView).addView(contentLayout, LayoutHelper.createScroll(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.TOP));
|
|
|
|
|
contentLayout.setOnTouchListener((v, event) -> true);
|
2016-10-11 13:57:01 +02:00
|
|
|
|
|
|
|
|
|
FrameLayout frameLayout = new FrameLayout(context);
|
2019-12-31 14:08:08 +01:00
|
|
|
|
contentLayout.addView(frameLayout, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, 0, 24, 0, 0));
|
2016-10-11 13:57:01 +02:00
|
|
|
|
|
|
|
|
|
avatarImage = new BackupImageView(context);
|
|
|
|
|
avatarImage.setImageDrawable(avatarDrawable);
|
|
|
|
|
frameLayout.addView(avatarImage, LayoutHelper.createFrame(60, 60, Gravity.LEFT | Gravity.TOP, 0, 9, 0, 0));
|
2020-09-30 15:48:47 +02:00
|
|
|
|
boolean needInvalidateAvatar = false;
|
2016-10-11 13:57:01 +02:00
|
|
|
|
|
2017-12-08 18:35:59 +01:00
|
|
|
|
firstNameField = new EditTextBoldCursor(context);
|
2016-10-11 13:57:01 +02:00
|
|
|
|
firstNameField.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
|
2017-03-31 01:58:05 +02:00
|
|
|
|
firstNameField.setHintTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteHintText));
|
|
|
|
|
firstNameField.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
|
2016-10-11 13:57:01 +02:00
|
|
|
|
firstNameField.setMaxLines(1);
|
|
|
|
|
firstNameField.setLines(1);
|
|
|
|
|
firstNameField.setSingleLine(true);
|
2022-03-11 17:49:54 +01:00
|
|
|
|
firstNameField.setBackground(null);
|
|
|
|
|
firstNameField.setLineColors(getThemedColor(Theme.key_windowBackgroundWhiteInputField), getThemedColor(Theme.key_windowBackgroundWhiteInputFieldActivated), getThemedColor(Theme.key_windowBackgroundWhiteRedText3));
|
2016-10-11 13:57:01 +02:00
|
|
|
|
firstNameField.setGravity(Gravity.LEFT);
|
|
|
|
|
firstNameField.setInputType(InputType.TYPE_TEXT_FLAG_CAP_SENTENCES | InputType.TYPE_TEXT_FLAG_AUTO_CORRECT);
|
|
|
|
|
firstNameField.setImeOptions(EditorInfo.IME_ACTION_NEXT);
|
|
|
|
|
firstNameField.setHint(LocaleController.getString("FirstName", R.string.FirstName));
|
2017-12-08 18:35:59 +01:00
|
|
|
|
firstNameField.setCursorColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
|
|
|
|
|
firstNameField.setCursorSize(AndroidUtilities.dp(20));
|
|
|
|
|
firstNameField.setCursorWidth(1.5f);
|
2020-09-30 15:48:47 +02:00
|
|
|
|
if (initialFirstName != null) {
|
|
|
|
|
firstNameField.setText(initialFirstName);
|
|
|
|
|
initialFirstName = null;
|
|
|
|
|
needInvalidateAvatar = true;
|
|
|
|
|
}
|
2016-10-11 13:57:01 +02:00
|
|
|
|
frameLayout.addView(firstNameField, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 34, Gravity.LEFT | Gravity.TOP, 84, 0, 0, 0));
|
2019-01-23 18:03:33 +01:00
|
|
|
|
firstNameField.setOnEditorActionListener((textView, i, keyEvent) -> {
|
|
|
|
|
if (i == EditorInfo.IME_ACTION_NEXT) {
|
|
|
|
|
lastNameField.requestFocus();
|
|
|
|
|
lastNameField.setSelection(lastNameField.length());
|
|
|
|
|
return true;
|
2016-10-11 13:57:01 +02:00
|
|
|
|
}
|
2019-01-23 18:03:33 +01:00
|
|
|
|
return false;
|
2016-10-11 13:57:01 +02:00
|
|
|
|
});
|
|
|
|
|
firstNameField.addTextChangedListener(new TextWatcher() {
|
|
|
|
|
@Override
|
|
|
|
|
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void afterTextChanged(Editable editable) {
|
2020-09-30 15:48:47 +02:00
|
|
|
|
invalidateAvatar();
|
2016-10-11 13:57:01 +02:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2017-12-08 18:35:59 +01:00
|
|
|
|
lastNameField = new EditTextBoldCursor(context);
|
2016-10-11 13:57:01 +02:00
|
|
|
|
lastNameField.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
|
2017-03-31 01:58:05 +02:00
|
|
|
|
lastNameField.setHintTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteHintText));
|
|
|
|
|
lastNameField.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
|
2022-03-11 17:49:54 +01:00
|
|
|
|
lastNameField.setBackground(null);
|
|
|
|
|
lastNameField.setLineColors(getThemedColor(Theme.key_windowBackgroundWhiteInputField), getThemedColor(Theme.key_windowBackgroundWhiteInputFieldActivated), getThemedColor(Theme.key_windowBackgroundWhiteRedText3));
|
2016-10-11 13:57:01 +02:00
|
|
|
|
lastNameField.setMaxLines(1);
|
|
|
|
|
lastNameField.setLines(1);
|
|
|
|
|
lastNameField.setSingleLine(true);
|
|
|
|
|
lastNameField.setGravity(Gravity.LEFT);
|
|
|
|
|
lastNameField.setInputType(InputType.TYPE_TEXT_FLAG_CAP_SENTENCES | InputType.TYPE_TEXT_FLAG_AUTO_CORRECT);
|
|
|
|
|
lastNameField.setImeOptions(EditorInfo.IME_ACTION_NEXT);
|
|
|
|
|
lastNameField.setHint(LocaleController.getString("LastName", R.string.LastName));
|
2017-12-08 18:35:59 +01:00
|
|
|
|
lastNameField.setCursorColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
|
|
|
|
|
lastNameField.setCursorSize(AndroidUtilities.dp(20));
|
|
|
|
|
lastNameField.setCursorWidth(1.5f);
|
2020-09-30 15:48:47 +02:00
|
|
|
|
if (initialLastName != null) {
|
|
|
|
|
lastNameField.setText(initialLastName);
|
|
|
|
|
initialLastName = null;
|
|
|
|
|
needInvalidateAvatar = true;
|
|
|
|
|
}
|
2016-10-11 13:57:01 +02:00
|
|
|
|
frameLayout.addView(lastNameField, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 34, Gravity.LEFT | Gravity.TOP, 84, 44, 0, 0));
|
2019-01-23 18:03:33 +01:00
|
|
|
|
lastNameField.setOnEditorActionListener((textView, i, keyEvent) -> {
|
|
|
|
|
if (i == EditorInfo.IME_ACTION_NEXT) {
|
|
|
|
|
phoneField.requestFocus();
|
|
|
|
|
phoneField.setSelection(phoneField.length());
|
|
|
|
|
return true;
|
2016-10-11 13:57:01 +02:00
|
|
|
|
}
|
2019-01-23 18:03:33 +01:00
|
|
|
|
return false;
|
2016-10-11 13:57:01 +02:00
|
|
|
|
});
|
|
|
|
|
lastNameField.addTextChangedListener(new TextWatcher() {
|
|
|
|
|
@Override
|
|
|
|
|
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void afterTextChanged(Editable editable) {
|
2020-09-30 15:48:47 +02:00
|
|
|
|
invalidateAvatar();
|
2016-10-11 13:57:01 +02:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2020-09-30 15:48:47 +02:00
|
|
|
|
if (needInvalidateAvatar) {
|
|
|
|
|
invalidateAvatar();
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-11 13:57:01 +02:00
|
|
|
|
countryButton = new TextView(context);
|
|
|
|
|
countryButton.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
|
2019-12-31 14:08:08 +01:00
|
|
|
|
countryButton.setPadding(0, AndroidUtilities.dp(4), 0, AndroidUtilities.dp(4));
|
2017-03-31 01:58:05 +02:00
|
|
|
|
countryButton.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
|
2016-10-11 13:57:01 +02:00
|
|
|
|
countryButton.setMaxLines(1);
|
|
|
|
|
countryButton.setSingleLine(true);
|
|
|
|
|
countryButton.setEllipsize(TextUtils.TruncateAt.END);
|
|
|
|
|
countryButton.setGravity(Gravity.LEFT | Gravity.CENTER_HORIZONTAL);
|
2019-12-31 14:08:08 +01:00
|
|
|
|
countryButton.setBackground(Theme.getSelectorDrawable(true));
|
|
|
|
|
contentLayout.addView(countryButton, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 36, 0, 24, 0, 14));
|
2019-01-23 18:03:33 +01:00
|
|
|
|
countryButton.setOnClickListener(view -> {
|
|
|
|
|
CountrySelectActivity fragment = new CountrySelectActivity(true);
|
2021-09-20 00:10:42 +02:00
|
|
|
|
fragment.setCountrySelectActivityDelegate((country) -> {
|
|
|
|
|
selectCountry(country.name);
|
2019-01-23 18:03:33 +01:00
|
|
|
|
phoneField.requestFocus();
|
|
|
|
|
phoneField.setSelection(phoneField.length());
|
|
|
|
|
});
|
|
|
|
|
presentFragment(fragment);
|
2016-10-11 13:57:01 +02:00
|
|
|
|
});
|
|
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
|
lineView = new View(context);
|
|
|
|
|
lineView.setPadding(AndroidUtilities.dp(8), 0, AndroidUtilities.dp(8), 0);
|
|
|
|
|
lineView.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhiteGrayLine));
|
2019-12-31 14:08:08 +01:00
|
|
|
|
contentLayout.addView(lineView, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 1, 0, -17.5f, 0, 0));
|
2016-10-11 13:57:01 +02:00
|
|
|
|
|
|
|
|
|
LinearLayout linearLayout2 = new LinearLayout(context);
|
|
|
|
|
linearLayout2.setOrientation(HORIZONTAL);
|
2019-12-31 14:08:08 +01:00
|
|
|
|
contentLayout.addView(linearLayout2, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, 0, 20, 0, 0));
|
2016-10-11 13:57:01 +02:00
|
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
|
textView = new TextView(context);
|
2016-10-11 13:57:01 +02:00
|
|
|
|
textView.setText("+");
|
2017-03-31 01:58:05 +02:00
|
|
|
|
textView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
|
2016-10-11 13:57:01 +02:00
|
|
|
|
textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
|
2019-05-14 14:08:05 +02:00
|
|
|
|
textView.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO);
|
2016-10-11 13:57:01 +02:00
|
|
|
|
linearLayout2.addView(textView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT));
|
|
|
|
|
|
2017-12-08 18:35:59 +01:00
|
|
|
|
codeField = new EditTextBoldCursor(context);
|
2016-10-11 13:57:01 +02:00
|
|
|
|
codeField.setInputType(InputType.TYPE_CLASS_PHONE);
|
2017-03-31 01:58:05 +02:00
|
|
|
|
codeField.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
|
2022-03-11 17:49:54 +01:00
|
|
|
|
codeField.setBackgroundDrawable(null);
|
|
|
|
|
codeField.setLineColors(getThemedColor(Theme.key_windowBackgroundWhiteInputField), getThemedColor(Theme.key_windowBackgroundWhiteInputFieldActivated), getThemedColor(Theme.key_windowBackgroundWhiteRedText3));
|
2017-12-08 18:35:59 +01:00
|
|
|
|
codeField.setCursorColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
|
|
|
|
|
codeField.setCursorSize(AndroidUtilities.dp(20));
|
|
|
|
|
codeField.setCursorWidth(1.5f);
|
2016-10-11 13:57:01 +02:00
|
|
|
|
codeField.setPadding(AndroidUtilities.dp(10), 0, 0, 0);
|
|
|
|
|
codeField.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
|
|
|
|
|
codeField.setMaxLines(1);
|
|
|
|
|
codeField.setGravity(Gravity.LEFT | Gravity.CENTER_VERTICAL);
|
|
|
|
|
codeField.setImeOptions(EditorInfo.IME_ACTION_NEXT | EditorInfo.IME_FLAG_NO_EXTRACT_UI);
|
|
|
|
|
linearLayout2.addView(codeField, LayoutHelper.createLinear(55, 36, -9, 0, 16, 0));
|
|
|
|
|
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));
|
|
|
|
|
phoneField.setHintText(null);
|
|
|
|
|
countryState = 1;
|
|
|
|
|
} else {
|
|
|
|
|
String country;
|
|
|
|
|
boolean ok = false;
|
|
|
|
|
String textToSet = null;
|
|
|
|
|
if (text.length() > 4) {
|
|
|
|
|
ignoreOnTextChange = true;
|
|
|
|
|
for (int a = 4; a >= 1; a--) {
|
|
|
|
|
String sub = text.substring(0, a);
|
|
|
|
|
country = codesMap.get(sub);
|
|
|
|
|
if (country != null) {
|
|
|
|
|
ok = true;
|
2019-07-18 15:01:39 +02:00
|
|
|
|
textToSet = text.substring(a) + phoneField.getText().toString();
|
2016-10-11 13:57:01 +02:00
|
|
|
|
codeField.setText(text = sub);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!ok) {
|
|
|
|
|
ignoreOnTextChange = true;
|
2019-07-18 15:01:39 +02:00
|
|
|
|
textToSet = text.substring(1) + phoneField.getText().toString();
|
2016-10-11 13:57:01 +02:00
|
|
|
|
codeField.setText(text = text.substring(0, 1));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
country = codesMap.get(text);
|
|
|
|
|
if (country != null) {
|
|
|
|
|
int index = countriesArray.indexOf(country);
|
|
|
|
|
if (index != -1) {
|
|
|
|
|
ignoreSelection = true;
|
|
|
|
|
countryButton.setText(countriesArray.get(index));
|
|
|
|
|
String hint = phoneFormatMap.get(text);
|
|
|
|
|
phoneField.setHintText(hint != null ? hint.replace('X', '–') : null);
|
|
|
|
|
countryState = 0;
|
|
|
|
|
} else {
|
|
|
|
|
countryButton.setText(LocaleController.getString("WrongCountry", R.string.WrongCountry));
|
|
|
|
|
phoneField.setHintText(null);
|
|
|
|
|
countryState = 2;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
countryButton.setText(LocaleController.getString("WrongCountry", R.string.WrongCountry));
|
|
|
|
|
phoneField.setHintText(null);
|
|
|
|
|
countryState = 2;
|
|
|
|
|
}
|
|
|
|
|
if (!ok) {
|
|
|
|
|
codeField.setSelection(codeField.getText().length());
|
|
|
|
|
}
|
|
|
|
|
if (textToSet != null) {
|
2019-07-18 15:01:39 +02:00
|
|
|
|
if (initialPhoneNumber == null) {
|
|
|
|
|
phoneField.requestFocus();
|
|
|
|
|
}
|
2016-10-11 13:57:01 +02:00
|
|
|
|
phoneField.setText(textToSet);
|
|
|
|
|
phoneField.setSelection(phoneField.length());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
ignoreOnTextChange = false;
|
|
|
|
|
}
|
|
|
|
|
});
|
2019-01-23 18:03:33 +01:00
|
|
|
|
codeField.setOnEditorActionListener((textView, i, keyEvent) -> {
|
|
|
|
|
if (i == EditorInfo.IME_ACTION_NEXT) {
|
|
|
|
|
phoneField.requestFocus();
|
|
|
|
|
phoneField.setSelection(phoneField.length());
|
|
|
|
|
return true;
|
2016-10-11 13:57:01 +02:00
|
|
|
|
}
|
2019-01-23 18:03:33 +01:00
|
|
|
|
return false;
|
2016-10-11 13:57:01 +02:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
phoneField = new HintEditText(context);
|
|
|
|
|
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));
|
2022-03-11 17:49:54 +01:00
|
|
|
|
phoneField.setBackgroundDrawable(null);
|
|
|
|
|
phoneField.setLineColors(getThemedColor(Theme.key_windowBackgroundWhiteInputField), getThemedColor(Theme.key_windowBackgroundWhiteInputFieldActivated), getThemedColor(Theme.key_windowBackgroundWhiteRedText3));
|
2016-10-11 13:57:01 +02: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);
|
2016-10-11 13:57:01 +02:00
|
|
|
|
phoneField.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
|
|
|
|
|
phoneField.setMaxLines(1);
|
|
|
|
|
phoneField.setGravity(Gravity.LEFT | Gravity.CENTER_VERTICAL);
|
|
|
|
|
phoneField.setImeOptions(EditorInfo.IME_ACTION_DONE | EditorInfo.IME_FLAG_NO_EXTRACT_UI);
|
|
|
|
|
linearLayout2.addView(phoneField, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 36));
|
|
|
|
|
phoneField.addTextChangedListener(new TextWatcher() {
|
|
|
|
|
|
|
|
|
|
private int characterAction = -1;
|
|
|
|
|
private int actionPosition;
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
characterAction = -1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void afterTextChanged(Editable s) {
|
|
|
|
|
if (ignoreOnPhoneChange) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
int start = phoneField.getSelectionStart();
|
|
|
|
|
String phoneChars = "0123456789";
|
|
|
|
|
String str = phoneField.getText().toString();
|
|
|
|
|
if (characterAction == 3) {
|
2019-07-18 15:01:39 +02:00
|
|
|
|
str = str.substring(0, actionPosition) + str.substring(actionPosition + 1);
|
2016-10-11 13:57:01 +02: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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
phoneField.setText(builder);
|
|
|
|
|
if (start >= 0) {
|
2020-10-15 02:39:36 +02:00
|
|
|
|
phoneField.setSelection(Math.min(start, phoneField.length()));
|
2016-10-11 13:57:01 +02:00
|
|
|
|
}
|
|
|
|
|
phoneField.onTextChange();
|
|
|
|
|
ignoreOnPhoneChange = false;
|
|
|
|
|
}
|
|
|
|
|
});
|
2019-01-23 18:03:33 +01:00
|
|
|
|
phoneField.setOnEditorActionListener((textView, i, keyEvent) -> {
|
|
|
|
|
if (i == EditorInfo.IME_ACTION_DONE) {
|
|
|
|
|
editDoneItem.performClick();
|
|
|
|
|
return true;
|
2016-10-11 13:57:01 +02:00
|
|
|
|
}
|
2019-01-23 18:03:33 +01:00
|
|
|
|
return false;
|
2016-10-11 13:57:01 +02:00
|
|
|
|
});
|
2019-02-08 03:30:32 +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;
|
|
|
|
|
});
|
2016-10-11 13:57:01 +02:00
|
|
|
|
|
|
|
|
|
HashMap<String, String> languageMap = new HashMap<>();
|
|
|
|
|
try {
|
|
|
|
|
BufferedReader reader = new BufferedReader(new InputStreamReader(context.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]);
|
|
|
|
|
if (args.length > 3) {
|
|
|
|
|
phoneFormatMap.put(args[0], args[3]);
|
|
|
|
|
}
|
|
|
|
|
languageMap.put(args[1], args[2]);
|
|
|
|
|
}
|
|
|
|
|
reader.close();
|
|
|
|
|
} catch (Exception e) {
|
2017-03-31 01:58:05 +02:00
|
|
|
|
FileLog.e(e);
|
2016-10-11 13:57:01 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-01-23 18:03:33 +01:00
|
|
|
|
Collections.sort(countriesArray, String::compareTo);
|
2016-10-11 13:57:01 +02:00
|
|
|
|
|
2019-07-18 15:01:39 +02:00
|
|
|
|
if (!TextUtils.isEmpty(initialPhoneNumber)) {
|
2020-10-02 23:48:16 +02:00
|
|
|
|
TLRPC.User user = getUserConfig().getCurrentUser();
|
|
|
|
|
if (initialPhoneNumber.startsWith("+")) {
|
|
|
|
|
codeField.setText(initialPhoneNumber.substring(1));
|
|
|
|
|
} else if (initialPhoneNumberWithCountryCode || user == null || TextUtils.isEmpty(user.phone)) {
|
|
|
|
|
codeField.setText(initialPhoneNumber);
|
|
|
|
|
} else {
|
|
|
|
|
String phone = user.phone;
|
|
|
|
|
for (int a = 4; a >= 1; a--) {
|
|
|
|
|
String sub = phone.substring(0, a);
|
|
|
|
|
String country = codesMap.get(sub);
|
|
|
|
|
if (country != null) {
|
|
|
|
|
codeField.setText(sub);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
phoneField.setText(initialPhoneNumber);
|
|
|
|
|
}
|
2019-07-18 15:01:39 +02:00
|
|
|
|
initialPhoneNumber = null;
|
|
|
|
|
} else {
|
|
|
|
|
String country = null;
|
|
|
|
|
try {
|
|
|
|
|
TelephonyManager telephonyManager = (TelephonyManager) ApplicationLoader.applicationContext.getSystemService(Context.TELEPHONY_SERVICE);
|
|
|
|
|
if (telephonyManager != null) {
|
|
|
|
|
country = telephonyManager.getSimCountryIso().toUpperCase();
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
FileLog.e(e);
|
2016-10-11 13:57:01 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-07-18 15:01:39 +02:00
|
|
|
|
if (country != null) {
|
|
|
|
|
String countryName = languageMap.get(country);
|
|
|
|
|
if (countryName != null) {
|
|
|
|
|
int index = countriesArray.indexOf(countryName);
|
|
|
|
|
if (index != -1) {
|
|
|
|
|
codeField.setText(countriesMap.get(countryName));
|
|
|
|
|
countryState = 0;
|
|
|
|
|
}
|
2016-10-11 13:57:01 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2019-07-18 15:01:39 +02:00
|
|
|
|
if (codeField.length() == 0) {
|
|
|
|
|
countryButton.setText(LocaleController.getString("ChooseCountry", R.string.ChooseCountry));
|
|
|
|
|
phoneField.setHintText(null);
|
|
|
|
|
countryState = 1;
|
|
|
|
|
}
|
2016-10-11 13:57:01 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return fragmentView;
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-15 02:39:36 +02:00
|
|
|
|
public static String getPhoneNumber(Context context, TLRPC.User user, String number, boolean withCoutryCode) {
|
|
|
|
|
HashMap<String, String> codesMap = new HashMap<>();
|
|
|
|
|
try {
|
|
|
|
|
BufferedReader reader = new BufferedReader(new InputStreamReader(context.getResources().getAssets().open("countries.txt")));
|
|
|
|
|
String line;
|
|
|
|
|
while ((line = reader.readLine()) != null) {
|
|
|
|
|
String[] args = line.split(";");
|
|
|
|
|
codesMap.put(args[0], args[2]);
|
|
|
|
|
}
|
|
|
|
|
reader.close();
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
FileLog.e(e);
|
|
|
|
|
}
|
|
|
|
|
if (number.startsWith("+")) {
|
|
|
|
|
return number;
|
|
|
|
|
} else if (withCoutryCode || user == null || TextUtils.isEmpty(user.phone)) {
|
|
|
|
|
return "+" + number;
|
|
|
|
|
} else {
|
|
|
|
|
String phone = user.phone;
|
|
|
|
|
for (int a = 4; a >= 1; a--) {
|
|
|
|
|
String sub = phone.substring(0, a);
|
|
|
|
|
String country = codesMap.get(sub);
|
|
|
|
|
if (country != null) {
|
|
|
|
|
return "+" + sub + number;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return number;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-30 15:48:47 +02:00
|
|
|
|
private void invalidateAvatar() {
|
|
|
|
|
avatarDrawable.setInfo(5, firstNameField.getText().toString(), lastNameField.getText().toString());
|
|
|
|
|
avatarImage.invalidate();
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-11 13:57:01 +02:00
|
|
|
|
@Override
|
|
|
|
|
public void onTransitionAnimationEnd(boolean isOpen, boolean backward) {
|
|
|
|
|
if (isOpen) {
|
2019-12-31 14:08:08 +01:00
|
|
|
|
View focusedView = contentLayout.findFocus();
|
|
|
|
|
if (focusedView == null) {
|
|
|
|
|
firstNameField.requestFocus();
|
|
|
|
|
focusedView = firstNameField;
|
|
|
|
|
}
|
|
|
|
|
AndroidUtilities.showKeyboard(focusedView);
|
2016-10-11 13:57:01 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-02 23:48:16 +02:00
|
|
|
|
public void setInitialPhoneNumber(String value, boolean withCoutryCode) {
|
2019-07-18 15:01:39 +02:00
|
|
|
|
initialPhoneNumber = value;
|
2020-10-02 23:48:16 +02:00
|
|
|
|
initialPhoneNumberWithCountryCode = withCoutryCode;
|
2019-07-18 15:01:39 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-09-30 15:48:47 +02:00
|
|
|
|
public void setInitialName(String firstName, String lastName) {
|
|
|
|
|
initialFirstName = firstName;
|
|
|
|
|
initialLastName = lastName;
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-11 13:57:01 +02:00
|
|
|
|
public void selectCountry(String name) {
|
|
|
|
|
int index = countriesArray.indexOf(name);
|
|
|
|
|
if (index != -1) {
|
|
|
|
|
ignoreOnTextChange = true;
|
|
|
|
|
String code = countriesMap.get(name);
|
|
|
|
|
codeField.setText(code);
|
|
|
|
|
countryButton.setText(name);
|
|
|
|
|
String hint = phoneFormatMap.get(code);
|
|
|
|
|
phoneField.setHintText(hint != null ? hint.replace('X', '–') : null);
|
|
|
|
|
countryState = 0;
|
|
|
|
|
ignoreOnTextChange = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onNothingSelected(AdapterView<?> adapterView) {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void showEditDoneProgress(final boolean show, boolean animated) {
|
|
|
|
|
if (editDoneItemAnimation != null) {
|
|
|
|
|
editDoneItemAnimation.cancel();
|
|
|
|
|
}
|
|
|
|
|
if (!animated) {
|
|
|
|
|
if (show) {
|
2019-07-18 15:01:39 +02:00
|
|
|
|
editDoneItem.getContentView().setScaleX(0.1f);
|
|
|
|
|
editDoneItem.getContentView().setScaleY(0.1f);
|
|
|
|
|
editDoneItem.getContentView().setAlpha(0.0f);
|
2016-10-11 13:57:01 +02:00
|
|
|
|
editDoneItemProgress.setScaleX(1.0f);
|
|
|
|
|
editDoneItemProgress.setScaleY(1.0f);
|
|
|
|
|
editDoneItemProgress.setAlpha(1.0f);
|
2019-07-18 15:01:39 +02:00
|
|
|
|
editDoneItem.getContentView().setVisibility(View.INVISIBLE);
|
2016-10-11 13:57:01 +02:00
|
|
|
|
editDoneItemProgress.setVisibility(View.VISIBLE);
|
|
|
|
|
editDoneItem.setEnabled(false);
|
|
|
|
|
} else {
|
|
|
|
|
editDoneItemProgress.setScaleX(0.1f);
|
|
|
|
|
editDoneItemProgress.setScaleY(0.1f);
|
|
|
|
|
editDoneItemProgress.setAlpha(0.0f);
|
2019-07-18 15:01:39 +02:00
|
|
|
|
editDoneItem.getContentView().setScaleX(1.0f);
|
|
|
|
|
editDoneItem.getContentView().setScaleY(1.0f);
|
|
|
|
|
editDoneItem.getContentView().setAlpha(1.0f);
|
|
|
|
|
editDoneItem.getContentView().setVisibility(View.VISIBLE);
|
2016-10-11 13:57:01 +02:00
|
|
|
|
editDoneItemProgress.setVisibility(View.INVISIBLE);
|
|
|
|
|
editDoneItem.setEnabled(true);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
editDoneItemAnimation = new AnimatorSet();
|
|
|
|
|
if (show) {
|
|
|
|
|
editDoneItemProgress.setVisibility(View.VISIBLE);
|
|
|
|
|
editDoneItem.setEnabled(false);
|
|
|
|
|
editDoneItemAnimation.playTogether(
|
2019-07-18 15:01:39 +02:00
|
|
|
|
ObjectAnimator.ofFloat(editDoneItem.getContentView(), "scaleX", 0.1f),
|
|
|
|
|
ObjectAnimator.ofFloat(editDoneItem.getContentView(), "scaleY", 0.1f),
|
|
|
|
|
ObjectAnimator.ofFloat(editDoneItem.getContentView(), "alpha", 0.0f),
|
2016-10-11 13:57:01 +02:00
|
|
|
|
ObjectAnimator.ofFloat(editDoneItemProgress, "scaleX", 1.0f),
|
|
|
|
|
ObjectAnimator.ofFloat(editDoneItemProgress, "scaleY", 1.0f),
|
|
|
|
|
ObjectAnimator.ofFloat(editDoneItemProgress, "alpha", 1.0f));
|
|
|
|
|
} else {
|
2019-07-18 15:01:39 +02:00
|
|
|
|
editDoneItem.getContentView().setVisibility(View.VISIBLE);
|
2016-10-11 13:57:01 +02:00
|
|
|
|
editDoneItem.setEnabled(true);
|
|
|
|
|
editDoneItemAnimation.playTogether(
|
|
|
|
|
ObjectAnimator.ofFloat(editDoneItemProgress, "scaleX", 0.1f),
|
|
|
|
|
ObjectAnimator.ofFloat(editDoneItemProgress, "scaleY", 0.1f),
|
|
|
|
|
ObjectAnimator.ofFloat(editDoneItemProgress, "alpha", 0.0f),
|
2019-07-18 15:01:39 +02:00
|
|
|
|
ObjectAnimator.ofFloat(editDoneItem.getContentView(), "scaleX", 1.0f),
|
|
|
|
|
ObjectAnimator.ofFloat(editDoneItem.getContentView(), "scaleY", 1.0f),
|
|
|
|
|
ObjectAnimator.ofFloat(editDoneItem.getContentView(), "alpha", 1.0f));
|
2016-10-11 13:57:01 +02:00
|
|
|
|
|
|
|
|
|
}
|
2017-03-31 01:58:05 +02:00
|
|
|
|
editDoneItemAnimation.addListener(new AnimatorListenerAdapter() {
|
2016-10-11 13:57:01 +02:00
|
|
|
|
@Override
|
|
|
|
|
public void onAnimationEnd(Animator animation) {
|
|
|
|
|
if (editDoneItemAnimation != null && editDoneItemAnimation.equals(animation)) {
|
|
|
|
|
if (!show) {
|
|
|
|
|
editDoneItemProgress.setVisibility(View.INVISIBLE);
|
|
|
|
|
} else {
|
2019-07-18 15:01:39 +02:00
|
|
|
|
editDoneItem.getContentView().setVisibility(View.INVISIBLE);
|
2016-10-11 13:57:01 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onAnimationCancel(Animator animation) {
|
|
|
|
|
if (editDoneItemAnimation != null && editDoneItemAnimation.equals(animation)) {
|
|
|
|
|
editDoneItemAnimation = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
editDoneItemAnimation.setDuration(150);
|
|
|
|
|
editDoneItemAnimation.start();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
|
@Override
|
2020-04-24 11:21:58 +02:00
|
|
|
|
public ArrayList<ThemeDescription> getThemeDescriptions() {
|
|
|
|
|
ArrayList<ThemeDescription> themeDescriptions = new ArrayList<>();
|
|
|
|
|
|
2019-01-23 18:03:33 +01:00
|
|
|
|
ThemeDescription.ThemeDescriptionDelegate cellDelegate = () -> {
|
|
|
|
|
if (avatarImage != null) {
|
2020-09-30 15:48:47 +02:00
|
|
|
|
invalidateAvatar();
|
2017-03-31 01:58:05 +02:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2020-04-24 11:21:58 +02:00
|
|
|
|
themeDescriptions.add(new ThemeDescription(fragmentView, ThemeDescription.FLAG_BACKGROUND, null, null, null, null, Theme.key_windowBackgroundWhite));
|
|
|
|
|
|
|
|
|
|
themeDescriptions.add(new ThemeDescription(actionBar, ThemeDescription.FLAG_BACKGROUND, null, null, null, null, Theme.key_actionBarDefault));
|
|
|
|
|
themeDescriptions.add(new ThemeDescription(fragmentView, ThemeDescription.FLAG_LISTGLOWCOLOR, null, null, null, null, Theme.key_actionBarDefault));
|
|
|
|
|
themeDescriptions.add(new ThemeDescription(actionBar, ThemeDescription.FLAG_AB_ITEMSCOLOR, null, null, null, null, Theme.key_actionBarDefaultIcon));
|
|
|
|
|
themeDescriptions.add(new ThemeDescription(actionBar, ThemeDescription.FLAG_AB_TITLECOLOR, null, null, null, null, Theme.key_actionBarDefaultTitle));
|
|
|
|
|
themeDescriptions.add(new ThemeDescription(actionBar, ThemeDescription.FLAG_AB_SELECTORCOLOR, null, null, null, null, Theme.key_actionBarDefaultSelector));
|
|
|
|
|
|
|
|
|
|
themeDescriptions.add(new ThemeDescription(firstNameField, ThemeDescription.FLAG_TEXTCOLOR, null, null, null, null, Theme.key_windowBackgroundWhiteBlackText));
|
|
|
|
|
themeDescriptions.add(new ThemeDescription(firstNameField, ThemeDescription.FLAG_HINTTEXTCOLOR, null, null, null, null, Theme.key_windowBackgroundWhiteHintText));
|
|
|
|
|
themeDescriptions.add(new ThemeDescription(firstNameField, ThemeDescription.FLAG_BACKGROUNDFILTER, null, null, null, null, Theme.key_windowBackgroundWhiteInputField));
|
|
|
|
|
themeDescriptions.add(new ThemeDescription(firstNameField, ThemeDescription.FLAG_BACKGROUNDFILTER | ThemeDescription.FLAG_DRAWABLESELECTEDSTATE, null, null, null, null, Theme.key_windowBackgroundWhiteInputFieldActivated));
|
|
|
|
|
|
|
|
|
|
themeDescriptions.add(new ThemeDescription(lastNameField, ThemeDescription.FLAG_TEXTCOLOR, null, null, null, null, Theme.key_windowBackgroundWhiteBlackText));
|
|
|
|
|
themeDescriptions.add(new ThemeDescription(lastNameField, ThemeDescription.FLAG_HINTTEXTCOLOR, null, null, null, null, Theme.key_windowBackgroundWhiteHintText));
|
|
|
|
|
themeDescriptions.add(new ThemeDescription(lastNameField, ThemeDescription.FLAG_BACKGROUNDFILTER, null, null, null, null, Theme.key_windowBackgroundWhiteInputField));
|
|
|
|
|
themeDescriptions.add(new ThemeDescription(lastNameField, ThemeDescription.FLAG_BACKGROUNDFILTER | ThemeDescription.FLAG_DRAWABLESELECTEDSTATE, null, null, null, null, Theme.key_windowBackgroundWhiteInputFieldActivated));
|
|
|
|
|
|
|
|
|
|
themeDescriptions.add(new ThemeDescription(codeField, ThemeDescription.FLAG_TEXTCOLOR, null, null, null, null, Theme.key_windowBackgroundWhiteBlackText));
|
|
|
|
|
themeDescriptions.add(new ThemeDescription(codeField, ThemeDescription.FLAG_BACKGROUNDFILTER, null, null, null, null, Theme.key_windowBackgroundWhiteInputField));
|
|
|
|
|
themeDescriptions.add(new ThemeDescription(codeField, ThemeDescription.FLAG_BACKGROUNDFILTER | ThemeDescription.FLAG_DRAWABLESELECTEDSTATE, null, null, null, null, Theme.key_windowBackgroundWhiteInputFieldActivated));
|
|
|
|
|
|
|
|
|
|
themeDescriptions.add(new ThemeDescription(phoneField, ThemeDescription.FLAG_TEXTCOLOR, null, null, null, null, Theme.key_windowBackgroundWhiteBlackText));
|
|
|
|
|
themeDescriptions.add(new ThemeDescription(phoneField, ThemeDescription.FLAG_HINTTEXTCOLOR, null, null, null, null, Theme.key_windowBackgroundWhiteHintText));
|
|
|
|
|
themeDescriptions.add(new ThemeDescription(phoneField, ThemeDescription.FLAG_BACKGROUNDFILTER, null, null, null, null, Theme.key_windowBackgroundWhiteInputField));
|
|
|
|
|
themeDescriptions.add(new ThemeDescription(phoneField, ThemeDescription.FLAG_BACKGROUNDFILTER | ThemeDescription.FLAG_DRAWABLESELECTEDSTATE, null, null, null, null, Theme.key_windowBackgroundWhiteInputFieldActivated));
|
|
|
|
|
|
|
|
|
|
themeDescriptions.add(new ThemeDescription(textView, ThemeDescription.FLAG_TEXTCOLOR, null, null, null, null, Theme.key_windowBackgroundWhiteBlackText));
|
|
|
|
|
|
|
|
|
|
themeDescriptions.add(new ThemeDescription(lineView, ThemeDescription.FLAG_BACKGROUND, null, null, null, null, Theme.key_windowBackgroundWhiteGrayLine));
|
|
|
|
|
|
|
|
|
|
themeDescriptions.add(new ThemeDescription(countryButton, ThemeDescription.FLAG_TEXTCOLOR, null, null, null, null, Theme.key_windowBackgroundWhiteBlackText));
|
|
|
|
|
themeDescriptions.add(new ThemeDescription(countryButton, ThemeDescription.FLAG_SELECTORWHITE, null, null, null, null, Theme.key_windowBackgroundWhite));
|
|
|
|
|
themeDescriptions.add(new ThemeDescription(countryButton, ThemeDescription.FLAG_SELECTORWHITE, null, null, null, null, Theme.key_listSelector));
|
|
|
|
|
|
|
|
|
|
themeDescriptions.add(new ThemeDescription(editDoneItemProgress, 0, null, null, null, null, Theme.key_contextProgressInner2));
|
|
|
|
|
themeDescriptions.add(new ThemeDescription(editDoneItemProgress, 0, null, null, null, null, Theme.key_contextProgressOuter2));
|
|
|
|
|
|
|
|
|
|
themeDescriptions.add(new ThemeDescription(null, 0, null, null, Theme.avatarDrawables, cellDelegate, Theme.key_avatar_text));
|
|
|
|
|
themeDescriptions.add(new ThemeDescription(null, 0, null, null, null, cellDelegate, Theme.key_avatar_backgroundRed));
|
|
|
|
|
themeDescriptions.add(new ThemeDescription(null, 0, null, null, null, cellDelegate, Theme.key_avatar_backgroundOrange));
|
|
|
|
|
themeDescriptions.add(new ThemeDescription(null, 0, null, null, null, cellDelegate, Theme.key_avatar_backgroundViolet));
|
|
|
|
|
themeDescriptions.add(new ThemeDescription(null, 0, null, null, null, cellDelegate, Theme.key_avatar_backgroundGreen));
|
|
|
|
|
themeDescriptions.add(new ThemeDescription(null, 0, null, null, null, cellDelegate, Theme.key_avatar_backgroundCyan));
|
|
|
|
|
themeDescriptions.add(new ThemeDescription(null, 0, null, null, null, cellDelegate, Theme.key_avatar_backgroundBlue));
|
|
|
|
|
themeDescriptions.add(new ThemeDescription(null, 0, null, null, null, cellDelegate, Theme.key_avatar_backgroundPink));
|
|
|
|
|
|
|
|
|
|
return themeDescriptions;
|
2016-10-11 13:57:01 +02:00
|
|
|
|
}
|
|
|
|
|
}
|