|
39 | 39 | import com.nextcloud.client.database.dao.OfflineOperationDao; |
40 | 40 | import com.nextcloud.client.database.entity.FileEntity; |
41 | 41 | import com.nextcloud.client.database.entity.OfflineOperationEntity; |
| 42 | +import com.nextcloud.client.database.entity.ShareEntity; |
42 | 43 | import com.nextcloud.client.jobs.offlineOperations.repository.OfflineOperationsRepository; |
43 | 44 | import com.nextcloud.client.jobs.offlineOperations.repository.OfflineOperationsRepositoryType; |
44 | 45 | import com.nextcloud.model.OCFileFilterType; |
|
83 | 84 | import java.util.List; |
84 | 85 | import java.util.Locale; |
85 | 86 | import java.util.Set; |
| 87 | +import java.util.function.Consumer; |
86 | 88 |
|
87 | 89 | import androidx.annotation.NonNull; |
88 | 90 | import androidx.annotation.Nullable; |
@@ -1536,41 +1538,33 @@ public List<OCShare> getSharesByPathAndType(String path, ShareType type, String |
1536 | 1538 | private ContentValues createContentValueForRemoteFile(RemoteFile remoteFile) { |
1537 | 1539 | ContentValues contentValues = new ContentValues(); |
1538 | 1540 |
|
1539 | | - // Aligned properties between RemoteFile and OCShare |
1540 | 1541 | 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()); |
1557 | 1556 | } |
1558 | 1557 |
|
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 | + } |
1574 | 1568 |
|
1575 | 1569 | return contentValues; |
1576 | 1570 | } |
@@ -1648,25 +1642,6 @@ private OCShare createShareInstance(Cursor cursor) { |
1648 | 1642 | return share; |
1649 | 1643 | } |
1650 | 1644 |
|
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 | | - |
1670 | 1645 | private void resetShareFlagsInFolder(OCFile folder) { |
1671 | 1646 | ContentValues contentValues = new ContentValues(); |
1672 | 1647 | contentValues.put(ProviderTableMeta.FILE_SHARED_VIA_LINK, Boolean.FALSE); |
@@ -1784,10 +1759,16 @@ public void removeShare(OCShare share) { |
1784 | 1759 | } |
1785 | 1760 |
|
1786 | 1761 | public void saveSharesFromRemoteFile(List<RemoteFile> shares) { |
| 1762 | + if (shares == null || shares.isEmpty()) { |
| 1763 | + return; |
| 1764 | + } |
| 1765 | + |
1787 | 1766 | final ArrayList<ContentProviderOperation> operations = prepareInsertSharesFromRemoteFile(shares); |
| 1767 | + |
1788 | 1768 | if (operations.isEmpty()) { |
1789 | 1769 | return; |
1790 | 1770 | } |
| 1771 | + |
1791 | 1772 | applyBatch(operations); |
1792 | 1773 | } |
1793 | 1774 |
|
|
0 commit comments