Skip to content

Commit 59949da

Browse files
committed
improve: api.
1 parent 0de0dad commit 59949da

4 files changed

Lines changed: 31 additions & 16 deletions

File tree

dfc/src/main/java/com/lazygeniouz/dfc/file/DocumentFileCompat.kt

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import com.lazygeniouz.dfc.controller.DocumentController
99
import com.lazygeniouz.dfc.file.internals.RawDocumentFileCompat
1010
import com.lazygeniouz.dfc.file.internals.SingleDocumentFileCompat
1111
import com.lazygeniouz.dfc.file.internals.TreeDocumentFileCompat
12-
import com.lazygeniouz.dfc.resolver.ResolverCompat
1312
import java.io.File
1413

1514
/**
@@ -59,6 +58,14 @@ abstract class DocumentFileCompat(
5958
*/
6059
abstract fun createDirectory(name: String): DocumentFileCompat?
6160

61+
/**
62+
* This will return a list of [DocumentFileCompat] with all the defined fields
63+
* only when the current document is a **Directory**.
64+
*
65+
* A [UnsupportedOperationException] is thrown if the uri is not a directory.
66+
*/
67+
abstract fun listFiles(): List<DocumentFileCompat>
68+
6269
/**
6370
* Same as [listFiles] but allows specifying a custom [projection] (columns to query).
6471
*
@@ -188,16 +195,6 @@ abstract class DocumentFileCompat(
188195
return fileController.isDirectory()
189196
}
190197

191-
/**
192-
* This will return a list of [DocumentFileCompat] with all the defined fields
193-
* only when the current document is a **Directory**.
194-
*
195-
* A [UnsupportedOperationException] is thrown if the uri is not a directory.
196-
*/
197-
open fun listFiles(): List<DocumentFileCompat> {
198-
return listFiles(ResolverCompat.fullProjection)
199-
}
200-
201198
/**
202199
* Converts a non serializable [DocumentFileCompat] to a serializable [SerializedFile].
203200
*/

dfc/src/main/java/com/lazygeniouz/dfc/file/internals/RawDocumentFileCompat.kt

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,15 +96,20 @@ internal class RawDocumentFileCompat(context: Context, var file: File) :
9696
else null
9797
}
9898

99+
/**
100+
* Returns list of files using File API.
101+
*/
102+
override fun listFiles(): List<DocumentFileCompat> {
103+
return file.listFiles()?.map { child -> fromFile(context, child) } ?: emptyList()
104+
}
105+
99106
/**
100107
* Returns list of files using File API.
101108
*
102-
* The performance of File api is pretty great as compared to others.
103-
*
104-
* Note: [projection] parameter is ignored as File API doesn't support custom projections.
109+
* Note: [projection] is ignored as the File API doesn't support it.
105110
*/
106111
override fun listFiles(projection: Array<String>): List<DocumentFileCompat> {
107-
return file.listFiles()?.map { child -> fromFile(context, child) } ?: emptyList()
112+
return listFiles()
108113
}
109114

110115
/**

dfc/src/main/java/com/lazygeniouz/dfc/file/internals/SingleDocumentFileCompat.kt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,19 @@ internal class SingleDocumentFileCompat(
4646
*
4747
* @throws UnsupportedOperationException
4848
*/
49-
override fun listFiles(projection: Array<String>): List<DocumentFileCompat> {
49+
override fun listFiles(): List<DocumentFileCompat> {
5050
throw UnsupportedOperationException()
5151
}
5252

53+
/**
54+
* Single document Uris don't have children, so projections are not applicable.
55+
*
56+
* @throws UnsupportedOperationException
57+
*/
58+
override fun listFiles(projection: Array<String>): List<DocumentFileCompat> {
59+
return listFiles()
60+
}
61+
5362
/**
5463
* No [listFiles], no children, no count.
5564
*

dfc/src/main/java/com/lazygeniouz/dfc/file/internals/TreeDocumentFileCompat.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ internal class TreeDocumentFileCompat(
5757
return fileController.listFiles(projection)
5858
}
5959

60+
override fun listFiles(): List<DocumentFileCompat> {
61+
return fileController.listFiles()
62+
}
63+
6064
/**
6165
* This will return the children count in the directory.
6266
*

0 commit comments

Comments
 (0)