Search in sources :

Example 1 with AuthorViewHolder

use of com.foobnix.ui2.adapter.AuthorsAdapter2.AuthorViewHolder in project LibreraReader by foobnix.

the class FileMetaAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(final RecyclerView.ViewHolder holderAll, final int position) {
    final FileMeta fileMeta = getItem(position);
    if (holderAll instanceof StarsTitleViewHolder) {
        final StarsTitleViewHolder holder = (StarsTitleViewHolder) holderAll;
        if (holder.clearAllFolders != null) {
            TxtUtils.underlineTextView(holder.clearAllFolders).setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    clearAllStarredFolders.run();
                }
            });
        }
        if (holder.clearAllBooks != null) {
            TxtUtils.underlineTextView(holder.clearAllBooks).setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    clearAllStarredBooks.run();
                }
            });
        }
        if (holder.onGridList != null) {
            PopupHelper.updateGridOrListIcon(holder.onGridList, AppState.get().starsMode);
            holder.onGridList.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    onGridOrList.onResultRecive(holder.onGridList);
                }
            });
        }
        TintUtil.setBackgroundFillColor(holder.parent, TintUtil.color);
    }
    if (holderAll instanceof FileMetaViewHolder) {
        final FileMetaViewHolder holder = (FileMetaViewHolder) holderAll;
        if (!AppState.get().isShowImages && adapterType == ADAPTER_COVERS) {
            adapterType = ADAPTER_GRID;
        }
        bindFileMetaView(holder, position);
        IMG.getCoverPageWithEffect(holder.image, fileMeta.getPath(), IMG.getImageSize(), new SimpleImageLoadingListener() {

            @Override
            public void onLoadingCancelled(String imageUri, View view) {
                super.onLoadingCancelled(imageUri, view);
            }

            @Override
            public void onLoadingStarted(String imageUri, View view) {
                super.onLoadingStarted(imageUri, view);
            }

            @Override
            public void onLoadingComplete(String arg0, View arg1, Bitmap arg2) {
                if (position <= items.size() - 1) {
                    FileMeta it = AppDB.get().load(fileMeta.getPath());
                    if (it != null) {
                        items.set(position, it);
                        bindFileMetaView(holder, position);
                    }
                }
            }
        });
        holder.imageParent.setVisibility(AppState.get().isShowImages ? View.VISIBLE : View.GONE);
    } else if (holderAll instanceof TagViewHolder) {
        final TagViewHolder holder = (TagViewHolder) holderAll;
        holder.title.setText(fileMeta.getPathTxt());
        TintUtil.setTintImageWithAlpha(holder.image);
        bindItemClickAndLongClickListeners(holder.parent, fileMeta);
    } else if (holderAll instanceof DirectoryViewHolder) {
        final DirectoryViewHolder holder = (DirectoryViewHolder) holderAll;
        holder.title.setText(fileMeta.getPathTxt());
        holder.path.setText(fileMeta.getPath());
        TintUtil.setTintImageWithAlpha(holder.image, holder.image.getContext() instanceof MainTabs2 ? TintUtil.getColorInDayNighth() : TintUtil.getColorInDayNighthBook());
        bindItemClickAndLongClickListeners(holder.parent, fileMeta);
        if (!AppState.get().isBorderAndShadow) {
            holder.parent.setBackgroundColor(Color.TRANSPARENT);
        }
        if (AppDB.get().isStarFolder(fileMeta.getPath())) {
            holder.starIcon.setImageResource(R.drawable.star_1);
        } else {
            holder.starIcon.setImageResource(R.drawable.star_2);
        }
        TintUtil.setTintImageWithAlpha(holder.starIcon, holder.starIcon.getContext() instanceof MainTabs2 ? TintUtil.getColorInDayNighth() : TintUtil.getColorInDayNighthBook());
        if (onStarClickListener != null) {
            holder.starIcon.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    onStarClickListener.onResultRecive(fileMeta, FileMetaAdapter.this);
                }
            });
        }
        holder.starIcon.setVisibility(ExtUtils.isExteralSD(fileMeta.getPath()) ? View.GONE : View.VISIBLE);
        if (adapterType == ADAPTER_GRID || adapterType == ADAPTER_COVERS) {
            // holder.image.setVisibility(View.GONE);
            holder.path.setVisibility(View.GONE);
        } else {
            // holder.image.setVisibility(View.VISIBLE);
            if (tempValue == TEMP_VALUE_FOLDER_PATH) {
                holder.path.setVisibility(View.VISIBLE);
            } else {
                holder.path.setVisibility(View.GONE);
            }
        }
    } else if (holderAll instanceof StarsLayoutViewHolder) {
        final StarsLayoutViewHolder holder = (StarsLayoutViewHolder) holderAll;
        final FileMetaAdapter adapter = new FileMetaAdapter();
        adapter.setOnItemClickListener(onItemClickListener);
        adapter.setOnItemLongClickListener(onItemLongClickListener);
        adapter.setOnMenuClickListener(onMenuClickListener);
        adapter.setOnStarClickListener(onStarClickListener);
        adapter.setOnAuthorClickListener(onAuthorClickListener);
        adapter.setOnSeriesClickListener(onSeriesClickListener);
        adapter.setAdapterType(FileMetaAdapter.ADAPTER_GRID);
        adapter.tempValue = TEMP_VALUE_STAR_GRID_ITEM;
        holder.recyclerView.setAdapter(adapter);
        adapter.getItemsList().clear();
        TintUtil.setBackgroundFillColor(holder.panelRecent, TintUtil.color);
        TintUtil.setBackgroundFillColor(holder.panelStars, TintUtil.color);
        List<FileMeta> allStars = AppDB.get().getStarsFiles();
        final String STARRED = holder.starredName.getContext().getString(R.string.starred).toUpperCase(Locale.US) + " (" + allStars.size() + ")";
        holder.recentName.setText(holder.starredName.getContext().getString(R.string.recent) + " (" + (getItemCount() - 1) + ")");
        holder.starredNameIcon.setImageResource(R.drawable.star_1);
        TintUtil.setTintImageNoAlpha(holder.starredNameIcon, Color.WHITE);
        TxtUtils.underlineTextView(holder.starredName);
        holder.starredName.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(final View v) {
                MyPopupMenu menu = new MyPopupMenu(v.getContext(), v);
                menu.getMenu().add(STARRED).setIcon(R.drawable.star_1).setOnMenuItemClickListener(new OnMenuItemClickListener() {

                    @Override
                    public boolean onMenuItemClick(MenuItem item) {
                        AppState.get().recentTag = "";
                        holder.starredNameIcon.setImageResource(R.drawable.star_1);
                        TintUtil.setTintImageNoAlpha(holder.starredNameIcon, Color.WHITE);
                        TxtUtils.underline(holder.starredName, STARRED);
                        adapter.getItemsList().clear();
                        List<FileMeta> allStars = AppDB.get().getStarsFiles();
                        adapter.getItemsList().addAll(allStars);
                        adapter.notifyDataSetChanged();
                        return false;
                    }
                });
                List<String> tags = AppDB.get().getAll(SEARCH_IN.TAGS);
                Collections.sort(tags);
                for (final String tag : tags) {
                    int count = AppDB.get().getAllWithTag(tag).size();
                    final String nameName = tag + " (" + count + ")";
                    menu.getMenu().add(nameName).setIcon(R.drawable.glyphicons_67_tags).setOnMenuItemClickListener(new OnMenuItemClickListener() {

                        @Override
                        public boolean onMenuItemClick(MenuItem item) {
                            AppState.get().recentTag = tag;
                            holder.starredNameIcon.setImageResource(R.drawable.glyphicons_67_tags);
                            TintUtil.setTintImageNoAlpha(holder.starredNameIcon, Color.WHITE);
                            TxtUtils.underline(holder.starredName, nameName);
                            adapter.getItemsList().clear();
                            List<FileMeta> allTags = AppDB.get().searchBy("@tags " + tag, SORT_BY.FILE_NAME, false);
                            adapter.getItemsList().addAll(allTags);
                            adapter.notifyDataSetChanged();
                            return false;
                        }
                    });
                }
                menu.show();
            }
        });
        if (TxtUtils.isEmpty(AppState.get().recentTag)) {
            holder.starredNameIcon.setImageResource(R.drawable.star_1);
            TintUtil.setTintImageNoAlpha(holder.starredNameIcon, Color.WHITE);
            TxtUtils.underline(holder.starredName, STARRED);
            adapter.getItemsList().clear();
            adapter.getItemsList().addAll(allStars);
            adapter.notifyDataSetChanged();
        } else {
            holder.starredNameIcon.setImageResource(R.drawable.glyphicons_67_tags);
            TintUtil.setTintImageNoAlpha(holder.starredNameIcon, Color.WHITE);
            adapter.getItemsList().clear();
            List<FileMeta> allTags = AppDB.get().searchBy("@tags " + AppState.get().recentTag, SORT_BY.FILE_NAME, false);
            adapter.getItemsList().addAll(allTags);
            adapter.notifyDataSetChanged();
            TxtUtils.underline(holder.starredName, AppState.get().recentTag + " (" + allTags.size() + ")");
        }
    } else if (holderAll instanceof AuthorViewHolder) {
        AuthorViewHolder aHolder = (AuthorViewHolder) holderAll;
        aHolder.onBindViewHolder(aHolder, fileMeta.getSequence());
        aHolder.parent.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                if (onSeriesClickListener != null) {
                    onSeriesClickListener.onResultRecive(fileMeta.getSequence());
                }
            }
        });
    }
}
Also used : MainTabs2(com.foobnix.ui2.MainTabs2) OnMenuItemClickListener(android.view.MenuItem.OnMenuItemClickListener) MyPopupMenu(com.foobnix.pdf.info.view.MyPopupMenu) MenuItem(android.view.MenuItem) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) SimpleImageLoadingListener(com.nostra13.universalimageloader.core.listener.SimpleImageLoadingListener) Bitmap(android.graphics.Bitmap) AuthorViewHolder(com.foobnix.ui2.adapter.AuthorsAdapter2.AuthorViewHolder) OnClickListener(android.view.View.OnClickListener) List(java.util.List) FileMeta(com.foobnix.dao2.FileMeta)

Aggregations

Bitmap (android.graphics.Bitmap)1 RecyclerView (android.support.v7.widget.RecyclerView)1 MenuItem (android.view.MenuItem)1 OnMenuItemClickListener (android.view.MenuItem.OnMenuItemClickListener)1 View (android.view.View)1 OnClickListener (android.view.View.OnClickListener)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 FileMeta (com.foobnix.dao2.FileMeta)1 MyPopupMenu (com.foobnix.pdf.info.view.MyPopupMenu)1 MainTabs2 (com.foobnix.ui2.MainTabs2)1 AuthorViewHolder (com.foobnix.ui2.adapter.AuthorsAdapter2.AuthorViewHolder)1 SimpleImageLoadingListener (com.nostra13.universalimageloader.core.listener.SimpleImageLoadingListener)1 List (java.util.List)1