Merge pull request #33 from lacerta-doc/feature/add_doc_proc_missing

DocumentProcessorの不足しているメソッドを実装する(1)
This commit is contained in:
ろむねこ 2024-01-09 17:16:11 +09:00 committed by GitHub
commit 217f096a38
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 38 additions and 7 deletions

View File

@ -7,9 +7,9 @@ public interface DocumentProcessor {
// ページ操作 // ページ操作
void addNewPageToLast(Bitmap bitmap) throws Exception; void addNewPageToLast(Bitmap bitmap) throws Exception;
void addNewPagesToLast(Bitmap[] bitmaps) throws Exception; void addNewPagesToLast(Bitmap[] bitmaps) throws Exception;
void addNewPageAfterIndex(Bitmap bitmap, int index); void addNewPageAfterIndex(Bitmap bitmap, int index) throws Exception;
void addNewPageBeforeIndex(Bitmap bitmap, int index); void addNewPageBeforeIndex(Bitmap bitmap, int index) throws Exception;
void removePageAtIndex(int index); void removePageAtIndex(int index) throws Exception;
// 更新 // 更新
void updatePageAtIndex(Bitmap bitmap, int index); void updatePageAtIndex(Bitmap bitmap, int index);

View File

@ -118,14 +118,45 @@ public class DocumentProcessorImpl implements DocumentProcessor{
} // TODO-rca: 効率悪いので改善する } // TODO-rca: 効率悪いので改善する
} }
@Override // Internal
public void addNewPageAfterIndex(Bitmap bitmap, int index) { // Indexを振り直す
private ArrayList<XmlMetaPageModel> reIndexPages(ArrayList<XmlMetaPageModel> pages) {
logger.debug("reIndexPages", "called"); // TODO-rca: 効率化
ArrayList<XmlMetaPageModel> 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 @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 @Override