Compare commits

..
Author SHA1 Message Date
r-ca a7286f0a4a レイアウトマージン設定 2023-12-21 12:19:48 +09:00
r-ca cbe34bfed2 余白が異常に大きくなるのを修正 2023-12-21 12:18:50 +09:00
r-ca 62f5d53bb3 コメント追加 2023-12-21 12:01:30 +09:00
r-ca cd1f2b2261 一旦保存して読み込むように 2023-12-21 12:00:56 +09:00
r-ca 54abcb1ac9 権限修正 2023-12-21 12:00:45 +09:00
r-ca ea2307e347 プロバイダパスを追加 2023-12-21 11:48:19 +09:00
r-ca af383835b3 プロバイダパスを追加 2023-12-21 11:48:16 +09:00
r-ca d325866c3a AndroidManifest.xmlにFileProviderを追加 WIP 2023-12-21 11:47:33 +09:00
r-ca a37648d9d5 取得される画像の解像度が低すぎるので修正 WIP 2023-12-21 11:37:54 +09:00
r-ca 98565c799f レイアウト修正 2023-12-20 12:55:09 +09:00
r-ca df70d27f23 レイアウト修正 2023-12-20 12:54:21 +09:00
r-ca deac33a3d6 Revert "Revert "内部クラスじゃだめそうなので切り出し""
This reverts commit ba4ff5652e.
2023-12-20 12:49:43 +09:00
r-ca 19c52b89a6 Revert "Revert "WIP 内部クラスじゃだめそうなので切り出し""
This reverts commit aea6ea3808.
2023-12-20 12:49:43 +09:00
r-ca 2e617baf1c WIP 2023-12-20 12:49:21 +09:00
r-ca aea6ea3808 Revert "WIP 内部クラスじゃだめそうなので切り出し"
This reverts commit 9a71fb5c26.
2023-12-20 12:48:02 +09:00
r-ca ba4ff5652e Revert "内部クラスじゃだめそうなので切り出し"
This reverts commit c0e64ad5fd.
2023-12-20 12:48:02 +09:00
r-ca c0e64ad5fd 内部クラスじゃだめそうなので切り出し 2023-12-20 12:47:56 +09:00
r-ca 9a71fb5c26 WIP 内部クラスじゃだめそうなので切り出し 2023-12-20 12:46:54 +09:00
r-ca 1419100e1f WIP 結果をプレビューするロジック実装 2023-12-20 12:44:55 +09:00
r-ca 576d1d7c9b 命名修正 2023-12-20 12:42:44 +09:00
r-ca c1d132a460 レイアウト修正 2023-12-20 12:41:45 +09:00
r-ca 94faf3c56d fix typo 2023-12-20 12:41:17 +09:00
r-ca cc9423ef17 レイアウト修正 2023-12-20 12:38:17 +09:00
r-ca 714b3e9e6e レイアウト修正 2023-12-20 12:33:55 +09:00
r-ca aadd0ae17c レイアウト修正 2023-12-20 12:32:08 +09:00
r-ca 3bfbd904f4 レイアウト実装WIP 2023-12-20 12:29:32 +09:00
r-ca 64fe9abc20 レイアウトファイル作成 2023-12-20 12:25:31 +09:00
r-ca e4d77d9245 仮置きデータモデル作成 2023-12-20 12:24:31 +09:00
r-ca 05586c181f 仮置きデータモデル作成 2023-12-20 12:23:14 +09:00
r-ca a8d27e408c レイアウトにRecyclerViewを追加 2023-12-20 12:21:31 +09:00
r-ca a9273561b1 まちがえてrequireActivityを使っていたので修正 2023-12-20 12:13:06 +09:00
r-ca 0946fa80f1 ログ追加 2023-12-20 12:12:35 +09:00
r-ca 06a0e53639 パーミッションを追加してみた 2023-12-20 12:12:30 +09:00
r-ca d9a56fd2ce デバッグメニューにリンクを追加 2023-12-20 12:05:49 +09:00
r-ca d78ebd0b7c 暫定, debugメニューのナビゲーショングラフに追加 2023-12-20 12:05:12 +09:00
r-ca 9f11005c4f fix typo 2023-12-20 12:04:10 +09:00
r-ca 3fd0a3efe5 fix typo 2023-12-20 12:03:54 +09:00
r-ca 8054f0d4f9 debugの依存関係にスキャナコンポーネントを追加 2023-12-20 12:02:53 +09:00
r-ca 7de08a4d62 ボタンアクションを実装 2023-12-20 12:02:07 +09:00
r-ca 81411d5271 カメラ起動を実装 2023-12-20 12:00:11 +09:00
r-ca ca8e272980 ArrayListに変更 2023-12-20 11:59:50 +09:00
r-ca 562034d8a5 ロジック実装 WIP 2023-12-20 11:58:55 +09:00
r-ca d64038b9eb 引数削除 2023-12-20 11:49:58 +09:00
r-ca 71c6ab68e1 スタイル変更 2023-12-20 11:49:24 +09:00
r-ca 4855f6c75e レイアウトマージン修正 2023-12-20 11:49:02 +09:00
r-ca b1bdfb4ae4 テーマ設定 2023-12-20 11:48:32 +09:00
r-ca a70f92a872 依存関係追加 2023-12-20 11:48:12 +09:00
r-ca 9a48dbdaea レイアウト作成 WIP 2023-12-20 11:47:23 +09:00
r-ca b083a98ef6 スキャナのスタブを実装 WIP 2023-12-20 11:44:14 +09:00
r-ca 05e2a0360f 一旦過去に作成したフラグメントを削除 2023-12-20 11:42:30 +09:00
55 changed files with 56 additions and 1628 deletions

