Search in sources :

Example 81 with User

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

the class SyncedFoldersActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    binding = SyncedFoldersLayoutBinding.inflate(getLayoutInflater());
    setContentView(binding.getRoot());
    if (getIntent() != null && getIntent().getExtras() != null) {
        final String accountName = getIntent().getExtras().getString(NotificationWork.KEY_NOTIFICATION_ACCOUNT);
        Optional<User> optionalUser = getUser();
        if (optionalUser.isPresent() && accountName != null) {
            User user = optionalUser.get();
            if (!accountName.equalsIgnoreCase(user.getAccountName())) {
                accountManager.setCurrentOwnCloudAccount(accountName);
                setUser(getUserAccountManager().getUser());
            }
        }
        path = getIntent().getStringExtra(MediaFoldersDetectionWork.KEY_MEDIA_FOLDER_PATH);
        type = getIntent().getIntExtra(MediaFoldersDetectionWork.KEY_MEDIA_FOLDER_TYPE, -1);
        // Cancel notification
        int notificationId = getIntent().getIntExtra(MediaFoldersDetectionWork.NOTIFICATION_ID, 0);
        NotificationManager notificationManager = (NotificationManager) getSystemService(Activity.NOTIFICATION_SERVICE);
        notificationManager.cancel(notificationId);
    }
    // setup toolbar
    setupToolbar();
    updateActionBarTitleAndHomeButtonByString(getString(R.string.drawer_synced_folders));
    setupDrawer();
    setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
    if (getSupportActionBar() != null) {
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    }
    if (mDrawerToggle != null) {
        mDrawerToggle.setDrawerIndicatorEnabled(false);
    }
    // TODO: The content loading should be done asynchronously
    setupContent();
    if (ThemeUtils.themingEnabled(this)) {
        setTheme(R.style.FallbackThemingTheme);
    }
    binding.emptyList.emptyListViewAction.setOnClickListener(v -> showHiddenItems());
}
Also used : User(com.nextcloud.client.account.User) NotificationManager(android.app.NotificationManager) SuppressLint(android.annotation.SuppressLint)

Example 82 with User

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

the class SyncedFoldersActivity method load.

/**
 * loads all media/synced folders, adds them to the recycler view adapter and shows the list.
 *
 * @param perFolderMediaItemLimit the amount of media items to be loaded/shown per media folder
 */
private void load(final int perFolderMediaItemLimit, boolean force) {
    if (adapter.getItemCount() > 0 && !force) {
        return;
    }
    showLoadingContent();
    final List<MediaFolder> mediaFolders = MediaProvider.getImageFolders(getContentResolver(), perFolderMediaItemLimit, this, false);
    mediaFolders.addAll(MediaProvider.getVideoFolders(getContentResolver(), perFolderMediaItemLimit, this, false));
    List<SyncedFolder> syncedFolderArrayList = syncedFolderProvider.getSyncedFolders();
    List<SyncedFolder> currentAccountSyncedFoldersList = new ArrayList<>();
    User user = getUserAccountManager().getUser();
    for (SyncedFolder syncedFolder : syncedFolderArrayList) {
        if (syncedFolder.getAccount().equals(user.getAccountName())) {
            // delete non-existing & disabled synced folders
            if (!new File(syncedFolder.getLocalPath()).exists() && !syncedFolder.isEnabled()) {
                syncedFolderProvider.deleteSyncedFolder(syncedFolder.getId());
            } else {
                currentAccountSyncedFoldersList.add(syncedFolder);
            }
        }
    }
    List<SyncedFolderDisplayItem> syncFolderItems = sortSyncedFolderItems(mergeFolderData(currentAccountSyncedFoldersList, mediaFolders));
    adapter.setSyncFolderItems(syncFolderItems);
    adapter.notifyDataSetChanged();
    showList();
    if (!TextUtils.isEmpty(path)) {
        int section = adapter.getSectionByLocalPathAndType(path, type);
        if (section >= 0) {
            onSyncFolderSettingsClick(section, adapter.get(section));
        }
    }
}
Also used : User(com.nextcloud.client.account.User) SyncedFolder(com.owncloud.android.datamodel.SyncedFolder) ArrayList(java.util.ArrayList) SyncedFolderDisplayItem(com.owncloud.android.datamodel.SyncedFolderDisplayItem) MediaFolder(com.owncloud.android.datamodel.MediaFolder) OCFile(com.owncloud.android.datamodel.OCFile) File(java.io.File) SuppressLint(android.annotation.SuppressLint)

