package com.tencent.mm.plugin.setting.ui.setting;

import android.content.Context;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView.LayoutParams;
import android.widget.ImageView;
import android.widget.LinearLayout;
import com.tencent.matrix.trace.core.AppMethodBeat;
import com.tencent.mm.ba.a;
import com.tencent.mm.ba.m;
import com.tencent.mm.ba.n;
import com.tencent.mm.ba.r;
import com.tencent.mm.kernel.g;
import com.tencent.mm.sdk.platformtools.bo;
import com.tencent.mm.sdk.platformtools.d;
import com.tencent.mm.ui.p;

class SettingsSelectBgUI$a extends p<m> {
    private Context context;
    private int itemWidth;
    final /* synthetic */ SettingsSelectBgUI qoV;

    public final /* synthetic */ Object a(Object obj, Cursor cursor) {
        AppMethodBeat.i(127479);
        m mVar = (m) obj;
        if (mVar == null) {
            mVar = new m();
        }
        mVar.d(cursor);
        AppMethodBeat.o(127479);
        return mVar;
    }

    public SettingsSelectBgUI$a(SettingsSelectBgUI settingsSelectBgUI, Context context, int i) {
        this.qoV = settingsSelectBgUI;
        super(context, new m());
        AppMethodBeat.i(127474);
        this.context = context;
        this.itemWidth = i;
        AppMethodBeat.o(127474);
    }

    public final int getCount() {
        AppMethodBeat.i(127475);
        int count = getCursor().getCount() + 2;
        AppMethodBeat.o(127475);
        return count;
    }

    public final void KD() {
        AppMethodBeat.i(127476);
        KC();
        AppMethodBeat.o(127476);
    }

    public final void KC() {
        AppMethodBeat.i(127477);
        setCursor(r.aix().ait());
        super.notifyDataSetChanged();
        AppMethodBeat.o(127477);
    }

    public final View getView(int i, View view, ViewGroup viewGroup) {
        b bVar;
        AppMethodBeat.i(127478);
        if (view == null) {
            view = View.inflate(this.context, 2130970643, null);
            view.setLayoutParams(new LayoutParams(this.itemWidth, this.itemWidth));
            b bVar2 = new b();
            bVar2.qqB = (LinearLayout) view.findViewById(2131827419);
            bVar2.qqC = (LinearLayout) view.findViewById(2131827422);
            bVar2.qqD = (LinearLayout) view.findViewById(2131827423);
            bVar2.qqE = (LinearLayout) view.findViewById(2131827424);
            bVar2.qqF = (LinearLayout) view.findViewById(2131827425);
            view.setTag(bVar2);
            bVar = bVar2;
        } else {
            bVar = (b) view.getTag();
        }
        int a = bo.a((Integer) g.RP().Ry().get(12311, null), -2);
        a sU = r.aiy().sU(SettingsSelectBgUI.f(this.qoV));
        if (i == 0) {
            if (!(SettingsSelectBgUI.c(this.qoV) && a == -2) && (!(!SettingsSelectBgUI.c(this.qoV) && a == -2 && sU == null) && (sU == null || sU.fLV != -2))) {
                bVar.WA("downloaded");
            } else {
                bVar.WA("using");
            }
            ((ImageView) view.findViewById(2131827418)).setImageBitmap(d.a(BitmapFactory.decodeResource(this.context.getResources(), 2130838255), true, 10.0f));
            AppMethodBeat.o(127478);
        } else if (i == 1) {
            if (!(SettingsSelectBgUI.c(this.qoV) && a == 0) && (!(!SettingsSelectBgUI.c(this.qoV) && a == 0 && sU == null) && (sU == null || sU.fLV != 0))) {
                bVar.WA("downloaded");
            } else {
                bVar.WA("using");
            }
            ((ImageView) view.findViewById(2131827418)).setImageBitmap(d.a(BitmapFactory.decodeResource(this.context.getResources(), 2130838254), true, 10.0f));
            AppMethodBeat.o(127478);
        } else {
            Bitmap aml;
            m mVar = (m) getItem(i - 2);
            r.aix();
            if (g.RP().isSDCardAvailable()) {
                aml = d.aml(n.aiu() + n.cw(mVar.id, mVar.cBc));
            } else {
                aml = BitmapFactory.decodeResource(this.qoV.getResources(), 2130839708);
            }
            if (aml == null) {
                AppMethodBeat.o(127478);
            } else {
                ((ImageView) view.findViewById(2131827418)).setImageBitmap(d.a(aml, true, 10.0f));
                switch (mVar.status) {
                    case 1:
                        if (!SettingsSelectBgUI.c(this.qoV) && sU != null && sU.fLV != mVar.id) {
                            bVar.WA("downloaded");
                            break;
                        }
                        bVar.WA("using");
                        break;
                        break;
                    case 2:
                        if (!SettingsSelectBgUI.c(this.qoV) && sU != null && sU.fLV == mVar.id) {
                            bVar.WA("using");
                            break;
                        }
                        bVar.WA("downloaded");
                        break;
                        break;
                    case 3:
                        bVar.WA("downloading");
                        break;
                    case 4:
                        bVar.WA("canceling");
                        break;
                    case 5:
                        bVar.WA("undownloaded");
                        break;
                }
                AppMethodBeat.o(127478);
            }
        }
        return view;
    }
}
