Skip to content

Commit c66788f

Browse files
author
Augusto
committed
fix class import
1 parent 298a4de commit c66788f

File tree

1 file changed

+46
-34
lines changed

1 file changed

+46
-34
lines changed

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

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

1112
import com.facebook.react.bridge.ActivityEventListener;
1213
import com.facebook.react.bridge.Callback;
@@ -38,26 +39,23 @@
3839

3940
public class RNFetchBlob extends ReactContextBaseJavaModule {
4041

41-
// Cookies
42-
private final ForwardingCookieHandler mCookieHandler;
43-
private final CookieJarContainer mCookieJarContainer;
4442
private final OkHttpClient mClient;
4543

4644
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);
4947
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<>();
5351

5452
public RNFetchBlob(ReactApplicationContext reactContext) {
5553

5654
super(reactContext);
5755

5856
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();
6159
mCookieJarContainer.setCookieJar(new JavaNetCookieJar(mCookieHandler));
6260

6361
RCTContext = reactContext;
@@ -89,14 +87,23 @@ public Map<String, Object> getConstants() {
8987
}
9088

9189
@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) {
9391
threadPool.execute(new Runnable() {
9492
@Override
9593
public void run() {
96-
RNFetchBlobFS.createFile(path, content, encode, callback);
94+
RNFetchBlobFS.createFile(path, content, encode, promise);
9795
}
9896
});
97+
}
9998

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+
});
100107
}
101108

102109
@ReactMethod
@@ -147,21 +154,10 @@ public void onHostDestroy() {
147154
};
148155
RCTContext.addLifecycleEventListener(listener);
149156
} catch(Exception ex) {
150-
promise.reject(ex.getLocalizedMessage());
157+
promise.reject("EUNSPECIFIED", ex.getLocalizedMessage());
151158
}
152159
}
153160

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-
165161
@ReactMethod
166162
public void writeArrayChunk(final String streamId, final ReadableArray dataArray, final Callback callback) {
167163
RNFetchBlobFS.writeArrayChunk(streamId, dataArray, callback);
@@ -173,8 +169,8 @@ public void unlink(String path, Callback callback) {
173169
}
174170

175171
@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);
178174
}
179175

180176
@ReactMethod
@@ -190,7 +186,6 @@ public void run() {
190186
RNFetchBlobFS.cp(path, dest, callback);
191187
}
192188
});
193-
194189
}
195190

196191
@ReactMethod
@@ -199,8 +194,8 @@ public void mv(String path, String dest, Callback callback) {
199194
}
200195

201196
@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);
204199
}
205200

206201
@ReactMethod
@@ -251,7 +246,6 @@ public void run() {
251246
RNFetchBlobFS.writeFile(path, encoding, data, append, promise);
252247
}
253248
});
254-
255249
}
256250

257251
@ReactMethod
@@ -286,15 +280,24 @@ public void run() {
286280
new RNFetchBlobFS(ctx).scanFile(p, m, callback);
287281
}
288282
});
289-
290283
}
291284

292285
@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+
293295
/**
294296
* @param path Stream file path
295297
* @param encoding Stream encoding, should be one of `base64`, `ascii`, and `utf8`
296298
* @param bufferSize Stream buffer size, default to 4096 or 4095(base64).
297299
*/
300+
@ReactMethod
298301
public void readStream(final String path, final String encoding, final int bufferSize, final int tick, final String streamId) {
299302
final ReactApplicationContext ctx = this.getReactApplicationContext();
300303
fsThreadPool.execute(new Runnable() {
@@ -368,10 +371,10 @@ public void getContentIntent(String mime, Promise promise) {
368371

369372
@ReactMethod
370373
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);
372375
String path = RNFetchBlobFS.normalizePath(config.getString("path"));
373376
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"));
375378
return;
376379
}
377380
try {
@@ -388,9 +391,18 @@ public void addCompleteDownload (ReadableMap config, Promise promise) {
388391
promise.resolve(null);
389392
}
390393
catch(Exception ex) {
391-
promise.reject("RNFetchblob.addCompleteDownload failed", ex.getStackTrace().toString());
394+
promise.reject("EUNSPECIFIED", ex.getLocalizedMessage());
392395
}
393396

394397
}
395398

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

0 commit comments

Comments
 (0)