Search in sources :

Example 1 with GalleryActivity

use of com.dar.nclientv2.GalleryActivity in project NClientV2 by Dar9586.

the class ListAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(@NonNull final GenericAdapter.ViewHolder holder, int position) {
    if (position >= mDataset.size())
        return;
    final SimpleGallery ent = mDataset.get(holder.getBindingAdapterPosition());
    if (ent == null)
        return;
    if (!Global.showTitles()) {
        holder.title.setAlpha(0f);
        holder.flag.setAlpha(0f);
    } else {
        holder.title.setAlpha(1f);
        holder.flag.setAlpha(1f);
    }
    if (context instanceof GalleryActivity) {
        CardView card = (CardView) holder.layout.getParent();
        ViewGroup.LayoutParams params = card.getLayoutParams();
        params.width = Global.getGalleryWidth();
        params.height = Global.getGalleryHeight();
        card.setLayoutParams(params);
    }
    holder.overlay.setVisibility((queryString != null && ent.hasIgnoredTags(queryString)) ? View.VISIBLE : View.GONE);
    loadGallery(holder, ent);
    holder.pages.setVisibility(View.GONE);
    holder.title.setText(ent.getTitle());
    holder.flag.setVisibility(View.VISIBLE);
    if (Global.getOnlyLanguage() == Language.ALL || context instanceof GalleryActivity) {
        holder.flag.setText(Global.getLanguageFlag(ent.getLanguage()));
    } else
        holder.flag.setVisibility(View.GONE);
    holder.title.setOnClickListener(v -> {
        Layout layout = holder.title.getLayout();
        if (Build.VERSION.SDK_INT > Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) {
            if (layout.getEllipsisCount(layout.getLineCount() - 1) > 0)
                holder.title.setMaxLines(7);
            else if (holder.title.getMaxLines() == 7)
                holder.title.setMaxLines(3);
            else
                holder.layout.performClick();
        } else
            holder.layout.performClick();
    });
    holder.layout.setOnClickListener(v -> {
        /*Intent intent = new Intent(context, GalleryActivity.class);
              intent.putExtra(context.getPackageName() + ".ID", ent.getId());
              context.startActivity(intent);*/
        if (context instanceof MainActivity)
            ((MainActivity) context).setIdOpenedGallery(ent.getId());
        downloadGallery(ent);
        holder.overlay.setVisibility((queryString != null && ent.hasIgnoredTags(queryString)) ? View.VISIBLE : View.GONE);
    });
    holder.overlay.setOnClickListener(v -> holder.overlay.setVisibility(View.GONE));
    holder.layout.setOnLongClickListener(v -> {
        holder.title.animate().alpha(holder.title.getAlpha() == 0f ? 1f : 0f).setDuration(100).start();
        holder.flag.animate().alpha(holder.flag.getAlpha() == 0f ? 1f : 0f).setDuration(100).start();
        holder.pages.animate().alpha(holder.pages.getAlpha() == 0f ? 1f : 0f).setDuration(100).start();
        return true;
    });
    int statusColor = statuses.get(ent.getId(), 0);
    if (statusColor == 0) {
        statusColor = Queries.StatusMangaTable.getStatus(ent.getId()).color;
        statuses.put(ent.getId(), statusColor);
    }
    holder.title.setBackgroundColor(statusColor);
}
Also used : SimpleGallery(com.dar.nclientv2.api.SimpleGallery) Layout(android.text.Layout) ViewGroup(android.view.ViewGroup) CardView(androidx.cardview.widget.CardView) GalleryActivity(com.dar.nclientv2.GalleryActivity) MainActivity(com.dar.nclientv2.MainActivity)

Aggregations

Layout (android.text.Layout)1 ViewGroup (android.view.ViewGroup)1 CardView (androidx.cardview.widget.CardView)1 GalleryActivity (com.dar.nclientv2.GalleryActivity)1 MainActivity (com.dar.nclientv2.MainActivity)1 SimpleGallery (com.dar.nclientv2.api.SimpleGallery)1