Skip to content

Commit 2630ab7

Browse files
allow to set/edit note on shares
Signed-off-by: tobiasKaminsky <[email protected]>
1 parent c01061b commit 2630ab7

File tree

15 files changed

+500
-169
lines changed

15 files changed

+500
-169
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ dependencies {
214214
// implementation project('nextcloud-android-library')
215215
genericImplementation "com.github.nextcloud:android-library:master-SNAPSHOT"
216216
gplayImplementation "com.github.nextcloud:android-library:master-SNAPSHOT"
217-
versionDevImplementation 'com.github.nextcloud:android-library:master-SNAPSHOT' // use always latest master
217+
versionDevImplementation "com.github.nextcloud:android-library:master-SNAPSHOT" // use always latest master
218218
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
219219
implementation "com.android.support:support-v4:${supportLibraryVersion}"
220220
implementation "com.android.support:design:${supportLibraryVersion}"

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

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,16 +1000,13 @@ public boolean saveShare(OCShare share) {
10001000
cv.put(ProviderTableMeta.OCSHARES_SHARED_DATE, share.getSharedDate());
10011001
cv.put(ProviderTableMeta.OCSHARES_EXPIRATION_DATE, share.getExpirationDate());
10021002
cv.put(ProviderTableMeta.OCSHARES_TOKEN, share.getToken());
1003-
cv.put(
1004-
ProviderTableMeta.OCSHARES_SHARE_WITH_DISPLAY_NAME,
1005-
share.getSharedWithDisplayName()
1006-
);
1003+
cv.put(ProviderTableMeta.OCSHARES_SHARE_WITH_DISPLAY_NAME, share.getSharedWithDisplayName());
10071004
cv.put(ProviderTableMeta.OCSHARES_IS_DIRECTORY, share.isFolder() ? 1 : 0);
10081005
cv.put(ProviderTableMeta.OCSHARES_USER_ID, share.getUserId());
10091006
cv.put(ProviderTableMeta.OCSHARES_ID_REMOTE_SHARED, share.getRemoteId());
10101007
cv.put(ProviderTableMeta.OCSHARES_ACCOUNT_OWNER, mAccount.name);
1011-
10121008
cv.put(ProviderTableMeta.OCSHARES_IS_PASSWORD_PROTECTED, share.isPasswordProtected() ? 1 : 0);
1009+
cv.put(ProviderTableMeta.OCSHARES_NOTE, share.getNote());
10131010

10141011
if (shareExistsForRemoteId(share.getRemoteId())) {// for renamed files; no more delete and create
10151012
overriden = true;
@@ -1215,6 +1212,7 @@ private OCShare createShareInstance(Cursor c) {
12151212
share.setUserId(c.getLong(c.getColumnIndex(ProviderTableMeta.OCSHARES_USER_ID)));
12161213
share.setIdRemoteShared(c.getLong(c.getColumnIndex(ProviderTableMeta.OCSHARES_ID_REMOTE_SHARED)));
12171214
share.setIsPasswordProtected(c.getInt(c.getColumnIndex(ProviderTableMeta.OCSHARES_IS_PASSWORD_PROTECTED)) == 1);
1215+
share.setNote(c.getString(c.getColumnIndex(ProviderTableMeta.OCSHARES_NOTE)));
12181216
}
12191217
return share;
12201218
}
@@ -1313,16 +1311,13 @@ public void saveShares(Collection<OCShare> shares) {
13131311
cv.put(ProviderTableMeta.OCSHARES_SHARED_DATE, share.getSharedDate());
13141312
cv.put(ProviderTableMeta.OCSHARES_EXPIRATION_DATE, share.getExpirationDate());
13151313
cv.put(ProviderTableMeta.OCSHARES_TOKEN, share.getToken());
1316-
cv.put(
1317-
ProviderTableMeta.OCSHARES_SHARE_WITH_DISPLAY_NAME,
1318-
share.getSharedWithDisplayName()
1319-
);
1314+
cv.put(ProviderTableMeta.OCSHARES_SHARE_WITH_DISPLAY_NAME, share.getSharedWithDisplayName());
13201315
cv.put(ProviderTableMeta.OCSHARES_IS_DIRECTORY, share.isFolder() ? 1 : 0);
13211316
cv.put(ProviderTableMeta.OCSHARES_USER_ID, share.getUserId());
13221317
cv.put(ProviderTableMeta.OCSHARES_ID_REMOTE_SHARED, share.getRemoteId());
13231318
cv.put(ProviderTableMeta.OCSHARES_ACCOUNT_OWNER, mAccount.name);
1324-
13251319
cv.put(ProviderTableMeta.OCSHARES_IS_PASSWORD_PROTECTED, share.isPasswordProtected() ? 1 : 0);
1320+
cv.put(ProviderTableMeta.OCSHARES_NOTE, share.getNote());
13261321

13271322
if (shareExistsForRemoteId(share.getRemoteId())) {
13281323
// updating an existing file
@@ -1596,23 +1591,17 @@ private ArrayList<ContentProviderOperation> prepareInsertShares(
15961591
cv.put(ProviderTableMeta.OCSHARES_SHARED_DATE, share.getSharedDate());
15971592
cv.put(ProviderTableMeta.OCSHARES_EXPIRATION_DATE, share.getExpirationDate());
15981593
cv.put(ProviderTableMeta.OCSHARES_TOKEN, share.getToken());
1599-
cv.put(
1600-
ProviderTableMeta.OCSHARES_SHARE_WITH_DISPLAY_NAME,
1601-
share.getSharedWithDisplayName()
1602-
);
1594+
cv.put(ProviderTableMeta.OCSHARES_SHARE_WITH_DISPLAY_NAME, share.getSharedWithDisplayName());
16031595
cv.put(ProviderTableMeta.OCSHARES_IS_DIRECTORY, share.isFolder() ? 1 : 0);
16041596
cv.put(ProviderTableMeta.OCSHARES_USER_ID, share.getUserId());
16051597
cv.put(ProviderTableMeta.OCSHARES_ID_REMOTE_SHARED, share.getRemoteId());
16061598
cv.put(ProviderTableMeta.OCSHARES_ACCOUNT_OWNER, mAccount.name);
1607-
16081599
cv.put(ProviderTableMeta.OCSHARES_IS_PASSWORD_PROTECTED, share.isPasswordProtected() ? 1 : 0);
1600+
cv.put(ProviderTableMeta.OCSHARES_NOTE, share.getNote());
16091601

16101602
// adding a new share resource
1611-
operations.add(
1612-
ContentProviderOperation.newInsert(ProviderTableMeta.CONTENT_URI_SHARE).
1613-
withValues(cv).
1614-
build()
1615-
);
1603+
operations.add(ContentProviderOperation.newInsert(
1604+
ProviderTableMeta.CONTENT_URI_SHARE).withValues(cv).build());
16161605
}
16171606
}
16181607
return operations;

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
public class ProviderMeta {
3333

3434
public static final String DB_NAME = "filelist";
35-
public static final int DB_VERSION = 34;
35+
public static final int DB_VERSION = 35;
3636

3737
private ProviderMeta() {
3838
}
@@ -129,6 +129,7 @@ static public class ProviderTableMeta implements BaseColumns {
129129
public static final String OCSHARES_ID_REMOTE_SHARED = "id_remote_shared";
130130
public static final String OCSHARES_ACCOUNT_OWNER = "owner_share";
131131
public static final String OCSHARES_IS_PASSWORD_PROTECTED = "is_password_protected";
132+
public static final String OCSHARES_NOTE = "note";
132133

133134
public static final String OCSHARES_DEFAULT_SORT_ORDER = OCSHARES_FILE_SOURCE
134135
+ " collate nocase asc";
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
* Nextcloud Android client application
3+
*
4+
* @author Tobias Kaminsky
5+
* Copyright (C) 2018 Tobias Kaminsky
6+
* Copyright (C) 2018 Nextcloud GmbH.
7+
*
8+
* This program is free software: you can redistribute it and/or modify
9+
* it under the terms of the GNU General Public License as published by
10+
* the Free Software Foundation, either version 3 of the License, or
11+
* (at your option) any later version.
12+
*
13+
* This program is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
* GNU General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU General Public License
19+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
20+
*/
21+
22+
package com.owncloud.android.operations;
23+
24+
import com.owncloud.android.lib.common.OwnCloudClient;
25+
import com.owncloud.android.lib.common.operations.RemoteOperation;
26+
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
27+
import com.owncloud.android.lib.resources.shares.GetRemoteShareOperation;
28+
import com.owncloud.android.lib.resources.shares.OCShare;
29+
import com.owncloud.android.lib.resources.shares.UpdateRemoteShareOperation;
30+
import com.owncloud.android.operations.common.SyncOperation;
31+
32+
33+
/**
34+
* Updates a note of a private share.
35+
*/
36+
public class UpdateNoteForShareOperation extends SyncOperation {
37+
38+
private long shareId;
39+
private String note;
40+
41+
public UpdateNoteForShareOperation(long shareId, String note) {
42+
this.shareId = shareId;
43+
this.note = note;
44+
}
45+
46+
@Override
47+
protected RemoteOperationResult run(OwnCloudClient client) {
48+
49+
OCShare share = getStorageManager().getShareById(shareId);
50+
51+
if (share == null) {
52+
return new RemoteOperationResult(RemoteOperationResult.ResultCode.SHARE_NOT_FOUND);
53+
}
54+
55+
UpdateRemoteShareOperation updateOperation = new UpdateRemoteShareOperation(share.getRemoteId());
56+
updateOperation.setNote(note);
57+
RemoteOperationResult result = updateOperation.execute(client);
58+
59+
if (result.isSuccess()) {
60+
RemoteOperation getShareOp = new GetRemoteShareOperation(share.getRemoteId());
61+
result = getShareOp.execute(client);
62+
if (result.isSuccess()) {
63+
getStorageManager().saveShare((OCShare) result.getData().get(0));
64+
}
65+
}
66+
67+
return result;
68+
}
69+
}
70+

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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -770,7 +770,8 @@ private void createOCSharesTable(SQLiteDatabase db) {
770770
+ ProviderTableMeta.OCSHARES_USER_ID + INTEGER
771771
+ ProviderTableMeta.OCSHARES_ID_REMOTE_SHARED + INTEGER
772772
+ ProviderTableMeta.OCSHARES_ACCOUNT_OWNER + TEXT
773-
+ ProviderTableMeta.OCSHARES_IS_PASSWORD_PROTECTED + " INTEGER );");
773+
+ ProviderTableMeta.OCSHARES_IS_PASSWORD_PROTECTED + INTEGER
774+
+ ProviderTableMeta.OCSHARES_NOTE + " TEXT );");
774775
}
775776

776777
private void createCapabilitiesTable(SQLiteDatabase db) {
@@ -1745,6 +1746,24 @@ public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
17451746
if (!upgraded) {
17461747
Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
17471748
}
1749+
1750+
if (oldVersion < 35 && newVersion >= 35) {
1751+
Log_OC.i(SQL, "Entering in the #35 add note to share table");
1752+
db.beginTransaction();
1753+
try {
1754+
db.execSQL(ALTER_TABLE + ProviderTableMeta.OCSHARES_TABLE_NAME +
1755+
ADD_COLUMN + ProviderTableMeta.OCSHARES_NOTE + " TEXT ");
1756+
1757+
upgraded = true;
1758+
db.setTransactionSuccessful();
1759+
} finally {
1760+
db.endTransaction();
1761+
}
1762+
}
1763+
1764+
if (!upgraded) {
1765+
Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
1766+
}
17481767
}
17491768

17501769
@Override

0 commit comments

Comments
 (0)