discord-jadx/app/src/main/java/com/discord/views/phone/PhoneOrEmailInputView.java
2021-07-19 21:45:22 +02:00

312 lines
14 KiB
Java

package com.discord.views.phone;
import android.animation.LayoutTransition;
import android.content.Context;
import android.content.res.TypedArray;
import android.os.Build;
import android.text.Editable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import c.a.i.j2;
import com.discord.R;
import com.discord.models.phone.PhoneCountryCode;
import com.discord.utilities.phone.PhoneUtils;
import com.discord.utilities.view.extensions.ViewExtensions;
import com.discord.widgets.phone.WidgetPhoneCountryCodeBottomSheet;
import com.google.android.material.textfield.TextInputEditText;
import com.google.android.material.textfield.TextInputLayout;
import d0.z.d.m;
import d0.z.d.o;
import kotlin.Unit;
import kotlin.jvm.functions.Function0;
import kotlin.jvm.functions.Function1;
/* compiled from: PhoneOrEmailInputView.kt */
public final class PhoneOrEmailInputView extends LinearLayout {
public static final /* synthetic */ int i = 0;
public final j2 j;
public Mode k;
public CharSequence l;
public CharSequence m;
/* compiled from: PhoneOrEmailInputView.kt */
public enum Mode {
ADAPTIVE,
EMAIL,
PHONE
}
/* compiled from: PhoneOrEmailInputView.kt */
public static final class a extends o implements Function1<Editable, Unit> {
public final /* synthetic */ Function0 $onAfterTextChanged;
/* JADX INFO: super call moved to the top of the method (can break code semantics) */
public a(Function0 function0) {
super(1);
this.$onAfterTextChanged = function0;
}
/* Return type fixed from 'java.lang.Object' to match base method */
/* JADX DEBUG: Method arguments types fixed to match base method, original types: [java.lang.Object] */
@Override // kotlin.jvm.functions.Function1
public Unit invoke(Editable editable) {
m.checkNotNullParameter(editable, "it");
this.$onAfterTextChanged.mo1invoke();
return Unit.a;
}
}
/* compiled from: PhoneOrEmailInputView.kt */
public static final class b extends o implements Function1<Editable, Unit> {
public final /* synthetic */ Function0 $onAfterTextChanged;
public final /* synthetic */ PhoneOrEmailInputView this$0;
/* JADX INFO: super call moved to the top of the method (can break code semantics) */
public b(PhoneOrEmailInputView phoneOrEmailInputView, Function0 function0) {
super(1);
this.this$0 = phoneOrEmailInputView;
this.$onAfterTextChanged = function0;
}
/* Return type fixed from 'java.lang.Object' to match base method */
/* JADX DEBUG: Method arguments types fixed to match base method, original types: [java.lang.Object] */
@Override // kotlin.jvm.functions.Function1
public Unit invoke(Editable editable) {
m.checkNotNullParameter(editable, "it");
PhoneOrEmailInputView phoneOrEmailInputView = this.this$0;
int i = PhoneOrEmailInputView.i;
phoneOrEmailInputView.c();
this.$onAfterTextChanged.mo1invoke();
return Unit.a;
}
}
/* compiled from: PhoneOrEmailInputView.kt */
public static final class c extends o implements Function1<View, Unit> {
public final /* synthetic */ Fragment $fragment;
/* JADX INFO: super call moved to the top of the method (can break code semantics) */
public c(Fragment fragment) {
super(1);
this.$fragment = fragment;
}
/* Return type fixed from 'java.lang.Object' to match base method */
/* JADX DEBUG: Method arguments types fixed to match base method, original types: [java.lang.Object] */
@Override // kotlin.jvm.functions.Function1
public Unit invoke(View view) {
m.checkNotNullParameter(view, "it");
WidgetPhoneCountryCodeBottomSheet.Companion companion = WidgetPhoneCountryCodeBottomSheet.Companion;
FragmentManager parentFragmentManager = this.$fragment.getParentFragmentManager();
m.checkNotNullExpressionValue(parentFragmentManager, "fragment.parentFragmentManager");
companion.show(parentFragmentManager);
return Unit.a;
}
}
/* compiled from: PhoneOrEmailInputView.kt */
public static final class d extends o implements Function1<Editable, Unit> {
public final /* synthetic */ PhoneOrEmailInputView this$0;
/* JADX INFO: super call moved to the top of the method (can break code semantics) */
public d(PhoneOrEmailInputView phoneOrEmailInputView) {
super(1);
this.this$0 = phoneOrEmailInputView;
}
/* Return type fixed from 'java.lang.Object' to match base method */
/* JADX DEBUG: Method arguments types fixed to match base method, original types: [java.lang.Object] */
@Override // kotlin.jvm.functions.Function1
public Unit invoke(Editable editable) {
m.checkNotNullParameter(editable, "it");
PhoneOrEmailInputView phoneOrEmailInputView = this.this$0;
TextInputLayout textInputLayout = phoneOrEmailInputView.j.d;
m.checkNotNullExpressionValue(textInputLayout, "binding.phoneOrEmailMainInputWrap");
String textOrEmpty = ViewExtensions.getTextOrEmpty(textInputLayout);
if (phoneOrEmailInputView.k.ordinal() != 2) {
phoneOrEmailInputView.l = textOrEmpty;
} else {
phoneOrEmailInputView.m = textOrEmpty;
}
this.this$0.c();
return Unit.a;
}
}
/* JADX INFO: super call moved to the top of the method (can break code semantics) */
public PhoneOrEmailInputView(Context context, AttributeSet attributeSet) {
super(context, attributeSet, 0);
m.checkNotNullParameter(context, "context");
LayoutInflater.from(context).inflate(2131558782, this);
int i2 = 2131364314;
TextInputLayout textInputLayout = (TextInputLayout) findViewById(2131364314);
if (textInputLayout != null) {
i2 = 2131364315;
TextInputEditText textInputEditText = (TextInputEditText) findViewById(2131364315);
if (textInputEditText != null) {
i2 = 2131364316;
TextInputLayout textInputLayout2 = (TextInputLayout) findViewById(2131364316);
if (textInputLayout2 != null) {
j2 j2Var = new j2(this, textInputLayout, textInputEditText, textInputLayout2);
m.checkNotNullExpressionValue(j2Var, "ViewPhoneOrEmailInputBin…ater.from(context), this)");
this.j = j2Var;
Mode mode = Mode.ADAPTIVE;
this.k = mode;
this.l = "";
this.m = "";
setLayoutTransition(new LayoutTransition());
if (attributeSet != null) {
TypedArray obtainStyledAttributes = context.obtainStyledAttributes(attributeSet, R.a.PhoneOrEmailInputView, 0, 0);
m.checkNotNullExpressionValue(obtainStyledAttributes, "context.obtainStyledAttr…neOrEmailInputView, 0, 0)");
try {
setHint(obtainStyledAttributes.getString(1));
setMode(Mode.values()[obtainStyledAttributes.getInt(0, mode.ordinal())]);
int resourceId = obtainStyledAttributes.getResourceId(2, -1);
if (resourceId != -1) {
setMainInputNextFocusForwardId(resourceId);
}
return;
} finally {
obtainStyledAttributes.recycle();
}
} else {
return;
}
}
}
}
throw new NullPointerException("Missing required view with ID: ".concat(getResources().getResourceName(i2)));
}
private final void setMainInputNextFocusForwardId(int i2) {
TextInputLayout textInputLayout = this.j.d;
m.checkNotNullExpressionValue(textInputLayout, "binding.phoneOrEmailMainInputWrap");
textInputLayout.setNextFocusForwardId(i2);
}
public final void a(Fragment fragment, Function0<Unit> function0) {
m.checkNotNullParameter(fragment, "fragment");
m.checkNotNullParameter(function0, "onAfterTextChanged");
TextInputLayout textInputLayout = this.j.b;
m.checkNotNullExpressionValue(textInputLayout, "binding.phoneOrEmailCountryCodeWrap");
ViewExtensions.addBindedTextWatcher(textInputLayout, fragment, new a(function0));
TextInputLayout textInputLayout2 = this.j.d;
m.checkNotNullExpressionValue(textInputLayout2, "binding.phoneOrEmailMainInputWrap");
ViewExtensions.addBindedTextWatcher(textInputLayout2, fragment, new b(this, function0));
}
public final void b(Fragment fragment) {
m.checkNotNullParameter(fragment, "fragment");
TextInputLayout textInputLayout = this.j.b;
m.checkNotNullExpressionValue(textInputLayout, "binding.phoneOrEmailCountryCodeWrap");
ViewExtensions.setOnEditTextClickListener(textInputLayout, new c(fragment));
TextInputLayout textInputLayout2 = this.j.d;
m.checkNotNullExpressionValue(textInputLayout2, "binding.phoneOrEmailMainInputWrap");
ViewExtensions.addBindedTextWatcher(textInputLayout2, fragment, new d(this));
c();
d();
}
public final void c() {
TextInputLayout textInputLayout = this.j.b;
m.checkNotNullExpressionValue(textInputLayout, "binding.phoneOrEmailCountryCodeWrap");
textInputLayout.setVisibility(e() ? 0 : 8);
}
public final void d() {
if (this.k.ordinal() != 2) {
TextInputEditText textInputEditText = this.j.f110c;
m.checkNotNullExpressionValue(textInputEditText, "binding.phoneOrEmailMainInput");
textInputEditText.setInputType(32);
if (Build.VERSION.SDK_INT >= 26) {
this.j.f110c.setAutofillHints(new String[]{"emailAddress"});
}
TextInputLayout textInputLayout = this.j.d;
m.checkNotNullExpressionValue(textInputLayout, "binding.phoneOrEmailMainInputWrap");
ViewExtensions.setText(textInputLayout, this.l);
this.j.f110c.setSelection(this.l.length());
return;
}
TextInputEditText textInputEditText2 = this.j.f110c;
m.checkNotNullExpressionValue(textInputEditText2, "binding.phoneOrEmailMainInput");
textInputEditText2.setInputType(3);
if (Build.VERSION.SDK_INT >= 26) {
this.j.f110c.setAutofillHints(new String[]{"phone"});
}
TextInputLayout textInputLayout2 = this.j.d;
m.checkNotNullExpressionValue(textInputLayout2, "binding.phoneOrEmailMainInputWrap");
ViewExtensions.setText(textInputLayout2, this.m);
this.j.f110c.setSelection(this.m.length());
}
public final boolean e() {
int ordinal = this.k.ordinal();
if (ordinal == 1) {
return false;
}
if (ordinal == 2) {
return true;
}
PhoneUtils phoneUtils = PhoneUtils.INSTANCE;
TextInputLayout textInputLayout = this.j.d;
m.checkNotNullExpressionValue(textInputLayout, "binding.phoneOrEmailMainInputWrap");
return phoneUtils.isLikelyToContainPhoneNumber(ViewExtensions.getTextOrEmpty(textInputLayout));
}
public final TextInputEditText getMainEditText() {
TextInputEditText textInputEditText = this.j.f110c;
m.checkNotNullExpressionValue(textInputEditText, "binding.phoneOrEmailMainInput");
return textInputEditText;
}
public final TextInputLayout getMainTextInputLayout() {
TextInputLayout textInputLayout = this.j.d;
m.checkNotNullExpressionValue(textInputLayout, "binding.phoneOrEmailMainInputWrap");
return textInputLayout;
}
public final String getTextOrEmpty() {
if (e()) {
StringBuilder sb = new StringBuilder();
TextInputLayout textInputLayout = this.j.b;
m.checkNotNullExpressionValue(textInputLayout, "binding.phoneOrEmailCountryCodeWrap");
sb.append(ViewExtensions.getTextOrEmpty(textInputLayout));
TextInputLayout textInputLayout2 = this.j.d;
m.checkNotNullExpressionValue(textInputLayout2, "binding.phoneOrEmailMainInputWrap");
sb.append(ViewExtensions.getTextOrEmpty(textInputLayout2));
return sb.toString();
}
TextInputLayout textInputLayout3 = this.j.d;
m.checkNotNullExpressionValue(textInputLayout3, "binding.phoneOrEmailMainInputWrap");
return ViewExtensions.getTextOrEmpty(textInputLayout3);
}
public final void setCountryCode(PhoneCountryCode phoneCountryCode) {
m.checkNotNullParameter(phoneCountryCode, "countryCode");
TextInputLayout textInputLayout = this.j.b;
m.checkNotNullExpressionValue(textInputLayout, "binding.phoneOrEmailCountryCodeWrap");
ViewExtensions.setText(textInputLayout, phoneCountryCode.getCode());
}
public final void setHint(CharSequence charSequence) {
TextInputLayout textInputLayout = this.j.d;
m.checkNotNullExpressionValue(textInputLayout, "binding.phoneOrEmailMainInputWrap");
textInputLayout.setHint(charSequence);
}
public final void setMode(Mode mode) {
m.checkNotNullParameter(mode, "mode");
this.k = mode;
c();
d();
}
public final void setText(CharSequence charSequence) {
TextInputLayout textInputLayout = this.j.d;
m.checkNotNullExpressionValue(textInputLayout, "binding.phoneOrEmailMainInputWrap");
ViewExtensions.setText(textInputLayout, charSequence);
}
}