@@ -415,8 +415,7 @@ class PreviewImageActivity :
415415 showDetails(file)
416416 }
417417
418- @JvmOverloads
419- fun requestForDownload (file : OCFile ? , downloadBehaviour : String? = null) {
418+ fun requestForDownload (file : OCFile ? ) {
420419 if (file == null ) return
421420 val user = user.orElseThrow { RuntimeException () }
422421 FileDownloadHelper .instance().downloadFileIfNotStartedBefore(user, file)
@@ -469,18 +468,20 @@ class PreviewImageActivity :
469468 */
470469 private inner class DownloadFinishReceiver : BroadcastReceiver () {
471470 override fun onReceive (context : Context , intent : Intent ) {
472- /*
473- Log_OC.d(TAG, "Download worker stopped")
471+ Log_OC .d(TAG , " Download worker stopped" )
474472 isDownloadWorkStarted = false
473+ val accountName = intent.getStringExtra(FileDownloadEventBroadcaster .EXTRA_ACCOUNT_NAME )
474+ val downloadedRemotePath = intent.getStringExtra(FileDownloadEventBroadcaster .EXTRA_REMOTE_PATH )
475+ if (account.name != accountName || downloadedRemotePath == null ) {
476+ return
477+ }
478+ val file = storageManager.getFileByEncryptedRemotePath(downloadedRemotePath)
475479
476480 if (screenState == PreviewImageActivityState .Edit ) {
477- onImageDownloadComplete(state.currentFile )
481+ onImageDownloadComplete(file )
478482 } else {
479483 setDownloadedItem()
480484 }
481- */
482-
483- previewNewImage(intent)
484485 }
485486 }
486487
@@ -495,45 +496,6 @@ class PreviewImageActivity :
495496 }
496497 }
497498
498- @Suppress(" NestedBlockDepth" , " ReturnCount" )
499- private fun previewNewImage (intent : Intent ) {
500- val accountName = intent.getStringExtra(FileDownloadEventBroadcaster .EXTRA_ACCOUNT_NAME )
501- val downloadedRemotePath = intent.getStringExtra(FileDownloadEventBroadcaster .EXTRA_REMOTE_PATH )
502- val downloadBehaviour = intent.getStringExtra(FileDownloadEventBroadcaster .EXTRA_DOWNLOAD_BEHAVIOUR )
503-
504- if (account.name != accountName || downloadedRemotePath == null ) {
505- return
506- }
507-
508- val file = storageManager.getFileByEncryptedRemotePath(downloadedRemotePath)
509- val downloadWasFine = intent.getBooleanExtra(FileDownloadEventBroadcaster .EXTRA_DOWNLOAD_RESULT , false )
510-
511- if (EditImageActivity .OPEN_IMAGE_EDITOR == downloadBehaviour) {
512- startImageEditor(file)
513- } else {
514- val position = previewImagePagerAdapter?.getFilePosition(file) ? : return
515-
516- if (position >= 0 ) {
517- if (downloadWasFine) {
518- previewImagePagerAdapter?.updateFile(position, file)
519- } else {
520- previewImagePagerAdapter?.updateWithDownloadError(position)
521- }
522- previewImagePagerAdapter?.notifyItemChanged(position)
523- } else if (downloadWasFine) {
524- val user = user
525-
526- if (user.isPresent) {
527- initViewPager(user.get())
528- val newPosition = previewImagePagerAdapter?.getFilePosition(file) ? : return
529- if (newPosition >= 0 ) {
530- viewPager?.currentItem = newPosition
531- }
532- }
533- }
534- }
535- }
536-
537499 val isSystemUIVisible: Boolean
538500 get() = supportActionBar == null || supportActionBar?.isShowing == true
539501
@@ -554,7 +516,7 @@ class PreviewImageActivity :
554516 } else {
555517 showLoadingDialog(getString(R .string.preview_image_downloading_image_for_edit))
556518 screenState = PreviewImageActivityState .Edit
557- requestForDownload(file, EditImageActivity . OPEN_IMAGE_EDITOR )
519+ requestForDownload(file)
558520 }
559521 }
560522
0 commit comments