提出用: 代替処理実装

This commit is contained in:
r-ca 2024-01-23 03:38:58 +09:00
parent 32b238df58
commit ce4656558a
No known key found for this signature in database
GPG Key ID: 6A72911AC73464A9
5 changed files with 33 additions and 8 deletions

View File

@ -1,6 +1,7 @@
package one.nem.lacerta.data.impl; package one.nem.lacerta.data.impl;
import java.text.DateFormat; import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
@ -99,12 +100,14 @@ public class LacertaLibraryImpl implements LacertaLibrary {
listItems.add(listItem); listItems.add(listItem);
} }
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:");
for (DocumentEntity documentEntity : documentEntities) { for (DocumentEntity documentEntity : documentEntities) {
logger.debug("LacertaLibraryImpl", "documentEntity.title: " + documentEntity.title); logger.debug("LacertaLibraryImpl", "documentEntity.title: " + documentEntity.title);
ListItem listItem = new ListItem(); ListItem listItem = new ListItem();
listItem.setItemType(ListItemType.ITEM_TYPE_DOCUMENT); listItem.setItemType(ListItemType.ITEM_TYPE_DOCUMENT);
listItem.setTitle(documentEntity.title); 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); listItem.setItemId(documentEntity.id);
listItems.add(listItem); listItems.add(listItem);
} }

View File

@ -36,7 +36,8 @@ import one.nem.lacerta.data.Document;
import one.nem.lacerta.data.LacertaLibrary; import one.nem.lacerta.data.LacertaLibrary;
import one.nem.lacerta.model.ListItem; import one.nem.lacerta.model.ListItem;
import one.nem.lacerta.model.document.DocumentMeta; 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); listItemAdapter.setListItems(listItems);
getActivity().runOnUiThread(() -> { getActivity().runOnUiThread(() -> {
Log.d("HomeTopFragment", "onViewCreated: " + listItems.size());
if (FeatureSwitch.RecyclerView.useSimpleNotifyMethod) {
listItemAdapter.notifyDataSetChanged();
} else {
// IndexOutOfBoundsExceptionを吐くことがあったので
listItemAdapter.notifyItemRangeInserted(0, listItems.size() - 1); listItemAdapter.notifyItemRangeInserted(0, listItems.size() - 1);
}
}); });
}); });
} }

View File

@ -54,7 +54,11 @@ public class ListItemAdapter extends RecyclerView.Adapter<ListItemAdapter.ListIt
@Override @Override
public int getItemCount() { public int getItemCount() {
return listItems == null ? 0 : listItems.size(); if (listItems == null) {
return 0;
} else {
return listItems.size();
}
} }
public static class ListItemViewHolder extends RecyclerView.ViewHolder{ public static class ListItemViewHolder extends RecyclerView.ViewHolder{

View File

@ -40,6 +40,7 @@ import one.nem.lacerta.data.LacertaLibrary;
import one.nem.lacerta.model.FragmentNavigation; import one.nem.lacerta.model.FragmentNavigation;
import one.nem.lacerta.model.LibraryItemPage; import one.nem.lacerta.model.LibraryItemPage;
import one.nem.lacerta.model.PublicPath; import one.nem.lacerta.model.PublicPath;
import one.nem.lacerta.utils.FeatureSwitch;
import one.nem.lacerta.utils.LacertaLogger; import one.nem.lacerta.utils.LacertaLogger;
@ -199,12 +200,18 @@ public class LibraryPageFragment extends Fragment {
} }
logger.debug("LibraryTopFragment", "Item selected! Total item page: " + this.libraryItemPage.getListItems().size()); logger.debug("LibraryTopFragment", "Item selected! Total item page: " + this.libraryItemPage.getListItems().size());
if (!FeatureSwitch.RecyclerView.useSimpleNotifyMethod) {
getActivity().runOnUiThread(() -> { // TODO-rca: 実行条件を考える getActivity().runOnUiThread(() -> { // TODO-rca: 実行条件を考える
listItemAdapter.notifyItemRangeRemoved(0, this.libraryItemPage.getListItems().size() - 1); listItemAdapter.notifyItemRangeRemoved(0, this.libraryItemPage.getListItems().size() - 1);
}); });
}
listItemAdapter.setLibraryItemPage(this.libraryItemPage); listItemAdapter.setLibraryItemPage(this.libraryItemPage);
getActivity().runOnUiThread(() -> { getActivity().runOnUiThread(() -> {
if (FeatureSwitch.RecyclerView.useSimpleNotifyMethod) {
listItemAdapter.notifyDataSetChanged();
} else {
listItemAdapter.notifyItemRangeInserted(0, this.libraryItemPage.getListItems().size() - 1); listItemAdapter.notifyItemRangeInserted(0, this.libraryItemPage.getListItems().size() - 1);
}
}); });
}); });
} }

View File

@ -6,6 +6,10 @@ public class FeatureSwitch {
public static boolean canOverrideSwitch = false; public static boolean canOverrideSwitch = false;
} }
public static class RecyclerView {
public static boolean useSimpleNotifyMethod = true;
}
public static class FeatureMaster { public static class FeatureMaster {
public static boolean enableSearch = false; public static boolean enableSearch = false;
public static boolean enableDebugMenu = true; public static boolean enableDebugMenu = true;