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) {
// Detect if the account exists
if (AccountUtils.exists(mCurrentDownload.getAccount(), getApplicationContext())) {
Log_OC.d(TAG, "Account " + mCurrentDownload.getAccount().name + " exists");
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(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 = OwnCloudClientManagerFactory.getDefaultSingleton().getClientFor(ocAccount, this);
/// perform the download
downloadResult = mCurrentDownload.execute(mDownloadClient);
if (downloadResult.isSuccess()) {
saveDownloadedFile();
}
} catch (Exception e) {
Log_OC.e(TAG, "Error downloading", e);
downloadResult = new RemoteOperationResult(e);
} finally {
Pair<DownloadFileOperation, String> removeResult = mPendingDownloads.removePayload(mCurrentAccount.name, mCurrentDownload.getRemotePath());
/// notify result
notifyDownloadResult(mCurrentDownload, downloadResult);
sendBroadcastDownloadFinished(mCurrentDownload, downloadResult, removeResult.second);
}
} else {
// Cancel the transfer
Log_OC.d(TAG, "Account " + mCurrentDownload.getAccount().toString() + " doesn't exist");
cancelDownloadsForAccount(mCurrentDownload.getAccount());
}
}
}
use of com.owncloud.android.datamodel.FileDataStorageManager in project android by owncloud.
the class ErrorsWhileCopyingHandlerActivity method onCreate.
/**
* {@link}
*/
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
/// read extra parameters in intent
Intent intent = getIntent();
mAccount = intent.getParcelableExtra(EXTRA_ACCOUNT);
mRemotePaths = intent.getStringArrayListExtra(EXTRA_REMOTE_PATHS);
mLocalPaths = intent.getStringArrayListExtra(EXTRA_LOCAL_PATHS);
mStorageManager = new FileDataStorageManager(mAccount, getContentResolver());
mHandler = new Handler();
if (mCurrentDialog != null) {
mCurrentDialog.dismiss();
mCurrentDialog = null;
}
/// load generic layout
setContentView(R.layout.generic_explanation);
/// customize text message
TextView textView = (TextView) findViewById(R.id.message);
String appName = getString(R.string.app_name);
String message = String.format(getString(R.string.sync_foreign_files_forgotten_explanation), appName, appName, appName, appName, mAccount.name);
textView.setText(message);
textView.setMovementMethod(new ScrollingMovementMethod());
/// load the list of local and remote files that failed
ListView listView = (ListView) findViewById(R.id.list);
if (mLocalPaths != null && mLocalPaths.size() > 0) {
mAdapter = new ErrorsWhileCopyingListAdapter();
listView.setAdapter(mAdapter);
} else {
listView.setVisibility(View.GONE);
mAdapter = null;
}
/// customize buttons
Button cancelBtn = (Button) findViewById(R.id.cancel);
Button okBtn = (Button) findViewById(R.id.ok);
okBtn.setText(R.string.foreign_files_move);
cancelBtn.setOnClickListener(this);
okBtn.setOnClickListener(this);
}
use of com.owncloud.android.datamodel.FileDataStorageManager in project android by owncloud.
the class FileObserverService method startObservation.
/**
* Read from the local database the list of files that must to be kept
* synchronized and starts observers to monitor local changes on them.
*
* Updates the list of currently observed files if called multiple times.
*/
private void startObservation() {
Log_OC.d(TAG, "Loading all available offline files from database to start watching them");
FileDataStorageManager fds = new FileDataStorageManager(// this is dangerous - handle with care
null, getContentResolver());
List<Pair<OCFile, String>> availableOfflineFiles = fds.getAvailableOfflineFilesFromEveryAccount();
OCFile file;
String accountName;
Account account;
for (Pair<OCFile, String> pair : availableOfflineFiles) {
file = pair.first;
accountName = pair.second;
account = new Account(accountName, MainApp.getAccountType());
if (!AccountUtils.exists(account, this)) {
continue;
}
addObservedFile(file, account);
}
// watch for instant uploads
updateInstantUploadsObservers();
// service does not stopSelf() ; that way it tries to be alive forever
}
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)));
}
}
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();
}
Aggregations