mirror of
https://github.com/lacerta-doc/Lacerta.git
synced 2026-11-07 19:47:36 +00:00
Compare commits
222
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1b85845499 | ||
|
|
523008ff3f | ||
|
|
50c2b1dc4d | ||
|
|
ae8f7ef1f1 | ||
|
|
27766effc1 | ||
|
|
f7fe8b35b1 | ||
|
|
87c4738f37 | ||
|
|
96bfca0550 | ||
|
|
0140c0376b | ||
|
|
89a3a179bd | ||
|
|
ff905d9280 | ||
|
|
4b0ea02f16 | ||
|
|
ca37a97e2f | ||
|
|
217f096a38 | ||
|
|
0c59c85b28 | ||
|
|
e3a5dee36c | ||
|
|
1805cd7d73 | ||
|
|
513a91b41e | ||
|
|
3f2534b1eb | ||
|
|
af836ed486 | ||
|
|
fe3d332a36 | ||
|
|
5fb938c263 | ||
|
|
3cafa05b27 | ||
|
|
9065ee1e1f | ||
|
|
36ecb3ab13 | ||
|
|
01e111bdd5 | ||
|
|
65a25ad228 | ||
|
|
1efac1ffb6 | ||
|
|
c05d45afdd | ||
|
|
27aa6a2f15 | ||
|
|
1b676f8368 | ||
|
|
30ed65079b | ||
|
|
943ca1daf5 | ||
|
|
8913f8118d | ||
|
|
4cf3ff5f3c | ||
|
|
360580eff2 | ||
|
|
730640425f | ||
|
|
69b60944b4 | ||
|
|
e8804e8f84 | ||
|
|
7951bef6e0 | ||
|
|
fbde892f40 | ||
|
|
022e7e278a | ||
|
|
d88c9c2030 | ||
|
|
e055f8fe9e | ||
|
|
1af344a6d3 | ||
|
|
f3ac07e633 | ||
|
|
a887446d21 | ||
|
|
b3a4207762 | ||
|
|
0439a998e3 | ||
|
|
a2eb04e96b | ||
|
|
b0c97da382 | ||
|
|
3a9053e987 | ||
|
|
7cdb005ebb | ||
|
|
3a270cdc9f | ||
|
|
f380e7eef8 | ||
|
|
8ca642c7f4 | ||
|
|
c28d94e417 | ||
|
|
8587c6a707 | ||
|
|
f3465bcf81 | ||
|
|
3e2a295a22 | ||
|
|
f36dc05db1 | ||
|
|
78525d634a | ||
|
|
0736a7326a | ||
|
|
76f4a6c228 | ||
|
|
3a41c4e105 | ||
|
|
301678658c | ||
|
|
e20b3f4a35 | ||
|
|
e0a344bb48 | ||
|
|
a2eda32183 | ||
|
|
0f8b71e739 | ||
|
|
91fe39d141 | ||
|
|
0dced5d0dc | ||
|
|
9e5b2dad46 | ||
|
|
5c931ece3f | ||
|
|
3b861e3a07 | ||
|
|
37497cb1ea | ||
|
|
3efaf30b95 | ||
|
|
9142696fac | ||
|
|
d5cf2f31d6 | ||
|
|
fcda369a2e | ||
|
|
9faf5c9055 | ||
|
|
0d78f9fa7c | ||
|
|
8ebc96fa98 | ||
|
|
2b8766db0a | ||
|
|
2233bb1a35 | ||
|
|
c513b44e8d | ||
|
|
cc35d8a5ea | ||
|
|
16ac36dd4f | ||
|
|
eadd65a334 | ||
|
|
3ed835ef2f | ||
|
|
4a66ed786d | ||
|
|
89e2f15a29 | ||
|
|
717b8e9637 | ||
|
|
3e24896bd1 | ||
|
|
94943184c4 | ||
|
|
30f2dc39ae | ||
|
|
4621025e62 | ||
|
|
164527d41a | ||
|
|
d770ac76aa | ||
|
|
642f306ad6 | ||
|
|
930b48af2f | ||
|
|
3205923eb5 | ||
|
|
441479d9b9 | ||
|
|
099d900ffd | ||
|
|
080e86d05d | ||
|
|
6d6f4790a0 | ||
|
|
1a31d63786 | ||
|
|
ce834a7cfd | ||
|
|
f7b8006fa4 | ||
|
|
5bb2f0d387 | ||
|
|
e54cc07e9d | ||
|
|
bc5d0edd68 | ||
|
|
3540f20c46 | ||
|
|
164b6ea6d4 | ||
|
|
8fdefb9850 | ||
|
|
8e4018beb0 | ||
|
|
ddd2b097e6 | ||
|
|
9fe646fad8 | ||
|
|
5e1d1f6a76 | ||
|
|
649d6ccfdc | ||
|
|
dccb3090e1 | ||
|
|
de4a501c3f | ||
|
|
28b5f97c31 | ||
|
|
4656914203 | ||
|
|
1996d8dc4a | ||
|
|
dec4983bfc | ||
|
|
88dfae7d37 | ||
|
|
48101190a2 | ||
|
|
2b79c7669f | ||
|
|
3b6d88bafd | ||
|
|
a439bbd888 | ||
|
|
3453d224e1 | ||
|
|
b75759b650 | ||
|
|
a78cac8178 | ||
|
|
a42ef8f4fc | ||
|
|
5c16ea6e21 | ||
|
|
f000addbce | ||
|
|
73fa8201d6 | ||
|
|
5c0fd4fdbb | ||
|
|
6e514b216a | ||
|
|
59ba2cdcfc | ||
|
|
b3be0b9e21 | ||
|
|
a836410cbd | ||
|
|
15d454690e | ||
|
|
2ba243ea4a | ||
|
|
52657fdbbd | ||
|
|
88cd58f920 | ||
|
|
1ee0a1b8ea | ||
|
|
656482e968 | ||
|
|
efc16423d4 | ||
|
|
38db65c9d3 | ||
|
|
31a0220b90 | ||
|
|
5cb57997b8 | ||
|
|
0fade2c41b | ||
|
|
5a0b215626 | ||
|
|
49775a1f49 | ||
|
|
552f0e42b5 | ||
|
|
b8e70cd015 | ||
|
|
67350639c7 | ||
|
|
eb6a13baba | ||
|
|
bd0a16bec6 | ||
|
|
1019b1d035 | ||
|
|
2f0460a9ea | ||
|
|
2b4a24de7c | ||
|
|
b683c311df | ||
|
|
4bbb119729 | ||
|
|
8c714d5193 | ||
|
|
f441a957f7 | ||
|
|
dfe5c36e9e | ||
|
|
c54967f016 | ||
|
|
95beda8cc2 | ||
|
|
02d72ffa68 | ||
|
|
b159db97bb | ||
|
|
1653da9c94 | ||
|
|
1b00f2c64e | ||
|
|
de668412fc | ||
|
|
07042f4e91 | ||
|
|
78c36df105 | ||
|
|
14837f83cc | ||
|
|
4fd490ee12 | ||
|
|
d453c0705f | ||
|
|
aca90aa6e1 | ||
|
|
f52d00f930 | ||
|
|
9b70adecac | ||
|
|
80c5bca179 | ||
|
|
0a639d4b05 | ||
|
|
3ed6f7b5a6 | ||
|
|
f86dc981b4 | ||
|
|
c9eda4837b | ||
|
|
4d72fc10bf | ||
|
|
c9a594763d | ||
|
|
5a93b79b07 | ||
|
|
8a5cbe7b18 | ||
|
|
ca153f5602 | ||
|
|
73f553cff3 | ||
|
|
bd1a1d56cb | ||
|
|
b98fa18cae | ||
|
|
4875394417 | ||
|
|
b675e7ffa9 | ||
|
|
453fa4c4cf | ||
|
|
ce3565c082 | ||
|
|
523a66429e | ||
|
|
b7062a4942 | ||
|
|
43c7f4ae0f | ||
|
|
77702b9da5 | ||
|
|
d2950ab781 | ||
|
|
4aefae6b51 | ||
|
|
f2ed0515f8 | ||
|
|
b30834479e | ||
|
|
aa0728e97b | ||
|
|
3affd2dd2f | ||
|
|
9534e36a9d | ||
|
|
3bfcc9fd63 | ||
|
|
e3186249a0 | ||
|
|
54f2076eda | ||
|
|
c31a590ce3 | ||
|
|
2402936a19 | ||
|
|
ba87fb283e | ||
|
|
c35c4e829e | ||
|
|
017748b4a6 | ||
|
|
c2ee49d274 | ||
|
|
dd98602309 |
No files matched your search
@@ -0,0 +1,17 @@
|
|||||||
|
---
|
||||||
|
name: 不具合用テンプレート
|
||||||
|
about: 不具合用テンプレート
|
||||||
|
title: "[BUG]: "
|
||||||
|
labels: バグ
|
||||||
|
assignees: ''
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
# 概要
|
||||||
|
<!-- Issueの概要 -->
|
||||||
|
|
||||||
|
# 詳細
|
||||||
|
<!-- バグの詳細 -->
|
||||||
|
|
||||||
|
# 影響箇所
|
||||||
|
<!-- 予想される影響箇所(省略可) -->
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
---
|
||||||
|
name: 改善用テンプレート
|
||||||
|
about: 改善用テンプレート
|
||||||
|
title: "[IMPROVE]"
|
||||||
|
labels: ''
|
||||||
|
assignees: ''
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
# 概要
|
||||||
|
<!-- Issueの概要 -->
|
||||||
|
|
||||||
|
# 詳細
|
||||||
|
<!-- 改善内容の詳細 -->
|
||||||
|
|
||||||
|
# 影響箇所
|
||||||
|
<!-- 予想される影響箇所(省略可) -->
|
||||||
@@ -1,10 +1,20 @@
|
|||||||
---
|
---
|
||||||
name: 新機能用テンプレート
|
name: 新機能用テンプレート
|
||||||
about: 新規開発Issue用テンプレート
|
about: 新規能用テンプレート
|
||||||
title: ''
|
title: ''
|
||||||
labels: ''
|
labels: 新機能
|
||||||
assignees: ''
|
assignees: ''
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
WIP
|
# 概要
|
||||||
|
<!-- Issueの概要 -->
|
||||||
|
|
||||||
|
# 詳細
|
||||||
|
<!-- 機能の詳細 -->
|
||||||
|
|
||||||
|
# 関連Issue
|
||||||
|
<!-- 関連するIssueがあれば -->
|
||||||
|
|
||||||
|
# 影響箇所
|
||||||
|
<!-- 予想される影響箇所(省略可) -->
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
# 概要
|
||||||
|
<!-- PRの概要 -->
|
||||||
|
|
||||||
|
# 関連Issue
|
||||||
|
- #000 <!-- 関連するIssueを指定(なければ省略可) -->
|
||||||
|
|
||||||
|
# 詳細
|
||||||
|
<!-- 詳細 -->
|
||||||
|
|
||||||
|
# 影響箇所
|
||||||
|
<!-- 予想される影響箇所 -->
|
||||||
|
|
||||||
|
# チェック
|
||||||
|
<!-- 参考用, 全てにチェックがついている必要があるわけではありません -->
|
||||||
|
- [ ] 機能として完成している
|
||||||
|
- [ ] WIP(Work in progress: 作業中)
|
||||||
|
- [ ] 正常にビルド/起動ができる
|
||||||
|
- [ ] 既存の機能を壊していない
|
||||||
Generated
-17
@@ -1,17 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="deploymentTargetDropDown">
|
|
||||||
<runningDeviceTargetSelectedWithDropDown>
|
|
||||||
<Target>
|
|
||||||
<type value="RUNNING_DEVICE_TARGET" />
|
|
||||||
<deviceKey>
|
|
||||||
<Key>
|
|
||||||
<type value="SERIAL_NUMBER" />
|
|
||||||
<value value="ZY227DCBHN" />
|
|
||||||
</Key>
|
|
||||||
</deviceKey>
|
|
||||||
</Target>
|
|
||||||
</runningDeviceTargetSelectedWithDropDown>
|
|
||||||
<timeTargetWasSelectedWithDropDown value="2023-12-21T04:53:14.729902700Z" />
|
|
||||||
</component>
|
|
||||||
</project>
|
|
||||||
@@ -7,6 +7,44 @@ WIP
|
|||||||
## メモ
|
## メモ
|
||||||
- アイコン: Google Material Icons https://fonts.google.com/icons (Weight:300, Grade:0, Optical size: 24px)
|
- アイコン: Google Material Icons https://fonts.google.com/icons (Weight:300, Grade:0, Optical size: 24px)
|
||||||
|
|
||||||
|
## モジュール構成
|
||||||
|
### モジュール一覧
|
||||||
|
- `component` : コンポーネント
|
||||||
|
- `common` : 共通コンポーネント
|
||||||
|
- UIの中で共通で使う要素(メニューアイテムとか)
|
||||||
|
- `scanner` : スキャナー
|
||||||
|
- スキャナーの実装
|
||||||
|
- `viewer` : ビューワー
|
||||||
|
- ドキュメントビューワーの実装
|
||||||
|
- `data` : データ
|
||||||
|
- UIからデータを取得/保存するためのラッパーモジュール
|
||||||
|
- `Document` : ドキュメント関係
|
||||||
|
- WIP(JavaDocを参照してください, 余裕があったら追記します)
|
||||||
|
- `feature` : 機能モジュール(ナビゲーションからみた機能で分割)
|
||||||
|
- `common`: 共通機能
|
||||||
|
- 設定画面とか、どこからでも呼ばれうる画面
|
||||||
|
- `debug`: デバッグメニュー
|
||||||
|
- `home`: ホーム画面
|
||||||
|
- `library`: ライブラリ画面
|
||||||
|
- `scan`: スキャン画面
|
||||||
|
- `search`: 検索画面
|
||||||
|
- `model` : モデル
|
||||||
|
- データモデルをまとめたモジュール (WIP)
|
||||||
|
- `document` : ドキュメント
|
||||||
|
- `meta` : メタデータ
|
||||||
|
- `processor` : プロセッサ
|
||||||
|
- いくつかの処理をまとめたモジュール
|
||||||
|
- `DocumentProcessor` : ドキュメント処理(ドキュメントにページを追加したり更新したり)
|
||||||
|
- `shared` :
|
||||||
|
- 共有リソース
|
||||||
|
- `source` : ソース
|
||||||
|
- (バックエンドが使うのでとりあえず後回し、フロントから直接操作することは絶対にありません)
|
||||||
|
- `utils` : ユーティリティ
|
||||||
|
- ちょっとしたユーティリティをまとめたモジュール
|
||||||
|
- `LacertaLogger` : ロガー
|
||||||
|
- `XmlMetaParser` : XMLメタデータパーサー(フロントから直接操作することは絶対にありません)
|
||||||
|
|
||||||
|
|
||||||
## コーディング規則/推奨(WIP)
|
## コーディング規則/推奨(WIP)
|
||||||
### 規則
|
### 規則
|
||||||
- `// TODO`コメントには任意のsuffixを付ける
|
- `// TODO`コメントには任意のsuffixを付ける
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
plugins {
|
plugins {
|
||||||
alias(libs.plugins.com.android.library)
|
alias(libs.plugins.com.android.library)
|
||||||
|
id 'com.google.dagger.hilt.android'
|
||||||
}
|
}
|
||||||
|
|
||||||
android {
|
android {
|
||||||
@@ -33,8 +34,16 @@ dependencies {
|
|||||||
androidTestImplementation libs.androidx.test.ext.junit
|
androidTestImplementation libs.androidx.test.ext.junit
|
||||||
androidTestImplementation libs.androidx.test.espresso.core
|
androidTestImplementation libs.androidx.test.espresso.core
|
||||||
|
|
||||||
|
// Hilt (DI)
|
||||||
|
implementation libs.com.google.dagger.hilt.android
|
||||||
|
annotationProcessor libs.com.google.dagger.hilt.compiler
|
||||||
|
|
||||||
implementation 'com.websitebeaver:documentscanner:1.0.0'
|
implementation 'com.websitebeaver:documentscanner:1.0.0'
|
||||||
|
|
||||||
implementation project(':shared:ui')
|
implementation project(':shared:ui')
|
||||||
implementation project(':model')
|
implementation project(':model')
|
||||||
|
|
||||||
|
implementation project(':processor')
|
||||||
|
|
||||||
|
implementation project(':utils')
|
||||||
}
|
}
|
||||||
+106
@@ -25,15 +25,32 @@ import android.widget.Toast;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
import dagger.hilt.android.AndroidEntryPoint;
|
||||||
|
import one.nem.lacerta.model.document.DocumentDetail;
|
||||||
|
import one.nem.lacerta.model.document.DocumentMeta;
|
||||||
|
import one.nem.lacerta.model.document.path.DocumentPath;
|
||||||
|
import one.nem.lacerta.processor.DocumentProcessor;
|
||||||
|
import one.nem.lacerta.processor.factory.DocumentProcessorFactory;
|
||||||
|
|
||||||
|
import one.nem.lacerta.utils.LacertaLogger;
|
||||||
|
|
||||||
|
import one.nem.lacerta.utils.repository.DeviceInfoUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A simple {@link Fragment} subclass.
|
* A simple {@link Fragment} subclass.
|
||||||
* Use the {@link ScannerDataManagerStubFragment#newInstance} factory method to
|
* Use the {@link ScannerDataManagerStubFragment#newInstance} factory method to
|
||||||
* create an instance of this fragment.
|
* create an instance of this fragment.
|
||||||
*/
|
*/
|
||||||
|
@AndroidEntryPoint
|
||||||
public class ScannerDataManagerStubFragment extends Fragment {
|
public class ScannerDataManagerStubFragment extends Fragment {
|
||||||
|
|
||||||
// TODO-rca: 時間があったらcacheを使うようにする?
|
// TODO-rca: 時間があったらcacheを使うようにする?
|
||||||
@@ -43,6 +60,19 @@ public class ScannerDataManagerStubFragment extends Fragment {
|
|||||||
|
|
||||||
private Uri photoURI;
|
private Uri photoURI;
|
||||||
|
|
||||||
|
private DocumentDetail documentDetail;
|
||||||
|
|
||||||
|
private DocumentProcessor documentProcessor;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
DocumentProcessorFactory documentProcessorFactory;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
LacertaLogger logger;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
DeviceInfoUtils deviceInfoUtils;
|
||||||
|
|
||||||
private final ActivityResultLauncher<Intent> cameraLauncher = registerForActivityResult(
|
private final ActivityResultLauncher<Intent> cameraLauncher = registerForActivityResult(
|
||||||
new ActivityResultContracts.StartActivityForResult(),
|
new ActivityResultContracts.StartActivityForResult(),
|
||||||
result -> {
|
result -> {
|
||||||
@@ -120,6 +150,82 @@ public class ScannerDataManagerStubFragment extends Fragment {
|
|||||||
}
|
}
|
||||||
updateResults();
|
updateResults();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
view.findViewById(R.id.button_create_documnent).setOnClickListener(v -> {
|
||||||
|
Log.d("ScannerDataManagerStubFragment", "button_create_documnent clicked");
|
||||||
|
Toast.makeText(getActivity(), "button_create_documnent clicked", Toast.LENGTH_LONG).show();
|
||||||
|
|
||||||
|
this.documentDetail = createSampleDocumentDetail();
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
view.findViewById(R.id.button_init_document_processor).setOnClickListener(v -> {
|
||||||
|
Log.d("ScannerDataManagerStubFragment", "button_init_document_processor clicked");
|
||||||
|
Toast.makeText(getActivity(), "button_init_document_processor clicked", Toast.LENGTH_LONG).show();
|
||||||
|
// TODO-rca: ここでDocumentProcessorを初期化する
|
||||||
|
if (this.documentDetail == null) {
|
||||||
|
Toast.makeText(getActivity(), "documentDetail is null", Toast.LENGTH_LONG).show();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.documentProcessor = documentProcessorFactory.create(this.documentDetail);
|
||||||
|
Toast.makeText(getActivity(), "documentProcessor created", Toast.LENGTH_LONG).show();
|
||||||
|
try {
|
||||||
|
this.documentProcessor.init();
|
||||||
|
} catch (Exception e) {
|
||||||
|
Toast.makeText(getActivity(), "Error occurred while initializing documentProcessor", Toast.LENGTH_LONG).show();
|
||||||
|
Log.e("ScannerDataManagerStubFragment", "Error occurred while initializing documentProcessor", e);
|
||||||
|
}
|
||||||
|
Toast.makeText(getActivity(), "documentProcessor initialized", Toast.LENGTH_LONG).show();
|
||||||
|
});
|
||||||
|
|
||||||
|
view.findViewById(R.id.button_add_page).setOnClickListener(v -> {
|
||||||
|
Log.d("ScannerDataManagerStubFragment", "button_add_page clicked");
|
||||||
|
Toast.makeText(getActivity(), "button_add_page clicked", Toast.LENGTH_LONG).show();
|
||||||
|
if (this.documentProcessor == null) {
|
||||||
|
Toast.makeText(getActivity(), "documentProcessor is null", Toast.LENGTH_LONG).show();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Bitmap[] bitmaps = new Bitmap[results.size()];
|
||||||
|
for (int i = 0; i < results.size(); i++) {
|
||||||
|
bitmaps[i] = results.get(i).getBitmap();
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
this.documentProcessor.addNewPagesToLast(bitmaps);
|
||||||
|
} catch (Exception e) {
|
||||||
|
Toast.makeText(getActivity(), "Error occurred while adding pages", Toast.LENGTH_LONG).show();
|
||||||
|
Log.e("ScannerDataManagerStubFragment", "Error occurred while adding pages", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
Toast.makeText(getActivity(), "pages added", Toast.LENGTH_LONG).show();
|
||||||
|
|
||||||
|
try {
|
||||||
|
this.documentProcessor.close();
|
||||||
|
} catch (Exception e) {
|
||||||
|
Toast.makeText(getActivity(), "Error occurred while closing documentProcessor", Toast.LENGTH_LONG).show();
|
||||||
|
Log.e("ScannerDataManagerStubFragment", "Error occurred while closing documentProcessor", e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public DocumentDetail createSampleDocumentDetail() {
|
||||||
|
|
||||||
|
String id = UUID.randomUUID().toString();
|
||||||
|
|
||||||
|
Toast.makeText(getActivity(), "Generated id: " + id, Toast.LENGTH_LONG).show();
|
||||||
|
//logger.debug("CreateSample", "Generated id: " + id);
|
||||||
|
|
||||||
|
DocumentMeta meta = new DocumentMeta(
|
||||||
|
id,
|
||||||
|
"Sample" + DateTimeFormatter.ofPattern("yyyyMMddHHmmss").format(LocalDateTime.now()),
|
||||||
|
new Date(),
|
||||||
|
new Date());
|
||||||
|
|
||||||
|
DocumentPath path = new DocumentPath(
|
||||||
|
deviceInfoUtils.getExternalStorageDirectoryString(),
|
||||||
|
"Sample" + DateTimeFormatter.ofPattern("yyyyMMddHHmmss").format(LocalDateTime.now()));
|
||||||
|
|
||||||
|
return new DocumentDetail(meta, path, "SampleAuthor", "SampleDefaultBranch");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
android:id="@+id/action_button_container"
|
android:id="@+id/action_button_container"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="0dp"
|
android:layout_height="0dp"
|
||||||
|
android:weightSum="2"
|
||||||
android:orientation="horizontal"
|
android:orientation="horizontal"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
@@ -19,7 +20,7 @@
|
|||||||
<com.google.android.material.button.MaterialButton
|
<com.google.android.material.button.MaterialButton
|
||||||
android:id="@+id/button_call_camera"
|
android:id="@+id/button_call_camera"
|
||||||
style="@style/Widget.Material3.Button.IconButton.Filled"
|
style="@style/Widget.Material3.Button.IconButton.Filled"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_margin="16px"
|
android:layout_margin="16px"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
@@ -27,6 +28,58 @@
|
|||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/init_button_container"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="0dp"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:weightSum="2"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@id/action_button_container">
|
||||||
|
|
||||||
|
<com.google.android.material.button.MaterialButton
|
||||||
|
android:id="@+id/button_create_documnent"
|
||||||
|
style="@style/Widget.Material3.Button.IconButton.Filled"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_margin="16px"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:text="Create Doc Obj" />
|
||||||
|
|
||||||
|
<com.google.android.material.button.MaterialButton
|
||||||
|
android:id="@+id/button_init_document_processor"
|
||||||
|
style="@style/Widget.Material3.Button.IconButton.Filled"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_margin="16px"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:text="Init Processor" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/doc_button_container"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="0dp"
|
||||||
|
android:weightSum="2"
|
||||||
|
android:orientation="horizontal"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@id/init_button_container">
|
||||||
|
|
||||||
|
<com.google.android.material.button.MaterialButton
|
||||||
|
android:id="@+id/button_add_page"
|
||||||
|
style="@style/Widget.Material3.Button.IconButton.Filled"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_margin="16px"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:text="Add page to last" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
<androidx.recyclerview.widget.RecyclerView
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
android:id="@+id/result_recycler_view"
|
android:id="@+id/result_recycler_view"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
@@ -35,6 +88,6 @@
|
|||||||
app:layout_constraintBottom_toBottomOf="parent"
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toBottomOf="@id/action_button_container" />
|
app:layout_constraintTop_toBottomOf="@id/doc_button_container" />
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
@@ -65,4 +65,7 @@ dependencies {
|
|||||||
// Scanner
|
// Scanner
|
||||||
implementation project(':component:scanner')
|
implementation project(':component:scanner')
|
||||||
|
|
||||||
|
// Processor
|
||||||
|
implementation project(':processor')
|
||||||
|
|
||||||
}
|
}
|
||||||
+11
-6
@@ -10,16 +10,16 @@ import android.view.ViewGroup;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* A simple {@link Fragment} subclass.
|
* A simple {@link Fragment} subclass.
|
||||||
* Use the {@link DebugMenuMetaDataFragment#newInstance} factory method to
|
* Use the {@link DebugMenuDocProcessorTesterFragment#newInstance} factory method to
|
||||||
* create an instance of this fragment.
|
* create an instance of this fragment.
|
||||||
*/
|
*/
|
||||||
public class DebugMenuMetaDataFragment extends Fragment {
|
public class DebugMenuDocProcessorTesterFragment extends Fragment {
|
||||||
public DebugMenuMetaDataFragment() {
|
public DebugMenuDocProcessorTesterFragment() {
|
||||||
// Required empty public constructor
|
// Required empty public constructor
|
||||||
}
|
}
|
||||||
|
|
||||||
public static DebugMenuMetaDataFragment newInstance() {
|
public static DebugMenuDocProcessorTesterFragment newInstance() {
|
||||||
DebugMenuMetaDataFragment fragment = new DebugMenuMetaDataFragment();
|
DebugMenuDocProcessorTesterFragment fragment = new DebugMenuDocProcessorTesterFragment();
|
||||||
Bundle args = new Bundle();
|
Bundle args = new Bundle();
|
||||||
fragment.setArguments(args);
|
fragment.setArguments(args);
|
||||||
return fragment;
|
return fragment;
|
||||||
@@ -28,12 +28,17 @@ public class DebugMenuMetaDataFragment extends Fragment {
|
|||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||||
Bundle savedInstanceState) {
|
Bundle savedInstanceState) {
|
||||||
// Inflate the layout for this fragment
|
// Inflate the layout for this fragment
|
||||||
return inflater.inflate(R.layout.fragment_debug_menu_meta_data, container, false);
|
View view = inflater.inflate(R.layout.fragment_debug_menu_doc_processor_tester, container, false);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return view;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
-110
@@ -1,110 +0,0 @@
|
|||||||
package one.nem.lacerta.feature.debug;
|
|
||||||
|
|
||||||
import android.graphics.Bitmap;
|
|
||||||
import android.graphics.Canvas;
|
|
||||||
import android.graphics.Color;
|
|
||||||
import android.graphics.Paint;
|
|
||||||
import android.os.Bundle;
|
|
||||||
|
|
||||||
import androidx.fragment.app.Fragment;
|
|
||||||
|
|
||||||
import android.view.LayoutInflater;
|
|
||||||
import android.view.View;
|
|
||||||
import android.view.ViewGroup;
|
|
||||||
import android.widget.EditText;
|
|
||||||
|
|
||||||
import dagger.hilt.android.AndroidEntryPoint;
|
|
||||||
import one.nem.lacerta.source.file.FileManager;
|
|
||||||
import one.nem.lacerta.source.file.factory.FileManagerFactory;
|
|
||||||
|
|
||||||
import one.nem.lacerta.utils.repository.DeviceInfoUtils;
|
|
||||||
|
|
||||||
import javax.inject.Inject;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A simple {@link Fragment} subclass.
|
|
||||||
* Use the {@link DebugMenuFileManagerTesterFragment#newInstance} factory method to
|
|
||||||
* create an instance of this fragment.
|
|
||||||
*/
|
|
||||||
@AndroidEntryPoint
|
|
||||||
public class DebugMenuFileManagerTesterFragment extends Fragment {
|
|
||||||
|
|
||||||
public DebugMenuFileManagerTesterFragment() {
|
|
||||||
// Required empty public constructor
|
|
||||||
}
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
FileManagerFactory fileManagerFactory;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
DeviceInfoUtils deviceInfoUtils;
|
|
||||||
|
|
||||||
// TODO: Rename and change types and number of parameters
|
|
||||||
public static DebugMenuFileManagerTesterFragment newInstance() {
|
|
||||||
DebugMenuFileManagerTesterFragment fragment = new DebugMenuFileManagerTesterFragment();
|
|
||||||
Bundle args = new Bundle();
|
|
||||||
|
|
||||||
fragment.setArguments(args);
|
|
||||||
return fragment;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
|
||||||
Bundle savedInstanceState) {
|
|
||||||
// Inflate the layout for this fragment
|
|
||||||
View view = inflater.inflate(R.layout.fragment_debug_menu_file_manager_tester, container, false);
|
|
||||||
|
|
||||||
view.findViewById(R.id.button_create_directory).setOnClickListener(v -> {
|
|
||||||
EditText editText = view.findViewById(R.id.edit_text_dir_name);
|
|
||||||
String dirName = editText.getText().toString();
|
|
||||||
|
|
||||||
FileManager fileManager = fileManagerFactory.create(deviceInfoUtils.getExternalStorageDirectory());
|
|
||||||
fileManager.createDir(dirName);
|
|
||||||
});
|
|
||||||
|
|
||||||
view.findViewById(R.id.button_save_item).setOnClickListener(v -> {
|
|
||||||
FileManager fileManager = fileManagerFactory.create(deviceInfoUtils.getExternalStorageDirectory());
|
|
||||||
fileManager.createDir("test");
|
|
||||||
fileManager.changeDir("test");
|
|
||||||
Bitmap bitmap = Bitmap.createBitmap(1000, 1000, Bitmap.Config.ARGB_8888);
|
|
||||||
// Bitmapに描画処理を行う
|
|
||||||
Canvas canvas = new Canvas(bitmap);
|
|
||||||
// 大きな山の形状を作成
|
|
||||||
android.graphics.Path bigMountainPath = new android.graphics.Path();
|
|
||||||
bigMountainPath.moveTo(100, 800); // 左下の開始点
|
|
||||||
bigMountainPath.lineTo(500, 300); // 頂点
|
|
||||||
bigMountainPath.lineTo(900, 800); // 右下
|
|
||||||
bigMountainPath.close(); // パスを閉じる
|
|
||||||
|
|
||||||
// 山の描画設定
|
|
||||||
Paint mountainPaint = new Paint();
|
|
||||||
mountainPaint.setColor(Color.GREEN);
|
|
||||||
mountainPaint.setStyle(Paint.Style.FILL);
|
|
||||||
|
|
||||||
// 大きな山を描画
|
|
||||||
canvas.drawPath(bigMountainPath, mountainPaint);
|
|
||||||
|
|
||||||
// 小さな山の形状を作成
|
|
||||||
android.graphics.Path smallMountainPath = new android.graphics.Path();
|
|
||||||
smallMountainPath.moveTo(400, 800); // 左下の開始点
|
|
||||||
smallMountainPath.lineTo(650, 400); // 頂点
|
|
||||||
smallMountainPath.lineTo(900, 800); // 右下
|
|
||||||
smallMountainPath.close(); // パスを閉じる
|
|
||||||
|
|
||||||
Paint smallMountainPaint = new Paint();
|
|
||||||
smallMountainPaint.setColor(Color.parseColor("#006e54"));
|
|
||||||
smallMountainPaint.setStyle(Paint.Style.FILL);
|
|
||||||
|
|
||||||
// 小さな山を描画
|
|
||||||
canvas.drawPath(smallMountainPath, smallMountainPaint);
|
|
||||||
fileManager.saveBitmapAtCurrent(bitmap, "test.png");
|
|
||||||
});
|
|
||||||
|
|
||||||
return view;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -48,10 +48,8 @@ public class DebugMenuTopFragment extends Fragment {
|
|||||||
recyclerView.setLayoutManager(new androidx.recyclerview.widget.LinearLayoutManager(getContext()));
|
recyclerView.setLayoutManager(new androidx.recyclerview.widget.LinearLayoutManager(getContext()));
|
||||||
List<DebugMenuListItem> debugMenuListItems = new ArrayList<>();
|
List<DebugMenuListItem> debugMenuListItems = new ArrayList<>();
|
||||||
|
|
||||||
debugMenuListItems.add(new DebugMenuListItem("Meta Data", "View meta data", R.id.action_debugMenuTopFragment_to_debugMenuMetaDataFragment, true));
|
|
||||||
debugMenuListItems.add(new DebugMenuListItem("Document Tester", "placeholder", R.id.action_debugMenuTopFragment_to_debugMenuDocumentTesterTopFragment, true));
|
debugMenuListItems.add(new DebugMenuListItem("Document Tester", "placeholder", R.id.action_debugMenuTopFragment_to_debugMenuDocumentTesterTopFragment, true));
|
||||||
debugMenuListItems.add(new DebugMenuListItem("Scanner", "placeholder", R.id.action_debugMenuTopFragment_to_scannerDataManagerStubFragment, true));
|
debugMenuListItems.add(new DebugMenuListItem("Scanner", "placeholder", R.id.action_debugMenuTopFragment_to_scannerDataManagerStubFragment, true));
|
||||||
debugMenuListItems.add(new DebugMenuListItem("File Manager", "placeholder", R.id.action_debugMenuTopFragment_to_debugMenuFileManagerTesterFragment, true));
|
|
||||||
|
|
||||||
DebugMenuListItemAdapter adapter = new DebugMenuListItemAdapter(debugMenuListItems);
|
DebugMenuListItemAdapter adapter = new DebugMenuListItemAdapter(debugMenuListItems);
|
||||||
recyclerView.setAdapter(adapter);
|
recyclerView.setAdapter(adapter);
|
||||||
|
|||||||
@@ -0,0 +1,36 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:theme="@style/Theme.Lacerta"
|
||||||
|
tools:context=".DebugMenuDocProcessorTesterFragment" >
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="1dp"
|
||||||
|
android:layout_marginTop="1dp"
|
||||||
|
android:layout_marginEnd="1dp"
|
||||||
|
android:orientation="vertical"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
|
<com.google.android.material.button.MaterialButton
|
||||||
|
android:id="@+id/button_gen_random_img"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:text="Generate random image" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
@@ -1,40 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
tools:context=".DebugMenuFileManagerTesterFragment">
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:orientation="vertical"
|
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
|
||||||
app:layout_constraintTop_toTopOf="parent">
|
|
||||||
|
|
||||||
<EditText
|
|
||||||
android:id="@+id/edit_text_dir_name"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"/>
|
|
||||||
|
|
||||||
<Button
|
|
||||||
android:id="@+id/button_create_directory"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:text="Create dir" />
|
|
||||||
<Button
|
|
||||||
android:id="@+id/button_dir_list"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:text="List item in current" />
|
|
||||||
|
|
||||||
<Button
|
|
||||||
android:id="@+id/button_save_item"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:text="Save Test Image" />
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
tools:context=".DebugMenuMetaDataFragment">
|
|
||||||
|
|
||||||
<!-- TODO: Update blank fragment layout -->
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</FrameLayout>
|
|
||||||
@@ -10,24 +10,13 @@
|
|||||||
android:name="one.nem.lacerta.feature.debug.DebugMenuTopFragment"
|
android:name="one.nem.lacerta.feature.debug.DebugMenuTopFragment"
|
||||||
android:label="fragment_debug_menu_top"
|
android:label="fragment_debug_menu_top"
|
||||||
tools:layout="@layout/fragment_debug_menu_top" >
|
tools:layout="@layout/fragment_debug_menu_top" >
|
||||||
<action
|
|
||||||
android:id="@+id/action_debugMenuTopFragment_to_debugMenuMetaDataFragment"
|
|
||||||
app:destination="@id/debugMenuMetaDataFragment" />
|
|
||||||
<action
|
<action
|
||||||
android:id="@+id/action_debugMenuTopFragment_to_debugMenuDocumentTesterTopFragment"
|
android:id="@+id/action_debugMenuTopFragment_to_debugMenuDocumentTesterTopFragment"
|
||||||
app:destination="@id/debugMenuDocumentTesterTopFragment" />
|
app:destination="@id/debugMenuDocumentTesterTopFragment" />
|
||||||
<action
|
<action
|
||||||
android:id="@+id/action_debugMenuTopFragment_to_scannerDataManagerStubFragment"
|
android:id="@+id/action_debugMenuTopFragment_to_scannerDataManagerStubFragment"
|
||||||
app:destination="@id/scannerDataManagerStubFragment" />
|
app:destination="@id/scannerDataManagerStubFragment" />
|
||||||
<action
|
|
||||||
android:id="@+id/action_debugMenuTopFragment_to_debugMenuFileManagerTesterFragment"
|
|
||||||
app:destination="@id/debugMenuFileManagerTesterFragment" />
|
|
||||||
</fragment>
|
</fragment>
|
||||||
<fragment
|
|
||||||
android:id="@+id/debugMenuMetaDataFragment"
|
|
||||||
android:name="one.nem.lacerta.feature.debug.DebugMenuMetaDataFragment"
|
|
||||||
android:label="fragment_debug_menu_meta_data"
|
|
||||||
tools:layout="@layout/fragment_debug_menu_meta_data" />
|
|
||||||
<fragment
|
<fragment
|
||||||
android:id="@+id/debugMenuDocumentTesterTopFragment"
|
android:id="@+id/debugMenuDocumentTesterTopFragment"
|
||||||
android:name="one.nem.lacerta.feature.debug.DebugMenuDocumentTesterTopFragment"
|
android:name="one.nem.lacerta.feature.debug.DebugMenuDocumentTesterTopFragment"
|
||||||
@@ -54,9 +43,4 @@
|
|||||||
android:id="@+id/scannerDataManagerStubFragment"
|
android:id="@+id/scannerDataManagerStubFragment"
|
||||||
android:name="one.nem.lacerta.component.scanner.ScannerDataManagerStubFragment"
|
android:name="one.nem.lacerta.component.scanner.ScannerDataManagerStubFragment"
|
||||||
android:label="ScannerDataManagerStubFragment" />
|
android:label="ScannerDataManagerStubFragment" />
|
||||||
<fragment
|
|
||||||
android:id="@+id/debugMenuFileManagerTesterFragment"
|
|
||||||
android:name="one.nem.lacerta.feature.debug.DebugMenuFileManagerTesterFragment"
|
|
||||||
android:label="fragment_debug_menu_file_manager_tester"
|
|
||||||
tools:layout="@layout/fragment_debug_menu_file_manager_tester" />
|
|
||||||
</navigation>
|
</navigation>
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
plugins {
|
plugins {
|
||||||
id 'com.android.library'
|
id 'com.android.library'
|
||||||
|
id 'com.google.dagger.hilt.android'
|
||||||
}
|
}
|
||||||
|
|
||||||
android {
|
android {
|
||||||
@@ -46,5 +47,9 @@ dependencies {
|
|||||||
|
|
||||||
implementation project(':shared:ui')
|
implementation project(':shared:ui')
|
||||||
|
|
||||||
|
implementation project(':model')
|
||||||
|
|
||||||
|
implementation project(':data')
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -10,12 +10,18 @@ import androidx.recyclerview.widget.RecyclerView;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import one.nem.lacerta.model.document.DocumentMeta;
|
||||||
|
|
||||||
public class DocumentAdapter extends RecyclerView.Adapter<DocumentAdapter.DocumentViewHolder> {
|
public class DocumentAdapter extends RecyclerView.Adapter<DocumentAdapter.DocumentViewHolder> {
|
||||||
|
|
||||||
private List<String> documentList;
|
private List<DocumentMeta> documentMetas;
|
||||||
|
|
||||||
public DocumentAdapter(List<String> documentList) {
|
public DocumentAdapter(List<DocumentMeta> documentMetas) {
|
||||||
this.documentList = documentList;
|
// nullの場合に例外を発生させる
|
||||||
|
if (documentMetas == null) {
|
||||||
|
throw new IllegalArgumentException("DocumentMetas list cannot be null or empty");
|
||||||
|
}
|
||||||
|
this.documentMetas = documentMetas;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@@ -27,12 +33,15 @@ public class DocumentAdapter extends RecyclerView.Adapter<DocumentAdapter.Docume
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(@NonNull DocumentViewHolder holder, int position) {
|
public void onBindViewHolder(@NonNull DocumentViewHolder holder, int position) {
|
||||||
holder.title.setText(documentList.get(position));
|
DocumentMeta documentMeta = documentMetas.get(position);
|
||||||
|
if (documentMeta != null) {
|
||||||
|
holder.title.setText(documentMeta.getTitle());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getItemCount() {
|
public int getItemCount() {
|
||||||
return documentList.size();
|
return documentMetas.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
class DocumentViewHolder extends RecyclerView.ViewHolder {
|
class DocumentViewHolder extends RecyclerView.ViewHolder {
|
||||||
@@ -40,7 +49,7 @@ public class DocumentAdapter extends RecyclerView.Adapter<DocumentAdapter.Docume
|
|||||||
|
|
||||||
DocumentViewHolder(View itemView) {
|
DocumentViewHolder(View itemView) {
|
||||||
super(itemView);
|
super(itemView);
|
||||||
title = itemView.findViewById(R.id.debug_menu_item_title);
|
title = itemView.findViewById(R.id.debug_menu_item_title); // 適切な id に変更する
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+3
@@ -8,6 +8,9 @@ import android.widget.TextView;
|
|||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
|
||||||
// LibraryArchiveFragment.java
|
// LibraryArchiveFragment.java
|
||||||
|
|
||||||
|
//画面変移用のコード
|
||||||
|
//Fragmentへのデータの受け渡し機能
|
||||||
public class LibraryArchiveFragment extends AppCompatActivity {
|
public class LibraryArchiveFragment extends AppCompatActivity {
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import android.widget.TextView;
|
|||||||
|
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
|
|
||||||
|
//Fragmentにデータを受け渡す機能
|
||||||
public class LibraryDocFragment extends Fragment {
|
public class LibraryDocFragment extends Fragment {
|
||||||
|
|
||||||
private TextView textView; // フィールドとして TextView を定義
|
private TextView textView; // フィールドとして TextView を定義
|
||||||
|
|||||||
+18
-5
@@ -13,17 +13,29 @@ import android.view.ViewGroup;
|
|||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
import dagger.hilt.android.AndroidEntryPoint;
|
||||||
|
import one.nem.lacerta.data.Document;
|
||||||
|
import one.nem.lacerta.model.document.DocumentMeta;
|
||||||
|
import one.nem.lacerta.model.document.tag.DocumentTag;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A simple {@link Fragment} subclass.
|
* A simple {@link Fragment} subclass.
|
||||||
* Use the {@link LibraryTopFragment#newInstance} factory method to
|
* Use the {@link LibraryTopFragment#newInstance} factory method to
|
||||||
* create an instance of this fragment.
|
* create an instance of this fragment.
|
||||||
*/
|
*/
|
||||||
|
@AndroidEntryPoint
|
||||||
public class LibraryTopFragment extends Fragment {
|
public class LibraryTopFragment extends Fragment {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
Document document;
|
||||||
|
|
||||||
// TODO: Rename parameter arguments, choose names that match
|
// TODO: Rename parameter arguments, choose names that match
|
||||||
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
|
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
|
||||||
private static final String ARG_PARAM1 = "param1";
|
private static final String ARG_PARAM1 = "param1";
|
||||||
@@ -76,13 +88,14 @@ public class LibraryTopFragment extends Fragment {
|
|||||||
LinearLayoutManager layoutManager = new LinearLayoutManager(getContext());
|
LinearLayoutManager layoutManager = new LinearLayoutManager(getContext());
|
||||||
documentRecyclerView.setLayoutManager(layoutManager);
|
documentRecyclerView.setLayoutManager(layoutManager);
|
||||||
|
|
||||||
List<String> documentList = new ArrayList<>();
|
//データを取得
|
||||||
documentList.add("Document A");
|
|
||||||
documentList.add("Document B");
|
List<DocumentMeta> metas = document.getAllDocumentMetas(100);
|
||||||
documentList.add("Document C");
|
|
||||||
|
Toast.makeText(getContext(), "Documents: " + Integer.toString(metas.size()), Toast.LENGTH_LONG).show();
|
||||||
|
|
||||||
// Create and set the adapter
|
// Create and set the adapter
|
||||||
DocumentAdapter adapter = new DocumentAdapter(documentList);
|
DocumentAdapter adapter = new DocumentAdapter(metas);
|
||||||
documentRecyclerView.setAdapter(adapter);
|
documentRecyclerView.setAdapter(adapter);
|
||||||
|
|
||||||
// Use a LinearLayoutManager to specify the layout
|
// Use a LinearLayoutManager to specify the layout
|
||||||
|
|||||||
+1
-33
@@ -1,7 +1,6 @@
|
|||||||
package one.nem.lacerta.processor.model;
|
package one.nem.lacerta.model.document.internal;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
public class XmlMetaModel {
|
public class XmlMetaModel {
|
||||||
|
|
||||||
@@ -71,35 +70,4 @@ public class XmlMetaModel {
|
|||||||
this.pages = pages;
|
this.pages = pages;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Public Methods
|
|
||||||
|
|
||||||
public void addPage(XmlMetaPageModel page) {
|
|
||||||
this.pages.add(page);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addPageAfterIndex(int index, XmlMetaPageModel page) {
|
|
||||||
this.pages.add(index, page);
|
|
||||||
|
|
||||||
//Update index
|
|
||||||
this.updateIndex();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void removePage(XmlMetaPageModel page) {
|
|
||||||
this.pages.remove(page);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void removePageAtIndex(int index) {
|
|
||||||
this.pages.remove(index);
|
|
||||||
|
|
||||||
//Update index
|
|
||||||
this.updateIndex();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Internal Methods
|
|
||||||
private void updateIndex() { // TODO-rca: 効率悪そう
|
|
||||||
for (int i = 0; i < this.pages.size(); i++) {
|
|
||||||
this.pages.get(i).setIndex(i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
+2
-12
@@ -1,8 +1,7 @@
|
|||||||
package one.nem.lacerta.processor.model;
|
package one.nem.lacerta.model.document.internal;
|
||||||
|
|
||||||
public class XmlMetaPageModel {
|
public class XmlMetaPageModel {
|
||||||
|
|
||||||
int index;
|
|
||||||
String filename;
|
String filename;
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
@@ -10,27 +9,18 @@ public class XmlMetaPageModel {
|
|||||||
public XmlMetaPageModel() {
|
public XmlMetaPageModel() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public XmlMetaPageModel(int index, String filename) {
|
public XmlMetaPageModel(String filename) {
|
||||||
this.index = index;
|
|
||||||
this.filename = filename;
|
this.filename = filename;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Getter
|
// Getter
|
||||||
|
|
||||||
public int getIndex() {
|
|
||||||
return index;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getFilename() {
|
public String getFilename() {
|
||||||
return filename;
|
return filename;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setter
|
// Setter
|
||||||
|
|
||||||
public void setIndex(int index) {
|
|
||||||
this.index = index;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setFilename(String filename) {
|
public void setFilename(String filename) {
|
||||||
this.filename = filename;
|
this.filename = filename;
|
||||||
}
|
}
|
||||||
@@ -5,11 +5,11 @@ import android.graphics.Bitmap;
|
|||||||
public interface DocumentProcessor {
|
public interface DocumentProcessor {
|
||||||
|
|
||||||
// ページ操作
|
// ページ操作
|
||||||
void addNewPageToLast(Bitmap bitmap);
|
void addNewPageToLast(Bitmap bitmap) throws Exception;
|
||||||
void addNewPagesToLast(Bitmap[] bitmaps);
|
void addNewPagesToLast(Bitmap[] bitmaps) throws Exception;
|
||||||
void addNewPageAfterIndex(Bitmap bitmap, int index);
|
void addNewPageAfterIndex(Bitmap bitmap, int index) throws Exception;
|
||||||
void addNewPageBeforeIndex(Bitmap bitmap, int index);
|
void addNewPageBeforeIndex(Bitmap bitmap, int index) throws Exception;
|
||||||
void removePageAtIndex(int index);
|
void removePageAtIndex(int index) throws Exception;
|
||||||
|
|
||||||
// 更新
|
// 更新
|
||||||
void updatePageAtIndex(Bitmap bitmap, int index);
|
void updatePageAtIndex(Bitmap bitmap, int index);
|
||||||
@@ -18,4 +18,7 @@ public interface DocumentProcessor {
|
|||||||
Bitmap getPageAtIndex(int index);
|
Bitmap getPageAtIndex(int index);
|
||||||
int getPageCount();
|
int getPageCount();
|
||||||
|
|
||||||
|
void close() throws Exception;
|
||||||
|
void init() throws Exception; // TODO-rca: 例外処理
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
package one.nem.lacerta.processor;
|
|
||||||
|
|
||||||
import one.nem.lacerta.processor.model.XmlMetaModel;
|
|
||||||
import one.nem.lacerta.processor.model.XmlMetaPageModel;
|
|
||||||
|
|
||||||
public interface XmlMetaProcessor {
|
|
||||||
|
|
||||||
void saveXmlMeta(XmlMetaModel xmlMetaModel);
|
|
||||||
XmlMetaModel loadXmlMeta();
|
|
||||||
}
|
|
||||||
+7
-1
@@ -1,4 +1,10 @@
|
|||||||
package one.nem.lacerta.processor.factory;
|
package one.nem.lacerta.processor.factory;
|
||||||
|
|
||||||
public class DocumentProcessorFactory {
|
import dagger.assisted.AssistedFactory;
|
||||||
|
import one.nem.lacerta.model.document.DocumentDetail;
|
||||||
|
import one.nem.lacerta.processor.impl.DocumentProcessorImpl;
|
||||||
|
|
||||||
|
@AssistedFactory
|
||||||
|
public interface DocumentProcessorFactory {
|
||||||
|
DocumentProcessorImpl create(DocumentDetail documentDetail);
|
||||||
}
|
}
|
||||||
+119
-24
@@ -2,60 +2,143 @@ package one.nem.lacerta.processor.impl;
|
|||||||
|
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import dagger.assisted.Assisted;
|
||||||
|
import dagger.assisted.AssistedInject;
|
||||||
|
import one.nem.lacerta.model.document.internal.XmlMetaPageModel;
|
||||||
import one.nem.lacerta.processor.DocumentProcessor;
|
import one.nem.lacerta.processor.DocumentProcessor;
|
||||||
|
|
||||||
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.internal.XmlMetaModel;
|
||||||
import one.nem.lacerta.source.file.FileManager;
|
import one.nem.lacerta.source.file.FileManager;
|
||||||
import one.nem.lacerta.source.file.factory.FileManagerFactory;
|
import one.nem.lacerta.source.file.factory.FileManagerFactory;
|
||||||
|
|
||||||
|
import one.nem.lacerta.utils.LacertaLogger;
|
||||||
|
|
||||||
|
import one.nem.lacerta.utils.XmlMetaParser;
|
||||||
|
|
||||||
|
|
||||||
public class DocumentProcessorImpl implements DocumentProcessor{
|
public class DocumentProcessorImpl implements DocumentProcessor{
|
||||||
|
|
||||||
// Magic Numbers
|
// Magic Numbers
|
||||||
private static final String DEFAULT_SAVE_DIR = "raw";
|
private static final String DEFAULT_SAVE_DIR = "raw";
|
||||||
|
|
||||||
private DocumentDetail documentDetail;
|
// Variables
|
||||||
|
private final DocumentDetail documentDetail;
|
||||||
|
private XmlMetaModel xmlMetaModel;
|
||||||
|
private Path documentRootPath;
|
||||||
|
private FileManager fileManager;
|
||||||
|
|
||||||
// Injection
|
// Injection
|
||||||
@Inject
|
private final FileManagerFactory fileManagerFactory;
|
||||||
FileManagerFactory fileManagerFactory;
|
private final LacertaLogger logger;
|
||||||
|
private final XmlMetaParser xmlMetaParser;
|
||||||
// Internal utils
|
@AssistedInject
|
||||||
|
public DocumentProcessorImpl(FileManagerFactory fileManagerFactory, LacertaLogger logger, XmlMetaParser xmlMetaParser, @Assisted DocumentDetail documentDetail) {
|
||||||
@Override
|
this.fileManagerFactory = fileManagerFactory;
|
||||||
public void addNewPageToLast(Bitmap bitmap) {
|
this.logger = logger;
|
||||||
Path path = documentDetail.getPath().getFullPath();
|
this.xmlMetaParser = xmlMetaParser;
|
||||||
String fileName = String.format(UUID.randomUUID().toString() + ".png"); // TODO-rca: 対応表をもたせる
|
if (documentDetail == null) {
|
||||||
FileManager fileManager = fileManagerFactory.create(path);
|
throw new IllegalArgumentException("documentDetail must not be null");
|
||||||
if(fileManager.getList().contains(path.resolve(DEFAULT_SAVE_DIR))) {
|
|
||||||
fileManager.changeDir(DEFAULT_SAVE_DIR);
|
|
||||||
} else {
|
|
||||||
fileManager.createDir(DEFAULT_SAVE_DIR);
|
|
||||||
fileManager.changeDir(DEFAULT_SAVE_DIR);
|
|
||||||
}
|
}
|
||||||
fileManager.saveBitmapAtCurrent(bitmap, fileName);
|
this.documentDetail = documentDetail;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addNewPagesToLast(Bitmap[] bitmaps) {
|
public void init() throws Exception{
|
||||||
|
logger.debug("init", "called");
|
||||||
|
// Init Variables
|
||||||
|
this.documentRootPath = this.documentDetail.getPath().getFullPath();
|
||||||
|
logger.debug("init", "documentRootPath: " + this.documentRootPath);
|
||||||
|
|
||||||
|
this.fileManager = fileManagerFactory.create(this.documentRootPath).enableAutoCreateParent(); //Initialize FileManager
|
||||||
|
|
||||||
|
FileManager initFileManager = this.fileManager.getNewInstance();
|
||||||
|
|
||||||
|
logger.debug("init", "fileManager created");
|
||||||
|
|
||||||
|
// xmlファイルの読み込み
|
||||||
|
if (initFileManager.isExist("meta.xml")) {
|
||||||
|
logger.debug("init", "meta.xml found");
|
||||||
|
try {
|
||||||
|
this.xmlMetaModel = xmlMetaParser.deserialize(this.fileManager.loadXml("meta.xml"));
|
||||||
|
logger.debug("init", "meta.xml parsed");
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.debug("init", "meta.xml parse failed");
|
||||||
|
logger.trace("init", e.getMessage());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
logger.debug("init", "meta.xml not found");
|
||||||
|
xmlMetaModel = new XmlMetaModel();
|
||||||
|
|
||||||
|
xmlMetaModel.setTitle(this.documentDetail.getMeta().getTitle());
|
||||||
|
xmlMetaModel.setAuthor(this.documentDetail.getAuthor());
|
||||||
|
xmlMetaModel.setDescription(""); // FIXME-rca:
|
||||||
|
xmlMetaModel.setDefaultBranch(this.documentDetail.getDefaultBranch());
|
||||||
|
xmlMetaModel.setPages(new ArrayList<>());
|
||||||
|
|
||||||
|
try {
|
||||||
|
initFileManager.createFileIfNotExist("meta.xml").saveXml(xmlMetaParser.serialize(xmlMetaModel), "meta.xml");
|
||||||
|
logger.debug("init", "meta.xml saved");
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("init", "meta.xml save failed");
|
||||||
|
logger.trace("init", e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.info("init", "finished");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addNewPageAfterIndex(Bitmap bitmap, int index) {
|
public void addNewPageToLast(Bitmap bitmap) throws Exception{
|
||||||
|
logger.debug("addNewPageToLast", "called");
|
||||||
|
String filename = UUID.randomUUID().toString() + ".png"; // TODO-rca: 拡張子を動的にする
|
||||||
|
|
||||||
|
this.fileManager.getNewInstance().createDirectoryIfNotExist(DEFAULT_SAVE_DIR).resolve(DEFAULT_SAVE_DIR).saveBitmap(bitmap, filename);
|
||||||
|
|
||||||
|
XmlMetaPageModel xmlMetaPageModel = new XmlMetaPageModel();
|
||||||
|
xmlMetaPageModel.setFilename(filename);
|
||||||
|
xmlMetaModel.getPages().add(xmlMetaPageModel);
|
||||||
|
|
||||||
|
logger.info("addNewPageToLast", "finished");
|
||||||
|
logger.info("addNewPageToLast", "filename: " + filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addNewPageBeforeIndex(Bitmap bitmap, int index) {
|
public void addNewPagesToLast(Bitmap[] bitmaps) throws Exception{
|
||||||
|
logger.debug("addNewPagesToLast", "called");
|
||||||
|
|
||||||
|
for (Bitmap bitmap : bitmaps) {
|
||||||
|
addNewPageToLast(bitmap);
|
||||||
|
} // TODO-rca: 効率悪いので改善する
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addNewPageAfterIndex(Bitmap bitmap, int index) throws Exception {
|
||||||
|
logger.debug("addNewPageAfterIndex", "called");
|
||||||
|
String filename = UUID.randomUUID().toString() + ".png"; // TODO-rca: 拡張子を動的にする
|
||||||
|
|
||||||
|
this.fileManager.getNewInstance().createDirectoryIfNotExist(DEFAULT_SAVE_DIR).resolve(DEFAULT_SAVE_DIR).saveBitmap(bitmap, filename);
|
||||||
|
|
||||||
|
XmlMetaPageModel xmlMetaPageModel = new XmlMetaPageModel();
|
||||||
|
xmlMetaPageModel.setFilename(filename);
|
||||||
|
xmlMetaModel.getPages().add(index, xmlMetaPageModel);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addNewPageBeforeIndex(Bitmap bitmap, int index) throws Exception {
|
||||||
|
logger.debug("addNewPageBeforeIndex", "called");
|
||||||
|
String filename = UUID.randomUUID().toString() + ".png"; // TODO-rca: 拡張子を動的にする
|
||||||
|
|
||||||
|
this.fileManager.getNewInstance().createDirectoryIfNotExist(DEFAULT_SAVE_DIR).resolve(DEFAULT_SAVE_DIR).saveBitmap(bitmap, filename);
|
||||||
|
|
||||||
|
XmlMetaPageModel xmlMetaPageModel = new XmlMetaPageModel();
|
||||||
|
xmlMetaPageModel.setFilename(filename);
|
||||||
|
xmlMetaModel.getPages().add(index - 1, xmlMetaPageModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -77,4 +160,16 @@ public class DocumentProcessorImpl implements DocumentProcessor{
|
|||||||
public int getPageCount() {
|
public int getPageCount() {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close() throws Exception{
|
||||||
|
logger.debug("close", "called");
|
||||||
|
try {
|
||||||
|
this.fileManager.getNewInstance().createFileIfNotExist("meta.xml").saveXml(xmlMetaParser.serialize(xmlMetaModel), "meta.xml");
|
||||||
|
logger.debug("close", "meta.xml saved");
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("close", "meta.xml save failed");
|
||||||
|
logger.trace("close", e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
package one.nem.lacerta.processor.impl;
|
|
||||||
|
|
||||||
import one.nem.lacerta.processor.XmlMetaProcessor;
|
|
||||||
import one.nem.lacerta.processor.model.XmlMetaModel;
|
|
||||||
|
|
||||||
public class XmlMetaProcessorImpl implements XmlMetaProcessor{
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void saveXmlMeta(XmlMetaModel xmlMetaModel) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public XmlMetaModel loadXmlMeta() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,4 +1,16 @@
|
|||||||
package one.nem.lacerta.processor.module;
|
package one.nem.lacerta.processor.module;
|
||||||
|
|
||||||
|
import dagger.assisted.Assisted;
|
||||||
|
import dagger.assisted.AssistedInject;
|
||||||
|
import one.nem.lacerta.model.document.DocumentDetail;
|
||||||
|
|
||||||
public class DocumentProcessorModule {
|
public class DocumentProcessorModule {
|
||||||
|
|
||||||
|
private final DocumentDetail documentDetail;
|
||||||
|
|
||||||
|
@AssistedInject
|
||||||
|
public DocumentProcessorModule(@Assisted DocumentDetail documentDetail) {
|
||||||
|
this.documentDetail = documentDetail;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -2,26 +2,64 @@ package one.nem.lacerta.source.file;
|
|||||||
|
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
|
|
||||||
|
import org.w3c.dom.Document;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.lang.reflect.Field;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
|
/** @noinspection unused*/
|
||||||
public interface FileManager {
|
public interface FileManager {
|
||||||
|
|
||||||
Path getRootDir();
|
File getFileRef();
|
||||||
void changeDir(String dirName); //cd
|
boolean isExist(String name) throws IOException;
|
||||||
void backDir(); //cd ..
|
boolean isExist();
|
||||||
void backRootDir(); //cd /
|
boolean isDirectory();
|
||||||
List<Path> getList();
|
boolean isFile();
|
||||||
void createDir(String dirName);
|
boolean isWritable();
|
||||||
void removeDir(String dirName);
|
boolean isReadable();
|
||||||
|
// Get current instance
|
||||||
|
FileManager getCurrentInstance();
|
||||||
|
FileManager getNewInstance();
|
||||||
|
|
||||||
void saveBitmapAtCurrent(Bitmap bitmap, String fileName);
|
// Configure
|
||||||
Bitmap loadBitmap(Path path);
|
FileManager enableAutoCreateParent();
|
||||||
void removeBitmap(Path path);
|
FileManager disableRootDirCheck();
|
||||||
|
|
||||||
// void saveFileAtCurrent(File file);
|
FileManager setRootDir(Path rootDir);
|
||||||
// File getFile(Path path);
|
FileManager setPath(Path path);
|
||||||
// void removeFile(Path path);
|
FileManager resolve(String path) throws IOException;
|
||||||
|
|
||||||
|
// Create
|
||||||
|
FileManager createFile() throws IOException;
|
||||||
|
FileManager createFile(String fileName) throws IOException;
|
||||||
|
FileManager createFileIfNotExist() throws IOException;
|
||||||
|
FileManager createFileIfNotExist(String fileName) throws IOException;
|
||||||
|
FileManager createDirectory() throws IOException;
|
||||||
|
FileManager createDirectory(String directoryName) throws IOException;
|
||||||
|
FileManager createDirectoryIfNotExist() throws IOException;
|
||||||
|
FileManager createDirectoryIfNotExist(String directoryName) throws IOException;
|
||||||
|
|
||||||
|
// Save
|
||||||
|
// XML
|
||||||
|
void saveXml(Document document, String fileName) throws IOException;
|
||||||
|
void saveXml(Document document) throws IOException;
|
||||||
|
|
||||||
|
// Bitmap
|
||||||
|
void saveBitmap(Bitmap bitmap, String fileName) throws IOException; // TODO-rca: パラメータに対応させる
|
||||||
|
void saveBitmap(Bitmap bitmap) throws IOException; // TODO-rca: パラメータに対応させる
|
||||||
|
|
||||||
|
|
||||||
|
// Load
|
||||||
|
// XML
|
||||||
|
Document loadXml(String fileName) throws IOException;
|
||||||
|
Document loadXml() throws IOException;
|
||||||
|
|
||||||
|
// Bitmap
|
||||||
|
Bitmap loadBitmap(String fileName) throws IOException;
|
||||||
|
Bitmap loadBitmap() throws IOException;
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,130 +1,364 @@
|
|||||||
package one.nem.lacerta.source.file.impl;
|
package one.nem.lacerta.source.file.impl;
|
||||||
|
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
|
import android.graphics.BitmapFactory;
|
||||||
|
|
||||||
|
import org.w3c.dom.Document;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.DirectoryStream;
|
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.xml.parsers.DocumentBuilder;
|
||||||
|
import javax.xml.parsers.DocumentBuilderFactory;
|
||||||
|
import javax.xml.transform.Transformer;
|
||||||
|
import javax.xml.transform.TransformerFactory;
|
||||||
|
import javax.xml.transform.dom.DOMSource;
|
||||||
|
import javax.xml.transform.stream.StreamResult;
|
||||||
|
|
||||||
import dagger.assisted.Assisted;
|
import dagger.assisted.Assisted;
|
||||||
import dagger.assisted.AssistedInject;
|
import dagger.assisted.AssistedInject;
|
||||||
import one.nem.lacerta.source.file.FileManager;
|
import one.nem.lacerta.source.file.FileManager;
|
||||||
|
|
||||||
|
import one.nem.lacerta.utils.LacertaLogger;
|
||||||
|
|
||||||
public class FileManagerImpl implements FileManager {
|
public class FileManagerImpl implements FileManager {
|
||||||
|
|
||||||
// RootDir
|
// variables
|
||||||
private Path rootDir;
|
private Path rootDir;
|
||||||
|
private Path path;
|
||||||
|
private boolean autoCreateParent = false;
|
||||||
|
private boolean disableRootDirCheck = false;
|
||||||
|
|
||||||
// CurrentDir
|
|
||||||
private Path currentDir;
|
|
||||||
|
|
||||||
// Internal Methods
|
// Injection
|
||||||
private Path convertPath(String path) {
|
private final LacertaLogger logger;
|
||||||
Path convertedPath = currentDir.resolve(path);
|
@AssistedInject
|
||||||
if (convertedPath.startsWith(rootDir)) { // 異常なパスの場合はnullを返す // TODO-rca: エラーハンドリング
|
public FileManagerImpl(LacertaLogger logger, @Assisted Path rootDir) {
|
||||||
return convertedPath;
|
this.logger = logger;
|
||||||
|
this.rootDir = rootDir;
|
||||||
|
}
|
||||||
|
|
||||||
|
// for generate new instance
|
||||||
|
public FileManagerImpl(LacertaLogger logger, Path rootDir, Path path, boolean autoCreateParent, boolean disableRootDirCheck) {
|
||||||
|
this.logger = logger;
|
||||||
|
this.rootDir = rootDir;
|
||||||
|
this.path = path;
|
||||||
|
this.autoCreateParent = autoCreateParent;
|
||||||
|
this.disableRootDirCheck = disableRootDirCheck;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Internal
|
||||||
|
private Path resolveStringPath(String path) throws IOException{
|
||||||
|
String[] pathArray = path.split("/");
|
||||||
|
Path resolvedPath = this.path;
|
||||||
|
for (String pathPart : pathArray) {
|
||||||
|
if (pathPart.equals("..")) {
|
||||||
|
resolvedPath = resolvedPath.getParent();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
resolvedPath = resolvedPath.resolve(pathPart);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new IOException("Invalid path: " + path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
logger.debug("resolveStringPath", "resolvedPath: " + resolvedPath);
|
||||||
|
return resolvedPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
private FileManager newInstance(Path rootDir, Path path, boolean autoCreateParent, boolean disableRootDirCheck) {
|
||||||
|
logger.debug("newInstance", "Generating new instance");
|
||||||
|
logger.debug("newInstance", "Path: " + path);
|
||||||
|
return new FileManagerImpl(this.logger, rootDir, path, autoCreateParent, disableRootDirCheck);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public File getFileRef() {
|
||||||
|
if (this.isExist()) {
|
||||||
|
return this.path.toFile();
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@AssistedInject
|
@Override
|
||||||
public FileManagerImpl(@Assisted Path rootDir) {
|
public boolean isExist(String name) throws IOException {
|
||||||
this.rootDir = rootDir;
|
Path resolvedPath = this.resolveStringPath(name);
|
||||||
this.currentDir = rootDir;
|
return Files.exists(resolvedPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Path getRootDir() {
|
public boolean isExist(){
|
||||||
return rootDir;
|
return Files.exists(this.path);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void changeDir(String dirName) {
|
public boolean isDirectory() {
|
||||||
this.currentDir = rootDir.resolve(dirName);
|
if (this.isExist()) {
|
||||||
|
File file = this.path.toFile();
|
||||||
|
return file.isDirectory();
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void backDir() {
|
public boolean isFile() {
|
||||||
this.currentDir = currentDir.getParent();
|
if (this.isExist()) {
|
||||||
|
File file = this.path.toFile();
|
||||||
|
return file.isFile();
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void backRootDir() {
|
public boolean isReadable() {
|
||||||
this.currentDir = rootDir;
|
if (this.isExist()) {
|
||||||
|
File file = this.path.toFile();
|
||||||
|
return file.canRead();
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Path> getList() {
|
public boolean isWritable() {
|
||||||
List<Path> list = new ArrayList<>();
|
if (this.isExist()) {
|
||||||
try (DirectoryStream<Path> stream = Files.newDirectoryStream(currentDir)) {
|
File file = this.path.toFile();
|
||||||
for (Path entry : stream) { // TODO-rca: エラーハンドリング, 効率化
|
return file.canWrite();
|
||||||
list.add(entry);
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FileManager getCurrentInstance() {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FileManager getNewInstance() {
|
||||||
|
return this.newInstance(this.rootDir, this.rootDir, this.autoCreateParent, this.disableRootDirCheck);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FileManager enableAutoCreateParent() {
|
||||||
|
this.autoCreateParent = true;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FileManager disableRootDirCheck() {
|
||||||
|
this.disableRootDirCheck = true;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FileManager setRootDir(Path rootDir) {
|
||||||
|
return this.newInstance(rootDir, this.path, this.autoCreateParent, this.disableRootDirCheck);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FileManager setPath(Path path) {
|
||||||
|
Path resolvedPath;
|
||||||
|
if (this.disableRootDirCheck) {
|
||||||
|
resolvedPath = path;
|
||||||
|
} else {
|
||||||
|
if (path.startsWith(this.rootDir)) {
|
||||||
|
resolvedPath = path;
|
||||||
|
} else {
|
||||||
|
throw new IllegalArgumentException("path must be in rootDir");
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
return list;
|
logger.debug("setPath", "resolvedPath: " + resolvedPath);
|
||||||
|
return this.newInstance(this.rootDir, resolvedPath, this.autoCreateParent, this.disableRootDirCheck);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void createDir(String dirName) {
|
public FileManager resolve(String path) throws IOException{
|
||||||
currentDir.resolve(dirName).toFile().mkdir(); // TODO-rca: エラーハンドリング
|
Path resolvedPath;
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void removeDir(String dirName) {
|
|
||||||
currentDir.resolve(dirName).toFile().delete(); // TODO-rca: エラーハンドリング
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void saveBitmapAtCurrent(Bitmap bitmap, String fileName) { // TODO-rca: ファイル形式を変更できるようにする?
|
|
||||||
try {
|
try {
|
||||||
File file = currentDir.resolve(fileName).toFile();
|
resolvedPath = resolveStringPath(path);
|
||||||
bitmap.compress(Bitmap.CompressFormat.PNG, 100, Files.newOutputStream(file.toPath()));
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
logger.error("resolve", e.getMessage());
|
||||||
|
throw new IOException("Invalid path: " + path);
|
||||||
|
}
|
||||||
|
return this.setPath(resolvedPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Internal
|
||||||
|
private void createFileInternal(Path path) throws IOException {
|
||||||
|
try {
|
||||||
|
if (this.autoCreateParent) {
|
||||||
|
if (!path.getParent().toFile().exists()) {
|
||||||
|
Files.createDirectories(path.getParent());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Files.createFile(path);
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("createFileInternal", e.getMessage());
|
||||||
|
throw new IOException("Failed to create file");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Bitmap loadBitmap(Path path) {
|
public FileManager createFile() throws IOException {
|
||||||
return null;
|
this.createFileInternal(this.path);
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeBitmap(Path path) {
|
public FileManager createFile(String fileName) throws IOException { // pathが書き換わってしまうのは想像できない挙動かも?
|
||||||
|
this.createFileInternal(this.resolveStringPath(fileName));
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Override
|
@Override
|
||||||
// public void saveFileAtCurrent(File file) {
|
public FileManager createFileIfNotExist() throws IOException {
|
||||||
// try {
|
if (!this.isExist()) {
|
||||||
// Files.copy(file.toPath(), currentDir.resolve(file.getName()));
|
this.createFile();
|
||||||
// } catch (IOException e) {
|
}
|
||||||
// e.printStackTrace();
|
return this;
|
||||||
// }
|
}
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public File getFile(Path path) {
|
|
||||||
// // ファイルを取得する
|
|
||||||
// return path.toFile();
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public void removeFile(Path path) {
|
|
||||||
// // ファイルを削除する
|
|
||||||
// if (path.toFile().exists()) {
|
|
||||||
// path.toFile().delete(); // Resultを返す?
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FileManager createFileIfNotExist(String fileName) throws IOException {
|
||||||
|
if (!this.isExist(fileName)) {
|
||||||
|
this.createFile(fileName);
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Internal
|
||||||
|
private void createDirectoryInternal(Path path) throws IOException {
|
||||||
|
try {
|
||||||
|
if (this.autoCreateParent) {
|
||||||
|
if (!path.getParent().toFile().exists()) {
|
||||||
|
Files.createDirectories(path.getParent());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Files.createDirectory(path);
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("createDirectoryInternal", e.getMessage());
|
||||||
|
throw new IOException("Failed to create directory");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FileManager createDirectory() throws IOException {
|
||||||
|
this.createDirectoryInternal(this.path);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FileManager createDirectory(String directoryName) throws IOException {
|
||||||
|
this.createDirectoryInternal(this.resolveStringPath(directoryName));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FileManager createDirectoryIfNotExist() throws IOException {
|
||||||
|
if (!this.isExist()) {
|
||||||
|
this.createDirectory();
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FileManager createDirectoryIfNotExist(String directoryName) throws IOException {
|
||||||
|
if (!this.isExist(directoryName)) {
|
||||||
|
this.createDirectory(directoryName);
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Internal
|
||||||
|
private void saveXmlInternal(Document document, Path path) throws IOException {
|
||||||
|
try {
|
||||||
|
TransformerFactory transformerFactory = TransformerFactory.newInstance();
|
||||||
|
Transformer transformer = transformerFactory.newTransformer();
|
||||||
|
DOMSource source = new DOMSource(document);
|
||||||
|
|
||||||
|
StreamResult result = new StreamResult(path.toFile());
|
||||||
|
|
||||||
|
transformer.transform(source, result);
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("saveXmlInternal", e.getMessage());
|
||||||
|
e.printStackTrace();
|
||||||
|
throw new IOException("Failed to save xml");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void saveBitmapInternal(Bitmap bitmap, Path path) throws IOException {
|
||||||
|
try {
|
||||||
|
logger.debug("saveBitmapInternal", "path: " + path);
|
||||||
|
bitmap.compress(Bitmap.CompressFormat.PNG, 100, Files.newOutputStream(path));
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("saveBitmapInternal", e.getMessage());
|
||||||
|
throw new IOException("Failed to save bitmap");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void saveXml(Document document, String fileName) throws IOException {
|
||||||
|
this.saveXmlInternal(document, this.resolveStringPath(fileName));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void saveXml(Document document) throws IOException {
|
||||||
|
this.saveXmlInternal(document, this.path);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void saveBitmap(Bitmap bitmap, String fileName) throws IOException {
|
||||||
|
this.saveBitmapInternal(bitmap, this.resolveStringPath(fileName));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void saveBitmap(Bitmap bitmap) throws IOException {
|
||||||
|
this.saveBitmapInternal(bitmap, this.path);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Internal
|
||||||
|
private Document loadXmlInternal(Path path) throws IOException {
|
||||||
|
try {
|
||||||
|
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
||||||
|
DocumentBuilder builder = factory.newDocumentBuilder();
|
||||||
|
return builder.parse(Files.newInputStream(path));
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("loadXmlInternal", e.getMessage());
|
||||||
|
throw new IOException("Failed to load xml");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private Bitmap loadBitmapInternal(Path path) throws IOException {
|
||||||
|
try {
|
||||||
|
return BitmapFactory.decodeFile(path.toString());
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("loadBitmapInternal", e.getMessage());
|
||||||
|
throw new IOException("Failed to load bitmap");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Document loadXml(String fileName) throws IOException {
|
||||||
|
return this.loadXmlInternal(this.resolveStringPath(fileName));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Document loadXml() throws IOException {
|
||||||
|
return this.loadXmlInternal(this.path);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Bitmap loadBitmap(String fileName) throws IOException {
|
||||||
|
return this.loadBitmapInternal(this.resolveStringPath(fileName));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Bitmap loadBitmap() throws IOException {
|
||||||
|
return this.loadBitmapInternal(this.path);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+2
-1
@@ -37,5 +37,6 @@ dependencies {
|
|||||||
implementation libs.com.google.dagger.hilt.android
|
implementation libs.com.google.dagger.hilt.android
|
||||||
annotationProcessor libs.com.google.dagger.hilt.compiler
|
annotationProcessor libs.com.google.dagger.hilt.compiler
|
||||||
|
|
||||||
//
|
// model
|
||||||
|
implementation project(':model')
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
package one.nem.lacerta.utils;
|
package one.nem.lacerta.utils;
|
||||||
|
|
||||||
|
import one.nem.lacerta.utils.model.KeyValueLog;
|
||||||
|
|
||||||
public interface LacertaLogger {
|
public interface LacertaLogger {
|
||||||
|
|
||||||
void info(String tag, String message);
|
void info(String tag, String message);
|
||||||
@@ -9,4 +11,7 @@ public interface LacertaLogger {
|
|||||||
void trace(String tag, String message);
|
void trace(String tag, String message);
|
||||||
void fatal(String tag, String message);
|
void fatal(String tag, String message);
|
||||||
|
|
||||||
|
String buildKVMessage(KeyValueLog... logs);
|
||||||
|
// With name
|
||||||
|
String buildKVMessage(String name, KeyValueLog... logs);
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package one.nem.lacerta.utils;
|
||||||
|
|
||||||
|
import org.w3c.dom.Document;
|
||||||
|
|
||||||
|
import one.nem.lacerta.model.document.internal.XmlMetaModel;
|
||||||
|
|
||||||
|
public interface XmlMetaParser {
|
||||||
|
|
||||||
|
XmlMetaModel deserialize(Document document);
|
||||||
|
|
||||||
|
Document serialize(XmlMetaModel meta);
|
||||||
|
|
||||||
|
}
|
||||||
@@ -5,6 +5,8 @@ import android.util.Log;
|
|||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import one.nem.lacerta.utils.LacertaLogger;
|
import one.nem.lacerta.utils.LacertaLogger;
|
||||||
|
import one.nem.lacerta.utils.model.KeyValueLog;
|
||||||
|
|
||||||
public class LacertaLoggerImpl implements LacertaLogger{
|
public class LacertaLoggerImpl implements LacertaLogger{
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
@@ -40,4 +42,30 @@ public class LacertaLoggerImpl implements LacertaLogger{
|
|||||||
public void fatal(String tag, String message) {
|
public void fatal(String tag, String message) {
|
||||||
Log.wtf(tag, message);
|
Log.wtf(tag, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String buildKVMessage(KeyValueLog... logs) {
|
||||||
|
StringBuilder builder = new StringBuilder();
|
||||||
|
for (KeyValueLog log : logs) {
|
||||||
|
builder.append(log.getKey());
|
||||||
|
builder.append(": ");
|
||||||
|
builder.append(log.getValue());
|
||||||
|
builder.append("\n");
|
||||||
|
}
|
||||||
|
return builder.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String buildKVMessage(String name, KeyValueLog... logs) {
|
||||||
|
StringBuilder builder = new StringBuilder();
|
||||||
|
builder.append(name);
|
||||||
|
builder.append("\n");
|
||||||
|
for (KeyValueLog log : logs) {
|
||||||
|
builder.append(log.getKey());
|
||||||
|
builder.append(": ");
|
||||||
|
builder.append(log.getValue());
|
||||||
|
builder.append("\n");
|
||||||
|
}
|
||||||
|
return builder.toString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,96 @@
|
|||||||
|
package one.nem.lacerta.utils.impl;
|
||||||
|
|
||||||
|
import org.w3c.dom.Document;
|
||||||
|
import org.w3c.dom.Element;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import javax.xml.parsers.DocumentBuilder;
|
||||||
|
import javax.xml.parsers.DocumentBuilderFactory;
|
||||||
|
|
||||||
|
import one.nem.lacerta.model.document.internal.XmlMetaModel;
|
||||||
|
import one.nem.lacerta.model.document.internal.XmlMetaPageModel;
|
||||||
|
import one.nem.lacerta.utils.XmlMetaParser;
|
||||||
|
|
||||||
|
import one.nem.lacerta.utils.LacertaLogger;
|
||||||
|
|
||||||
|
public class XmlMetaParserImpl implements XmlMetaParser{
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
LacertaLogger logger;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
public XmlMetaParserImpl() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public XmlMetaModel deserialize(Document document) {
|
||||||
|
logger.debug("deserialize", "called");
|
||||||
|
try {
|
||||||
|
Element rootElement = document.getDocumentElement();
|
||||||
|
|
||||||
|
XmlMetaModel meta = new XmlMetaModel();
|
||||||
|
|
||||||
|
meta.setTitle(rootElement.getElementsByTagName("title").item(0).getTextContent());
|
||||||
|
meta.setAuthor(rootElement.getElementsByTagName("author").item(0).getTextContent());
|
||||||
|
meta.setDescription(rootElement.getElementsByTagName("description").item(0).getTextContent());
|
||||||
|
meta.setDefaultBranch(rootElement.getElementsByTagName("defaultBranch").item(0).getTextContent());
|
||||||
|
|
||||||
|
ArrayList<XmlMetaPageModel> pages = new ArrayList<>();
|
||||||
|
for(int i = 0; i < rootElement.getElementsByTagName("pages").getLength(); i++) {
|
||||||
|
Element pageElement = (Element) rootElement.getElementsByTagName("page").item(i);
|
||||||
|
XmlMetaPageModel page = new XmlMetaPageModel();
|
||||||
|
page.setFilename(pageElement.getElementsByTagName("filename").item(0).getTextContent());
|
||||||
|
pages.add(page);
|
||||||
|
}
|
||||||
|
|
||||||
|
meta.setPages(pages);
|
||||||
|
|
||||||
|
return meta;
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("deserialize", "something wrong");
|
||||||
|
logger.trace("deserialize", e.getMessage());
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public Document serialize(XmlMetaModel meta) {
|
||||||
|
logger.debug("serialize", "called");
|
||||||
|
try {
|
||||||
|
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
||||||
|
DocumentBuilder builder = factory.newDocumentBuilder();
|
||||||
|
Document document = builder.newDocument();
|
||||||
|
|
||||||
|
Element rootElement = document.createElement("meta");
|
||||||
|
|
||||||
|
appendElement(document, rootElement, "title", meta.getTitle());
|
||||||
|
appendElement(document, rootElement, "author", meta.getAuthor());
|
||||||
|
appendElement(document, rootElement, "description", meta.getDescription());
|
||||||
|
appendElement(document, rootElement, "defaultBranch", meta.getDefaultBranch());
|
||||||
|
|
||||||
|
Element pagesElement = document.createElement("pages");
|
||||||
|
for(XmlMetaPageModel page : meta.getPages()) {
|
||||||
|
Element pageElement = document.createElement("page");
|
||||||
|
appendElement(document, pageElement, "filename", page.getFilename());
|
||||||
|
pagesElement.appendChild(pageElement);
|
||||||
|
}
|
||||||
|
|
||||||
|
rootElement.appendChild(pagesElement);
|
||||||
|
|
||||||
|
document.appendChild(rootElement);
|
||||||
|
|
||||||
|
return document;
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("serialize", "something wrong");
|
||||||
|
logger.trace("serialize", e.getMessage());
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
// Internal Methods
|
||||||
|
private void appendElement(Document document, Element rootElement, String name, String textContent) {
|
||||||
|
Element element = document.createElement(name);
|
||||||
|
element.setTextContent(textContent);
|
||||||
|
rootElement.appendChild(element);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
package one.nem.lacerta.utils.model;
|
||||||
|
|
||||||
|
public class KeyValueLog {
|
||||||
|
|
||||||
|
String key;
|
||||||
|
String value;
|
||||||
|
|
||||||
|
public KeyValueLog(String key, String value) {
|
||||||
|
this.key = key;
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Getter
|
||||||
|
public String getKey() {
|
||||||
|
return key;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Setter
|
||||||
|
public void setKey(String key) {
|
||||||
|
this.key = key;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setValue(String value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package one.nem.lacerta.utils.module;
|
||||||
|
|
||||||
|
|
||||||
|
import dagger.Binds;
|
||||||
|
import dagger.Module;
|
||||||
|
import dagger.hilt.InstallIn;
|
||||||
|
import dagger.hilt.components.SingletonComponent;
|
||||||
|
|
||||||
|
import one.nem.lacerta.utils.XmlMetaParser;
|
||||||
|
import one.nem.lacerta.utils.impl.XmlMetaParserImpl;
|
||||||
|
@Module
|
||||||
|
@InstallIn(SingletonComponent.class)
|
||||||
|
abstract public class XmlMetaParserModule {
|
||||||
|
|
||||||
|
@Binds
|
||||||
|
public abstract XmlMetaParser bindXmlMetaParser(XmlMetaParserImpl impl);
|
||||||
|
}
|
||||||
Reference in new issue
Block a user