From 349bf1aa54c96abe467e40d2a1c3cb90e96b4e0f Mon Sep 17 00:00:00 2001 From: tobiasKaminsky Date: Tue, 11 Oct 2022 14:24:09 +0200 Subject: [PATCH] wip Signed-off-by: tobiasKaminsky --- app/build.gradle | 4 + .../webdav/ReadFilesystemOperationIT.kt | 30 +++++ .../application/NextcloudTalkApplication.kt | 4 +- .../filebrowser/models/BrowserFile.kt | 14 +-- .../models/properties/NCEncrypted.kt | 61 ---------- .../models/properties/NCPermission.kt | 63 ---------- .../models/properties/NCPreview.kt | 61 ---------- .../models/properties/OCFavorite.kt | 61 ---------- .../filebrowser/models/properties/OCId.kt | 61 ---------- .../filebrowser/models/properties/OCSize.kt | 61 ---------- .../filebrowser/webdav/DavUtils.java | 109 ------------------ .../webdav/ReadFilesystemOperation.java | 62 ++++++---- .../webdav/ReadFolderListingOperation.kt | 19 +-- .../upload/chunked/ChunkedFileUploader.kt | 15 +-- .../com/nextcloud/talk/utils/ApiUtils.java | 5 +- build.gradle | 1 + settings.gradle | 6 + 17 files changed, 109 insertions(+), 528 deletions(-) create mode 100644 app/src/androidTest/java/com/nextcloud/talk/components/filebrowser/webdav/ReadFilesystemOperationIT.kt delete mode 100644 app/src/main/java/com/nextcloud/talk/components/filebrowser/models/properties/NCEncrypted.kt delete mode 100644 app/src/main/java/com/nextcloud/talk/components/filebrowser/models/properties/NCPermission.kt delete mode 100644 app/src/main/java/com/nextcloud/talk/components/filebrowser/models/properties/NCPreview.kt delete mode 100644 app/src/main/java/com/nextcloud/talk/components/filebrowser/models/properties/OCFavorite.kt delete mode 100644 app/src/main/java/com/nextcloud/talk/components/filebrowser/models/properties/OCId.kt delete mode 100644 app/src/main/java/com/nextcloud/talk/components/filebrowser/models/properties/OCSize.kt delete mode 100644 app/src/main/java/com/nextcloud/talk/components/filebrowser/webdav/DavUtils.java diff --git a/app/build.gradle b/app/build.gradle index cdc3ee0ec..3132da757 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -311,6 +311,10 @@ dependencies { implementation 'com.github.nextcloud.android-common:ui:0.12.0' implementation 'com.github.nextcloud-deps:android-talk-webrtc:110.5481.0' + + implementation("com.github.nextcloud:android-library:$androidLibraryVersion") { + exclude group: 'org.ogce', module: 'xpp3' // unused in Android and brings wrong Junit version + } } task installGitHooks(type: Copy, group: "development") { diff --git a/app/src/androidTest/java/com/nextcloud/talk/components/filebrowser/webdav/ReadFilesystemOperationIT.kt b/app/src/androidTest/java/com/nextcloud/talk/components/filebrowser/webdav/ReadFilesystemOperationIT.kt new file mode 100644 index 000000000..74e75d7e4 --- /dev/null +++ b/app/src/androidTest/java/com/nextcloud/talk/components/filebrowser/webdav/ReadFilesystemOperationIT.kt @@ -0,0 +1,30 @@ +package com.nextcloud.talk.components.filebrowser.webdav + +import android.net.Uri +import androidx.test.platform.app.InstrumentationRegistry +import com.nextcloud.talk.components.filebrowser.models.BrowserFile +import com.nextcloud.talk.data.user.model.User +import junit.framework.Assert.assertEquals +import okhttp3.OkHttpClient +import org.junit.Test + +class ReadFilesystemOperationIT { + @Test + fun showContent() { + val arguments = InstrumentationRegistry.getArguments() + val url = Uri.parse(arguments.getString("TEST_SERVER_URL")) + val username = arguments.getString("TEST_SERVER_USERNAME") + val password = arguments.getString("TEST_SERVER_PASSWORD") + + val client = OkHttpClient() + val user = User().apply { + baseUrl = url.toString() + userId = username + this.username = username + token = password + } + val sut = ReadFilesystemOperation(client, user, "", 1) + val data = sut.readRemotePath().data as List + assertEquals(1, data.size) + } +} diff --git a/app/src/main/java/com/nextcloud/talk/application/NextcloudTalkApplication.kt b/app/src/main/java/com/nextcloud/talk/application/NextcloudTalkApplication.kt index 569747409..eb0eabd52 100644 --- a/app/src/main/java/com/nextcloud/talk/application/NextcloudTalkApplication.kt +++ b/app/src/main/java/com/nextcloud/talk/application/NextcloudTalkApplication.kt @@ -50,7 +50,6 @@ import coil.decode.SvgDecoder import coil.memory.MemoryCache import coil.util.DebugLogger import com.nextcloud.talk.BuildConfig -import com.nextcloud.talk.components.filebrowser.webdav.DavUtils import com.nextcloud.talk.dagger.modules.BusModule import com.nextcloud.talk.dagger.modules.ContextModule import com.nextcloud.talk.dagger.modules.DatabaseModule @@ -70,6 +69,7 @@ import com.nextcloud.talk.utils.database.arbitrarystorage.ArbitraryStorageModule import com.nextcloud.talk.utils.database.user.UserModule import com.nextcloud.talk.utils.preferences.AppPreferences import com.nextcloud.talk.webrtc.MagicWebRTCUtils +import com.owncloud.android.lib.common.network.WebdavUtils import com.vanniktech.emoji.EmojiManager import com.vanniktech.emoji.google.GoogleEmojiProvider import de.cotech.hw.SecurityKeyManager @@ -164,7 +164,7 @@ class NextcloudTalkApplication : MultiDexApplication(), LifecycleObserver { initializeWebRtc() buildComponent() - DavUtils.registerCustomFactories() + WebdavUtils.registerCustomFactories() componentApplication.inject(this) diff --git a/app/src/main/java/com/nextcloud/talk/components/filebrowser/models/BrowserFile.kt b/app/src/main/java/com/nextcloud/talk/components/filebrowser/models/BrowserFile.kt index 789987df7..4112a784a 100644 --- a/app/src/main/java/com/nextcloud/talk/components/filebrowser/models/BrowserFile.kt +++ b/app/src/main/java/com/nextcloud/talk/components/filebrowser/models/BrowserFile.kt @@ -30,13 +30,13 @@ import at.bitfire.dav4jvm.property.GetLastModified import at.bitfire.dav4jvm.property.ResourceType import at.bitfire.dav4jvm.property.ResourceType.Companion.COLLECTION import com.bluelinelabs.logansquare.annotation.JsonObject -import com.nextcloud.talk.components.filebrowser.models.properties.NCEncrypted -import com.nextcloud.talk.components.filebrowser.models.properties.NCPermission -import com.nextcloud.talk.components.filebrowser.models.properties.NCPreview -import com.nextcloud.talk.components.filebrowser.models.properties.OCFavorite import com.nextcloud.talk.components.filebrowser.models.properties.OCId import com.nextcloud.talk.components.filebrowser.models.properties.OCSize import com.nextcloud.talk.utils.Mimetype.FOLDER +import com.owncloud.android.lib.resources.files.webdav.NCEncrypted +import com.owncloud.android.lib.resources.files.webdav.NCFavorite +import com.owncloud.android.lib.resources.files.webdav.NCPermissions +import com.owncloud.android.lib.resources.files.webdav.NCPreview import kotlinx.parcelize.Parcelize import java.io.File @@ -101,7 +101,7 @@ data class BrowserFile( is NCPreview -> { browserFile.hasPreview = property.isNcPreview } - is OCFavorite -> { + is NCFavorite -> { browserFile.isFavorite = property.isOcFavorite } is DisplayName -> { @@ -110,8 +110,8 @@ data class BrowserFile( is NCEncrypted -> { browserFile.isEncrypted = property.isNcEncrypted } - is NCPermission -> { - browserFile.permissions = property.ncPermission + is NCPermissions -> { + browserFile.permissions = property.permissions } } } diff --git a/app/src/main/java/com/nextcloud/talk/components/filebrowser/models/properties/NCEncrypted.kt b/app/src/main/java/com/nextcloud/talk/components/filebrowser/models/properties/NCEncrypted.kt deleted file mode 100644 index adf28329e..000000000 --- a/app/src/main/java/com/nextcloud/talk/components/filebrowser/models/properties/NCEncrypted.kt +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Nextcloud Talk application - * - * @author Mario Danic - * @author Andy Scherzinger - * Copyright (C) 2021 Andy Scherzinger - * Copyright (C) 2017-2019 Mario Danic - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.nextcloud.talk.components.filebrowser.models.properties - -import android.text.TextUtils -import android.util.Log -import at.bitfire.dav4jvm.Property -import at.bitfire.dav4jvm.PropertyFactory -import at.bitfire.dav4jvm.XmlUtils.readText -import com.nextcloud.talk.components.filebrowser.webdav.DavUtils -import org.xmlpull.v1.XmlPullParser -import org.xmlpull.v1.XmlPullParserException -import java.io.IOException - -class NCEncrypted private constructor(var isNcEncrypted: Boolean) : Property { - - class Factory : PropertyFactory { - override fun create(parser: XmlPullParser): Property { - try { - val text = readText(parser) - if (!TextUtils.isEmpty(text)) { - return NCEncrypted("1" == text) - } - } catch (e: IOException) { - Log.e("NCEncrypted", "failed to create property", e) - } catch (e: XmlPullParserException) { - Log.e("NCEncrypted", "failed to create property", e) - } - return NCEncrypted(false) - } - - override fun getName(): Property.Name { - return NAME - } - } - - companion object { - @JvmField - val NAME: Property.Name = Property.Name(DavUtils.NC_NAMESPACE, DavUtils.EXTENDED_PROPERTY_IS_ENCRYPTED) - } -} diff --git a/app/src/main/java/com/nextcloud/talk/components/filebrowser/models/properties/NCPermission.kt b/app/src/main/java/com/nextcloud/talk/components/filebrowser/models/properties/NCPermission.kt deleted file mode 100644 index 1b888183f..000000000 --- a/app/src/main/java/com/nextcloud/talk/components/filebrowser/models/properties/NCPermission.kt +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Nextcloud Talk application - * - * @author Mario Danic - * @author Marcel Hibbe - * @author Andy Scherzinger - * Copyright (C) 2021 Andy Scherzinger - * Copyright (C) 2021 Marcel Hibbe - * Copyright (C) 2017-2019 Mario Danic - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.nextcloud.talk.components.filebrowser.models.properties - -import android.text.TextUtils -import android.util.Log -import at.bitfire.dav4jvm.Property -import at.bitfire.dav4jvm.PropertyFactory -import at.bitfire.dav4jvm.XmlUtils.readText -import com.nextcloud.talk.components.filebrowser.webdav.DavUtils -import org.xmlpull.v1.XmlPullParser -import org.xmlpull.v1.XmlPullParserException -import java.io.IOException - -class NCPermission private constructor(var ncPermission: String?) : Property { - - class Factory : PropertyFactory { - override fun create(parser: XmlPullParser): Property { - try { - val text = readText(parser) - if (!TextUtils.isEmpty(text)) { - return NCPermission(text) - } - } catch (e: IOException) { - Log.e("NCPermission", "failed to create property", e) - } catch (e: XmlPullParserException) { - Log.e("NCPermission", "failed to create property", e) - } - return NCPermission("") - } - - override fun getName(): Property.Name { - return NAME - } - } - - companion object { - @JvmField - val NAME: Property.Name = Property.Name(DavUtils.OC_NAMESPACE, DavUtils.EXTENDED_PROPERTY_NAME_PERMISSIONS) - } -} diff --git a/app/src/main/java/com/nextcloud/talk/components/filebrowser/models/properties/NCPreview.kt b/app/src/main/java/com/nextcloud/talk/components/filebrowser/models/properties/NCPreview.kt deleted file mode 100644 index a8bb67a6e..000000000 --- a/app/src/main/java/com/nextcloud/talk/components/filebrowser/models/properties/NCPreview.kt +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Nextcloud Talk application - * - * @author Mario Danic - * @author Andy Scherzinger - * Copyright (C) 2021 Andy Scherzinger - * Copyright (C) 2017-2019 Mario Danic - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.nextcloud.talk.components.filebrowser.models.properties - -import android.text.TextUtils -import android.util.Log -import at.bitfire.dav4jvm.Property -import at.bitfire.dav4jvm.PropertyFactory -import at.bitfire.dav4jvm.XmlUtils.readText -import com.nextcloud.talk.components.filebrowser.webdav.DavUtils -import org.xmlpull.v1.XmlPullParser -import org.xmlpull.v1.XmlPullParserException -import java.io.IOException - -class NCPreview private constructor(var isNcPreview: Boolean) : Property { - - class Factory : PropertyFactory { - override fun create(parser: XmlPullParser): Property { - try { - val text = readText(parser) - if (!TextUtils.isEmpty(text)) { - return NCPreview(java.lang.Boolean.parseBoolean(text)) - } - } catch (e: IOException) { - Log.e("NCPreview", "failed to create property", e) - } catch (e: XmlPullParserException) { - Log.e("NCPreview", "failed to create property", e) - } - return OCFavorite(false) - } - - override fun getName(): Property.Name { - return NAME - } - } - - companion object { - @JvmField - val NAME: Property.Name = Property.Name(DavUtils.NC_NAMESPACE, DavUtils.EXTENDED_PROPERTY_HAS_PREVIEW) - } -} diff --git a/app/src/main/java/com/nextcloud/talk/components/filebrowser/models/properties/OCFavorite.kt b/app/src/main/java/com/nextcloud/talk/components/filebrowser/models/properties/OCFavorite.kt deleted file mode 100644 index 3094a786e..000000000 --- a/app/src/main/java/com/nextcloud/talk/components/filebrowser/models/properties/OCFavorite.kt +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Nextcloud Talk application - * - * @author Mario Danic - * @author Andy Scherzinger - * Copyright (C) 2021 Andy Scherzinger - * Copyright (C) 2017-2019 Mario Danic - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.nextcloud.talk.components.filebrowser.models.properties - -import android.text.TextUtils -import android.util.Log -import at.bitfire.dav4jvm.Property -import at.bitfire.dav4jvm.PropertyFactory -import at.bitfire.dav4jvm.XmlUtils.readText -import com.nextcloud.talk.components.filebrowser.webdav.DavUtils -import org.xmlpull.v1.XmlPullParser -import org.xmlpull.v1.XmlPullParserException -import java.io.IOException - -class OCFavorite internal constructor(var isOcFavorite: Boolean) : Property { - - class Factory : PropertyFactory { - override fun create(parser: XmlPullParser): Property { - try { - val text = readText(parser) - if (!TextUtils.isEmpty(text)) { - return OCFavorite("1" == text) - } - } catch (e: IOException) { - Log.e("OCFavorite", "failed to create property", e) - } catch (e: XmlPullParserException) { - Log.e("OCFavorite", "failed to create property", e) - } - return OCFavorite(false) - } - - override fun getName(): Property.Name { - return NAME - } - } - - companion object { - @JvmField - val NAME: Property.Name = Property.Name(DavUtils.OC_NAMESPACE, DavUtils.EXTENDED_PROPERTY_FAVORITE) - } -} diff --git a/app/src/main/java/com/nextcloud/talk/components/filebrowser/models/properties/OCId.kt b/app/src/main/java/com/nextcloud/talk/components/filebrowser/models/properties/OCId.kt deleted file mode 100644 index 0eb92461b..000000000 --- a/app/src/main/java/com/nextcloud/talk/components/filebrowser/models/properties/OCId.kt +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Nextcloud Talk application - * - * @author Mario Danic - * @author Andy Scherzinger - * Copyright (C) 2021 Andy Scherzinger - * Copyright (C) 2017-2019 Mario Danic - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.nextcloud.talk.components.filebrowser.models.properties - -import android.text.TextUtils -import android.util.Log -import at.bitfire.dav4jvm.Property -import at.bitfire.dav4jvm.PropertyFactory -import at.bitfire.dav4jvm.XmlUtils.readText -import com.nextcloud.talk.components.filebrowser.webdav.DavUtils -import org.xmlpull.v1.XmlPullParser -import org.xmlpull.v1.XmlPullParserException -import java.io.IOException - -class OCId private constructor(var ocId: String?) : Property { - - class Factory : PropertyFactory { - override fun create(parser: XmlPullParser): Property { - try { - val text = readText(parser) - if (!TextUtils.isEmpty(text)) { - return OCId(text) - } - } catch (e: IOException) { - Log.e("OCId", "failed to create property", e) - } catch (e: XmlPullParserException) { - Log.e("OCId", "failed to create property", e) - } - return OCId("") - } - - override fun getName(): Property.Name { - return NAME - } - } - - companion object { - @JvmField - val NAME: Property.Name = Property.Name(DavUtils.OC_NAMESPACE, DavUtils.EXTENDED_PROPERTY_NAME_REMOTE_ID) - } -} diff --git a/app/src/main/java/com/nextcloud/talk/components/filebrowser/models/properties/OCSize.kt b/app/src/main/java/com/nextcloud/talk/components/filebrowser/models/properties/OCSize.kt deleted file mode 100644 index 951feec9d..000000000 --- a/app/src/main/java/com/nextcloud/talk/components/filebrowser/models/properties/OCSize.kt +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Nextcloud Talk application - * - * @author Mario Danic - * @author Andy Scherzinger - * Copyright (C) 2021 Andy Scherzinger - * Copyright (C) 2017-2019 Mario Danic - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.nextcloud.talk.components.filebrowser.models.properties - -import android.text.TextUtils -import android.util.Log -import at.bitfire.dav4jvm.Property -import at.bitfire.dav4jvm.PropertyFactory -import at.bitfire.dav4jvm.XmlUtils.readText -import com.nextcloud.talk.components.filebrowser.webdav.DavUtils -import org.xmlpull.v1.XmlPullParser -import org.xmlpull.v1.XmlPullParserException -import java.io.IOException - -class OCSize private constructor(var ocSize: Long) : Property { - - class Factory : PropertyFactory { - override fun create(parser: XmlPullParser): Property { - try { - val text = readText(parser) - if (!TextUtils.isEmpty(text)) { - return OCSize(text!!.toLong()) - } - } catch (e: IOException) { - Log.e("OCSize", "failed to create property", e) - } catch (e: XmlPullParserException) { - Log.e("OCSize", "failed to create property", e) - } - return OCSize(-1) - } - - override fun getName(): Property.Name { - return NAME - } - } - - companion object { - @JvmField - val NAME: Property.Name = Property.Name(DavUtils.OC_NAMESPACE, DavUtils.EXTENDED_PROPERTY_NAME_SIZE) - } -} diff --git a/app/src/main/java/com/nextcloud/talk/components/filebrowser/webdav/DavUtils.java b/app/src/main/java/com/nextcloud/talk/components/filebrowser/webdav/DavUtils.java deleted file mode 100644 index 6b18f5a32..000000000 --- a/app/src/main/java/com/nextcloud/talk/components/filebrowser/webdav/DavUtils.java +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Nextcloud Talk application - * - * @author Andy Scherzinger - * @author Mario Danic - * Copyright (C) 2022 Andy Scherzinger - * Copyright (C) 2017-2019 Mario Danic - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.nextcloud.talk.components.filebrowser.webdav; - -import com.nextcloud.talk.components.filebrowser.models.properties.NCEncrypted; -import com.nextcloud.talk.components.filebrowser.models.properties.NCPermission; -import com.nextcloud.talk.components.filebrowser.models.properties.NCPreview; -import com.nextcloud.talk.components.filebrowser.models.properties.OCFavorite; -import com.nextcloud.talk.components.filebrowser.models.properties.OCId; -import com.nextcloud.talk.components.filebrowser.models.properties.OCSize; - -import java.util.ArrayList; -import java.util.List; - -import at.bitfire.dav4jvm.Property; -import at.bitfire.dav4jvm.PropertyRegistry; -import at.bitfire.dav4jvm.property.CreationDate; -import at.bitfire.dav4jvm.property.DisplayName; -import at.bitfire.dav4jvm.property.GetContentLength; -import at.bitfire.dav4jvm.property.GetContentType; -import at.bitfire.dav4jvm.property.GetETag; -import at.bitfire.dav4jvm.property.GetLastModified; -import at.bitfire.dav4jvm.property.ResourceType; - -public class DavUtils { - - public static final String OC_NAMESPACE = "http://owncloud.org/ns"; - public static final String NC_NAMESPACE = "http://nextcloud.org/ns"; - public static final String DAV_PATH = "/remote.php/dav/files/"; - - public static final String EXTENDED_PROPERTY_NAME_PERMISSIONS = "permissions"; - public static final String EXTENDED_PROPERTY_NAME_REMOTE_ID = "id"; - public static final String EXTENDED_PROPERTY_NAME_SIZE = "size"; - public static final String EXTENDED_PROPERTY_FAVORITE = "favorite"; - public static final String EXTENDED_PROPERTY_IS_ENCRYPTED = "is-encrypted"; - public static final String EXTENDED_PROPERTY_MOUNT_TYPE = "mount-type"; - public static final String EXTENDED_PROPERTY_OWNER_ID = "owner-id"; - public static final String EXTENDED_PROPERTY_OWNER_DISPLAY_NAME = "owner-display-name"; - public static final String EXTENDED_PROPERTY_UNREAD_COMMENTS = "comments-unread"; - public static final String EXTENDED_PROPERTY_HAS_PREVIEW = "has-preview"; - public static final String EXTENDED_PROPERTY_NOTE = "note"; - - // public static final String TRASHBIN_FILENAME = "trashbin-filename"; - // public static final String TRASHBIN_ORIGINAL_LOCATION = "trashbin-original-location"; - // public static final String TRASHBIN_DELETION_TIME = "trashbin-deletion-time"; - - // public static final String PROPERTY_QUOTA_USED_BYTES = "quota-used-bytes"; - // public static final String PROPERTY_QUOTA_AVAILABLE_BYTES = "quota-available-bytes"; - - static Property.Name[] getAllPropSet() { - List props = new ArrayList<>(20); - - props.add(DisplayName.NAME); - props.add(GetContentType.NAME); - props.add(GetContentLength.NAME); - props.add(GetContentType.NAME); - props.add(GetContentLength.NAME); - props.add(GetLastModified.NAME); - props.add(CreationDate.NAME); - props.add(GetETag.NAME); - props.add(ResourceType.NAME); - - props.add(NCPermission.NAME); - props.add(OCId.NAME); - props.add(OCSize.NAME); - props.add(OCFavorite.NAME); - props.add(new Property.Name(OC_NAMESPACE, EXTENDED_PROPERTY_OWNER_ID)); - props.add(new Property.Name(OC_NAMESPACE, EXTENDED_PROPERTY_OWNER_DISPLAY_NAME)); - props.add(new Property.Name(OC_NAMESPACE, EXTENDED_PROPERTY_UNREAD_COMMENTS)); - - props.add(NCEncrypted.NAME); - props.add(new Property.Name(NC_NAMESPACE, EXTENDED_PROPERTY_MOUNT_TYPE)); - props.add(NCPreview.NAME); - props.add(new Property.Name(NC_NAMESPACE, EXTENDED_PROPERTY_NOTE)); - - return props.toArray(new Property.Name[0]); - } - - public static void registerCustomFactories() { - PropertyRegistry propertyRegistry = PropertyRegistry.INSTANCE; - - propertyRegistry.register(new OCId.Factory()); - propertyRegistry.register(new NCPreview.Factory()); - propertyRegistry.register(new NCEncrypted.Factory()); - propertyRegistry.register(new OCFavorite.Factory()); - propertyRegistry.register(new OCSize.Factory()); - propertyRegistry.register(new NCPermission.Factory()); - } -} diff --git a/app/src/main/java/com/nextcloud/talk/components/filebrowser/webdav/ReadFilesystemOperation.java b/app/src/main/java/com/nextcloud/talk/components/filebrowser/webdav/ReadFilesystemOperation.java index e07754e50..28e39b9e0 100644 --- a/app/src/main/java/com/nextcloud/talk/components/filebrowser/webdav/ReadFilesystemOperation.java +++ b/app/src/main/java/com/nextcloud/talk/components/filebrowser/webdav/ReadFilesystemOperation.java @@ -20,6 +20,7 @@ package com.nextcloud.talk.components.filebrowser.webdav; +import android.net.Uri; import android.util.Log; import com.nextcloud.talk.components.filebrowser.models.BrowserFile; @@ -27,6 +28,9 @@ import com.nextcloud.talk.components.filebrowser.models.DavResponse; import com.nextcloud.talk.dagger.modules.RestModule; import com.nextcloud.talk.data.user.model.User; import com.nextcloud.talk.utils.ApiUtils; +import com.owncloud.android.lib.common.network.WebdavUtils; +import com.owncloud.android.lib.common.utils.WebDavFileUtils; +import com.owncloud.android.lib.resources.files.model.RemoteFile; import java.io.IOException; import java.util.ArrayList; @@ -60,7 +64,7 @@ public class ReadFilesystemOperation { "Authorization") ); this.okHttpClient = okHttpClientBuilder.build(); - this.basePath = currentUser.getBaseUrl() + DavUtils.DAV_PATH + currentUser.getUserId(); + this.basePath = currentUser.getBaseUrl() + ApiUtils.filesApi + currentUser.getUserId(); this.url = basePath + path; this.depth = depth; } @@ -69,36 +73,46 @@ public class ReadFilesystemOperation { DavResponse davResponse = new DavResponse(); final List memberElements = new ArrayList<>(); final Response[] rootElement = new Response[1]; + final List browserFiles = new ArrayList<>(); + final List remoteFiles = new ArrayList<>(); try { - new DavResource(okHttpClient, HttpUrl.parse(url)).propfind(depth, DavUtils.getAllPropSet(), - new Function2() { - @Override - public Unit invoke(Response response, Response.HrefRelation hrefRelation) { - davResponse.setResponse(response); - switch (hrefRelation) { - case MEMBER: - memberElements.add(response); - break; - case SELF: - rootElement[0] = response; - break; - case OTHER: - default: - } - return Unit.INSTANCE; - } - }); + new DavResource(okHttpClient, HttpUrl.parse(url)).propfind(depth, WebdavUtils.getAllPropertiesList(), + new Function2() { + @Override + public Unit invoke(Response response, Response.HrefRelation hrefRelation) { + davResponse.setResponse(response); + switch (hrefRelation) { + case MEMBER: + memberElements.add(response); + break; + case SELF: + rootElement[0] = response; + break; + case OTHER: + default: + } + return Unit.INSTANCE; + } + }); } catch (IOException | DavException e) { Log.w(TAG, "Error reading remote path"); } - final List remoteFiles = new ArrayList<>(1 + memberElements.size()); - remoteFiles.add(BrowserFile.Companion.getModelFromResponse(rootElement[0], - rootElement[0].getHref().toString().substring(basePath.length()))); + WebDavFileUtils webDavFileUtils = new WebDavFileUtils(); + + browserFiles.add(BrowserFile.Companion.getModelFromResponse(rootElement[0], + rootElement[0].getHref().toString().substring(basePath.length()))); + + remoteFiles.add(webDavFileUtils.parseResponse(rootElement[0], + Uri.parse(basePath))); + for (Response memberElement : memberElements) { - remoteFiles.add(BrowserFile.Companion.getModelFromResponse(memberElement, - memberElement.getHref().toString().substring(basePath.length()))); + browserFiles.add(BrowserFile.Companion.getModelFromResponse(memberElement, + memberElement.getHref().toString().substring(basePath.length()))); + + remoteFiles.add(webDavFileUtils.parseResponse(memberElement, + Uri.parse(basePath))); } davResponse.setData(remoteFiles); diff --git a/app/src/main/java/com/nextcloud/talk/components/filebrowser/webdav/ReadFolderListingOperation.kt b/app/src/main/java/com/nextcloud/talk/components/filebrowser/webdav/ReadFolderListingOperation.kt index 293dfa925..819e4df00 100644 --- a/app/src/main/java/com/nextcloud/talk/components/filebrowser/webdav/ReadFolderListingOperation.kt +++ b/app/src/main/java/com/nextcloud/talk/components/filebrowser/webdav/ReadFolderListingOperation.kt @@ -34,10 +34,6 @@ import at.bitfire.dav4jvm.property.GetContentType import at.bitfire.dav4jvm.property.GetLastModified import at.bitfire.dav4jvm.property.ResourceType import com.nextcloud.talk.components.filebrowser.models.DavResponse -import com.nextcloud.talk.components.filebrowser.models.properties.NCEncrypted -import com.nextcloud.talk.components.filebrowser.models.properties.NCPermission -import com.nextcloud.talk.components.filebrowser.models.properties.NCPreview -import com.nextcloud.talk.components.filebrowser.models.properties.OCFavorite import com.nextcloud.talk.components.filebrowser.models.properties.OCId import com.nextcloud.talk.components.filebrowser.models.properties.OCSize import com.nextcloud.talk.dagger.modules.RestModule.HttpAuthenticator @@ -45,6 +41,11 @@ import com.nextcloud.talk.data.user.model.User import com.nextcloud.talk.remotefilebrowser.model.RemoteFileBrowserItem import com.nextcloud.talk.utils.ApiUtils import com.nextcloud.talk.utils.Mimetype.FOLDER +import com.owncloud.android.lib.common.network.WebdavUtils +import com.owncloud.android.lib.resources.files.webdav.NCEncrypted +import com.owncloud.android.lib.resources.files.webdav.NCFavorite +import com.owncloud.android.lib.resources.files.webdav.NCPermissions +import com.owncloud.android.lib.resources.files.webdav.NCPreview import okhttp3.HttpUrl.Companion.toHttpUrlOrNull import okhttp3.OkHttpClient import java.io.File @@ -70,7 +71,7 @@ class ReadFolderListingOperation(okHttpClient: OkHttpClient, currentUser: User, ) ) this.okHttpClient = okHttpClientBuilder.build() - basePath = currentUser.baseUrl + DavUtils.DAV_PATH + currentUser.userId + basePath = currentUser.baseUrl + ApiUtils.filesApi + currentUser.userId url = basePath + path this.depth = depth } @@ -86,7 +87,7 @@ class ReadFolderListingOperation(okHttpClient: OkHttpClient, currentUser: User, url.toHttpUrlOrNull()!! ).propfind( depth = depth, - reqProp = DavUtils.getAllPropSet() + reqProp = WebdavUtils.getAllPropertiesList() ) { response: Response, hrefRelation: HrefRelation? -> davResponse.setResponse(response) when (hrefRelation) { @@ -158,7 +159,7 @@ class ReadFolderListingOperation(okHttpClient: OkHttpClient, currentUser: User, is NCPreview -> { remoteFileBrowserItem.hasPreview = property.isNcPreview } - is OCFavorite -> { + is NCFavorite -> { remoteFileBrowserItem.isFavorite = property.isOcFavorite } is DisplayName -> { @@ -167,8 +168,8 @@ class ReadFolderListingOperation(okHttpClient: OkHttpClient, currentUser: User, is NCEncrypted -> { remoteFileBrowserItem.isEncrypted = property.isNcEncrypted } - is NCPermission -> { - remoteFileBrowserItem.permissions = property.ncPermission + is NCPermissions -> { + remoteFileBrowserItem.permissions = property.permissions } } } diff --git a/app/src/main/java/com/nextcloud/talk/upload/chunked/ChunkedFileUploader.kt b/app/src/main/java/com/nextcloud/talk/upload/chunked/ChunkedFileUploader.kt index 018305951..a2f9be77a 100644 --- a/app/src/main/java/com/nextcloud/talk/upload/chunked/ChunkedFileUploader.kt +++ b/app/src/main/java/com/nextcloud/talk/upload/chunked/ChunkedFileUploader.kt @@ -41,10 +41,6 @@ import at.bitfire.dav4jvm.property.ResourceType import autodagger.AutoInjector import com.nextcloud.talk.application.NextcloudTalkApplication import com.nextcloud.talk.components.filebrowser.models.DavResponse -import com.nextcloud.talk.components.filebrowser.models.properties.NCEncrypted -import com.nextcloud.talk.components.filebrowser.models.properties.NCPermission -import com.nextcloud.talk.components.filebrowser.models.properties.NCPreview -import com.nextcloud.talk.components.filebrowser.models.properties.OCFavorite import com.nextcloud.talk.components.filebrowser.models.properties.OCId import com.nextcloud.talk.components.filebrowser.models.properties.OCSize import com.nextcloud.talk.dagger.modules.RestModule @@ -54,6 +50,10 @@ import com.nextcloud.talk.remotefilebrowser.model.RemoteFileBrowserItem import com.nextcloud.talk.utils.ApiUtils import com.nextcloud.talk.utils.FileUtils import com.nextcloud.talk.utils.Mimetype +import com.owncloud.android.lib.resources.files.webdav.NCEncrypted +import com.owncloud.android.lib.resources.files.webdav.NCFavorite +import com.owncloud.android.lib.resources.files.webdav.NCPermissions +import com.owncloud.android.lib.resources.files.webdav.NCPreview import okhttp3.HttpUrl.Companion.toHttpUrlOrNull import okhttp3.MediaType import okhttp3.OkHttpClient @@ -355,6 +355,7 @@ class ChunkedFileUploader( } @Suppress("Detekt.ComplexMethod") + // TODO remove all of them and combine in library! private fun mapPropertyToBrowserFile(property: Property, remoteFileBrowserItem: RemoteFileBrowserItem) { when (property) { is OCId -> { @@ -375,7 +376,7 @@ class ChunkedFileUploader( is NCPreview -> { remoteFileBrowserItem.hasPreview = property.isNcPreview } - is OCFavorite -> { + is NCFavorite -> { remoteFileBrowserItem.isFavorite = property.isOcFavorite } is DisplayName -> { @@ -384,8 +385,8 @@ class ChunkedFileUploader( is NCEncrypted -> { remoteFileBrowserItem.isEncrypted = property.isNcEncrypted } - is NCPermission -> { - remoteFileBrowserItem.permissions = property.ncPermission + is NCPermissions -> { + remoteFileBrowserItem.permissions = property.permissions } } } diff --git a/app/src/main/java/com/nextcloud/talk/utils/ApiUtils.java b/app/src/main/java/com/nextcloud/talk/utils/ApiUtils.java index 4b0ec13d9..35aa7e75e 100644 --- a/app/src/main/java/com/nextcloud/talk/utils/ApiUtils.java +++ b/app/src/main/java/com/nextcloud/talk/utils/ApiUtils.java @@ -52,6 +52,7 @@ public class ApiUtils { private static final String ocsApiVersion = "/ocs/v2.php"; private static final String spreedApiVersion = "/apps/spreed/api/v1"; private static final String spreedApiBase = ocsApiVersion + "/apps/spreed/api/v"; + public static final String filesApi = "/remote.php/dav/files/"; private static final String userAgent = "Mozilla/5.0 (Android) Nextcloud-Talk v"; @@ -421,7 +422,7 @@ public class ApiUtils { } public static String getUrlForFileUpload(String baseUrl, String user, String remotePath) { - return baseUrl + "/remote.php/dav/files/" + user + remotePath; + return baseUrl + filesApi + user + remotePath; } public static String getUrlForChunkedUpload(String baseUrl, String user) { @@ -429,7 +430,7 @@ public class ApiUtils { } public static String getUrlForFileDownload(String baseUrl, String user, String remotePath) { - return baseUrl + "/remote.php/dav/files/" + user + "/" + remotePath; + return baseUrl + filesApi + user + "/" + remotePath; } public static String getUrlForTempAvatar(String baseUrl) { diff --git a/build.gradle b/build.gradle index 01f942742..40aa24cb8 100644 --- a/build.gradle +++ b/build.gradle @@ -25,6 +25,7 @@ buildscript { ext { kotlinVersion = '1.9.10' + androidLibraryVersion = "master-SNAPSHOT" } repositories { diff --git a/settings.gradle b/settings.gradle index 7cf8a9b08..a3d72a3ef 100644 --- a/settings.gradle +++ b/settings.gradle @@ -32,3 +32,9 @@ include ':app' // substitute module('com.github.nextcloud-deps:ImagePicker') using project(':imagepicker') // } //} + +includeBuild('../android-library') { + dependencySubstitution { + substitute module('com.github.nextcloud:android-library') using project(':library') + } +}