diff --git a/app/build.gradle b/app/build.gradle index cdc3ee0ecd0..d469baca587 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -143,7 +143,7 @@ ext { daggerVersion = "2.48.1" emojiVersion = "1.4.0" lifecycleVersion = '2.6.2' - okhttpVersion = "4.11.0" + okhttpVersion = "5.0.0-alpha.10" markwonVersion = "4.6.2" materialDialogsVersion = "3.3.0" parcelerVersion = "1.1.13" @@ -184,9 +184,6 @@ dependencies { implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0' androidTestImplementation "androidx.work:work-testing:${workVersion}" implementation 'com.google.android.flexbox:flexbox:3.0.0' - implementation ('com.gitlab.bitfireAT:dav4jvm:2.1.3', { - exclude group: 'org.ogce', module: 'xpp3' // Android comes with its own XmlPullParser - }) implementation 'org.conscrypt:conscrypt-android:2.5.2' implementation "androidx.camera:camera-core:${androidxCameraVersion}" @@ -311,6 +308,10 @@ dependencies { implementation 'com.github.nextcloud.android-common:ui:0.12.0' implementation 'com.github.nextcloud-deps:android-talk-webrtc:110.5481.0' + + api("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 00000000000..792b45ecb9a --- /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/adapters/messages/PreviewMessageViewHolder.kt b/app/src/main/java/com/nextcloud/talk/adapters/messages/PreviewMessageViewHolder.kt index edc73786664..487e68474db 100644 --- a/app/src/main/java/com/nextcloud/talk/adapters/messages/PreviewMessageViewHolder.kt +++ b/app/src/main/java/com/nextcloud/talk/adapters/messages/PreviewMessageViewHolder.kt @@ -44,7 +44,6 @@ import com.nextcloud.android.common.ui.theme.utils.ColorRole import com.nextcloud.talk.R import com.nextcloud.talk.application.NextcloudTalkApplication import com.nextcloud.talk.application.NextcloudTalkApplication.Companion.sharedApplication -import com.nextcloud.talk.components.filebrowser.models.BrowserFile import com.nextcloud.talk.components.filebrowser.webdav.ReadFilesystemOperation import com.nextcloud.talk.data.user.model.User import com.nextcloud.talk.databinding.ReactionsInsideMessageBinding @@ -56,6 +55,7 @@ import com.nextcloud.talk.utils.DisplayUtils import com.nextcloud.talk.utils.DrawableUtils.getDrawableResourceIdForMimeType import com.nextcloud.talk.utils.FileViewerUtils import com.nextcloud.talk.utils.FileViewerUtils.ProgressUi +import com.owncloud.android.lib.resources.files.model.RemoteFile import com.stfalcon.chatkit.messages.MessageHolders.IncomingImageMessageViewHolder import io.reactivex.Single import io.reactivex.SingleObserver @@ -287,7 +287,7 @@ abstract class PreviewMessageViewHolder(itemView: View?, payload: Any?) : override fun onSuccess(readFilesystemOperation: ReadFilesystemOperation) { val davResponse = readFilesystemOperation.readRemotePath() if (davResponse.data != null) { - val browserFileList = davResponse.data as List + val browserFileList = davResponse.data as List if (browserFileList.isNotEmpty()) { Handler(context!!.mainLooper).post { val resourceId = getDrawableResourceIdForMimeType(browserFileList[0].mimeType) 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 56974740942..eb0eabd52f0 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 789987df733..48812c9f718 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,18 +30,19 @@ 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 @Parcelize @JsonObject +@Deprecated("Use library", replaceWith = ReplaceWith("RemoteFile")) data class BrowserFile( var path: String? = null, var displayName: String? = null, @@ -93,7 +94,7 @@ data class BrowserFile( browserFile.modifiedTimestamp = property.lastModified } is GetContentType -> { - browserFile.mimeType = property.type + browserFile.mimeType = property.type?.toString() } is OCSize -> { browserFile.size = property.ocSize @@ -101,7 +102,7 @@ data class BrowserFile( is NCPreview -> { browserFile.hasPreview = property.isNcPreview } - is OCFavorite -> { + is NCFavorite -> { browserFile.isFavorite = property.isOcFavorite } is DisplayName -> { @@ -110,8 +111,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 adf28329e2c..00000000000 --- 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 1b888183fcc..00000000000 --- 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 a8bb67a6e80..00000000000 --- 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 3094a786e89..00000000000 --- 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 0eb92461b9b..00000000000 --- 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 951feec9def..00000000000 --- 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 6b18f5a3257..00000000000 --- 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 e07754e503a..5d7f9cb827e 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,23 +20,26 @@ package com.nextcloud.talk.components.filebrowser.webdav; +import android.net.Uri; import android.util.Log; -import com.nextcloud.talk.components.filebrowser.models.BrowserFile; 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; import java.util.List; +import androidx.annotation.NonNull; import at.bitfire.dav4jvm.DavResource; +import at.bitfire.dav4jvm.MultiResponseCallback; import at.bitfire.dav4jvm.Response; import at.bitfire.dav4jvm.exception.DavException; -import kotlin.Unit; -import kotlin.jvm.functions.Function2; import okhttp3.HttpUrl; import okhttp3.OkHttpClient; @@ -60,7 +63,7 @@ public ReadFilesystemOperation(OkHttpClient okHttpClient, User currentUser, Stri "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; } @@ -71,34 +74,38 @@ public DavResponse readRemotePath() { final Response[] rootElement = new Response[1]; 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 MultiResponseCallback() { + @Override + public void onResponse(@NonNull Response response, @NonNull Response.HrefRelation hrefRelation) { + davResponse.setResponse(response); + switch (hrefRelation) { + case MEMBER: + memberElements.add(response); + break; + case SELF: + rootElement[0] = response; + break; + case OTHER: + default: + } + } + }); } 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(); + + final List remoteFiles = new ArrayList<>(1 + memberElements.size()); + + 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()))); + 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 293dfa925fc..9710ba176da 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) { @@ -150,7 +151,7 @@ class ReadFolderListingOperation(okHttpClient: OkHttpClient, currentUser: User, remoteFileBrowserItem.modifiedTimestamp = property.lastModified } is GetContentType -> { - remoteFileBrowserItem.mimeType = property.type + remoteFileBrowserItem.mimeType = property.type?.toString() } is OCSize -> { remoteFileBrowserItem.size = property.ocSize @@ -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 01830595136..561a3fffe85 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 -> { @@ -367,7 +368,7 @@ class ChunkedFileUploader( remoteFileBrowserItem.modifiedTimestamp = property.lastModified } is GetContentType -> { - remoteFileBrowserItem.mimeType = property.type + remoteFileBrowserItem.mimeType = property.type?.toString() } is OCSize -> { remoteFileBrowserItem.size = property.ocSize @@ -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 4b0ec13d9df..35aa7e75e33 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 static String getUrlForSearchByNumber(String baseUrl) { } 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 static String getUrlForChunkedUpload(String baseUrl, String user) { } 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 01f94274222..940fdeff1f5 100644 --- a/build.gradle +++ b/build.gradle @@ -25,6 +25,7 @@ buildscript { ext { kotlinVersion = '1.9.10' + androidLibraryVersion = "dav4jvm-SNAPSHOT" } repositories { diff --git a/settings.gradle b/settings.gradle index 7cf8a9b08e5..bb0692b16ef 100644 --- a/settings.gradle +++ b/settings.gradle @@ -26,9 +26,3 @@ include ':app' // substitute module('com.github.nextcloud.android-common:ui') using project(':ui') // } //} - -//includeBuild('../../../deps/ImagePicker') { -// dependencySubstitution { -// substitute module('com.github.nextcloud-deps:ImagePicker') using project(':imagepicker') -// } -//}