Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/itznotabug/documentfilecompat
A blazing fast alternative to AndroidX's DocumentFile.
https://github.com/itznotabug/documentfilecompat
android-documentfile android-library android-saf androidx-documentfile androidx-library
Last synced: about 1 month ago
JSON representation
A blazing fast alternative to AndroidX's DocumentFile.
- Host: GitHub
- URL: https://github.com/itznotabug/documentfilecompat
- Owner: ItzNotABug
- License: apache-2.0
- Created: 2021-12-04T13:41:11.000Z (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2023-10-14T08:25:43.000Z (about 1 year ago)
- Last Synced: 2024-10-08T15:56:52.714Z (about 1 month ago)
- Topics: android-documentfile, android-library, android-saf, androidx-documentfile, androidx-library
- Language: Kotlin
- Homepage:
- Size: 250 KB
- Stars: 60
- Watchers: 1
- Forks: 4
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# DocumentFileCompat
A faster alternative to AndroidX's DocumentFile.
### The Problem with DocumentFile
It is horribly slow!\
For **almost** every method, there is a query to **ContentResolver**.The most common one is `DocumentFile.findFile()`, `DocumentFile.getName()` and other is building a
Custom Data Model with multiple parameters.\
This can take like a horrible amount of time.### Solution
`DocumentFileCompat` is a drop-in replacement which gathers relevant parameters when querying for
files.\
The performance can sometimes peak to 2x or quite higher, depending on the size of the folder.Check the screenshots below:
[](/screenshots/filecompat_directory_perf.jpeg)
[](/screenshots/filecompat_file_perf.jpeg)**48 whopping seconds for directory listing compared to 3.5!** (Obviously, No competition with the
Native File API).\
Also extracting file information does not take that much time but the improvement is still
significant.**Note:** `DocumentFileCompat` is something that I used internally for some projects & therefore I
didn't do much of file manipulation with it (only delete files) and therefore this API does
not offer too much out of the box.\
This is now a completely usable alternative to `DocumentFile`.### Installation
#### Gradle
```gradle
dependencies {
implementation "com.lazygeniouz:dfc:$latest_version"
}
```#### Maven
```xml
com.lazygeniouz
dfc
$latest_version
aar```
### Usage
Almost all of the methods & getters are identical to `DocumentFile`, you'll just have to replace the
imports.\
Additional methods like `copyTo(destination: Uri)` & `copyFrom(source: Uri)` are added as well.#### Reference:
1. https://stackoverflow.com/a/42187419/6819340
2. https://stackoverflow.com/a/63466997/6819340### Issues & Suggestions
Create a new issue if you experience any problem or have any suggestions.\
I'll appreciate if you create a PR as well (if possible).Finally, don't forget to ⭐️ the library! :)