From 13e1227fc5e7e846e41793307240f42604ec9cc1 Mon Sep 17 00:00:00 2001 From: inorichi Date: Thu, 19 Nov 2015 04:58:29 +0100 Subject: [PATCH] Show animations on reader menu. Don't retain fragment instances in ViewPagerReader. --- .../mangafeed/ui/reader/ReaderActivity.java | 9 ++-- .../mangafeed/ui/reader/ReaderMenu.java | 54 +++++++++++++++++-- .../common/ViewPagerReaderFragment.java | 12 ++--- app/src/main/res/anim/enter_from_bottom.xml | 8 +++ app/src/main/res/anim/enter_from_top.xml | 8 +++ app/src/main/res/anim/exit_to_bottom.xml | 8 +++ app/src/main/res/anim/exit_to_top.xml | 8 +++ app/src/main/res/layout/reader_menu.xml | 1 + 8 files changed, 93 insertions(+), 15 deletions(-) create mode 100644 app/src/main/res/anim/enter_from_bottom.xml create mode 100644 app/src/main/res/anim/enter_from_top.xml create mode 100644 app/src/main/res/anim/exit_to_bottom.xml create mode 100644 app/src/main/res/anim/exit_to_top.xml 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 90d8e5123c..69d7e0ed1b 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 @@ -68,8 +68,6 @@ public class ReaderActivity extends BaseRxActivity { readerMenu = new ReaderMenu(this, prefs); createUiHideFlags(); enableHardwareAcceleration(); - - viewer = getViewer(); } @Override @@ -94,6 +92,7 @@ public class ReaderActivity extends BaseRxActivity { } public void onChapterReady(List pages, Manga manga, Chapter chapter) { + viewer = getViewer(manga); viewer.onPageListReady(pages); viewer.updatePageNumber(); readerMenu.onChapterReady(pages.size(), manga, chapter); @@ -132,8 +131,10 @@ public class ReaderActivity extends BaseRxActivity { readerMenu.toggle(); } - private BaseReader getViewer() { - switch (prefs.getDefaultViewer()) { + private BaseReader getViewer(Manga manga) { + int mangaViewer = manga.viewer == 0 ? prefs.getDefaultViewer() : manga.viewer; + + switch (mangaViewer) { case LEFT_TO_RIGHT: default: return new LeftToRightReader(this, container); case RIGHT_TO_LEFT: 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 index 0099657c46..937515756b 100644 --- a/app/src/main/java/eu/kanade/mangafeed/ui/reader/ReaderMenu.java +++ b/app/src/main/java/eu/kanade/mangafeed/ui/reader/ReaderMenu.java @@ -1,6 +1,10 @@ package eu.kanade.mangafeed.ui.reader; +import android.support.v7.widget.Toolbar; import android.view.View; +import android.view.animation.Animation; +import android.view.animation.AnimationUtils; +import android.widget.LinearLayout; import android.widget.RelativeLayout; import android.widget.SeekBar; import android.widget.TextView; @@ -17,11 +21,12 @@ import eu.kanade.mangafeed.data.preference.PreferencesHelper; public class ReaderMenu { @Bind(R.id.reader_menu) RelativeLayout menu; + @Bind(R.id.reader_menu_bottom) LinearLayout bottomMenu; + @Bind(R.id.toolbar) Toolbar toolbar; @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; @@ -37,12 +42,33 @@ public class ReaderMenu { } public void toggle() { - toggle(!showing); + if (showing) + hide(); + else + show(); } - private void toggle(boolean show) { - menu.setVisibility(show ? View.VISIBLE : View.GONE); - showing = show; + private void show() { + menu.setVisibility(View.VISIBLE); + + Animation toolbarAnimation = AnimationUtils.loadAnimation(activity, R.anim.enter_from_top); + toolbar.startAnimation(toolbarAnimation); + + Animation bottomMenuAnimation = AnimationUtils.loadAnimation(activity, R.anim.enter_from_bottom); + bottomMenu.startAnimation(bottomMenuAnimation); + + showing = true; + } + + private void hide() { + Animation toolbarAnimation = AnimationUtils.loadAnimation(activity, R.anim.exit_to_top); + toolbarAnimation.setAnimationListener(new HideMenuAnimationListener()); + toolbar.startAnimation(toolbarAnimation); + + Animation bottomMenuAnimation = AnimationUtils.loadAnimation(activity, R.anim.exit_to_bottom); + bottomMenu.startAnimation(bottomMenuAnimation); + + showing = false; } public void onChapterReady(int numPages, Manga manga, Chapter chapter) { @@ -77,4 +103,22 @@ public class ReaderMenu { @Override public void onStopTrackingTouch(SeekBar seekBar) {} } + + class HideMenuAnimationListener implements Animation.AnimationListener { + + @Override + public void onAnimationStart(Animation animation) { + + } + + @Override + public void onAnimationEnd(Animation animation) { + menu.setVisibility(View.GONE); + } + + @Override + public void onAnimationRepeat(Animation animation) { + + } + } } diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/reader/viewer/common/ViewPagerReaderFragment.java b/app/src/main/java/eu/kanade/mangafeed/ui/reader/viewer/common/ViewPagerReaderFragment.java index 720b89094c..814f2d7c7e 100644 --- a/app/src/main/java/eu/kanade/mangafeed/ui/reader/viewer/common/ViewPagerReaderFragment.java +++ b/app/src/main/java/eu/kanade/mangafeed/ui/reader/viewer/common/ViewPagerReaderFragment.java @@ -50,12 +50,6 @@ public class ViewPagerReaderFragment extends BaseFragment { return fragment; } - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setRetainInstance(true); - } - @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_page, container, false); @@ -70,6 +64,12 @@ public class ViewPagerReaderFragment extends BaseFragment { return view; } + @Override + public void onDestroyView() { + ButterKnife.unbind(this); + super.onDestroyView(); + } + public void onStart() { super.onStart(); observeStatus(); diff --git a/app/src/main/res/anim/enter_from_bottom.xml b/app/src/main/res/anim/enter_from_bottom.xml new file mode 100644 index 0000000000..c9bd492a55 --- /dev/null +++ b/app/src/main/res/anim/enter_from_bottom.xml @@ -0,0 +1,8 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/anim/enter_from_top.xml b/app/src/main/res/anim/enter_from_top.xml new file mode 100644 index 0000000000..ec0431ba00 --- /dev/null +++ b/app/src/main/res/anim/enter_from_top.xml @@ -0,0 +1,8 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/anim/exit_to_bottom.xml b/app/src/main/res/anim/exit_to_bottom.xml new file mode 100644 index 0000000000..d5d94c795e --- /dev/null +++ b/app/src/main/res/anim/exit_to_bottom.xml @@ -0,0 +1,8 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/anim/exit_to_top.xml b/app/src/main/res/anim/exit_to_top.xml new file mode 100644 index 0000000000..3a6f3e9db9 --- /dev/null +++ b/app/src/main/res/anim/exit_to_top.xml @@ -0,0 +1,8 @@ + + + + \ 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 index f6bd3dcdca..5af00e95ec 100644 --- a/app/src/main/res/layout/reader_menu.xml +++ b/app/src/main/res/layout/reader_menu.xml @@ -10,6 +10,7 @@