Skip to content

Commit 173e7a0

Browse files
use localID everywhere, it is now long instead of String
Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
1 parent f29018b commit 173e7a0

12 files changed

Lines changed: 50 additions & 44 deletions

File tree

src/main/java/com/nextcloud/client/media/LoadUrlTask.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import com.owncloud.android.lib.common.OwnCloudClient
2828

2929
internal class LoadUrlTask(
3030
private val client: OwnCloudClient,
31-
private val fileId: String,
31+
private val fileId: Long,
3232
private val onResult: (String?) -> Unit
3333
) : AsyncTask<Void, Void, String>() {
3434

src/main/java/com/nextcloud/client/media/Player.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ internal class Player(
9696
checkNotNull(user)
9797
playedFile?.let {
9898
val client = clientFactory.create(user)
99-
val task = LoadUrlTask(client, it.remoteId, this@Player::onDownloaded)
99+
val task = LoadUrlTask(client, it.localId, this@Player::onDownloaded)
100100
task.execute()
101101
loadUrlTask = task
102102
}

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

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ public class OCFile implements Parcelable, Comparable<OCFile>, ServerFileInterfa
7777
private String etagOnServer;
7878
private boolean sharedViaLink;
7979
private String permissions;
80+
private long localId; // unique fileId for the file within the instance
8081
private String remoteId; // The fileid namespaced by the instance fileId, globally unique
8182
private boolean updateThumbnailNeeded;
8283
private boolean downloading;
@@ -151,6 +152,7 @@ private OCFile(Parcel source) {
151152
etagOnServer = source.readString();
152153
sharedViaLink = source.readInt() == 1;
153154
permissions = source.readString();
155+
localId = source.readLong();
154156
remoteId = source.readString();
155157
updateThumbnailNeeded = source.readInt() == 1;
156158
downloading = source.readInt() == 1;
@@ -184,6 +186,7 @@ public void writeToParcel(Parcel dest, int flags) {
184186
dest.writeString(etagOnServer);
185187
dest.writeInt(sharedViaLink ? 1 : 0);
186188
dest.writeString(permissions);
189+
dest.writeLong(localId);
187190
dest.writeString(remoteId);
188191
dest.writeInt(updateThumbnailNeeded ? 1 : 0);
189192
dest.writeInt(downloading ? 1 : 0);
@@ -250,9 +253,13 @@ public String getRemotePath() {
250253
}
251254
}
252255

256+
@Override
257+
public String getImageKey() {
258+
return remoteId;
259+
}
260+
253261
/**
254-
* Can be used to check, whether or not this file exists in the database
255-
* already
262+
* Can be used to check, whether or not this file exists in the database already
256263
*
257264
* @return true, if the file exists in the database
258265
*/
@@ -449,6 +456,7 @@ private void resetData() {
449456
etagOnServer = null;
450457
sharedViaLink = false;
451458
permissions = null;
459+
localId = -1;
452460
remoteId = null;
453461
updateThumbnailNeeded = false;
454462
downloading = false;
@@ -546,14 +554,8 @@ public boolean isHidden() {
546554
return !TextUtils.isEmpty(getFileName()) && getFileName().charAt(0) == '.';
547555
}
548556

549-
/**
550-
* The unique fileId for the file within the instance
551-
*
552-
* @return file fileId, unique within the instance
553-
*/
554-
public String getLocalId() {
555-
// fileId, instanceId. instanceId is 12 chars long
556-
return getRemoteId().substring(0, getRemoteId().length() - 12).replaceAll("^0*", "");
557+
public long getLocalId() {
558+
return localId;
557559
}
558560

559561
public boolean isInConflict() {

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,7 @@ public void setListener(Listener listener){
583583
private Bitmap doThumbnailFromOCFileInBackground() {
584584
Bitmap thumbnail;
585585
ServerFileInterface file = (ServerFileInterface) mFile;
586-
String imageKey = PREFIX_THUMBNAIL + file.getRemoteId();
586+
String imageKey = PREFIX_THUMBNAIL + file.getImageKey();
587587

588588
// Check disk cache in background thread
589589
thumbnail = getBitmapFromDiskCache(imageKey);
@@ -621,7 +621,7 @@ private Bitmap doThumbnailFromOCFileInBackground() {
621621

622622
if (thumbnail == null) {
623623
// check if resized version is available
624-
String resizedImageKey = PREFIX_RESIZED_IMAGE + file.getRemoteId();
624+
String resizedImageKey = PREFIX_RESIZED_IMAGE + file.getImageKey();
625625
Bitmap resizedImage = getBitmapFromDiskCache(resizedImageKey);
626626

627627
if (resizedImage != null) {
@@ -636,9 +636,11 @@ private Bitmap doThumbnailFromOCFileInBackground() {
636636
if (file instanceof OCFile) {
637637
uri = mClient.getBaseUri() + "/index.php/apps/files/api/v1/thumbnail/" +
638638
pxW + "/" + pxH + Uri.encode(file.getRemotePath(), "/");
639-
} else {
639+
} else if (file instanceof TrashbinFile) {
640640
uri = mClient.getBaseUri() + "/index.php/apps/files_trashbin/preview?fileId=" +
641-
file.getLocalId() + "&x=" + pxW + "&y=" + pxH;
641+
((TrashbinFile) file).getRemoteId() + "&x=" + pxW + "&y=" + pxH;
642+
} else {
643+
return null;
642644
}
643645

644646
Log_OC.d(TAG, "generate thumbnail: " + file.getFileName() + " URI: " + uri);

src/main/java/com/owncloud/android/files/StreamMediaFileOperation.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,15 @@ public class StreamMediaFileOperation extends RemoteOperation {
3737
private static final int SYNC_CONNECTION_TIMEOUT = 5000;
3838
private static final String STREAM_MEDIA_URL = "/ocs/v2.php/apps/dav/api/v1/direct";
3939

40-
private String fileID;
40+
private final long fileID;
4141

4242
// JSON node names
4343
private static final String NODE_OCS = "ocs";
4444
private static final String NODE_DATA = "data";
4545
private static final String NODE_URL = "url";
4646
private static final String JSON_FORMAT = "?format=json";
4747

48-
public StreamMediaFileOperation(String fileID) {
48+
public StreamMediaFileOperation(long fileID) {
4949
this.fileID = fileID;
5050
}
5151

@@ -55,7 +55,7 @@ protected RemoteOperationResult run(OwnCloudClient client) {
5555

5656
try {
5757
postMethod = new Utf8PostMethod(client.getBaseUri() + STREAM_MEDIA_URL + JSON_FORMAT);
58-
postMethod.setParameter("fileId", fileID);
58+
postMethod.setParameter("fileId", String.valueOf(fileID));
5959

6060
// remote request
6161
postMethod.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE);

src/main/java/com/owncloud/android/operations/CommentFileOperation.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,15 @@
3333
*/
3434
public class CommentFileOperation extends SyncOperation {
3535

36-
private String message;
37-
private String fileId;
36+
private final String message;
37+
private final long fileId;
3838

3939
/**
4040
* Constructor
4141
*
4242
* @param message Comment to store
4343
*/
44-
public CommentFileOperation(String message, String fileId) {
44+
public CommentFileOperation(String message, long fileId) {
4545
this.message = message;
4646
this.fileId = fileId;
4747
}

src/main/java/com/owncloud/android/operations/RemoveRemoteEncryptedFileOperation.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,12 @@ public class RemoveRemoteEncryptedFileOperation extends RemoteOperation {
6262
private static final int REMOVE_READ_TIMEOUT = 30000;
6363
private static final int REMOVE_CONNECTION_TIMEOUT = 5000;
6464

65-
private String remotePath;
66-
private String parentId;
67-
private Account account;
65+
private final String remotePath;
66+
private final long parentId;
67+
private final Account account;
6868

69-
private ArbitraryDataProvider arbitraryDataProvider;
70-
private String fileName;
69+
private final ArbitraryDataProvider arbitraryDataProvider;
70+
private final String fileName;
7171

7272
/**
7373
* Constructor
@@ -76,7 +76,7 @@ public class RemoveRemoteEncryptedFileOperation extends RemoteOperation {
7676
* @param parentId local id of parent folder
7777
*/
7878
RemoveRemoteEncryptedFileOperation(String remotePath,
79-
String parentId,
79+
long parentId,
8080
Account account,
8181
Context context,
8282
String fileName) {

src/main/java/com/owncloud/android/operations/RichDocumentsUrlOperation.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,10 @@ public class RichDocumentsUrlOperation extends RemoteOperation {
5151
private static final String NODE_URL = "url";
5252
private static final String JSON_FORMAT = "?format=json";
5353

54-
private String fileID;
54+
private final long fileId;
5555

56-
public RichDocumentsUrlOperation(String fileID) {
57-
this.fileID = fileID;
56+
public RichDocumentsUrlOperation(long fileID) {
57+
this.fileId = fileID;
5858
}
5959

6060
@NextcloudServer(max = 18)
@@ -64,7 +64,7 @@ protected RemoteOperationResult run(OwnCloudClient client) {
6464

6565
try {
6666
postMethod = new Utf8PostMethod(client.getBaseUri() + DOCUMENT_URL + JSON_FORMAT);
67-
postMethod.setParameter(FILE_ID, fileID);
67+
postMethod.setParameter(FILE_ID, String.valueOf(fileId));
6868

6969
// remote request
7070
postMethod.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE);
@@ -86,7 +86,7 @@ protected RemoteOperationResult run(OwnCloudClient client) {
8686
}
8787
} catch (Exception e) {
8888
result = new RemoteOperationResult(e);
89-
Log_OC.e(TAG, "Get rich document url for file with id " + fileID + " failed: " + result.getLogMessage(),
89+
Log_OC.e(TAG, "Get rich document url for file with id " + fileId + " failed: " + result.getLogMessage(),
9090
result.getException());
9191
} finally {
9292
if (postMethod != null) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,7 @@ private Pair<Target, RemoteOperation> newOperation(Intent operationIntent) {
677677

678678
case ACTION_RESTORE_VERSION:
679679
FileVersion fileVersion = operationIntent.getParcelableExtra(EXTRA_FILE_VERSION);
680-
operation = new RestoreFileVersionRemoteOperation(fileVersion.getRemoteId(),
680+
operation = new RestoreFileVersionRemoteOperation(fileVersion.getLocalId(),
681681
fileVersion.getFileName());
682682
break;
683683

src/main/java/com/owncloud/android/ui/events/EncryptionEvent.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@
2323
* Event for set folder as encrypted/decrypted
2424
*/
2525
public class EncryptionEvent {
26-
public final String localId;
26+
public final long localId;
2727
public final String remotePath;
2828
public final String remoteId;
2929
public final boolean shouldBeEncrypted;
3030

31-
public EncryptionEvent(String localId, String remoteId, String remotePath, boolean shouldBeEncrypted) {
31+
public EncryptionEvent(long localId, String remoteId, String remotePath, boolean shouldBeEncrypted) {
3232
this.localId = localId;
3333
this.remoteId = remoteId;
3434
this.remotePath = remotePath;

0 commit comments

Comments
 (0)