mirror of
https://github.com/lacerta-doc/Lacerta.git
synced 2024-11-23 00:13:16 +00:00
commit
5e0310beb2
|
@ -35,6 +35,8 @@ public interface LacertaLibrary {
|
|||
// Tag
|
||||
CompletableFuture<ArrayList<DocumentTag>> getTagList();
|
||||
|
||||
CompletableFuture<ArrayList<DocumentTag>> getAppliedTagList(String documentId);
|
||||
|
||||
CompletableFuture<Void> createTag(DocumentTag tag);
|
||||
|
||||
CompletableFuture<Void> updateTag(DocumentTag tag);
|
||||
|
|
|
@ -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<ToxiDocumentTagEntity> documentTagEntities = database.toxiDocumentTagDao().findByDocumentId(documentEntity.id);
|
||||
ArrayList<DocumentTag> 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<ArrayList<DocumentTag>> getAppliedTagList(String documentId) {
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
List<ToxiDocumentTagEntity> toxiDocumentTagEntities = database.toxiDocumentTagDao().findByDocumentId(documentId);
|
||||
logger.debug("LacertaLibraryImpl", "Database Query: Get ToxiDocumentTagEntity List (Size: " + toxiDocumentTagEntities.size() + ")");
|
||||
ArrayList<DocumentTag> 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<Void> createTag(DocumentTag tag) {
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
|
|
|
@ -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 サブタイトル
|
||||
|
|
|
@ -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<ListItemAdapter.ListIt
|
|||
@NonNull
|
||||
@Override
|
||||
public ListItemViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
View view = LayoutInflater.from(parent.getContext()).inflate(one.nem.lacerta.shared.ui.R.layout.common_list_item, parent, false);
|
||||
View view = LayoutInflater.from(parent.getContext()).inflate(one.nem.lacerta.shared.ui.R.layout.common_list_item_with_tag, parent, false);
|
||||
return new ListItemViewHolder(view);
|
||||
}
|
||||
|
||||
|
@ -43,6 +48,19 @@ public class ListItemAdapter extends RecyclerView.Adapter<ListItemAdapter.ListIt
|
|||
holder.title.setText(listItem.getTitle());
|
||||
holder.description.setText(listItem.getDescription());
|
||||
|
||||
if (listItem.getTagList() != null && !listItem.getTagList().isEmpty()) {
|
||||
for (int i = 0; i < listItem.getTagList().size(); i++) {
|
||||
Toast.makeText(holder.tagGroup.getContext(), listItem.getTagList().get(i).getName(), Toast.LENGTH_SHORT).show();
|
||||
ChipGroup chipGroup = holder.tagGroup;
|
||||
Chip chip = new Chip(chipGroup.getContext());
|
||||
chip.setText(listItem.getTagList().get(i).getName());
|
||||
chipGroup.addView(chip);
|
||||
}
|
||||
holder.tagGroup.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
holder.tagGroup.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
holder.itemView.setOnClickListener( v -> {
|
||||
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<ListItemAdapter.ListIt
|
|||
ImageView icon;
|
||||
TextView title;
|
||||
TextView description;
|
||||
ChipGroup tagGroup;
|
||||
public ListItemViewHolder(@NonNull View itemView) {
|
||||
super(itemView);
|
||||
|
||||
icon = itemView.findViewById(one.nem.lacerta.shared.ui.R.id.item_icon);
|
||||
title = itemView.findViewById(one.nem.lacerta.shared.ui.R.id.item_title);
|
||||
description = itemView.findViewById(one.nem.lacerta.shared.ui.R.id.item_description);
|
||||
tagGroup = itemView.findViewById(one.nem.lacerta.shared.ui.R.id.item_tags);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
package one.nem.lacerta.feature.library;
|
||||
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.BaseAdapter;
|
||||
|
||||
import com.google.android.material.chip.Chip;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import one.nem.lacerta.model.document.tag.DocumentTag;
|
||||
|
||||
public class TagAdapter extends BaseAdapter {
|
||||
|
||||
private ArrayList<DocumentTag> 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;
|
||||
}
|
||||
}
|
|
@ -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<DocumentTag> 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<DocumentTag> 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<DocumentTag> getTagList() {
|
||||
return tagList;
|
||||
}
|
||||
|
||||
// Setter
|
||||
|
||||
public void setTitle(String title) {
|
||||
|
@ -77,4 +95,7 @@ public class ListItem {
|
|||
this.hasCombined = hasCombined;
|
||||
}
|
||||
|
||||
public void setTagList(ArrayList<DocumentTag> tagList) {
|
||||
this.tagList = tagList;
|
||||
}
|
||||
}
|
||||
|
|
63
shared/ui/src/main/res/layout/common_list_item_with_tag.xml
Normal file
63
shared/ui/src/main/res/layout/common_list_item_with_tag.xml
Normal file
|
@ -0,0 +1,63 @@
|
|||
<?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:paddingHorizontal="24dp"
|
||||
android:paddingVertical="16dp"
|
||||
android:theme="@style/Theme.Lacerta">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/item_icon"
|
||||
android:layout_width="32dp"
|
||||
android:layout_height="0dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toStartOf="@id/item_text_container"
|
||||
app:srcCompat="@drawable/description_24px"
|
||||
android:contentDescription="icon" />
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:id="@+id/item_text_container"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toEndOf="@id/item_icon"
|
||||
app:layout_constraintTop_toTopOf="parent">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/item_title"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="16sp"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:text="Placeholder Title"
|
||||
android:textColor="@color/colorOnSurface"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/item_description"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="14sp"
|
||||
android:text="Placeholder Description"
|
||||
android:textColor="@color/colorOnSurfaceSecondary"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/item_title" />
|
||||
|
||||
<com.google.android.material.chip.ChipGroup
|
||||
android:id="@+id/item_tags"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:visibility="gone"
|
||||
app:layout_constraintTop_toBottomOf="@id/item_description">
|
||||
|
||||
</com.google.android.material.chip.ChipGroup>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
Loading…
Reference in New Issue
Block a user