Search in sources :

Example 56 with FileDataStorageManager

use of com.owncloud.android.datamodel.FileDataStorageManager in project android by nextcloud.

the class EditShareFragment method refreshUiFromDB.

/**
 * Get {@link OCShare} instance from DB and updates the UI.
 *
 * Depends on the parent Activity provides a {@link com.owncloud.android.datamodel.FileDataStorageManager}
 * instance ready to use. If not ready, does nothing.
 *
 * @param editShareView     Root view in the fragment.
 */
private void refreshUiFromDB(View editShareView) {
    FileDataStorageManager storageManager = ((FileActivity) getActivity()).getStorageManager();
    if (storageManager != null) {
        // Get edited share
        mShare = storageManager.getShareById(mShare.getId());
        // Updates UI with new state
        refreshUiFromState(editShareView);
    }
}
Also used : FileDataStorageManager(com.owncloud.android.datamodel.FileDataStorageManager) FileActivity(com.owncloud.android.ui.activity.FileActivity)

Example 57 with FileDataStorageManager

use of com.owncloud.android.datamodel.FileDataStorageManager in project android by nextcloud.

the class ContactsBackupFragment method refreshBackupFolder.

private void refreshBackupFolder(final String backupFolderPath, final ContactsPreferenceActivity contactsPreferenceActivity) {
    AsyncTask<String, Integer, Boolean> task = new AsyncTask<String, Integer, Boolean>() {

        @Override
        protected Boolean doInBackground(String... path) {
            FileDataStorageManager storageManager = new FileDataStorageManager(account, contactsPreferenceActivity.getContentResolver());
            OCFile folder = storageManager.getFileByPath(path[0]);
            if (folder != null) {
                RefreshFolderOperation operation = new RefreshFolderOperation(folder, System.currentTimeMillis(), false, false, false, storageManager, account, getContext());
                RemoteOperationResult result = operation.execute(account, getContext());
                return result.isSuccess();
            } else {
                return false;
            }
        }

        @Override
        protected void onPostExecute(Boolean result) {
            if (result) {
                OCFile backupFolder = contactsPreferenceActivity.getStorageManager().getFileByPath(backupFolderPath);
                List<OCFile> backupFiles = contactsPreferenceActivity.getStorageManager().getFolderContent(backupFolder, false);
                if (backupFiles == null || backupFiles.size() == 0) {
                    contactsDatePickerBtn.setVisibility(View.GONE);
                } else {
                    contactsDatePickerBtn.setVisibility(View.VISIBLE);
                }
            }
        }
    };
    task.execute(backupFolderPath);
}
Also used : OCFile(com.owncloud.android.datamodel.OCFile) RemoteOperationResult(com.owncloud.android.lib.common.operations.RemoteOperationResult) RefreshFolderOperation(com.owncloud.android.operations.RefreshFolderOperation) AsyncTask(android.os.AsyncTask) FileDataStorageManager(com.owncloud.android.datamodel.FileDataStorageManager)

Example 58 with FileDataStorageManager

use of com.owncloud.android.datamodel.FileDataStorageManager in project android by nextcloud.

the class ThemeUtils method getCapability.

private static OCCapability getCapability(Account acc) {
    Account account;
    Context context = MainApp.getAppContext();
    if (context == null) {
        return new OCCapability();
    }
    if (acc != null) {
        account = acc;
    } else {
        account = AccountUtils.getCurrentOwnCloudAccount(context);
    }
    if (account != null) {
        FileDataStorageManager storageManager = new FileDataStorageManager(account, context.getContentResolver());
        return storageManager.getCapability(account.name);
    } else {
        return new OCCapability();
    }
}
Also used : Context(android.content.Context) Account(android.accounts.Account) OCCapability(com.owncloud.android.lib.resources.status.OCCapability) FileDataStorageManager(com.owncloud.android.datamodel.FileDataStorageManager)

Example 59 with FileDataStorageManager

use of com.owncloud.android.datamodel.FileDataStorageManager in project android by nextcloud.

the class RemoveFileDialogFragment method onCancel.

/**
 * Performs the removal of the local copy of the target file
 */
@Override
public void onCancel(String callerTag) {
    ComponentsGetter cg = (ComponentsGetter) getActivity();
    ArrayList<OCFile> list = new ArrayList<>();
    list.add(mTargetFile);
    cg.getFileOperationsHelper().removeFiles(list, true);
    FileDataStorageManager storageManager = cg.getStorageManager();
    boolean containsFavorite = false;
    if (mTargetFile.isFolder()) {
        List<OCFile> files = storageManager.getFolderContent(mTargetFile, false);
        for (OCFile file : files) {
            containsFavorite = file.isAvailableOffline() || containsFavorite;
            if (containsFavorite) {
                break;
            }
        }
    }
    // or is a folder and contains favorite
    if (mTargetFile.isAvailableOffline() || containsFavorite) {
        OCFile folder = null;
        if (mTargetFile.isFolder()) {
            folder = mTargetFile;
        } else {
            folder = storageManager.getFileById(mTargetFile.getParentId());
        }
        folder.setEtag("");
        storageManager.saveFile(folder);
    }
}
Also used : ComponentsGetter(com.owncloud.android.ui.activity.ComponentsGetter) OCFile(com.owncloud.android.datamodel.OCFile) ArrayList(java.util.ArrayList) FileDataStorageManager(com.owncloud.android.datamodel.FileDataStorageManager)

