|
@@ -4,31 +4,23 @@ import android.support.v7.widget.RecyclerView;
|
|
import android.view.LayoutInflater;
|
|
import android.view.LayoutInflater;
|
|
import android.view.View;
|
|
import android.view.View;
|
|
import android.view.ViewGroup;
|
|
import android.view.ViewGroup;
|
|
-import android.view.animation.Animation;
|
|
|
|
-import android.view.animation.AnimationUtils;
|
|
|
|
-import android.widget.ProgressBar;
|
|
|
|
-
|
|
|
|
-import com.davemorrissey.labs.subscaleview.ImageSource;
|
|
|
|
-import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
|
-import butterknife.Bind;
|
|
|
|
-import butterknife.ButterKnife;
|
|
|
|
import eu.kanade.mangafeed.R;
|
|
import eu.kanade.mangafeed.R;
|
|
import eu.kanade.mangafeed.data.source.model.Page;
|
|
import eu.kanade.mangafeed.data.source.model.Page;
|
|
|
|
|
|
-public class WebtoonAdapter extends RecyclerView.Adapter<WebtoonAdapter.ImageHolder> {
|
|
|
|
|
|
+public class WebtoonAdapter extends RecyclerView.Adapter<WebtoonHolder> {
|
|
|
|
|
|
- private List<Page> pages;
|
|
|
|
private WebtoonReader fragment;
|
|
private WebtoonReader fragment;
|
|
- private View.OnTouchListener listener;
|
|
|
|
|
|
+ private List<Page> pages;
|
|
|
|
+ private View.OnTouchListener touchListener;
|
|
|
|
|
|
public WebtoonAdapter(WebtoonReader fragment) {
|
|
public WebtoonAdapter(WebtoonReader fragment) {
|
|
this.fragment = fragment;
|
|
this.fragment = fragment;
|
|
pages = new ArrayList<>();
|
|
pages = new ArrayList<>();
|
|
- listener = (v, event) -> fragment.onImageTouch(event);
|
|
|
|
|
|
+ touchListener = (v, event) -> fragment.onImageTouch(event);
|
|
}
|
|
}
|
|
|
|
|
|
public Page getItem(int position) {
|
|
public Page getItem(int position) {
|
|
@@ -36,14 +28,14 @@ public class WebtoonAdapter extends RecyclerView.Adapter<WebtoonAdapter.ImageHol
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- public ImageHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
|
|
|
|
|
+ public WebtoonHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
|
LayoutInflater inflater = fragment.getActivity().getLayoutInflater();
|
|
LayoutInflater inflater = fragment.getActivity().getLayoutInflater();
|
|
View v = inflater.inflate(R.layout.item_webtoon_reader, parent, false);
|
|
View v = inflater.inflate(R.layout.item_webtoon_reader, parent, false);
|
|
- return new ImageHolder(v, listener);
|
|
|
|
|
|
+ return new WebtoonHolder(v, this, touchListener);
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- public void onBindViewHolder(ImageHolder holder, int position) {
|
|
|
|
|
|
+ public void onBindViewHolder(WebtoonHolder holder, int position) {
|
|
final Page page = getItem(position);
|
|
final Page page = getItem(position);
|
|
holder.onSetValues(page);
|
|
holder.onSetValues(page);
|
|
}
|
|
}
|
|
@@ -53,9 +45,9 @@ public class WebtoonAdapter extends RecyclerView.Adapter<WebtoonAdapter.ImageHol
|
|
return pages.size();
|
|
return pages.size();
|
|
}
|
|
}
|
|
|
|
|
|
- public void addPage(Page page) {
|
|
|
|
- pages.add(page);
|
|
|
|
- notifyItemInserted(page.getPageNumber());
|
|
|
|
|
|
+ public void setPages(List<Page> pages) {
|
|
|
|
+ this.pages = pages;
|
|
|
|
+ notifyDataSetChanged();
|
|
}
|
|
}
|
|
|
|
|
|
public void clear() {
|
|
public void clear() {
|
|
@@ -65,41 +57,8 @@ public class WebtoonAdapter extends RecyclerView.Adapter<WebtoonAdapter.ImageHol
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- public static class ImageHolder extends RecyclerView.ViewHolder {
|
|
|
|
-
|
|
|
|
- @Bind(R.id.page_image_view) SubsamplingScaleImageView imageView;
|
|
|
|
- @Bind(R.id.progress) ProgressBar progressBar;
|
|
|
|
-
|
|
|
|
- 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.setOnTouchListener(listener);
|
|
|
|
- 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()));
|
|
|
|
- progressBar.setVisibility(View.GONE);
|
|
|
|
- } else {
|
|
|
|
- imageView.setVisibility(View.GONE);
|
|
|
|
- progressBar.setVisibility(View.VISIBLE);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ public void retryPage(Page page) {
|
|
|
|
+ fragment.getReaderActivity().getPresenter().retryPage(page);
|
|
}
|
|
}
|
|
|
|
+
|
|
}
|
|
}
|