Search in sources :

Example 1 with SimpleGallery

use of com.dar.nclientv2.api.SimpleGallery in project NClientV2 by Dar9586.

the class ListAdapter method addGalleries.

public void addGalleries(List<GenericGallery> galleries) {
    int c = mDataset.size();
    for (GenericGallery g : galleries) {
        mDataset.add((SimpleGallery) g);
        LogUtility.d("Simple: " + g);
    }
    LogUtility.d(String.format(Locale.US, "%s,old:%d,new:%d,len%d", this, c, mDataset.size(), galleries.size()));
    context.runOnUiThread(() -> notifyItemRangeInserted(c, galleries.size()));
}
Also used : GenericGallery(com.dar.nclientv2.api.components.GenericGallery)

Example 2 with SimpleGallery

use of com.dar.nclientv2.api.SimpleGallery 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)

Example 3 with SimpleGallery

use of com.dar.nclientv2.api.SimpleGallery in project NClientV2 by Dar9586.

the class DownloadGalleryV2 method downloadGallery.

public static void downloadGallery(Context context, GenericGallery gallery) {
    if (gallery.isValid() && gallery instanceof Gallery)
        downloadGallery(context, (Gallery) gallery);
    if (gallery.getId() > 0) {
        if (gallery instanceof SimpleGallery) {
            SimpleGallery simple = (SimpleGallery) gallery;
            downloadGallery(context, gallery.getTitle(), simple.getThumbnail(), simple.getId());
        } else
            downloadGallery(context, null, null, gallery.getId());
    }
}
Also used : SimpleGallery(com.dar.nclientv2.api.SimpleGallery) SimpleGallery(com.dar.nclientv2.api.SimpleGallery) Gallery(com.dar.nclientv2.api.components.Gallery) GenericGallery(com.dar.nclientv2.api.components.GenericGallery)

Example 4 with SimpleGallery

use of com.dar.nclientv2.api.SimpleGallery in project NClientV2 by Dar9586.

the class ListAdapter method downloadGallery.

private void downloadGallery(final SimpleGallery ent) {
    InspectorV3.galleryInspector(context, ent.getId(), new InspectorV3.DefaultInspectorResponse() {

        @Override
        public void onFailure(Exception e) {
            super.onFailure(e);
            File file = Global.findGalleryFolder(context, ent.getId());
            if (file != null) {
                LocalAdapter.startGallery(context, file);
            } else if (context.getMasterLayout() != null) {
                context.runOnUiThread(() -> {
                    Snackbar snackbar = Snackbar.make(context.getMasterLayout(), R.string.unable_to_connect_to_the_site, Snackbar.LENGTH_SHORT);
                    snackbar.setAction(R.string.retry, v -> downloadGallery(ent));
                    snackbar.show();
                });
            }
        }

        @Override
        public void onSuccess(List<GenericGallery> galleries) {
            if (galleries.size() != 1) {
                if (context.getMasterLayout() != null) {
                    context.runOnUiThread(() -> Snackbar.make(context.getMasterLayout(), R.string.no_entry_found, Snackbar.LENGTH_SHORT).show());
                }
                return;
            }
            Intent intent = new Intent(context, GalleryActivity.class);
            LogUtility.d(galleries.get(0).toString());
            intent.putExtra(context.getPackageName() + ".GALLERY", galleries.get(0));
            context.runOnUiThread(() -> context.startActivity(intent));
        }
    }).start();
}
Also used : SparseIntArray(android.util.SparseIntArray) NonNull(androidx.annotation.NonNull) SimpleGallery(com.dar.nclientv2.api.SimpleGallery) BaseActivity(com.dar.nclientv2.components.activities.BaseActivity) LogUtility(com.dar.nclientv2.utility.LogUtility) Intent(android.content.Intent) ArrayList(java.util.ArrayList) GenericGallery(com.dar.nclientv2.api.components.GenericGallery) MainActivity(com.dar.nclientv2.MainActivity) TagV2(com.dar.nclientv2.settings.TagV2) GalleryActivity(com.dar.nclientv2.GalleryActivity) ImageDownloadUtility(com.dar.nclientv2.utility.ImageDownloadUtility) Locale(java.util.Locale) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) Build(android.os.Build) Language(com.dar.nclientv2.api.enums.Language) CardView(androidx.cardview.widget.CardView) Global(com.dar.nclientv2.settings.Global) LayoutInflater(android.view.LayoutInflater) R(com.dar.nclientv2.R) ViewGroup(android.view.ViewGroup) File(java.io.File) List(java.util.List) Layout(android.text.Layout) Snackbar(com.google.android.material.snackbar.Snackbar) InspectorV3(com.dar.nclientv2.api.InspectorV3) Queries(com.dar.nclientv2.async.database.Queries) ArrayList(java.util.ArrayList) List(java.util.List) Intent(android.content.Intent) File(java.io.File) Snackbar(com.google.android.material.snackbar.Snackbar)

Example 5 with SimpleGallery

use of com.dar.nclientv2.api.SimpleGallery in project NClientV2 by Dar9586.

the class ListAdapter method restartDataset.

public void restartDataset(List<GenericGallery> galleries) {
    /*int c=mDataset.size();
        if(c>0) {
            mDataset.clear();
            context.runOnUiThread(() -> notifyItemRangeRemoved(0, c));
        }
        mDataset.addAll(galleries);
        context.runOnUiThread(()->notifyItemRangeInserted(0,galleries.size()));*/
    mDataset.clear();
    for (GenericGallery g : galleries) if (g instanceof SimpleGallery)
        mDataset.add((SimpleGallery) g);
    context.runOnUiThread(this::notifyDataSetChanged);
}
Also used : SimpleGallery(com.dar.nclientv2.api.SimpleGallery) GenericGallery(com.dar.nclientv2.api.components.GenericGallery)

Aggregations

SimpleGallery (com.dar.nclientv2.api.SimpleGallery)4 GenericGallery (com.dar.nclientv2.api.components.GenericGallery)4 Layout (android.text.Layout)2 ViewGroup (android.view.ViewGroup)2 CardView (androidx.cardview.widget.CardView)2 GalleryActivity (com.dar.nclientv2.GalleryActivity)2 MainActivity (com.dar.nclientv2.MainActivity)2 Intent (android.content.Intent)1 Build (android.os.Build)1 SparseIntArray (android.util.SparseIntArray)1 LayoutInflater (android.view.LayoutInflater)1 View (android.view.View)1 NonNull (androidx.annotation.NonNull)1 RecyclerView (androidx.recyclerview.widget.RecyclerView)1 R (com.dar.nclientv2.R)1 InspectorV3 (com.dar.nclientv2.api.InspectorV3)1 Gallery (com.dar.nclientv2.api.components.Gallery)1 Language (com.dar.nclientv2.api.enums.Language)1 Queries (com.dar.nclientv2.async.database.Queries)1 BaseActivity (com.dar.nclientv2.components.activities.BaseActivity)1