mirror of
https://github.com/nextcloud/talk-android
synced 2025-06-21 20:49:36 +01:00
replace too long paramter lists with data classes
Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
This commit is contained in:
parent
6e02c5de41
commit
ba3e24bbc7
@ -99,10 +99,18 @@ class UploadAndShareFilesWorker(val context: Context, workerParameters: WorkerPa
|
|||||||
checkNotNull(roomToken)
|
checkNotNull(roomToken)
|
||||||
|
|
||||||
for (index in sourcefiles.indices) {
|
for (index in sourcefiles.indices) {
|
||||||
val sourcefileUri = Uri.parse(sourcefiles[index])
|
val sourceFileUri = Uri.parse(sourcefiles[index])
|
||||||
val filename = UriUtils.getFileName(sourcefileUri, context)
|
uploadFile(
|
||||||
val requestBody = createRequestBody(sourcefileUri)
|
currentUser!!,
|
||||||
uploadFile(currentUser, ncTargetpath, filename, roomToken, requestBody, sourcefileUri, metaData)
|
UploadItem(
|
||||||
|
sourceFileUri,
|
||||||
|
UriUtils.getFileName(sourceFileUri, context),
|
||||||
|
createRequestBody(sourceFileUri)
|
||||||
|
),
|
||||||
|
ncTargetpath,
|
||||||
|
roomToken,
|
||||||
|
metaData
|
||||||
|
)
|
||||||
}
|
}
|
||||||
} catch (e: IllegalStateException) {
|
} catch (e: IllegalStateException) {
|
||||||
Log.e(javaClass.simpleName, "Something went wrong when trying to upload file", e)
|
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(
|
private fun uploadFile(
|
||||||
currentUser: UserEntity,
|
currentUser: UserEntity,
|
||||||
ncTargetpath: String?,
|
uploadItem: UploadItem,
|
||||||
filename: String,
|
ncTargetPath: String?,
|
||||||
roomToken: String?,
|
roomToken: String?,
|
||||||
requestBody: RequestBody?,
|
|
||||||
sourcefileUri: Uri,
|
|
||||||
metaData: String?
|
metaData: String?
|
||||||
) {
|
) {
|
||||||
ncApi.uploadFile(
|
ncApi.uploadFile(
|
||||||
ApiUtils.getCredentials(currentUser.username, currentUser.token),
|
ApiUtils.getCredentials(currentUser.username, currentUser.token),
|
||||||
ApiUtils.getUrlForFileUpload(currentUser.baseUrl, currentUser.userId, ncTargetpath, filename),
|
ApiUtils.getUrlForFileUpload(currentUser.baseUrl, currentUser.userId, ncTargetPath, uploadItem.fileName),
|
||||||
requestBody
|
uploadItem.requestBody
|
||||||
)
|
)
|
||||||
.subscribeOn(Schedulers.io())
|
.subscribeOn(Schedulers.io())
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
@ -154,12 +160,12 @@ class UploadAndShareFilesWorker(val context: Context, workerParameters: WorkerPa
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onError(e: Throwable) {
|
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() {
|
override fun onComplete() {
|
||||||
shareFile(roomToken, currentUser, ncTargetpath, filename, metaData)
|
shareFile(roomToken, currentUser, ncTargetPath, uploadItem.fileName, metaData)
|
||||||
copyFileToCache(sourcefileUri, filename)
|
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?,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
* Nextcloud Talk application
|
* Nextcloud Talk application
|
||||||
*
|
*
|
||||||
* @author Mario Danic
|
* @author Mario Danic
|
||||||
|
* @author Andy Scherzinger
|
||||||
|
* Copyright (C) 2021 Andy Scherzinger <info@andy-scherzinger.de>
|
||||||
* Copyright (C) 2017 Mario Danic <mario@lovelyhq.com>
|
* Copyright (C) 2017 Mario Danic <mario@lovelyhq.com>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
@ -62,9 +64,7 @@ object NotificationUtils {
|
|||||||
@TargetApi(Build.VERSION_CODES.O)
|
@TargetApi(Build.VERSION_CODES.O)
|
||||||
private fun createNotificationChannel(
|
private fun createNotificationChannel(
|
||||||
context: Context,
|
context: Context,
|
||||||
channelId: String,
|
notificationChannel: Channel,
|
||||||
channelName: String,
|
|
||||||
channelDescription: String,
|
|
||||||
sound: Uri?,
|
sound: Uri?,
|
||||||
audioAttributes: AudioAttributes
|
audioAttributes: AudioAttributes
|
||||||
) {
|
) {
|
||||||
@ -73,14 +73,14 @@ object NotificationUtils {
|
|||||||
|
|
||||||
if (
|
if (
|
||||||
Build.VERSION.SDK_INT >= Build.VERSION_CODES.O &&
|
Build.VERSION.SDK_INT >= Build.VERSION_CODES.O &&
|
||||||
notificationManager.getNotificationChannel(channelId) == null
|
notificationManager.getNotificationChannel(notificationChannel.id) == null
|
||||||
) {
|
) {
|
||||||
val channel = NotificationChannel(
|
val channel = NotificationChannel(
|
||||||
channelId, channelName,
|
notificationChannel.id, notificationChannel.name,
|
||||||
NotificationManager.IMPORTANCE_HIGH
|
NotificationManager.IMPORTANCE_HIGH
|
||||||
)
|
)
|
||||||
|
|
||||||
channel.description = channelDescription
|
channel.description = notificationChannel.description
|
||||||
channel.enableLights(true)
|
channel.enableLights(true)
|
||||||
channel.lightColor = R.color.colorPrimary
|
channel.lightColor = R.color.colorPrimary
|
||||||
channel.setSound(sound, audioAttributes)
|
channel.setSound(sound, audioAttributes)
|
||||||
@ -103,9 +103,10 @@ object NotificationUtils {
|
|||||||
|
|
||||||
createNotificationChannel(
|
createNotificationChannel(
|
||||||
context,
|
context,
|
||||||
NOTIFICATION_CHANNEL_CALLS_V4,
|
Channel(
|
||||||
context.resources.getString(R.string.nc_notification_channel_calls),
|
NOTIFICATION_CHANNEL_CALLS_V4,
|
||||||
context.resources.getString(R.string.nc_notification_channel_calls_description),
|
context.resources.getString(R.string.nc_notification_channel_calls),
|
||||||
|
context.resources.getString(R.string.nc_notification_channel_calls_description)),
|
||||||
soundUri,
|
soundUri,
|
||||||
audioAttributes
|
audioAttributes
|
||||||
)
|
)
|
||||||
@ -124,9 +125,10 @@ object NotificationUtils {
|
|||||||
|
|
||||||
createNotificationChannel(
|
createNotificationChannel(
|
||||||
context,
|
context,
|
||||||
NOTIFICATION_CHANNEL_MESSAGES_V4,
|
Channel(
|
||||||
context.resources.getString(R.string.nc_notification_channel_messages),
|
NOTIFICATION_CHANNEL_MESSAGES_V4,
|
||||||
context.resources.getString(R.string.nc_notification_channel_messages_description),
|
context.resources.getString(R.string.nc_notification_channel_messages),
|
||||||
|
context.resources.getString(R.string.nc_notification_channel_messages_description)),
|
||||||
soundUri,
|
soundUri,
|
||||||
audioAttributes
|
audioAttributes
|
||||||
)
|
)
|
||||||
@ -322,4 +324,10 @@ object NotificationUtils {
|
|||||||
appPreferences.messageRingtoneUri, DEFAULT_MESSAGE_RINGTONE_URI, NOTIFICATION_CHANNEL_MESSAGES_V4
|
appPreferences.messageRingtoneUri, DEFAULT_MESSAGE_RINGTONE_URI, NOTIFICATION_CHANNEL_MESSAGES_V4
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private data class Channel(
|
||||||
|
val id: String,
|
||||||
|
val name: String,
|
||||||
|
val description: String
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user