public void removeNonActiveDownloads(boolean isChecked) { ArrayList<DownloadInfoRunnable> allDownloads = new ArrayList<DownloadInfoRunnable>(); allDownloads.addAll(manager.getmErrorList()); allDownloads.addAll(manager.getmCompletedList()); for (DownloadInfoRunnable downloadInfoRunnable : allDownloads) { downloadInfoRunnable.remove(isChecked); } }
public ArrayList<DownloadInfoRunnable> getOngoingDownloads() { ArrayList<DownloadInfoRunnable> ongoingDownloads = new ArrayList<DownloadInfoRunnable>(); ongoingDownloads.addAll(manager.getmActiveList()); ongoingDownloads.addAll(manager.getmPendingList()); return ongoingDownloads; }
public ArrayList<Displayable> getAllNonActiveDownloads() { ArrayList<Displayable> allNonActive = new ArrayList<>(); ArrayList<DownloadInfoRunnable> allDownloads = new ArrayList<>(); allDownloads.addAll(manager.getmErrorList()); allDownloads.addAll(manager.getmCompletedList()); for (DownloadInfoRunnable info : allDownloads) { allNonActive.add(new NotOngoingDownloadRow(info.getDownload())); } return allNonActive; }
private void updateProgress() { Collection<DownloadInfoRunnable> list = getOngoingDownloads(); list.addAll(manager.getmCompletedList()); for (DownloadInfoRunnable info : list) { if (info.getStatusState() instanceof ActiveState) { try { info.getmBuilder() .setProgress(100, info.getPercentDownloaded(), info.getPercentDownloaded() == 0); if (info.getEta() > 0) { String remaining = DownloadUtils.formatEta(info.getEta(), ""); info.getmBuilder().setContentInfo("ETA: " + (!remaining.equals("") ? remaining : "0s")); } mBuilder = info.getmBuilder(); ((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE)) .notify(-3, mBuilder.build()); } catch (Exception e) { e.printStackTrace(); } return; } } }
public void startExistingDownload(long id) { startService(new Intent(getApplicationContext(), DownloadService.class)); final NotificationCompat.Builder builder = setNotification(id); if (mBuilder == null) mBuilder = createDefaultNotification(); startForeground(-3, mBuilder.build()); startIfStopped(); // Log.d("Aptoide-DownloadManager", "Starting existing download " + id); for (final DownloadInfoRunnable info : manager.getmCompletedList()) { if (info.getId() == id) { final PackageManager packageManager = getPackageManager(); new Thread( new Runnable() { @Override public void run() { for (DownloadModel model : info.getmFilesToDownload()) { try { PackageInfo packageInfo = packageManager.getPackageInfo( info.getDownload().getPackageName(), PackageManager.SIGNATURE_MATCH); if (packageInfo.versionName.equals(info.getDownload().getVersion())) { new Handler(Looper.getMainLooper()) .post( new Runnable() { @Override public void run() { Intent LaunchIntent = packageManager.getLaunchIntentForPackage( info.getDownload().getPackageName()); if (LaunchIntent != null) startActivity(LaunchIntent); } }); } else { throw new PackageManager.NameNotFoundException(); } } catch (PackageManager.NameNotFoundException e) { try { String calculatedMd5 = AptoideUtils.Algorithms.md5Calc(new File(model.getDestination())); if (!calculatedMd5.equals(info.getDownload().getMd5())) { // Log.d("download-trace", "Failed Md5 for " + // info.getDownload().getName() + " : " + info.getDestination() + " // calculated " + calculatedMd5 + " vs " + info.getDownload().getMd5()); info.setmBuilder(builder); info.download(); break; } else { info.autoExecute(); // Log.d("download-trace", "Checked Md5 for " + // info.getDownload().getName() + ", application download it's already // completed!"); break; } } catch (Exception e1) { e1.printStackTrace(); } } } } }) .start(); return; } } for (DownloadInfoRunnable info : manager.getmErrorList()) { if (info.getId() == id) { info.setmBuilder(builder); info.download(); return; } } }