Skip to content

Commit

Permalink
Fix code analytics
Browse files Browse the repository at this point in the history
Signed-off-by: alperozturk <[email protected]>
  • Loading branch information
alperozturk96 committed Jan 4, 2024
1 parent 857d479 commit d61fb06
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand All @@ -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))
Expand All @@ -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)
ErrorMessageAdapter.getErrorCauseMessage(result, download, context.resources)
}
}

notificationBuilder.run {
setContentText(message)
notificationManager.notify(notifyId, this.build())
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)
}
}

NotificationUtils.cancelWithDelay(
notificationManager,
notifyId,
2000
)
private fun getTickerId(
isSuccess: Boolean?,
needsToUpdateCredentials: Boolean?,
folder: OCFile?,
isAnyOperationFailed: Boolean?
): Int {
return if (needsToUpdateCredentials == true) {
R.string.downloader_download_failed_credentials_error
} else {
folder?.let { getFolderTickerId(isAnyOperationFailed) } ?: getFileTickerId(isSuccess)
}
}

private fun getResultText(result: RemoteOperationResult<*>, download: DownloadFileOperation): String {
return if (result.isSuccess) {
download.file.fileName
private fun getFileTickerId(isSuccess: Boolean?): Int {
return if (isSuccess == true) {
R.string.downloader_download_succeeded_ticker
} else {
ErrorMessageAdapter.getErrorCauseMessage(
result,
download,
context.resources
)
R.string.downloader_download_failed_ticker
}
}

private fun getTickerId(isSuccess: Boolean, needsToUpdateCredentials: Boolean?): Int {
return if (needsToUpdateCredentials == true) {
R.string.downloader_download_failed_credentials_error
private fun getFolderTickerId(isAnyOperationFailed: Boolean?): Int {
return if (isAnyOperationFailed == false) {
R.string.downloader_folder_downloaded
} else {
if (isSuccess) {
R.string.downloader_download_succeeded_ticker
} else {
R.string.downloader_download_failed_ticker
}
R.string.downloader_folder_download_failed
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down Expand Up @@ -370,7 +370,7 @@ class FileDownloadWorker(
}

if (folder == null) {
notifyForResult(downloadResult, download)
notifyForResult(downloadResult, download, null, null)
}
}
}
Expand Down

0 comments on commit d61fb06

Please sign in to comment.