Search in sources :

Example 1 with ShareeUser

use of com.owncloud.android.lib.resources.shares.ShareeUser in project android by nextcloud.

the class OCFileListAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
    if (holder instanceof OCFileListFooterViewHolder) {
        OCFileListFooterViewHolder footerViewHolder = (OCFileListFooterViewHolder) holder;
        footerViewHolder.binding.footerText.setText(getFooterText());
        footerViewHolder.binding.loadingProgressBar.getIndeterminateDrawable().setColorFilter(ThemeColorUtils.primaryColor(activity), PorterDuff.Mode.SRC_IN);
        footerViewHolder.binding.loadingProgressBar.setVisibility(ocFileListFragmentInterface.isLoading() ? View.VISIBLE : View.GONE);
    } else if (holder instanceof OCFileListHeaderViewHolder) {
        OCFileListHeaderViewHolder headerViewHolder = (OCFileListHeaderViewHolder) holder;
        String text = currentDirectory.getRichWorkspace();
        PreviewTextFragment.setText(headerViewHolder.binding.headerText, text, null, activity, true, true);
        headerViewHolder.binding.headerView.setOnClickListener(v -> ocFileListFragmentInterface.onHeaderClicked());
    } else {
        ListGridImageViewHolder gridViewHolder = (ListGridImageViewHolder) holder;
        OCFile file = getItem(position);
        boolean gridImage = MimeTypeUtil.isImage(file) || MimeTypeUtil.isVideo(file);
        gridViewHolder.getThumbnail().setTag(file.getFileId());
        setThumbnail(file, gridViewHolder.getThumbnail(), user, mStorageManager, asyncTasks, gridView, activity, gridViewHolder.getShimmerThumbnail(), preferences);
        if (highlightedItem != null && file.getFileId() == highlightedItem.getFileId()) {
            gridViewHolder.getItemLayout().setBackgroundColor(activity.getResources().getColor(R.color.selected_item_background));
        } else if (isCheckedFile(file)) {
            gridViewHolder.getItemLayout().setBackgroundColor(activity.getResources().getColor(R.color.selected_item_background));
            gridViewHolder.getCheckbox().setImageDrawable(ThemeDrawableUtils.tintDrawable(R.drawable.ic_checkbox_marked, ThemeColorUtils.primaryColor(activity)));
        } else {
            gridViewHolder.getItemLayout().setBackgroundColor(activity.getResources().getColor(R.color.bg_default));
            gridViewHolder.getCheckbox().setImageResource(R.drawable.ic_checkbox_blank_outline);
        }
        gridViewHolder.getItemLayout().setOnClickListener(v -> ocFileListFragmentInterface.onItemClicked(file));
        if (!hideItemOptions) {
            gridViewHolder.getItemLayout().setLongClickable(true);
            gridViewHolder.getItemLayout().setOnLongClickListener(v -> ocFileListFragmentInterface.onLongItemClicked(file));
        }
        // unread comments
        if (file.getUnreadCommentsCount() > 0) {
            gridViewHolder.getUnreadComments().setVisibility(View.VISIBLE);
            gridViewHolder.getUnreadComments().setOnClickListener(view -> ocFileListFragmentInterface.showActivityDetailView(file));
        } else {
            gridViewHolder.getUnreadComments().setVisibility(View.GONE);
        }
        if (holder instanceof ListItemViewHolder) {
            ListItemViewHolder itemViewHolder = (ListItemViewHolder) holder;
            if ((file.isSharedWithMe() || file.isSharedWithSharee()) && !multiSelect && !gridView && !hideItemOptions) {
                itemViewHolder.getSharedAvatars().setVisibility(View.VISIBLE);
                itemViewHolder.getSharedAvatars().removeAllViews();
                String fileOwner = file.getOwnerId();
                List<ShareeUser> sharees = file.getSharees();
                // use fileOwner if not oneself, then add at first
                ShareeUser fileOwnerSharee = new ShareeUser(fileOwner, file.getOwnerDisplayName(), ShareType.USER);
                if (!TextUtils.isEmpty(fileOwner) && !fileOwner.equals(userId) && !sharees.contains(fileOwnerSharee)) {
                    sharees.add(fileOwnerSharee);
                }
                Collections.reverse(sharees);
                Log_OC.d(this, "sharees of " + file.getFileName() + ": " + sharees);
                itemViewHolder.getSharedAvatars().setAvatars(user, sharees);
                itemViewHolder.getSharedAvatars().setOnClickListener(view -> ocFileListFragmentInterface.onShareIconClick(file));
            } else {
                itemViewHolder.getSharedAvatars().setVisibility(View.GONE);
                itemViewHolder.getSharedAvatars().removeAllViews();
            }
            // npe fix: looks like file without local storage path somehow get here
            final String storagePath = file.getStoragePath();
            if (onlyOnDevice && storagePath != null) {
                File localFile = new File(storagePath);
                long localSize;
                if (localFile.isDirectory()) {
                    localSize = FileStorageUtils.getFolderSize(localFile);
                } else {
                    localSize = localFile.length();
                }
                itemViewHolder.getFileSize().setText(DisplayUtils.bytesToHumanReadable(localSize));
            } else {
                itemViewHolder.getFileSize().setText(DisplayUtils.bytesToHumanReadable(file.getFileLength()));
            }
            itemViewHolder.getLastModification().setText(DisplayUtils.getRelativeTimestamp(activity, file.getModificationTimestamp()));
            if (multiSelect || gridView || hideItemOptions) {
                itemViewHolder.getOverflowMenu().setVisibility(View.GONE);
            } else {
                itemViewHolder.getOverflowMenu().setVisibility(View.VISIBLE);
                itemViewHolder.getOverflowMenu().setOnClickListener(view -> ocFileListFragmentInterface.onOverflowIconClicked(file, view));
            }
        }
        // default first
        gridViewHolder.getLocalFileIndicator().setVisibility(View.INVISIBLE);
        if (showMetadata) {
            OperationsService.OperationsServiceBinder operationsServiceBinder = transferServiceGetter.getOperationsServiceBinder();
            FileDownloader.FileDownloaderBinder fileDownloaderBinder = transferServiceGetter.getFileDownloaderBinder();
            FileUploader.FileUploaderBinder fileUploaderBinder = transferServiceGetter.getFileUploaderBinder();
            if (operationsServiceBinder != null && operationsServiceBinder.isSynchronizing(user, file)) {
                // synchronizing
                gridViewHolder.getLocalFileIndicator().setImageResource(R.drawable.ic_synchronizing);
                gridViewHolder.getLocalFileIndicator().setVisibility(View.VISIBLE);
            } else if (fileDownloaderBinder != null && fileDownloaderBinder.isDownloading(user, file)) {
                // downloading
                gridViewHolder.getLocalFileIndicator().setImageResource(R.drawable.ic_synchronizing);
                gridViewHolder.getLocalFileIndicator().setVisibility(View.VISIBLE);
            } else if (fileUploaderBinder != null && fileUploaderBinder.isUploading(user, file)) {
                // uploading
                gridViewHolder.getLocalFileIndicator().setImageResource(R.drawable.ic_synchronizing);
                gridViewHolder.getLocalFileIndicator().setVisibility(View.VISIBLE);
            } else if (file.getEtagInConflict() != null) {
                // conflict
                gridViewHolder.getLocalFileIndicator().setImageResource(R.drawable.ic_synchronizing_error);
                gridViewHolder.getLocalFileIndicator().setVisibility(View.VISIBLE);
            } else if (file.isDown()) {
                gridViewHolder.getLocalFileIndicator().setImageResource(R.drawable.ic_synced);
                gridViewHolder.getLocalFileIndicator().setVisibility(View.VISIBLE);
            }
            gridViewHolder.getFavorite().setVisibility(file.isFavorite() ? View.VISIBLE : View.GONE);
        }
        if (multiSelect) {
            gridViewHolder.getCheckbox().setVisibility(View.VISIBLE);
        } else {
            gridViewHolder.getCheckbox().setVisibility(View.GONE);
        }
        if (holder instanceof ListGridItemViewHolder) {
            ListGridItemViewHolder gridItemViewHolder = (ListGridItemViewHolder) holder;
            gridItemViewHolder.getFileName().setText(file.getDecryptedFileName());
            if (gridView && gridImage) {
                gridItemViewHolder.getFileName().setVisibility(View.GONE);
            } else {
                if (gridView && ocFileListFragmentInterface.getColumnsCount() > showFilenameColumnThreshold) {
                    gridItemViewHolder.getFileName().setVisibility(View.GONE);
                } else {
                    gridItemViewHolder.getFileName().setVisibility(View.VISIBLE);
                }
            }
        }
        if (gridView || hideItemOptions || (file.isFolder() && !file.canReshare())) {
            gridViewHolder.getShared().setVisibility(View.GONE);
        } else {
            showShareIcon(gridViewHolder, file);
        }
    }
}
Also used : User(com.nextcloud.client.account.User) ThumbnailsCacheManager(com.owncloud.android.datamodel.ThumbnailsCacheManager) RemoteFile(com.owncloud.android.lib.resources.files.model.RemoteFile) NonNull(androidx.annotation.NonNull) WindowManager(android.view.WindowManager) FrameLayout(android.widget.FrameLayout) ImageView(android.widget.ImageView) OCFile(com.owncloud.android.datamodel.OCFile) Drawable(android.graphics.drawable.Drawable) RemoteOperationResult(com.owncloud.android.lib.common.operations.RemoteOperationResult) Vector(java.util.Vector) OCShare(com.owncloud.android.lib.resources.shares.OCShare) AvatarGroupLayout(com.owncloud.android.ui.AvatarGroupLayout) Locale(java.util.Locale) Handler(android.os.Handler) Looper(android.os.Looper) View(android.view.View) FileSortOrder(com.owncloud.android.utils.FileSortOrder) RecyclerView(androidx.recyclerview.widget.RecyclerView) DisplayUtils(com.owncloud.android.utils.DisplayUtils) ThemeDrawableUtils(com.owncloud.android.utils.theme.ThemeDrawableUtils) AccountManager(android.accounts.AccountManager) ListHeaderBinding(com.owncloud.android.databinding.ListHeaderBinding) RefreshFolderOperation(com.owncloud.android.operations.RefreshFolderOperation) SearchType(com.owncloud.android.ui.fragment.SearchType) Set(java.util.Set) AppPreferences(com.nextcloud.client.preferences.AppPreferences) PorterDuff(android.graphics.PorterDuff) ViewGroup(android.view.ViewGroup) GridItemBinding(com.owncloud.android.databinding.GridItemBinding) Log_OC(com.owncloud.android.lib.common.utils.Log_OC) List(java.util.List) TextView(android.widget.TextView) GridImageBinding(com.owncloud.android.databinding.GridImageBinding) ShareType(com.owncloud.android.lib.resources.shares.ShareType) BitmapUtils(com.owncloud.android.utils.BitmapUtils) ThemeColorUtils(com.owncloud.android.utils.theme.ThemeColorUtils) Nullable(androidx.annotation.Nullable) MainApp(com.owncloud.android.MainApp) FileDataStorageManager(com.owncloud.android.datamodel.FileDataStorageManager) VirtualFolderType(com.owncloud.android.datamodel.VirtualFolderType) FileUploader(com.owncloud.android.files.services.FileUploader) MimeTypeUtil(com.owncloud.android.utils.MimeTypeUtil) ContentValues(android.content.ContentValues) R(com.owncloud.android.R) Context(android.content.Context) ResourcesCompat(androidx.core.content.res.ResourcesCompat) Filter(android.widget.Filter) ComponentsGetter(com.owncloud.android.ui.activity.ComponentsGetter) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) FileDownloader(com.owncloud.android.files.services.FileDownloader) LoaderImageView(com.elyeproj.loaderviewlibrary.LoaderImageView) OCFileListFragmentInterface(com.owncloud.android.ui.interfaces.OCFileListFragmentInterface) LayoutInflater(android.view.LayoutInflater) RemoteOperationFailedException(com.owncloud.android.operations.RemoteOperationFailedException) PreviewTextFragment(com.owncloud.android.ui.preview.PreviewTextFragment) Point(android.graphics.Point) TextUtils(android.text.TextUtils) ListItemBinding(com.owncloud.android.databinding.ListItemBinding) RemoteOperation(com.owncloud.android.lib.common.operations.RemoteOperation) ReadFileRemoteOperation(com.owncloud.android.lib.resources.files.ReadFileRemoteOperation) File(java.io.File) ListFooterBinding(com.owncloud.android.databinding.ListFooterBinding) OperationsService(com.owncloud.android.services.OperationsService) FileStorageUtils(com.owncloud.android.utils.FileStorageUtils) Bitmap(android.graphics.Bitmap) ShareeUser(com.owncloud.android.lib.resources.shares.ShareeUser) ProviderMeta(com.owncloud.android.db.ProviderMeta) Activity(android.app.Activity) Collections(java.util.Collections) VisibleForTesting(androidx.annotation.VisibleForTesting) Resources(android.content.res.Resources) OCFile(com.owncloud.android.datamodel.OCFile) ShareeUser(com.owncloud.android.lib.resources.shares.ShareeUser) List(java.util.List) ArrayList(java.util.ArrayList) RemoteFile(com.owncloud.android.lib.resources.files.model.RemoteFile) OCFile(com.owncloud.android.datamodel.OCFile) File(java.io.File)

