package com.ss.android.ugc.aweme.share.download.photodownload;

import X.070;
import X.0Bs;
import X.0Bv;
import X.0Bx;
import X.0By;
import X.0HH;
import X.1hK;
import X.2GD;
import X.4rR;
import X.C2333Aqf;
import X.C2338Aqk;
import X.C2339Aql;
import X.C2340Aqm;
import X.C2341Aqn;
import X.C2342Aqo;
import X.C2343Aqp;
import X.C2349Aqv;
import X.C6474CbG;
import X.C6523Cc3;
import X.CE9;
import X.JR5;
import X.M12;
import X.Qeg;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.util.SparseArray;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.bytedance.covode.number.Covode;
import com.bytedance.keva.Keva;
import com.ss.android.ugc.aweme.feed.model.Aweme;
import com.ss.android.ugc.aweme.feed.model.PhotoModeImageInfo;
import com.ss.android.ugc.aweme.feed.model.PhotoModeImageUrlModel;
import java.util.List;
import kotlin.h.b.n;

public final class PhotoModeDownloadFragment extends Fragment {
    public static final C2342Aqo LJI = new C2342Aqo((byte) 0);
    public PhotoSelectionViewModel LIZ;
    public final Aweme LIZIZ;
    public final 4rR LIZJ;
    public final String LIZLLL;
    public final String LJ;
    public final JR5 LJFF;
    public SparseArray LJII;

    static {
        Covode.recordClassIndex(107027);
    }

    public final View LIZ(int i) {
        if (this.LJII == null) {
            this.LJII = new SparseArray();
        }
        View view = (View) this.LJII.get(i);
        if (view != null) {
            return view;
        }
        View view2 = getView();
        if (view2 == null) {
            return null;
        }
        View findViewById = view2.findViewById(i);
        this.LJII.put(i, findViewById);
        return findViewById;
    }

    public final /* synthetic */ void onDestroyView() {
        PhotoModeDownloadFragment.super.onDestroyView();
        SparseArray sparseArray = this.LJII;
        if (sparseArray != null) {
            sparseArray.clear();
        }
    }

    public static final /* synthetic */ PhotoSelectionViewModel LIZ(PhotoModeDownloadFragment photoModeDownloadFragment) {
        PhotoSelectionViewModel photoSelectionViewModel = photoModeDownloadFragment.LIZ;
        if (photoSelectionViewModel == null) {
            n.LIZ("");
        }
        return photoSelectionViewModel;
    }

    public final void onActivityCreated(Bundle bundle) {
        ViewParent viewParent;
        PhotoModeDownloadFragment.super.onActivityCreated(bundle);
        View view = getView();
        View view2 = null;
        if (view != null) {
            viewParent = view.getParent();
        } else {
            viewParent = null;
        }
        if (viewParent instanceof View) {
            view2 = viewParent;
        }
        View view3 = view2;
        if (view3 != null) {
            view3.setBackgroundColor(0);
        }
    }

