Skip to content

Commit

Permalink
Fix download progress
Browse files Browse the repository at this point in the history
Signed-off-by: alperozturk <[email protected]>
  • Loading branch information
alperozturk96 committed Dec 21, 2023
1 parent 4e63d44 commit 0a69f40
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class FilesDownloadHelper {
user,
ocFile,
"",
null,
DownloadType.DOWNLOAD,
"",
"",
null
Expand All @@ -58,7 +58,7 @@ class FilesDownloadHelper {
user,
ocFile,
behaviour,
null,
DownloadType.DOWNLOAD,
"",
"",
null
Expand All @@ -82,7 +82,7 @@ class FilesDownloadHelper {
user,
ocFile,
"",
null,
DownloadType.DOWNLOAD,
"",
"",
conflictUploadId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class FilesDownloadWorker(
private lateinit var notificationBuilder: NotificationCompat.Builder
private val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
private val pendingDownloads = IndexedForest<DownloadFileOperation>()
private var downloadBinder: IBinder? = null
private var downloadBinder: IBinder = FileDownloaderBinder()
private var currentUser = Optional.empty<User>()
private var startedDownload = false
private var storageManager: FileDataStorageManager? = null
Expand Down Expand Up @@ -158,6 +158,7 @@ class FilesDownloadWorker(
val packageName = inputData.keyValueMap[PACKAGE_NAME] as String

val requestedDownloads: AbstractList<String> = Vector()

try {
val operation = DownloadFileOperation(
user,
Expand All @@ -169,16 +170,19 @@ class FilesDownloadWorker(
downloadType
)
operation.addDatatransferProgressListener(this)
operation.addDatatransferProgressListener(downloadBinder as FileDownloaderBinder?)
operation.addDatatransferProgressListener(downloadBinder as FileDownloaderBinder)
val putResult = pendingDownloads.putIfAbsent(
user?.accountName,
file.remotePath,
operation
)

val downloadKey = putResult.first
requestedDownloads.add(downloadKey)
sendBroadcastNewDownload(operation, putResult.second)
if (putResult != null) {
val downloadKey = putResult.first
requestedDownloads.add(downloadKey)
sendBroadcastNewDownload(operation, putResult.second)
}

} catch (e: IllegalArgumentException) {
Log_OC.e(TAG, "Not enough information provided in intent: " + e.message)
}
Expand Down Expand Up @@ -207,12 +211,14 @@ class FilesDownloadWorker(

private fun startDownloadForEachRequest(requestDownloads: AbstractList<String>) {
val it: Iterator<String> = requestDownloads.iterator()

while (it.hasNext()) {
val next = it.next()
Log_OC.e(TAG, "Download Key: $next")

downloadFile(next)
}

startedDownload = false
}

private fun downloadFile(downloadKey: String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public interface ComponentsGetter {

/**
* To be invoked when the parent activity is fully created to get a reference
* to the FileDownloader service API.
* to the FileDownloadWorker.
*/
public FilesDownloadWorker.FileDownloaderBinder getFileDownloaderBinder();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
import com.owncloud.android.lib.resources.files.SearchRemoteOperation;
import com.owncloud.android.operations.CopyFileOperation;
import com.owncloud.android.operations.CreateFolderOperation;
import com.owncloud.android.operations.DownloadType;
import com.owncloud.android.operations.MoveFileOperation;
import com.owncloud.android.operations.RefreshFolderOperation;
import com.owncloud.android.operations.RemoveFileOperation;
Expand Down Expand Up @@ -1953,7 +1954,7 @@ public void run() {
private void requestForDownload(OCFile file, String downloadBehaviour, String packageName, String activityName) {
final User currentUser = getUser().orElseThrow(RuntimeException::new);
if (!mDownloaderBinder.isDownloading(currentUser, mWaitingToPreview)) {
new FilesDownloadHelper().downloadFile(currentUser, file, downloadBehaviour, null, activityName, packageName, null);
new FilesDownloadHelper().downloadFile(currentUser, file, downloadBehaviour, DownloadType.DOWNLOAD, activityName, packageName, null);
}
}

Expand Down

0 comments on commit 0a69f40

Please sign in to comment.