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();
}
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();
}
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();
}
}
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);
}
}
}
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)));
}
}
Aggregations