package ඓ.ᨨ.K.ඓ.㸾.ʬ;

import android.content.Context;
import android.content.res.TypedArray;
import android.database.Cursor;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.zhihu.matisse.R$attr;
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 com.zhihu.matisse.internal.ui.widget.CheckView;
import com.zhihu.matisse.internal.ui.widget.MediaGrid;
import ඓ.ᨨ.K.ඓ.ʬ.C0766;
import ඓ.ᨨ.K.ඓ.K.C0778;
import ඓ.ᨨ.K.ඓ.K.C0781;

/* renamed from: ඓ.ᨨ.K.ඓ.㸾.ʬ.K  reason: contains not printable characters */
/* compiled from: AlbumMediaAdapter */
public class C0785 extends AbstractC0792<RecyclerView.AbstractC0269> implements MediaGrid.AbstractC0569 {

    /* renamed from: ʬ  reason: contains not printable characters */
    public final C0766 f3976;

    /* renamed from: ඓ  reason: contains not printable characters */
    public C0778 f3977 = C0778.C0779.f3967;

    /* renamed from: ᨨ  reason: contains not printable characters */
    public int f3978;

    /* renamed from: ⁱ  reason: contains not printable characters */
    public AbstractC0787 f3979;

    /* renamed from: 㴹  reason: contains not printable characters */
    public AbstractC0786 f3980;

    /* renamed from: 㸾  reason: contains not printable characters */
    public final Drawable f3981;

    /* renamed from: 㿎  reason: contains not printable characters */
    public RecyclerView f3982;

    /* renamed from: ඓ.ᨨ.K.ඓ.㸾.ʬ.K$ʬ  reason: contains not printable characters */
    /* compiled from: AlbumMediaAdapter */
    public interface AbstractC0786 {
        /* renamed from: ⁱ  reason: contains not printable characters */
        void m2372();
    }

    /* renamed from: ඓ.ᨨ.K.ඓ.㸾.ʬ.K$ඓ  reason: contains not printable characters */
    /* compiled from: AlbumMediaAdapter */
    public interface AbstractC0787 {
        /* renamed from: K  reason: contains not printable characters */
        void m2373(Album album, Item item, int i);
    }

    /* renamed from: ඓ.ᨨ.K.ඓ.㸾.ʬ.K$ῲ  reason: contains not printable characters */
    /* compiled from: AlbumMediaAdapter */
    public static class C0788 extends RecyclerView.AbstractC0269 {

        /* renamed from: K  reason: contains not printable characters */
        public TextView f3983;

        public C0788(View view) {
            super(view);
            this.f3983 = (TextView) view.findViewById(R$id.hint);
        }
    }

    /* renamed from: ඓ.ᨨ.K.ඓ.㸾.ʬ.K$K  reason: contains not printable characters */
    /* compiled from: AlbumMediaAdapter */
    public class View$OnClickListenerC0789 implements View.OnClickListener {
        public View$OnClickListenerC0789(C0785 k) {
        }

        public void onClick(View view) {
            if (view.getContext() instanceof AbstractC0790) {
                ((AbstractC0790) view.getContext()).m2374();
            }
        }
    }

    /* renamed from: ඓ.ᨨ.K.ඓ.㸾.ʬ.K$㴹  reason: contains not printable characters */
    /* compiled from: AlbumMediaAdapter */
    public interface AbstractC0790 {
        /* renamed from: 㿎  reason: contains not printable characters */
        void m2374();
    }

    /* renamed from: ඓ.ᨨ.K.ඓ.㸾.ʬ.K$㸾  reason: contains not printable characters */
    /* compiled from: AlbumMediaAdapter */
    public static class C0791 extends RecyclerView.AbstractC0269 {

        /* renamed from: K  reason: contains not printable characters */
        public MediaGrid f3984;

        public C0791(View view) {
            super(view);
            this.f3984 = (MediaGrid) view;
        }
    }

    public C0785(Context context, C0766 r4, RecyclerView recyclerView) {
        super(null);
        this.f3976 = r4;
        TypedArray obtainStyledAttributes = context.getTheme().obtainStyledAttributes(new int[]{R$attr.item_placeholder});
        this.f3981 = obtainStyledAttributes.getDrawable(0);
        obtainStyledAttributes.recycle();
        this.f3982 = recyclerView;
    }

    @Override // androidx.recyclerview.widget.RecyclerView.AbstractC0246
    public RecyclerView.AbstractC0269 onCreateViewHolder(ViewGroup viewGroup, int i) {
        if (i == 1) {
            C0788 r4 = new C0788(LayoutInflater.from(viewGroup.getContext()).inflate(R$layout.photo_capture_item, viewGroup, false));
            r4.itemView.setOnClickListener(new View$OnClickListenerC0789(this));
            return r4;
        } else if (i == 2) {
            return new C0791(LayoutInflater.from(viewGroup.getContext()).inflate(R$layout.media_grid_item, viewGroup, false));
        } else {
            return null;
        }
    }

    public void registerOnMediaClickListener(AbstractC0787 r1) {
        this.f3979 = r1;
    }

