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()));
}
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);
}
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());
}
}
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();
}
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);
}
Aggregations