|
34 | 34 | import com.hippo.ehviewer.client.EhUrl;
|
35 | 35 | import com.hippo.ehviewer.client.data.ArchiverData;
|
36 | 36 | import com.hippo.ehviewer.client.data.GalleryDetail;
|
| 37 | +import com.hippo.ehviewer.client.data.GalleryInfo; |
37 | 38 | import com.hippo.ehviewer.client.exception.NoHAtHClientException;
|
38 | 39 | import com.hippo.ehviewer.dao.DownloadInfo;
|
39 | 40 | import com.hippo.ehviewer.spider.SpiderDen;
|
@@ -206,36 +207,23 @@ public void onSuccess(String downloadUrl) {
|
206 | 207 | DownloadManager.Request request = new DownloadManager.Request(downloadUri);
|
207 | 208 | request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_MOBILE | DownloadManager.Request.NETWORK_WIFI);
|
208 | 209 | request.setAllowedOverRoaming(true);
|
209 |
| - request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); |
| 210 | + request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE); |
210 | 211 | request.setTitle(galleryDetail.title);
|
211 | 212 | request.setDescription(context.getString(R.string.download_archive_started));
|
212 | 213 | request.setVisibleInDownloadsUi(true);
|
213 |
| -// request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "EhviewerArchiver/"+galleryDetail.title + ".zip"); |
214 |
| - request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "EhviewerArchiver/"+"[Abe Nattsu] SEX de Wakaru Unmei no Hito ~ Karada no Aishou... Tameshite miru? ~ Ch. 1-6 [Chinese] [裸單騎漢化]" + ".zip"); |
| 214 | + request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "EhviewerArchiver/"+galleryDetail.title + ".zip"); |
215 | 215 | request.allowScanningByMediaScanner();
|
216 | 216 |
|
217 | 217 | DownloadManager downloadManager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
|
218 |
| - myDownloadId = downloadManager.enqueue(request); |
219 | 218 |
|
220 |
| - context.registerReceiver(downloadReceiver, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE)); |
| 219 | +// downloadManager.query(new DownloadManager.Query().setFilterByStatus(DownloadManager.STATUS_PAUSED)); |
221 | 220 |
|
| 221 | + myDownloadId = downloadManager.enqueue(request); |
| 222 | + Settings.putArchiverDownloadId(galleryDetail.gid,myDownloadId); |
| 223 | + Settings.putArchiverDownload(myDownloadId,galleryDetail); |
| 224 | + detailScene.bindArchiverProgress(galleryDetail); |
222 | 225 |
|
223 |
| -// String path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getPath(); |
224 |
| -// String name = galleryDetail.title + ".zip"; |
225 |
| -// DownloadArchiverManager.Archiver archiver = new DownloadArchiverManager.Archiver(downloadUrl,path,name); |
226 |
| -// final DownloadArchiverManager manager = archiverDownloadDialog.downloadArchiverManager; |
227 |
| -// manager.addDownloadArchiverListener(this); |
228 |
| -// |
229 |
| -// NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); |
230 |
| -// if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { |
231 |
| -// NotificationChannel channel = new NotificationChannel(CHANNEL_ID,context.getString(R.string.download_service),NotificationManager.IMPORTANCE_LOW); |
232 |
| -// notificationManager.createNotificationChannel(channel); |
233 |
| -// } |
234 |
| -// NotificationCompat.Builder builder = new NotificationCompat.Builder(context,CHANNEL_ID) |
235 |
| -// .setContentTitle(context.getString(R.string.download)) |
236 |
| -// .setContentText(archiver.name) |
237 |
| -// .setSmallIcon(R.mipmap.ic_launcher) |
238 |
| -// .setProgress(100,0,false); |
| 226 | + context.registerReceiver(downloadReceiver, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE)); |
239 | 227 | }
|
240 | 228 |
|
241 | 229 | @Override
|
@@ -322,18 +310,19 @@ private void unzipAndImportFile(Cursor cursor) throws IllegalArgumentException,
|
322 | 310 | if (tempDir == null) {
|
323 | 311 | return;
|
324 | 312 | }
|
| 313 | + long downloadId = cursor.getLong(cursor.getColumnIndexOrThrow(DownloadManager.COLUMN_ID)); |
325 | 314 | String tempFilePath = tempDir.getPath() + "/" + galleryDetail.title;
|
326 | 315 | String zipFilePath = zipFile.getPath();
|
327 | 316 | new Thread(() -> {
|
328 | 317 | boolean result = GZIPUtils.UnZipFolder(zipFilePath, tempFilePath);
|
329 | 318 | if (!result) {
|
330 | 319 | return;
|
331 | 320 | }
|
332 |
| - importGallery(tempFilePath); |
| 321 | + importGallery(tempFilePath,downloadId); |
333 | 322 | }).start();
|
334 | 323 | }
|
335 | 324 |
|
336 |
| - private void importGallery(String tempFilePath) { |
| 325 | + private void importGallery(String tempFilePath, long downloadId) { |
337 | 326 | if (tempFilePath.isEmpty() || context == null) {
|
338 | 327 | return;
|
339 | 328 | }
|
@@ -398,6 +387,12 @@ private void importGallery(String tempFilePath) {
|
398 | 387 | if (downloadReceiver != null) {
|
399 | 388 | context.unregisterReceiver(downloadReceiver);
|
400 | 389 | }
|
| 390 | + GalleryInfo info = Settings.getArchiverDownload(downloadId); |
| 391 | + if (info==null){ |
| 392 | + return; |
| 393 | + } |
| 394 | + Settings.deleteArchiverDownloadId(info.gid); |
| 395 | + Settings.deleteArchiverDownload(downloadId); |
401 | 396 | });
|
402 | 397 | }
|
403 | 398 | }
|
|
0 commit comments