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

import android.content.Context;
import android.graphics.Color;
import android.util.AttributeSet;
import android.view.ViewParent;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.tencent.matrix.trace.core.AppMethodBeat;
import com.tencent.mm.at.a.a.c.a;
import com.tencent.mm.at.o;
import com.tencent.mm.plugin.downloader.model.c;
import com.tencent.mm.plugin.downloader_app.b.d;
import com.tencent.mm.plugin.downloader_app.b.h;
import com.tencent.mm.plugin.downloader_app.b.i;
import com.tencent.mm.sdk.platformtools.ab;
import com.tencent.mm.sdk.platformtools.at;
import com.tencent.mm.sdk.platformtools.bo;
import com.tencent.mm.ui.aj;
import com.tencent.ytcommon.BuildConfig;
import java.util.Iterator;

public class TaskItemView extends LinearLayout {
    ProgressBar gHA;
    ImageView kPV;
    private ImageView kQA;
    private Button kQB;
    private RelativeLayout kQC;
    private TextView kQD;
    private LinearLayout kQE;
    private TextView kQF;
    private LinearLayout kQG;
    private ImageView kQH;
    private TextView kQI;
    private LinearLayout kQJ;
    private TextView kQK;
    i kQL;
    boolean kQM = false;
    private boolean kQN = false;
    private AppIconView kQv;
    private TextView kQw;
    private TextView kQx;
    private TextView kQy;
    private FrameLayout kQz;

    static /* synthetic */ void b(TaskItemView taskItemView) {
        AppMethodBeat.i(136280);
        taskItemView.biT();
        AppMethodBeat.o(136280);
    }

    public TaskItemView(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
    }

    /* Access modifiers changed, original: protected */
    public void onFinishInflate() {
        AppMethodBeat.i(136272);
        super.onFinishInflate();
        this.kPV = (ImageView) findViewById(2131823256);
        this.kQv = (AppIconView) findViewById(2131820915);
        this.kQw = (TextView) findViewById(2131823322);
        this.kQx = (TextView) findViewById(2131823323);
        this.kQy = (TextView) findViewById(2131823324);
        this.kQz = (FrameLayout) findViewById(2131823325);
        this.gHA = (ProgressBar) findViewById(2131821099);
        this.gHA.setOnClickListener(new 1(this));
        this.gHA.setSecondaryProgress(100);
        this.kQA = (ImageView) findViewById(2131823326);
        this.kQA.setOnClickListener(new 3(this));
        this.kQB = (Button) findViewById(2131823327);
        this.kQB.setOnClickListener(new 4(this));
        this.kQC = (RelativeLayout) findViewById(2131823328);
        this.kQD = (TextView) findViewById(2131823330);
        this.kQE = (LinearLayout) findViewById(2131823331);
        this.kQF = (TextView) findViewById(2131823332);
        this.kQF.getViewTreeObserver().addOnGlobalLayoutListener(new 5(this));
        this.kQE.setOnClickListener(new 6(this));
        this.kQF.setOnClickListener(new 7(this));
        this.kQG = (LinearLayout) findViewById(2131823333);
        this.kQH = (ImageView) findViewById(2131823334);
        this.kQI = (TextView) findViewById(2131823335);
        this.kQJ = (LinearLayout) findViewById(2131823336);
        this.kQJ.setOnClickListener(new 8(this));
        this.kQK = (TextView) findViewById(2131823337);
        AppMethodBeat.o(136272);
    }

    public void onDetachedFromWindow() {
        AppMethodBeat.i(136273);
        super.onDetachedFromWindow();
        AppMethodBeat.o(136273);
    }

    public void onAttachedToWindow() {
        AppMethodBeat.i(136274);
        super.onAttachedToWindow();
        AppMethodBeat.o(136274);
    }

