Search in sources :

Example 86 with FileDataStorageManager

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

the class PreviewAudioFragment method onFileMetadataChanged.

@Override
public void onFileMetadataChanged() {
    FileDataStorageManager storageManager = mContainerActivity.getStorageManager();
    if (storageManager != null) {
        setFile(storageManager.getFileByPath(getFile().getRemotePath()));
    }
    getActivity().invalidateOptionsMenu();
}
Also used : FileDataStorageManager(com.owncloud.android.datamodel.FileDataStorageManager)

Example 87 with FileDataStorageManager

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

the class FileDetailFragment method updateFileDetails.

/**
 * Updates the view with all relevant details about that file.
 *
 * @param forcedTransferring Flag signaling if the file should be considered as downloading or uploading,
 *                           although {@link FileDownloaderBinder#isDownloading(Account, OCFile)}  and
 *                           {@link FileUploaderBinder#isUploading(Account, OCFile)} return false.
 * @param refresh            If 'true', try to refresh the whole file from the database
 */
private void updateFileDetails(boolean forcedTransferring, boolean refresh) {
    if (readyToShow()) {
        FileDataStorageManager storageManager = mContainerActivity.getStorageManager();
        if (refresh && storageManager != null) {
            setFile(storageManager.getFileByPath(getFile().getRemotePath()));
        }
        OCFile file = getFile();
        // set file details
        setFilename(file.getFileName());
        setFiletype(file);
        setFilesize(file.getFileLength());
        setTimeModified(file.getModificationTimestamp());
        // configure UI for depending upon local state of the file
        FileDownloaderBinder downloaderBinder = mContainerActivity.getFileDownloaderBinder();
        FileUploaderBinder uploaderBinder = mContainerActivity.getFileUploaderBinder();
        if (forcedTransferring || (downloaderBinder != null && downloaderBinder.isDownloading(mAccount, file)) || (uploaderBinder != null && uploaderBinder.isUploading(mAccount, file))) {
            setButtonsForTransferring();
        } else if (file.isDown()) {
            setButtonsForDown();
        } else {
            // TODO load default preview image; when the local file is removed, the preview
            // remains there
            setButtonsForRemote();
        }
    }
    getView().invalidate();
}
Also used : OCFile(com.owncloud.android.datamodel.OCFile) FileDownloaderBinder(com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder) FileUploaderBinder(com.owncloud.android.files.services.FileUploader.FileUploaderBinder) FileDataStorageManager(com.owncloud.android.datamodel.FileDataStorageManager)

Example 88 with FileDataStorageManager

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

the class OCFileListFragment method listDirectory.

/**
 * Lists the given directory on the view. When the input parameter is null,
 * it will either refresh the last known directory. list the root
 * if there never was a directory.
 *
 * @param directory File to be listed
 */
public void listDirectory(OCFile directory) {
    if (mContainerActivity == null) {
        Timber.e("No container activity attached");
        return;
    }
    FileDataStorageManager storageManager = mContainerActivity.getStorageManager();
    if (storageManager != null) {
        // Check input parameters for null
        if (directory == null) {
            if (mFile != null) {
                directory = mFile;
            } else {
                directory = storageManager.getFileByPath(OCFile.ROOT_PATH);
                if (directory == null) {
                    // no files, wait for sync
                    return;
                }
            }
        }
        // If that's not a directory -> List its parent
        if (!directory.isFolder()) {
            Timber.w("You see, that is not a directory -> %s", directory.toString());
            directory = storageManager.getFileById(directory.getParentId());
        }
        mFileListAdapter.swapDirectory(directory, storageManager);
        if (mFile == null || !mFile.equals(directory)) {
            mCurrentListView.setSelection(0);
        }
        mFile = directory;
        updateLayout();
    }
}
Also used : FileDataStorageManager(com.owncloud.android.datamodel.FileDataStorageManager)

Example 89 with FileDataStorageManager

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

the class FileDownloader method downloadFile.

/**
 * Core download method: requests a file to download and stores it.
 *
 * @param downloadKey Key to access the download to perform, contained in mPendingDownloads
 */
