diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/reader/viewer/common/PagerReaderFragment.java b/app/src/main/java/eu/kanade/mangafeed/ui/reader/viewer/common/PagerReaderFragment.java index bcdad34e1f..2e59d7a05f 100644 --- a/app/src/main/java/eu/kanade/mangafeed/ui/reader/viewer/common/PagerReaderFragment.java +++ b/app/src/main/java/eu/kanade/mangafeed/ui/reader/viewer/common/PagerReaderFragment.java @@ -51,7 +51,7 @@ public class PagerReaderFragment extends BaseFragment { @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { - View view = inflater.inflate(R.layout.fragment_page, container, false); + View view = inflater.inflate(R.layout.item_pager_reader, container, false); ButterKnife.bind(this, view); ReaderActivity activity = (ReaderActivity) getActivity(); diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/reader/viewer/webtoon/WebtoonAdapter.java b/app/src/main/java/eu/kanade/mangafeed/ui/reader/viewer/webtoon/WebtoonAdapter.java index baf9f60fb0..ee19e380d2 100644 --- a/app/src/main/java/eu/kanade/mangafeed/ui/reader/viewer/webtoon/WebtoonAdapter.java +++ b/app/src/main/java/eu/kanade/mangafeed/ui/reader/viewer/webtoon/WebtoonAdapter.java @@ -4,31 +4,23 @@ import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.view.animation.Animation; -import android.view.animation.AnimationUtils; -import android.widget.ProgressBar; - -import com.davemorrissey.labs.subscaleview.ImageSource; -import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView; import java.util.ArrayList; import java.util.List; -import butterknife.Bind; -import butterknife.ButterKnife; import eu.kanade.mangafeed.R; import eu.kanade.mangafeed.data.source.model.Page; -public class WebtoonAdapter extends RecyclerView.Adapter { +public class WebtoonAdapter extends RecyclerView.Adapter { - private List pages; private WebtoonReader fragment; - private View.OnTouchListener listener; + private List pages; + private View.OnTouchListener touchListener; public WebtoonAdapter(WebtoonReader fragment) { this.fragment = fragment; pages = new ArrayList<>(); - listener = (v, event) -> fragment.onImageTouch(event); + touchListener = (v, event) -> fragment.onImageTouch(event); } public Page getItem(int position) { @@ -36,14 +28,14 @@ public class WebtoonAdapter extends RecyclerView.Adapter pages) { + this.pages = pages; + notifyDataSetChanged(); } public void clear() { @@ -65,41 +57,8 @@ public class WebtoonAdapter extends RecyclerView.Adapter { + if (event.getAction() == MotionEvent.ACTION_UP) { + if (page != null) + adapter.retryPage(page); + return true; + } + return true; + }); + } + + public void onSetValues(Page page) { + this.page = page; + switch (page.getStatus()) { + case Page.QUEUE: + onQueue(); + break; + case Page.LOAD_PAGE: + onLoading(); + break; + case Page.DOWNLOAD_IMAGE: + onLoading(); + break; + case Page.READY: + onReady(); + break; + case Page.ERROR: + onError(); + break; + } + } + + private void onLoading() { + setErrorButtonVisible(false); + setImageVisible(false); + setProgressVisible(true); + } + + private void onReady() { + setErrorButtonVisible(false); + setProgressVisible(false); + setImageVisible(true); + imageView.setImage(ImageSource.uri(page.getImagePath())); + } + + private void onError() { + setImageVisible(false); + setProgressVisible(false); + setErrorButtonVisible(true); + } + + private void onQueue() { + setImageVisible(false); + setErrorButtonVisible(false); + setProgressVisible(false); + } + + private void setProgressVisible(boolean visible) { + progressBar.setVisibility(visible ? View.VISIBLE : View.GONE); + } + + private void setImageVisible(boolean visible) { + imageView.setVisibility(visible ? View.VISIBLE : View.GONE); + } + + private void setErrorButtonVisible(boolean visible) { + retryButton.setVisibility(visible ? View.VISIBLE : View.GONE); + } +} \ No newline at end of file diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/reader/viewer/webtoon/WebtoonReader.java b/app/src/main/java/eu/kanade/mangafeed/ui/reader/viewer/webtoon/WebtoonReader.java index cb752ccc4e..169604adbb 100644 --- a/app/src/main/java/eu/kanade/mangafeed/ui/reader/viewer/webtoon/WebtoonReader.java +++ b/app/src/main/java/eu/kanade/mangafeed/ui/reader/viewer/webtoon/WebtoonReader.java @@ -25,6 +25,7 @@ public class WebtoonReader extends BaseReader { private WebtoonAdapter adapter; private RecyclerView recycler; + private PreCachingLayoutManager layoutManager; private Subscription subscription; private GestureDetector gestureDetector; @@ -32,7 +33,7 @@ public class WebtoonReader extends BaseReader { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedState) { adapter = new WebtoonAdapter(this); - PreCachingLayoutManager layoutManager = new PreCachingLayoutManager(getActivity()); + layoutManager = new PreCachingLayoutManager(getActivity()); layoutManager.setExtraLayoutSpace(getResources().getDisplayMetrics().heightPixels); recycler = new RecyclerView(getActivity()); @@ -40,15 +41,6 @@ public class WebtoonReader extends BaseReader { recycler.setLayoutManager(layoutManager); recycler.setItemAnimator(null); recycler.setAdapter(adapter); - recycler.addOnScrollListener(new RecyclerView.OnScrollListener() { - @Override - public void onScrolled(RecyclerView recyclerView, int dx, int dy) { - super.onScrolled(recyclerView, dx, dy); - - currentPage = layoutManager.findLastVisibleItemPosition(); - updatePageNumber(); - } - }); gestureDetector = new GestureDetector(getActivity(), new SimpleOnGestureListener() { @Override @@ -100,11 +92,27 @@ public class WebtoonReader extends BaseReader { private void setPages() { if (pages != null) { unsubscribeStatus(); + recycler.clearOnScrollListeners(); adapter.clear(); + recycler.scrollTo(0, 0); + adapter.setPages(pages); + setScrollListener(); observeStatus(0); } } + private void setScrollListener() { + recycler.addOnScrollListener(new RecyclerView.OnScrollListener() { + @Override + public void onScrolled(RecyclerView recyclerView, int dx, int dy) { + super.onScrolled(recyclerView, dx, dy); + + currentPage = layoutManager.findLastVisibleItemPosition(); + updatePageNumber(); + } + }); + } + @Override public boolean onImageTouch(MotionEvent motionEvent) { return gestureDetector.onTouchEvent(motionEvent); @@ -115,7 +123,6 @@ public class WebtoonReader extends BaseReader { return; final Page page = pages.get(position); - adapter.addPage(page); PublishSubject statusSubject = PublishSubject.create(); page.setStatusSubject(statusSubject); @@ -130,17 +137,9 @@ public class WebtoonReader extends BaseReader { } 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; + adapter.notifyItemChanged(position); + if (status == Page.READY) { + observeStatus(position + 1); } } diff --git a/app/src/main/res/layout/fragment_page.xml b/app/src/main/res/layout/item_pager_reader.xml similarity index 95% rename from app/src/main/res/layout/fragment_page.xml rename to app/src/main/res/layout/item_pager_reader.xml index dc95020a42..6813bcb2de 100644 --- a/app/src/main/res/layout/fragment_page.xml +++ b/app/src/main/res/layout/item_pager_reader.xml @@ -34,7 +34,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/retry_button" - android:text="Retry" + android:text="@string/action_retry" android:layout_gravity="center" android:visibility="gone"/> diff --git a/app/src/main/res/layout/item_webtoon_reader.xml b/app/src/main/res/layout/item_webtoon_reader.xml index 91677a1f34..4d3fe8870e 100644 --- a/app/src/main/res/layout/item_webtoon_reader.xml +++ b/app/src/main/res/layout/item_webtoon_reader.xml @@ -4,12 +4,27 @@ android:layout_width="match_parent" android:layout_height="match_parent"> - + + + + +