package defpackage;

import android.app.Activity;
import android.app.Application;
import android.content.Context;
import android.content.ContextWrapper;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import androidx.fragment.app.ab;
import androidx.fragment.app.o;
import androidx.fragment.app.t;
import java.util.Iterator;
import java.util.List;

/* JADX INFO: loaded from: classes.dex */
public class d18 implements Handler.Callback {
    public static final b f = new a();
    public volatile a18 a;
    public final b b;
    public final ts c = new ts(0);
    public final qp3 d;
    public final m85 e;

    public class a implements b {
        @Override // d18.b
        public final a18 a(com.bumptech.glide.a aVar, y75 y75Var, e18 e18Var, Context context) {
            return new a18(aVar, y75Var, e18Var, context);
        }
    }

    public interface b {
        a18 a(com.bumptech.glide.a aVar, y75 y75Var, e18 e18Var, Context context);
    }

    public d18() {
        b bVar = f;
        this.b = bVar;
        this.e = new m85(bVar);
        this.d = (xz3.f && xz3.e) ? new e23() : new yd2();
    }

    public static Activity a(Context context) {
        if (context instanceof Activity) {
            return (Activity) context;
        }
        if (context instanceof ContextWrapper) {
            return a(((ContextWrapper) context).getBaseContext());
        }
        return null;
    }

    public static void b(List list, ts tsVar) {
        if (list == null) {
            return;
        }
        Iterator it = list.iterator();
        while (it.hasNext()) {
            o oVar = (o) it.next();
            if (oVar != null && oVar.getView() != null) {
                tsVar.put(oVar.getView(), oVar);
                b(oVar.getChildFragmentManager().ak(), tsVar);
            }
        }
    }

    public final a18 c(Context context) {
        if (context == null) {
            throw new IllegalArgumentException("You cannot start a load on a null Context");
        }
        char[] cArr = hda.a;
        if (Looper.myLooper() == Looper.getMainLooper() && !(context instanceof Application)) {
            if (context instanceof t) {
                return e((t) context);
            }
            if (context instanceof ContextWrapper) {
                ContextWrapper contextWrapper = (ContextWrapper) context;
                if (contextWrapper.getBaseContext().getApplicationContext() != null) {
                    return c(contextWrapper.getBaseContext());
                }
            }
        }
        if (this.a == null) {
            synchronized (this) {
                try {
                    if (this.a == null) {
                        this.a = this.b.a(com.bumptech.glide.a.b(context.getApplicationContext()), new dr(), new nk2(), context.getApplicationContext());
                    }
                } finally {
                }
            }
        }
        return this.a;
    }

    public final a18 d(o oVar) {
        gf7.c(oVar.getContext(), "You cannot start a load on a fragment before it is attached or after it is destroyed");
        char[] cArr = hda.a;
        if (!(Looper.myLooper() == Looper.getMainLooper())) {
            return c(oVar.getContext().getApplicationContext());
        }
        if (oVar.getActivity() != null) {
            this.d.a(oVar.getActivity());
        }
        ab childFragmentManager = oVar.getChildFragmentManager();
        Context context = oVar.getContext();
        return this.e.a(context, com.bumptech.glide.a.b(context.getApplicationContext()), oVar.getLifecycle(), childFragmentManager, oVar.isVisible());
    }

    public final a18 e(t tVar) {
        char[] cArr = hda.a;
        if (!(Looper.myLooper() == Looper.getMainLooper())) {
            return c(tVar.getApplicationContext());
        }
        if (tVar.isDestroyed()) {
            throw new IllegalArgumentException("You cannot start a load for a destroyed activity");
        }
        this.d.a(tVar);
        Activity activityA = a(tVar);
        return this.e.a(tVar, com.bumptech.glide.a.b(tVar.getApplicationContext()), tVar.getLifecycle(), tVar.getSupportFragmentManager(), activityA == null || !activityA.isFinishing());
    }

    @Override // android.os.Handler.Callback
    public final boolean handleMessage(Message message) {
        return false;
    }
}
