package ඓ.ᨨ.K.ඓ.ʬ;

import android.content.Context;
import android.content.res.Resources;
import android.net.Uri;
import android.os.Bundle;
import com.zhihu.matisse.R;
import com.zhihu.matisse.R$string;
import com.zhihu.matisse.internal.entity.Item;
import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import ඓ.ᨨ.K.ඓ.ඓ.C0771;
import ඓ.ᨨ.K.ඓ.K.C0778;
import ඓ.ᨨ.K.ඓ.K.C0781;
import ඓ.ⁱ.K.ඓ.C1252;

/* renamed from: ඓ.ᨨ.K.ඓ.ʬ.ʬ  reason: contains not printable characters */
/* compiled from: SelectedItemCollection */
public class C0766 {

    /* renamed from: ʬ  reason: contains not printable characters */
    public int f3916 = 0;

    /* renamed from: ῲ  reason: contains not printable characters */
    public Set<Item> f3917;

    /* renamed from: K  reason: contains not printable characters */
    public final Context f3918;

    public C0766(Context context) {
        this.f3918 = context;
    }

    /* renamed from: ʬ  reason: contains not printable characters */
    public List<Uri> m2311() {
        ArrayList arrayList = new ArrayList();
        for (Item item : this.f3917) {
            arrayList.add(item.m1915());
        }
        return arrayList;
    }

    /* renamed from: ඓ  reason: contains not printable characters */
    public boolean m2314(Item item) {
        boolean remove = this.f3917.remove(item);
        if (remove) {
            boolean z = false;
            if (this.f3917.size() == 0) {
                this.f3916 = 0;
            } else if (this.f3916 == 3) {
                boolean z2 = false;
                for (Item item2 : this.f3917) {
                    if (item2.m1916() && !z) {
                        z = true;
                    }
                    if (item2.m1913() && !z2) {
                        z2 = true;
                    }
                }
                if (z && z2) {
                    this.f3916 = 3;
                } else if (z) {
                    this.f3916 = 1;
                } else if (z2) {
                    this.f3916 = 2;
                }
            }
        }
        return remove;
    }

    /* renamed from: ῲ  reason: contains not printable characters */
    public void m2317(Bundle bundle) {
        bundle.putParcelableArrayList("state_selection", new ArrayList<>(this.f3917));
        bundle.putInt("state_collection_type", this.f3916);
    }

    /* renamed from: ⁱ  reason: contains not printable characters */
    public boolean m2318() {
        return this.f3917.size() == m2313();
    }

    /* renamed from: K  reason: contains not printable characters */
    public void m2320(Bundle bundle) {
        if (bundle == null) {
            this.f3917 = new LinkedHashSet();
            return;
        }
        this.f3917 = new LinkedHashSet(bundle.getParcelableArrayList("state_selection"));
        this.f3916 = bundle.getInt("state_collection_type", 0);
    }

    /* renamed from: 㴹  reason: contains not printable characters */
    public Bundle m2323() {
        Bundle bundle = new Bundle();
        bundle.putParcelableArrayList("state_selection", new ArrayList<>(this.f3917));
        bundle.putInt("state_collection_type", this.f3916);
        return bundle;
    }

    /* renamed from: 㸾  reason: contains not printable characters */
    public boolean m2326(Item item) {
        return this.f3917.contains(item);
    }

    /* renamed from: 㸾  reason: contains not printable characters */
    public int m2325() {
        return this.f3917.size();
    }

    /* renamed from: ῲ  reason: contains not printable characters */
    public List<String> m2316() {
        ArrayList arrayList = new ArrayList();
        for (Item item : this.f3917) {
            arrayList.add(C1252.m3340(this.f3918, item.m1915()));
        }
        return arrayList;
    }

    /* renamed from: ʬ  reason: contains not printable characters */
    public C0781 m2312(Item item) {
        String str;
        if (m2318()) {
            int r7 = m2313();
            try {
                str = this.f3918.getResources().getQuantityString(R.plurals.error_over_count, r7, Integer.valueOf(r7));
            } catch (Resources.NotFoundException unused) {
                str = this.f3918.getString(R$string.error_over_count, Integer.valueOf(r7));
            } catch (NoClassDefFoundError unused2) {
                str = this.f3918.getString(R$string.error_over_count, Integer.valueOf(r7));
            }
            return new C0781(str);
        } else if (m2324(item)) {
            return new C0781(this.f3918.getString(R$string.error_type_conflict));
        } else {
            return C0771.m2344(this.f3918, item);
        }
    }

    /* renamed from: 㴹  reason: contains not printable characters */
    public boolean m2324(Item item) {
        int i;
        int i2;
        if (C0778.C0779.f3967.f3954) {
            if (item.m1916() && ((i2 = this.f3916) == 2 || i2 == 3)) {
                return true;
            }
            if (!item.m1913() || ((i = this.f3916) != 1 && i != 3)) {
                return false;
            }
            return true;
        }
        return false;
    }

    /* renamed from: K  reason: contains not printable characters */
    public boolean m2322(Item item) {
        if (!m2324(item)) {
            boolean add = this.f3917.add(item);
            if (add) {
                int i = this.f3916;
                if (i == 0) {
                    if (item.m1916()) {
                        this.f3916 = 1;
                    } else if (item.m1913()) {
                        this.f3916 = 2;
                    }
                } else if (i == 1) {
                    if (item.m1913()) {
                        this.f3916 = 3;
                    }
                } else if (i == 2 && item.m1916()) {
                    this.f3916 = 3;
                }
            }
            return add;
        }
        throw new IllegalArgumentException("Can't select images and videos at the same time.");
    }

    /* renamed from: ῲ  reason: contains not printable characters */
    public int m2315(Item item) {
        int indexOf = new ArrayList(this.f3917).indexOf(item);
        if (indexOf == -1) {
            return Integer.MIN_VALUE;
        }
        return indexOf + 1;
    }

    /* renamed from: ඓ  reason: contains not printable characters */
    public final int m2313() {
        C0778 r0 = C0778.C0779.f3967;
        int i = r0.f3955;
        if (i > 0) {
            return i;
        }
        int i2 = this.f3916;
        if (i2 == 1) {
            return r0.f3964;
        }
        return i2 == 2 ? r0.f3953 : i;
    }

    /* renamed from: K  reason: contains not printable characters */
    public void m2321(ArrayList<Item> arrayList, int i) {
        if (arrayList.size() == 0) {
            this.f3916 = 0;
        } else {
            this.f3916 = i;
        }
        this.f3917.clear();
        this.f3917.addAll(arrayList);
    }

    /* renamed from: K  reason: contains not printable characters */
    public List<Item> m2319() {
        return new ArrayList(this.f3917);
    }
}
