mirror of
https://github.com/mihonapp/mihon.git
synced 2024-12-24 18:08:24 +01:00
Enable tiling to webtoon reader and add a fade in animation
This commit is contained in:
parent
737d3d4282
commit
8000d67871
@ -4,6 +4,8 @@ import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.animation.Animation;
|
||||
import android.view.animation.AnimationUtils;
|
||||
import android.widget.ProgressBar;
|
||||
|
||||
import com.davemorrissey.labs.subscaleview.ImageSource;
|
||||
@ -21,13 +23,11 @@ public class WebtoonAdapter extends RecyclerView.Adapter<WebtoonAdapter.ImageHol
|
||||
|
||||
private List<Page> pages;
|
||||
private WebtoonReader fragment;
|
||||
private int maxBitmapSize;
|
||||
private View.OnTouchListener listener;
|
||||
|
||||
public WebtoonAdapter(WebtoonReader fragment) {
|
||||
this.fragment = fragment;
|
||||
pages = new ArrayList<>();
|
||||
maxBitmapSize = fragment.getReaderActivity().getMaxBitmapSize();
|
||||
listener = (v, event) -> fragment.onImageTouch(event);
|
||||
}
|
||||
|
||||
@ -39,7 +39,7 @@ public class WebtoonAdapter extends RecyclerView.Adapter<WebtoonAdapter.ImageHol
|
||||
public ImageHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
LayoutInflater inflater = fragment.getActivity().getLayoutInflater();
|
||||
View v = inflater.inflate(R.layout.item_webtoon_reader, parent, false);
|
||||
return new ImageHolder(v, maxBitmapSize, listener);
|
||||
return new ImageHolder(v, listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -63,24 +63,31 @@ public class WebtoonAdapter extends RecyclerView.Adapter<WebtoonAdapter.ImageHol
|
||||
@Bind(R.id.page_image_view) SubsamplingScaleImageView imageView;
|
||||
@Bind(R.id.progress) ProgressBar progressBar;
|
||||
|
||||
public ImageHolder(View view, int maxBitmapSize, View.OnTouchListener listener) {
|
||||
private Animation fadeInAnimation;
|
||||
|
||||
public ImageHolder(View view, View.OnTouchListener listener) {
|
||||
super(view);
|
||||
ButterKnife.bind(this, view);
|
||||
|
||||
fadeInAnimation = AnimationUtils.loadAnimation(view.getContext(), R.anim.fade_in);
|
||||
|
||||
imageView.setParallelLoadingEnabled(true);
|
||||
imageView.setDoubleTapZoomStyle(SubsamplingScaleImageView.ZOOM_FOCUS_FIXED);
|
||||
imageView.setPanLimit(SubsamplingScaleImageView.PAN_LIMIT_INSIDE);
|
||||
imageView.setMinimumScaleType(SubsamplingScaleImageView.SCALE_TYPE_CENTER_INSIDE);
|
||||
imageView.setZoomEnabled(false);
|
||||
imageView.setPanEnabled(false);
|
||||
imageView.setOnTouchListener(listener);
|
||||
// TODO Using tiling here is annoying. RecyclerView isn't good at all for a webtoon reader
|
||||
// imageView.setMaxDimensions(maxBitmapSize, maxBitmapSize);
|
||||
imageView.setOnImageEventListener(new SubsamplingScaleImageView.DefaultOnImageEventListener() {
|
||||
@Override
|
||||
public void onImageLoaded() {
|
||||
imageView.startAnimation(fadeInAnimation);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void onSetValues(Page page) {
|
||||
if (page.getImagePath() != null) {
|
||||
imageView.setVisibility(View.VISIBLE);
|
||||
imageView.setImage(ImageSource.uri(page.getImagePath()).tilingDisabled());
|
||||
imageView.setImage(ImageSource.uri(page.getImagePath()));
|
||||
progressBar.setVisibility(View.GONE);
|
||||
} else {
|
||||
imageView.setVisibility(View.GONE);
|
||||
|
@ -33,6 +33,7 @@ public class WebtoonReader extends BaseReader {
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedState) {
|
||||
adapter = new WebtoonAdapter(this);
|
||||
PreCachingLayoutManager layoutManager = new PreCachingLayoutManager(getActivity());
|
||||
layoutManager.setExtraLayoutSpace(getResources().getDisplayMetrics().heightPixels);
|
||||
|
||||
recycler = new RecyclerView(getActivity());
|
||||
recycler.setLayoutParams(new ViewGroup.LayoutParams(MATCH_PARENT, MATCH_PARENT));
|
||||
@ -55,6 +56,14 @@ public class WebtoonReader extends BaseReader {
|
||||
getReaderActivity().onCenterSingleTap();
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onDown(MotionEvent e) {
|
||||
// The only way I've found to allow panning. Double tap event (zoom) is lost
|
||||
// but panning should be the most used one
|
||||
return true;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
setPages();
|
||||
|
8
app/src/main/res/anim/fade_in.xml
Normal file
8
app/src/main/res/anim/fade_in.xml
Normal file
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<set xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<alpha
|
||||
android:fromAlpha="0.0"
|
||||
android:toAlpha="1.0"
|
||||
android:interpolator="@android:anim/accelerate_interpolator"
|
||||
android:duration="300" />
|
||||
</set>
|
Loading…
Reference in New Issue
Block a user