package com.ss.android.ugc.aweme.shortvideo.mvtemplate.choosemedia;

import X.07U;
import X.0EF;
import X.0HH;
import X.6q3;
import X.77a;
import X.Bij;
import X.C4682O2j;
import X.C4683O2k;
import X.C4690O2r;
import X.C4714O3p;
import X.EkW;
import X.ME0;
import X.O0X;
import X.O5A;
import X.O9H;
import X.QIe;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;
import androidx.recyclerview.widget.RecyclerView;
import com.bytedance.covode.number.Covode;
import com.ss.android.ugc.aweme.appcompat.AmeBaseFragment;
import com.ss.android.ugc.aweme.shortvideo.mvtemplate.choosemedia.model.MyMediaModel;
import java.util.ArrayList;
import java.util.List;

public abstract class AVMediaChooseBaseFragment extends AmeBaseFragment {
    public int LIZIZ = 4;
    public C4682O2j LIZJ;
    public RecyclerView LIZLLL;
    public C4690O2r LJ;
    public View LJFF;
    public TextView LJI;
    public EkW LJII;
    public int LJIIIIZZ = 6q3.LIZIZ.LIZ();
    public int LJIIIZ = 6q3.LIZIZ.LIZ();
    public boolean LJIIJ;
    public int LJIIJJI;
    public List<String> LJIIL = new ArrayList();
    public Long LJIILIIL = 0L;
    public boolean LJIILJJIL = false;
    public boolean LJIILL = true;
    public O0X LJIILLIIL = new O0X((byte) 0);
    public String LJIIZILJ = "";
    public int LJIJ = -1;
    public O5A LJIJI;
    public boolean LJIJJ = false;
    public boolean LJIJJLI = false;
    public boolean LJIL = false;

    static {
        Covode.recordClassIndex(111088);
    }

    public abstract void LIZ(List<MyMediaModel> list, boolean z);

    public void LIZ(boolean z) {
    }

    public void LIZJ() {
        this.LJIL = true;
    }

    public final void LJ() {
        C4682O2j o2j = this.LIZJ;
        if (o2j != null) {
            o2j.LIZLLL();
        }
    }

    public final int LIZIZ() {
        C4682O2j o2j = this.LIZJ;
        if (o2j != null) {
            return o2j.LIZLLL;
        }
        return 0;
    }

    public final void LJFF() {
        O9H o9h;
        C4714O3p o3p = this.LIZLLL;
        if ((o3p instanceof C4714O3p) && (o9h = o3p.LJJJ) != null && o9h.LIZ(o9h.LJ) && o9h.LJ != null) {
            o9h.getHandler().removeCallbacks(o9h.LJIIL);
            o9h.LIZ(o9h.LJFF);
            o9h.LJ.setVisibility(8);
        }
    }

    public final void LIZLLL() {
        C4682O2j o2j = this.LIZJ;
        if (o2j != null) {
            07U LIZ = Bij.LIZ(o2j.LJIIIZ);
            int intValue = ((Integer) LIZ.LIZ).intValue();
            o2j.notifyItemRangeChanged(intValue, (((Integer) LIZ.LIZIZ).intValue() - intValue) + 1, new Object());
        }
    }

    public final String LJI() {
        if (!this.LJIILL) {
            return "";
        }
        String LIZ = 6q3.LIZIZ.LIZ(this.LJFF.getContext());
        if (this.LJIILLIIL.LJ.LJFF) {
            return getString(2131823555, new Object[]{Integer.valueOf(this.LJIIIZ)});
        }
        int i = this.LJIIJJI;
        if (i == 1 || i == 10) {
            return 0HH.LIZ(getString(2131823555), new Object[]{Integer.valueOf(this.LJIIIZ)});
        } else if (i == 18) {
            return getResources().getString(2131833445);
        } else {
            if (i == 16) {
                return 0HH.LIZ(getString(2131823555), new Object[]{10});
            } else if (i == 19) {
                return 0HH.LIZ(getString(2131823555), new Object[]{1});
            } else if (77a.LIZJ) {
                return 6q3.LIZIZ.LIZ(this.LJFF.getContext());
            } else {
                if (77a.LIZJ) {
                    return 77a.LIZLLL.LIZ(this.LJFF.getContext());
                }
                return LIZ;
            }
        }
    }

    public final void LIZ(MyMediaModel myMediaModel) {
        C4682O2j o2j = this.LIZJ;
        if (o2j != null) {
            o2j.LIZ(myMediaModel);
        }
    }

