mirror of
https://github.com/lacerta-doc/Lacerta.git
synced 2024-11-26 09:43:15 +00:00
Merge pull request #124 from lacerta-doc/add_edit_meta_dialog
結合したドキュメントの名前を変えられるように, タグをドキュメントに付与/剥奪できるように
This commit is contained in:
commit
0a0a4b56b9
|
@ -0,0 +1,83 @@
|
|||
package one.nem.lacerta.component.common;
|
||||
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.CheckBox;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import one.nem.lacerta.component.common.model.DocumentTagApplyTagDialogExtendedModel;
|
||||
import one.nem.lacerta.model.document.tag.DocumentTag;
|
||||
|
||||
public class LacertaApplyTagAdapter extends RecyclerView.Adapter<LacertaApplyTagAdapter.LacertaApplyTagViewHolder>{
|
||||
|
||||
// Listener
|
||||
public interface LacertaApplyTagDialogListener {
|
||||
void itemChecked(View view, String tagId);
|
||||
void itemUnchecked(View view, String tagId);
|
||||
}
|
||||
|
||||
// Variables
|
||||
private ArrayList<DocumentTagApplyTagDialogExtendedModel> documentTagArrayList;
|
||||
private LacertaApplyTagDialogListener listener;
|
||||
|
||||
// Setter
|
||||
public LacertaApplyTagAdapter setListener(LacertaApplyTagDialogListener listener) {
|
||||
this.listener = listener;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LacertaApplyTagAdapter setDocumentTagArrayList(ArrayList<DocumentTagApplyTagDialogExtendedModel> documentTagArrayList) {
|
||||
this.documentTagArrayList = documentTagArrayList;
|
||||
return this;
|
||||
}
|
||||
|
||||
// Empty constructor
|
||||
public LacertaApplyTagAdapter() {
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public LacertaApplyTagAdapter.LacertaApplyTagViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.apply_tag_list_item, parent, false);
|
||||
return new LacertaApplyTagAdapter.LacertaApplyTagViewHolder(view);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull LacertaApplyTagAdapter.LacertaApplyTagViewHolder holder, int position) {
|
||||
DocumentTagApplyTagDialogExtendedModel documentTag = documentTagArrayList.get(position);
|
||||
if (holder.checkBox == null) {
|
||||
Log.d("LacertaApplyTagAdapter", "onBindViewHolder: holder.checkBox is null");
|
||||
}
|
||||
holder.checkBox.setText(documentTag.getName());
|
||||
holder.checkBox.setChecked(documentTag.getIsChecked());
|
||||
holder.checkBox.setOnCheckedChangeListener((buttonView, isChecked) -> {
|
||||
if (isChecked) {
|
||||
listener.itemChecked(buttonView, documentTag.getId());
|
||||
} else {
|
||||
listener.itemUnchecked(buttonView, documentTag.getId());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return documentTagArrayList == null ? 0 : documentTagArrayList.size();
|
||||
}
|
||||
|
||||
public class LacertaApplyTagViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
CheckBox checkBox;
|
||||
|
||||
public LacertaApplyTagViewHolder(@NonNull View itemView) {
|
||||
super(itemView);
|
||||
|
||||
checkBox = itemView.findViewById(R.id.tag_check_box);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,184 @@
|
|||
package one.nem.lacerta.component.common;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.Checkable;
|
||||
import android.widget.EditText;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.fragment.app.DialogFragment;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.CompletionException;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import dagger.hilt.android.AndroidEntryPoint;
|
||||
import one.nem.lacerta.component.common.model.DocumentTagApplyTagDialogExtendedModel;
|
||||
import one.nem.lacerta.data.Document;
|
||||
import one.nem.lacerta.data.LacertaLibrary;
|
||||
import one.nem.lacerta.model.document.tag.DocumentTag;
|
||||
import one.nem.lacerta.utils.LacertaLogger;
|
||||
|
||||
@AndroidEntryPoint
|
||||
public class LacertaApplyTagDialog extends DialogFragment {
|
||||
|
||||
@Inject
|
||||
LacertaLogger logger;
|
||||
|
||||
@Inject
|
||||
LacertaLibrary lacertaLibrary;
|
||||
|
||||
// Listener
|
||||
public interface LacertaApplyTagDialogListener {
|
||||
void onDialogPositiveClick(ArrayList<DocumentTag> appliedTags);
|
||||
void onDialogNegativeClick();
|
||||
}
|
||||
|
||||
// Variables
|
||||
private String title;
|
||||
private String message;
|
||||
private String positiveButtonText;
|
||||
private String negativeButtonText;
|
||||
private String documentId;
|
||||
private LacertaApplyTagDialogListener listener;
|
||||
private ArrayList<DocumentTag> registeredTags;
|
||||
private ArrayList<DocumentTag> appliedTags;
|
||||
|
||||
// Setter
|
||||
|
||||
public LacertaApplyTagDialog setListener(LacertaApplyTagDialogListener listener) {
|
||||
this.listener = listener;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LacertaApplyTagDialog setTitle(String title) {
|
||||
this.title = title;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LacertaApplyTagDialog setMessage(String message) {
|
||||
this.message = message;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LacertaApplyTagDialog setPositiveButtonText(String positiveButtonText) {
|
||||
this.positiveButtonText = positiveButtonText;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LacertaApplyTagDialog setNegativeButtonText(String negativeButtonText) {
|
||||
this.negativeButtonText = negativeButtonText;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LacertaApplyTagDialog setDocumentId(String documentId) {
|
||||
this.documentId = documentId;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(getActivity());
|
||||
LayoutInflater inflater = requireActivity().getLayoutInflater();
|
||||
View view = inflater.inflate(R.layout.lacerta_dialog_apply_tag, null);
|
||||
|
||||
// RecyclerView
|
||||
RecyclerView recyclerView = view.findViewById(R.id.apply_tag_list);
|
||||
|
||||
LacertaApplyTagAdapter lacertaApplyTagAdapter = new LacertaApplyTagAdapter();
|
||||
lacertaApplyTagAdapter.setListener(new LacertaApplyTagAdapter.LacertaApplyTagDialogListener() {
|
||||
@Override
|
||||
public void itemChecked(View view, String tagId) {
|
||||
applyChangeToVariable(true, tagId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void itemUnchecked(View view, String tagId) {
|
||||
applyChangeToVariable(false, tagId);
|
||||
}
|
||||
});
|
||||
|
||||
recyclerView.setAdapter(lacertaApplyTagAdapter);
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(view.getContext()));
|
||||
|
||||
getDocumentTagArrayList(documentId).thenAccept(documentTagArrayList -> {
|
||||
lacertaApplyTagAdapter.setDocumentTagArrayList(documentTagArrayList);
|
||||
lacertaApplyTagAdapter.notifyDataSetChanged(); // TODO-rca: アニメーション
|
||||
});
|
||||
|
||||
// Set the dialog title
|
||||
builder.setTitle(title)
|
||||
.setMessage(message)
|
||||
.setView(view)
|
||||
.setPositiveButton(positiveButtonText == null ? "OK" : positiveButtonText, (dialog, id) -> {
|
||||
// Send the positive button event back to the host activity
|
||||
listener.onDialogPositiveClick(this.appliedTags);
|
||||
})
|
||||
.setNegativeButton(negativeButtonText == null ? "Cancel" : negativeButtonText, (dialog, id) -> {
|
||||
// Send the negative button event back to the host activity
|
||||
listener.onDialogNegativeClick();
|
||||
});
|
||||
return builder.create();
|
||||
}
|
||||
|
||||
private void applyChangeToVariable(boolean isChecked, String tagId) {
|
||||
if (isChecked) {
|
||||
this.registeredTags.stream().filter(tag -> tag.getId().equals(tagId)).findFirst().ifPresent(tag -> this.appliedTags.add(tag));
|
||||
} else {
|
||||
this.appliedTags.stream().filter(tag -> tag.getId().equals(tagId)).findFirst().ifPresent(tag -> this.appliedTags.remove(tag));
|
||||
}
|
||||
}
|
||||
|
||||
private CompletableFuture<ArrayList<DocumentTagApplyTagDialogExtendedModel>> getDocumentTagArrayList(String documentId) {
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
ArrayList<DocumentTagApplyTagDialogExtendedModel> documentTagArrayList = new ArrayList<>();
|
||||
setRegisteredTagList().thenRun(() -> setAppliedTagList(documentId).join()).thenAccept(Void -> {
|
||||
logger.debug("getDocumentTagArrayList", "this.registeredTags.size(): " + this.registeredTags.size());
|
||||
logger.debug("getDocumentTagArrayList", "this.appliedTags.size(): " + this.appliedTags.size());
|
||||
|
||||
documentTagArrayList.addAll(this.registeredTags.stream().map(tag -> {
|
||||
DocumentTagApplyTagDialogExtendedModel documentTag = new DocumentTagApplyTagDialogExtendedModel(
|
||||
new DocumentTag(tag.getId(), tag.getName(), tag.getColor()),
|
||||
this.appliedTags.stream().anyMatch(appliedTag -> appliedTag.getId().equals(tag.getId()))
|
||||
);
|
||||
return documentTag;
|
||||
}).collect(Collectors.toCollection(ArrayList::new)));
|
||||
|
||||
}).join();
|
||||
return documentTagArrayList;
|
||||
});
|
||||
}
|
||||
|
||||
private CompletableFuture<Void> setRegisteredTagList() {
|
||||
return CompletableFuture.runAsync(() -> {
|
||||
this.registeredTags = new ArrayList<>();
|
||||
this.lacertaLibrary.getTagList().thenAccept(documentTagList -> {
|
||||
for (int i = 0; i < documentTagList.size(); i++) {
|
||||
this.registeredTags.add(new DocumentTag(documentTagList.get(i).getId(), documentTagList.get(i).getName(), documentTagList.get(i).getColor()));
|
||||
}
|
||||
}).join();
|
||||
});
|
||||
}
|
||||
|
||||
private CompletableFuture<Void> setAppliedTagList(String documentId) {
|
||||
return CompletableFuture.runAsync(() -> {
|
||||
this.appliedTags = new ArrayList<>();
|
||||
this.lacertaLibrary.getAppliedTagList(documentId).thenAccept(documentTagList -> {
|
||||
for (int i = 0; i < documentTagList.size(); i++) {
|
||||
this.appliedTags.add(new DocumentTag(documentTagList.get(i).getId(), documentTagList.get(i).getName(), documentTagList.get(i).getColor()));
|
||||
}
|
||||
}).join();
|
||||
});
|
||||
}
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
package one.nem.lacerta.component.common;
|
||||
|
||||
public class LacertaEditMetaDialog {
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
package one.nem.lacerta.component.common.model;
|
||||
|
||||
import one.nem.lacerta.model.document.tag.DocumentTag;
|
||||
|
||||
// TODO-rca: クラス名が長すぎ
|
||||
|
||||
/**
|
||||
* DocumentTagを設定するダイアログで使うための拡張モデル
|
||||
* チェックボックスの状態を保持するように
|
||||
*/
|
||||
public class DocumentTagApplyTagDialogExtendedModel extends DocumentTag {
|
||||
|
||||
private boolean isChecked;
|
||||
|
||||
public DocumentTagApplyTagDialogExtendedModel(DocumentTag documentTag) {
|
||||
super(documentTag.getId(), documentTag.getName(), documentTag.getColor());
|
||||
}
|
||||
|
||||
public DocumentTagApplyTagDialogExtendedModel(DocumentTag documentTag, boolean isChecked) {
|
||||
super(documentTag.getId(), documentTag.getName(), documentTag.getColor());
|
||||
this.isChecked = isChecked;
|
||||
}
|
||||
|
||||
public boolean getIsChecked() {
|
||||
return isChecked;
|
||||
}
|
||||
|
||||
public void setIsChecked(boolean checked) {
|
||||
isChecked = checked;
|
||||
}
|
||||
}
|
15
component/common/src/main/res/layout/apply_tag_list_item.xml
Normal file
15
component/common/src/main/res/layout/apply_tag_list_item.xml
Normal file
|
@ -0,0 +1,15 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/tag_check_box"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="16sp"
|
||||
android:layout_marginHorizontal="16dp"
|
||||
android:layout_marginVertical="4dp"
|
||||
android:text="CheckBox" />
|
||||
|
||||
</LinearLayout>
|
|
@ -0,0 +1,10 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/apply_tag_list"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
</FrameLayout>
|
|
@ -0,0 +1,21 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
android:id="@+id/title_text_input_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingTop="8dp"
|
||||
android:paddingHorizontal="16dp"
|
||||
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox">
|
||||
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
android:id="@+id/tag_name_edit_text"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
|
||||
</LinearLayout>
|
|
@ -19,13 +19,18 @@ import com.google.android.material.tabs.TabLayoutMediator;
|
|||
import com.google.android.material.textfield.TextInputEditText;
|
||||
import com.google.android.material.textfield.TextInputLayout;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import dagger.hilt.android.AndroidEntryPoint;
|
||||
import one.nem.lacerta.component.common.LacertaApplyTagDialog;
|
||||
import one.nem.lacerta.component.common.picker.LacertaFilePickerDialog;
|
||||
import one.nem.lacerta.data.Document;
|
||||
import one.nem.lacerta.data.LacertaLibrary;
|
||||
import one.nem.lacerta.model.document.page.Page;
|
||||
import one.nem.lacerta.model.document.tag.DocumentTag;
|
||||
import one.nem.lacerta.model.pref.ToxiDocumentModel;
|
||||
import one.nem.lacerta.utils.LacertaLogger;
|
||||
|
||||
|
@ -52,6 +57,7 @@ public class ViewerContainerFragment extends Fragment {
|
|||
private String documentId;
|
||||
private String documentName;
|
||||
private boolean hasCombined = false;
|
||||
private ViewerViewPagerAdapter viewerViewPagerAdapter;
|
||||
|
||||
public ViewerContainerFragment() {
|
||||
// Required empty public constructor
|
||||
|
@ -102,7 +108,7 @@ public class ViewerContainerFragment extends Fragment {
|
|||
ViewPager2 viewPager = view.findViewById(R.id.view_pager);
|
||||
|
||||
// Init view pager adapter
|
||||
ViewerViewPagerAdapter viewerViewPagerAdapter = new ViewerViewPagerAdapter(requireActivity());
|
||||
this.viewerViewPagerAdapter = new ViewerViewPagerAdapter(requireActivity());
|
||||
viewPager.setAdapter(viewerViewPagerAdapter);
|
||||
|
||||
// Init tab layout
|
||||
|
@ -112,22 +118,24 @@ public class ViewerContainerFragment extends Fragment {
|
|||
Toolbar toolbar = view.findViewById(R.id.toolbar);
|
||||
initToolbar(toolbar, true, documentName);
|
||||
|
||||
if (this.hasCombined) {
|
||||
// Get document page
|
||||
if (this.hasCombined) { // 結合親の場合
|
||||
logger.debug("ViewerContainerFragment", "hasCombined: " + hasCombined);
|
||||
lacertaLibrary.getCombinedDocumentToxiList(documentId).thenAccept(combinedDocumentToxiList -> {
|
||||
logger.debug("ViewerContainerFragment", "combinedDocumentToxiList: " + combinedDocumentToxiList.size());
|
||||
for (ToxiDocumentModel toxiDocumentModel : combinedDocumentToxiList) {
|
||||
logger.debug("ViewerContainerFragment", "titleCache: " + toxiDocumentModel.getTitleCache());
|
||||
viewerViewPagerAdapter
|
||||
.addFragment(ViewerBodyFragment.newInstance(toxiDocumentModel.getChildDocumentId(), toxiDocumentModel.getTitleCache()),
|
||||
toxiDocumentModel.getTitleCache());
|
||||
}
|
||||
|
||||
viewerViewPagerAdapter.setFragmentTargetIdList(
|
||||
combinedDocumentToxiList.stream().map(ToxiDocumentModel::getChildDocumentId).collect(Collectors.toCollection(ArrayList::new)));
|
||||
viewerViewPagerAdapter.setFragmentTitleList(
|
||||
combinedDocumentToxiList.stream().map(ToxiDocumentModel::getTitleCache).collect(Collectors.toCollection(ArrayList::new)));
|
||||
|
||||
viewerViewPagerAdapter.notifyItemRangeChanged(0, combinedDocumentToxiList.size());
|
||||
});
|
||||
} else {
|
||||
} else { // それ以外の場合
|
||||
logger.debug("ViewerContainerFragment", "hasCombined: " + hasCombined);
|
||||
tabLayout.setVisibility(View.GONE);
|
||||
viewerViewPagerAdapter.addFragment(ViewerBodyFragment.newInstance(documentId, documentName), documentName);
|
||||
viewerViewPagerAdapter.setFragmentTargetIdList(new ArrayList<String>(){{add(documentId);}}); // TODO-rca: 読みにくいので直接追加できるようにする
|
||||
viewerViewPagerAdapter.setFragmentTitleList(new ArrayList<String>(){{add(documentName);}});
|
||||
viewerViewPagerAdapter.notifyItemRangeChanged(0, 1);
|
||||
}
|
||||
|
||||
|
@ -140,13 +148,54 @@ public class ViewerContainerFragment extends Fragment {
|
|||
|
||||
ImageButton imageButton = customView.findViewById(R.id.tab_modify);
|
||||
imageButton.setOnClickListener(v -> {
|
||||
Toast.makeText(getContext(), "Working!, Index:" + position, Toast.LENGTH_SHORT).show();
|
||||
renameCombinedDocument(
|
||||
this.documentId,
|
||||
viewerViewPagerAdapter.getFragmentTargetId(position),
|
||||
viewerViewPagerAdapter.getFragmentTitle(position),
|
||||
position);
|
||||
});
|
||||
|
||||
tab.setCustomView(customView);
|
||||
}).attach();
|
||||
}
|
||||
|
||||
private void renameCombinedDocument(String parentId, String childId, String current, int position) { // TODO-rca: 無理やりpositionを渡してるのでなんとかする
|
||||
MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(getContext());
|
||||
builder.setTitle("アイテム名の変更");
|
||||
builder.setMessage("アイテム名を入力してください");
|
||||
|
||||
View view = LayoutInflater.from(getContext()).inflate(one.nem.lacerta.shared.ui.R.layout.lacerta_dialog_edit_text_layout, null);
|
||||
TextInputEditText textInputEditText = view.findViewById(one.nem.lacerta.shared.ui.R.id.custom_edit_text);
|
||||
TextInputLayout textInputLayout = view.findViewById(one.nem.lacerta.shared.ui.R.id.custom_text_input_layout);
|
||||
textInputEditText.setText(current);
|
||||
textInputLayout.setHint("アイテム名");
|
||||
builder.setView(view);
|
||||
|
||||
builder.setPositiveButton("変更", (dialog, which) -> {
|
||||
document.renameDocument(childId, textInputEditText.getText().toString()).thenCombine(
|
||||
lacertaLibrary.updateTitleCache(parentId, childId, textInputEditText.getText().toString()), (aVoid, aVoid2) -> {
|
||||
getActivity().runOnUiThread(() -> {
|
||||
Toast.makeText(getContext(), "変更しました", Toast.LENGTH_SHORT).show();
|
||||
updateTabTitle(position, textInputEditText.getText().toString());
|
||||
dialog.dismiss();
|
||||
});
|
||||
return null;
|
||||
});
|
||||
});
|
||||
builder.setNegativeButton("キャンセル", (dialog, which) -> {
|
||||
dialog.cancel();
|
||||
});
|
||||
|
||||
builder.show();
|
||||
}
|
||||
|
||||
private void updateTabTitle(int position, String title) {
|
||||
ArrayList<String> fragmentTitleList = viewerViewPagerAdapter.getFragmentTitleList();
|
||||
fragmentTitleList.set(position, title);
|
||||
viewerViewPagerAdapter.setFragmentTitleList(fragmentTitleList);
|
||||
viewerViewPagerAdapter.notifyItemChanged(position);
|
||||
}
|
||||
|
||||
/**
|
||||
* Toolbarをinitする
|
||||
*
|
||||
|
@ -187,6 +236,9 @@ public class ViewerContainerFragment extends Fragment {
|
|||
} else if (item.getItemId() == R.id.action_combine) {
|
||||
combineDocument();
|
||||
return true;
|
||||
} else if (item.getItemId() == R.id.action_apply_tag) {
|
||||
applyTag();
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
@ -194,6 +246,33 @@ public class ViewerContainerFragment extends Fragment {
|
|||
});
|
||||
}
|
||||
|
||||
private void applyTag() {
|
||||
LacertaApplyTagDialog lacertaApplyTagDialog = new LacertaApplyTagDialog();
|
||||
lacertaApplyTagDialog
|
||||
.setTitle("タグの適用")
|
||||
.setMessage("タグを適用するファイルを選択してください")
|
||||
.setNegativeButtonText("キャンセル")
|
||||
.setDocumentId(documentId)
|
||||
.setListener(new LacertaApplyTagDialog.LacertaApplyTagDialogListener() {
|
||||
@Override
|
||||
public void onDialogPositiveClick(ArrayList<DocumentTag> appliedTags) {
|
||||
logger.debug("ViewerContainerFragment", "Dialog Result: appliedTags: " + appliedTags.size());
|
||||
lacertaLibrary.applyTagListToDocument(documentId, appliedTags).thenAccept(aVoid -> {
|
||||
getActivity().runOnUiThread(() -> {
|
||||
Toast.makeText(getContext(), "タグを適用しました", Toast.LENGTH_SHORT).show();
|
||||
lacertaApplyTagDialog.dismiss();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDialogNegativeClick() {
|
||||
lacertaApplyTagDialog.dismiss();
|
||||
}
|
||||
})
|
||||
.show(getChildFragmentManager(), "LacertaApplyTagDialog");
|
||||
}
|
||||
|
||||
private void combineDocument() {
|
||||
LacertaFilePickerDialog lacertaFilePickerDialog = new LacertaFilePickerDialog();
|
||||
lacertaFilePickerDialog.setListener((fileName, selectedId) -> {
|
||||
|
|
|
@ -13,13 +13,17 @@ import java.util.ArrayList;
|
|||
public class ViewerViewPagerAdapter extends FragmentStateAdapter {
|
||||
|
||||
// Variables
|
||||
private ArrayList<Fragment> fragmentArrayList = new ArrayList<>();
|
||||
private ArrayList<String> fragmentTargetIdList = new ArrayList<>();
|
||||
private ArrayList<String> fragmentTitleList = new ArrayList<>();
|
||||
|
||||
// Setter
|
||||
public void addFragment(Fragment fragment, String title){
|
||||
fragmentArrayList.add(fragment);
|
||||
fragmentTitleList.add(title);
|
||||
|
||||
public void setFragmentTargetIdList(ArrayList<String> fragmentTargetIdList) {
|
||||
this.fragmentTargetIdList = fragmentTargetIdList;
|
||||
}
|
||||
|
||||
public void setFragmentTitleList(ArrayList<String> fragmentTitleList) {
|
||||
this.fragmentTitleList = fragmentTitleList;
|
||||
}
|
||||
|
||||
public ViewerViewPagerAdapter(@NonNull FragmentActivity fragmentActivity) {
|
||||
|
@ -29,16 +33,40 @@ public class ViewerViewPagerAdapter extends FragmentStateAdapter {
|
|||
@NonNull
|
||||
@Override
|
||||
public Fragment createFragment(int position) {
|
||||
return fragmentArrayList.get(position);
|
||||
return ViewerBodyFragment.newInstance(fragmentTargetIdList.get(position), fragmentTitleList.get(position));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return fragmentArrayList == null ? 0 : fragmentArrayList.size();
|
||||
if (fragmentTargetIdList == null || fragmentTitleList == null) {
|
||||
return 0;
|
||||
} else if (fragmentTargetIdList.size() != fragmentTitleList.size()) {
|
||||
throw new IllegalStateException("fragmentTargetIdList.size() != fragmentTitleList.size()");
|
||||
} else {
|
||||
return fragmentTargetIdList.size();
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public CharSequence getTabTitle(int position) {
|
||||
return fragmentTitleList.get(position);
|
||||
}
|
||||
|
||||
// Getter
|
||||
|
||||
public String getFragmentTargetId(int position) {
|
||||
return fragmentTargetIdList.get(position);
|
||||
}
|
||||
|
||||
public String getFragmentTitle(int position) {
|
||||
return fragmentTitleList.get(position);
|
||||
}
|
||||
|
||||
public ArrayList<String> getFragmentTargetIdList() {
|
||||
return fragmentTargetIdList;
|
||||
}
|
||||
|
||||
public ArrayList<String> getFragmentTitleList() {
|
||||
return fragmentTitleList;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,4 +20,12 @@
|
|||
android:id="@+id/action_combine"
|
||||
android:title="結合" />
|
||||
|
||||
<item
|
||||
android:id="@+id/action_edit_meta"
|
||||
android:title="メタデータ編集" />
|
||||
|
||||
<item
|
||||
android:id="@+id/action_apply_tag"
|
||||
android:title="タグの管理" />
|
||||
|
||||
</menu>
|
|
@ -45,12 +45,16 @@ public interface LacertaLibrary {
|
|||
|
||||
CompletableFuture<Void> addTagToDocument(String documentId, String tagId);
|
||||
|
||||
CompletableFuture<Void> applyTagListToDocument(String documentId, ArrayList<DocumentTag> tagList);
|
||||
|
||||
CompletableFuture<Void> removeTagFromDocument(String documentId, String tagId);
|
||||
|
||||
// Combined Document
|
||||
|
||||
CompletableFuture<Void> combineDocument(String parentId, String childId);
|
||||
|
||||
CompletableFuture<Void> updateTitleCache(String parentId, String childId, String titleCache);
|
||||
|
||||
CompletableFuture<Void> uncombineDocument(String parentId, String childId);
|
||||
|
||||
// CompletableFuture<Void> combineDocument(String parentId, ArrayList<String> childIdList);
|
||||
|
|
|
@ -321,6 +321,20 @@ public class LacertaLibraryImpl implements LacertaLibrary {
|
|||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Void> applyTagListToDocument(String documentId, ArrayList<DocumentTag> tagArrayList) {
|
||||
return CompletableFuture.supplyAsync(() -> { // TODO-rca: 必要なものだけInsertするべき, 時間があれば...
|
||||
// 一旦全てのタグを削除
|
||||
database.toxiDocumentTagDao().deleteByDocumentId(documentId);
|
||||
logger.debug("LacertaLibraryImpl", "Database Query: Deleted ToxiDocumentTagEntity");
|
||||
// タグを追加
|
||||
for (DocumentTag documentTag : tagArrayList) {
|
||||
addTagToDocument(documentId, documentTag.getId());
|
||||
}
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Void> removeTagFromDocument(String documentId, String tagId) {
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
|
@ -375,6 +389,21 @@ public class LacertaLibraryImpl implements LacertaLibrary {
|
|||
logger.debug("LacertaLibraryImpl", "Database Query: Inserted ToxiDocumentEntity");
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Void> updateTitleCache(String parentId, String documentId, String titleCache) {
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
ToxiDocumentEntity toxiDocumentEntity = database.toxiDocumentDao().findByParentIdAndChildId(parentId, documentId);
|
||||
if (toxiDocumentEntity == null) {
|
||||
logger.warn("LacertaLibraryImpl", "ToxiDocumentEntity is not found.");
|
||||
return null;
|
||||
}
|
||||
toxiDocumentEntity.titleCache = titleCache;
|
||||
database.toxiDocumentDao().update(toxiDocumentEntity);
|
||||
logger.debug("LacertaLibraryImpl", "Database Query: Updated ToxiDocumentEntity");
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Void> uncombineDocument(String parentId, String childId) {
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
|
|
|
@ -15,6 +15,9 @@ public interface ToxiDocumentDao {
|
|||
@Query("SELECT * FROM toxi_document WHERE parent_document_id = :parentId AND is_active = 1 ORDER BY `order` ASC")
|
||||
List<ToxiDocumentEntity> findByParentId(String parentId);
|
||||
|
||||
@Query("SELECT * FROM toxi_document WHERE parent_document_id = :parentId AND child_document_id = :childId AND is_active = 1")
|
||||
ToxiDocumentEntity findByParentIdAndChildId(String parentId, String childId);
|
||||
|
||||
@Insert
|
||||
void insert(ToxiDocumentEntity toxiDocument);
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user