Skip to content

Commit 6a9b486

Browse files
committed
clear up some code
1 parent da6ae88 commit 6a9b486

File tree

2 files changed

+47
-84
lines changed

2 files changed

+47
-84
lines changed
Lines changed: 20 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.rumors.reactnativefirebaseui.storage;
22

33
import java.util.Map;
4+
import java.util.Map.Entry;
45
import java.util.HashMap;
56
import java.util.ArrayList;
67

@@ -23,7 +24,7 @@
2324

2425
public class ExtendedImageView extends ImageView {
2526
protected String mPath = null;
26-
protected Map<CornerType, Integer> mBorderRadii = null;
27+
protected Map<CornerType, Integer> mBorderRadii = new HashMap<CornerType, Integer>();
2728
protected ScaleType mScaleType;
2829

2930
protected ThemedReactContext mContext = null;
@@ -43,52 +44,32 @@ public void setScaleType(ScaleType scaleType) {
4344
}
4445

4546
public void setBorderRadius(int borderRadius, CornerType cornerType) {
46-
if (mBorderRadii == null ) {
47-
mBorderRadii = new HashMap<CornerType, Integer>();
48-
}
4947
mBorderRadii.put(cornerType, borderRadius);
5048
}
5149

5250
public void updateView() {
5351
StorageReference storageReference = FirebaseStorage.getInstance().getReference(mPath);
5452
FirebaseImageLoader imageLoader = new FirebaseImageLoader();
5553

56-
if (mBorderRadii != null) {
57-
ArrayList<Transformation> transformations = new ArrayList<>();
58-
for (CornerType cornerType : mBorderRadii.keySet()) {
59-
transformations.add(new RoundedCornersTransformation(mContext, mBorderRadii.get(cornerType), 0, cornerType));
60-
}
61-
Transformation[] transformationsArray;
62-
63-
if (mScaleType == ScaleType.CENTER_CROP) {
64-
transformations.add(0, new CenterCrop(mContext));
65-
transformationsArray = transformations.toArray(new Transformation[transformations.size()]);
66-
67-
Glide.with(mContext).using(imageLoader)
68-
.load(storageReference)
69-
.bitmapTransform(transformationsArray)
70-
.into(this);
71-
} else {
72-
transformations.add(0, new FitCenter(mContext));
73-
transformationsArray = transformations.toArray(new Transformation[transformations.size()]);
74-
75-
Glide.with(mContext).using(imageLoader)
76-
.load(storageReference)
77-
.bitmapTransform(transformationsArray)
78-
.into(this);
79-
}
54+
ArrayList<Transformation> transformations = new ArrayList<Transformation>(1 + mBorderRadii.size());
55+
56+
if (mScaleType == ScaleType.CENTER_CROP) {
57+
transformations.add(new CenterCrop(mContext));
8058
} else {
81-
if (mScaleType == ScaleType.CENTER_CROP) {
82-
Glide.with(mContext).using(imageLoader)
83-
.load(storageReference)
84-
.centerCrop()
85-
.into(this);
86-
} else {
87-
Glide.with(mContext).using(imageLoader)
88-
.load(storageReference)
89-
.fitCenter()
90-
.into(this);
91-
}
59+
transformations.add(new FitCenter(mContext));
60+
}
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));
9266
}
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);
9374
}
9475
}
Lines changed: 27 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,30 @@
11
package 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+
48
import com.github.chrisbanes.photoview.PhotoView;
59
import android.widget.ImageView.ScaleType;
610

11+
import com.facebook.react.uimanager.ThemedReactContext;
712
import com.firebase.ui.storage.images.FirebaseImageLoader;
813
import com.google.firebase.storage.StorageReference;
914
import com.google.firebase.storage.FirebaseStorage;
1015
import com.bumptech.glide.Glide;
16+
import com.bumptech.glide.load.Transformation;
1117
import com.bumptech.glide.load.resource.bitmap.FitCenter;
1218
import 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

2021
import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
2122
import jp.wasabeef.glide.transformations.RoundedCornersTransformation.CornerType;
2223

24+
2325
public 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

Comments
 (0)