Search in sources :

Example 51 with FileDataStorageManager

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

the class FileDisplayActivity method openFile.

private void openFile(User user, String fileId) {
    setUser(user);
    if (fileId == null) {
        dismissLoadingDialog();
        DisplayUtils.showSnackMessage(this, getString(R.string.error_retrieving_file));
        return;
    }
    FileDataStorageManager storageManager = getStorageManager();
    if (storageManager == null) {
        storageManager = new FileDataStorageManager(user, getContentResolver());
    }
    FetchRemoteFileTask fetchRemoteFileTask = new FetchRemoteFileTask(user, fileId, storageManager, this);
    fetchRemoteFileTask.execute();
}
Also used : FileDataStorageManager(com.owncloud.android.datamodel.FileDataStorageManager) FetchRemoteFileTask(com.owncloud.android.ui.asynctasks.FetchRemoteFileTask)

Example 52 with FileDataStorageManager

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

the class FolderPickerActivity method getCurrentFolder.

protected OCFile getCurrentFolder() {
    OCFile currentFile = getFile();
    OCFile finalFolder = null;
    FileDataStorageManager storageManager = getStorageManager();
    // If the file is null, take the root folder to avoid any error in functions depending on this one
    if (currentFile != null) {
        if (currentFile.isFolder()) {
            finalFolder = currentFile;
        } else if (currentFile.getRemotePath() != null) {
            String parentPath = new File(currentFile.getRemotePath()).getParent();
            finalFolder = storageManager.getFileByPath(parentPath);
        }
    } else {
        finalFolder = storageManager.getFileByPath(OCFile.ROOT_PATH);
    }
    return finalFolder;
}
Also used : OCFile(com.owncloud.android.datamodel.OCFile) FileDataStorageManager(com.owncloud.android.datamodel.FileDataStorageManager) OCFile(com.owncloud.android.datamodel.OCFile) File(java.io.File)

Example 53 with FileDataStorageManager

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

the class FileSyncAdapter method onPerformSync.

/**
 * {@inheritDoc}
 */
@Override
public synchronized void onPerformSync(Account account, Bundle extras, String authority, ContentProviderClient providerClient, SyncResult syncResult) {
    mCancellation = false;
    mFailedResultsCounter = 0;
    mLastFailedResult = null;
    mConflictsFound = 0;
    mFailsInFavouritesFound = 0;
    mForgottenLocalFiles = new HashMap<String, String>();
    mSyncResult = syncResult;
    mSyncResult.fullSyncRequested = false;
    // avoid too many automatic synchronizations
    mSyncResult.delayUntil = (System.currentTimeMillis() / 1000) + 3 * 60 * 60;
    this.setAccount(account);
    this.setContentProviderClient(providerClient);
    this.setStorageManager(new FileDataStorageManager(getUser(), providerClient));
    try {
        this.initClientForCurrentAccount();
    } catch (IOException | AccountsException e) {
        // / the account is unknown for the Synchronization Manager, unreachable this context,
        // or can not be authenticated; don't try this again
        mSyncResult.tooManyRetries = true;
        notifyFailedSynchronization();
        return;
    }
    Log_OC.d(TAG, "Synchronization of ownCloud account " + account.name + " starting");
    // message to signal the start
    sendLocalBroadcast(EVENT_FULL_SYNC_START, null, null);
    // of the synchronization to the UI
    /* When 'true' the process was requested by the user through the user interface;
           when 'false', it was requested automatically by the system */
    boolean mIsManualSync = extras.getBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, false);
    try {
        updateOCVersion();
        mCurrentSyncTime = System.currentTimeMillis();
        if (!mCancellation) {
            synchronizeFolder(getStorageManager().getFileByPath(OCFile.ROOT_PATH));
        } else {
            Log_OC.d(TAG, "Leaving synchronization before synchronizing the root folder " + "because cancellation request");
        }
    } finally {
        if (mFailedResultsCounter > 0 && mIsManualSync) {
            // / don't let the system synchronization manager retries MANUAL synchronizations
            // (be careful: "MANUAL" currently includes the synchronization requested when
            // a new account is created and when the user changes the current account)
            mSyncResult.tooManyRetries = true;
            // / notify the user about the failure of MANUAL synchronization
            notifyFailedSynchronization();
        }
        if (mConflictsFound > 0 || mFailsInFavouritesFound > 0) {
            notifyFailsInFavourites();
        }
        if (mForgottenLocalFiles.size() > 0) {
            notifyForgottenLocalFiles();
        }
        // message to signal
        sendLocalBroadcast(EVENT_FULL_SYNC_END, null, mLastFailedResult);
    // the end to the UI
    }
}
Also used : FileDataStorageManager(com.owncloud.android.datamodel.FileDataStorageManager) IOException(java.io.IOException) AccountsException(android.accounts.AccountsException)

Example 54 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 55 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)

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