Show an icon if the gallery is downloaded

This commit is contained in:
seven332 committed 2019-02-23 17:04:17 +08:00
1 parent c08068eeea
commit 6c253238ad
7 files changed
+63 -12

No files matched your search

@@ -356,6 +356,11 @@ public class EhApplication extends RecordingApplication {
return application.mSpiderInfoCache;
}
@NonNull
public static DownloadManager getDownloadManager() {
return getDownloadManager(instance);
}
@NonNull
public static DownloadManager getDownloadManager(@NonNull Context context) {
EhApplication application = ((EhApplication) context.getApplicationContext());
@@ -124,6 +124,8 @@ public class GalleryInfo implements Parcelable {
public int favoriteSlot = -2;
public String favoriteName;
public boolean downloaded;
public final void generateSLang() {
if (simpleTags != null) {
generateSLangFromTags();
@@ -180,6 +182,7 @@ public class GalleryInfo implements Parcelable {
dest.writeInt(this.spanGroupIndex);
dest.writeInt(this.favoriteSlot);
dest.writeString(this.favoriteName);
dest.writeByte(this.downloaded ? (byte) 1 : (byte) 0);
}
public GalleryInfo() {}
@@ -204,6 +207,7 @@ public class GalleryInfo implements Parcelable {
this.spanGroupIndex = in.readInt();
this.favoriteSlot = in.readInt();
this.favoriteName = in.readString();
this.downloaded = in.readByte() != 0;
}
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.EhApplication;
import com.hippo.ehviewer.EhDB;
import com.hippo.ehviewer.client.EhUtils;
import com.hippo.ehviewer.client.data.GalleryInfo;
@@ -196,6 +197,8 @@ public class GalleryListParser {
if (gi.favoriteSlot == -2) {
gi.favoriteSlot = EhDB.containLocalFavorites(gi.gid) ? -1 : -2;
}
// Downloaded
gi.downloaded = EhApplication.getDownloadManager().containDownloadInfo(gi.gid);
gi.generateSLang();
@@ -276,6 +279,9 @@ public class GalleryListParser {
gi.favoriteSlot = EhDB.containLocalFavorites(gi.gid) ? -1 : -2;
}
// Downloaded
gi.downloaded = EhApplication.getDownloadManager().containDownloadInfo(gi.gid);
gi.generateSLang();
return gi;
@@ -210,13 +210,8 @@ abstract class GalleryAdapter extends RecyclerView.Adapter<GalleryHolder> {
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.favourited.setVisibility((gi.favoriteSlot >= -1 && gi.favoriteSlot <= 10) ? View.VISIBLE : View.GONE);
holder.downloaded.setVisibility(gi.downloaded ? View.VISIBLE : View.GONE);
break;
}
case TYPE_GRID: {
@@ -17,8 +17,8 @@
package com.hippo.ehviewer.ui.scene;
import android.view.View;
import android.widget.ImageView;
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;
@@ -34,7 +34,8 @@ class GalleryHolder extends RecyclerView.ViewHolder {
public final TextView posted;
public final TextView pages;
public final TextView simpleLanguage;
public final AppCompatImageView favouriteSlot;
public final ImageView favourited;
public final ImageView downloaded;
public GalleryHolder(View itemView) {
super(itemView);
@@ -47,6 +48,7 @@ class GalleryHolder extends RecyclerView.ViewHolder {
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);
favourited = itemView.findViewById(R.id.favourited);
downloaded = itemView.findViewById(R.id.downloaded);
}
}