From b05ee22c295238b39f8c05687d6b746d8fb4f0dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=8D=E3=82=80=E3=81=AD=E3=81=93?= Date: Mon, 22 Jan 2024 11:34:03 +0900 Subject: [PATCH 1/8] =?UTF-8?q?createFolder=E9=96=A2=E6=95=B0=E5=AE=9F?= =?UTF-8?q?=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../one/nem/lacerta/data/LacertaLibrary.java | 3 +++ .../lacerta/data/impl/LacertaLibraryImpl.java | 24 +++++++++++++++++++ 2 files changed, 27 insertions(+) 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 cb19b425..6d424179 100644 --- a/data/src/main/java/one/nem/lacerta/data/LacertaLibrary.java +++ b/data/src/main/java/one/nem/lacerta/data/LacertaLibrary.java @@ -21,4 +21,7 @@ public interface LacertaLibrary { CompletableFuture getLibraryPage(String pageId, int limit); CompletableFuture getLibraryPage(String pageId, int limit, int offset); + // Create Folder + CompletableFuture createFolder(String path, String name); + } 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 7fcf9cb5..7d7f7aaa 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 @@ -5,6 +5,7 @@ import java.time.format.DateTimeFormatter; import java.util.ArrayList; import java.util.Collection; import java.util.List; +import java.util.UUID; import java.util.concurrent.CompletableFuture; import javax.inject.Inject; @@ -13,6 +14,7 @@ import one.nem.lacerta.data.LacertaLibrary; import one.nem.lacerta.model.LibraryItemPage; import one.nem.lacerta.model.ListItem; import one.nem.lacerta.model.ListItemType; +import one.nem.lacerta.model.PublicPath; import one.nem.lacerta.model.document.DocumentDetail; import one.nem.lacerta.source.database.LacertaDatabase; import one.nem.lacerta.source.database.common.DateTypeConverter; @@ -143,4 +145,26 @@ public class LacertaLibraryImpl implements LacertaLibrary { return null; }); } + + @Override + public CompletableFuture createFolder(String parentId, String name) { + return CompletableFuture.supplyAsync(() -> { + + FolderEntity parentFolderEntity = database.folderDao().findById(parentId); + PublicPath publicPath; + if (parentFolderEntity == null) { + publicPath = new PublicPath().resolve("/"); + } else { + publicPath = new PublicPath().resolve(parentFolderEntity.publicPath); + } + publicPath = publicPath.resolve(name); + + FolderEntity folderEntity = new FolderEntity(); + folderEntity.id = UUID.randomUUID().toString(); + folderEntity.name = name; + folderEntity.publicPath = publicPath.toString(); + database.folderDao().insert(folderEntity); + return folderEntity.id; + }); + } } From c4e10b9487ac604897c3a1a719e902df115e7af3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=8D=E3=82=80=E3=81=AD=E3=81=93?= Date: Mon, 22 Jan 2024 11:49:45 +0900 Subject: [PATCH 2/8] =?UTF-8?q?=E7=B5=B6=E5=AF=BE=E3=83=91=E3=82=B9?= =?UTF-8?q?=E3=82=92=E6=AD=A3=E5=B8=B8=E3=81=AB=E8=A7=A3=E6=B1=BA=E3=81=A7?= =?UTF-8?q?=E3=81=8D=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/one/nem/lacerta/model/PublicPath.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/model/src/main/java/one/nem/lacerta/model/PublicPath.java b/model/src/main/java/one/nem/lacerta/model/PublicPath.java index 47f68ca7..a5253f1d 100644 --- a/model/src/main/java/one/nem/lacerta/model/PublicPath.java +++ b/model/src/main/java/one/nem/lacerta/model/PublicPath.java @@ -27,10 +27,16 @@ public class PublicPath { } private void resolveInternal(String path) { - if (path.equals("..")) { - this.path.remove(this.path.size() - 1); + if (path.startsWith("/")) { + this.path.clear(); } else { - add(path); + if (path.equals("..")) { + this.path.remove(this.path.size() - 1); + } else if (path.equals(".")) { + // do nothing + } else { + this.path.add(path); + } } } From caf3a0dd3419687cda83dfb5549aee647b3b60db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=8D=E3=82=80=E3=81=AD=E3=81=93?= Date: Mon, 22 Jan 2024 11:50:29 +0900 Subject: [PATCH 3/8] =?UTF-8?q?=E7=B5=B6=E5=AF=BE=E3=83=91=E3=82=B9?= =?UTF-8?q?=E3=82=92=E6=AD=A3=E5=B8=B8=E3=81=AB=E8=A7=A3=E6=B1=BA=E3=81=A7?= =?UTF-8?q?=E3=81=8D=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- model/src/main/java/one/nem/lacerta/model/PublicPath.java | 1 + 1 file changed, 1 insertion(+) diff --git a/model/src/main/java/one/nem/lacerta/model/PublicPath.java b/model/src/main/java/one/nem/lacerta/model/PublicPath.java index a5253f1d..0c8c67d2 100644 --- a/model/src/main/java/one/nem/lacerta/model/PublicPath.java +++ b/model/src/main/java/one/nem/lacerta/model/PublicPath.java @@ -29,6 +29,7 @@ public class PublicPath { private void resolveInternal(String path) { if (path.startsWith("/")) { this.path.clear(); + this.path.add("/"); } else { if (path.equals("..")) { this.path.remove(this.path.size() - 1); From b2c608593338dd94e5d7f537831fb04828ff0f6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=8D=E3=82=80=E3=81=AD=E3=81=93?= Date: Mon, 22 Jan 2024 11:54:39 +0900 Subject: [PATCH 4/8] =?UTF-8?q?=E3=83=91=E3=83=BC=E3=82=B9=E3=83=A1?= =?UTF-8?q?=E3=82=BD=E3=83=83=E3=83=89=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- model/src/main/java/one/nem/lacerta/model/PublicPath.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/model/src/main/java/one/nem/lacerta/model/PublicPath.java b/model/src/main/java/one/nem/lacerta/model/PublicPath.java index 0c8c67d2..de000fbc 100644 --- a/model/src/main/java/one/nem/lacerta/model/PublicPath.java +++ b/model/src/main/java/one/nem/lacerta/model/PublicPath.java @@ -41,6 +41,14 @@ public class PublicPath { } } + public PublicPath parse(String path) { + String[] pathArray = path.split("/"); + for (String p : pathArray) { + resolveInternal(p); + } + return this; + } + public PublicPath resolve(String path) { resolveInternal(path); return this; From 81fa259985ec2082abb73105449fe0bf935a3efa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=8D=E3=82=80=E3=81=AD=E3=81=93?= Date: Mon, 22 Jan 2024 11:55:38 +0900 Subject: [PATCH 5/8] =?UTF-8?q?=E3=83=95=E3=82=A9=E3=83=AB=E3=83=80?= =?UTF-8?q?=E3=82=92=E4=BD=9C=E6=88=90=E3=81=A7=E3=81=8D=E3=82=8B=E3=82=88?= =?UTF-8?q?=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lacerta/data/impl/LacertaLibraryImpl.java | 3 +- .../feature/library/LibraryTopFragment.java | 39 ++++++++++++++++++- 2 files changed, 38 insertions(+), 4 deletions(-) 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 7d7f7aaa..f2e87da9 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 @@ -157,12 +157,11 @@ public class LacertaLibraryImpl implements LacertaLibrary { } else { publicPath = new PublicPath().resolve(parentFolderEntity.publicPath); } - publicPath = publicPath.resolve(name); FolderEntity folderEntity = new FolderEntity(); folderEntity.id = UUID.randomUUID().toString(); folderEntity.name = name; - folderEntity.publicPath = publicPath.toString(); + folderEntity.publicPath = publicPath.getStringPath(); database.folderDao().insert(folderEntity); return folderEntity.id; }); diff --git a/feature/library/src/main/java/one/nem/lacerta/feature/library/LibraryTopFragment.java b/feature/library/src/main/java/one/nem/lacerta/feature/library/LibraryTopFragment.java index 8dd366d8..7d35c9cb 100644 --- a/feature/library/src/main/java/one/nem/lacerta/feature/library/LibraryTopFragment.java +++ b/feature/library/src/main/java/one/nem/lacerta/feature/library/LibraryTopFragment.java @@ -13,6 +13,7 @@ import androidx.recyclerview.widget.RecyclerView; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuInflater; +import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.widget.ArrayAdapter; @@ -51,6 +52,10 @@ public class LibraryTopFragment extends Fragment { @Inject LacertaLogger logger; + ListItemAdapter listItemAdapter; + + int currentTotalItemCount = 0; + public LibraryTopFragment() { // Required empty public constructor } @@ -83,7 +88,7 @@ public class LibraryTopFragment extends Fragment { RecyclerView recyclerView = view.findViewById(R.id.library_item_recycler_view); - ListItemAdapter listItemAdapter = new ListItemAdapter(documentId -> { + this.listItemAdapter = new ListItemAdapter(documentId -> { Toast.makeText(getContext(), documentId, Toast.LENGTH_SHORT).show(); }); recyclerView.setAdapter(listItemAdapter); @@ -92,8 +97,9 @@ public class LibraryTopFragment extends Fragment { lacertaLibrary.getLibraryPage(10).thenAccept(libraryItemPage -> { logger.debug("LibraryTopFragment", "Item selected! libraryItemPage.getListItems().size(): " + libraryItemPage.getListItems().size()); listItemAdapter.setLibraryItemPage(libraryItemPage); + this.currentTotalItemCount = libraryItemPage.getListItems().size(); getActivity().runOnUiThread(() -> { - listItemAdapter.notifyItemRangeInserted(0, libraryItemPage.getListItems().size() - 1); + listItemAdapter.notifyItemRangeInserted(0, this.currentTotalItemCount - 1); }); }); } @@ -103,4 +109,33 @@ public class LibraryTopFragment extends Fragment { inflater.inflate(R.menu.dir_menu, menu); super.onCreateOptionsMenu(menu, inflater); } + + // Selected + @Override + public boolean onOptionsItemSelected(@NonNull MenuItem item) { + if (item.getItemId() == R.id.menu_item_create_new_folder) { + lacertaLibrary.createFolder(null, "New Folder").thenAccept(folderId -> { + logger.debug("LibraryTopFragment", "folderId: " + folderId); + }); + // Refresh + updateItem(); + return true; + } else { + return super.onOptionsItemSelected(item); + } + } + + private void updateItem() { + lacertaLibrary.getLibraryPage(10).thenAccept(libraryItemPage -> { + logger.debug("LibraryTopFragment", "Item selected! libraryItemPage.getListItems().size(): " + libraryItemPage.getListItems().size()); + getActivity().runOnUiThread(() -> { + listItemAdapter.notifyItemRangeRemoved(0, this.currentTotalItemCount - 1); + }); + listItemAdapter.setLibraryItemPage(libraryItemPage); + getActivity().runOnUiThread(() -> { + listItemAdapter.notifyItemRangeInserted(0, libraryItemPage.getListItems().size() - 1); + }); + this.currentTotalItemCount = libraryItemPage.getListItems().size(); + }); + } } From 281238a38e2362d6ecfcd9971d4bf1c61aac41ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=8D=E3=82=80=E3=81=AD=E3=81=93?= Date: Mon, 22 Jan 2024 12:07:07 +0900 Subject: [PATCH 6/8] =?UTF-8?q?=E4=BD=9C=E6=88=90=E3=81=99=E3=82=8B?= =?UTF-8?q?=E3=83=95=E3=82=A9=E3=83=AB=E3=83=80=E3=81=AE=E5=90=8D=E5=89=8D?= =?UTF-8?q?=E3=82=92=E6=8C=87=E5=AE=9A=E3=81=A7=E3=81=8D=E3=82=8B=E3=82=88?= =?UTF-8?q?=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../feature/library/LibraryTopFragment.java | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/feature/library/src/main/java/one/nem/lacerta/feature/library/LibraryTopFragment.java b/feature/library/src/main/java/one/nem/lacerta/feature/library/LibraryTopFragment.java index 7d35c9cb..172246f4 100644 --- a/feature/library/src/main/java/one/nem/lacerta/feature/library/LibraryTopFragment.java +++ b/feature/library/src/main/java/one/nem/lacerta/feature/library/LibraryTopFragment.java @@ -1,5 +1,6 @@ package one.nem.lacerta.feature.library; +import android.app.AlertDialog; import android.os.Bundle; import androidx.annotation.NonNull; @@ -24,6 +25,8 @@ import android.widget.Toast; import com.google.android.material.appbar.AppBarLayout; import com.google.android.material.appbar.CollapsingToolbarLayout; +import org.w3c.dom.Text; + import java.util.ArrayList; import java.util.List; @@ -35,7 +38,7 @@ import one.nem.lacerta.data.LacertaLibrary; import one.nem.lacerta.model.document.DocumentMeta; import one.nem.lacerta.model.document.tag.DocumentTag; import one.nem.lacerta.utils.LacertaLogger; - +import one.nem.lacerta.utils.TextInputDialog; /** @@ -114,11 +117,23 @@ public class LibraryTopFragment extends Fragment { @Override public boolean onOptionsItemSelected(@NonNull MenuItem item) { if (item.getItemId() == R.id.menu_item_create_new_folder) { - lacertaLibrary.createFolder(null, "New Folder").thenAccept(folderId -> { - logger.debug("LibraryTopFragment", "folderId: " + folderId); + AlertDialog.Builder builder = new AlertDialog.Builder(getContext()); + builder.setTitle("フォルダの作成"); + builder.setMessage("フォルダ名を入力してください"); + final android.widget.EditText input = new android.widget.EditText(getContext()); + input.setText("フォルダ名"); + builder.setView(input); + builder.setPositiveButton("作成", (dialog, which) -> { + lacertaLibrary.createFolder(null, input.getText().toString()).thenAccept(folderId -> { + logger.debug("LibraryTopFragment", "folderId: " + folderId); + }); + // Refresh + updateItem(); }); - // Refresh - updateItem(); + builder.setNegativeButton("キャンセル", (dialog, which) -> { + dialog.cancel(); + }); + builder.show(); return true; } else { return super.onOptionsItemSelected(item); From 301fab802417ea81bff966efa1eb143f848af9c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=8D=E3=82=80=E3=81=AD=E3=81=93?= Date: Mon, 22 Jan 2024 12:07:46 +0900 Subject: [PATCH 7/8] =?UTF-8?q?InputDialog=E3=81=AEWrapper=E4=BD=9C?= =?UTF-8?q?=E6=88=90=20WIP?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../nem/lacerta/utils/TextInputDialog.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 utils/src/main/java/one/nem/lacerta/utils/TextInputDialog.java diff --git a/utils/src/main/java/one/nem/lacerta/utils/TextInputDialog.java b/utils/src/main/java/one/nem/lacerta/utils/TextInputDialog.java new file mode 100644 index 00000000..6f845589 --- /dev/null +++ b/utils/src/main/java/one/nem/lacerta/utils/TextInputDialog.java @@ -0,0 +1,28 @@ +package one.nem.lacerta.utils; + +import android.app.AlertDialog; +import android.content.Context; +import android.content.DialogInterface; + +import java.util.concurrent.CompletableFuture; + +public class TextInputDialog { + public static CompletableFuture show(Context context, String title, String message, String defaultValue, String positiveButton, String negativeButton) { + return CompletableFuture.supplyAsync(() -> { + AlertDialog.Builder builder = new AlertDialog.Builder(context); + builder.setTitle(title); + builder.setMessage(message); + final android.widget.EditText input = new android.widget.EditText(context); + input.setText(defaultValue); + builder.setView(input); + builder.setPositiveButton(positiveButton, (dialog, which) -> { + dialog.dismiss(); + }); + builder.setNegativeButton(negativeButton, (dialog, which) -> { + dialog.cancel(); + }); + builder.show(); + return input.getText().toString(); + }); + } +} From 580e79b03afb224966a2941f47f08dec70f40d81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=8D=E3=82=80=E3=81=AD=E3=81=93?= Date: Mon, 22 Jan 2024 12:07:52 +0900 Subject: [PATCH 8/8] =?UTF-8?q?Revert=20"InputDialog=E3=81=AEWrapper?= =?UTF-8?q?=E4=BD=9C=E6=88=90=20WIP"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 301fab802417ea81bff966efa1eb143f848af9c7. --- .../nem/lacerta/utils/TextInputDialog.java | 28 ------------------- 1 file changed, 28 deletions(-) delete mode 100644 utils/src/main/java/one/nem/lacerta/utils/TextInputDialog.java diff --git a/utils/src/main/java/one/nem/lacerta/utils/TextInputDialog.java b/utils/src/main/java/one/nem/lacerta/utils/TextInputDialog.java deleted file mode 100644 index 6f845589..00000000 --- a/utils/src/main/java/one/nem/lacerta/utils/TextInputDialog.java +++ /dev/null @@ -1,28 +0,0 @@ -package one.nem.lacerta.utils; - -import android.app.AlertDialog; -import android.content.Context; -import android.content.DialogInterface; - -import java.util.concurrent.CompletableFuture; - -public class TextInputDialog { - public static CompletableFuture show(Context context, String title, String message, String defaultValue, String positiveButton, String negativeButton) { - return CompletableFuture.supplyAsync(() -> { - AlertDialog.Builder builder = new AlertDialog.Builder(context); - builder.setTitle(title); - builder.setMessage(message); - final android.widget.EditText input = new android.widget.EditText(context); - input.setText(defaultValue); - builder.setView(input); - builder.setPositiveButton(positiveButton, (dialog, which) -> { - dialog.dismiss(); - }); - builder.setNegativeButton(negativeButton, (dialog, which) -> { - dialog.cancel(); - }); - builder.show(); - return input.getText().toString(); - }); - } -}