package ඓ.ᨨ.K.ඓ.㸾;

import android.content.Context;
import android.database.Cursor;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.zhihu.matisse.R$dimen;
import com.zhihu.matisse.R$id;
import com.zhihu.matisse.R$layout;
import com.zhihu.matisse.internal.entity.Album;
import com.zhihu.matisse.internal.entity.Item;
import ඓ.ᨨ.K.ඓ.ʬ.C0766;
import ඓ.ᨨ.K.ඓ.ʬ.C0767;
import ඓ.ᨨ.K.ඓ.K.C0778;
import ඓ.ᨨ.K.ඓ.㸾.ʬ.C0785;
import ඓ.ᨨ.K.ඓ.㸾.㸾.C0798;
import ῲ.ᓣ.K.AbstractC1695;

/* renamed from: ඓ.ᨨ.K.ඓ.㸾.K  reason: contains not printable characters */
/* compiled from: MediaSelectionFragment */
public class C0796 extends Fragment implements C0767.AbstractC0768, C0785.AbstractC0786, C0785.AbstractC0787 {

    /* renamed from: ʬ  reason: contains not printable characters */
    public RecyclerView f3991;

    /* renamed from: ඓ  reason: contains not printable characters */
    public AbstractC0797 f3992;

    /* renamed from: ῲ  reason: contains not printable characters */
    public final C0767 f3993 = new C0767();

    /* renamed from: ⁱ  reason: contains not printable characters */
    public C0785.AbstractC0787 f3994;

    /* renamed from: 㴹  reason: contains not printable characters */
    public C0785.AbstractC0786 f3995;

    /* renamed from: 㸾  reason: contains not printable characters */
    public C0785 f3996;

    /* renamed from: ඓ.ᨨ.K.ඓ.㸾.K$K  reason: contains not printable characters */
    /* compiled from: MediaSelectionFragment */
    public interface AbstractC0797 {
        /* renamed from: ඓ  reason: contains not printable characters */
        C0766 m2385();
    }

    @Override // androidx.fragment.app.Fragment
    public void onActivityCreated(Bundle bundle) {
        super.onActivityCreated(bundle);
        Album album = (Album) getArguments().getParcelable("extra_album");
        this.f3996 = new C0785(getContext(), this.f3992.m2385(), this.f3991);
        this.f3996.m2371(this);
        this.f3996.registerOnMediaClickListener(this);
        int i = 1;
        this.f3991.setHasFixedSize(true);
        C0778 r0 = C0778.C0779.f3967;
        if (r0.f3945 > 0) {
            int round = Math.round(((float) getContext().getResources().getDisplayMetrics().widthPixels) / ((float) r0.f3945));
            if (round != 0) {
                i = round;
            }
        } else {
            i = r0.f3966;
        }
        this.f3991.setLayoutManager(new GridLayoutManager(getContext(), i));
        this.f3991.addItemDecoration(new C0798(i, getResources().getDimensionPixelSize(R$dimen.media_grid_spacing), false));
        this.f3991.setAdapter(this.f3996);
        this.f3993.m2328(getActivity(), this);
        this.f3993.m2329(album, r0.f3952);
    }

    @Override // androidx.fragment.app.Fragment
    public void onAttach(Context context) {
        super.onAttach(context);
        if (context instanceof AbstractC0797) {
            this.f3992 = (AbstractC0797) context;
            if (context instanceof C0785.AbstractC0786) {
                this.f3995 = (C0785.AbstractC0786) context;
            }
            if (context instanceof C0785.AbstractC0787) {
                this.f3994 = (C0785.AbstractC0787) context;
                return;
            }
            return;
        }
        throw new IllegalStateException("Context must implement SelectionProvider.");
    }

    @Override // androidx.fragment.app.Fragment
    public View onCreateView(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
        return layoutInflater.inflate(R$layout.fragment_media_selection, viewGroup, false);
    }

    @Override // androidx.fragment.app.Fragment
    public void onDestroyView() {
        super.onDestroyView();
        C0767 r0 = this.f3993;
        AbstractC1695 k = r0.f3920;
        if (k != null) {
            k.m4341(2);
        }
        r0.f3919 = null;
    }

    @Override // androidx.fragment.app.Fragment
    public void onViewCreated(View view, Bundle bundle) {
        super.onViewCreated(view, bundle);
        this.f3991 = (RecyclerView) view.findViewById(R$id.recyclerview);
    }

    @Override // ඓ.ᨨ.K.ඓ.㸾.ʬ.C0785.AbstractC0786
    /* renamed from: ⁱ  reason: contains not printable characters */
    public void m2380() {
        C0785.AbstractC0786 r0 = this.f3995;
        if (r0 != null) {
            r0.m2372();
        }
    }

    @Override // ඓ.ᨨ.K.ඓ.ʬ.C0767.AbstractC0768
    /* renamed from: K  reason: contains not printable characters */
    public void m2381(Cursor cursor) {
        this.f3996.m2375(cursor);
    }

    @Override // ඓ.ᨨ.K.ඓ.ʬ.C0767.AbstractC0768
    /* renamed from: 㴹  reason: contains not printable characters */
    public void m2383() {
        this.f3996.m2375(null);
    }

    /* renamed from: 㿎  reason: contains not printable characters */
    public void m2384() {
        this.f3996.notifyDataSetChanged();
    }

    @Override // ඓ.ᨨ.K.ඓ.㸾.ʬ.C0785.AbstractC0787
    /* renamed from: K  reason: contains not printable characters */
    public void m2382(Album album, Item item, int i) {
        C0785.AbstractC0787 r3 = this.f3994;
        if (r3 != null) {
            r3.m2373((Album) getArguments().getParcelable("extra_album"), item, i);
        }
    }
}
