mirror of
https://github.com/mihonapp/mihon.git
synced 2025-06-25 10:37:51 +02:00
Improve reader options menu. Allow to select default viewer per manga. Allow to lock screen rotation. Working on more options.
This commit is contained in:
@ -40,6 +40,19 @@ public class PreferencesHelper {
|
||||
return prefs.getBoolean(getKey(R.string.pref_hide_status_bar_key), true);
|
||||
}
|
||||
|
||||
public boolean isOrientationLocked() {
|
||||
return prefs.getBoolean(getKey(R.string.pref_lock_orientation_key), true);
|
||||
}
|
||||
|
||||
public void setOrientationLocked(boolean lock) {
|
||||
prefs.edit().putBoolean(getKey(R.string.pref_lock_orientation_key), lock).apply();
|
||||
}
|
||||
|
||||
public Observable<Boolean> isOrientationLockedObservable() {
|
||||
return rxPrefs.getBoolean(getKey(R.string.pref_lock_orientation_key), true)
|
||||
.asObservable();
|
||||
}
|
||||
|
||||
public int getDefaultViewer() {
|
||||
return Integer.parseInt(prefs.getString(getKey(R.string.pref_default_viewer_key), "1"));
|
||||
}
|
||||
|
@ -4,9 +4,11 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
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.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.TextView;
|
||||
@ -30,6 +32,7 @@ import eu.kanade.mangafeed.ui.reader.viewer.horizontal.RightToLeftReader;
|
||||
import eu.kanade.mangafeed.ui.reader.viewer.vertical.VerticalReader;
|
||||
import eu.kanade.mangafeed.ui.reader.viewer.webtoon.WebtoonReader;
|
||||
import eu.kanade.mangafeed.util.ToastUtil;
|
||||
import icepick.Icepick;
|
||||
import nucleus.factory.RequiresPresenter;
|
||||
|
||||
@RequiresPresenter(ReaderPresenter.class)
|
||||
@ -66,10 +69,20 @@ public class ReaderActivity extends BaseRxActivity<ReaderPresenter> {
|
||||
setupToolbar(toolbar);
|
||||
|
||||
readerMenu = new ReaderMenu(this, prefs);
|
||||
Icepick.restoreInstanceState(readerMenu, savedState);
|
||||
if (savedState != null && readerMenu.showing)
|
||||
readerMenu.show(false);
|
||||
|
||||
createUiHideFlags();
|
||||
enableHardwareAcceleration();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
readerMenu.destroy();
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
@ -83,11 +96,17 @@ public class ReaderActivity extends BaseRxActivity<ReaderPresenter> {
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSaveInstanceState(@NonNull Bundle outState) {
|
||||
Icepick.saveInstanceState(readerMenu, outState);
|
||||
super.onSaveInstanceState(outState);
|
||||
}
|
||||
|
||||
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)
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT)
|
||||
uiFlags |= View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
|
||||
}
|
||||
|
||||
@ -131,18 +150,22 @@ public class ReaderActivity extends BaseRxActivity<ReaderPresenter> {
|
||||
readerMenu.toggle();
|
||||
}
|
||||
|
||||
public ViewGroup getContainer() {
|
||||
return container;
|
||||
}
|
||||
|
||||
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);
|
||||
return new LeftToRightReader(this);
|
||||
case RIGHT_TO_LEFT:
|
||||
return new RightToLeftReader(this, container);
|
||||
return new RightToLeftReader(this);
|
||||
case VERTICAL:
|
||||
return new VerticalReader(this, container);
|
||||
return new VerticalReader(this);
|
||||
case WEBTOON:
|
||||
return new WebtoonReader(this, container);
|
||||
return new WebtoonReader(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,9 +1,16 @@
|
||||
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.View;
|
||||
import android.view.WindowManager;
|
||||
import android.view.animation.Animation;
|
||||
import android.view.animation.AnimationUtils;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.SeekBar;
|
||||
@ -17,6 +24,8 @@ 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 icepick.State;
|
||||
import rx.subscriptions.CompositeSubscription;
|
||||
|
||||
public class ReaderMenu {
|
||||
|
||||
@ -26,41 +35,58 @@ public class ReaderMenu {
|
||||
@Bind(R.id.current_page) TextView currentPage;
|
||||
@Bind(R.id.page_seeker) SeekBar seekBar;
|
||||
@Bind(R.id.total_pages) TextView totalPages;
|
||||
@Bind(R.id.lock_orientation) ImageButton lockOrientation;
|
||||
@Bind(R.id.reader_selector) ImageButton readerSelector;
|
||||
|
||||
|
||||
private ReaderActivity activity;
|
||||
private PreferencesHelper preferences;
|
||||
private boolean showing;
|
||||
@State boolean showing;
|
||||
private DecimalFormat decimalFormat;
|
||||
|
||||
private CompositeSubscription subscriptions;
|
||||
|
||||
public ReaderMenu(ReaderActivity activity, PreferencesHelper preferences) {
|
||||
this.activity = activity;
|
||||
this.preferences = preferences;
|
||||
ButterKnife.bind(this, activity);
|
||||
|
||||
// Intercept all image events in this layout
|
||||
bottomMenu.setOnTouchListener((v, event) -> true);
|
||||
|
||||
seekBar.setOnSeekBarChangeListener(new PageSeekBarChangeListener());
|
||||
decimalFormat = new DecimalFormat("#.##");
|
||||
|
||||
subscriptions = new CompositeSubscription();
|
||||
initializeOptions();
|
||||
}
|
||||
|
||||
public void destroy() {
|
||||
subscriptions.unsubscribe();
|
||||
}
|
||||
|
||||
public void toggle() {
|
||||
if (showing)
|
||||
hide();
|
||||
else
|
||||
show();
|
||||
show(true);
|
||||
}
|
||||
|
||||
private void show() {
|
||||
public void show(boolean animate) {
|
||||
menu.setVisibility(View.VISIBLE);
|
||||
|
||||
Animation toolbarAnimation = AnimationUtils.loadAnimation(activity, R.anim.enter_from_top);
|
||||
toolbar.startAnimation(toolbarAnimation);
|
||||
if (animate) {
|
||||
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);
|
||||
Animation bottomMenuAnimation = AnimationUtils.loadAnimation(activity, R.anim.enter_from_bottom);
|
||||
bottomMenu.startAnimation(bottomMenuAnimation);
|
||||
}
|
||||
|
||||
showing = true;
|
||||
}
|
||||
|
||||
private void hide() {
|
||||
public void hide() {
|
||||
Animation toolbarAnimation = AnimationUtils.loadAnimation(activity, R.anim.exit_to_top);
|
||||
toolbarAnimation.setAnimationListener(new HideMenuAnimationListener());
|
||||
toolbar.startAnimation(toolbarAnimation);
|
||||
@ -77,9 +103,9 @@ public class ReaderMenu {
|
||||
|
||||
activity.setToolbarTitle(manga.title);
|
||||
activity.setToolbarSubtitle(chapter.chapter_number != -1 ?
|
||||
activity.getString(R.string.chapter_subtitle,
|
||||
decimalFormat.format(chapter.chapter_number)) :
|
||||
chapter.name);
|
||||
activity.getString(R.string.chapter_subtitle,
|
||||
decimalFormat.format(chapter.chapter_number)) :
|
||||
chapter.name);
|
||||
|
||||
}
|
||||
|
||||
@ -88,6 +114,73 @@ public class ReaderMenu {
|
||||
seekBar.setProgress(pageIndex);
|
||||
}
|
||||
|
||||
private void initializeOptions() {
|
||||
// Orientation changes
|
||||
lockOrientation.setOnClickListener(v ->
|
||||
preferences.setOrientationLocked(!preferences.isOrientationLocked()));
|
||||
|
||||
subscriptions.add(preferences.isOrientationLockedObservable()
|
||||
.subscribe(this::onOrientationOptionChanged));
|
||||
|
||||
// Reader selector
|
||||
readerSelector.setOnClickListener(v -> {
|
||||
final Manga manga = activity.getPresenter().getManga();
|
||||
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();
|
||||
}
|
||||
d.dismiss();
|
||||
})
|
||||
.create();
|
||||
|
||||
// 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());
|
||||
});
|
||||
}
|
||||
|
||||
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 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;
|
||||
}
|
||||
activity.setRequestedOrientation(orientation);
|
||||
}
|
||||
|
||||
class PageSeekBarChangeListener implements SeekBar.OnSeekBarChangeListener {
|
||||
|
||||
@Override
|
||||
|
@ -232,4 +232,13 @@ public class ReaderPresenter extends BasePresenter<ReaderActivity> {
|
||||
loadChapter(previousChapter);
|
||||
}
|
||||
}
|
||||
|
||||
public Manga getManga() {
|
||||
return manga;
|
||||
}
|
||||
|
||||
public void updateMangaViewer(int viewer) {
|
||||
manga.viewer = viewer;
|
||||
db.insertManga(manga).executeAsBlocking();
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
package eu.kanade.mangafeed.ui.reader.viewer.base;
|
||||
|
||||
import android.view.MotionEvent;
|
||||
import android.widget.FrameLayout;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -11,12 +11,12 @@ import eu.kanade.mangafeed.ui.reader.ReaderActivity;
|
||||
public abstract class BaseReader {
|
||||
|
||||
protected ReaderActivity activity;
|
||||
protected FrameLayout container;
|
||||
protected ViewGroup container;
|
||||
protected int currentPosition;
|
||||
|
||||
public BaseReader(ReaderActivity activity, FrameLayout container) {
|
||||
public BaseReader(ReaderActivity activity) {
|
||||
this.activity = activity;
|
||||
this.container = container;
|
||||
this.container = activity.getContainer();
|
||||
}
|
||||
|
||||
public void updatePageNumber() {
|
||||
|
@ -1,7 +1,6 @@
|
||||
package eu.kanade.mangafeed.ui.reader.viewer.horizontal;
|
||||
|
||||
import android.view.MotionEvent;
|
||||
import android.widget.FrameLayout;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -19,8 +18,8 @@ public abstract class HorizontalReader extends BaseReader {
|
||||
|
||||
protected ViewPagerReaderAdapter adapter;
|
||||
|
||||
public HorizontalReader(ReaderActivity activity, FrameLayout container) {
|
||||
super(activity, container);
|
||||
public HorizontalReader(ReaderActivity activity) {
|
||||
super(activity);
|
||||
activity.getLayoutInflater().inflate(R.layout.reader_horizontal, container);
|
||||
ButterKnife.bind(this, container);
|
||||
|
||||
|
@ -1,13 +1,11 @@
|
||||
package eu.kanade.mangafeed.ui.reader.viewer.horizontal;
|
||||
|
||||
import android.widget.FrameLayout;
|
||||
|
||||
import eu.kanade.mangafeed.ui.reader.ReaderActivity;
|
||||
|
||||
public class LeftToRightReader extends HorizontalReader {
|
||||
|
||||
public LeftToRightReader(ReaderActivity activity, FrameLayout container) {
|
||||
super(activity, container);
|
||||
public LeftToRightReader(ReaderActivity activity) {
|
||||
super(activity);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,7 +1,5 @@
|
||||
package eu.kanade.mangafeed.ui.reader.viewer.horizontal;
|
||||
|
||||
import android.widget.FrameLayout;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
@ -11,8 +9,8 @@ import eu.kanade.mangafeed.ui.reader.ReaderActivity;
|
||||
|
||||
public class RightToLeftReader extends HorizontalReader {
|
||||
|
||||
public RightToLeftReader(ReaderActivity activity, FrameLayout container) {
|
||||
super(activity, container);
|
||||
public RightToLeftReader(ReaderActivity activity) {
|
||||
super(activity);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -2,7 +2,6 @@ package eu.kanade.mangafeed.ui.reader.viewer.vertical;
|
||||
|
||||
import android.support.v4.view.ViewPager;
|
||||
import android.view.MotionEvent;
|
||||
import android.widget.FrameLayout;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -20,8 +19,8 @@ public class VerticalReader extends BaseReader {
|
||||
|
||||
private ViewPagerReaderAdapter adapter;
|
||||
|
||||
public VerticalReader(ReaderActivity activity, FrameLayout container) {
|
||||
super(activity, container);
|
||||
public VerticalReader(ReaderActivity activity) {
|
||||
super(activity);
|
||||
activity.getLayoutInflater().inflate(R.layout.reader_vertical, container);
|
||||
ButterKnife.bind(this, container);
|
||||
|
||||
|
@ -3,7 +3,6 @@ package eu.kanade.mangafeed.ui.reader.viewer.webtoon;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.MotionEvent;
|
||||
import android.widget.FrameLayout;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -22,8 +21,8 @@ public class WebtoonReader extends BaseReader {
|
||||
private List<Page> pages;
|
||||
private Subscription subscription;
|
||||
|
||||
public WebtoonReader(ReaderActivity activity, FrameLayout container) {
|
||||
super(activity, container);
|
||||
public WebtoonReader(ReaderActivity activity) {
|
||||
super(activity);
|
||||
|
||||
recycler = new RecyclerView(activity);
|
||||
layoutManager = new LinearLayoutManager(activity);
|
||||
|
Reference in New Issue
Block a user