Bladeren bron

fix class import

Augusto 6 jaren geleden
bovenliggende
commit
c66788ff23
1 gewijzigde bestanden met toevoegingen van 46 en 34 verwijderingen
  1. 46
    34
      android/src/main/java/com/RNFetchBlob/RNFetchBlob.java

+ 46
- 34
android/src/main/java/com/RNFetchBlob/RNFetchBlob.java Bestand weergeven

7
 import android.net.Uri;
7
 import android.net.Uri;
8
 import android.os.Build;
8
 import android.os.Build;
9
 import android.support.v4.content.FileProvider;
9
 import android.support.v4.content.FileProvider;
10
+import android.util.SparseArray;
10
 
11
 
11
 import com.facebook.react.bridge.ActivityEventListener;
12
 import com.facebook.react.bridge.ActivityEventListener;
12
 import com.facebook.react.bridge.Callback;
13
 import com.facebook.react.bridge.Callback;
38
 
39
 
39
 public class RNFetchBlob extends ReactContextBaseJavaModule {
40
 public class RNFetchBlob extends ReactContextBaseJavaModule {
40
 
41
 
41
-    // Cookies
42
-    private final ForwardingCookieHandler mCookieHandler;
43
-    private final CookieJarContainer mCookieJarContainer;
44
     private final OkHttpClient mClient;
42
     private final OkHttpClient mClient;
45
 
43
 
46
     static ReactApplicationContext RCTContext;
44
     static ReactApplicationContext RCTContext;
47
-    static LinkedBlockingQueue<Runnable> taskQueue = new LinkedBlockingQueue<>();
48
-    static ThreadPoolExecutor threadPool = new ThreadPoolExecutor(5, 10, 5000, TimeUnit.MILLISECONDS, taskQueue);
45
+    private static LinkedBlockingQueue<Runnable> taskQueue = new LinkedBlockingQueue<>();
46
+    private static ThreadPoolExecutor threadPool = new ThreadPoolExecutor(5, 10, 5000, TimeUnit.MILLISECONDS, taskQueue);
49
     static LinkedBlockingQueue<Runnable> fsTaskQueue = new LinkedBlockingQueue<>();
47
     static LinkedBlockingQueue<Runnable> fsTaskQueue = new LinkedBlockingQueue<>();
50
-    static ThreadPoolExecutor fsThreadPool = new ThreadPoolExecutor(2, 10, 5000, TimeUnit.MILLISECONDS, taskQueue);
51
-    static public boolean ActionViewVisible = false;
52
-    static HashMap<Integer, Promise> promiseTable = new HashMap<>();
48
+    private static ThreadPoolExecutor fsThreadPool = new ThreadPoolExecutor(2, 10, 5000, TimeUnit.MILLISECONDS, taskQueue);
49
+    private static boolean ActionViewVisible = false;
50
+    private static SparseArray<Promise> promiseTable = new SparseArray<>();
53
 
51
 
54
     public RNFetchBlob(ReactApplicationContext reactContext) {
52
     public RNFetchBlob(ReactApplicationContext reactContext) {
55
 
53
 
56
         super(reactContext);
54
         super(reactContext);
57
 
55
 
58
         mClient = OkHttpClientProvider.getOkHttpClient();
56
         mClient = OkHttpClientProvider.getOkHttpClient();
59
-        mCookieHandler = new ForwardingCookieHandler(reactContext);
60
-        mCookieJarContainer = (CookieJarContainer) mClient.cookieJar();
57
+        ForwardingCookieHandler mCookieHandler = new ForwardingCookieHandler(reactContext);
58
+        CookieJarContainer mCookieJarContainer = (CookieJarContainer) mClient.cookieJar();
61
         mCookieJarContainer.setCookieJar(new JavaNetCookieJar(mCookieHandler));
59
         mCookieJarContainer.setCookieJar(new JavaNetCookieJar(mCookieHandler));
62
 
60
 
63
         RCTContext = reactContext;
61
         RCTContext = reactContext;
89
     }
87
     }
90
 
88
 
91
     @ReactMethod
89
     @ReactMethod
92
-    public void createFile(final String path, final String content, final String encode, final Callback callback) {
90
+    public void createFile(final String path, final String content, final String encode, final Promise promise) {
93
         threadPool.execute(new Runnable() {
91
         threadPool.execute(new Runnable() {
94
             @Override
92
             @Override
95
             public void run() {
93
             public void run() {
96
-                RNFetchBlobFS.createFile(path, content, encode, callback);
94
+                RNFetchBlobFS.createFile(path, content, encode, promise);
97
             }
95
             }
98
         });
96
         });
97
+    }
99
 
98
 
99
+    @ReactMethod
100
+    public void createFileASCII(final String path, final ReadableArray dataArray, final Promise promise) {
101
+        threadPool.execute(new Runnable() {
102
+            @Override
103
+            public void run() {
104
+                RNFetchBlobFS.createFileASCII(path, dataArray, promise);
105
+            }
106
+        });
100
     }
107
     }
101
 
108
 
102
     @ReactMethod
109
     @ReactMethod
147
             };
154
             };
148
             RCTContext.addLifecycleEventListener(listener);
155
             RCTContext.addLifecycleEventListener(listener);
149
         } catch(Exception ex) {
156
         } catch(Exception ex) {
150
-            promise.reject(ex.getLocalizedMessage());
157
+            promise.reject("EUNSPECIFIED", ex.getLocalizedMessage());
151
         }
158
         }
152
     }
159
     }
153
 
160
 
154
-    @ReactMethod
155
-    public void createFileASCII(final String path, final ReadableArray dataArray, final Callback callback) {
156
-        threadPool.execute(new Runnable() {
157
-            @Override
158
-            public void run() {
159
-                RNFetchBlobFS.createFileASCII(path, dataArray, callback);
160
-            }
161
-        });
162
-
163
-    }
164
-
165
     @ReactMethod
