diff --git a/app/src/main/java/com/hippo/drawable/UnikeryDrawable.java b/app/src/main/java/com/hippo/drawable/UnikeryDrawable.java index e5b0b2d8b..7813168d5 100644 --- a/app/src/main/java/com/hippo/drawable/UnikeryDrawable.java +++ b/app/src/main/java/com/hippo/drawable/UnikeryDrawable.java @@ -11,7 +11,7 @@ import com.hippo.ehviewer.R; public class UnikeryDrawable extends WrapDrawable implements Unikery { - private int mTaskId; + private int mTaskId = Unikery.INVAILD_ID; private View mView; diff --git a/app/src/main/java/com/hippo/ehviewer/client/data/GalleryDetail.java b/app/src/main/java/com/hippo/ehviewer/client/data/GalleryDetail.java index 270154aaa..09a600843 100644 --- a/app/src/main/java/com/hippo/ehviewer/client/data/GalleryDetail.java +++ b/app/src/main/java/com/hippo/ehviewer/client/data/GalleryDetail.java @@ -18,10 +18,10 @@ package com.hippo.ehviewer.client.data; import java.util.List; -// TODO not extends GalleryInfo -public class GalleryDetail extends GalleryInfo { +public class GalleryDetail { public int gid; + public String token; public String thumb; public String title; public String titleJpn; diff --git a/app/src/main/java/com/hippo/ehviewer/client/data/GalleryInfo.java b/app/src/main/java/com/hippo/ehviewer/client/data/GalleryInfo.java index f431a0992..9caffc132 100644 --- a/app/src/main/java/com/hippo/ehviewer/client/data/GalleryInfo.java +++ b/app/src/main/java/com/hippo/ehviewer/client/data/GalleryInfo.java @@ -16,12 +16,9 @@ package com.hippo.ehviewer.client.data; -import android.os.Parcel; -import android.os.Parcelable; - import java.util.regex.Pattern; -public class GalleryInfo implements Parcelable { +public class GalleryInfo { /** * ISO 639-1 @@ -98,63 +95,10 @@ public class GalleryInfo implements Parcelable { */ public String simpleLanguage; - public static final Creator CREATOR = - new Creator() { - @Override - public GalleryInfo createFromParcel(Parcel source) { - GalleryInfo p = new GalleryInfo(); - p.gid = source.readInt(); - p.token = source.readString(); - p.title = source.readString(); - p.posted = source.readString(); - p.category = source.readInt(); - p.thumb = source.readString(); - p.uploader = source.readString(); - p.rating = source.readFloat(); - p.simpleLanguage = source.readString(); - return p; - } - - @Override - public GalleryInfo[] newArray(int size) { - return new GalleryInfo[size]; - } - }; - - @Override - public int describeContents() { - return 0; - } - - @Override - public void writeToParcel(Parcel dest, int flags) { - dest.writeInt(gid); - dest.writeString(token); - dest.writeString(title); - dest.writeString(posted); - dest.writeInt(category); - dest.writeString(thumb); - dest.writeString(uploader); - dest.writeFloat(rating); - dest.writeString(simpleLanguage); - } - public GalleryInfo() { // Empty } - public GalleryInfo(GalleryInfo gi) { - gid = gi.gid; - token = gi.token; - title = gi.title; - posted = gi.posted; - category = gi.category; - thumb = gi.thumb; - uploader = gi.uploader; - rating = gi.rating; - simpleLanguage = gi.simpleLanguage; - } - @Override public boolean equals(Object o) { return o instanceof GalleryInfo && ((GalleryInfo) o).gid == gid; diff --git a/app/src/main/java/com/hippo/ehviewer/client/data/LargePreviewSet.java b/app/src/main/java/com/hippo/ehviewer/client/data/LargePreviewSet.java index 00be19447..de4cb1d1f 100644 --- a/app/src/main/java/com/hippo/ehviewer/client/data/LargePreviewSet.java +++ b/app/src/main/java/com/hippo/ehviewer/client/data/LargePreviewSet.java @@ -50,8 +50,11 @@ public class LargePreviewSet extends PreviewSet { final Item item = mItemList.get(i); final int index = i + getStartIndex(); final ViewGroup viewGroup = (ViewGroup) simpleGridLayout.getChildAt(i); - conaco.load((LoadImageView) viewGroup.getChildAt(0), - EhImageKeyFactory.getLargePreviewKey(getGid(), index), item.imageUrl); + + LoadImageView imageView = ((LoadImageView) viewGroup.getChildAt(0)); + imageView.setRetryType(LoadImageView.RetryType.LONG_CLICK); + imageView.load(conaco, EhImageKeyFactory.getLargePreviewKey(getGid(), index), item.imageUrl); + ((TextView) viewGroup.getChildAt(1)).setText(Integer.toString(index + 1)); } } @@ -61,7 +64,7 @@ public class LargePreviewSet extends PreviewSet { int count = simpleGridLayout.getChildCount(); for (int i = 0; i < count; i++) { final ViewGroup viewGroup = (ViewGroup) simpleGridLayout.getChildAt(i); - conaco.cancel((LoadImageView) viewGroup.getChildAt(0)); + ((LoadImageView) viewGroup.getChildAt(0)).cancel(); } } diff --git a/app/src/main/java/com/hippo/ehviewer/client/data/LofiGalleryInfo.java b/app/src/main/java/com/hippo/ehviewer/client/data/LofiGalleryInfo.java index 80c79da86..9e104389b 100644 --- a/app/src/main/java/com/hippo/ehviewer/client/data/LofiGalleryInfo.java +++ b/app/src/main/java/com/hippo/ehviewer/client/data/LofiGalleryInfo.java @@ -16,65 +16,7 @@ package com.hippo.ehviewer.client.data; -import android.os.Parcel; - public class LofiGalleryInfo extends GalleryInfo { public String[] lofiTags; - - public static final Creator CREATOR = - new Creator() { - @Override - public LofiGalleryInfo createFromParcel(Parcel source) { - int length; - - LofiGalleryInfo p = new LofiGalleryInfo(); - p.gid = source.readInt(); - p.token = source.readString(); - p.title = source.readString(); - p.posted = source.readString(); - p.category = source.readInt(); - p.thumb = source.readString(); - p.uploader = source.readString(); - p.rating = source.readFloat(); - p.simpleLanguage = source.readString(); - - length = source.readInt(); - p.lofiTags = new String[length]; - for (int i = 0; i < length; i++) - p.lofiTags[i] = source.readString(); - - return p; - } - - @Override - public LofiGalleryInfo[] newArray(int size) { - return new LofiGalleryInfo[size]; - } - }; - - public LofiGalleryInfo() {} - - public LofiGalleryInfo(GalleryInfo galleryInfo) { - gid = galleryInfo.gid; - token = galleryInfo.token; - title = galleryInfo.title; - posted = galleryInfo.posted; - category = galleryInfo.category; - thumb = galleryInfo.thumb; - uploader = galleryInfo.uploader; - rating = galleryInfo.rating; - simpleLanguage = galleryInfo.simpleLanguage; - lofiTags = new String[0]; - } - - @Override - public void writeToParcel(Parcel dest, int flags) { - super.writeToParcel(dest, flags); - - int length = lofiTags == null ? 0 : lofiTags.length; - dest.writeInt(length); - for (int i = 0; i < length; i++) - dest.writeString(lofiTags[i]); - } } diff --git a/app/src/main/java/com/hippo/ehviewer/client/data/NormalPreviewSet.java b/app/src/main/java/com/hippo/ehviewer/client/data/NormalPreviewSet.java index c04f8d713..e5fb984fd 100644 --- a/app/src/main/java/com/hippo/ehviewer/client/data/NormalPreviewSet.java +++ b/app/src/main/java/com/hippo/ehviewer/client/data/NormalPreviewSet.java @@ -23,6 +23,7 @@ import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.Drawable; import android.graphics.drawable.TransitionDrawable; import android.view.LayoutInflater; +import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; import android.widget.TextView; @@ -31,6 +32,7 @@ import com.hippo.conaco.BitmapHolder; import com.hippo.conaco.Conaco; import com.hippo.conaco.Unikery; import com.hippo.ehviewer.EhImageKeyFactory; +import com.hippo.ehviewer.R; import com.hippo.util.Log; import com.hippo.widget.SimpleGridLayout; @@ -81,7 +83,7 @@ public class NormalPreviewSet extends PreviewSet { i++; } - LoadImageTask loadImageTask = new LoadImageTask(row, imageViews); + LoadImageTask loadImageTask = new LoadImageTask(conaco, row, imageViews); mLoadImageTasks.add(loadImageTask); String key; @@ -96,19 +98,32 @@ public class NormalPreviewSet extends PreviewSet { @Override public void cancelLoadTask(SimpleGridLayout simpleGridLayout, Conaco conaco) { + // Cancel load task for (LoadImageTask loadImageTask : mLoadImageTasks) { conaco.cancel(loadImageTask); } mLoadImageTasks.clear(); + + //Cancel long click + int count = simpleGridLayout.getChildCount(); + for (int i = 0; i < count; i++) { + ViewGroup viewGroup = (ViewGroup) simpleGridLayout.getChildAt(i); + View view = viewGroup.getChildAt(0); + view.setOnLongClickListener(null); + view.setLongClickable(false); + } } class LoadImageTask implements Unikery { - private int mTaskId; + private int mTaskId = Unikery.INVAILD_ID; + + private Conaco mConaco; private Row mRow; private ImageView[] mImageViews; - public LoadImageTask(Row row, ImageView[] imageViews) { + public LoadImageTask(Conaco conaco, Row row, ImageView[] imageViews) { + mConaco = conaco; mRow = row; mImageViews = imageViews; } @@ -175,8 +190,14 @@ public class NormalPreviewSet extends PreviewSet { @Override public void onFailure() { - // TODO mLoadImageTasks.remove(this); + + // Add long click to retry + RetryTask retryTask = new RetryTask(mConaco, mRow, mImageViews); + for (ImageView imageView : mImageViews) { + imageView.setImageResource(R.drawable.retry_load_image); + imageView.setOnLongClickListener(retryTask); + } } @Override @@ -185,6 +206,41 @@ public class NormalPreviewSet extends PreviewSet { } } + class RetryTask implements View.OnLongClickListener { + + private Conaco mConaco; + private Row mRow; + private ImageView[] mImageViews; + + public RetryTask(Conaco conaco, Row row, ImageView[] imageViews) { + mConaco = conaco; + mRow = row; + mImageViews = imageViews; + } + + @Override + public boolean onLongClick(View v) { + for (ImageView imageView : mImageViews) { + imageView.setImageDrawable(null); + imageView.setOnLongClickListener(null); + imageView.setLongClickable(false); + } + + LoadImageTask loadImageTask = new LoadImageTask(mConaco, mRow, mImageViews); + mLoadImageTasks.add(loadImageTask); + + String key; + if (mRow.imageIndex != -1) { + key = EhImageKeyFactory.getNormalPreviewKey(getGid(), mRow.imageIndex); + } else { + key = mRow.imageUrl; + } + mConaco.load(loadImageTask, key, mRow.imageUrl); + + return true; + } + } + class Row { public String imageUrl; diff --git a/app/src/main/java/com/hippo/ehviewer/ui/scene/CommentScene.java b/app/src/main/java/com/hippo/ehviewer/ui/scene/CommentScene.java index b7560aab6..53c0cfe70 100644 --- a/app/src/main/java/com/hippo/ehviewer/ui/scene/CommentScene.java +++ b/app/src/main/java/com/hippo/ehviewer/ui/scene/CommentScene.java @@ -24,15 +24,24 @@ import java.util.List; public class CommentScene extends AppbarScene { + public static final String KEY_COMMENTS = "key_comments"; + private EasyRecyclerView mRecyclerView; - private CommentAdapter mAdapter; private List mCommentList; + @SuppressWarnings("unchecked") private void handleAnnouncer(Announcer announcer) { - if (announcer != null) { - mCommentList = (List) announcer.getObject(); - mAdapter.notifyDataSetChanged(); + if (announcer == null) { + finish(); + return; + } + + Object obj = announcer.getExtra(KEY_COMMENTS); + if (obj instanceof List) { + mCommentList = (List) obj; + } else { + finish(); } } @@ -49,8 +58,8 @@ public class CommentScene extends AppbarScene { mRecyclerView = (EasyRecyclerView) findViewById(R.id.recycler_view); - mAdapter = new CommentAdapter(); - mRecyclerView.setAdapter(mAdapter); + CommentAdapter adapter = new CommentAdapter(); + mRecyclerView.setAdapter(adapter); mRecyclerView.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false)); LinearDividerItemDecoration decoration = new LinearDividerItemDecoration( LinearDividerItemDecoration.VERTICAL, resources.getColor(R.color.divider_light), @@ -70,13 +79,6 @@ public class CommentScene extends AppbarScene { handleAnnouncer(getAnnouncer()); } - @Override - protected void onRestore() { - super.onRestore(); - - // mCommentList is already setted, nothing to do - } - @Override public void onIconClick() { finish(); diff --git a/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryDetailScene.java b/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryDetailScene.java index 46ab2df5a..025f2bfdb 100644 --- a/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryDetailScene.java +++ b/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryDetailScene.java @@ -53,7 +53,6 @@ import com.hippo.rippleold.RippleSalon; import com.hippo.scene.Announcer; import com.hippo.scene.RippleCurtain; import com.hippo.scene.Scene; -import com.hippo.scene.SimpleCurtain; import com.hippo.scene.SimpleDialog; import com.hippo.util.Log; import com.hippo.util.URLImageGetter; @@ -69,7 +68,14 @@ import static com.hippo.ehviewer.R.id.no_tags; public class GalleryDetailScene extends Scene implements View.OnClickListener, AccurateClick.OnAccurateClickListener { - public static final String KEY_GALLERY_INFO = "gallery_info"; + public static final String ACTION_GALLERY_INFO = "action_gallery_info"; + public static final String ACTION_GID_TOKEN = "action_gid_token"; + public static final String ACTION_URL = "action_url"; + + public static final String KEY_GALLERY_INFO = "key_gallery_info"; + public static final String KEY_GID = "key_gid"; + public static final String KEY_TOKEN = "key_token"; + public static final String KEY_URL = "key_url"; private FrameLayout mDetailFrameLayout; @@ -116,63 +122,82 @@ public class GalleryDetailScene extends Scene implements View.OnClickListener, } private void handleAnnouncer(Announcer announcer) { - GalleryInfo gi; - if (announcer == null) { Log.e("No announcer in GalleryDetailScene, finish itself"); finish(); return; - } else if (null != (gi = announcer.getParcelableExtra(KEY_GALLERY_INFO))){ - Conaco conaco = EhApplication.getConaco(getStageActivity()); - conaco.load(mThumb, EhImageKeyFactory.getThumbKey(gi.gid), gi.thumb); - mTitle.setText(gi.title); - mUploader.setText(gi.uploader); - mCategory.setText(EhUtils.getCategory(gi.category)); - mCategory.setTextColor(EhUtils.getCategoryColor(gi.category)); - - requestGalleryDetail(gi); } - Context context = getStageActivity(); - Resources resources = context.getResources(); + String action = announcer.getAction(); + if (ACTION_GALLERY_INFO.equals(action)) { + Object obj = announcer.getExtra(KEY_GALLERY_INFO); + if (obj instanceof GalleryInfo) { + GalleryInfo gi = (GalleryInfo) obj; - mViewTransition.showView(1, false); + Conaco conaco = EhApplication.getConaco(getStageActivity()); + mThumb.load(conaco, EhImageKeyFactory.getThumbKey(gi.gid), gi.thumb); + mTitle.setText(gi.title); + mUploader.setText(gi.uploader); + mCategory.setText(EhUtils.getCategory(gi.category)); + mCategory.setTextColor(EhUtils.getCategoryColor(gi.category)); - mRatingText.setFactory(new RatingTextViewFactory()); - - Drawable favoriteDrawable = resources.getDrawable(R.drawable.ic_heart_theme_primary); - Drawable torrentDrawable = resources.getDrawable(R.drawable.ic_water_pump_theme_primary); - Drawable shareDrawable = resources.getDrawable(R.drawable.ic_share_theme_primary); - Drawable rateDrawable = resources.getDrawable(R.drawable.ic_thumbs_up_down_theme_primary); - - int drawableSize = resources.getDimensionPixelOffset(R.dimen.detail_action_size); - favoriteDrawable.setBounds(0, 0, drawableSize, drawableSize); - torrentDrawable.setBounds(0, 0, drawableSize, drawableSize); - shareDrawable.setBounds(0, 0, drawableSize, drawableSize); - rateDrawable.setBounds(0, 0, drawableSize, drawableSize); - - mFavorite.setCompoundDrawables(null, favoriteDrawable, null, null); - mTorrent.setCompoundDrawables(null, torrentDrawable, null, null); - mShare.setCompoundDrawables(null, shareDrawable, null, null); - mRate.setCompoundDrawables(null, rateDrawable, null, null); + requestGalleryDetail(gi); - mRead.setOnClickListener(this); - mDownload.setOnClickListener(this); - mFavorite.setOnClickListener(this); - mTorrent.setOnClickListener(this); - mShare.setOnClickListener(this); - mRate.setOnClickListener(this); + Context context = getStageActivity(); + Resources resources = context.getResources(); - AccurateClick.setOnAccurateClickListener(mInfo, this); - AccurateClick.setOnAccurateClickListener(mComment, this); + mViewTransition.showView(1, false); - RippleSalon.addRipple(mRead, false); - RippleSalon.addRipple(mDownload, false); - RippleSalon.addRipple(mFavorite, false); - RippleSalon.addRipple(mTorrent, false); - RippleSalon.addRipple(mShare, false); - RippleSalon.addRipple(mRate, false); + mRatingText.setFactory(new RatingTextViewFactory()); + + Drawable favoriteDrawable = resources.getDrawable(R.drawable.ic_heart_theme_primary); + Drawable torrentDrawable = resources.getDrawable(R.drawable.ic_water_pump_theme_primary); + Drawable shareDrawable = resources.getDrawable(R.drawable.ic_share_theme_primary); + Drawable rateDrawable = resources.getDrawable(R.drawable.ic_thumbs_up_down_theme_primary); + + int drawableSize = resources.getDimensionPixelOffset(R.dimen.detail_action_size); + favoriteDrawable.setBounds(0, 0, drawableSize, drawableSize); + torrentDrawable.setBounds(0, 0, drawableSize, drawableSize); + shareDrawable.setBounds(0, 0, drawableSize, drawableSize); + rateDrawable.setBounds(0, 0, drawableSize, drawableSize); + + mFavorite.setCompoundDrawables(null, favoriteDrawable, null, null); + mTorrent.setCompoundDrawables(null, torrentDrawable, null, null); + mShare.setCompoundDrawables(null, shareDrawable, null, null); + mRate.setCompoundDrawables(null, rateDrawable, null, null); + + + mRead.setOnClickListener(this); + mDownload.setOnClickListener(this); + mFavorite.setOnClickListener(this); + mTorrent.setOnClickListener(this); + mShare.setOnClickListener(this); + mRate.setOnClickListener(this); + + AccurateClick.setOnAccurateClickListener(mInfo, this); + AccurateClick.setOnAccurateClickListener(mComment, this); + + RippleSalon.addRipple(mRead, false); + RippleSalon.addRipple(mDownload, false); + RippleSalon.addRipple(mFavorite, false); + RippleSalon.addRipple(mTorrent, false); + RippleSalon.addRipple(mShare, false); + RippleSalon.addRipple(mRate, false); + + } else { + Log.e("Can't get GalleryDetail"); + finish(); + } + + } else if (ACTION_GID_TOKEN.equals(action)) { + + } else if (ACTION_URL.equals(action)) { + + } else { + Log.e("Unkonwn action " + action); + finish(); + } } @Override @@ -231,12 +256,7 @@ public class GalleryDetailScene extends Scene implements View.OnClickListener, return; } - if (v == mInfo) { - Announcer announcer = new Announcer(); - announcer.setObject(mGalleryDetail); - startScene(InfoScene.class, announcer, - new SimpleCurtain(SimpleCurtain.DIRECTION_RIGHT)); - } else if (v == mRead) { + if (v == mRead) { } else if (v == mDownload) { @@ -261,14 +281,14 @@ public class GalleryDetailScene extends Scene implements View.OnClickListener, int[] position = new int[2]; ViewUtils.getLocationInAncestor(mInfo, position, getSceneView()); Announcer announcer = new Announcer(); - announcer.setObject(mGalleryDetail); + announcer.putExtra(InfoScene.KEY_INFO, mGalleryDetail); startScene(InfoScene.class, announcer, new RippleCurtain((int) x + position[0], (int) y + position[1])); } else if (v == mComment) { int[] position = new int[2]; ViewUtils.getLocationInAncestor(mComment, position, getSceneView()); Announcer announcer = new Announcer(); - announcer.setObject(mGalleryDetail.comments); + announcer.putExtra(CommentScene.KEY_COMMENTS, mGalleryDetail.comments); startScene(CommentScene.class, announcer, new RippleCurtain((int) x + position[0], (int) y + position[1])); } diff --git a/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryListScene.java b/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryListScene.java index 70e9070e9..389934cb3 100644 --- a/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryListScene.java +++ b/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryListScene.java @@ -658,10 +658,8 @@ public final class GalleryListScene extends Scene implements SearchBar.Helper, show = true; } else if (recyclerView.computeVerticalScrollOffset() < mSearchBarOriginalBottom){ show = true; - } else if (mSearchBar.getBottom() > (mSearchBarOriginalBottom - mSearchBarOriginalTop) / 2) { - show = true; } else { - show = false; + show = mSearchBar.getBottom() > (mSearchBarOriginalBottom - mSearchBarOriginalTop) / 2; } } @@ -722,6 +720,7 @@ public final class GalleryListScene extends Scene implements SearchBar.Helper, public boolean onItemClick(EasyRecyclerView parent, View view, int position, long id) { GalleryInfo gi = mGalleryListHelper.getDataAt(position); Announcer announcer = new Announcer(); + announcer.setAction(GalleryDetailScene.ACTION_GALLERY_INFO); announcer.putExtra(GalleryDetailScene.KEY_GALLERY_INFO, gi); Curtain curtain = new TransitionCurtain(new TransitonHelper(position)); @@ -910,7 +909,7 @@ public final class GalleryListScene extends Scene implements SearchBar.Helper, GalleryInfo gi = getDataAt(position); Conaco conaco = EhApplication.getConaco(getStageActivity()); - conaco.load(holder.thumb, EhImageKeyFactory.getThumbKey(gi.gid), gi.thumb); + holder.thumb.load(conaco, EhImageKeyFactory.getThumbKey(gi.gid), gi.thumb); holder.title.setText(gi.title); holder.uploader.setText(gi.uploader); diff --git a/app/src/main/java/com/hippo/ehviewer/ui/scene/InfoScene.java b/app/src/main/java/com/hippo/ehviewer/ui/scene/InfoScene.java index a831e18ed..8137bf967 100644 --- a/app/src/main/java/com/hippo/ehviewer/ui/scene/InfoScene.java +++ b/app/src/main/java/com/hippo/ehviewer/ui/scene/InfoScene.java @@ -43,6 +43,8 @@ import java.util.List; public class InfoScene extends AppbarScene implements EasyRecyclerView.OnItemLongClickListener { + public static final String KEY_INFO = "key_info"; + private Resources mResources; private EasyRecyclerView mRecyclerView; @@ -103,10 +105,17 @@ public class InfoScene extends AppbarScene implements EasyRecyclerView.OnItemLon } private void handleAnnouncer(Announcer announcer) { - if (announcer != null) { - GalleryDetail gd = (GalleryDetail) announcer.getObject(); + if (announcer == null) { + finish(); + return; + } + + Object obj = announcer.getExtra(KEY_INFO); + if (obj instanceof GalleryDetail) { + GalleryDetail gd = (GalleryDetail) obj; addData(R.string.header_key, mResources.getString(R.string.header_value)); addData(R.string.key_gid, Integer.toString(gd.gid)); + addData(R.string.key_token, gd.token); addData(R.string.key_title, gd.title); addData(R.string.key_title_jpn, gd.titleJpn); addData(R.string.key_thumb, gd.thumb); diff --git a/app/src/main/java/com/hippo/ehviewer/widget/LoadImageView.java b/app/src/main/java/com/hippo/ehviewer/widget/LoadImageView.java index 2df81bb8f..f96fd4853 100644 --- a/app/src/main/java/com/hippo/ehviewer/widget/LoadImageView.java +++ b/app/src/main/java/com/hippo/ehviewer/widget/LoadImageView.java @@ -1,38 +1,143 @@ package com.hippo.ehviewer.widget; import android.content.Context; +import android.content.res.TypedArray; import android.graphics.Color; import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.Drawable; import android.graphics.drawable.TransitionDrawable; import android.util.AttributeSet; +import android.view.View; import com.hippo.conaco.BitmapHolder; import com.hippo.conaco.Conaco; import com.hippo.conaco.Unikery; +import com.hippo.ehviewer.R; import com.hippo.widget.FixedAspectImageView; -public class LoadImageView extends FixedAspectImageView implements Unikery { +public class LoadImageView extends FixedAspectImageView implements Unikery, + View.OnClickListener, View.OnLongClickListener { + + private static final int STATE_NONE = 0; + private static final int STATE_LOADING = 1; + private static final int STATE_LOADED = 2; + private static final int STATE_FAILURE = 3; + + private static final int RETRY_DRAWABLE = R.drawable.retry_load_image; private int mTaskId = Unikery.INVAILD_ID; + private int mState = STATE_NONE; + private BitmapHolder mBitmapHolder; + private Conaco mConaco; + private String mKey; + private String mUrl; + + private RetryType mRetryType = RetryType.NONE; + + private static final RetryType[] sRetryTypeArray = { + RetryType.NONE, + RetryType.CLICK, + RetryType.LONG_CLICK + }; + + public enum RetryType { + NONE (0), + CLICK (1), + LONG_CLICK (2); + + RetryType(int ni) { + nativeInt = ni; + } + final int nativeInt; + } + public LoadImageView(Context context) { super(context); } public LoadImageView(Context context, AttributeSet attrs) { super(context, attrs); + init(context, attrs); } public LoadImageView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); + init(context, attrs); + } + + private void init(Context context, AttributeSet attrs) { + TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.LoadImageView); + final int index = a.getInt(R.styleable.LoadImageView_retryType, -1); + if (index >= 0) { + setRetryType(sRetryTypeArray[index]); + } + a.recycle(); + } + + public void setRetryType(RetryType retryType) { + if (mRetryType != retryType) { + RetryType oldRetryType = mRetryType; + mRetryType = retryType; + + if (mState == STATE_FAILURE) { + if (oldRetryType == RetryType.CLICK) { + setOnClickListener(null); + setClickable(false); + } else if (oldRetryType == RetryType.LONG_CLICK) { + setOnLongClickListener(null); + setLongClickable(false); + } + + if (retryType == RetryType.CLICK) { + setOnClickListener(this); + } else if (retryType == RetryType.LONG_CLICK) { + setOnLongClickListener(this); + } + + if (oldRetryType != RetryType.NONE && retryType == RetryType.NONE) { + setImageDrawable(null); + } else if (oldRetryType == RetryType.NONE && retryType != RetryType.NONE) { + setImageResource(RETRY_DRAWABLE); + } + } + } + } + + public void load(Conaco conaco, String key, String url) { + mState = STATE_LOADING; + + mConaco = conaco; + mKey = key; + mUrl = url; + conaco.load(this, key, url); + } + + public void cancel() { + mState = STATE_NONE; + + if (mConaco != null) { + mConaco.cancel(this); + + // release + mConaco = null; + mKey = null; + mUrl = null; + } } @Override public void setBitmap(BitmapHolder bitmapHolder, Conaco.Source source) { + mState = STATE_LOADED; + + // release + mConaco = null; + mKey = null; + mUrl = null; + BitmapHolder oldBitmapHolder = mBitmapHolder; mBitmapHolder = bitmapHolder; @@ -55,6 +160,8 @@ public class LoadImageView extends FixedAspectImageView implements Unikery { @Override public void setDrawable(Drawable drawable) { + mState = STATE_NONE; + setImageDrawable(drawable); } @@ -70,11 +177,37 @@ public class LoadImageView extends FixedAspectImageView implements Unikery { @Override public void onFailure() { + mState = STATE_FAILURE; + if (mRetryType == RetryType.CLICK) { + setImageResource(RETRY_DRAWABLE); + setOnClickListener(this); + } else if (mRetryType == RetryType.LONG_CLICK) { + setImageResource(RETRY_DRAWABLE); + setOnLongClickListener(this); + } } @Override public void onCancel() { + // Empty, everything is done in cancel + } + @Override + public void onClick(View v) { + setOnClickListener(null); + setClickable(false); + + load(mConaco, mKey, mUrl); + } + + @Override + public boolean onLongClick(View v) { + setOnLongClickListener(null); + setLongClickable(false); + + load(mConaco, mKey, mUrl); + + return true; } } diff --git a/app/src/main/java/com/hippo/ehviewer/widget/PreviewLayout.java b/app/src/main/java/com/hippo/ehviewer/widget/PreviewLayout.java index 40e761484..b26376db1 100644 --- a/app/src/main/java/com/hippo/ehviewer/widget/PreviewLayout.java +++ b/app/src/main/java/com/hippo/ehviewer/widget/PreviewLayout.java @@ -110,9 +110,11 @@ public final class PreviewLayout extends LinearLayout implements View.OnClickLis } private boolean isLargePreview() { - for (PreviewSet previewSet : mPreviewSets) { - if (previewSet != null) { - return previewSet instanceof LargePreviewSet; + if (mPreviewSets != null) { + for (PreviewSet previewSet : mPreviewSets) { + if (previewSet != null) { + return previewSet instanceof LargePreviewSet; + } } } return false; diff --git a/app/src/main/java/com/hippo/scene/Announcer.java b/app/src/main/java/com/hippo/scene/Announcer.java index fc78013d3..0eb02a81e 100644 --- a/app/src/main/java/com/hippo/scene/Announcer.java +++ b/app/src/main/java/com/hippo/scene/Announcer.java @@ -16,354 +16,113 @@ package com.hippo.scene; -import android.os.Bundle; -import android.os.Parcelable; -import android.support.annotation.Nullable; +import java.util.HashMap; +import java.util.Map; -import java.io.Serializable; - -// TODO Do not copy Intent, set clone stuff and non-clone stuff public class Announcer { - private @Nullable Bundle mExtras; + private String mAction; - private Object mObject; + private Map mMap = new HashMap<>(); - public void setObject(Object object) { - mObject = object; + public void setAction(String action) { + mAction = action; } - public Object getObject() { - return mObject; + public String getAction() { + return mAction; } - public boolean getBooleanExtra(String name, boolean defaultValue) { - return mExtras == null ? defaultValue : - mExtras.getBoolean(name, defaultValue); + public void putExtra(String key, Object value) { + mMap.put(key, value); } - public byte getByteExtra(String name, byte defaultValue) { - return mExtras == null ? defaultValue : - mExtras.getByte(name, defaultValue); - } - - public short getShortExtra(String name, short defaultValue) { - return mExtras == null ? defaultValue : - mExtras.getShort(name, defaultValue); - } - - public char getCharExtra(String name, char defaultValue) { - return mExtras == null ? defaultValue : - mExtras.getChar(name, defaultValue); - } - - public int getIntExtra(String name, int defaultValue) { - return mExtras == null ? defaultValue : - mExtras.getInt(name, defaultValue); - } - - public long getLongExtra(String name, long defaultValue) { - return mExtras == null ? defaultValue : - mExtras.getLong(name, defaultValue); - } - - public float getFloatExtra(String name, float defaultValue) { - return mExtras == null ? defaultValue : - mExtras.getFloat(name, defaultValue); - } - - public double getDoubleExtra(String name, double defaultValue) { - return mExtras == null ? defaultValue : - mExtras.getDouble(name, defaultValue); - } - - public String getStringExtra(String name) { - return mExtras == null ? null : mExtras.getString(name); - } - - public CharSequence getCharSequenceExtra(String name) { - return mExtras == null ? null : mExtras.getCharSequence(name); - } - - public T getParcelableExtra(String name) { - return mExtras == null ? null : mExtras.getParcelable(name); - } - - public Parcelable[] getParcelableArrayExtra(String name) { - return mExtras == null ? null : mExtras.getParcelableArray(name); - } - - public Serializable getSerializableExtra(String name) { - return mExtras == null ? null : mExtras.getSerializable(name); - } - - public boolean[] getBooleanArrayExtra(String name) { - return mExtras == null ? null : mExtras.getBooleanArray(name); - } - - public byte[] getByteArrayExtra(String name) { - return mExtras == null ? null : mExtras.getByteArray(name); - } - - public short[] getShortArrayExtra(String name) { - return mExtras == null ? null : mExtras.getShortArray(name); - } - - public char[] getCharArrayExtra(String name) { - return mExtras == null ? null : mExtras.getCharArray(name); - } - - public int[] getIntArrayExtra(String name) { - return mExtras == null ? null : mExtras.getIntArray(name); - } - - public long[] getLongArrayExtra(String name) { - return mExtras == null ? null : mExtras.getLongArray(name); - } - - public float[] getFloatArrayExtra(String name) { - return mExtras == null ? null : mExtras.getFloatArray(name); - } - - public double[] getDoubleArrayExtra(String name) { - return mExtras == null ? null : mExtras.getDoubleArray(name); - } - - public String[] getStringArrayExtra(String name) { - return mExtras == null ? null : mExtras.getStringArray(name); - } - - public CharSequence[] getCharSequenceArrayExtra(String name) { - return mExtras == null ? null : mExtras.getCharSequenceArray(name); - } - - public Bundle getBundleExtra(String name) { - return mExtras == null ? null : mExtras.getBundle(name); - } - - public Bundle getExtras() { - return (mExtras != null) - ? new Bundle(mExtras) - : null; - } - - public Announcer putExtra(String name, boolean value) { - if (mExtras == null) { - mExtras = new Bundle(); + public boolean getBooleanExtra(String key, boolean defaultValue) { + Object obj = mMap.get(key); + if (obj instanceof Boolean) { + return (Boolean) obj; + } else { + return defaultValue; } - mExtras.putBoolean(name, value); - return this; } - public Announcer putExtra(String name, byte value) { - if (mExtras == null) { - mExtras = new Bundle(); + public byte getByteExtra(String key, byte defaultValue) { + Object obj = mMap.get(key); + if (obj instanceof Byte) { + return (Byte) obj; + } else { + return defaultValue; } - mExtras.putByte(name, value); - return this; } - public Announcer putExtra(String name, char value) { - if (mExtras == null) { - mExtras = new Bundle(); + public char getCharExtra(String key, char defaultValue) { + Object obj = mMap.get(key); + if (obj instanceof Character) { + return (Character) obj; + } else { + return defaultValue; } - mExtras.putChar(name, value); - return this; } - public Announcer putExtra(String name, short value) { - if (mExtras == null) { - mExtras = new Bundle(); + public short getShortExtra(String key, short defaultValue) { + Object obj = mMap.get(key); + if (obj instanceof Short) { + return (Short) obj; + } else { + return defaultValue; } - mExtras.putShort(name, value); - return this; } - public Announcer putExtra(String name, int value) { - if (mExtras == null) { - mExtras = new Bundle(); + public int getIntExtra(String key, int defaultValue) { + Object obj = mMap.get(key); + if (obj instanceof Integer) { + return (Integer) obj; + } else { + return defaultValue; } - mExtras.putInt(name, value); - return this; } - public Announcer putExtra(String name, long value) { - if (mExtras == null) { - mExtras = new Bundle(); + public long getLongExtra(String key, long defaultValue) { + Object obj = mMap.get(key); + if (obj instanceof Long) { + return (Long) obj; + } else { + return defaultValue; } - mExtras.putLong(name, value); - return this; } - public Announcer putExtra(String name, float value) { - if (mExtras == null) { - mExtras = new Bundle(); + public float getFloatExtra(String key, float defaultValue) { + Object obj = mMap.get(key); + if (obj instanceof Float) { + return (Float) obj; + } else { + return defaultValue; } - mExtras.putFloat(name, value); - return this; } - public Announcer putExtra(String name, double value) { - if (mExtras == null) { - mExtras = new Bundle(); + public double getDoubleExtra(String key, double defaultValue) { + Object obj = mMap.get(key); + if (obj instanceof Double) { + return (Double) obj; + } else { + return defaultValue; } - mExtras.putDouble(name, value); - return this; } - public Announcer putExtra(String name, String value) { - if (mExtras == null) { - mExtras = new Bundle(); + public String getStringExtra(String key, String defaultValue) { + Object obj = mMap.get(key); + if (obj instanceof String) { + return (String) obj; + } else { + return defaultValue; } - mExtras.putString(name, value); - return this; } - public Announcer putExtra(String name, CharSequence value) { - if (mExtras == null) { - mExtras = new Bundle(); - } - mExtras.putCharSequence(name, value); - return this; + public Object getExtra(String key) { + return mMap.get(key); } - public Announcer putExtra(String name, Parcelable value) { - if (mExtras == null) { - mExtras = new Bundle(); - } - mExtras.putParcelable(name, value); - return this; - } - - public Announcer putExtra(String name, Parcelable[] value) { - if (mExtras == null) { - mExtras = new Bundle(); - } - mExtras.putParcelableArray(name, value); - return this; - } - - public Announcer putExtra(String name, Serializable value) { - if (mExtras == null) { - mExtras = new Bundle(); - } - mExtras.putSerializable(name, value); - return this; - } - - public Announcer putExtra(String name, boolean[] value) { - if (mExtras == null) { - mExtras = new Bundle(); - } - mExtras.putBooleanArray(name, value); - return this; - } - - public Announcer putExtra(String name, byte[] value) { - if (mExtras == null) { - mExtras = new Bundle(); - } - mExtras.putByteArray(name, value); - return this; - } - - public Announcer putExtra(String name, short[] value) { - if (mExtras == null) { - mExtras = new Bundle(); - } - mExtras.putShortArray(name, value); - return this; - } - - public Announcer putExtra(String name, char[] value) { - if (mExtras == null) { - mExtras = new Bundle(); - } - mExtras.putCharArray(name, value); - return this; - } - - public Announcer putExtra(String name, int[] value) { - if (mExtras == null) { - mExtras = new Bundle(); - } - mExtras.putIntArray(name, value); - return this; - } - - public Announcer putExtra(String name, long[] value) { - if (mExtras == null) { - mExtras = new Bundle(); - } - mExtras.putLongArray(name, value); - return this; - } - - public Announcer putExtra(String name, float[] value) { - if (mExtras == null) { - mExtras = new Bundle(); - } - mExtras.putFloatArray(name, value); - return this; - } - - public Announcer putExtra(String name, double[] value) { - if (mExtras == null) { - mExtras = new Bundle(); - } - mExtras.putDoubleArray(name, value); - return this; - } - - public Announcer putExtra(String name, String[] value) { - if (mExtras == null) { - mExtras = new Bundle(); - } - mExtras.putStringArray(name, value); - return this; - } - - public Announcer putExtra(String name, CharSequence[] value) { - if (mExtras == null) { - mExtras = new Bundle(); - } - mExtras.putCharSequenceArray(name, value); - return this; - } - - public Announcer putExtra(String name, Bundle value) { - if (mExtras == null) { - mExtras = new Bundle(); - } - mExtras.putBundle(name, value); - return this; - } - - public Announcer putExtras(Announcer src) { - if (src.mExtras != null) { - if (mExtras == null) { - mExtras = new Bundle(src.mExtras); - } else { - mExtras.putAll(src.mExtras); - } - } - return this; - } - - public Announcer putExtras(Bundle extras) { - if (mExtras == null) { - mExtras = new Bundle(); - } - mExtras.putAll(extras); - return this; - } - - public void removeExtra(String name) { - if (mExtras != null) { - mExtras.remove(name); - if (mExtras.size() == 0) { - mExtras = null; - } - } + public void removeExtra(String key) { + mMap.remove(key); } } diff --git a/app/src/main/java/com/hippo/scene/SimpleDialogCurtain.java b/app/src/main/java/com/hippo/scene/SimpleDialogCurtain.java index 8c3c40e65..4855060a2 100644 --- a/app/src/main/java/com/hippo/scene/SimpleDialogCurtain.java +++ b/app/src/main/java/com/hippo/scene/SimpleDialogCurtain.java @@ -87,6 +87,9 @@ public class SimpleDialogCurtain extends Curtain { ViewUtils.setVisibility(cushion, View.INVISIBLE); ViewUtils.setVisibility(frame, View.INVISIBLE); + // TODO addOnGlobalLayoutListener is not reliable + // TODO use isLayoutRequested + // TODO if isLayoutRequested return false, try to use StageView Size frame.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { diff --git a/app/src/main/java/com/hippo/util/Utils.java b/app/src/main/java/com/hippo/util/Utils.java index 0033e3586..047597741 100644 --- a/app/src/main/java/com/hippo/util/Utils.java +++ b/app/src/main/java/com/hippo/util/Utils.java @@ -153,8 +153,8 @@ public final class Utils { * If you want to copy on new thread, use it to know * success or not. */ - public static interface OnCopyFileOverListener { - public void onCopyFileOver(boolean success, File src, File dst); + public interface OnCopyFileOverListener { + void onCopyFileOver(boolean success, File src, File dst); } /** @@ -214,8 +214,8 @@ public final class Utils { * If you want to copy on new thread, use it to know * success or not. */ - public static interface OnDeleteFileOverListener { - public void onDeleteFileOver(boolean success, File file); + public interface OnDeleteFileOverListener { + void onDeleteFileOver(boolean success, File file); } /** @@ -632,10 +632,7 @@ public final class Utils { if (area.length != 4) throw new IllegalArgumentException( "area's length should be 4, but it's length is " + area.length); - if (x >= area[0] && x < area[2] && y >= area[1] && y < area[3]) - return true; - else - return false; + return x >= area[0] && x < area[2] && y >= area[1] && y < area[3]; } /** diff --git a/app/src/main/res/drawable/retry_load_image.xml b/app/src/main/res/drawable/retry_load_image.xml new file mode 100644 index 000000000..4f8d5cb14 --- /dev/null +++ b/app/src/main/res/drawable/retry_load_image.xml @@ -0,0 +1,40 @@ + + + + + + + diff --git a/app/src/main/res/layout/item_gallery_list_detail.xml b/app/src/main/res/layout/item_gallery_list_detail.xml index a26cc6c0f..917cb53e9 100644 --- a/app/src/main/res/layout/item_gallery_list_detail.xml +++ b/app/src/main/res/layout/item_gallery_list_detail.xml @@ -28,7 +28,8 @@ + android:layout_height="@dimen/list_thumb_height" + auto:retryType="click"/> + + + + + + + + diff --git a/app/src/main/res/values/pathdata.xml b/app/src/main/res/values/pathdata.xml index c26b0e3b8..f3d794395 100644 --- a/app/src/main/res/values/pathdata.xml +++ b/app/src/main/res/values/pathdata.xml @@ -40,5 +40,6 @@ M22.5,10.5H15.75C15.13,10.5 14.6,10.88 14.37,11.41L12.11,16.7C12.04,16.87 12,17.06 12,17.25V18.5A1,1 0 0,0 13,19.5H18.18L17.5,22.68V22.92C17.5,23.23 17.63,23.5 17.83,23.72L18.62,24.5L23.56,19.56C23.83,19.29 24,18.91 24,18.5V12A1.5,1.5 0 0,0 22.5,10.5M12,6.5A1,1 0 0,0 11,5.5H5.82L6.5,2.32V2.09C6.5,1.78 6.37,1.5 6.17,1.29L5.38,0.5L0.44,5.44C0.17,5.71 0,6.09 0,6.5V13A1.5,1.5 0 0,0 1.5,14.5H8.25C8.87,14.5 9.4,14.12 9.63,13.59L11.89,8.3C11.96,8.13 12,7.94 12,7.75V6.5Z M15.41,16.58L10.83,12L15.41,7.41L14,6L8,12L14,18L15.41,16.58Z M8.59,16.58L13.17,12L8.59,7.41L10,6L16,12L10,18L8.59,16.58Z + M13,9H18.5L13,3.5V9M6,2H14L20,8V20A2,2 0 0,1 18,22H6C4.89,22 4,21.1 4,20V4C4,2.89 4.89,2 6,2M6,20H15L18,20V12L14,16L12,14L6,20M8,9A2,2 0 0,0 6,11A2,2 0 0,0 8,13A2,2 0 0,0 10,11A2,2 0 0,0 8,9Z diff --git a/conaco b/conaco index 4c3d08bc9..3e65839be 160000 --- a/conaco +++ b/conaco @@ -1 +1 @@ -Subproject commit 4c3d08bc939463d0e1bfcdcf1c104946c87cfc05 +Subproject commit 3e65839beeaee1b79aedc606ab46f2dcb5ca456e