package com.ss.android.ugc.aweme.tools.draft.adapter.viewholder;

import X.0CB;
import X.0CG;
import X.0CH;
import X.0HH;
import X.2FV;
import X.2He;
import X.4ZZ;
import X.7s1;
import X.8jA;
import X.9Y3;
import X.AnonymousClass6ZR;
import X.AnonymousClass744;
import X.AnonymousClass74J;
import X.C38646es;
import X.C38666eu;
import X.C42016kJ;
import X.C42616lH;
import X.C530374z;
import X.C533876i;
import X.C534976t;
import X.C535076u;
import X.C535176v;
import X.C535276w;
import X.C535376x;
import X.C535576z;
import X.CE9;
import X.HeD;
import X.M12;
import X.OCO;
import X.QJv;
import X.Qeg;
import X.Qx3;
import X.TSt;
import android.app.Application;
import android.content.ClipboardManager;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Point;
import android.net.Uri;
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import android.text.TextPaint;
import android.view.Display;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.CompoundButton;
import android.widget.RelativeLayout;
import android.widget.TextView;
import androidx.core.g.t;
import com.bytedance.covode.number.Covode;
import com.bytedance.frameworks.apm.trace.MethodCollector;
import java.io.File;
import java.lang.reflect.Field;
import java.util.Objects;
import kotlin.h.b.n;
import kotlin.o.z;

public final class NewDraftViewHolder extends C533876i<AnonymousClass744> implements 0CG {
    public final String LIZ = "NewDraftViewHolder";
    public Context LIZIZ;
    public CE9 LIZJ;
    public QJv LIZLLL;
    public AnonymousClass744 LJ;
    public long LJFF;
    public final C535076u LJI;
    public final C42616lH LJII;
    public Qeg LJIIIIZZ;
    public View LJIIIZ;
    public Qeg LJIIJ;
    public ViewGroup LJIIJJI;
    public ViewGroup LJIIL;
    public ViewGroup LJIILIIL;
    public 4ZZ LJIILJJIL;
    public TextView LJIILL;
    public C38666eu LJIILLIIL;

    static {
        Covode.recordClassIndex(119291);
    }

    public final void onStateChanged(0CH r1, 0CB r2) {
    }

    public static final /* synthetic */ AnonymousClass744 LIZ(NewDraftViewHolder newDraftViewHolder) {
        AnonymousClass744 r1 = newDraftViewHolder.LJ;
        if (r1 == null) {
            n.LIZ("");
        }
        return r1;
    }

    public static final /* synthetic */ QJv LIZIZ(NewDraftViewHolder newDraftViewHolder) {
        QJv qJv = newDraftViewHolder.LIZLLL;
        if (qJv == null) {
            n.LIZ("");
        }
        return qJv;
    }

