Welcome to mirror list, hosted at ThFree Co, Russian Federation.

GalleryFragment.java « gallery « maps « mapswithme « com « src « android - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: dbfae127200a5a863bf1869c68bc91f71d928755 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package com.mapswithme.maps.gallery;

import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.mapswithme.maps.R;
import com.mapswithme.maps.base.BaseMwmFragment;
import com.mapswithme.maps.widget.recycler.GridDividerItemDecoration;
import com.mapswithme.maps.widget.recycler.RecyclerClickListener;

import java.util.ArrayList;

public class GalleryFragment extends BaseMwmFragment implements RecyclerClickListener
{
  private static final int NUM_COLUMNS = 3;

  @Nullable
  private ArrayList<Image> mImages;

  @Nullable
  @Override
  public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
                           @Nullable Bundle savedInstanceState)
  {
    return inflater.inflate(R.layout.fragment_gallery, container, false);
  }

  @Override
  public void onViewCreated(View view, @Nullable Bundle savedInstanceState)
  {
    super.onViewCreated(view, savedInstanceState);
    readArguments();

    if (mImages != null)
    {
      RecyclerView rvGallery = (RecyclerView) view.findViewById(R.id.rv__gallery);
      rvGallery.setLayoutManager(new GridLayoutManager(getContext(), NUM_COLUMNS));
      rvGallery.setAdapter(new ImageAdapter(mImages, this));
      Drawable divider = ContextCompat.getDrawable(getContext(), R.drawable.divider_transparent_quarter);
      rvGallery.addItemDecoration(new GridDividerItemDecoration(divider, divider, NUM_COLUMNS));
    }
  }

  private void readArguments()
  {
    final Bundle arguments = getArguments();
    if (arguments == null)
      return;

    mImages = arguments.getParcelableArrayList(GalleryActivity.EXTRA_IMAGES);
  }

  @Override
  public void onItemClick(View v, int position)
  {
    FullScreenGalleryActivity.start(getContext(), mImages, position);
  }
}