package com.squareup.picasso; import android.content.Context; import android.graphics.Bitmap; import android.net.Uri; import android.os.Handler; import android.os.Looper; import android.os.Message; import android.os.Process; import android.view.ViewTreeObserver; import android.widget.ImageView; import java.lang.ref.Reference; import java.lang.ref.ReferenceQueue; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Map; import java.util.WeakHashMap; import java.util.concurrent.ExecutorService; import o.AbstractC12987fNZ; import o.AbstractC13013fNz; import o.C13012fNy; import o.C13020fOa; import o.C13021fOb; import o.C13022fOc; import o.C13025fOf; import o.EnumC12984fNP; import o.RunnableC13011fNx; import o.fNB; import o.fNC; import o.fND; import o.fNG; import o.fNH; import o.fNI; import o.fNJ; import o.fNK; import o.fNN; import o.fNT; import o.fNU; import o.fNV; import o.fNW; import o.fNX; /* loaded from: classes.dex */ public class Picasso { public static final Handler d = new Handler(Looper.getMainLooper()) { // from class: com.squareup.picasso.Picasso.5 @Override // android.os.Handler public final void handleMessage(Message message) { int i = message.what; if (i == 3) { AbstractC13013fNz abstractC13013fNz = (AbstractC13013fNz) message.obj; if (abstractC13013fNz.h.f) { C13025fOf.d("Main", "canceled", abstractC13013fNz.g.c(), "target got garbage collected"); } Picasso picasso = abstractC13013fNz.h; Reference reference = abstractC13013fNz.n; picasso.e(reference != null ? reference.get() : null); return; } if (i != 8) { if (i == 13) { List list = (List) message.obj; int size = list.size(); for (int i2 = 0; i2 < size; i2++) { AbstractC13013fNz abstractC13013fNz2 = (AbstractC13013fNz) list.get(i2); Picasso picasso2 = abstractC13013fNz2.h; Bitmap aBo_ = EnumC12984fNP.e(abstractC13013fNz2.e) ? picasso2.aBo_(abstractC13013fNz2.c) : null; if (aBo_ != null) { picasso2.aBn_(aBo_, HBt.MEMORY, abstractC13013fNz2, null); if (picasso2.f) { String c = abstractC13013fNz2.g.c(); StringBuilder sb = new StringBuilder("from "); sb.append(HBt.MEMORY); C13025fOf.d("Main", "completed", c, sb.toString()); } } else { picasso2.a(abstractC13013fNz2); if (picasso2.f) { C13025fOf.d("Main", "resumed", abstractC13013fNz2.g.c()); } } } return; } StringBuilder sb2 = new StringBuilder("Unknown handler message received: "); sb2.append(message.what); throw new AssertionError(sb2.toString()); } List list2 = (List) message.obj; int size2 = list2.size(); for (int i3 = 0; i3 < size2; i3++) { RunnableC13011fNx runnableC13011fNx = (RunnableC13011fNx) list2.get(i3); Picasso picasso3 = runnableC13011fNx.j; AbstractC13013fNz abstractC13013fNz3 = runnableC13011fNx.e; List list3 = runnableC13011fNx.a; boolean z = (list3 == null || list3.isEmpty()) ? false : true; if (abstractC13013fNz3 != null || z) { Uri uri = runnableC13011fNx.c.r; Exception exc = runnableC13011fNx.d; Bitmap bitmap = runnableC13011fNx.m; HBt hBt = runnableC13011fNx.g; if (abstractC13013fNz3 != null) { picasso3.aBn_(bitmap, hBt, abstractC13013fNz3, exc); } if (z) { int size3 = list3.size(); for (int i4 = 0; i4 < size3; i4++) { picasso3.aBn_(bitmap, hBt, list3.get(i4), exc); } } Sts sts = picasso3.i; if (sts != null && exc != null) { sts.b(); } } } } }; private static volatile Picasso k = null; public final fNH a; public final fNB b; public final Context c; public final Bitmap.Config e; public volatile boolean f; public final ReferenceQueue g; public final List h; final Sts i; public boolean j; public Map l; public final tOB m; public boolean n; /* renamed from: o, reason: collision with root package name */ public final C13022fOc f8088o; private Map q; private final IeS t; /* loaded from: classes.dex */ public enum LWm { LOW, NORMAL, HIGH } /* loaded from: classes.dex */ public interface Sts { void b(); } /* loaded from: classes.dex */ public interface tOB { public static final tOB c = new tOB() { // from class: com.squareup.picasso.Picasso.tOB.3 @Override // com.squareup.picasso.Picasso.tOB public final fNW b(fNW fnw) { return fnw; } }; fNW b(fNW fnw); } Picasso(Context context, fNH fnh, fNB fnb, Sts sts, tOB tob, List list, C13022fOc c13022fOc, Bitmap.Config config, boolean z, boolean z2) { this.c = context; this.a = fnh; this.b = fnb; this.i = sts; this.m = tob; this.e = config; ArrayList arrayList = new ArrayList((list != null ? list.size() : 0) + 7); arrayList.add(new C13021fOb(context)); if (list != null) { arrayList.addAll(list); } arrayList.add(new fNG(context)); arrayList.add(new fNT(context)); arrayList.add(new fND(context)); arrayList.add(new C13012fNy(context)); arrayList.add(new fNK(context)); arrayList.add(new fNN(fnh.c, c13022fOc)); this.h = Collections.unmodifiableList(arrayList); this.f8088o = c13022fOc; this.q = new WeakHashMap(); this.l = new WeakHashMap(); this.j = z; this.f = z2; ReferenceQueue referenceQueue = new ReferenceQueue<>(); this.g = referenceQueue; IeS ieS = new IeS(referenceQueue, d); this.t = ieS; ieS.start(); } public final C13020fOa e(String str) { if (str == null) { return new C13020fOa(this, null, 0); } if (str.trim().length() == 0) { throw new IllegalArgumentException("Path must not be empty."); } return new C13020fOa(this, Uri.parse(str), 0); } public final void a(AbstractC13013fNz abstractC13013fNz) { Reference reference = abstractC13013fNz.n; Object obj = reference == null ? null : reference.get(); if (obj != null && this.q.get(obj) != abstractC13013fNz) { e(obj); this.q.put(obj, abstractC13013fNz); } Handler handler = this.a.g; handler.sendMessage(handler.obtainMessage(1, abstractC13013fNz)); } public final Bitmap aBo_(String str) { Bitmap aBj_ = this.b.aBj_(str); if (aBj_ != null) { this.f8088o.i.sendEmptyMessage(0); } else { this.f8088o.i.sendEmptyMessage(1); } return aBj_; } public final void e(Object obj) { C13025fOf.b(); AbstractC13013fNz remove = this.q.remove(obj); if (remove != null) { remove.d(); Handler handler = this.a.g; handler.sendMessage(handler.obtainMessage(2, remove)); } if (obj instanceof ImageView) { fNC remove2 = this.l.remove((ImageView) obj); if (remove2 != null) { remove2.c.d = null; remove2.b = null; ImageView imageView = remove2.e.get(); if (imageView != null) { remove2.e.clear(); imageView.removeOnAttachStateChangeListener(remove2); ViewTreeObserver viewTreeObserver = imageView.getViewTreeObserver(); if (viewTreeObserver.isAlive()) { viewTreeObserver.removeOnPreDrawListener(remove2); } } } } } /* loaded from: classes.dex */ static class IeS extends Thread { private final ReferenceQueue c; private final Handler d; IeS(ReferenceQueue referenceQueue, Handler handler) { this.c = referenceQueue; this.d = handler; setDaemon(true); setName("Picasso-refQueue"); } @Override // java.lang.Thread, java.lang.Runnable public final void run() { Process.setThreadPriority(10); while (true) { try { AbstractC13013fNz.Sts sts = (AbstractC13013fNz.Sts) this.c.remove(1000L); Message obtainMessage = this.d.obtainMessage(); if (sts != null) { obtainMessage.what = 3; obtainMessage.obj = sts.b; this.d.sendMessage(obtainMessage); } else { obtainMessage.recycle(); } } catch (InterruptedException unused) { return; } catch (Exception e) { this.d.post(new Runnable(this, e) { // from class: com.squareup.picasso.Picasso.IeS.1 private Exception b; private IeS d; { this.d = this; this.b = e; } @Override // java.lang.Runnable public final void run() { throw new RuntimeException(this.b); } }); return; } } } } public static Picasso d() { if (k == null) { synchronized (Picasso.class) { if (k == null) { if (fNX.e == null) { throw new IllegalStateException("context == null"); } k = new RVV(fNX.e).a(); } } } return k; } /* loaded from: classes.dex */ public static class RVV { private fNB a; private boolean b; private final Context c; public fNJ d; private Bitmap.Config e; private boolean f; private tOB g; private Sts h; private List i; private ExecutorService j; public RVV(Context context) { if (context == null) { throw new IllegalArgumentException("Context must not be null."); } this.c = context.getApplicationContext(); } public final RVV c(Sts sts) { if (sts == null) { throw new IllegalArgumentException("Listener must not be null."); } if (this.h != null) { throw new IllegalStateException("Listener already set."); } this.h = sts; return this; } public final RVV d(AbstractC12987fNZ abstractC12987fNZ) { if (this.i == null) { this.i = new ArrayList(); } if (this.i.contains(abstractC12987fNZ)) { throw new IllegalStateException("RequestHandler already registered."); } this.i.add(abstractC12987fNZ); return this; } public final Picasso a() { Context context = this.c; if (this.d == null) { this.d = new fNV(context); } if (this.a == null) { this.a = new fNI(context); } if (this.j == null) { this.j = new fNU(); } if (this.g == null) { this.g = tOB.c; } C13022fOc c13022fOc = new C13022fOc(this.a); return new Picasso(context, new fNH(context, this.j, Picasso.d, this.d, this.a, c13022fOc), this.a, this.h, this.g, this.i, c13022fOc, this.e, this.b, this.f); } } /* loaded from: classes.dex */ public enum HBt { MEMORY(-16711936), DISK(-16776961), NETWORK(-65536); public final int debugColor; HBt(int i) { this.debugColor = i; } } final void aBn_(Bitmap bitmap, HBt hBt, AbstractC13013fNz abstractC13013fNz, Exception exc) { if (abstractC13013fNz.a) { return; } if (!abstractC13013fNz.l) { Map map = this.q; Reference reference = abstractC13013fNz.n; map.remove(reference == null ? null : reference.get()); } if (bitmap == null) { abstractC13013fNz.a(exc); if (this.f) { C13025fOf.d("Main", "errored", abstractC13013fNz.g.c(), exc.getMessage()); return; } return; } if (hBt == null) { throw new AssertionError("LoadedFrom cannot be null."); } abstractC13013fNz.aBD_(bitmap, hBt); if (this.f) { C13025fOf.d("Main", "completed", abstractC13013fNz.g.c(), "from ".concat(String.valueOf(hBt))); } } }