Skip to content

Commit c88108e

Browse files
committed
add share attribute field
Signed-off-by: alperozturk <alper_ozturk@proton.me>
1 parent dd3683b commit c88108e

11 files changed

Lines changed: 1419 additions & 8 deletions

File tree

app/schemas/com.nextcloud.client.database.NextcloudDatabase/89.json

Lines changed: 1349 additions & 0 deletions
Large diffs are not rendered by default.

app/src/main/java/com/nextcloud/client/database/NextcloudDatabase.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ import com.owncloud.android.db.ProviderMeta
7171
AutoMigration(from = 84, to = 85, spec = DatabaseMigrationUtil.DeleteColumnSpec::class),
7272
AutoMigration(from = 85, to = 86, spec = DatabaseMigrationUtil.ResetCapabilitiesPostMigration::class),
7373
AutoMigration(from = 86, to = 87, spec = DatabaseMigrationUtil.ResetCapabilitiesPostMigration::class),
74-
AutoMigration(from = 87, to = 88, spec = DatabaseMigrationUtil.ResetCapabilitiesPostMigration::class)
74+
AutoMigration(from = 87, to = 88, spec = DatabaseMigrationUtil.ResetCapabilitiesPostMigration::class),
75+
AutoMigration(from = 88, to = 89)
7576
],
7677
exportSchema = true
7778
)

app/src/main/java/com/nextcloud/client/database/entity/ShareEntity.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,7 @@ data class ShareEntity(
5858
@ColumnInfo(name = ProviderTableMeta.OCSHARES_DOWNLOADLIMIT_LIMIT)
5959
val downloadLimitLimit: Int?,
6060
@ColumnInfo(name = ProviderTableMeta.OCSHARES_DOWNLOADLIMIT_COUNT)
61-
val downloadLimitCount: Int?
61+
val downloadLimitCount: Int?,
62+
@ColumnInfo(name = ProviderTableMeta.OCSHARES_ATTRIBUTES)
63+
val attributes: String?
6264
)

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1566,6 +1566,8 @@ private ContentValues createContentValueForShare(OCShare share) {
15661566
contentValues.putNull(ProviderTableMeta.OCSHARES_DOWNLOADLIMIT_COUNT);
15671567
}
15681568

1569+
contentValues.put(ProviderTableMeta.OCSHARES_ATTRIBUTES, share.getAttributes());
1570+
15691571
return contentValues;
15701572
}
15711573

@@ -1596,6 +1598,8 @@ private OCShare createShareInstance(Cursor cursor) {
15961598
getInt(cursor, ProviderTableMeta.OCSHARES_DOWNLOADLIMIT_COUNT));
15971599
share.setFileDownloadLimit(downloadLimit);
15981600

1601+
share.setAttributes(getString(cursor,ProviderTableMeta.OCSHARES_ATTRIBUTES));
1602+
15991603
return share;
16001604
}
16011605

