Skip to main content

Offline Mode

Offline mode makes files available for use even when there is no internet connection. When you add a file offline, a copy of the file is downloaded to the application folder. When you change a file in the cloud, the local copy will also be updated.

Add To Offline#

After adding a file to the offline storage, the file library automatically starts downloading the file from cloud storage to a dedicated local application directory. After the download is complete, the application can use the path from FileItem.localPath to access the locally saved file.

You can monitor the offline status of a file either through FileManager.offline.getStorageObservable(sort), or through FileManager.browser.getDirectoryContentObservable().

The FileItem.offlineStatus field contains the offline status of a file.

The following code example demonstrates adding a file to the offline storage.

// File item to add to offline storage.val fileItem: FileItem
FileManager.offline.addFile(fileItem)

Links - FileItem.

Remove From Offline#

The following code example demonstrates removing a file from the offline storage.

// File item to remove from offline storage.val fileItem: FileItem
FileManager.offline.removeFile(fileItem)

Links - FileItem.

Offline Storage Monitoring#

The following code example demonstrates the offline storage monitoring.

var disposable: Disposable? = null
// Sort mode.val sortMode: FileTreeBrowser.Sort = FileTreeBrowser.Sort.NO_SORTING// 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 content of the offline storage every time // when one of the following is changed:// * New file added to offline// * File removed from offline// * File status changed//// You have to subscribe on returned observable in order to receive updates.disposable = FileManager.offline.getStorageObservable(sort)        .subscribe { // it: List<FileItem>!            // Update your recycler view adapter with received list.        }
// ...
// 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.Sort, FileItem.

Synchronizing the offline storage#

The following code example demonstrates syncing the offline storage.

FileManager.offline.syncStorage()