Skip to content

Commit 0ccc6fa

Browse files
committed
add createContentValueForRemoteFile
Signed-off-by: alperozturk <alper_ozturk@proton.me>
1 parent 34d8a87 commit 0ccc6fa

3 files changed

Lines changed: 42 additions & 53 deletions

File tree

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

Lines changed: 32 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import com.nextcloud.client.database.dao.OfflineOperationDao;
4040
import com.nextcloud.client.database.entity.FileEntity;
4141
import com.nextcloud.client.database.entity.OfflineOperationEntity;
42+
import com.nextcloud.client.database.entity.ShareEntity;
4243
import com.nextcloud.client.jobs.offlineOperations.repository.OfflineOperationsRepository;
4344
import com.nextcloud.client.jobs.offlineOperations.repository.OfflineOperationsRepositoryType;
4445
import com.nextcloud.model.OCFileFilterType;
@@ -83,6 +84,7 @@
8384
import java.util.List;
8485
import java.util.Locale;
8586
import java.util.Set;
87+
import java.util.function.Consumer;
8688

8789
import androidx.annotation.NonNull;
8890
import androidx.annotation.Nullable;
@@ -1536,41 +1538,33 @@ public List<OCShare> getSharesByPathAndType(String path, ShareType type, String
15361538
private ContentValues createContentValueForRemoteFile(RemoteFile remoteFile) {
15371539
ContentValues contentValues = new ContentValues();
15381540

1539-
// Aligned properties between RemoteFile and OCShare
15401541
contentValues.put(ProviderTableMeta.OCSHARES_PATH, remoteFile.getRemotePath());
1541-
contentValues.put(ProviderTableMeta.OCSHARES_PERMISSIONS, remoteFile.getPermissions());
1542-
contentValues.put(ProviderTableMeta.OCSHARES_IS_DIRECTORY,
1543-
"DIR".equals(remoteFile.getMimeType()) ? 1 : 0);
1544-
contentValues.put(ProviderTableMeta.OCSHARES_USER_ID, remoteFile.getOwnerId());
1545-
contentValues.put(ProviderTableMeta.OCSHARES_NOTE, remoteFile.getNote());
1546-
contentValues.put(ProviderTableMeta.OCSHARES_HIDE_DOWNLOAD, remoteFile.isHasPreview());
1547-
1548-
// Handle FileDownloadLimit - RemoteFile has a List while OCShare has a single object
1549-
List<FileDownloadLimit> downloadLimits = remoteFile.getFileDownloadLimit();
1550-
if (!downloadLimits.isEmpty()) {
1551-
FileDownloadLimit downloadLimit = downloadLimits.get(0); // Take the first one
1552-
contentValues.put(ProviderTableMeta.OCSHARES_DOWNLOADLIMIT_LIMIT, downloadLimit.getLimit());
1553-
contentValues.put(ProviderTableMeta.OCSHARES_DOWNLOADLIMIT_COUNT, downloadLimit.getCount());
1554-
} else {
1555-
contentValues.putNull(ProviderTableMeta.OCSHARES_DOWNLOADLIMIT_LIMIT);
1556-
contentValues.putNull(ProviderTableMeta.OCSHARES_DOWNLOADLIMIT_COUNT);
1542+
boolean isDirectory = MimeTypeUtil.isFolder(remoteFile.getMimeType());
1543+
contentValues.put(ProviderTableMeta.OCSHARES_IS_DIRECTORY, isDirectory);
1544+
contentValues.put(ProviderTableMeta.OCSHARES_ACCOUNT_OWNER, user.getAccountName());
1545+
1546+
if (remoteFile.getSharees().length > 0) {
1547+
final var sharee = remoteFile.getSharees()[0];
1548+
contentValues.put(ProviderTableMeta.OCSHARES_SHARE_WITH_DISPLAY_NAME, sharee.getDisplayName());
1549+
1550+
ShareType shareType = sharee.getShareType();
1551+
if (shareType != null) {
1552+
contentValues.put(ProviderTableMeta.OCSHARES_SHARE_TYPE, shareType.getValue());
1553+
}
1554+
1555+
contentValues.put(ProviderTableMeta.OCSHARES_USER_ID, sharee.getUserId());
15571556
}
15581557

1559-
// Set default/null values for non-matching OCShare fields
1560-
contentValues.putNull(ProviderTableMeta.OCSHARES_FILE_SOURCE);
1561-
contentValues.putNull(ProviderTableMeta.OCSHARES_ITEM_SOURCE);
1562-
contentValues.putNull(ProviderTableMeta.OCSHARES_SHARE_TYPE);
1563-
contentValues.putNull(ProviderTableMeta.OCSHARES_SHARE_WITH);
1564-
contentValues.putNull(ProviderTableMeta.OCSHARES_SHARED_DATE);
1565-
contentValues.putNull(ProviderTableMeta.OCSHARES_EXPIRATION_DATE);
1566-
contentValues.putNull(ProviderTableMeta.OCSHARES_TOKEN);
1567-
contentValues.putNull(ProviderTableMeta.OCSHARES_SHARE_WITH_DISPLAY_NAME);
1568-
contentValues.putNull(ProviderTableMeta.OCSHARES_ID_REMOTE_SHARED);
1569-
contentValues.put(ProviderTableMeta.OCSHARES_ACCOUNT_OWNER, user.getAccountName()); // Assuming user is available
1570-
contentValues.put(ProviderTableMeta.OCSHARES_IS_PASSWORD_PROTECTED, 0);
1571-
contentValues.putNull(ProviderTableMeta.OCSHARES_SHARE_LINK);
1572-
contentValues.putNull(ProviderTableMeta.OCSHARES_SHARE_LABEL);
1573-
contentValues.putNull(ProviderTableMeta.OCSHARES_ATTRIBUTES);
1558+
if (!remoteFile.getFileDownloadLimit().isEmpty()) {
1559+
FileDownloadLimit downloadLimit = remoteFile.getFileDownloadLimit().get(0);
1560+
if (downloadLimit != null) {
1561+
contentValues.put(ProviderTableMeta.OCSHARES_DOWNLOADLIMIT_LIMIT, downloadLimit.getLimit());
1562+
contentValues.put(ProviderTableMeta.OCSHARES_DOWNLOADLIMIT_COUNT, downloadLimit.getCount());
1563+
} else {
1564+
contentValues.putNull(ProviderTableMeta.OCSHARES_DOWNLOADLIMIT_LIMIT);
1565+
contentValues.putNull(ProviderTableMeta.OCSHARES_DOWNLOADLIMIT_COUNT);
1566+
}
1567+
}
15741568

15751569
return contentValues;
15761570
}
@@ -1648,25 +1642,6 @@ private OCShare createShareInstance(Cursor cursor) {
16481642
return share;
16491643
}
16501644

1651-
private void resetShareFlagsInAllFiles() {
1652-
ContentValues cv = new ContentValues();
1653-
cv.put(ProviderTableMeta.FILE_SHARED_VIA_LINK, Boolean.FALSE);
1654-
cv.put(ProviderTableMeta.FILE_SHARED_WITH_SHAREE, Boolean.FALSE);
1655-
String where = ProviderTableMeta.FILE_ACCOUNT_OWNER + "=?";
1656-
String[] whereArgs = new String[]{user.getAccountName()};
1657-
1658-
if (getContentResolver() != null) {
1659-
getContentResolver().update(ProviderTableMeta.CONTENT_URI, cv, where, whereArgs);
1660-
1661-
} else {
1662-
try {
1663-
getContentProviderClient().update(ProviderTableMeta.CONTENT_URI, cv, where, whereArgs);
1664-
} catch (RemoteException e) {
1665-
Log_OC.e(TAG, "Exception in resetShareFlagsInAllFiles" + e.getMessage(), e);
1666-
}
1667-
}
1668-
}
1669-
16701645
private void resetShareFlagsInFolder(OCFile folder) {
16711646
ContentValues contentValues = new ContentValues();
16721647
contentValues.put(ProviderTableMeta.FILE_SHARED_VIA_LINK, Boolean.FALSE);
@@ -1784,10 +1759,16 @@ public void removeShare(OCShare share) {
17841759
}
17851760

17861761
public void saveSharesFromRemoteFile(List<RemoteFile> shares) {
1762+
if (shares == null || shares.isEmpty()) {
1763+
return;
1764+
}
1765+
17871766
final ArrayList<ContentProviderOperation> operations = prepareInsertSharesFromRemoteFile(shares);
1767+
17881768
if (operations.isEmpty()) {
17891769
return;
17901770
}
1771+
17911772
applyBatch(operations);
17921773
}
17931774

app/src/main/java/com/owncloud/android/operations/RefreshFolderOperation.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,9 @@ protected RemoteOperationResult run(OwnCloudClient client) {
266266
}
267267

268268
if (result.isSuccess() && !mSyncFullAccount && !mOnlyFileMetadata) {
269-
refreshSharesForFolder(client); // share result is ignored
269+
final ArrayList<RemoteFile> remoteFiles = result.getData();
270+
fileDataStorageManager.saveSharesFromRemoteFile(remoteFiles);
271+
// refreshSharesForFolder(client); // share result is ignored
270272
}
271273

272274
if (!mSyncFullAccount) {

app/src/main/java/com/owncloud/android/providers/FileContentProvider.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,13 @@ private Uri insert(SupportSQLiteDatabase db, Uri uri, ContentValues values) {
345345

346346
private void updateFilesTableAccordingToShareInsertion(SupportSQLiteDatabase db, ContentValues newShare) {
347347
ContentValues fileValues = new ContentValues();
348-
ShareType newShareType = ShareType.fromValue(newShare.getAsInteger(ProviderTableMeta.OCSHARES_SHARE_TYPE));
348+
Integer shareTypeValue = newShare.getAsInteger(ProviderTableMeta.OCSHARES_SHARE_TYPE);
349+
if (shareTypeValue == null) {
350+
Log_OC.w(TAG, "Share type is null. Skipping file update.");
351+
return;
352+
}
353+
354+
ShareType newShareType = ShareType.fromValue(shareTypeValue);
349355

350356
switch (newShareType) {
351357
case PUBLIC_LINK:

0 commit comments

Comments
 (0)