From b36aa69a67f174b51bb7d12e94a593fd29f777f8 Mon Sep 17 00:00:00 2001 From: inorichi Date: Sat, 17 Oct 2015 16:28:35 +0200 Subject: [PATCH] All fragments using Nucleus --- .../mangafeed/presenter/SourcePresenter.java | 37 +++----------- .../eu/kanade/mangafeed/sources/Batoto.java | 4 +- .../kanade/mangafeed/sources/MangaHere.java | 4 +- .../eu/kanade/mangafeed/sources/Source.java | 2 +- .../ui/activity/CatalogueActivity.java | 10 ++++ .../mangafeed/ui/fragment/BaseFragment.java | 23 +++++++-- .../mangafeed/ui/fragment/BaseFragment2.java | 23 --------- .../ui/fragment/LibraryFragment.java | 2 +- .../ui/fragment/MangaChaptersFragment.java | 2 +- .../ui/fragment/MangaInfoFragment.java | 2 +- .../mangafeed/ui/fragment/SourceFragment.java | 50 +++++++++++-------- 11 files changed, 74 insertions(+), 85 deletions(-) delete mode 100644 app/src/main/java/eu/kanade/mangafeed/ui/fragment/BaseFragment2.java diff --git a/app/src/main/java/eu/kanade/mangafeed/presenter/SourcePresenter.java b/app/src/main/java/eu/kanade/mangafeed/presenter/SourcePresenter.java index e05e96d7a2..baa4e05240 100644 --- a/app/src/main/java/eu/kanade/mangafeed/presenter/SourcePresenter.java +++ b/app/src/main/java/eu/kanade/mangafeed/presenter/SourcePresenter.java @@ -1,45 +1,24 @@ package eu.kanade.mangafeed.presenter; -import android.content.Intent; - import javax.inject.Inject; -import eu.kanade.mangafeed.App; import eu.kanade.mangafeed.data.helpers.SourceManager; import eu.kanade.mangafeed.sources.Source; -import eu.kanade.mangafeed.ui.activity.CatalogueActivity; -import eu.kanade.mangafeed.ui.adapter.SourceHolder; -import eu.kanade.mangafeed.view.SourceView; -import uk.co.ribot.easyadapter.EasyAdapter; +import eu.kanade.mangafeed.ui.fragment.SourceFragment; -public class SourcePresenter { - - private SourceView view; +public class SourcePresenter extends BasePresenter2 { @Inject SourceManager sourceManager; - EasyAdapter adapter; + @Override + protected void onTakeView(SourceFragment view) { + super.onTakeView(view); - public SourcePresenter(SourceView view) { - this.view = view; - App.getComponent(view.getActivity()).inject(this); + view.setItems(sourceManager.getSources()); } - public void initializeSources() { - adapter = new EasyAdapter<>( - view.getActivity(), - SourceHolder.class, - sourceManager.getSources()); - - view.setAdapter(adapter); - view.setSourceClickListener(); - } - - public void onSourceClick(int position) { - sourceManager.setSelectedSource(adapter.getItem(position).getSource()); - Intent intent = new Intent(view.getActivity(), CatalogueActivity.class); - intent.putExtra(Intent.EXTRA_UID, adapter.getItem(position).getSource()); - view.getActivity().startActivity(intent); + public void setSelectedSource(Source source) { + sourceManager.setSelectedSource(source.getSourceId()); } } diff --git a/app/src/main/java/eu/kanade/mangafeed/sources/Batoto.java b/app/src/main/java/eu/kanade/mangafeed/sources/Batoto.java index 73de744a29..d5a9529263 100644 --- a/app/src/main/java/eu/kanade/mangafeed/sources/Batoto.java +++ b/app/src/main/java/eu/kanade/mangafeed/sources/Batoto.java @@ -92,7 +92,7 @@ public class Batoto extends Source { } @Override - public int getSource() { + public int getSourceId() { return SourceManager.BATOTO; } @@ -148,7 +148,7 @@ public class Batoto extends Source { Element nameElement = urlElement; Element updateElement = htmlBlock.select("td").get(5); - mangaFromHtmlBlock.source = getSource(); + mangaFromHtmlBlock.source = getSourceId(); if (urlElement != null) { String fieldUrl = urlElement.attr("href"); diff --git a/app/src/main/java/eu/kanade/mangafeed/sources/MangaHere.java b/app/src/main/java/eu/kanade/mangafeed/sources/MangaHere.java index 6ca5f22a34..ef0838a939 100644 --- a/app/src/main/java/eu/kanade/mangafeed/sources/MangaHere.java +++ b/app/src/main/java/eu/kanade/mangafeed/sources/MangaHere.java @@ -37,7 +37,7 @@ public class MangaHere extends Source { return NAME; } - public int getSource() { + public int getSourceId() { return SourceManager.MANGAHERE; } @@ -112,7 +112,7 @@ public class MangaHere extends Source { private Manga constructMangaFromHtmlBlock(Element htmlBlock) { Manga mangaFromHtmlBlock = new Manga(); - mangaFromHtmlBlock.source = getSource(); + mangaFromHtmlBlock.source = getSourceId(); Element urlElement = htmlBlock.select("a.manga_info").first(); Element nameElement = htmlBlock.select("a.manga_info").first(); diff --git a/app/src/main/java/eu/kanade/mangafeed/sources/Source.java b/app/src/main/java/eu/kanade/mangafeed/sources/Source.java index 9f2653f9ee..fa91b6a0fc 100644 --- a/app/src/main/java/eu/kanade/mangafeed/sources/Source.java +++ b/app/src/main/java/eu/kanade/mangafeed/sources/Source.java @@ -102,7 +102,7 @@ public abstract class Source { } public abstract String getName(); - public abstract int getSource(); + public abstract int getSourceId(); protected abstract String getUrlFromPageNumber(int page); protected abstract String getSearchUrl(String query, int page); diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/activity/CatalogueActivity.java b/app/src/main/java/eu/kanade/mangafeed/ui/activity/CatalogueActivity.java index a69f3d1229..fe39bd2466 100644 --- a/app/src/main/java/eu/kanade/mangafeed/ui/activity/CatalogueActivity.java +++ b/app/src/main/java/eu/kanade/mangafeed/ui/activity/CatalogueActivity.java @@ -1,5 +1,7 @@ package eu.kanade.mangafeed.ui.activity; +import android.content.Context; +import android.content.Intent; import android.os.Bundle; import android.support.v7.widget.SearchView; import android.support.v7.widget.Toolbar; @@ -39,6 +41,14 @@ public class CatalogueActivity extends BaseActivity { private EasyAdapter adapter; private EndlessScrollListener scroll_listener; + public final static String SOURCE_ID = "source_id"; + + public static Intent newIntent(Context context, int source_id) { + Intent intent = new Intent(context, CatalogueActivity.class); + intent.putExtra(SOURCE_ID, source_id); + return intent; + } + @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/fragment/BaseFragment.java b/app/src/main/java/eu/kanade/mangafeed/ui/fragment/BaseFragment.java index 505cddc925..b220bf513c 100644 --- a/app/src/main/java/eu/kanade/mangafeed/ui/fragment/BaseFragment.java +++ b/app/src/main/java/eu/kanade/mangafeed/ui/fragment/BaseFragment.java @@ -1,6 +1,23 @@ package eu.kanade.mangafeed.ui.fragment; -import android.support.v4.app.Fragment; +import android.os.Bundle; -public class BaseFragment extends Fragment { -} +import eu.kanade.mangafeed.App; +import nucleus.factory.PresenterFactory; +import nucleus.presenter.Presenter; +import nucleus.view.NucleusSupportFragment; + +public class BaseFragment

extends NucleusSupportFragment

{ + + @Override + public void onCreate(Bundle savedInstanceState) { + final PresenterFactory

superFactory = super.getPresenterFactory(); + setPresenterFactory(() -> { + P presenter = superFactory.createPresenter(); + App.getComponentReflection(getActivity()).inject(presenter); + return presenter; + }); + super.onCreate(savedInstanceState); + } + +} \ No newline at end of file diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/fragment/BaseFragment2.java b/app/src/main/java/eu/kanade/mangafeed/ui/fragment/BaseFragment2.java deleted file mode 100644 index 1a4832917c..0000000000 --- a/app/src/main/java/eu/kanade/mangafeed/ui/fragment/BaseFragment2.java +++ /dev/null @@ -1,23 +0,0 @@ -package eu.kanade.mangafeed.ui.fragment; - -import android.os.Bundle; - -import eu.kanade.mangafeed.App; -import nucleus.factory.PresenterFactory; -import nucleus.presenter.Presenter; -import nucleus.view.NucleusSupportFragment; - -public class BaseFragment2

extends NucleusSupportFragment

{ - - @Override - public void onCreate(Bundle savedInstanceState) { - final PresenterFactory

superFactory = super.getPresenterFactory(); - setPresenterFactory(() -> { - P presenter = superFactory.createPresenter(); - App.getComponentReflection(getActivity()).inject(presenter); - return presenter; - }); - super.onCreate(savedInstanceState); - } - -} \ No newline at end of file diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/fragment/LibraryFragment.java b/app/src/main/java/eu/kanade/mangafeed/ui/fragment/LibraryFragment.java index b6895a6198..c49c9b5a7a 100644 --- a/app/src/main/java/eu/kanade/mangafeed/ui/fragment/LibraryFragment.java +++ b/app/src/main/java/eu/kanade/mangafeed/ui/fragment/LibraryFragment.java @@ -23,7 +23,7 @@ import eu.kanade.mangafeed.ui.adapter.LibraryAdapter; import nucleus.factory.RequiresPresenter; @RequiresPresenter(LibraryPresenter.class) -public class LibraryFragment extends BaseFragment2 { +public class LibraryFragment extends BaseFragment { @Bind(R.id.gridView) GridView grid; private MainActivity activity; 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 3aa330b070..5757b32b26 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 @@ -13,7 +13,7 @@ import eu.kanade.mangafeed.ui.activity.MangaDetailActivity; import nucleus.factory.RequiresPresenter; @RequiresPresenter(MangaChaptersPresenter.class) -public class MangaChaptersFragment extends BaseFragment2 { +public class MangaChaptersFragment extends BaseFragment { private long manga_id; diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/fragment/MangaInfoFragment.java b/app/src/main/java/eu/kanade/mangafeed/ui/fragment/MangaInfoFragment.java index d0fbf2e4a1..c8eef2b178 100644 --- a/app/src/main/java/eu/kanade/mangafeed/ui/fragment/MangaInfoFragment.java +++ b/app/src/main/java/eu/kanade/mangafeed/ui/fragment/MangaInfoFragment.java @@ -19,7 +19,7 @@ import eu.kanade.mangafeed.ui.activity.MangaDetailActivity; import nucleus.factory.RequiresPresenter; @RequiresPresenter(MangaInfoPresenter.class) -public class MangaInfoFragment extends BaseFragment2 { +public class MangaInfoFragment extends BaseFragment { @Bind(R.id.manga_artist) TextView mArtist; @Bind(R.id.manga_author) TextView mAuthor; diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/fragment/SourceFragment.java b/app/src/main/java/eu/kanade/mangafeed/ui/fragment/SourceFragment.java index 03731cf66f..88fb686ec3 100644 --- a/app/src/main/java/eu/kanade/mangafeed/ui/fragment/SourceFragment.java +++ b/app/src/main/java/eu/kanade/mangafeed/ui/fragment/SourceFragment.java @@ -1,40 +1,41 @@ package eu.kanade.mangafeed.ui.fragment; +import android.content.Intent; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ListView; +import java.util.List; + import butterknife.Bind; import butterknife.ButterKnife; +import butterknife.OnItemClick; import eu.kanade.mangafeed.R; import eu.kanade.mangafeed.presenter.SourcePresenter; +import eu.kanade.mangafeed.sources.Source; +import eu.kanade.mangafeed.ui.activity.CatalogueActivity; import eu.kanade.mangafeed.ui.activity.MainActivity; -import eu.kanade.mangafeed.view.SourceView; +import eu.kanade.mangafeed.ui.adapter.SourceHolder; +import nucleus.factory.RequiresPresenter; import uk.co.ribot.easyadapter.EasyAdapter; +@RequiresPresenter(SourcePresenter.class) +public class SourceFragment extends BaseFragment { -public class SourceFragment extends BaseFragment implements SourceView { + @Bind(R.id.catalogue_list) ListView source_list; - private SourcePresenter presenter; private MainActivity activity; - - @Bind(R.id.catalogue_list) - ListView source_list; + private EasyAdapter adapter; public static SourceFragment newInstance() { - SourceFragment fragment = new SourceFragment(); - Bundle args = new Bundle(); - fragment.setArguments(args); - return fragment; + return new SourceFragment(); } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - - presenter = new SourcePresenter(this); activity = (MainActivity)getActivity(); } @@ -46,22 +47,27 @@ public class SourceFragment extends BaseFragment implements SourceView { activity.setToolbarTitle(R.string.catalogues_title); ButterKnife.bind(this, view); - presenter.initializeSources(); + createAdapter(); + return view; } - // SourceView + @OnItemClick(R.id.catalogue_list) + public void onSourceClick(int position) { + Source source = adapter.getItem(position); + getPresenter().setSelectedSource(source); - @Override - public void setAdapter(EasyAdapter adapter) { + Intent intent = CatalogueActivity.newIntent(activity, source.getSourceId()); + startActivity(intent); + } + + private void createAdapter() { + adapter = new EasyAdapter<>(activity, SourceHolder.class); source_list.setAdapter(adapter); } - @Override - public void setSourceClickListener() { - source_list.setOnItemClickListener( - (parent, view, position, id) -> - presenter.onSourceClick(position) - ); + public void setItems(List items) { + adapter.setItems(items); } + }