Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable-3.30] Fix wrong null->0L conversion #13842

Merged
merged 5 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -39,6 +45,12 @@ class InternalTwoWaySyncViewHolder(val binding: InternalTwoWaySyncViewHolderBind
folder.internalFolderSyncTimestamp
)
}

unset.setOnClickListener {
folder.internalFolderSyncTimestamp = -1L
dataStorageManager.saveFile(folder)
internalTwoWaySyncAdapter.update()
}
}
}
}
13 changes: 11 additions & 2 deletions app/src/main/res/layout/internal_two_way_sync_view_holder.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@
android:src="@drawable/folder" />

<LinearLayout
android:layout_width="match_parent"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="@dimen/min_list_item_size"
android:layout_marginStart="@dimen/standard_half_margin"
android:gravity="center_vertical"
android:gravity="center_vertical|start"
android:orientation="vertical">

<TextView
Expand Down Expand Up @@ -94,4 +95,12 @@
</LinearLayout>
</LinearLayout>

<ImageView
android:id="@+id/unset"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:contentDescription="@string/unset_internal_two_way_sync_description"
android:src="@drawable/ic_close" />

</LinearLayout>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1237,4 +1237,5 @@
<string name="file_name_validator_error_forbidden_space_character_extensions">Filenames must not contain spaces at the beginning or end</string>
<string name="sync">Sync</string>
<string name="please_select_a_server">Please select a server…</string>
<string name="unset_internal_two_way_sync_description">Remove folder from internal two way sync</string>
</resources>
Loading