Skip to content
13 changes: 0 additions & 13 deletions owncloudApp/src/main/java/com/owncloud/android/MainApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,6 @@ public class MainApp extends Application {

private static Context mContext;

// TODO Enable when "On Device" is recovered?
// TODO better place
// private static boolean mOnlyOnDevice = false;

public static String BETA_VERSION = "beta";

public void onCreate() {
Expand Down Expand Up @@ -235,15 +231,6 @@ public static String getLogName() {
return getAppContext().getResources().getString(R.string.log_name);
}

// TODO Enable when "On Device" is recovered ?
// public static void showOnlyFilesOnDevice(boolean state){
// mOnlyOnDevice = state;
// }
//
// public static boolean getOnlyOnDevice(){
// return mOnlyOnDevice;
// }

// user agent
public static String getUserAgent() {
String appString = getAppContext().getResources().getString(R.string.user_agent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* @author Bartek Przybylski
* @author Christian Schabesberger
* @author David González Verdugo
* @author Abel García de Prada
* <p>
* Copyright (C) 2012 Bartek Przybylski
* Copyright (C) 2019 ownCloud GmbH.
Expand Down Expand Up @@ -175,22 +176,20 @@ public boolean fileExists(String path) {
return fileExists(ProviderTableMeta.FILE_PATH, path);
}

public Vector<OCFile> getFolderContent(OCFile f/*, boolean onlyOnDevice*/) {
public Vector<OCFile> getFolderContent(OCFile f, boolean onlyAvailableOffline) {
if (f != null && f.isFolder() && f.getFileId() != -1) {
// TODO Enable when "On Device" is recovered ?
return getFolderContent(f.getFileId()/*, onlyOnDevice*/);
return getFolderContent(f.getFileId(), onlyAvailableOffline);

} else {
return new Vector<>();
}
}

public Vector<OCFile> getFolderImages(OCFile folder/*, boolean onlyOnDevice*/) {
public Vector<OCFile> getFolderImages(OCFile folder) {
Vector<OCFile> ret = new Vector<OCFile>();
if (folder != null) {
// TODO better implementation, filtering in the access to database instead of here
// TODO Enable when "On Device" is recovered ?
Vector<OCFile> tmp = getFolderContent(folder/*, onlyOnDevice*/);
Vector<OCFile> tmp = getFolderContent(folder, false);
OCFile current;
for (int i = 0; i < tmp.size(); i++) {
current = tmp.get(i);
Expand Down Expand Up @@ -666,8 +665,7 @@ private boolean removeLocalFolder(OCFile folder) {
File localFolder = new File(localFolderPath);
if (localFolder.exists()) {
// stage 1: remove the local files already registered in the files database
// TODO Enable when "On Device" is recovered ?
Vector<OCFile> files = getFolderContent(folder.getFileId()/*, false*/);
Vector<OCFile> files = getFolderContent(folder.getFileId(), false);
if (files != null) {
for (OCFile file : files) {
if (file.isFolder()) {
Expand Down Expand Up @@ -713,7 +711,7 @@ private boolean removeLocalFolder(File localFolder) {

/**
* Updates database and file system for a file or folder that was moved to a different location.
*
* <p>
* TODO explore better (faster) implementations
* TODO throw exceptions up !
*/
Expand Down Expand Up @@ -928,38 +926,44 @@ private boolean copyFile(File src, File target) {
return ret;
}

private Vector<OCFile> getFolderContent(long parentId/*, boolean onlyOnDevice*/) {

private Vector<OCFile> getFolderContent(long parentId, boolean onlyAvailableOffline) {
Vector<OCFile> ret = new Vector<OCFile>();

Uri req_uri = Uri.withAppendedPath(
ProviderTableMeta.CONTENT_URI_DIR,
String.valueOf(parentId));
Cursor c = null;

String selection;
String[] selectionArgs;

if (!onlyAvailableOffline) {
selection = ProviderTableMeta.FILE_PARENT + "=?";
selectionArgs = new String[] {String.valueOf(parentId)};
} else {
selection = ProviderTableMeta.FILE_PARENT + "=? AND (" + ProviderTableMeta.FILE_KEEP_IN_SYNC +
" = ? OR " + ProviderTableMeta.FILE_KEEP_IN_SYNC + "=? )";
selectionArgs = new String[]{String.valueOf(parentId),
String.valueOf(OCFile.AvailableOfflineStatus.AVAILABLE_OFFLINE.getValue()),
String.valueOf(OCFile.AvailableOfflineStatus.AVAILABLE_OFFLINE_PARENT.getValue())};
}

if (getContentProviderClient() != null) {
try {
c = getContentProviderClient().query(req_uri, null,
ProviderTableMeta.FILE_PARENT + "=?",
new String[]{String.valueOf(parentId)}, null);
c = getContentProviderClient().query(req_uri, null, selection, selectionArgs, null);
} catch (RemoteException e) {
Log_OC.e(TAG, e.getMessage());
return ret;
}
} else {
c = getContentResolver().query(req_uri, null,
ProviderTableMeta.FILE_PARENT + "=?",
new String[]{String.valueOf(parentId)}, null);
c = getContentResolver().query(req_uri, null, selection, selectionArgs, null);
}

if (c != null) {
if (c.moveToFirst()) {
do {
OCFile child = createFileInstance(c);
// TODO Enable when "On Device" is recovered ?
// if (child.isFolder() || !onlyOnDevice || onlyOnDevice && child.isDown()){
ret.add(child);
// }
} while (c.moveToNext());
}
c.close();
Expand Down Expand Up @@ -1591,8 +1595,7 @@ private ArrayList<ContentProviderOperation> prepareRemoveSharesInFolder(
+ ProviderTableMeta.OCSHARES_ACCOUNT_OWNER + "=?";
String[] whereArgs = new String[]{"", mAccount.name};

// TODO Enable when "On Device" is recovered ?
Vector<OCFile> files = getFolderContent(folder /*, false*/);
Vector<OCFile> files = getFolderContent(folder, false);

for (OCFile file : files) {
whereArgs[0] = file.getRemotePath();
Expand Down Expand Up @@ -2184,4 +2187,51 @@ public List<Pair<OCFile, String>> getAvailableOfflineFilesFromEveryAccount() {

return result;
}

/**
* Get a collection with all the files set by the user as available offline, from current account
* putting away files whose parent is also available offline
*
* @return List with all the files set by current user as available offline.
*/
public Vector<OCFile> getAvailableOfflineFilesFromCurrentAccount() {
Vector<OCFile> result = new Vector<>();

Cursor cursorOnKeptInSync = null;
try {
// query for available offline files in current account and whose parent is not.
cursorOnKeptInSync = getContentResolver().query(
ProviderTableMeta.CONTENT_URI,
null,
"(" + ProviderTableMeta.FILE_KEEP_IN_SYNC + " = ? AND NOT " +
ProviderTableMeta.FILE_KEEP_IN_SYNC + " = ? ) AND " +
ProviderTableMeta.FILE_ACCOUNT_OWNER + " = ? ",
new String[]{
String.valueOf(OCFile.AvailableOfflineStatus.AVAILABLE_OFFLINE.getValue()),
String.valueOf(OCFile.AvailableOfflineStatus.AVAILABLE_OFFLINE_PARENT.getValue()),
mAccount.name
},
null
);

if (cursorOnKeptInSync != null && cursorOnKeptInSync.moveToFirst()) {
OCFile file;
do {
file = createFileInstance(cursorOnKeptInSync);
result.add(file);
} while (cursorOnKeptInSync.moveToNext());
}

} catch (Exception e) {
Log_OC.e(TAG, "Exception retrieving all the available offline files", e);

} finally {
if (cursorOnKeptInSync != null) {
cursorOnKeptInSync.close();
}
}

Collections.sort(result);
return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*
* @author David A. Velasco
* @author Christian Schabesberger
* @author Abel García de Prada
* Copyright (C) 2019 ownCloud GmbH.
* <p>
* This program is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -89,15 +90,16 @@ public FileMenuFilter(OCFile targetFile, Account account, ComponentsGetter cg,
*
* @param menu Options or context menu to filter.
*/
public void filter(Menu menu, boolean displaySelectAll, boolean displaySelectInverse) {
public void filter(Menu menu, boolean displaySelectAll, boolean displaySelectInverse,
boolean onlyAvailableOffline) {
if (mFiles == null || mFiles.size() <= 0) {
hideAll(menu);

} else {
List<Integer> toShow = new ArrayList<>();
List<Integer> toHide = new ArrayList<>();

filter(toShow, toHide, displaySelectAll, displaySelectInverse);
filter(toShow, toHide, displaySelectAll, displaySelectInverse, onlyAvailableOffline);

MenuItem item;
for (int i : toShow) {
Expand Down Expand Up @@ -135,8 +137,9 @@ private void hideAll(Menu menu) {
* @param toShow List to save the options that must be shown in the menu.
* @param toHide List to save the options that must be shown in the menu.
*/
private void filter(List<Integer> toShow, List<Integer> toHide, boolean displaySelectAll,
boolean displaySelectInverse) {

private void filter(List<Integer> toShow, List <Integer> toHide, boolean displaySelectAll,
boolean displaySelectInverse, boolean onlyAvailableOffline) {

boolean synchronizing = anyFileSynchronizing();

Expand All @@ -158,23 +161,24 @@ private void filter(List<Integer> toShow, List<Integer> toHide, boolean displayS
}

// DOWNLOAD
if (mFiles.isEmpty() || containsFolder() || anyFileDown() || synchronizing || videoPreviewing) {
if (mFiles.isEmpty() || containsFolder() || anyFileDown() || synchronizing || videoPreviewing ||
onlyAvailableOffline) {
toHide.add(R.id.action_download_file);

} else {
toShow.add(R.id.action_download_file);
}

// RENAME
if (!isSingleSelection() || synchronizing || videoPreviewing) {
if (!isSingleSelection() || synchronizing || videoPreviewing || onlyAvailableOffline) {
toHide.add(R.id.action_rename_file);

} else {
toShow.add(R.id.action_rename_file);
}

// MOVE & COPY
if (mFiles.isEmpty() || synchronizing || videoPreviewing) {
if (mFiles.isEmpty() || synchronizing || videoPreviewing || onlyAvailableOffline) {
toHide.add(R.id.action_move);
toHide.add(R.id.action_copy);

Expand All @@ -184,7 +188,7 @@ private void filter(List<Integer> toShow, List<Integer> toHide, boolean displayS
}

// REMOVE
if (mFiles.isEmpty() || synchronizing) {
if (mFiles.isEmpty() || synchronizing || onlyAvailableOffline) {
toHide.add(R.id.action_remove_file);

} else {
Expand All @@ -200,15 +204,15 @@ private void filter(List<Integer> toShow, List<Integer> toHide, boolean displayS
}

// CANCEL SYNCHRONIZATION
if (mFiles.isEmpty() || !synchronizing || anyFavorite()) {
if (mFiles.isEmpty() || !synchronizing || anyFavorite() || onlyAvailableOffline) {
toHide.add(R.id.action_cancel_sync);

} else {
toShow.add(R.id.action_cancel_sync);
}

// SYNC CONTENTS (BOTH FILE AND FOLDER)
if (mFiles.isEmpty() || (!anyFileDown() && !containsFolder()) || synchronizing) {
if (mFiles.isEmpty() || (!anyFileDown() && !containsFolder()) || synchronizing || onlyAvailableOffline) {
toHide.add(R.id.action_sync_file);

} else {
Expand All @@ -231,7 +235,7 @@ private void filter(List<Integer> toShow, List<Integer> toHide, boolean displayS
capability != null && capability.getFilesSharingResharing().isFalse();

if ((!shareViaLinkAllowed && !shareWithUsersAllowed) || !isSingleSelection() ||
!shareApiEnabled || notAllowResharing) {
!shareApiEnabled || notAllowResharing || onlyAvailableOffline) {
toHide.add(R.id.action_share_file);
} else {
toShow.add(R.id.action_share_file);
Expand All @@ -247,7 +251,7 @@ private void filter(List<Integer> toShow, List<Integer> toHide, boolean displayS
// SEND
boolean sendAllowed = (mContext != null &&
mContext.getString(R.string.send_files_to_other_apps).equalsIgnoreCase("on"));
if (!isSingleFile() || !sendAllowed || synchronizing || videoStreaming) {
if (!isSingleFile() || !sendAllowed || synchronizing || videoStreaming || onlyAvailableOffline) {
toHide.add(R.id.action_send_file);
} else {
toShow.add(R.id.action_send_file);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
* Operation performing the synchronization of the list of files contained
* in a folder identified with its remote path.
*
* Fetches the list and properties of the files contained in the given folder, including their
q * Fetches the list and properties of the files contained in the given folder, including their
* properties, and updates the local database with them.
*
* Does NOT enter in the child folders to synchronize their contents also, BUT requests for a new operation instance
Expand Down Expand Up @@ -303,7 +303,7 @@ private void mergeRemoteFolder(ArrayList<RemoteFile> folderAndFiles)
}

// get current data about local contents of the folder to synchronize
List<OCFile> localFiles = storageManager.getFolderContent(mLocalFolder);
List<OCFile> localFiles = storageManager.getFolderContent(mLocalFolder, false);
Map<String, OCFile> localFilesMap = new HashMap<>(localFiles.size());
for (OCFile file : localFiles) {
localFilesMap.put(file.getRemoteId(), file);
Expand Down Expand Up @@ -370,7 +370,7 @@ private void mergeRemoteFolder(ArrayList<RemoteFile> folderAndFiles)
}

private void preparePushOfLocalChanges() {
List<OCFile> children = getStorageManager().getFolderContent(mLocalFolder);
List<OCFile> children = getStorageManager().getFolderContent(mLocalFolder, false);
mFoldersToVisit = new Vector<>(children.size());
for (OCFile child : children) {
addToSyncContents(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public Cursor queryChildDocuments(String parentDocumentId, String[] projection,
final OCFile browsedDir = mCurrentStorageManager.getFileById(folderId);

// Create result cursor before syncing folder again, in order to enable faster loading
for (OCFile file : mCurrentStorageManager.getFolderContent(browsedDir)) {
for (OCFile file : mCurrentStorageManager.getFolderContent(browsedDir, false)) {
resultCursor.addFile(file);
}

Expand Down Expand Up @@ -260,7 +260,7 @@ private boolean waitOrGetCancelled(CancellationSignal cancellationSignal) {

Vector<OCFile> findFiles(OCFile root, String query) {
Vector<OCFile> result = new Vector<OCFile>();
for (OCFile f : mCurrentStorageManager.getFolderContent(root)) {
for (OCFile f : mCurrentStorageManager.getFolderContent(root, false)) {
if (f.isFolder()) {
result.addAll(findFiles(f, query));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,25 +241,19 @@ public boolean onNavigationItemSelected(MenuItem menuItem) {
case R.id.nav_all_files:
menuItem.setChecked(true);
mCheckedMenuItem = menuItem.getItemId();

allFilesOption();
// TODO activate when On Device branch is merged
// MainApp.showOnlyFilesOnDevice(false);
// refreshDirectory();
break;
// TODO activate when On Device branch is merged
// case R.id.nav_on_device:
// menuItem.setChecked(true);
// mCheckedMenuItem = menuItem.getItemId();
// MainApp.showOnlyFilesOnDevice(true);
// refreshDirectory();
// break;
case R.id.nav_uploads:
Intent uploadListIntent = new Intent(getApplicationContext(),
UploadListActivity.class);
uploadListIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(uploadListIntent);
break;
case R.id.nav_only_available_offline:
menuItem.setChecked(true);
mCheckedMenuItem = menuItem.getItemId();
onlyAvailableOfflineOption();
break;
case R.id.nav_settings:
Intent settingsIntent = new Intent(getApplicationContext(),
Preferences.class);
Expand Down Expand Up @@ -537,6 +531,11 @@ private void updateQuota() {
*/
public abstract void allFilesOption();

/**
* Method that gets called on drawer menu click for 'Available Offline'.
*/
public abstract void onlyAvailableOfflineOption();

/**
* Updates title bar and home buttons (state and icon).
* <p/>
Expand Down
Loading