Kaynağa Gözat

fix class imports

Augusto 6 yıl önce
ebeveyn
işleme
298a4de4f7

+ 35
- 49
android/src/main/java/com/RNFetchBlob/RNFetchBlob.java Dosyayı Görüntüle

@@ -7,7 +7,6 @@ import android.content.pm.PackageManager;
7 7
 import android.net.Uri;
8 8
 import android.os.Build;
9 9
 import android.support.v4.content.FileProvider;
10
-import android.util.SparseArray;
11 10
 
12 11
 import com.facebook.react.bridge.ActivityEventListener;
13 12
 import com.facebook.react.bridge.Callback;
@@ -24,8 +23,6 @@ import com.facebook.react.bridge.WritableMap;
24 23
 import com.facebook.react.modules.network.ForwardingCookieHandler;
25 24
 import com.facebook.react.modules.network.CookieJarContainer;
26 25
 import com.facebook.react.modules.network.OkHttpClientProvider;
27
-import com.squareup.okhttp.OkHttpClient;
28
-
29 26
 import okhttp3.OkHttpClient;
30 27
 import okhttp3.JavaNetCookieJar;
31 28
 
@@ -41,23 +38,26 @@ import static com.RNFetchBlob.RNFetchBlobConst.GET_CONTENT_INTENT;
41 38
 
42 39
 public class RNFetchBlob extends ReactContextBaseJavaModule {
43 40
 
41
+    // Cookies
42
+    private final ForwardingCookieHandler mCookieHandler;
43
+    private final CookieJarContainer mCookieJarContainer;
44 44
     private final OkHttpClient mClient;
45 45
 
46 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 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 54
     public RNFetchBlob(ReactApplicationContext reactContext) {
55 55
 
56 56
         super(reactContext);
57 57
 
58 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 61
         mCookieJarContainer.setCookieJar(new JavaNetCookieJar(mCookieHandler));
62 62
 
63 63
         RCTContext = reactContext;
@@ -89,23 +89,14 @@ public class RNFetchBlob extends ReactContextBaseJavaModule {
89 89
     }
90 90
 
91 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 93
         threadPool.execute(new Runnable() {
94 94
             @Override
95 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 102
     @ReactMethod
@@ -156,10 +147,21 @@ public class RNFetchBlob extends ReactContextBaseJavaModule {
156 147
             };
157 148
             RCTContext.addLifecycleEventListener(listener);
158 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 165
     @ReactMethod
164 166
     public void writeArrayChunk(final String streamId, final ReadableArray dataArray, final Callback callback) {
165 167
         RNFetchBlobFS.writeArrayChunk(streamId, dataArray, callback);
@@ -171,8 +173,8 @@ public class RNFetchBlob extends ReactContextBaseJavaModule {
171 173
     }
172 174
 
173 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 180
     @ReactMethod
@@ -188,6 +190,7 @@ public class RNFetchBlob extends ReactContextBaseJavaModule {
188 190
                 RNFetchBlobFS.cp(path, dest, callback);
189 191
             }
190 192
         });
193
+
191 194
     }
192 195
 
193 196
     @ReactMethod
@@ -196,8 +199,8 @@ public class RNFetchBlob extends ReactContextBaseJavaModule {
196 199
     }
197 200
 
198 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 206
     @ReactMethod
@@ -248,6 +251,7 @@ public class RNFetchBlob extends ReactContextBaseJavaModule {
248 251
                 RNFetchBlobFS.writeFile(path, encoding, data, append, promise);
249 252
             }
250 253
         });
254
+
251 255
     }
252 256
 
253 257
     @ReactMethod
@@ -282,24 +286,15 @@ public class RNFetchBlob extends ReactContextBaseJavaModule {
282 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 294
      * @param path Stream file path
299 295
      * @param encoding Stream encoding, should be one of `base64`, `ascii`, and `utf8`
300 296
      * @param bufferSize Stream buffer size, default to 4096 or 4095(base64).
301 297
      */
302
-    @ReactMethod
303 298
     public void readStream(final String path, final String encoding, final int bufferSize, final int tick, final String streamId) {
304 299
         final ReactApplicationContext ctx = this.getReactApplicationContext();
305 300
         fsThreadPool.execute(new Runnable() {
@@ -373,10 +368,10 @@ public class RNFetchBlob extends ReactContextBaseJavaModule {
373 368
 
374 369
     @ReactMethod
375 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 372
         String path = RNFetchBlobFS.normalizePath(config.getString("path"));
378 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 375
             return;
381 376
         }
382 377
         try {
@@ -393,18 +388,9 @@ public class RNFetchBlob extends ReactContextBaseJavaModule {
393 388
             promise.resolve(null);
394 389
         }
395 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
+}