From 8c0994747f80e617a2de991599a34a1e6acad4df Mon Sep 17 00:00:00 2001 From: inorichi Date: Sat, 17 Oct 2015 15:51:44 +0200 Subject: [PATCH] All activities using Nucleus --- .../presenter/MangaCataloguePresenter.java | 27 +------------- .../mangafeed/ui/activity/BaseActivity.java | 30 +++++++++++---- .../mangafeed/ui/activity/BaseActivity2.java | 37 ------------------- .../ui/activity/CatalogueActivity.java | 2 +- .../mangafeed/ui/activity/MainActivity.java | 5 ++- .../ui/activity/MangaCatalogueActivity.java | 32 ++-------------- .../ui/activity/MangaDetailActivity.java | 2 +- 7 files changed, 34 insertions(+), 101 deletions(-) delete mode 100644 app/src/main/java/eu/kanade/mangafeed/ui/activity/BaseActivity2.java diff --git a/app/src/main/java/eu/kanade/mangafeed/presenter/MangaCataloguePresenter.java b/app/src/main/java/eu/kanade/mangafeed/presenter/MangaCataloguePresenter.java index 8c3efd6f8..0cccaaaa2 100644 --- a/app/src/main/java/eu/kanade/mangafeed/presenter/MangaCataloguePresenter.java +++ b/app/src/main/java/eu/kanade/mangafeed/presenter/MangaCataloguePresenter.java @@ -1,30 +1,7 @@ package eu.kanade.mangafeed.presenter; -import eu.kanade.mangafeed.App; -import eu.kanade.mangafeed.data.models.Manga; -import eu.kanade.mangafeed.view.MangaCatalogueView; +import eu.kanade.mangafeed.ui.activity.MangaCatalogueActivity; -public class MangaCataloguePresenter extends BasePresenter { +public class MangaCataloguePresenter extends BasePresenter2 { - private MangaCatalogueView view; - private Manga manga; - - public MangaCataloguePresenter(MangaCatalogueView view) { - this.view = view; - App.getComponent(view.getActivity()).inject(this); - } - - public void initialize() { - - } - - public void onEventMainThread(Manga manga) { - this.manga = manga; - initializeManga(); - } - - private void initializeManga() { - view.setTitle(manga.title); - view.setMangaInformation(manga); - } } 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 ebefe83ff..079bd28ee 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 @@ -1,13 +1,31 @@ package eu.kanade.mangafeed.ui.activity; import android.content.Context; -import android.support.v7.app.AppCompatActivity; +import android.os.Bundle; import android.support.v7.widget.Toolbar; import eu.kanade.mangafeed.App; -import eu.kanade.mangafeed.AppComponent; +import nucleus.factory.PresenterFactory; +import nucleus.presenter.Presenter; +import nucleus.view.NucleusAppCompatActivity; +import timber.log.Timber; -public class BaseActivity extends AppCompatActivity { +public class BaseActivity

extends NucleusAppCompatActivity

{ + + @Override + protected void onCreate(Bundle savedInstanceState) { + 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()); + } + return presenter; + }); + super.onCreate(savedInstanceState); + } protected void setupToolbar(Toolbar toolbar) { setSupportActionBar(toolbar); @@ -18,11 +36,7 @@ public class BaseActivity extends AppCompatActivity { getSupportActionBar().setTitle(title); } - protected AppComponent applicationComponent() { - return App.get(this).getComponent(); - } - public Context getActivity() { return this; } -} +} \ No newline at end of file diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/activity/BaseActivity2.java b/app/src/main/java/eu/kanade/mangafeed/ui/activity/BaseActivity2.java deleted file mode 100644 index 090254329..000000000 --- a/app/src/main/java/eu/kanade/mangafeed/ui/activity/BaseActivity2.java +++ /dev/null @@ -1,37 +0,0 @@ -package eu.kanade.mangafeed.ui.activity; - -import android.content.Context; -import android.os.Bundle; -import android.support.v7.widget.Toolbar; - -import eu.kanade.mangafeed.App; -import nucleus.factory.PresenterFactory; -import nucleus.presenter.Presenter; -import nucleus.view.NucleusAppCompatActivity; - -public class BaseActivity2

extends NucleusAppCompatActivity

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

