A faster alternative to AndroidX's DocumentFile

Overview

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:

     

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.

Reference:

  1. https://stackoverflow.com/a/42187419/6819340
  2. https://stackoverflow.com/a/63466997/6819340
You might also like...
A nicer-looking, more intuitive and highly customizable alternative for radio buttons and dropdowns for Android.
A nicer-looking, more intuitive and highly customizable alternative for radio buttons and dropdowns for Android.

SwipeSelector Undergoing for some API changes for a 2.0 major version, see example usage in the sample module! What and why? Bored of dull looking rad

A nicer-looking, more intuitive and highly customizable alternative for radio buttons and dropdowns for Android.
A nicer-looking, more intuitive and highly customizable alternative for radio buttons and dropdowns for Android.

SwipeSelector Undergoing for some API changes for a 2.0 major version, see example usage in the sample module! What and why? Bored of dull looking rad

An alternative DatePicker for Android

Copyright (C) 2011 Daniel Berndt - Codeus Ltd - DateSlider 1.1 Licensed under the Apache License, Version 2.0 (the "License"); you may not use this

A super fast build tool for Android, an alternative to Instant Run
A super fast build tool for Android, an alternative to Instant Run

Freeline Freeline is a super fast build tool for Android and an alternative to Instant Run. Caching reusable class files and resource indices, it enab

Parallax everywhere is a library with alternative android widgets with parallax effects.

Parallax Everywhere# Parallax everywhere (PEW) is a library with alternative android views using parallax effects. Demo You can try the demo app on go

Reactor is key value database and is a great alternative to Shared Preferences.

Reactor Reactor is a fast and secure key-value library for Android, and has an embedded database based on the JSON structure and is a great alternativ

Twire is an alternative and open source Twitch client for Android

Twire This is a fork of the Pocket Plays for Twitch Android application. More information in this issue. Twire is an open source, ad-free Twitch brows

Open-source alternative Instagram client on Android.
Open-source alternative Instagram client on Android.

Instagram client; previously known as InstaGrabber.

A lightweight alternative to Android's ViewModels. The easiest way to retain instances in Activities, Fragments or Composables.

A lightweight alternative to Android's ViewModels. The easiest way to retain instances in Activities, Fragments or Composables.

Disk Usage/Free Utility - a better 'df' alternative
Disk Usage/Free Utility - a better 'df' alternative

duf Disk Usage/Free Utility (Linux, BSD, macOS & Windows) Features User-friendly, colorful output Adjusts to your terminal's theme & width Sort the re

LiveData 数据倒灌:别问,问就是不可预期 - Perfect alternative to SingleLiveEvent, supporting multiple observers.
LiveData 数据倒灌:别问,问就是不可预期 - Perfect alternative to SingleLiveEvent, supporting multiple observers.

前言 大家好,我是《Jetpack MVVM Best Practice》作者 KunMinX。 今天提到的 “数据倒灌” 一词,缘于我为了方便理解和记忆 “页面在 ‘二进宫’ 时收到旧数据推送” 的情况,而在 2019 年 自创并在网上传播的 关于此类现象的概括。 它主要发生在:通过 Shared

Keep data as a linked list on disk. A alternative way to reduce redundant operation for DiskLruCache
Keep data as a linked list on disk. A alternative way to reduce redundant operation for DiskLruCache

DiskLinkedList Keep data as a linked list on disk. An alternative way to reduce redundant operation for DiskLruCache Use-case Android have build-in Di

How to write Gradle plugins - answers to common questions and alternative implementation solutions
How to write Gradle plugins - answers to common questions and alternative implementation solutions

Gradle Plugins: Why? How? There is some misunderstanding and confusion about the concept of Plugins in Gradle. This is unfortunate, as it is one of th

Poc-sealed-secrets - An alternative to store sensitive data in the template Secrets Kubernetes an encrypted way

POC Sealed Secrets Overview Proof of concept with the objective of showing an al

Alternative YouTube frontend for Android built with Piped
Alternative YouTube frontend for Android built with Piped

Alternative YouTube frontend for Android built with Piped

Alternative to DreamStorageService, but instead of storing files on a database, it is stored on the file system itself.

EtherealGambi Alternative to DreamStorageService, but instead of storing files on a database, it is stored on the file system itself. I made this beca

Pref-DB - Android SharedPreferences alternative library

Pref-DB Android SharedPreferences alternative library.

Fully customizable, built from scratch NumberPicker for android. Created as an alternative to non-customizable native android NumberPicker
Fully customizable, built from scratch NumberPicker for android. Created as an alternative to non-customizable native android NumberPicker

