データセット更新をUiスレッドでやるように(IndexOutOfBounds対策, デバイスのスペックなどの都合で挿入が更新に追いつかないと壊れるため)

This commit is contained in:
r-ca 2024-01-28 10:58:22 +09:00
parent 41776b360b
commit 13e8ee7d87
No known key found for this signature in database
GPG Key ID: 6A72911AC73464A9
2 changed files with 21 additions and 5 deletions

View File

@ -18,6 +18,8 @@ import one.nem.lacerta.component.common.R;
import one.nem.lacerta.component.common.picker.base.LacertaFilePickerAdapterBase;
import one.nem.lacerta.component.common.picker.base.LacertaFilePickerDialogBase;
import one.nem.lacerta.data.LacertaLibrary;
import one.nem.lacerta.model.ListItemType;
import one.nem.lacerta.model.PublicPath;
@AndroidEntryPoint
public class LacertaDirPickerDialog extends LacertaFilePickerDialogBase {
@ -53,13 +55,13 @@ public class LacertaDirPickerDialog extends LacertaFilePickerDialogBase {
@Override
public void onItemSelected(String dirId) {
updateList(adapter, dirId);
currentDirTextView.setText(dirId);
updatePublicPath(currentDirTextView, dirId);
}
@Override
public void onBackSelected(String dirId) {
updateList(adapter, dirId);
currentDirTextView.setText(dirId);
updatePublicPath(currentDirTextView, dirId);
}
});
@ -88,10 +90,20 @@ public class LacertaDirPickerDialog extends LacertaFilePickerDialogBase {
return builder.create();
}
private void updatePublicPath(TextView currentDirTextView, String folderId) {
lacertaLibrary.getPublicPath(folderId, ListItemType.ITEM_TYPE_FOLDER).thenAccept(publicPath -> {
this.updatePathTextView(currentDirTextView, publicPath);
});
}
private void updateList(LacertaFilePickerAdapterBase adapter, String folderId) {
lacertaLibrary.getFolderList(folderId).thenAccept(libraryItemPage -> {
adapter.setListItems(libraryItemPage);
this.updateListView(adapter, libraryItemPage, adapter.getItemCount(), adapter.getCurrentId());
int currentCount = adapter.getItemCount();
String currentId = adapter.getCurrentId();
// adapter.setListItems(libraryItemPage);
getActivity().runOnUiThread(() -> {
this.updateListView(adapter, libraryItemPage, currentCount, currentId);
});
});
}
}

View File

@ -51,7 +51,11 @@ public class LacertaFilePickerDialogBase extends DialogFragment {
}
}
protected void updateListView(LacertaFilePickerAdapterBase adapter, LibraryItemPage libraryItemPage, int currentCount, String currentDirId) {
if (currentDirId == null) {
if (currentCount == 0) {
// 初回表示
adapter.setListItems(libraryItemPage);
adapter.notifyItemRangeInserted(0, libraryItemPage.getListItems().size());
} else if (currentDirId == null) {
// Rootが関わる推移 (Rootからの推移)
adapter.setListItems(libraryItemPage);
adapter.notifyItemRangeRemoved(0, currentCount);