Skip to content

Commit ed5c539

Browse files
committed
# Conflicts: # lib/modules/storage/index.js # package.json
2 parents 9435b1b + 7630c91 commit ed5c539

File tree

13 files changed

+500
-603
lines changed

13 files changed

+500
-603
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ public static void todoNote(final String tag, final String name, final Callback
3838
* send a JS event
3939
**/
4040
public static void sendEvent(final ReactContext context, final String eventName, final WritableMap params) {
41-
if (context != null && context.hasActiveCatalystInstance()) {
41+
if (context != null) {
4242
context
4343
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
4444
.emit(eventName, params);
4545
} else {
46-
Log.d(TAG, "Waiting for CatalystInstance before sending event");
46+
Log.d(TAG, "Missing context - cannot send event!");
4747
}
4848
}
4949

android/src/main/java/io/fullstack/firestack/database/FirestackDatabase.java

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ public void onComplete(DatabaseError error, DatabaseReference ref) {
159159
} else {
160160
Log.d(TAG, "No value passed to push: " + newPath);
161161
WritableMap res = Arguments.createMap();
162-
res.putString("result", "success");
162+
res.putString("status", "success");
163163
res.putString("ref", newPath);
164164
callback.invoke(null, res);
165165
}
@@ -180,7 +180,7 @@ public void on(final String path,
180180
}
181181

182182
WritableMap resp = Arguments.createMap();
183-
resp.putString("result", "success");
183+
resp.putString("status", "success");
184184
resp.putString("handle", path);
185185
callback.invoke(null, resp);
186186
}
@@ -205,13 +205,31 @@ public void onOnce(final String path,
205205
public void off(
206206
final String path,
207207
final String modifiersString,
208-
@Deprecated final String name,
208+
final String name,
209209
final Callback callback) {
210-
this.removeDBHandle(path, modifiersString);
210+
211+
String key = this.getDBListenerKey(path, modifiersString);
212+
FirestackDatabaseReference r = mDBListeners.get(key);
213+
214+
if (r != null) {
215+
if (name == null || "".equals(name)) {
216+
r.cleanup();
217+
mDBListeners.remove(key);
218+
} else {
219+
//TODO: Remove individual listeners as per iOS code
220+
//1) Remove event handler
221+
//2) If no more listeners, remove from listeners map
222+
r.cleanup();
223+
mDBListeners.remove(key);
224+
}
225+
}
226+
211227
Log.d(TAG, "Removed listener " + path + "/" + modifiersString);
212228
WritableMap resp = Arguments.createMap();
213229
resp.putString("handle", path);
214-
resp.putString("result", "success");
230+
resp.putString("status", "success");
231+
resp.putString("modifiersString", modifiersString);
232+
//TODO: Remaining listeners
215233
callback.invoke(null, resp);
216234
}
217235

@@ -268,6 +286,16 @@ public void onComplete(DatabaseError error, DatabaseReference ref) {
268286
});
269287
}
270288

289+
@ReactMethod
290+
public void goOnline() {
291+
mFirebaseDatabase.goOnline();
292+
}
293+
294+
@ReactMethod
295+
public void goOffline() {
296+
mFirebaseDatabase.goOffline();
297+
}
298+
271299
private void handleCallback(
272300
final String methodName,
273301
final Callback callback,
@@ -304,14 +332,4 @@ private FirestackDatabaseReference getDBHandle(final String path,
304332
private String getDBListenerKey(String path, String modifiersString) {
305333
return path + " | " + modifiersString;
306334
}
307-
308-
private void removeDBHandle(final String path, String modifiersString) {
309-
String key = this.getDBListenerKey(path, modifiersString);
310-
FirestackDatabaseReference r = mDBListeners.get(key);
311-
312-
if (r != null) {
313-
r.cleanup();
314-
mDBListeners.remove(key);
315-
}
316-
}
317335
}

android/src/main/java/io/fullstack/firestack/database/FirestackDatabaseReference.java

Lines changed: 61 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public void onCancelled(DatabaseError error) {
9292
Log.d(TAG, "Added ValueEventListener for path: " + mPath + " with modifiers: "+ mModifiersString);
9393
//this.setListeningTo(mPath, modifiersString, "value");
9494
} else {
95-
Log.w(TAG, "trying to add duplicate ValueEventListener for path: " + mPath + " with modifiers: "+ mModifiersString);
95+
Log.w(TAG, "Trying to add duplicate ValueEventListener for path: " + mPath + " with modifiers: "+ mModifiersString);
9696
}
9797
}
9898

