|
| 1 | +package com.ReactNativeBlobUtil; |
| 2 | + |
| 3 | +import android.os.Build; |
| 4 | + |
| 5 | +import androidx.annotation.NonNull; |
| 6 | +import androidx.annotation.RequiresApi; |
| 7 | + |
| 8 | +import com.facebook.fbreact.specs.NativeBlobUtilsSpec; |
| 9 | +import com.facebook.react.bridge.Callback; |
| 10 | +import com.facebook.react.bridge.Promise; |
| 11 | +import com.facebook.react.bridge.ReactApplicationContext; |
| 12 | +import com.facebook.react.bridge.ReadableArray; |
| 13 | +import com.facebook.react.bridge.ReadableMap; |
| 14 | + |
| 15 | +import java.util.HashMap; |
| 16 | +import java.util.Map; |
| 17 | + |
| 18 | +import javax.annotation.Nullable; |
| 19 | + |
| 20 | +public class ReactNativeBlobUtil extends NativeBlobUtilsSpec { |
| 21 | + |
| 22 | + private final ReactNativeBlobUtilImpl delegate; |
| 23 | + |
| 24 | + public ReactNativeBlobUtil(ReactApplicationContext reactContext) { |
| 25 | + super(reactContext); |
| 26 | + delegate = new ReactNativeBlobUtilImpl(reactContext); |
| 27 | + } |
| 28 | + |
| 29 | + @Override |
| 30 | + protected Map<String, Object> getTypedExportedConstants() { |
| 31 | + Map<String, Object> res = new HashMap<>(); |
| 32 | + res.putAll(ReactNativeBlobUtilFS.getSystemfolders(this.getReactApplicationContext())); |
| 33 | + res.putAll(ReactNativeBlobUtilFS.getLegacySystemfolders(this.getReactApplicationContext())); |
| 34 | + return res; |
| 35 | + } |
| 36 | + |
| 37 | + @NonNull |
| 38 | + @Override |
| 39 | + public String getName() { |
| 40 | + return ReactNativeBlobUtilImpl.NAME; |
| 41 | + } |
| 42 | + |
| 43 | + @Override |
| 44 | + public void fetchBlobForm(ReadableMap options, String taskId, String method, String url, ReadableMap headers, ReadableArray form, Callback callback) { |
| 45 | + delegate.fetchBlobForm(options, taskId, method, url, headers, form, callback); |
| 46 | + } |
| 47 | + |
| 48 | + @Override |
| 49 | + public void fetchBlob(ReadableMap options, String taskId, String method, String url, ReadableMap headers, String body, Callback callback) { |
| 50 | + delegate.fetchBlob(options, taskId, method, url, headers, body, callback); |
| 51 | + } |
| 52 | + |
| 53 | + @Override |
| 54 | + public void createFile(String path, String data, String encoding, Promise promise) { |
| 55 | + delegate.createFile(path, data, encoding, promise); |
| 56 | + } |
| 57 | + |
| 58 | + @Override |
| 59 | + public void createFileASCII(String path, ReadableArray data, Promise promise) { |
| 60 | + delegate.createFileASCII(path, data, promise); |
| 61 | + } |
| 62 | + |
| 63 | + |
| 64 | + @Override |
| 65 | + public void pathForAppGroup(String groupName, Promise promise) { |
| 66 | + // Not implemented as ReactNativeBlobUtil.pathForAppGroup only supports IOS |
| 67 | + // This will be rejected at the iOS layer |
| 68 | + } |
| 69 | + |
| 70 | + @Override |
| 71 | + public String syncPathAppGroup(String groupName) { |
| 72 | + // Not implemented as ReactNativeBlobUtil.syncPathAppGroup only supports IOS |
| 73 | + // This will be rejected at the iOS layer |
| 74 | + return null; |
| 75 | + } |
| 76 | + |
| 77 | + @Override |
| 78 | + public void exists(String path, Callback callback) { |
| 79 | + delegate.exists(path, callback); |
| 80 | + } |
| 81 | + |
| 82 | + @Override |
| 83 | + public void writeFile(String path, String encoding, String data, boolean transformFile, boolean append, Promise promise) { |
| 84 | + delegate.writeFile(path, encoding, data, transformFile, append, promise); |
| 85 | + } |
| 86 | + |
| 87 | + @Override |
| 88 | + public void writeFileArray(String path, ReadableArray data, boolean append, Promise promise) { |
| 89 | + delegate.writeFileArray(path, data, append, promise); |
| 90 | + } |
| 91 | + |
| 92 | + @Override |
| 93 | + public void writeStream(String path, String withEncoding, boolean appendData, Callback callback) { |
| 94 | + delegate.writeStream(path, withEncoding, appendData, callback); |
| 95 | + } |
| 96 | + |
| 97 | + @Override |
| 98 | + public void writeArrayChunk(String streamId, ReadableArray withArray, Callback callback) { |
| 99 | + delegate.writeArrayChunk(streamId, withArray, callback); |
| 100 | + } |
| 101 | + |
| 102 | + @Override |
| 103 | + public void writeChunk(String streamId, String withData, Callback callback) { |
| 104 | + delegate.writeChunk(streamId, withData, callback); |
| 105 | + } |
| 106 | + |
| 107 | + @Override |
| 108 | + public void closeStream(String streamId, Callback callback) { |
| 109 | + delegate.closeStream(streamId, callback); |
| 110 | + } |
| 111 | + |
| 112 | + @Override |
| 113 | + public void unlink(String path, Callback callback) { |
| 114 | + delegate.unlink(path, callback); |
| 115 | + } |
| 116 | + |
| 117 | + @Override |
| 118 | + public void removeSession(ReadableArray paths, Callback callback) { |
| 119 | + delegate.removeSession(paths, callback); |
| 120 | + } |
| 121 | + |
| 122 | + @Override |
| 123 | + public void ls(String path, Promise promise) { |
| 124 | + delegate.ls(path, promise); |
| 125 | + } |
| 126 | + |
| 127 | + @Override |
| 128 | + public void stat(String target, Callback callback) { |
| 129 | + delegate.stat(target, callback); |
| 130 | + } |
| 131 | + |
| 132 | + @Override |
| 133 | + public void lstat(String path, Callback callback) { |
| 134 | + delegate.lstat(path, callback); |
| 135 | + } |
| 136 | + |
| 137 | + @Override |
| 138 | + public void cp(String src, String dest, Callback callback) { |
| 139 | + delegate.cp(src, dest, callback); |
| 140 | + } |
| 141 | + |
| 142 | + @Override |
| 143 | + public void mv(String path, String dest, Callback callback) { |
| 144 | + delegate.mv(path, dest, callback); |
| 145 | + } |
| 146 | + |
| 147 | + @Override |
| 148 | + public void mkdir(String path, Promise promise) { |
| 149 | + delegate.mkdir(path, promise); |
| 150 | + } |
| 151 | + |
| 152 | + @Override |
| 153 | + public void readFile(String path, String encoding, boolean transformFile, Promise promise) { |
| 154 | + delegate.readFile(path, encoding, transformFile, promise); |
| 155 | + } |
| 156 | + |
| 157 | + @Override |
| 158 | + public void hash(String path, String algorithm, Promise promise) { |
| 159 | + delegate.hash(path, algorithm, promise); |
| 160 | + } |
| 161 | + |
| 162 | + @Override |
| 163 | + public void readStream(String path, String encoding, double bufferSize, double tick, String streamId) { |
| 164 | + delegate.readStream(path, encoding, (int) bufferSize, (int) tick, streamId); |
| 165 | + } |
| 166 | + |
| 167 | + @Override |
| 168 | + public void getEnvironmentDirs(Callback callback) { |
| 169 | + // Not implemented as ReactNativeBlobUtil.getEnvironmentDirs only supports IOS |
| 170 | + } |
| 171 | + |
| 172 | + @Override |
| 173 | + public void cancelRequest(String taskId, Callback callback) { |
| 174 | + delegate.cancelRequest(taskId, callback); |
| 175 | + } |
| 176 | + |
| 177 | + @Override |
| 178 | + public void enableProgressReport(String taskId, double interval, double count) { |
| 179 | + delegate.enableProgressReport(taskId, (int) interval, (int) count); |
| 180 | + } |
| 181 | + |
| 182 | + @Override |
| 183 | + public void enableUploadProgressReport(String taskId, double interval, double count) { |
| 184 | + delegate.enableUploadProgressReport(taskId, (int) interval, (int) count); |
| 185 | + } |
| 186 | + |
| 187 | + @Override |
| 188 | + public void slice(String src, String dest, double start, double end, Promise promise) { |
| 189 | + delegate.slice(src, dest, (int) start, (int) end, promise); |
| 190 | + } |
| 191 | + |
| 192 | + @Override |
| 193 | + public void presentOptionsMenu(String uri, String scheme, Promise promise) { |
| 194 | + // Not implemented as ReactNativeBlobUtil.presentOptionsMenu only supports IOS |
| 195 | + // This will be rejected at the iOS layer |
| 196 | + } |
| 197 | + |
| 198 | + @Override |
| 199 | + public void presentOpenInMenu(String uri, String scheme, Promise promise) { |
| 200 | + // Not implemented as ReactNativeBlobUtil.presentOpenInMenu only supports IOS |
| 201 | + // This will be rejected at the iOS layer |
| 202 | + } |
| 203 | + |
| 204 | + @Override |
| 205 | + public void presentPreview(String uri, String scheme, Promise promise) { |
| 206 | + // Not implemented as ReactNativeBlobUtil.presentPreview only supports IOS |
| 207 | + // This will be rejected at the iOS layer |
| 208 | + } |
| 209 | + |
| 210 | + @Override |
| 211 | + public void excludeFromBackupKey(String url, Promise promise) { |
| 212 | + // Not implemented as ReactNativeBlobUtil.excludeFromBackupKey only supports IOS |
| 213 | + } |
| 214 | + |
| 215 | + @Override |
| 216 | + public void df(Callback callback) { |
| 217 | + delegate.df(callback); |
| 218 | + } |
| 219 | + |
| 220 | + @Override |
| 221 | + public void emitExpiredEvent(Callback callback) { |
| 222 | + // Not implemented as ReactNativeBlobUtil.emitExpiredEvent only supports IOS |
| 223 | + } |
| 224 | + |
| 225 | + @Override |
| 226 | + public void actionViewIntent(String path, String mime, String chooserTitle, Promise promise) { |
| 227 | + delegate.actionViewIntent(path, mime, chooserTitle, promise); |
| 228 | + } |
| 229 | + |
| 230 | + @Override |
| 231 | + public void addCompleteDownload(ReadableMap config, Promise promise) { |
| 232 | + delegate.addCompleteDownload(config, promise); |
| 233 | + } |
| 234 | + |
| 235 | + @RequiresApi(api = Build.VERSION_CODES.Q) |
| 236 | + @Override |
| 237 | + public void copyToInternal(String contentUri, String destpath, Promise promise) { |
| 238 | + delegate.copyToInternal(contentUri, destpath, promise); |
| 239 | + } |
| 240 | + |
| 241 | + @Override |
| 242 | + public void copyToMediaStore(ReadableMap filedata, String mt, String path, Promise promise) { |
| 243 | + delegate.copyToMediaStore(filedata, mt, path, promise); |
| 244 | + } |
| 245 | + |
| 246 | + @Override |
| 247 | + public void createMediaFile(ReadableMap filedata, String mt, Promise promise) { |
| 248 | + delegate.createMediaFile(filedata, mt, promise); |
| 249 | + } |
| 250 | + |
| 251 | + @RequiresApi(api = Build.VERSION_CODES.Q) |
| 252 | + @Override |
| 253 | + public void getBlob(String contentUri, String encoding, Promise promise) { |
| 254 | + delegate.getBlob(contentUri, encoding, promise); |
| 255 | + } |
| 256 | + |
| 257 | + @Override |
| 258 | + public void getContentIntent(String mime, Promise promise) { |
| 259 | + delegate.getContentIntent(mime, promise); |
| 260 | + } |
| 261 | + |
| 262 | + @Override |
| 263 | + public void getSDCardDir(Promise promise) { |
| 264 | + delegate.getSDCardDir(promise); |
| 265 | + } |
| 266 | + |
| 267 | + @Override |
| 268 | + public void getSDCardApplicationDir(Promise promise) { |
| 269 | + delegate.getSDCardApplicationDir(promise); |
| 270 | + } |
| 271 | + |
| 272 | + @Override |
| 273 | + public void scanFile(final ReadableArray pairs, final Callback callback) { |
| 274 | + delegate.scanFile(pairs, callback); |
| 275 | + } |
| 276 | + |
| 277 | + @Override |
| 278 | + public void writeToMediaFile(String fileUri, String path, boolean transformFile, Promise promise) { |
| 279 | + delegate.writeToMediaFile(fileUri, path, transformFile, promise); |
| 280 | + } |
| 281 | +} |
0 commit comments