From 381bedf68d166125750fdf2b2ea7b8628307bd7e Mon Sep 17 00:00:00 2001 From: inorichi Date: Sun, 11 Oct 2015 15:48:17 +0200 Subject: [PATCH] Create presenter and view for CatalogueList --- .../eu/kanade/mangafeed/AppComponent.java | 4 ++- .../presenter/CatalogueListPresenter.java | 27 +++++++++++++++++++ .../ui/activity/CatalogueListActivity.java | 22 ++++++++++----- .../ui/fragment/CatalogueFragment.java | 1 - .../mangafeed/view/CatalogueListView.java | 10 +++++++ 5 files changed, 55 insertions(+), 9 deletions(-) create mode 100644 app/src/main/java/eu/kanade/mangafeed/presenter/CatalogueListPresenter.java create mode 100644 app/src/main/java/eu/kanade/mangafeed/view/CatalogueListView.java diff --git a/app/src/main/java/eu/kanade/mangafeed/AppComponent.java b/app/src/main/java/eu/kanade/mangafeed/AppComponent.java index 1200bfcacc..02ae634d83 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.CatalogueListPresenter; import eu.kanade.mangafeed.presenter.CataloguePresenter; import eu.kanade.mangafeed.presenter.LibraryPresenter; import eu.kanade.mangafeed.presenter.MangaDetailPresenter; @@ -25,6 +26,7 @@ public interface AppComponent { void inject(LibraryPresenter libraryPresenter); void inject(MangaDetailPresenter mangaDetailPresenter); void inject(CataloguePresenter cataloguePresenter); + void inject(CatalogueListPresenter catalogueListPresenter); Application application(); -} \ No newline at end of file +} diff --git a/app/src/main/java/eu/kanade/mangafeed/presenter/CatalogueListPresenter.java b/app/src/main/java/eu/kanade/mangafeed/presenter/CatalogueListPresenter.java new file mode 100644 index 0000000000..564b68e8b3 --- /dev/null +++ b/app/src/main/java/eu/kanade/mangafeed/presenter/CatalogueListPresenter.java @@ -0,0 +1,27 @@ +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.view.CatalogueListView; + +public class CatalogueListPresenter { + + CatalogueListView view; + + @Inject SourceManager sourceManager; + + public CatalogueListPresenter(CatalogueListView view) { + this.view = view; + App.getComponent(view.getActivity()).inject(this); + } + + public void initializeSource() { + Intent intent = view.getIntent(); + int sourceId = intent.getIntExtra(Intent.EXTRA_UID, -1); + view.setSource(sourceManager.get(sourceId)); + } +} diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/activity/CatalogueListActivity.java b/app/src/main/java/eu/kanade/mangafeed/ui/activity/CatalogueListActivity.java index 37e4429f27..aaf321b6a5 100644 --- a/app/src/main/java/eu/kanade/mangafeed/ui/activity/CatalogueListActivity.java +++ b/app/src/main/java/eu/kanade/mangafeed/ui/activity/CatalogueListActivity.java @@ -1,23 +1,23 @@ package eu.kanade.mangafeed.ui.activity; -import android.content.Intent; import android.os.Bundle; -import android.support.design.widget.FloatingActionButton; -import android.support.design.widget.Snackbar; -import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; -import android.view.View; import butterknife.Bind; import butterknife.ButterKnife; import eu.kanade.mangafeed.R; +import eu.kanade.mangafeed.presenter.CatalogueListPresenter; import eu.kanade.mangafeed.sources.Source; +import eu.kanade.mangafeed.view.CatalogueListView; -public class CatalogueListActivity extends BaseActivity { +public class CatalogueListActivity extends BaseActivity implements CatalogueListView { @Bind(R.id.toolbar) Toolbar toolbar; + private CatalogueListPresenter presenter; + private Source source; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -25,6 +25,14 @@ public class CatalogueListActivity extends BaseActivity { ButterKnife.bind(this); setupToolbar(toolbar); + + presenter = new CatalogueListPresenter(this); + presenter.initializeSource(); } - + + public void setSource(Source source) { + this.source = source; + setToolbarTitle(source.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 index f58da91aa6..f05a91e5af 100644 --- a/app/src/main/java/eu/kanade/mangafeed/ui/fragment/CatalogueFragment.java +++ b/app/src/main/java/eu/kanade/mangafeed/ui/fragment/CatalogueFragment.java @@ -47,7 +47,6 @@ public class CatalogueFragment extends BaseFragment implements CatalogueView { ButterKnife.bind(this, view); presenter.initializeSources(); - return view; } diff --git a/app/src/main/java/eu/kanade/mangafeed/view/CatalogueListView.java b/app/src/main/java/eu/kanade/mangafeed/view/CatalogueListView.java new file mode 100644 index 0000000000..dc9b8c1933 --- /dev/null +++ b/app/src/main/java/eu/kanade/mangafeed/view/CatalogueListView.java @@ -0,0 +1,10 @@ +package eu.kanade.mangafeed.view; + +import android.content.Intent; + +import eu.kanade.mangafeed.sources.Source; + +public interface CatalogueListView extends BaseView { + Intent getIntent(); + void setSource(Source source); +}