Adapter, Dialogベース実装

This commit is contained in:
r-ca 2024-01-28 10:28:38 +09:00
parent 1654700ee0
commit be64f5a186
No known key found for this signature in database
GPG Key ID: 6A72911AC73464A9
2 changed files with 15 additions and 8 deletions

View File

@ -9,19 +9,24 @@ import android.widget.TextView;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
import one.nem.lacerta.component.common.LacertaSelectDirDialogInternalEventListener;
import one.nem.lacerta.model.LibraryItemPage; import one.nem.lacerta.model.LibraryItemPage;
import one.nem.lacerta.model.ListItem; import one.nem.lacerta.model.ListItem;
import one.nem.lacerta.model.ListItemType; import one.nem.lacerta.model.ListItemType;
public class LacertaFilePickerAdapterBase extends RecyclerView.Adapter<LacertaFilePickerAdapterBase.LacertaFilePickerViewHolder> { public class LacertaFilePickerAdapterBase extends RecyclerView.Adapter<LacertaFilePickerAdapterBase.LacertaFilePickerViewHolder> {
// Listener
public interface LacertaFilePickerAdapterListener {
void onItemSelected(String dirId);
void onBackSelected(String dirId);
}
private LibraryItemPage libraryItemPage; private LibraryItemPage libraryItemPage;
LacertaSelectDirDialogInternalEventListener listener;
public LacertaFilePickerAdapterBase(LacertaSelectDirDialogInternalEventListener listener) { private LacertaFilePickerAdapterListener listener;
this.listener = listener;
// Empty constructor
public LacertaFilePickerAdapterBase() {
} }
public void setListItems(LibraryItemPage libraryItemPage) { public void setListItems(LibraryItemPage libraryItemPage) {
@ -31,6 +36,10 @@ public class LacertaFilePickerAdapterBase extends RecyclerView.Adapter<LacertaFi
} }
} }
public void setListener(LacertaFilePickerAdapterListener listener) {
this.listener = listener;
}
@NonNull @NonNull
@Override @Override
public LacertaFilePickerViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { public LacertaFilePickerViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
@ -47,7 +56,7 @@ public class LacertaFilePickerAdapterBase extends RecyclerView.Adapter<LacertaFi
if(listItem.getItemType() == ListItemType.ITEM_TYPE_ACTION_BACK) { if(listItem.getItemType() == ListItemType.ITEM_TYPE_ACTION_BACK) {
holder.itemView.setOnClickListener(v -> listener.onBackSelected(this.libraryItemPage.getParentId())); holder.itemView.setOnClickListener(v -> listener.onBackSelected(this.libraryItemPage.getParentId()));
} else { } else {
holder.itemView.setOnClickListener(v -> listener.onDirSelected(listItem.getTitle(), listItem.getItemId())); holder.itemView.setOnClickListener(v -> listener.onItemSelected(listItem.getItemId()));
} }
} }

View File

@ -48,9 +48,7 @@ public class LacertaFilePickerDialogBase extends DialogFragment {
} }
// Methods // Methods
protected void updateList(LacertaFilePickerAdapterBase adapter, LibraryItemPage libraryItemPage) { protected void updateList(LacertaFilePickerAdapterBase adapter, LibraryItemPage libraryItemPage, int currentCount, String currentDirId) {
int currentCount = adapter.getItemCount();
String currentDirId = adapter.getCurrentId();
if (currentDirId == null) { if (currentDirId == null) {
// Rootが関わる推移 (Rootからの推移) // Rootが関わる推移 (Rootからの推移)
adapter.setListItems(libraryItemPage); adapter.setListItems(libraryItemPage);