From 3c75a04a5f2209b0cdbe000f8d991cf2d36706d4 Mon Sep 17 00:00:00 2001 From: r-ca Date: Mon, 29 Jan 2024 04:13:04 +0900 Subject: [PATCH 01/11] =?UTF-8?q?=E5=BC=95=E6=95=B0=E3=81=A7=E6=9C=80?= =?UTF-8?q?=E5=A4=A7=E6=92=AE=E5=BD=B1=E6=9E=9A=E6=95=B0=E3=82=92=E6=8C=87?= =?UTF-8?q?=E5=AE=9A=E3=81=A7=E3=81=8D=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../component/scanner/ScannerManagerActivity.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) 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 80cf6ae5..de0eb081 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 @@ -2,6 +2,7 @@ package one.nem.lacerta.component.scanner; import android.Manifest; import android.app.ProgressDialog; +import android.content.Intent; import android.content.pm.PackageManager; import android.graphics.Bitmap; import android.graphics.BitmapFactory; @@ -56,6 +57,9 @@ public class ScannerManagerActivity extends AppCompatActivity { // Variables private ArrayList croppedImages = new ArrayList<>(); + private int maxPage = 0; + private boolean singlePage = false; + View view; DocumentScanner documentScanner = new DocumentScanner( @@ -82,7 +86,7 @@ public class ScannerManagerActivity extends AppCompatActivity { }, null, null, - null + singlePage ? 1 : maxPage ); @Override @@ -113,6 +117,12 @@ public class ScannerManagerActivity extends AppCompatActivity { this.view = findViewById(R.id.main); // TODO-rca:なんとかする + Intent intent = getIntent(); + Bundle bundle = intent.getExtras(); + if (bundle != null) { + this.maxPage = bundle.getInt("maxPage", 0); + this.singlePage = bundle.getBoolean("singlePage", false); + } } @Override From b0a06825611ed68dc25f07b292cb3728ea0562f1 Mon Sep 17 00:00:00 2001 From: r-ca Date: Mon, 29 Jan 2024 04:13:59 +0900 Subject: [PATCH 02/11] =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lacerta/component/scanner/ScannerManagerActivity.java | 6 +++--- 1 file changed, 3 insertions(+), 3 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 de0eb081..b48fb62d 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 @@ -58,7 +58,7 @@ public class ScannerManagerActivity extends AppCompatActivity { private ArrayList croppedImages = new ArrayList<>(); private int maxPage = 0; - private boolean singlePage = false; + private boolean withOutLimit = false; View view; @@ -86,7 +86,7 @@ public class ScannerManagerActivity extends AppCompatActivity { }, null, null, - singlePage ? 1 : maxPage + withOutLimit ? null : maxPage ); @Override @@ -121,7 +121,7 @@ public class ScannerManagerActivity extends AppCompatActivity { Bundle bundle = intent.getExtras(); if (bundle != null) { this.maxPage = bundle.getInt("maxPage", 0); - this.singlePage = bundle.getBoolean("singlePage", false); + this.withOutLimit = bundle.getBoolean("withOutLimit", false); } } From 719769c045394e2733962260200d48b2ade5cc92 Mon Sep 17 00:00:00 2001 From: r-ca Date: Mon, 29 Jan 2024 04:17:01 +0900 Subject: [PATCH 03/11] =?UTF-8?q?Single=E3=83=A2=E3=83=BC=E3=83=89?= =?UTF-8?q?=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../scanner/ScannerManagerActivity.java | 49 +++++++++++++++---- 1 file changed, 40 insertions(+), 9 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 b48fb62d..d38140ed 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 @@ -57,8 +57,7 @@ public class ScannerManagerActivity extends AppCompatActivity { // Variables private ArrayList croppedImages = new ArrayList<>(); - private int maxPage = 0; - private boolean withOutLimit = false; + private boolean single = false; View view; @@ -86,9 +85,37 @@ public class ScannerManagerActivity extends AppCompatActivity { }, null, null, - withOutLimit ? null : maxPage + null ); + DocumentScanner documentScannerSingle = new DocumentScanner( // TODO-rca: ひどすぎるのでなんとかする + this, + (croppedImageResults) -> { + logger.debug(TAG, "croppedImage size: " + croppedImageResults.size()); + ArrayList croppedImages = new ArrayList<>(); + for (String result : croppedImageResults) { + croppedImages.add(BitmapFactory.decodeFile(result)); + } + processResult(croppedImages); + return null; + }, + (errorMessage) -> { + // an error happened + logger.error(TAG, "Error: " + errorMessage); + logger.e_code("543a230e-cb9a-47a2-8131-3beecfe1c458"); + return null; + }, + () -> { + // user canceled document scan + logger.debug(TAG, "User canceled document scan"); + return null; + }, + null, + null, + 1 + ); + + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -112,17 +139,21 @@ public class ScannerManagerActivity extends AppCompatActivity { setSupportActionBar(toolbar); Objects.requireNonNull(getSupportActionBar()).setDisplayHomeAsUpEnabled(true); + Intent intent = getIntent(); + Bundle bundle = intent.getExtras(); + if (bundle != null) { + this.single = bundle.getBoolean("single", false); + } + + if (this.single) { + documentScanner = documentScannerSingle; + } documentScanner.startScan(); // Init this.view = findViewById(R.id.main); // TODO-rca:なんとかする - Intent intent = getIntent(); - Bundle bundle = intent.getExtras(); - if (bundle != null) { - this.maxPage = bundle.getInt("maxPage", 0); - this.withOutLimit = bundle.getBoolean("withOutLimit", false); - } + } @Override From d76d0a02e2e040ea1f8b3a1e0778013d58e53620 Mon Sep 17 00:00:00 2001 From: r-ca Date: Mon, 29 Jan 2024 04:17:31 +0900 Subject: [PATCH 04/11] =?UTF-8?q?=E3=82=B9=E3=82=AD=E3=83=A3=E3=83=B3?= =?UTF-8?q?=E3=81=8C=E3=82=AD=E3=83=A3=E3=83=B3=E3=82=BB=E3=83=AB=E3=81=95?= =?UTF-8?q?=E3=82=8C=E3=81=9F=E3=82=89=E7=B5=82=E4=BA=86=E3=81=99=E3=82=8B?= =?UTF-8?q?=E3=82=88=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../nem/lacerta/component/scanner/ScannerManagerActivity.java | 1 + 1 file changed, 1 insertion(+) 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 d38140ed..44391547 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 @@ -108,6 +108,7 @@ public class ScannerManagerActivity extends AppCompatActivity { () -> { // user canceled document scan logger.debug(TAG, "User canceled document scan"); + finish(); return null; }, null, From 5645cf64b65c31d77c2546d3742978aab9290320 Mon Sep 17 00:00:00 2001 From: r-ca Date: Mon, 29 Jan 2024 04:17:46 +0900 Subject: [PATCH 05/11] =?UTF-8?q?=E5=A4=B1=E6=95=97=E3=81=97=E3=81=9F?= =?UTF-8?q?=E3=82=89=E7=B5=82=E4=BA=86=E3=81=99=E3=82=8B=E3=82=88=E3=81=86?= =?UTF-8?q?=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../nem/lacerta/component/scanner/ScannerManagerActivity.java | 1 + 1 file changed, 1 insertion(+) 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 44391547..a27241fe 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 @@ -103,6 +103,7 @@ public class ScannerManagerActivity extends AppCompatActivity { // an error happened logger.error(TAG, "Error: " + errorMessage); logger.e_code("543a230e-cb9a-47a2-8131-3beecfe1c458"); + finish(); return null; }, () -> { From 49ac5c2ddc53baf1ead77d9ead5d74f2f599965b Mon Sep 17 00:00:00 2001 From: r-ca Date: Mon, 29 Jan 2024 04:18:33 +0900 Subject: [PATCH 06/11] =?UTF-8?q?=E4=BE=9D=E5=AD=98=E9=96=A2=E4=BF=82?= =?UTF-8?q?=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- component/scanner/build.gradle | 2 ++ 1 file changed, 2 insertions(+) diff --git a/component/scanner/build.gradle b/component/scanner/build.gradle index a62143ad..e04fb839 100644 --- a/component/scanner/build.gradle +++ b/component/scanner/build.gradle @@ -52,4 +52,6 @@ dependencies { implementation project(':vcs') implementation project(':data') + + implementation project(':component:common') } \ No newline at end of file From 832976902814fc8975a86ab3a59bf5761219f7e0 Mon Sep 17 00:00:00 2001 From: r-ca Date: Mon, 29 Jan 2024 04:23:41 +0900 Subject: [PATCH 07/11] =?UTF-8?q?=E3=82=B3=E3=83=A1=E3=83=B3=E3=83=88?= =?UTF-8?q?=E8=A7=A3=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/res/menu/scanner_result_toolbar.xml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/component/scanner/src/main/res/menu/scanner_result_toolbar.xml b/component/scanner/src/main/res/menu/scanner_result_toolbar.xml index dc815d7b..9d957b4e 100644 --- a/component/scanner/src/main/res/menu/scanner_result_toolbar.xml +++ b/component/scanner/src/main/res/menu/scanner_result_toolbar.xml @@ -6,9 +6,9 @@ android:icon="@drawable/save_24px" android:title="Save" app:showAsAction="ifRoom"/> - - - - - + \ No newline at end of file From beef661e3b4d6feec8056f624bcd86c703a17b44 Mon Sep 17 00:00:00 2001 From: r-ca Date: Mon, 29 Jan 2024 04:24:01 +0900 Subject: [PATCH 08/11] WIP --- .../scanner/ScannerManagerActivity.java | 35 +++++++++++++------ 1 file changed, 24 insertions(+), 11 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 a27241fe..66b8dc1e 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 @@ -30,7 +30,9 @@ import java.util.concurrent.CompletableFuture; import javax.inject.Inject; import dagger.hilt.android.AndroidEntryPoint; +import one.nem.lacerta.component.common.picker.LacertaFilePickerDialog; 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.processor.factory.DocumentProcessorFactory; @@ -48,6 +50,9 @@ public class ScannerManagerActivity extends AppCompatActivity { @Inject Document document; + @Inject + LacertaLibrary lacertaLibrary; + @Inject DocumentProcessorFactory documentProcessorFactory; @@ -168,15 +173,13 @@ public class ScannerManagerActivity extends AppCompatActivity { public boolean onOptionsItemSelected(android.view.MenuItem item) { if (item.getItemId() == R.id.action_save_new) { // 新ドキュメントとして保存 - Toast.makeText(this, "保存処理", Toast.LENGTH_SHORT).show(); saveNewDocument(); return true; -// } -// else if (item.getItemId() == R.id.action_insert_exist) { -// // 既存ドキュメントに挿入 -// Toast.makeText(this, "Work in progress", Toast.LENGTH_SHORT).show(); -// insertToExistDocument(); -// return true; + } + else if (item.getItemId() == R.id.action_insert_exist) { + // 既存ドキュメントに挿入 + insertToExistDocument(); + return true; } else if (item.getItemId() == android.R.id.home) { finish(); return true; @@ -217,7 +220,7 @@ public class ScannerManagerActivity extends AppCompatActivity { Bitmap[] bitmaps = new Bitmap[croppedImages.size()]; croppedImages.toArray(bitmaps); logger.debug(TAG, "bitmaps.length: " + bitmaps.length); - addPagesToDocumentDetail(documentDetail, bitmaps).join(); + addPagesToDocumentDetail(documentDetail, bitmaps, null).join(); document.updateDocument(documentDetail).join(); dialog.dismiss(); finish(); @@ -225,11 +228,11 @@ public class ScannerManagerActivity extends AppCompatActivity { } - private CompletableFuture addPagesToDocumentDetail(DocumentDetail documentDetail, Bitmap[] bitmaps) { + private CompletableFuture addPagesToDocumentDetail(DocumentDetail documentDetail, Bitmap[] bitmaps, String commitMessage) { return CompletableFuture.runAsync(() -> { try { document.updateDocument(documentProcessorFactory.create(documentDetail).addNewPagesToLast(bitmaps).getDocumentDetail()).join(); - lacertaVcsFactory.create(documentDetail.getMeta().getId()).generateRevisionAtCurrent("Initial commit"); + lacertaVcsFactory.create(documentDetail.getMeta().getId()).generateRevisionAtCurrent(commitMessage == null ? "Update" : commitMessage); } catch (Exception e) { logger.error(TAG, "Error: " + e.getMessage()); logger.e_code("9dff2a28-20e8-4ccd-9d04-f0c7646faa6a"); @@ -239,7 +242,17 @@ public class ScannerManagerActivity extends AppCompatActivity { private void insertToExistDocument() { logger.debug(TAG, "insertToExistDocument"); - // TODO-rca: 実装 + LacertaFilePickerDialog dialog = new LacertaFilePickerDialog(); + dialog.setListener(((name, fileId) -> { + document.getDocument(fileId).thenAccept((documentDetail) -> { + Bitmap[] bitmaps = new Bitmap[croppedImages.size()]; + croppedImages.toArray(bitmaps); + logger.debug(TAG, "bitmaps.length: " + bitmaps.length); + addPagesToDocumentDetail(documentDetail, bitmaps, "ページを追加").join(); + document.updateDocument(documentDetail).join(); + finish(); + }); + })); } private void updateResultView(ArrayList resultImages) { From 4158faf453b095d98cb9424c4c1bfcd4617d96e2 Mon Sep 17 00:00:00 2001 From: r-ca Date: Mon, 29 Jan 2024 04:26:22 +0900 Subject: [PATCH 09/11] =?UTF-8?q?=E3=82=B3=E3=83=B3=E3=82=B9=E3=83=88?= =?UTF-8?q?=E3=83=A9=E3=82=AF=E3=82=BF=E3=82=A4=E3=83=B3=E3=82=B8=E3=82=A7?= =?UTF-8?q?=E3=82=AF=E3=82=B7=E3=83=A7=E3=83=B3=E3=81=AB=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../scanner/ScannerManagerActivity.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 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 66b8dc1e..8275e88e 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 @@ -44,21 +44,25 @@ public class ScannerManagerActivity extends AppCompatActivity { String TAG = "ScannerManagerActivity"; - @Inject LacertaLogger logger; - @Inject Document document; - @Inject LacertaLibrary lacertaLibrary; - @Inject DocumentProcessorFactory documentProcessorFactory; - @Inject LacertaVcsFactory lacertaVcsFactory; + @Inject + public ScannerManagerActivity(LacertaLogger logger, Document document, LacertaLibrary lacertaLibrary, DocumentProcessorFactory documentProcessorFactory, LacertaVcsFactory lacertaVcsFactory) { + this.logger = logger; + this.document = document; + this.lacertaLibrary = lacertaLibrary; + this.documentProcessorFactory = documentProcessorFactory; + this.lacertaVcsFactory = lacertaVcsFactory; + } + // Variables private ArrayList croppedImages = new ArrayList<>(); @@ -253,6 +257,8 @@ public class ScannerManagerActivity extends AppCompatActivity { finish(); }); })); + dialog.setTitle("追加するドキュメントを選択"); + dialog.show(getSupportFragmentManager(), "LacertaFilePickerDialog"); } private void updateResultView(ArrayList resultImages) { From 57d1c7809c0133f27f424288344ddb4a1e06241b Mon Sep 17 00:00:00 2001 From: r-ca Date: Mon, 29 Jan 2024 04:31:14 +0900 Subject: [PATCH 10/11] Iroiro --- .../scanner/ScannerManagerActivity.java | 41 +++++++++++-------- 1 file changed, 24 insertions(+), 17 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 8275e88e..994f6943 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 @@ -44,23 +44,30 @@ public class ScannerManagerActivity extends AppCompatActivity { String TAG = "ScannerManagerActivity"; + @Inject LacertaLogger logger; + @Inject Document document; - LacertaLibrary lacertaLibrary; - + @Inject DocumentProcessorFactory documentProcessorFactory; + @Inject LacertaVcsFactory lacertaVcsFactory; +// @Inject +// public ScannerManagerActivity(LacertaLogger logger, Document document, LacertaLibrary lacertaLibrary, DocumentProcessorFactory documentProcessorFactory, LacertaVcsFactory lacertaVcsFactory) { +// this.logger = logger; +// this.document = document; +// this.lacertaLibrary = lacertaLibrary; +// this.documentProcessorFactory = documentProcessorFactory; +// this.lacertaVcsFactory = lacertaVcsFactory; +// } + @Inject - public ScannerManagerActivity(LacertaLogger logger, Document document, LacertaLibrary lacertaLibrary, DocumentProcessorFactory documentProcessorFactory, LacertaVcsFactory lacertaVcsFactory) { - this.logger = logger; - this.document = document; - this.lacertaLibrary = lacertaLibrary; - this.documentProcessorFactory = documentProcessorFactory; - this.lacertaVcsFactory = lacertaVcsFactory; + public ScannerManagerActivity() { + // Required empty public constructor } // Variables @@ -150,15 +157,15 @@ public class ScannerManagerActivity extends AppCompatActivity { setSupportActionBar(toolbar); Objects.requireNonNull(getSupportActionBar()).setDisplayHomeAsUpEnabled(true); - Intent intent = getIntent(); - Bundle bundle = intent.getExtras(); - if (bundle != null) { - this.single = bundle.getBoolean("single", false); - } - - if (this.single) { - documentScanner = documentScannerSingle; - } +// Intent intent = getIntent(); +// Bundle bundle = intent.getExtras(); +// if (bundle != null) { +// this.single = bundle.getBoolean("single", false); +// } +// +// if (this.single) { +// documentScanner = documentScannerSingle; +// } documentScanner.startScan(); // Init From 1fb37a0317453b7c548e5a5d9665e43d63340cad Mon Sep 17 00:00:00 2001 From: r-ca Date: Mon, 29 Jan 2024 04:31:38 +0900 Subject: [PATCH 11/11] iroiro --- .../scanner/ScannerManagerActivity.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 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 994f6943..c2c8ed69 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 @@ -157,15 +157,15 @@ public class ScannerManagerActivity extends AppCompatActivity { setSupportActionBar(toolbar); Objects.requireNonNull(getSupportActionBar()).setDisplayHomeAsUpEnabled(true); -// Intent intent = getIntent(); -// Bundle bundle = intent.getExtras(); -// if (bundle != null) { -// this.single = bundle.getBoolean("single", false); -// } -// -// if (this.single) { -// documentScanner = documentScannerSingle; -// } + Intent intent = getIntent(); + Bundle bundle = intent.getExtras(); + if (bundle != null) { + this.single = bundle.getBoolean("single", false); + } + + if (this.single) { + documentScanner = documentScannerSingle; + } documentScanner.startScan(); // Init