diff --git a/data/src/main/java/one/nem/lacerta/data/LacertaLibrary.java b/data/src/main/java/one/nem/lacerta/data/LacertaLibrary.java index 7e8ba899..764dcb5a 100644 --- a/data/src/main/java/one/nem/lacerta/data/LacertaLibrary.java +++ b/data/src/main/java/one/nem/lacerta/data/LacertaLibrary.java @@ -35,6 +35,8 @@ public interface LacertaLibrary { // Tag CompletableFuture> getTagList(); + CompletableFuture> getAppliedTagList(String documentId); + CompletableFuture createTag(DocumentTag tag); CompletableFuture updateTag(DocumentTag tag); 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 e6c19bd9..5c65a2af 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 @@ -121,6 +121,19 @@ public class LacertaLibraryImpl implements LacertaLibrary { listItem.setDescription(simpleDateFormat.format(documentEntity.updatedAt)); listItem.setItemId(documentEntity.id); listItem.setHasCombined(documentEntity.isCombineParent); + // タグを取得して関連付ける処理 TODO-rca: わかりにくい + 責任がめちゃくちゃ + めちゃくちゃ重いのでなんとかする + List documentTagEntities = database.toxiDocumentTagDao().findByDocumentId(documentEntity.id); + ArrayList documentTags = new ArrayList<>(); + for (ToxiDocumentTagEntity toxiDocumentTagEntity : documentTagEntities) { + logger.debug("LacertaLibraryImpl", "toxiDocumentTagEntity.tagId: " + toxiDocumentTagEntity.tagId); + TagEntity tagEntity = database.tagDao().findById(toxiDocumentTagEntity.tagId); + if (tagEntity != null) { + logger.debug("LacertaLibraryImpl", "tagEntity.tagName: " + tagEntity.tagName); + documentTags.add(convertTagEntityToDocumentTag(tagEntity)); + } + } + listItem.setTagList(documentTags); + logger.debug("LacertaLibraryImpl", "documentTags.size(): " + documentTags.size()); listItems.add(listItem); } @@ -248,6 +261,22 @@ public class LacertaLibraryImpl implements LacertaLibrary { }); } + @Override + public CompletableFuture> getAppliedTagList(String documentId) { + return CompletableFuture.supplyAsync(() -> { + List toxiDocumentTagEntities = database.toxiDocumentTagDao().findByDocumentId(documentId); + logger.debug("LacertaLibraryImpl", "Database Query: Get ToxiDocumentTagEntity List (Size: " + toxiDocumentTagEntities.size() + ")"); + ArrayList documentTags = new ArrayList<>(); + for (ToxiDocumentTagEntity toxiDocumentTagEntity : toxiDocumentTagEntities) { + TagEntity tagEntity = database.tagDao().findById(toxiDocumentTagEntity.tagId); + if (tagEntity != null) { + documentTags.add(convertTagEntityToDocumentTag(tagEntity)); + } + } + return documentTags; + }); + } + @Override public CompletableFuture createTag(DocumentTag tag) { return CompletableFuture.supplyAsync(() -> { diff --git a/feature/library/src/main/java/one/nem/lacerta/feature/library/LibraryPageFragment.java b/feature/library/src/main/java/one/nem/lacerta/feature/library/LibraryPageFragment.java index 7a37e9f1..158e61e1 100644 --- a/feature/library/src/main/java/one/nem/lacerta/feature/library/LibraryPageFragment.java +++ b/feature/library/src/main/java/one/nem/lacerta/feature/library/LibraryPageFragment.java @@ -21,9 +21,11 @@ import javax.inject.Inject; import dagger.hilt.android.AndroidEntryPoint; import one.nem.lacerta.component.viewer.ViewerMainActivity; +import one.nem.lacerta.data.Document; import one.nem.lacerta.data.LacertaLibrary; import one.nem.lacerta.model.LibraryItemPage; import one.nem.lacerta.model.ListItemType; +import one.nem.lacerta.model.document.tag.DocumentTag; import one.nem.lacerta.utils.FeatureSwitch; import one.nem.lacerta.utils.LacertaLogger; @@ -53,6 +55,9 @@ public class LibraryPageFragment extends Fragment { @Inject LacertaLogger logger; + @Inject + Document document; + ListItemAdapter listItemAdapter; public LibraryPageFragment() { @@ -233,6 +238,9 @@ public class LibraryPageFragment extends Fragment { }); } + private void getTag(String documentId) { //debug + } + /** * Toolbarのサブタイトルを更新 * @param subtitle サブタイトル diff --git a/feature/library/src/main/java/one/nem/lacerta/feature/library/ListItemAdapter.java b/feature/library/src/main/java/one/nem/lacerta/feature/library/ListItemAdapter.java index 57edf131..ee310413 100644 --- a/feature/library/src/main/java/one/nem/lacerta/feature/library/ListItemAdapter.java +++ b/feature/library/src/main/java/one/nem/lacerta/feature/library/ListItemAdapter.java @@ -1,14 +1,19 @@ package one.nem.lacerta.feature.library; +import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; import android.widget.TextView; +import android.widget.Toast; import androidx.annotation.NonNull; import androidx.recyclerview.widget.RecyclerView; +import com.google.android.material.chip.Chip; +import com.google.android.material.chip.ChipGroup; + import one.nem.lacerta.model.LibraryItemPage; import one.nem.lacerta.model.ListItem; import one.nem.lacerta.model.ListItemType; @@ -31,7 +36,7 @@ public class ListItemAdapter extends RecyclerView.Adapter { if (listItem.getItemType() == ListItemType.ITEM_TYPE_DOCUMENT) { listener.onDocumentSelected(listItem.getItemId(), listItem.getTitle(), listItem.getHasCombined()); @@ -64,12 +82,14 @@ public class ListItemAdapter extends RecyclerView.Adapter tagList; + + @Override + public int getCount() { + return 0; + } + + @Override + public Object getItem(int position) { + return null; + } + + @Override + public long getItemId(int position) { + return 0; + } + + @Override + public View getView(int position, View convertView, ViewGroup parent) { + Chip chip; + if (convertView == null) { + chip = new Chip(parent.getContext()); + } + else { + chip = (Chip) convertView; + } + chip.setText(tagList.get(position).getName()); + return chip; + } +} 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 b987b616..533aee20 100644 --- a/model/src/main/java/one/nem/lacerta/model/ListItem.java +++ b/model/src/main/java/one/nem/lacerta/model/ListItem.java @@ -2,6 +2,10 @@ package one.nem.lacerta.model; import android.graphics.drawable.Drawable; +import java.util.ArrayList; + +import one.nem.lacerta.model.document.tag.DocumentTag; + public class ListItem { // Properties @@ -11,6 +15,7 @@ public class ListItem { ListItemType itemType; String itemId; boolean hasCombined; + ArrayList tagList; // Constructor @@ -29,6 +34,15 @@ public class ListItem { this.hasCombined = hasCombined; } + public ListItem(String title, String description, ListItemType itemType, String itemId,boolean hasCombined, ArrayList tagList) { + this.title = title; + this.description = description; + this.itemType = itemType; + this.itemId = itemId; + this.hasCombined = hasCombined; + this.tagList = tagList; + } + public ListItem() { // Empty constructor } @@ -55,6 +69,10 @@ public class ListItem { return hasCombined; } + public ArrayList getTagList() { + return tagList; + } + // Setter public void setTitle(String title) { @@ -77,4 +95,7 @@ public class ListItem { this.hasCombined = hasCombined; } + public void setTagList(ArrayList tagList) { + this.tagList = tagList; + } } diff --git a/shared/ui/src/main/res/layout/common_list_item_with_tag.xml b/shared/ui/src/main/res/layout/common_list_item_with_tag.xml new file mode 100644 index 00000000..dadf574c --- /dev/null +++ b/shared/ui/src/main/res/layout/common_list_item_with_tag.xml @@ -0,0 +1,63 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file