diff --git a/data/build.gradle b/data/build.gradle index 10a00015..4615289e 100644 --- a/data/build.gradle +++ b/data/build.gradle @@ -41,6 +41,9 @@ dependencies { // JGit implementation 'org.eclipse.jgit:org.eclipse.jgit:6.8.0.202311291450-r' + // Java Faker + implementation 'com.github.javafaker:javafaker:1.0.2' + // Room implementation libs.androidx.room.runtime annotationProcessor libs.androidx.room.compiler diff --git a/data/src/main/java/one/nem/lacerta/data/impl/LacertaLibraryImpl.java b/data/src/main/java/one/nem/lacerta/data/impl/LacertaLibraryImpl.java index b3e9c855..49f7303a 100644 --- a/data/src/main/java/one/nem/lacerta/data/impl/LacertaLibraryImpl.java +++ b/data/src/main/java/one/nem/lacerta/data/impl/LacertaLibraryImpl.java @@ -1,4 +1,42 @@ package one.nem.lacerta.data.impl; -public class LacertaLibraryImpl { +import one.nem.lacerta.data.LacertaLibrary; +import one.nem.lacerta.model.LibraryItemPage; +import one.nem.lacerta.model.document.DocumentDetail; + +public class LacertaLibraryImpl implements LacertaLibrary { + @Override + public LibraryItemPage getRecentDocument(int limit) { + return null; + } + + @Override + public LibraryItemPage getRecentDocument(int limit, int offset) { + return null; + } + + @Override + public LibraryItemPage getLibraryPage(int limit) { + return null; + } + + @Override + public LibraryItemPage getLibraryPage(int limit, int offset) { + return null; + } + + @Override + public LibraryItemPage getLibraryPage(String pageId, int limit) { + return null; + } + + @Override + public LibraryItemPage getLibraryPage(String pageId, int limit, int offset) { + return null; + } + + @Override + public DocumentDetail getDocumentDetailById(String id) { + return null; + } } diff --git a/data/src/main/java/one/nem/lacerta/data/impl/LacertaLibraryStubImpl.java b/data/src/main/java/one/nem/lacerta/data/impl/LacertaLibraryStubImpl.java new file mode 100644 index 00000000..55129bba --- /dev/null +++ b/data/src/main/java/one/nem/lacerta/data/impl/LacertaLibraryStubImpl.java @@ -0,0 +1,219 @@ +package one.nem.lacerta.data.impl; + +import one.nem.lacerta.data.LacertaLibrary; +import one.nem.lacerta.model.LibraryItemPage; +import one.nem.lacerta.model.ListItem; +import one.nem.lacerta.model.ListItemType; +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.utils.LacertaLogger; + +import com.github.javafaker.DateAndTime; +import com.github.javafaker.Faker; + +import java.text.DateFormat; +import java.util.ArrayList; +import java.util.Objects; +import java.util.UUID; + +import javax.inject.Inject; + +/** + * LacertaLibraryのスタブ実装 + */ +public class LacertaLibraryStubImpl implements LacertaLibrary { + + LacertaLogger logger; + + Faker faker; + + @Inject + public LacertaLibraryStubImpl(LacertaLogger logger) { + faker = new Faker(); // Init Faker + this.logger = logger; + logger.debug("LibraryStub", "Initialized"); + } + + // Internal Methods + + // Generate Stub Data + private LibraryItemPage generateStubLibraryItemPage(int limit, String pageId) { + logger.debug("LibraryStub", "generateStubLibraryItemPage"); + ArrayList listItems = new ArrayList<>(); + int itemTotal = faker.number().numberBetween(1, limit); // 実際に返却するアイテム数を決定 + int folderTotal; + // フォルダ数の抽選 + if (itemTotal > 4) { + folderTotal = faker.number().numberBetween(1, itemTotal - 2); + } + else { + if (itemTotal > 2) { + folderTotal = 1; + } + else { // ドキュメント数がゼロにならないように + folderTotal = 0; + } + } + int documentTotal = itemTotal - folderTotal; // ドキュメント数を決定 + logger.debug("LibraryStub", "itemTotal: " + itemTotal); + logger.debug("LibraryStub", "folderTotal: " + folderTotal); + logger.debug("LibraryStub", "documentTotal: " + documentTotal); + + // フォルダを生成 + for (int i = 0; i < folderTotal; i++) { + listItems.add(generateStubListItem(ListItemType.ITEM_TYPE_FOLDER)); + } + // ドキュメントを生成 + for (int i = 0; i < documentTotal; i++) { + listItems.add(generateStubListItem(ListItemType.ITEM_TYPE_DOCUMENT)); + } + + LibraryItemPage libraryItemPage = new LibraryItemPage(); + libraryItemPage.setListItems(listItems); + if (pageId == null) { + libraryItemPage.setPageId(UUID.randomUUID().toString()); + } else { + libraryItemPage.setPageId(pageId); + } + libraryItemPage.setPageTitle("FakePage" + faker.number().digits(3)); + + return libraryItemPage; + } + + private ListItem generateStubListItem(ListItemType itemType) { + if (itemType == ListItemType.ITEM_TYPE_FOLDER) { + ListItem listItem = new ListItem(); + listItem.setTitle("FakeFolder" + faker.number().digits(3)); + listItem.setDescription("Updated at " + DateFormat.getDateTimeInstance().format(faker.date().birthday())); + listItem.setItemType(ListItemType.ITEM_TYPE_FOLDER); + listItem.setItemId(UUID.randomUUID().toString()); + return listItem; + } else if (itemType == ListItemType.ITEM_TYPE_DOCUMENT) { + ListItem listItem = new ListItem(); + listItem.setTitle("FakeDocument" + faker.book().title()); + listItem.setDescription("Updated at " + DateFormat.getDateTimeInstance().format(faker.date().birthday())); + listItem.setItemType(ListItemType.ITEM_TYPE_DOCUMENT); + listItem.setItemId(UUID.randomUUID().toString()); + return listItem; + } else { + return null; + } + } + + private LibraryItemPage getRecentDocumentPage(int limit) { + int itemTotal = faker.number().numberBetween(1, limit); + ArrayList listItems = new ArrayList<>(); + for (int i = 0; i < itemTotal; i++) { + listItems.add(generateStubListItem(ListItemType.ITEM_TYPE_DOCUMENT)); + } + // DescriptionからDateを抽出して新しい順にソート + listItems.sort((a, b) -> { + String aDate = a.getDescription().substring(11); + String bDate = b.getDescription().substring(11); + return bDate.compareTo(aDate); + }); + LibraryItemPage libraryItemPage = new LibraryItemPage(); + libraryItemPage.setListItems(listItems); + libraryItemPage.setPageId(UUID.randomUUID().toString()); + libraryItemPage.setPageTitle("RecentDocument"); + return libraryItemPage; + } + + private DocumentDetail generateStubDocumentDetail(String id) throws IllegalArgumentException { + + if (Objects.isNull(id)) { + throw new IllegalArgumentException("id is null"); + } + + DocumentMeta documentMeta = new DocumentMeta(); + documentMeta.setId(id); + documentMeta.setTitle("FakeDocument" + faker.book().title()); + documentMeta.setCreatedAt(faker.date().birthday()); + documentMeta.setUpdatedAt(faker.date().birthday()); // TODO-rca: 更新日のほうが古くなることがあるのでなんとかする? + ArrayList tagIds = new ArrayList<>(); + + DocumentDetail documentDetail = new DocumentDetail(); + documentDetail.setMeta(documentMeta); + documentDetail.setPath(null); // TODO-rca: なんとかする + documentDetail.setAuthor(faker.name().fullName()); + documentDetail.setRepository(null); // TODO-rca: なんとかする + return documentDetail; + } + + /** + * 履歴ページを取得する + * @param limit 取得するアイテム数 + * @return ページオブジェクト + */ + @Override + public LibraryItemPage getRecentDocument(int limit) { + return getRecentDocumentPage(limit); + } + + /** + * 履歴ページを取得する + * @param limit 取得するアイテム数 + * @param offset 取得するアイテムのオフセット + * @return ページオブジェクト + */ + @Override + public LibraryItemPage getRecentDocument(int limit, int offset) { + return getRecentDocumentPage(limit); + } + + /** + * ライブラリページを取得する + * @param limit 取得するアイテム数 + * @return ページオブジェクト + */ + @Override + public LibraryItemPage getLibraryPage(int limit) { + return generateStubLibraryItemPage(limit, null); + } + + /** + * ライブラリページを取得する + * @param limit 取得するアイテム数 + * @param offset 取得するアイテムのオフセット + * @return ページオブジェクト + */ + @Override + public LibraryItemPage getLibraryPage(int limit, int offset) { + return generateStubLibraryItemPage(limit, null); + } + + /** + * ライブラリページを取得する + * @param pageId ページID + * @param limit 取得するアイテム数 + * @return ページオブジェクト + */ + @Override + public LibraryItemPage getLibraryPage(String pageId, int limit) { + return generateStubLibraryItemPage(limit, pageId); + } + + /** + * ライブラリページを取得する + * @param pageId ページID + * @param limit 取得するアイテム数 + * @param offset 取得するアイテムのオフセット + * @return ページオブジェクト + */ + @Override + public LibraryItemPage getLibraryPage(String pageId, int limit, int offset) { + return generateStubLibraryItemPage(limit, pageId); + } + + /** + * ドキュメント詳細を取得する + * @param id ドキュメントID + * @return ドキュメント詳細オブジェクト + */ + @Override + public DocumentDetail getDocumentDetailById(String id) throws IllegalArgumentException { + return generateStubDocumentDetail(id); + } +} diff --git a/data/src/main/java/one/nem/lacerta/data/module/LacertaLibraryModule.java b/data/src/main/java/one/nem/lacerta/data/module/LacertaLibraryModule.java index 889a66ef..6c98e653 100644 --- a/data/src/main/java/one/nem/lacerta/data/module/LacertaLibraryModule.java +++ b/data/src/main/java/one/nem/lacerta/data/module/LacertaLibraryModule.java @@ -1,4 +1,21 @@ package one.nem.lacerta.data.module; -public class LacertaLibraryModule { +import dagger.Binds; +import dagger.Module; +import dagger.hilt.InstallIn; +import dagger.hilt.android.components.FragmentComponent; +import dagger.hilt.migration.DisableInstallInCheck; + +import one.nem.lacerta.data.LacertaLibrary; +import one.nem.lacerta.data.impl.LacertaLibraryStubImpl; +import one.nem.lacerta.utils.LacertaLogger; + +@Module +// Fragmentにinstall +@InstallIn(FragmentComponent.class) +abstract public class LacertaLibraryModule { + + @Binds + public abstract LacertaLibrary bindLacertaLibrary(LacertaLibraryStubImpl impl); + } diff --git a/feature/debug/src/main/java/one/nem/lacerta/feature/debug/DebugMenuLibraryItemListPageFragment.java b/feature/debug/src/main/java/one/nem/lacerta/feature/debug/DebugMenuLibraryItemListPageFragment.java new file mode 100644 index 00000000..a6be2bb4 --- /dev/null +++ b/feature/debug/src/main/java/one/nem/lacerta/feature/debug/DebugMenuLibraryItemListPageFragment.java @@ -0,0 +1,115 @@ +package one.nem.lacerta.feature.debug; + +import android.os.Bundle; + +import androidx.annotation.AnimatorRes; +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.TextView; + +import java.util.ArrayList; + +import javax.inject.Inject; + +import dagger.hilt.android.AndroidEntryPoint; +import one.nem.lacerta.data.LacertaLibrary; + +import one.nem.lacerta.model.LibraryItemPage; +import one.nem.lacerta.model.document.DocumentDetail; +import one.nem.lacerta.model.ListItem; +import one.nem.lacerta.model.ListItemType; + +/** + * A simple {@link Fragment} subclass. + * Use the {@link DebugMenuLibraryItemListPageFragment#newInstance} factory method to + * create an instance of this fragment. + */ +@AndroidEntryPoint +public class DebugMenuLibraryItemListPageFragment extends Fragment { + + @Inject + LacertaLibrary lacertaLibrary; + + public DebugMenuLibraryItemListPageFragment() { + // Required empty public constructor + } + + public static DebugMenuLibraryItemListPageFragment newInstance() { + DebugMenuLibraryItemListPageFragment fragment = new DebugMenuLibraryItemListPageFragment(); + 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_library_item_list_page, container, false); + + LibraryItemPage libraryItemPage = lacertaLibrary.getRecentDocument(10); + for (ListItem listItem : libraryItemPage.getListItems()) { + System.out.println(listItem.getTitle()); + } + + RecyclerView recyclerView = view.findViewById(R.id.item_recycler_view); + recyclerView.setAdapter(new ItemAdapter(libraryItemPage.getListItems())); + + recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); + + return view; + } + + private class ItemAdapter extends RecyclerView.Adapter { + private ArrayList listItems; + + public ItemAdapter(ArrayList listItems) { + this.listItems = listItems; + } + + @Override + public ItemViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { + View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_item_debug_menu_document, parent, false); + return new ItemViewHolder(view); + } + + @Override + public void onBindViewHolder(ItemViewHolder holder, int position) { + ListItem listItem = listItems.get(position); + holder.document_list_item_title.setText(listItem.getTitle()); + holder.document_list_item_description.setText(listItem.getDescription()); + holder.document_list_item_updated_at.setText(listItem.getItemType().toString()); + } + + @Override + public int getItemCount() { + return listItems.size(); + } + + public class ItemViewHolder extends RecyclerView.ViewHolder { + + TextView document_list_item_title; + TextView document_list_item_description; + TextView document_list_item_updated_at; + + + public ItemViewHolder(View itemView) { + super(itemView); + document_list_item_title = itemView.findViewById(R.id.document_list_item_title); + document_list_item_description = itemView.findViewById(R.id.document_list_item_description); + document_list_item_updated_at = itemView.findViewById(R.id.document_list_item_updated_at); + } + } + } + +} \ No newline at end of file diff --git a/feature/debug/src/main/java/one/nem/lacerta/feature/debug/DebugMenuTopFragment.java b/feature/debug/src/main/java/one/nem/lacerta/feature/debug/DebugMenuTopFragment.java index 1d00694e..331ce00c 100644 --- a/feature/debug/src/main/java/one/nem/lacerta/feature/debug/DebugMenuTopFragment.java +++ b/feature/debug/src/main/java/one/nem/lacerta/feature/debug/DebugMenuTopFragment.java @@ -50,6 +50,7 @@ public class DebugMenuTopFragment extends Fragment { 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("Document List", "placeholder", R.id.action_debugMenuTopFragment_to_debugMenuLibraryItemListPageFragment, true)); DebugMenuListItemAdapter adapter = new DebugMenuListItemAdapter(debugMenuListItems); recyclerView.setAdapter(adapter); diff --git a/feature/debug/src/main/res/layout/fragment_debug_menu_library_item_list_page.xml b/feature/debug/src/main/res/layout/fragment_debug_menu_library_item_list_page.xml new file mode 100644 index 00000000..0e184902 --- /dev/null +++ b/feature/debug/src/main/res/layout/fragment_debug_menu_library_item_list_page.xml @@ -0,0 +1,17 @@ + + + + + \ No newline at end of file diff --git a/feature/debug/src/main/res/navigation/feature_debug_internal_navigation.xml b/feature/debug/src/main/res/navigation/feature_debug_internal_navigation.xml index b2fa3af7..26855e38 100644 --- a/feature/debug/src/main/res/navigation/feature_debug_internal_navigation.xml +++ b/feature/debug/src/main/res/navigation/feature_debug_internal_navigation.xml @@ -16,6 +16,9 @@ + + \ No newline at end of file diff --git a/model/src/main/java/one/nem/lacerta/model/LibraryItemPage.java b/model/src/main/java/one/nem/lacerta/model/LibraryItemPage.java index aed41a09..825c2396 100644 --- a/model/src/main/java/one/nem/lacerta/model/LibraryItemPage.java +++ b/model/src/main/java/one/nem/lacerta/model/LibraryItemPage.java @@ -8,12 +8,20 @@ public class LibraryItemPage { String pageId; ArrayList listItems; + // Constructor + public LibraryItemPage(String pageTitle, String pageId, ArrayList listItems) { this.pageTitle = pageTitle; this.pageId = pageId; this.listItems = listItems; } + public LibraryItemPage() { + // Empty constructor + } + + // Getter + public String getPageTitle() { return pageTitle; } @@ -25,4 +33,19 @@ public class LibraryItemPage { public ArrayList getListItems() { return listItems; } + + // Setter + + public void setPageTitle(String pageTitle) { + this.pageTitle = pageTitle; + } + + public void setPageId(String pageId) { + this.pageId = pageId; + } + + public void setListItems(ArrayList listItems) { + this.listItems = listItems; + } + } diff --git a/model/src/main/java/one/nem/lacerta/model/ListItem.java b/model/src/main/java/one/nem/lacerta/model/ListItem.java index 231438c8..323b6bdd 100644 --- a/model/src/main/java/one/nem/lacerta/model/ListItem.java +++ b/model/src/main/java/one/nem/lacerta/model/ListItem.java @@ -20,6 +20,10 @@ public class ListItem { this.itemId = itemId; } + public ListItem() { + // Empty constructor + } + // Getter public String getTitle() { @@ -38,4 +42,22 @@ public class ListItem { return itemId; } + // Setter + + public void setTitle(String title) { + this.title = title; + } + + public void setDescription(String description) { + this.description = description; + } + + public void setItemType(ListItemType itemType) { + this.itemType = itemType; + } + + public void setItemId(String itemId) { + this.itemId = itemId; + } + }