From 58e74dbb1628bc3ed5c2694ac7e81439b072d2a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=8D=E3=82=80=E3=81=AD=E3=81=93?= Date: Fri, 26 Jan 2024 18:38:02 +0900 Subject: [PATCH] =?UTF-8?q?=E8=A1=A8=E7=A4=BA=E3=82=A2=E3=83=8B=E3=83=A1?= =?UTF-8?q?=E3=83=BC=E3=82=B7=E3=83=A7=E3=83=B3=E3=82=92500ms=E4=BB=A5?= =?UTF-8?q?=E4=B8=8A=E3=81=8B=E3=81=8B=E3=81=A3=E3=81=9F=E5=A0=B4=E5=90=88?= =?UTF-8?q?=E3=81=AE=E3=81=BF=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../feature/library/LibraryPageFragment.java | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/feature/library/src/main/java/one/nem/lacerta/feature/library/LibraryPageFragment.java b/feature/library/src/main/java/one/nem/lacerta/feature/library/LibraryPageFragment.java index 5e0e5b2f..2214882c 100644 --- a/feature/library/src/main/java/one/nem/lacerta/feature/library/LibraryPageFragment.java +++ b/feature/library/src/main/java/one/nem/lacerta/feature/library/LibraryPageFragment.java @@ -214,16 +214,22 @@ public class LibraryPageFragment extends Fragment { * RecyclerViewのアイテムとUIを更新する */ private void updateItem(String pageId) { + long startTime = System.currentTimeMillis(); lacertaLibrary.getLibraryPage(pageId, 10).thenAccept(libraryItemPage -> { + long endTime = System.currentTimeMillis(); this.libraryItemPage = libraryItemPage; logger.debug("LibraryTopFragment", "Item selected! libraryItemPage.getListItems().size(): " + libraryItemPage.getListItems().size()); - getActivity().runOnUiThread(() -> { - listItemAdapter.notifyItemRangeRemoved(0, libraryItemPage.getListItems().size() - 1); - }); - listItemAdapter.setLibraryItemPage(libraryItemPage); - getActivity().runOnUiThread(() -> { - listItemAdapter.notifyItemRangeInserted(0, libraryItemPage.getListItems().size() - 1); - }); + if (endTime - startTime > 500) { // 500ms以上かかった場合は表示アニメーションをする + getActivity().runOnUiThread(() -> { + listItemAdapter.setLibraryItemPage(libraryItemPage); + listItemAdapter.notifyItemRangeInserted(0, this.libraryItemPage.getListItems().size()); + }); + } else { + listItemAdapter.setLibraryItemPage(libraryItemPage); + getActivity().runOnUiThread(() -> { + listItemAdapter.notifyDataSetChanged(); + }); + } }); }