Search in sources :

Example 31 with FileDataStorageManager

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

the class DialogFragmentIT method testAccountChooserDialogWithStatusDisabled.

@Test
@ScreenshotTest
public void testAccountChooserDialogWithStatusDisabled() throws AccountUtils.AccountNotFoundException {
    AccountManager accountManager = AccountManager.get(targetContext);
    for (Account account : accountManager.getAccounts()) {
        accountManager.removeAccountExplicitly(account);
    }
    Account newAccount = new Account("test@https://nextcloud.localhost", MainApp.getAccountType(targetContext));
    accountManager.addAccountExplicitly(newAccount, "password", null);
    accountManager.setUserData(newAccount, AccountUtils.Constants.KEY_OC_BASE_URL, SERVER_URL);
    accountManager.setUserData(newAccount, AccountUtils.Constants.KEY_USER_ID, "test");
    accountManager.setAuthToken(newAccount, AccountTypeUtils.getAuthTokenTypePass(newAccount.type), "password");
    FileDisplayActivity fda = getFileDisplayActivity();
    UserAccountManager userAccountManager = fda.getUserAccountManager();
    User newUser = userAccountManager.getUser(newAccount.name).get();
    FileDataStorageManager fileDataStorageManager = new FileDataStorageManager(newUser, targetContext.getContentResolver());
    OCCapability capability = new OCCapability();
    capability.setUserStatus(CapabilityBooleanType.FALSE);
    fileDataStorageManager.saveCapabilities(capability);
    ChooseAccountDialogFragment sut = ChooseAccountDialogFragment.newInstance(new RegisteredUser(newAccount, new OwnCloudAccount(newAccount, targetContext), new Server(URI.create(SERVER_URL), OwnCloudVersion.nextcloud_20)));
    showDialog(fda, sut);
}
Also used : UserAccountManager(com.nextcloud.client.account.UserAccountManager) Account(android.accounts.Account) OwnCloudAccount(com.owncloud.android.lib.common.OwnCloudAccount) FileDisplayActivity(com.owncloud.android.ui.activity.FileDisplayActivity) User(com.nextcloud.client.account.User) RegisteredUser(com.nextcloud.client.account.RegisteredUser) OCCapability(com.owncloud.android.lib.resources.status.OCCapability) Server(com.nextcloud.client.account.Server) FileDataStorageManager(com.owncloud.android.datamodel.FileDataStorageManager) ChooseAccountDialogFragment(com.nextcloud.ui.ChooseAccountDialogFragment) UserAccountManager(com.nextcloud.client.account.UserAccountManager) AccountManager(android.accounts.AccountManager) OwnCloudAccount(com.owncloud.android.lib.common.OwnCloudAccount) RegisteredUser(com.nextcloud.client.account.RegisteredUser) ScreenshotTest(com.owncloud.android.utils.ScreenshotTest) Test(org.junit.Test) ScreenshotTest(com.owncloud.android.utils.ScreenshotTest)

Example 32 with FileDataStorageManager

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

the class AppPreferencesImpl method getFolderPreference.

/**
 * Get preference value for a folder.
 * If folder is not set itself, it finds an ancestor that is set.
 *
 * @param context Context object.
 * @param preferenceName Name of the preference to lookup.
 * @param folder Folder.
 * @param defaultValue Fallback value in case no ancestor is set.
 * @return Preference value
 */
private static String getFolderPreference(final Context context, final User user, final String preferenceName, final OCFile folder, final String defaultValue) {
    if (user.isAnonymous()) {
        return defaultValue;
    }
    ArbitraryDataProvider dataProvider = new ArbitraryDataProvider(context.getContentResolver());
    FileDataStorageManager storageManager = new FileDataStorageManager(user, context.getContentResolver());
    String value = dataProvider.getValue(user.getAccountName(), getKeyFromFolder(preferenceName, folder));
    OCFile prefFolder = folder;
    while (prefFolder != null && value.isEmpty()) {
        prefFolder = storageManager.getFileById(prefFolder.getParentId());
        value = dataProvider.getValue(user.getAccountName(), getKeyFromFolder(preferenceName, prefFolder));
    }
    return value.isEmpty() ? defaultValue : value;
}
Also used : OCFile(com.owncloud.android.datamodel.OCFile) FileDataStorageManager(com.owncloud.android.datamodel.FileDataStorageManager) ArbitraryDataProvider(com.owncloud.android.datamodel.ArbitraryDataProvider)

