use of com.nextcloud.client.account.User in project android by nextcloud.
the class FileOperationsHelper method cancelTransference.
/**
* Cancel the transference in downloads (files/folders) and file uploads
*
* @param file OCFile
*/
public void cancelTransference(OCFile file) {
User currentUser = fileActivity.getUser().orElseThrow(IllegalStateException::new);
if (file.isFolder()) {
OperationsService.OperationsServiceBinder opsBinder = fileActivity.getOperationsServiceBinder();
if (opsBinder != null) {
opsBinder.cancel(currentUser.toPlatformAccount(), file);
}
}
// for both files and folders
FileDownloaderBinder downloaderBinder = fileActivity.getFileDownloaderBinder();
if (downloaderBinder != null && downloaderBinder.isDownloading(currentUser, file)) {
downloaderBinder.cancel(currentUser.toPlatformAccount(), file);
}
FileUploaderBinder uploaderBinder = fileActivity.getFileUploaderBinder();
if (uploaderBinder != null && uploaderBinder.isUploading(currentUser, file)) {
uploaderBinder.cancel(currentUser.toPlatformAccount(), file);
}
}
use of com.nextcloud.client.account.User in project android by nextcloud.
the class FileOperationsHelper method openFile.
public void openFile(OCFile file) {
if (file != null) {
final Intent openFileWithIntent = createOpenFileIntent(file);
List<ResolveInfo> launchables = fileActivity.getPackageManager().queryIntentActivities(openFileWithIntent, PackageManager.GET_RESOLVED_FILTER);
if (launchables.isEmpty()) {
Optional<User> optionalUser = fileActivity.getUser();
if (optionalUser.isPresent() && FileMenuFilter.isEditorAvailable(fileActivity.getContentResolver(), optionalUser.get(), file.getMimeType())) {
openFileWithTextEditor(file, fileActivity);
} else {
Account account = fileActivity.getAccount();
OCCapability capability = fileActivity.getStorageManager().getCapability(account.name);
if (capability.getRichDocumentsMimeTypeList().contains(file.getMimeType()) && capability.getRichDocumentsDirectEditing().isTrue()) {
openFileAsRichDocument(file, fileActivity);
return;
} else {
DisplayUtils.showSnackMessage(fileActivity, R.string.file_list_no_app_for_file_type);
return;
}
}
}
fileActivity.showLoadingDialog(fileActivity.getResources().getString(R.string.sync_in_progress));
new Thread(new Runnable() {
@Override
public void run() {
User user = currentAccount.getUser();
FileDataStorageManager storageManager = new FileDataStorageManager(user, fileActivity.getContentResolver());
// a fresh object is needed; many things could have occurred to the file
// since it was registered to observe again, assuming that local files
// are linked to a remote file AT MOST, SOMETHING TO BE DONE;
SynchronizeFileOperation sfo = new SynchronizeFileOperation(file, null, user, true, fileActivity, storageManager);
RemoteOperationResult result = sfo.execute(fileActivity);
fileActivity.dismissLoadingDialog();
if (result.getCode() == RemoteOperationResult.ResultCode.SYNC_CONFLICT) {
// ISSUE 5: if the user is not running the app (this is a service!),
// this can be very intrusive; a notification should be preferred
Intent intent = ConflictsResolveActivity.createIntent(file, user, -1, Intent.FLAG_ACTIVITY_NEW_TASK, fileActivity);
fileActivity.startActivity(intent);
} else {
if (!launchables.isEmpty()) {
try {
if (!result.isSuccess()) {
DisplayUtils.showSnackMessage(fileActivity, R.string.file_not_synced);
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
Log.e(TAG, "Failed to sleep");
}
}
openFileWithIntent.setFlags(openFileWithIntent.getFlags() | Intent.FLAG_ACTIVITY_NEW_TASK);
fileActivity.startActivity(openFileWithIntent);
} catch (ActivityNotFoundException exception) {
DisplayUtils.showSnackMessage(fileActivity, R.string.file_list_no_app_for_file_type);
}
} else {
DisplayUtils.showSnackMessage(fileActivity, R.string.file_list_no_app_for_file_type);
}
}
}
}).start();
} else {
Log_OC.e(TAG, "Trying to open a NULL OCFile");
}
}
use of com.nextcloud.client.account.User in project android by nextcloud.
the class PreviewTextFileFragment method onPrepareOptionsMenu.
/**
* {@inheritDoc}
*/
@Override
public void onPrepareOptionsMenu(@NonNull Menu menu) {
super.onPrepareOptionsMenu(menu);
if (containerActivity.getStorageManager() != null) {
User user = accountManager.getUser();
FileMenuFilter mf = new FileMenuFilter(getFile(), containerActivity, getActivity(), false, user);
mf.filter(menu, true);
}
// additional restriction for this fragment
FileMenuFilter.hideMenuItems(menu.findItem(R.id.action_rename_file), menu.findItem(R.id.action_select_all), menu.findItem(R.id.action_move), menu.findItem(R.id.action_download_file), menu.findItem(R.id.action_sync_file), menu.findItem(R.id.action_favorite), menu.findItem(R.id.action_unset_favorite));
if (getFile().isSharedWithMe() && !getFile().canReshare()) {
FileMenuFilter.hideMenuItem(menu.findItem(R.id.action_send_share_file));
}
}
use of com.nextcloud.client.account.User in project android by nextcloud.
the class TrashbinActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final User currentUser = getUser().orElse(accountProvider.getUser());
final String targetAccount = getIntent().getStringExtra(Intent.EXTRA_USER);
if (targetAccount != null && !currentUser.nameEquals(targetAccount)) {
final Optional<User> targetUser = getUserAccountManager().getUser(targetAccount);
if (targetUser.isPresent()) {
setUser(targetUser.get());
} else {
Toast.makeText(this, R.string.associated_account_not_found, Toast.LENGTH_LONG).show();
finish();
return;
}
}
final RemoteTrashbinRepository trashRepository = new RemoteTrashbinRepository(getUser().orElse(accountProvider.getUser()), clientFactory);
trashbinPresenter = new TrashbinPresenter(trashRepository, this);
binding = TrashbinActivityBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
setupToolbar();
findViewById(R.id.sort_list_button_group).setVisibility(View.VISIBLE);
findViewById(R.id.switch_grid_view_button).setVisibility(View.GONE);
updateActionBarTitleAndHomeButtonByString(getString(R.string.trashbin_activity_title));
setupDrawer(R.id.nav_trashbin);
}
use of com.nextcloud.client.account.User in project android by nextcloud.
the class FileOperationsHelper method streamMediaFile.
public void streamMediaFile(OCFile file) {
fileActivity.showLoadingDialog(fileActivity.getString(R.string.wait_a_moment));
final User user = currentAccount.getUser();
new Thread(() -> {
StreamMediaFileOperation sfo = new StreamMediaFileOperation(file.getLocalId());
RemoteOperationResult result = sfo.execute(user.toPlatformAccount(), fileActivity);
fileActivity.dismissLoadingDialog();
if (!result.isSuccess()) {
DisplayUtils.showSnackMessage(fileActivity, R.string.stream_not_possible_headline);
return;
}
Intent openFileWithIntent = new Intent(Intent.ACTION_VIEW);
Uri uri = Uri.parse((String) result.getData().get(0));
openFileWithIntent.setDataAndType(uri, file.getMimeType());
fileActivity.startActivity(Intent.createChooser(openFileWithIntent, fileActivity.getString(R.string.stream)));
}).start();
}
Aggregations