Show animations on reader menu. Don't retain fragment instances in ViewPagerReader.

This commit is contained in:
inorichi 2015-11-19 04:58:29 +01:00
parent 3c1b00435c
commit 13e1227fc5
8 changed files with 93 additions and 15 deletions

View file

@ -68,8 +68,6 @@ public class ReaderActivity extends BaseRxActivity<ReaderPresenter> {
readerMenu = new ReaderMenu(this, prefs); readerMenu = new ReaderMenu(this, prefs);
createUiHideFlags(); createUiHideFlags();
enableHardwareAcceleration(); enableHardwareAcceleration();
viewer = getViewer();
} }
@Override @Override
@ -94,6 +92,7 @@ public class ReaderActivity extends BaseRxActivity<ReaderPresenter> {
} }
public void onChapterReady(List<Page> pages, Manga manga, Chapter chapter) { public void onChapterReady(List<Page> pages, Manga manga, Chapter chapter) {
viewer = getViewer(manga);
viewer.onPageListReady(pages); viewer.onPageListReady(pages);
viewer.updatePageNumber(); viewer.updatePageNumber();
readerMenu.onChapterReady(pages.size(), manga, chapter); readerMenu.onChapterReady(pages.size(), manga, chapter);
@ -132,8 +131,10 @@ public class ReaderActivity extends BaseRxActivity<ReaderPresenter> {
readerMenu.toggle(); readerMenu.toggle();
} }
private BaseReader getViewer() { private BaseReader getViewer(Manga manga) {
switch (prefs.getDefaultViewer()) { int mangaViewer = manga.viewer == 0 ? prefs.getDefaultViewer() : manga.viewer;
switch (mangaViewer) {
case LEFT_TO_RIGHT: default: case LEFT_TO_RIGHT: default:
return new LeftToRightReader(this, container); return new LeftToRightReader(this, container);
case RIGHT_TO_LEFT: case RIGHT_TO_LEFT:

View file

@ -1,6 +1,10 @@
package eu.kanade.mangafeed.ui.reader; package eu.kanade.mangafeed.ui.reader;
import android.support.v7.widget.Toolbar;
import android.view.View; 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.RelativeLayout;
import android.widget.SeekBar; import android.widget.SeekBar;
import android.widget.TextView; import android.widget.TextView;
@ -17,11 +21,12 @@ import eu.kanade.mangafeed.data.preference.PreferencesHelper;
public class ReaderMenu { public class ReaderMenu {
@Bind(R.id.reader_menu) RelativeLayout menu; @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.current_page) TextView currentPage;
@Bind(R.id.page_seeker) SeekBar seekBar; @Bind(R.id.page_seeker) SeekBar seekBar;
@Bind(R.id.total_pages) TextView totalPages; @Bind(R.id.total_pages) TextView totalPages;
private ReaderActivity activity; private ReaderActivity activity;
private PreferencesHelper preferences; private PreferencesHelper preferences;
private boolean showing; private boolean showing;
@ -37,12 +42,33 @@ public class ReaderMenu {
} }
public void toggle() { public void toggle() {
toggle(!showing); if (showing)
hide();
else
show();
} }
private void toggle(boolean show) { private void show() {
menu.setVisibility(show ? View.VISIBLE : View.GONE); menu.setVisibility(View.VISIBLE);
showing = show;
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) { public void onChapterReady(int numPages, Manga manga, Chapter chapter) {
@ -77,4 +103,22 @@ public class ReaderMenu {
@Override @Override
public void onStopTrackingTouch(SeekBar seekBar) {} 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) {
}
}
} }

View file

@ -50,12 +50,6 @@ public class ViewPagerReaderFragment extends BaseFragment {
return fragment; return fragment;
} }
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setRetainInstance(true);
}
@Override @Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_page, container, false); View view = inflater.inflate(R.layout.fragment_page, container, false);
@ -70,6 +64,12 @@ public class ViewPagerReaderFragment extends BaseFragment {
return view; return view;
} }
@Override
public void onDestroyView() {
ButterKnife.unbind(this);
super.onDestroyView();
}
public void onStart() { public void onStart() {
super.onStart(); super.onStart();
observeStatus(); observeStatus();

View file

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<translate
android:duration="200"
android:fromYDelta="100%"
android:toYDelta="0%" />
</set>

View file

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<translate
android:duration="200"
android:fromYDelta="-100%"
android:toYDelta="0%" />
</set>

View file

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<translate
android:duration="200"
android:fromYDelta="0%"
android:toYDelta="100%" />
</set>

View file

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<translate
android:duration="200"
android:fromYDelta="0%"
android:toYDelta="-100%" />
</set>

View file

@ -10,6 +10,7 @@
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:id="@+id/reader_menu_bottom"
android:background="@color/reader_menu_background" android:background="@color/reader_menu_background"
android:layout_alignParentBottom="true"> android:layout_alignParentBottom="true">