Skip to content

Commit 8ffc345

Browse files
committed
fixes download all images in e2ee folder
Signed-off-by: alperozturk96 <alper_ozturk@proton.me>
1 parent 0280e4b commit 8ffc345

3 files changed

Lines changed: 14 additions & 53 deletions

File tree

app/src/main/java/com/nextcloud/client/jobs/folderDownload/FolderDownloadEventBroadcaster.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ package com.nextcloud.client.jobs.folderDownload
1010
import android.content.Context
1111
import android.content.Intent
1212
import androidx.localbroadcastmanager.content.LocalBroadcastManager
13-
import com.nextcloud.client.jobs.download.FileDownloadEventBroadcaster
1413
import com.owncloud.android.lib.common.utils.Log_OC
1514

1615
class FolderDownloadEventBroadcaster(
@@ -28,7 +27,7 @@ class FolderDownloadEventBroadcaster(
2827
const val EXTRA_FILE_ID = ARG_PREFIX + "EXTRA_FILE_ID"
2928
}
3029

31-
fun sendAdded(id: Long) {
30+
fun sendDownloadEnqueued(id: Long) {
3231
Log_OC.d(TAG, "Download enqueued broadcast sent")
3332

3433
val intent = Intent(ACTION_DOWNLOAD_ENQUEUED).apply {
@@ -38,7 +37,7 @@ class FolderDownloadEventBroadcaster(
3837
broadcastManager.sendBroadcast(intent)
3938
}
4039

41-
fun sendFinished(id: Long) {
40+
fun sendDownloadCompleted(id: Long) {
4241
Log_OC.d(TAG, "Download completed broadcast sent")
4342

4443
val intent = Intent(ACTION_DOWNLOAD_COMPLETED).apply {

app/src/main/java/com/nextcloud/client/jobs/folderDownload/FolderDownloadWorker.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class FolderDownloadWorker(
8080

8181
trySetForeground(folder)
8282

83-
folderDownloadEventBroadcaster.sendAdded(folder.fileId)
83+
folderDownloadEventBroadcaster.sendDownloadEnqueued(folder.fileId)
8484
pendingDownloads.add(folder.fileId)
8585

8686
val downloadHelper = FileDownloadHelper.instance()
@@ -138,7 +138,7 @@ class FolderDownloadWorker(
138138
Log_OC.d(TAG, "❌ failed reason: $e")
139139
Result.failure()
140140
} finally {
141-
folderDownloadEventBroadcaster.sendFinished(folder.fileId)
141+
folderDownloadEventBroadcaster.sendDownloadCompleted(folder.fileId)
142142
pendingDownloads.remove(folder.fileId)
143143
notificationManager.dismiss()
144144
}

app/src/main/java/com/owncloud/android/ui/preview/PreviewImageActivity.kt

Lines changed: 10 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)