GoodNumberPicker GoodPicker is an Android library that provides a picker with customizable UI. It was developed as alternative to the default NumberPi

🚀📱💖Animated LazyColumn/Row changes scale/color with animation and have a current selected item like a Pager. An elegant alternative for selecting from a list

Compose AnimatedList Animated infinite and finite LazyRow and LazyColumn with scale and color animations on scroll change based on how far they are to

Comments
  • Directory detection always returns true.

    Directory detection always returns true.

    Hey great work with this alternative to DocumentFile. For my current project i can not use the original one because it is way too slow. I found one bug. The function ResolverCompat.isTreeUri() (in file ResolverCompat.kt:101) does not work anymore. It always returns true. So all files declared as directory. For me it works fine when i only use the mime type to decide if it is a directory.

        // Returns True if the Uri is a Tree Uri, false otherwise.
        internal fun isTreeUri(): Boolean {
            val paths = uri.pathSegments
            return paths.size >= 2 && "tree" == paths[0]
        }
    
    opened by timo-drick 4
  • Latest release tag doesn't point to the correct commit

    Latest release tag doesn't point to the correct commit

    Hey there. I'm opening this issue as we're planning to use this library for Skyline Emulator. I figured I'd be writing essentially the same code, so it would be pretty stubborn of me to do the work again.

    As per #1, some commits were added after tag 0.8, but the tag was not updated accordingly. #1 says the following:

    Completed via https://github.com/ItzNotABug/DocumentFileCompat/commit/f7df1334410976187ca43cf9ad8f19f015447c3b. The new artifact has the same api & has the same published version (0.8)

    but the current 0.8 tag makes it confusing when looking at the repo. Is the new package published on Maven Central? And could you update tag 0.8 to point to the correct commit?

    opened by lynxnb 2
Releases(0.91)
Owner
DarShan
SIH'20 Winner, Entrepreneur, Google Certified Android Dev, Flutter, and a lil bit of iOS Swift. 🔥🙌
DarShan
Stateful is a Kotlin library which makes Android application development faster and easier.

Stateful Stateful is a Kotlin library which makes Android application development faster and easier. It helps you delete all the boilerplate code for

PicsArt 67 Oct 3, 2022
A library for image manipulation with power of renderScript which is faster than other ordinary solutions.

Pixl is a library for image manipulation with power of renderScript which is faster than other ordinary solutions, currently it includes three basic scripts, brightness, contrast, saturation.

Jibran Iqbal 20 Jan 23, 2022
when you use restful api and network get disconnect you have to store your data local for make your app faster and work on ofline mode

AppArchitectureOflineMode when you use restful api and network get disconnect you have to store your data local for make your app faster and work on o

Kareem-Mansy 3 Jun 20, 2021
Barista makes developing UI test faster, easier and more predictable. Built on top of Espresso

Barista makes developing UI test faster, easier and more predictable. Built on top of Espresso, it provides a simple and discoverable API, removing most of the boilerplate and verbosity of common Espresso tasks. You and your Android team will write tests with no effort.

Adevinta Spain 1.6k Jan 5, 2023
An Anime Watching App With Better player And Faster Servers

Kayuri An Android app to watch anime on your phone without ads.With GoogleServers and Manual Settings Toogles. This is a Fork Of Anime X Stream which

Killerpac 380 Oct 23, 2022
🚀A powerful android clean architecture that helps you build your apps faster.

IMStudio ?? Table of Contents Project Structure Convention RxJava Common Scripts Technical Stack Dependencies Library Architecture Case Study Authors

Hau NGUYEN (Leo) 0 Nov 20, 2022
Volley is an HTTP library that makes networking for Android apps easier and, most importantly, faster.

Volley Volley is an HTTP library that makes networking for Android apps easier and, most importantly, faster. For more information about Volley and ho

Google 3.3k Jan 1, 2023
An open source GitHub Android client app, faster and concise.

An open-source GitHub Android client app, faster and concise.

30度的射线 4.1k Dec 26, 2022
An Android base project building on MVVM Architecture Pattern. This can help you build new apps faster

MVVM Explanation If you can't imagine what is MVVM, please read my medium article here first. It can fully explain the revolution of Software architec

Danh Dev 29 Sep 21, 2022
Remoter - An alternative to Android AIDL for Android Remote IPC services using plain java interfaces

Remoter Remoter - An alternative to Android AIDL for Android Remote IPC services using plain java interfaces Remoter makes developing android remote s

Joseph Samuel 68 Dec 16, 2022