Fix code analytics

Signed-off-by: alperozturk <alper_ozturk@proton.me>
This commit is contained in:
alperozturk 2024-01-04 10:43:19 +01:00 committed by Alper Öztürk
parent 9f1ff12f46
commit 1df82a7302
2 changed files with 54 additions and 40 deletions

View file

@ -32,6 +32,7 @@ import androidx.core.app.NotificationCompat
import com.nextcloud.client.account.User
import com.owncloud.android.R
import com.owncloud.android.authentication.AuthenticatorActivity
import com.owncloud.android.datamodel.OCFile
import com.owncloud.android.lib.common.operations.RemoteOperationResult
import com.owncloud.android.lib.resources.files.FileUtils
import com.owncloud.android.operations.DownloadFileOperation
@ -87,7 +88,7 @@ class DownloadNotificationManager(private val context: Context, private val view
downloadResult: RemoteOperationResult<*>,
needsToUpdateCredentials: Boolean
) {
val tickerId = getTickerId(downloadResult.isSuccess, needsToUpdateCredentials)
val tickerId = getTickerId(downloadResult.isSuccess, needsToUpdateCredentials, null, null)
notificationBuilder
.setTicker(context.getString(tickerId))
@ -98,12 +99,17 @@ class DownloadNotificationManager(private val context: Context, private val view
}
@Suppress("MagicNumber")
fun notifyForResult(result: RemoteOperationResult<*>, download: DownloadFileOperation) {
fun notifyForResult(
result: RemoteOperationResult<*>?,
download: DownloadFileOperation?,
folder: OCFile?,
isAnyOperationFailed: Boolean?
) {
dismissDownloadInProgressNotification()
val tickerId = getTickerId(result.isSuccess, null)
val tickerId = getTickerId(result?.isSuccess, null, folder, isAnyOperationFailed)
val notifyId = SecureRandom().nextInt()
val resultText = getResultText(result, download)
val resultText = getResultText(result, download, folder, isAnyOperationFailed)
notificationBuilder.run {
setTicker(context.getString(tickerId))
@ -118,47 +124,55 @@ class DownloadNotificationManager(private val context: Context, private val view
)
}
fun notifyForFolderResult(isAnyOperationFailed: Boolean, folderName: String) {
val notifyId = SecureRandom().nextInt()
val message = if (!isAnyOperationFailed) {
context.getString(R.string.downloader_folder_downloaded, folderName)
private fun getResultText(
result: RemoteOperationResult<*>?,
download: DownloadFileOperation?,
folder: OCFile?,
isAnyOperationFailed: Boolean?
): String {
return folder?.let {
getFolderResultText(isAnyOperationFailed, it)
} ?: if (result?.isSuccess == true) {
download?.file?.fileName ?: ""
} else {
context.getString(R.string.downloader_folder_download_failed, folderName)
}
notificationBuilder.run {
setContentText(message)
notificationManager.notify(notifyId, this.build())
}
NotificationUtils.cancelWithDelay(
notificationManager,
notifyId,
2000
)
}
private fun getResultText(result: RemoteOperationResult<*>, download: DownloadFileOperation): String {
return if (result.isSuccess) {
download.file.fileName
} else {
ErrorMessageAdapter.getErrorCauseMessage(
result,
download,
context.resources
)
ErrorMessageAdapter.getErrorCauseMessage(result, download, context.resources)
}
}
private fun getTickerId(isSuccess: Boolean, needsToUpdateCredentials: Boolean?): Int {
private fun getFolderResultText(isAnyOperationFailed: Boolean?, folder: OCFile): String {
return if (isAnyOperationFailed == false) {
context.getString(R.string.downloader_folder_downloaded, folder.fileName)
} else {
context.getString(R.string.downloader_folder_download_failed, folder.fileName)
}
}
private fun getTickerId(
isSuccess: Boolean?,
needsToUpdateCredentials: Boolean?,
folder: OCFile?,
isAnyOperationFailed: Boolean?
): Int {
return if (needsToUpdateCredentials == true) {
R.string.downloader_download_failed_credentials_error
} else {
if (isSuccess) {
R.string.downloader_download_succeeded_ticker
} else {
R.string.downloader_download_failed_ticker
}
folder?.let { getFolderTickerId(isAnyOperationFailed) } ?: getFileTickerId(isSuccess)
}
}
private fun getFileTickerId(isSuccess: Boolean?): Int {
return if (isSuccess == true) {
R.string.downloader_download_succeeded_ticker
} else {
R.string.downloader_download_failed_ticker
}
}
private fun getFolderTickerId(isAnyOperationFailed: Boolean?): Int {
return if (isAnyOperationFailed == false) {
R.string.downloader_folder_downloaded
} else {
R.string.downloader_folder_download_failed
}
}

View file

@ -145,7 +145,7 @@ class FileDownloadWorker(
}
private fun notifyForFolderResult(folder: OCFile) {
notificationManager.notifyForFolderResult(isAnyOperationFailed, folder.fileName)
notificationManager.notifyForResult(null, null, folder, isAnyOperationFailed)
}
private fun getRequestDownloads(): AbstractList<String> {
@ -370,7 +370,7 @@ class FileDownloadWorker(
}
if (folder == null) {
notifyForResult(downloadResult, download)
notifyForResult(downloadResult, download, null, null)
}
}
}