Sfoglia il codice sorgente

Add vertical viewer. Allow to select a viewer

inorichi 9 anni fa
parent
commit
c7e9016ad7

+ 5 - 0
app/src/main/java/eu/kanade/mangafeed/data/helpers/PreferencesHelper.java

@@ -11,6 +11,7 @@ public class PreferencesHelper {
     private static SharedPreferences mPref;
 
     private static final String PREF_HIDE_STATUS_BAR = "hide_status_bar";
+    private static final String PREF_DEFAULT_VIEWER = "default_viewer";
 
     public PreferencesHelper(Context context) {
         PreferenceManager.setDefaultValues(context, R.xml.preferences, false);
@@ -26,4 +27,8 @@ public class PreferencesHelper {
         return mPref.getBoolean(PREF_HIDE_STATUS_BAR, false);
     }
 
+    public int getDefaultViewer() {
+        return Integer.parseInt(mPref.getString(PREF_DEFAULT_VIEWER, "1"));
+    }
+
 }

+ 3 - 0
app/src/main/java/eu/kanade/mangafeed/injection/component/AppComponent.java

@@ -14,6 +14,7 @@ import eu.kanade.mangafeed.presenter.MangaDetailPresenter;
 import eu.kanade.mangafeed.presenter.MangaInfoPresenter;
 import eu.kanade.mangafeed.presenter.ReaderPresenter;
 import eu.kanade.mangafeed.presenter.SourcePresenter;
+import eu.kanade.mangafeed.ui.activity.ReaderActivity;
 
 @Singleton
 @Component(
@@ -32,6 +33,8 @@ public interface AppComponent {
     void inject(MangaChaptersPresenter mangaChaptersPresenter);
     void inject(ReaderPresenter readerPresenter);
 
+    void inject(ReaderActivity readerActivity);
+
     Application application();
 
 }

+ 1 - 1
app/src/main/java/eu/kanade/mangafeed/sources/Batoto.java

@@ -252,7 +252,7 @@ public class Batoto extends Source {
     private Chapter constructChapterFromHtmlBlock(Element chapterElement) {
         Chapter newChapter = Chapter.newChapter();
 
-        Element urlElement = chapterElement.select("a[href^=http://bato.to/read/").first();
+        Element urlElement = chapterElement.select("a[href^=http://bato.to/reader").first();
         Element nameElement = urlElement;
         Element dateElement = chapterElement.select("td").get(4);
 

+ 33 - 1
app/src/main/java/eu/kanade/mangafeed/ui/activity/ReaderActivity.java

@@ -11,13 +11,20 @@ import android.widget.TextView;
 
 import java.util.List;
 
+import javax.inject.Inject;
+
 import butterknife.Bind;
 import butterknife.ButterKnife;
+import eu.kanade.mangafeed.App;
 import eu.kanade.mangafeed.R;
+import eu.kanade.mangafeed.data.helpers.PreferencesHelper;
 import eu.kanade.mangafeed.data.models.Page;
 import eu.kanade.mangafeed.presenter.ReaderPresenter;
 import eu.kanade.mangafeed.ui.activity.base.BaseRxActivity;
 import eu.kanade.mangafeed.ui.viewer.LeftToRightViewer;
+import eu.kanade.mangafeed.ui.viewer.RightToLeftViewer;
+import eu.kanade.mangafeed.ui.viewer.VerticalViewer;
+import eu.kanade.mangafeed.ui.viewer.WebtoonViewer;
 import eu.kanade.mangafeed.ui.viewer.base.BaseViewer;
 import nucleus.factory.RequiresPresenter;
 
@@ -27,9 +34,17 @@ public class ReaderActivity extends BaseRxActivity<ReaderPresenter> {
     @Bind(R.id.page_number) TextView pageNumber;
     @Bind(R.id.viewer) FrameLayout container;
 
+    @Inject PreferencesHelper prefs;
+
     private int currentPage;
     private BaseViewer viewer;
 
+    private static final int LEFT_TO_RIGHT = 1;
+    private static final int RIGHT_TO_LEFT = 2;
+    private static final int VERTICAL = 3;
+    private static final int WEBTOON = 4;
+
+
     public static Intent newInstance(Context context) {
         return new Intent(context, ReaderActivity.class);
     }
@@ -37,10 +52,11 @@ public class ReaderActivity extends BaseRxActivity<ReaderPresenter> {
     @Override
     public void onCreate(Bundle savedState) {
         super.onCreate(savedState);
+        App.get(this).getComponent().inject(this);
         setContentView(R.layout.activity_reader);
         ButterKnife.bind(this);
 
-        viewer = new LeftToRightViewer(this, container);
+        viewer = getViewer();
 
         enableHardwareAcceleration();
     }
@@ -83,4 +99,20 @@ public class ReaderActivity extends BaseRxActivity<ReaderPresenter> {
     public boolean onImageTouch(MotionEvent motionEvent) {
         return viewer.onImageTouch(motionEvent);
     }
+
+    private BaseViewer getViewer() {
+        int prefsViewer = prefs.getDefaultViewer();
+        switch (prefsViewer) {
+            case LEFT_TO_RIGHT:
+                return new LeftToRightViewer(this, container);
+            case RIGHT_TO_LEFT:
+                return new RightToLeftViewer(this, container);
+            case VERTICAL:
+                return new VerticalViewer(this, container);
+            case WEBTOON:
+                return new WebtoonViewer(this, container);
+        }
+        return null;
+    }
+
 }

+ 68 - 0
app/src/main/java/eu/kanade/mangafeed/ui/viewer/VerticalViewer.java

@@ -0,0 +1,68 @@
+package eu.kanade.mangafeed.ui.viewer;
+
+import android.view.MotionEvent;
+import android.widget.FrameLayout;
+
+import java.util.List;
+
+import eu.kanade.mangafeed.R;
+import eu.kanade.mangafeed.data.models.Page;
+import eu.kanade.mangafeed.ui.activity.ReaderActivity;
+import eu.kanade.mangafeed.ui.adapter.ReaderPageAdapter;
+import eu.kanade.mangafeed.ui.viewer.base.BaseViewer;
+import eu.kanade.mangafeed.widget.ReaderViewPager;
+import fr.castorflex.android.verticalviewpager.VerticalViewPager;
+
+public class VerticalViewer extends BaseViewer {
+
+    private VerticalViewPager viewPager;
+    private ReaderPageAdapter adapter;
+
+    public VerticalViewer(ReaderActivity activity, FrameLayout container) {
+        super(activity, container);
+        activity.getLayoutInflater().inflate(R.layout.viewer_verticalviewpager, container);
+
+        adapter = new ReaderPageAdapter(activity.getSupportFragmentManager());
+        viewPager = (VerticalViewPager) activity.findViewById(R.id.view_pager);
+        viewPager.setAdapter(adapter);
+        viewPager.setOffscreenPageLimit(3);
+        viewPager.setOnPageChangeListener(new ReaderViewPager.OnPageChangeListener() {
+            @Override
+            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
+
+            }
+
+            @Override
+            public void onPageSelected(int position) {
+                currentPosition = position;
+                updatePageNumber();
+            }
+
+            @Override
+            public void onPageScrollStateChanged(int state) {
+
+            }
+        });
+    }
+
+    @Override
+    public int getTotalPages() {
+        return adapter.getCount();
+    }
+
+    @Override
+    public void onPageListReady(List<Page> pages) {
+        adapter.setPages(pages);
+        updatePageNumber();
+    }
+
+    @Override
+    public void onImageReady(Page page) {
+        adapter.replacePage(getPosFromPage(page), page);
+    }
+
+    @Override
+    public boolean onImageTouch(MotionEvent motionEvent) {
+        return false;
+    }
+}

+ 8 - 0
app/src/main/res/layout/viewer_verticalviewpager.xml

@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="utf-8"?>
+<fr.castorflex.android.verticalviewpager.VerticalViewPager
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    android:id="@+id/view_pager"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent">
+
+</fr.castorflex.android.verticalviewpager.VerticalViewPager>

+ 17 - 0
app/src/main/res/values/arrays.xml

@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+    <string-array name="viewers">
+        <item>@string/left_to_right_viewer</item>
+        <item>@string/right_to_left_viewer</item>
+        <item>@string/vertical_viewer</item>
+        <item>@string/webtoon_viewer</item>
+    </string-array>
+
+    <string-array name="viewers_values">
+        <item>1</item>
+        <item>2</item>
+        <item>3</item>
+        <item>4</item>
+    </string-array>
+
+</resources>

+ 5 - 0
app/src/main/res/values/strings.xml

@@ -49,5 +49,10 @@
     <string name="title_activity_settings">Settings</string>
     <string name="pref_hide_status_bar">Hide status bar</string>
     <string name="pref_hide_status_bar_summary">This option will hide the status bar while reading</string>
+    <string name="pref_viewer_type">Default viewer</string>
+    <string name="left_to_right_viewer">Left to right</string>
+    <string name="right_to_left_viewer">Right to left</string>
+    <string name="vertical_viewer">Vertical</string>
+    <string name="webtoon_viewer">Webtoon (experimental)</string>
 
 </resources>

+ 6 - 0
app/src/main/res/xml/preferences.xml

@@ -6,4 +6,10 @@
         android:summary="@string/pref_hide_status_bar_summary"
         android:key="hide_status_bar" />
 
+    <ListPreference android:title="@string/pref_viewer_type"
+        android:key="default_viewer"
+        android:entries="@array/viewers"
+        android:entryValues="@array/viewers_values"
+        android:defaultValue="1"/>
+
 </PreferenceScreen>