package com.tencent.mm.plugin.downloader.model;

import android.content.Intent;
import com.tencent.matrix.trace.core.AppMethodBeat;
import com.tencent.mm.bp.d;
import com.tencent.mm.plugin.cdndownloader.d.b;
import com.tencent.mm.plugin.downloader.f.a;
import com.tencent.mm.plugin.report.service.h;
import com.tencent.mm.sdk.platformtools.ab;
import com.tencent.mm.sdk.platformtools.ah;
import com.tencent.mm.sdk.platformtools.at;
import com.tencent.mm.sdk.platformtools.bo;

class a$1 implements b {
    final /* synthetic */ a kME;

    a$1(a aVar) {
        this.kME = aVar;
    }

    public final void f(String str, int i, int i2, String str2) {
        AppMethodBeat.i(2354);
        a Iq = c.Iq(str);
        if (Iq == null) {
            h.pYm.a(710, 18, 1, false);
            ab.i("MicroMsg.FileCDNDownloader", "onDownloadTaskStateChanged, info is null");
            AppMethodBeat.o(2354);
            return;
        }
        ab.i("MicroMsg.FileCDNDownloader", "onDownloadTaskStateChanged, url = %s, state = %d, errCode = %d, errMsg = %s", new Object[]{str, Integer.valueOf(i), Integer.valueOf(i2), str2});
        switch (i) {
            case 1:
                Iq.field_status = 1;
                c.e(Iq);
                AppMethodBeat.o(2354);
                return;
            case 3:
                Iq.field_finishTime = System.currentTimeMillis();
                Iq.field_downloadedSize = Iq.field_totalSize;
                Iq.field_status = 6;
                ab.i("MicroMsg.FileCDNDownloader", "download succeed, downloadedSize = %d, startSize = %d", new Object[]{Long.valueOf(Iq.field_downloadedSize), Long.valueOf(Iq.field_startSize)});
                c.e(Iq);
                this.kME.kMT.hu(Iq.field_downloadId);
                Intent intent = new Intent();
                intent.putExtra(FileDownloadService.kNn, 1);
                intent.setClass(a.c(this.kME), FileDownloadService.class);
                intent.putExtra(FileDownloadService.EXTRA_ID, Iq.field_downloadId);
                try {
                    d.aH(intent);
                } catch (Exception e) {
                    ab.e("MicroMsg.FileCDNDownloader", e.getMessage());
                }
                a.a(this.kME, Iq.field_downloadUrl);
                a.a(this.kME).remove(Iq.field_downloadUrl);
                a.b(this.kME).remove(Iq.field_downloadUrl);
                break;
            case 4:
                Iq.field_finishTime = System.currentTimeMillis();
                Iq.field_errCode = Math.abs(i2);
                Iq.field_status = 4;
                if (at.isWifi(ah.getContext()) && Iq.field_downloadInWifi) {
                    Iq.field_downloadInWifi = false;
                    Iq.field_reserveInWifi = false;
                }
                c.e(Iq);
                this.kME.kMT.d(Iq.field_downloadId, Math.abs(i2), false);
                a.a(this.kME, Iq.field_downloadUrl, 4, 0, false);
                a.a(this.kME).remove(Iq.field_downloadUrl);
                a.b(this.kME).remove(Iq.field_downloadUrl);
                AppMethodBeat.o(2354);
                return;
        }
        AppMethodBeat.o(2354);
    }

    public final void m(String str, long j, long j2) {
        AppMethodBeat.i(2355);
        ab.d("MicroMsg.FileCDNDownloader", "onDownloadTaskProgressChanged, totalDataLen = %d, receiveDataLen = %d", new Object[]{Long.valueOf(j2), Long.valueOf(j)});
        a Iq = c.Iq(str);
        if (Iq == null) {
            ab.i("MicroMsg.FileCDNDownloader", "onDownloadTaskProgressChanged, info is null");
            AppMethodBeat.o(2355);
            return;
        }
        long a;
        if (Iq.field_downloadInWifi && !at.isWifi(ah.getContext())) {
            this.kME.hq(Iq.field_downloadId);
        }
        Long valueOf = Long.valueOf(bo.c((Long) a.a(this.kME).get(Iq.field_downloadUrl)));
        if (valueOf.longValue() == 0) {
            valueOf = Long.valueOf(j);
            a.a(this.kME).put(Iq.field_downloadUrl, Long.valueOf(j));
        }
        long longValue = j - valueOf.longValue();
        if (j2 == 0) {
            ab.i("MicroMsg.FileCDNDownloader", "onDownloadTaskProgressChanged, totalDataLen = 0");
        } else {
            int i = (int) ((((float) j) / ((float) j2)) * 100.0f);
            if ((100 * longValue) / j2 >= 1) {
                a = bo.a((Long) a.b(this.kME).get(Iq.field_downloadUrl), Iq.field_startTime);
                long currentTimeMillis = System.currentTimeMillis();
                float f = ((((float) longValue) * 1000.0f) / ((float) (currentTimeMillis - a))) / 1048576.0f;
                ab.d("MicroMsg.FileCDNDownloader", "downloadSpeed, appId = %s, speed = %f, period = %d, downloadedSize = %d, totalSize = %d, totalPercent = %d", new Object[]{Iq.field_appId, Float.valueOf(f), Long.valueOf(currentTimeMillis - a), Long.valueOf(longValue), Long.valueOf(j2), Integer.valueOf(i)});
                com.tencent.mm.plugin.downloader.h.b.a(Iq.field_downloadId, f, i);
                a.b(this.kME).put(Iq.field_downloadUrl, Long.valueOf(currentTimeMillis));
                a.a(this.kME).put(Iq.field_downloadUrl, Long.valueOf(j));
            }
        }
        valueOf = Long.valueOf(bo.c((Long) a.d(this.kME).get(Iq.field_downloadUrl)));
        Long valueOf2 = Long.valueOf(System.currentTimeMillis());
        a = valueOf2.longValue() - valueOf.longValue();
        if (valueOf == null || a <= 0 || a >= 500) {
            a.d(this.kME).put(Iq.field_downloadUrl, valueOf2);
            Iq.field_downloadedSize = j;
            Iq.field_totalSize = j2;
            c.e(Iq);
            this.kME.kMT.ht(Iq.field_downloadId);
            int i2 = 0;
            if (j2 > 0) {
                i2 = (int) ((((float) j) / ((float) j2)) * 100.0f);
            }
            if (i2 < 0) {
                i2 = 0;
            } else if (i2 > 100) {
                i2 = 100;
            }
            a.a(this.kME, Iq.field_downloadUrl, 1, i2, false);
            AppMethodBeat.o(2355);
            return;
        }
        AppMethodBeat.o(2355);
    }
}
