Parcourir la source

fix class imports

Augusto il y a 6 ans
Parent
révision
298a4de4f7
1 fichiers modifiés avec 35 ajouts et 49 suppressions
  1. 35
    49
      android/src/main/java/com/RNFetchBlob/RNFetchBlob.java

+ 35
- 49
android/src/main/java/com/RNFetchBlob/RNFetchBlob.java Voir le fichier

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