diff --git a/app/src/main/java/com/nextcloud/client/files/downloader/FilesDownloadWorker.kt b/app/src/main/java/com/nextcloud/client/files/downloader/FilesDownloadWorker.kt index d81c61358b..2b76379698 100644 --- a/app/src/main/java/com/nextcloud/client/files/downloader/FilesDownloadWorker.kt +++ b/app/src/main/java/com/nextcloud/client/files/downloader/FilesDownloadWorker.kt @@ -39,12 +39,9 @@ import androidx.localbroadcastmanager.content.LocalBroadcastManager import androidx.work.Worker import androidx.work.WorkerParameters import com.google.gson.Gson -import com.google.gson.GsonBuilder import com.nextcloud.client.account.User import com.nextcloud.client.account.UserAccountManager import com.nextcloud.java.util.Optional -import com.nextcloud.utils.InterfaceSerializer -import com.nextcloud.utils.InterfaceSerializer.interfaceSerializer import com.owncloud.android.R import com.owncloud.android.authentication.AuthenticatorActivity import com.owncloud.android.datamodel.FileDataStorageManager @@ -88,7 +85,7 @@ class FilesDownloadWorker( companion object { private val TAG = FilesDownloadWorker::class.java.simpleName - const val USER = "USER" + const val USER_NAME = "USER" const val FILE = "FILE" const val BEHAVIOUR = "BEHAVIOUR" const val DOWNLOAD_TYPE = "DOWNLOAD_TYPE" @@ -146,17 +143,11 @@ class FilesDownloadWorker( } } - // FIXME stackoverflow - private fun getUserGson(): Gson { - return GsonBuilder() - .registerTypeAdapter(User::class.java, interfaceSerializer(User::class.java)) - .create() - } - private fun getRequestDownloads(): AbstractList { conflictUploadId = inputData.keyValueMap[CONFLICT_UPLOAD_ID] as Long? val file = gson.fromJson(inputData.keyValueMap[FILE] as String, OCFile::class.java) - val user = getUserGson().fromJson(inputData.keyValueMap[USER] as String, User::class.java) + val accountName = inputData.keyValueMap[USER_NAME] as String + val user = accountManager.getUser(accountName).get() val downloadTypeAsString = inputData.keyValueMap[DOWNLOAD_TYPE] as String? val downloadType = if (downloadTypeAsString != null) { if (downloadTypeAsString == DownloadType.DOWNLOAD.toString()) { diff --git a/app/src/main/java/com/nextcloud/client/jobs/BackgroundJobManagerImpl.kt b/app/src/main/java/com/nextcloud/client/jobs/BackgroundJobManagerImpl.kt index e1ea1a2957..bad195010b 100644 --- a/app/src/main/java/com/nextcloud/client/jobs/BackgroundJobManagerImpl.kt +++ b/app/src/main/java/com/nextcloud/client/jobs/BackgroundJobManagerImpl.kt @@ -521,7 +521,7 @@ internal class BackgroundJobManagerImpl( val gson = Gson() val data = workDataOf( - FilesDownloadWorker.USER to gson.toJson(user), + FilesDownloadWorker.USER_NAME to user.accountName, FilesDownloadWorker.FILE to gson.toJson(ocFile), FilesDownloadWorker.BEHAVIOUR to behaviour, FilesDownloadWorker.DOWNLOAD_TYPE to downloadType.toString(), diff --git a/app/src/main/java/com/nextcloud/utils/InterfaceSerializer.java b/app/src/main/java/com/nextcloud/utils/InterfaceSerializer.java deleted file mode 100644 index da253c14d9..0000000000 --- a/app/src/main/java/com/nextcloud/utils/InterfaceSerializer.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Nextcloud Android client application - * - * @author Alper Ozturk - * Copyright (C) 2023 Alper Ozturk - * Copyright (C) 2023 Nextcloud GmbH - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package com.nextcloud.utils; - -import com.google.gson.JsonDeserializationContext; -import com.google.gson.JsonDeserializer; -import com.google.gson.JsonElement; -import com.google.gson.JsonSerializationContext; -import com.google.gson.JsonSerializer; - -import java.lang.reflect.Type; - -final public class InterfaceSerializer implements JsonSerializer, JsonDeserializer { - - private final Class implementationClass; - - private InterfaceSerializer(final Class implementationClass) { - this.implementationClass = implementationClass; - } - - public static InterfaceSerializer interfaceSerializer(final Class implementationClass) { - return new InterfaceSerializer<>(implementationClass); - } - - @Override - public JsonElement serialize(final T value, final Type type, final JsonSerializationContext context) { - final Type targetType = value != null - ? value.getClass() - : type; - return context.serialize(value, targetType); - } - - @Override - public T deserialize(final JsonElement jsonElement, final Type typeOfT, final JsonDeserializationContext context) { - return context.deserialize(jsonElement, implementationClass); - } -}