Example 83 with User

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

the class RichDocumentsEditorWebView method handleRemoteFile.

private void handleRemoteFile(Intent data) {
    OCFile file = data.getParcelableExtra(FolderPickerActivity.EXTRA_FILES);
    new Thread(() -> {
        User user = currentAccountProvider.getUser();
        RichDocumentsCreateAssetOperation operation = new RichDocumentsCreateAssetOperation(file.getRemotePath());
        RemoteOperationResult result = operation.execute(user.toPlatformAccount(), this);
        if (result.isSuccess()) {
            String asset = (String) result.getSingleData();
            runOnUiThread(() -> getWebView().evaluateJavascript("OCA.RichDocuments.documentsMain.postAsset('" + file.getFileName() + "', '" + asset + "');", null));
        } else {
            runOnUiThread(() -> DisplayUtils.showSnackMessage(this, "Inserting image failed!"));
        }
    }).start();
}
Also used : OCFile(com.owncloud.android.datamodel.OCFile) User(com.nextcloud.client.account.User) RichDocumentsCreateAssetOperation(com.owncloud.android.operations.RichDocumentsCreateAssetOperation) RemoteOperationResult(com.owncloud.android.lib.common.operations.RemoteOperationResult)

Example 84 with User

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

the class ShareActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ShareActivityBinding binding = ShareActivityBinding.inflate(getLayoutInflater());
    setContentView(binding.getRoot());
    OCFile file = getFile();
    Optional<User> optionalUser = getUser();
    if (!optionalUser.isPresent()) {
        finish();
        return;
    }
    // Icon
    if (file.isFolder()) {
        binding.shareFileIcon.setImageDrawable(MimeTypeUtil.getFolderTypeIcon(file.isSharedWithMe() || file.isSharedWithSharee(), file.isSharedViaLink(), file.isEncrypted(), file.getMountType(), this));
    } else {
        binding.shareFileIcon.setImageDrawable(MimeTypeUtil.getFileTypeIcon(file.getMimeType(), file.getFileName(), optionalUser.get(), this));
        if (MimeTypeUtil.isImage(file)) {
            String remoteId = String.valueOf(file.getRemoteId());
            Bitmap thumbnail = ThumbnailsCacheManager.getBitmapFromDiskCache(remoteId);
            if (thumbnail != null) {
                binding.shareFileIcon.setImageBitmap(thumbnail);
            }
        }
    }
    // Name
    binding.shareFileName.setText(getResources().getString(R.string.share_file, file.getFileName()));
    binding.shareHeaderDivider.getBackground().setColorFilter(ThemeColorUtils.primaryAccentColor(this), PorterDuff.Mode.SRC_ATOP);
    // Size
    binding.shareFileSize.setText(DisplayUtils.bytesToHumanReadable(file.getFileLength()));
    Activity activity = this;
    new Thread(() -> {
        RemoteOperationResult result = new ReadFileRemoteOperation(getFile().getRemotePath()).execute(optionalUser.get().toPlatformAccount(), activity);
        if (result.isSuccess()) {
            RemoteFile remoteFile = (RemoteFile) result.getData().get(0);
            long length = remoteFile.getLength();
            getFile().setFileLength(length);
            runOnUiThread(() -> binding.shareFileSize.setText(DisplayUtils.bytesToHumanReadable(length)));
        }
    }).start();
    if (savedInstanceState == null) {
        // Add Share fragment on first creation
        FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
        Fragment fragment = FileDetailSharingFragment.newInstance(getFile(), optionalUser.get());
        ft.replace(R.id.share_fragment_container, fragment, TAG_SHARE_FRAGMENT);
        ft.commit();
    }
}
Also used : User(com.nextcloud.client.account.User) RemoteOperationResult(com.owncloud.android.lib.common.operations.RemoteOperationResult) ShareActivityBinding(com.owncloud.android.databinding.ShareActivityBinding) Activity(android.app.Activity) FileDetailSharingFragment(com.owncloud.android.ui.fragment.FileDetailSharingFragment) Fragment(androidx.fragment.app.Fragment) OCFile(com.owncloud.android.datamodel.OCFile) Bitmap(android.graphics.Bitmap) FragmentTransaction(androidx.fragment.app.FragmentTransaction) ReadFileRemoteOperation(com.owncloud.android.lib.resources.files.ReadFileRemoteOperation) RemoteFile(com.owncloud.android.lib.resources.files.model.RemoteFile)

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