Search in sources :

Example 71 with User

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);
    }
}
Also used : User(com.nextcloud.client.account.User) FileDownloaderBinder(com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder) FileUploaderBinder(com.owncloud.android.files.services.FileUploader.FileUploaderBinder) OperationsService(com.owncloud.android.services.OperationsService)

Example 72 with User

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");
    }
}
Also used : Account(android.accounts.Account) User(com.nextcloud.client.account.User) OCCapability(com.owncloud.android.lib.resources.status.OCCapability) RemoteOperationResult(com.owncloud.android.lib.common.operations.RemoteOperationResult) Intent(android.content.Intent) ResolveInfo(android.content.pm.ResolveInfo) ActivityNotFoundException(android.content.ActivityNotFoundException) FileDataStorageManager(com.owncloud.android.datamodel.FileDataStorageManager) SynchronizeFileOperation(com.owncloud.android.operations.SynchronizeFileOperation)

Example 73 with User

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));
    }
}
Also used : User(com.nextcloud.client.account.User) FileMenuFilter(com.owncloud.android.files.FileMenuFilter)

Example 74 with User

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);
}
Also used : User(com.nextcloud.client.account.User)

Example 75 with User

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();
}
Also used : User(com.nextcloud.client.account.User) RemoteOperationResult(com.owncloud.android.lib.common.operations.RemoteOperationResult) Intent(android.content.Intent) Uri(android.net.Uri) StreamMediaFileOperation(com.owncloud.android.files.StreamMediaFileOperation)

Aggregations

User (com.nextcloud.client.account.User)84 OCFile (com.owncloud.android.datamodel.OCFile)21 FileDataStorageManager (com.owncloud.android.datamodel.FileDataStorageManager)19 RemoteOperationResult (com.owncloud.android.lib.common.operations.RemoteOperationResult)19 Intent (android.content.Intent)14 Account (android.accounts.Account)12 ArrayList (java.util.ArrayList)12 Context (android.content.Context)9 Fragment (androidx.fragment.app.Fragment)9 OwnCloudAccount (com.owncloud.android.lib.common.OwnCloudAccount)9 File (java.io.File)9 ArbitraryDataProvider (com.owncloud.android.datamodel.ArbitraryDataProvider)7 Uri (android.net.Uri)6 Bundle (android.os.Bundle)6 OCCapability (com.owncloud.android.lib.resources.status.OCCapability)6 GalleryFragment (com.owncloud.android.ui.fragment.GalleryFragment)6 PreviewTextFileFragment (com.owncloud.android.ui.preview.PreviewTextFileFragment)6 PreviewTextFragment (com.owncloud.android.ui.preview.PreviewTextFragment)6 PreviewTextStringFragment (com.owncloud.android.ui.preview.PreviewTextStringFragment)6 View (android.view.View)5