No files matched your search

@@ -1,17 +0,0 @@
---
name: 不具合用テンプレート
about: 不具合用テンプレート
title: "[BUG]: "
labels: バグ
assignees: ''
---
# 概要
<!-- Issueの概要 -->
# 詳細
<!-- バグの詳細 -->
# 影響箇所
<!-- 予想される影響箇所(省略可) -->
@@ -1,17 +0,0 @@
---
name: 改善用テンプレート
about: 改善用テンプレート
title: "[IMPROVE]"
labels: ''
assignees: ''
---
# 概要
<!-- Issueの概要 -->
# 詳細
<!-- 改善内容の詳細 -->
# 影響箇所
<!-- 予想される影響箇所(省略可) -->
@@ -1,20 +1,10 @@
---
name: 新機能用テンプレート
about: 新規能用テンプレート
about: 新規開発Issue用テンプレート
title: ''
labels: 新機能
labels: ''
assignees: ''
---
# 概要
<!-- Issueの概要 -->
# 詳細
<!-- 機能の詳細 -->
# 関連Issue
<!-- 関連するIssueがあれば -->
# 影響箇所
<!-- 予想される影響箇所(省略可) -->
WIP
-18
View File
@@ -1,18 +0,0 @@
# 概要
<!-- PRの概要 -->
# 関連Issue
- #000 <!-- 関連するIssueを指定(なければ省略可) -->
# 詳細
<!-- 詳細 -->
# 影響箇所
<!-- 予想される影響箇所 -->
# チェック
<!-- 参考用, 全てにチェックがついている必要があるわけではありません -->
- [ ] 機能として完成している
- [ ] WIP(Work in progress: 作業中)
- [ ] 正常にビルド/起動ができる
- [ ] 既存の機能を壊していない
+10
View File
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="deploymentTargetDropDown">
<value>
<entry key="app">
<State />
</entry>
</value>
</component>
</project>
-1
View File
@@ -4,7 +4,6 @@
<component name="GradleSettings">
<option name="linkedExternalProjectsSettings">
<GradleProjectSettings>
<option name="testRunner" value="GRADLE" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="gradleJvm" value="jbr-17" />
<option name="modules">
+1 -1
View File
@@ -1,6 +1,6 @@
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" project-jdk-name="jbr-17" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="jbr-17" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">
-6
View File
@@ -7,12 +7,6 @@
android:required="false" />
<uses-permission android:name="android.permission.CAMERA" />
<queries>
<intent>
<action android:name="android.media.action.IMAGE_CAPTURE" />
</intent>
</queries>
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
-9
View File
@@ -1,6 +1,5 @@
plugins {
alias(libs.plugins.com.android.library)
id 'com.google.dagger.hilt.android'
}
android {
@@ -34,16 +33,8 @@ dependencies {
androidTestImplementation libs.androidx.test.ext.junit
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 project(':shared:ui')
implementation project(':model')
implementation project(':processor')
implementation project(':utils')
}
@@ -25,32 +25,15 @@ import android.widget.Toast;
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Date;
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.
* Use the {@link ScannerDataManagerStubFragment#newInstance} factory method to
* create an instance of this fragment.
*/
@AndroidEntryPoint
public class ScannerDataManagerStubFragment extends Fragment {
// TODO-rca: 時間があったらcacheを使うようにする?
@@ -60,19 +43,6 @@ public class ScannerDataManagerStubFragment extends Fragment {
private Uri photoURI;
private DocumentDetail documentDetail;
private DocumentProcessor documentProcessor;
@Inject
DocumentProcessorFactory documentProcessorFactory;
@Inject
LacertaLogger logger;
@Inject
DeviceInfoUtils deviceInfoUtils;
private final ActivityResultLauncher<Intent> cameraLauncher = registerForActivityResult(
new ActivityResultContracts.StartActivityForResult(),
result -> {
@@ -150,82 +120,6 @@ public class ScannerDataManagerStubFragment extends Fragment {
}
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
@@ -11,7 +11,6 @@
android:id="@+id/action_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"
@@ -20,7 +19,7 @@
<com.google.android.material.button.MaterialButton
android:id="@+id/button_call_camera"
style="@style/Widget.Material3.Button.IconButton.Filled"
android:layout_width="match_parent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16px"
android:layout_weight="1"
@@ -28,58 +27,6 @@
</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
android:id="@+id/result_recycler_view"
android:layout_width="match_parent"
@@ -88,6 +35,6 @@
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/doc_button_container" />
app:layout_constraintTop_toBottomOf="@id/action_button_container" />
</androidx.constraintlayout.widget.ConstraintLayout>
-3
View File
@@ -65,7 +65,4 @@ dependencies {
// Scanner
implementation project(':component:scanner')
// Processor
implementation project(':processor')
}
@@ -10,16 +10,16 @@ import android.view.ViewGroup;
/**
* A simple {@link Fragment} subclass.
* Use the {@link DebugMenuDocProcessorTesterFragment#newInstance} factory method to
* Use the {@link DebugMenuMetaDataFragment#newInstance} factory method to
* create an instance of this fragment.
*/
public class DebugMenuDocProcessorTesterFragment extends Fragment {
public DebugMenuDocProcessorTesterFragment() {
public class DebugMenuMetaDataFragment extends Fragment {
public DebugMenuMetaDataFragment() {
// Required empty public constructor
}
public static DebugMenuDocProcessorTesterFragment newInstance() {
DebugMenuDocProcessorTesterFragment fragment = new DebugMenuDocProcessorTesterFragment();
public static DebugMenuMetaDataFragment newInstance() {
DebugMenuMetaDataFragment fragment = new DebugMenuMetaDataFragment();
Bundle args = new Bundle();
fragment.setArguments(args);
return fragment;
@@ -28,17 +28,12 @@ public class DebugMenuDocProcessorTesterFragment extends 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_doc_processor_tester, container, false);
return view;
return inflater.inflate(R.layout.fragment_debug_menu_meta_data, container, false);
}
}
@@ -12,7 +12,6 @@ import android.view.ViewGroup;
import java.util.ArrayList;
import java.util.List;
import dagger.hilt.android.AndroidEntryPoint;
import one.nem.lacerta.feature.debug.common.adapter.DebugMenuListItemAdapter;
import one.nem.lacerta.feature.debug.common.model.DebugMenuListItem;
@@ -21,7 +20,6 @@ import one.nem.lacerta.feature.debug.common.model.DebugMenuListItem;
* Use the {@link DebugMenuTopFragment#newInstance} factory method to
* create an instance of this fragment.
*/
@AndroidEntryPoint
public class DebugMenuTopFragment extends Fragment {
public DebugMenuTopFragment() {
// Required empty public constructor
@@ -48,6 +46,7 @@ public class DebugMenuTopFragment extends Fragment {
recyclerView.setLayoutManager(new androidx.recyclerview.widget.LinearLayoutManager(getContext()));
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("Scanner", "placeholder", R.id.action_debugMenuTopFragment_to_scannerDataManagerStubFragment, true));
@@ -1,36 +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"
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>
@@ -0,0 +1,12 @@
<?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,6 +10,9 @@
android:name="one.nem.lacerta.feature.debug.DebugMenuTopFragment"
android:label="fragment_debug_menu_top"
tools:layout="@layout/fragment_debug_menu_top" >
<action
android:id="@+id/action_debugMenuTopFragment_to_debugMenuMetaDataFragment"
app:destination="@id/debugMenuMetaDataFragment" />
<action
android:id="@+id/action_debugMenuTopFragment_to_debugMenuDocumentTesterTopFragment"
app:destination="@id/debugMenuDocumentTesterTopFragment" />
@@ -17,6 +20,11 @@
android:id="@+id/action_debugMenuTopFragment_to_scannerDataManagerStubFragment"
app:destination="@id/scannerDataManagerStubFragment" />
</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
android:id="@+id/debugMenuDocumentTesterTopFragment"
android:name="one.nem.lacerta.feature.debug.DebugMenuDocumentTesterTopFragment"
-14
View File
@@ -1,6 +1,5 @@
plugins {
id 'com.android.library'
id 'com.google.dagger.hilt.android'
}
android {
@@ -30,8 +29,6 @@ dependencies {
implementation libs.androidx.appcompat
implementation libs.com.google.android.material
implementation 'androidx.navigation:navigation-fragment:2.7.5'
implementation 'androidx.navigation:navigation-ui:2.7.5'
testImplementation libs.junit
androidTestImplementation libs.androidx.test.ext.junit
androidTestImplementation libs.androidx.test.espresso.core
@@ -41,15 +38,4 @@ dependencies {
implementation libs.navigation.ui
implementation libs.navigation.dynamic.features.fragment
// Hilt (DI)
implementation libs.com.google.dagger.hilt.android
annotationProcessor libs.com.google.dagger.hilt.compiler
implementation project(':shared:ui')
implementation project(':model')
implementation project(':data')
}
@@ -1,55 +0,0 @@
package one.nem.lacerta.feature.library;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import java.util.List;
import one.nem.lacerta.model.document.DocumentMeta;
public class DocumentAdapter extends RecyclerView.Adapter<DocumentAdapter.DocumentViewHolder> {
private List<DocumentMeta> documentMetas;
public DocumentAdapter(List<DocumentMeta> documentMetas) {
// nullの場合に例外を発生させる
if (documentMetas == null) {
throw new IllegalArgumentException("DocumentMetas list cannot be null or empty");
}
this.documentMetas = documentMetas;
}
@NonNull
@Override
public DocumentViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_item_library_menu, parent, false);
return new DocumentViewHolder(view);
}
@Override
public void onBindViewHolder(@NonNull DocumentViewHolder holder, int position) {
DocumentMeta documentMeta = documentMetas.get(position);
if (documentMeta != null) {
holder.title.setText(documentMeta.getTitle());
}
}
@Override
public int getItemCount() {
return documentMetas.size();
}
class DocumentViewHolder extends RecyclerView.ViewHolder {
TextView title;
DocumentViewHolder(View itemView) {
super(itemView);
title = itemView.findViewById(R.id.debug_menu_item_title); // 適切な id に変更する
}
}
}
@@ -1,38 +0,0 @@
package one.nem.lacerta.feature.library;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
// LibraryArchiveFragment.java
//画面変移用のコード
//Fragmentへのデータの受け渡し機能
public class LibraryArchiveFragment extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_library_top);
// ここに入力された内容を表示する機能
TextView textView = findViewById(R.id.document_list);
textView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// 文字をタップしたときの処理
// 移動先のアクティビティを指定
Intent intent = new Intent(LibraryArchiveFragment.this, LibraryDocFragment.class);
// データを付加する
intent.putExtra("key_name", "value_data");
startActivity(intent);
}
});
}
}
@@ -1,51 +0,0 @@
package one.nem.lacerta.feature.library;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.fragment.app.Fragment;
//Fragmentにデータを受け渡す機能
public class LibraryDocFragment extends Fragment {
private TextView textView; // フィールドとして TextView を定義
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_library_file, container, false);
textView = view.findViewById(R.id.textView);
return view;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// フラグメントに渡されたデータを取得
if (getArguments() != null) {
String receivedData = getArguments().getString("key_name");
// onCreateView メソッドで取得した TextView にデータをセットする
if (textView != null) {
textView.setText(receivedData);
}
}
}
// Factory method for creating a new instance of the fragment
public static LibraryDocFragment newInstance(String data) {
LibraryDocFragment fragment = new LibraryDocFragment();
// フラグメントにデータを渡す
Bundle args = new Bundle();
args.putString("key_name", data);
fragment.setArguments(args);
return fragment;
}
}
@@ -2,40 +2,19 @@ package one.nem.lacerta.feature.library;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import java.util.ArrayList;
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.
* Use the {@link LibraryTopFragment#newInstance} factory method to
* create an instance of this fragment.
*/
@AndroidEntryPoint
public class LibraryTopFragment extends Fragment {
@Inject
Document document;
// TODO: Rename parameter arguments, choose names that match
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
private static final String ARG_PARAM1 = "param1";
@@ -76,29 +55,10 @@ public class LibraryTopFragment extends Fragment {
}
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_library_top, container, false);
// Use view.findViewById instead of findViewById
RecyclerView documentRecyclerView = view.findViewById(R.id.document_list);
LinearLayoutManager layoutManager = new LinearLayoutManager(getContext());
documentRecyclerView.setLayoutManager(layoutManager);
//データを取得
List<DocumentMeta> metas = document.getAllDocumentMetas(100);
Toast.makeText(getContext(), "Documents: " + Integer.toString(metas.size()), Toast.LENGTH_LONG).show();
// Create and set the adapter
DocumentAdapter adapter = new DocumentAdapter(metas);
documentRecyclerView.setAdapter(adapter);
// Use a LinearLayoutManager to specify the layout
return view;
return inflater.inflate(R.layout.fragment_library_top, container, false);
}
}
}
@@ -1,17 +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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp">
<TextView
android:id="@+id/textView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:textSize="16sp"
android:layout_marginEnd="8dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
@@ -1,32 +1,14 @@
<?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"
<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"
android:theme="@style/Theme.Lacerta"
tools:context=".LibraryTopFragment">
<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/tool_bar"
<!-- TODO: Update blank fragment layout -->
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimaryContainer"
android:minHeight="?attr/actionBarSize"
android:theme="?attr/actionBarTheme"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:title="Library"
app:titleTextColor="@color/colorOnPrimaryContainer" />
android:layout_height="match_parent"
android:text="@string/hello_blank_fragment" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/document_list"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tool_bar" />
</androidx.constraintlayout.widget.ConstraintLayout>
</FrameLayout>
@@ -1,26 +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"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp">
<TextView
android:id="@+id/debug_menu_item_title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:textSize="16sp"
android:layout_marginEnd="8dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/debug_menu_item_description"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:textSize="14sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/debug_menu_item_title" />
</androidx.constraintlayout.widget.ConstraintLayout>
@@ -1,3 +1,4 @@
<resources>
<string name="app_name">Library</string>
<!-- TODO: Remove or change this placeholder text -->
<string name="hello_blank_fragment">Hello blank fragment</string>
</resources>
-2
View File
@@ -36,6 +36,4 @@ dependencies {
// JGit
implementation 'org.eclipse.jgit:org.eclipse.jgit:6.8.0.202311291450-r'
implementation project(":shared:ui")
}
@@ -1,41 +0,0 @@
package one.nem.lacerta.model;
import android.graphics.drawable.Drawable;
public class ListItem {
// Properties
String title;
String description;
ListItemType itemType;
String itemId;
// Constructor
public ListItem(String title, String description, ListItemType itemType, String itemId) {
this.title = title;
this.description = description;
this.itemType = itemType;
this.itemId = itemId;
}
// Getter
public String getTitle() {
return title;
}
public String getDescription() {
return description;
}
public ListItemType getItemType() {
return itemType;
}
public String getItemId() {
return itemId;
}
}
@@ -1,17 +0,0 @@
package one.nem.lacerta.model;
public enum ListItemType {
ITEM_TYPE_FOLDER(one.nem.lacerta.shared.ui.R.drawable.folder_24px),
ITEM_TYPE_DOCUMENT(one.nem.lacerta.shared.ui.R.drawable.description_24px);
private int iconId;
ListItemType(int iconId) {
this.iconId = iconId;
}
public int getIconId() {
return iconId;
}
}
@@ -1,73 +0,0 @@
package one.nem.lacerta.model.document.internal;
import java.util.ArrayList;
public class XmlMetaModel {
String title;
String author;
String description;
// Date created;
// Date updated;
String defaultBranch;
ArrayList<XmlMetaPageModel> pages;
// Constructor
public XmlMetaModel() {
}
public XmlMetaModel(String title, String author, String description, String defaultBranch, ArrayList<XmlMetaPageModel> pages) {
this.title = title;
this.author = author;
this.description = description;
this.defaultBranch = defaultBranch;
this.pages = pages;
}
// Getter
public String getTitle() {
return title;
}
public String getAuthor() {
return author;
}
public String getDescription() {
return description;
}
public String getDefaultBranch() {
return defaultBranch;
}
public ArrayList<XmlMetaPageModel> getPages() {
return pages;
}
// Setter
public void setTitle(String title) {
this.title = title;
}
public void setAuthor(String author) {
this.author = author;
}
public void setDescription(String description) {
this.description = description;
}
public void setDefaultBranch(String defaultBranch) {
this.defaultBranch = defaultBranch;
}
public void setPages(ArrayList<XmlMetaPageModel> pages) {
this.pages = pages;
}
}
@@ -1,27 +0,0 @@
package one.nem.lacerta.model.document.internal;
public class XmlMetaPageModel {
String filename;
// Constructor
public XmlMetaPageModel() {
}
public XmlMetaPageModel(String filename) {
this.filename = filename;
}
// Getter
public String getFilename() {
return filename;
}
// Setter
public void setFilename(String filename) {
this.filename = filename;
}
}
-12
View File
@@ -32,16 +32,4 @@ dependencies {
testImplementation libs.junit
androidTestImplementation libs.androidx.test.ext.junit
androidTestImplementation libs.androidx.test.espresso.core
// DI
implementation libs.com.google.dagger.hilt.android
annotationProcessor libs.com.google.dagger.hilt.compiler
// JGit
implementation 'org.eclipse.jgit:org.eclipse.jgit:6.8.0.202311291450-r'
implementation project(':model')
implementation project(':source')
implementation project(':utils')
implementation project(':data')
}
@@ -1,24 +0,0 @@
package one.nem.lacerta.processor;
import android.graphics.Bitmap;
public interface DocumentProcessor {
// ページ操作
void addNewPageToLast(Bitmap bitmap) throws Exception;
void addNewPagesToLast(Bitmap[] bitmaps) throws Exception;
void addNewPageAfterIndex(Bitmap bitmap, int index) throws Exception;
void addNewPageBeforeIndex(Bitmap bitmap, int index) throws Exception;
void removePageAtIndex(int index) throws Exception;
// 更新
void updatePageAtIndex(Bitmap bitmap, int index);
// ページ取得
Bitmap getPageAtIndex(int index);
int getPageCount();
void close() throws Exception;
void init() throws Exception; // TODO-rca: 例外処理
}
@@ -1,10 +0,0 @@
package one.nem.lacerta.processor.factory;
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);
}
@@ -1,175 +0,0 @@
package one.nem.lacerta.processor.impl;
import android.graphics.Bitmap;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.UUID;
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.model.document.DocumentDetail;
import one.nem.lacerta.model.document.internal.XmlMetaModel;
import one.nem.lacerta.source.file.FileManager;
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{
// Magic Numbers
private static final String DEFAULT_SAVE_DIR = "raw";
// Variables
private final DocumentDetail documentDetail;
private XmlMetaModel xmlMetaModel;
private Path documentRootPath;
private FileManager fileManager;
// Injection
private final FileManagerFactory fileManagerFactory;
private final LacertaLogger logger;
private final XmlMetaParser xmlMetaParser;
@AssistedInject
public DocumentProcessorImpl(FileManagerFactory fileManagerFactory, LacertaLogger logger, XmlMetaParser xmlMetaParser, @Assisted DocumentDetail documentDetail) {
this.fileManagerFactory = fileManagerFactory;
this.logger = logger;
this.xmlMetaParser = xmlMetaParser;
if (documentDetail == null) {
throw new IllegalArgumentException("documentDetail must not be null");
}
this.documentDetail = documentDetail;
}
@Override
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
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
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
public void removePageAtIndex(int index) {
}
@Override
public void updatePageAtIndex(Bitmap bitmap, int index) {
}
@Override
public Bitmap getPageAtIndex(int index) {
return null;
}
@Override
public int getPageCount() {
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());
}
}
}
Whitespace-only changes.
@@ -1,16 +0,0 @@
package one.nem.lacerta.processor.module;
import dagger.assisted.Assisted;
import dagger.assisted.AssistedInject;
import one.nem.lacerta.model.document.DocumentDetail;
public class DocumentProcessorModule {
private final DocumentDetail documentDetail;
@AssistedInject
public DocumentProcessorModule(@Assisted DocumentDetail documentDetail) {
this.documentDetail = documentDetail;
}
}
Whitespace-only changes.
Whitespace-only changes.
@@ -1,4 +0,0 @@
<resources>
<!-- TODO: Remove or change this placeholder text -->
<string name="hello_blank_fragment">Hello blank fragment</string>
</resources>
@@ -1,10 +0,0 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="960"
android:viewportHeight="960"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M330,710L630,710L630,650L330,650L330,710ZM330,550L630,550L630,490L330,490L330,550ZM252.31,860Q222,860 201,839Q180,818 180,787.69L180,172.31Q180,142 201,121Q222,100 252.31,100L570,100L780,310L780,787.69Q780,818 759,839Q738,860 707.69,860L252.31,860ZM540,340L540,160L252.31,160Q247.69,160 243.85,163.85Q240,167.69 240,172.31L240,787.69Q240,792.31 243.85,796.15Q247.69,800 252.31,800L707.69,800Q712.31,800 716.15,796.15Q720,792.31 720,787.69L720,340L540,340ZM240,160L240,160L240,340L240,340L240,160L240,340L240,340L240,787.69Q240,792.31 240,796.15Q240,800 240,800L240,800Q240,800 240,796.15Q240,792.31 240,787.69L240,172.31Q240,167.69 240,163.85Q240,160 240,160Z"/>
</vector>
@@ -1,65 +0,0 @@
package one.nem.lacerta.source.file;
import android.graphics.Bitmap;
import org.w3c.dom.Document;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Field;
import java.nio.file.Path;
import java.util.List;
/** @noinspection unused*/
public interface FileManager {
File getFileRef();
boolean isExist(String name) throws IOException;
boolean isExist();
boolean isDirectory();
boolean isFile();
boolean isWritable();
boolean isReadable();
// Get current instance
FileManager getCurrentInstance();
FileManager getNewInstance();
// Configure
FileManager enableAutoCreateParent();
FileManager disableRootDirCheck();
FileManager setRootDir(Path rootDir);
FileManager setPath(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,11 +0,0 @@
package one.nem.lacerta.source.file.factory;
import java.nio.file.Path;
import dagger.assisted.AssistedFactory;
import one.nem.lacerta.source.file.impl.FileManagerImpl;
@AssistedFactory
public interface FileManagerFactory {
FileManagerImpl create(Path rootDir);
}
Whitespace-only changes.
@@ -1,364 +0,0 @@
package one.nem.lacerta.source.file.impl;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import org.w3c.dom.Document;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
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.AssistedInject;
import one.nem.lacerta.source.file.FileManager;
import one.nem.lacerta.utils.LacertaLogger;
public class FileManagerImpl implements FileManager {
// variables
private Path rootDir;
private Path path;
private boolean autoCreateParent = false;
private boolean disableRootDirCheck = false;
// Injection
private final LacertaLogger logger;
@AssistedInject
public FileManagerImpl(LacertaLogger logger, @Assisted Path rootDir) {
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 {
return null;
}
}
@Override
public boolean isExist(String name) throws IOException {
Path resolvedPath = this.resolveStringPath(name);
return Files.exists(resolvedPath);
}
@Override
public boolean isExist(){
return Files.exists(this.path);
}
@Override
public boolean isDirectory() {
if (this.isExist()) {
File file = this.path.toFile();
return file.isDirectory();
} else {
return false;
}
}
@Override
public boolean isFile() {
if (this.isExist()) {
File file = this.path.toFile();
return file.isFile();
} else {
return false;
}
}
@Override
public boolean isReadable() {
if (this.isExist()) {
File file = this.path.toFile();
return file.canRead();
} else {
return false;
}
}
@Override
public boolean isWritable() {
if (this.isExist()) {
File file = this.path.toFile();
return file.canWrite();
} 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");
}
}
logger.debug("setPath", "resolvedPath: " + resolvedPath);
return this.newInstance(this.rootDir, resolvedPath, this.autoCreateParent, this.disableRootDirCheck);
}
@Override
public FileManager resolve(String path) throws IOException{
Path resolvedPath;
try {
resolvedPath = resolveStringPath(path);
} catch (IOException e) {
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
public FileManager createFile() throws IOException {
this.createFileInternal(this.path);
return this;
}
@Override
public FileManager createFile(String fileName) throws IOException { // pathが書き換わってしまうのは想像できない挙動かも?
this.createFileInternal(this.resolveStringPath(fileName));
return this;
}
@Override
public FileManager createFileIfNotExist() throws IOException {
if (!this.isExist()) {
this.createFile();
}
return this;
}
@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);
}
}
Whitespace-only changes.
@@ -1,20 +0,0 @@
package one.nem.lacerta.source.file.module;
import java.nio.file.Path;
import dagger.assisted.Assisted;
import dagger.assisted.AssistedInject;
public class FileManagerModule {
private final Path rootDir;
@AssistedInject
public FileManagerModule(@Assisted Path rootDir) {
this.rootDir = rootDir;
}
public Path getRootDir() {
return rootDir;
}
}
Whitespace-only changes.
+1 -2
View File
@@ -37,6 +37,5 @@ dependencies {
implementation libs.com.google.dagger.hilt.android
annotationProcessor libs.com.google.dagger.hilt.compiler
// model
implementation project(':model')
//
}
@@ -1,7 +1,5 @@
package one.nem.lacerta.utils;
import one.nem.lacerta.utils.model.KeyValueLog;
public interface LacertaLogger {
void info(String tag, String message);
@@ -11,7 +9,4 @@ public interface LacertaLogger {
void trace(String tag, String message);
void fatal(String tag, String message);
String buildKVMessage(KeyValueLog... logs);
// With name
String buildKVMessage(String name, KeyValueLog... logs);
}
@@ -1,13 +0,0 @@
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,8 +5,6 @@ import android.util.Log;
import javax.inject.Inject;
import one.nem.lacerta.utils.LacertaLogger;
import one.nem.lacerta.utils.model.KeyValueLog;
public class LacertaLoggerImpl implements LacertaLogger{
@Inject
@@ -42,30 +40,4 @@ public class LacertaLoggerImpl implements LacertaLogger{
public void fatal(String tag, String 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();
}
}
@@ -1,96 +0,0 @@
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);
}
}
@@ -1,31 +0,0 @@
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;
}
}
@@ -1,17 +0,0 @@
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);
}