Improve reader gestures. Upgrade gradle and retrolambda.

This commit is contained in:
inorichi 2015-11-28 23:32:13 +01:00
parent c803b91223
commit a05cc934d0
7 changed files with 31 additions and 47 deletions

View file

@ -7,7 +7,6 @@ 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;
@ -82,14 +81,6 @@ public class ReaderActivity extends BaseRxActivity<ReaderPresenter> {
initializeSettings();
}
@Override
protected void onDestroy() {
readerMenu.destroy();
if (viewer != null)
viewer.destroy();
super.onDestroy();
}
@Override
protected void onResume() {
super.onResume();
@ -103,6 +94,14 @@ public class ReaderActivity extends BaseRxActivity<ReaderPresenter> {
super.onPause();
}
@Override
protected void onDestroy() {
readerMenu.destroy();
if (viewer != null)
viewer.destroy();
super.onDestroy();
}
@Override
protected void onSaveInstanceState(@NonNull Bundle outState) {
Icepick.saveInstanceState(readerMenu, outState);
@ -146,10 +145,6 @@ public class ReaderActivity extends BaseRxActivity<ReaderPresenter> {
viewer.setSelectedPage(pageIndex);
}
public boolean onImageSingleTap(MotionEvent motionEvent) {
return viewer.onImageTouch(motionEvent);
}
public void onCenterSingleTap() {
readerMenu.toggle();
}
@ -262,4 +257,8 @@ public class ReaderActivity extends BaseRxActivity<ReaderPresenter> {
return preferences;
}
public BaseReader getViewer() {
return viewer;
}
}

View file

@ -181,15 +181,14 @@ public class ReaderPresenter extends BasePresenter<ReaderActivity> {
nextChapterPageList = pages;
// Preload at most 5 pages
int pagesToPreload = Math.min(pages.size(), 5);
return Observable.from(pages)
.take(pagesToPreload)
.concatMap(page -> page.getImageUrl() == null ?
source.getImageUrlFromPage(page) :
Observable.just(page))
.doOnCompleted(this::stopPreloadingNextChapter);
return Observable.from(pages).take(pagesToPreload);
})
.concatMap(page -> page.getImageUrl() == null ?
source.getImageUrlFromPage(page) :
Observable.just(page))
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread());
.observeOn(AndroidSchedulers.mainThread())
.doOnCompleted(this::stopPreloadingNextChapter);
}
// Loads the given chapter

View file

@ -3,6 +3,7 @@ package eu.kanade.mangafeed.ui.reader.viewer.common;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
@ -18,7 +19,6 @@ import java.util.concurrent.atomic.AtomicInteger;
import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;
import de.greenrobot.event.EventBus;
import eu.kanade.mangafeed.R;
import eu.kanade.mangafeed.data.source.model.Page;
@ -37,7 +37,6 @@ public class ViewPagerReaderFragment extends BaseFragment {
@Bind(R.id.progress_container) LinearLayout progressContainer;
@Bind(R.id.progress) ProgressBar progressBar;
@Bind(R.id.progress_text) TextView progressText;
@Bind(R.id.image_error) TextView errorText;
@Bind(R.id.retry_button) Button retryButton;
private Page page;
@ -59,7 +58,16 @@ public class ViewPagerReaderFragment extends BaseFragment {
imageView.setPanLimit(SubsamplingScaleImageView.PAN_LIMIT_INSIDE);
imageView.setMinimumScaleType(SubsamplingScaleImageView.SCALE_TYPE_CENTER_INSIDE);
imageView.setOnTouchListener((v, motionEvent) ->
((ReaderActivity) getActivity()).onImageSingleTap(motionEvent));
((ReaderActivity) getActivity()).getViewer().onImageTouch(motionEvent));
retryButton.setOnTouchListener((v, event) -> {
if (event.getAction() == MotionEvent.ACTION_UP) {
if (page != null)
EventBus.getDefault().postSticky(new RetryPageEvent(page));
return true;
}
return true;
});
return view;
}
@ -86,11 +94,6 @@ public class ViewPagerReaderFragment extends BaseFragment {
this.page = page;
}
@OnClick(R.id.retry_button)
void retry() {
EventBus.getDefault().postSticky(new RetryPageEvent(page));
}
private void showImage() {
if (page == null || page.getImagePath() == null)
return;
@ -112,12 +115,10 @@ public class ViewPagerReaderFragment extends BaseFragment {
private void showError() {
progressContainer.setVisibility(View.GONE);
errorText.setVisibility(View.VISIBLE);
retryButton.setVisibility(View.VISIBLE);
}
private void hideError() {
errorText.setVisibility(View.GONE);
retryButton.setVisibility(View.GONE);
}

View file

@ -26,8 +26,6 @@ public class HorizontalViewPager extends ViewPager {
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
try {
gestureDetector.onTouchEvent(ev);
if ((ev.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) {
if (this.getCurrentItem() == 0 || this.getCurrentItem() == this.getAdapter().getCount() - 1) {
startDragX = ev.getX();
@ -85,7 +83,6 @@ public class HorizontalViewPager extends ViewPager {
public interface OnChapterBoundariesOutListener {
void onFirstPageOutEvent();
void onLastPageOutEvent();
}

View file

@ -25,8 +25,6 @@ public class VerticalViewPager extends fr.castorflex.android.verticalviewpager.V
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
try {
gestureDetector.onTouchEvent(ev);
if ((ev.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) {
if (this.getCurrentItem() == 0 || this.getCurrentItem() == this.getAdapter().getCount() - 1) {
startDragY = ev.getY();
@ -84,7 +82,6 @@ public class VerticalViewPager extends fr.castorflex.android.verticalviewpager.V
public interface OnChapterBoundariesOutListener {
void onFirstPageOutEvent();
void onLastPageOutEvent();
}

View file

@ -30,15 +30,6 @@
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/image_error"
android:text=":("
android:layout_gravity="center"
android:textSize="32sp"
android:visibility="gone"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"

View file

@ -6,9 +6,9 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.3.0'
classpath 'com.android.tools.build:gradle:1.5.0'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.7'
classpath 'me.tatarka:gradle-retrolambda:3.2.3'
classpath 'me.tatarka:gradle-retrolambda:3.2.4'
classpath 'com.github.ben-manes:gradle-versions-plugin:0.11.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files