package c.b.f;

import android.content.Context;
import android.content.res.ColorStateList;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.View;
import c.f.j.a0;
import java.util.WeakHashMap;

/* JADX INFO: compiled from: AppCompatBackgroundHelper.java */
/* JADX INFO: loaded from: classes.dex */
public class g {
    public final View a;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public b1 f840d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public b1 f841e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public b1 f842f;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public int f839c = -1;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final m f838b = m.a();

    public g(View view) {
        this.a = view;
    }

    public void a() {
        Drawable background = this.a.getBackground();
        if (background != null) {
            boolean z = true;
            if (this.f840d != null) {
                if (this.f842f == null) {
                    this.f842f = new b1();
                }
                b1 b1Var = this.f842f;
                b1Var.a = null;
                b1Var.f779d = false;
                b1Var.f777b = null;
                b1Var.f778c = false;
                View view = this.a;
                WeakHashMap<View, c.f.j.i0> weakHashMap = c.f.j.a0.a;
                ColorStateList colorStateListG = a0.h.g(view);
                if (colorStateListG != null) {
                    b1Var.f779d = true;
                    b1Var.a = colorStateListG;
                }
                PorterDuff.Mode modeH = a0.h.h(this.a);
                if (modeH != null) {
                    b1Var.f778c = true;
                    b1Var.f777b = modeH;
                }
                if (b1Var.f779d || b1Var.f778c) {
                    m.e(background, b1Var, this.a.getDrawableState());
                } else {
                    z = false;
                }
                if (z) {
                    return;
                }
            }
            b1 b1Var2 = this.f841e;
            if (b1Var2 != null) {
                m.e(background, b1Var2, this.a.getDrawableState());
                return;
            }
            b1 b1Var3 = this.f840d;
            if (b1Var3 != null) {
                m.e(background, b1Var3, this.a.getDrawableState());
            }
        }
    }

    public ColorStateList b() {
        b1 b1Var = this.f841e;
        if (b1Var != null) {
            return b1Var.a;
        }
        return null;
    }

    public PorterDuff.Mode c() {
        b1 b1Var = this.f841e;
        if (b1Var != null) {
            return b1Var.f777b;
        }
        return null;
    }

    public void d(AttributeSet attributeSet, int i2) {
        Context context = this.a.getContext();
        int[] iArr = c.b.b.z;
        d1 d1VarO = d1.o(context, attributeSet, iArr, i2, 0);
        View view = this.a;
        c.f.j.a0.k(view, view.getContext(), iArr, attributeSet, d1VarO.f806b, i2, 0);
        try {
            if (d1VarO.m(0)) {
                this.f839c = d1VarO.j(0, -1);
                ColorStateList colorStateListC = this.f838b.c(this.a.getContext(), this.f839c);
                if (colorStateListC != null) {
                    g(colorStateListC);
                }
            }
            if (d1VarO.m(1)) {
                a0.h.q(this.a, d1VarO.b(1));
            }
            if (d1VarO.m(2)) {
                a0.h.r(this.a, k0.c(d1VarO.h(2, -1), null));
            }
            d1VarO.f806b.recycle();
        } catch (Throwable th) {
            d1VarO.f806b.recycle();
            throw th;
        }
    }

    public void e() {
        this.f839c = -1;
        g(null);
        a();
    }

    public void f(int i2) {
        this.f839c = i2;
        m mVar = this.f838b;
        g(mVar != null ? mVar.c(this.a.getContext(), i2) : null);
        a();
    }

    public void g(ColorStateList colorStateList) {
        if (colorStateList != null) {
            if (this.f840d == null) {
                this.f840d = new b1();
            }
            b1 b1Var = this.f840d;
            b1Var.a = colorStateList;
            b1Var.f779d = true;
        } else {
            this.f840d = null;
        }
        a();
    }

    public void h(ColorStateList colorStateList) {
        if (this.f841e == null) {
            this.f841e = new b1();
        }
        b1 b1Var = this.f841e;
        b1Var.a = colorStateList;
        b1Var.f779d = true;
        a();
    }

    public void i(PorterDuff.Mode mode) {
        if (this.f841e == null) {
            this.f841e = new b1();
        }
        b1 b1Var = this.f841e;
        b1Var.f777b = mode;
        b1Var.f778c = true;
        a();
    }
}