superFactory = super.getPresenterFactory(); - setPresenterFactory(() -> { - P presenter = superFactory.createPresenter(); - App.getComponentReflection(getActivity()).inject(presenter); - return presenter; - }); - super.onCreate(savedInstanceState); - } - - protected void setupToolbar(Toolbar toolbar) { - setSupportActionBar(toolbar); - getSupportActionBar().setDisplayHomeAsUpEnabled(true); - } - - public void setToolbarTitle(String title) { - getSupportActionBar().setTitle(title); - } - - public Context getActivity() { - return this; - } -} \ No newline at end of file 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 83fc7ce42..a69f3d122 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 @@ -22,7 +22,7 @@ import nucleus.factory.RequiresPresenter; import uk.co.ribot.easyadapter.EasyAdapter; @RequiresPresenter(CataloguePresenter.class) -public class CatalogueActivity extends BaseActivity2 { +public class CatalogueActivity extends BaseActivity { @Bind(R.id.toolbar) Toolbar toolbar; 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 c71f80d80..d36973c96 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,10 +13,13 @@ import com.mikepenz.materialdrawer.model.PrimaryDrawerItem; import butterknife.Bind; import butterknife.ButterKnife; import eu.kanade.mangafeed.R; +import eu.kanade.mangafeed.presenter.BasePresenter2; import eu.kanade.mangafeed.ui.fragment.LibraryFragment; import eu.kanade.mangafeed.ui.fragment.SourceFragment; +import nucleus.factory.RequiresPresenter; -public class MainActivity extends BaseActivity { +@RequiresPresenter(BasePresenter2.class) +public class MainActivity extends BaseActivity { @Bind(R.id.toolbar) Toolbar toolbar; diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/activity/MangaCatalogueActivity.java b/app/src/main/java/eu/kanade/mangafeed/ui/activity/MangaCatalogueActivity.java index 7893c6e7e..461b8a728 100644 --- a/app/src/main/java/eu/kanade/mangafeed/ui/activity/MangaCatalogueActivity.java +++ b/app/src/main/java/eu/kanade/mangafeed/ui/activity/MangaCatalogueActivity.java @@ -13,9 +13,10 @@ import butterknife.ButterKnife; import eu.kanade.mangafeed.R; import eu.kanade.mangafeed.data.models.Manga; import eu.kanade.mangafeed.presenter.MangaCataloguePresenter; -import eu.kanade.mangafeed.view.MangaCatalogueView; +import nucleus.factory.RequiresPresenter; -public class MangaCatalogueActivity extends BaseActivity implements MangaCatalogueView { +@RequiresPresenter(MangaCataloguePresenter.class) +public class MangaCatalogueActivity extends BaseActivity { @Bind(R.id.toolbar) Toolbar toolbar; @@ -27,8 +28,6 @@ public class MangaCatalogueActivity extends BaseActivity implements MangaCatalog @Bind(R.id.manga_summary) TextView mDescription; @Bind(R.id.manga_cover) ImageView mCover; - private MangaCataloguePresenter presenter; - @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -36,32 +35,9 @@ public class MangaCatalogueActivity extends BaseActivity implements MangaCatalog ButterKnife.bind(this); setupToolbar(toolbar); - - presenter = new MangaCataloguePresenter(this); - presenter.initialize(); } - @Override - public void onStart() { - super.onStart(); - presenter.registerForStickyEvents(); - } - - @Override - public void onStop() { - presenter.unregisterForEvents(); - super.onStop(); - } - - // MangaCatalogueView - - @Override - public void setTitle(String title) { - setToolbarTitle(title); - } - - @Override - public void setMangaInformation(Manga manga) { + public void setMangaInfo(Manga manga) { mArtist.setText(manga.artist); mAuthor.setText(manga.author); mChapters.setText("0"); // TODO 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 a1ee6ad96..e7023ae0d 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 @@ -21,7 +21,7 @@ import eu.kanade.mangafeed.ui.fragment.MangaInfoFragment; import nucleus.factory.RequiresPresenter; @RequiresPresenter(MangaDetailPresenter.class) -public class MangaDetailActivity extends BaseActivity2 { +public class MangaDetailActivity extends BaseActivity { @Bind(R.id.toolbar) Toolbar toolbar;