SourceFragment.java 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. package eu.kanade.mangafeed.ui.fragment;
  2. import android.content.Intent;
  3. import android.os.Bundle;
  4. import android.view.LayoutInflater;
  5. import android.view.View;
  6. import android.view.ViewGroup;
  7. import android.widget.ListView;
  8. import java.util.List;
  9. import butterknife.Bind;
  10. import butterknife.ButterKnife;
  11. import butterknife.OnItemClick;
  12. import eu.kanade.mangafeed.R;
  13. import eu.kanade.mangafeed.presenter.SourcePresenter;
  14. import eu.kanade.mangafeed.sources.Source;
  15. import eu.kanade.mangafeed.ui.activity.CatalogueActivity;
  16. import eu.kanade.mangafeed.ui.activity.MainActivity;
  17. import eu.kanade.mangafeed.ui.adapter.SourceHolder;
  18. import nucleus.factory.RequiresPresenter;
  19. import uk.co.ribot.easyadapter.EasyAdapter;
  20. @RequiresPresenter(SourcePresenter.class)
  21. public class SourceFragment extends BaseFragment<SourcePresenter> {
  22. @Bind(R.id.catalogue_list) ListView source_list;
  23. private MainActivity activity;
  24. private EasyAdapter<Source> adapter;
  25. public static SourceFragment newInstance() {
  26. return new SourceFragment();
  27. }
  28. @Override
  29. public void onCreate(Bundle savedInstanceState) {
  30. super.onCreate(savedInstanceState);
  31. activity = (MainActivity)getActivity();
  32. }
  33. @Override
  34. public View onCreateView(LayoutInflater inflater, ViewGroup container,
  35. Bundle savedInstanceState) {
  36. // Inflate the layout for this fragment
  37. View view = inflater.inflate(R.layout.fragment_catalogue, container, false);
  38. ButterKnife.bind(this, view);
  39. activity.setToolbarTitle(R.string.catalogues_title);
  40. createAdapter();
  41. return view;
  42. }
  43. @OnItemClick(R.id.catalogue_list)
  44. public void onSourceClick(int position) {
  45. Source source = adapter.getItem(position);
  46. Intent intent = CatalogueActivity.newIntent(activity, source.getSourceId());
  47. startActivity(intent);
  48. }
  49. private void createAdapter() {
  50. adapter = new EasyAdapter<>(activity, SourceHolder.class);
  51. source_list.setAdapter(adapter);
  52. }
  53. public void setItems(List<Source> items) {
  54. adapter.setItems(items);
  55. }
  56. }