非同期化

This commit is contained in:
r-ca 2024-01-20 22:39:35 +09:00
parent acc5b166d5
commit e6a4393b6d
No known key found for this signature in database
GPG Key ID: 6A72911AC73464A9

View File

@ -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);
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<Void> addPagesToDocumentDetail(DocumentDetail documentDetail, Bitmap[] bitmaps) {
return CompletableFuture.runAsync(() -> {
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");
}
});
}
private void insertToExistDocument() {