Added Android code
[wl-app.git] / Android / app / src / main / java / com / moiseum / wolnelektury / view / player / PlayerActivity.java
1 package com.moiseum.wolnelektury.view.player;
2
3 import android.content.Context;
4 import android.os.Bundle;
5
6 import com.moiseum.wolnelektury.R;
7 import com.moiseum.wolnelektury.base.AbstractActivity;
8 import com.moiseum.wolnelektury.base.AbstractIntent;
9 import com.moiseum.wolnelektury.connection.models.BookDetailsModel;
10
11 import org.parceler.Parcels;
12
13 import static com.moiseum.wolnelektury.view.player.PlayerActivity.PlayerIntent.BOOK_KEY;
14 import static com.moiseum.wolnelektury.view.player.PlayerActivity.PlayerIntent.BOOK_SLUG_KEY;
15
16 /**
17  * Created by Piotr Ostrowski on 22.05.2018.
18  */
19 public class PlayerActivity extends AbstractActivity {
20
21         private static final String PLAYER_FRAGMENT_TAG = "PlayerFragmentTag";
22
23         public static class PlayerIntent extends AbstractIntent {
24
25                 static final String BOOK_KEY = "BookKey";
26                 static final String BOOK_SLUG_KEY = "BookSlugKey";
27
28                 public PlayerIntent(BookDetailsModel book, String slug, Context context) {
29                         super(context, PlayerActivity.class);
30                         putExtra(BOOK_KEY, Parcels.wrap(book));
31                         putExtra(BOOK_SLUG_KEY, slug);
32                 }
33         }
34
35         @Override
36         public int getLayoutResourceId() {
37                 return R.layout.activity_blank;
38         }
39
40         @Override
41         public void prepareView(Bundle savedInstanceState) {
42                 PlayerFragment playerFragment = (PlayerFragment) getSupportFragmentManager().findFragmentByTag(PLAYER_FRAGMENT_TAG);
43                 if (playerFragment == null) {
44                         playerFragment = PlayerFragment.newInstance(Parcels.unwrap(getIntent().getParcelableExtra(BOOK_KEY)), getIntent().getStringExtra(BOOK_SLUG_KEY));
45                         getSupportFragmentManager().beginTransaction().add(R.id.flContainer, playerFragment, PLAYER_FRAGMENT_TAG).commit();
46                 }
47         }
48 }