mirror of
https://github.com/nextcloud/android.git
synced 2024-12-19 15:33:00 +03:00
fix for #857
This commit is contained in:
parent
12ae31601a
commit
ac8b0b30bb
9 changed files with 368 additions and 52 deletions
|
@ -27,6 +27,7 @@ import android.content.ContentProviderResult;
|
|||
import android.content.ContentResolver;
|
||||
import android.content.ContentUris;
|
||||
import android.content.ContentValues;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.OperationApplicationException;
|
||||
import android.database.Cursor;
|
||||
|
@ -36,7 +37,10 @@ import android.provider.MediaStore;
|
|||
|
||||
import com.owncloud.android.MainApp;
|
||||
import com.owncloud.android.db.ProviderMeta.ProviderTableMeta;
|
||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
||||
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||
import com.owncloud.android.lib.resources.files.ReadRemoteFileOperation;
|
||||
import com.owncloud.android.lib.resources.files.RemoteFile;
|
||||
import com.owncloud.android.lib.resources.shares.OCShare;
|
||||
import com.owncloud.android.lib.resources.shares.ShareType;
|
||||
import com.owncloud.android.lib.resources.status.CapabilityBooleanType;
|
||||
|
@ -247,6 +251,39 @@ public class FileDataStorageManager {
|
|||
return overriden;
|
||||
}
|
||||
|
||||
public long saveFileWithParent(OCFile file, Context context) {
|
||||
if (file.getParentId() != 0 || file.getRemotePath().equals("/")) {
|
||||
saveFile(file);
|
||||
|
||||
} else {
|
||||
String remotePath = file.getRemotePath();
|
||||
String parentPath = remotePath.substring(0, remotePath.lastIndexOf(file.getFileName()));
|
||||
|
||||
OCFile parentFile = getFileByPath(parentPath);
|
||||
|
||||
long fileId;
|
||||
if (parentFile == null) {
|
||||
// remote request
|
||||
ReadRemoteFileOperation operation = new ReadRemoteFileOperation(parentPath);
|
||||
RemoteOperationResult result = operation.execute(getAccount(), context);
|
||||
if (result.isSuccess()) {
|
||||
OCFile remoteFolder = FileStorageUtils.fillOCFile((RemoteFile) result.getData().get(0));
|
||||
|
||||
fileId = saveFileWithParent(remoteFolder, context);
|
||||
} else {
|
||||
fileId = -1;
|
||||
Log_OC.e(TAG, "Error during saving file with parents: " + file.getRemotePath());
|
||||
}
|
||||
} else {
|
||||
fileId = saveFileWithParent(parentFile, context);
|
||||
}
|
||||
|
||||
file.setParentId(fileId);
|
||||
saveFile(file);
|
||||
}
|
||||
|
||||
return getFileByPath(file.getRemotePath()).getFileId();
|
||||
}
|
||||
|
||||
public void saveNewFile(OCFile newFile) {
|
||||
String remoteParentPath = new File(newFile.getRemotePath()).getParent();
|
||||
|
@ -868,6 +905,15 @@ public class FileDataStorageManager {
|
|||
return c;
|
||||
}
|
||||
|
||||
private OCFile createFileInstanceFromVirtual(Cursor c) {
|
||||
OCFile file = null;
|
||||
if (c != null) {
|
||||
long fileId = c.getLong(c.getColumnIndex(ProviderTableMeta.VIRTUAL_OCFILE_ID));
|
||||
file = getFileById(fileId);
|
||||
}
|
||||
|
||||
return file;
|
||||
}
|
||||
|
||||
private OCFile createFileInstance(Cursor c) {
|
||||
OCFile file = null;
|
||||
|
@ -2005,4 +2051,89 @@ public class FileDataStorageManager {
|
|||
return capability;
|
||||
}
|
||||
|
||||
public void deleteVirtuals(VirtualFolderType type) {
|
||||
if (getContentResolver() != null) {
|
||||
getContentResolver().delete(ProviderTableMeta.CONTENT_URI_VIRTUAL,
|
||||
ProviderTableMeta.VIRTUAL_TYPE + "=?", new String[]{String.valueOf(type)});
|
||||
} else {
|
||||
try {
|
||||
getContentProviderClient().delete(ProviderTableMeta.CONTENT_URI_VIRTUAL,
|
||||
ProviderTableMeta.VIRTUAL_TYPE + "=?", new String[]{String.valueOf(type)});
|
||||
} 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());
|
||||
cv.put(ProviderTableMeta.VIRTUAL_OCFILE_ID, file.getFileId());
|
||||
|
||||
if (getContentResolver() != null) {
|
||||
getContentResolver().insert(ProviderTableMeta.CONTENT_URI_VIRTUAL, cv);
|
||||
} else {
|
||||
try {
|
||||
getContentProviderClient().insert(ProviderTableMeta.CONTENT_URI_VIRTUAL, cv);
|
||||
} catch (RemoteException e) {
|
||||
Log_OC.e(TAG, FAILED_TO_INSERT_MSG + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Vector<OCFile> getVirtualFolderContent(VirtualFolderType type, boolean onlyImages) {
|
||||
Vector<OCFile> ocFiles = new Vector<>();
|
||||
Uri req_uri = ProviderTableMeta.CONTENT_URI_VIRTUAL;
|
||||
Cursor c;
|
||||
|
||||
if (getContentProviderClient() != null) {
|
||||
try {
|
||||
c = getContentProviderClient().query(
|
||||
req_uri,
|
||||
null,
|
||||
ProviderTableMeta.VIRTUAL_TYPE + "=?",
|
||||
new String[]{String.valueOf(type)},
|
||||
null
|
||||
);
|
||||
} catch (RemoteException e) {
|
||||
Log_OC.e(TAG, e.getMessage(), e);
|
||||
return ocFiles;
|
||||
}
|
||||
} else {
|
||||
c = getContentResolver().query(
|
||||
req_uri,
|
||||
null,
|
||||
ProviderTableMeta.VIRTUAL_TYPE + "=?",
|
||||
new String[]{String.valueOf(type)},
|
||||
null
|
||||
);
|
||||
}
|
||||
|
||||
if (c != null && c.moveToFirst()) {
|
||||
do {
|
||||
OCFile child = createFileInstanceFromVirtual(c);
|
||||
ocFiles.add(child);
|
||||
} while (c.moveToNext());
|
||||
c.close();
|
||||
}
|
||||
|
||||
if (onlyImages) {
|
||||
OCFile current = null;
|
||||
Vector<OCFile> temp = new Vector<>();
|
||||
for (int i=0; i < ocFiles.size(); i++) {
|
||||
current = ocFiles.get(i);
|
||||
if (MimeTypeUtil.isImage(current)) {
|
||||
temp.add(current);
|
||||
}
|
||||
}
|
||||
ocFiles = temp;
|
||||
}
|
||||
|
||||
if (ocFiles.size() > 0) {
|
||||
Collections.sort(ocFiles);
|
||||
}
|
||||
|
||||
return ocFiles;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
/**
|
||||
* Nextcloud Android client application
|
||||
*
|
||||
* @author Tobias Kaminsky
|
||||
* Copyright (C) 2017 Tobias Kaminsky
|
||||
* Copyright (C) 2017 Nextcloud GmbH.
|
||||
* <p>
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* at your option) any later version.
|
||||
* <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 Affero General Public License for more details.
|
||||
* <p>
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.owncloud.android.datamodel;
|
||||
|
||||
/**
|
||||
* Type for virtual folders
|
||||
*/
|
||||
|
||||
public enum VirtualFolderType {
|
||||
FAVORITE, PHOTOS, NONE
|
||||
}
|
|
@ -45,6 +45,7 @@ public class ProviderMeta {
|
|||
public static final String SYNCED_FOLDERS_TABLE_NAME = "synced_folders";
|
||||
public static final String EXTERNAL_LINKS_TABLE_NAME = "external_links";
|
||||
public static final String ARBITRARY_DATA_TABLE_NAME = "arbitrary_data";
|
||||
public static final String VIRTUAL_TABLE_NAME = "virtual";
|
||||
|
||||
private static final String CONTENT_PREFIX = "content://";
|
||||
|
||||
|
@ -66,6 +67,7 @@ public class ProviderMeta {
|
|||
+ MainApp.getAuthority() + "/external_links");
|
||||
public static final Uri CONTENT_URI_ARBITRARY_DATA = Uri.parse(CONTENT_PREFIX
|
||||
+ MainApp.getAuthority() + "/arbitrary_data");
|
||||
public static final Uri CONTENT_URI_VIRTUAL = Uri.parse(CONTENT_PREFIX + MainApp.getAuthority() + "/virtual");
|
||||
|
||||
public static final String CONTENT_TYPE = "vnd.android.cursor.dir/vnd.owncloud.file";
|
||||
public static final String CONTENT_TYPE_ITEM = "vnd.android.cursor.item/vnd.owncloud.file";
|
||||
|
@ -185,5 +187,9 @@ public class ProviderMeta {
|
|||
public static final String ARBITRARY_DATA_CLOUD_ID = "cloud_id";
|
||||
public static final String ARBITRARY_DATA_KEY = "key";
|
||||
public static final String ARBITRARY_DATA_VALUE = "value";
|
||||
|
||||
// Columns of virtual
|
||||
public static final String VIRTUAL_TYPE = "type";
|
||||
public static final String VIRTUAL_OCFILE_ID = "ocfile_id";
|
||||
}
|
||||
}
|
|
@ -73,6 +73,7 @@ public class FileContentProvider extends ContentProvider {
|
|||
private static final int SYNCED_FOLDERS = 7;
|
||||
private static final int EXTERNAL_LINKS = 8;
|
||||
private static final int ARBITRARY_DATA = 9;
|
||||
private static final int VIRTUAL = 10;
|
||||
|
||||
private static final String TAG = FileContentProvider.class.getSimpleName();
|
||||
|
||||
|
@ -205,6 +206,9 @@ public class FileContentProvider extends ContentProvider {
|
|||
case ARBITRARY_DATA:
|
||||
count = db.delete(ProviderTableMeta.ARBITRARY_DATA_TABLE_NAME, where, whereArgs);
|
||||
break;
|
||||
case VIRTUAL:
|
||||
count = db.delete(ProviderTableMeta.VIRTUAL_TABLE_NAME, where, whereArgs);
|
||||
break;
|
||||
default:
|
||||
//Log_OC.e(TAG, "Unknown uri " + uri);
|
||||
throw new IllegalArgumentException("Unknown uri: " + uri.toString());
|
||||
|
@ -350,7 +354,17 @@ public class FileContentProvider extends ContentProvider {
|
|||
|
||||
}
|
||||
return insertedArbitraryDataUri;
|
||||
case VIRTUAL:
|
||||
Uri insertedVirtualUri;
|
||||
long virtualId = db.insert(ProviderTableMeta.VIRTUAL_TABLE_NAME, null, values);
|
||||
|
||||
if (virtualId > 0) {
|
||||
insertedVirtualUri = ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_VIRTUAL, virtualId);
|
||||
} else {
|
||||
throw new SQLException("ERROR " + uri);
|
||||
}
|
||||
|
||||
return insertedVirtualUri;
|
||||
default:
|
||||
throw new IllegalArgumentException("Unknown uri id: " + uri);
|
||||
}
|
||||
|
@ -402,6 +416,7 @@ public class FileContentProvider extends ContentProvider {
|
|||
mUriMatcher.addURI(authority, "synced_folders", SYNCED_FOLDERS);
|
||||
mUriMatcher.addURI(authority, "external_links", EXTERNAL_LINKS);
|
||||
mUriMatcher.addURI(authority, "arbitrary_data", ARBITRARY_DATA);
|
||||
mUriMatcher.addURI(authority, "virtual", VIRTUAL);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -497,6 +512,12 @@ public class FileContentProvider extends ContentProvider {
|
|||
+ uri.getPathSegments().get(1));
|
||||
}
|
||||
break;
|
||||
case VIRTUAL:
|
||||
sqlQuery.setTables(ProviderTableMeta.VIRTUAL_TABLE_NAME);
|
||||
if (uri.getPathSegments().size() > 1) {
|
||||
sqlQuery.appendWhere(ProviderTableMeta._ID + "=" + uri.getPathSegments().get(1));
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException("Unknown uri id: " + uri);
|
||||
}
|
||||
|
@ -522,6 +543,9 @@ public class FileContentProvider extends ContentProvider {
|
|||
case ARBITRARY_DATA:
|
||||
order = ProviderTableMeta.ARBITRARY_DATA_CLOUD_ID;
|
||||
break;
|
||||
case VIRTUAL:
|
||||
order = ProviderTableMeta.VIRTUAL_TYPE;
|
||||
break;
|
||||
default: // Files
|
||||
order = ProviderTableMeta.FILE_DEFAULT_SORT_ORDER;
|
||||
break;
|
||||
|
@ -635,6 +659,9 @@ public class FileContentProvider extends ContentProvider {
|
|||
|
||||
// Create arbitrary data table
|
||||
createArbitraryData(db);
|
||||
|
||||
// Create virtual table
|
||||
createVirtualTable(db);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -957,11 +984,13 @@ public class FileContentProvider extends ContentProvider {
|
|||
db.beginTransaction();
|
||||
try {
|
||||
createArbitraryData(db);
|
||||
createVirtualTable(db);
|
||||
upgraded = true;
|
||||
db.setTransactionSuccessful();
|
||||
} finally {
|
||||
db.endTransaction();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (!upgraded) {
|
||||
|
@ -1047,7 +1076,7 @@ public class FileContentProvider extends ContentProvider {
|
|||
+ ProviderTableMeta.CAPABILITIES_FILES_UNDELETE + INTEGER // boolean
|
||||
+ ProviderTableMeta.CAPABILITIES_FILES_VERSIONING + INTEGER // boolean
|
||||
+ ProviderTableMeta.CAPABILITIES_FILES_DROP + INTEGER // boolean
|
||||
+ ProviderTableMeta.CAPABILITIES_EXTERNAL_LINKS + " INTEGER );" ); // boolean
|
||||
+ ProviderTableMeta.CAPABILITIES_EXTERNAL_LINKS + " INTEGER );"); // boolean
|
||||
}
|
||||
|
||||
private void createUploadsTable(SQLiteDatabase db) {
|
||||
|
@ -1113,6 +1142,14 @@ public class FileContentProvider extends ContentProvider {
|
|||
);
|
||||
}
|
||||
|
||||
private void createVirtualTable(SQLiteDatabase db) {
|
||||
db.execSQL("CREATE TABLE " + ProviderTableMeta.VIRTUAL_TABLE_NAME + "("
|
||||
+ ProviderTableMeta._ID + " INTEGER PRIMARY KEY, " // id
|
||||
+ ProviderTableMeta.VIRTUAL_TYPE + " TEXT, " // type
|
||||
+ ProviderTableMeta.VIRTUAL_OCFILE_ID + " INTEGER )" // file id
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Version 10 of database does not modify its scheme. It coincides with the upgrade of the ownCloud account names
|
||||
* structure to include in it the path to the server instance. Updating the account names and path to local files
|
||||
|
@ -1120,7 +1157,7 @@ public class FileContentProvider extends ContentProvider {
|
|||
*
|
||||
* See {@link com.owncloud.android.authentication.AccountUtils#updateAccountVersion(android.content.Context)}
|
||||
*
|
||||
* @param db Database where table of files is included.
|
||||
* @param db Database where table of files is included.
|
||||
*/
|
||||
private void updateAccountName(SQLiteDatabase db) {
|
||||
Log_OC.d(SQL, "THREAD: " + Thread.currentThread().getName());
|
||||
|
@ -1177,9 +1214,9 @@ public class FileContentProvider extends ContentProvider {
|
|||
* Rename the local ownCloud folder of one account to match the a rename of the account itself. Updates the
|
||||
* table of files in database so that the paths to the local files keep being the same.
|
||||
*
|
||||
* @param db Database where table of files is included.
|
||||
* @param newAccountName New name for the target OC account.
|
||||
* @param oldAccountName Old name of the target OC account.
|
||||
* @param db Database where table of files is included.
|
||||
* @param newAccountName New name for the target OC account.
|
||||
* @param oldAccountName Old name of the target OC account.
|
||||
*/
|
||||
private void updateDownloadedFiles(SQLiteDatabase db, String newAccountName,
|
||||
String oldAccountName) {
|
||||
|
|
|
@ -62,6 +62,7 @@ import com.owncloud.android.MainApp;
|
|||
import com.owncloud.android.R;
|
||||
import com.owncloud.android.datamodel.FileDataStorageManager;
|
||||
import com.owncloud.android.datamodel.OCFile;
|
||||
import com.owncloud.android.datamodel.VirtualFolderType;
|
||||
import com.owncloud.android.db.PreferenceManager;
|
||||
import com.owncloud.android.files.services.FileDownloader;
|
||||
import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder;
|
||||
|
@ -1914,6 +1915,19 @@ public class FileDisplayActivity extends HookActivity
|
|||
showDetailsIntent.putExtra(EXTRA_FILE, file);
|
||||
showDetailsIntent.putExtra(EXTRA_ACCOUNT, getAccount());
|
||||
startActivity(showDetailsIntent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens the image gallery showing the image {@link OCFile} received as parameter.
|
||||
*
|
||||
* @param file Image {@link OCFile} to show.
|
||||
*/
|
||||
public void startImagePreview(OCFile file, VirtualFolderType type) {
|
||||
Intent showDetailsIntent = new Intent(this, PreviewImageActivity.class);
|
||||
showDetailsIntent.putExtra(PreviewImageActivity.EXTRA_FILE, file);
|
||||
showDetailsIntent.putExtra(EXTRA_ACCOUNT, getAccount());
|
||||
showDetailsIntent.putExtra(PreviewImageActivity.EXTRA_VIRTUAL_TYPE, type);
|
||||
startActivity(showDetailsIntent);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -46,6 +46,7 @@ import com.owncloud.android.authentication.AccountUtils;
|
|||
import com.owncloud.android.datamodel.FileDataStorageManager;
|
||||
import com.owncloud.android.datamodel.OCFile;
|
||||
import com.owncloud.android.datamodel.ThumbnailsCacheManager;
|
||||
import com.owncloud.android.datamodel.VirtualFolderType;
|
||||
import com.owncloud.android.db.PreferenceManager;
|
||||
import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder;
|
||||
import com.owncloud.android.files.services.FileUploader.FileUploaderBinder;
|
||||
|
@ -485,37 +486,9 @@ public class FileListListAdapter extends BaseAdapter {
|
|||
public void setData(ArrayList<Object> objects, ExtendedListFragment.SearchType searchType) {
|
||||
mFiles = new Vector<>();
|
||||
if (searchType.equals(ExtendedListFragment.SearchType.SHARED_FILTER)) {
|
||||
ArrayList<OCShare> shares = new ArrayList<>();
|
||||
for (int i = 0; i < objects.size(); i++) {
|
||||
// check type before cast as of long running data fetch it is possible that old result is filled
|
||||
if (objects.get(i) instanceof OCShare) {
|
||||
OCShare ocShare = (OCShare) objects.get(i);
|
||||
|
||||
shares.add(ocShare);
|
||||
|
||||
// get ocFile from Server to have an up-to-date copy
|
||||
ReadRemoteFileOperation operation = new ReadRemoteFileOperation(ocShare.getPath());
|
||||
RemoteOperationResult result = operation.execute(mAccount, mContext);
|
||||
if (result.isSuccess()) {
|
||||
OCFile file = FileStorageUtils.fillOCFile((RemoteFile) result.getData().get(0));
|
||||
|
||||
mStorageManager.saveFile(file);
|
||||
|
||||
if (!mFiles.contains(file)) {
|
||||
mFiles.add(file);
|
||||
}
|
||||
} else {
|
||||
Log_OC.e(TAG, "Error in getting prop for file: " + ocShare.getPath());
|
||||
}
|
||||
}
|
||||
}
|
||||
mStorageManager.saveShares(shares);
|
||||
parseShares(objects);
|
||||
} else {
|
||||
for (int i = 0; i < objects.size(); i++) {
|
||||
OCFile ocFile = FileStorageUtils.fillOCFile((RemoteFile) objects.get(i));
|
||||
searchForLocalFileInDefaultPath(ocFile);
|
||||
mFiles.add(ocFile);
|
||||
}
|
||||
parseVirtuals(objects, searchType);
|
||||
}
|
||||
|
||||
if (!searchType.equals(ExtendedListFragment.SearchType.PHOTO_SEARCH) &&
|
||||
|
@ -539,6 +512,62 @@ public class FileListListAdapter extends BaseAdapter {
|
|||
});
|
||||
}
|
||||
|
||||
private void parseShares(ArrayList<Object> objects) {
|
||||
ArrayList<OCShare> shares = new ArrayList<>();
|
||||
for (int i = 0; i < objects.size(); i++) {
|
||||
// check type before cast as of long running data fetch it is possible that old result is filled
|
||||
if (objects.get(i) instanceof OCShare) {
|
||||
OCShare ocShare = (OCShare) objects.get(i);
|
||||
|
||||
shares.add(ocShare);
|
||||
|
||||
// get ocFile from Server to have an up-to-date copy
|
||||
ReadRemoteFileOperation operation = new ReadRemoteFileOperation(ocShare.getPath());
|
||||
RemoteOperationResult result = operation.execute(mAccount, mContext);
|
||||
if (result.isSuccess()) {
|
||||
OCFile file = FileStorageUtils.fillOCFile((RemoteFile) result.getData().get(0));
|
||||
|
||||
mStorageManager.saveFile(file);
|
||||
|
||||
if (!mFiles.contains(file)) {
|
||||
mFiles.add(file);
|
||||
}
|
||||
} else {
|
||||
Log_OC.e(TAG, "Error in getting prop for file: " + ocShare.getPath());
|
||||
}
|
||||
}
|
||||
}
|
||||
mStorageManager.saveShares(shares);
|
||||
}
|
||||
|
||||
private void parseVirtuals(ArrayList<Object> objects, ExtendedListFragment.SearchType searchType) {
|
||||
VirtualFolderType type;
|
||||
boolean onlyImages = false;
|
||||
switch (searchType) {
|
||||
case FAVORITE_SEARCH:
|
||||
type = VirtualFolderType.FAVORITE;
|
||||
break;
|
||||
case PHOTO_SEARCH:
|
||||
type = VirtualFolderType.PHOTOS;
|
||||
onlyImages = true;
|
||||
break;
|
||||
default:
|
||||
type = VirtualFolderType.NONE;
|
||||
break;
|
||||
}
|
||||
|
||||
mStorageManager.deleteVirtuals(type);
|
||||
|
||||
for (int i = 0; i < objects.size(); i++) {
|
||||
OCFile ocFile = FileStorageUtils.fillOCFile((RemoteFile) objects.get(i));
|
||||
searchForLocalFileInDefaultPath(ocFile);
|
||||
mStorageManager.saveFileWithParent(ocFile, mContext);
|
||||
mStorageManager.saveVirtual(type, mStorageManager.getFileByPath(ocFile.getRemotePath()));
|
||||
}
|
||||
|
||||
mFiles.addAll(mStorageManager.getVirtualFolderContent(type, onlyImages));
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter for getting only the folders
|
||||
*
|
||||
|
|
|
@ -59,6 +59,7 @@ import com.owncloud.android.R;
|
|||
import com.owncloud.android.authentication.AccountUtils;
|
||||
import com.owncloud.android.datamodel.FileDataStorageManager;
|
||||
import com.owncloud.android.datamodel.OCFile;
|
||||
import com.owncloud.android.datamodel.VirtualFolderType;
|
||||
import com.owncloud.android.files.FileMenuFilter;
|
||||
import com.owncloud.android.lib.common.OwnCloudAccount;
|
||||
import com.owncloud.android.lib.common.OwnCloudClient;
|
||||
|
@ -801,7 +802,23 @@ public class OCFileListFragment extends ExtendedListFragment implements OCFileLi
|
|||
} else { /// Click on a file
|
||||
if (PreviewImageFragment.canBePreviewed(file)) {
|
||||
// preview image - it handles the download, if needed
|
||||
((FileDisplayActivity) mContainerActivity).startImagePreview(file);
|
||||
if (searchFragment) {
|
||||
VirtualFolderType type;
|
||||
switch (currentSearchType) {
|
||||
case FAVORITE_SEARCH:
|
||||
type = VirtualFolderType.FAVORITE;
|
||||
break;
|
||||
case PHOTO_SEARCH:
|
||||
type = VirtualFolderType.PHOTOS;
|
||||
break;
|
||||
default:
|
||||
type = VirtualFolderType.NONE;
|
||||
break;
|
||||
}
|
||||
((FileDisplayActivity) mContainerActivity).startImagePreview(file, type);
|
||||
} else {
|
||||
((FileDisplayActivity) mContainerActivity).startImagePreview(file);
|
||||
}
|
||||
} else if (file.isDown() && MimeTypeUtil.isVCard(file)){
|
||||
((FileDisplayActivity) mContainerActivity).startContactListFragment(file);
|
||||
} else if (PreviewTextFragment.canBePreviewed(file)) {
|
||||
|
|
|
@ -40,6 +40,7 @@ import com.owncloud.android.R;
|
|||
import com.owncloud.android.authentication.AccountUtils;
|
||||
import com.owncloud.android.datamodel.FileDataStorageManager;
|
||||
import com.owncloud.android.datamodel.OCFile;
|
||||
import com.owncloud.android.datamodel.VirtualFolderType;
|
||||
import com.owncloud.android.files.services.FileDownloader;
|
||||
import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder;
|
||||
import com.owncloud.android.files.services.FileUploader;
|
||||
|
@ -72,6 +73,8 @@ public class PreviewImageActivity extends FileActivity implements
|
|||
private static final String KEY_WAITING_FOR_BINDER = "WAITING_FOR_BINDER";
|
||||
private static final String KEY_SYSTEM_VISIBLE = "TRUE";
|
||||
|
||||
public static final String EXTRA_VIRTUAL_TYPE = "EXTRA_VIRTUAL_TYPE";
|
||||
|
||||
private ExtendedViewPager mViewPager;
|
||||
private PreviewImagePagerAdapter mPreviewImagePagerAdapter;
|
||||
private int mSavedPosition = 0;
|
||||
|
@ -128,25 +131,36 @@ public class PreviewImageActivity extends FileActivity implements
|
|||
}
|
||||
|
||||
private void initViewPager() {
|
||||
// get parent from path
|
||||
String parentPath = getFile().getRemotePath().substring(0,
|
||||
getFile().getRemotePath().lastIndexOf(getFile().getFileName()));
|
||||
OCFile parentFolder = getStorageManager().getFileByPath(parentPath);
|
||||
if (parentFolder == null) {
|
||||
// should not be necessary
|
||||
parentFolder = getStorageManager().getFileByPath(OCFile.ROOT_PATH);
|
||||
// virtual folder
|
||||
if (getIntent().getSerializableExtra(EXTRA_VIRTUAL_TYPE) != null) {
|
||||
VirtualFolderType type = (VirtualFolderType) getIntent().getSerializableExtra(EXTRA_VIRTUAL_TYPE);
|
||||
|
||||
mPreviewImagePagerAdapter = new PreviewImagePagerAdapter(getSupportFragmentManager(),
|
||||
type, getAccount(), getStorageManager());
|
||||
} else {
|
||||
// get parent from path
|
||||
String parentPath = getFile().getRemotePath().substring(0,
|
||||
getFile().getRemotePath().lastIndexOf(getFile().getFileName()));
|
||||
OCFile parentFolder = getStorageManager().getFileByPath(parentPath);
|
||||
|
||||
if (parentFolder == null) {
|
||||
// should not be necessary
|
||||
parentFolder = getStorageManager().getFileByPath(OCFile.ROOT_PATH);
|
||||
}
|
||||
|
||||
mPreviewImagePagerAdapter = new PreviewImagePagerAdapter(getSupportFragmentManager(),
|
||||
parentFolder, getAccount(), getStorageManager(), MainApp.isOnlyOnDevice());
|
||||
}
|
||||
|
||||
mPreviewImagePagerAdapter = new PreviewImagePagerAdapter(getSupportFragmentManager(),
|
||||
parentFolder, getAccount(), getStorageManager(), MainApp.isOnlyOnDevice());
|
||||
|
||||
mViewPager = (ExtendedViewPager) findViewById(R.id.fragmentPager);
|
||||
int position = mHasSavedPosition ? mSavedPosition :
|
||||
mPreviewImagePagerAdapter.getFilePosition(getFile());
|
||||
|
||||
int position = mHasSavedPosition ? mSavedPosition : mPreviewImagePagerAdapter.getFilePosition(getFile());
|
||||
position = (position >= 0) ? position : 0;
|
||||
mViewPager.setAdapter(mPreviewImagePagerAdapter);
|
||||
|
||||
mViewPager.setAdapter(mPreviewImagePagerAdapter);
|
||||
mViewPager.setOnPageChangeListener(this);
|
||||
mViewPager.setCurrentItem(position);
|
||||
|
||||
if (position == 0 && !getFile().isDown()) {
|
||||
// this is necessary because mViewPager.setCurrentItem(0) just after setting the
|
||||
// adapter does not result in a call to #onPageSelected(0)
|
||||
|
@ -446,7 +460,7 @@ public class PreviewImageActivity extends FileActivity implements
|
|||
super.onAccountSet(stateWasRecovered);
|
||||
if (getAccount() != null) {
|
||||
OCFile file = getFile();
|
||||
/// Validate handled file (first image to preview)
|
||||
/// Validate handled file (first image to preview)
|
||||
if (file == null) {
|
||||
throw new IllegalStateException("Instanced with a NULL OCFile");
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@ import android.view.ViewGroup;
|
|||
|
||||
import com.owncloud.android.datamodel.FileDataStorageManager;
|
||||
import com.owncloud.android.datamodel.OCFile;
|
||||
import com.owncloud.android.datamodel.VirtualFolderType;
|
||||
import com.owncloud.android.ui.fragment.FileFragment;
|
||||
import com.owncloud.android.utils.FileStorageUtils;
|
||||
|
||||
|
@ -87,7 +88,44 @@ public class PreviewImagePagerAdapter extends FragmentStatePagerAdapter {
|
|||
//mFragmentManager = fragmentManager;
|
||||
mCachedFragments = new HashMap<Integer, FileFragment>();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param fragmentManager {@link FragmentManager} instance that will handle
|
||||
* the {@link Fragment}s provided by the adapter.
|
||||
* @param type Type of virtual folder, e.g. favorite or photos
|
||||
* @param storageManager Bridge to database.
|
||||
*/
|
||||
public PreviewImagePagerAdapter(FragmentManager fragmentManager, VirtualFolderType type,
|
||||
Account account, FileDataStorageManager storageManager) {
|
||||
super(fragmentManager);
|
||||
|
||||
if (fragmentManager == null) {
|
||||
throw new IllegalArgumentException("NULL FragmentManager instance");
|
||||
}
|
||||
if (type == null) {
|
||||
throw new IllegalArgumentException("NULL parent folder");
|
||||
}
|
||||
if (storageManager == null) {
|
||||
throw new IllegalArgumentException("NULL storage manager");
|
||||
}
|
||||
|
||||
mAccount = account;
|
||||
mStorageManager = storageManager;
|
||||
mImageFiles = mStorageManager.getVirtualFolderContent(type, true);
|
||||
|
||||
if (type == VirtualFolderType.PHOTOS) {
|
||||
mImageFiles = FileStorageUtils.sortOCFilesByDate(mImageFiles);
|
||||
}
|
||||
|
||||
mObsoleteFragments = new HashSet<Object>();
|
||||
mObsoletePositions = new HashSet<Integer>();
|
||||
mDownloadErrors = new HashSet<Integer>();
|
||||
//mFragmentManager = fragmentManager;
|
||||
mCachedFragments = new HashMap<Integer, FileFragment>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the image files handled by the adapter.
|
||||
*
|
||||
|
@ -195,7 +233,7 @@ public class PreviewImagePagerAdapter extends FragmentStatePagerAdapter {
|
|||
public void resetZoom() {
|
||||
Iterator<FileFragment> entries = mCachedFragments.values().iterator();
|
||||
while (entries.hasNext()) {
|
||||
FileFragment fileFragment = (FileFragment) entries.next();
|
||||
FileFragment fileFragment = entries.next();
|
||||
if (fileFragment instanceof PreviewImageFragment) {
|
||||
((PreviewImageFragment) fileFragment).getImageView().resetZoom();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue