11package io .rumors .reactnativefirebaseui .storage ;
22
3- import com .bumptech .glide .load .Transformation ;
3+ import java .util .Map ;
4+ import java .util .Map .Entry ;
5+ import java .util .HashMap ;
6+ import java .util .ArrayList ;
7+
48import com .github .chrisbanes .photoview .PhotoView ;
59import android .widget .ImageView .ScaleType ;
610
11+ import com .facebook .react .uimanager .ThemedReactContext ;
712import com .firebase .ui .storage .images .FirebaseImageLoader ;
813import com .google .firebase .storage .StorageReference ;
914import com .google .firebase .storage .FirebaseStorage ;
1015import com .bumptech .glide .Glide ;
16+ import com .bumptech .glide .load .Transformation ;
1117import com .bumptech .glide .load .resource .bitmap .FitCenter ;
1218import com .bumptech .glide .load .resource .bitmap .CenterCrop ;
1319
14- import com .facebook .react .uimanager .ThemedReactContext ;
15-
16- import java .util .ArrayList ;
17- import java .util .HashMap ;
18- import java .util .Map ;
1920
2021import jp .wasabeef .glide .transformations .RoundedCornersTransformation ;
2122import jp .wasabeef .glide .transformations .RoundedCornersTransformation .CornerType ;
2223
24+
2325public class ExtendedPhotoView extends PhotoView {
2426 protected String mPath = null ;
25- protected Map <CornerType , Integer > mBorderRadii = null ;
27+ protected Map <CornerType , Integer > mBorderRadii = new HashMap < CornerType , Integer >() ;
2628 protected ScaleType mScaleType ;
2729
2830 protected ThemedReactContext mContext = null ;
@@ -42,52 +44,32 @@ public void setScaleType(ScaleType scaleType) {
4244 }
4345
4446 public void setBorderRadius (int borderRadius , CornerType cornerType ) {
45- if (mBorderRadii == null ) {
46- mBorderRadii = new HashMap <CornerType , Integer >();
47- }
4847 mBorderRadii .put (cornerType , borderRadius );
4948 }
5049
5150 public void updateView () {
5251 StorageReference storageReference = FirebaseStorage .getInstance ().getReference (mPath );
5352 FirebaseImageLoader imageLoader = new FirebaseImageLoader ();
5453
55- if (mBorderRadii != null ) {
56- ArrayList <Transformation > transformations = new ArrayList <>();
57- for (CornerType cornerType : mBorderRadii .keySet ()) {
58- transformations .add (new RoundedCornersTransformation (mContext , mBorderRadii .get (cornerType ), 0 , cornerType ));
59- }
60- Transformation [] transformationsArray ;
61-
62- if (mScaleType == ScaleType .CENTER_CROP ) {
63- transformations .add (0 , new CenterCrop (mContext ));
64- transformationsArray = transformations .toArray (new Transformation [transformations .size ()]);
65-
66- Glide .with (mContext ).using (imageLoader )
67- .load (storageReference )
68- .bitmapTransform (transformationsArray )
69- .into (this );
70- } else {
71- transformations .add (0 , new FitCenter (mContext ));
72- transformationsArray = transformations .toArray (new Transformation [transformations .size ()]);
73-
74- Glide .with (mContext ).using (imageLoader )
75- .load (storageReference )
76- .bitmapTransform (transformationsArray )
77- .into (this );
78- }
54+ ArrayList <Transformation > transformations = new ArrayList <Transformation >(1 + mBorderRadii .size ());
55+
56+ if (mScaleType == ScaleType .CENTER_CROP ) {
57+ transformations .add (new CenterCrop (mContext ));
7958 } else {
80- if (mScaleType == ScaleType .CENTER_CROP ) {
81- Glide .with (mContext ).using (imageLoader )
82- .load (storageReference )
83- .centerCrop ()
84- .into (this );
85- } else {
86- Glide .with (mContext ).using (imageLoader )
87- .load (storageReference )
88- .fitCenter ()
89- .into (this );
90- }
59+ transformations .add (new FitCenter (mContext ));
9160 }
61+
62+ for (Entry <CornerType , Integer > entry : mBorderRadii .entrySet ()) {
63+ CornerType cornerType = entry .getKey ();
64+ Integer radius = entry .getValue ();
65+ transformations .add (new RoundedCornersTransformation (mContext , radius , 0 , cornerType ));
66+ }
67+
68+ Transformation [] transformationsArray = transformations .toArray (new Transformation [transformations .size ()]);
69+
70+ Glide .with (mContext ).using (imageLoader )
71+ .load (storageReference )
72+ .bitmapTransform (transformationsArray )
73+ .into (this );
9274 }
9375}
0 commit comments