use of com.nextcloud.client.account.User in project android by nextcloud.
the class FileDisplayActivity method selectUserAndOpenFile.
private void selectUserAndOpenFile(List<User> users, String fileId) {
final CharSequence[] userNames = new CharSequence[users.size()];
for (int i = 0; i < userNames.length; i++) {
userNames[i] = users.get(i).getAccountName();
}
final AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(R.string.common_choose_account).setItems(userNames, (dialog, which) -> {
User user = users.get(which);
openFile(user, fileId);
showLoadingDialog(getString(R.string.retrieving_file));
});
final AlertDialog dialog = builder.create();
dismissLoadingDialog();
dialog.show();
}
use of com.nextcloud.client.account.User in project android by nextcloud.
the class FileDisplayActivity method requestForDownload.
private void requestForDownload() {
User user = getUser().orElseThrow(RuntimeException::new);
// if (!mWaitingToPreview.isDownloading()) {
if (!mDownloaderBinder.isDownloading(user, mWaitingToPreview)) {
Intent i = new Intent(this, FileDownloader.class);
i.putExtra(FileDownloader.EXTRA_USER, user);
i.putExtra(FileDownloader.EXTRA_FILE, mWaitingToPreview);
startService(i);
}
}
use of com.nextcloud.client.account.User in project android by nextcloud.
the class FileDisplayActivity method showDetails.
/**
* Shows the information of the {@link OCFile} received as a parameter in the second fragment.
*
* @param file {@link OCFile} whose details will be shown
* @param activeTab the active tab in the details view
*/
public void showDetails(OCFile file, int activeTab) {
User currentUser = getUser().orElseThrow(RuntimeException::new);
resetHeaderScrollingState();
Fragment detailFragment = FileDetailFragment.newInstance(file, currentUser, activeTab);
setLeftFragment(detailFragment);
updateActionBarTitleAndHomeButton(file);
mDrawerToggle.setDrawerIndicatorEnabled(false);
}
use of com.nextcloud.client.account.User in project android by nextcloud.
the class FileDisplayActivity method onRenameFileOperationFinish.
/**
* Updates the view associated to the activity after the finish of an operation trying to rename a file.
*
* @param operation Renaming operation performed.
* @param result Result of the renaming.
*/
private void onRenameFileOperationFinish(RenameFileOperation operation, RemoteOperationResult result) {
Optional<User> optionalUser = getUser();
OCFile renamedFile = operation.getFile();
if (result.isSuccess() && optionalUser.isPresent()) {
final User currentUser = optionalUser.get();
Fragment leftFragment = getLeftFragment();
if (leftFragment instanceof FileFragment) {
final FileFragment fileFragment = (FileFragment) leftFragment;
if (fileFragment instanceof FileDetailFragment && renamedFile.equals(fileFragment.getFile())) {
((FileDetailFragment) fileFragment).updateFileDetails(renamedFile, currentUser);
showDetails(renamedFile);
} else if (fileFragment instanceof PreviewMediaFragment && renamedFile.equals(fileFragment.getFile())) {
((PreviewMediaFragment) fileFragment).updateFile(renamedFile);
if (PreviewMediaFragment.canBePreviewed(renamedFile)) {
long position = ((PreviewMediaFragment) fileFragment).getPosition();
startMediaPreview(renamedFile, position, true, true, true);
} else {
getFileOperationsHelper().openFile(renamedFile);
}
} else if (fileFragment instanceof PreviewTextFragment && renamedFile.equals(fileFragment.getFile())) {
((PreviewTextFileFragment) fileFragment).updateFile(renamedFile);
if (PreviewTextFileFragment.canBePreviewed(renamedFile)) {
startTextPreview(renamedFile, true);
} else {
getFileOperationsHelper().openFile(renamedFile);
}
}
}
OCFile file = getStorageManager().getFileById(renamedFile.getParentId());
if (file != null && file.equals(getCurrentDir())) {
updateListOfFilesFragment(false);
}
} else {
DisplayUtils.showSnackMessage(this, ErrorMessageAdapter.getErrorCauseMessage(result, operation, getResources()));
if (result.isSslRecoverableException()) {
mLastSslUntrustedServerResult = result;
showUntrustedCertDialog(mLastSslUntrustedServerResult);
}
}
}
use of com.nextcloud.client.account.User in project android by nextcloud.
the class DocumentsStorageProvider method openDocument.
@SuppressLint("LongLogTag")
@Override
public ParcelFileDescriptor openDocument(String documentId, String mode, CancellationSignal cancellationSignal) throws FileNotFoundException {
Log.d(TAG, "openDocument(), id=" + documentId);
Document document = toDocument(documentId);
Context context = getNonNullContext();
OCFile ocFile = document.getFile();
User user = document.getUser();
int accessMode = ParcelFileDescriptor.parseMode(mode);
boolean writeOnly = (accessMode & MODE_WRITE_ONLY) != 0;
boolean wasNotYetStored = ocFile.getStoragePath() == null;
boolean needsDownload = (!writeOnly || wasNotYetStored) && (!ocFile.isDown() || hasServerChange(document));
if (needsDownload) {
if (ocFile.getLocalModificationTimestamp() > ocFile.getLastSyncDateForData()) {
// TODO show a conflict notification with a pending intent that shows a ConflictResolveDialog
Log_OC.w(TAG, "Conflict found!");
} else {
DownloadFileOperation downloadFileOperation = new DownloadFileOperation(user, ocFile, context);
RemoteOperationResult result = downloadFileOperation.execute(document.getClient());
if (!result.isSuccess()) {
if (ocFile.isDown()) {
Handler handler = new Handler(Looper.getMainLooper());
handler.post(() -> Toast.makeText(MainApp.getAppContext(), R.string.file_not_synced, Toast.LENGTH_SHORT).show());
} else {
Log_OC.e(TAG, result.toString());
throw new FileNotFoundException("Error downloading file: " + ocFile.getFileName());
}
} else {
saveDownloadedFile(document.getStorageManager(), downloadFileOperation, ocFile);
}
}
}
File file = new File(ocFile.getStoragePath());
if (accessMode != MODE_READ_ONLY) {
// The calling thread is not guaranteed to have a Looper, so we can't block it with the OnCloseListener.
// Thus, we are unable to do a synchronous upload and have to start an asynchronous one.
Handler handler = new Handler(context.getMainLooper());
try {
return ParcelFileDescriptor.open(file, accessMode, handler, error -> {
if (error == null) {
// no error
// As we can't upload the file synchronously, let's at least update its metadata here already.
ocFile.setFileLength(file.length());
ocFile.setModificationTimestamp(System.currentTimeMillis());
document.getStorageManager().saveFile(ocFile);
// TODO disable upload notifications as DocumentsProvider users already show them
// upload file with FileUploader service (off main thread)
FileUploader.uploadUpdateFile(context, user.toPlatformAccount(), ocFile, LOCAL_BEHAVIOUR_DELETE, NameCollisionPolicy.OVERWRITE, false);
} else {
// error, no upload needed
Log_OC.e(TAG, "File was closed with an error: " + ocFile.getFileName(), error);
}
});
} catch (IOException e) {
throw new FileNotFoundException("Failed to open document for writing " + ocFile.getFileName());
}
} else {
return ParcelFileDescriptor.open(file, accessMode);
}
}
Aggregations