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