Show chapters tab if it's a manga from library

This commit is contained in:
inorichi 2015-10-17 17:32:31 +02:00
parent 161a4b17a6
commit c13d747665
2 changed files with 18 additions and 5 deletions

View file

@ -102,6 +102,7 @@ public class CatalogueActivity extends BaseActivity<CataloguePresenter> {
Manga selectedManga = adapter.getItem(position); Manga selectedManga = adapter.getItem(position);
Intent intent = MangaDetailActivity.newIntent(this, selectedManga); Intent intent = MangaDetailActivity.newIntent(this, selectedManga);
intent.putExtra(MangaDetailActivity.MANGA_ONLINE, true);
startActivity(intent); startActivity(intent);
} }

View file

@ -32,10 +32,12 @@ public class MangaDetailActivity extends BaseActivity<MangaDetailPresenter> {
@Bind(R.id.viewpager) @Bind(R.id.viewpager)
ViewPager view_pager; ViewPager view_pager;
long manga_id; private long manga_id;
private boolean is_online = false;
public final static String MANGA_ID = "manga_id"; public final static String MANGA_ID = "manga_id";
public final static String MANGA_TITLE = "manga_title"; public final static String MANGA_TITLE = "manga_title";
public final static String MANGA_ONLINE = "manga_online";
public static Intent newIntent(Context context, Manga manga) { public static Intent newIntent(Context context, Manga manga) {
Intent intent = new Intent(context, MangaDetailActivity.class); Intent intent = new Intent(context, MangaDetailActivity.class);
@ -53,10 +55,14 @@ public class MangaDetailActivity extends BaseActivity<MangaDetailPresenter> {
setupToolbar(toolbar); setupToolbar(toolbar);
disableToolbarElevation(); disableToolbarElevation();
String manga_title = getIntent().getStringExtra(MANGA_TITLE); Intent intent = getIntent();
String manga_title = intent.getStringExtra(MANGA_TITLE);
setToolbarTitle(manga_title); setToolbarTitle(manga_title);
manga_id = getIntent().getLongExtra(MANGA_ID, -1); manga_id = intent.getLongExtra(MANGA_ID, -1);
is_online = intent.getBooleanExtra(MANGA_ONLINE, false);
setupViewPager(); setupViewPager();
} }
@ -73,6 +79,9 @@ public class MangaDetailActivity extends BaseActivity<MangaDetailPresenter> {
manga_id)); manga_id));
tabs.setupWithViewPager(view_pager); tabs.setupWithViewPager(view_pager);
if (!is_online)
view_pager.setCurrentItem(MangaDetailAdapter.CHAPTERS_FRAGMENT);
} }
} }
@ -84,6 +93,9 @@ class MangaDetailAdapter extends FragmentPagerAdapter {
private Context context; private Context context;
private long manga_id; private long manga_id;
final static int INFO_FRAGMENT = 0;
final static int CHAPTERS_FRAGMENT = 1;
public MangaDetailAdapter(FragmentManager fm, Context context, long manga_id) { public MangaDetailAdapter(FragmentManager fm, Context context, long manga_id) {
super(fm); super(fm);
this.context = context; this.context = context;
@ -102,9 +114,9 @@ class MangaDetailAdapter extends FragmentPagerAdapter {
@Override @Override
public Fragment getItem(int position) { public Fragment getItem(int position) {
switch (position) { switch (position) {
case 0: case INFO_FRAGMENT:
return MangaInfoFragment.newInstance(manga_id); return MangaInfoFragment.newInstance(manga_id);
case 1: case CHAPTERS_FRAGMENT:
return MangaChaptersFragment.newInstance(manga_id); return MangaChaptersFragment.newInstance(manga_id);
default: return null; default: return null;