|
1 | 1 | package io.fullstack.firestack;
|
2 | 2 |
|
| 3 | +import android.os.Environment; |
| 4 | +import android.os.StatFs; |
3 | 5 | import android.content.Context;
|
4 | 6 | import android.util.Log;
|
5 | 7 | import java.util.Map;
|
| 8 | +import java.util.HashMap; |
6 | 9 | import java.io.File;
|
7 | 10 | import java.io.FileInputStream;
|
8 | 11 | import java.io.InputStream;
|
|
41 | 44 | class FirestackStorageModule extends ReactContextBaseJavaModule {
|
42 | 45 |
|
43 | 46 | private static final String TAG = "FirestackStorage";
|
| 47 | + private static final String DocumentDirectoryPath = "DOCUMENT_DIRECTORY_PATH"; |
| 48 | + private static final String ExternalDirectoryPath = "EXTERNAL_DIRECTORY_PATH"; |
| 49 | + private static final String ExternalStorageDirectoryPath = "EXTERNAL_STORAGE_DIRECTORY_PATH"; |
| 50 | + private static final String PicturesDirectoryPath = "PICTURES_DIRECTORY_PATH"; |
| 51 | + private static final String TemporaryDirectoryPath = "TEMPORARY_DIRECTORY_PATH"; |
| 52 | + private static final String CachesDirectoryPath = "CACHES_DIRECTORY_PATH"; |
| 53 | + private static final String DocumentDirectory = "DOCUMENT_DIRECTORY_PATH"; |
| 54 | + |
| 55 | + private static final String FileTypeRegular = "FILETYPE_REGULAR"; |
| 56 | + private static final String FileTypeDirectory = "FILETYPE_DIRECTORY"; |
| 57 | + |
44 | 58 |
|
45 | 59 | private Context context;
|
46 | 60 | private ReactContext mReactContext;
|
@@ -186,4 +200,34 @@ public void onPaused(UploadTask.TaskSnapshot taskSnapshot) {
|
186 | 200 | callback.invoke(err);
|
187 | 201 | }
|
188 | 202 | }
|
| 203 | + |
| 204 | + // Comes almost directory from react-native-fs |
| 205 | + @Override |
| 206 | + public Map<String, Object> getConstants() { |
| 207 | + final Map<String, Object> constants = new HashMap<>(); |
| 208 | + |
| 209 | + constants.put(DocumentDirectory, 0); |
| 210 | + constants.put(DocumentDirectoryPath, this.getReactApplicationContext().getFilesDir().getAbsolutePath()); |
| 211 | + constants.put(TemporaryDirectoryPath, null); |
| 212 | + constants.put(PicturesDirectoryPath, Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).getAbsolutePath()); |
| 213 | + constants.put(CachesDirectoryPath, this.getReactApplicationContext().getCacheDir().getAbsolutePath()); |
| 214 | + constants.put(FileTypeRegular, 0); |
| 215 | + constants.put(FileTypeDirectory, 1); |
| 216 | + |
| 217 | + File externalStorageDirectory = Environment.getExternalStorageDirectory(); |
| 218 | + if (externalStorageDirectory != null) { |
| 219 | + constants.put(ExternalStorageDirectoryPath, externalStorageDirectory.getAbsolutePath()); |
| 220 | + } else { |
| 221 | + constants.put(ExternalStorageDirectoryPath, null); |
| 222 | + } |
| 223 | + |
| 224 | + File externalDirectory = this.getReactApplicationContext().getExternalFilesDir(null); |
| 225 | + if (externalDirectory != null) { |
| 226 | + constants.put(ExternalDirectoryPath, externalDirectory.getAbsolutePath()); |
| 227 | + } else { |
| 228 | + constants.put(ExternalDirectoryPath, null); |
| 229 | + } |
| 230 | + |
| 231 | + return constants; |
| 232 | + } |
189 | 233 | }
|
0 commit comments