Rebase master

Signed-off-by: alperozturk <alper_ozturk@proton.me>
This commit is contained in:
alperozturk 2024-01-12 14:27:29 +01:00 committed by Jonas Mayer
parent 30d03d84bc
commit 96c2284b26
3 changed files with 57 additions and 16 deletions

View file

@ -34,6 +34,8 @@ import com.nextcloud.client.jobs.BackgroundJobManager
import com.nextcloud.client.jobs.BackgroundJobManagerImpl
import com.nextcloud.client.network.ConnectivityService
import com.nextcloud.java.util.Optional
import com.nextcloud.model.WorkerState
import com.nextcloud.model.WorkerStateLiveData
import com.owncloud.android.R
import com.owncloud.android.datamodel.FileDataStorageManager
import com.owncloud.android.datamodel.ThumbnailsCacheManager
@ -70,22 +72,47 @@ class FileUploadWorker(
private val fileUploaderDelegate = FileUploaderDelegate()
override fun doWork(): Result {
backgroundJobManager.logStartOfWorker(BackgroundJobManagerImpl.formatClassTag(this::class))
return try {
backgroundJobManager.logStartOfWorker(BackgroundJobManagerImpl.formatClassTag(this::class))
val accountName = inputData.getString(ACCOUNT)
if (accountName.isNullOrEmpty()) {
Log_OC.w(TAG, "User was null for file upload worker")
val accountName = inputData.getString(ACCOUNT)
if (accountName.isNullOrEmpty()) {
Log_OC.w(TAG, "User was null for file upload worker")
val result = Result.failure()
val result = Result.failure()
backgroundJobManager.logEndOfWorker(BackgroundJobManagerImpl.formatClassTag(this::class), result)
return result
}
retrievePagesBySortingUploadsByID(accountName)
Log_OC.e(TAG, "FileUploadWorker successfully completed")
val result = Result.success()
backgroundJobManager.logEndOfWorker(BackgroundJobManagerImpl.formatClassTag(this::class), result)
return result
result
} catch (t: Throwable) {
Log_OC.e(TAG, "Error caught at FileUploadWorker " + t.localizedMessage)
Result.failure()
}
}
retrievePagesBySortingUploadsByID(accountName)
override fun onStopped() {
Log_OC.e(TAG, "FileUploadWorker stopped")
val result = Result.success()
backgroundJobManager.logEndOfWorker(BackgroundJobManagerImpl.formatClassTag(this::class), result)
return result
setIdleWorkerState()
currentUploadFileOperation?.cancel(null)
notificationManager.dismissWorkerNotifications()
super.onStopped()
}
private fun setWorkerState(user: User?, uploads: List<OCUpload>) {
WorkerStateLiveData.instance().setWorkState(WorkerState.Upload(user, uploads))
}
private fun setIdleWorkerState() {
WorkerStateLiveData.instance().setWorkState(WorkerState.Idle)
}
private fun retrievePagesBySortingUploadsByID(accountName: String) {
@ -103,6 +130,8 @@ class FileUploadWorker(
private fun handlePendingUploads(uploads: List<OCUpload>, accountName: String) {
val user = userAccountManager.getUser(accountName)
setWorkerState(user.get(), uploads)
for (upload in uploads) {
if (isStopped) {
break
@ -275,12 +304,6 @@ class FileUploadWorker(
lastPercent = percent
}
override fun onStopped() {
super.onStopped()
currentUploadFileOperation?.cancel(null)
notificationManager.dismissWorkerNotifications()
}
companion object {
val TAG: String = FileUploadWorker::class.java.simpleName

View file

@ -22,9 +22,11 @@
package com.nextcloud.model
import com.nextcloud.client.account.User
import com.owncloud.android.db.OCUpload
import com.owncloud.android.operations.DownloadFileOperation
sealed class WorkerState {
object Idle : WorkerState()
class Download(var user: User?, var currentDownload: DownloadFileOperation?) : WorkerState()
class Upload(var user: User?, var uploads: List<OCUpload>) : WorkerState()
}

View file

@ -42,6 +42,8 @@ import com.nextcloud.client.files.uploader.FileUploadWorker;
import com.nextcloud.client.jobs.BackgroundJobManager;
import com.nextcloud.client.network.ConnectivityService;
import com.nextcloud.client.utils.Throttler;
import com.nextcloud.model.WorkerState;
import com.nextcloud.model.WorkerStateLiveData;
import com.owncloud.android.R;
import com.owncloud.android.databinding.UploadListLayoutBinding;
import com.owncloud.android.datamodel.OCFile;
@ -142,6 +144,20 @@ public class UploadListActivity extends FileActivity {
setupDrawer(R.id.nav_uploads);
setupContent();
observeWorkerState();
}
private void observeWorkerState() {
WorkerStateLiveData.Companion.instance().observe(this, state -> {
if (state instanceof WorkerState.Upload) {
Log_OC.d(TAG, "Upload worker started");
handleUploadWorkerState();
}
});
}
private void handleUploadWorkerState() {
uploadListAdapter.loadUploadItemsFromDb();
}
private void setupContent() {