Skip to content

Commit 298a4de

Browse files
author
Augusto
committed
fix class imports
1 parent a88b59f commit 298a4de

File tree

1 file changed

+35
-49
lines changed

1 file changed

+35
-49
lines changed

android/src/main/java/com/RNFetchBlob/RNFetchBlob.java

Lines changed: 35 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import android.net.Uri;
88
import android.os.Build;
99
import android.support.v4.content.FileProvider;
10-
import android.util.SparseArray;
1110

1211
import com.facebook.react.bridge.ActivityEventListener;
1312
import com.facebook.react.bridge.Callback;
@@ -24,8 +23,6 @@
2423
import com.facebook.react.modules.network.ForwardingCookieHandler;
2524
import com.facebook.react.modules.network.CookieJarContainer;
2625
import com.facebook.react.modules.network.OkHttpClientProvider;
27-
import com.squareup.okhttp.OkHttpClient;
28-
2926
import okhttp3.OkHttpClient;
3027
import okhttp3.JavaNetCookieJar;
3128

@@ -41,23 +38,26 @@
4138

4239
public class RNFetchBlob extends ReactContextBaseJavaModule {
4340

41+
// Cookies
42+
private final ForwardingCookieHandler mCookieHandler;
43+
private final CookieJarContainer mCookieJarContainer;
4444
private final OkHttpClient mClient;
4545

4646
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);
4949
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<>();
5353

5454
public RNFetchBlob(ReactApplicationContext reactContext) {
5555

5656
super(reactContext);
5757

5858
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();
6161
mCookieJarContainer.setCookieJar(new JavaNetCookieJar(mCookieHandler));
6262

6363
RCTContext = reactContext;
@@ -89,23 +89,14 @@ public Map<String, Object> getConstants() {
8989
}
9090

9191
@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) {
9393
threadPool.execute(new Runnable() {
9494
@Override
9595
public void run() {
96-
RNFetchBlobFS.createFile(path, content, encode, promise);
96+
RNFetchBlobFS.createFile(path, content, encode, callback);
9797
}
9898
});
99-
}
10099

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-
});
109100
}
110101

111102
@ReactMethod
@@ -156,10 +147,21 @@ public void onHostDestroy() {
156147
};
157148
RCTContext.addLifecycleEventListener(listener);
158149
} catch(Exception ex) {
159-
promise.reject("EUNSPECIFIED", ex.getLocalizedMessage());
150+
promise.reject(ex.getLocalizedMessage());
160151
}
161152
}
162153

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+
163165
@ReactMethod
164166
public void writeArrayChunk(final String streamId, final ReadableArray dataArray, final Callback callback) {
165167
RNFetchBlobFS.writeArrayChunk(streamId, dataArray, callback);
@@ -171,8 +173,8 @@ public void unlink(String path, Callback callback) {
171173
}
172174

173175
@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);
176178
}
177179

178180
@ReactMethod
@@ -188,6 +190,7 @@ public void run() {
188190
RNFetchBlobFS.cp(path, dest, callback);
189191
}
190192
});
193+
191194
}
192195

193196
@ReactMethod
@@ -196,8 +199,8 @@ public void mv(String path, String dest, Callback callback) {
196199
}
197200

198201
@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);
201204
}
202205

203206
@ReactMethod
@@ -248,6 +251,7 @@ public void run() {
248251
RNFetchBlobFS.writeFile(path, encoding, data, append, promise);
249252
}
250253
});
254+
251255
}
252256

253257
@ReactMethod
@@ -282,24 +286,15 @@ public void run() {
282286
new RNFetchBlobFS(ctx).scanFile(p, m, callback);
283287
}
284288
});
285-
}
286289

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-
});
295290
}
296291

292+
@ReactMethod
297293
/**
298294
* @param path Stream file path
299295
* @param encoding Stream encoding, should be one of `base64`, `ascii`, and `utf8`
300296
* @param bufferSize Stream buffer size, default to 4096 or 4095(base64).
301297
*/
302-
@ReactMethod
303298
public void readStream(final String path, final String encoding, final int bufferSize, final int tick, final String streamId) {
304299
final ReactApplicationContext ctx = this.getReactApplicationContext();
305300
fsThreadPool.execute(new Runnable() {
@@ -373,10 +368,10 @@ public void getContentIntent(String mime, Promise promise) {
373368

374369
@ReactMethod
375370
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);
377372
String path = RNFetchBlobFS.normalizePath(config.getString("path"));
378373
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);
380375
return;
381376
}
382377
try {
@@ -393,18 +388,9 @@ public void addCompleteDownload (ReadableMap config, Promise promise) {
393388
promise.resolve(null);
394389
}
395390
catch(Exception ex) {
396-
promise.reject("EUNSPECIFIED", ex.getLocalizedMessage());
391+
promise.reject("RNFetchblob.addCompleteDownload failed", ex.getStackTrace().toString());
397392
}
398393

399394
}
400395

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+
}

0 commit comments

Comments
 (0)