diff --git a/data/src/main/java/one/nem/lacerta/data/impl/LacertaLibraryImpl.java b/data/src/main/java/one/nem/lacerta/data/impl/LacertaLibraryImpl.java index e9ecee78..e080f7d0 100644 --- a/data/src/main/java/one/nem/lacerta/data/impl/LacertaLibraryImpl.java +++ b/data/src/main/java/one/nem/lacerta/data/impl/LacertaLibraryImpl.java @@ -1,6 +1,7 @@ package one.nem.lacerta.data.impl; import java.text.DateFormat; +import java.time.format.DateTimeFormatter; import java.util.ArrayList; import java.util.Collection; import java.util.List; @@ -16,6 +17,7 @@ import one.nem.lacerta.model.document.DocumentDetail; import one.nem.lacerta.source.database.LacertaDatabase; import one.nem.lacerta.source.database.common.DateTypeConverter; import one.nem.lacerta.source.database.entity.DocumentEntity; +import one.nem.lacerta.source.database.entity.FolderEntity; import one.nem.lacerta.utils.LacertaLogger; public class LacertaLibraryImpl implements LacertaLibrary { @@ -60,10 +62,48 @@ public class LacertaLibraryImpl implements LacertaLibrary { return null; // TODO-rca: Implement } + // Internal + private CompletableFuture> getFolderEntitiesByPublicPath(String publicPath) { + return CompletableFuture.supplyAsync(() -> { + return database.folderDao().findByPublicPathWithLimit(publicPath, 10); // TODO-rca: ハードコーディングやめる + }); + } + + private CompletableFuture> getDocumentEntitiesByPublicPath(String publicPath) { + return CompletableFuture.supplyAsync(() -> { + return database.documentDao().findByPublicPathWithLimit(publicPath, 10); // TODO-rca: ハードコーディングやめる + }); + } + @Override public CompletableFuture getLibraryPage(int limit) { return CompletableFuture.supplyAsync(() -> { - return null; + LibraryItemPage libraryItemPage = new LibraryItemPage(); + + List folderEntities = getFolderEntitiesByPublicPath("/").join(); + List documentEntities = getDocumentEntitiesByPublicPath("/").join(); + + ArrayList listItems = new ArrayList<>(); + for (FolderEntity folderEntity : folderEntities) { + ListItem listItem = new ListItem(); + listItem.setItemType(ListItemType.ITEM_TYPE_FOLDER); + listItem.setTitle(folderEntity.name); + listItem.setDescription("フォルダ"); // TODO-rca: ハードコーディングやめる + listItem.setItemId(folderEntity.id); + listItems.add(listItem); + } + for (DocumentEntity documentEntity : documentEntities) { + ListItem listItem = new ListItem(); + listItem.setItemType(ListItemType.ITEM_TYPE_DOCUMENT); + listItem.setTitle(documentEntity.title); + listItem.setDescription(DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm").format(documentEntity.updatedAt.toInstant())); + listItem.setItemId(documentEntity.id); + listItems.add(listItem); + } + + libraryItemPage.setListItems(listItems); + + return libraryItemPage; }); } diff --git a/source/src/main/java/one/nem/lacerta/source/database/dao/DocumentDao.java b/source/src/main/java/one/nem/lacerta/source/database/dao/DocumentDao.java index 802afb7f..f5f1eb61 100644 --- a/source/src/main/java/one/nem/lacerta/source/database/dao/DocumentDao.java +++ b/source/src/main/java/one/nem/lacerta/source/database/dao/DocumentDao.java @@ -6,6 +6,7 @@ import androidx.room.Insert; import androidx.room.Query; import androidx.room.Update; +import java.util.ArrayList; import java.util.List; import one.nem.lacerta.source.database.entity.DocumentEntity; diff --git a/source/src/main/java/one/nem/lacerta/source/database/dao/FolderDao.java b/source/src/main/java/one/nem/lacerta/source/database/dao/FolderDao.java index 1d429245..451854e5 100644 --- a/source/src/main/java/one/nem/lacerta/source/database/dao/FolderDao.java +++ b/source/src/main/java/one/nem/lacerta/source/database/dao/FolderDao.java @@ -4,6 +4,9 @@ import androidx.room.Dao; import androidx.room.Insert; import androidx.room.Query; +import java.util.ArrayList; +import java.util.List; + import one.nem.lacerta.source.database.entity.FolderEntity; @Dao @@ -15,6 +18,9 @@ public interface FolderDao { @Query("SELECT * FROM Folder WHERE public_path = :publicPath") FolderEntity findByPublicPath(String publicPath); + @Query("SELECT * FROM Folder WHERE public_path = :publicPath LIMIT :limit") + List findByPublicPathWithLimit(String publicPath, int limit); + @Insert void insert(FolderEntity folderEntity);