mirror of
https://github.com/mihonapp/mihon.git
synced 2024-11-21 20:47:03 -05:00
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:
parent
4ba0f343e3
commit
34dc85e605
6 changed files with 96 additions and 19 deletions
|
@ -13,6 +13,7 @@ import java.util.List;
|
|||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import eu.kanade.tachiyomi.data.cache.ChapterCache;
|
||||
import eu.kanade.tachiyomi.data.database.DatabaseHelper;
|
||||
import eu.kanade.tachiyomi.data.database.models.Chapter;
|
||||
import eu.kanade.tachiyomi.data.database.models.Manga;
|
||||
|
@ -43,6 +44,7 @@ public class ReaderPresenter extends BasePresenter<ReaderActivity> {
|
|||
@Inject DownloadManager downloadManager;
|
||||
@Inject MangaSyncManager syncManager;
|
||||
@Inject SourceManager sourceManager;
|
||||
@Inject ChapterCache chapterCache;
|
||||
|
||||
@State Manga manga;
|
||||
@State Chapter activeChapter;
|
||||
|
@ -288,8 +290,14 @@ public class ReaderPresenter extends BasePresenter<ReaderActivity> {
|
|||
}
|
||||
|
||||
public void retryPage(Page page) {
|
||||
page.setStatus(Page.QUEUE);
|
||||
retryPageSubject.onNext(page);
|
||||
if (page != null) {
|
||||
page.setStatus(Page.QUEUE);
|
||||
if (page.getImagePath() != null) {
|
||||
File file = new File(page.getImagePath());
|
||||
chapterCache.removeFileFromCache(file.getName());
|
||||
}
|
||||
retryPageSubject.onNext(page);
|
||||
}
|
||||
}
|
||||
|
||||
// Called before loading another chapter or leaving the reader. It allows to do operations
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -65,21 +65,21 @@ public abstract class PagerReader extends BaseReader {
|
|||
.doOnNext(this::setDecoderClass)
|
||||
.skip(1)
|
||||
.distinctUntilChanged()
|
||||
.subscribe(v -> pager.setAdapter(adapter)));
|
||||
.subscribe(v -> refreshPages()));
|
||||
|
||||
subscriptions.add(preferences.imageScaleType()
|
||||
.asObservable()
|
||||
.doOnNext(this::setImageScaleType)
|
||||
.skip(1)
|
||||
.distinctUntilChanged()
|
||||
.subscribe(v -> pager.setAdapter(adapter)));
|
||||
.subscribe(v -> refreshPages()));
|
||||
|
||||
subscriptions.add(preferences.zoomStart()
|
||||
.asObservable()
|
||||
.doOnNext(this::setZoomStart)
|
||||
.skip(1)
|
||||
.distinctUntilChanged()
|
||||
.subscribe(v -> pager.setAdapter(adapter)));
|
||||
.subscribe(v -> refreshPages()));
|
||||
|
||||
subscriptions.add(preferences.enableTransitions()
|
||||
.asObservable()
|
||||
|
@ -147,6 +147,11 @@ public abstract class PagerReader extends BaseReader {
|
|||
pager.setCurrentItem(pageNumber, false);
|
||||
}
|
||||
|
||||
private void refreshPages() {
|
||||
pager.setAdapter(adapter);
|
||||
pager.setCurrentItem(currentPage, false);
|
||||
}
|
||||
|
||||
protected void onLeftSideTap() {
|
||||
moveToPrevious();
|
||||
}
|
||||
|
|
|
@ -4,7 +4,6 @@ import android.graphics.PointF;
|
|||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.view.Gravity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MotionEvent;
|
||||
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.ui.base.fragment.BaseFragment;
|
||||
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.vertical.VerticalReader;
|
||||
import rx.Observable;
|
||||
|
@ -103,14 +103,13 @@ public class PagerReaderFragment extends BaseFragment {
|
|||
|
||||
@Override
|
||||
public void onImageLoadError(Exception e) {
|
||||
showImageLoadError();
|
||||
showImageDecodeError();
|
||||
}
|
||||
});
|
||||
|
||||
retryButton.setOnTouchListener((v, event) -> {
|
||||
if (event.getAction() == MotionEvent.ACTION_UP) {
|
||||
if (page != null)
|
||||
activity.getPresenter().retryPage(page);
|
||||
activity.getPresenter().retryPage(page);
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
@ -175,18 +174,16 @@ public class PagerReaderFragment extends BaseFragment {
|
|||
retryButton.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
private void showImageLoadError() {
|
||||
private void showImageDecodeError() {
|
||||
ViewGroup view = (ViewGroup) getView();
|
||||
if (view == null)
|
||||
return;
|
||||
|
||||
TextView errorText = new TextView(getContext());
|
||||
errorText.setGravity(Gravity.CENTER);
|
||||
errorText.setText(R.string.decode_image_error);
|
||||
errorText.setTextColor(getReaderActivity().getReaderTheme() == ReaderActivity.BLACK_THEME ?
|
||||
lightGreyColor : blackColor);
|
||||
LinearLayout errorLayout = new PageDecodeErrorLayout(getContext(), page,
|
||||
getReaderActivity().getReaderTheme(),
|
||||
() -> getReaderActivity().getPresenter().retryPage(page));
|
||||
|
||||
view.addView(errorText);
|
||||
view.addView(errorLayout);
|
||||
}
|
||||
|
||||
private void processStatus(int status) {
|
||||
|
|
|
@ -62,8 +62,7 @@ public class WebtoonHolder extends RecyclerView.ViewHolder {
|
|||
container.setOnTouchListener(touchListener);
|
||||
retryButton.setOnTouchListener((v, event) -> {
|
||||
if (event.getAction() == MotionEvent.ACTION_UP) {
|
||||
if (page != null)
|
||||
adapter.retryPage(page);
|
||||
adapter.retryPage(page);
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
|
|
@ -41,6 +41,7 @@
|
|||
<string name="action_previous_chapter">Previous chapter</string>
|
||||
<string name="action_next_chapter">Next chapter</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>
|
||||
|
||||
<!-- Buttons -->
|
||||
|
@ -211,7 +212,7 @@
|
|||
<string name="chapter_subtitle">Chapter %1$s</string>
|
||||
<string name="no_next_chapter">Next 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>
|
||||
|
||||
<!-- Downloads activity and service -->
|
||||
|
|
Loading…
Reference in a new issue