From 9f31b2760958dddc0e474337f7323e814815d2e7 Mon Sep 17 00:00:00 2001 From: tobiasKaminsky Date: Mon, 21 Oct 2024 10:06:40 +0200 Subject: [PATCH 1/5] Fix wrong null->0L conversion add button to remove sync entries Signed-off-by: tobiasKaminsky --- .../datamodel/FileDataStorageManager.java | 6 +++++- .../ui/adapter/InternalTwoWaySyncAdapter.kt | 13 ++++++++++--- .../adapter/InternalTwoWaySyncViewHolder.kt | 14 +++++++++++++- .../internal_two_way_sync_view_holder.xml | 19 ++++++++++++++++++- 4 files changed, 46 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/owncloud/android/datamodel/FileDataStorageManager.java b/app/src/main/java/com/owncloud/android/datamodel/FileDataStorageManager.java index c4b99d48bdfa..3b5c12a2a17d 100644 --- a/app/src/main/java/com/owncloud/android/datamodel/FileDataStorageManager.java +++ b/app/src/main/java/com/owncloud/android/datamodel/FileDataStorageManager.java @@ -976,6 +976,10 @@ private long nullToZero(Long i) { return (i == null) ? 0 : i; } + private long nullToMinusOne(Long i) { + return (i == null) ? -1L : i; + } + private OCFile createFileInstance(FileEntity fileEntity) { OCFile ocFile = new OCFile(fileEntity.getPath()); ocFile.setDecryptedRemotePath(fileEntity.getPathDecrypted()); @@ -1040,7 +1044,7 @@ private OCFile createFileInstance(FileEntity fileEntity) { ocFile.setLivePhoto(fileEntity.getMetadataLivePhoto()); ocFile.setHidden(nullToZero(fileEntity.getHidden()) == 1); ocFile.setE2eCounter(fileEntity.getE2eCounter()); - ocFile.setInternalFolderSyncTimestamp(nullToZero(fileEntity.getInternalTwoWaySync())); + ocFile.setInternalFolderSyncTimestamp(nullToMinusOne(fileEntity.getInternalTwoWaySync())); String sharees = fileEntity.getSharees(); // Surprisingly JSON deserialization causes significant overhead. diff --git a/app/src/main/java/com/owncloud/android/ui/adapter/InternalTwoWaySyncAdapter.kt b/app/src/main/java/com/owncloud/android/ui/adapter/InternalTwoWaySyncAdapter.kt index b432add035ef..b766a3d67953 100644 --- a/app/src/main/java/com/owncloud/android/ui/adapter/InternalTwoWaySyncAdapter.kt +++ b/app/src/main/java/com/owncloud/android/ui/adapter/InternalTwoWaySyncAdapter.kt @@ -7,6 +7,7 @@ package com.owncloud.android.ui.adapter +import android.annotation.SuppressLint import android.content.Context import android.view.LayoutInflater import android.view.ViewGroup @@ -17,8 +18,8 @@ import com.owncloud.android.datamodel.FileDataStorageManager import com.owncloud.android.datamodel.OCFile class InternalTwoWaySyncAdapter( - dataStorageManager: FileDataStorageManager, - user: User, + private val dataStorageManager: FileDataStorageManager, + private val user: User, val context: Context ) : RecyclerView.Adapter() { var folders: List = dataStorageManager.getInternalTwoWaySyncFolders(user) @@ -38,6 +39,12 @@ class InternalTwoWaySyncAdapter( } override fun onBindViewHolder(holder: InternalTwoWaySyncViewHolder, position: Int) { - holder.bind(folders[position], context) + holder.bind(folders[position], context, dataStorageManager, this) + } + + @SuppressLint("NotifyDataSetChanged") + fun update() { + folders = dataStorageManager.getInternalTwoWaySyncFolders(user) + notifyDataSetChanged() } } diff --git a/app/src/main/java/com/owncloud/android/ui/adapter/InternalTwoWaySyncViewHolder.kt b/app/src/main/java/com/owncloud/android/ui/adapter/InternalTwoWaySyncViewHolder.kt index 978b8c73172a..a35f362bdec6 100644 --- a/app/src/main/java/com/owncloud/android/ui/adapter/InternalTwoWaySyncViewHolder.kt +++ b/app/src/main/java/com/owncloud/android/ui/adapter/InternalTwoWaySyncViewHolder.kt @@ -12,12 +12,18 @@ import android.view.View import androidx.recyclerview.widget.RecyclerView import com.owncloud.android.R import com.owncloud.android.databinding.InternalTwoWaySyncViewHolderBinding +import com.owncloud.android.datamodel.FileDataStorageManager import com.owncloud.android.datamodel.OCFile import com.owncloud.android.utils.DisplayUtils class InternalTwoWaySyncViewHolder(val binding: InternalTwoWaySyncViewHolderBinding) : RecyclerView.ViewHolder(binding.root) { - fun bind(folder: OCFile, context: Context) { + fun bind( + folder: OCFile, + context: Context, + dataStorageManager: FileDataStorageManager, + internalTwoWaySyncAdapter: InternalTwoWaySyncAdapter + ) { binding.run { size.text = DisplayUtils.bytesToHumanReadable(folder.fileLength) name.text = folder.decryptedFileName @@ -39,6 +45,12 @@ class InternalTwoWaySyncViewHolder(val binding: InternalTwoWaySyncViewHolderBind folder.internalFolderSyncTimestamp ) } + + unset.setOnClickListener { + folder.internalFolderSyncTimestamp = -1L + dataStorageManager.saveFile(folder) + internalTwoWaySyncAdapter.update() + } } } } diff --git a/app/src/main/res/layout/internal_two_way_sync_view_holder.xml b/app/src/main/res/layout/internal_two_way_sync_view_holder.xml index 4304150df226..8391bc745983 100644 --- a/app/src/main/res/layout/internal_two_way_sync_view_holder.xml +++ b/app/src/main/res/layout/internal_two_way_sync_view_holder.xml @@ -28,17 +28,34 @@ android:gravity="center_vertical" android:orientation="vertical"> + + + + + + + From 7ddbe9d9ef3ef31a6d54d81a26d8cdd77bc9e120 Mon Sep 17 00:00:00 2001 From: tobiasKaminsky Date: Mon, 21 Oct 2024 14:30:51 +0200 Subject: [PATCH 2/5] x correct positioned Signed-off-by: tobiasKaminsky --- .../internal_two_way_sync_view_holder.xml | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/app/src/main/res/layout/internal_two_way_sync_view_holder.xml b/app/src/main/res/layout/internal_two_way_sync_view_holder.xml index 8391bc745983..858d868a3e47 100644 --- a/app/src/main/res/layout/internal_two_way_sync_view_holder.xml +++ b/app/src/main/res/layout/internal_two_way_sync_view_holder.xml @@ -22,10 +22,11 @@ android:src="@drawable/folder" /> @@ -47,13 +48,6 @@ android:textSize="@dimen/two_line_primary_text_size" tools:text="Folder abc" /> - - + + From c7e1463fc0386fba7616eaf6d03a84148f3318cf Mon Sep 17 00:00:00 2001 From: ZetaTom <70907959+ZetaTom@users.noreply.github.com> Date: Mon, 21 Oct 2024 16:09:43 +0200 Subject: [PATCH 3/5] Skip root folder for two way sync Signed-off-by: ZetaTom <70907959+ZetaTom@users.noreply.github.com> --- .../com/nextcloud/client/jobs/InternalTwoWaySyncWork.kt | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/src/main/java/com/nextcloud/client/jobs/InternalTwoWaySyncWork.kt b/app/src/main/java/com/nextcloud/client/jobs/InternalTwoWaySyncWork.kt index a08cba02d738..a84331685257 100644 --- a/app/src/main/java/com/nextcloud/client/jobs/InternalTwoWaySyncWork.kt +++ b/app/src/main/java/com/nextcloud/client/jobs/InternalTwoWaySyncWork.kt @@ -52,6 +52,13 @@ class InternalTwoWaySyncWork( return checkFreeSpaceResult } + // do not attempt to sync root folder + if (folder.remotePath == OCFile.ROOT_PATH) { + folder.internalFolderSyncTimestamp = -1L + fileDataStorageManager.saveFile(folder) + continue + } + Log_OC.d(TAG, "Folder ${folder.remotePath}: started!") val operation = SynchronizeFolderOperation(context, folder.remotePath, user, fileDataStorageManager) .execute(context) From a74236cbd95bd44782811208e0953c0adfc286cd Mon Sep 17 00:00:00 2001 From: ZetaTom <70907959+ZetaTom@users.noreply.github.com> Date: Mon, 21 Oct 2024 16:34:46 +0200 Subject: [PATCH 4/5] Remove unnecessary LinearLayout Signed-off-by: ZetaTom <70907959+ZetaTom@users.noreply.github.com> [skip ci] --- .../res/layout/internal_two_way_sync_view_holder.xml | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/app/src/main/res/layout/internal_two_way_sync_view_holder.xml b/app/src/main/res/layout/internal_two_way_sync_view_holder.xml index 858d868a3e47..680b9213910c 100644 --- a/app/src/main/res/layout/internal_two_way_sync_view_holder.xml +++ b/app/src/main/res/layout/internal_two_way_sync_view_holder.xml @@ -29,27 +29,17 @@ android:gravity="center_vertical|start" android:orientation="vertical"> - - - - - From c054f747cd8df42bdbc354eae3f23e8d35e19450 Mon Sep 17 00:00:00 2001 From: tobiasKaminsky Date: Mon, 21 Oct 2024 16:50:43 +0200 Subject: [PATCH 5/5] Fix backport Signed-off-by: tobiasKaminsky --- app/src/main/res/values/strings.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index ef279d0b936f..0d480ab72456 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1237,4 +1237,5 @@ Filenames must not contain spaces at the beginning or end Sync Please select a server… + Remove folder from internal two way sync