ダイアログ内でパスを移動できるように

This commit is contained in:
ろむねこ 2024-01-25 13:46:51 +09:00
parent 69d64fd44f
commit dfe6049775
No known key found for this signature in database
GPG Key ID: FA1F39A1BA37D168
2 changed files with 23 additions and 15 deletions

View File

@ -8,6 +8,7 @@ import android.widget.Toast;
import androidx.appcompat.widget.Toolbar;
import androidx.fragment.app.DialogFragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
@ -25,25 +26,28 @@ public class LacertaSelectDirDialog extends DialogFragment {
private SelectDirDialogItemAdapter adapter;
private RecyclerView recyclerView;
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
super.onCreateDialog(savedInstanceState);
MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(getActivity());
LayoutInflater inflater = requireActivity().getLayoutInflater();
View view = inflater.inflate(R.layout.lacerta_dialog_select_dir, null);
RecyclerView recyclerView = view.findViewById(R.id.select_dir_recycler_view);
this.recyclerView = view.findViewById(R.id.select_dir_recycler_view);
this.adapter = new SelectDirDialogItemAdapter((name, itemId) -> {
Toast.makeText(getContext(), "Called:" + name, Toast.LENGTH_SHORT).show();
showRecyclerViewItem(itemId);
dismiss();
});
recyclerView.setAdapter(this.adapter);
recyclerView.setLayoutManager(new androidx.recyclerview.widget.LinearLayoutManager(getContext()));
this.recyclerView.setAdapter(this.adapter);
builder.setView(view);
showRecyclerViewItem(null); // get root folder list
showRecyclerViewItem(null); // get root folder
builder.setTitle("Select Directory");
builder.setMessage("Please select a directory.");
@ -54,9 +58,12 @@ public class LacertaSelectDirDialog extends DialogFragment {
private void showRecyclerViewItem(String parent) {
lacertaLibrary.getFolderList(parent).thenAccept(listItems -> {
getActivity().runOnUiThread(() -> {
int currentCount = adapter.getItemCount();
adapter.notifyItemRangeRemoved(0, currentCount);
adapter.setListItems(listItems);
adapter.notifyDataSetChanged();
adapter.notifyItemRangeInserted(0, listItems.size());
});
});
}
}

View File

@ -12,7 +12,7 @@ import java.util.ArrayList;
import one.nem.lacerta.model.ListItem;
public class SelectDirDialogItemAdapter extends RecyclerView.Adapter<SelectDirDialogItemAdapter.ViewHolder> {
public class SelectDirDialogItemAdapter extends RecyclerView.Adapter<SelectDirDialogItemAdapter.SelectDirDialogItemViewHolder> {
ArrayList<ListItem> listItems;
LacertaSelectDirDialogEventListener listener;
@ -25,14 +25,15 @@ public class SelectDirDialogItemAdapter extends RecyclerView.Adapter<SelectDirDi
this.listItems = listItems;
}
@NonNull
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
public SelectDirDialogItemViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(one.nem.lacerta.shared.ui.R.layout.common_list_item, parent, false);
return new ViewHolder(view);
return new SelectDirDialogItemViewHolder(view);
}
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
public void onBindViewHolder(SelectDirDialogItemViewHolder holder, int position) {
ListItem listItem = listItems.get(position);
holder.title.setText(listItem.getTitle());
holder.description.setText(listItem.getDescription());
@ -43,16 +44,16 @@ public class SelectDirDialogItemAdapter extends RecyclerView.Adapter<SelectDirDi
@Override
public int getItemCount() {
return listItems.size();
return listItems == null ? 0 : listItems.size();
}
public class ViewHolder extends RecyclerView.ViewHolder {
public static class SelectDirDialogItemViewHolder extends RecyclerView.ViewHolder {
TextView title;
TextView description;
public ViewHolder(@NonNull View itemView) {
public SelectDirDialogItemViewHolder(@NonNull View itemView) {
super(itemView);
title = itemView.findViewById(one.nem.lacerta.shared.ui.R.id.item_title);