Skip to content

Commit 7040d76

Browse files
committed
more fixes and refactoring - fixed unnecessary imports, duplications, renamed modules to match web api, linting issues, fixed several crashes
1 parent 2d680c3 commit 7040d76

13 files changed

+785
-783
lines changed

.babelrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
22
"presets": ["react-native"]
3-
}
3+
}

android/src/main/java/io/fullstack/firestack/FirestackAuth.java

+591-596
Large diffs are not rendered by default.

android/src/main/java/io/fullstack/firestack/FirestackStorage.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,9 @@ public void onSuccess(Uri uri) {
9696
res.putString("bucket", storageRef.getBucket());
9797
res.putString("fullPath", uri.toString());
9898
res.putString("path", uri.getPath());
99+
res.putString("url", uri.toString());
99100

100-
storageRef.getMetadata()
101+
fileRef.getMetadata()
101102
.addOnSuccessListener(new OnSuccessListener<StorageMetadata>() {
102103
@Override
103104
public void onSuccess(final StorageMetadata storageMetadata) {
@@ -230,9 +231,9 @@ public void getRealPathFromURI(final String uri, final Callback callback) {
230231
Cursor cursor = context.getContentResolver().query(Uri.parse(uri), proj, null, null, null);
231232
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
232233
cursor.moveToFirst();
233-
String path = cursor.getString(column_index);
234+
String path = cursor.getString(column_index);
234235
cursor.close();
235-
236+
236237
callback.invoke(null, path);
237238
} catch (Exception ex) {
238239
ex.printStackTrace();

android/src/main/java/io/fullstack/firestack/FirestackUtils.java

+117-113
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
public class FirestackUtils {
2424
private static final String TAG = "FirestackUtils";
2525

26-
// TODO NOTE
26+
// TODO NOTE
2727
public static void todoNote(final String tag, final String name, final Callback callback) {
2828
Log.e(tag, "The method " + name + " has not yet been implemented.");
2929
Log.e(tag, "Feel free to contribute to finish the method in the source.");
@@ -34,11 +34,11 @@ public static void todoNote(final String tag, final String name, final Callback
3434
}
3535

3636
/**
37-
* send a JS event
38-
**/
37+
* send a JS event
38+
**/
3939
public static void sendEvent(final ReactContext context,
40-
final String eventName,
41-
final WritableMap params) {
40+
final String eventName,
41+
final WritableMap params) {
4242
if (context.hasActiveCatalystInstance()) {
4343
context
4444
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
@@ -49,57 +49,61 @@ public static void sendEvent(final ReactContext context,
4949
}
5050

5151
// snapshot
52-
public static WritableMap dataSnapshotToMap(String name,
53-
String path,
54-
DataSnapshot dataSnapshot) {
55-
WritableMap data = Arguments.createMap();
56-
57-
data.putString("key", dataSnapshot.getKey());
58-
data.putBoolean("exists", dataSnapshot.exists());
59-
data.putBoolean("hasChildren", dataSnapshot.hasChildren());
60-
61-
data.putDouble("childrenCount", dataSnapshot.getChildrenCount());
62-
if (!dataSnapshot.hasChildren()) {
63-
Object value = dataSnapshot.getValue();
64-
String type = value!=null ? value.getClass().getName() : "";
65-
switch (type) {
66-
case "java.lang.Boolean":
67-
data.putBoolean("value", (Boolean)value);
68-
break;
69-
case "java.lang.Long":
70-
Long longVal = (Long) value;
71-
data.putDouble("value", (double)longVal);
72-
break;
73-
case "java.lang.Double":
74-
data.putDouble("value", (Double) value);
75-
break;
76-
case "java.lang.String":
77-
data.putString("value",(String) value);
78-
break;
79-
default:
80-
data.putString("value", null);
81-
}
82-
} else{
83-
WritableMap valueMap = FirestackUtils.castSnapshotValue(dataSnapshot);
84-
data.putMap("value", valueMap);
52+
public static WritableMap dataSnapshotToMap(
53+
String name,
54+
String path,
55+
String modifiersString,
56+
DataSnapshot dataSnapshot
57+
) {
58+
WritableMap data = Arguments.createMap();
59+
60+
data.putString("key", dataSnapshot.getKey());
61+
data.putBoolean("exists", dataSnapshot.exists());
62+
data.putBoolean("hasChildren", dataSnapshot.hasChildren());
63+
64+
data.putDouble("childrenCount", dataSnapshot.getChildrenCount());
65+
if (!dataSnapshot.hasChildren()) {
66+
Object value = dataSnapshot.getValue();
67+
String type = value != null ? value.getClass().getName() : "";
68+
switch (type) {
69+
case "java.lang.Boolean":
70+
data.putBoolean("value", (Boolean) value);
71+
break;
72+
case "java.lang.Long":
73+
Long longVal = (Long) value;
74+
data.putDouble("value", (double) longVal);
75+
break;
76+
case "java.lang.Double":
77+
data.putDouble("value", (Double) value);
78+
break;
79+
case "java.lang.String":
80+
data.putString("value", (String) value);
81+
break;
82+
default:
83+
data.putString("value", null);
8584
}
85+
} else {
86+
WritableMap valueMap = FirestackUtils.castSnapshotValue(dataSnapshot);
87+
data.putMap("value", valueMap);
88+
}
8689

87-
// Child keys
88-
WritableArray childKeys = FirestackUtils.getChildKeys(dataSnapshot);
89-
data.putArray("childKeys", childKeys);
90+
// Child keys
91+
WritableArray childKeys = FirestackUtils.getChildKeys(dataSnapshot);
92+
data.putArray("childKeys", childKeys);
9093

91-
Object priority = dataSnapshot.getPriority();
92-
if (priority == null) {
93-
data.putString("priority", null);
94-
} else {
95-
data.putString("priority", priority.toString());
96-
}
94+
Object priority = dataSnapshot.getPriority();
95+
if (priority == null) {
96+
data.putString("priority", null);
97+
} else {
98+
data.putString("priority", priority.toString());
99+
}
97100

98-
WritableMap eventMap = Arguments.createMap();
99-
eventMap.putString("eventName", name);
100-
eventMap.putMap("snapshot", data);
101-
eventMap.putString("path", path);
102-
return eventMap;
101+
WritableMap eventMap = Arguments.createMap();
102+
eventMap.putString("eventName", name);
103+
eventMap.putMap("snapshot", data);
104+
eventMap.putString("path", path);
105+
eventMap.putString("modifiersString", modifiersString);
106+
return eventMap;
103107
}
104108

105109
public static <Any> Any castSnapshotValue(DataSnapshot snapshot) {
@@ -113,7 +117,7 @@ public static <Any> Any castSnapshotValue(DataSnapshot snapshot) {
113117
break;
114118
case "java.lang.Long":
115119
Long longVal = (Long) castedChild;
116-
data.putDouble(child.getKey(), (double)longVal);
120+
data.putDouble(child.getKey(), (double) longVal);
117121
break;
118122
case "java.lang.Double":
119123
data.putDouble(child.getKey(), (Double) castedChild);
@@ -135,15 +139,15 @@ public static <Any> Any castSnapshotValue(DataSnapshot snapshot) {
135139
String type = snapshot.getValue().getClass().getName();
136140
switch (type) {
137141
case "java.lang.Boolean":
138-
return (Any)(snapshot.getValue());
142+
return (Any) (snapshot.getValue());
139143
case "java.lang.Long":
140-
return (Any)(snapshot.getValue());
144+
return (Any) (snapshot.getValue());
141145
case "java.lang.Double":
142-
return (Any)(snapshot.getValue());
146+
return (Any) (snapshot.getValue());
143147
case "java.lang.String":
144-
return (Any)(snapshot.getValue());
148+
return (Any) (snapshot.getValue());
145149
default:
146-
Log.w(TAG, "Invalid type: "+type);
150+
Log.w(TAG, "Invalid type: " + type);
147151
return (Any) null;
148152
}
149153
}
@@ -164,65 +168,65 @@ public static WritableArray getChildKeys(DataSnapshot snapshot) {
164168
}
165169

166170
public static Map<String, Object> recursivelyDeconstructReadableMap(ReadableMap readableMap) {
167-
ReadableMapKeySetIterator iterator = readableMap.keySetIterator();
168-
Map<String, Object> deconstructedMap = new HashMap<>();
169-
while (iterator.hasNextKey()) {
170-
String key = iterator.nextKey();
171-
ReadableType type = readableMap.getType(key);
172-
switch (type) {
173-
case Null:
174-
deconstructedMap.put(key, null);
175-
break;
176-
case Boolean:
177-
deconstructedMap.put(key, readableMap.getBoolean(key));
178-
break;
179-
case Number:
180-
deconstructedMap.put(key, readableMap.getDouble(key));
181-
break;
182-
case String:
183-
deconstructedMap.put(key, readableMap.getString(key));
184-
break;
185-
case Map:
186-
deconstructedMap.put(key, FirestackUtils.recursivelyDeconstructReadableMap(readableMap.getMap(key)));
187-
break;
188-
case Array:
189-
deconstructedMap.put(key, FirestackUtils.recursivelyDeconstructReadableArray(readableMap.getArray(key)));
190-
break;
191-
default:
192-
throw new IllegalArgumentException("Could not convert object with key: " + key + ".");
193-
}
194-
171+
ReadableMapKeySetIterator iterator = readableMap.keySetIterator();
172+
Map<String, Object> deconstructedMap = new HashMap<>();
173+
while (iterator.hasNextKey()) {
174+
String key = iterator.nextKey();
175+
ReadableType type = readableMap.getType(key);
176+
switch (type) {
177+
case Null:
178+
deconstructedMap.put(key, null);
179+
break;
180+
case Boolean:
181+
deconstructedMap.put(key, readableMap.getBoolean(key));
182+
break;
183+
case Number:
184+
deconstructedMap.put(key, readableMap.getDouble(key));
185+
break;
186+
case String:
187+
deconstructedMap.put(key, readableMap.getString(key));
188+
break;
189+
case Map:
190+
deconstructedMap.put(key, FirestackUtils.recursivelyDeconstructReadableMap(readableMap.getMap(key)));
191+
break;
192+
case Array:
193+
deconstructedMap.put(key, FirestackUtils.recursivelyDeconstructReadableArray(readableMap.getArray(key)));
194+
break;
195+
default:
196+
throw new IllegalArgumentException("Could not convert object with key: " + key + ".");
195197
}
196-
return deconstructedMap;
198+
199+
}
200+
return deconstructedMap;
197201
}
198202

199203
public static List<Object> recursivelyDeconstructReadableArray(ReadableArray readableArray) {
200-
List<Object> deconstructedList = new ArrayList<>(readableArray.size());
201-
for (int i = 0; i < readableArray.size(); i++) {
202-
ReadableType indexType = readableArray.getType(i);
203-
switch(indexType) {
204-
case Null:
205-
deconstructedList.add(i, null);
206-
break;
207-
case Boolean:
208-
deconstructedList.add(i, readableArray.getBoolean(i));
209-
break;
210-
case Number:
211-
deconstructedList.add(i, readableArray.getDouble(i));
212-
break;
213-
case String:
214-
deconstructedList.add(i, readableArray.getString(i));
215-
break;
216-
case Map:
217-
deconstructedList.add(i, FirestackUtils.recursivelyDeconstructReadableMap(readableArray.getMap(i)));
218-
break;
219-
case Array:
220-
deconstructedList.add(i, FirestackUtils.recursivelyDeconstructReadableArray(readableArray.getArray(i)));
221-
break;
222-
default:
223-
throw new IllegalArgumentException("Could not convert object at index " + i + ".");
224-
}
204+
List<Object> deconstructedList = new ArrayList<>(readableArray.size());
205+
for (int i = 0; i < readableArray.size(); i++) {
206+
ReadableType indexType = readableArray.getType(i);
207+
switch (indexType) {
208+
case Null:
209+
deconstructedList.add(i, null);
210+
break;
211+
case Boolean:
212+
deconstructedList.add(i, readableArray.getBoolean(i));
213+
break;
214+
case Number:
215+
deconstructedList.add(i, readableArray.getDouble(i));
216+
break;
217+
case String:
218+
deconstructedList.add(i, readableArray.getString(i));
219+
break;
220+
case Map:
221+
deconstructedList.add(i, FirestackUtils.recursivelyDeconstructReadableMap(readableArray.getMap(i)));
222+
break;
223+
case Array:
224+
deconstructedList.add(i, FirestackUtils.recursivelyDeconstructReadableArray(readableArray.getArray(i)));
225+
break;
226+
default:
227+
throw new IllegalArgumentException("Could not convert object at index " + i + ".");
225228
}
226-
return deconstructedList;
229+
}
230+
return deconstructedList;
227231
}
228232
}

0 commit comments

Comments
 (0)