    public void setSelected(boolean z) {
        AppMethodBeat.i(136275);
        ab.d("MicroMsg.TaskItemView", "setSelected selected: %b, appid: %s", new Object[]{Boolean.valueOf(z), this.kQL.appId});
        this.kQL.gBF = z;
        if (z) {
            this.kPV.setImageResource(2130838331);
        } else {
            this.kPV.setImageResource(2130838332);
        }
        for (ViewParent parent = getParent(); parent != null; parent = parent.getParent()) {
            if (parent instanceof TaskListView) {
                boolean z2;
                TaskListView taskListView = (TaskListView) parent;
                h hVar = taskListView.kQZ.kQR;
                Iterator it = hVar.iterator();
                int i = 0;
                while (it.hasNext()) {
                    i iVar = (i) it.next();
                    if (iVar.biN() && iVar.gBF) {
                        i++;
                    }
                    i = i;
                }
                if (i > 0) {
                    z2 = true;
                } else {
                    z2 = false;
                }
                d.gf(z2);
                if (i != hVar.size() - 3) {
                    ((DownloadMainUI) taskListView.getContext()).gj(false);
                } else if (taskListView.getContext() instanceof DownloadMainUI) {
                    ((DownloadMainUI) taskListView.getContext()).gj(true);
                    AppMethodBeat.o(136275);
                    return;
                }
                AppMethodBeat.o(136275);
                return;
            }
        }
        AppMethodBeat.o(136275);
    }

    public void setData(i iVar) {
        AppMethodBeat.i(136276);
        this.kQL = iVar;
        if (iVar == null) {
            setVisibility(8);
            AppMethodBeat.o(136276);
            return;
        }
        setVisibility(0);
        this.kQz.setVisibility(8);
        this.kQB.setVisibility(8);
        this.kQC.setVisibility(8);
        this.kQG.setVisibility(8);
        new a().ePH = true;
        o.ahp().a(this.kQL.iconUrl, this.kQv);
        this.kQw.setText(this.kQL.appName);
        com.tencent.mm.plugin.downloader.f.a In = c.In(this.kQL.appId);
        if (In == null || !In.field_autoDownload) {
            this.kQx.setVisibility(8);
        } else {
            this.kQx.setVisibility(0);
        }
        if (this.kQL.kci) {
            if (this.kPV.getVisibility() != 0) {
                this.kPV.setVisibility(0);
                this.kPV.startAnimation(AnimationUtils.loadAnimation(getContext(), 2131034244));
            }
            setSelected(this.kQL.gBF);
            H(this.kQL.kPc.kKP, this.kQL.kPc.kKP);
            AppMethodBeat.o(136276);
            return;
        }
        this.kPV.setVisibility(8);
        if (this.kQL.kPe != null) {
            LayoutParams layoutParams = (LayoutParams) this.kQG.getLayoutParams();
            if (this.kQL.kci) {
                layoutParams.leftMargin = aj.fromDPToPix(getContext(), 114);
            } else {
                layoutParams.leftMargin = aj.fromDPToPix(getContext(), 78);
            }
            this.kQG.setLayoutParams(layoutParams);
            this.kQG.setVisibility(0);
            new a().ePH = true;
            o.ahp().a(this.kQL.kPe.cIY, this.kQH);
            if (this.kQL.kPe.kKL != null) {
                this.kQI.setText(this.kQL.kPe.kKL.value);
                try {
                    this.kQI.setTextColor(Color.parseColor(this.kQL.kPe.kKL.color));
                } catch (Exception e) {
                }
            }
            if (this.kQL.kPe.kKM != null) {
                this.kQJ.setVisibility(0);
                this.kQK.setText(this.kQL.kPe.kKM.value);
                try {
                    this.kQK.setTextColor(Color.parseColor(this.kQL.kPe.kKM.color));
                } catch (Exception e2) {
                }
            } else {
                this.kQJ.setVisibility(8);
            }
            if (!this.kQL.kOZ) {
                this.kQL.kOZ = true;
                com.tencent.mm.plugin.downloader_app.c.a.a(10, 1006, this.kQL.position, 1, this.kQL.appId, BuildConfig.FLAVOR, BuildConfig.FLAVOR);
            }
        } else {
            this.kQG.setVisibility(8);
        }
        H(this.kQL.kPc.kKP, this.kQL.kPc.kKP);
        if (this.kQL.type == 4) {
            In = c.In(this.kQL.appId);
            if (In == null || In.field_status == 0 || In.field_status == 5) {
                this.kQz.setVisibility(8);
                this.kQB.setVisibility(0);
                this.kQB.setText(getContext().getResources().getString(2131304173));
                if (!bo.isNullOrNil(this.kQL.kPa)) {
                    this.kQC.setVisibility(0);
                    this.kQD.setText(this.kQL.kPa);
                    this.kQD.setMaxLines(2);
                    AppMethodBeat.o(136276);
                    return;
                }
            }
            biT();
            AppMethodBeat.o(136276);
        } else if (this.kQL.type == 6) {
            this.kQz.setVisibility(8);
            this.kQB.setVisibility(0);
            this.kQB.setText(getContext().getResources().getString(2131300935));
            AppMethodBeat.o(136276);
        } else {
            biT();
            AppMethodBeat.o(136276);
        }
    }

