Эх сурвалжийг харах

Fix wrong null->0L conversion
add button to remove sync entries

Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>

tobiasKaminsky 6 сар өмнө
parent
commit
5ddec7fa76

+ 5 - 1
app/src/main/java/com/owncloud/android/datamodel/FileDataStorageManager.java

@@ -1126,6 +1126,10 @@ public class FileDataStorageManager {
         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());
@@ -1190,7 +1194,7 @@ public class FileDataStorageManager {
         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.

+ 10 - 3
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<InternalTwoWaySyncViewHolder>() {
     var folders: List<OCFile> = 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()
     }
 }

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

+ 18 - 1
app/src/main/res/layout/internal_two_way_sync_view_holder.xml

@@ -28,17 +28,34 @@
         android:gravity="center_vertical"
         android:orientation="vertical">
 
+
+        <LinearLayout
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:orientation="horizontal"
+            tools:ignore="UseCompoundDrawables">
+
         <TextView
             android:id="@+id/name"
-            android:layout_width="wrap_content"
+            android:layout_width="0dp"
             android:layout_height="wrap_content"
             android:ellipsize="middle"
+            android:layout_weight="1"
             android:gravity="center_vertical"
             android:singleLine="true"
             android:textColor="@color/text_color"
             android:textSize="@dimen/two_line_primary_text_size"
             tools:text="Folder abc" />
 
+        <ImageView
+            android:id="@+id/unset"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:contentDescription="@string/unset_internal_two_way_sync_description"
+            android:src="@drawable/ic_close" />
+            
+        </LinearLayout>
+
         <LinearLayout
             android:layout_width="match_parent"
             android:layout_height="wrap_content">

+ 1 - 0
app/src/main/res/values/strings.xml

@@ -1247,4 +1247,5 @@
     <string name="sync">Sync</string>
     <string name="please_select_a_server">Please select a server…</string>
     <string name="notification_icon_description">Unread notifications exist</string>
+    <string name="unset_internal_two_way_sync_description">Remove folder from internal two way sync</string>
 </resources>