From 0a9b84ea1104a8e414ceeceb3c5d3941d7360fb2 Mon Sep 17 00:00:00 2001 From: inorichi Date: Sat, 24 Oct 2015 21:09:58 +0200 Subject: [PATCH] Add broken webtoon viewer (not sure if it will be possible with RecyclerView) --- .../mangafeed/ui/adapter/WebtoonAdapter.java | 70 +++++++++++++++++++ .../mangafeed/ui/viewer/WebtoonViewer.java | 50 +++++++++++++ .../mangafeed/ui/viewer/base/BaseViewer.java | 2 +- app/src/main/res/layout/chapter_image.xml | 5 ++ app/src/main/res/layout/fragment_page.xml | 5 +- app/src/main/res/layout/viewer_webtoon.xml | 7 ++ 6 files changed, 134 insertions(+), 5 deletions(-) create mode 100644 app/src/main/java/eu/kanade/mangafeed/ui/adapter/WebtoonAdapter.java create mode 100644 app/src/main/java/eu/kanade/mangafeed/ui/viewer/WebtoonViewer.java create mode 100644 app/src/main/res/layout/chapter_image.xml create mode 100644 app/src/main/res/layout/viewer_webtoon.xml diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/adapter/WebtoonAdapter.java b/app/src/main/java/eu/kanade/mangafeed/ui/adapter/WebtoonAdapter.java new file mode 100644 index 0000000000..946fb979c7 --- /dev/null +++ b/app/src/main/java/eu/kanade/mangafeed/ui/adapter/WebtoonAdapter.java @@ -0,0 +1,70 @@ +package eu.kanade.mangafeed.ui.adapter; + +import android.content.Context; +import android.view.View; + +import com.davemorrissey.labs.subscaleview.ImageSource; +import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView; + +import java.util.ArrayList; +import java.util.List; + +import eu.kanade.mangafeed.R; +import eu.kanade.mangafeed.data.models.Page; +import uk.co.ribot.easyadapter.BaseEasyRecyclerAdapter; +import uk.co.ribot.easyadapter.ItemViewHolder; +import uk.co.ribot.easyadapter.PositionInfo; +import uk.co.ribot.easyadapter.annotations.LayoutId; + +public class WebtoonAdapter extends BaseEasyRecyclerAdapter { + + List pages; + + public WebtoonAdapter(Context context) { + super(context, ImageViewHolder.class); + pages = new ArrayList<>(); + } + + @Override + public Page getItem(int position) { + return pages.get(position); + } + + @Override + public int getItemCount() { + return pages.size(); + } + + public void setPages(List pages) { + this.pages = pages; + notifyDataSetChanged(); + } + + public void setPage(int position, Page page) { + pages.set(position, page); + notifyItemChanged(position); + } + + + @LayoutId(R.layout.chapter_image) + static class ImageViewHolder extends ItemViewHolder { + + SubsamplingScaleImageView imageView; + + public ImageViewHolder(View view) { + super(view); + imageView = (SubsamplingScaleImageView) getView(); + 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); + } + + @Override + public void onSetValues(Page page, PositionInfo positionInfo) { + if (page.getImagePath() != null) + imageView.setImage(ImageSource.uri(page.getImagePath()).tilingDisabled()); + } + } +} diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/viewer/WebtoonViewer.java b/app/src/main/java/eu/kanade/mangafeed/ui/viewer/WebtoonViewer.java new file mode 100644 index 0000000000..97159b1106 --- /dev/null +++ b/app/src/main/java/eu/kanade/mangafeed/ui/viewer/WebtoonViewer.java @@ -0,0 +1,50 @@ +package eu.kanade.mangafeed.ui.viewer; + +import android.support.v7.widget.LinearLayoutManager; +import android.support.v7.widget.RecyclerView; +import android.view.MotionEvent; +import android.widget.FrameLayout; + +import java.util.List; + +import eu.kanade.mangafeed.data.models.Page; +import eu.kanade.mangafeed.ui.activity.ReaderActivity; +import eu.kanade.mangafeed.ui.adapter.WebtoonAdapter; +import eu.kanade.mangafeed.ui.viewer.base.BaseViewer; + +public class WebtoonViewer extends BaseViewer { + + private RecyclerView recycler; + private WebtoonAdapter adapter; + + public WebtoonViewer(ReaderActivity activity, FrameLayout container) { + super(activity, container); + + recycler = new RecyclerView(activity); + recycler.setLayoutManager(new LinearLayoutManager(activity)); + adapter = new WebtoonAdapter(activity); + recycler.setAdapter(adapter); + + container.addView(recycler); + } + + @Override + public int getTotalPages() { + return adapter.getItemCount(); + } + + @Override + public void onImageReady(Page page) { + adapter.setPage(getPosFromPage(page), page); + } + + @Override + public void onPageListReady(List pages) { + adapter.setPages(pages); + } + + @Override + public boolean onImageTouch(MotionEvent motionEvent) { + return true; + } +} diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/viewer/base/BaseViewer.java b/app/src/main/java/eu/kanade/mangafeed/ui/viewer/base/BaseViewer.java index 9c9a1d27e4..e8d8992867 100644 --- a/app/src/main/java/eu/kanade/mangafeed/ui/viewer/base/BaseViewer.java +++ b/app/src/main/java/eu/kanade/mangafeed/ui/viewer/base/BaseViewer.java @@ -32,7 +32,7 @@ public abstract class BaseViewer { } public abstract int getTotalPages(); - public abstract void onImageReady(Page page); public abstract void onPageListReady(List pages); + public abstract void onImageReady(Page page); public abstract boolean onImageTouch(MotionEvent motionEvent); } diff --git a/app/src/main/res/layout/chapter_image.xml b/app/src/main/res/layout/chapter_image.xml new file mode 100644 index 0000000000..0b661bba53 --- /dev/null +++ b/app/src/main/res/layout/chapter_image.xml @@ -0,0 +1,5 @@ + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_page.xml b/app/src/main/res/layout/fragment_page.xml index 761a332edb..5f48d4f042 100644 --- a/app/src/main/res/layout/fragment_page.xml +++ b/app/src/main/res/layout/fragment_page.xml @@ -13,9 +13,6 @@ android:layout_gravity="center_vertical|center_horizontal" android:visibility="gone" /> - + \ No newline at end of file diff --git a/app/src/main/res/layout/viewer_webtoon.xml b/app/src/main/res/layout/viewer_webtoon.xml new file mode 100644 index 0000000000..8288a8d683 --- /dev/null +++ b/app/src/main/res/layout/viewer_webtoon.xml @@ -0,0 +1,7 @@ + + + + \ No newline at end of file