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;
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<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;
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<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) {
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;
}
}
}

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;
@RequiresPresenter(CataloguePresenter.class)
public class CatalogueActivity extends BaseActivity2<CataloguePresenter> {
public class CatalogueActivity extends BaseActivity<CataloguePresenter> {
@Bind(R.id.toolbar)
Toolbar toolbar;

View file

@ -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<BasePresenter2> {
@Bind(R.id.toolbar)
Toolbar toolbar;

View file

@ -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<MangaCataloguePresenter> {
@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

View file

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