Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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.

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! :)