@@ -197,27 +197,75 @@ private Query buildDatabaseQueryAtPathAndModifiers(final FirebaseDatabase fireba
197197
query = query.limitToFirst(limit);
198198
} else if (methStr.contains("equalTo")) {
199199
String value = strArr[1];
200-
String key = strArr.length >= 3 ? strArr[2] : null;
201-
if (key == null) {
202-
query = query.equalTo(value);
200+
String type = strArr[2];
201+
if ("number".equals(type)) {
202+
double doubleValue = Double.parseDouble(value);
203+
if (strArr.length > 3) {
204+
query = query.equalTo(doubleValue, strArr[3]);
205+
} else {
206+
query = query.equalTo(doubleValue);
207+
}
208+
} else if ("boolean".equals(type)) {
209+
boolean booleanValue = Boolean.parseBoolean(value);
210+
if (strArr.length > 3) {
211+
query = query.equalTo(booleanValue, strArr[3] );
212+
} else {
213+
query = query.equalTo(booleanValue);
214+
}
203215
} else {
204-
query = query.equalTo(value, key);
216+
if (strArr.length > 3) {
217+
query = query.equalTo(value, strArr[3]);
218+
} else {
219+
query = query.equalTo(value);
220+
}
205221
}
206222
} else if (methStr.contains("endAt")) {
207223
String value = strArr[1];
208-
String key = strArr.length >= 3 ? strArr[2] : null;
209-
if (key == null) {
210-
query = query.endAt(value);
224+
String type = strArr[2];
225+
if ("number".equals(type)) {
226+
double doubleValue = Double.parseDouble(value);
227+
if (strArr.length > 3) {
228+
query = query.endAt(doubleValue, strArr[3]);
229+
} else {
230+
query = query.endAt(doubleValue);
231+
}
232+
} else if ("boolean".equals(type)) {
233+
boolean booleanValue = Boolean.parseBoolean(value);
234+
if (strArr.length > 3) {
235+
query = query.endAt(booleanValue, strArr[3] );
236+
} else {
237+
query = query.endAt(booleanValue);
238+
}
211239
} else {
212-
query = query.endAt(value, key);
240+
if (strArr.length > 3) {
241+
query = query.endAt(value, strArr[3]);
242+
} else {
243+
query = query.endAt(value);
244+
}
213245
}
214246
} else if (methStr.contains("startAt")) {
215247
String value = strArr[1];
216-
String key = strArr.length >= 3 ? strArr[2] : null;
217-
if (key == null) {
218-
query = query.startAt(value);
248+
String type = strArr[2];
249+
if ("number".equals(type)) {
250+
double doubleValue = Double.parseDouble(value);
251+
if (strArr.length > 3) {
252+
query = query.startAt(doubleValue, strArr[3]);
253+
} else {
254+
query = query.startAt(doubleValue);
255+
}
256+
} else if ("boolean".equals(type)) {
257+
boolean booleanValue = Boolean.parseBoolean(value);
258+
if (strArr.length > 3) {
259+
query = query.startAt(booleanValue, strArr[3] );
260+
} else {
261+
query = query.startAt(booleanValue);
262+
}
219263
} else {
220-
query = query.startAt(value, key);
264+
if (strArr.length > 3) {
265+
query = query.startAt(value, strArr[3]);
266+
} else {
267+
query = query.startAt(value);
268+
}
221269
}
222270
}
223271
}

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

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,9 @@ public boolean isExternalStorageWritable() {
8585
}
8686

8787
@ReactMethod
88-
public void downloadFile(final String urlStr,
89-
final String fbPath,
88+
public void downloadFile(final String remotePath,
9089
final String localFile,
9190
final Callback callback) {
92-
Log.d(TAG, "downloadFile: " + urlStr + ", " + localFile);
9391
if (!isExternalStorageWritable()) {
9492
Log.w(TAG, "downloadFile failed: external storage not writable");
9593
WritableMap error = Arguments.createMap();
@@ -99,13 +97,9 @@ public void downloadFile(final String urlStr,
9997
callback.invoke(error);
10098
return;
10199
}
102-
FirebaseStorage storage = FirebaseStorage.getInstance();
103-
String storageBucket = storage.getApp().getOptions().getStorageBucket();
104-
String storageUrl = "gs://" + storageBucket;
105-
Log.d(TAG, "Storage url " + storageUrl + fbPath);
100+
Log.d(TAG, "downloadFile from remote path: " + remotePath);
106101

107-
StorageReference storageRef = storage.getReferenceFromUrl(storageUrl);
108-
StorageReference fileRef = storageRef.child(fbPath);
102+
StorageReference fileRef = FirebaseStorage.getInstance().getReference(remotePath);
109103

110104
fileRef.getStream(new StreamDownloadTask.StreamProcessor() {
111105
@Override
@@ -182,15 +176,10 @@ public void onFailure(@NonNull Exception exception) {
182176
}
183177

184178
@ReactMethod
185-
public void downloadUrl(final String javascriptStorageBucket,
186-
final String path,
179+
public void downloadUrl(final String remotePath,
187180
final Callback callback) {
188-
FirebaseStorage storage = FirebaseStorage.getInstance();
189-
String storageBucket = storage.getApp().getOptions().getStorageBucket();
190-
String storageUrl = "gs://" + storageBucket;
191-
Log.d(TAG, "Storage url " + storageUrl + path);
192-
final StorageReference storageRef = storage.getReferenceFromUrl(storageUrl);
193-
final StorageReference fileRef = storageRef.child(path);
181+
Log.d(TAG, "Download url for remote path: " + remotePath);
182+
final StorageReference fileRef = FirebaseStorage.getInstance().getReference(remotePath);
194183

195184
Task<Uri> downloadTask = fileRef.getDownloadUrl();
196185
downloadTask
@@ -200,7 +189,7 @@ public void onSuccess(Uri uri) {
200189
final WritableMap res = Arguments.createMap();
201190

202191
res.putString("status", "success");
203-
res.putString("bucket", storageRef.getBucket());
192+
res.putString("bucket", FirebaseStorage.getInstance().getApp().getOptions().getStorageBucket());
204193
res.putString("fullPath", uri.toString());
205194
res.putString("path", uri.getPath());
206195
res.putString("url", uri.toString());
@@ -256,12 +245,10 @@ private WritableMap getMetadataAsMap(StorageMetadata storageMetadata) {
256245

257246
// STORAGE
258247
@ReactMethod
259-
public void uploadFile(final String urlStr, final String name, final String filepath, final ReadableMap metadata, final Callback callback) {
260-
FirebaseStorage storage = FirebaseStorage.getInstance();
261-
StorageReference storageRef = storage.getReferenceFromUrl(urlStr);
262-
StorageReference fileRef = storageRef.child(name);
248+
public void uploadFile(final String remotePath, final String filepath, final ReadableMap metadata, final Callback callback) {
249+
StorageReference fileRef = FirebaseStorage.getInstance().getReference(remotePath);
263250

264-
Log.i(TAG, "From file: " + filepath + " to " + urlStr + " with name " + name);
251+
Log.i(TAG, "Upload file: " + filepath + " to " + remotePath);
265252

266253
try {
267254
Uri file;

ios/Firestack/FirestackDatabase.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,8 @@
1717

1818
}
1919

20-
@property (nonatomic) NSDictionary *_DBHandles;
21-
@property (nonatomic, weak) FIRDatabaseReference *ref;
20+
@property NSMutableDictionary *dbReferences;
2221

2322
@end
2423

25-
#endif
24+
#endif

0 commit comments

Comments
 (0)