    public final /* synthetic */ void LIZ(AnonymousClass74J r11) {
        AnonymousClass744 r112 = (AnonymousClass744) r11;
        M12.LIZ(r112);
        this.LJ = r112;
        if (r112 == null) {
            n.LIZ("");
        }
        if (r112.LIZ) {
            CE9 ce9 = this.LIZJ;
            if (ce9 == null) {
                n.LIZ("");
            }
            ce9.setVisibility(0);
        } else {
            CE9 ce92 = this.LIZJ;
            if (ce92 == null) {
                n.LIZ("");
            }
            ce92.setVisibility(8);
            AnonymousClass744 r0 = this.LJ;
            if (r0 == null) {
                n.LIZ("");
            }
            r0.LJ = false;
        }
        CE9 ce93 = this.LIZJ;
        if (ce93 == null) {
            n.LIZ("");
        }
        ce93.setOnCheckedChangeListener((CompoundButton.OnCheckedChangeListener) null);
        CE9 ce94 = this.LIZJ;
        if (ce94 == null) {
            n.LIZ("");
        }
        AnonymousClass744 r02 = this.LJ;
        if (r02 == null) {
            n.LIZ("");
        }
        ce94.setChecked(r02.LJ);
        CE9 ce95 = this.LIZJ;
        if (ce95 == null) {
            n.LIZ("");
        }
        ce95.setOnCheckedChangeListener(new C535576z(this));
        QJv qJv = this.LIZLLL;
        if (qJv == null) {
            n.LIZ("");
        }
        AnonymousClass744 r03 = this.LJ;
        if (r03 == null) {
            n.LIZ("");
        }
        qJv.setTag(r03.LIZJ);
        QJv qJv2 = this.LIZLLL;
        if (qJv2 == null) {
            n.LIZ("");
        }
        qJv2.setActualImageResource(2131232637);
        AnonymousClass744 r7 = this.LJ;
        if (r7 == null) {
            n.LIZ("");
        }
        File file = new File(r7.LIZLLL);
        if (file.exists()) {
            Uri fromFile = Uri.fromFile(file);
            QJv qJv3 = this.LIZLLL;
            if (qJv3 == null) {
                n.LIZ("");
            }
            OCO.LIZ(qJv3, fromFile.toString(), -1, -1);
        } else {
            C42016kJ LIZ2 = this.LJII.LIZ(r7.LIZJ);
            if (LIZ2 == null) {
                AnonymousClass6ZR.LIZIZ(this.LIZ + ": bindDraftCover -> draft is null");
                TSt.LIZ("queryNull -> " + this.LIZ + " : bindDraftCover");
            } else {
                int dimensionPixelOffset = this.LIZIZ.getResources().getDimensionPixelOffset(2131165585);
                C38666eu r1 = new C38666eu(dimensionPixelOffset, dimensionPixelOffset, Bitmap.Config.ARGB_8888);
                this.LJIILLIIL = r1;
                C38646es.LIZ(LIZ2, r1, new C535376x(this, r7, LIZ2));
            }
        }
        AnonymousClass744 r04 = this.LJ;
        if (r04 == null) {
            n.LIZ("");
        }
        if (!r04.LIZ) {
            Qeg qeg = this.LJIIIIZZ;
            if (qeg == null) {
                n.LIZ("");
            }
            qeg.setVisibility(0);
            Qeg qeg2 = this.LJIIIIZZ;
            if (qeg2 == null) {
                n.LIZ("");
            }
            AnonymousClass744 r05 = this.LJ;
            if (r05 == null) {
                n.LIZ("");
            }
            qeg2.setText(r05.LJIIIIZZ);
        } else {
            Qeg qeg3 = this.LJIIIIZZ;
            if (qeg3 == null) {
                n.LIZ("");
            }
            qeg3.setVisibility(8);
        }
        AnonymousClass744 r06 = this.LJ;
        if (r06 == null) {
            n.LIZ("");
        }
        if (r06.LIZIZ) {
            ViewGroup viewGroup = this.LJIILIIL;
            if (viewGroup == null) {
                n.LIZ("");
            }
            viewGroup.setVisibility(0);
            ViewGroup viewGroup2 = this.LJIIJJI;
            if (viewGroup2 == null) {
                n.LIZ("");
            }
            viewGroup2.setVisibility(8);
            TextView textView = this.LJIILL;
            if (textView == null) {
                n.LIZ("");
            }
            Context context = this.LIZIZ;
            AnonymousClass744 r07 = this.LJ;
            if (r07 == null) {
                n.LIZ("");
            }
            long j = r07.LJFF;
            M12.LIZ(context);
            String string = context.getString(2131832273, new Object[]{Double.valueOf(((double) j) / 1048576.0d)});
            n.LIZIZ(string, "");
            textView.setText(string);
            return;
        }
        ViewGroup viewGroup3 = this.LJIILIIL;
        if (viewGroup3 == null) {
            n.LIZ("");
        }
        viewGroup3.setVisibility(8);
        AnonymousClass744 r08 = this.LJ;
        if (r08 == null) {
            n.LIZ("");
        }
        if (r08.LJI.length() > 0) {
            AnonymousClass744 r09 = this.LJ;
            if (r09 == null) {
                n.LIZ("");
            }
            LIZ(r09);
        } else {
            Qeg qeg4 = this.LJIIJ;
            if (qeg4 == null) {
                n.LIZ("");
            }
            qeg4.setVisibility(8);
            ViewGroup viewGroup4 = this.LJIIJJI;
            if (viewGroup4 == null) {
                n.LIZ("");
            }
            viewGroup4.setVisibility(8);
        }
        ViewGroup viewGroup5 = this.LJIIJJI;
        if (viewGroup5 == null) {
            n.LIZ("");
        }
        viewGroup5.setOnClickListener(new C534976t(this, r112));
    }

