|
@@ -1,21 +1,20 @@
|
|
|
/**
|
|
|
- * ownCloud Android client application
|
|
|
- *
|
|
|
- * Copyright (C) 2012 Bartek Przybylski
|
|
|
- * Copyright (C) 2015 ownCloud Inc.
|
|
|
- *
|
|
|
- * This program is free software: you can redistribute it and/or modify
|
|
|
- * it under the terms of the GNU General Public License version 2,
|
|
|
- * as published by the Free Software Foundation.
|
|
|
- *
|
|
|
- * This program is distributed in the hope that it will be useful,
|
|
|
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
- * GNU General Public License for more details.
|
|
|
- *
|
|
|
- * You should have received a copy of the GNU General Public License
|
|
|
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
- *
|
|
|
+ * ownCloud Android client application
|
|
|
+ * <p>
|
|
|
+ * Copyright (C) 2012 Bartek Przybylski
|
|
|
+ * Copyright (C) 2015 ownCloud Inc.
|
|
|
+ * <p>
|
|
|
+ * This program is free software: you can redistribute it and/or modify
|
|
|
+ * it under the terms of the GNU General Public License version 2,
|
|
|
+ * as published by the Free Software Foundation.
|
|
|
+ * <p>
|
|
|
+ * This program is distributed in the hope that it will be useful,
|
|
|
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
+ * GNU General Public License for more details.
|
|
|
+ * <p>
|
|
|
+ * You should have received a copy of the GNU General Public License
|
|
|
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
*/
|
|
|
|
|
|
package com.owncloud.android.datamodel;
|
|
@@ -164,7 +163,7 @@ public class FileDataStorageManager {
|
|
|
// TODO better implementation, filtering in the access to database instead of here
|
|
|
Vector<OCFile> tmp = getFolderContent(folder, onlyOnDevice);
|
|
|
OCFile current = null;
|
|
|
- for (int i=0; i<tmp.size(); i++) {
|
|
|
+ for (int i = 0; i < tmp.size(); i++) {
|
|
|
current = tmp.get(i);
|
|
|
if (MimeTypeUtil.isImage(current)) {
|
|
|
ret.add(current);
|
|
@@ -253,7 +252,7 @@ public class FileDataStorageManager {
|
|
|
|
|
|
public OCFile saveFileWithParent(OCFile file, Context context) {
|
|
|
if (file.getParentId() != 0 || file.getRemotePath().equals("/")) {
|
|
|
- saveFile(file);
|
|
|
+// nothing needed
|
|
|
|
|
|
} else {
|
|
|
String remotePath = file.getRemotePath();
|
|
@@ -313,7 +312,7 @@ public class FileDataStorageManager {
|
|
|
OCFile folder, Collection<OCFile> updatedFiles, Collection<OCFile> filesToRemove
|
|
|
) {
|
|
|
|
|
|
- Log_OC.d(TAG, "Saving folder " + folder.getRemotePath() + " with " + updatedFiles.size()
|
|
|
+ Log_OC.d(TAG, "Saving folder " + folder.getRemotePath() + " with " + updatedFiles.size()
|
|
|
+ " children and " + filesToRemove.size() + " files to remove");
|
|
|
|
|
|
ArrayList<ContentProviderOperation> operations =
|
|
@@ -371,7 +370,7 @@ public class FileDataStorageManager {
|
|
|
// prepare operations to remove files in the given folder
|
|
|
String where = ProviderTableMeta.FILE_ACCOUNT_OWNER + AND +
|
|
|
ProviderTableMeta.FILE_PATH + "=?";
|
|
|
- String [] whereArgs = null;
|
|
|
+ String[] whereArgs = null;
|
|
|
for (OCFile file : filesToRemove) {
|
|
|
if (file.getParentId() == folder.getFileId()) {
|
|
|
whereArgs = new String[]{mAccount.name, file.getRemotePath()};
|
|
@@ -536,7 +535,7 @@ public class FileDataStorageManager {
|
|
|
Uri folder_uri = Uri.withAppendedPath(ProviderTableMeta.CONTENT_URI_DIR, "" + folder.getFileId()); // URI
|
|
|
// for recursive deletion
|
|
|
String where = ProviderTableMeta.FILE_ACCOUNT_OWNER + AND + ProviderTableMeta.FILE_PATH + "=?";
|
|
|
- String [] whereArgs = new String[]{mAccount.name, folder.getRemotePath()};
|
|
|
+ String[] whereArgs = new String[]{mAccount.name, folder.getRemotePath()};
|
|
|
int deleted = 0;
|
|
|
if (getContentProviderClient() != null) {
|
|
|
try {
|
|
@@ -830,9 +829,9 @@ public class FileDataStorageManager {
|
|
|
if (c != null && c.moveToFirst()) {
|
|
|
do {
|
|
|
OCFile child = createFileInstance(c);
|
|
|
- if (child.isFolder() || !onlyOnDevice || child.isDown()) {
|
|
|
- ret.add(child);
|
|
|
- }
|
|
|
+ if (child.isFolder() || !onlyOnDevice || child.isDown()) {
|
|
|
+ ret.add(child);
|
|
|
+ }
|
|
|
} while (c.moveToNext());
|
|
|
c.close();
|
|
|
}
|
|
@@ -1024,7 +1023,7 @@ public class FileDataStorageManager {
|
|
|
* Retrieves an stored {@link OCShare} given its id.
|
|
|
*
|
|
|
* @param id Identifier.
|
|
|
- * @return Stored {@link OCShare} given its id.
|
|
|
+ * @return Stored {@link OCShare} given its id.
|
|
|
*/
|
|
|
public OCShare getShareById(long id) {
|
|
|
OCShare share = null;
|
|
@@ -1082,7 +1081,7 @@ public class FileDataStorageManager {
|
|
|
.query(ProviderTableMeta.CONTENT_URI_SHARE,
|
|
|
null,
|
|
|
key + AND
|
|
|
- + ProviderTableMeta.OCSHARES_ACCOUNT_OWNER + "=?",
|
|
|
+ + ProviderTableMeta.OCSHARES_ACCOUNT_OWNER + "=?",
|
|
|
new String[]{value, mAccount.name},
|
|
|
null
|
|
|
);
|
|
@@ -1096,7 +1095,7 @@ public class FileDataStorageManager {
|
|
|
null
|
|
|
);
|
|
|
} catch (RemoteException e) {
|
|
|
- Log_OC.w(TAG, "Could not get details, assuming share does not exist: "+ e.getMessage());
|
|
|
+ Log_OC.w(TAG, "Could not get details, assuming share does not exist: " + e.getMessage());
|
|
|
c = null;
|
|
|
}
|
|
|
}
|
|
@@ -1104,14 +1103,13 @@ public class FileDataStorageManager {
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
* Get first share bound to a file with a known path and given {@link ShareType}.
|
|
|
*
|
|
|
* @param path Path of the file.
|
|
|
* @param type Type of the share to get
|
|
|
* @param shareWith Target of the share. Ignored in type is {@link ShareType#PUBLIC_LINK}
|
|
|
- * @return First {@link OCShare} instance found in DB bound to the file in 'path'
|
|
|
+ * @return First {@link OCShare} instance found in DB bound to the file in 'path'
|
|
|
*/
|
|
|
public OCShare getFirstShareByPathAndType(String path, ShareType type, String shareWith) {
|
|
|
Cursor cursor = null;
|
|
@@ -1121,12 +1119,12 @@ public class FileDataStorageManager {
|
|
|
|
|
|
String selection = ProviderTableMeta.OCSHARES_PATH + AND
|
|
|
+ ProviderTableMeta.OCSHARES_SHARE_TYPE + AND
|
|
|
- + ProviderTableMeta.OCSHARES_ACCOUNT_OWNER + "=?" ;
|
|
|
+ + ProviderTableMeta.OCSHARES_ACCOUNT_OWNER + "=?";
|
|
|
if (!ShareType.PUBLIC_LINK.equals(type)) {
|
|
|
selection += " AND " + ProviderTableMeta.OCSHARES_SHARE_WITH + "=?";
|
|
|
}
|
|
|
|
|
|
- String [] selectionArgs;
|
|
|
+ String[] selectionArgs;
|
|
|
if (ShareType.PUBLIC_LINK.equals(type)) {
|
|
|
selectionArgs = new String[]{
|
|
|
path,
|
|
@@ -1219,7 +1217,7 @@ public class FileDataStorageManager {
|
|
|
cv.put(ProviderTableMeta.FILE_SHARED_WITH_SHAREE, false);
|
|
|
cv.put(ProviderTableMeta.FILE_PUBLIC_LINK, "");
|
|
|
String where = ProviderTableMeta.FILE_ACCOUNT_OWNER + AND + ProviderTableMeta.FILE_PARENT + "=?";
|
|
|
- String [] whereArgs = new String[] { mAccount.name , String.valueOf(folder.getFileId()) };
|
|
|
+ String[] whereArgs = new String[]{mAccount.name, String.valueOf(folder.getFileId())};
|
|
|
|
|
|
if (getContentResolver() != null) {
|
|
|
getContentResolver().update(ProviderTableMeta.CONTENT_URI, cv, where, whereArgs);
|
|
@@ -1233,13 +1231,13 @@ public class FileDataStorageManager {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void resetShareFlagInAFile(String filePath){
|
|
|
+ private void resetShareFlagInAFile(String filePath) {
|
|
|
ContentValues cv = new ContentValues();
|
|
|
cv.put(ProviderTableMeta.FILE_SHARED_VIA_LINK, false);
|
|
|
cv.put(ProviderTableMeta.FILE_SHARED_WITH_SHAREE, false);
|
|
|
cv.put(ProviderTableMeta.FILE_PUBLIC_LINK, "");
|
|
|
- String where = ProviderTableMeta.FILE_ACCOUNT_OWNER + AND + ProviderTableMeta.FILE_PATH+ "=?";
|
|
|
- String [] whereArgs = new String[] { mAccount.name , filePath };
|
|
|
+ String where = ProviderTableMeta.FILE_ACCOUNT_OWNER + AND + ProviderTableMeta.FILE_PATH + "=?";
|
|
|
+ String[] whereArgs = new String[]{mAccount.name, filePath};
|
|
|
|
|
|
if (getContentResolver() != null) {
|
|
|
getContentResolver().update(ProviderTableMeta.CONTENT_URI, cv, where, whereArgs);
|
|
@@ -1426,7 +1424,7 @@ public class FileDataStorageManager {
|
|
|
Uri share_uri = ProviderTableMeta.CONTENT_URI_SHARE;
|
|
|
String where = ProviderTableMeta.OCSHARES_ACCOUNT_OWNER + AND +
|
|
|
ProviderTableMeta._ID + "=?";
|
|
|
- String [] whereArgs = new String[]{mAccount.name, Long.toString(share.getId())};
|
|
|
+ String[] whereArgs = new String[]{mAccount.name, Long.toString(share.getId())};
|
|
|
if (getContentProviderClient() != null) {
|
|
|
try {
|
|
|
getContentProviderClient().delete(share_uri, where, whereArgs);
|
|
@@ -1443,16 +1441,16 @@ public class FileDataStorageManager {
|
|
|
|
|
|
// Reset flags & Remove shares for this files
|
|
|
String filePath = "";
|
|
|
- for (OCShare share: shares) {
|
|
|
- if (filePath != share.getPath()){
|
|
|
+ for (OCShare share : shares) {
|
|
|
+ if (filePath != share.getPath()) {
|
|
|
filePath = share.getPath();
|
|
|
resetShareFlagInAFile(filePath);
|
|
|
operations = prepareRemoveSharesInFile(filePath, operations);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // Add operations to insert shares
|
|
|
- operations = prepareInsertShares(shares, operations);
|
|
|
+ // Add operations to insert shares
|
|
|
+ operations = prepareInsertShares(shares, operations);
|
|
|
|
|
|
// apply operations in batch
|
|
|
if (operations.size() > 0) {
|
|
@@ -1593,7 +1591,7 @@ public class FileDataStorageManager {
|
|
|
if (folder != null) {
|
|
|
String where = ProviderTableMeta.OCSHARES_PATH + AND
|
|
|
+ ProviderTableMeta.OCSHARES_ACCOUNT_OWNER + "=?";
|
|
|
- String [] whereArgs = new String[]{ "", mAccount.name };
|
|
|
+ String[] whereArgs = new String[]{"", mAccount.name};
|
|
|
|
|
|
Vector<OCFile> files = getFolderContent(folder, false);
|
|
|
|
|
@@ -1627,15 +1625,15 @@ public class FileDataStorageManager {
|
|
|
|
|
|
}
|
|
|
|
|
|
- public ArrayList<OCShare> getSharesWithForAFile(String filePath, String accountName){
|
|
|
+ public ArrayList<OCShare> getSharesWithForAFile(String filePath, String accountName) {
|
|
|
// Condition
|
|
|
String where = ProviderTableMeta.OCSHARES_PATH + AND
|
|
|
+ ProviderTableMeta.OCSHARES_ACCOUNT_OWNER + AND
|
|
|
+ " (" + ProviderTableMeta.OCSHARES_SHARE_TYPE + "=? OR "
|
|
|
- + ProviderTableMeta.OCSHARES_SHARE_TYPE + "=? OR "
|
|
|
- + ProviderTableMeta.OCSHARES_SHARE_TYPE + "=? OR "
|
|
|
+ + ProviderTableMeta.OCSHARES_SHARE_TYPE + "=? OR "
|
|
|
+ + ProviderTableMeta.OCSHARES_SHARE_TYPE + "=? OR "
|
|
|
+ ProviderTableMeta.OCSHARES_SHARE_TYPE + "=? ) ";
|
|
|
- String [] whereArgs = new String[]{ filePath, accountName ,
|
|
|
+ String[] whereArgs = new String[]{filePath, accountName,
|
|
|
Integer.toString(ShareType.USER.getValue()),
|
|
|
Integer.toString(ShareType.GROUP.getValue()),
|
|
|
Integer.toString(ShareType.EMAIL.getValue()),
|
|
@@ -1734,7 +1732,7 @@ public class FileDataStorageManager {
|
|
|
ProviderTableMeta.CONTENT_URI_FILE,
|
|
|
cv,
|
|
|
ProviderTableMeta._ID + "=?",
|
|
|
- new String[] { String.valueOf(file.getFileId())}
|
|
|
+ new String[]{String.valueOf(file.getFileId())}
|
|
|
);
|
|
|
} else {
|
|
|
try {
|
|
@@ -1871,7 +1869,7 @@ public class FileDataStorageManager {
|
|
|
|
|
|
}
|
|
|
|
|
|
- public OCCapability saveCapabilities(OCCapability capability){
|
|
|
+ public OCCapability saveCapabilities(OCCapability capability) {
|
|
|
|
|
|
// Prepare capabilities data
|
|
|
ContentValues cv = new ContentValues();
|
|
@@ -1958,7 +1956,7 @@ public class FileDataStorageManager {
|
|
|
return exists;
|
|
|
}
|
|
|
|
|
|
- private Cursor getCapabilityCursorForAccount(String accountName){
|
|
|
+ private Cursor getCapabilityCursorForAccount(String accountName) {
|
|
|
Cursor c = null;
|
|
|
if (getContentResolver() != null) {
|
|
|
c = getContentResolver()
|
|
@@ -1981,7 +1979,8 @@ public class FileDataStorageManager {
|
|
|
return c;
|
|
|
|
|
|
}
|
|
|
- public OCCapability getCapability(String accountName){
|
|
|
+
|
|
|
+ public OCCapability getCapability(String accountName) {
|
|
|
OCCapability capability = null;
|
|
|
Cursor c = getCapabilityCursorForAccount(accountName);
|
|
|
|
|
@@ -2065,6 +2064,19 @@ public class FileDataStorageManager {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public void saveVirtuals(VirtualFolderType type, List<ContentValues> values) {
|
|
|
+
|
|
|
+ if (getContentResolver() != null) {
|
|
|
+ getContentResolver().bulkInsert(ProviderTableMeta.CONTENT_URI_VIRTUAL, values.toArray(new ContentValues[values.size()]));
|
|
|
+ } else {
|
|
|
+ try {
|
|
|
+ getContentProviderClient().bulkInsert(ProviderTableMeta.CONTENT_URI_VIRTUAL, values.toArray(new ContentValues[values.size()]));
|
|
|
+ } catch (RemoteException e) {
|
|
|
+ Log_OC.e(TAG, FAILED_TO_INSERT_MSG + e.getMessage(), e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
public void saveVirtual(VirtualFolderType type, OCFile file) {
|
|
|
ContentValues cv = new ContentValues();
|
|
|
cv.put(ProviderTableMeta.VIRTUAL_TYPE, type.toString());
|
|
@@ -2112,7 +2124,7 @@ public class FileDataStorageManager {
|
|
|
if (c != null && c.moveToFirst()) {
|
|
|
do {
|
|
|
OCFile child = createFileInstanceFromVirtual(c);
|
|
|
- ocFiles.add(child);
|
|
|
+ ocFiles.add(child);
|
|
|
} while (c.moveToNext());
|
|
|
c.close();
|
|
|
}
|