Example 60 with FileDataStorageManager

use of com.owncloud.android.datamodel.FileDataStorageManager in project android by nextcloud.

the class SynchronizeFolderOperation method synchronizeData.

/**
 * Synchronizes the data retrieved from the server about the contents of the target folder
 * with the current data in the local database.
 *
 * Grants that mChildren is updated with fresh data after execution.
 *
 * @param folderAndFiles Remote folder and children files in Folder
 */
private void synchronizeData(ArrayList<Object> folderAndFiles) throws OperationCancelledException {
    FileDataStorageManager storageManager = getStorageManager();
    // parse data from remote folder
    OCFile remoteFolder = FileStorageUtils.fillOCFile((RemoteFile) folderAndFiles.get(0));
    remoteFolder.setParentId(mLocalFolder.getParentId());
    remoteFolder.setFileId(mLocalFolder.getFileId());
    Log_OC.d(TAG, "Remote folder " + mLocalFolder.getRemotePath() + " changed - starting update of local data ");
    List<OCFile> updatedFiles = new Vector<>(folderAndFiles.size() - 1);
    mFilesForDirectDownload.clear();
    mFilesToSyncContents.clear();
    if (mCancellationRequested.get()) {
        throw new OperationCancelledException();
    }
    // get current data about local contents of the folder to synchronize
    List<OCFile> localFiles = storageManager.getFolderContent(mLocalFolder, false);
    Map<String, OCFile> localFilesMap = new HashMap<>(localFiles.size());
    for (OCFile file : localFiles) {
        localFilesMap.put(file.getRemotePath(), file);
    }
    // loop to synchronize every child
    OCFile remoteFile = null;
    OCFile localFile = null;
    OCFile updatedFile = null;
    RemoteFile r;
    for (int i = 1; i < folderAndFiles.size(); i++) {
        // / new OCFile instance with the data from the server
        r = (RemoteFile) folderAndFiles.get(i);
        remoteFile = FileStorageUtils.fillOCFile(r);
        // / retrieve local data for the read file
        // localFile = mStorageManager.getFileByPath(remoteFile.getRemotePath());
        localFile = localFilesMap.remove(remoteFile.getRemotePath());
        // / new OCFile instance to merge fresh data from server with local state
        updatedFile = FileStorageUtils.fillOCFile(r);
        updatedFile.setParentId(mLocalFolder.getFileId());
        // / add to updatedFile data about LOCAL STATE (not existing in server)
        updateLocalStateData(remoteFile, localFile, updatedFile);
        // / check and fix, if needed, local storage path
        searchForLocalFileInDefaultPath(updatedFile);
        // / classify file to sync/download contents later
        classifyFileForLaterSyncOrDownload(remoteFile, localFile);
        updatedFiles.add(updatedFile);
    }
    // save updated contents in local database
    storageManager.saveFolder(remoteFolder, updatedFiles, localFilesMap.values());
}
Also used : OCFile(com.owncloud.android.datamodel.OCFile) HashMap(java.util.HashMap) OperationCancelledException(com.owncloud.android.lib.common.operations.OperationCancelledException) FileDataStorageManager(com.owncloud.android.datamodel.FileDataStorageManager) Vector(java.util.Vector) RemoteFile(com.owncloud.android.lib.resources.files.RemoteFile)

Aggregations

FileDataStorageManager (com.owncloud.android.datamodel.FileDataStorageManager)91 OCFile (com.owncloud.android.datamodel.OCFile)42 RemoteOperationResult (com.owncloud.android.lib.common.operations.RemoteOperationResult)22 Account (android.accounts.Account)19 User (com.nextcloud.client.account.User)17 Intent (android.content.Intent)12 OwnCloudAccount (com.owncloud.android.lib.common.OwnCloudAccount)12 ArrayList (java.util.ArrayList)10 OCCapability (com.owncloud.android.lib.resources.status.OCCapability)9 File (java.io.File)9 Context (android.content.Context)8 Test (org.junit.Test)8 ScreenshotTest (com.owncloud.android.utils.ScreenshotTest)7 OCUpload (com.owncloud.android.db.OCUpload)6 AccountManager (android.accounts.AccountManager)5 OperationCancelledException (com.owncloud.android.lib.common.operations.OperationCancelledException)5 UploadFileOperation (com.owncloud.android.operations.UploadFileOperation)5 Handler (android.os.Handler)4 DialogFragment (androidx.fragment.app.DialogFragment)4 IOException (java.io.IOException)4