From 1d2f3345dfa54d6a25654e55ab24b404dfa9c438 Mon Sep 17 00:00:00 2001 From: r-ca Date: Sat, 20 Jan 2024 22:22:59 +0900 Subject: [PATCH 01/19] =?UTF-8?q?CompletableFeature=E3=82=92=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=E3=81=97=E3=81=A6=E5=87=A6=E7=90=86=E3=81=99=E3=82=8B?= =?UTF-8?q?=E3=82=88=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- data/src/main/java/one/nem/lacerta/data/Document.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/data/src/main/java/one/nem/lacerta/data/Document.java b/data/src/main/java/one/nem/lacerta/data/Document.java index 145a5905..0904c3a2 100644 --- a/data/src/main/java/one/nem/lacerta/data/Document.java +++ b/data/src/main/java/one/nem/lacerta/data/Document.java @@ -2,6 +2,7 @@ package one.nem.lacerta.data; import java.lang.reflect.Array; import java.util.ArrayList; +import java.util.concurrent.CompletableFuture; import one.nem.lacerta.model.document.DocumentMeta; import one.nem.lacerta.model.document.DocumentDetail; @@ -13,13 +14,13 @@ import one.nem.lacerta.model.document.tag.DocumentTag; */ public interface Document { - DocumentDetail createDocument(DocumentMeta meta); + CompletableFuture createDocument(DocumentMeta meta); - DocumentDetail createDocument(); + CompletableFuture createDocument(); - void deleteDocument(String documentId); + CompletableFuture deleteDocument(String documentId); - void updateDocument(DocumentMeta meta, DocumentDetail detail); + CompletableFuture updateDocument(DocumentMeta meta, DocumentDetail detail); - DocumentDetail getDocument(String documentId); + CompletableFuture getDocument(String documentId); } From acc5b166d51118605b3e249886e660d8060653c5 Mon Sep 17 00:00:00 2001 From: r-ca Date: Sat, 20 Jan 2024 22:24:12 +0900 Subject: [PATCH 02/19] =?UTF-8?q?CompletableFeature=E3=82=92=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=E3=81=97=E3=81=A6=E5=87=A6=E7=90=86=E3=81=99=E3=82=8B?= =?UTF-8?q?=E3=82=88=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../nem/lacerta/data/impl/DocumentImpl.java | 46 +++++++++---------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/data/src/main/java/one/nem/lacerta/data/impl/DocumentImpl.java b/data/src/main/java/one/nem/lacerta/data/impl/DocumentImpl.java index 1253d0a4..ab0f41ef 100644 --- a/data/src/main/java/one/nem/lacerta/data/impl/DocumentImpl.java +++ b/data/src/main/java/one/nem/lacerta/data/impl/DocumentImpl.java @@ -3,6 +3,7 @@ package one.nem.lacerta.data.impl; import java.util.ArrayList; import java.util.Date; import java.util.UUID; +import java.util.concurrent.CompletableFuture; // Hilt import javax.inject.Inject; @@ -49,31 +50,30 @@ public class DocumentImpl implements Document { @Override - public DocumentDetail createDocument(DocumentMeta meta) { - DocumentDetail detail = new DocumentDetail(); - detail.setMeta(meta); - detail.setPages(new ArrayList<>()); + public CompletableFuture createDocument(DocumentMeta meta) { + return CompletableFuture.supplyAsync(() -> { + DocumentDetail detail = new DocumentDetail(); + detail.setMeta(meta); + detail.setPages(new ArrayList<>()); + // Create DocumentEntity + DocumentEntity documentEntity = new DocumentEntity(); + documentEntity.id = meta.getId(); + documentEntity.title = meta.getTitle(); + documentEntity.author = meta.getAuthor(); + documentEntity.defaultBranch = meta.getDefaultBranch(); + documentEntity.updatedAt = meta.getUpdatedAt(); + documentEntity.createdAt = meta.getCreatedAt(); + documentEntity.publicPath = meta.getPath().getStringPath(); + documentEntity.tagIds = meta.getTagIds(); - // TODO-rca: UIスレッドから追い出す + database.documentDao().insert(documentEntity); - // Create DocumentEntity - DocumentEntity documentEntity = new DocumentEntity(); - documentEntity.id = meta.getId(); - documentEntity.title = meta.getTitle(); - documentEntity.author = meta.getAuthor(); - documentEntity.defaultBranch = meta.getDefaultBranch(); - documentEntity.updatedAt = meta.getUpdatedAt(); - documentEntity.createdAt = meta.getCreatedAt(); - documentEntity.publicPath = meta.getPath().getStringPath(); - documentEntity.tagIds = meta.getTagIds(); + // Vcs + LacertaVcs vcs = vcsFactory.create(meta.getId()); + vcs.createDocument(meta.getId()); - database.documentDao().insert(documentEntity); - - // Vcs - LacertaVcs vcs = vcsFactory.create(meta.getId()); - vcs.createDocument(meta.getId()); - - return detail; + return detail; + }); } @Override @@ -102,6 +102,6 @@ public class DocumentImpl implements Document { @Override public DocumentDetail getDocument(String documentId) { - return null; + } } From e6a4393b6d28415a9cf27114225c31b8e65af383 Mon Sep 17 00:00:00 2001 From: r-ca Date: Sat, 20 Jan 2024 22:39:35 +0900 Subject: [PATCH 03/19] =?UTF-8?q?=E9=9D=9E=E5=90=8C=E6=9C=9F=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../scanner/ScannerManagerActivity.java | 40 ++++++++++++------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/component/scanner/src/main/java/one/nem/lacerta/component/scanner/ScannerManagerActivity.java b/component/scanner/src/main/java/one/nem/lacerta/component/scanner/ScannerManagerActivity.java index f55484a1..70654993 100644 --- a/component/scanner/src/main/java/one/nem/lacerta/component/scanner/ScannerManagerActivity.java +++ b/component/scanner/src/main/java/one/nem/lacerta/component/scanner/ScannerManagerActivity.java @@ -1,5 +1,6 @@ package one.nem.lacerta.component.scanner; +import android.app.ProgressDialog; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.drawable.BitmapDrawable; @@ -22,6 +23,7 @@ import com.websitebeaver.documentscanner.DocumentScanner; import java.util.ArrayList; import java.util.Objects; +import java.util.concurrent.CompletableFuture; import javax.inject.Inject; @@ -152,21 +154,31 @@ public class ScannerManagerActivity extends AppCompatActivity { private void saveNewDocument() { logger.debug(TAG, "saveNewDocument"); + // Deprecatedだが、中断機能が存在しないので操作をブロックする目的で(意図的に)使用 + ProgressDialog dialog = new ProgressDialog(this); + dialog.setMessage("保存中..."); // TODO-rca: テキストをリソースに移動 DocumentMeta documentMeta = new DocumentMeta("Untitled"); // TODO-rca: デフォルトタイトルを指定できるようにする - DocumentDetail documentDetail = document.createDocument(documentMeta); - Bitmap[] bitmaps = new Bitmap[this.croppedImages.size()]; - this.croppedImages.toArray(bitmaps); - try { - documentProcessorFactory.create(documentDetail).addNewPagesToLast(bitmaps); - Toast.makeText(this, "Saved.", Toast.LENGTH_SHORT).show(); - lacertaVcsFactory.create(documentDetail.getMeta().getId()).generateRevisionAtCurrent("Initial commit"); - lacertaVcsFactory.create(documentDetail.getMeta().getId()).printLog(); // Debug - lacertaVcsFactory.create(documentDetail.getMeta().getId()).printRev(); // Debug - finish(); - } catch (Exception e) { - logger.error(TAG, "Error: " + e.getMessage()); - logger.e_code("9dff2a28-20e8-4ccd-9d04-f0c7646faa6a"); - } + document.createDocument(documentMeta).thenAccept((documentDetail1) -> { + Bitmap[] bitmaps = new Bitmap[this.croppedImages.size()]; + this.croppedImages.toArray(bitmaps); + addPagesToDocumentDetail(documentDetail1, bitmaps).thenRun(() -> { + dialog.dismiss(); + finish(); + }); + }); + + } + + private CompletableFuture addPagesToDocumentDetail(DocumentDetail documentDetail, Bitmap[] bitmaps) { + return CompletableFuture.runAsync(() -> { + try { + documentProcessorFactory.create(documentDetail).addNewPagesToLast(bitmaps); + lacertaVcsFactory.create(documentDetail.getMeta().getId()).generateRevisionAtCurrent("Initial commit"); + } catch (Exception e) { + logger.error(TAG, "Error: " + e.getMessage()); + logger.e_code("9dff2a28-20e8-4ccd-9d04-f0c7646faa6a"); + } + }); } private void insertToExistDocument() { From 176160cd8f188e2573b3efb19351b40354dea02b Mon Sep 17 00:00:00 2001 From: r-ca Date: Sat, 20 Jan 2024 22:40:03 +0900 Subject: [PATCH 04/19] =?UTF-8?q?createDocument=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- data/src/main/java/one/nem/lacerta/data/impl/DocumentImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/src/main/java/one/nem/lacerta/data/impl/DocumentImpl.java b/data/src/main/java/one/nem/lacerta/data/impl/DocumentImpl.java index ab0f41ef..22a6d20e 100644 --- a/data/src/main/java/one/nem/lacerta/data/impl/DocumentImpl.java +++ b/data/src/main/java/one/nem/lacerta/data/impl/DocumentImpl.java @@ -77,7 +77,7 @@ public class DocumentImpl implements Document { } @Override - public DocumentDetail createDocument() { + public CompletableFuture createDocument() { DocumentMeta meta = new DocumentMeta(); meta.setId(UUID.randomUUID().toString()); meta.setTitle("New Document"); From d47c6d0cc8d6025ee973681cf159d121e65b7e1a Mon Sep 17 00:00:00 2001 From: r-ca Date: Sat, 20 Jan 2024 22:40:59 +0900 Subject: [PATCH 05/19] =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/one/nem/lacerta/data/impl/DocumentImpl.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/data/src/main/java/one/nem/lacerta/data/impl/DocumentImpl.java b/data/src/main/java/one/nem/lacerta/data/impl/DocumentImpl.java index 22a6d20e..af3551db 100644 --- a/data/src/main/java/one/nem/lacerta/data/impl/DocumentImpl.java +++ b/data/src/main/java/one/nem/lacerta/data/impl/DocumentImpl.java @@ -91,13 +91,17 @@ public class DocumentImpl implements Document { } @Override - public void deleteDocument(String documentId) { - + public CompletableFuture deleteDocument(String documentId) { + return CompletableFuture.supplyAsync(() -> { + return null; + }); } @Override - public void updateDocument(DocumentMeta meta, DocumentDetail detail) { - + public CompletableFuture updateDocument(DocumentMeta meta, DocumentDetail detail) { + return CompletableFuture.supplyAsync(() -> { + return null; + }); } @Override From 5c17f96d3d4208a16ff3d8b76fbf6e7e39074d39 Mon Sep 17 00:00:00 2001 From: r-ca Date: Sat, 20 Jan 2024 22:59:00 +0900 Subject: [PATCH 06/19] =?UTF-8?q?=E3=83=89=E3=82=AD=E3=83=A5=E3=83=A1?= =?UTF-8?q?=E3=83=B3=E3=83=88=E3=82=92=E9=9D=9E=E5=90=8C=E6=9C=9F=E3=81=A7?= =?UTF-8?q?=E5=8F=96=E5=BE=97=E3=81=A7=E3=81=8D=E3=82=8B=E3=82=88=E3=81=86?= =?UTF-8?q?=E3=81=AB=E3=81=97=E3=81=9F=20WIP?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../nem/lacerta/data/impl/DocumentImpl.java | 79 ++++++++++++++++++- 1 file changed, 78 insertions(+), 1 deletion(-) diff --git a/data/src/main/java/one/nem/lacerta/data/impl/DocumentImpl.java b/data/src/main/java/one/nem/lacerta/data/impl/DocumentImpl.java index af3551db..0fec6757 100644 --- a/data/src/main/java/one/nem/lacerta/data/impl/DocumentImpl.java +++ b/data/src/main/java/one/nem/lacerta/data/impl/DocumentImpl.java @@ -1,5 +1,6 @@ package one.nem.lacerta.data.impl; +import java.io.IOException; import java.util.ArrayList; import java.util.Date; import java.util.UUID; @@ -17,13 +18,19 @@ import one.nem.lacerta.model.document.DocumentMeta; import one.nem.lacerta.model.document.DocumentDetail; // Lacerta/source +import one.nem.lacerta.model.document.internal.XmlMetaPageModel; +import one.nem.lacerta.model.document.page.Page; import one.nem.lacerta.source.database.LacertaDatabase; import one.nem.lacerta.source.database.entity.DocumentEntity; // Lacerta/utils +import one.nem.lacerta.source.file.FileManager; +import one.nem.lacerta.source.file.factory.FileManagerFactory; import one.nem.lacerta.utils.LacertaLogger; // Lacerta/vcs +import one.nem.lacerta.utils.XmlMetaParser; +import one.nem.lacerta.utils.repository.DeviceInfoUtils; import one.nem.lacerta.vcs.LacertaVcs; import one.nem.lacerta.vcs.factory.LacertaVcsFactory; @@ -41,6 +48,14 @@ public class DocumentImpl implements Document { @Inject LacertaVcsFactory vcsFactory; + @Inject + FileManagerFactory fileManagerFactory; + + @Inject + DeviceInfoUtils deviceInfoUtils; + + @Inject + XmlMetaParser xmlMetaParser; @Inject public DocumentImpl() { @@ -105,7 +120,69 @@ public class DocumentImpl implements Document { } @Override - public DocumentDetail getDocument(String documentId) { + public CompletableFuture getDocument(String documentId) { + return CompletableFuture.supplyAsync(() -> { + DocumentEntity documentEntity = database.documentDao().findById(documentId); + if (documentEntity == null) { + throw new IllegalArgumentException("documentId is not found"); + } + DocumentMeta meta = new DocumentMeta(); + meta.setId(documentEntity.id); + meta.setTitle(documentEntity.title); + meta.setAuthor(documentEntity.author); + meta.setDefaultBranch(documentEntity.defaultBranch); + meta.setUpdatedAt(documentEntity.updatedAt); + meta.setCreatedAt(documentEntity.createdAt); + meta.setPath(new PublicPath().resolve(documentEntity.publicPath)); + meta.setTags(new ArrayList<>()); // TODO-rca: タグを取得する + DocumentDetail detail = new DocumentDetail(); + + getPagesByXmlMeta(documentId).thenCompose(xmlMetaPageModels -> getPagesByXmlMetaPageModel(documentId, xmlMetaPageModels)).thenAccept(pages -> { + detail.setMeta(meta); + detail.setPages(pages); + }); + return detail; + }); + } + + private CompletableFuture> getPagesByXmlMeta(String documentId) { + return CompletableFuture.supplyAsync(() -> { + FileManager fileManager = fileManagerFactory.create(deviceInfoUtils.getExternalStorageDirectory()); + try { + return xmlMetaParser.deserialize(fileManager.resolve(documentId).loadXml("meta.xml")).getPages(); + } catch (IOException e) { + logger.error(TAG, "DocumentMeta parse error"); + logger.trace(TAG, e.getMessage()); + logger.e_code("db18c04a-1625-4871-9e4e-918d805568ac"); + } + return null; + }); + } + + private CompletableFuture> getPagesByXmlMetaPageModel(String documentId, ArrayList xmlMetaPageModels) { + return CompletableFuture.supplyAsync(() -> { + ArrayList pages = new ArrayList<>(); + FileManager fileManager; + try { + fileManager = fileManagerFactory.create(deviceInfoUtils.getExternalStorageDirectory()).resolve(documentId); + } catch (IOException e) { + logger.error(TAG, "FileManager resolve error"); + logger.trace(TAG, e.getMessage()); + logger.e_code("2235e8ee-4177-46f8-af6b-084381b202e6"); + return null; + } + for (XmlMetaPageModel xmlMetaPageModel : xmlMetaPageModels) { + try { + pages.add(new Page(xmlMetaPageModel.getFilename(), fileManager.loadBitmap(xmlMetaPageModel.getFilename()))); + } catch (IOException e) { + logger.error(TAG, "Bitmap decode error"); + logger.trace(TAG, e.getMessage()); + logger.e_code("3bba8c8f-90fb-4a24-a726-7ea201929f8b"); + return null; + } + } + return pages; + }); } } From 9aea4bb90e9335dff9f576a93c3cd034cfe156ee Mon Sep 17 00:00:00 2001 From: r-ca Date: Sat, 20 Jan 2024 23:00:21 +0900 Subject: [PATCH 07/19] =?UTF-8?q?LacertaLibrary=E3=81=AE=E3=82=B9=E3=82=BF?= =?UTF-8?q?=E3=83=96=E3=82=92=E5=BB=83=E6=AD=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../data/impl/LacertaLibraryStubImpl.java | 438 +++++++++--------- .../data/module/LacertaLibraryModule.java | 4 +- 2 files changed, 221 insertions(+), 221 deletions(-) diff --git a/data/src/main/java/one/nem/lacerta/data/impl/LacertaLibraryStubImpl.java b/data/src/main/java/one/nem/lacerta/data/impl/LacertaLibraryStubImpl.java index df5aec9a..bebea642 100644 --- a/data/src/main/java/one/nem/lacerta/data/impl/LacertaLibraryStubImpl.java +++ b/data/src/main/java/one/nem/lacerta/data/impl/LacertaLibraryStubImpl.java @@ -1,219 +1,219 @@ -package one.nem.lacerta.data.impl; - -import one.nem.lacerta.data.LacertaLibrary; -import one.nem.lacerta.model.LibraryItemPage; -import one.nem.lacerta.model.ListItem; -import one.nem.lacerta.model.ListItemType; -import one.nem.lacerta.model.document.DocumentDetail; - -import one.nem.lacerta.model.document.DocumentMeta; -import one.nem.lacerta.model.document.path.DocumentPath; -import one.nem.lacerta.utils.LacertaLogger; - -import com.github.javafaker.DateAndTime; -import com.github.javafaker.Faker; - -import java.text.DateFormat; -import java.util.ArrayList; -import java.util.Objects; -import java.util.UUID; - -import javax.inject.Inject; - -/** - * LacertaLibraryのスタブ実装 - */ -public class LacertaLibraryStubImpl implements LacertaLibrary { - - LacertaLogger logger; - - Faker faker; - - @Inject - public LacertaLibraryStubImpl(LacertaLogger logger) { - faker = new Faker(); // Init Faker - this.logger = logger; - logger.debug("LibraryStub", "Initialized"); - } - - // Internal Methods - - // Generate Stub Data - private LibraryItemPage generateStubLibraryItemPage(int limit, String pageId) { - logger.debug("LibraryStub", "generateStubLibraryItemPage"); - ArrayList listItems = new ArrayList<>(); - int itemTotal = faker.number().numberBetween(1, limit); // 実際に返却するアイテム数を決定 - int folderTotal; - // フォルダ数の抽選 - if (itemTotal > 4) { - folderTotal = faker.number().numberBetween(1, itemTotal - 2); - } - else { - if (itemTotal > 2) { - folderTotal = 1; - } - else { // ドキュメント数がゼロにならないように - folderTotal = 0; - } - } - int documentTotal = itemTotal - folderTotal; // ドキュメント数を決定 - logger.debug("LibraryStub", "itemTotal: " + itemTotal); - logger.debug("LibraryStub", "folderTotal: " + folderTotal); - logger.debug("LibraryStub", "documentTotal: " + documentTotal); - - // フォルダを生成 - for (int i = 0; i < folderTotal; i++) { - listItems.add(generateStubListItem(ListItemType.ITEM_TYPE_FOLDER)); - } - // ドキュメントを生成 - for (int i = 0; i < documentTotal; i++) { - listItems.add(generateStubListItem(ListItemType.ITEM_TYPE_DOCUMENT)); - } - - LibraryItemPage libraryItemPage = new LibraryItemPage(); - libraryItemPage.setListItems(listItems); - if (pageId == null) { - libraryItemPage.setPageId(UUID.randomUUID().toString()); - } else { - libraryItemPage.setPageId(pageId); - } - libraryItemPage.setPageTitle("FakePage" + faker.number().digits(3)); - - return libraryItemPage; - } - - private ListItem generateStubListItem(ListItemType itemType) { - if (itemType == ListItemType.ITEM_TYPE_FOLDER) { - ListItem listItem = new ListItem(); - listItem.setTitle("FakeFolder" + faker.number().digits(3)); - listItem.setDescription("Updated at " + DateFormat.getDateTimeInstance().format(faker.date().birthday())); - listItem.setItemType(ListItemType.ITEM_TYPE_FOLDER); - listItem.setItemId(UUID.randomUUID().toString()); - return listItem; - } else if (itemType == ListItemType.ITEM_TYPE_DOCUMENT) { - ListItem listItem = new ListItem(); - listItem.setTitle("FakeDocument" + faker.book().title()); - listItem.setDescription("Updated at " + DateFormat.getDateTimeInstance().format(faker.date().birthday())); - listItem.setItemType(ListItemType.ITEM_TYPE_DOCUMENT); - listItem.setItemId(UUID.randomUUID().toString()); - return listItem; - } else { - return null; - } - } - - private LibraryItemPage getRecentDocumentPage(int limit) { - int itemTotal = faker.number().numberBetween(1, limit); - ArrayList listItems = new ArrayList<>(); - for (int i = 0; i < itemTotal; i++) { - listItems.add(generateStubListItem(ListItemType.ITEM_TYPE_DOCUMENT)); - } - // DescriptionからDateを抽出して新しい順にソート - listItems.sort((a, b) -> { - String aDate = a.getDescription().substring(11); - String bDate = b.getDescription().substring(11); - return bDate.compareTo(aDate); - }); - LibraryItemPage libraryItemPage = new LibraryItemPage(); - libraryItemPage.setListItems(listItems); - libraryItemPage.setPageId(UUID.randomUUID().toString()); - libraryItemPage.setPageTitle("RecentDocument"); - return libraryItemPage; - } - - private DocumentDetail generateStubDocumentDetail(String id) throws IllegalArgumentException { - - if (Objects.isNull(id)) { - throw new IllegalArgumentException("id is null"); - } - - DocumentMeta documentMeta = new DocumentMeta(); - documentMeta.setId(id); - documentMeta.setTitle("FakeDocument" + faker.book().title()); - documentMeta.setCreatedAt(faker.date().birthday()); - documentMeta.setUpdatedAt(faker.date().birthday()); // TODO-rca: 更新日のほうが古くなることがあるのでなんとかする? - ArrayList tagIds = new ArrayList<>(); - - DocumentDetail documentDetail = new DocumentDetail(); - documentDetail.setMeta(documentMeta); -// documentDetail.setPath(null); // TODO-rca: なんとかする -// documentDetail.setAuthor(faker.name().fullName()); -// documentDetail.setRepository(null); // TODO-rca: なんとかする - return documentDetail; - } - - /** - * 履歴ページを取得する - * @param limit 取得するアイテム数 - * @return ページオブジェクト - */ - @Override - public ArrayList getRecentDocument(int limit) { - return getRecentDocumentPage(limit).getListItems(); - } - - /** - * 履歴ページを取得する - * @param limit 取得するアイテム数 - * @param offset 取得するアイテムのオフセット - * @return ページオブジェクト - */ - @Override - public ArrayList getRecentDocument(int limit, int offset) { - return getRecentDocumentPage(limit).getListItems(); - } - - /** - * ライブラリページを取得する - * @param limit 取得するアイテム数 - * @return ページオブジェクト - */ - @Override - public LibraryItemPage getLibraryPage(int limit) { - return generateStubLibraryItemPage(limit, null); - } - - /** - * ライブラリページを取得する - * @param limit 取得するアイテム数 - * @param offset 取得するアイテムのオフセット - * @return ページオブジェクト - */ - @Override - public LibraryItemPage getLibraryPage(int limit, int offset) { - return generateStubLibraryItemPage(limit, null); - } - - /** - * ライブラリページを取得する - * @param pageId ページID - * @param limit 取得するアイテム数 - * @return ページオブジェクト - */ - @Override - public LibraryItemPage getLibraryPage(String pageId, int limit) { - return generateStubLibraryItemPage(limit, pageId); - } - - /** - * ライブラリページを取得する - * @param pageId ページID - * @param limit 取得するアイテム数 - * @param offset 取得するアイテムのオフセット - * @return ページオブジェクト - */ - @Override - public LibraryItemPage getLibraryPage(String pageId, int limit, int offset) { - return generateStubLibraryItemPage(limit, pageId); - } - - /** - * ドキュメント詳細を取得する - * @param id ドキュメントID - * @return ドキュメント詳細オブジェクト - */ - @Override - public DocumentDetail getDocumentDetailById(String id) throws IllegalArgumentException { - return generateStubDocumentDetail(id); - } -} +//package one.nem.lacerta.data.impl; +// +//import one.nem.lacerta.data.LacertaLibrary; +//import one.nem.lacerta.model.LibraryItemPage; +//import one.nem.lacerta.model.ListItem; +//import one.nem.lacerta.model.ListItemType; +//import one.nem.lacerta.model.document.DocumentDetail; +// +//import one.nem.lacerta.model.document.DocumentMeta; +//import one.nem.lacerta.model.document.path.DocumentPath; +//import one.nem.lacerta.utils.LacertaLogger; +// +//import com.github.javafaker.DateAndTime; +//import com.github.javafaker.Faker; +// +//import java.text.DateFormat; +//import java.util.ArrayList; +//import java.util.Objects; +//import java.util.UUID; +// +//import javax.inject.Inject; +// +///** +// * LacertaLibraryのスタブ実装 +// */ +//public class LacertaLibraryStubImpl implements LacertaLibrary { +// +// LacertaLogger logger; +// +// Faker faker; +// +// @Inject +// public LacertaLibraryStubImpl(LacertaLogger logger) { +// faker = new Faker(); // Init Faker +// this.logger = logger; +// logger.debug("LibraryStub", "Initialized"); +// } +// +// // Internal Methods +// +// // Generate Stub Data +// private LibraryItemPage generateStubLibraryItemPage(int limit, String pageId) { +// logger.debug("LibraryStub", "generateStubLibraryItemPage"); +// ArrayList listItems = new ArrayList<>(); +// int itemTotal = faker.number().numberBetween(1, limit); // 実際に返却するアイテム数を決定 +// int folderTotal; +// // フォルダ数の抽選 +// if (itemTotal > 4) { +// folderTotal = faker.number().numberBetween(1, itemTotal - 2); +// } +// else { +// if (itemTotal > 2) { +// folderTotal = 1; +// } +// else { // ドキュメント数がゼロにならないように +// folderTotal = 0; +// } +// } +// int documentTotal = itemTotal - folderTotal; // ドキュメント数を決定 +// logger.debug("LibraryStub", "itemTotal: " + itemTotal); +// logger.debug("LibraryStub", "folderTotal: " + folderTotal); +// logger.debug("LibraryStub", "documentTotal: " + documentTotal); +// +// // フォルダを生成 +// for (int i = 0; i < folderTotal; i++) { +// listItems.add(generateStubListItem(ListItemType.ITEM_TYPE_FOLDER)); +// } +// // ドキュメントを生成 +// for (int i = 0; i < documentTotal; i++) { +// listItems.add(generateStubListItem(ListItemType.ITEM_TYPE_DOCUMENT)); +// } +// +// LibraryItemPage libraryItemPage = new LibraryItemPage(); +// libraryItemPage.setListItems(listItems); +// if (pageId == null) { +// libraryItemPage.setPageId(UUID.randomUUID().toString()); +// } else { +// libraryItemPage.setPageId(pageId); +// } +// libraryItemPage.setPageTitle("FakePage" + faker.number().digits(3)); +// +// return libraryItemPage; +// } +// +// private ListItem generateStubListItem(ListItemType itemType) { +// if (itemType == ListItemType.ITEM_TYPE_FOLDER) { +// ListItem listItem = new ListItem(); +// listItem.setTitle("FakeFolder" + faker.number().digits(3)); +// listItem.setDescription("Updated at " + DateFormat.getDateTimeInstance().format(faker.date().birthday())); +// listItem.setItemType(ListItemType.ITEM_TYPE_FOLDER); +// listItem.setItemId(UUID.randomUUID().toString()); +// return listItem; +// } else if (itemType == ListItemType.ITEM_TYPE_DOCUMENT) { +// ListItem listItem = new ListItem(); +// listItem.setTitle("FakeDocument" + faker.book().title()); +// listItem.setDescription("Updated at " + DateFormat.getDateTimeInstance().format(faker.date().birthday())); +// listItem.setItemType(ListItemType.ITEM_TYPE_DOCUMENT); +// listItem.setItemId(UUID.randomUUID().toString()); +// return listItem; +// } else { +// return null; +// } +// } +// +// private LibraryItemPage getRecentDocumentPage(int limit) { +// int itemTotal = faker.number().numberBetween(1, limit); +// ArrayList listItems = new ArrayList<>(); +// for (int i = 0; i < itemTotal; i++) { +// listItems.add(generateStubListItem(ListItemType.ITEM_TYPE_DOCUMENT)); +// } +// // DescriptionからDateを抽出して新しい順にソート +// listItems.sort((a, b) -> { +// String aDate = a.getDescription().substring(11); +// String bDate = b.getDescription().substring(11); +// return bDate.compareTo(aDate); +// }); +// LibraryItemPage libraryItemPage = new LibraryItemPage(); +// libraryItemPage.setListItems(listItems); +// libraryItemPage.setPageId(UUID.randomUUID().toString()); +// libraryItemPage.setPageTitle("RecentDocument"); +// return libraryItemPage; +// } +// +// private DocumentDetail generateStubDocumentDetail(String id) throws IllegalArgumentException { +// +// if (Objects.isNull(id)) { +// throw new IllegalArgumentException("id is null"); +// } +// +// DocumentMeta documentMeta = new DocumentMeta(); +// documentMeta.setId(id); +// documentMeta.setTitle("FakeDocument" + faker.book().title()); +// documentMeta.setCreatedAt(faker.date().birthday()); +// documentMeta.setUpdatedAt(faker.date().birthday()); // TODO-rca: 更新日のほうが古くなることがあるのでなんとかする? +// ArrayList tagIds = new ArrayList<>(); +// +// DocumentDetail documentDetail = new DocumentDetail(); +// documentDetail.setMeta(documentMeta); +//// documentDetail.setPath(null); // TODO-rca: なんとかする +//// documentDetail.setAuthor(faker.name().fullName()); +//// documentDetail.setRepository(null); // TODO-rca: なんとかする +// return documentDetail; +// } +// +// /** +// * 履歴ページを取得する +// * @param limit 取得するアイテム数 +// * @return ページオブジェクト +// */ +// @Override +// public ArrayList getRecentDocument(int limit) { +// return getRecentDocumentPage(limit).getListItems(); +// } +// +// /** +// * 履歴ページを取得する +// * @param limit 取得するアイテム数 +// * @param offset 取得するアイテムのオフセット +// * @return ページオブジェクト +// */ +// @Override +// public ArrayList getRecentDocument(int limit, int offset) { +// return getRecentDocumentPage(limit).getListItems(); +// } +// +// /** +// * ライブラリページを取得する +// * @param limit 取得するアイテム数 +// * @return ページオブジェクト +// */ +// @Override +// public LibraryItemPage getLibraryPage(int limit) { +// return generateStubLibraryItemPage(limit, null); +// } +// +// /** +// * ライブラリページを取得する +// * @param limit 取得するアイテム数 +// * @param offset 取得するアイテムのオフセット +// * @return ページオブジェクト +// */ +// @Override +// public LibraryItemPage getLibraryPage(int limit, int offset) { +// return generateStubLibraryItemPage(limit, null); +// } +// +// /** +// * ライブラリページを取得する +// * @param pageId ページID +// * @param limit 取得するアイテム数 +// * @return ページオブジェクト +// */ +// @Override +// public LibraryItemPage getLibraryPage(String pageId, int limit) { +// return generateStubLibraryItemPage(limit, pageId); +// } +// +// /** +// * ライブラリページを取得する +// * @param pageId ページID +// * @param limit 取得するアイテム数 +// * @param offset 取得するアイテムのオフセット +// * @return ページオブジェクト +// */ +// @Override +// public LibraryItemPage getLibraryPage(String pageId, int limit, int offset) { +// return generateStubLibraryItemPage(limit, pageId); +// } +// +// /** +// * ドキュメント詳細を取得する +// * @param id ドキュメントID +// * @return ドキュメント詳細オブジェクト +// */ +// @Override +// public DocumentDetail getDocumentDetailById(String id) throws IllegalArgumentException { +// return generateStubDocumentDetail(id); +// } +//} diff --git a/data/src/main/java/one/nem/lacerta/data/module/LacertaLibraryModule.java b/data/src/main/java/one/nem/lacerta/data/module/LacertaLibraryModule.java index 6c98e653..abf17b27 100644 --- a/data/src/main/java/one/nem/lacerta/data/module/LacertaLibraryModule.java +++ b/data/src/main/java/one/nem/lacerta/data/module/LacertaLibraryModule.java @@ -7,7 +7,7 @@ import dagger.hilt.android.components.FragmentComponent; import dagger.hilt.migration.DisableInstallInCheck; import one.nem.lacerta.data.LacertaLibrary; -import one.nem.lacerta.data.impl.LacertaLibraryStubImpl; +import one.nem.lacerta.data.impl.LacertaLibraryImpl; import one.nem.lacerta.utils.LacertaLogger; @Module @@ -16,6 +16,6 @@ import one.nem.lacerta.utils.LacertaLogger; abstract public class LacertaLibraryModule { @Binds - public abstract LacertaLibrary bindLacertaLibrary(LacertaLibraryStubImpl impl); + public abstract LacertaLibrary bindLacertaLibrary(LacertaLibraryImpl impl); } From 9efecab4b6aa27ac3c86d803dc20bce6802fc001 Mon Sep 17 00:00:00 2001 From: r-ca Date: Sat, 20 Jan 2024 23:00:57 +0900 Subject: [PATCH 08/19] =?UTF-8?q?=E3=82=B3=E3=83=B3=E3=82=B9=E3=83=88?= =?UTF-8?q?=E3=83=A9=E3=82=AF=E3=82=BF=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/one/nem/lacerta/data/impl/LacertaLibraryImpl.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) 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 01a7209f..3a182552 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 @@ -18,11 +18,14 @@ import one.nem.lacerta.utils.LacertaLogger; public class LacertaLibraryImpl implements LacertaLibrary { - @Inject LacertaLogger logger; + LacertaDatabase database; @Inject - LacertaDatabase database; + public LacertaLibraryImpl(LacertaLogger logger, LacertaDatabase database) { + this.logger = logger; + this.database = database; + } @Override public ArrayList getRecentDocument(int limit) { From df22a754b7b5fce1807ee656f0d8e6d41a786aaa Mon Sep 17 00:00:00 2001 From: r-ca Date: Sat, 20 Jan 2024 23:07:17 +0900 Subject: [PATCH 09/19] =?UTF-8?q?ProgressDialog=E3=82=92Show=E3=81=97?= =?UTF-8?q?=E3=81=A6=E3=81=84=E3=81=AA=E3=81=8B=E3=81=A3=E3=81=9F=E3=81=AE?= =?UTF-8?q?=E3=81=A7=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../nem/lacerta/component/scanner/ScannerManagerActivity.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/component/scanner/src/main/java/one/nem/lacerta/component/scanner/ScannerManagerActivity.java b/component/scanner/src/main/java/one/nem/lacerta/component/scanner/ScannerManagerActivity.java index 70654993..3603ff12 100644 --- a/component/scanner/src/main/java/one/nem/lacerta/component/scanner/ScannerManagerActivity.java +++ b/component/scanner/src/main/java/one/nem/lacerta/component/scanner/ScannerManagerActivity.java @@ -157,6 +157,9 @@ public class ScannerManagerActivity extends AppCompatActivity { // Deprecatedだが、中断機能が存在しないので操作をブロックする目的で(意図的に)使用 ProgressDialog dialog = new ProgressDialog(this); dialog.setMessage("保存中..."); // TODO-rca: テキストをリソースに移動 + dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); + dialog.setCancelable(false); + dialog.show(); DocumentMeta documentMeta = new DocumentMeta("Untitled"); // TODO-rca: デフォルトタイトルを指定できるようにする document.createDocument(documentMeta).thenAccept((documentDetail1) -> { Bitmap[] bitmaps = new Bitmap[this.croppedImages.size()]; From 4ab13508c46043afa5e5daf51910af6d0f6fcea2 Mon Sep 17 00:00:00 2001 From: r-ca Date: Sat, 20 Jan 2024 23:08:49 +0900 Subject: [PATCH 10/19] =?UTF-8?q?Interface=E3=82=92CompletableFuture?= =?UTF-8?q?=E3=81=AB=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/one/nem/lacerta/data/LacertaLibrary.java | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/data/src/main/java/one/nem/lacerta/data/LacertaLibrary.java b/data/src/main/java/one/nem/lacerta/data/LacertaLibrary.java index eeb8546b..cb19b425 100644 --- a/data/src/main/java/one/nem/lacerta/data/LacertaLibrary.java +++ b/data/src/main/java/one/nem/lacerta/data/LacertaLibrary.java @@ -1,6 +1,7 @@ package one.nem.lacerta.data; import java.util.ArrayList; +import java.util.concurrent.CompletableFuture; import one.nem.lacerta.model.ListItem; import one.nem.lacerta.model.ListItemType; @@ -11,15 +12,13 @@ import one.nem.lacerta.model.document.DocumentDetail; public interface LacertaLibrary { // Get History - ArrayList getRecentDocument(int limit); - ArrayList getRecentDocument(int limit, int offset); + CompletableFuture> getRecentDocument(int limit); + CompletableFuture> getRecentDocument(int limit, int offset); // Get Library page - LibraryItemPage getLibraryPage(int limit); - LibraryItemPage getLibraryPage(int limit, int offset); - LibraryItemPage getLibraryPage(String pageId, int limit); - LibraryItemPage getLibraryPage(String pageId, int limit, int offset); + CompletableFuture getLibraryPage(int limit); + CompletableFuture getLibraryPage(int limit, int offset); + CompletableFuture getLibraryPage(String pageId, int limit); + CompletableFuture getLibraryPage(String pageId, int limit, int offset); - // GetDocument - DocumentDetail getDocumentDetailById(String id); // TODO-rca: Documentに統合する } From 4e5aab276adc95d095914e0e34ec69cb82f4904a Mon Sep 17 00:00:00 2001 From: r-ca Date: Sat, 20 Jan 2024 23:17:31 +0900 Subject: [PATCH 11/19] =?UTF-8?q?getRecentDocument=E3=82=92=E9=9D=9E?= =?UTF-8?q?=E5=90=8C=E6=9C=9F=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lacerta/data/impl/LacertaLibraryImpl.java | 31 +++++++++++-------- 1 file changed, 18 insertions(+), 13 deletions(-) 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 3a182552..086005f8 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 @@ -2,7 +2,9 @@ package one.nem.lacerta.data.impl; import java.text.DateFormat; import java.util.ArrayList; +import java.util.Collection; import java.util.List; +import java.util.concurrent.CompletableFuture; import javax.inject.Inject; @@ -28,23 +30,26 @@ public class LacertaLibraryImpl implements LacertaLibrary { } @Override - public ArrayList getRecentDocument(int limit) { - List documentEntities = database.documentDao().getRecentDocument(limit); + public CompletableFuture> getRecentDocument(int limit) { + return CompletableFuture.supplyAsync(() -> { + List documentEntities = database.documentDao().getRecentDocument(limit); - ArrayList listItems = new ArrayList<>(); - for (DocumentEntity documentEntity : documentEntities) { - ListItem listItem = new ListItem(); - listItem.setItemType(ListItemType.ITEM_TYPE_DOCUMENT); - listItem.setTitle(documentEntity.title); - listItem.setDescription(DateFormat.getDateInstance().format(documentEntity.updatedAt)); - listItem.setItemId(documentEntity.id); - listItems.add(listItem); - } - return listItems; + ArrayList listItems = new ArrayList<>(); + for (DocumentEntity documentEntity : documentEntities) { + ListItem listItem = new ListItem(); + listItem.setItemType(ListItemType.ITEM_TYPE_DOCUMENT); + listItem.setTitle(documentEntity.title); + listItem.setDescription(DateFormat.getDateInstance().format(documentEntity.updatedAt)); + listItem.setItemId(documentEntity.id); + listItems.add(listItem); + } + + return listItems; + }); } @Override - public ArrayList getRecentDocument(int limit, int offset) { + public CompletableFuture> getRecentDocument(int limit, int offset) { return null; // TODO-rca: Implement } From 7214da80fa99e97c97b7cfbf613bd5ef707971cf Mon Sep 17 00:00:00 2001 From: r-ca Date: Sat, 20 Jan 2024 23:19:20 +0900 Subject: [PATCH 12/19] =?UTF-8?q?=E4=BB=AE=E7=BD=AE=E3=81=8D=E3=82=92?= =?UTF-8?q?=E9=9D=9E=E5=90=8C=E6=9C=9F=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lacerta/data/impl/LacertaLibraryImpl.java | 29 ++++++++++--------- 1 file changed, 16 insertions(+), 13 deletions(-) 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 086005f8..0c78b2e6 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 @@ -54,27 +54,30 @@ public class LacertaLibraryImpl implements LacertaLibrary { } @Override - public LibraryItemPage getLibraryPage(int limit) { - return null; + public CompletableFuture getLibraryPage(int limit) { + return CompletableFuture.supplyAsync(() -> { + return null; + }); } @Override - public LibraryItemPage getLibraryPage(int limit, int offset) { - return null; + public CompletableFuture getLibraryPage(int limit, int offset) { + return CompletableFuture.supplyAsync(() -> { + return null; + }); } @Override - public LibraryItemPage getLibraryPage(String pageId, int limit) { - return null; + public CompletableFuture getLibraryPage(String pageId, int limit) { + return CompletableFuture.supplyAsync(() -> { + return null; + }); } @Override - public LibraryItemPage getLibraryPage(String pageId, int limit, int offset) { - return null; - } - - @Override - public DocumentDetail getDocumentDetailById(String id) { - return null; + public CompletableFuture getLibraryPage(String pageId, int limit, int offset) { + return CompletableFuture.supplyAsync(() -> { + return null; + }); } } From 1b70b444f2eea456fe8f9d8ba954246f0682035c Mon Sep 17 00:00:00 2001 From: r-ca Date: Sat, 20 Jan 2024 23:23:54 +0900 Subject: [PATCH 13/19] =?UTF-8?q?=E3=82=B3=E3=83=B3=E3=82=B9=E3=83=88?= =?UTF-8?q?=E3=83=A9=E3=82=AF=E3=82=BF=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../one/nem/lacerta/feature/home/ListItemAdapter.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/feature/home/src/main/java/one/nem/lacerta/feature/home/ListItemAdapter.java b/feature/home/src/main/java/one/nem/lacerta/feature/home/ListItemAdapter.java index 1c2698d3..840064b4 100644 --- a/feature/home/src/main/java/one/nem/lacerta/feature/home/ListItemAdapter.java +++ b/feature/home/src/main/java/one/nem/lacerta/feature/home/ListItemAdapter.java @@ -21,6 +21,14 @@ public class ListItemAdapter extends RecyclerView.Adapter(); + } + + public void setListItems(ArrayList listItems) { + this.listItems = listItems; + } + @NonNull @Override public ListItemAdapter.ListItemViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { From ce3f9ebfd73a18d0151e97507394face77283ab1 Mon Sep 17 00:00:00 2001 From: r-ca Date: Sat, 20 Jan 2024 23:30:09 +0900 Subject: [PATCH 14/19] =?UTF-8?q?=E3=82=A8=E3=83=A9=E3=83=BC=E5=9B=9E?= =?UTF-8?q?=E9=81=BF(=E6=9A=AB=E5=AE=9A,=20=E5=BB=83=E6=AD=A2=E4=BA=88?= =?UTF-8?q?=E5=AE=9A)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../feature/debug/DebugMenuLibraryItemListPageFragment.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/feature/debug/src/main/java/one/nem/lacerta/feature/debug/DebugMenuLibraryItemListPageFragment.java b/feature/debug/src/main/java/one/nem/lacerta/feature/debug/DebugMenuLibraryItemListPageFragment.java index 35b9d263..cb5ae57e 100644 --- a/feature/debug/src/main/java/one/nem/lacerta/feature/debug/DebugMenuLibraryItemListPageFragment.java +++ b/feature/debug/src/main/java/one/nem/lacerta/feature/debug/DebugMenuLibraryItemListPageFragment.java @@ -57,7 +57,8 @@ public class DebugMenuLibraryItemListPageFragment extends Fragment { // Inflate the layout for this fragment View view = inflater.inflate(R.layout.fragment_debug_menu_library_item_list_page, container, false); - ArrayList listItems = lacertaLibrary.getRecentDocument(10); +// ArrayList listItems = lacertaLibrary.getRecentDocument(10); + ArrayList listItems = new ArrayList<>(); for (ListItem listItem : listItems) { System.out.println(listItem.getTitle()); } From 11e32572ef09b0ee8a9b0088a56d31928a4a43d3 Mon Sep 17 00:00:00 2001 From: r-ca Date: Sat, 20 Jan 2024 23:30:14 +0900 Subject: [PATCH 15/19] =?UTF-8?q?=E3=82=A8=E3=83=A9=E3=83=BC=E5=9B=9E?= =?UTF-8?q?=E9=81=BF(=E6=9A=AB=E5=AE=9A,=20=E5=BB=83=E6=AD=A2=E4=BA=88?= =?UTF-8?q?=E5=AE=9A)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lacerta/data/impl/LacertaSearchStubImpl.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/data/src/main/java/one/nem/lacerta/data/impl/LacertaSearchStubImpl.java b/data/src/main/java/one/nem/lacerta/data/impl/LacertaSearchStubImpl.java index b6076cfd..e0ba38a7 100644 --- a/data/src/main/java/one/nem/lacerta/data/impl/LacertaSearchStubImpl.java +++ b/data/src/main/java/one/nem/lacerta/data/impl/LacertaSearchStubImpl.java @@ -30,9 +30,10 @@ public class LacertaSearchStubImpl implements LacertaSearch { */ @Override public ArrayList autoSearch(String query, int limit) { - logger.debug("SearchStub", "autoSearch"); - logger.debug("SearchStub", "query: " + query); - return library.getLibraryPage(limit).getListItems(); +// logger.debug("SearchStub", "autoSearch"); +// logger.debug("SearchStub", "query: " + query); +// return library.getLibraryPage(limit).getListItems(); + return null; } /** @@ -44,8 +45,9 @@ public class LacertaSearchStubImpl implements LacertaSearch { */ @Override public ArrayList autoSearch(String query, int limit, int offset) { - logger.debug("SearchStub", "autoSearch"); - logger.debug("SearchStub", "query: " + query); - return library.getLibraryPage(limit, offset).getListItems(); +// logger.debug("SearchStub", "autoSearch"); +// logger.debug("SearchStub", "query: " + query); +// return library.getLibraryPage(limit, offset).getListItems(); + return null; } } From aaff0be4380c1e55440ac76bfc78df98debdebd5 Mon Sep 17 00:00:00 2001 From: r-ca Date: Sat, 20 Jan 2024 23:40:32 +0900 Subject: [PATCH 16/19] Debug --- .../java/one/nem/lacerta/data/impl/LacertaLibraryImpl.java | 7 +++++++ 1 file changed, 7 insertions(+) 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 0c78b2e6..82747715 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 @@ -32,6 +32,13 @@ public class LacertaLibraryImpl implements LacertaLibrary { @Override public CompletableFuture> getRecentDocument(int limit) { return CompletableFuture.supplyAsync(() -> { + // 5秒フリーズさせる + try { + Thread.sleep(5000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + List documentEntities = database.documentDao().getRecentDocument(limit); ArrayList listItems = new ArrayList<>(); From 12ba9234a46fbd1c51c11366421c51842e7dd6d7 Mon Sep 17 00:00:00 2001 From: r-ca Date: Sat, 20 Jan 2024 23:49:13 +0900 Subject: [PATCH 17/19] =?UTF-8?q?=E9=81=85=E3=82=8C=E3=81=A6=E8=BF=BD?= =?UTF-8?q?=E5=8A=A0=E3=81=95=E3=82=8C=E3=81=9F=E3=82=A2=E3=82=A4=E3=83=86?= =?UTF-8?q?=E3=83=A0=E3=82=92UI=E3=81=AB=E5=8F=8D=E6=98=A0=E3=81=A7?= =?UTF-8?q?=E3=81=8D=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lacerta/feature/home/HomeTopFragment.java | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/feature/home/src/main/java/one/nem/lacerta/feature/home/HomeTopFragment.java b/feature/home/src/main/java/one/nem/lacerta/feature/home/HomeTopFragment.java index 46a452d5..f8cc7ba2 100644 --- a/feature/home/src/main/java/one/nem/lacerta/feature/home/HomeTopFragment.java +++ b/feature/home/src/main/java/one/nem/lacerta/feature/home/HomeTopFragment.java @@ -15,6 +15,7 @@ import androidx.appcompat.widget.Toolbar; import androidx.core.content.ContextCompat; import androidx.drawerlayout.widget.DrawerLayout; import androidx.fragment.app.Fragment; +import androidx.recyclerview.widget.DefaultItemAnimator; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; @@ -23,6 +24,7 @@ import com.google.android.material.appbar.CollapsingToolbarLayout; import java.util.ArrayList; import java.util.List; +import java.util.concurrent.CompletableFuture; import javax.inject.Inject; @@ -67,18 +69,6 @@ public class HomeTopFragment extends Fragment { // Inflate the layout for this fragment View view = inflater.inflate(R.layout.fragment_home_top, container, false); - ArrayList recentDocument = lacertaLibrary.getRecentDocument(10); - - Log.d("docs", Integer.toString(recentDocument.size())); - - RecyclerView recyclerView = view.findViewById(R.id.home_item_recycler_view); - - recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); - - ListItemAdapter listItemAdapter = new ListItemAdapter(recentDocument); - - recyclerView.setAdapter(listItemAdapter); - return view; } @@ -86,6 +76,18 @@ public class HomeTopFragment extends Fragment { public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); + RecyclerView recyclerView = view.findViewById(R.id.home_item_recycler_view); + recyclerView.setItemAnimator(new DefaultItemAnimator()); + + ListItemAdapter listItemAdapter = new ListItemAdapter(); + recyclerView.setAdapter(listItemAdapter); + recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); + + lacertaLibrary.getRecentDocument(10).thenAccept(listItems -> { + listItemAdapter.setListItems(listItems); + getActivity().runOnUiThread(listItemAdapter::notifyDataSetChanged); + }); + CollapsingToolbarLayout collapsingToolbarLayout = view.findViewById(R.id.collapsing_toolbar); Toolbar toolbar = view.findViewById(R.id.toolbar); From c53c4ed9a169b82ef159c26a1ae9d898d060fc36 Mon Sep 17 00:00:00 2001 From: r-ca Date: Sat, 20 Jan 2024 23:51:20 +0900 Subject: [PATCH 18/19] Debug --- .../main/java/one/nem/lacerta/data/impl/LacertaLibraryImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 82747715..e9ecee78 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 @@ -34,7 +34,7 @@ public class LacertaLibraryImpl implements LacertaLibrary { return CompletableFuture.supplyAsync(() -> { // 5秒フリーズさせる try { - Thread.sleep(5000); + Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } From 017a2413b6e099e79eb699257895d2296c3ff532 Mon Sep 17 00:00:00 2001 From: r-ca Date: Sat, 20 Jan 2024 23:51:34 +0900 Subject: [PATCH 19/19] =?UTF-8?q?=E6=8C=BF=E5=85=A5=E6=99=82=E3=81=AB?= =?UTF-8?q?=E3=82=A2=E3=83=8B=E3=83=A1=E3=83=BC=E3=82=B7=E3=83=A7=E3=83=B3?= =?UTF-8?q?=E3=81=8C=E7=99=BA=E7=94=9F=E3=81=99=E3=82=8B=E3=82=88=E3=81=86?= =?UTF-8?q?=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/one/nem/lacerta/feature/home/HomeTopFragment.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/feature/home/src/main/java/one/nem/lacerta/feature/home/HomeTopFragment.java b/feature/home/src/main/java/one/nem/lacerta/feature/home/HomeTopFragment.java index f8cc7ba2..1510b2ac 100644 --- a/feature/home/src/main/java/one/nem/lacerta/feature/home/HomeTopFragment.java +++ b/feature/home/src/main/java/one/nem/lacerta/feature/home/HomeTopFragment.java @@ -15,7 +15,6 @@ import androidx.appcompat.widget.Toolbar; import androidx.core.content.ContextCompat; import androidx.drawerlayout.widget.DrawerLayout; import androidx.fragment.app.Fragment; -import androidx.recyclerview.widget.DefaultItemAnimator; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; @@ -77,7 +76,7 @@ public class HomeTopFragment extends Fragment { super.onViewCreated(view, savedInstanceState); RecyclerView recyclerView = view.findViewById(R.id.home_item_recycler_view); - recyclerView.setItemAnimator(new DefaultItemAnimator()); + ListItemAdapter listItemAdapter = new ListItemAdapter(); recyclerView.setAdapter(listItemAdapter); @@ -85,7 +84,9 @@ public class HomeTopFragment extends Fragment { lacertaLibrary.getRecentDocument(10).thenAccept(listItems -> { listItemAdapter.setListItems(listItems); - getActivity().runOnUiThread(listItemAdapter::notifyDataSetChanged); + getActivity().runOnUiThread(() -> { + listItemAdapter.notifyItemRangeInserted(0, listItems.size()); + }); }); CollapsingToolbarLayout collapsingToolbarLayout = view.findViewById(R.id.collapsing_toolbar);