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 c2c8ed69..5efd0652 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 @@ -35,6 +35,8 @@ import one.nem.lacerta.data.Document; import one.nem.lacerta.data.LacertaLibrary; import one.nem.lacerta.model.document.DocumentDetail; import one.nem.lacerta.model.document.DocumentMeta; +import one.nem.lacerta.model.document.page.Page; +import one.nem.lacerta.processor.DocumentProcessor; import one.nem.lacerta.processor.factory.DocumentProcessorFactory; import one.nem.lacerta.utils.LacertaLogger; import one.nem.lacerta.vcs.factory.LacertaVcsFactory; @@ -73,7 +75,9 @@ public class ScannerManagerActivity extends AppCompatActivity { // Variables private ArrayList croppedImages = new ArrayList<>(); - private boolean single = false; + private boolean update = false; + private String documentId; + private int index = 0; View view; @@ -104,7 +108,7 @@ public class ScannerManagerActivity extends AppCompatActivity { null ); - DocumentScanner documentScannerSingle = new DocumentScanner( // TODO-rca: ひどすぎるのでなんとかする + DocumentScanner documentScannerUpdate = new DocumentScanner( // TODO-rca: ひどすぎるのでなんとかする this, (croppedImageResults) -> { logger.debug(TAG, "croppedImage size: " + croppedImageResults.size()); @@ -160,11 +164,12 @@ public class ScannerManagerActivity extends AppCompatActivity { Intent intent = getIntent(); Bundle bundle = intent.getExtras(); if (bundle != null) { - this.single = bundle.getBoolean("single", false); + update = bundle.getBoolean("update", false); + documentId = bundle.getString("documentId"); + index = bundle.getInt("index", 0); } - - if (this.single) { - documentScanner = documentScannerSingle; + if (this.update) { + documentScanner = documentScannerUpdate; } documentScanner.startScan(); // Init @@ -251,6 +256,22 @@ public class ScannerManagerActivity extends AppCompatActivity { }); } + private void updatePage() { + logger.debug(TAG, "updatePage"); + // Deprecatedだが、中断機能が存在しないので操作をブロックする目的で(意図的に)使用 + ProgressDialog dialog = new ProgressDialog(this); + dialog.setMessage("保存中..."); // TODO-rca: テキストをリソースに移動 + dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); + dialog.setCancelable(false); + dialog.show(); + document.getDocument(documentId).thenAccept((documentDetail) -> { + DocumentProcessor documentProcessor = documentProcessorFactory.create(documentDetail); + documentProcessor.updatePageAtIndex(croppedImages.get(0), index); + document.updateDocument(documentProcessor.getDocumentDetail()).join(); + dialog.dismiss(); + }); + } + private void insertToExistDocument() { logger.debug(TAG, "insertToExistDocument"); LacertaFilePickerDialog dialog = new LacertaFilePickerDialog(); diff --git a/component/viewer/src/main/java/one/nem/lacerta/component/viewer/ViewerBodyFragment.java b/component/viewer/src/main/java/one/nem/lacerta/component/viewer/ViewerBodyFragment.java index 82c98341..f52576d4 100644 --- a/component/viewer/src/main/java/one/nem/lacerta/component/viewer/ViewerBodyFragment.java +++ b/component/viewer/src/main/java/one/nem/lacerta/component/viewer/ViewerBodyFragment.java @@ -1,5 +1,6 @@ package one.nem.lacerta.component.viewer; +import android.content.Intent; import android.os.Bundle; import androidx.fragment.app.Fragment; @@ -16,6 +17,7 @@ import com.google.android.material.dialog.MaterialAlertDialogBuilder; import javax.inject.Inject; import dagger.hilt.android.AndroidEntryPoint; +import one.nem.lacerta.component.scanner.ScannerManagerActivity; import one.nem.lacerta.data.Document; import one.nem.lacerta.data.LacertaLibrary; import one.nem.lacerta.utils.LacertaLogger; @@ -107,7 +109,12 @@ public class ViewerBodyFragment extends Fragment { builder.setTitle("ページを更新しますか?"); builder.setPositiveButton("更新", (dialog, which) -> { - // update + // ScannerをIntent + Intent intent = new Intent(getActivity(), ScannerManagerActivity.class); + intent.putExtra("update", true); + intent.putExtra("documentId", documentId); + intent.putExtra("index", position); + startActivity(intent); }); builder.setNegativeButton("キャンセル", (dialog, which) -> { // cancel