    /* Access modifiers changed, original: final */
    public final void biT() {
        AppMethodBeat.i(136277);
        ab.d("MicroMsg.TaskItemView", "updateDownloadStatus: %s", new Object[]{this.kQL.appId});
        this.gHA.setIndeterminate(false);
        com.tencent.mm.plugin.downloader.f.a In = c.In(this.kQL.appId);
        if (In == null || In.field_status == 5) {
            H(this.kQL.kPc.kKP, this.kQL.kPc.kKP);
            this.kQz.setVisibility(0);
            this.gHA.setIndeterminate(true);
            this.kQA.setVisibility(8);
            this.kQB.setVisibility(8);
            AppMethodBeat.o(136277);
            return;
        }
        H(In.field_downloadedSize, this.kQL.kPc.kKP);
        if (In.field_status == 3) {
            this.kQz.setVisibility(8);
            this.kQB.setText(2131300623);
            this.kQB.setVisibility(0);
            AppMethodBeat.o(136277);
        } else if (In.field_status == 6) {
            this.kQz.setVisibility(8);
            this.kQB.setText(getResources().getString(2131301418));
            this.kQB.setVisibility(0);
            AppMethodBeat.o(136277);
        } else {
            this.kQz.setVisibility(0);
            this.gHA.setVisibility(0);
            this.kQB.setVisibility(8);
            if (this.kQM) {
                this.kQA.setVisibility(8);
                this.gHA.setIndeterminate(true);
                AppMethodBeat.o(136277);
            } else if (In.field_status == 1) {
                this.kQM = false;
                this.kQA.setImageResource(2130840420);
                this.kQA.setVisibility(0);
                AppMethodBeat.o(136277);
            } else if (In.field_reserveInWifi && !at.isWifi(getContext())) {
                this.kQz.setVisibility(8);
                this.kQB.setText(2131304503);
                this.kQB.setVisibility(0);
                AppMethodBeat.o(136277);
            } else if (In.field_status == 4) {
                this.kQz.setVisibility(8);
                this.kQB.setText(2131298932);
                this.kQB.setVisibility(0);
                AppMethodBeat.o(136277);
            } else {
                this.kQA.setImageResource(2130840419);
                this.kQA.setVisibility(0);
                AppMethodBeat.o(136277);
            }
        }
    }

    private void H(long j, long j2) {
        AppMethodBeat.i(136278);
        float f = ((float) j2) / 1.07374182E9f;
        float f2 = ((float) j2) / 1048576.0f;
        if (j < j2) {
            f = ((float) j) / 1048576.0f;
            this.kQy.setText(String.format("%.1fMB / %.1fMB", new Object[]{Float.valueOf(f), Float.valueOf(f2)}));
            final int i = (int) ((100 * j) / j2);
            post(new Runnable() {
                public final void run() {
                    AppMethodBeat.i(136270);
                    TaskItemView.this.gHA.setSecondaryProgress(100);
                    TaskItemView.this.gHA.setProgress(i);
                    AppMethodBeat.o(136270);
                }
            });
            AppMethodBeat.o(136278);
        } else if (f >= 1.0f) {
            this.kQy.setText(String.format("%.1fGB", new Object[]{Float.valueOf(f)}));
            AppMethodBeat.o(136278);
        } else {
            this.kQy.setText(String.format("%.1fMB", new Object[]{Float.valueOf(f2)}));
            AppMethodBeat.o(136278);
        }
    }

    public int getNamePaddingLeft() {
        AppMethodBeat.i(136279);
        int dimensionPixelSize;
        if (this.kPV.getVisibility() == 0) {
            dimensionPixelSize = getResources().getDimensionPixelSize(2131428228);
            AppMethodBeat.o(136279);
            return dimensionPixelSize;
        }
        dimensionPixelSize = getResources().getDimensionPixelSize(2131428227);
        AppMethodBeat.o(136279);
        return dimensionPixelSize;
    }
}
