package com.duoyou.task.pro.c; import android.app.Notification; import android.app.NotificationChannel; import android.app.NotificationManager; import android.app.PendingIntent; import android.content.Context; import android.content.Intent; import android.content.pm.PackageManager; import android.graphics.Bitmap; import android.graphics.drawable.BitmapDrawable; import android.os.Build; import android.text.TextUtils; import android.util.Log; import android.widget.RemoteViews; import androidx.core.app.NotificationCompat; import com.bytedance.sdk.openadsdk.downloadnew.core.TTDownloadField; import com.duoyou.task.pro.g.e; import com.duoyou.task.pro.g.f; import com.duoyou.task.sdk.R; import com.duoyou.task.sdk.download.DownloadReceiver; import com.duoyou.task.sdk.xutils.common.Callback; import com.duoyou.task.sdk.xutils.http.RequestParams; import com.duoyou.task.sdk.xutils.x; import java.io.File; import java.util.HashMap; import java.util.Map; import java.util.concurrent.Executor; import java.util.concurrent.Executors; public class a { public static a f; public Executor a; public Map<String, c> b = new HashMap(); public Map<String, Callback.Cancelable> c = new HashMap(); public Map<String, Integer> d = new HashMap(); public Map<String, String> e = new HashMap(); public static a a() { if (f == null) { synchronized (a.class) { if (f == null) { f = new a(); } } } return f; } /* JADX WARNING: Code restructure failed: missing block: B:11:0x0061, code lost: r6 = null; */ /* JADX WARNING: Exception block dominator not found, dom blocks: [] */ /* JADX WARNING: Removed duplicated region for block: B:26:0x0116 */ /* JADX WARNING: Removed duplicated region for block: B:29:0x012c */ /* JADX WARNING: Removed duplicated region for block: B:30:0x013b */ public static void a(a aVar, Context context, b bVar) { Bitmap bitmap; int i; int i2; String str; aVar.getClass(); try { Intent intent = new Intent(context, DownloadReceiver.class); intent.setAction("com.duoyou.action.NOTIFICATION_CLICK"); intent.putExtra(TTDownloadField.TT_DOWNLOAD_URL, bVar.a); intent.putExtra("packageName", bVar.b); intent.putExtra("downloadStatus", bVar.g); PendingIntent broadcast = PendingIntent.getBroadcast(context, 100, intent, 134217728); NotificationManager notificationManager = (NotificationManager) context.getSystemService("notification"); RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.dy_notification_layout); synchronized (com.duoyou.task.pro.b.a.class) { PackageManager packageManager = context.getApplicationContext().getPackageManager(); bitmap = ((BitmapDrawable) packageManager.getApplicationIcon(packageManager.getApplicationInfo(context.getPackageName(), 0))).getBitmap(); } remoteViews.setTextViewText(R.id.name_tv, bVar.b); remoteViews.setImageViewBitmap(R.id.dy_icon_iv, bitmap); int i3 = bVar.g; if (i3 == 2) { remoteViews.setViewVisibility(R.id.dy_progress_bar_layout, 8); remoteViews.setViewVisibility(R.id.dy_status_tv, 0); i2 = R.id.dy_status_tv; str = "点击安装"; } else if (i3 == 3) { remoteViews.setViewVisibility(R.id.dy_progress_bar_layout, 8); remoteViews.setViewVisibility(R.id.dy_status_tv, 0); i2 = R.id.dy_status_tv; str = "下载失败,点击重试"; } else if (i3 == 3) { remoteViews.setViewVisibility(R.id.dy_progress_bar_layout, 8); remoteViews.setViewVisibility(R.id.dy_status_tv, 0); i2 = R.id.dy_status_tv; str = "继续下载"; } else { remoteViews.setViewVisibility(R.id.dy_status_tv, 8); remoteViews.setViewVisibility(R.id.dy_progress_bar_layout, 0); remoteViews.setTextViewText(R.id.dy_speed_tv, bVar.c); remoteViews.setTextViewText(R.id.dy_current_length_tv, String.format("%s/%s", com.duoyou.task.pro.b.a.a(bVar.d), com.duoyou.task.pro.b.a.a(bVar.e))); remoteViews.setProgressBar(R.id.dy_progress_bar, 100, bVar.f, false); Notification build = new NotificationCompat.Builder(context, "douyou").setSmallIcon(R.drawable.dy_small_icon).setWhen(System.currentTimeMillis()).setAutoCancel(true).setTicker(bVar.b).setDefaults(8).setContentIntent(broadcast).setContent(remoteViews).build(); if (Build.VERSION.SDK_INT >= 26) { notificationManager.createNotificationChannel(new NotificationChannel("douyou", bVar.b, 2)); } if (!aVar.d.containsKey(bVar.b)) { i = aVar.d.get(bVar.b).intValue(); } else { int size = aVar.d.size() + 1; aVar.d.put(bVar.b, Integer.valueOf(size)); i = size; } notificationManager.notify(i, build); } remoteViews.setTextViewText(i2, str); remoteViews.setProgressBar(R.id.dy_progress_bar, 100, bVar.f, false); Notification build2 = new NotificationCompat.Builder(context, "douyou").setSmallIcon(R.drawable.dy_small_icon).setWhen(System.currentTimeMillis()).setAutoCancel(true).setTicker(bVar.b).setDefaults(8).setContentIntent(broadcast).setContent(remoteViews).build(); if (Build.VERSION.SDK_INT >= 26) { } if (!aVar.d.containsKey(bVar.b)) { } notificationManager.notify(i, build2); } catch (Exception e2) { e2.printStackTrace(); } } public boolean b(Context context, String str) { a().a(context, str); try { Intent launchIntentForPackage = context.getPackageManager().getLaunchIntentForPackage(str); launchIntentForPackage.setFlags(270663680); context.startActivity(launchIntentForPackage); return true; } catch (Exception e2) { e2.printStackTrace(); return false; } } /* renamed from: com.duoyou.task.pro.c.a$a reason: collision with other inner class name */ public class C0042a extends c { public Context a; public long b; public long c; public b d; public C0042a(Context context, b bVar) { this.a = context; this.d = bVar; } @Override // com.duoyou.task.pro.c.c public void a(String str, String str2) { Log.i("json", "download onLoading = " + str2 + str); c a2 = a.this.a(this.d); if (a2 != null) { a2.a(str, str2); } b bVar = this.d; bVar.g = 3; a.a(a.this, this.a, bVar); a.this.b.remove(this.d.a); a.this.c.remove(this.d.a); } @Override // com.duoyou.task.sdk.xutils.common.Callback.CommonCallback, com.duoyou.task.pro.c.c public void onCancelled(Callback.CancelledException cancelledException) { Log.i("json", "download onCancelled = "); c a2 = a.this.a(this.d); if (a2 != null) { a2.onCancelled(cancelledException); } b bVar = this.d; bVar.g = 4; a.a(a.this, this.a, bVar); a.this.b.remove(this.d.a); } @Override // com.duoyou.task.sdk.xutils.common.Callback.ProgressCallback, com.duoyou.task.pro.c.c public void onLoading(long j, long j2, boolean z) { long j3; Log.i("json", "download onLoading = " + j2); if (this.b == 0) { this.b = System.currentTimeMillis(); this.c = j2; } long currentTimeMillis = System.currentTimeMillis(); long j4 = currentTimeMillis - this.b; if (j4 > 0) { j3 = ((j2 - this.c) * 1000) / j4; this.b = currentTimeMillis; this.c = j2; } else { j3 = 0; } a(j > 0 ? (int) ((((double) j2) * 100.0d) / ((double) j)) : 0, j3, j2, j); } @Override // com.duoyou.task.pro.c.c public void a(int i, long j, long j2, long j3) { b bVar = this.d; bVar.f = i; bVar.c = com.duoyou.task.pro.b.a.a(j); b bVar2 = this.d; bVar2.d = j2; bVar2.e = j3; bVar2.g = 1; c a2 = a.this.a(bVar2); a.a(a.this, this.a, this.d); if (a2 != null) { a2.a(i, j, j2, j3); } } @Override // com.duoyou.task.pro.c.c /* renamed from: a */ public void onSuccess(File file) { if (!com.duoyou.task.pro.b.a.f(this.a, file.getAbsolutePath())) { file.delete(); } else if (!com.duoyou.task.pro.b.a.b(this.a, file.getAbsolutePath(), this.d.b)) { file.delete(); com.duoyou.task.pro.b.a.k(this.a, "安装失败,请重试"); } c a2 = a.this.a(this.d); if (a2 != null) { a2.onSuccess(file); } b bVar = this.d; bVar.g = 2; a.a(a.this, this.a, bVar); a.this.b.remove(this.d.a); } } public void a(Context context, String str) { try { String str2 = a().e.get(str); if (!TextUtils.isEmpty(str2) && com.duoyou.task.pro.b.a.g(context, str)) { a().e.remove(str2); File file = new File(str2); if (file.exists()) { file.delete(); com.duoyou.task.pro.b.a.k(context, "安装包已删除"); } } } catch (Exception e2) { e2.printStackTrace(); } } public c a(b bVar) { if (this.b.containsKey(bVar.a)) { return this.b.get(bVar.a); } return null; } public String a(Context context, b bVar) { if (TextUtils.isEmpty(e.a)) { try { e.a = context.getExternalFilesDir("Download").getAbsolutePath() + "/"; } catch (Exception e2) { e2.printStackTrace(); e.a = context.getFilesDir().getAbsolutePath() + "/"; } } Log.i("json", "download_file_path = " + e.a); try { File file = new File(e.a); if (!file.exists()) { file.mkdirs(); } } catch (Exception e3) { e3.printStackTrace(); } String str = e.a; String a2 = f.a(bVar.a); return str + a2 + ".apk"; } public void a(Context context, b bVar, c cVar) { String str = bVar.a; String a2 = a(context, bVar); try { this.e.put(bVar.b, a2); } catch (Exception e2) { e2.printStackTrace(); } if (com.duoyou.task.pro.b.a.g(context, bVar.b)) { b(context, bVar.b); cVar.onSuccess(new File(a2)); } else if (com.duoyou.task.pro.b.a.f(context, a2)) { com.duoyou.task.pro.b.a.b(context, a2, bVar.b); cVar.onSuccess(new File(a2)); } else if (this.b.containsKey(str)) { this.b.remove(str); this.b.put(str, cVar); cVar.getClass(); com.duoyou.task.pro.b.a.k(context, "当前任务正在下载"); } else { this.b.put(str, cVar); RequestParams requestParams = new RequestParams(str); requestParams.setAutoRename(false); requestParams.setSaveFilePath(a2); if (this.a == null) { this.a = Executors.newFixedThreadPool(20); } requestParams.setExecutor(this.a); requestParams.setCancelFast(true); requestParams.setRedirectHandler(new d()); Callback.Cancelable cancelable = x.http().get(requestParams, new C0042a(context, bVar)); if (cancelable != null) { this.c.put(bVar.a, cancelable); } } } }