package com.ss.android.ugc.aweme.shortvideo.image;

import X.0Bs;
import X.0Bv;
import X.0Bx;
import X.0By;
import X.0CB;
import X.0CH;
import X.0CN;
import X.1hK;
import X.2FV;
import X.2GD;
import X.2He;
import X.2Pr;
import X.3BB;
import X.3Dg;
import X.4ZZ;
import X.6Gd;
import X.6Is;
import X.6J4;
import X.6lY;
import X.6wl;
import X.74z;
import X.7s1;
import X.8jA;
import X.C0045FQt;
import X.C0145FUp;
import X.C0217FXj;
import X.C0218FXk;
import X.C0275FZp;
import X.C0338Fca;
import X.C5112HeD;
import X.Fa2;
import X.FbF;
import X.FcV;
import X.FcW;
import X.FcX;
import X.FcY;
import X.FcZ;
import X.Ls2;
import X.M12;
import X.Mtx;
import X.NnW;
import android.animation.ValueAnimator;
import android.content.ClipboardManager;
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import com.bytedance.covode.number.Covode;
import com.bytedance.frameworks.apm.trace.MethodCollector;
import com.ss.android.ugc.aweme.base.SafeHandler;
import com.ss.android.ugc.aweme.image.model.ImageAlbumData;
import com.ss.android.ugc.aweme.shortvideo.edit.VideoPublishEditModel;
import java.lang.reflect.Field;
import java.util.List;
import java.util.Objects;
import kotlin.h.b.n;

public final class ExpandedTitleModule implements 6Is, Fa2, C0275FZp {
    public static final C0338Fca LJJIII = new C0338Fca((byte) 0);
    public final 3Dg LIZ;
    public final EditText LIZIZ;
    public final FbF LIZJ;
    public final 4ZZ LIZLLL;
    public final 4ZZ LJ;
    public final ViewGroup LJFF;
    public final C0218FXk LJI;
    public final int LJII;
    public int LJIIIIZZ;
    public boolean LJIIIZ;
    public boolean LJIIJ;
    public int LJIIJJI;
    public int LJIIL;
    public int LJIILIIL;
    public int LJIILJJIL;
    public boolean LJIILL;
    public SafeHandler LJIILLIIL;
    public final ViewGroup LJIIZILJ;
    public final ViewGroup LJIJ;
    public final ViewGroup LJIJI;
    public final ViewGroup LJIJJ;
    public boolean LJIJJLI;
    public final ExpandTextViewModel LJIL;
    public final Runnable LJJ;
    public int LJJI;
    public final 1hK LJJIFFI;
    public final View LJJII;
    public final View LJJIIJ;
    public final int LJJIIJZLJL;
    public final int LJJIIZ;
    public final boolean LJJIIZI;
    public final long LJJIJ = 250;
    public final int LJJIJIIJI;
    public final int LJJIJIIJIL;
    public int LJJIJIL;
    public final View LJJIJL;
    public final View LJJIJLIJ;
    public final InputMethodManager LJJIL;
    public NnW LJJIZ;
    public final FcV LJJJ;
    public final VideoPublishEditModel LJJJI;
    public final ViewGroup LJJJIL;

    static {
        Covode.recordClassIndex(110783);
    }

    public final void onStateChanged(0CH r2, 0CB r3) {
        if (r3 == 0CB.ON_PAUSE) {
            onPause();
        } else if (r3 == 0CB.ON_RESUME) {
            onResume();
        } else if (r3 == 0CB.ON_DESTROY) {
            release();
        }
    }

    @0CN(LIZ = 0CB.ON_DESTROY)
    public final void release() {
        this.LJJIZ.LIZ();
    }

    public final String LIZ() {
        EditText editText = this.LIZIZ;
        n.LIZIZ(editText, "");
        return editText.getText().toString();
    }

    public final void LIZIZ() {
        int i;
        if (this.LJIIZILJ.getVisibility() == 0) {
            i = 3;
        } else {
            i = 2;
        }
        LIZ(i);
    }

    public final boolean LIZJ() {
        int i = this.LJJI;
        if (i == 2 || i == 3) {
            return true;
        }
        return false;
    }

    @0CN(LIZ = 0CB.ON_PAUSE)
    public final void onPause() {
        if (LIZJ()) {
            this.LJIIJ = true;
            LJ();
        }
    }