Example 2 with ShareeUser

use of com.owncloud.android.lib.resources.shares.ShareeUser in project android by nextcloud.

the class AvatarGroupLayout method setAvatars.

public void setAvatars(@NonNull User user, @NonNull List<ShareeUser> sharees) {
    @NonNull Context context = getContext();
    removeAllViews();
    RelativeLayout.LayoutParams avatarLayoutParams;
    int avatarCount;
    int shareeSize = Math.min(sharees.size(), MAX_AVATAR_COUNT);
    Resources resources = context.getResources();
    float avatarRadius = resources.getDimension(R.dimen.list_item_avatar_icon_radius);
    ShareeUser sharee;
    for (avatarCount = 0; avatarCount < shareeSize; avatarCount++) {
        avatarLayoutParams = new RelativeLayout.LayoutParams(avatarSize, avatarSize);
        avatarLayoutParams.setMargins(0, 0, avatarCount * overlapPx, 0);
        avatarLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
        final ImageView avatar = new ImageView(context);
        avatar.setLayoutParams(avatarLayoutParams);
        avatar.setPadding(avatarBorderSize, avatarBorderSize, avatarBorderSize, avatarBorderSize);
        avatar.setBackground(borderDrawable);
        addView(avatar);
        avatar.requestLayout();
        if (avatarCount == 0 && sharees.size() > MAX_AVATAR_COUNT) {
            avatar.setImageResource(R.drawable.ic_people);
            ThemeDrawableUtils.setIconColor(avatar.getDrawable());
        } else {
            sharee = sharees.get(avatarCount);
            switch(sharee.getShareType()) {
                case GROUP:
                case EMAIL:
                case ROOM:
                case CIRCLE:
                    ThemeAvatarUtils.createAvatar(sharee.getShareType(), avatar, context);
                    break;
                case FEDERATED:
                    showFederatedShareAvatar(context, sharee.getUserId(), avatarRadius, resources, avatar);
                    break;
                default:
                    avatar.setTag(sharee);
                    DisplayUtils.setAvatar(user, sharee.getUserId(), sharee.getDisplayName(), this, avatarRadius, resources, avatar, context);
                    break;
            }
        }
    }
    // Recalculate container size based on avatar count
    int size = overlapPx * (avatarCount - 1) + avatarSize;
    ViewGroup.LayoutParams rememberParam = getLayoutParams();
    rememberParam.width = size;
    setLayoutParams(rememberParam);
}
Also used : Context(android.content.Context) ViewGroup(android.view.ViewGroup) NonNull(androidx.annotation.NonNull) ShareeUser(com.owncloud.android.lib.resources.shares.ShareeUser) RelativeLayout(android.widget.RelativeLayout) Resources(android.content.res.Resources) ImageView(android.widget.ImageView)