app/src/main/java/com/owncloud/android/db/ProviderMeta.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
*/
2626
public class ProviderMeta {
2727
public static final String DB_NAME = "filelist";
28-
public static final int DB_VERSION = 88;
28+
public static final int DB_VERSION = 89;
2929

3030
private ProviderMeta() {
3131
// No instance
@@ -201,6 +201,7 @@ static public class ProviderTableMeta implements BaseColumns {
201201
public static final String OCSHARES_SHARE_LABEL = "share_label";
202202
public static final String OCSHARES_DOWNLOADLIMIT_LIMIT = "download_limit_limit";
203203
public static final String OCSHARES_DOWNLOADLIMIT_COUNT = "download_limit_count";
204+
public static final String OCSHARES_ATTRIBUTES = "attributes";
204205

205206
public static final String OCSHARES_DEFAULT_SORT_ORDER = OCSHARES_FILE_SOURCE
206207
+ " collate nocase asc";

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ public class CreateShareWithShareeOperation extends SyncOperation {
5656
private String label;
5757
private final Context context;
5858
private final User user;
59+
private String attributes;
5960

6061
private ArbitraryDataProvider arbitraryDataProvider;
6162

@@ -85,6 +86,7 @@ public CreateShareWithShareeOperation(String path,
8586
String sharePassword,
8687
long expirationDateInMillis,
8788
boolean hideFileDownload,
89+
String attributes,
8890
FileDataStorageManager storageManager,
8991
Context context,
9092
User user,
@@ -105,6 +107,7 @@ public CreateShareWithShareeOperation(String path,
105107
this.context = context;
106108
this.user = user;
107109
this.arbitraryDataProvider = arbitraryDataProvider;
110+
this.attributes = attributes;
108111
}
109112

110113
@Override
@@ -156,7 +159,8 @@ protected RemoteOperationResult run(OwnCloudClient client) {
156159
false,
157160
sharePassword,
158161
permissions,
159-
noteMessage
162+
noteMessage,
163+
attributes
160164
);
161165
operation.setGetShareDetails(true);
162166
RemoteOperationResult shareResult = operation.execute(client);

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public class UpdateShareInfoOperation extends SyncOperation {
3535
private int permissions = -1;
3636
private String password;
3737
private String label;
38+
private String attributes;
3839

3940
/**
4041
* Constructor
@@ -93,6 +94,7 @@ protected RemoteOperationResult run(OwnCloudClient client) {
9394
}
9495
updateOp.setPassword(password);
9596
updateOp.setLabel(label);
97+
updateOp.setAttributes(attributes);
9698

9799
RemoteOperationResult result = updateOp.execute(client);
98100

@@ -125,6 +127,10 @@ public void setHideFileDownload(boolean hideFileDownload) {
125127
this.hideFileDownload = hideFileDownload;
126128
}
127129

130+
public void setAttributes(String attributes) {
131+
this.attributes = attributes;
132+
}
133+
128134
public void setPermissions(int permissions) {
129135
this.permissions = permissions;
130136
}

app/src/main/java/com/owncloud/android/services/OperationsService.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ public class OperationsService extends Service {
101101
public static final String EXTRA_SHARE_NOTE = "SHARE_NOTE";
102102
public static final String EXTRA_IN_BACKGROUND = "IN_BACKGROUND";
103103
public static final String EXTRA_FILES_DOWNLOAD_LIMIT = "FILES_DOWNLOAD_LIMIT";
104+
public static final String EXTRA_SHARE_ATTRIBUTES = "SHARE_ATTRIBUTES";
104105

105106
public static final String ACTION_CREATE_SHARE_VIA_LINK = "CREATE_SHARE_VIA_LINK";
106107
public static final String ACTION_CREATE_SECURE_FILE_DROP = "CREATE_SECURE_FILE_DROP";
@@ -593,6 +594,8 @@ private Pair<Target, RemoteOperation> newOperation(Intent operationIntent) {
593594
.getLongExtra(EXTRA_SHARE_EXPIRATION_DATE_IN_MILLIS, 0L);
594595
boolean hideFileDownload = operationIntent.getBooleanExtra(EXTRA_SHARE_HIDE_FILE_DOWNLOAD,
595596
false);
597+
String attributes = operationIntent.getStringExtra(EXTRA_SHARE_ATTRIBUTES);
598+
596599
if (!TextUtils.isEmpty(remotePath)) {
597600
CreateShareWithShareeOperation createShareWithShareeOperation =
598601
new CreateShareWithShareeOperation(remotePath,
@@ -603,6 +606,7 @@ private Pair<Target, RemoteOperation> newOperation(Intent operationIntent) {
603606
sharePassword,
604607
expirationDateInMillis,
605608
hideFileDownload,
609+
attributes,
606610
fileDataStorageManager,
607611
getApplicationContext(),
608612
user,
@@ -641,6 +645,9 @@ private Pair<Target, RemoteOperation> newOperation(Intent operationIntent) {
641645
updateShare.setLabel(operationIntent.getStringExtra(EXTRA_SHARE_PUBLIC_LABEL));
642646
}
643647

648+
String shareAttributes = operationIntent.getStringExtra(EXTRA_SHARE_ATTRIBUTES);
649+
updateShare.setAttributes(shareAttributes);
650+
644651
operation = updateShare;
645652
}
646653
break;

app/src/main/java/com/owncloud/android/ui/fragment/FileDetailsSharingProcessFragment.kt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -490,10 +490,6 @@ class FileDetailsSharingProcessFragment :
490490
showExpirationDateDialog()
491491
}
492492

493-
shareAllowDownloadAndSyncCheckbox.setOnCheckedChangeListener { _, isChecked ->
494-
share
495-
}
496-
497493
// region RadioButtons
498494
shareProcessPermissionRadioGroup.setOnCheckedChangeListener { radioGroup, optionId ->
499495
when (optionId) {
@@ -546,6 +542,8 @@ class FileDetailsSharingProcessFragment :
546542
isEnabled = false
547543
}
548544
}
545+
546+
shareAllowDownloadAndSyncCheckbox.isChecked = isAllowDownloadAndSyncEnabled(share)
549547
}
550548
}
551549

@@ -564,6 +562,10 @@ class FileDetailsSharingProcessFragment :
564562
checkboxes.forEach { (checkbox, flag) ->
565563
checkbox.setOnCheckedChangeListener { _, isChecked -> togglePermission(isChecked, flag) }
566564
}
565+
566+
binding.shareAllowDownloadAndSyncCheckbox.setOnCheckedChangeListener { _, isChecked ->
567+
share?.attributes = sharePermissionManager.toggleAllowDownloadAndSync(isChecked, share)
568+
}
567569
}
568570

569571
private fun showExpirationDateDialog(chosenDateInMillis: Long = chosenExpDateInMills) {
@@ -726,6 +728,7 @@ class FileDetailsSharingProcessFragment :
726728
binding.shareProcessEnterPassword.text.toString().trim(),
727729
chosenExpDateInMills,
728730
noteText,
731+
share?.attributes,
729732
binding.shareProcessChangeName.text.toString().trim(),
730733
true
731734
)

app/src/main/java/com/owncloud/android/ui/fragment/util/SharePermissionManager.kt

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ package com.owncloud.android.ui.fragment.util
99

1010
import com.owncloud.android.lib.common.utils.Log_OC
1111
import com.owncloud.android.lib.resources.shares.OCShare
12+
import com.owncloud.android.lib.resources.shares.attributes.ShareAttributes
13+
import com.owncloud.android.lib.resources.shares.attributes.ShareAttributesJsonHandler
14+
import com.owncloud.android.lib.resources.shares.attributes.getDownloadAttribute
1215
import com.owncloud.android.ui.fragment.FileDetailsSharingProcessFragment.Companion.TAG
1316

1417
class SharePermissionManager {
@@ -85,4 +88,32 @@ class SharePermissionManager {
8588
OCShare.MAXIMUM_PERMISSIONS_FOR_FILE
8689
}
8790
}
91+
92+
fun toggleAllowDownloadAndSync(isChecked: Boolean, share: OCShare?): String? {
93+
val shareAttributes = getShareAttributes(share)?.toMutableList()
94+
val downloadAttributeIndex = shareAttributes?.indexOf(shareAttributes.getDownloadAttribute())
95+
if (downloadAttributeIndex != null && downloadAttributeIndex >= 0) {
96+
val updatedAttribute = shareAttributes[downloadAttributeIndex].copy(isEnabled = isChecked)
97+
shareAttributes[downloadAttributeIndex] = updatedAttribute
98+
}
99+
100+
if (shareAttributes == null) {
101+
return null
102+
}
103+
104+
return ShareAttributesJsonHandler.toJson(shareAttributes)
105+
}
106+
107+
fun isAllowDownloadAndSyncEnabled(share: OCShare?): Boolean {
108+
val shareAttributes = getShareAttributes(share)?.toMutableList()
109+
return shareAttributes.getDownloadAttribute()?.isEnabled == true
110+
}
111+
112+
private fun getShareAttributes(share: OCShare?): List<ShareAttributes>? {
113+
if (share == null || share.attributes == null) {
114+
return null
115+
}
116+
117+
return ShareAttributesJsonHandler.parseJson(share.attributes!!)
118+
}
88119
}

0 commit comments

Comments
 (0)