mirror of
https://github.com/mihonapp/mihon.git
synced 2024-11-28 22:53:15 -05:00
All fragments using Nucleus
This commit is contained in:
parent
8c0994747f
commit
b36aa69a67
11 changed files with 74 additions and 85 deletions
|
@ -1,45 +1,24 @@
|
||||||
package eu.kanade.mangafeed.presenter;
|
package eu.kanade.mangafeed.presenter;
|
||||||
|
|
||||||
import android.content.Intent;
|
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import eu.kanade.mangafeed.App;
|
|
||||||
import eu.kanade.mangafeed.data.helpers.SourceManager;
|
import eu.kanade.mangafeed.data.helpers.SourceManager;
|
||||||
import eu.kanade.mangafeed.sources.Source;
|
import eu.kanade.mangafeed.sources.Source;
|
||||||
import eu.kanade.mangafeed.ui.activity.CatalogueActivity;
|
import eu.kanade.mangafeed.ui.fragment.SourceFragment;
|
||||||
import eu.kanade.mangafeed.ui.adapter.SourceHolder;
|
|
||||||
import eu.kanade.mangafeed.view.SourceView;
|
|
||||||
import uk.co.ribot.easyadapter.EasyAdapter;
|
|
||||||
|
|
||||||
|
|
||||||
public class SourcePresenter {
|
public class SourcePresenter extends BasePresenter2<SourceFragment> {
|
||||||
|
|
||||||
private SourceView view;
|
|
||||||
|
|
||||||
@Inject SourceManager sourceManager;
|
@Inject SourceManager sourceManager;
|
||||||
|
|
||||||
EasyAdapter<Source> adapter;
|
@Override
|
||||||
|
protected void onTakeView(SourceFragment view) {
|
||||||
|
super.onTakeView(view);
|
||||||
|
|
||||||
public SourcePresenter(SourceView view) {
|
view.setItems(sourceManager.getSources());
|
||||||
this.view = view;
|
|
||||||
App.getComponent(view.getActivity()).inject(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void initializeSources() {
|
public void setSelectedSource(Source source) {
|
||||||
adapter = new EasyAdapter<>(
|
sourceManager.setSelectedSource(source.getSourceId());
|
||||||
view.getActivity(),
|
|
||||||
SourceHolder.class,
|
|
||||||
sourceManager.getSources());
|
|
||||||
|
|
||||||
view.setAdapter(adapter);
|
|
||||||
view.setSourceClickListener();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onSourceClick(int position) {
|
|
||||||
sourceManager.setSelectedSource(adapter.getItem(position).getSource());
|
|
||||||
Intent intent = new Intent(view.getActivity(), CatalogueActivity.class);
|
|
||||||
intent.putExtra(Intent.EXTRA_UID, adapter.getItem(position).getSource());
|
|
||||||
view.getActivity().startActivity(intent);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -92,7 +92,7 @@ public class Batoto extends Source {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getSource() {
|
public int getSourceId() {
|
||||||
return SourceManager.BATOTO;
|
return SourceManager.BATOTO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -148,7 +148,7 @@ public class Batoto extends Source {
|
||||||
Element nameElement = urlElement;
|
Element nameElement = urlElement;
|
||||||
Element updateElement = htmlBlock.select("td").get(5);
|
Element updateElement = htmlBlock.select("td").get(5);
|
||||||
|
|
||||||
mangaFromHtmlBlock.source = getSource();
|
mangaFromHtmlBlock.source = getSourceId();
|
||||||
|
|
||||||
if (urlElement != null) {
|
if (urlElement != null) {
|
||||||
String fieldUrl = urlElement.attr("href");
|
String fieldUrl = urlElement.attr("href");
|
||||||
|
|
|
@ -37,7 +37,7 @@ public class MangaHere extends Source {
|
||||||
return NAME;
|
return NAME;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getSource() {
|
public int getSourceId() {
|
||||||
return SourceManager.MANGAHERE;
|
return SourceManager.MANGAHERE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -112,7 +112,7 @@ public class MangaHere extends Source {
|
||||||
|
|
||||||
private Manga constructMangaFromHtmlBlock(Element htmlBlock) {
|
private Manga constructMangaFromHtmlBlock(Element htmlBlock) {
|
||||||
Manga mangaFromHtmlBlock = new Manga();
|
Manga mangaFromHtmlBlock = new Manga();
|
||||||
mangaFromHtmlBlock.source = getSource();
|
mangaFromHtmlBlock.source = getSourceId();
|
||||||
|
|
||||||
Element urlElement = htmlBlock.select("a.manga_info").first();
|
Element urlElement = htmlBlock.select("a.manga_info").first();
|
||||||
Element nameElement = htmlBlock.select("a.manga_info").first();
|
Element nameElement = htmlBlock.select("a.manga_info").first();
|
||||||
|
|
|
@ -102,7 +102,7 @@ public abstract class Source {
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract String getName();
|
public abstract String getName();
|
||||||
public abstract int getSource();
|
public abstract int getSourceId();
|
||||||
|
|
||||||
protected abstract String getUrlFromPageNumber(int page);
|
protected abstract String getUrlFromPageNumber(int page);
|
||||||
protected abstract String getSearchUrl(String query, int page);
|
protected abstract String getSearchUrl(String query, int page);
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package eu.kanade.mangafeed.ui.activity;
|
package eu.kanade.mangafeed.ui.activity;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v7.widget.SearchView;
|
import android.support.v7.widget.SearchView;
|
||||||
import android.support.v7.widget.Toolbar;
|
import android.support.v7.widget.Toolbar;
|
||||||
|
@ -39,6 +41,14 @@ public class CatalogueActivity extends BaseActivity<CataloguePresenter> {
|
||||||
private EasyAdapter<Manga> adapter;
|
private EasyAdapter<Manga> adapter;
|
||||||
private EndlessScrollListener scroll_listener;
|
private EndlessScrollListener scroll_listener;
|
||||||
|
|
||||||
|
public final static String SOURCE_ID = "source_id";
|
||||||
|
|
||||||
|
public static Intent newIntent(Context context, int source_id) {
|
||||||
|
Intent intent = new Intent(context, CatalogueActivity.class);
|
||||||
|
intent.putExtra(SOURCE_ID, source_id);
|
||||||
|
return intent;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
|
@ -1,6 +1,23 @@
|
||||||
package eu.kanade.mangafeed.ui.fragment;
|
package eu.kanade.mangafeed.ui.fragment;
|
||||||
|
|
||||||
import android.support.v4.app.Fragment;
|
import android.os.Bundle;
|
||||||
|
|
||||||
public class BaseFragment extends Fragment {
|
import eu.kanade.mangafeed.App;
|
||||||
}
|
import nucleus.factory.PresenterFactory;
|
||||||
|
import nucleus.presenter.Presenter;
|
||||||
|
import nucleus.view.NucleusSupportFragment;
|
||||||
|
|
||||||
|
public class BaseFragment<P extends Presenter> extends NucleusSupportFragment<P> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,23 +0,0 @@
|
||||||
package eu.kanade.mangafeed.ui.fragment;
|
|
||||||
|
|
||||||
import android.os.Bundle;
|
|
||||||
|
|
||||||
import eu.kanade.mangafeed.App;
|
|
||||||
import nucleus.factory.PresenterFactory;
|
|
||||||
import nucleus.presenter.Presenter;
|
|
||||||
import nucleus.view.NucleusSupportFragment;
|
|
||||||
|
|
||||||
public class BaseFragment2<P extends Presenter> extends NucleusSupportFragment<P> {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public 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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -23,7 +23,7 @@ import eu.kanade.mangafeed.ui.adapter.LibraryAdapter;
|
||||||
import nucleus.factory.RequiresPresenter;
|
import nucleus.factory.RequiresPresenter;
|
||||||
|
|
||||||
@RequiresPresenter(LibraryPresenter.class)
|
@RequiresPresenter(LibraryPresenter.class)
|
||||||
public class LibraryFragment extends BaseFragment2<LibraryPresenter> {
|
public class LibraryFragment extends BaseFragment<LibraryPresenter> {
|
||||||
|
|
||||||
@Bind(R.id.gridView) GridView grid;
|
@Bind(R.id.gridView) GridView grid;
|
||||||
private MainActivity activity;
|
private MainActivity activity;
|
||||||
|
|
|
@ -13,7 +13,7 @@ import eu.kanade.mangafeed.ui.activity.MangaDetailActivity;
|
||||||
import nucleus.factory.RequiresPresenter;
|
import nucleus.factory.RequiresPresenter;
|
||||||
|
|
||||||
@RequiresPresenter(MangaChaptersPresenter.class)
|
@RequiresPresenter(MangaChaptersPresenter.class)
|
||||||
public class MangaChaptersFragment extends BaseFragment2<MangaChaptersPresenter> {
|
public class MangaChaptersFragment extends BaseFragment<MangaChaptersPresenter> {
|
||||||
|
|
||||||
private long manga_id;
|
private long manga_id;
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@ import eu.kanade.mangafeed.ui.activity.MangaDetailActivity;
|
||||||
import nucleus.factory.RequiresPresenter;
|
import nucleus.factory.RequiresPresenter;
|
||||||
|
|
||||||
@RequiresPresenter(MangaInfoPresenter.class)
|
@RequiresPresenter(MangaInfoPresenter.class)
|
||||||
public class MangaInfoFragment extends BaseFragment2<MangaInfoPresenter> {
|
public class MangaInfoFragment extends BaseFragment<MangaInfoPresenter> {
|
||||||
|
|
||||||
@Bind(R.id.manga_artist) TextView mArtist;
|
@Bind(R.id.manga_artist) TextView mArtist;
|
||||||
@Bind(R.id.manga_author) TextView mAuthor;
|
@Bind(R.id.manga_author) TextView mAuthor;
|
||||||
|
|
|
@ -1,40 +1,41 @@
|
||||||
package eu.kanade.mangafeed.ui.fragment;
|
package eu.kanade.mangafeed.ui.fragment;
|
||||||
|
|
||||||
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import butterknife.Bind;
|
import butterknife.Bind;
|
||||||
import butterknife.ButterKnife;
|
import butterknife.ButterKnife;
|
||||||
|
import butterknife.OnItemClick;
|
||||||
import eu.kanade.mangafeed.R;
|
import eu.kanade.mangafeed.R;
|
||||||
import eu.kanade.mangafeed.presenter.SourcePresenter;
|
import eu.kanade.mangafeed.presenter.SourcePresenter;
|
||||||
|
import eu.kanade.mangafeed.sources.Source;
|
||||||
|
import eu.kanade.mangafeed.ui.activity.CatalogueActivity;
|
||||||
import eu.kanade.mangafeed.ui.activity.MainActivity;
|
import eu.kanade.mangafeed.ui.activity.MainActivity;
|
||||||
import eu.kanade.mangafeed.view.SourceView;
|
import eu.kanade.mangafeed.ui.adapter.SourceHolder;
|
||||||
|
import nucleus.factory.RequiresPresenter;
|
||||||
import uk.co.ribot.easyadapter.EasyAdapter;
|
import uk.co.ribot.easyadapter.EasyAdapter;
|
||||||
|
|
||||||
|
@RequiresPresenter(SourcePresenter.class)
|
||||||
|
public class SourceFragment extends BaseFragment<SourcePresenter> {
|
||||||
|
|
||||||
public class SourceFragment extends BaseFragment implements SourceView {
|
@Bind(R.id.catalogue_list) ListView source_list;
|
||||||
|
|
||||||
private SourcePresenter presenter;
|
|
||||||
private MainActivity activity;
|
private MainActivity activity;
|
||||||
|
private EasyAdapter<Source> adapter;
|
||||||
@Bind(R.id.catalogue_list)
|
|
||||||
ListView source_list;
|
|
||||||
|
|
||||||
public static SourceFragment newInstance() {
|
public static SourceFragment newInstance() {
|
||||||
SourceFragment fragment = new SourceFragment();
|
return new SourceFragment();
|
||||||
Bundle args = new Bundle();
|
|
||||||
fragment.setArguments(args);
|
|
||||||
return fragment;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
presenter = new SourcePresenter(this);
|
|
||||||
activity = (MainActivity)getActivity();
|
activity = (MainActivity)getActivity();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,22 +47,27 @@ public class SourceFragment extends BaseFragment implements SourceView {
|
||||||
activity.setToolbarTitle(R.string.catalogues_title);
|
activity.setToolbarTitle(R.string.catalogues_title);
|
||||||
ButterKnife.bind(this, view);
|
ButterKnife.bind(this, view);
|
||||||
|
|
||||||
presenter.initializeSources();
|
createAdapter();
|
||||||
|
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
// SourceView
|
@OnItemClick(R.id.catalogue_list)
|
||||||
|
public void onSourceClick(int position) {
|
||||||
|
Source source = adapter.getItem(position);
|
||||||
|
getPresenter().setSelectedSource(source);
|
||||||
|
|
||||||
@Override
|
Intent intent = CatalogueActivity.newIntent(activity, source.getSourceId());
|
||||||
public void setAdapter(EasyAdapter adapter) {
|
startActivity(intent);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void createAdapter() {
|
||||||
|
adapter = new EasyAdapter<>(activity, SourceHolder.class);
|
||||||
source_list.setAdapter(adapter);
|
source_list.setAdapter(adapter);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public void setItems(List<Source> items) {
|
||||||
public void setSourceClickListener() {
|
adapter.setItems(items);
|
||||||
source_list.setOnItemClickListener(
|
|
||||||
(parent, view, position, id) ->
|
|
||||||
presenter.onSourceClick(position)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue