package com.discord.views; import android.content.Context; import android.content.res.TypedArray; import android.graphics.drawable.Drawable; import android.util.AttributeSet; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.view.inputmethod.BaseInputConnection; import android.view.inputmethod.EditorInfo; import android.view.inputmethod.InputConnection; import android.view.inputmethod.InputMethodManager; import android.widget.LinearLayout; import android.widget.TextView; import androidx.core.content.ContextCompat; import androidx.core.view.ViewCompat; import c.a.i.u1; import c.a.y.b; import c.a.y.c; import c.a.y.d; import c.a.y.e; import com.discord.R; import d0.g0.w; import d0.t.n; import d0.z.d.m; import java.util.List; import java.util.Objects; import kotlin.Unit; import kotlin.jvm.functions.Function1; import kotlin.jvm.internal.DefaultConstructorMarker; /* compiled from: CodeVerificationView.kt */ public final class CodeVerificationView extends LinearLayout { public static final a i = a.NUMERIC; public final u1 j; public final List k; public final Drawable l; public final Drawable m; public a n; public String o; public Function1 p; /* compiled from: CodeVerificationView.kt */ public enum a { NUMERIC, /* Fake field, exist only in values array */ ALPHANUMERIC; public static final a[] k = values(); public static final C0180a l = new C0180a(null); /* compiled from: CodeVerificationView.kt */ /* renamed from: com.discord.views.CodeVerificationView$a$a reason: collision with other inner class name */ public static final class C0180a { public C0180a(DefaultConstructorMarker defaultConstructorMarker) { } } } /* JADX INFO: super call moved to the top of the method (can break code semantics) */ public CodeVerificationView(Context context, AttributeSet attributeSet) { super(context, attributeSet, 0); m.checkNotNullParameter(context, "context"); View inflate = LayoutInflater.from(context).inflate(2131558744, (ViewGroup) this, false); addView(inflate); int i2 = 2131365630; TextView textView = (TextView) inflate.findViewById(2131365630); if (textView != null) { i2 = 2131365631; TextView textView2 = (TextView) inflate.findViewById(2131365631); if (textView2 != null) { i2 = 2131365632; TextView textView3 = (TextView) inflate.findViewById(2131365632); if (textView3 != null) { i2 = 2131365633; TextView textView4 = (TextView) inflate.findViewById(2131365633); if (textView4 != null) { i2 = 2131365634; TextView textView5 = (TextView) inflate.findViewById(2131365634); if (textView5 != null) { i2 = 2131365635; TextView textView6 = (TextView) inflate.findViewById(2131365635); if (textView6 != null) { u1 u1Var = new u1((LinearLayout) inflate, textView, textView2, textView3, textView4, textView5, textView6); m.checkNotNullExpressionValue(u1Var, "ViewCodeVerificationBind…rom(context), this, true)"); this.j = u1Var; this.o = ""; this.p = e.i; if (attributeSet != null) { TypedArray obtainStyledAttributes = getContext().obtainStyledAttributes(attributeSet, R.a.CodeVerificationView, 0, 0); m.checkNotNullExpressionValue(obtainStyledAttributes, "context.obtainStyledAttr…deVerificationView, 0, 0)"); try { int i3 = obtainStyledAttributes.getInt(0, i.ordinal()); a.C0180a aVar = a.l; this.n = a.k[i3]; } finally { obtainStyledAttributes.recycle(); } } setClickable(true); setFocusable(true); setFocusableInTouchMode(true); setOnFocusChangeListener(new b(this)); setOnClickListener(new c(this)); setOnKeyListener(new d(this)); m.checkNotNullExpressionValue(textView, "binding.verifyChar1"); m.checkNotNullExpressionValue(textView2, "binding.verifyChar2"); m.checkNotNullExpressionValue(textView3, "binding.verifyChar3"); m.checkNotNullExpressionValue(textView4, "binding.verifyChar4"); m.checkNotNullExpressionValue(textView5, "binding.verifyChar5"); m.checkNotNullExpressionValue(textView6, "binding.verifyChar6"); List listOf = n.listOf((Object[]) new TextView[]{textView, textView2, textView3, textView4, textView5, textView6}); this.k = listOf; listOf.get(0).requestFocus(); TextView textView7 = listOf.get(0); if (!ViewCompat.isLaidOut(textView7) || textView7.isLayoutRequested()) { textView7.addOnLayoutChangeListener(new c.a.y.a(this)); } else { a(this); } this.l = ContextCompat.getDrawable(context, 2131231229); this.m = ContextCompat.getDrawable(context, 2131231230); e(); return; } } } } } } throw new NullPointerException("Missing required view with ID: ".concat(inflate.getResources().getResourceName(i2))); } public static final void a(CodeVerificationView codeVerificationView) { Object systemService = codeVerificationView.getContext().getSystemService("input_method"); Objects.requireNonNull(systemService, "null cannot be cast to non-null type android.view.inputmethod.InputMethodManager"); ((InputMethodManager) systemService).showSoftInput(codeVerificationView, 2); } public final void b() { if (this.o.length() > 0) { this.o = ""; d(); } } public final void c(char c2) { if (this.o.length() < 6) { String str = this.o; this.o = str + c2; d(); } } public final void d() { int i2 = 0; for (Object obj : this.k) { int i3 = i2 + 1; if (i2 < 0) { n.throwIndexOverflow(); } TextView textView = (TextView) obj; if (i2 <= w.getLastIndex(this.o)) { textView.setText(String.valueOf(this.o.charAt(i2))); } else { textView.setText(""); } i2 = i3; } if (this.o.length() == 6) { this.p.invoke(this.o); } e(); } public final void e() { int min = Math.min(this.o.length(), n.getLastIndex(this.k)); int i2 = 0; for (Object obj : this.k) { int i3 = i2 + 1; if (i2 < 0) { n.throwIndexOverflow(); } ((TextView) obj).setBackground(i2 == min ? this.m : this.l); i2 = i3; } } public final String getCode() { return this.o; } /* JADX DEBUG: Type inference failed for r0v0. Raw type applied. Possible types: kotlin.jvm.functions.Function1, kotlin.jvm.functions.Function1 */ public final Function1 getOnCodeEntered() { return this.p; } @Override // android.view.View public boolean onCheckIsTextEditor() { return true; } @Override // android.view.View public InputConnection onCreateInputConnection(EditorInfo editorInfo) { m.checkNotNullParameter(editorInfo, "outAttrs"); a aVar = this.n; if (aVar == null) { m.throwUninitializedPropertyAccessException("inputType"); } if (aVar != a.NUMERIC) { return super.onCreateInputConnection(editorInfo); } BaseInputConnection baseInputConnection = new BaseInputConnection(this, false); editorInfo.inputType = 18; return baseInputConnection; } public final void setCode(CharSequence charSequence) { m.checkNotNullParameter(charSequence, "code"); String str = this.o; String obj = charSequence.toString(); this.o = obj; if (!m.areEqual(str, obj)) { d(); } } public final void setOnCodeEntered(Function1 function1) { m.checkNotNullParameter(function1, ""); this.p = function1; } }