    public final void LIZ(int i) {
        this.LJIIIZ = i;
        this.LJIIIIZZ = i;
        C4682O2j o2j = this.LIZJ;
        if (o2j != null) {
            o2j.LIZ = i;
        }
    }

    public final void LIZJ(MyMediaModel myMediaModel) {
        C4682O2j o2j = this.LIZJ;
        if (o2j != null && myMediaModel.LJIL >= 0) {
            o2j.LIZ(myMediaModel, -1);
        }
    }

    public final void LIZIZ(int i) {
        this.LJIIIIZZ = i;
        C4682O2j o2j = this.LIZJ;
        if (o2j != null) {
            o2j.LIZ = i;
        }
    }

    public final void LIZJ(int i) {
        0EF layoutManager;
        RecyclerView recyclerView = this.LIZLLL;
        if (recyclerView != null && (layoutManager = recyclerView.getLayoutManager()) != null && layoutManager.LIZJ(i) == null) {
            layoutManager.LJ(i);
        }
    }

    public final View LIZLLL(int i) {
        0EF layoutManager;
        RecyclerView recyclerView = this.LIZLLL;
        if (recyclerView == null || (layoutManager = recyclerView.getLayoutManager()) == null) {
            return null;
        }
        return layoutManager.LIZJ(i);
    }

    public void onCreate(Bundle bundle) {
        AVMediaChooseBaseFragment.super.onCreate(bundle);
        Bundle arguments = getArguments();
        if (arguments != null) {
            this.LJIIZILJ = arguments.getString("shoot_way", "");
        }
    }

    public final void LIZ(List<String> list) {
        this.LJIIJ = true;
        this.LJIIL.addAll(list);
    }

    public final void LIZIZ(MyMediaModel myMediaModel) {
        C4682O2j o2j = this.LIZJ;
        if (o2j != null) {
            o2j.LIZ(myMediaModel, -1, false);
        }
    }

    public final int LIZLLL(MyMediaModel myMediaModel) {
        C4682O2j o2j = this.LIZJ;
        if (o2j != null) {
            for (int i = 0; i < o2j.LJIIJ.size(); i++) {
                if (TextUtils.equals(o2j.LJIIJ.get(i).LIZ, myMediaModel.LIZ)) {
                    return i;
                }
            }
        }
        return -1;
    }

    public void onActivityCreated(Bundle bundle) {
        AVMediaChooseBaseFragment.super.onActivityCreated(bundle);
        this.LJIJJ = true;
        if (this.LJIJJLI && !this.LJIL) {
            LIZJ();
        }
        if (getArguments() != null && getArguments().getParcelable("PREVIEW_CONFIG") != null) {
            this.LJIILLIIL = (O0X) getArguments().getParcelable("PREVIEW_CONFIG");
        }
    }

    public void setUserVisibleHint(boolean z) {
        AVMediaChooseBaseFragment.super.setUserVisibleHint(z);
        this.LJIJJLI = z;
        if (this.LJIJJ && !this.LJIL) {
            LIZJ();
        }
        if (this.LJIL) {
            C4682O2j o2j = this.LIZJ;
            boolean z2 = !z;
            o2j.LJIILLIIL = true;
            if (ME0.LIZ()) {
                for (int i = 0; i < o2j.LJIIIZ.getChildCount(); i++) {
                    C4683O2k LIZ = o2j.LJIIIZ.LIZ(o2j.LJIIIZ.getChildAt(i));
                    if (!o2j.LJIILJJIL.contains(LIZ)) {
                        if (z2) {
                            LIZ.LIZ.setController((QIe) null);
                        } else {
                            o2j.LIZ(LIZ, -1);
                        }
                    }
                }
            }
        }
    }

    public void onViewCreated(View view, Bundle bundle) {
        this.LJIILIIL = Long.valueOf(System.currentTimeMillis());
        AVMediaChooseBaseFragment.super.onViewCreated(view, bundle);
    }

    public final void LIZ(MyMediaModel myMediaModel, boolean z) {
        C4682O2j o2j = this.LIZJ;
        if (o2j == null) {
            return;
        }
        if (!z) {
            o2j.LIZ(myMediaModel);
        } else if (myMediaModel != null) {
            if (!o2j.LIZJ.contains(myMediaModel)) {
                o2j.LIZJ.add(myMediaModel);
            }
            o2j.LIZLLL();
        }
    }
}
