diff --git a/processor/src/main/java/one/nem/lacerta/processor/DocumentProcessor.java b/processor/src/main/java/one/nem/lacerta/processor/DocumentProcessor.java index abca8a84..d5584c24 100644 --- a/processor/src/main/java/one/nem/lacerta/processor/DocumentProcessor.java +++ b/processor/src/main/java/one/nem/lacerta/processor/DocumentProcessor.java @@ -7,9 +7,9 @@ public interface DocumentProcessor { // ページ操作 void addNewPageToLast(Bitmap bitmap) throws Exception; void addNewPagesToLast(Bitmap[] bitmaps) throws Exception; - void addNewPageAfterIndex(Bitmap bitmap, int index); - void addNewPageBeforeIndex(Bitmap bitmap, int index); - void removePageAtIndex(int index); + void addNewPageAfterIndex(Bitmap bitmap, int index) throws Exception; + void addNewPageBeforeIndex(Bitmap bitmap, int index) throws Exception; + void removePageAtIndex(int index) throws Exception; // 更新 void updatePageAtIndex(Bitmap bitmap, int index); diff --git a/processor/src/main/java/one/nem/lacerta/processor/impl/DocumentProcessorImpl.java b/processor/src/main/java/one/nem/lacerta/processor/impl/DocumentProcessorImpl.java index ad31fc6c..1eada540 100644 --- a/processor/src/main/java/one/nem/lacerta/processor/impl/DocumentProcessorImpl.java +++ b/processor/src/main/java/one/nem/lacerta/processor/impl/DocumentProcessorImpl.java @@ -118,14 +118,45 @@ public class DocumentProcessorImpl implements DocumentProcessor{ } // TODO-rca: 効率悪いので改善する } - @Override - public void addNewPageAfterIndex(Bitmap bitmap, int index) { - + // Internal + // Indexを振り直す + private ArrayList reIndexPages(ArrayList pages) { + logger.debug("reIndexPages", "called"); // TODO-rca: 効率化 + ArrayList newPages = new ArrayList<>(); + for (int i = 0; i < pages.size(); i++) { + XmlMetaPageModel xmlMetaPageModel = pages.get(i); + xmlMetaPageModel.setIndex(i + 1); + newPages.add(xmlMetaPageModel); + } + return newPages; } @Override - public void addNewPageBeforeIndex(Bitmap bitmap, int index) { + public void addNewPageAfterIndex(Bitmap bitmap, int index) throws Exception { + logger.debug("addNewPageAfterIndex", "called"); + String filename = UUID.randomUUID().toString() + ".png"; // TODO-rca: 拡張子を動的にする + this.fileManager.getNewInstance().createDirectoryIfNotExist(DEFAULT_SAVE_DIR).resolve(DEFAULT_SAVE_DIR).saveBitmap(bitmap, filename); + + XmlMetaPageModel xmlMetaPageModel = new XmlMetaPageModel(); + xmlMetaPageModel.setFilename(filename); + xmlMetaPageModel.setIndex(index + 1); + xmlMetaModel.getPages().add(index, xmlMetaPageModel); + xmlMetaModel.setPages(reIndexPages(xmlMetaModel.getPages())); + } + + @Override + public void addNewPageBeforeIndex(Bitmap bitmap, int index) throws Exception { + logger.debug("addNewPageBeforeIndex", "called"); + String filename = UUID.randomUUID().toString() + ".png"; // TODO-rca: 拡張子を動的にする + + this.fileManager.getNewInstance().createDirectoryIfNotExist(DEFAULT_SAVE_DIR).resolve(DEFAULT_SAVE_DIR).saveBitmap(bitmap, filename); + + XmlMetaPageModel xmlMetaPageModel = new XmlMetaPageModel(); + xmlMetaPageModel.setFilename(filename); + xmlMetaPageModel.setIndex(index); + xmlMetaModel.getPages().add(index - 1, xmlMetaPageModel); + xmlMetaModel.setPages(reIndexPages(xmlMetaModel.getPages())); } @Override