From 1af344a6d37973aff8e25dc7699ea656de2ddf01 Mon Sep 17 00:00:00 2001 From: r-ca Date: Tue, 9 Jan 2024 13:47:58 +0900 Subject: [PATCH] =?UTF-8?q?throws=E8=BF=BD=E5=8A=A0,=20=E5=AE=9F=E8=A3=85W?= =?UTF-8?q?IP?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lacerta/processor/DocumentProcessor.java | 4 +-- .../processor/impl/DocumentProcessorImpl.java | 29 ++++--------------- 2 files changed, 8 insertions(+), 25 deletions(-) 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 f5e55c5a..7d4e9fcb 100644 --- a/processor/src/main/java/one/nem/lacerta/processor/DocumentProcessor.java +++ b/processor/src/main/java/one/nem/lacerta/processor/DocumentProcessor.java @@ -5,8 +5,8 @@ import android.graphics.Bitmap; public interface DocumentProcessor { // ページ操作 - void addNewPageToLast(Bitmap bitmap); - void addNewPagesToLast(Bitmap[] bitmaps); + 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); 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 7df5c163..4631b33c 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 @@ -62,7 +62,8 @@ public class DocumentProcessorImpl implements DocumentProcessor{ if (fileManager.isExist("meta.xml")) { logger.debug("init", "meta.xml found"); try { - xmlMetaModel = xmlMetaParser.deserialize(this.fileManager.loadDocument("meta.xml")); + this.xmlMetaModel = xmlMetaParser.deserialize(this.fileManager.loadXml("meta.xml")); + logger.debug("init", "meta.xml parsed"); } catch (Exception e) { logger.debug("init", "meta.xml parse failed"); logger.trace("init", e.getMessage()); @@ -78,7 +79,7 @@ public class DocumentProcessorImpl implements DocumentProcessor{ xmlMetaModel.setPages(new ArrayList<>()); try { - this.fileManager.saveDocument(xmlMetaParser.serialize(xmlMetaModel), "meta.xml"); + this.fileManager.createFile("meta.xml").saveXml(xmlMetaParser.serialize(xmlMetaModel)); logger.debug("init", "meta.xml saved"); } catch (Exception e) { logger.error("init", "meta.xml save failed"); @@ -90,33 +91,15 @@ public class DocumentProcessorImpl implements DocumentProcessor{ } @Override - public void addNewPageToLast(Bitmap bitmap) { + public void addNewPageToLast(Bitmap bitmap) throws Exception{ logger.debug("addNewPageToLast", "called"); String filename = UUID.randomUUID().toString() + ".png"; // TODO-rca: 拡張子を動的にする - // FileManager - if (this.fileManager.getCurrentDir().equals(this.documentRootPath.resolve(DEFAULT_SAVE_DIR))) { // TODO-rca: 効率化 - logger.debug("addNewPageToLast", "currentDir is documentRootPath"); - } else { - logger.debug("addNewPageToLast", "currentDir is not documentRootPath"); - this.fileManager.backRootDir(); - this.fileManager.autoCreateDir(DEFAULT_SAVE_DIR); - this.fileManager.changeDir(DEFAULT_SAVE_DIR); - } - logger.debug("addNewPageToLast", "DirInit finished"); - - // Save file - this.fileManager.saveBitmapAtCurrent(bitmap, filename); - - // Update meta - XmlMetaPageModel page = new XmlMetaPageModel(); - page.setIndex(xmlMetaModel.getPages().size() + 1); - page.setFilename(filename); - xmlMetaModel.addPage(page); + this.fileManager.resolve(DEFAULT_SAVE_DIR).createDirectory(); } @Override - public void addNewPagesToLast(Bitmap[] bitmaps) { + public void addNewPagesToLast(Bitmap[] bitmaps) throws Exception{ logger.debug("addNewPagesToLast", "called"); for (Bitmap bitmap : bitmaps) {