Skip to content

Commit 48fc78e

Browse files
Merge pull request #13842 from nextcloud/backport/13838/stable-3.30
[stable-3.30] Fix wrong null->0L conversion
2 parents 7491d01 + c054f74 commit 48fc78e

File tree

6 files changed

+47
-7
lines changed

6 files changed

+47
-7
lines changed

app/src/main/java/com/nextcloud/client/jobs/InternalTwoWaySyncWork.kt

+7
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,13 @@ class InternalTwoWaySyncWork(
5252
return checkFreeSpaceResult
5353
}
5454

55+
// do not attempt to sync root folder
56+
if (folder.remotePath == OCFile.ROOT_PATH) {
57+
folder.internalFolderSyncTimestamp = -1L
58+
fileDataStorageManager.saveFile(folder)
59+
continue
60+
}
61+
5562
Log_OC.d(TAG, "Folder ${folder.remotePath}: started!")
5663
val operation = SynchronizeFolderOperation(context, folder.remotePath, user, fileDataStorageManager)
5764
.execute(context)

app/src/main/java/com/owncloud/android/datamodel/FileDataStorageManager.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -976,6 +976,10 @@ private long nullToZero(Long i) {
976976
return (i == null) ? 0 : i;
977977
}
978978

979+
private long nullToMinusOne(Long i) {
980+
return (i == null) ? -1L : i;
981+
}
982+
979983
private OCFile createFileInstance(FileEntity fileEntity) {
980984
OCFile ocFile = new OCFile(fileEntity.getPath());
981985
ocFile.setDecryptedRemotePath(fileEntity.getPathDecrypted());
@@ -1040,7 +1044,7 @@ private OCFile createFileInstance(FileEntity fileEntity) {
10401044
ocFile.setLivePhoto(fileEntity.getMetadataLivePhoto());
10411045
ocFile.setHidden(nullToZero(fileEntity.getHidden()) == 1);
10421046
ocFile.setE2eCounter(fileEntity.getE2eCounter());
1043-
ocFile.setInternalFolderSyncTimestamp(nullToZero(fileEntity.getInternalTwoWaySync()));
1047+
ocFile.setInternalFolderSyncTimestamp(nullToMinusOne(fileEntity.getInternalTwoWaySync()));
10441048

10451049
String sharees = fileEntity.getSharees();
10461050
// Surprisingly JSON deserialization causes significant overhead.

app/src/main/java/com/owncloud/android/ui/adapter/InternalTwoWaySyncAdapter.kt

+10-3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
package com.owncloud.android.ui.adapter
99

10+
import android.annotation.SuppressLint
1011
import android.content.Context
1112
import android.view.LayoutInflater
1213
import android.view.ViewGroup
@@ -17,8 +18,8 @@ import com.owncloud.android.datamodel.FileDataStorageManager
1718
import com.owncloud.android.datamodel.OCFile
1819

1920
class InternalTwoWaySyncAdapter(
20-
dataStorageManager: FileDataStorageManager,
21-
user: User,
21+
private val dataStorageManager: FileDataStorageManager,
22+
private val user: User,
2223
val context: Context
2324
) : RecyclerView.Adapter<InternalTwoWaySyncViewHolder>() {
2425
var folders: List<OCFile> = dataStorageManager.getInternalTwoWaySyncFolders(user)
@@ -38,6 +39,12 @@ class InternalTwoWaySyncAdapter(
3839
}
3940

4041
override fun onBindViewHolder(holder: InternalTwoWaySyncViewHolder, position: Int) {
41-
holder.bind(folders[position], context)
42+
holder.bind(folders[position], context, dataStorageManager, this)
43+
}
44+
45+
@SuppressLint("NotifyDataSetChanged")
46+
fun update() {
47+
folders = dataStorageManager.getInternalTwoWaySyncFolders(user)
48+
notifyDataSetChanged()
4249
}
4350
}

app/src/main/java/com/owncloud/android/ui/adapter/InternalTwoWaySyncViewHolder.kt

+13-1
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,18 @@ import android.view.View
1212
import androidx.recyclerview.widget.RecyclerView
1313
import com.owncloud.android.R
1414
import com.owncloud.android.databinding.InternalTwoWaySyncViewHolderBinding
15+
import com.owncloud.android.datamodel.FileDataStorageManager
1516
import com.owncloud.android.datamodel.OCFile
1617
import com.owncloud.android.utils.DisplayUtils
1718

1819
class InternalTwoWaySyncViewHolder(val binding: InternalTwoWaySyncViewHolderBinding) :
1920
RecyclerView.ViewHolder(binding.root) {
20-
fun bind(folder: OCFile, context: Context) {
21+
fun bind(
22+
folder: OCFile,
23+
context: Context,
24+
dataStorageManager: FileDataStorageManager,
25+
internalTwoWaySyncAdapter: InternalTwoWaySyncAdapter
26+
) {
2127
binding.run {
2228
size.text = DisplayUtils.bytesToHumanReadable(folder.fileLength)
2329
name.text = folder.decryptedFileName
@@ -39,6 +45,12 @@ class InternalTwoWaySyncViewHolder(val binding: InternalTwoWaySyncViewHolderBind
3945
folder.internalFolderSyncTimestamp
4046
)
4147
}
48+
49+
unset.setOnClickListener {
50+
folder.internalFolderSyncTimestamp = -1L
51+
dataStorageManager.saveFile(folder)
52+
internalTwoWaySyncAdapter.update()
53+
}
4254
}
4355
}
4456
}

app/src/main/res/layout/internal_two_way_sync_view_holder.xml

+11-2
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,11 @@
2222
android:src="@drawable/folder" />
2323

2424
<LinearLayout
25-
android:layout_width="match_parent"
25+
android:layout_width="0dp"
26+
android:layout_weight="1"
2627
android:layout_height="@dimen/min_list_item_size"
2728
android:layout_marginStart="@dimen/standard_half_margin"
28-
android:gravity="center_vertical"
29+
android:gravity="center_vertical|start"
2930
android:orientation="vertical">
3031

3132
<TextView
@@ -94,4 +95,12 @@
9495
</LinearLayout>
9596
</LinearLayout>
9697

98+
<ImageView
99+
android:id="@+id/unset"
100+
android:layout_width="wrap_content"
101+
android:layout_height="wrap_content"
102+
android:layout_gravity="center_vertical"
103+
android:contentDescription="@string/unset_internal_two_way_sync_description"
104+
android:src="@drawable/ic_close" />
105+
97106
</LinearLayout>

app/src/main/res/values/strings.xml

+1
Original file line numberDiff line numberDiff line change
@@ -1237,4 +1237,5 @@
12371237
<string name="file_name_validator_error_forbidden_space_character_extensions">Filenames must not contain spaces at the beginning or end</string>
12381238
<string name="sync">Sync</string>
12391239
<string name="please_select_a_server">Please select a server…</string>
1240+
<string name="unset_internal_two_way_sync_description">Remove folder from internal two way sync</string>
12401241
</resources>

0 commit comments

Comments
 (0)