Search in sources :

Example 16 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) {
        // 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());
        }
    }
}
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 17 with FileDataStorageManager

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);
}
Also used : ListView(android.widget.ListView) Button(android.widget.Button) FileDataStorageManager(com.owncloud.android.datamodel.FileDataStorageManager) Handler(android.os.Handler) Intent(android.content.Intent) TextView(android.widget.TextView) ScrollingMovementMethod(android.text.method.ScrollingMovementMethod)

Example 18 with FileDataStorageManager

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
}
Also used : OCFile(com.owncloud.android.datamodel.OCFile) Account(android.accounts.Account) FileDataStorageManager(com.owncloud.android.datamodel.FileDataStorageManager) Pair(android.support.v4.util.Pair)

Example 19 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)

Example 20 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)

Aggregations

FileDataStorageManager (com.owncloud.android.datamodel.FileDataStorageManager)23 OCFile (com.owncloud.android.datamodel.OCFile)9 RemoteOperationResult (com.owncloud.android.lib.common.operations.RemoteOperationResult)6 Account (android.accounts.Account)4 OwnCloudAccount (com.owncloud.android.lib.common.OwnCloudAccount)4 AccountsException (android.accounts.AccountsException)2 Intent (android.content.Intent)2 File (java.io.File)2 IOException (java.io.IOException)2 ContentResolver (android.content.ContentResolver)1 SharedPreferences (android.content.SharedPreferences)1 MatrixCursor (android.database.MatrixCursor)1 Uri (android.net.Uri)1 Handler (android.os.Handler)1 Pair (android.support.v4.util.Pair)1 ScrollingMovementMethod (android.text.method.ScrollingMovementMethod)1 Pair (android.util.Pair)1 Button (android.widget.Button)1 ListView (android.widget.ListView)1 TextView (android.widget.TextView)1