Search in sources :

Example 51 with User

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();
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) User(com.nextcloud.client.account.User) SuppressLint(android.annotation.SuppressLint)

Example 52 with User

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

Example 53 with User

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);
}
Also used : User(com.nextcloud.client.account.User) OCFileListFragment(com.owncloud.android.ui.fragment.OCFileListFragment) UnifiedSearchFragment(com.owncloud.android.ui.fragment.UnifiedSearchFragment) Fragment(androidx.fragment.app.Fragment) TaskRetainerFragment(com.owncloud.android.ui.fragment.TaskRetainerFragment) FileFragment(com.owncloud.android.ui.fragment.FileFragment) PreviewTextStringFragment(com.owncloud.android.ui.preview.PreviewTextStringFragment) PreviewTextFragment(com.owncloud.android.ui.preview.PreviewTextFragment) PreviewTextFileFragment(com.owncloud.android.ui.preview.PreviewTextFileFragment) GalleryFragment(com.owncloud.android.ui.fragment.GalleryFragment) SortingOrderDialogFragment(com.owncloud.android.ui.dialog.SortingOrderDialogFragment) PreviewImageFragment(com.owncloud.android.ui.preview.PreviewImageFragment) PreviewMediaFragment(com.owncloud.android.ui.preview.PreviewMediaFragment) FileDetailFragment(com.owncloud.android.ui.fragment.FileDetailFragment) PreviewPdfFragment(com.owncloud.android.ui.preview.pdf.PreviewPdfFragment)

Example 54 with User

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);
        }
    }
}
Also used : OCFile(com.owncloud.android.datamodel.OCFile) PreviewTextFileFragment(com.owncloud.android.ui.preview.PreviewTextFileFragment) User(com.nextcloud.client.account.User) FileFragment(com.owncloud.android.ui.fragment.FileFragment) PreviewTextFileFragment(com.owncloud.android.ui.preview.PreviewTextFileFragment) PreviewMediaFragment(com.owncloud.android.ui.preview.PreviewMediaFragment) FileDetailFragment(com.owncloud.android.ui.fragment.FileDetailFragment) PreviewTextFragment(com.owncloud.android.ui.preview.PreviewTextFragment) OCFileListFragment(com.owncloud.android.ui.fragment.OCFileListFragment) UnifiedSearchFragment(com.owncloud.android.ui.fragment.UnifiedSearchFragment) Fragment(androidx.fragment.app.Fragment) TaskRetainerFragment(com.owncloud.android.ui.fragment.TaskRetainerFragment) FileFragment(com.owncloud.android.ui.fragment.FileFragment) PreviewTextStringFragment(com.owncloud.android.ui.preview.PreviewTextStringFragment) PreviewTextFragment(com.owncloud.android.ui.preview.PreviewTextFragment) PreviewTextFileFragment(com.owncloud.android.ui.preview.PreviewTextFileFragment) GalleryFragment(com.owncloud.android.ui.fragment.GalleryFragment) SortingOrderDialogFragment(com.owncloud.android.ui.dialog.SortingOrderDialogFragment) PreviewImageFragment(com.owncloud.android.ui.preview.PreviewImageFragment) PreviewMediaFragment(com.owncloud.android.ui.preview.PreviewMediaFragment) FileDetailFragment(com.owncloud.android.ui.fragment.FileDetailFragment) PreviewPdfFragment(com.owncloud.android.ui.preview.pdf.PreviewPdfFragment)

Example 55 with User

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);
    }
}
Also used : Context(android.content.Context) OCFile(com.owncloud.android.datamodel.OCFile) DownloadFileOperation(com.owncloud.android.operations.DownloadFileOperation) User(com.nextcloud.client.account.User) RemoteOperationResult(com.owncloud.android.lib.common.operations.RemoteOperationResult) FileNotFoundException(java.io.FileNotFoundException) Handler(android.os.Handler) IOException(java.io.IOException) OCFile(com.owncloud.android.datamodel.OCFile) File(java.io.File) SuppressLint(android.annotation.SuppressLint) Point(android.graphics.Point) SuppressLint(android.annotation.SuppressLint)

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