Allow to retry image when decoding fails or open in the browser. Fixes #177 and fixes #120. Also fix a bug where the current page was not restored when changing settings.

This commit is contained in:
inorichi 2016-02-23 20:02:49 +01:00
parent 4ba0f343e3
commit 34dc85e605
6 changed files with 96 additions and 19 deletions

View file

@ -13,6 +13,7 @@ import java.util.List;
import javax.inject.Inject; import javax.inject.Inject;
import eu.kanade.tachiyomi.data.cache.ChapterCache;
import eu.kanade.tachiyomi.data.database.DatabaseHelper; import eu.kanade.tachiyomi.data.database.DatabaseHelper;
import eu.kanade.tachiyomi.data.database.models.Chapter; import eu.kanade.tachiyomi.data.database.models.Chapter;
import eu.kanade.tachiyomi.data.database.models.Manga; import eu.kanade.tachiyomi.data.database.models.Manga;
@ -43,6 +44,7 @@ public class ReaderPresenter extends BasePresenter<ReaderActivity> {
@Inject DownloadManager downloadManager; @Inject DownloadManager downloadManager;
@Inject MangaSyncManager syncManager; @Inject MangaSyncManager syncManager;
@Inject SourceManager sourceManager; @Inject SourceManager sourceManager;
@Inject ChapterCache chapterCache;
@State Manga manga; @State Manga manga;
@State Chapter activeChapter; @State Chapter activeChapter;
@ -288,9 +290,15 @@ public class ReaderPresenter extends BasePresenter<ReaderActivity> {
} }
public void retryPage(Page page) { public void retryPage(Page page) {
if (page != null) {
page.setStatus(Page.QUEUE); page.setStatus(Page.QUEUE);
if (page.getImagePath() != null) {
File file = new File(page.getImagePath());
chapterCache.removeFileFromCache(file.getName());
}
retryPageSubject.onNext(page); retryPageSubject.onNext(page);
} }
}
// Called before loading another chapter or leaving the reader. It allows to do operations // Called before loading another chapter or leaving the reader. It allows to do operations
// over the chapter read like saving progress // over the chapter read like saving progress

View file

@ -0,0 +1,67 @@
package eu.kanade.tachiyomi.ui.reader.viewer.base;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.support.v4.content.ContextCompat;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;
import eu.kanade.tachiyomi.R;
import eu.kanade.tachiyomi.data.source.model.Page;
import eu.kanade.tachiyomi.ui.reader.ReaderActivity;
import rx.functions.Action0;
import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
public class PageDecodeErrorLayout extends LinearLayout {
private final int lightGreyColor;
private final int blackColor;
public PageDecodeErrorLayout(Context context) {
super(context);
setOrientation(LinearLayout.VERTICAL);
setGravity(Gravity.CENTER);
lightGreyColor = ContextCompat.getColor(context, R.color.light_grey);
blackColor = ContextCompat.getColor(context, R.color.primary_text);
}
public PageDecodeErrorLayout(Context context, Page page, int theme, Action0 retryListener) {
this(context);
TextView errorText = new TextView(context);
errorText.setGravity(Gravity.CENTER);
errorText.setText(R.string.decode_image_error);
errorText.setTextColor(theme == ReaderActivity.BLACK_THEME ? lightGreyColor : blackColor);
Button retryButton = new Button(context);
retryButton.setLayoutParams(new ViewGroup.LayoutParams(WRAP_CONTENT, WRAP_CONTENT));
retryButton.setText(R.string.action_retry);
retryButton.setOnClickListener((v) -> {
removeAllViews();
retryListener.call();
});
Button openInBrowserButton = new Button(context);
openInBrowserButton.setLayoutParams(new ViewGroup.LayoutParams(WRAP_CONTENT, WRAP_CONTENT));
openInBrowserButton.setText(R.string.action_open_in_browser);
openInBrowserButton.setOnClickListener((v) -> {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(page.getImageUrl()));
context.startActivity(intent);
});
if (page.getImageUrl() == null) {
openInBrowserButton.setVisibility(View.GONE);
}
addView(errorText);
addView(retryButton);
addView(openInBrowserButton);
}
}

View file

