Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,130 changes: 1,130 additions & 0 deletions app/schemas/com.nextcloud.client.database.NextcloudDatabase/67.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,12 @@

import com.owncloud.android.db.ProviderMeta;

public class FileDataStorageManagerContentProviderClientIT extends FileDataStorageManagerIT {
import org.junit.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

@Override
public class FileDataStorageManagerContentProviderClientIT extends FileDataStorageManagerIT {
public void before() {
sut = new FileDataStorageManager(user,
targetContext
Expand All @@ -36,4 +39,24 @@ public void before() {

super.before();
}

@Test
public void saveFile() {

String path = "/1.txt";
OCFile file = new OCFile(path);
file.setRemoteId("00000008ocjycgrudn78");

// TODO check via reflection that every parameter is set

file.setFileLength(1024000);
file.setModificationTimestamp(1582019340);
sut.saveNewFile(file);


OCFile read = sut.getFileByPath(path);
assertNotNull(read);

assertEquals(file.getRemotePath(), read.getRemotePath());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ public void testSaveNewFile() {
targetContext).execute(client).isSuccess());

OCFile newFile = new OCFile("/1/1/1.txt");
newFile.setRemoteId("123");
newFile.setRemoteId("12345678");

sut.saveNewFile(newFile);
}
Expand All @@ -369,4 +369,5 @@ public void testOCCapability() {

assertEquals(capability.getUserStatus(), newCapability.getUserStatus());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ public void keepNew() {
OCFile existingFile = new OCFile("/newFile.txt");
existingFile.setFileLength(1024000);
existingFile.setModificationTimestamp(1582019340);
existingFile.setRemoteId("123abc");
existingFile.setRemoteId("00000123abc");

OCFile newFile = new OCFile("/newFile.txt");
newFile.setFileLength(56000);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ class GalleryFragmentIT : AbstractIT() {
fun before() {
activity = testActivityRule.launchActivity(null)

createImage(1, true, 700, 300)
createImage(2, true, 500, 300)
createImage(10000001, true, 700, 300)
createImage(10000002, true, 500, 300)

createImage(7, true, 300, 400)
createImage(10000007, true, 300, 400)
}

@After
Expand All @@ -73,14 +73,14 @@ class GalleryFragmentIT : AbstractIT() {
longSleep()
}

private fun createImage(int: Int, createPreview: Boolean = true, width: Int? = null, height: Int? = null) {
private fun createImage(id: Int, createPreview: Boolean = true, width: Int? = null, height: Int? = null) {
val defaultSize = ThumbnailsCacheManager.getThumbnailDimension().toFloat()
val file = OCFile("/$int.png").apply {
fileId = int.toLong()
remoteId = "$int"
val file = OCFile("/$id.png").apply {
fileId = id.toLong()
remoteId = "$id"
mimeType = "image/png"
isPreviewAvailable = true
modificationTimestamp = (1658475504 + int.toLong()) * 1000
modificationTimestamp = (1658475504 + id.toLong()) * 1000
imageDimension = ImageDimension(width?.toFloat() ?: defaultSize, height?.toFloat() ?: defaultSize)
storageManager.saveFile(this)
}
Expand Down Expand Up @@ -116,6 +116,6 @@ class GalleryFragmentIT : AbstractIT() {

assertNotNull(ThumbnailsCacheManager.getBitmapFromDiskCache(PREFIX_RESIZED_IMAGE + file.remoteId))

Log_OC.d("Gallery_thumbnail", "created $int with ${bitmap.width} x ${bitmap.height}")
Log_OC.d("Gallery_thumbnail", "created $id with ${bitmap.width} x ${bitmap.height}")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ import com.owncloud.android.db.ProviderMeta
],
version = ProviderMeta.DB_VERSION,
autoMigrations = [
AutoMigration(from = 65, to = 66)
AutoMigration(from = 65, to = 66),
AutoMigration(from = 66, to = 67)
],
exportSchema = true
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ data class FileEntity(
val permissions: String?,
@ColumnInfo(name = ProviderTableMeta.FILE_REMOTE_ID)
val remoteId: String?,
@ColumnInfo(name = ProviderTableMeta.FILE_LOCAL_ID)
val localId: Long?,
@ColumnInfo(name = ProviderTableMeta.FILE_UPDATE_THUMBNAIL)
val updateThumbnail: Int?,
@ColumnInfo(name = ProviderTableMeta.FILE_IS_DOWNLOADING)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import com.owncloud.android.lib.common.OwnCloudClient

internal class LoadUrlTask(
private val client: OwnCloudClient,
private val fileId: String,
private val fileId: Long,
private val onResult: (String?) -> Unit
) : AsyncTask<Void, Void, String>() {

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/nextcloud/client/media/Player.kt
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ internal class Player(
checkNotNull(user)
playedFile?.let {
val client = clientFactory.create(user)
val task = LoadUrlTask(client, it.remoteId, this@Player::onDownloaded)
val task = LoadUrlTask(client, it.localId, this@Player::onDownloaded)
task.execute()
loadUrlTask = task
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,7 @@ private ContentValues createContentValuesBase(OCFile fileOrFolder) {
cv.put(ProviderTableMeta.FILE_SHARED_WITH_SHAREE, fileOrFolder.isSharedWithSharee() ? 1 : 0);
cv.put(ProviderTableMeta.FILE_PERMISSIONS, fileOrFolder.getPermissions());
cv.put(ProviderTableMeta.FILE_REMOTE_ID, fileOrFolder.getRemoteId());
cv.put(ProviderTableMeta.FILE_LOCAL_ID, fileOrFolder.getLocalId());
cv.put(ProviderTableMeta.FILE_FAVORITE, fileOrFolder.isFavorite());
cv.put(ProviderTableMeta.FILE_UNREAD_COMMENTS_COUNT, fileOrFolder.getUnreadCommentsCount());
cv.put(ProviderTableMeta.FILE_OWNER_ID, fileOrFolder.getOwnerId());
Expand Down Expand Up @@ -903,6 +904,7 @@ private OCFile createFileInstance(FileEntity fileEntity) {
ocFile.setSharedWithSharee(nullToZero(fileEntity.getSharedWithSharee()) == 1);
ocFile.setPermissions(fileEntity.getPermissions());
ocFile.setRemoteId(fileEntity.getRemoteId());
ocFile.setLocalId(fileEntity.getLocalId());
ocFile.setUpdateThumbnailNeeded(nullToZero(fileEntity.getUpdateThumbnail()) == 1);
ocFile.setDownloading(nullToZero(fileEntity.isDownloading()) == 1);
ocFile.setEtagInConflict(fileEntity.getEtagInConflict());
Expand Down
29 changes: 17 additions & 12 deletions app/src/main/java/com/owncloud/android/datamodel/OCFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import androidx.core.content.FileProvider;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import third_parties.daveKoeller.AlphanumComparator;

public class OCFile implements Parcelable, Comparable<OCFile>, ServerFileInterface {
Expand Down Expand Up @@ -83,6 +84,7 @@ public class OCFile implements Parcelable, Comparable<OCFile>, ServerFileInterfa
private String etagOnServer;
private boolean sharedViaLink;
private String permissions;
private long localId; // unique fileId for the file within the instance
private String remoteId; // The fileid namespaced by the instance fileId, globally unique
private boolean updateThumbnailNeeded;
private boolean downloading;
Expand Down Expand Up @@ -166,6 +168,7 @@ private OCFile(Parcel source) {
etagOnServer = source.readString();
sharedViaLink = source.readInt() == 1;
permissions = source.readString();
localId = source.readLong();
remoteId = source.readString();
updateThumbnailNeeded = source.readInt() == 1;
downloading = source.readInt() == 1;
Expand Down Expand Up @@ -208,6 +211,7 @@ public void writeToParcel(Parcel dest, int flags) {
dest.writeString(etagOnServer);
dest.writeInt(sharedViaLink ? 1 : 0);
dest.writeString(permissions);
dest.writeLong(localId);
dest.writeString(remoteId);
dest.writeInt(updateThumbnailNeeded ? 1 : 0);
dest.writeInt(downloading ? 1 : 0);
Expand Down Expand Up @@ -284,8 +288,7 @@ public String getRemotePath() {
}

/**
* Can be used to check, whether or not this file exists in the database
* already
* Can be used to check, whether or not this file exists in the database already
*
* @return true, if the file exists in the database
*/
Expand Down Expand Up @@ -486,6 +489,7 @@ private void resetData() {
etagOnServer = null;
sharedViaLink = false;
permissions = null;
localId = -1;
remoteId = null;
updateThumbnailNeeded = false;
downloading = false;
Expand Down Expand Up @@ -594,17 +598,14 @@ public boolean isHidden() {
return !TextUtils.isEmpty(getFileName()) && getFileName().charAt(0) == '.';
}

/**
* The unique fileId for the file within the instance
*
* @return file fileId, unique within the instance
*/
@Nullable
public String getLocalId() {
if (getRemoteId() != null) {
return getRemoteId().substring(0, 8).replaceAll("^0*", "");
@SuppressFBWarnings("STT")
public long getLocalId() {
if (localId > 0) {
return localId;
} else if (remoteId != null) {
return Long.parseLong(remoteId.substring(0, 8).replaceAll("^0*", ""));
} else {
return null;
return -1;
}
}

Expand Down Expand Up @@ -772,6 +773,10 @@ public void setFileId(long fileId) {
this.fileId = fileId;
}

public void setLocalId(long localId) {
this.localId = localId;
}

public void setParentId(long parentId) {
this.parentId = parentId;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,7 @@ private Bitmap doThumbnailFromOCFileInBackground() {
Bitmap bitmap;
if (MimeTypeUtil.isVideo(ocFile)) {
bitmap = ThumbnailUtils.createVideoThumbnail(ocFile.getStoragePath(),
MediaStore.Images.Thumbnails.MINI_KIND);
MediaStore.Images.Thumbnails.MINI_KIND);
} else {
bitmap = BitmapUtils.decodeSampledBitmapFromFile(ocFile.getStoragePath(), pxW, pxH);
}
Expand Down Expand Up @@ -733,16 +733,16 @@ private Bitmap doThumbnailFromOCFileInBackground() {
pxW + "/" + pxH + Uri.encode(file.getRemotePath(), "/");
} else {
uri = mClient.getBaseUri() + "/index.php/apps/files_trashbin/preview?fileId=" +
file.getLocalId() + "&x=" + pxW + "&y=" + pxH;
file.getLocalId() + "&x=" + pxW + "&y=" + pxH;
}

Log_OC.d(TAG, "generate thumbnail: " + file.getFileName() + " URI: " + uri);
getMethod = new GetMethod(uri);
getMethod.setRequestHeader("Cookie",
"nc_sameSiteCookielax=true;nc_sameSiteCookiestrict=true");
"nc_sameSiteCookielax=true;nc_sameSiteCookiestrict=true");

getMethod.setRequestHeader(RemoteOperation.OCS_API_HEADER,
RemoteOperation.OCS_API_HEADER_VALUE);
RemoteOperation.OCS_API_HEADER_VALUE);

int status = mClient.executeMethod(getMethod, READ_TIMEOUT, CONNECTION_TIMEOUT);
if (status == HttpStatus.SC_OK) {
Expand Down
4 changes: 3 additions & 1 deletion app/src/main/java/com/owncloud/android/db/ProviderMeta.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
*/
public class ProviderMeta {
public static final String DB_NAME = "filelist";
public static final int DB_VERSION = 66;
public static final int DB_VERSION = 67;

private ProviderMeta() {
// No instance
Expand Down Expand Up @@ -101,6 +101,7 @@ static public class ProviderTableMeta implements BaseColumns {
public static final String FILE_SHARED_VIA_LINK = "share_by_link";
public static final String FILE_SHARED_WITH_SHAREE = "shared_via_users";
public static final String FILE_PERMISSIONS = "permissions";
public static final String FILE_LOCAL_ID = "local_id";
public static final String FILE_REMOTE_ID = "remote_id";
public static final String FILE_UPDATE_THUMBNAIL = "update_thumbnail";
public static final String FILE_IS_DOWNLOADING = "is_downloading";
Expand Down Expand Up @@ -148,6 +149,7 @@ static public class ProviderTableMeta implements BaseColumns {
FILE_SHARED_WITH_SHAREE,
FILE_PERMISSIONS,
FILE_REMOTE_ID,
FILE_LOCAL_ID,
FILE_UPDATE_THUMBNAIL,
FILE_IS_DOWNLOADING,
FILE_ETAG_IN_CONFLICT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ public class StreamMediaFileOperation extends RemoteOperation {
private static final int SYNC_CONNECTION_TIMEOUT = 5000;
private static final String STREAM_MEDIA_URL = "/ocs/v2.php/apps/dav/api/v1/direct";

private String fileID;
private final long fileID;

// JSON node names
private static final String NODE_OCS = "ocs";
private static final String NODE_DATA = "data";
private static final String NODE_URL = "url";
private static final String JSON_FORMAT = "?format=json";

public StreamMediaFileOperation(String fileID) {
public StreamMediaFileOperation(long fileID) {
this.fileID = fileID;
}

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

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

// remote request
postMethod.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@
public class CommentFileOperation extends RemoteOperation {

private final String message;
private final String fileId;
private final long fileId;

/**
* Constructor
*
* @param message Comment to store
*/
public CommentFileOperation(String message, String fileId) {
public CommentFileOperation(String message, long fileId) {
this.message = message;
this.fileId = fileId;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ public class RemoveRemoteEncryptedFileOperation extends RemoteOperation {
private static final int REMOVE_READ_TIMEOUT = 30000;
private static final int REMOVE_CONNECTION_TIMEOUT = 5000;

private String remotePath;
private String parentId;
private final String remotePath;
private final long parentId;
private User user;

private ArbitraryDataProvider arbitraryDataProvider;
private String fileName;
private final ArbitraryDataProvider arbitraryDataProvider;
private final String fileName;

/**
* Constructor
Expand All @@ -76,7 +76,7 @@ public class RemoveRemoteEncryptedFileOperation extends RemoteOperation {
* @param parentId local id of parent folder
*/
RemoveRemoteEncryptedFileOperation(String remotePath,
String parentId,
long parentId,
User user,
Context context,
String fileName) {
Expand Down
Loading