use of com.owncloud.android.datamodel.FileDataStorageManager in project android by nextcloud.
the class ErrorMessageAdapterIT method getErrorCauseMessageForForbiddenRemoval.
@Test
public void getErrorCauseMessageForForbiddenRemoval() {
Resources resources = InstrumentationRegistry.getInstrumentation().getTargetContext().getResources();
User user = new MockUser("name", ACCOUNT_TYPE);
Context context = MainApp.getAppContext();
String errorMessage = ErrorMessageAdapter.getErrorCauseMessage(new RemoteOperationResult(RemoteOperationResult.ResultCode.FORBIDDEN), new RemoveFileOperation(new OCFile(PATH_TO_DELETE), false, user.toPlatformAccount(), false, context, new FileDataStorageManager(user, context.getContentResolver())), resources);
assertEquals(EXPECTED_ERROR_MESSAGE, errorMessage);
}
use of com.owncloud.android.datamodel.FileDataStorageManager in project android by nextcloud.
the class FileDetailActivitiesFragment method setupView.
private void setupView() {
FileDataStorageManager storageManager = new FileDataStorageManager(user, contentResolver);
operationsHelper = ((ComponentsGetter) requireActivity()).getFileOperationsHelper();
OCCapability capability = storageManager.getCapability(user.getAccountName());
restoreFileVersionSupported = capability.getFilesVersioning().isTrue();
binding.emptyList.emptyListIcon.setImageDrawable(ResourcesCompat.getDrawable(getResources(), R.drawable.ic_activity, null));
binding.emptyList.emptyListView.setVisibility(View.GONE);
adapter = new ActivityAndVersionListAdapter(getContext(), accountManager, this, this, clientFactory, themeColorUtils, themeDrawableUtils);
binding.list.setAdapter(adapter);
LinearLayoutManager layoutManager = new LinearLayoutManager(getContext());
binding.list.setLayoutManager(layoutManager);
binding.list.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
int visibleItemCount = recyclerView.getChildCount();
int totalItemCount = layoutManager.getItemCount();
int firstVisibleItemIndex = layoutManager.findFirstVisibleItemPosition();
// synchronize loading state when item count changes
if (!isLoadingActivities && (totalItemCount - visibleItemCount) <= (firstVisibleItemIndex + 5) && lastGiven > 0) {
// Almost reached the end, continue to load new activities
fetchAndSetData(lastGiven);
}
}
});
}
use of com.owncloud.android.datamodel.FileDataStorageManager in project android by nextcloud.
the class OCFileListFragment method onBrowseUp.
/**
* Call this, when the user presses the up button.
*
* Tries to move up the current folder one level. If the parent folder was removed from the
* database, it continues browsing up until finding an existing folders.
*
* return Count of folder levels browsed up.
*/
public int onBrowseUp() {
OCFile parentDir;
int moveCount = 0;
if (mFile != null) {
FileDataStorageManager storageManager = mContainerActivity.getStorageManager();
String parentPath = null;
if (mFile.getParentId() != FileDataStorageManager.ROOT_PARENT_ID) {
parentPath = new File(mFile.getRemotePath()).getParent();
parentPath = parentPath.endsWith(OCFile.PATH_SEPARATOR) ? parentPath : parentPath + OCFile.PATH_SEPARATOR;
parentDir = storageManager.getFileByPath(parentPath);
moveCount++;
} else {
parentDir = storageManager.getFileByPath(ROOT_PATH);
}
while (parentDir == null) {
parentPath = new File(parentPath).getParent();
parentPath = parentPath.endsWith(OCFile.PATH_SEPARATOR) ? parentPath : parentPath + OCFile.PATH_SEPARATOR;
parentDir = storageManager.getFileByPath(parentPath);
moveCount++;
}
// exit is granted because storageManager.getFileByPath("/") never returns null
mFile = parentDir;
listDirectory(mFile, MainApp.isOnlyOnDevice(), false);
onRefresh(false);
// restore index and top position
restoreIndexAndTopPosition();
}
return moveCount;
}
use of com.owncloud.android.datamodel.FileDataStorageManager in project android by nextcloud.
the class OCFileListFragment method onMessageEvent.
@Subscribe(threadMode = ThreadMode.BACKGROUND)
public void onMessageEvent(EncryptionEvent event) {
final User user = accountManager.getUser();
try {
OwnCloudClient client = clientFactory.create(user);
RemoteOperationResult remoteOperationResult = new ToggleEncryptionRemoteOperation(event.localId, event.remotePath, event.shouldBeEncrypted).execute(client);
if (remoteOperationResult.isSuccess()) {
mAdapter.setEncryptionAttributeForItemID(event.remoteId, event.shouldBeEncrypted);
// check if keys are stored
ArbitraryDataProvider arbitraryDataProvider = new ArbitraryDataProvider(requireContext().getContentResolver());
String publicKey = arbitraryDataProvider.getValue(user, EncryptionUtils.PUBLIC_KEY);
String privateKey = arbitraryDataProvider.getValue(user, EncryptionUtils.PRIVATE_KEY);
if (publicKey.isEmpty() || privateKey.isEmpty()) {
Log_OC.d(TAG, "no public key for " + user.getAccountName());
FileDataStorageManager storageManager = mContainerActivity.getStorageManager();
OCFile file = storageManager.getFileByRemoteId(event.remoteId);
int position = -1;
if (file != null) {
position = mAdapter.getItemPosition(file);
}
SetupEncryptionDialogFragment dialog = SetupEncryptionDialogFragment.newInstance(user, position);
dialog.setTargetFragment(this, SetupEncryptionDialogFragment.SETUP_ENCRYPTION_REQUEST_CODE);
dialog.show(getParentFragmentManager(), SetupEncryptionDialogFragment.SETUP_ENCRYPTION_DIALOG_TAG);
}
} else if (remoteOperationResult.getHttpCode() == HttpStatus.SC_FORBIDDEN) {
Snackbar.make(getRecyclerView(), R.string.end_to_end_encryption_folder_not_empty, Snackbar.LENGTH_LONG).show();
} else {
Snackbar.make(getRecyclerView(), R.string.common_error_unknown, Snackbar.LENGTH_LONG).show();
}
} catch (ClientFactory.CreationException e) {
Log_OC.e(TAG, "Cannot create client", e);
}
}
use of com.owncloud.android.datamodel.FileDataStorageManager in project android by nextcloud.
the class BackupFragment method onDateSet.
@Override
public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) {
final ContactsPreferenceActivity contactsPreferenceActivity = (ContactsPreferenceActivity) getActivity();
if (contactsPreferenceActivity == null) {
Toast.makeText(getContext(), getString(R.string.error_choosing_date), Toast.LENGTH_LONG).show();
return;
}
selectedDate = new Date(year, month, dayOfMonth);
String contactsBackupFolderString = getResources().getString(R.string.contacts_backup_folder) + OCFile.PATH_SEPARATOR;
String calendarBackupFolderString = getResources().getString(R.string.calendar_backup_folder) + OCFile.PATH_SEPARATOR;
FileDataStorageManager storageManager = contactsPreferenceActivity.getStorageManager();
OCFile contactsBackupFolder = storageManager.getFileByDecryptedRemotePath(contactsBackupFolderString);
OCFile calendarBackupFolder = storageManager.getFileByDecryptedRemotePath(calendarBackupFolderString);
List<OCFile> backupFiles = storageManager.getFolderContent(contactsBackupFolder, false);
backupFiles.addAll(storageManager.getFolderContent(calendarBackupFolder, false));
// find file with modification with date and time between 00:00 and 23:59
// if more than one file exists, take oldest
Calendar date = Calendar.getInstance();
date.set(year, month, dayOfMonth);
// start
date.set(Calendar.HOUR, 0);
date.set(Calendar.MINUTE, 0);
date.set(Calendar.SECOND, 1);
date.set(Calendar.MILLISECOND, 0);
date.set(Calendar.AM_PM, Calendar.AM);
long start = date.getTimeInMillis();
// end
date.set(Calendar.HOUR, 23);
date.set(Calendar.MINUTE, 59);
date.set(Calendar.SECOND, 59);
long end = date.getTimeInMillis();
OCFile contactsBackupToRestore = null;
List<OCFile> calendarBackupsToRestore = new ArrayList<>();
for (OCFile file : backupFiles) {
if (start < file.getModificationTimestamp() && end > file.getModificationTimestamp()) {
// contact
if (MimeTypeUtil.isVCard(file)) {
if (contactsBackupToRestore == null) {
contactsBackupToRestore = file;
} else if (contactsBackupToRestore.getModificationTimestamp() < file.getModificationTimestamp()) {
contactsBackupToRestore = file;
}
}
// calendars
if (MimeTypeUtil.isCalendar(file)) {
calendarBackupsToRestore.add(file);
}
}
}
List<OCFile> backupToRestore = new ArrayList<>();
if (contactsBackupToRestore != null) {
backupToRestore.add(contactsBackupToRestore);
}
backupToRestore.addAll(calendarBackupsToRestore);
if (backupToRestore.isEmpty()) {
DisplayUtils.showSnackMessage(getView().findViewById(R.id.contacts_linear_layout), R.string.contacts_preferences_no_file_found);
} else {
final User user = contactsPreferenceActivity.getUser().orElseThrow(RuntimeException::new);
OCFile[] files = new OCFile[backupToRestore.size()];
Fragment contactListFragment = BackupListFragment.newInstance(backupToRestore.toArray(files), user);
contactsPreferenceActivity.getSupportFragmentManager().beginTransaction().replace(R.id.frame_container, contactListFragment, BackupListFragment.TAG).addToBackStack(ContactsPreferenceActivity.BACKUP_TO_LIST).commit();
}
}
Aggregations