Explorar o código

Create user from accountName

Signed-off-by: alperozturk <alper_ozturk@proton.me>
alperozturk hai 1 ano
pai
achega
9f3e61cef3

+ 3 - 12
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<String> {
         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()) {

+ 1 - 1
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(),

+ 0 - 56
app/src/main/java/com/nextcloud/utils/InterfaceSerializer.java

@@ -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 <https://www.gnu.org/licenses/>.
- */
-
-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<T> implements JsonSerializer<T>, JsonDeserializer<T> {
-
-    private final Class<T> implementationClass;
-
-    private InterfaceSerializer(final Class<T> implementationClass) {
-        this.implementationClass = implementationClass;
-    }
-
-    public static <T> InterfaceSerializer<T> interfaceSerializer(final Class<T> 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);
-    }
-}