mirror of
https://github.com/mihonapp/mihon.git
synced 2024-11-21 20:47:03 -05:00
Volume keys scroll pages. Closes #95
This commit is contained in:
parent
e50c683159
commit
0c0ebe06e5
5 changed files with 54 additions and 10 deletions
|
@ -10,6 +10,7 @@ import android.support.annotation.NonNull;
|
|||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.Surface;
|
||||
|
@ -153,6 +154,24 @@ public class ReaderActivity extends BaseRxActivity<ReaderPresenter> {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean dispatchKeyEvent(KeyEvent event) {
|
||||
int action = event.getAction();
|
||||
int keyCode = event.getKeyCode();
|
||||
switch (keyCode) {
|
||||
case KeyEvent.KEYCODE_VOLUME_DOWN:
|
||||
if (action == KeyEvent.ACTION_UP && viewer != null)
|
||||
viewer.moveToNext();
|
||||
return true;
|
||||
case KeyEvent.KEYCODE_VOLUME_UP:
|
||||
if (action == KeyEvent.ACTION_UP && viewer != null)
|
||||
viewer.moveToPrevious();
|
||||
return true;
|
||||
default:
|
||||
return super.dispatchKeyEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
public void onChapterError() {
|
||||
finish();
|
||||
ToastUtil.showShort(this, R.string.page_list_error);
|
||||
|
|
|
@ -93,6 +93,8 @@ public abstract class BaseReader extends BaseFragment {
|
|||
public abstract void setSelectedPage(int pageNumber);
|
||||
public abstract void onSetChapter(Chapter chapter, Page currentPage);
|
||||
public abstract void onAppendChapter(Chapter chapter);
|
||||
public abstract void moveToNext();
|
||||
public abstract void moveToPrevious();
|
||||
|
||||
public void setDecoderClass(int value) {
|
||||
switch (value) {
|
||||
|
|
|
@ -148,14 +148,14 @@ public abstract class PagerReader extends BaseReader {
|
|||
}
|
||||
|
||||
protected void onLeftSideTap() {
|
||||
if (pager.getCurrentItem() != 0) {
|
||||
pager.setCurrentItem(pager.getCurrentItem() - 1, transitions);
|
||||
} else {
|
||||
getReaderActivity().requestPreviousChapter();
|
||||
}
|
||||
moveToPrevious();
|
||||
}
|
||||
|
||||
protected void onRightSideTap() {
|
||||
moveToNext();
|
||||
}
|
||||
|
||||
public void moveToNext() {
|
||||
if (pager.getCurrentItem() != pager.getAdapter().getCount() - 1) {
|
||||
pager.setCurrentItem(pager.getCurrentItem() + 1, transitions);
|
||||
} else {
|
||||
|
@ -163,6 +163,14 @@ public abstract class PagerReader extends BaseReader {
|
|||
}
|
||||
}
|
||||
|
||||
public void moveToPrevious() {
|
||||
if (pager.getCurrentItem() != 0) {
|
||||
pager.setCurrentItem(pager.getCurrentItem() - 1, transitions);
|
||||
} else {
|
||||
getReaderActivity().requestPreviousChapter();
|
||||
}
|
||||
}
|
||||
|
||||
private void setImageScaleType(int scaleType) {
|
||||
this.scaleType = scaleType;
|
||||
}
|
||||
|
|
|
@ -19,12 +19,12 @@ public class RightToLeftReader extends PagerReader {
|
|||
|
||||
@Override
|
||||
protected void onLeftSideTap() {
|
||||
super.onRightSideTap();
|
||||
moveToNext();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onRightSideTap() {
|
||||
super.onLeftSideTap();
|
||||
moveToPrevious();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -69,9 +69,9 @@ public class WebtoonReader extends BaseReader {
|
|||
final float positionX = e.getX();
|
||||
|
||||
if (positionX < recycler.getWidth() * LEFT_REGION) {
|
||||
recycler.smoothScrollBy(0, -scrollDistance);
|
||||
moveToPrevious();
|
||||
} else if (positionX > recycler.getWidth() * RIGHT_REGION) {
|
||||
recycler.smoothScrollBy(0, scrollDistance);
|
||||
moveToNext();
|
||||
} else {
|
||||
getReaderActivity().onCenterSingleTap();
|
||||
}
|
||||
|
@ -113,6 +113,16 @@ public class WebtoonReader extends BaseReader {
|
|||
recycler.scrollToPosition(pageNumber);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void moveToNext() {
|
||||
recycler.smoothScrollBy(0, scrollDistance);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void moveToPrevious() {
|
||||
recycler.smoothScrollBy(0, -scrollDistance);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSetChapter(Chapter chapter, Page currentPage) {
|
||||
pages = new ArrayList<>(chapter.getPages());
|
||||
|
@ -134,6 +144,9 @@ public class WebtoonReader extends BaseReader {
|
|||
if (recycler != null) {
|
||||
adapter.setPages(pages);
|
||||
adapter.notifyItemRangeInserted(insertStart, chapter.getPages().size());
|
||||
if (subscription != null && subscription.isUnsubscribed()) {
|
||||
observeStatus(insertStart);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -162,8 +175,10 @@ public class WebtoonReader extends BaseReader {
|
|||
}
|
||||
|
||||
private void observeStatus(int position) {
|
||||
if (position == pages.size())
|
||||
if (position == pages.size()) {
|
||||
unsubscribeStatus();
|
||||
return;
|
||||
}
|
||||
|
||||
final Page page = pages.get(position);
|
||||
|
||||
|
|
Loading…
Reference in a new issue