diff --git a/app/src/main/java/eu/kanade/mangafeed/data/helpers/PreferencesHelper.java b/app/src/main/java/eu/kanade/mangafeed/data/helpers/PreferencesHelper.java index 072d5fa29..d2944441e 100644 --- a/app/src/main/java/eu/kanade/mangafeed/data/helpers/PreferencesHelper.java +++ b/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")); + } + } diff --git a/app/src/main/java/eu/kanade/mangafeed/injection/component/AppComponent.java b/app/src/main/java/eu/kanade/mangafeed/injection/component/AppComponent.java index 52dd08198..b6f48e1b2 100644 --- a/app/src/main/java/eu/kanade/mangafeed/injection/component/AppComponent.java +++ b/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(); } diff --git a/app/src/main/java/eu/kanade/mangafeed/sources/Batoto.java b/app/src/main/java/eu/kanade/mangafeed/sources/Batoto.java index d5a952926..60860cc54 100644 --- a/app/src/main/java/eu/kanade/mangafeed/sources/Batoto.java +++ b/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); diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/activity/ReaderActivity.java b/app/src/main/java/eu/kanade/mangafeed/ui/activity/ReaderActivity.java index 396a7d06c..fa3681a7b 100644 --- a/app/src/main/java/eu/kanade/mangafeed/ui/activity/ReaderActivity.java +++ b/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 { @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 { @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 { 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; + } + } diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/viewer/VerticalViewer.java b/app/src/main/java/eu/kanade/mangafeed/ui/viewer/VerticalViewer.java new file mode 100644 index 000000000..f1c4252b1 --- /dev/null +++ b/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 pages) { + adapter.setPages(pages); + updatePageNumber(); + } + + @Override + public void onImageReady(Page page) { + adapter.replacePage(getPosFromPage(page), page); + } + + @Override + public boolean onImageTouch(MotionEvent motionEvent) { + return false; + } +} diff --git a/app/src/main/res/layout/viewer_verticalviewpager.xml b/app/src/main/res/layout/viewer_verticalviewpager.xml new file mode 100644 index 000000000..03b3a3989 --- /dev/null +++ b/app/src/main/res/layout/viewer_verticalviewpager.xml @@ -0,0 +1,8 @@ + + + + diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml new file mode 100644 index 000000000..a89cd1024 --- /dev/null +++ b/app/src/main/res/values/arrays.xml @@ -0,0 +1,17 @@ + + + + @string/left_to_right_viewer + @string/right_to_left_viewer + @string/vertical_viewer + @string/webtoon_viewer + + + + 1 + 2 + 3 + 4 + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index b5bb1de7d..e3e4c59d6 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -49,5 +49,10 @@ Settings Hide status bar This option will hide the status bar while reading + Default viewer + Left to right + Right to left + Vertical + Webtoon (experimental) diff --git a/app/src/main/res/xml/preferences.xml b/app/src/main/res/xml/preferences.xml index 0998906ad..fd93c50f3 100644 --- a/app/src/main/res/xml/preferences.xml +++ b/app/src/main/res/xml/preferences.xml @@ -6,4 +6,10 @@ android:summary="@string/pref_hide_status_bar_summary" android:key="hide_status_bar" /> + + \ No newline at end of file