@ -65,21 +65,21 @@ public abstract class PagerReader extends BaseReader {
.doOnNext(this::setDecoderClass) .doOnNext(this::setDecoderClass)
.skip(1) .skip(1)
.distinctUntilChanged() .distinctUntilChanged()
.subscribe(v -> pager.setAdapter(adapter))); .subscribe(v -> refreshPages()));
subscriptions.add(preferences.imageScaleType() subscriptions.add(preferences.imageScaleType()
.asObservable() .asObservable()
.doOnNext(this::setImageScaleType) .doOnNext(this::setImageScaleType)
.skip(1) .skip(1)
.distinctUntilChanged() .distinctUntilChanged()
.subscribe(v -> pager.setAdapter(adapter))); .subscribe(v -> refreshPages()));
subscriptions.add(preferences.zoomStart() subscriptions.add(preferences.zoomStart()
.asObservable() .asObservable()
.doOnNext(this::setZoomStart) .doOnNext(this::setZoomStart)
.skip(1) .skip(1)
.distinctUntilChanged() .distinctUntilChanged()
.subscribe(v -> pager.setAdapter(adapter))); .subscribe(v -> refreshPages()));
subscriptions.add(preferences.enableTransitions() subscriptions.add(preferences.enableTransitions()
.asObservable() .asObservable()
@ -147,6 +147,11 @@ public abstract class PagerReader extends BaseReader {
pager.setCurrentItem(pageNumber, false); pager.setCurrentItem(pageNumber, false);
} }
private void refreshPages() {
pager.setAdapter(adapter);
pager.setCurrentItem(currentPage, false);
}
protected void onLeftSideTap() { protected void onLeftSideTap() {
moveToPrevious(); moveToPrevious();
} }

View file

@ -4,7 +4,6 @@ import android.graphics.PointF;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat; import android.support.v4.content.ContextCompat;
import android.view.Gravity;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.view.View; import android.view.View;
@ -27,6 +26,7 @@ import eu.kanade.tachiyomi.R;
import eu.kanade.tachiyomi.data.source.model.Page; import eu.kanade.tachiyomi.data.source.model.Page;
import eu.kanade.tachiyomi.ui.base.fragment.BaseFragment; import eu.kanade.tachiyomi.ui.base.fragment.BaseFragment;
import eu.kanade.tachiyomi.ui.reader.ReaderActivity; import eu.kanade.tachiyomi.ui.reader.ReaderActivity;
import eu.kanade.tachiyomi.ui.reader.viewer.base.PageDecodeErrorLayout;
import eu.kanade.tachiyomi.ui.reader.viewer.pager.horizontal.RightToLeftReader; import eu.kanade.tachiyomi.ui.reader.viewer.pager.horizontal.RightToLeftReader;
import eu.kanade.tachiyomi.ui.reader.viewer.pager.vertical.VerticalReader; import eu.kanade.tachiyomi.ui.reader.viewer.pager.vertical.VerticalReader;
import rx.Observable; import rx.Observable;
@ -103,13 +103,12 @@ public class PagerReaderFragment extends BaseFragment {
@Override @Override
public void onImageLoadError(Exception e) { public void onImageLoadError(Exception e) {
showImageLoadError(); showImageDecodeError();
} }
}); });
retryButton.setOnTouchListener((v, event) -> { retryButton.setOnTouchListener((v, event) -> {
if (event.getAction() == MotionEvent.ACTION_UP) { if (event.getAction() == MotionEvent.ACTION_UP) {
if (page != null)
activity.getPresenter().retryPage(page); activity.getPresenter().retryPage(page);
} }
return true; return true;
@ -175,18 +174,16 @@ public class PagerReaderFragment extends BaseFragment {
retryButton.setVisibility(View.GONE); retryButton.setVisibility(View.GONE);
} }
private void showImageLoadError() { private void showImageDecodeError() {
ViewGroup view = (ViewGroup) getView(); ViewGroup view = (ViewGroup) getView();
if (view == null) if (view == null)
return; return;
TextView errorText = new TextView(getContext()); LinearLayout errorLayout = new PageDecodeErrorLayout(getContext(), page,
errorText.setGravity(Gravity.CENTER); getReaderActivity().getReaderTheme(),
errorText.setText(R.string.decode_image_error); () -> getReaderActivity().getPresenter().retryPage(page));
errorText.setTextColor(getReaderActivity().getReaderTheme() == ReaderActivity.BLACK_THEME ?
lightGreyColor : blackColor);
view.addView(errorText); view.addView(errorLayout);
} }
private void processStatus(int status) { private void processStatus(int status) {

View file

@ -62,7 +62,6 @@ public class WebtoonHolder extends RecyclerView.ViewHolder {
container.setOnTouchListener(touchListener); container.setOnTouchListener(touchListener);
retryButton.setOnTouchListener((v, event) -> { retryButton.setOnTouchListener((v, event) -> {
if (event.getAction() == MotionEvent.ACTION_UP) { if (event.getAction() == MotionEvent.ACTION_UP) {
if (page != null)
adapter.retryPage(page); adapter.retryPage(page);
} }
return true; return true;

View file

@ -41,6 +41,7 @@
<string name="action_previous_chapter">Previous chapter</string> <string name="action_previous_chapter">Previous chapter</string>
<string name="action_next_chapter">Next chapter</string> <string name="action_next_chapter">Next chapter</string>
<string name="action_retry">Retry</string> <string name="action_retry">Retry</string>
<string name="action_open_in_browser">Open in browser</string>
<string name="action_display_mode">Change display mode</string> <string name="action_display_mode">Change display mode</string>
<!-- Buttons --> <!-- Buttons -->
@ -211,7 +212,7 @@
<string name="chapter_subtitle">Chapter %1$s</string> <string name="chapter_subtitle">Chapter %1$s</string>
<string name="no_next_chapter">Next chapter not found</string> <string name="no_next_chapter">Next chapter not found</string>
<string name="no_previous_chapter">Previous chapter not found</string> <string name="no_previous_chapter">Previous chapter not found</string>
<string name="decode_image_error">Image could not be loaded.\nTry changing the image decoder</string> <string name="decode_image_error">Image could not be loaded.\nTry changing the image decoder or with one of the options below</string>
<string name="confirm_update_manga_sync">Update last chapter read in enabled services to %1$d?</string> <string name="confirm_update_manga_sync">Update last chapter read in enabled services to %1$d?</string>
<!-- Downloads activity and service --> <!-- Downloads activity and service -->