pages = new ArrayList<>();
+ for (int i = 0; i < pageUrls.size(); i++) {
+ pages.add(new Page(i, pageUrls.get(i)));
+ }
+ return Observable.just(pages);
+ }
}
diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/activity/BaseActivity.java b/app/src/main/java/eu/kanade/mangafeed/ui/activity/BaseActivity.java
index 079bd28ee2..e40afaef6c 100644
--- a/app/src/main/java/eu/kanade/mangafeed/ui/activity/BaseActivity.java
+++ b/app/src/main/java/eu/kanade/mangafeed/ui/activity/BaseActivity.java
@@ -8,7 +8,6 @@ import eu.kanade.mangafeed.App;
import nucleus.factory.PresenterFactory;
import nucleus.presenter.Presenter;
import nucleus.view.NucleusAppCompatActivity;
-import timber.log.Timber;
public class BaseActivity extends NucleusAppCompatActivity
{
@@ -17,11 +16,7 @@ public class BaseActivity
extends NucleusAppCompatActivity<
final PresenterFactory
superFactory = super.getPresenterFactory();
setPresenterFactory(() -> {
P presenter = superFactory.createPresenter();
- try {
- App.getComponentReflection(getActivity()).inject(presenter);
- } catch(Exception e) {
- Timber.w("No injection for " + presenter.getClass().toString());
- }
+ App.getComponentReflection(getActivity()).inject(presenter);
return presenter;
});
super.onCreate(savedInstanceState);
diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/activity/MainActivity.java b/app/src/main/java/eu/kanade/mangafeed/ui/activity/MainActivity.java
index 72ec067211..13e46ab0c4 100644
--- a/app/src/main/java/eu/kanade/mangafeed/ui/activity/MainActivity.java
+++ b/app/src/main/java/eu/kanade/mangafeed/ui/activity/MainActivity.java
@@ -13,13 +13,13 @@ import com.mikepenz.materialdrawer.model.PrimaryDrawerItem;
import butterknife.Bind;
import butterknife.ButterKnife;
import eu.kanade.mangafeed.R;
-import eu.kanade.mangafeed.presenter.BasePresenter;
+import eu.kanade.mangafeed.presenter.MainPresenter;
import eu.kanade.mangafeed.ui.fragment.LibraryFragment;
import eu.kanade.mangafeed.ui.fragment.SourceFragment;
import nucleus.factory.RequiresPresenter;
-@RequiresPresenter(BasePresenter.class)
-public class MainActivity extends BaseActivity {
+@RequiresPresenter(MainPresenter.class)
+public class MainActivity extends BaseActivity {
@Bind(R.id.toolbar)
Toolbar toolbar;
diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/activity/MangaDetailActivity.java b/app/src/main/java/eu/kanade/mangafeed/ui/activity/MangaDetailActivity.java
index 64e1b43f99..97333cc7a7 100644
--- a/app/src/main/java/eu/kanade/mangafeed/ui/activity/MangaDetailActivity.java
+++ b/app/src/main/java/eu/kanade/mangafeed/ui/activity/MangaDetailActivity.java
@@ -26,7 +26,7 @@ public class MangaDetailActivity extends BaseActivity {
@Bind(R.id.toolbar) Toolbar toolbar;
@Bind(R.id.tabs) TabLayout tabs;
- @Bind(R.id.viewpager) ViewPager view_pager;
+ @Bind(R.id.view_pager) ViewPager view_pager;
private MangaDetailAdapter adapter;
private long manga_id;
@@ -80,8 +80,7 @@ public class MangaDetailActivity extends BaseActivity {
private void setupViewPager() {
adapter = new MangaDetailAdapter(
getSupportFragmentManager(),
- getActivity(),
- manga_id);
+ getActivity());
view_pager.setAdapter(adapter);
tabs.setupWithViewPager(view_pager);
@@ -107,19 +106,17 @@ public class MangaDetailActivity extends BaseActivity {
final int PAGE_COUNT = 2;
private String tab_titles[];
private Context context;
- private long manga_id;
final static int INFO_FRAGMENT = 0;
final static int CHAPTERS_FRAGMENT = 1;
- public MangaDetailAdapter(FragmentManager fm, Context context, long manga_id) {
+ public MangaDetailAdapter(FragmentManager fm, Context context) {
super(fm);
this.context = context;
tab_titles = new String[]{
context.getString(R.string.manga_detail_tab),
context.getString(R.string.manga_chapters_tab)
};
- this.manga_id = manga_id;
}
@Override
diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/activity/ViewerActivity.java b/app/src/main/java/eu/kanade/mangafeed/ui/activity/ViewerActivity.java
new file mode 100644
index 0000000000..8c641a9ed0
--- /dev/null
+++ b/app/src/main/java/eu/kanade/mangafeed/ui/activity/ViewerActivity.java
@@ -0,0 +1,40 @@
+package eu.kanade.mangafeed.ui.activity;
+
+import android.content.Context;
+import android.content.Intent;
+import android.os.Bundle;
+import android.support.v4.view.ViewPager;
+
+import butterknife.Bind;
+import butterknife.ButterKnife;
+import eu.kanade.mangafeed.R;
+import eu.kanade.mangafeed.presenter.ViewerPresenter;
+import eu.kanade.mangafeed.ui.adapter.ViewerPageAdapter;
+import nucleus.factory.RequiresPresenter;
+
+@RequiresPresenter(ViewerPresenter.class)
+public class ViewerActivity extends BaseActivity {
+
+ @Bind(R.id.view_pager) ViewPager viewPager;
+
+ private ViewerPageAdapter adapter;
+
+ public static Intent newInstance(Context context) {
+ return new Intent(context, ViewerActivity.class);
+ }
+
+ @Override
+ public void onCreate(Bundle savedState) {
+ super.onCreate(savedState);
+ setContentView(R.layout.activity_viewer);
+ ButterKnife.bind(this);
+
+ createAdapter();
+ }
+
+ private void createAdapter() {
+ adapter = new ViewerPageAdapter(getSupportFragmentManager());
+ viewPager.setAdapter(adapter);
+ }
+
+}
diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/adapter/ChapterListHolder.java b/app/src/main/java/eu/kanade/mangafeed/ui/adapter/ChapterListHolder.java
index 0157a1261b..ee18a9c39d 100644
--- a/app/src/main/java/eu/kanade/mangafeed/ui/adapter/ChapterListHolder.java
+++ b/app/src/main/java/eu/kanade/mangafeed/ui/adapter/ChapterListHolder.java
@@ -20,12 +20,29 @@ public class ChapterListHolder extends ItemViewHolder {
@ViewId(R.id.chapter_download_image)
ImageView download_icon;
+ View view;
+
public ChapterListHolder(View view) {
super(view);
+ this.view = view;
}
public void onSetValues(Chapter chapter, PositionInfo positionInfo) {
title.setText(chapter.name);
download_icon.setImageResource(R.drawable.ic_file_download_black_48dp);
}
+
+ @Override
+ public void onSetListeners() {
+ view.setOnClickListener(view -> {
+ ChapterListener listener = getListener(ChapterListener.class);
+ if (listener != null) {
+ listener.onRowClicked(getItem());
+ }
+ });
+ }
+
+ public interface ChapterListener {
+ void onRowClicked(Chapter chapter);
+ }
}
diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/adapter/SmartFragmentStatePagerAdapter.java b/app/src/main/java/eu/kanade/mangafeed/ui/adapter/SmartFragmentStatePagerAdapter.java
new file mode 100644
index 0000000000..38ef584e43
--- /dev/null
+++ b/app/src/main/java/eu/kanade/mangafeed/ui/adapter/SmartFragmentStatePagerAdapter.java
@@ -0,0 +1,36 @@
+package eu.kanade.mangafeed.ui.adapter;
+
+import android.support.v4.app.Fragment;
+import android.support.v4.app.FragmentManager;
+import android.support.v4.app.FragmentStatePagerAdapter;
+import android.util.SparseArray;
+import android.view.ViewGroup;
+
+public abstract class SmartFragmentStatePagerAdapter extends FragmentStatePagerAdapter {
+ // Sparse array to keep track of registered fragments in memory
+ private SparseArray registeredFragments = new SparseArray();
+
+ public SmartFragmentStatePagerAdapter(FragmentManager fragmentManager) {
+ super(fragmentManager);
+ }
+
+ // Register the fragment when the item is instantiated
+ @Override
+ public Object instantiateItem(ViewGroup container, int position) {
+ Fragment fragment = (Fragment) super.instantiateItem(container, position);
+ registeredFragments.put(position, fragment);
+ return fragment;
+ }
+
+ // Unregister when the item is inactive
+ @Override
+ public void destroyItem(ViewGroup container, int position, Object object) {
+ registeredFragments.remove(position);
+ super.destroyItem(container, position, object);
+ }
+
+ // Returns the fragment for the position (if instantiated)
+ public Fragment getRegisteredFragment(int position) {
+ return registeredFragments.get(position);
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/adapter/ViewerPageAdapter.java b/app/src/main/java/eu/kanade/mangafeed/ui/adapter/ViewerPageAdapter.java
new file mode 100644
index 0000000000..f6e50f2328
--- /dev/null
+++ b/app/src/main/java/eu/kanade/mangafeed/ui/adapter/ViewerPageAdapter.java
@@ -0,0 +1,39 @@
+package eu.kanade.mangafeed.ui.adapter;
+
+import android.support.v4.app.Fragment;
+import android.support.v4.app.FragmentManager;
+
+import java.util.List;
+
+import eu.kanade.mangafeed.ui.fragment.ViewerPageFragment;
+
+public class ViewerPageAdapter extends SmartFragmentStatePagerAdapter {
+
+ private List imageUrls;
+
+ public ViewerPageAdapter(FragmentManager fragmentManager) {
+ super(fragmentManager);
+ }
+
+ @Override
+ public int getCount() {
+ if (imageUrls != null)
+ return imageUrls.size();
+
+ return 0;
+ }
+
+ @Override
+ public Fragment getItem(int position) {
+ return ViewerPageFragment.newInstance(imageUrls.get(position), position);
+ }
+
+ public List getImageUrls() {
+ return imageUrls;
+ }
+
+ public void setImageUrls(List imageUrls) {
+ this.imageUrls = imageUrls;
+ }
+
+}
diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/fragment/MangaChaptersFragment.java b/app/src/main/java/eu/kanade/mangafeed/ui/fragment/MangaChaptersFragment.java
index 161948c24f..d9e2102908 100644
--- a/app/src/main/java/eu/kanade/mangafeed/ui/fragment/MangaChaptersFragment.java
+++ b/app/src/main/java/eu/kanade/mangafeed/ui/fragment/MangaChaptersFragment.java
@@ -1,5 +1,6 @@
package eu.kanade.mangafeed.ui.fragment;
+import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.widget.SwipeRefreshLayout;
@@ -20,6 +21,7 @@ import eu.kanade.mangafeed.R;
import eu.kanade.mangafeed.data.models.Chapter;
import eu.kanade.mangafeed.presenter.MangaChaptersPresenter;
import eu.kanade.mangafeed.ui.activity.MangaDetailActivity;
+import eu.kanade.mangafeed.ui.activity.ViewerActivity;
import eu.kanade.mangafeed.ui.adapter.ChapterListHolder;
import nucleus.factory.RequiresPresenter;
import uk.co.ribot.easyadapter.EasyRecyclerAdapter;
@@ -73,7 +75,13 @@ public class MangaChaptersFragment extends BaseFragment
}
private void createAdapter() {
- adapter = new EasyRecyclerAdapter<>(getActivity(), ChapterListHolder.class);
+ ChapterListHolder.ChapterListener listener = chapter -> {
+ getPresenter().onChapterClicked(chapter);
+ Intent intent = ViewerActivity.newInstance(getActivity());
+ startActivity(intent);
+ };
+
+ adapter = new EasyRecyclerAdapter<>(getActivity(), ChapterListHolder.class, listener);
chapters.setAdapter(adapter);
}
diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/fragment/ViewerPageFragment.java b/app/src/main/java/eu/kanade/mangafeed/ui/fragment/ViewerPageFragment.java
new file mode 100644
index 0000000000..56640932c6
--- /dev/null
+++ b/app/src/main/java/eu/kanade/mangafeed/ui/fragment/ViewerPageFragment.java
@@ -0,0 +1,84 @@
+package eu.kanade.mangafeed.ui.fragment;
+
+import android.os.Bundle;
+import android.support.annotation.Nullable;
+import android.support.v4.app.Fragment;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+
+import com.bumptech.glide.Glide;
+import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView;
+
+import eu.kanade.mangafeed.R;
+import eu.kanade.mangafeed.util.PageFileTarget;
+
+public class ViewerPageFragment extends Fragment {
+ public static final String URL_ARGUMENT_KEY = "UrlArgumentKey";
+
+ private SubsamplingScaleImageView mPageImageView;
+
+ private String mUrl;
+
+ public static ViewerPageFragment newInstance(String url, int position) {
+ ViewerPageFragment newInstance = new ViewerPageFragment();
+ Bundle arguments = new Bundle();
+ arguments.putString(URL_ARGUMENT_KEY, url);
+ newInstance.setArguments(arguments);
+ return newInstance;
+ }
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ Bundle arguments = getArguments();
+ if (arguments != null) {
+ if (arguments.containsKey(URL_ARGUMENT_KEY)) {
+ mUrl = arguments.getString(URL_ARGUMENT_KEY);
+ }
+ }
+ }
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
+ mPageImageView = (SubsamplingScaleImageView)inflater.inflate(R.layout.fragment_page, container, false);
+ mPageImageView.setVisibility(View.INVISIBLE);
+ mPageImageView.setDoubleTapZoomStyle(SubsamplingScaleImageView.ZOOM_FOCUS_FIXED);
+ mPageImageView.setPanLimit(SubsamplingScaleImageView.PAN_LIMIT_INSIDE);
+ mPageImageView.setMinimumScaleType(SubsamplingScaleImageView.SCALE_TYPE_CENTER_INSIDE);
+ mPageImageView.setOnImageEventListener(new SubsamplingScaleImageView.OnImageEventListener() {
+ @Override
+ public void onReady() {
+ mPageImageView.setVisibility(View.VISIBLE);
+ }
+
+ @Override
+ public void onImageLoaded() {
+ }
+
+ @Override
+ public void onPreviewLoadError(Exception e) {
+ }
+
+ @Override
+ public void onImageLoadError(Exception e) {
+ }
+
+ @Override
+ public void onTileLoadError(Exception e) {
+ }
+ });
+
+ return mPageImageView;
+ }
+
+ @Override
+ public void onActivityCreated(@Nullable Bundle savedInstanceState) {
+ super.onActivityCreated(savedInstanceState);
+
+ Glide.with(getActivity())
+ .load(mUrl)
+ .downloadOnly(new PageFileTarget(mPageImageView));
+ }
+}
diff --git a/app/src/main/java/eu/kanade/mangafeed/util/PageFileTarget.java b/app/src/main/java/eu/kanade/mangafeed/util/PageFileTarget.java
new file mode 100644
index 0000000000..a94a9d45fa
--- /dev/null
+++ b/app/src/main/java/eu/kanade/mangafeed/util/PageFileTarget.java
@@ -0,0 +1,36 @@
+package eu.kanade.mangafeed.util;
+
+import android.graphics.drawable.Drawable;
+import android.net.Uri;
+
+import com.bumptech.glide.request.animation.GlideAnimation;
+import com.bumptech.glide.request.target.ViewTarget;
+import com.davemorrissey.labs.subscaleview.ImageSource;
+import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView;
+
+import java.io.File;
+
+import eu.kanade.mangafeed.R;
+
+public class PageFileTarget extends ViewTarget {
+ public static final String TAG = PageFileTarget.class.getSimpleName();
+
+ public PageFileTarget(SubsamplingScaleImageView view) {
+ super(view);
+ }
+
+ @Override
+ public void onLoadCleared(Drawable placeholder) {
+ view.setImage(ImageSource.resource(R.drawable.ic_action_refresh));
+ }
+
+ @Override
+ public void onLoadStarted(Drawable placeholder) {
+ view.setImage(ImageSource.resource(R.drawable.ic_action_refresh));
+ }
+
+ @Override
+ public void onResourceReady(File resource, GlideAnimation super File> glideAnimation) {
+ view.setImage(ImageSource.uri(Uri.fromFile(resource)));
+ }
+}
diff --git a/app/src/main/java/eu/kanade/mangafeed/util/events/SourceChapterEvent.java b/app/src/main/java/eu/kanade/mangafeed/util/events/SourceChapterEvent.java
new file mode 100644
index 0000000000..c033bdd71c
--- /dev/null
+++ b/app/src/main/java/eu/kanade/mangafeed/util/events/SourceChapterEvent.java
@@ -0,0 +1,23 @@
+package eu.kanade.mangafeed.util.events;
+
+import eu.kanade.mangafeed.data.models.Chapter;
+import eu.kanade.mangafeed.sources.Source;
+
+public class SourceChapterEvent {
+
+ private Source source;
+ private Chapter chapter;
+
+ public SourceChapterEvent(Source source, Chapter chapter) {
+ this.source = source;
+ this.chapter = chapter;
+ }
+
+ public Source getSource() {
+ return source;
+ }
+
+ public Chapter getChapter() {
+ return chapter;
+ }
+}
diff --git a/app/src/main/res/layout/activity_manga_detail.xml b/app/src/main/res/layout/activity_manga_detail.xml
index 3faf4ca94a..423ac4f7b2 100644
--- a/app/src/main/res/layout/activity_manga_detail.xml
+++ b/app/src/main/res/layout/activity_manga_detail.xml
@@ -28,7 +28,7 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/fragment_page.xml b/app/src/main/res/layout/fragment_page.xml
new file mode 100644
index 0000000000..1ae04344bf
--- /dev/null
+++ b/app/src/main/res/layout/fragment_page.xml
@@ -0,0 +1,6 @@
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index b3d4aa065e..adf1611a60 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -45,5 +45,6 @@
Description
Info
Chapters
+ ViewerActivity
diff --git a/app/src/test/java/eu/kanade/mangafeed/BatotoTest.java b/app/src/test/java/eu/kanade/mangafeed/BatotoTest.java
index 42046965b6..215627e70c 100644
--- a/app/src/test/java/eu/kanade/mangafeed/BatotoTest.java
+++ b/app/src/test/java/eu/kanade/mangafeed/BatotoTest.java
@@ -19,9 +19,6 @@ import eu.kanade.mangafeed.data.models.Chapter;
import eu.kanade.mangafeed.data.models.Manga;
import eu.kanade.mangafeed.sources.Batoto;
import eu.kanade.mangafeed.sources.Source;
-import rx.android.schedulers.AndroidSchedulers;
-import rx.observers.TestSubscriber;
-import rx.schedulers.Schedulers;
@Config(constants = BuildConfig.class, sdk = Build.VERSION_CODES.LOLLIPOP)
@RunWith(RobolectricGradleTestRunner.class)
@@ -44,7 +41,7 @@ public class BatotoTest {
@Test
public void testImageList() {
- List imageUrls = b.getImageUrlsFromNetwork(chapterUrl)
+ List imageUrls = b.getRemainingImageUrlsFromPageList(chapterUrl)
.toList().toBlocking().single();
Assert.assertTrue(imageUrls.size() > 5);
diff --git a/app/src/test/java/eu/kanade/mangafeed/MangahereTest.java b/app/src/test/java/eu/kanade/mangafeed/MangahereTest.java
index c494a8c043..3d6097075c 100644
--- a/app/src/test/java/eu/kanade/mangafeed/MangahereTest.java
+++ b/app/src/test/java/eu/kanade/mangafeed/MangahereTest.java
@@ -39,7 +39,7 @@ public class MangahereTest {
@Test
public void testImageList() {
- List imageUrls = b.getImageUrlsFromNetwork(chapterUrl)
+ List imageUrls = b.getRemainingImageUrlsFromPageList(chapterUrl)
.toList().toBlocking().single();
Assert.assertTrue(imageUrls.size() > 5);