    public final void onViewCreated(View view, Bundle bundle) {
        List<PhotoModeImageUrlModel> imageList;
        int size;
        PhotoModeImageInfo photoModeImageInfo;
        List<PhotoModeImageUrlModel> imageList2;
        List<PhotoModeImageUrlModel> imageList3;
        M12.LIZ(view);
        PhotoModeDownloadFragment.super.onViewCreated(view, bundle);
        PhotoModeImageInfo photoModeImageInfo2 = this.LIZIZ.getPhotoModeImageInfo();
        int i = 0;
        if (photoModeImageInfo2 != null && (imageList = photoModeImageInfo2.getImageList()) != null && (size = imageList.size()) > 0) {
            1hK activity = getActivity();
            if (activity != null) {
                0Bx LIZ2 = 0By.LIZ(activity, (0Bv) null);
                if (2GD.LIZ) {
                    0Bs.LIZ(LIZ2, activity);
                }
                PhotoSelectionViewModel LIZ3 = LIZ2.LIZ(PhotoSelectionViewModel.class);
                n.LIZIZ(LIZ3, "");
                PhotoSelectionViewModel photoSelectionViewModel = LIZ3;
                this.LIZ = photoSelectionViewModel;
                if (photoSelectionViewModel == null) {
                    n.LIZ("");
                }
                photoSelectionViewModel.LIZIZ();
            }
            1hK activity2 = getActivity();
            if (activity2 != null) {
                C6523Cc3.LIZIZ((Activity) activity2);
            }
            Qeg LIZ4 = LIZ(2131367695);
            Context context = LIZ4.getContext();
            n.LIZIZ(context, "");
            LIZ4.setText(context.getResources().getText(2131834864));
            LIZ4.setTextColor(070.LIZJ(LIZ4.getContext(), this.LIZJ.LJI));
            LIZ4.setAlpha(this.LIZJ.LJII);
            LIZ4.setVisibility(0);
            LIZ(2131364214).setOnClickListener(new C2341Aqn(this));
            RecyclerView LIZ5 = LIZ(2131368498);
            n.LIZIZ(LIZ5, "");
            getActivity();
            LIZ5.setLayoutManager(new LinearLayoutManager(0, false));
            Aweme aweme = this.LIZIZ;
            PhotoSelectionViewModel photoSelectionViewModel2 = this.LIZ;
            if (photoSelectionViewModel2 == null) {
                n.LIZ("");
            }
            C2333Aqf aqf = new C2333Aqf(aweme, photoSelectionViewModel2);
            RecyclerView LIZ6 = LIZ(2131368498);
            n.LIZIZ(LIZ6, "");
            LIZ6.setAdapter(aqf);
            if (Keva.getRepo("download_photo_selection_keva").getBoolean("is_default_select_all", false)) {
                CE9 ce9 = (CE9) LIZ(2131370027);
                n.LIZIZ(ce9, "");
                ce9.setChecked(true);
                PhotoSelectionViewModel photoSelectionViewModel3 = this.LIZ;
                if (photoSelectionViewModel3 == null) {
                    n.LIZ("");
                }
                PhotoModeImageInfo photoModeImageInfo3 = this.LIZIZ.getPhotoModeImageInfo();
                if (!(photoModeImageInfo3 == null || (imageList3 = photoModeImageInfo3.getImageList()) == null)) {
                    i = imageList3.size();
                }
                photoSelectionViewModel3.LIZIZ(i);
            } else {
                int i2 = C2349Aqv.LJIILL;
                if (i2 >= 0 && (photoModeImageInfo = this.LIZIZ.getPhotoModeImageInfo()) != null && (imageList2 = photoModeImageInfo.getImageList()) != null && i2 < imageList2.size()) {
                    PhotoSelectionViewModel photoSelectionViewModel4 = this.LIZ;
                    if (photoSelectionViewModel4 == null) {
                        n.LIZ("");
                    }
                    photoSelectionViewModel4.LIZ(i2);
                }
            }
            LIZ(2131370028).setOnClickListener(new C2338Aqk(this, aqf));
            ((CE9) LIZ(2131370027)).setOnClickListener(new C2339Aql(this, aqf));
            ((C6474CbG) LIZ(2131369801)).setOnClickListener(new C2343Aqp(this));
            1hK activity3 = getActivity();
            if (activity3 != null) {
                PhotoSelectionViewModel photoSelectionViewModel5 = this.LIZ;
                if (photoSelectionViewModel5 == null) {
                    n.LIZ("");
                }
                photoSelectionViewModel5.LIZ().observe(activity3, new C2340Aqm(this, size));
            }
        }
    }

    public final View onCreateView(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
        M12.LIZ(layoutInflater);
        return 0HH.LIZ(layoutInflater, 2131561317, viewGroup, false);
    }

    public PhotoModeDownloadFragment(Aweme aweme, 4rR r2, String str, String str2, JR5 jr5) {
        M12.LIZ(aweme, r2, str, str2, jr5);
        this.LIZIZ = aweme;
        this.LIZJ = r2;
        this.LIZLLL = str;
        this.LJ = str2;
        this.LJFF = jr5;
    }
}