    @Override // ඓ.ᨨ.K.ඓ.㸾.ʬ.AbstractC0792
    /* renamed from: K  reason: contains not printable characters */
    public void m2368(RecyclerView.AbstractC0269 r10, Cursor cursor) {
        Drawable.ConstantState constantState;
        if (r10 instanceof C0788) {
            C0788 r11 = (C0788) r10;
            Drawable[] compoundDrawables = r11.f3983.getCompoundDrawables();
            TypedArray obtainStyledAttributes = r10.itemView.getContext().getTheme().obtainStyledAttributes(new int[]{R$attr.capture_textColor});
            int color = obtainStyledAttributes.getColor(0, 0);
            obtainStyledAttributes.recycle();
            for (int i = 0; i < compoundDrawables.length; i++) {
                Drawable drawable = compoundDrawables[i];
                if (!(drawable == null || (constantState = drawable.getConstantState()) == null)) {
                    Drawable mutate = constantState.newDrawable().mutate();
                    mutate.setColorFilter(color, PorterDuff.Mode.SRC_IN);
                    mutate.setBounds(drawable.getBounds());
                    compoundDrawables[i] = mutate;
                }
            }
            r11.f3983.setCompoundDrawables(compoundDrawables[0], compoundDrawables[1], compoundDrawables[2], compoundDrawables[3]);
        } else if (r10 instanceof C0791) {
            C0791 r0 = (C0791) r10;
            Item r112 = Item.m1911(cursor);
            MediaGrid mediaGrid = r0.f3984;
            Context context = mediaGrid.getContext();
            if (this.f3978 == 0) {
                int r6 = ((GridLayoutManager) this.f3982.getLayoutManager()).m772();
                this.f3978 = (context.getResources().getDisplayMetrics().widthPixels - ((r6 - 1) * context.getResources().getDimensionPixelSize(R$dimen.media_grid_spacing))) / r6;
                this.f3978 = (int) (((float) this.f3978) * this.f3977.f3958);
            }
            mediaGrid.m1930(new MediaGrid.C0568(this.f3978, this.f3981, this.f3977.f3961, r10));
            r0.f3984.m1929(r112);
            r0.f3984.setOnMediaGridClickListener(this);
            MediaGrid mediaGrid2 = r0.f3984;
            if (this.f3977.f3961) {
                int r113 = this.f3976.m2315(r112);
                if (r113 > 0) {
                    mediaGrid2.setCheckEnabled(true);
                    mediaGrid2.setCheckedNum(r113);
                } else if (this.f3976.m2318()) {
                    mediaGrid2.setCheckEnabled(false);
                    mediaGrid2.setCheckedNum(Integer.MIN_VALUE);
                } else {
                    mediaGrid2.setCheckEnabled(true);
                    mediaGrid2.setCheckedNum(r113);
                }
            } else if (this.f3976.f3917.contains(r112)) {
                mediaGrid2.setCheckEnabled(true);
                mediaGrid2.setChecked(true);
            } else if (this.f3976.m2318()) {
                mediaGrid2.setCheckEnabled(false);
                mediaGrid2.setChecked(false);
            } else {
                mediaGrid2.setCheckEnabled(true);
                mediaGrid2.setChecked(false);
            }
        }
    }

    @Override // com.zhihu.matisse.internal.ui.widget.MediaGrid.AbstractC0569
    /* renamed from: K  reason: contains not printable characters */
    public void m2367(ImageView imageView, Item item, RecyclerView.AbstractC0269 r4) {
        if (this.f3977.f3950) {
            AbstractC0787 r2 = this.f3979;
            if (r2 != null) {
                r2.m2373(null, item, r4.getAdapterPosition());
                return;
            }
            return;
        }
        m2369(item, r4);
    }

    @Override // com.zhihu.matisse.internal.ui.widget.MediaGrid.AbstractC0569
    /* renamed from: K  reason: contains not printable characters */
    public void m2370(CheckView checkView, Item item, RecyclerView.AbstractC0269 r3) {
        m2369(item, r3);
    }

    /* renamed from: K  reason: contains not printable characters */
    public final void m2369(Item item, RecyclerView.AbstractC0269 r6) {
        boolean z = true;
        if (this.f3977.f3961) {
            if (this.f3976.m2315(item) == Integer.MIN_VALUE) {
                Context context = r6.itemView.getContext();
                C0781 r0 = this.f3976.m2312(item);
                C0781.m2362(context, r0);
                if (r0 != null) {
                    z = false;
                }
                if (z) {
                    this.f3976.m2322(item);
                    m2366();
                    return;
                }
                return;
            }
            this.f3976.m2314(item);
            m2366();
        } else if (this.f3976.f3917.contains(item)) {
            this.f3976.m2314(item);
            m2366();
        } else {
            Context context2 = r6.itemView.getContext();
            C0781 r02 = this.f3976.m2312(item);
            C0781.m2362(context2, r02);
            if (r02 != null) {
                z = false;
            }
            if (z) {
                this.f3976.m2322(item);
                m2366();
            }
        }
    }

    /* renamed from: K  reason: contains not printable characters */
    public final void m2366() {
        notifyDataSetChanged();
        AbstractC0786 r0 = this.f3980;
        if (r0 != null) {
            r0.m2372();
        }
    }

    @Override // ඓ.ᨨ.K.ඓ.㸾.ʬ.AbstractC0792
    /* renamed from: K  reason: contains not printable characters */
    public int m2365(int i, Cursor cursor) {
        return Item.m1911(cursor).m1914() ? 1 : 2;
    }

    /* renamed from: K  reason: contains not printable characters */
    public void m2371(AbstractC0786 r1) {
        this.f3980 = r1;
    }
}
