Show heart icon if the gallery is favourited

This commit is contained in:
seven332 committed 2019-02-23 16:23:14 +08:00
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);
}
}
+28
View File
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright 2019 Hippo Seven
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<size
android:width="6dp"
android:height="6dp"/>
<solid android:color="@android:color/transparent"/>
</shape>
+29
View File
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright 2019 Hippo Seven
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<vector
xmlns:android="http://schemas.android.com/apk/res/android"
android:height="16dp"
android:width="16dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="?android:attr/textColorSecondary"
android:pathData="@string/pd_heart"/>
</vector>
+27 -16
View File
@@ -87,23 +87,34 @@
android:layout_marginRight="6dp"
android:layout_marginBottom="4dp"/>
<TextView
android:id="@+id/pages"
style="@style/CardMessage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@id/posted"
android:layout_alignParentRight="true"
android:layout_marginRight="6dp"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@id/posted"
android:layout_alignParentRight="true"
android:layout_marginRight="6dp"
android:orientation="horizontal"
android:divider="@drawable/spacer_x6"
android:showDividers="middle"
android:gravity="center_vertical">
<TextView
android:id="@+id/simple_language"
style="@style/CardMessage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@id/posted"
android:layout_toLeftOf="@+id/pages"
android:layout_marginRight="6dp"/>
<ImageView
android:id="@+id/favourite_slot"
android:layout_width="16dp"
android:layout_height="16dp"/>
<TextView
android:id="@+id/simple_language"
style="@style/CardMessage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:id="@+id/pages"
style="@style/CardMessage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
</RelativeLayout>
</androidx.cardview.widget.CardView>