mirror of
https://github.com/lacerta-doc/Lacerta.git
synced 2024-11-23 00:13:16 +00:00
データセット更新をUiスレッドでやるように(IndexOutOfBounds対策, デバイスのスペックなどの都合で挿入が更新に追いつかないと壊れるため)
This commit is contained in:
parent
41776b360b
commit
13e8ee7d87
|
@ -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);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue
Block a user