From e6a4393b6d28415a9cf27114225c31b8e65af383 Mon Sep 17 00:00:00 2001 From: r-ca Date: Sat, 20 Jan 2024 22:39:35 +0900 Subject: [PATCH] =?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() {