More improvements to webtoon viewer

This commit is contained in:
inorichi 2015-11-11 04:56:16 +01:00
parent 692d3c1b2c
commit 089b5d3326
7 changed files with 97 additions and 14 deletions

View file

@ -26,6 +26,7 @@ import eu.kanade.mangafeed.data.models.MangaStorIOSQLitePutResolver;
import eu.kanade.mangafeed.data.resolvers.MangaWithUnreadGetResolver;
import eu.kanade.mangafeed.data.tables.ChaptersTable;
import eu.kanade.mangafeed.data.tables.MangasTable;
import eu.kanade.mangafeed.util.ChapterRecognition;
import eu.kanade.mangafeed.util.PostResult;
import rx.Observable;
@ -192,6 +193,10 @@ public class DatabaseHelper {
Observable<Integer> newChaptersObs = chapterList
.flatMap(dbChapters -> Observable.from(chapters)
.filter(c -> !dbChapters.contains(c))
.map(c -> {
ChapterRecognition.parseChapterNumber(c, manga);
return c;
})
.toList()
.flatMap(newChapters -> insertChapters(newChapters).createObservable())
.map(PutResults::numberOfInserts));

View file

@ -78,6 +78,7 @@ public class ReaderActivity extends BaseRxActivity<ReaderPresenter> {
@Override
protected void onPause() {
getPresenter().setCurrentPage(viewer.getCurrentPosition());
viewer.destroySubscriptions();
super.onPause();
}

View file

@ -2,6 +2,7 @@ package eu.kanade.mangafeed.ui.adapter;
import android.content.Context;
import android.view.View;
import android.widget.ProgressBar;
import com.davemorrissey.labs.subscaleview.ImageSource;
import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView;
@ -41,10 +42,16 @@ public class WebtoonAdapter extends BaseEasyRecyclerAdapter<Page> {
notifyDataSetChanged();
}
@LayoutId(R.layout.chapter_image)
public void addPage(Page page) {
pages.add(page);
notifyItemChanged(page.getPageNumber());
}
@LayoutId(R.layout.item_webtoon_viewer)
static class ImageViewHolder extends ItemViewHolder<Page> {
@ViewId(R.id.page_image_view) SubsamplingScaleImageView imageView;
@ViewId(R.id.progress) ProgressBar progressBar;
public ImageViewHolder(View view) {
super(view);
@ -60,8 +67,10 @@ public class WebtoonAdapter extends BaseEasyRecyclerAdapter<Page> {
if (page.getImagePath() != null) {
imageView.setVisibility(View.VISIBLE);
imageView.setImage(ImageSource.uri(page.getImagePath()).tilingDisabled());
progressBar.setVisibility(View.GONE);
} else {
imageView.setVisibility(View.GONE);
progressBar.setVisibility(View.VISIBLE);
}
}

View file

@ -11,27 +11,43 @@ import eu.kanade.mangafeed.data.models.Page;
import eu.kanade.mangafeed.ui.activity.ReaderActivity;
import eu.kanade.mangafeed.ui.adapter.WebtoonAdapter;
import eu.kanade.mangafeed.ui.viewer.base.BaseViewer;
import rx.Subscription;
import rx.android.schedulers.AndroidSchedulers;
import rx.subjects.PublishSubject;
public class WebtoonViewer extends BaseViewer {
private RecyclerView recycler;
private LinearLayoutManager layoutManager;
private WebtoonAdapter adapter;
private List<Page> pages;
private Subscription subscription;
public WebtoonViewer(ReaderActivity activity, FrameLayout container) {
super(activity, container);
recycler = new RecyclerView(activity);
LinearLayoutManager layoutManager = new LinearLayoutManager(activity);
layoutManager = new LinearLayoutManager(activity);
recycler.setLayoutManager(layoutManager);
adapter = new WebtoonAdapter(activity);
recycler.setAdapter(adapter);
recycler.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
currentPosition = layoutManager.findFirstVisibleItemPosition();
updatePageNumber();
}
});
container.addView(recycler);
}
@Override
public int getTotalPages() {
return adapter.getItemCount();
return pages.size();
}
@Override
@ -42,11 +58,52 @@ public class WebtoonViewer extends BaseViewer {
@Override
public void onPageListReady(List<Page> pages) {
adapter.setPages(pages);
this.pages = pages;
observeStatus(0);
}
@Override
public boolean onImageTouch(MotionEvent motionEvent) {
return true;
}
private void observeStatus(int position) {
if (position == pages.size())
return;
final Page page = pages.get(position);
adapter.addPage(page);
PublishSubject<Integer> statusSubject = PublishSubject.create();
page.setStatusSubject(statusSubject);
if (subscription != null && !subscription.isUnsubscribed())
subscription.unsubscribe();
subscription = statusSubject
.startWith(page.getStatus())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(status -> processStatus(position, status));
}
private void processStatus(int position, int status) {
switch (status) {
case Page.LOAD_PAGE:
break;
case Page.DOWNLOAD_IMAGE:
break;
case Page.READY:
adapter.notifyItemChanged(position);
observeStatus(position + 1);
break;
case Page.ERROR:
break;
}
}
@Override
public void destroySubscriptions() {
if (subscription != null && !subscription.isUnsubscribed())
subscription.unsubscribe();
}
}

View file

@ -33,6 +33,8 @@ public abstract class BaseViewer {
return getCurrentPageIndex(currentPosition);
}
public void destroySubscriptions() {}
public abstract int getTotalPages();
public abstract void setSelectedPage(int pageNumber);
public abstract void onPageListReady(List<Page> pages);

View file

@ -1,13 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
<com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/page_image_view" />
</LinearLayout>

View file

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ProgressBar
android:id="@+id/progress"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal"/>
<include layout="@layout/chapter_image"/>
</FrameLayout>