From 3c1b00435c95facf5e4bb45095cad4de083c1af9 Mon Sep 17 00:00:00 2001 From: inorichi Date: Wed, 18 Nov 2015 21:54:33 +0100 Subject: [PATCH] Add an initial menu for the reader, and some minor changes. --- app/src/main/AndroidManifest.xml | 1 - .../data/database/models/Chapter.java | 6 +- .../data/preference/PreferencesHelper.java | 4 +- .../data/source/base/BaseSource.java | 5 - .../mangafeed/data/source/base/Source.java | 3 +- .../data/source/online/english/Batoto.java | 2 +- .../data/source/online/english/Mangahere.java | 2 +- .../ui/base/activity/BaseActivity.java | 22 +++++ .../mangafeed/ui/manga/MangaActivity.java | 11 --- .../mangafeed/ui/reader/ReaderActivity.java | 98 ++++++++----------- .../mangafeed/ui/reader/ReaderMenu.java | 80 +++++++++++++++ .../mangafeed/ui/reader/ReaderPresenter.java | 9 +- .../ui/setting/SettingsActivity.java | 11 --- .../mangafeed/util/ChapterRecognition.java | 2 +- app/src/main/res/layout/activity_reader.xml | 8 +- app/src/main/res/layout/reader_menu.xml | 43 ++++++++ app/src/main/res/values/colors.xml | 2 + app/src/main/res/values/keys.xml | 2 +- app/src/main/res/values/strings.xml | 3 +- app/src/main/res/xml/pref_reader.xml | 4 +- 20 files changed, 214 insertions(+), 104 deletions(-) create mode 100644 app/src/main/java/eu/kanade/mangafeed/ui/reader/ReaderMenu.java create mode 100644 app/src/main/res/layout/reader_menu.xml diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 1bb8bd0207..a2b5742e75 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -15,7 +15,6 @@ android:theme="@style/AppTheme" > diff --git a/app/src/main/java/eu/kanade/mangafeed/data/database/models/Chapter.java b/app/src/main/java/eu/kanade/mangafeed/data/database/models/Chapter.java index eca4f5fc33..a4e03f465e 100644 --- a/app/src/main/java/eu/kanade/mangafeed/data/database/models/Chapter.java +++ b/app/src/main/java/eu/kanade/mangafeed/data/database/models/Chapter.java @@ -60,8 +60,10 @@ public class Chapter { return url.hashCode(); } - public static Chapter newChapter() { - return new Chapter(); + public static Chapter create() { + Chapter chapter = new Chapter(); + chapter.chapter_number = -1; + return chapter; } } diff --git a/app/src/main/java/eu/kanade/mangafeed/data/preference/PreferencesHelper.java b/app/src/main/java/eu/kanade/mangafeed/data/preference/PreferencesHelper.java index a6a0417b42..b1768bc84a 100644 --- a/app/src/main/java/eu/kanade/mangafeed/data/preference/PreferencesHelper.java +++ b/app/src/main/java/eu/kanade/mangafeed/data/preference/PreferencesHelper.java @@ -36,8 +36,8 @@ public class PreferencesHelper { prefs.edit().clear().apply(); } - public boolean useFullscreenSet() { - return prefs.getBoolean(getKey(R.string.pref_fullscreen_key), false); + public boolean isHideStatusBarSet() { + return prefs.getBoolean(getKey(R.string.pref_hide_status_bar_key), true); } public int getDefaultViewer() { diff --git a/app/src/main/java/eu/kanade/mangafeed/data/source/base/BaseSource.java b/app/src/main/java/eu/kanade/mangafeed/data/source/base/BaseSource.java index 921e9c8997..fc789868c1 100644 --- a/app/src/main/java/eu/kanade/mangafeed/data/source/base/BaseSource.java +++ b/app/src/main/java/eu/kanade/mangafeed/data/source/base/BaseSource.java @@ -92,9 +92,4 @@ public abstract class BaseSource { return builder; } - // Number of images to download at the same time. 3 by default - protected int overrideNumberOfConcurrentPageDownloads() { - return 3; - } - } diff --git a/app/src/main/java/eu/kanade/mangafeed/data/source/base/Source.java b/app/src/main/java/eu/kanade/mangafeed/data/source/base/Source.java index 528cc382b4..0faff6db67 100644 --- a/app/src/main/java/eu/kanade/mangafeed/data/source/base/Source.java +++ b/app/src/main/java/eu/kanade/mangafeed/data/source/base/Source.java @@ -97,8 +97,7 @@ public abstract class Source extends BaseSource { public Observable getRemainingImageUrlsFromPageList(final List pages) { return Observable.from(pages) .filter(page -> page.getImageUrl() == null) - .window(overrideNumberOfConcurrentPageDownloads()) - .concatMap(batchedPages -> batchedPages.concatMap(this::getImageUrlFromPage)); + .concatMap(this::getImageUrlFromPage); } public Observable getImageUrlFromPage(final Page page) { diff --git a/app/src/main/java/eu/kanade/mangafeed/data/source/online/english/Batoto.java b/app/src/main/java/eu/kanade/mangafeed/data/source/online/english/Batoto.java index 6477bfe694..b8c192d476 100644 --- a/app/src/main/java/eu/kanade/mangafeed/data/source/online/english/Batoto.java +++ b/app/src/main/java/eu/kanade/mangafeed/data/source/online/english/Batoto.java @@ -305,7 +305,7 @@ public class Batoto extends Source { } private Chapter constructChapterFromHtmlBlock(Element chapterElement) { - Chapter newChapter = Chapter.newChapter(); + Chapter newChapter = Chapter.create(); Element urlElement = chapterElement.select("a[href^=http://bato.to/reader").first(); Element nameElement = urlElement; diff --git a/app/src/main/java/eu/kanade/mangafeed/data/source/online/english/Mangahere.java b/app/src/main/java/eu/kanade/mangafeed/data/source/online/english/Mangahere.java index 7088fbcf13..566aa4d9d5 100644 --- a/app/src/main/java/eu/kanade/mangafeed/data/source/online/english/Mangahere.java +++ b/app/src/main/java/eu/kanade/mangafeed/data/source/online/english/Mangahere.java @@ -288,7 +288,7 @@ public class Mangahere extends Source { } private Chapter constructChapterFromHtmlBlock(Element chapterElement) { - Chapter newChapter = Chapter.newChapter(); + Chapter newChapter = Chapter.create(); Element urlElement = chapterElement.select("a").first(); Element nameElement = chapterElement.select("a").first(); diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/base/activity/BaseActivity.java b/app/src/main/java/eu/kanade/mangafeed/ui/base/activity/BaseActivity.java index 6cda297dd7..9daa434137 100644 --- a/app/src/main/java/eu/kanade/mangafeed/ui/base/activity/BaseActivity.java +++ b/app/src/main/java/eu/kanade/mangafeed/ui/base/activity/BaseActivity.java @@ -3,6 +3,7 @@ package eu.kanade.mangafeed.ui.base.activity; import android.content.Context; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; +import android.view.MenuItem; public class BaseActivity extends AppCompatActivity { @@ -22,7 +23,28 @@ public class BaseActivity extends AppCompatActivity { getSupportActionBar().setTitle(getString(titleResource)); } + public void setToolbarSubtitle(String title) { + if (getSupportActionBar() != null) + getSupportActionBar().setSubtitle(title); + } + + public void setToolbarSubtitle(int titleResource) { + if (getSupportActionBar() != null) + getSupportActionBar().setSubtitle(getString(titleResource)); + } + public Context getActivity() { return this; } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case android.R.id.home: + onBackPressed(); + return true; + } + return super.onOptionsItemSelected(item); + } + } \ No newline at end of file diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/manga/MangaActivity.java b/app/src/main/java/eu/kanade/mangafeed/ui/manga/MangaActivity.java index 0bad49da55..612a48eed3 100644 --- a/app/src/main/java/eu/kanade/mangafeed/ui/manga/MangaActivity.java +++ b/app/src/main/java/eu/kanade/mangafeed/ui/manga/MangaActivity.java @@ -10,7 +10,6 @@ import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentPagerAdapter; import android.support.v4.view.ViewPager; import android.support.v7.widget.Toolbar; -import android.view.MenuItem; import butterknife.Bind; import butterknife.ButterKnife; @@ -61,16 +60,6 @@ public class MangaActivity extends BaseRxActivity { getPresenter().queryManga(manga_id); } - @Override - public boolean onOptionsItemSelected(MenuItem item) { - switch (item.getItemId()) { - case android.R.id.home: - finish(); - return true; - } - return super.onOptionsItemSelected(item); - } - private void disableToolbarElevation() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { toolbar.setElevation(0); diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/reader/ReaderActivity.java b/app/src/main/java/eu/kanade/mangafeed/ui/reader/ReaderActivity.java index 7bc07278c4..90d8e5123c 100644 --- a/app/src/main/java/eu/kanade/mangafeed/ui/reader/ReaderActivity.java +++ b/app/src/main/java/eu/kanade/mangafeed/ui/reader/ReaderActivity.java @@ -4,6 +4,7 @@ import android.content.Context; import android.content.Intent; import android.os.Build; import android.os.Bundle; +import android.support.v7.widget.Toolbar; import android.view.MotionEvent; import android.view.View; import android.view.WindowManager; @@ -18,6 +19,8 @@ import butterknife.Bind; import butterknife.ButterKnife; import eu.kanade.mangafeed.App; import eu.kanade.mangafeed.R; +import eu.kanade.mangafeed.data.database.models.Chapter; +import eu.kanade.mangafeed.data.database.models.Manga; import eu.kanade.mangafeed.data.preference.PreferencesHelper; import eu.kanade.mangafeed.data.source.model.Page; import eu.kanade.mangafeed.ui.base.activity.BaseRxActivity; @@ -34,11 +37,14 @@ public class ReaderActivity extends BaseRxActivity { @Bind(R.id.page_number) TextView pageNumber; @Bind(R.id.reader) FrameLayout container; + @Bind(R.id.toolbar) Toolbar toolbar; @Inject PreferencesHelper prefs; private BaseReader viewer; - private boolean isFullscreen; + private ReaderMenu readerMenu; + + private int uiFlags; private static final int LEFT_TO_RIGHT = 1; private static final int RIGHT_TO_LEFT = 2; @@ -57,27 +63,19 @@ public class ReaderActivity extends BaseRxActivity { setContentView(R.layout.activity_reader); ButterKnife.bind(this); - if (prefs.useFullscreenSet()) - enableFullScreen(); + setupToolbar(toolbar); + readerMenu = new ReaderMenu(this, prefs); + createUiHideFlags(); enableHardwareAcceleration(); viewer = getViewer(); } - - public void onPageListReady(List pages) { - viewer.onPageListReady(pages); - viewer.updatePageNumber(); - } - public void onPageListError() { - finish(); - ToastUtil.showShort(this, R.string.page_list_error); - } - - public void onPageChanged(int currentPageIndex, int totalPages) { - String page = (currentPageIndex + 1) + "/" + totalPages; - pageNumber.setText(page); + @Override + protected void onResume() { + super.onResume(); + hideSystemUI(); } @Override @@ -87,42 +85,37 @@ public class ReaderActivity extends BaseRxActivity { super.onPause(); } + private void createUiHideFlags() { + uiFlags |= View.SYSTEM_UI_FLAG_HIDE_NAVIGATION; + if (prefs.isHideStatusBarSet()) + uiFlags |= View.SYSTEM_UI_FLAG_FULLSCREEN; + if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT) + uiFlags |= View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY; + } + + public void onChapterReady(List pages, Manga manga, Chapter chapter) { + viewer.onPageListReady(pages); + viewer.updatePageNumber(); + readerMenu.onChapterReady(pages.size(), manga, chapter); + } + + public void onChapterError() { + finish(); + ToastUtil.showShort(this, R.string.page_list_error); + } + + public void onPageChanged(int currentPageIndex, int totalPages) { + String page = (currentPageIndex + 1) + "/" + totalPages; + pageNumber.setText(page); + readerMenu.onPageChanged(currentPageIndex); + } + public void setSelectedPage(int pageIndex) { viewer.setSelectedPage(pageIndex); } - public void enableFullScreen() { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { - getWindow().getDecorView().setSystemUiVisibility( - View.SYSTEM_UI_FLAG_LOW_PROFILE - | View.SYSTEM_UI_FLAG_LAYOUT_STABLE - | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION - | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN - | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION - | View.SYSTEM_UI_FLAG_FULLSCREEN - | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY - ); - } else { - getWindow().getDecorView().setSystemUiVisibility( - View.SYSTEM_UI_FLAG_LOW_PROFILE - ); - } - isFullscreen = true; - } - - public void disableFullscreen() { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { - getWindow().getDecorView().setSystemUiVisibility( - View.SYSTEM_UI_FLAG_LAYOUT_STABLE - | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION - | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN - ); - } else { - getWindow().getDecorView().setSystemUiVisibility( - View.VISIBLE - ); - } - isFullscreen = false; + public void hideSystemUI() { + getWindow().getDecorView().setSystemUiVisibility(uiFlags); } public void enableHardwareAcceleration() { @@ -136,14 +129,7 @@ public class ReaderActivity extends BaseRxActivity { } public void onCenterSingleTap() { - toggleFullscreen(); - } - - private void toggleFullscreen() { - if (isFullscreen) - disableFullscreen(); - else - enableFullScreen(); + readerMenu.toggle(); } private BaseReader getViewer() { diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/reader/ReaderMenu.java b/app/src/main/java/eu/kanade/mangafeed/ui/reader/ReaderMenu.java new file mode 100644 index 0000000000..0099657c46 --- /dev/null +++ b/app/src/main/java/eu/kanade/mangafeed/ui/reader/ReaderMenu.java @@ -0,0 +1,80 @@ +package eu.kanade.mangafeed.ui.reader; + +import android.view.View; +import android.widget.RelativeLayout; +import android.widget.SeekBar; +import android.widget.TextView; + +import java.text.DecimalFormat; + +import butterknife.Bind; +import butterknife.ButterKnife; +import eu.kanade.mangafeed.R; +import eu.kanade.mangafeed.data.database.models.Chapter; +import eu.kanade.mangafeed.data.database.models.Manga; +import eu.kanade.mangafeed.data.preference.PreferencesHelper; + +public class ReaderMenu { + + @Bind(R.id.reader_menu) RelativeLayout menu; + @Bind(R.id.current_page) TextView currentPage; + @Bind(R.id.page_seeker) SeekBar seekBar; + @Bind(R.id.total_pages) TextView totalPages; + + + private ReaderActivity activity; + private PreferencesHelper preferences; + private boolean showing; + private DecimalFormat decimalFormat; + + public ReaderMenu(ReaderActivity activity, PreferencesHelper preferences) { + this.activity = activity; + this.preferences = preferences; + ButterKnife.bind(this, activity); + + seekBar.setOnSeekBarChangeListener(new PageSeekBarChangeListener()); + decimalFormat = new DecimalFormat("#.##"); + } + + public void toggle() { + toggle(!showing); + } + + private void toggle(boolean show) { + menu.setVisibility(show ? View.VISIBLE : View.GONE); + showing = show; + } + + public void onChapterReady(int numPages, Manga manga, Chapter chapter) { + totalPages.setText("" + numPages); + seekBar.setMax(numPages - 1); + + activity.setToolbarTitle(manga.title); + activity.setToolbarSubtitle(chapter.chapter_number != -1 ? + activity.getString(R.string.chapter_subtitle, + decimalFormat.format(chapter.chapter_number)) : + chapter.name); + + } + + public void onPageChanged(int pageIndex) { + currentPage.setText("" + (pageIndex + 1)); + seekBar.setProgress(pageIndex); + } + + class PageSeekBarChangeListener implements SeekBar.OnSeekBarChangeListener { + + @Override + public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { + if (fromUser) { + activity.setSelectedPage(progress); + } + } + + @Override + public void onStartTrackingTouch(SeekBar seekBar) {} + + @Override + public void onStopTrackingTouch(SeekBar seekBar) {} + } +} diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/reader/ReaderPresenter.java b/app/src/main/java/eu/kanade/mangafeed/ui/reader/ReaderPresenter.java index 71ee701008..eea229add4 100644 --- a/app/src/main/java/eu/kanade/mangafeed/ui/reader/ReaderPresenter.java +++ b/app/src/main/java/eu/kanade/mangafeed/ui/reader/ReaderPresenter.java @@ -66,12 +66,12 @@ public class ReaderPresenter extends BasePresenter { start(RETRY_IMAGES); }), (view, pages) -> { - view.onPageListReady(pages); + view.onChapterReady(pages, manga, chapter); if (currentPage != 0) view.setSelectedPage(currentPage); }, (view, error) -> { - view.onPageListError(); + view.onChapterError(); }); restartableReplay(GET_PAGE_IMAGES, @@ -158,7 +158,7 @@ public class ReaderPresenter extends BasePresenter { pages = Observable.from(pageList) .filter(page -> page.getImageUrl() != null) .mergeWith(source.getRemainingImageUrlsFromPageList(pageList)) - .flatMap(source::getCachedImage); + .flatMap(source::getCachedImage, 3); } else { File chapterDir = downloadManager.getAbsoluteChapterDirectory(source, manga, chapter); @@ -178,7 +178,8 @@ public class ReaderPresenter extends BasePresenter { return Observable.just(page); }) .flatMap(source::getCachedImage) - .subscribeOn(Schedulers.io()); + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()); } public void setCurrentPage(int currentPage) { diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/setting/SettingsActivity.java b/app/src/main/java/eu/kanade/mangafeed/ui/setting/SettingsActivity.java index becf45c763..1a174eabb2 100644 --- a/app/src/main/java/eu/kanade/mangafeed/ui/setting/SettingsActivity.java +++ b/app/src/main/java/eu/kanade/mangafeed/ui/setting/SettingsActivity.java @@ -2,7 +2,6 @@ package eu.kanade.mangafeed.ui.setting; import android.os.Bundle; import android.support.v7.widget.Toolbar; -import android.view.MenuItem; import butterknife.Bind; import butterknife.ButterKnife; @@ -32,14 +31,4 @@ public class SettingsActivity extends BaseActivity { if( !getFragmentManager().popBackStackImmediate() ) super.onBackPressed(); } - @Override - public boolean onOptionsItemSelected(MenuItem item) { - switch (item.getItemId()) { - case android.R.id.home: - onBackPressed(); - return true; - } - return super.onOptionsItemSelected(item); - } - } diff --git a/app/src/main/java/eu/kanade/mangafeed/util/ChapterRecognition.java b/app/src/main/java/eu/kanade/mangafeed/util/ChapterRecognition.java index 4ae12d3a59..c052245ff8 100644 --- a/app/src/main/java/eu/kanade/mangafeed/util/ChapterRecognition.java +++ b/app/src/main/java/eu/kanade/mangafeed/util/ChapterRecognition.java @@ -14,7 +14,7 @@ public class ChapterRecognition { private static Pattern p2 = Pattern.compile("(\\d+[\\.,]?\\d*)"); public static void parseChapterNumber(Chapter chapter, Manga manga) { - if (chapter.chapter_number != 0) + if (chapter.chapter_number != -1) return; // Remove spaces and convert to lower case diff --git a/app/src/main/res/layout/activity_reader.xml b/app/src/main/res/layout/activity_reader.xml index 04ef42407e..b1bf068072 100644 --- a/app/src/main/res/layout/activity_reader.xml +++ b/app/src/main/res/layout/activity_reader.xml @@ -6,17 +6,19 @@ + android:layout_height="match_parent"> + + \ No newline at end of file diff --git a/app/src/main/res/layout/reader_menu.xml b/app/src/main/res/layout/reader_menu.xml new file mode 100644 index 0000000000..f6bd3dcdca --- /dev/null +++ b/app/src/main/res/layout/reader_menu.xml @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index 0f731d7e34..6b8e3b1167 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -17,4 +17,6 @@ #E8E8E8 #909090 #607D8B + #AAE9E9E9 + #333333 \ No newline at end of file diff --git a/app/src/main/res/values/keys.xml b/app/src/main/res/values/keys.xml index 04ea8b2c25..85c3f0bd72 100644 --- a/app/src/main/res/values/keys.xml +++ b/app/src/main/res/values/keys.xml @@ -3,7 +3,7 @@ pref_category_reader_key pref_category_accounts_key pref_category_downloads_key - pref_fullscreen_key + pref_hide_status_bar_key pref_default_viewer_key pref_download_directory_key pref_download_threads_key diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 5f321d91a0..705a439857 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -27,7 +27,7 @@ Downloads - Read in fullscreen + Hide status bar Default viewer Left to right Right to left @@ -75,6 +75,7 @@ Downloaded %1$d%% Page: %1$d Error fetching page list. Is network available? + Chapter %1$s Update progress: %1$d/%2$d diff --git a/app/src/main/res/xml/pref_reader.xml b/app/src/main/res/xml/pref_reader.xml index 312cbb5f33..b8029dc892 100644 --- a/app/src/main/res/xml/pref_reader.xml +++ b/app/src/main/res/xml/pref_reader.xml @@ -1,8 +1,8 @@ -