    private final void LIZ(AnonymousClass744 r14) {
        boolean z;
        if (r14.LIZ) {
            ViewGroup viewGroup = this.LJIIJJI;
            if (viewGroup == null) {
                n.LIZ("");
            }
            viewGroup.setVisibility(8);
            return;
        }
        if (9Y3.LIZ(9Y3.LIZ(), true, "studio_create_new_video", 0) == 2) {
            z = true;
        } else {
            z = false;
        }
        if (z) {
            RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(-1, -2);
            layoutParams.addRule(20);
            View view = this.itemView;
            n.LIZIZ(view, "");
            int LIZIZ2 = (int) HeD.LIZIZ(view.getContext(), 4.0f);
            View view2 = this.itemView;
            n.LIZIZ(view2, "");
            int LIZIZ3 = (int) HeD.LIZIZ(view2.getContext(), 6.0f);
            layoutParams.setMargins(LIZIZ2, LIZIZ3, LIZIZ2, LIZIZ3);
            ViewGroup viewGroup2 = this.LJIIL;
            if (viewGroup2 == null) {
                n.LIZ("");
            }
            viewGroup2.setLayoutParams(layoutParams);
            4ZZ r1 = this.LJIILJJIL;
            if (r1 == null) {
                n.LIZ("");
            }
            r1.setIconRes(2131755550);
            4ZZ r0 = this.LJIILJJIL;
            if (r0 == null) {
                n.LIZ("");
            }
            r0.setTintColorRes(2130968624);
            Qeg qeg = this.LJIIJ;
            if (qeg == null) {
                n.LIZ("");
            }
            qeg.setMaxLines(1);
            Qeg qeg2 = this.LJIIJ;
            if (qeg2 == null) {
                n.LIZ("");
            }
            qeg2.setMinTextSize(13.0f);
            Qeg qeg3 = this.LJIIJ;
            if (qeg3 == null) {
                n.LIZ("");
            }
            qeg3.setTuxFont(62);
            Qeg qeg4 = this.LJIIJ;
            if (qeg4 == null) {
                n.LIZ("");
            }
            qeg4.setText(r14.LJI);
        } else {
            4ZZ r12 = this.LJIILJJIL;
            if (r12 == null) {
                n.LIZ("");
            }
            r12.setIconRes(2131755718);
            4ZZ r02 = this.LJIILJJIL;
            if (r02 == null) {
                n.LIZ("");
            }
            r02.setTintColorRes(2130968624);
            Qeg qeg5 = this.LJIIJ;
            if (qeg5 == null) {
                n.LIZ("");
            }
            qeg5.setMaxLines(2);
            Qeg qeg6 = this.LJIIJ;
            if (qeg6 == null) {
                n.LIZ("");
            }
            qeg6.setMinTextSize(10.0f);
            Object LIZ2 = LIZ(C530374z.LIZ, "window");
            Objects.requireNonNull(LIZ2, "null cannot be cast to non-null type android.view.WindowManager");
            Display defaultDisplay = ((WindowManager) LIZ2).getDefaultDisplay();
            Point point = new Point();
            defaultDisplay.getRealSize(point);
            int i = point.x / 3;
            View view3 = this.itemView;
            n.LIZIZ(view3, "");
            int LIZIZ4 = i - ((int) HeD.LIZIZ(view3.getContext(), 34.0f));
            Qeg qeg7 = this.LJIIJ;
            if (qeg7 == null) {
                n.LIZ("");
            }
            TextPaint paint = qeg7.getPaint();
            String string = this.LIZIZ.getString(2131824087);
            n.LIZIZ(string, "");
            Qeg qeg8 = this.LJIIJ;
            if (qeg8 == null) {
                n.LIZ("");
            }
            qeg8.setText(2131824087);
            Qeg qeg9 = this.LJIIJ;
            if (qeg9 == null) {
                n.LIZ("");
            }
            qeg9.setTuxFont(92);
            float f = (float) LIZIZ4;
            if (paint.measureText(string) > f) {
                Qeg qeg10 = this.LJIIJ;
                if (qeg10 == null) {
                    n.LIZ("");
                }
                qeg10.setTuxFont(92);
            } else {
                Qeg qeg11 = this.LJIIJ;
                if (qeg11 == null) {
                    n.LIZ("");
                }
                qeg11.setTuxFont(62);
            }
            Object[] array = z.LIZ(string, new String[]{" "}, 0, 6).toArray(new String[0]);
            Objects.requireNonNull(array, "null cannot be cast to non-null type kotlin.Array<T>");
            String[] strArr = (String[]) array;
            if (paint.measureText(string) > f) {
                try {
                    String str = strArr[0];
                    int length = strArr.length;
                    int i2 = 0;
                    for (int i3 = 1; i3 < length; i3++) {
                        if (paint.measureText(str + " " + strArr[i3]) <= f) {
                            str = str + " " + strArr[i3];
                        } else {
                            i2 = i3;
                        }
                    }
                    String str2 = strArr[i2];
                    for (int i4 = i2 + 1; i4 < strArr.length; i4++) {
                        str2 = str2 + " " + strArr[i4];
                    }
                    float LIZIZ5 = Qx3.LIZIZ(paint.measureText(str), paint.measureText(str2));
                    Qeg qeg12 = this.LJIIJ;
                    if (qeg12 == null) {
                        n.LIZ("");
                    }
                    qeg12.setWidth((int) (LIZIZ5 + 1.0f));
                } catch (IndexOutOfBoundsException e) {
                    0HH.LIZ(e);
                } catch (NullPointerException e2) {
                    0HH.LIZ(e2);
                }
            }
        }
        Qeg qeg13 = this.LJIIJ;
        if (qeg13 == null) {
            n.LIZ("");
        }
        qeg13.setVisibility(0);
        ViewGroup viewGroup3 = this.LJIIJJI;
        if (viewGroup3 == null) {
            n.LIZ("");
        }
        viewGroup3.setVisibility(0);
    }

