浏览代码

Add broken webtoon viewer (not sure if it will be possible with RecyclerView)

inorichi 9 年之前
父节点
当前提交
0a9b84ea11

+ 70 - 0
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<Page> {
+
+    List<Page> 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<Page> 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<Page> {
+
+        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());
+        }
+    }
+}

+ 50 - 0
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<Page> pages) {
+        adapter.setPages(pages);
+    }
+
+    @Override
+    public boolean onImageTouch(MotionEvent motionEvent) {
+        return true;
+    }
+}

+ 1 - 1
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<Page> pages);
+    public abstract void onImageReady(Page page);
     public abstract boolean onImageTouch(MotionEvent motionEvent);
 }

+ 5 - 0
app/src/main/res/layout/chapter_image.xml

@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8"?>
+<com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    android:id="@+id/page_image_view" />

+ 1 - 4
app/src/main/res/layout/fragment_page.xml

@@ -13,9 +13,6 @@
         android:layout_gravity="center_vertical|center_horizontal"
         android:visibility="gone" />
 
-    <com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView xmlns:android="http://schemas.android.com/apk/res/android"
-        android:layout_width="match_parent"
-        android:layout_height="match_parent"
-        android:id="@+id/page_image_view" />
+        <include layout="@layout/chapter_image"/>
 
 </FrameLayout>

+ 7 - 0
app/src/main/res/layout/viewer_webtoon.xml

@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="utf-8"?>
+<android.support.v7.widget.RecyclerView
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent">
+
+</android.support.v7.widget.RecyclerView>