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,6 +72,7 @@ class FileUploadWorker(
private val fileUploaderDelegate = FileUploaderDelegate()
override fun doWork(): Result {
return try {
backgroundJobManager.logStartOfWorker(BackgroundJobManagerImpl.formatClassTag(this::class))
val accountName = inputData.getString(ACCOUNT)
@ -83,9 +86,33 @@ class FileUploadWorker(
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()
}
}
override fun onStopped() {
Log_OC.e(TAG, "FileUploadWorker stopped")
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() {