Search in sources :

Example 1 with ItemViewHolder

use of com.amaze.filemanager.adapters.holders.ItemViewHolder in project AmazeFileManager by TeamAmaze.

the class RecyclerAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(final RecyclerView.ViewHolder vholder, int p) {
    if (vholder instanceof ItemViewHolder) {
        final ItemViewHolder holder = (ItemViewHolder) vholder;
        final boolean isBackButton = getBoolean(PREFERENCE_SHOW_GOBACK_BUTTON) && p == 0;
        if (isBackButton) {
            holder.about.setVisibility(View.GONE);
        }
        if (mainFrag.IS_LIST) {
            if (p == getItemCount() - 1) {
                holder.rl.setMinimumHeight((int) minRowHeight);
                if (itemsDigested.size() == (getBoolean(PREFERENCE_SHOW_GOBACK_BUTTON) ? 1 : 0))
                    holder.txtTitle.setText(R.string.nofiles);
                else
                    holder.txtTitle.setText("");
                return;
            }
        }
        if (!this.stoppedAnimation && !itemsDigested.get(p).getAnimating()) {
            animate(holder);
            itemsDigested.get(p).setAnimate(true);
        }
        final LayoutElementParcelable rowItem = itemsDigested.get(p).elem;
        if (mainFrag.IS_LIST) {
            holder.rl.setOnClickListener(v -> {
                mainFrag.onListItemClicked(isBackButton, vholder.getAdapterPosition(), rowItem, holder.checkImageView);
            });
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                holder.checkImageView.setBackground(new CircleGradientDrawable(accentColor, utilsProvider.getAppTheme(), mainFrag.getResources().getDisplayMetrics()));
            } else {
                holder.checkImageView.setBackgroundDrawable(new CircleGradientDrawable(accentColor, utilsProvider.getAppTheme(), mainFrag.getResources().getDisplayMetrics()));
            }
            holder.rl.setOnLongClickListener(p1 -> {
                // check if the item on which action is performed is not the first {goback} item
                if (!isBackButton) {
                    toggleChecked(vholder.getAdapterPosition(), holder.checkImageView);
                }
                return true;
            });
            holder.txtTitle.setText(rowItem.title);
            holder.genericText.setText("");
            if (holder.about != null) {
                if (utilsProvider.getAppTheme().equals(AppTheme.LIGHT))
                    holder.about.setColorFilter(grey_color);
                showPopup(holder.about, rowItem, p);
            }
            holder.genericIcon.setOnClickListener(v -> {
                int id = v.getId();
                if (id == R.id.generic_icon || id == R.id.picture_icon || id == R.id.apk_icon) {
                    // TODO: transform icon on press to the properties dialog with animation
                    if (!isBackButton) {
                        toggleChecked(vholder.getAdapterPosition(), holder.checkImageView);
                    } else
                        mainFrag.goBack();
                }
            });
            holder.pictureIcon.setOnClickListener(view -> {
                if (!isBackButton) {
                    toggleChecked(vholder.getAdapterPosition(), holder.checkImageView);
                } else
                    mainFrag.goBack();
            });
            holder.apkIcon.setOnClickListener(view -> {
                if (!isBackButton) {
                    toggleChecked(vholder.getAdapterPosition(), holder.checkImageView);
                } else
                    mainFrag.goBack();
            });
            // resetting icons visibility
            holder.genericIcon.setVisibility(View.GONE);
            holder.pictureIcon.setVisibility(View.GONE);
            holder.apkIcon.setVisibility(View.GONE);
            holder.checkImageView.setVisibility(View.INVISIBLE);
            // pictureIcon is circular drawable
            switch(rowItem.filetype) {
                case Icons.IMAGE:
                case Icons.VIDEO:
                    if (getBoolean(PREFERENCE_SHOW_THUMB)) {
                        if (getBoolean(PREFERENCE_USE_CIRCULAR_IMAGES)) {
                            showThumbnailWithBackground(holder, rowItem.iconData, holder.pictureIcon, rowItem.iconData::setImageBroken);
                        } else {
                            showThumbnailWithBackground(holder, rowItem.iconData, holder.apkIcon, rowItem.iconData::setImageBroken);
                        }
                    }
                    break;
                case Icons.APK:
                    if (getBoolean(PREFERENCE_SHOW_THUMB)) {
                        showThumbnailWithBackground(holder, rowItem.iconData, holder.apkIcon, rowItem.iconData::setImageBroken);
                    }
                    break;
                case Icons.NOT_KNOWN:
                    holder.genericIcon.setVisibility(View.VISIBLE);
                    // if the file type is any unknown variable
                    String ext = !rowItem.isDirectory ? MimeTypes.getExtension(rowItem.title) : null;
                    if (ext != null && ext.trim().length() != 0) {
                        holder.genericText.setText(ext);
                        holder.genericIcon.setImageDrawable(null);
                    // holder.genericIcon.setVisibility(View.INVISIBLE);
                    } else {
                        // we could not find the extension, set a generic file type icon probably a directory
                        modelProvider.getPreloadRequestBuilder(rowItem.iconData).into(holder.genericIcon);
                    }
                    break;
                case Icons.ENCRYPTED:
                    if (getBoolean(PREFERENCE_SHOW_THUMB)) {
                        holder.genericIcon.setVisibility(View.VISIBLE);
                        modelProvider.getPreloadRequestBuilder(rowItem.iconData).into(holder.genericIcon);
                    }
                    break;
                default:
                    holder.genericIcon.setVisibility(View.VISIBLE);
                    modelProvider.getPreloadRequestBuilder(rowItem.iconData).into(holder.genericIcon);
                    break;
            }
            if (utilsProvider.getAppTheme().equals(AppTheme.LIGHT)) {
                holder.rl.setBackgroundResource(R.drawable.safr_ripple_white);
            } else {
                holder.rl.setBackgroundResource(R.drawable.safr_ripple_black);
            }
            holder.rl.setSelected(false);
            if (itemsDigested.get(p).getChecked() == ListItem.CHECKED) {
                holder.checkImageView.setVisibility(View.VISIBLE);
                // so that user can still look at the thumbs even after selection
                if ((rowItem.filetype != Icons.IMAGE && rowItem.filetype != Icons.APK && rowItem.filetype != Icons.VIDEO)) {
                    holder.apkIcon.setVisibility(View.GONE);
                    holder.pictureIcon.setVisibility(View.GONE);
                    holder.genericIcon.setVisibility(View.VISIBLE);
                    GradientDrawable gradientDrawable = (GradientDrawable) holder.genericIcon.getBackground();
                    gradientDrawable.setColor(goBackColor);
                }
                holder.rl.setSelected(true);
            // holder.genericText.setText("");
            } else {
                holder.checkImageView.setVisibility(View.INVISIBLE);
                if (!rowItem.iconData.isImageBroken()) {
                    GradientDrawable gradientDrawable = (GradientDrawable) holder.genericIcon.getBackground();
                    if (getBoolean(PREFERENCE_COLORIZE_ICONS)) {
                        if (rowItem.isDirectory) {
                            gradientDrawable.setColor(iconSkinColor);
                        } else {
                            ColorUtils.colorizeIcons(context, rowItem.filetype, gradientDrawable, iconSkinColor);
                        }
                    } else
                        gradientDrawable.setColor(iconSkinColor);
                    if (isBackButton) {
                        gradientDrawable.setColor(goBackColor);
                    }
                }
            }
            if (getBoolean(PREFERENCE_SHOW_PERMISSIONS))
                holder.perm.setText(rowItem.permissions);
            if (getBoolean(PREFERENCE_SHOW_LAST_MODIFIED)) {
                holder.date.setText(rowItem.date1);
            } else {
                holder.date.setVisibility(View.GONE);
            }
            if (isBackButton) {
                holder.date.setText(rowItem.size);
                holder.txtDesc.setText("");
            } else if (getBoolean(PREFERENCE_SHOW_FILE_SIZE)) {
                holder.txtDesc.setText(rowItem.size);
            }
        } else {
            // view is a grid view
            holder.checkImageViewGrid.setColorFilter(accentColor);
            holder.rl.setOnClickListener(v -> {
                mainFrag.onListItemClicked(isBackButton, vholder.getAdapterPosition(), rowItem, holder.checkImageViewGrid);
            });
            holder.rl.setOnLongClickListener(p1 -> {
                if (!isBackButton) {
                    toggleChecked(vholder.getAdapterPosition(), holder.checkImageViewGrid);
                }
                return true;
            });
            holder.txtTitle.setText(rowItem.title);
            holder.imageView1.setVisibility(View.INVISIBLE);
            holder.genericIcon.setVisibility(View.VISIBLE);
            holder.checkImageViewGrid.setVisibility(View.INVISIBLE);
            ((RoundedImageView) holder.genericIcon).setRelativeSize(1.25f, 1.25f);
            GlideApp.with(mainFrag).load(rowItem.iconData.image).into(holder.genericIcon);
            if (rowItem.filetype == Icons.IMAGE || rowItem.filetype == Icons.VIDEO) {
                holder.imageView1.setVisibility(View.VISIBLE);
                holder.imageView1.setImageDrawable(null);
                if (utilsProvider.getAppTheme().equals(AppTheme.DARK) || utilsProvider.getAppTheme().equals(AppTheme.BLACK))
                    holder.imageView1.setBackgroundColor(Color.BLACK);
                showRoundedThumbnail(holder, rowItem.iconData, holder.imageView1, rowItem.iconData::setImageBroken);
            } else if (rowItem.filetype == Icons.APK) {
                showRoundedThumbnail(holder, rowItem.iconData, holder.genericIcon, rowItem.iconData::setImageBroken);
            }
            if (holder.genericIcon.getVisibility() == View.VISIBLE) {
                View iconBackground = getBoolean(PREFERENCE_USE_CIRCULAR_IMAGES) ? holder.genericIcon : holder.iconLayout;
                if (rowItem.isDirectory) {
                    iconBackground.setBackgroundColor(iconSkinColor);
                } else {
                    switch(rowItem.filetype) {
                        case Icons.VIDEO:
                            iconBackground.setBackgroundColor(videoColor);
                            break;
                        case Icons.AUDIO:
                            iconBackground.setBackgroundColor(audioColor);
                            break;
                        case Icons.PDF:
                            iconBackground.setBackgroundColor(pdfColor);
                            break;
                        case Icons.CODE:
                            iconBackground.setBackgroundColor(codeColor);
                            break;
                        case Icons.TEXT:
                            iconBackground.setBackgroundColor(textColor);
                            break;
                        case Icons.COMPRESSED:
                            iconBackground.setBackgroundColor(archiveColor);
                            break;
                        case Icons.NOT_KNOWN:
                            iconBackground.setBackgroundColor(genericColor);
                            break;
                        case Icons.APK:
                        case Icons.IMAGE:
                            // While these are loading or if they fail, color has to be set (done in showRoundedThumbnail()).
                            break;
                        default:
                            iconBackground.setBackgroundColor(iconSkinColor);
                            break;
                    }
                }
                if (isBackButton) {
                    iconBackground.setBackgroundColor(goBackColor);
                }
            }
            if (itemsDigested.get(p).getChecked() == ListItem.CHECKED) {
                if (holder.genericIcon.getVisibility() == View.VISIBLE) {
                    View iconBackground = getBoolean(PREFERENCE_USE_CIRCULAR_IMAGES) ? holder.genericIcon : holder.iconLayout;
                    iconBackground.setBackgroundColor(iconSkinColor);
                // holder.genericIcon.setImageDrawable(main.getResources().getDrawable(R.drawable.abc_ic_cab_done_holo_dark));
                }
                holder.checkImageViewGrid.setVisibility(View.VISIBLE);
                holder.rl.setBackgroundColor(Utils.getColor(context, R.color.item_background));
            } else {
                holder.checkImageViewGrid.setVisibility(View.INVISIBLE);
                if (utilsProvider.getAppTheme().equals(AppTheme.LIGHT))
                    holder.rl.setBackgroundResource(R.drawable.item_doc_grid);
                else {
                    holder.rl.setBackgroundResource(R.drawable.ic_grid_card_background_dark);
                    holder.rl.findViewById(R.id.icon_frame).setBackgroundColor(Utils.getColor(context, R.color.icon_background_dark));
                }
            }
            if (holder.about != null) {
                if (utilsProvider.getAppTheme().equals(AppTheme.LIGHT))
                    holder.about.setColorFilter(grey_color);
                showPopup(holder.about, rowItem, p);
            }
            if (getBoolean(PREFERENCE_SHOW_LAST_MODIFIED))
                holder.date.setText(rowItem.date1);
            if (isBackButton) {
                holder.date.setText(rowItem.size);
                holder.txtDesc.setText("");
            }
            /*else if(main.SHOW_SIZE)
                holder.txtDesc.setText(rowItem.getSize());
           */
            if (getBoolean(PREFERENCE_SHOW_PERMISSIONS))
                holder.perm.setText(rowItem.permissions);
        }
    }
}
Also used : RoundedImageView(com.amaze.filemanager.ui.views.RoundedImageView) LayoutElementParcelable(com.amaze.filemanager.adapters.data.LayoutElementParcelable) CircleGradientDrawable(com.amaze.filemanager.ui.views.CircleGradientDrawable) ItemViewHolder(com.amaze.filemanager.adapters.holders.ItemViewHolder) ImageView(android.widget.ImageView) View(android.view.View) RoundedImageView(com.amaze.filemanager.ui.views.RoundedImageView) RecyclerView(android.support.v7.widget.RecyclerView) CircleGradientDrawable(com.amaze.filemanager.ui.views.CircleGradientDrawable) GradientDrawable(android.graphics.drawable.GradientDrawable)

