とりあえずタグを表示できるようにした

This commit is contained in:
r-ca 2024-01-28 23:13:20 +09:00
parent ab92c6ce93
commit 9045cec67d
No known key found for this signature in database
GPG Key ID: 6A72911AC73464A9
3 changed files with 43 additions and 1 deletions

View File

@ -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);
}

View File

@ -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 サブタイトル

View File

@ -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,20 @@ public class ListItemAdapter extends RecyclerView.Adapter<ListItemAdapter.ListIt
holder.title.setText(listItem.getTitle());
holder.description.setText(listItem.getDescription());
if (listItem.getTagList() != null) {
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 {
Log.d("tagList", "tagList is null");
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 +83,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);
}
}
}