1 package com.moiseum.wolnelektury.view.book;
3 import android.content.Context;
4 import android.os.Bundle;
6 import com.moiseum.wolnelektury.R;
7 import com.moiseum.wolnelektury.base.AbstractActivity;
8 import com.moiseum.wolnelektury.base.AbstractIntent;
11 * Created by Piotr Ostrowski on 17.11.2017.
14 public class BookActivity extends AbstractActivity {
16 private static final String BOOK_FRAGMENT_TAG = "BookFragmentTag";
17 static final String BOOK_SLUG_KEY = "BookSlugKey";
18 static final String BOOK_TYPE_KEY = "BookTypeKey";
20 public static class BookIntent extends AbstractIntent {
22 public BookIntent(String slug, BookType type, Context context) {
23 super(context, BookActivity.class);
24 putExtra(BOOK_SLUG_KEY, slug);
25 putExtra(BOOK_TYPE_KEY, type.name());
30 public int getLayoutResourceId() {
31 return R.layout.activity_blank;
35 public void prepareView(Bundle savedInstanceState) {
37 if (!getIntent().hasExtra(BOOK_SLUG_KEY)) {
38 throw new IllegalStateException("Missing either slug or full ebook model.");
40 if (!getIntent().hasExtra(BOOK_TYPE_KEY)) {
41 throw new IllegalStateException("Missing book type.");
44 String bookSlug = getIntent().getStringExtra(BOOK_SLUG_KEY);
45 BookType type = BookType.valueOf(getIntent().getStringExtra(BOOK_TYPE_KEY));
47 BookFragment bookFragment = (BookFragment) getSupportFragmentManager().findFragmentByTag(BOOK_FRAGMENT_TAG);
48 if (bookFragment == null) {
49 bookFragment = BookFragment.newInstance(bookSlug, type);
50 getSupportFragmentManager().beginTransaction().add(R.id.flContainer, bookFragment, BOOK_FRAGMENT_TAG).commit();