    /* JADX DEBUG: Multi-variable search result rejected for TypeSearchVarInfo{r2v4, resolved type: android.widget.EditText} */
    /* JADX WARNING: type inference failed for: r2v1, types: [android.view.View, android.widget.EditText] */
    /* JADX WARNING: type inference failed for: r2v3 */
    /* JADX WARNING: Multi-variable type inference failed */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    public final boolean LIZLLL() {
        /*
            r3 = this;
            android.widget.EditText r0 = r3.LIZIZ
            boolean r0 = r0.hasFocus()
            if (r0 == 0) goto L_0x001a
            android.widget.EditText r2 = r3.LIZIZ
        L_0x000a:
            r2.requestFocus()
            android.view.inputmethod.InputMethodManager r1 = r3.LJJIL
            if (r1 == 0) goto L_0x001d
            r0 = 2
            boolean r1 = r1.showSoftInput(r2, r0)
            r0 = 1
            if (r1 != r0) goto L_0x001d
            return r0
        L_0x001a:
            X.FbF r2 = r3.LIZJ
            goto L_0x000a
        L_0x001d:
            r0 = 0
            return r0
        */
        throw new UnsupportedOperationException("Method not decompiled: com.ss.android.ugc.aweme.shortvideo.image.ExpandedTitleModule.LIZLLL():boolean");
    }

    private final boolean LJI() {
        ViewGroup[] viewGroupArr = {this.LJIIZILJ, this.LJIJ, this.LJIJI};
        int i = 0;
        while (viewGroupArr[i].getVisibility() != 0) {
            i++;
            if (i >= 3) {
                return false;
            }
        }
        return true;
    }

    public final void LJ() {
        InputMethodManager inputMethodManager;
        if (this.LJJIFFI.getCurrentFocus() != null && this.LJIJJLI && (inputMethodManager = this.LJJIL) != null) {
            FbF fbF = this.LIZJ;
            n.LIZIZ(fbF, "");
            inputMethodManager.hideSoftInputFromWindow(fbF.getWindowToken(), 0);
        }
    }

    public final boolean LJFF() {
        ViewGroup viewGroup = this.LJFF;
        n.LIZIZ(viewGroup, "");
        if (viewGroup.getAlpha() >= 1.0f) {
            return false;
        }
        3BB r1 = new 3BB(74z.LIZ);
        r1.LIZIZ(2131830812);
        r1.LIZIZ();
        return true;
    }

    @0CN(LIZ = 0CB.ON_RESUME)
    public final void onResume() {
        this.LJIIIZ = false;
        this.LJIILJJIL = 0;
        this.LJIJJLI = false;
        this.LJJIZ.LIZIZ = 0;
        if (LIZJ()) {
            this.LJIIJ = false;
            if (!LIZLLL()) {
                this.LJIILLIIL.postDelayed(new FcZ(this), 500);
            }
        }
    }

    public final void LIZIZ(int i) {
        ViewGroup.LayoutParams layoutParams = this.LIZ.getLayoutParams();
        Objects.requireNonNull(layoutParams, "null cannot be cast to non-null type android.view.ViewGroup.MarginLayoutParams");
        ViewGroup.MarginLayoutParams marginLayoutParams = (ViewGroup.MarginLayoutParams) layoutParams;
        marginLayoutParams.height = i;
        this.LIZ.setLayoutParams(marginLayoutParams);
        this.LIZJ.requestLayout();
    }

