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

FullScreenGalleryActivity.java « gallery « maps « mapswithme « com « src « android - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 278b344c77096192aa4628ecc98d8acf642b3727 (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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
package com.mapswithme.maps.gallery;

import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.annotation.StyleRes;
import androidx.core.graphics.drawable.RoundedBitmapDrawable;
import androidx.core.graphics.drawable.RoundedBitmapDrawableFactory;
import androidx.viewpager.widget.ViewPager;
import androidx.appcompat.widget.Toolbar;
import android.text.TextUtils;
import android.text.format.DateFormat;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.target.BitmapImageViewTarget;
import com.mapswithme.maps.R;
import com.mapswithme.maps.base.BaseMwmFragmentActivity;
import com.mapswithme.util.ThemeUtils;
import com.mapswithme.util.UiUtils;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class FullScreenGalleryActivity extends BaseMwmFragmentActivity
    implements ViewPager.OnPageChangeListener
{
  public static final String EXTRA_IMAGES = "gallery_images";
  public static final String EXTRA_POSITION = "gallery_position";

  private List<Image> mImages;
  private int mPosition;
  private View mUserBlock;
  private TextView mDescription;
  private TextView mUserName;
  private TextView mSource;
  private TextView mDate;
  private ImageView mAvatar;

  private GalleryPageAdapter mGalleryPageAdapter;

  public static void start(Context context, ArrayList<Image> images, int position)
  {
    final Intent i = new Intent(context, FullScreenGalleryActivity.class);
    i.putParcelableArrayListExtra(EXTRA_IMAGES, images);
    i.putExtra(EXTRA_POSITION, position);
    context.startActivity(i);
  }

  @Override
  protected void onSafeCreate(Bundle savedInstanceState)
  {
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

    super.onSafeCreate(savedInstanceState);
    Toolbar toolbar = getToolbar();
    toolbar.setTitle("");
    UiUtils.showHomeUpButton(toolbar);
    displayToolbarAsActionBar();

    mUserBlock = findViewById(R.id.rl__user_block);
    mDescription = (TextView) findViewById(R.id.tv__description);
    mUserName = (TextView) findViewById(R.id.tv__name);
    mSource = (TextView) findViewById(R.id.tv__source);
    mDate = (TextView) findViewById(R.id.tv__date);
    mAvatar = (ImageView) findViewById(R.id.iv__avatar);

    readParameters();
    if (mImages != null)
    {
      mGalleryPageAdapter = new GalleryPageAdapter(getSupportFragmentManager(), mImages);
      final ViewPager viewPager = (ViewPager) findViewById(R.id.vp__image);
      viewPager.addOnPageChangeListener(this);
      viewPager.setAdapter(mGalleryPageAdapter);
      viewPager.setCurrentItem(mPosition);
      viewPager.post(new Runnable()
      {
        @Override
        public void run()
        {
          onPageSelected(viewPager.getCurrentItem());
        }
      });
    }
  }

  @Override
  @StyleRes
  public int getThemeResourceId(@NonNull String theme)
  {
    if (ThemeUtils.isDefaultTheme(theme))
      return R.style.MwmTheme_FullScreenGalleryActivity;

    if (ThemeUtils.isNightTheme(theme))
      return R.style.MwmTheme_Night_FullScreenGalleryActivity;

    throw new IllegalArgumentException("Attempt to apply unsupported theme: " + theme);
  }

  @Override
  protected int getContentLayoutResId()
  {
    return R.layout.activity_full_screen_gallery;
  }

  @Override
  public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels)
  {
  }

  @Override
  public void onPageSelected(int position)
  {
    updateInformation(mGalleryPageAdapter.getImage(position));
  }

  @Override
  public void onPageScrollStateChanged(int state)
  {
  }

  private void readParameters()
  {
    Bundle extras = getIntent().getExtras();
    if (extras != null)
    {
      mImages = extras.getParcelableArrayList(EXTRA_IMAGES);
      mPosition = extras.getInt(EXTRA_POSITION);
    }
  }

  private void updateInformation(@NonNull Image image)
  {
    UiUtils.setTextAndHideIfEmpty(mDescription, image.getDescription());
    UiUtils.setTextAndHideIfEmpty(mUserName, image.getUserName());
    UiUtils.setTextAndHideIfEmpty(mSource, image.getSource());
    updateDate(image);
    updateUserAvatar(image);
    updateUserBlock();
  }

  private void updateDate(Image image)
  {
    if (image.getDate() != null)
    {
      Date date = new Date(image.getDate());
      mDate.setText(DateFormat.getMediumDateFormat(this).format(date));
      UiUtils.show(mDate);
    }
    else
    {
      UiUtils.hide(mDate);
    }
  }

  private void updateUserAvatar(Image image)
  {
    if (!TextUtils.isEmpty(image.getUserAvatar()))
    {
      UiUtils.show(mAvatar);
      Glide.with(this)
           .load(image.getUserAvatar())
           .asBitmap()
           .centerCrop()
           .into(new BitmapImageViewTarget(mAvatar)
           {
             @Override
             protected void setResource(Bitmap resource)
             {
               RoundedBitmapDrawable circularBitmapDrawable =
                   RoundedBitmapDrawableFactory.create(getResources(), resource);
               circularBitmapDrawable.setCircular(true);
               mAvatar.setImageDrawable(circularBitmapDrawable);
             }
           });
    }
    else
      UiUtils.hide(mAvatar);
  }

  private void updateUserBlock()
  {
    if (UiUtils.isHidden(mUserName)
        && UiUtils.isHidden(mSource)
        && UiUtils.isHidden(mDate)
        && UiUtils.isHidden(mAvatar))
    {
      UiUtils.hide(mUserBlock);
    }
    else
    {
      UiUtils.show(mUserBlock);
    }
  }
}