    public static Object LIZ(Application application, String str) {
        Object obj;
        MethodCollector.i(11770);
        if (Build.VERSION.SDK_INT > 27 || !"clipboard".equals(str)) {
            if (!2FV.LIZIZ && "connectivity".equals(str)) {
                try {
                    new 7s1().LIZ();
                    2FV.LIZIZ = true;
                    obj = application.getSystemService(str);
                } catch (Throwable unused) {
                }
            }
            obj = application.getSystemService(str);
        } else if (2FV.LIZ) {
            synchronized (ClipboardManager.class) {
                try {
                    obj = application.getSystemService(str);
                    if (Thread.currentThread() != Looper.getMainLooper().getThread()) {
                        Field declaredField = ClipboardManager.class.getDeclaredField("mHandler");
                        declaredField.setAccessible(true);
                        declaredField.set(obj, new 2He((Handler) declaredField.get(obj)));
                    }
                } catch (Exception e) {
                    8jA.LIZ(e, "ClipboardManager Handler Reflect Fail");
                } catch (Throwable th) {
                    MethodCollector.o(11770);
                    throw th;
                }
                2FV.LIZ = false;
            }
        } else {
            obj = application.getSystemService(str);
        }
        MethodCollector.o(11770);
        return obj;
    }

    /* JADX WARNING: type inference failed for: r0v31, types: [android.view.View$OnClickListener, X.76w] */
    /* JADX INFO: super call moved to the top of the method (can break code semantics) */
    public NewDraftViewHolder(View view, C535076u r5, C42616lH r6) {
        super(view);
        M12.LIZ(view, r5, r6);
        this.LJI = r5;
        this.LJII = r6;
        Context context = view.getContext();
        n.LIZIZ(context, "");
        this.LIZIZ = context;
        View findViewById = view.findViewById(2131363673);
        n.LIZIZ(findViewById, "");
        this.LJIIIZ = findViewById;
        Qeg findViewById2 = view.findViewById(2131372209);
        n.LIZIZ(findViewById2, "");
        this.LJIIJ = findViewById2;
        QJv LIZ2 = t.LIZ(view, 2131363809);
        n.LIZIZ(LIZ2, "");
        this.LIZLLL = LIZ2;
        Qeg findViewById3 = view.findViewById(2131372436);
        n.LIZIZ(findViewById3, "");
        this.LJIIIIZZ = findViewById3;
        View findViewById4 = view.findViewById(2131372789);
        n.LIZIZ(findViewById4, "");
        this.LJIIJJI = (ViewGroup) findViewById4;
        View findViewById5 = view.findViewById(2131371108);
        n.LIZIZ(findViewById5, "");
        this.LJIIL = (ViewGroup) findViewById5;
        View LIZ3 = t.LIZ(view, 2131371942);
        n.LIZIZ(LIZ3, "");
        this.LJIILL = (TextView) LIZ3;
        View LIZ4 = t.LIZ(view, 2131370372);
        n.LIZIZ(LIZ4, "");
        this.LJIILIIL = (ViewGroup) LIZ4;
        CE9 LIZ5 = t.LIZ(view, 2131363271);
        n.LIZIZ(LIZ5, "");
        this.LIZJ = LIZ5;
        4ZZ findViewById6 = view.findViewById(2131366605);
        n.LIZIZ(findViewById6, "");
        this.LJIILJJIL = findViewById6;
        View view2 = this.LJIIIZ;
        if (view2 == null) {
            n.LIZ("");
        }
        view2.setOnClickListener(new C535276w(this));
        View view3 = this.LJIIIZ;
        if (view3 == null) {
            n.LIZ("");
        }
        view3.setOnLongClickListener(new C535176v(this));
    }
}
