mirror of
				https://github.com/mihonapp/mihon.git
				synced 2025-10-30 22:07:57 +01:00 
			
		
		
		
	Add more settings to the reader
This commit is contained in:
		| @@ -4,6 +4,7 @@ import android.content.Context; | ||||
| import android.content.SharedPreferences; | ||||
| import android.preference.PreferenceManager; | ||||
|  | ||||
| import com.f2prateek.rx.preferences.Preference; | ||||
| import com.f2prateek.rx.preferences.RxSharedPreferences; | ||||
|  | ||||
| import eu.kanade.mangafeed.R; | ||||
| @@ -36,21 +37,24 @@ public class PreferencesHelper { | ||||
|         prefs.edit().clear().apply(); | ||||
|     } | ||||
|  | ||||
|     public boolean isHideStatusBarSet() { | ||||
|         return prefs.getBoolean(getKey(R.string.pref_hide_status_bar_key), true); | ||||
|     public Preference<Boolean> lockOrientation() { | ||||
|         return rxPrefs.getBoolean(getKey(R.string.pref_lock_orientation_key), true); | ||||
|     } | ||||
|  | ||||
|     public boolean isOrientationLocked() { | ||||
|         return prefs.getBoolean(getKey(R.string.pref_lock_orientation_key), true); | ||||
|     public Preference<Boolean> enableTransitions() { | ||||
|         return rxPrefs.getBoolean(getKey(R.string.pref_enable_transitions_key), true); | ||||
|     } | ||||
|  | ||||
|     public void setOrientationLocked(boolean lock) { | ||||
|         prefs.edit().putBoolean(getKey(R.string.pref_lock_orientation_key), lock).apply(); | ||||
|     public Preference<Boolean> showPageNumber() { | ||||
|         return rxPrefs.getBoolean(getKey(R.string.pref_show_page_number_key), true); | ||||
|     } | ||||
|  | ||||
|     public Observable<Boolean> isOrientationLockedObservable() { | ||||
|         return rxPrefs.getBoolean(getKey(R.string.pref_lock_orientation_key), true) | ||||
|                 .asObservable(); | ||||
|     public Preference<Boolean> hideStatusBar() { | ||||
|         return rxPrefs.getBoolean(getKey(R.string.pref_hide_status_bar_key), true); | ||||
|     } | ||||
|  | ||||
|     public Preference<Boolean> keepScreenOn() { | ||||
|         return rxPrefs.getBoolean(getKey(R.string.pref_keep_screen_on_key), true); | ||||
|     } | ||||
|  | ||||
|     public int getDefaultViewer() { | ||||
|   | ||||
| @@ -165,7 +165,7 @@ public class ChaptersFragment extends BaseRxFragment<ChaptersPresenter> implemen | ||||
|             return true; | ||||
|         } else { | ||||
|             getPresenter().onChapterClicked(adapter.getItem(position)); | ||||
|             Intent intent = ReaderActivity.newInstance(getActivity()); | ||||
|             Intent intent = ReaderActivity.newIntent(getActivity()); | ||||
|             startActivity(intent); | ||||
|             return false; | ||||
|         } | ||||
|   | ||||
| @@ -2,11 +2,13 @@ package eu.kanade.mangafeed.ui.reader; | ||||
|  | ||||
| import android.content.Context; | ||||
| import android.content.Intent; | ||||
| import android.content.pm.ActivityInfo; | ||||
| import android.os.Build; | ||||
| import android.os.Bundle; | ||||
| import android.support.annotation.NonNull; | ||||
| import android.support.v7.widget.Toolbar; | ||||
| import android.view.MotionEvent; | ||||
| import android.view.Surface; | ||||
| import android.view.View; | ||||
| import android.view.ViewGroup; | ||||
| import android.view.WindowManager; | ||||
| @@ -34,6 +36,7 @@ import eu.kanade.mangafeed.ui.reader.viewer.webtoon.WebtoonReader; | ||||
| import eu.kanade.mangafeed.util.ToastUtil; | ||||
| import icepick.Icepick; | ||||
| import nucleus.factory.RequiresPresenter; | ||||
| import rx.subscriptions.CompositeSubscription; | ||||
|  | ||||
| @RequiresPresenter(ReaderPresenter.class) | ||||
| public class ReaderActivity extends BaseRxActivity<ReaderPresenter> { | ||||
| @@ -42,20 +45,20 @@ public class ReaderActivity extends BaseRxActivity<ReaderPresenter> { | ||||
|     @Bind(R.id.reader) FrameLayout container; | ||||
|     @Bind(R.id.toolbar) Toolbar toolbar; | ||||
|  | ||||
|     @Inject PreferencesHelper prefs; | ||||
|     @Inject PreferencesHelper preferences; | ||||
|  | ||||
|     private BaseReader viewer; | ||||
|     private ReaderMenu readerMenu; | ||||
|  | ||||
|     private int uiFlags; | ||||
|     private CompositeSubscription subscriptions; | ||||
|  | ||||
|     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) { | ||||
|     public static Intent newIntent(Context context) { | ||||
|         return new Intent(context, ReaderActivity.class); | ||||
|     } | ||||
|  | ||||
| @@ -67,14 +70,16 @@ public class ReaderActivity extends BaseRxActivity<ReaderPresenter> { | ||||
|         ButterKnife.bind(this); | ||||
|  | ||||
|         setupToolbar(toolbar); | ||||
|         subscriptions = new CompositeSubscription(); | ||||
|  | ||||
|         readerMenu = new ReaderMenu(this, prefs); | ||||
|         readerMenu = new ReaderMenu(this); | ||||
|         Icepick.restoreInstanceState(readerMenu, savedState); | ||||
|         if (savedState != null && readerMenu.showing) | ||||
|             readerMenu.show(false); | ||||
|  | ||||
|         createUiHideFlags(); | ||||
|         enableHardwareAcceleration(); | ||||
|  | ||||
|         initializeSettings(); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
| @@ -86,7 +91,7 @@ public class ReaderActivity extends BaseRxActivity<ReaderPresenter> { | ||||
|     @Override | ||||
|     protected void onResume() { | ||||
|         super.onResume(); | ||||
|         hideSystemUI(); | ||||
|         setSystemUiVisibility(); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
| @@ -102,16 +107,17 @@ public class ReaderActivity extends BaseRxActivity<ReaderPresenter> { | ||||
|         super.onSaveInstanceState(outState); | ||||
|     } | ||||
|  | ||||
|     private void createUiHideFlags() { | ||||
|     private void createUiHideFlags(boolean statusBarHidden) { | ||||
|         uiFlags = 0; | ||||
|         uiFlags |= View.SYSTEM_UI_FLAG_HIDE_NAVIGATION; | ||||
|         if (prefs.isHideStatusBarSet()) | ||||
|         if (statusBarHidden) | ||||
|             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<Page> pages, Manga manga, Chapter chapter) { | ||||
|         viewer = getViewer(manga); | ||||
|         viewer = createViewer(manga); | ||||
|         viewer.onPageListReady(pages); | ||||
|         viewer.updatePageNumber(); | ||||
|         readerMenu.onChapterReady(pages.size(), manga, chapter); | ||||
| @@ -132,7 +138,7 @@ public class ReaderActivity extends BaseRxActivity<ReaderPresenter> { | ||||
|         viewer.setSelectedPage(pageIndex); | ||||
|     } | ||||
|  | ||||
|     public void hideSystemUI() { | ||||
|     public void setSystemUiVisibility() { | ||||
|         getWindow().getDecorView().setSystemUiVisibility(uiFlags); | ||||
|     } | ||||
|  | ||||
| @@ -154,8 +160,12 @@ public class ReaderActivity extends BaseRxActivity<ReaderPresenter> { | ||||
|         return container; | ||||
|     } | ||||
|  | ||||
|     private BaseReader getViewer(Manga manga) { | ||||
|         int mangaViewer = manga.viewer == 0 ? prefs.getDefaultViewer() : manga.viewer; | ||||
|     public PreferencesHelper getPreferences() { | ||||
|         return preferences; | ||||
|     } | ||||
|  | ||||
|     private BaseReader createViewer(Manga manga) { | ||||
|         int mangaViewer = manga.viewer == 0 ? preferences.getDefaultViewer() : manga.viewer; | ||||
|  | ||||
|         switch (mangaViewer) { | ||||
|             case LEFT_TO_RIGHT: default: | ||||
| @@ -169,4 +179,69 @@ public class ReaderActivity extends BaseRxActivity<ReaderPresenter> { | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     private void initializeSettings() { | ||||
|         subscriptions.add(preferences.showPageNumber() | ||||
|                 .asObservable() | ||||
|                 .subscribe(this::setPageNumberVisibility)); | ||||
|  | ||||
|         subscriptions.add(preferences.lockOrientation() | ||||
|                 .asObservable() | ||||
|                 .subscribe(this::setOrientation)); | ||||
|  | ||||
|         subscriptions.add(preferences.hideStatusBar() | ||||
|                 .asObservable() | ||||
|                 .subscribe(this::setStatusBarVisibility)); | ||||
|  | ||||
|         preferences.keepScreenOn() | ||||
|                 .asObservable() | ||||
|                 .subscribe(this::setKeepScreenOn); | ||||
|     } | ||||
|  | ||||
|     private void setOrientation(boolean locked) { | ||||
|         if (locked) { | ||||
|             int orientation; | ||||
|             int rotation = ((WindowManager) getSystemService( | ||||
|                     Context.WINDOW_SERVICE)).getDefaultDisplay().getRotation(); | ||||
|             switch (rotation) { | ||||
|                 case Surface.ROTATION_0: | ||||
|                     orientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; | ||||
|                     break; | ||||
|                 case Surface.ROTATION_90: | ||||
|                     orientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; | ||||
|                     break; | ||||
|                 case Surface.ROTATION_180: | ||||
|                     orientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT; | ||||
|                     break; | ||||
|                 default: | ||||
|                     orientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE; | ||||
|                     break; | ||||
|             } | ||||
|             setRequestedOrientation(orientation); | ||||
|         } else { | ||||
|             setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     private void setPageNumberVisibility(boolean visible) { | ||||
|         pageNumber.setVisibility(visible ? View.VISIBLE : View.INVISIBLE); | ||||
|     } | ||||
|  | ||||
|     private void setStatusBarVisibility(boolean hidden) { | ||||
|         createUiHideFlags(hidden); | ||||
|         setSystemUiVisibility(); | ||||
|     } | ||||
|  | ||||
|     private void setKeepScreenOn(boolean enabled) { | ||||
|         if (enabled) { | ||||
|             getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); | ||||
|         } else { | ||||
|             getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); | ||||
|         } | ||||
|     } | ||||
|      | ||||
|     protected void setMangaDefaultViewer(int viewer) { | ||||
|         getPresenter().updateMangaViewer(viewer); | ||||
|         recreate(); | ||||
|     } | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -2,16 +2,18 @@ package eu.kanade.mangafeed.ui.reader; | ||||
|  | ||||
| import android.app.Dialog; | ||||
| import android.content.Context; | ||||
| import android.content.pm.ActivityInfo; | ||||
| import android.support.v7.app.AlertDialog; | ||||
| import android.support.v7.widget.Toolbar; | ||||
| import android.view.Surface; | ||||
| import android.view.Gravity; | ||||
| import android.view.View; | ||||
| import android.view.WindowManager; | ||||
| import android.view.WindowManager.LayoutParams; | ||||
| import android.view.animation.Animation; | ||||
| import android.view.animation.AnimationUtils; | ||||
| import android.widget.CheckBox; | ||||
| import android.widget.ImageButton; | ||||
| import android.widget.LinearLayout; | ||||
| import android.widget.PopupWindow; | ||||
| import android.widget.RelativeLayout; | ||||
| import android.widget.SeekBar; | ||||
| import android.widget.TextView; | ||||
| @@ -37,18 +39,21 @@ public class ReaderMenu { | ||||
|     @Bind(R.id.total_pages) TextView totalPages; | ||||
|     @Bind(R.id.lock_orientation) ImageButton lockOrientation; | ||||
|     @Bind(R.id.reader_selector) ImageButton readerSelector; | ||||
|  | ||||
|     @Bind(R.id.reader_extra_settings) ImageButton extraSettings; | ||||
|  | ||||
|     private ReaderActivity activity; | ||||
|     private PreferencesHelper preferences; | ||||
|  | ||||
|     @State boolean showing; | ||||
|     private PopupWindow popupWindow; | ||||
|  | ||||
|     private DecimalFormat decimalFormat; | ||||
|  | ||||
|     private CompositeSubscription subscriptions; | ||||
|  | ||||
|     public ReaderMenu(ReaderActivity activity, PreferencesHelper preferences) { | ||||
|     public ReaderMenu(ReaderActivity activity) { | ||||
|         this.activity = activity; | ||||
|         this.preferences = preferences; | ||||
|         this.preferences = activity.getPreferences(); | ||||
|         ButterKnife.bind(this, activity); | ||||
|  | ||||
|         // Intercept all image events in this layout | ||||
| @@ -94,6 +99,8 @@ public class ReaderMenu { | ||||
|         Animation bottomMenuAnimation = AnimationUtils.loadAnimation(activity, R.anim.exit_to_bottom); | ||||
|         bottomMenu.startAnimation(bottomMenuAnimation); | ||||
|  | ||||
|         popupWindow.dismiss(); | ||||
|  | ||||
|         showing = false; | ||||
|     } | ||||
|  | ||||
| @@ -116,11 +123,18 @@ public class ReaderMenu { | ||||
|  | ||||
|     private void initializeOptions() { | ||||
|         // Orientation changes | ||||
|         lockOrientation.setOnClickListener(v -> | ||||
|                 preferences.setOrientationLocked(!preferences.isOrientationLocked())); | ||||
|         subscriptions.add(preferences.lockOrientation().asObservable() | ||||
|                 .subscribe(locked -> { | ||||
|                     int resourceId = !locked ? R.drawable.ic_screen_rotation : | ||||
|                             activity.getResources().getConfiguration().orientation == 1 ? | ||||
|                                     R.drawable.ic_screen_lock_portrait : | ||||
|                                     R.drawable.ic_screen_lock_landscape; | ||||
|  | ||||
|         subscriptions.add(preferences.isOrientationLockedObservable() | ||||
|                 .subscribe(this::onOrientationOptionChanged)); | ||||
|                     lockOrientation.setImageResource(resourceId); | ||||
|                 })); | ||||
|  | ||||
|         lockOrientation.setOnClickListener(v -> | ||||
|                 preferences.lockOrientation().set(!preferences.lockOrientation().get())); | ||||
|  | ||||
|         // Reader selector | ||||
|         readerSelector.setOnClickListener(v -> { | ||||
| @@ -128,57 +142,84 @@ public class ReaderMenu { | ||||
|             final Dialog dialog = new AlertDialog.Builder(activity) | ||||
|                     .setSingleChoiceItems(R.array.viewers_selector, manga.viewer, (d, which) -> { | ||||
|                         if (manga.viewer != which) { | ||||
|                             activity.getPresenter().updateMangaViewer(which); | ||||
|                             activity.recreate(); | ||||
|                             activity.setMangaDefaultViewer(which); | ||||
|                         } | ||||
|                         d.dismiss(); | ||||
|                     }) | ||||
|                     .create(); | ||||
|             showImmersiveDialog(dialog); | ||||
|         }); | ||||
|  | ||||
|             // Hack to not leave immersive mode | ||||
|             dialog.getWindow().setFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, | ||||
|                     WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE); | ||||
|             dialog.getWindow().getDecorView().setSystemUiVisibility( | ||||
|                     activity.getWindow().getDecorView().getSystemUiVisibility()); | ||||
|             dialog.show(); | ||||
|             dialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE); | ||||
|             WindowManager wm = (WindowManager) activity.getSystemService(Context.WINDOW_SERVICE); | ||||
|             wm.updateViewLayout(activity.getWindow().getDecorView(), activity.getWindow().getAttributes()); | ||||
|         // Extra settings menu | ||||
|         final View popupView = activity.getLayoutInflater().inflate(R.layout.reader_popup, null); | ||||
|         popupWindow = new SettingsPopupWindow(popupView); | ||||
|  | ||||
|         extraSettings.setOnClickListener(v -> { | ||||
|             if (!popupWindow.isShowing()) | ||||
|                 popupWindow.showAtLocation(extraSettings, | ||||
|                         Gravity.BOTTOM | Gravity.RIGHT, 0, bottomMenu.getHeight()); | ||||
|             else | ||||
|                 popupWindow.dismiss(); | ||||
|         }); | ||||
|     } | ||||
|  | ||||
|     private void onOrientationOptionChanged(boolean locked) { | ||||
|         if (locked) | ||||
|             lockOrientation(); | ||||
|         else | ||||
|             activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); | ||||
|         int resourceId = !locked ? R.drawable.ic_screen_rotation : | ||||
|                 activity.getResources().getConfiguration().orientation == 1 ? | ||||
|                         R.drawable.ic_screen_lock_portrait : | ||||
|                         R.drawable.ic_screen_lock_landscape; | ||||
|  | ||||
|         lockOrientation.setImageResource(resourceId); | ||||
|     private void showImmersiveDialog(Dialog dialog) { | ||||
|         // Hack to not leave immersive mode | ||||
|         dialog.getWindow().setFlags(LayoutParams.FLAG_NOT_FOCUSABLE, | ||||
|                 LayoutParams.FLAG_NOT_FOCUSABLE); | ||||
|         dialog.getWindow().getDecorView().setSystemUiVisibility( | ||||
|                 activity.getWindow().getDecorView().getSystemUiVisibility()); | ||||
|         dialog.show(); | ||||
|         dialog.getWindow().clearFlags(LayoutParams.FLAG_NOT_FOCUSABLE); | ||||
|         WindowManager wm = (WindowManager) activity.getSystemService(Context.WINDOW_SERVICE); | ||||
|         wm.updateViewLayout(activity.getWindow().getDecorView(), activity.getWindow().getAttributes()); | ||||
|     } | ||||
|  | ||||
|     private void lockOrientation() { | ||||
|         int orientation; | ||||
|         int rotation = ((WindowManager) activity.getSystemService( | ||||
|                 Context.WINDOW_SERVICE)).getDefaultDisplay().getRotation(); | ||||
|         switch (rotation) { | ||||
|             case Surface.ROTATION_0: | ||||
|                 orientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; | ||||
|                 break; | ||||
|             case Surface.ROTATION_90: | ||||
|                 orientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; | ||||
|                 break; | ||||
|             case Surface.ROTATION_180: | ||||
|                 orientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT; | ||||
|                 break; | ||||
|             default: | ||||
|                 orientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE; | ||||
|                 break; | ||||
|     class SettingsPopupWindow extends PopupWindow { | ||||
|  | ||||
|         @Bind(R.id.enable_transitions) CheckBox enableTransitions; | ||||
|         @Bind(R.id.show_page_number) CheckBox showPageNumber; | ||||
|         @Bind(R.id.hide_status_bar) CheckBox hideStatusBar; | ||||
|         @Bind(R.id.keep_screen_on) CheckBox keepScreenOn; | ||||
|  | ||||
|         public SettingsPopupWindow(View view) { | ||||
|             super(view, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); | ||||
|             setAnimationStyle(R.style.reader_settings_popup_animation); | ||||
|             ButterKnife.bind(this, view); | ||||
|             initializePopupMenu(); | ||||
|         } | ||||
|         activity.setRequestedOrientation(orientation); | ||||
|  | ||||
|         private void initializePopupMenu() { | ||||
|             subscriptions.add(preferences.enableTransitions() | ||||
|                     .asObservable() | ||||
|                     .subscribe(enableTransitions::setChecked)); | ||||
|  | ||||
|             subscriptions.add(preferences.showPageNumber() | ||||
|                     .asObservable() | ||||
|                     .subscribe(showPageNumber::setChecked)); | ||||
|  | ||||
|             subscriptions.add(preferences.hideStatusBar() | ||||
|                     .asObservable() | ||||
|                     .subscribe(hideStatusBar::setChecked)); | ||||
|  | ||||
|             subscriptions.add(preferences.keepScreenOn() | ||||
|                     .asObservable() | ||||
|                     .subscribe(keepScreenOn::setChecked)); | ||||
|  | ||||
|             enableTransitions.setOnCheckedChangeListener((view, isChecked) -> | ||||
|                     preferences.enableTransitions().set(isChecked)); | ||||
|  | ||||
|             showPageNumber.setOnCheckedChangeListener((view, isChecked) -> | ||||
|                     preferences.showPageNumber().set(isChecked)); | ||||
|  | ||||
|             hideStatusBar.setOnCheckedChangeListener((view, isChecked) -> | ||||
|                     preferences.hideStatusBar().set(isChecked)); | ||||
|  | ||||
|             keepScreenOn.setOnCheckedChangeListener((view, isChecked) -> | ||||
|                     preferences.keepScreenOn().set(isChecked)); | ||||
|  | ||||
|         } | ||||
|  | ||||
|     } | ||||
|  | ||||
|     class PageSeekBarChangeListener implements SeekBar.OnSeekBarChangeListener { | ||||
| @@ -214,4 +255,5 @@ public class ReaderMenu { | ||||
|  | ||||
|         } | ||||
|     } | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -11,6 +11,7 @@ import eu.kanade.mangafeed.data.source.model.Page; | ||||
| import eu.kanade.mangafeed.ui.reader.ReaderActivity; | ||||
| import eu.kanade.mangafeed.ui.reader.viewer.base.BaseReader; | ||||
| import eu.kanade.mangafeed.ui.reader.viewer.common.ViewPagerReaderAdapter; | ||||
| import rx.Subscription; | ||||
|  | ||||
| public abstract class HorizontalReader extends BaseReader { | ||||
|  | ||||
| @@ -18,11 +19,17 @@ public abstract class HorizontalReader extends BaseReader { | ||||
|  | ||||
|     protected ViewPagerReaderAdapter adapter; | ||||
|  | ||||
|     private boolean transitions; | ||||
|     private Subscription transitionsSubscription; | ||||
|  | ||||
|     public HorizontalReader(ReaderActivity activity) { | ||||
|         super(activity); | ||||
|         activity.getLayoutInflater().inflate(R.layout.reader_horizontal, container); | ||||
|         ButterKnife.bind(this, container); | ||||
|  | ||||
|         transitionsSubscription = activity.getPreferences().enableTransitions().asObservable() | ||||
|                 .subscribe(value -> transitions = value); | ||||
|  | ||||
|         viewPager.setOffscreenPageLimit(3); | ||||
|         viewPager.addOnPageChangeListener(new HorizontalViewPager.SimpleOnPageChangeListener() { | ||||
|             @Override | ||||
| @@ -42,7 +49,22 @@ public abstract class HorizontalReader extends BaseReader { | ||||
|                 onLastPageOut(); | ||||
|             } | ||||
|         }); | ||||
|         viewPager.setOnChapterSingleTapListener(activity::onCenterSingleTap); | ||||
|         viewPager.setOnChapterSingleTapListener(new HorizontalViewPager.OnChapterSingleTapListener() { | ||||
|             @Override | ||||
|             public void onCenterTap() { | ||||
|                 activity.onCenterSingleTap(); | ||||
|             } | ||||
|  | ||||
|             @Override | ||||
|             public void onLeftSideTap() { | ||||
|                 viewPager.setCurrentItem(viewPager.getCurrentItem() - 1, transitions); | ||||
|             } | ||||
|  | ||||
|             @Override | ||||
|             public void onRightSideTap() { | ||||
|                 viewPager.setCurrentItem(viewPager.getCurrentItem() + 1, transitions); | ||||
|             } | ||||
|         }); | ||||
|     } | ||||
|      | ||||
|     @Override | ||||
| @@ -67,6 +89,11 @@ public abstract class HorizontalReader extends BaseReader { | ||||
|         return viewPager.onImageTouch(motionEvent); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void destroySubscriptions() { | ||||
|         transitionsSubscription.unsubscribe(); | ||||
|     } | ||||
|  | ||||
|     public abstract void onFirstPageOut(); | ||||
|     public abstract void onLastPageOut(); | ||||
|  | ||||
|   | ||||
| @@ -90,7 +90,9 @@ public class HorizontalViewPager extends ViewPager { | ||||
|     } | ||||
|  | ||||
|     public interface OnChapterSingleTapListener { | ||||
|         void onSingleTap(); | ||||
|         void onCenterTap(); | ||||
|         void onLeftSideTap(); | ||||
|         void onRightSideTap(); | ||||
|     } | ||||
|  | ||||
|     public void setOnChapterBoundariesOutListener(OnChapterBoundariesOutListener onChapterBoundariesOutListener) { | ||||
| @@ -111,7 +113,9 @@ public class HorizontalViewPager extends ViewPager { | ||||
|  | ||||
|             if (positionX < getWidth() * LEFT_REGION) { | ||||
|                 if (position != 0) { | ||||
|                     setCurrentItem(position - 1, true); | ||||
|                     if (mOnChapterSingleTapListener != null) { | ||||
|                         mOnChapterSingleTapListener.onLeftSideTap(); | ||||
|                     } | ||||
|                 } else { | ||||
|                     if (mOnChapterBoundariesOutListener != null) { | ||||
|                         mOnChapterBoundariesOutListener.onFirstPageOutEvent(); | ||||
| @@ -119,7 +123,9 @@ public class HorizontalViewPager extends ViewPager { | ||||
|                 } | ||||
|             } else if (positionX > getWidth() * RIGHT_REGION) { | ||||
|                 if (position != getAdapter().getCount() - 1) { | ||||
|                     setCurrentItem(position + 1, true); | ||||
|                     if (mOnChapterSingleTapListener != null) { | ||||
|                         mOnChapterSingleTapListener.onRightSideTap(); | ||||
|                     } | ||||
|                 } else { | ||||
|                     if (mOnChapterBoundariesOutListener != null) { | ||||
|                         mOnChapterBoundariesOutListener.onLastPageOutEvent(); | ||||
| @@ -127,7 +133,7 @@ public class HorizontalViewPager extends ViewPager { | ||||
|                 } | ||||
|             } else { | ||||
|                 if (mOnChapterSingleTapListener != null) { | ||||
|                     mOnChapterSingleTapListener.onSingleTap(); | ||||
|                     mOnChapterSingleTapListener.onCenterTap(); | ||||
|                 } | ||||
|             } | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user