Example 33 with FileDataStorageManager

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

the class DiskLruImageCacheFileProvider method getFile.

private OCFile getFile(Uri uri) {
    User user = accountManager.getUser();
    FileDataStorageManager fileDataStorageManager = new FileDataStorageManager(user, MainApp.getAppContext().getContentResolver());
    return fileDataStorageManager.getFileByPath(uri.getPath());
}
Also used : User(com.nextcloud.client.account.User) FileDataStorageManager(com.owncloud.android.datamodel.FileDataStorageManager)

Example 34 with FileDataStorageManager

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

the class DocumentsStorageProvider method queryRoots.

@Override
public Cursor queryRoots(String[] projection) {
    // always recreate storage manager collection, as it will change after account creation/removal
    // and we need to serve document(tree)s with persist permissions
    initiateStorageMap();
    Context context = MainApp.getAppContext();
    AppPreferences preferences = AppPreferencesImpl.fromContext(context);
    if (SettingsActivity.LOCK_PASSCODE.equals(preferences.getLockPreference()) || SettingsActivity.LOCK_DEVICE_CREDENTIALS.equals(preferences.getLockPreference())) {
        return new FileCursor();
    }
    final RootCursor result = new RootCursor(projection);
    for (FileDataStorageManager manager : rootIdToStorageManager.values()) {
        result.addRoot(new Document(manager, ROOT_PATH), getContext());
    }
    return result;
}
Also used : Context(android.content.Context) FileCursor(org.nextcloud.providers.cursors.FileCursor) AppPreferences(com.nextcloud.client.preferences.AppPreferences) FileDataStorageManager(com.owncloud.android.datamodel.FileDataStorageManager) RootCursor(org.nextcloud.providers.cursors.RootCursor)

Example 35 with FileDataStorageManager

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

the class DocumentsStorageProvider method createFolder.

private String createFolder(Document targetFolder, String displayName) throws FileNotFoundException {
    Context context = getNonNullContext();
    String newDirPath = targetFolder.getRemotePath() + displayName + PATH_SEPARATOR;
    FileDataStorageManager storageManager = targetFolder.getStorageManager();
    RemoteOperationResult result = new CreateFolderOperation(newDirPath, accountManager.getUser(), context, storageManager).execute(targetFolder.getClient());
    if (!result.isSuccess()) {
        Log_OC.e(TAG, result.toString());
        throw new FileNotFoundException("Failed to create document with name " + displayName + " and documentId " + targetFolder.getDocumentId());
    }
    RemoteOperationResult updateParent = new RefreshFolderOperation(targetFolder.getFile(), System.currentTimeMillis(), false, false, true, storageManager, targetFolder.getUser(), context).execute(targetFolder.getClient());
    if (!updateParent.isSuccess()) {
        Log_OC.e(TAG, updateParent.toString());
        throw new FileNotFoundException("Failed to create document with documentId " + targetFolder.getDocumentId());
    }
    Document newFolder = new Document(storageManager, newDirPath);
    context.getContentResolver().notifyChange(toNotifyUri(targetFolder), null, false);
    return newFolder.getDocumentId();
}
Also used : Context(android.content.Context) CreateFolderOperation(com.owncloud.android.operations.CreateFolderOperation) RemoteOperationResult(com.owncloud.android.lib.common.operations.RemoteOperationResult) RefreshFolderOperation(com.owncloud.android.operations.RefreshFolderOperation) FileDataStorageManager(com.owncloud.android.datamodel.FileDataStorageManager) FileNotFoundException(java.io.FileNotFoundException)

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