1 package com.moiseum.wolnelektury.view.news.zoom;
3 import android.os.Bundle;
4 import android.support.v4.view.ViewPager;
5 import android.view.View;
7 import com.moiseum.wolnelektury.R;
8 import com.moiseum.wolnelektury.base.mvp.PresenterFragment;
10 import java.util.ArrayList;
11 import java.util.List;
13 import butterknife.BindView;
14 import me.relex.circleindicator.CircleIndicator;
17 * Created by Piotr Ostrowski on 07.08.2018.
19 public class ZoomFragment extends PresenterFragment<ZoomPresenter> implements ZoomView {
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;
25 @BindView(R.id.vpGallery)
27 @BindView(R.id.indicator)
28 CircleIndicator indicator;
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);
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");
44 ArrayList<String> urls = getArguments().getStringArrayList(PHOTOS_URL_KEY);
45 int position = getArguments().getInt(POSITION_KEY);
46 return new ZoomPresenter(urls, position, this);
50 public int getLayoutResourceId() {
51 return R.layout.fragment_zoom;
55 public void prepareView(View view, Bundle savedInstanceState) {
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);