Example 2 with ItemViewHolder

use of com.amaze.filemanager.adapters.holders.ItemViewHolder in project AmazeFileManager by TeamAmaze.

the class RecyclerAdapter method onCreateViewHolder.

@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    View view;
    switch(viewType) {
        case TYPE_HEADER_FOLDERS:
        case TYPE_HEADER_FILES:
            if (mainFrag.IS_LIST) {
                view = mInflater.inflate(R.layout.list_header, parent, false);
            } else {
                view = mInflater.inflate(R.layout.grid_header, parent, false);
            }
            int type = viewType == TYPE_HEADER_FOLDERS ? SpecialViewHolder.HEADER_FOLDERS : SpecialViewHolder.HEADER_FILES;
            return new SpecialViewHolder(context, view, utilsProvider, type);
        case TYPE_ITEM:
            if (mainFrag.IS_LIST) {
                view = mInflater.inflate(R.layout.rowlayout, parent, false);
                sizeProvider.addView(VIEW_GENERIC, view.findViewById(R.id.generic_icon));
                sizeProvider.addView(VIEW_PICTURE, view.findViewById(R.id.picture_icon));
                sizeProvider.addView(VIEW_APK, view.findViewById(R.id.apk_icon));
            } else {
                view = mInflater.inflate(R.layout.griditem, parent, false);
                sizeProvider.addView(VIEW_GENERIC, view.findViewById(R.id.generic_icon));
                sizeProvider.addView(VIEW_THUMB, view.findViewById(R.id.icon_thumb));
            }
            sizeProvider.closeOffAddition();
            return new ItemViewHolder(view);
        case EMPTY_LAST_ITEM:
            int totalFabHeight = (int) context.getResources().getDimension(R.dimen.fab_height), marginFab = (int) context.getResources().getDimension(R.dimen.fab_margin);
            view = new View(context);
            view.setMinimumHeight(totalFabHeight + marginFab);
            return new EmptyViewHolder(view);
        default:
            throw new IllegalArgumentException("Illegal: " + viewType);
    }
}
Also used : SpecialViewHolder(com.amaze.filemanager.adapters.holders.SpecialViewHolder) EmptyViewHolder(com.amaze.filemanager.adapters.holders.EmptyViewHolder) ImageView(android.widget.ImageView) View(android.view.View) RoundedImageView(com.amaze.filemanager.ui.views.RoundedImageView) RecyclerView(android.support.v7.widget.RecyclerView) ItemViewHolder(com.amaze.filemanager.adapters.holders.ItemViewHolder)

Aggregations

RecyclerView (android.support.v7.widget.RecyclerView)2 View (android.view.View)2 ImageView (android.widget.ImageView)2 ItemViewHolder (com.amaze.filemanager.adapters.holders.ItemViewHolder)2 RoundedImageView (com.amaze.filemanager.ui.views.RoundedImageView)2 GradientDrawable (android.graphics.drawable.GradientDrawable)1 LayoutElementParcelable (com.amaze.filemanager.adapters.data.LayoutElementParcelable)1 EmptyViewHolder (com.amaze.filemanager.adapters.holders.EmptyViewHolder)1 SpecialViewHolder (com.amaze.filemanager.adapters.holders.SpecialViewHolder)1 CircleGradientDrawable (com.amaze.filemanager.ui.views.CircleGradientDrawable)1