From dfe604977551417fea0c28705e7c580b010df334 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=8D=E3=82=80=E3=81=AD=E3=81=93?= Date: Thu, 25 Jan 2024 13:46:51 +0900 Subject: [PATCH] =?UTF-8?q?=E3=83=80=E3=82=A4=E3=82=A2=E3=83=AD=E3=82=B0?= =?UTF-8?q?=E5=86=85=E3=81=A7=E3=83=91=E3=82=B9=E3=82=92=E7=A7=BB=E5=8B=95?= =?UTF-8?q?=E3=81=A7=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 --- .../common/LacertaSelectDirDialog.java | 23 ++++++++++++------- .../common/SelectDirDialogItemAdapter.java | 15 ++++++------ 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/component/common/src/main/java/one/nem/lacerta/component/common/LacertaSelectDirDialog.java b/component/common/src/main/java/one/nem/lacerta/component/common/LacertaSelectDirDialog.java index e3262051..d89ba473 100644 --- a/component/common/src/main/java/one/nem/lacerta/component/common/LacertaSelectDirDialog.java +++ b/component/common/src/main/java/one/nem/lacerta/component/common/LacertaSelectDirDialog.java @@ -8,6 +8,7 @@ import android.widget.Toast; import androidx.appcompat.widget.Toolbar; import androidx.fragment.app.DialogFragment; +import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; import com.google.android.material.dialog.MaterialAlertDialogBuilder; @@ -25,25 +26,28 @@ public class LacertaSelectDirDialog extends DialogFragment { private SelectDirDialogItemAdapter adapter; + private RecyclerView recyclerView; + @Override public Dialog onCreateDialog(Bundle savedInstanceState) { + + super.onCreateDialog(savedInstanceState); + MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(getActivity()); LayoutInflater inflater = requireActivity().getLayoutInflater(); View view = inflater.inflate(R.layout.lacerta_dialog_select_dir, null); - RecyclerView recyclerView = view.findViewById(R.id.select_dir_recycler_view); + this.recyclerView = view.findViewById(R.id.select_dir_recycler_view); this.adapter = new SelectDirDialogItemAdapter((name, itemId) -> { Toast.makeText(getContext(), "Called:" + name, Toast.LENGTH_SHORT).show(); showRecyclerViewItem(itemId); - dismiss(); }); - recyclerView.setAdapter(this.adapter); - recyclerView.setLayoutManager(new androidx.recyclerview.widget.LinearLayoutManager(getContext())); + this.recyclerView.setAdapter(this.adapter); builder.setView(view); - showRecyclerViewItem(null); // get root folder list + showRecyclerViewItem(null); // get root folder builder.setTitle("Select Directory"); builder.setMessage("Please select a directory."); @@ -54,9 +58,12 @@ public class LacertaSelectDirDialog extends DialogFragment { private void showRecyclerViewItem(String parent) { lacertaLibrary.getFolderList(parent).thenAccept(listItems -> { - adapter.setListItems(listItems); - adapter.notifyDataSetChanged(); + getActivity().runOnUiThread(() -> { + int currentCount = adapter.getItemCount(); + adapter.notifyItemRangeRemoved(0, currentCount); + adapter.setListItems(listItems); + adapter.notifyItemRangeInserted(0, listItems.size()); + }); }); - } } diff --git a/component/common/src/main/java/one/nem/lacerta/component/common/SelectDirDialogItemAdapter.java b/component/common/src/main/java/one/nem/lacerta/component/common/SelectDirDialogItemAdapter.java index 79a95acb..b9bfddaa 100644 --- a/component/common/src/main/java/one/nem/lacerta/component/common/SelectDirDialogItemAdapter.java +++ b/component/common/src/main/java/one/nem/lacerta/component/common/SelectDirDialogItemAdapter.java @@ -12,7 +12,7 @@ import java.util.ArrayList; import one.nem.lacerta.model.ListItem; -public class SelectDirDialogItemAdapter extends RecyclerView.Adapter { +public class SelectDirDialogItemAdapter extends RecyclerView.Adapter { ArrayList listItems; LacertaSelectDirDialogEventListener listener; @@ -25,14 +25,15 @@ public class SelectDirDialogItemAdapter extends RecyclerView.Adapter