Search in sources :

Example 1 with IItemCollectionPage

use of com.onedrive.sdk.extensions.IItemCollectionPage in project keepass2android by PhilippC.

the class OneDriveStorage method listFiles.

@Override
public List<FileEntry> listFiles(String parentPath) throws Exception {
    try {
        ArrayList<FileEntry> result = new ArrayList<FileEntry>();
        parentPath = removeProtocol(parentPath);
        IItemCollectionPage itemsPage = oneDriveClient.getDrive().getRoot().getItemWithPath(parentPath).getChildren().buildRequest().get();
        if (parentPath.endsWith("/"))
            parentPath = parentPath.substring(0, parentPath.length() - 1);
        while (true) {
            List<Item> items = itemsPage.getCurrentPage();
            if (items.isEmpty())
                return result;
            for (Item i : items) {
                FileEntry e = getFileEntry(parentPath + "/" + i.name, i);
                Log.d("KP2AJ", e.path);
                result.add(e);
            }
            IItemCollectionRequestBuilder nextPageReqBuilder = itemsPage.getNextPage();
            if (nextPageReqBuilder == null)
                return result;
            itemsPage = nextPageReqBuilder.buildRequest().get();
        }
    } catch (OneDriveServiceException e) {
        throw convertException(e);
    }
}
Also used : Item(com.onedrive.sdk.extensions.Item) IItemCollectionPage(com.onedrive.sdk.extensions.IItemCollectionPage) ArrayList(java.util.ArrayList) IItemCollectionRequestBuilder(com.onedrive.sdk.extensions.IItemCollectionRequestBuilder) OneDriveServiceException(com.onedrive.sdk.http.OneDriveServiceException)

Aggregations

IItemCollectionPage (com.onedrive.sdk.extensions.IItemCollectionPage)1 IItemCollectionRequestBuilder (com.onedrive.sdk.extensions.IItemCollectionRequestBuilder)1 Item (com.onedrive.sdk.extensions.Item)1 OneDriveServiceException (com.onedrive.sdk.http.OneDriveServiceException)1 ArrayList (java.util.ArrayList)1