replace too long paramter lists with data classes

Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
This commit is contained in:
Andy Scherzinger 2022-03-11 18:29:39 +01:00
parent 6e02c5de41
commit ba3e24bbc7
No known key found for this signature in database
GPG Key ID: 6CADC7E3523C308B
2 changed files with 45 additions and 25 deletions

View File

@ -99,10 +99,18 @@ class UploadAndShareFilesWorker(val context: Context, workerParameters: WorkerPa
checkNotNull(roomToken)
for (index in sourcefiles.indices) {
val sourcefileUri = Uri.parse(sourcefiles[index])
val filename = UriUtils.getFileName(sourcefileUri, context)
val requestBody = createRequestBody(sourcefileUri)
uploadFile(currentUser, ncTargetpath, filename, roomToken, requestBody, sourcefileUri, metaData)
val sourceFileUri = Uri.parse(sourcefiles[index])
uploadFile(
currentUser!!,
UploadItem(
sourceFileUri,
UriUtils.getFileName(sourceFileUri, context),
createRequestBody(sourceFileUri)
),
ncTargetpath,
roomToken,
metaData
)
}
} catch (e: IllegalStateException) {
Log.e(javaClass.simpleName, "Something went wrong when trying to upload file", e)
@ -130,17 +138,15 @@ class UploadAndShareFilesWorker(val context: Context, workerParameters: WorkerPa
private fun uploadFile(
currentUser: UserEntity,
ncTargetpath: String?,
filename: String,
uploadItem: UploadItem,
ncTargetPath: String?,
roomToken: String?,
requestBody: RequestBody?,
sourcefileUri: Uri,
metaData: String?
) {
ncApi.uploadFile(
ApiUtils.getCredentials(currentUser.username, currentUser.token),
ApiUtils.getUrlForFileUpload(currentUser.baseUrl, currentUser.userId, ncTargetpath, filename),
requestBody
ApiUtils.getUrlForFileUpload(currentUser.baseUrl, currentUser.userId, ncTargetPath, uploadItem.fileName),
uploadItem.requestBody
)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
@ -154,12 +160,12 @@ class UploadAndShareFilesWorker(val context: Context, workerParameters: WorkerPa
}
override fun onError(e: Throwable) {
Log.e(TAG, "failed to upload file $filename")
Log.e(TAG, "failed to upload file ${uploadItem.fileName}")
}
override fun onComplete() {
shareFile(roomToken, currentUser, ncTargetpath, filename, metaData)
copyFileToCache(sourcefileUri, filename)
shareFile(roomToken, currentUser, ncTargetPath, uploadItem.fileName, metaData)
copyFileToCache(uploadItem.uri, uploadItem.fileName)
}
})
}
@ -274,4 +280,10 @@ class UploadAndShareFilesWorker(val context: Context, workerParameters: WorkerPa
}
}
}
private data class UploadItem(
val uri: Uri,
val fileName: String,
val requestBody: RequestBody?,
)
}

View File

@ -2,6 +2,8 @@
* Nextcloud Talk application
*
* @author Mario Danic
* @author Andy Scherzinger
* Copyright (C) 2021 Andy Scherzinger <info@andy-scherzinger.de>
* Copyright (C) 2017 Mario Danic <mario@lovelyhq.com>
*
* This program is free software: you can redistribute it and/or modify
@ -62,9 +64,7 @@ object NotificationUtils {
@TargetApi(Build.VERSION_CODES.O)
private fun createNotificationChannel(
context: Context,
channelId: String,
channelName: String,
channelDescription: String,
notificationChannel: Channel,
sound: Uri?,
audioAttributes: AudioAttributes
) {
@ -73,14 +73,14 @@ object NotificationUtils {
if (
Build.VERSION.SDK_INT >= Build.VERSION_CODES.O &&
notificationManager.getNotificationChannel(channelId) == null
notificationManager.getNotificationChannel(notificationChannel.id) == null
) {
val channel = NotificationChannel(
channelId, channelName,
notificationChannel.id, notificationChannel.name,
NotificationManager.IMPORTANCE_HIGH
)
channel.description = channelDescription
channel.description = notificationChannel.description
channel.enableLights(true)
channel.lightColor = R.color.colorPrimary
channel.setSound(sound, audioAttributes)
@ -103,9 +103,10 @@ object NotificationUtils {
createNotificationChannel(
context,
NOTIFICATION_CHANNEL_CALLS_V4,
context.resources.getString(R.string.nc_notification_channel_calls),
context.resources.getString(R.string.nc_notification_channel_calls_description),
Channel(
NOTIFICATION_CHANNEL_CALLS_V4,
context.resources.getString(R.string.nc_notification_channel_calls),
context.resources.getString(R.string.nc_notification_channel_calls_description)),
soundUri,
audioAttributes
)
@ -124,9 +125,10 @@ object NotificationUtils {
createNotificationChannel(
context,
NOTIFICATION_CHANNEL_MESSAGES_V4,
context.resources.getString(R.string.nc_notification_channel_messages),
context.resources.getString(R.string.nc_notification_channel_messages_description),
Channel(
NOTIFICATION_CHANNEL_MESSAGES_V4,
context.resources.getString(R.string.nc_notification_channel_messages),
context.resources.getString(R.string.nc_notification_channel_messages_description)),
soundUri,
audioAttributes
)
@ -322,4 +324,10 @@ object NotificationUtils {
appPreferences.messageRingtoneUri, DEFAULT_MESSAGE_RINGTONE_URI, NOTIFICATION_CHANNEL_MESSAGES_V4
)
}
private data class Channel(
val id: String,
val name: String,
val description: String
)
}