    public final void LIZJ(int i) {
        if (i != 1) {
            ViewGroup.LayoutParams layoutParams = this.LJIIZILJ.getLayoutParams();
            Objects.requireNonNull(layoutParams, "null cannot be cast to non-null type android.view.ViewGroup.MarginLayoutParams");
            ViewGroup.MarginLayoutParams marginLayoutParams = (ViewGroup.MarginLayoutParams) layoutParams;
            marginLayoutParams.topMargin = ((int) (((double) this.LJIILIIL) * 0.6d)) + ((int) C5112HeD.LIZIZ(this.LJJIFFI, 9.0f));
            marginLayoutParams.bottomMargin = this.LJIILJJIL;
            this.LJIIZILJ.setLayoutParams(marginLayoutParams);
            if (this.LJIJI.getVisibility() == 0) {
                this.LJIJI.setVisibility(8);
                this.LJIJJ.setVisibility(0);
            }
            C0145FUp.LIZIZ(this.LJIIZILJ);
            C0145FUp.LIZIZ(this.LJJIJL);
            C0145FUp.LIZIZ(this.LJJIJLIJ);
            return;
        }
        ViewGroup[] viewGroupArr = {this.LJIIZILJ, this.LJIJ};
        int i2 = 0;
        do {
            ViewGroup viewGroup = viewGroupArr[i2];
            ViewGroup.LayoutParams layoutParams2 = viewGroup.getLayoutParams();
            Objects.requireNonNull(layoutParams2, "null cannot be cast to non-null type android.view.ViewGroup.MarginLayoutParams");
            ViewGroup.MarginLayoutParams marginLayoutParams2 = (ViewGroup.MarginLayoutParams) layoutParams2;
            marginLayoutParams2.topMargin = this.LJJIJIIJI;
            marginLayoutParams2.bottomMargin = 0;
            viewGroup.setLayoutParams(marginLayoutParams2);
            C0145FUp.LIZ(viewGroup);
            i2++;
        } while (i2 < 2);
        ViewGroup[] viewGroupArr2 = {this.LJIJI};
        int i3 = 0;
        do {
            ViewGroup viewGroup2 = viewGroupArr2[0];
            ViewGroup.LayoutParams layoutParams3 = viewGroup2.getLayoutParams();
            Objects.requireNonNull(layoutParams3, "null cannot be cast to non-null type android.view.ViewGroup.MarginLayoutParams");
            ViewGroup.MarginLayoutParams marginLayoutParams3 = (ViewGroup.MarginLayoutParams) layoutParams3;
            marginLayoutParams3.topMargin = this.LJJIJIIJIL;
            marginLayoutParams3.bottomMargin = 0;
            viewGroup2.setLayoutParams(marginLayoutParams3);
            C0145FUp.LIZ(viewGroup2);
            i3++;
        } while (i3 <= 0);
        C0145FUp.LIZ(this.LJJIJL);
        C0145FUp.LIZ(this.LJJIJLIJ);
    }

    public final void LIZ(int i) {
        int i2;
        int i3;
        int i4;
        int i5;
        int i6;
        int i7;
        int i8 = this.LJJI;
        if (i8 != i) {
            boolean z = false;
            if (i8 == 1) {
                this.LJIILIIL = this.LJIIL - this.LJIILJJIL;
                C0218FXk fXk = this.LJI;
                n.LIZIZ(fXk, "");
                this.LJJIJIL = fXk.getScrollY();
                if (i == 2) {
                    i4 = this.LJIILIIL - this.LJII;
                } else {
                    i4 = (int) (((double) this.LJIILIIL) * 0.6d);
                }
                i6 = this.LJJIIJZLJL;
                i5 = i4 - this.LJIIIIZZ;
                i7 = (int) C5112HeD.LIZIZ(this.LJJIFFI, 8.0f);
                LIZJ(i);
                if (this.LJJIIZI) {
                    EditText editText = this.LIZIZ;
                    n.LIZIZ(editText, "");
                    if (editText.getVisibility() == 8) {
                        EditText editText2 = this.LIZIZ;
                        n.LIZIZ(editText2, "");
                        editText2.setVisibility(0);
                        this.LJJJI.getImageAlbumData().getImageUiBusinessData().setHasShowedTitle(true);
                    }
                }
                if (i == 3) {
                    this.LJJIIJ.setVisibility(0);
                }
            } else if (i == 1) {
                this.LJJIIJ.setVisibility(8);
                this.LJI.setForbidScroll(LJI());
                i4 = this.LJJIIZ;
                i6 = this.LJJIJIL;
                i5 = i4 - ((int) C5112HeD.LIZIZ(this.LJJIFFI, 33.0f));
                LIZJ(i);
                if (this.LJJI == 3) {
                    this.LJJIIJ.setVisibility(8);
                }
                i7 = 0;
            } else {
                if (i8 == 2) {
                    i2 = (int) (((double) this.LJIILIIL) * 0.6d);
                    i3 = this.LJIIIIZZ;
                } else {
                    i2 = this.LJIILIIL - this.LJII;
                    i3 = this.LJIIIIZZ;
                }
                i5 = i4 - i3;
                i6 = -1;
                i7 = -1;
            }
            if (this.LJJI == 1) {
                z = true;
            }
            LIZ(i4, i6, i5, i7, new C0217FXj(this, z));
            this.LJJI = i;
        }
    }

    public final void LIZ(boolean z) {
        this.LJJIIJ.setVisibility(8);
        if (z) {
            int i = this.LJJI;
            if (i == 1) {
                this.LJI.setForbidScroll(true);
            } else if (i == 2) {
                LIZ(3);
                if (this.LJIIZILJ.getVisibility() == 0) {
                    this.LJJIIJ.setVisibility(0);
                }
                if (this.LJIJI.getVisibility() == 0) {
                    LJ();
                }
            } else if (i == 3) {
                this.LJJIIJ.setVisibility(0);
            }
        } else {
            int i2 = this.LJJI;
            if (i2 == 1) {
                this.LJI.setForbidScroll(false);
            } else if (i2 == 3) {
                LIZ(2);
            }
        }
    }

