mirror of
https://github.com/nextcloud/android.git
synced 2024-12-20 07:52:18 +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.ContentResolver;
|
||||||
import android.content.ContentUris;
|
import android.content.ContentUris;
|
||||||
import android.content.ContentValues;
|
import android.content.ContentValues;
|
||||||
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.OperationApplicationException;
|
import android.content.OperationApplicationException;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
|
@ -36,7 +37,10 @@ import android.provider.MediaStore;
|
||||||
|
|
||||||
import com.owncloud.android.MainApp;
|
import com.owncloud.android.MainApp;
|
||||||
import com.owncloud.android.db.ProviderMeta.ProviderTableMeta;
|
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.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.OCShare;
|
||||||
import com.owncloud.android.lib.resources.shares.ShareType;
|
import com.owncloud.android.lib.resources.shares.ShareType;
|
||||||
import com.owncloud.android.lib.resources.status.CapabilityBooleanType;
|
import com.owncloud.android.lib.resources.status.CapabilityBooleanType;
|
||||||
|
@ -247,6 +251,39 @@ public class FileDataStorageManager {
|
||||||
return overriden;
|
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) {
|
public void saveNewFile(OCFile newFile) {
|
||||||
String remoteParentPath = new File(newFile.getRemotePath()).getParent();
|
String remoteParentPath = new File(newFile.getRemotePath()).getParent();
|
||||||
|
@ -868,6 +905,15 @@ public class FileDataStorageManager {
|
||||||
return c;
|
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) {
|
private OCFile createFileInstance(Cursor c) {
|
||||||
OCFile file = null;
|
OCFile file = null;
|
||||||
|
@ -2005,4 +2051,89 @@ public class FileDataStorageManager {
|
||||||
return capability;
|
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 SYNCED_FOLDERS_TABLE_NAME = "synced_folders";
|
||||||
public static final String EXTERNAL_LINKS_TABLE_NAME = "external_links";
|
public static final String EXTERNAL_LINKS_TABLE_NAME = "external_links";
|
||||||
public static final String ARBITRARY_DATA_TABLE_NAME = "arbitrary_data";
|
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://";
|
private static final String CONTENT_PREFIX = "content://";
|
||||||
|
|
||||||
|
@ -66,6 +67,7 @@ public class ProviderMeta {
|
||||||
+ MainApp.getAuthority() + "/external_links");
|
+ MainApp.getAuthority() + "/external_links");
|
||||||
public static final Uri CONTENT_URI_ARBITRARY_DATA = Uri.parse(CONTENT_PREFIX
|
public static final Uri CONTENT_URI_ARBITRARY_DATA = Uri.parse(CONTENT_PREFIX
|
||||||
+ MainApp.getAuthority() + "/arbitrary_data");
|
+ 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 = "vnd.android.cursor.dir/vnd.owncloud.file";
|
||||||
public static final String CONTENT_TYPE_ITEM = "vnd.android.cursor.item/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_CLOUD_ID = "cloud_id";
|
||||||
public static final String ARBITRARY_DATA_KEY = "key";
|
public static final String ARBITRARY_DATA_KEY = "key";
|
||||||
public static final String ARBITRARY_DATA_VALUE = "value";
|
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 SYNCED_FOLDERS = 7;
|
||||||
private static final int EXTERNAL_LINKS = 8;
|
private static final int EXTERNAL_LINKS = 8;
|
||||||
private static final int ARBITRARY_DATA = 9;
|
private static final int ARBITRARY_DATA = 9;
|
||||||
|
private static final int VIRTUAL = 10;
|
||||||
|
|
||||||
private static final String TAG = FileContentProvider.class.getSimpleName();
|
private static final String TAG = FileContentProvider.class.getSimpleName();
|
||||||
|
|
||||||
|
@ -205,6 +206,9 @@ public class FileContentProvider extends ContentProvider {
|
||||||
case ARBITRARY_DATA:
|
case ARBITRARY_DATA:
|
||||||
count = db.delete(ProviderTableMeta.ARBITRARY_DATA_TABLE_NAME, where, whereArgs);
|
count = db.delete(ProviderTableMeta.ARBITRARY_DATA_TABLE_NAME, where, whereArgs);
|
||||||
break;
|
break;
|
||||||
|
case VIRTUAL:
|
||||||
|
count = db.delete(ProviderTableMeta.VIRTUAL_TABLE_NAME, where, whereArgs);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
//Log_OC.e(TAG, "Unknown uri " + uri);
|
//Log_OC.e(TAG, "Unknown uri " + uri);
|
||||||
throw new IllegalArgumentException("Unknown uri: " + uri.toString());
|
throw new IllegalArgumentException("Unknown uri: " + uri.toString());
|
||||||
|
@ -350,7 +354,17 @@ public class FileContentProvider extends ContentProvider {
|
||||||
|
|
||||||
}
|
}
|
||||||
return insertedArbitraryDataUri;
|
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:
|
default:
|
||||||
throw new IllegalArgumentException("Unknown uri id: " + uri);
|
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, "synced_folders", SYNCED_FOLDERS);
|
||||||
mUriMatcher.addURI(authority, "external_links", EXTERNAL_LINKS);
|
mUriMatcher.addURI(authority, "external_links", EXTERNAL_LINKS);
|
||||||
mUriMatcher.addURI(authority, "arbitrary_data", ARBITRARY_DATA);
|
mUriMatcher.addURI(authority, "arbitrary_data", ARBITRARY_DATA);
|
||||||
|
mUriMatcher.addURI(authority, "virtual", VIRTUAL);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -497,6 +512,12 @@ public class FileContentProvider extends ContentProvider {
|
||||||
+ uri.getPathSegments().get(1));
|
+ uri.getPathSegments().get(1));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case VIRTUAL:
|
||||||
|
sqlQuery.setTables(ProviderTableMeta.VIRTUAL_TABLE_NAME);
|
||||||
|
if (uri.getPathSegments().size() > 1) {
|
||||||
|
sqlQuery.appendWhere(ProviderTableMeta._ID + "=" + uri.getPathSegments().get(1));
|
||||||
|
}
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
throw new IllegalArgumentException("Unknown uri id: " + uri);
|
throw new IllegalArgumentException("Unknown uri id: " + uri);
|
||||||
}
|
}
|
||||||
|
@ -522,6 +543,9 @@ public class FileContentProvider extends ContentProvider {
|
||||||
case ARBITRARY_DATA:
|
case ARBITRARY_DATA:
|
||||||
order = ProviderTableMeta.ARBITRARY_DATA_CLOUD_ID;
|
order = ProviderTableMeta.ARBITRARY_DATA_CLOUD_ID;
|
||||||
break;
|
break;
|
||||||
|
case VIRTUAL:
|
||||||
|
order = ProviderTableMeta.VIRTUAL_TYPE;
|
||||||
|
break;
|
||||||
default: // Files
|
default: // Files
|
||||||
order = ProviderTableMeta.FILE_DEFAULT_SORT_ORDER;
|
order = ProviderTableMeta.FILE_DEFAULT_SORT_ORDER;
|
||||||
break;
|
break;
|
||||||
|
@ -635,6 +659,9 @@ public class FileContentProvider extends ContentProvider {
|
||||||
|
|
||||||
// Create arbitrary data table
|
// Create arbitrary data table
|
||||||
createArbitraryData(db);
|
createArbitraryData(db);
|
||||||
|
|
||||||
|
// Create virtual table
|
||||||
|
createVirtualTable(db);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -957,11 +984,13 @@ public class FileContentProvider extends ContentProvider {
|
||||||
db.beginTransaction();
|
db.beginTransaction();
|
||||||
try {
|
try {
|
||||||
createArbitraryData(db);
|
createArbitraryData(db);
|
||||||
|
createVirtualTable(db);
|
||||||
upgraded = true;
|
upgraded = true;
|
||||||
db.setTransactionSuccessful();
|
db.setTransactionSuccessful();
|
||||||
} finally {
|
} finally {
|
||||||
db.endTransaction();
|
db.endTransaction();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!upgraded) {
|
if (!upgraded) {
|
||||||
|
@ -1047,7 +1076,7 @@ public class FileContentProvider extends ContentProvider {
|
||||||
+ ProviderTableMeta.CAPABILITIES_FILES_UNDELETE + INTEGER // boolean
|
+ ProviderTableMeta.CAPABILITIES_FILES_UNDELETE + INTEGER // boolean
|
||||||
+ ProviderTableMeta.CAPABILITIES_FILES_VERSIONING + INTEGER // boolean
|
+ ProviderTableMeta.CAPABILITIES_FILES_VERSIONING + INTEGER // boolean
|
||||||
+ ProviderTableMeta.CAPABILITIES_FILES_DROP + 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) {
|
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
|
* 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
|
* structure to include in it the path to the server instance. Updating the account names and path to local files
|
||||||
|
|
|
@ -62,6 +62,7 @@ import com.owncloud.android.MainApp;
|
||||||
import com.owncloud.android.R;
|
import com.owncloud.android.R;
|
||||||
import com.owncloud.android.datamodel.FileDataStorageManager;
|
import com.owncloud.android.datamodel.FileDataStorageManager;
|
||||||
import com.owncloud.android.datamodel.OCFile;
|
import com.owncloud.android.datamodel.OCFile;
|
||||||
|
import com.owncloud.android.datamodel.VirtualFolderType;
|
||||||
import com.owncloud.android.db.PreferenceManager;
|
import com.owncloud.android.db.PreferenceManager;
|
||||||
import com.owncloud.android.files.services.FileDownloader;
|
import com.owncloud.android.files.services.FileDownloader;
|
||||||
import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder;
|
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_FILE, file);
|
||||||
showDetailsIntent.putExtra(EXTRA_ACCOUNT, getAccount());
|
showDetailsIntent.putExtra(EXTRA_ACCOUNT, getAccount());
|
||||||
startActivity(showDetailsIntent);
|
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.FileDataStorageManager;
|
||||||
import com.owncloud.android.datamodel.OCFile;
|
import com.owncloud.android.datamodel.OCFile;
|
||||||
import com.owncloud.android.datamodel.ThumbnailsCacheManager;
|
import com.owncloud.android.datamodel.ThumbnailsCacheManager;
|
||||||
|
import com.owncloud.android.datamodel.VirtualFolderType;
|
||||||
import com.owncloud.android.db.PreferenceManager;
|
import com.owncloud.android.db.PreferenceManager;
|
||||||
import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder;
|
import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder;
|
||||||
import com.owncloud.android.files.services.FileUploader.FileUploaderBinder;
|
import com.owncloud.android.files.services.FileUploader.FileUploaderBinder;
|
||||||
|
@ -485,6 +486,33 @@ public class FileListListAdapter extends BaseAdapter {
|
||||||
public void setData(ArrayList<Object> objects, ExtendedListFragment.SearchType searchType) {
|
public void setData(ArrayList<Object> objects, ExtendedListFragment.SearchType searchType) {
|
||||||
mFiles = new Vector<>();
|
mFiles = new Vector<>();
|
||||||
if (searchType.equals(ExtendedListFragment.SearchType.SHARED_FILTER)) {
|
if (searchType.equals(ExtendedListFragment.SearchType.SHARED_FILTER)) {
|
||||||
|
parseShares(objects);
|
||||||
|
} else {
|
||||||
|
parseVirtuals(objects, searchType);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!searchType.equals(ExtendedListFragment.SearchType.PHOTO_SEARCH) &&
|
||||||
|
!searchType.equals(ExtendedListFragment.SearchType.PHOTOS_SEARCH_FILTER) &&
|
||||||
|
!searchType.equals(ExtendedListFragment.SearchType.RECENTLY_MODIFIED_SEARCH) &&
|
||||||
|
!searchType.equals(ExtendedListFragment.SearchType.RECENTLY_MODIFIED_SEARCH_FILTER)) {
|
||||||
|
mFiles = FileStorageUtils.sortOcFolder(mFiles);
|
||||||
|
} else {
|
||||||
|
mFiles = FileStorageUtils.sortOcFolderDescDateModified(mFiles);
|
||||||
|
}
|
||||||
|
|
||||||
|
mFilesAll = new Vector<>();
|
||||||
|
mFilesAll.addAll(mFiles);
|
||||||
|
|
||||||
|
new Handler(Looper.getMainLooper()).post(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
notifyDataSetChanged();
|
||||||
|
OCFileListFragmentInterface.finishedFiltering();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void parseShares(ArrayList<Object> objects) {
|
||||||
ArrayList<OCShare> shares = new ArrayList<>();
|
ArrayList<OCShare> shares = new ArrayList<>();
|
||||||
for (int i = 0; i < objects.size(); i++) {
|
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
|
// check type before cast as of long running data fetch it is possible that old result is filled
|
||||||
|
@ -510,33 +538,34 @@ public class FileListListAdapter extends BaseAdapter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mStorageManager.saveShares(shares);
|
mStorageManager.saveShares(shares);
|
||||||
} else {
|
}
|
||||||
|
|
||||||
|
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++) {
|
for (int i = 0; i < objects.size(); i++) {
|
||||||
OCFile ocFile = FileStorageUtils.fillOCFile((RemoteFile) objects.get(i));
|
OCFile ocFile = FileStorageUtils.fillOCFile((RemoteFile) objects.get(i));
|
||||||
searchForLocalFileInDefaultPath(ocFile);
|
searchForLocalFileInDefaultPath(ocFile);
|
||||||
mFiles.add(ocFile);
|
mStorageManager.saveFileWithParent(ocFile, mContext);
|
||||||
}
|
mStorageManager.saveVirtual(type, mStorageManager.getFileByPath(ocFile.getRemotePath()));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!searchType.equals(ExtendedListFragment.SearchType.PHOTO_SEARCH) &&
|
mFiles.addAll(mStorageManager.getVirtualFolderContent(type, onlyImages));
|
||||||
!searchType.equals(ExtendedListFragment.SearchType.PHOTOS_SEARCH_FILTER) &&
|
|
||||||
!searchType.equals(ExtendedListFragment.SearchType.RECENTLY_MODIFIED_SEARCH) &&
|
|
||||||
!searchType.equals(ExtendedListFragment.SearchType.RECENTLY_MODIFIED_SEARCH_FILTER)) {
|
|
||||||
mFiles = FileStorageUtils.sortOcFolder(mFiles);
|
|
||||||
} else {
|
|
||||||
mFiles = FileStorageUtils.sortOcFolderDescDateModified(mFiles);
|
|
||||||
}
|
|
||||||
|
|
||||||
mFilesAll = new Vector<>();
|
|
||||||
mFilesAll.addAll(mFiles);
|
|
||||||
|
|
||||||
new Handler(Looper.getMainLooper()).post(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
notifyDataSetChanged();
|
|
||||||
OCFileListFragmentInterface.finishedFiltering();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -59,6 +59,7 @@ import com.owncloud.android.R;
|
||||||
import com.owncloud.android.authentication.AccountUtils;
|
import com.owncloud.android.authentication.AccountUtils;
|
||||||
import com.owncloud.android.datamodel.FileDataStorageManager;
|
import com.owncloud.android.datamodel.FileDataStorageManager;
|
||||||
import com.owncloud.android.datamodel.OCFile;
|
import com.owncloud.android.datamodel.OCFile;
|
||||||
|
import com.owncloud.android.datamodel.VirtualFolderType;
|
||||||
import com.owncloud.android.files.FileMenuFilter;
|
import com.owncloud.android.files.FileMenuFilter;
|
||||||
import com.owncloud.android.lib.common.OwnCloudAccount;
|
import com.owncloud.android.lib.common.OwnCloudAccount;
|
||||||
import com.owncloud.android.lib.common.OwnCloudClient;
|
import com.owncloud.android.lib.common.OwnCloudClient;
|
||||||
|
@ -801,7 +802,23 @@ public class OCFileListFragment extends ExtendedListFragment implements OCFileLi
|
||||||
} else { /// Click on a file
|
} else { /// Click on a file
|
||||||
if (PreviewImageFragment.canBePreviewed(file)) {
|
if (PreviewImageFragment.canBePreviewed(file)) {
|
||||||
// preview image - it handles the download, if needed
|
// preview image - it handles the download, if needed
|
||||||
|
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);
|
((FileDisplayActivity) mContainerActivity).startImagePreview(file);
|
||||||
|
}
|
||||||
} else if (file.isDown() && MimeTypeUtil.isVCard(file)){
|
} else if (file.isDown() && MimeTypeUtil.isVCard(file)){
|
||||||
((FileDisplayActivity) mContainerActivity).startContactListFragment(file);
|
((FileDisplayActivity) mContainerActivity).startContactListFragment(file);
|
||||||
} else if (PreviewTextFragment.canBePreviewed(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.authentication.AccountUtils;
|
||||||
import com.owncloud.android.datamodel.FileDataStorageManager;
|
import com.owncloud.android.datamodel.FileDataStorageManager;
|
||||||
import com.owncloud.android.datamodel.OCFile;
|
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;
|
||||||
import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder;
|
import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder;
|
||||||
import com.owncloud.android.files.services.FileUploader;
|
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_WAITING_FOR_BINDER = "WAITING_FOR_BINDER";
|
||||||
private static final String KEY_SYSTEM_VISIBLE = "TRUE";
|
private static final String KEY_SYSTEM_VISIBLE = "TRUE";
|
||||||
|
|
||||||
|
public static final String EXTRA_VIRTUAL_TYPE = "EXTRA_VIRTUAL_TYPE";
|
||||||
|
|
||||||
private ExtendedViewPager mViewPager;
|
private ExtendedViewPager mViewPager;
|
||||||
private PreviewImagePagerAdapter mPreviewImagePagerAdapter;
|
private PreviewImagePagerAdapter mPreviewImagePagerAdapter;
|
||||||
private int mSavedPosition = 0;
|
private int mSavedPosition = 0;
|
||||||
|
@ -128,10 +131,18 @@ public class PreviewImageActivity extends FileActivity implements
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initViewPager() {
|
private void initViewPager() {
|
||||||
|
// 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
|
// get parent from path
|
||||||
String parentPath = getFile().getRemotePath().substring(0,
|
String parentPath = getFile().getRemotePath().substring(0,
|
||||||
getFile().getRemotePath().lastIndexOf(getFile().getFileName()));
|
getFile().getRemotePath().lastIndexOf(getFile().getFileName()));
|
||||||
OCFile parentFolder = getStorageManager().getFileByPath(parentPath);
|
OCFile parentFolder = getStorageManager().getFileByPath(parentPath);
|
||||||
|
|
||||||
if (parentFolder == null) {
|
if (parentFolder == null) {
|
||||||
// should not be necessary
|
// should not be necessary
|
||||||
parentFolder = getStorageManager().getFileByPath(OCFile.ROOT_PATH);
|
parentFolder = getStorageManager().getFileByPath(OCFile.ROOT_PATH);
|
||||||
|
@ -139,14 +150,17 @@ public class PreviewImageActivity extends FileActivity implements
|
||||||
|
|
||||||
mPreviewImagePagerAdapter = new PreviewImagePagerAdapter(getSupportFragmentManager(),
|
mPreviewImagePagerAdapter = new PreviewImagePagerAdapter(getSupportFragmentManager(),
|
||||||
parentFolder, getAccount(), getStorageManager(), MainApp.isOnlyOnDevice());
|
parentFolder, getAccount(), getStorageManager(), MainApp.isOnlyOnDevice());
|
||||||
|
}
|
||||||
|
|
||||||
mViewPager = (ExtendedViewPager) findViewById(R.id.fragmentPager);
|
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;
|
position = (position >= 0) ? position : 0;
|
||||||
|
|
||||||
mViewPager.setAdapter(mPreviewImagePagerAdapter);
|
mViewPager.setAdapter(mPreviewImagePagerAdapter);
|
||||||
mViewPager.setOnPageChangeListener(this);
|
mViewPager.setOnPageChangeListener(this);
|
||||||
mViewPager.setCurrentItem(position);
|
mViewPager.setCurrentItem(position);
|
||||||
|
|
||||||
if (position == 0 && !getFile().isDown()) {
|
if (position == 0 && !getFile().isDown()) {
|
||||||
// this is necessary because mViewPager.setCurrentItem(0) just after setting the
|
// this is necessary because mViewPager.setCurrentItem(0) just after setting the
|
||||||
// adapter does not result in a call to #onPageSelected(0)
|
// adapter does not result in a call to #onPageSelected(0)
|
||||||
|
|
|
@ -27,6 +27,7 @@ import android.view.ViewGroup;
|
||||||
|
|
||||||
import com.owncloud.android.datamodel.FileDataStorageManager;
|
import com.owncloud.android.datamodel.FileDataStorageManager;
|
||||||
import com.owncloud.android.datamodel.OCFile;
|
import com.owncloud.android.datamodel.OCFile;
|
||||||
|
import com.owncloud.android.datamodel.VirtualFolderType;
|
||||||
import com.owncloud.android.ui.fragment.FileFragment;
|
import com.owncloud.android.ui.fragment.FileFragment;
|
||||||
import com.owncloud.android.utils.FileStorageUtils;
|
import com.owncloud.android.utils.FileStorageUtils;
|
||||||
|
|
||||||
|
@ -88,6 +89,43 @@ public class PreviewImagePagerAdapter extends FragmentStatePagerAdapter {
|
||||||
mCachedFragments = new HashMap<Integer, FileFragment>();
|
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.
|
* Returns the image files handled by the adapter.
|
||||||
*
|
*
|
||||||
|
@ -195,7 +233,7 @@ public class PreviewImagePagerAdapter extends FragmentStatePagerAdapter {
|
||||||
public void resetZoom() {
|
public void resetZoom() {
|
||||||
Iterator<FileFragment> entries = mCachedFragments.values().iterator();
|
Iterator<FileFragment> entries = mCachedFragments.values().iterator();
|
||||||
while (entries.hasNext()) {
|
while (entries.hasNext()) {
|
||||||
FileFragment fileFragment = (FileFragment) entries.next();
|
FileFragment fileFragment = entries.next();
|
||||||
if (fileFragment instanceof PreviewImageFragment) {
|
if (fileFragment instanceof PreviewImageFragment) {
|
||||||
((PreviewImageFragment) fileFragment).getImageView().resetZoom();
|
((PreviewImageFragment) fileFragment).getImageView().resetZoom();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue