Skip to main content

Get Directory Content

To get the contents of the directory, you must subscribe to receiving the contents of the directory at the time of initialization of your activity or fragment. After that, the browser will return the cached data from the database.

var disposable: Disposable? = null
// ...
val currentPath: String = "/" // directory path to be observedval sortType = FileTreeBrowser.Sort.NAME_ASC_DIR_FIRST // sort mode// FileTreeBrowser.Sort:// * NO_SORTING - No sorting (default)// * NAME_ASC_DIR_FIRST - Sort by name ascending; Directories first.// * TYPE_ASC_DIR_FIRST - Sort by type ascending; Directories first.// * MODIFIED_DESC_DIR_FIRST - Sort by modification time descending; Directories first.// * SIZE_DESC_DIR_FIRST - Sort by size descending; Directories first.
// Returned observable that emits directory content.// You have to subscribe on returned observable in order to receive updates.disposable = FileManager.browser.getDirectoryContentObservable(currentPath, sortType)        .subscribeBy(                onNext = { // it: List<FileItem>!                    // Update your recycler view adapter with received list.                },                onError = { // it: Throwable                    // Handle it                }        )
// ...
// You must call dispose() on disposable that returned by subscribe() method,// when it no longer needed, for example in your fragment’s onStop() or onPause().disposable?.dispose()

The returned observable emits every time when one of the following is changed:

  • Directory content (local db)
  • Operations
  • Upload queue
  • Download queue

Then, if the network is available, call the function of updating the required directory from the backend to get the latest data.

var disposable: Disposable? = null
// ...
val dirPath = "/" // path of the remote directory to reload
// Returned completable.// You have to subscribe on returned Completable to track the completion of the operation.disposable = FileManager.browser.reloadDirectoryContent(dirPath)        .observeOn(AndroidSchedulers.mainThread())        .subscribeBy (            onComplete = { /* completion processing */ },            onError = { // it: Throwable                // Handle it            }        )
// You must call dispose() on disposable that returned by subscribe() method,// when it no longer needed, for example in your fragment’s onStop() or onPause().disposable?.dispose()

Links - FileTreeBrowser, FileTreeBrowser.Sort, FileItem.