11package io .rumors .reactnativefirebaseui .storage ;
22
3- import java .util .Map ;
4- import java .util .Map .Entry ;
5- import java .util .HashMap ;
6- import java .util .ArrayList ;
7-
83import javax .annotation .Nullable ;
94
105import android .widget .ImageView ;
11- import android .widget .ImageView .ScaleType ;
126import android .graphics .drawable .Drawable ;
137
148import com .facebook .react .uimanager .ThemedReactContext ;
159import com .facebook .react .views .imagehelper .ResourceDrawableIdHelper ;
16- import com .firebase .ui .storage .images .FirebaseImageLoader ;
1710import com .google .firebase .storage .StorageReference ;
1811import com .google .firebase .storage .FirebaseStorage ;
1912import com .bumptech .glide .Glide ;
20- import com .bumptech .glide .load .Transformation ;
21- import com .bumptech .glide .load .resource .bitmap .FitCenter ;
22- import com .bumptech .glide .load .resource .bitmap .CenterCrop ;
23- import com .bumptech .glide .load .MultiTransformation ;
2413import com .bumptech .glide .signature .MediaStoreSignature ;
25- import com .bumptech .glide .request .RequestOptions ;
26- import static com .bumptech .glide .request .RequestOptions .bitmapTransform ;
27-
28- import jp .wasabeef .glide .transformations .RoundedCornersTransformation ;
29- import jp .wasabeef .glide .transformations .RoundedCornersTransformation .CornerType ;
30-
3114
3215public class ExtendedImageView extends ImageView {
3316 protected String mPath = null ;
3417 protected @ Nullable Drawable mDefaultImageDrawable ;
35- protected Map <CornerType , Integer > mBorderRadii = new HashMap <CornerType , Integer >();
36- protected ScaleType mScaleType ;
3718 protected long mTimestamp = 0 ;
3819
3920 protected ThemedReactContext mContext = null ;
@@ -55,78 +36,12 @@ public void setTimestamp(long timestamp) {
5536 mTimestamp = timestamp ;
5637 }
5738
58- @ Override
59- public void setScaleType (ScaleType scaleType ) {
60- mScaleType = scaleType ;
61- }
62-
63- public void setBorderRadius (int borderRadius , CornerType cornerType ) {
64- mBorderRadii .put (cornerType , borderRadius );
65- }
66-
67- static Integer getCommonBorderRadii (Map <CornerType , Integer > borderRadii ) {
68- int borderRadiiCount = 0 ;
69- Integer borderRadius = 0 ;
70- for (Entry <CornerType , Integer > entry : borderRadii .entrySet ()) {
71- CornerType cornerType = entry .getKey ();
72- Integer radius = entry .getValue ();
73- if (borderRadiiCount == 0 ) {
74- borderRadius = radius ;
75- } else if (radius != borderRadius ) {
76- return -1 ; // not the same
77- }
78- borderRadiiCount += (cornerType == RoundedCornersTransformation .CornerType .ALL ) ? 4 : 1 ;
79- }
80- return ((borderRadiiCount == 0 ) || (borderRadiiCount >= 4 )) ? borderRadius : -1 ;
81- }
82-
8339 public void updateView () {
8440 StorageReference storageReference = FirebaseStorage .getInstance ().getReference (mPath );
85- FirebaseImageLoader imageLoader = new FirebaseImageLoader ();
86-
87- // When the border-radii are not all the same, apply the
88- // rounded corner transformation directly on top of the
89- // scaled bitmap.
90- RequestOptions transform ;
91- if (ExtendedImageView .getCommonBorderRadii (mBorderRadii ) < 0 ) {
92- ArrayList <Transformation > transformations = new ArrayList <Transformation >(1 + mBorderRadii .size ());
93-
94- if (mScaleType == ScaleType .CENTER_CROP ) {
95- transformations .add (new CenterCrop ());
96- } else {
97- transformations .add (new FitCenter ());
98- }
99-
100- for (Entry <CornerType , Integer > entry : mBorderRadii .entrySet ()) {
101- CornerType cornerType = entry .getKey ();
102- Integer radius = entry .getValue ();
103- transformations .add (new RoundedCornersTransformation (radius , 0 , cornerType ));
104- }
105-
106- Transformation [] transformationsArray = transformations .toArray (new Transformation [transformations .size ()]);
107-
108- MultiTransformation multi = new MultiTransformation <>(transformationsArray );
109- transform = bitmapTransform (multi );
110- }
111-
112- // When all border-radii are the same (or none are set)
113- // then let the ImageView apply the scale-type. This causes the
114- // underlying BitmapDrawable to use the original bitmap and makes
115- // it possible to do shared element transitions on this view.
116- else {
117- transform = null ;
118- super .setScaleType (mScaleType );
119- }
120-
121- GlideRequest request = GlideApp .with (mContext )
41+ GlideApp .with (mContext )
12242 .load (storageReference )
123- .placeholder (mDefaultImageDrawable );
124- if (transform != null ) {
125- request = request .apply (transform );
126- } else {
127- request = request .dontTransform ();
128- }
129- request
43+ .placeholder (mDefaultImageDrawable )
44+ .dontTransform ()
13045 //(String mimeType, long dateModified, int orientation)
13146 .signature (new MediaStoreSignature ("" , mTimestamp , 0 ))
13247 .into (this );
0 commit comments