Search in sources :

Example 11 with User

use of com.nextcloud.client.account.User in project android by nextcloud.

the class FileDisplayActivity method startContactListFragment.

public void startContactListFragment(OCFile file) {
    final User user = getUser().orElseThrow(RuntimeException::new);
    ContactsPreferenceActivity.startActivityWithContactsFile(this, user, file);
}
Also used : User(com.nextcloud.client.account.User)

Example 12 with User

use of com.nextcloud.client.account.User in project android by nextcloud.

the class FileDisplayActivity method onStart.

@Override
public void onStart() {
    super.onStart();
    final Optional<User> optionalUser = getUser();
    final FileDataStorageManager storageManager = getStorageManager();
    if (optionalUser.isPresent() && storageManager != null) {
        // / Check whether the 'main' OCFile handled by the Activity is contained in the
        // current Account
        OCFile file = getFile();
        // get parent from path
        String parentPath = "";
        if (file != null) {
            if (file.isDown() && file.getLastSyncDateForProperties() == 0) {
                // upload in progress - right now, files are not inserted in the local
                // cache until the upload is successful get parent from path
                parentPath = file.getRemotePath().substring(0, file.getRemotePath().lastIndexOf(file.getFileName()));
                if (storageManager.getFileByPath(parentPath) == null) {
                    // not able to know the directory where the file is uploading
                    file = null;
                }
            } else {
                file = storageManager.getFileByPath(file.getRemotePath());
            // currentDir = null if not in the current Account
            }
        }
        if (file == null) {
            // fall back to root folder
            // never returns null
            file = storageManager.getFileByPath(OCFile.ROOT_PATH);
        }
        setFile(file);
        User user = optionalUser.get();
        setupDrawer();
        mSwitchAccountButton.setTag(user.getAccountName());
        DisplayUtils.setAvatar(user, this, getResources().getDimension(R.dimen.nav_drawer_menu_avatar_radius), getResources(), mSwitchAccountButton, this);
        final boolean userChanged = !user.nameEquals(lastDisplayedUser.orElse(null));
        if (userChanged) {
            Log_OC.d(TAG, "Initializing Fragments in onAccountChanged..");
            initFragmentsWithFile(user, file);
            if (file.isFolder() && TextUtils.isEmpty(searchQuery)) {
                startSyncFolderOperation(file, false);
            }
        } else {
            updateActionBarTitleAndHomeButton(file.isFolder() ? null : file);
        }
    }
    lastDisplayedUser = optionalUser;
    EventBus.getDefault().post(new TokenPushEvent());
    checkForNewDevVersionNecessary(getApplicationContext());
}
Also used : OCFile(com.owncloud.android.datamodel.OCFile) User(com.nextcloud.client.account.User) TokenPushEvent(com.owncloud.android.ui.events.TokenPushEvent) FileDataStorageManager(com.owncloud.android.datamodel.FileDataStorageManager)

Example 13 with User

use of com.nextcloud.client.account.User in project android by nextcloud.

the class FileDisplayActivity method startTextPreview.

/**
 * Starts the preview of a text file {@link OCFile}.
 *
 * @param file Text {@link OCFile} to preview.
 */
public void startTextPreview(OCFile file, boolean showPreview) {
    Optional<User> optUser = getUser();
    if (!optUser.isPresent()) {
        // remnants of old unsafe system; do not crash, silently stop
        return;
    }
    User user = optUser.get();
    if (showPreview) {
        showSortListGroup(false);
        PreviewTextFileFragment fragment = PreviewTextFileFragment.create(user, file, searchOpen, searchQuery);
        setLeftFragment(fragment);
        binding.rightFragmentContainer.setVisibility(View.GONE);
        super.updateActionBarTitleAndHomeButton(file);
    } else {
        Intent previewIntent = new Intent();
        previewIntent.putExtra(EXTRA_FILE, file);
        previewIntent.putExtra(TEXT_PREVIEW, true);
        FileOperationsHelper fileOperationsHelper = new FileOperationsHelper(this, getUserAccountManager(), connectivityService);
        fileOperationsHelper.startSyncForFileAndIntent(file, previewIntent);
    }
}
Also used : PreviewTextFileFragment(com.owncloud.android.ui.preview.PreviewTextFileFragment) FileOperationsHelper(com.owncloud.android.ui.helpers.FileOperationsHelper) User(com.nextcloud.client.account.User) Intent(android.content.Intent)

Example 14 with User

use of com.nextcloud.client.account.User in project android by nextcloud.

the class FileDisplayActivity method startDownloadForPreview.

/**
 * Requests the download of the received {@link OCFile} , updates the UI to monitor the download progress and
 * prepares the activity to preview or open the file when the download finishes.
 *
 * @param file {@link OCFile} to download and preview.
 */
public void startDownloadForPreview(OCFile file) {
    final User currentUser = getUser().orElseThrow(RuntimeException::new);
    Fragment detailFragment = FileDetailFragment.newInstance(file, currentUser);
    setLeftFragment(detailFragment);
    mWaitingToPreview = file;
    requestForDownload();
    updateActionBarTitleAndHomeButton(file);
    setFile(file);
}
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 15 with User

use of com.nextcloud.client.account.User in project android by nextcloud.

the class FileActivity method onCreate.

/**
 * Loads the ownCloud {@link Account} and main {@link OCFile} to be handled by the instance of
 * the {@link FileActivity}.
 *
 * Grants that a valid ownCloud {@link Account} is associated to the instance, or that the user
 * is requested to create a new one.
 */
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mHandler = new Handler();
    mFileOperationsHelper = new FileOperationsHelper(this, getUserAccountManager(), connectivityService);
    if (savedInstanceState != null) {
        mFile = savedInstanceState.getParcelable(FileActivity.EXTRA_FILE);
        mFromNotification = savedInstanceState.getBoolean(FileActivity.EXTRA_FROM_NOTIFICATION);
        mFileOperationsHelper.setOpIdWaitingFor(savedInstanceState.getLong(KEY_WAITING_FOR_OP_ID, Long.MAX_VALUE));
        ThemeToolbarUtils.setColoredTitle(getSupportActionBar(), savedInstanceState.getString(KEY_ACTION_BAR_TITLE), this);
    } else {
        User user = getIntent().getParcelableExtra(FileActivity.EXTRA_USER);
        mFile = getIntent().getParcelableExtra(FileActivity.EXTRA_FILE);
        mFromNotification = getIntent().getBooleanExtra(FileActivity.EXTRA_FROM_NOTIFICATION, false);
        if (user != null) {
            setUser(user);
        }
    }
    mOperationsServiceConnection = new OperationsServiceConnection();
    bindService(new Intent(this, OperationsService.class), mOperationsServiceConnection, Context.BIND_AUTO_CREATE);
    mDownloadServiceConnection = newTransferenceServiceConnection();
    if (mDownloadServiceConnection != null) {
        bindService(new Intent(this, FileDownloader.class), mDownloadServiceConnection, Context.BIND_AUTO_CREATE);
    }
    mUploadServiceConnection = newTransferenceServiceConnection();
    if (mUploadServiceConnection != null) {
        bindService(new Intent(this, FileUploader.class), mUploadServiceConnection, Context.BIND_AUTO_CREATE);
    }
}
Also used : FileOperationsHelper(com.owncloud.android.ui.helpers.FileOperationsHelper) User(com.nextcloud.client.account.User) FileUploader(com.owncloud.android.files.services.FileUploader) Handler(android.os.Handler) Intent(android.content.Intent) FileDownloader(com.owncloud.android.files.services.FileDownloader) OperationsService(com.owncloud.android.services.OperationsService)

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