    public static Object LIZ(1hK r7, String str) {
        Object obj;
        MethodCollector.i(6642);
        if (Build.VERSION.SDK_INT > 27 || !"clipboard".equals(str)) {
            if (!2FV.LIZIZ && "connectivity".equals(str)) {
                try {
                    new 7s1().LIZ();
                    2FV.LIZIZ = true;
                    obj = r7.getSystemService(str);
                } catch (Throwable unused) {
                }
            }
            obj = r7.getSystemService(str);
        } else if (2FV.LIZ) {
            synchronized (ClipboardManager.class) {
                try {
                    obj = r7.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(6642);
                    throw th;
                }
                2FV.LIZ = false;
            }
        } else {
            obj = r7.getSystemService(str);
        }
        MethodCollector.o(6642);
        return obj;
    }

    public final void LIZ(boolean z, boolean z2) {
        Integer num;
        String str;
        List imageList;
        6lY r2 = 6lY.LIZ;
        6J4 r3 = new 6J4();
        r3.LIZ("enter_from", "video_post_page");
        r3.LIZ("shoot_way", this.LJJJI.mShootWay);
        r3.LIZ("content_source", 6Gd.LIZ(this.LJJJI));
        r3.LIZ("content_type", 6Gd.LIZJ(this.LJJJI));
        r3.LIZ("creation_id", this.LJJJI.getCreationId());
        r3.LIZ("mix_type", "photo");
        r3.LIZ("is_multi_content", 1);
        ImageAlbumData imageAlbumData = this.LJJJI.getImageAlbumData();
        if (imageAlbumData == null || (imageList = imageAlbumData.getImageList()) == null) {
            num = null;
        } else {
            num = Integer.valueOf(imageList.size());
        }
        r3.LIZ("pic_cnt", num);
        if (z) {
            str = "zoom_in";
        } else {
            str = "zoom_out";
        }
        r3.LIZ("to_status", str);
        r3.LIZ("is_effective", z2 ? 1 : 0);
        r2.LIZ("click_full_screen_input_button", r3.LIZ);
    }