private void downloadFile(String downloadKey) {
    mCurrentDownload = mPendingDownloads.get(downloadKey);
    if (mCurrentDownload != null) {
        // / Check account existence
        if (!AccountUtils.exists(mCurrentDownload.getAccount().name, this)) {
            Timber.w("Account " + mCurrentDownload.getAccount().name + " does not exist anymore -> cancelling all" + " its downloads");
            cancelDownloadsForAccount(mCurrentDownload.getAccount());
            return;
        }
        notifyDownloadStart(mCurrentDownload);
        RemoteOperationResult downloadResult = null;
        try {
            // / prepare client object to send the request to the ownCloud server
            if (mCurrentAccount == null || !mCurrentAccount.equals(mCurrentDownload.getAccount())) {
                mCurrentAccount = mCurrentDownload.getAccount();
                mStorageManager = new FileDataStorageManager(this, mCurrentAccount, getContentResolver());
            }
            // else, reuse storage manager from previous operation
            // always get client from client manager to get fresh credentials in case of update
            OwnCloudAccount ocAccount = new OwnCloudAccount(mCurrentAccount, this);
            mDownloadClient = SingleSessionManager.getDefaultSingleton().getClientFor(ocAccount, this);
            // / perform the download
            downloadResult = mCurrentDownload.execute(mDownloadClient);
            if (downloadResult.isSuccess()) {
                saveDownloadedFile();
            }
        } catch (Exception e) {
            Timber.e(e, "Error downloading");
            downloadResult = new RemoteOperationResult(e);
        } finally {
            Pair<DownloadFileOperation, String> removeResult = mPendingDownloads.removePayload(mCurrentAccount.name, mCurrentDownload.getRemotePath());
            if (!downloadResult.isSuccess() && downloadResult.getException() != null) {
                // if failed due to lack of connectivity, schedule an automatic retry
                TransferRequester requester = new TransferRequester();
                if (requester.shouldScheduleRetry(this, downloadResult.getException())) {
                    int jobId = mPendingDownloads.buildKey(mCurrentAccount.name, mCurrentDownload.getRemotePath()).hashCode();
                    requester.scheduleDownload(this, jobId, mCurrentAccount.name, mCurrentDownload.getRemotePath());
                    downloadResult = new RemoteOperationResult(ResultCode.NO_NETWORK_CONNECTION);
                } else {
                    Timber.v("Exception in download, network is OK, no retry scheduled for %1s in %2s", mCurrentDownload.getRemotePath(), mCurrentAccount.name);
                }
            } else {
                Timber.v("Success OR fail without exception for %1s in %2s", mCurrentDownload.getRemotePath(), mCurrentAccount.name);
            }
            // / notify result
            notifyDownloadResult(mCurrentDownload, downloadResult);
            sendBroadcastDownloadFinished(mCurrentDownload, downloadResult, removeResult.second);
        }
    }
}
Also used : DownloadFileOperation(com.owncloud.android.operations.DownloadFileOperation) RemoteOperationResult(com.owncloud.android.lib.common.operations.RemoteOperationResult) FileDataStorageManager(com.owncloud.android.datamodel.FileDataStorageManager) OwnCloudAccount(com.owncloud.android.lib.common.OwnCloudAccount)

Example 90 with FileDataStorageManager

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

the class SynchronizeFolderOperation method removeLocalFolder.

private void removeLocalFolder() {
    FileDataStorageManager storageManager = getStorageManager();
    if (storageManager.fileExists(mLocalFolder.getFileId())) {
        String currentSavePath = FileStorageUtils.getSavePath(mAccount.name);
        storageManager.removeFolder(mLocalFolder, true, (mLocalFolder.isDown() && mLocalFolder.getStoragePath().startsWith(currentSavePath)));
    }
}
Also used : FileDataStorageManager(com.owncloud.android.datamodel.FileDataStorageManager)

Aggregations

FileDataStorageManager (com.owncloud.android.datamodel.FileDataStorageManager)91 OCFile (com.owncloud.android.datamodel.OCFile)43 RemoteOperationResult (com.owncloud.android.lib.common.operations.RemoteOperationResult)21 Account (android.accounts.Account)19 User (com.nextcloud.client.account.User)16 Intent (android.content.Intent)12 OwnCloudAccount (com.owncloud.android.lib.common.OwnCloudAccount)12 Context (android.content.Context)9 File (java.io.File)9 ArrayList (java.util.ArrayList)9 OCCapability (com.owncloud.android.lib.resources.status.OCCapability)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 DialogFragment (androidx.fragment.app.DialogFragment)4 IOException (java.io.IOException)4 AccountsException (android.accounts.AccountsException)3