Show heart icon if the gallery is favourited
This commit is contained in:
1 parent
303c51f93d
commit
c08068eeea
8 files changed
+165
-37
No files matched your search
@@ -40,7 +40,6 @@ public class GalleryDetail extends GalleryInfo {
|
||||
public GalleryComment[] comments;
|
||||
public int previewPages;
|
||||
public PreviewSet previewSet;
|
||||
public String favoriteName;
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
@@ -65,7 +64,6 @@ public class GalleryDetail extends GalleryInfo {
|
||||
dest.writeParcelableArray(this.comments, 0);
|
||||
dest.writeInt(this.previewPages);
|
||||
dest.writeParcelable(previewSet, flags);
|
||||
dest.writeString(this.favoriteName);
|
||||
}
|
||||
|
||||
public GalleryDetail() {
|
||||
@@ -98,7 +96,6 @@ public class GalleryDetail extends GalleryInfo {
|
||||
}
|
||||
this.previewPages = in.readInt();
|
||||
this.previewSet = in.readParcelable(PreviewSet.class.getClassLoader());
|
||||
this.favoriteName = in.readString();
|
||||
}
|
||||
|
||||
public static final Creator<GalleryDetail> CREATOR = new Creator<GalleryDetail>() {
|
||||
|
||||
@@ -104,6 +104,7 @@ public class GalleryInfo implements Parcelable {
|
||||
public String posted;
|
||||
public String uploader;
|
||||
public float rating;
|
||||
public boolean rated;
|
||||
@Nullable
|
||||
public String[] simpleTags;
|
||||
public int pages;
|
||||
@@ -120,7 +121,8 @@ public class GalleryInfo implements Parcelable {
|
||||
*/
|
||||
public String simpleLanguage;
|
||||
|
||||
public boolean rated;
|
||||
public int favoriteSlot = -2;
|
||||
public String favoriteName;
|
||||
|
||||
public final void generateSLang() {
|
||||
if (simpleTags != null) {
|
||||
@@ -168,6 +170,7 @@ public class GalleryInfo implements Parcelable {
|
||||
dest.writeString(this.posted);
|
||||
dest.writeString(this.uploader);
|
||||
dest.writeFloat(this.rating);
|
||||
dest.writeByte(this.rated ? (byte) 1 : (byte) 0);
|
||||
dest.writeString(this.simpleLanguage);
|
||||
dest.writeStringArray(this.simpleTags);
|
||||
dest.writeInt(this.thumbWidth);
|
||||
@@ -175,6 +178,8 @@ public class GalleryInfo implements Parcelable {
|
||||
dest.writeInt(this.spanSize);
|
||||
dest.writeInt(this.spanIndex);
|
||||
dest.writeInt(this.spanGroupIndex);
|
||||
dest.writeInt(this.favoriteSlot);
|
||||
dest.writeString(this.favoriteName);
|
||||
}
|
||||
|
||||
public GalleryInfo() {}
|
||||
@@ -189,6 +194,7 @@ public class GalleryInfo implements Parcelable {
|
||||
this.posted = in.readString();
|
||||
this.uploader = in.readString();
|
||||
this.rating = in.readFloat();
|
||||
this.rated = in.readByte() != 0;
|
||||
this.simpleLanguage = in.readString();
|
||||
this.simpleTags = in.createStringArray();
|
||||
this.thumbWidth = in.readInt();
|
||||
@@ -196,6 +202,8 @@ public class GalleryInfo implements Parcelable {
|
||||
this.spanSize = in.readInt();
|
||||
this.spanIndex = in.readInt();
|
||||
this.spanGroupIndex = in.readInt();
|
||||
this.favoriteSlot = in.readInt();
|
||||
this.favoriteName = in.readString();
|
||||
}
|
||||
|
||||
public static final Parcelable.Creator<GalleryInfo> CREATOR = new Parcelable.Creator<GalleryInfo>() {
|
||||
|
||||
@@ -19,6 +19,7 @@ package com.hippo.ehviewer.client.parser;
|
||||
import android.util.Log;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import com.hippo.ehviewer.EhDB;
|
||||
import com.hippo.ehviewer.client.EhUtils;
|
||||
import com.hippo.ehviewer.client.data.GalleryInfo;
|
||||
import com.hippo.ehviewer.client.exception.ParseException;
|
||||
@@ -42,6 +43,7 @@ public class GalleryListParser {
|
||||
|
||||
private static final Pattern PATTERN_RATING = Pattern.compile("\\d+px");
|
||||
private static final Pattern PATTERN_THUMB_SIZE = Pattern.compile("height:(\\d+)px; width:(\\d+)px");
|
||||
private static final Pattern PATTERN_FAVORITE_SLOT = Pattern.compile("background-position:0px -(\\d+)px;");
|
||||
|
||||
public static class Result {
|
||||
public int pages;
|
||||
@@ -176,6 +178,24 @@ public class GalleryListParser {
|
||||
Log.w(TAG, "Can't parse gallery info uploader");
|
||||
gi.uploader = "";
|
||||
}
|
||||
// Favourite
|
||||
Element it3 = JsoupUtils.getElementByClass(e, "it3");
|
||||
if (it3 != null) {
|
||||
for (Element element : it3.children()) {
|
||||
if (!"i".equals(element.className())) {
|
||||
continue;
|
||||
}
|
||||
Matcher m = PATTERN_FAVORITE_SLOT.matcher(element.attr("style"));
|
||||
if (m.find()) {
|
||||
gi.favoriteSlot = (NumberUtils.parseIntSafely(m.group(1), -36) - 2) / 19;
|
||||
gi.favoriteName = element.attr("title");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (gi.favoriteSlot == -2) {
|
||||
gi.favoriteSlot = EhDB.containLocalFavorites(gi.gid) ? -1 : -2;
|
||||
}
|
||||
|
||||
gi.generateSLang();
|
||||
|
||||
@@ -233,6 +253,29 @@ public class GalleryListParser {
|
||||
gi.rating = -1.0f;
|
||||
}
|
||||
|
||||
// Rating
|
||||
Element id44 = JsoupUtils.getElementByClass(e, "id44");
|
||||
if (id44 != null) {
|
||||
Elements elements = id44.children();
|
||||
if (elements.size() > 0) {
|
||||
Element first = elements.first();
|
||||
for (Element element : first.children()) {
|
||||
if (!"i".equals(element.className())) {
|
||||
continue;
|
||||
}
|
||||
Matcher m = PATTERN_FAVORITE_SLOT.matcher(element.attr("style"));
|
||||
if (m.find()) {
|
||||
gi.favoriteSlot = (NumberUtils.parseIntSafely(m.group(1), -36) - 2) / 19;
|
||||
gi.favoriteName = element.attr("title");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (gi.favoriteSlot == -2) {
|
||||
gi.favoriteSlot = EhDB.containLocalFavorites(gi.gid) ? -1 : -2;
|
||||
}
|
||||
|
||||
gi.generateSLang();
|
||||
|
||||
return gi;
|
||||
|
||||
@@ -19,10 +19,10 @@ package com.hippo.ehviewer.ui.scene;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Build;
|
||||
import android.text.TextUtils;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
import androidx.annotation.IntDef;
|
||||
import androidx.annotation.NonNull;
|
||||
@@ -191,23 +191,32 @@ abstract class GalleryAdapter extends RecyclerView.Adapter<GalleryHolder> {
|
||||
holder.rating.setRating(gi.rating);
|
||||
TextView category = holder.category;
|
||||
String newCategoryText = EhUtils.getCategory(gi.category);
|
||||
if (!newCategoryText.equals(category.getText())) {
|
||||
if (!newCategoryText.equals(category.getText().toString())) {
|
||||
category.setText(newCategoryText);
|
||||
category.setBackgroundColor(EhUtils.getCategoryColor(gi.category));
|
||||
}
|
||||
holder.posted.setText(gi.posted);
|
||||
if (gi.pages == 0 || !Settings.getShowGalleryPages()) {
|
||||
holder.pages.setText(null);
|
||||
RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) holder.simpleLanguage.getLayoutParams();
|
||||
lp.addRule(RelativeLayout.LEFT_OF, 0);
|
||||
lp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
|
||||
holder.pages.setVisibility(View.GONE);
|
||||
} else {
|
||||
holder.pages.setText(Integer.toString(gi.pages) + "P");
|
||||
RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) holder.simpleLanguage.getLayoutParams();
|
||||
lp.addRule(RelativeLayout.LEFT_OF, R.id.pages);
|
||||
lp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, 0);
|
||||
holder.pages.setVisibility(View.VISIBLE);
|
||||
}
|
||||
if (TextUtils.isEmpty(gi.simpleLanguage)) {
|
||||
holder.simpleLanguage.setText(null);
|
||||
holder.simpleLanguage.setVisibility(View.GONE);
|
||||
} else {
|
||||
holder.simpleLanguage.setText(gi.simpleLanguage);
|
||||
holder.simpleLanguage.setVisibility(View.VISIBLE);
|
||||
}
|
||||
if (gi.favoriteSlot < -1 || gi.favoriteSlot > 10) {
|
||||
holder.favouriteSlot.setImageDrawable(null);
|
||||
holder.favouriteSlot.setVisibility(View.GONE);
|
||||
} else {
|
||||
holder.favouriteSlot.setImageResource(R.drawable.v_heart_x16);
|
||||
holder.favouriteSlot.setVisibility(View.VISIBLE);
|
||||
}
|
||||
holder.simpleLanguage.setText(gi.simpleLanguage);
|
||||
break;
|
||||
}
|
||||
case TYPE_GRID: {
|
||||
|
||||
@@ -18,6 +18,7 @@ package com.hippo.ehviewer.ui.scene;
|
||||
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
import androidx.appcompat.widget.AppCompatImageView;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.widget.SimpleRatingView;
|
||||
@@ -33,17 +34,19 @@ class GalleryHolder extends RecyclerView.ViewHolder {
|
||||
public final TextView posted;
|
||||
public final TextView pages;
|
||||
public final TextView simpleLanguage;
|
||||
public final AppCompatImageView favouriteSlot;
|
||||
|
||||
public GalleryHolder(View itemView) {
|
||||
super(itemView);
|
||||
|
||||
thumb = (LoadImageView) itemView.findViewById(R.id.thumb);
|
||||
title = (TextView) itemView.findViewById(R.id.title);
|
||||
uploader = (TextView) itemView.findViewById(R.id.uploader);
|
||||
rating = (SimpleRatingView) itemView.findViewById(R.id.rating);
|
||||
category = (TextView) itemView.findViewById(R.id.category);
|
||||
posted = (TextView) itemView.findViewById(R.id.posted);
|
||||
pages = (TextView) itemView.findViewById(R.id.pages);
|
||||
simpleLanguage = (TextView) itemView.findViewById(R.id.simple_language);
|
||||
thumb = itemView.findViewById(R.id.thumb);
|
||||
title = itemView.findViewById(R.id.title);
|
||||
uploader = itemView.findViewById(R.id.uploader);
|
||||
rating = itemView.findViewById(R.id.rating);
|
||||
category = itemView.findViewById(R.id.category);
|
||||
posted = itemView.findViewById(R.id.posted);
|
||||
pages = itemView.findViewById(R.id.pages);
|
||||
simpleLanguage = itemView.findViewById(R.id.simple_language);
|
||||
favouriteSlot = itemView.findViewById(R.id.favourite_slot);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user