diff --git a/component/common/src/main/java/one/nem/lacerta/component/common/LacertaCreateTagDialog.java b/component/common/src/main/java/one/nem/lacerta/component/common/LacertaCreateTagDialog.java
new file mode 100644
index 00000000..6a187926
--- /dev/null
+++ b/component/common/src/main/java/one/nem/lacerta/component/common/LacertaCreateTagDialog.java
@@ -0,0 +1,87 @@
+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.EditText;
+
+import androidx.fragment.app.DialogFragment;
+
+import com.google.android.material.dialog.MaterialAlertDialogBuilder;
+
+public class LacertaCreateTagDialog extends DialogFragment {
+
+ private String title;
+
+ private String message;
+
+ private String positiveButtonText;
+
+ private String negativeButtonText;
+
+ private LacertaCreateTagDialogListener listener;
+
+ // Setter
+
+ public LacertaCreateTagDialog setListener(LacertaCreateTagDialogListener listener) {
+ this.listener = listener;
+ return this;
+ }
+
+ public LacertaCreateTagDialog setTitle(String title) {
+ this.title = title;
+ return this;
+ }
+
+ public LacertaCreateTagDialog setMessage(String message) {
+ this.message = message;
+ return this;
+ }
+
+ public LacertaCreateTagDialog setPositiveButtonText(String positiveButtonText) {
+ this.positiveButtonText = positiveButtonText;
+ return this;
+ }
+
+ public LacertaCreateTagDialog setNegativeButtonText(String negativeButtonText) {
+ this.negativeButtonText = negativeButtonText;
+ 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_create_tag, null);
+
+ // TextEdit
+ EditText tag_name_edit_text = view.findViewById(R.id.tag_name_edit_text);
+ com.google.android.material.textfield.TextInputLayout tag_name_text_input_layout = view.findViewById(R.id.tag_name_text_input_layout);
+ tag_name_text_input_layout.setHint("タグの名前");
+ EditText tag_color_edit_text = view.findViewById(R.id.tag_color_edit_text);
+ com.google.android.material.textfield.TextInputLayout tag_color_text_input_layout = view.findViewById(R.id.tag_color_text_input_layout);
+ tag_color_text_input_layout.setHint("タグの色(カラーコード)");
+
+ builder.setTitle(this.title == null ? "Create new tag" : this.title);
+
+ // Button
+ builder.setPositiveButton(positiveButtonText == null ? "OK" : positiveButtonText, (dialog, which) -> {
+ String tag_name = tag_name_edit_text.getText().toString();
+ String tag_color = tag_color_edit_text.getText().toString();
+ if (listener != null) {
+ listener.onPositiveClick(tag_name, tag_color);
+ }
+ });
+ builder.setNegativeButton(negativeButtonText == null ? "Cancel" : negativeButtonText, (dialog, which) -> {
+ if (listener != null) {
+ listener.onNegativeClick();
+ }
+ });
+
+ builder.setView(view);
+ return builder.create();
+ }
+
+
+}
diff --git a/component/common/src/main/java/one/nem/lacerta/component/common/LacertaCreateTagDialogListener.java b/component/common/src/main/java/one/nem/lacerta/component/common/LacertaCreateTagDialogListener.java
new file mode 100644
index 00000000..fce79957
--- /dev/null
+++ b/component/common/src/main/java/one/nem/lacerta/component/common/LacertaCreateTagDialogListener.java
@@ -0,0 +1,8 @@
+package one.nem.lacerta.component.common;
+
+public interface LacertaCreateTagDialogListener {
+
+ void onPositiveClick(String tag_name, String tag_color);
+
+ void onNegativeClick();
+}
diff --git a/component/common/src/main/res/layout/lacerta_dialog_create_tag.xml b/component/common/src/main/res/layout/lacerta_dialog_create_tag.xml
index 4e72834f..8cd6efb9 100644
--- a/component/common/src/main/res/layout/lacerta_dialog_create_tag.xml
+++ b/component/common/src/main/res/layout/lacerta_dialog_create_tag.xml
@@ -4,12 +4,33 @@
android:layout_height="match_parent"
android:orientation="vertical">
-
+ android:layout_height="wrap_content"
+ android:paddingTop="8dp"
+ android:paddingHorizontal="16dp"
+ style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox">
+
+
+
+
+
+
\ No newline at end of file
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 88ef000f..816bf706 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
@@ -9,6 +9,7 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
+import java.util.Objects;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
@@ -244,6 +245,9 @@ public class LacertaLibraryImpl implements LacertaLibrary {
public CompletableFuture createTag(DocumentTag tag) {
return CompletableFuture.supplyAsync(() -> {
TagEntity tagEntity = convertDocumentTagToTagEntity(tag);
+ if (Objects.isNull(tagEntity.id) || tagEntity.id.isEmpty()) {
+ tagEntity.id = UUID.randomUUID().toString();
+ }
database.tagDao().insert(tagEntity);
logger.debug("LacertaLibraryImpl", "Database Query: Inserted TagEntity (" + tag.getId() + ")");
return null;
diff --git a/feature/setting/build.gradle b/feature/setting/build.gradle
index db8a19e6..235283ff 100644
--- a/feature/setting/build.gradle
+++ b/feature/setting/build.gradle
@@ -46,6 +46,8 @@ dependencies {
// shared
implementation project(':shared:ui')
+ implementation project(':component:common')
+
implementation project(':data')
implementation project(':model')
diff --git a/feature/setting/src/main/java/one/nem/lacerta/setting/SettingTagManageFragment.java b/feature/setting/src/main/java/one/nem/lacerta/setting/SettingTagManageFragment.java
index 46f96a7a..05a3267a 100644
--- a/feature/setting/src/main/java/one/nem/lacerta/setting/SettingTagManageFragment.java
+++ b/feature/setting/src/main/java/one/nem/lacerta/setting/SettingTagManageFragment.java
@@ -16,7 +16,10 @@ import android.widget.Toast;
import javax.inject.Inject;
import dagger.hilt.android.AndroidEntryPoint;
+import one.nem.lacerta.component.common.LacertaCreateTagDialog;
+import one.nem.lacerta.component.common.LacertaCreateTagDialogListener;
import one.nem.lacerta.data.LacertaLibrary;
+import one.nem.lacerta.model.document.tag.DocumentTag;
/**
* A simple {@link Fragment} subclass.
@@ -29,6 +32,10 @@ public class SettingTagManageFragment extends Fragment {
@Inject
LacertaLibrary lacertaLibrary;
+ private RecyclerView recyclerView;
+
+ private TagListItemAdapter adapter;
+
public SettingTagManageFragment() {
// Required empty public constructor
}
@@ -62,19 +69,29 @@ public class SettingTagManageFragment extends Fragment {
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
- RecyclerView recyclerView = view.findViewById(R.id.tag_item_recycler_view);
- TagListItemAdapter adapter = new TagListItemAdapter((tagId, tagName, tagColor) -> {
+ this.recyclerView = view.findViewById(R.id.tag_item_recycler_view);
+ this.adapter = new TagListItemAdapter((tagId, tagName, tagColor) -> {
Toast.makeText(getContext(), "Tag Clicked", Toast.LENGTH_SHORT).show();
});
recyclerView.setAdapter(adapter);
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
- lacertaLibrary.getTagList().thenAccept(documentTags -> {
- adapter.setDocumentTags(documentTags);
- adapter.notifyDataSetChanged();
- });
+ updateTagList();
+ }
+ /**
+ * タグリストを更新する
+ */
+ private void updateTagList() {
+ lacertaLibrary.getTagList().thenAccept(documentTags -> {
+ int currentTagCount = this.adapter.getItemCount();
+ this.adapter.setDocumentTags(documentTags);
+ if (currentTagCount != this.adapter.getItemCount()) {
+ this.adapter.notifyItemRangeRemoved(0, currentTagCount);
+ this.adapter.notifyItemRangeInserted(0, this.adapter.getItemCount());
+ }
+ });
}
/**
@@ -102,6 +119,25 @@ public class SettingTagManageFragment extends Fragment {
toolbar.setOnMenuItemClickListener(item -> {
if (item.getItemId() == R.id.setting_tag_manage_menu_add) {
Toast.makeText(getContext(), "Add Clicked", Toast.LENGTH_SHORT).show();
+ LacertaCreateTagDialog dialog = new LacertaCreateTagDialog();
+ dialog.setListener(new LacertaCreateTagDialogListener() {
+ @Override
+ public void onPositiveClick(String tagName, String tagColor) {
+ Toast.makeText(getContext(), "Positive Clicked", Toast.LENGTH_SHORT).show();
+ DocumentTag newTag = new DocumentTag();
+ newTag.setName(tagName);
+ newTag.setColor(tagColor);
+ lacertaLibrary.createTag(newTag).join();
+ updateTagList();
+ }
+
+ @Override
+ public void onNegativeClick() {
+ Toast.makeText(getContext(), "Negative Clicked", Toast.LENGTH_SHORT).show();
+ updateTagList();
+ }
+ });
+ dialog.show(getParentFragmentManager(), "create_tag_dialog");
return true;
} else {
return false;