package b8;

import android.content.Context;
import android.view.View;
import android.view.ViewTreeObserver;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.MapStyleOptions;
import h7.k;
import kotlin.jvm.internal.t;

/* loaded from: classes.dex */
public final class a implements ViewTreeObserver.OnGlobalLayoutListener, OnMapReadyCallback {

    /* renamed from: p, reason: collision with root package name */
    private final SupportMapFragment f6766p;

    /* renamed from: q, reason: collision with root package name */
    private final InterfaceC0176a f6767q;

    /* renamed from: r, reason: collision with root package name */
    private final Context f6768r;

    /* renamed from: s, reason: collision with root package name */
    private final View f6769s;

    /* renamed from: t, reason: collision with root package name */
    private boolean f6770t;

    /* renamed from: u, reason: collision with root package name */
    private boolean f6771u;

    /* renamed from: v, reason: collision with root package name */
    private GoogleMap f6772v;

    /* renamed from: b8.a$a, reason: collision with other inner class name */
    /* loaded from: classes.dex */
    public interface InterfaceC0176a {
        void onMapReady(GoogleMap googleMap);
    }

    public a(SupportMapFragment mapFragment, InterfaceC0176a toBeNotified, Context context) {
        t.g(mapFragment, "mapFragment");
        t.g(toBeNotified, "toBeNotified");
        t.g(context, "context");
        this.f6766p = mapFragment;
        this.f6767q = toBeNotified;
        this.f6768r = context;
        this.f6769s = mapFragment.getView();
        b();
    }

    private final void a() {
        if (this.f6770t && this.f6771u) {
            GoogleMap googleMap = this.f6772v;
            if (googleMap != null) {
                googleMap.setMapStyle(MapStyleOptions.loadRawResourceStyle(this.f6768r, k.f21112a));
            }
            this.f6767q.onMapReady(this.f6772v);
        }
    }

    private final void b() {
        View view = this.f6769s;
        boolean z10 = false;
        if (!(view != null && view.getWidth() == 0)) {
            View view2 = this.f6769s;
            if (view2 != null && view2.getHeight() == 0) {
                z10 = true;
            }
            if (!z10) {
                this.f6770t = true;
                this.f6766p.getMapAsync(this);
            }
        }
        this.f6769s.getViewTreeObserver().addOnGlobalLayoutListener(this);
        this.f6766p.getMapAsync(this);
    }

    @Override // android.view.ViewTreeObserver.OnGlobalLayoutListener
    public void onGlobalLayout() {
        ViewTreeObserver viewTreeObserver;
        View view = this.f6769s;
        if (view != null && (viewTreeObserver = view.getViewTreeObserver()) != null) {
            viewTreeObserver.removeOnGlobalLayoutListener(this);
        }
        this.f6770t = true;
        a();
    }

    @Override // com.google.android.gms.maps.OnMapReadyCallback
    public void onMapReady(GoogleMap googleMap) {
        t.g(googleMap, "googleMap");
        this.f6772v = googleMap;
        this.f6771u = true;
        a();
    }
}
