mirror of
https://github.com/nextcloud/android.git
synced 2024-11-22 13:15:35 +03:00
Rebase master
Signed-off-by: alperozturk <alper_ozturk@proton.me>
This commit is contained in:
parent
e507317005
commit
f6bd33734b
6 changed files with 27 additions and 52 deletions
|
@ -121,9 +121,7 @@ class FileUploadHelper {
|
|||
|
||||
@Suppress("ReturnCount")
|
||||
fun isUploading(user: User?, file: OCFile?): Boolean {
|
||||
if (user == null || file == null || !MainApp.getAppContext()
|
||||
.isWorkScheduled(BackgroundJobManagerImpl.JOB_FILES_UPLOAD)
|
||||
) {
|
||||
if (user == null || file == null || !backgroundJobManager.isStartFileUploadJobScheduled(user)) {
|
||||
return false
|
||||
}
|
||||
|
||||
|
|
|
@ -216,9 +216,9 @@ class FileUploadWorker(
|
|||
return
|
||||
}
|
||||
|
||||
val (tickerId, needsToUpdateCredentials) = getTickerId(uploadResult.code)
|
||||
val needsToUpdateCredentials = (uploadResult.code == ResultCode.UNAUTHORIZED)
|
||||
notificationManager.run {
|
||||
notifyForResult(tickerId)
|
||||
notifyForResult(uploadResult.code)
|
||||
setContentIntent(intents.resultIntent(ResultCode.OK, uploadFileOperation))
|
||||
|
||||
if (uploadResult.code == ResultCode.SYNC_CONFLICT) {
|
||||
|
@ -244,20 +244,6 @@ class FileUploadWorker(
|
|||
}
|
||||
}
|
||||
|
||||
private fun getTickerId(resultCode: ResultCode): Pair<Int, Boolean> {
|
||||
var tickerId = R.string.uploader_upload_failed_ticker
|
||||
|
||||
val needsToUpdateCredentials = (resultCode == ResultCode.UNAUTHORIZED)
|
||||
|
||||
if (needsToUpdateCredentials) {
|
||||
tickerId = R.string.uploader_upload_failed_credentials_error
|
||||
} else if (resultCode == ResultCode.SYNC_CONFLICT) {
|
||||
tickerId = R.string.uploader_upload_failed_sync_conflict_error
|
||||
}
|
||||
|
||||
return Pair(tickerId, needsToUpdateCredentials)
|
||||
}
|
||||
|
||||
override fun onTransferProgress(
|
||||
progressRate: Long,
|
||||
totalTransferredSoFar: Long,
|
||||
|
|
|
@ -28,6 +28,7 @@ import android.content.Context
|
|||
import android.graphics.BitmapFactory
|
||||
import androidx.core.app.NotificationCompat
|
||||
import com.owncloud.android.R
|
||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult
|
||||
import com.owncloud.android.lib.resources.files.FileUtils
|
||||
import com.owncloud.android.operations.UploadFileOperation
|
||||
import com.owncloud.android.ui.notifications.NotificationUtils
|
||||
|
@ -51,8 +52,8 @@ class UploadNotificationManager(private val context: Context, private val viewTh
|
|||
|
||||
private fun initNotificationBuilder() {
|
||||
notificationBuilder = NotificationUtils.newNotificationBuilder(context, viewThemeUtils).apply {
|
||||
setContentTitle(context.resources.getString(R.string.app_name))
|
||||
setContentText(context.resources.getString(R.string.foreground_service_upload))
|
||||
setContentTitle(context.getString(R.string.app_name))
|
||||
setContentText(context.getString(R.string.worker_upload))
|
||||
setSmallIcon(R.drawable.notification_icon)
|
||||
setLargeIcon(BitmapFactory.decodeResource(context.resources, R.drawable.notification_icon))
|
||||
setChannelId(NotificationUtils.NOTIFICATION_CHANNEL_UPLOAD)
|
||||
|
@ -91,16 +92,32 @@ class UploadNotificationManager(private val context: Context, private val viewTh
|
|||
}
|
||||
}
|
||||
|
||||
fun notifyForResult(tickerId: Int) {
|
||||
fun notifyForResult(resultCode: RemoteOperationResult.ResultCode) {
|
||||
val textId = resultText(resultCode)
|
||||
|
||||
notificationBuilder
|
||||
.setTicker(context.getString(tickerId))
|
||||
.setContentTitle(context.getString(tickerId))
|
||||
.setTicker(context.getString(textId))
|
||||
.setContentTitle(context.getString(textId))
|
||||
.setAutoCancel(true)
|
||||
.setOngoing(false)
|
||||
.setProgress(0, 0, false)
|
||||
.clearActions()
|
||||
}
|
||||
|
||||
private fun resultText(resultCode: RemoteOperationResult.ResultCode): Int {
|
||||
var result = R.string.uploader_upload_failed_ticker
|
||||
|
||||
val needsToUpdateCredentials = (resultCode == RemoteOperationResult.ResultCode.UNAUTHORIZED)
|
||||
|
||||
if (needsToUpdateCredentials) {
|
||||
result = R.string.uploader_upload_failed_credentials_error
|
||||
} else if (resultCode == RemoteOperationResult.ResultCode.SYNC_CONFLICT) {
|
||||
result = R.string.uploader_upload_failed_sync_conflict_error
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
fun setContentIntent(pendingIntent: PendingIntent) {
|
||||
notificationBuilder.setContentIntent(pendingIntent)
|
||||
}
|
||||
|
|
|
@ -144,6 +144,7 @@ interface BackgroundJobManager {
|
|||
fun startFilesUploadJob(user: User)
|
||||
fun getFileUploads(user: User): LiveData<List<JobInfo>>
|
||||
fun cancelFilesUploadJob(user: User)
|
||||
fun isStartFileUploadJobScheduled(user: User): Boolean
|
||||
|
||||
fun cancelFilesDownloadJob(user: User, fileId: Long)
|
||||
|
||||
|
|
|
@ -27,12 +27,7 @@ import android.content.Context
|
|||
import android.content.Intent
|
||||
import android.content.IntentFilter
|
||||
import android.os.Build
|
||||
import androidx.work.WorkInfo
|
||||
import androidx.work.WorkManager
|
||||
import com.google.common.util.concurrent.ListenableFuture
|
||||
import com.owncloud.android.datamodel.ReceiverFlag
|
||||
import com.owncloud.android.lib.common.utils.Log_OC
|
||||
import java.util.concurrent.ExecutionException
|
||||
|
||||
@SuppressLint("UnspecifiedRegisterReceiverFlag")
|
||||
fun Context.registerBroadcastReceiver(receiver: BroadcastReceiver?, filter: IntentFilter, flag: ReceiverFlag): Intent? {
|
||||
|
@ -42,25 +37,3 @@ fun Context.registerBroadcastReceiver(receiver: BroadcastReceiver?, filter: Inte
|
|||
registerReceiver(receiver, filter)
|
||||
}
|
||||
}
|
||||
|
||||
fun Context.isWorkScheduled(tag: String): Boolean {
|
||||
val instance = WorkManager.getInstance(this)
|
||||
val statuses: ListenableFuture<List<WorkInfo>> = instance.getWorkInfosByTag(tag)
|
||||
var running = false
|
||||
var workInfoList: List<WorkInfo> = emptyList()
|
||||
|
||||
try {
|
||||
workInfoList = statuses.get()
|
||||
} catch (e: ExecutionException) {
|
||||
Log_OC.d("Worker", "ExecutionException in isWorkScheduled: $e")
|
||||
} catch (e: InterruptedException) {
|
||||
Log_OC.d("Worker", "InterruptedException in isWorkScheduled: $e")
|
||||
}
|
||||
|
||||
for (workInfo in workInfoList) {
|
||||
val state = workInfo.state
|
||||
running = running || (state == WorkInfo.State.RUNNING || state == WorkInfo.State.ENQUEUED)
|
||||
}
|
||||
|
||||
return running
|
||||
}
|
||||
|
|
|
@ -640,7 +640,7 @@
|
|||
<string name="info_separator" translatable="false"> •</string>
|
||||
<string name="resharing_is_not_allowed">Resharing is not allowed</string>
|
||||
|
||||
<string name="foreground_service_upload">Uploading files…</string>
|
||||
<string name="worker_upload">Uploading files…</string>
|
||||
<string name="worker_download">Downloading files…</string>
|
||||
|
||||
<string name="prefs_sourcecode">Get source code</string>
|
||||
|
|
Loading…
Reference in a new issue