    public ExpandedTitleModule(1hK r11, VideoPublishEditModel videoPublishEditModel, ViewGroup viewGroup, View view) {
        M12.LIZ(r11, videoPublishEditModel, viewGroup, view);
        this.LJJIFFI = r11;
        this.LJJJI = videoPublishEditModel;
        this.LJJJIL = viewGroup;
        this.LJJII = view;
        3Dg findViewById = viewGroup.findViewById(2131364422);
        n.LIZIZ(findViewById, "");
        this.LIZ = findViewById;
        this.LIZIZ = (EditText) viewGroup.findViewById(2131364436);
        FbF fbF = (FbF) viewGroup.findViewById(2131364435);
        this.LIZJ = fbF;
        4ZZ findViewById2 = viewGroup.findViewById(2131364390);
        this.LIZLLL = findViewById2;
        4ZZ findViewById3 = viewGroup.findViewById(2131364386);
        this.LJ = findViewById3;
        this.LJFF = (ViewGroup) viewGroup.findViewById(2131366793);
        this.LJI = (C0218FXk) view.findViewById(2131369068);
        View findViewById4 = viewGroup.findViewById(2131365873);
        n.LIZIZ(findViewById4, "");
        this.LJJIIJ = findViewById4;
        this.LJII = (int) C5112HeD.LIZIZ(r11, 60.0f);
        this.LJJIIJZLJL = (int) C5112HeD.LIZIZ(r11, 108.0f);
        this.LJJIIZ = (int) C5112HeD.LIZIZ(r11, 85.0f);
        boolean LIZ2 = 6wl.LIZ();
        this.LJJIIZI = LIZ2;
        this.LJJIJIIJI = (int) C5112HeD.LIZIZ(r11, 254.0f);
        this.LJJIJIIJIL = (int) C5112HeD.LIZIZ(r11, 253.0f);
        this.LJIIJJI = -1;
        this.LJIIL = -1;
        this.LJIILIIL = -1;
        this.LJIILLIIL = new SafeHandler(r11);
        View findViewById5 = view.findViewById(2131365518);
        n.LIZIZ(findViewById5, "");
        this.LJIIZILJ = (ViewGroup) findViewById5;
        View findViewById6 = view.findViewById(2131362142);
        n.LIZIZ(findViewById6, "");
        this.LJIJ = (ViewGroup) findViewById6;
        View findViewById7 = view.findViewById(2131362154);
        n.LIZIZ(findViewById7, "");
        this.LJIJI = (ViewGroup) findViewById7;
        View findViewById8 = view.findViewById(2131362818);
        n.LIZIZ(findViewById8, "");
        this.LJIJJ = (ViewGroup) findViewById8;
        View findViewById9 = view.findViewById(2131362436);
        n.LIZIZ(findViewById9, "");
        this.LJJIJL = findViewById9;
        View findViewById10 = view.findViewById(2131362157);
        n.LIZIZ(findViewById10, "");
        this.LJJIJLIJ = findViewById10;
        Object LIZ3 = LIZ(r11, "input_method");
        this.LJJIL = (InputMethodManager) (!(LIZ3 instanceof InputMethodManager) ? null : LIZ3);
        this.LJJIZ = Mtx.LIZ(r11);
        0Bx LIZ4 = 0By.LIZ(r11, (0Bv) null);
        if (2GD.LIZ) {
            0Bs.LIZ(LIZ4, r11);
        }
        ExpandTextViewModel LIZ5 = LIZ4.LIZ(ExpandTextViewModel.class);
        n.LIZIZ(LIZ5, "");
        this.LJIL = LIZ5;
        FcV fcV = new FcV(this);
        this.LJJJ = fcV;
        this.LJJ = new FcY(this);
        this.LJJI = 1;
        fbF.LJIIIIZZ = false;
        if (C0045FQt.LIZ()) {
            n.LIZIZ(findViewById2, "");
            findViewById2.setVisibility(0);
            findViewById2.setOnClickListener(new View.OnClickListener(this) {
                public final /* synthetic */ ExpandedTitleModule LIZ;

                static {
                    Covode.recordClassIndex(110784);
                }

                {
                    this.LIZ = r1;
                }

                public final void onClick(View view) {
                    ExpandedTitleModule expandedTitleModule = this.LIZ;
                    if (!expandedTitleModule.LJIJJLI) {
                        expandedTitleModule.LJIIIZ = true;
                        expandedTitleModule.LIZLLL();
                        expandedTitleModule.LJIILL = true;
                        expandedTitleModule.LJIILLIIL.removeCallbacks(expandedTitleModule.LJJ);
                        expandedTitleModule.LJIILLIIL.postDelayed(expandedTitleModule.LJJ, 3000);
                    } else {
                        expandedTitleModule.LIZIZ();
                    }
                    this.LIZ.LIZ(true, true);
                }
            });
        }
        findViewById3.setOnClickListener(new View.OnClickListener(this) {
            public final /* synthetic */ ExpandedTitleModule LIZ;

            static {
                Covode.recordClassIndex(110785);
            }

            {
                this.LIZ = r1;
            }

            public final void onClick(View view) {
                this.LIZ.LJ();
                this.LIZ.LIZ(false, true);
            }
        });
        if (LIZ2) {
            this.LJIIIIZZ = (int) C5112HeD.LIZIZ(r11, 41.0f);
        }
        this.LJJIZ.LIZ(fcV);
        r11.getLifecycle().LIZ(this);
        view.post(new Runnable(this) {
            public final /* synthetic */ ExpandedTitleModule LIZ;

            static {
                Covode.recordClassIndex(110786);
            }

            {
                this.LIZ = r1;
            }

            public final void run() {
                ExpandedTitleModule expandedTitleModule = this.LIZ;
                expandedTitleModule.LJIIL = expandedTitleModule.LJJII.getMeasuredHeight();
                ExpandedTitleModule expandedTitleModule2 = this.LIZ;
                expandedTitleModule2.LJIIJJI = expandedTitleModule2.LJJII.getMeasuredWidth();
            }
        });
        C0145FUp.LIZ(findViewById10);
        LIZJ(1);
    }

    private final void LIZ(int i, int i2, int i3, int i4, Ls2<2Pr> ls2) {
        int height = this.LIZ.getHeight();
        C0218FXk fXk = this.LJI;
        n.LIZIZ(fXk, "");
        int scrollY = fXk.getScrollY();
        FbF fbF = this.LIZJ;
        n.LIZIZ(fbF, "");
        int minHeight = fbF.getMinHeight();
        ValueAnimator ofInt = ValueAnimator.ofInt(new int[]{height, i});
        ofInt.setDuration(this.LJJIJ);
        int i5 = i3;
        int i6 = i2;
        Ls2<2Pr> ls22 = ls2;
        int i7 = i4;
        ofInt.addUpdateListener(new FcX(this, i6, scrollY, i5, minHeight, ls22, i7));
        ofInt.addListener(new FcW(this, i6, scrollY, i5, minHeight, ls22, i7));
        ofInt.start();
    }
}
