use of com.owncloud.android.datamodel.FileDataStorageManager in project android by nextcloud.
the class OCFileListAdapter method setData.
public void setData(List<Object> objects, SearchType searchType, FileDataStorageManager storageManager, @Nullable OCFile folder, boolean clear) {
if (storageManager != null && mStorageManager == null) {
mStorageManager = storageManager;
ocFileListDelegate.setShowShareAvatar(mStorageManager.getCapability(user.getAccountName()).getVersion().isShareesOnDavSupported());
}
if (mStorageManager == null) {
mStorageManager = new FileDataStorageManager(user, activity.getContentResolver());
}
if (clear) {
mFiles.clear();
resetLastTimestamp();
preferences.setPhotoSearchTimestamp(0);
VirtualFolderType type;
switch(searchType) {
case FAVORITE_SEARCH:
type = VirtualFolderType.FAVORITE;
break;
case GALLERY_SEARCH:
type = VirtualFolderType.GALLERY;
break;
default:
type = VirtualFolderType.NONE;
break;
}
if (type != VirtualFolderType.GALLERY) {
mStorageManager.deleteVirtuals(type);
}
}
// early exit
if (objects.size() > 0 && mStorageManager != null) {
if (searchType == SearchType.SHARED_FILTER) {
parseShares(objects);
} else {
if (searchType != SearchType.GALLERY_SEARCH) {
parseVirtuals(objects, searchType);
}
}
}
if (searchType == SearchType.GALLERY_SEARCH || searchType == SearchType.RECENTLY_MODIFIED_SEARCH) {
mFiles = FileStorageUtils.sortOcFolderDescDateModifiedWithoutFavoritesFirst(mFiles);
} else if (searchType != SearchType.SHARED_FILTER) {
sortOrder = preferences.getSortOrderByFolder(folder);
mFiles = sortOrder.sortCloudFiles(mFiles);
}
mFilesAll.clear();
mFilesAll.addAll(mFiles);
new Handler(Looper.getMainLooper()).post(this::notifyDataSetChanged);
}
use of com.owncloud.android.datamodel.FileDataStorageManager in project android by nextcloud.
the class ConflictsResolveActivityIT method keepExisting.
@Test
@ScreenshotTest
public void keepExisting() {
returnCode = false;
OCUpload newUpload = new OCUpload(FileStorageUtils.getSavePath(user.getAccountName()) + "/nonEmpty.txt", "/newFile.txt", user.getAccountName());
OCFile existingFile = new OCFile("/newFile.txt");
existingFile.setFileLength(1024000);
existingFile.setModificationTimestamp(1582019340);
OCFile newFile = new OCFile("/newFile.txt");
newFile.setFileLength(56000);
newFile.setModificationTimestamp(1522019340);
newFile.setStoragePath(FileStorageUtils.getSavePath(user.getAccountName()) + "/nonEmpty.txt");
FileDataStorageManager storageManager = new FileDataStorageManager(user, targetContext.getContentResolver());
storageManager.saveNewFile(existingFile);
Intent intent = new Intent(targetContext, ConflictsResolveActivity.class);
intent.putExtra(ConflictsResolveActivity.EXTRA_FILE, newFile);
intent.putExtra(ConflictsResolveActivity.EXTRA_EXISTING_FILE, existingFile);
intent.putExtra(ConflictsResolveActivity.EXTRA_CONFLICT_UPLOAD_ID, newUpload.getUploadId());
ConflictsResolveActivity sut = activityRule.launchActivity(intent);
sut.listener = decision -> {
assertEquals(decision, ConflictsResolveDialog.Decision.KEEP_SERVER);
returnCode = true;
};
getInstrumentation().waitForIdleSync();
onView(withId(R.id.existing_checkbox)).perform(click());
DialogFragment dialog = (DialogFragment) sut.getSupportFragmentManager().findFragmentByTag("conflictDialog");
screenshot(Objects.requireNonNull(dialog.requireDialog().getWindow()).getDecorView());
onView(withText("OK")).perform(click());
assertTrue(returnCode);
}
use of com.owncloud.android.datamodel.FileDataStorageManager in project android by nextcloud.
the class ConflictsResolveActivityIT method keepNew.
@Test
@ScreenshotTest
public void keepNew() {
returnCode = false;
OCUpload newUpload = new OCUpload(FileStorageUtils.getSavePath(user.getAccountName()) + "/nonEmpty.txt", "/newFile.txt", user.getAccountName());
OCFile existingFile = new OCFile("/newFile.txt");
existingFile.setFileLength(1024000);
existingFile.setModificationTimestamp(1582019340);
existingFile.setRemoteId("123abc");
OCFile newFile = new OCFile("/newFile.txt");
newFile.setFileLength(56000);
newFile.setModificationTimestamp(1522019340);
newFile.setStoragePath(FileStorageUtils.getSavePath(user.getAccountName()) + "/nonEmpty.txt");
FileDataStorageManager storageManager = new FileDataStorageManager(user, targetContext.getContentResolver());
storageManager.saveNewFile(existingFile);
Intent intent = new Intent(targetContext, ConflictsResolveActivity.class);
intent.putExtra(ConflictsResolveActivity.EXTRA_FILE, newFile);
intent.putExtra(ConflictsResolveActivity.EXTRA_EXISTING_FILE, existingFile);
intent.putExtra(ConflictsResolveActivity.EXTRA_CONFLICT_UPLOAD_ID, newUpload.getUploadId());
ConflictsResolveActivity sut = activityRule.launchActivity(intent);
sut.listener = decision -> {
assertEquals(decision, ConflictsResolveDialog.Decision.KEEP_LOCAL);
returnCode = true;
};
getInstrumentation().waitForIdleSync();
onView(withId(R.id.new_checkbox)).perform(click());
DialogFragment dialog = (DialogFragment) sut.getSupportFragmentManager().findFragmentByTag("conflictDialog");
screenshot(Objects.requireNonNull(dialog.requireDialog().getWindow()).getDecorView());
onView(withText("OK")).perform(click());
assertTrue(returnCode);
}
use of com.owncloud.android.datamodel.FileDataStorageManager in project android by nextcloud.
the class DialogFragmentIT method testAccountChooserDialog.
@Test
@ScreenshotTest
public void testAccountChooserDialog() throws AccountUtils.AccountNotFoundException {
FileDisplayActivity activity = getFileDisplayActivity();
UserAccountManager userAccountManager = activity.getUserAccountManager();
AccountManager accountManager = AccountManager.get(targetContext);
for (Account account : accountManager.getAccountsByType(MainApp.getAccountType(targetContext))) {
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");
User newUser = userAccountManager.getUser(newAccount.name).orElseThrow(RuntimeException::new);
Account newAccount2 = new Account("user1@nextcloud.localhost", MainApp.getAccountType(targetContext));
accountManager.addAccountExplicitly(newAccount2, "password", null);
accountManager.setUserData(newAccount2, AccountUtils.Constants.KEY_OC_BASE_URL, SERVER_URL);
accountManager.setUserData(newAccount2, AccountUtils.Constants.KEY_USER_ID, "user1");
accountManager.setUserData(newAccount2, AccountUtils.Constants.KEY_OC_VERSION, "20.0.0");
accountManager.setAuthToken(newAccount2, AccountTypeUtils.getAuthTokenTypePass(newAccount.type), "password");
FileDataStorageManager fileDataStorageManager = new FileDataStorageManager(newUser, targetContext.getContentResolver());
OCCapability capability = new OCCapability();
capability.setUserStatus(CapabilityBooleanType.TRUE);
capability.setUserStatusSupportsEmoji(CapabilityBooleanType.TRUE);
fileDataStorageManager.saveCapabilities(capability);
ChooseAccountDialogFragment sut = ChooseAccountDialogFragment.newInstance(new RegisteredUser(newAccount, new OwnCloudAccount(newAccount, targetContext), new Server(URI.create(SERVER_URL), OwnCloudVersion.nextcloud_20)));
showDialog(activity, sut);
activity.runOnUiThread(() -> sut.setStatus(new Status(StatusType.DND, "Busy fixing 🐛…", "", -1), targetContext));
waitForIdleSync();
shortSleep();
screenshot(sut, "dnd");
activity.runOnUiThread(() -> sut.setStatus(new Status(StatusType.ONLINE, "", "", -1), targetContext));
waitForIdleSync();
shortSleep();
screenshot(sut, "online");
activity.runOnUiThread(() -> sut.setStatus(new Status(StatusType.ONLINE, "Let's have some fun", "🎉", -1), targetContext));
waitForIdleSync();
shortSleep();
screenshot(sut, "fun");
activity.runOnUiThread(() -> sut.setStatus(new Status(StatusType.OFFLINE, "", "", -1), targetContext));
waitForIdleSync();
shortSleep();
screenshot(sut, "offline");
activity.runOnUiThread(() -> sut.setStatus(new Status(StatusType.AWAY, "Vacation", "🌴", -1), targetContext));
waitForIdleSync();
shortSleep();
screenshot(sut, "away");
}
use of com.owncloud.android.datamodel.FileDataStorageManager in project android by nextcloud.
the class CapabilityUtils method getCapability.
public static OCCapability getCapability(User user, Context context) {
OCCapability capability = cachedCapabilities.get(user.getAccountName());
if (capability == null) {
FileDataStorageManager storageManager = new FileDataStorageManager(user, context.getContentResolver());
capability = storageManager.getCapability(user.getAccountName());
cachedCapabilities.put(capability.getAccountName(), capability);
}
return capability;
}
Aggregations