mirror of
https://github.com/lacerta-doc/Lacerta.git
synced 2024-11-26 09:43:15 +00:00
Merge pull request #125 from lacerta-doc/improve_scanner2
Improve scanner2
This commit is contained in:
commit
a3b3000d59
|
@ -52,4 +52,6 @@ dependencies {
|
||||||
implementation project(':vcs')
|
implementation project(':vcs')
|
||||||
|
|
||||||
implementation project(':data')
|
implementation project(':data')
|
||||||
|
|
||||||
|
implementation project(':component:common')
|
||||||
}
|
}
|
|
@ -2,6 +2,7 @@ package one.nem.lacerta.component.scanner;
|
||||||
|
|
||||||
import android.Manifest;
|
import android.Manifest;
|
||||||
import android.app.ProgressDialog;
|
import android.app.ProgressDialog;
|
||||||
|
import android.content.Intent;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.BitmapFactory;
|
import android.graphics.BitmapFactory;
|
||||||
|
@ -29,7 +30,9 @@ import java.util.concurrent.CompletableFuture;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import dagger.hilt.android.AndroidEntryPoint;
|
import dagger.hilt.android.AndroidEntryPoint;
|
||||||
|
import one.nem.lacerta.component.common.picker.LacertaFilePickerDialog;
|
||||||
import one.nem.lacerta.data.Document;
|
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.DocumentDetail;
|
||||||
import one.nem.lacerta.model.document.DocumentMeta;
|
import one.nem.lacerta.model.document.DocumentMeta;
|
||||||
import one.nem.lacerta.processor.factory.DocumentProcessorFactory;
|
import one.nem.lacerta.processor.factory.DocumentProcessorFactory;
|
||||||
|
@ -53,9 +56,25 @@ public class ScannerManagerActivity extends AppCompatActivity {
|
||||||
@Inject
|
@Inject
|
||||||
LacertaVcsFactory lacertaVcsFactory;
|
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() {
|
||||||
|
// Required empty public constructor
|
||||||
|
}
|
||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
private ArrayList<Bitmap> croppedImages = new ArrayList<>();
|
private ArrayList<Bitmap> croppedImages = new ArrayList<>();
|
||||||
|
|
||||||
|
private boolean single = false;
|
||||||
|
|
||||||
View view;
|
View view;
|
||||||
|
|
||||||
DocumentScanner documentScanner = new DocumentScanner(
|
DocumentScanner documentScanner = new DocumentScanner(
|
||||||
|
@ -85,6 +104,36 @@ public class ScannerManagerActivity extends AppCompatActivity {
|
||||||
null
|
null
|
||||||
);
|
);
|
||||||
|
|
||||||
|
DocumentScanner documentScannerSingle = new DocumentScanner( // TODO-rca: ひどすぎるのでなんとかする
|
||||||
|
this,
|
||||||
|
(croppedImageResults) -> {
|
||||||
|
logger.debug(TAG, "croppedImage size: " + croppedImageResults.size());
|
||||||
|
ArrayList<Bitmap> 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");
|
||||||
|
finish();
|
||||||
|
return null;
|
||||||
|
},
|
||||||
|
() -> {
|
||||||
|
// user canceled document scan
|
||||||
|
logger.debug(TAG, "User canceled document scan");
|
||||||
|
finish();
|
||||||
|
return null;
|
||||||
|
},
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
1
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
@ -108,11 +157,21 @@ public class ScannerManagerActivity extends AppCompatActivity {
|
||||||
setSupportActionBar(toolbar);
|
setSupportActionBar(toolbar);
|
||||||
Objects.requireNonNull(getSupportActionBar()).setDisplayHomeAsUpEnabled(true);
|
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();
|
documentScanner.startScan();
|
||||||
// Init
|
// Init
|
||||||
|
|
||||||
this.view = findViewById(R.id.main); // TODO-rca:なんとかする
|
this.view = findViewById(R.id.main); // TODO-rca:なんとかする
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -125,15 +184,13 @@ public class ScannerManagerActivity extends AppCompatActivity {
|
||||||
public boolean onOptionsItemSelected(android.view.MenuItem item) {
|
public boolean onOptionsItemSelected(android.view.MenuItem item) {
|
||||||
if (item.getItemId() == R.id.action_save_new) {
|
if (item.getItemId() == R.id.action_save_new) {
|
||||||
// 新ドキュメントとして保存
|
// 新ドキュメントとして保存
|
||||||
Toast.makeText(this, "保存処理", Toast.LENGTH_SHORT).show();
|
|
||||||
saveNewDocument();
|
saveNewDocument();
|
||||||
return true;
|
return true;
|
||||||
// }
|
}
|
||||||
// else if (item.getItemId() == R.id.action_insert_exist) {
|
else if (item.getItemId() == R.id.action_insert_exist) {
|
||||||
// // 既存ドキュメントに挿入
|
// 既存ドキュメントに挿入
|
||||||
// Toast.makeText(this, "Work in progress", Toast.LENGTH_SHORT).show();
|
insertToExistDocument();
|
||||||
// insertToExistDocument();
|
return true;
|
||||||
// return true;
|
|
||||||
} else if (item.getItemId() == android.R.id.home) {
|
} else if (item.getItemId() == android.R.id.home) {
|
||||||
finish();
|
finish();
|
||||||
return true;
|
return true;
|
||||||
|
@ -174,7 +231,7 @@ public class ScannerManagerActivity extends AppCompatActivity {
|
||||||
Bitmap[] bitmaps = new Bitmap[croppedImages.size()];
|
Bitmap[] bitmaps = new Bitmap[croppedImages.size()];
|
||||||
croppedImages.toArray(bitmaps);
|
croppedImages.toArray(bitmaps);
|
||||||
logger.debug(TAG, "bitmaps.length: " + bitmaps.length);
|
logger.debug(TAG, "bitmaps.length: " + bitmaps.length);
|
||||||
addPagesToDocumentDetail(documentDetail, bitmaps).join();
|
addPagesToDocumentDetail(documentDetail, bitmaps, null).join();
|
||||||
document.updateDocument(documentDetail).join();
|
document.updateDocument(documentDetail).join();
|
||||||
dialog.dismiss();
|
dialog.dismiss();
|
||||||
finish();
|
finish();
|
||||||
|
@ -182,11 +239,11 @@ public class ScannerManagerActivity extends AppCompatActivity {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private CompletableFuture<Void> addPagesToDocumentDetail(DocumentDetail documentDetail, Bitmap[] bitmaps) {
|
private CompletableFuture<Void> addPagesToDocumentDetail(DocumentDetail documentDetail, Bitmap[] bitmaps, String commitMessage) {
|
||||||
return CompletableFuture.runAsync(() -> {
|
return CompletableFuture.runAsync(() -> {
|
||||||
try {
|
try {
|
||||||
document.updateDocument(documentProcessorFactory.create(documentDetail).addNewPagesToLast(bitmaps).getDocumentDetail()).join();
|
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) {
|
} catch (Exception e) {
|
||||||
logger.error(TAG, "Error: " + e.getMessage());
|
logger.error(TAG, "Error: " + e.getMessage());
|
||||||
logger.e_code("9dff2a28-20e8-4ccd-9d04-f0c7646faa6a");
|
logger.e_code("9dff2a28-20e8-4ccd-9d04-f0c7646faa6a");
|
||||||
|
@ -196,7 +253,19 @@ public class ScannerManagerActivity extends AppCompatActivity {
|
||||||
|
|
||||||
private void insertToExistDocument() {
|
private void insertToExistDocument() {
|
||||||
logger.debug(TAG, "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();
|
||||||
|
});
|
||||||
|
}));
|
||||||
|
dialog.setTitle("追加するドキュメントを選択");
|
||||||
|
dialog.show(getSupportFragmentManager(), "LacertaFilePickerDialog");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateResultView(ArrayList<Bitmap> resultImages) {
|
private void updateResultView(ArrayList<Bitmap> resultImages) {
|
||||||
|
|
|
@ -6,9 +6,9 @@
|
||||||
android:icon="@drawable/save_24px"
|
android:icon="@drawable/save_24px"
|
||||||
android:title="Save"
|
android:title="Save"
|
||||||
app:showAsAction="ifRoom"/>
|
app:showAsAction="ifRoom"/>
|
||||||
<!-- <item-->
|
<item
|
||||||
<!-- android:id="@+id/action_insert_exist"-->
|
android:id="@+id/action_insert_exist"
|
||||||
<!-- android:icon="@drawable/description_24px"-->
|
android:icon="@drawable/description_24px"
|
||||||
<!-- android:title="Insert"-->
|
android:title="Insert"
|
||||||
<!-- app:showAsAction="ifRoom"/>-->
|
app:showAsAction="ifRoom"/>
|
||||||
</menu>
|
</menu>
|
Loading…
Reference in New Issue
Block a user