Example 3 with ShareeUser

use of com.owncloud.android.lib.resources.shares.ShareeUser in project android by nextcloud.

the class FileDataStorageManager method createFileInstance.

private OCFile createFileInstance(Cursor cursor) {
    OCFile ocFile = null;
    if (cursor != null) {
        ocFile = new OCFile(cursor.getString(cursor.getColumnIndexOrThrow(ProviderTableMeta.FILE_PATH)));
        ocFile.setDecryptedRemotePath(getString(cursor, ProviderTableMeta.FILE_PATH_DECRYPTED));
        ocFile.setFileId(cursor.getLong(cursor.getColumnIndexOrThrow(ProviderTableMeta._ID)));
        ocFile.setParentId(cursor.getLong(cursor.getColumnIndexOrThrow(ProviderTableMeta.FILE_PARENT)));
        ocFile.setMimeType(cursor.getString(cursor.getColumnIndexOrThrow(ProviderTableMeta.FILE_CONTENT_TYPE)));
        ocFile.setStoragePath(cursor.getString(cursor.getColumnIndexOrThrow(ProviderTableMeta.FILE_STORAGE_PATH)));
        if (ocFile.getStoragePath() == null) {
            // try to find existing file and bind it with current account;
            // with the current update of SynchronizeFolderOperation, this won't be
            // necessary anymore after a full synchronization of the account
            File file = new File(FileStorageUtils.getDefaultSavePathFor(user.getAccountName(), ocFile));
            if (file.exists()) {
                ocFile.setStoragePath(file.getAbsolutePath());
                ocFile.setLastSyncDateForData(file.lastModified());
            }
        }
        ocFile.setFileLength(cursor.getLong(cursor.getColumnIndexOrThrow(ProviderTableMeta.FILE_CONTENT_LENGTH)));
        ocFile.setCreationTimestamp(cursor.getLong(cursor.getColumnIndexOrThrow(ProviderTableMeta.FILE_CREATION)));
        ocFile.setModificationTimestamp(cursor.getLong(cursor.getColumnIndexOrThrow(ProviderTableMeta.FILE_MODIFIED)));
        ocFile.setModificationTimestampAtLastSyncForData(cursor.getLong(cursor.getColumnIndexOrThrow(ProviderTableMeta.FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA)));
        ocFile.setLastSyncDateForProperties(cursor.getLong(cursor.getColumnIndexOrThrow(ProviderTableMeta.FILE_LAST_SYNC_DATE)));
        ocFile.setLastSyncDateForData(cursor.getLong(cursor.getColumnIndexOrThrow(ProviderTableMeta.FILE_LAST_SYNC_DATE_FOR_DATA)));
        ocFile.setEtag(cursor.getString(cursor.getColumnIndexOrThrow(ProviderTableMeta.FILE_ETAG)));
        ocFile.setEtagOnServer(cursor.getString(cursor.getColumnIndexOrThrow(ProviderTableMeta.FILE_ETAG_ON_SERVER)));
        ocFile.setSharedViaLink(cursor.getInt(cursor.getColumnIndexOrThrow(ProviderTableMeta.FILE_SHARED_VIA_LINK)) == 1);
        ocFile.setSharedWithSharee(cursor.getInt(cursor.getColumnIndexOrThrow(ProviderTableMeta.FILE_SHARED_WITH_SHAREE)) == 1);
        ocFile.setPermissions(cursor.getString(cursor.getColumnIndexOrThrow(ProviderTableMeta.FILE_PERMISSIONS)));
        ocFile.setRemoteId(cursor.getString(cursor.getColumnIndexOrThrow(ProviderTableMeta.FILE_REMOTE_ID)));
        ocFile.setUpdateThumbnailNeeded(cursor.getInt(cursor.getColumnIndexOrThrow(ProviderTableMeta.FILE_UPDATE_THUMBNAIL)) == 1);
        ocFile.setDownloading(cursor.getInt(cursor.getColumnIndexOrThrow(ProviderTableMeta.FILE_IS_DOWNLOADING)) == 1);
        ocFile.setEtagInConflict(cursor.getString(cursor.getColumnIndexOrThrow(ProviderTableMeta.FILE_ETAG_IN_CONFLICT)));
        ocFile.setFavorite(cursor.getInt(cursor.getColumnIndexOrThrow(ProviderTableMeta.FILE_FAVORITE)) == 1);
        ocFile.setEncrypted(cursor.getInt(cursor.getColumnIndexOrThrow(ProviderTableMeta.FILE_IS_ENCRYPTED)) == 1);
        // if (ocFile.isEncrypted()) {
        // ocFile.setFileName(cursor.getString(cursor.getColumnIndexOrThrow(ProviderTableMeta.FILE_NAME)));
        // }
        ocFile.setMountType(WebdavEntry.MountType.values()[cursor.getInt(cursor.getColumnIndexOrThrow(ProviderTableMeta.FILE_MOUNT_TYPE))]);
        ocFile.setPreviewAvailable(cursor.getInt(cursor.getColumnIndexOrThrow(ProviderTableMeta.FILE_HAS_PREVIEW)) == 1);
        ocFile.setUnreadCommentsCount(cursor.getInt(cursor.getColumnIndexOrThrow(ProviderTableMeta.FILE_UNREAD_COMMENTS_COUNT)));
        ocFile.setOwnerId(cursor.getString(cursor.getColumnIndexOrThrow(ProviderTableMeta.FILE_OWNER_ID)));
        ocFile.setOwnerDisplayName(cursor.getString(cursor.getColumnIndexOrThrow(ProviderTableMeta.FILE_OWNER_DISPLAY_NAME)));
        ocFile.setNote(cursor.getString(cursor.getColumnIndexOrThrow(ProviderTableMeta.FILE_NOTE)));
        ocFile.setRichWorkspace(cursor.getString(cursor.getColumnIndexOrThrow(ProviderTableMeta.FILE_RICH_WORKSPACE)));
        String sharees = cursor.getString(cursor.getColumnIndexOrThrow(ProviderTableMeta.FILE_SHAREES));
        if (sharees == null || NULL_STRING.equals(sharees) || sharees.isEmpty()) {
            ocFile.setSharees(new ArrayList<>());
        } else {
            try {
                ShareeUser[] shareesArray = new Gson().fromJson(sharees, ShareeUser[].class);
                ocFile.setSharees(new ArrayList<>(Arrays.asList(shareesArray)));
            } catch (JsonSyntaxException e) {
                // ignore saved value due to api change
                ocFile.setSharees(new ArrayList<>());
            }
        }
    }
    return ocFile;
}
Also used : JsonSyntaxException(com.google.gson.JsonSyntaxException) ShareeUser(com.owncloud.android.lib.resources.shares.ShareeUser) ArrayList(java.util.ArrayList) Gson(com.google.gson.Gson) RemoteFile(com.owncloud.android.lib.resources.files.model.RemoteFile) File(java.io.File)

Aggregations

ShareeUser (com.owncloud.android.lib.resources.shares.ShareeUser)3 Context (android.content.Context)2 Resources (android.content.res.Resources)2 ViewGroup (android.view.ViewGroup)2 ImageView (android.widget.ImageView)2 NonNull (androidx.annotation.NonNull)2 AccountManager (android.accounts.AccountManager)1 Activity (android.app.Activity)1 ContentValues (android.content.ContentValues)1 Bitmap (android.graphics.Bitmap)1 Point (android.graphics.Point)1 PorterDuff (android.graphics.PorterDuff)1 Drawable (android.graphics.drawable.Drawable)1 Handler (android.os.Handler)1 Looper (android.os.Looper)1 TextUtils (android.text.TextUtils)1 LayoutInflater (android.view.LayoutInflater)1 View (android.view.View)1 WindowManager (android.view.WindowManager)1 Filter (android.widget.Filter)1