public void startDownloadFromJson(GetApkInfoJson json, long id, Download download) { ArrayList<DownloadModel> filesToDownload = new ArrayList<DownloadModel>(); if (json.getObb() != null) { DownloadModel mainObbDownload = new DownloadModel( json.getObb().getMain().getPath(), OBB_DESTINATION + download.getPackageName() + "/" + json.getObb().getMain().getFilename(), json.getObb().getMain().getMd5sum(), json.getObb().getMain().getFilesize().longValue()); filesToDownload.add(mainObbDownload); if (json.getObb().getPatch() != null) { DownloadModel patchObbDownload = new DownloadModel( json.getObb().getPatch().getPath(), OBB_DESTINATION + download.getPackageName() + "/" + json.getObb().getPatch().getFilename(), json.getObb().getPatch().getMd5sum(), json.getObb().getPatch().getFilesize().longValue()); filesToDownload.add(patchObbDownload); } } String path = Aptoide.getConfiguration().getPathCacheApks(); if (json.getApk().getMd5sum() != null) { download.setId(json.getApk().getMd5sum().hashCode()); } DownloadModel downloadModel = new DownloadModel( json.getApk().getPath(), path + json.getApk().getMd5sum() + ".apk", json.getApk().getMd5sum(), json.getApk().getSize().longValue()); downloadModel.setAutoExecute(true); downloadModel.setFallbackUrl(json.getApk().getAltPath()); filesToDownload.add(downloadModel); FinishedApk apk = new FinishedApk( download.getName(), download.getPackageName(), download.getVersion(), id, download.getIcon(), path + json.getApk().getMd5sum() + ".apk", new ArrayList<String>(json.getApk().getPermissions())); apk.setId(json.getApk().getId().longValue()); download(download.getId(), download, apk, filesToDownload); }
private NotificationCompat.Builder createDefaultNotification() { NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this); Intent onClick = new Intent(); onClick.setClassName( getPackageName(), /*Aptoide.getConfiguration().*/ getStartActivityClass().getName()); // TODO dependency injection onClick.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT | Intent.FLAG_ACTIVITY_NEW_TASK); onClick.setAction(Intent.ACTION_VIEW); onClick.putExtra("fromDownloadNotification", true); // The PendingIntent to launch our activity if the user selects this notification PendingIntent onClickAction = PendingIntent.getActivity( getApplicationContext(), 0, onClick, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setOngoing(true); mBuilder .setContentTitle( getString(R.string.aptoide_downloading, Aptoide.getConfiguration().getMarketName())) .setSmallIcon(R.drawable.stat_sys_download) .setProgress(0, 0, true) .setContentIntent(onClickAction); mBuilder.setProgress(100, 0, true); ((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE)) .notify(-3, mBuilder.build()); return mBuilder; }
public void startDownloadFromV6(Download download, UpdatesResponse.UpdateApk apk) { ArrayList<DownloadModel> filesToDownload = new ArrayList<>(); String path = Aptoide.getConfiguration().getPathCacheApks(); if (apk.md5sum != null) { download.setId(apk.md5sum.hashCode()); } DownloadModel downloadModel = new DownloadModel( apk.apk.path, path + apk.md5sum + ".apk", apk.md5sum, apk.apk.filesize.longValue()); downloadModel.setAutoExecute(true); downloadModel.setFallbackUrl(apk.apk.path_alt); filesToDownload.add(downloadModel); FinishedApk fapk = new FinishedApk( download.getName(), download.getPackageName(), download.getVersion(), apk.md5sum.hashCode(), download.getIcon(), path + apk.md5sum + ".apk", new ArrayList<String>()); fapk.setId(apk.md5sum.hashCode()); download(download.getId(), download, fapk, filesToDownload); }
private NotificationCompat.Builder setNotification(final long id) { DownloadInfoRunnable info = getDownload(id); final NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this); // TODO Intent onClick = new Intent(); onClick.setClassName( getPackageName(), /*Aptoide.getConfiguration().*/ getStartActivityClass().getName()); onClick.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT | Intent.FLAG_ACTIVITY_NEW_TASK); onClick.setAction(Intent.ACTION_VIEW); onClick.putExtra("fromDownloadNotification", true); // The PendingIntent to launch our activity if the user selects this notification PendingIntent onClickAction = PendingIntent.getActivity( getApplicationContext(), 0, onClick, PendingIntent.FLAG_UPDATE_CURRENT); int size = DownloadUtils.dpToPixels(getApplicationContext(), 36); Bitmap icon = null; try { // icon = // DownloadUtils.decodeSampledBitmapFromResource(ImageLoader.getInstance().getDiscCache().get(info.getDownload().getIcon()).getAbsolutePath(), size, size); icon = GlideUtils.downloadOnlyFromCache( Aptoide.getContext(), info.getDownload().getIcon(), size, size); } catch (Exception e) { e.printStackTrace(); } mBuilder.setOngoing(true); mBuilder.setContentTitle( getString(R.string.aptoide_downloading, Aptoide.getConfiguration().getMarketName())); mBuilder.setContentText(info.getDownload().getName()); if (icon != null) mBuilder.setLargeIcon(icon); mBuilder.setSmallIcon(android.R.drawable.stat_sys_download); mBuilder.setProgress(0, 0, true); mBuilder.setContentIntent(onClickAction); // Log.d("download-trace", "ETA: " + info.getEta()); if (info.getEta() > 0) { String remaining = DownloadUtils.formatEta(info.getEta(), ""); mBuilder.setContentInfo("ETA: " + (!remaining.equals("") ? remaining : "0s")); } return mBuilder; }
public void startDownloadFromUrl( String remotePath, String md5, long id, Download download, String repoName) { ArrayList<DownloadModel> filesToDownload = new ArrayList<DownloadModel>(); String path = Aptoide.getConfiguration().getPathCacheApks(); DownloadModel downloadModel = new DownloadModel(remotePath, path + md5 + ".apk", md5, 0); downloadModel.setAutoExecute(true); filesToDownload.add(downloadModel); FinishedApk apk = new FinishedApk( download.getName(), download.getPackageName(), download.getVersion(), id, download.getIcon(), path + md5 + ".apk", new ArrayList<String>()); apk.setRepoName(repoName); download(id, download, apk, filesToDownload); }