All activities using Nucleus

This commit is contained in:
inorichi 2015-10-17 15:51:44 +02:00
parent 0e52c81970
commit 8c0994747f
7 changed files with 34 additions and 101 deletions

View File

@ -1,30 +1,7 @@
package eu.kanade.mangafeed.presenter; package eu.kanade.mangafeed.presenter;
import eu.kanade.mangafeed.App; import eu.kanade.mangafeed.ui.activity.MangaCatalogueActivity;
import eu.kanade.mangafeed.data.models.Manga;
import eu.kanade.mangafeed.view.MangaCatalogueView;
public class MangaCataloguePresenter extends BasePresenter { public class MangaCataloguePresenter extends BasePresenter2<MangaCatalogueActivity> {
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);
}
} }

View File

@ -1,13 +1,31 @@
package eu.kanade.mangafeed.ui.activity; package eu.kanade.mangafeed.ui.activity;
import android.content.Context; import android.content.Context;
import android.support.v7.app.AppCompatActivity; import android.os.Bundle;
import android.support.v7.widget.Toolbar; import android.support.v7.widget.Toolbar;
import eu.kanade.mangafeed.App; 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<P extends Presenter> extends NucleusAppCompatActivity<P> {
@Override
protected void onCreate(Bundle savedInstanceState) {
final PresenterFactory<P> 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) { protected void setupToolbar(Toolbar toolbar) {
setSupportActionBar(toolbar); setSupportActionBar(toolbar);
@ -18,11 +36,7 @@ public class BaseActivity extends AppCompatActivity {
getSupportActionBar().setTitle(title); getSupportActionBar().setTitle(title);
} }
protected AppComponent applicationComponent() {
return App.get(this).getComponent();
}
public Context getActivity() { public Context getActivity() {
return this; return this;
} }
} }

View File

@ -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<P extends Presenter> extends NucleusAppCompatActivity<P> {
@Override
protected void onCreate(Bundle savedInstanceState) {
final PresenterFactory<P> 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;
}
}

View File

@ -22,7 +22,7 @@ import nucleus.factory.RequiresPresenter;
import uk.co.ribot.easyadapter.EasyAdapter; import uk.co.ribot.easyadapter.EasyAdapter;
@RequiresPresenter(CataloguePresenter.class) @RequiresPresenter(CataloguePresenter.class)
public class CatalogueActivity extends BaseActivity2<CataloguePresenter> { public class CatalogueActivity extends BaseActivity<CataloguePresenter> {
@Bind(R.id.toolbar) @Bind(R.id.toolbar)
Toolbar toolbar; Toolbar toolbar;

View File

@ -13,10 +13,13 @@ import com.mikepenz.materialdrawer.model.PrimaryDrawerItem;
import butterknife.Bind; import butterknife.Bind;
import butterknife.ButterKnife; import butterknife.ButterKnife;
import eu.kanade.mangafeed.R; import eu.kanade.mangafeed.R;
import eu.kanade.mangafeed.presenter.BasePresenter2;
import eu.kanade.mangafeed.ui.fragment.LibraryFragment; import eu.kanade.mangafeed.ui.fragment.LibraryFragment;
import eu.kanade.mangafeed.ui.fragment.SourceFragment; import eu.kanade.mangafeed.ui.fragment.SourceFragment;
import nucleus.factory.RequiresPresenter;
public class MainActivity extends BaseActivity { @RequiresPresenter(BasePresenter2.class)
public class MainActivity extends BaseActivity<BasePresenter2> {
@Bind(R.id.toolbar) @Bind(R.id.toolbar)
Toolbar toolbar; Toolbar toolbar;

View File

@ -13,9 +13,10 @@ import butterknife.ButterKnife;
import eu.kanade.mangafeed.R; import eu.kanade.mangafeed.R;
import eu.kanade.mangafeed.data.models.Manga; import eu.kanade.mangafeed.data.models.Manga;
import eu.kanade.mangafeed.presenter.MangaCataloguePresenter; 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<MangaCataloguePresenter> {
@Bind(R.id.toolbar) Toolbar toolbar; @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_summary) TextView mDescription;
@Bind(R.id.manga_cover) ImageView mCover; @Bind(R.id.manga_cover) ImageView mCover;
private MangaCataloguePresenter presenter;
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
@ -36,32 +35,9 @@ public class MangaCatalogueActivity extends BaseActivity implements MangaCatalog
ButterKnife.bind(this); ButterKnife.bind(this);
setupToolbar(toolbar); setupToolbar(toolbar);
presenter = new MangaCataloguePresenter(this);
presenter.initialize();
} }
@Override public void setMangaInfo(Manga manga) {
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) {
mArtist.setText(manga.artist); mArtist.setText(manga.artist);
mAuthor.setText(manga.author); mAuthor.setText(manga.author);
mChapters.setText("0"); // TODO mChapters.setText("0"); // TODO

View File

@ -21,7 +21,7 @@ import eu.kanade.mangafeed.ui.fragment.MangaInfoFragment;
import nucleus.factory.RequiresPresenter; import nucleus.factory.RequiresPresenter;
@RequiresPresenter(MangaDetailPresenter.class) @RequiresPresenter(MangaDetailPresenter.class)
public class MangaDetailActivity extends BaseActivity2<MangaDetailPresenter> { public class MangaDetailActivity extends BaseActivity<MangaDetailPresenter> {
@Bind(R.id.toolbar) @Bind(R.id.toolbar)
Toolbar toolbar; Toolbar toolbar;