From ce4656558a3ea4a0af83c81d7a4b9c5ffdf79daf Mon Sep 17 00:00:00 2001 From: r-ca Date: Tue, 23 Jan 2024 03:38:58 +0900 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E5=87=BA=E7=94=A8:=20=E4=BB=A3?= =?UTF-8?q?=E6=9B=BF=E5=87=A6=E7=90=86=E5=AE=9F=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../nem/lacerta/data/impl/LacertaLibraryImpl.java | 5 ++++- .../nem/lacerta/feature/home/HomeTopFragment.java | 11 +++++++++-- .../nem/lacerta/feature/home/ListItemAdapter.java | 6 +++++- .../feature/library/LibraryPageFragment.java | 15 +++++++++++---- .../java/one/nem/lacerta/utils/FeatureSwitch.java | 4 ++++ 5 files changed, 33 insertions(+), 8 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 1e2c56f7..5067f701 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 @@ -1,6 +1,7 @@ package one.nem.lacerta.data.impl; import java.text.DateFormat; +import java.text.SimpleDateFormat; import java.time.format.DateTimeFormatter; import java.util.ArrayList; import java.util.Collection; @@ -99,12 +100,14 @@ public class LacertaLibraryImpl implements LacertaLibrary { listItems.add(listItem); } + SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:"); + for (DocumentEntity documentEntity : documentEntities) { logger.debug("LacertaLibraryImpl", "documentEntity.title: " + documentEntity.title); ListItem listItem = new ListItem(); listItem.setItemType(ListItemType.ITEM_TYPE_DOCUMENT); listItem.setTitle(documentEntity.title); -// listItem.setDescription(DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm").format(documentEntity.updatedAt.toInstant())); + listItem.setDescription(simpleDateFormat.format(documentEntity.updatedAt)); listItem.setItemId(documentEntity.id); listItems.add(listItem); } diff --git a/feature/home/src/main/java/one/nem/lacerta/feature/home/HomeTopFragment.java b/feature/home/src/main/java/one/nem/lacerta/feature/home/HomeTopFragment.java index 8d3dcc84..1bd83d56 100644 --- a/feature/home/src/main/java/one/nem/lacerta/feature/home/HomeTopFragment.java +++ b/feature/home/src/main/java/one/nem/lacerta/feature/home/HomeTopFragment.java @@ -36,7 +36,8 @@ import one.nem.lacerta.data.Document; import one.nem.lacerta.data.LacertaLibrary; import one.nem.lacerta.model.ListItem; import one.nem.lacerta.model.document.DocumentMeta; - +import one.nem.lacerta.utils.FeatureSwitch; +import one.nem.lacerta.utils.Store; /** @@ -99,7 +100,13 @@ public class HomeTopFragment extends Fragment { } listItemAdapter.setListItems(listItems); getActivity().runOnUiThread(() -> { - listItemAdapter.notifyItemRangeInserted(0, listItems.size() - 1); + Log.d("HomeTopFragment", "onViewCreated: " + listItems.size()); + if (FeatureSwitch.RecyclerView.useSimpleNotifyMethod) { + listItemAdapter.notifyDataSetChanged(); + } else { + // IndexOutOfBoundsExceptionを吐くことがあったので + listItemAdapter.notifyItemRangeInserted(0, listItems.size() - 1); + } }); }); } diff --git a/feature/home/src/main/java/one/nem/lacerta/feature/home/ListItemAdapter.java b/feature/home/src/main/java/one/nem/lacerta/feature/home/ListItemAdapter.java index 604ecf4b..73624b32 100644 --- a/feature/home/src/main/java/one/nem/lacerta/feature/home/ListItemAdapter.java +++ b/feature/home/src/main/java/one/nem/lacerta/feature/home/ListItemAdapter.java @@ -54,7 +54,11 @@ public class ListItemAdapter extends RecyclerView.Adapter { // TODO-rca: 実行条件を考える? - listItemAdapter.notifyItemRangeRemoved(0, this.libraryItemPage.getListItems().size() - 1); - }); + if (!FeatureSwitch.RecyclerView.useSimpleNotifyMethod) { + getActivity().runOnUiThread(() -> { // TODO-rca: 実行条件を考える? + listItemAdapter.notifyItemRangeRemoved(0, this.libraryItemPage.getListItems().size() - 1); + }); + } listItemAdapter.setLibraryItemPage(this.libraryItemPage); getActivity().runOnUiThread(() -> { - listItemAdapter.notifyItemRangeInserted(0, this.libraryItemPage.getListItems().size() - 1); + if (FeatureSwitch.RecyclerView.useSimpleNotifyMethod) { + listItemAdapter.notifyDataSetChanged(); + } else { + listItemAdapter.notifyItemRangeInserted(0, this.libraryItemPage.getListItems().size() - 1); + } }); }); } diff --git a/utils/src/main/java/one/nem/lacerta/utils/FeatureSwitch.java b/utils/src/main/java/one/nem/lacerta/utils/FeatureSwitch.java index 91aab3eb..11cebefc 100644 --- a/utils/src/main/java/one/nem/lacerta/utils/FeatureSwitch.java +++ b/utils/src/main/java/one/nem/lacerta/utils/FeatureSwitch.java @@ -6,6 +6,10 @@ public class FeatureSwitch { public static boolean canOverrideSwitch = false; } + public static class RecyclerView { + public static boolean useSimpleNotifyMethod = true; + } + public static class FeatureMaster { public static boolean enableSearch = false; public static boolean enableDebugMenu = true;