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);
}
}
@@ -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_download"/>
</vector>
+12 -2
View File
@@ -88,6 +88,7 @@
android:layout_marginBottom="4dp"/>
<LinearLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@id/posted"
@@ -99,9 +100,18 @@
android:gravity="center_vertical">
<ImageView
android:id="@+id/favourite_slot"
android:id="@+id/downloaded"
android:layout_width="16dp"
android:layout_height="16dp"/>
android:layout_height="16dp"
android:visibility="gone"
app:srcCompat="@drawable/v_download_x16"/>
<ImageView
android:id="@+id/favourited"
android:layout_width="16dp"
android:layout_height="16dp"
android:visibility="gone"
app:srcCompat="@drawable/v_heart_x16"/>
<TextView
android:id="@+id/simple_language"