161
     @ReactMethod
166
     public void writeArrayChunk(final String streamId, final ReadableArray dataArray, final Callback callback) {
162
     public void writeArrayChunk(final String streamId, final ReadableArray dataArray, final Callback callback) {
167
         RNFetchBlobFS.writeArrayChunk(streamId, dataArray, callback);
163
         RNFetchBlobFS.writeArrayChunk(streamId, dataArray, callback);
173
     }
169
     }
174
 
170
 
175
     @ReactMethod
171
     @ReactMethod
176
-    public void mkdir(String path, Callback callback) {
177
-        RNFetchBlobFS.mkdir(path, callback);
172
+    public void mkdir(String path, Promise promise) {
173
+        RNFetchBlobFS.mkdir(path, promise);
178
     }
174
     }
179
 
175
 
180
     @ReactMethod
176
     @ReactMethod
190
                 RNFetchBlobFS.cp(path, dest, callback);
186
                 RNFetchBlobFS.cp(path, dest, callback);
191
             }
187
             }
192
         });
188
         });
193
-
194
     }
189
     }
195
 
190
 
196
     @ReactMethod
191
     @ReactMethod
199
     }
194
     }
200
 
195
 
201
     @ReactMethod
196
     @ReactMethod
202
-    public void ls(String path, Callback callback) {
203
-        RNFetchBlobFS.ls(path, callback);
197
+    public void ls(String path, Promise promise) {
198
+        RNFetchBlobFS.ls(path, promise);
204
     }
199
     }
205
 
200
 
206
     @ReactMethod
201
     @ReactMethod
251
                 RNFetchBlobFS.writeFile(path, encoding, data, append, promise);
246
                 RNFetchBlobFS.writeFile(path, encoding, data, append, promise);
252
             }
247
             }
253
         });
248
         });
254
-
255
     }
249
     }
256
 
250
 
257
     @ReactMethod
251
     @ReactMethod
286
                 new RNFetchBlobFS(ctx).scanFile(p, m, callback);
280
                 new RNFetchBlobFS(ctx).scanFile(p, m, callback);
287
             }
281
             }
288
         });
282
         });
289
-
290
     }
283
     }
291
 
284
 
292
     @ReactMethod
285
     @ReactMethod
286
+    public void hash(final String path, final String algorithm, final Promise promise) {
287
+        threadPool.execute(new Runnable() {
288
+            @Override
289
+            public void run() {
290
+                RNFetchBlobFS.hash(path, algorithm, promise);
291
+            }
292
+        });
293
+    }
294
+
293
     /**
295
     /**
294
      * @param path Stream file path
296
      * @param path Stream file path
295
      * @param encoding Stream encoding, should be one of `base64`, `ascii`, and `utf8`
297
      * @param encoding Stream encoding, should be one of `base64`, `ascii`, and `utf8`
296
      * @param bufferSize Stream buffer size, default to 4096 or 4095(base64).
298
      * @param bufferSize Stream buffer size, default to 4096 or 4095(base64).
297
      */
299
      */
300
+    @ReactMethod
298
     public void readStream(final String path, final String encoding, final int bufferSize, final int tick, final String streamId) {
301
     public void readStream(final String path, final String encoding, final int bufferSize, final int tick, final String streamId) {
299
         final ReactApplicationContext ctx = this.getReactApplicationContext();
302
         final ReactApplicationContext ctx = this.getReactApplicationContext();
300
         fsThreadPool.execute(new Runnable() {
303
         fsThreadPool.execute(new Runnable() {
368
 
371
 
369
     @ReactMethod
372
     @ReactMethod
370
     public void addCompleteDownload (ReadableMap config, Promise promise) {
373
     public void addCompleteDownload (ReadableMap config, Promise promise) {
371
-        DownloadManager dm = (DownloadManager) RNFetchBlob.RCTContext.getSystemService(RNFetchBlob.RCTContext.DOWNLOAD_SERVICE);
374
+        DownloadManager dm = (DownloadManager) RCTContext.getSystemService(RCTContext.DOWNLOAD_SERVICE);
372
         String path = RNFetchBlobFS.normalizePath(config.getString("path"));
375
         String path = RNFetchBlobFS.normalizePath(config.getString("path"));
373
         if(path == null) {
376
         if(path == null) {
374
-            promise.reject("RNFetchblob.addCompleteDownload can not resolve URI:" + config.getString("path"), "RNFetchblob.addCompleteDownload can not resolve URI:" + path);
377
+            promise.reject("EINVAL", "RNFetchblob.addCompleteDownload can not resolve URI:" + config.getString("path"));
375
             return;
378
             return;
376
         }
379
         }
377
         try {
380
         try {
388
             promise.resolve(null);
391
             promise.resolve(null);
389
         }
392
         }
390
         catch(Exception ex) {
393
         catch(Exception ex) {
391
-            promise.reject("RNFetchblob.addCompleteDownload failed", ex.getStackTrace().toString());
394
+            promise.reject("EUNSPECIFIED", ex.getLocalizedMessage());
392
         }
395
         }
393
 
396
 
394
     }
397
     }
395
 
398
 
399
+    @ReactMethod
400
+    public void getSDCardDir(Promise promise) {
401
+        RNFetchBlobFS.getSDCardDir(promise);
402
+    }
403
+
404
+    @ReactMethod
405
+    public void getSDCardApplicationDir(Promise promise) {
406
+        RNFetchBlobFS.getSDCardApplicationDir(this.getReactApplicationContext(), promise);
407
+    }
396
 }
408
 }