Commit 274f0b6
refactor: simplify file:// URL loading with URI.scheme checking
Simplify PR #329 implementation by removing unnecessary factory pattern
and using iOS-style approach with simple conditional dispatch.
Changes:
- Remove ResourceLoaderFactory, ResourceLoader interface, and implementations
- Replace factory pattern with simple if/else using URI.scheme
- Add loadFileUrlAsset() with background threading (Dispatchers.IO)
- Add loadRemoteUrlAsset() wrapping existing Volley logic
- Use proper URI parsing instead of string.startsWith()
Benefits:
- 50 fewer lines of code (net: -14 lines)
- Matches iOS architectural pattern (simple conditional dispatch)
- More maintainable - no unnecessary abstractions
- Uses URI.scheme for robust URL checking vs string matching
- Keeps critical improvements: background threading and error handling
Threading improvements:
- File I/O on Dispatchers.IO background thread
- Callbacks on main thread with withContext(Dispatchers.Main)
- Matches iOS pattern (DispatchQueue.global + DispatchQueue.main.async)
Error handling improvements:
- Check file existence and permissions before reading
- Return 404 NetworkResponse for FileNotFoundException
- Clear error messages for different failure modes
URL parsing improvements:
- Use java.net.URI instead of string.substring()
- Handles edge cases: file://, file:///, URL encoding
- Validates URI syntax properly
- Case-insensitive scheme checking
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>1 parent 5dc7f80 commit 274f0b6
1 file changed
Lines changed: 49 additions & 64 deletions
Lines changed: 49 additions & 64 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
| 41 | + | |
41 | 42 | | |
42 | 43 | | |
43 | 44 | | |
44 | 45 | | |
| 46 | + | |
| 47 | + | |
45 | 48 | | |
46 | 49 | | |
47 | 50 | | |
| |||
993 | 996 | | |
994 | 997 | | |
995 | 998 | | |
996 | | - | |
997 | | - | |
998 | | - | |
999 | | - | |
1000 | | - | |
1001 | | - | |
| 999 | + | |
| 1000 | + | |
| 1001 | + | |
| 1002 | + | |
| 1003 | + | |
| 1004 | + | |
| 1005 | + | |
| 1006 | + | |
| 1007 | + | |
| 1008 | + | |
| 1009 | + | |
| 1010 | + | |
| 1011 | + | |
| 1012 | + | |
| 1013 | + | |
| 1014 | + | |
| 1015 | + | |
| 1016 | + | |
| 1017 | + | |
| 1018 | + | |
| 1019 | + | |
| 1020 | + | |
| 1021 | + | |
| 1022 | + | |
| 1023 | + | |
| 1024 | + | |
| 1025 | + | |
| 1026 | + | |
| 1027 | + | |
| 1028 | + | |
| 1029 | + | |
| 1030 | + | |
| 1031 | + | |
| 1032 | + | |
| 1033 | + | |
| 1034 | + | |
| 1035 | + | |
| 1036 | + | |
| 1037 | + | |
| 1038 | + | |
| 1039 | + | |
| 1040 | + | |
| 1041 | + | |
| 1042 | + | |
| 1043 | + | |
| 1044 | + | |
1002 | 1045 | | |
1003 | 1046 | | |
1004 | 1047 | | |
| |||
1241 | 1284 | | |
1242 | 1285 | | |
1243 | 1286 | | |
1244 | | - | |
1245 | | - | |
1246 | | - | |
1247 | | - | |
1248 | | - | |
1249 | | - | |
1250 | | - | |
1251 | | - | |
1252 | | - | |
1253 | | - | |
1254 | | - | |
1255 | | - | |
1256 | | - | |
1257 | | - | |
1258 | | - | |
1259 | | - | |
1260 | | - | |
1261 | | - | |
1262 | | - | |
1263 | | - | |
1264 | | - | |
1265 | | - | |
1266 | | - | |
1267 | | - | |
1268 | | - | |
1269 | | - | |
1270 | | - | |
1271 | | - | |
1272 | | - | |
1273 | | - | |
1274 | | - | |
1275 | | - | |
1276 | | - | |
1277 | | - | |
1278 | | - | |
1279 | | - | |
1280 | | - | |
1281 | | - | |
1282 | | - | |
1283 | | - | |
1284 | | - | |
1285 | | - | |
1286 | | - | |
1287 | | - | |
1288 | | - | |
1289 | | - | |
1290 | | - | |
1291 | | - | |
1292 | | - | |
1293 | | - | |
1294 | | - | |
1295 | | - | |
1296 | | - | |
1297 | | - | |
1298 | | - | |
1299 | | - | |
1300 | | - | |
1301 | | - | |
0 commit comments