From 13124ee02ff848383121c875f77e2856ca77d6ee Mon Sep 17 00:00:00 2001 From: inorichi Date: Sat, 10 Oct 2015 14:28:57 +0200 Subject: [PATCH] Create catalogue fragment --- .../eu/kanade/mangafeed/AppComponent.java | 2 + .../mangafeed/data/helpers/SourceManager.java | 12 ++++ .../presenter/CataloguePresenter.java | 39 +++++++++++ .../eu/kanade/mangafeed/sources/Batoto.java | 7 +- .../eu/kanade/mangafeed/sources/Source.java | 17 +++-- .../mangafeed/ui/activity/MainActivity.java | 6 +- .../mangafeed/ui/adapter/SourceHolder.java | 28 ++++++++ .../ui/fragment/CatalogueFragment.java | 68 +++++++++++++++++++ .../ui/fragment/LibraryFragment.java | 6 +- .../kanade/mangafeed/view/CatalogueView.java | 11 +++ .../main/res/layout/fragment_catalogue.xml | 13 ++++ app/src/main/res/layout/item_source.xml | 11 +++ 12 files changed, 207 insertions(+), 13 deletions(-) create mode 100644 app/src/main/java/eu/kanade/mangafeed/presenter/CataloguePresenter.java create mode 100644 app/src/main/java/eu/kanade/mangafeed/ui/adapter/SourceHolder.java create mode 100644 app/src/main/java/eu/kanade/mangafeed/ui/fragment/CatalogueFragment.java create mode 100644 app/src/main/java/eu/kanade/mangafeed/view/CatalogueView.java create mode 100644 app/src/main/res/layout/fragment_catalogue.xml create mode 100644 app/src/main/res/layout/item_source.xml diff --git a/app/src/main/java/eu/kanade/mangafeed/AppComponent.java b/app/src/main/java/eu/kanade/mangafeed/AppComponent.java index fec255375f..1200bfcacc 100644 --- a/app/src/main/java/eu/kanade/mangafeed/AppComponent.java +++ b/app/src/main/java/eu/kanade/mangafeed/AppComponent.java @@ -6,6 +6,7 @@ import javax.inject.Singleton; import dagger.Component; import eu.kanade.mangafeed.data.DataModule; +import eu.kanade.mangafeed.presenter.CataloguePresenter; import eu.kanade.mangafeed.presenter.LibraryPresenter; import eu.kanade.mangafeed.presenter.MangaDetailPresenter; import eu.kanade.mangafeed.ui.activity.MainActivity; @@ -23,6 +24,7 @@ public interface AppComponent { void inject(LibraryPresenter libraryPresenter); void inject(MangaDetailPresenter mangaDetailPresenter); + void inject(CataloguePresenter cataloguePresenter); Application application(); } \ No newline at end of file diff --git a/app/src/main/java/eu/kanade/mangafeed/data/helpers/SourceManager.java b/app/src/main/java/eu/kanade/mangafeed/data/helpers/SourceManager.java index 8466cdbe2e..2cd673a3f0 100644 --- a/app/src/main/java/eu/kanade/mangafeed/data/helpers/SourceManager.java +++ b/app/src/main/java/eu/kanade/mangafeed/data/helpers/SourceManager.java @@ -1,6 +1,8 @@ package eu.kanade.mangafeed.data.helpers; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import eu.kanade.mangafeed.data.caches.CacheManager; import eu.kanade.mangafeed.sources.Batoto; @@ -18,6 +20,8 @@ public class SourceManager { mSourcesMap = new HashMap<>(); mNetworkHelper = networkHelper; mCacheManager = cacheManager; + + initializeSources(); } public Source get(int sourceKey) { @@ -35,4 +39,12 @@ public class SourceManager { return null; } + + private void initializeSources() { + mSourcesMap.put(BATOTO, createSource(BATOTO)); + } + + public List getSources() { + return new ArrayList(mSourcesMap.values()); + } } diff --git a/app/src/main/java/eu/kanade/mangafeed/presenter/CataloguePresenter.java b/app/src/main/java/eu/kanade/mangafeed/presenter/CataloguePresenter.java new file mode 100644 index 0000000000..296570e2e6 --- /dev/null +++ b/app/src/main/java/eu/kanade/mangafeed/presenter/CataloguePresenter.java @@ -0,0 +1,39 @@ +package eu.kanade.mangafeed.presenter; + +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.adapter.SourceHolder; +import eu.kanade.mangafeed.view.CatalogueView; +import uk.co.ribot.easyadapter.EasyAdapter; + + +public class CataloguePresenter { + + private CatalogueView view; + + @Inject SourceManager sourceManager; + + EasyAdapter adapter; + + public CataloguePresenter(CatalogueView view) { + this.view = view; + App.getComponent(view.getActivity()).inject(this); + } + + public void initializeSources() { + adapter = new EasyAdapter( + view.getActivity(), + SourceHolder.class, + sourceManager.getSources()); + + view.setAdapter(adapter); + view.setSourceClickListener(); + } + + public void onSourceClick(int position) { + + } +} 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 6944bea20d..07c2565a4b 100644 --- a/app/src/main/java/eu/kanade/mangafeed/sources/Batoto.java +++ b/app/src/main/java/eu/kanade/mangafeed/sources/Batoto.java @@ -32,6 +32,11 @@ public class Batoto extends Source { super(networkService, cacheManager); } + @Override + public String getName() { + return NAME; + } + @Override protected Headers.Builder headersBuilder() { Headers.Builder builder = super.headersBuilder(); @@ -85,7 +90,7 @@ public class Batoto extends Source { } @Override - protected int getSource() { + public int getSource() { return SourceManager.BATOTO; } 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 4ff121352b..bbf3136a87 100644 --- a/app/src/main/java/eu/kanade/mangafeed/sources/Source.java +++ b/app/src/main/java/eu/kanade/mangafeed/sources/Source.java @@ -94,12 +94,15 @@ public abstract class Source { return defaultMangaUrl; } - abstract protected int getSource(); - abstract protected String getUrlFromPageNumber(int page); - abstract protected List parsePopularMangasFromHtml(String unparsedHtml); - abstract protected Manga parseHtmlToManga(String mangaUrl, String unparsedHtml); - abstract protected List parseHtmlToChapters(String unparsedHtml); - abstract protected List parseHtmlToPageUrls(String unparsedHtml); - abstract protected String parseHtmlToImageUrl(String unparsedHtml); + public abstract String getName(); + public abstract int getSource(); + + protected abstract String getUrlFromPageNumber(int page); + protected abstract List parsePopularMangasFromHtml(String unparsedHtml); + protected abstract Manga parseHtmlToManga(String mangaUrl, String unparsedHtml); + protected abstract List parseHtmlToChapters(String unparsedHtml); + protected abstract List parseHtmlToPageUrls(String unparsedHtml); + protected abstract String parseHtmlToImageUrl(String unparsedHtml); + } 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 6587d816cd..984dddded1 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,6 +13,7 @@ import com.mikepenz.materialdrawer.model.PrimaryDrawerItem; import butterknife.Bind; import butterknife.ButterKnife; import eu.kanade.mangafeed.R; +import eu.kanade.mangafeed.ui.fragment.CatalogueFragment; import eu.kanade.mangafeed.ui.fragment.LibraryFragment; import rx.subscriptions.CompositeSubscription; @@ -64,8 +65,11 @@ public class MainActivity extends BaseActivity { case R.id.nav_drawer_library: setFragment(LibraryFragment.newInstance()); break; - case R.id.nav_drawer_catalogues: case R.id.nav_drawer_recent_updates: + break; + case R.id.nav_drawer_catalogues: + setFragment(CatalogueFragment.newInstance()); + break; case R.id.nav_drawer_settings: break; } diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/adapter/SourceHolder.java b/app/src/main/java/eu/kanade/mangafeed/ui/adapter/SourceHolder.java new file mode 100644 index 0000000000..8a584f5c8d --- /dev/null +++ b/app/src/main/java/eu/kanade/mangafeed/ui/adapter/SourceHolder.java @@ -0,0 +1,28 @@ +package eu.kanade.mangafeed.ui.adapter; + +import android.view.View; +import android.widget.TextView; + +import eu.kanade.mangafeed.R; +import eu.kanade.mangafeed.sources.Source; +import uk.co.ribot.easyadapter.ItemViewHolder; +import uk.co.ribot.easyadapter.PositionInfo; +import uk.co.ribot.easyadapter.annotations.LayoutId; +import uk.co.ribot.easyadapter.annotations.ViewId; + + +@LayoutId(R.layout.item_source) +public class SourceHolder extends ItemViewHolder { + + @ViewId(R.id.source_name) + TextView source_name; + + public SourceHolder(View view) { + super(view); + } + + @Override + public void onSetValues(Source item, PositionInfo positionInfo) { + source_name.setText(item.getName()); + } +} diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/fragment/CatalogueFragment.java b/app/src/main/java/eu/kanade/mangafeed/ui/fragment/CatalogueFragment.java new file mode 100644 index 0000000000..f58da91aa6 --- /dev/null +++ b/app/src/main/java/eu/kanade/mangafeed/ui/fragment/CatalogueFragment.java @@ -0,0 +1,68 @@ +package eu.kanade.mangafeed.ui.fragment; + +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ListView; + +import butterknife.Bind; +import butterknife.ButterKnife; +import eu.kanade.mangafeed.R; +import eu.kanade.mangafeed.presenter.CataloguePresenter; +import eu.kanade.mangafeed.ui.activity.MainActivity; +import eu.kanade.mangafeed.view.CatalogueView; +import uk.co.ribot.easyadapter.EasyAdapter; + + +public class CatalogueFragment extends BaseFragment implements CatalogueView { + + private CataloguePresenter presenter; + private MainActivity activity; + + @Bind(R.id.catalogue_list) + ListView source_list; + + public static CatalogueFragment newInstance() { + CatalogueFragment fragment = new CatalogueFragment(); + Bundle args = new Bundle(); + fragment.setArguments(args); + return fragment; + } + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + presenter = new CataloguePresenter(this); + activity = (MainActivity)getActivity(); + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + // Inflate the layout for this fragment + View view = inflater.inflate(R.layout.fragment_catalogue, container, false); + activity.setToolbarTitle(R.string.catalogues_title); + ButterKnife.bind(this, view); + + presenter.initializeSources(); + + return view; + } + + // CatalogueView + + @Override + public void setAdapter(EasyAdapter adapter) { + source_list.setAdapter(adapter); + } + + @Override + public void setSourceClickListener() { + source_list.setOnItemClickListener( + (parent, view, position, id) -> + presenter.onSourceClick(position) + ); + } +} 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 33532d260c..530cb2c565 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,8 +23,8 @@ import uk.co.ribot.easyadapter.EasyAdapter; public class LibraryFragment extends BaseFragment implements LibraryView { @Bind(R.id.gridView) GridView grid; - LibraryPresenter presenter; - MainActivity activity; + private LibraryPresenter presenter; + private MainActivity activity; public static LibraryFragment newInstance() { LibraryFragment fragment = new LibraryFragment(); @@ -99,8 +99,6 @@ public class LibraryFragment extends BaseFragment implements LibraryView { public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) { mode.setTitle(getResources().getString(R.string.library_selection_title) + ": " + grid.getCheckedItemCount()); - - } @Override diff --git a/app/src/main/java/eu/kanade/mangafeed/view/CatalogueView.java b/app/src/main/java/eu/kanade/mangafeed/view/CatalogueView.java new file mode 100644 index 0000000000..cd6405c92c --- /dev/null +++ b/app/src/main/java/eu/kanade/mangafeed/view/CatalogueView.java @@ -0,0 +1,11 @@ +package eu.kanade.mangafeed.view; + +import uk.co.ribot.easyadapter.EasyAdapter; + +/** + * Created by len on 10/10/2015. + */ +public interface CatalogueView extends BaseView { + void setAdapter(EasyAdapter adapter); + void setSourceClickListener(); +} diff --git a/app/src/main/res/layout/fragment_catalogue.xml b/app/src/main/res/layout/fragment_catalogue.xml new file mode 100644 index 0000000000..a1b34b32ed --- /dev/null +++ b/app/src/main/res/layout/fragment_catalogue.xml @@ -0,0 +1,13 @@ + + + + + + diff --git a/app/src/main/res/layout/item_source.xml b/app/src/main/res/layout/item_source.xml new file mode 100644 index 0000000000..d489d61ba8 --- /dev/null +++ b/app/src/main/res/layout/item_source.xml @@ -0,0 +1,11 @@ + + + + + \ No newline at end of file