Added Android code
[wl-app.git] / Android / app / src / main / java / com / moiseum / wolnelektury / view / news / zoom / ZoomFragment.java
1 package com.moiseum.wolnelektury.view.news.zoom;
2
3 import android.os.Bundle;
4 import android.support.v4.view.ViewPager;
5 import android.view.View;
6
7 import com.moiseum.wolnelektury.R;
8 import com.moiseum.wolnelektury.base.mvp.PresenterFragment;
9
10 import java.util.ArrayList;
11 import java.util.List;
12
13 import butterknife.BindView;
14 import me.relex.circleindicator.CircleIndicator;
15
16 /**
17  * Created by Piotr Ostrowski on 07.08.2018.
18  */
19 public class ZoomFragment extends PresenterFragment<ZoomPresenter> implements ZoomView {
20
21         private static final String PHOTOS_URL_KEY = "PhotoUrls";
22         private static final String POSITION_KEY = "PositionKey";
23         private static final int FIVE_PAGES = 5;
24
25         @BindView(R.id.vpGallery)
26         ViewPager vpGallery;
27         @BindView(R.id.indicator)
28         CircleIndicator indicator;
29
30         public static ZoomFragment newInstance(ArrayList<String> photoUrls, int position) {
31                 ZoomFragment fragment = new ZoomFragment();
32                 Bundle args = new Bundle(1);
33                 args.putStringArrayList(PHOTOS_URL_KEY, photoUrls);
34                 args.putInt(POSITION_KEY, position);
35                 fragment.setArguments(args);
36                 return fragment;
37         }
38
39         @Override
40         protected ZoomPresenter createPresenter() {
41                 if (getArguments() == null || getArguments().getStringArrayList(PHOTOS_URL_KEY) == null || getArguments().getInt(POSITION_KEY, -1) == -1) {
42                         throw new IllegalStateException("Fragment is missing arguments");
43                 }
44                 ArrayList<String> urls = getArguments().getStringArrayList(PHOTOS_URL_KEY);
45                 int position = getArguments().getInt(POSITION_KEY);
46                 return new ZoomPresenter(urls, position, this);
47         }
48
49         @Override
50         public int getLayoutResourceId() {
51                 return R.layout.fragment_zoom;
52         }
53
54         @Override
55         public void prepareView(View view, Bundle savedInstanceState) {
56                 // nop.
57         }
58
59         @Override
60         public void initializeZoomView(List<String> photoUrls, int initialPosition) {
61                 vpGallery.setAdapter(new ZoomPhotosAdapter(photoUrls, getContext()));
62                 vpGallery.setOffscreenPageLimit(FIVE_PAGES);
63                 vpGallery.setCurrentItem(initialPosition, false);
64                 indicator.setViewPager(vpGallery);
65         }
66 }