mirror of
https://github.com/lacerta-doc/Lacerta.git
synced 2024-11-23 08:23:15 +00:00
ダイアログ内でパスを移動できるように
This commit is contained in:
parent
69d64fd44f
commit
dfe6049775
|
@ -8,6 +8,7 @@ import android.widget.Toast;
|
||||||
|
|
||||||
import androidx.appcompat.widget.Toolbar;
|
import androidx.appcompat.widget.Toolbar;
|
||||||
import androidx.fragment.app.DialogFragment;
|
import androidx.fragment.app.DialogFragment;
|
||||||
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
|
||||||
|
@ -25,25 +26,28 @@ public class LacertaSelectDirDialog extends DialogFragment {
|
||||||
|
|
||||||
private SelectDirDialogItemAdapter adapter;
|
private SelectDirDialogItemAdapter adapter;
|
||||||
|
|
||||||
|
private RecyclerView recyclerView;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||||
|
|
||||||
|
super.onCreateDialog(savedInstanceState);
|
||||||
|
|
||||||
MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(getActivity());
|
MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(getActivity());
|
||||||
LayoutInflater inflater = requireActivity().getLayoutInflater();
|
LayoutInflater inflater = requireActivity().getLayoutInflater();
|
||||||
View view = inflater.inflate(R.layout.lacerta_dialog_select_dir, null);
|
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) -> {
|
this.adapter = new SelectDirDialogItemAdapter((name, itemId) -> {
|
||||||
Toast.makeText(getContext(), "Called:" + name, Toast.LENGTH_SHORT).show();
|
Toast.makeText(getContext(), "Called:" + name, Toast.LENGTH_SHORT).show();
|
||||||
showRecyclerViewItem(itemId);
|
showRecyclerViewItem(itemId);
|
||||||
dismiss();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
recyclerView.setAdapter(this.adapter);
|
this.recyclerView.setAdapter(this.adapter);
|
||||||
recyclerView.setLayoutManager(new androidx.recyclerview.widget.LinearLayoutManager(getContext()));
|
|
||||||
builder.setView(view);
|
builder.setView(view);
|
||||||
|
|
||||||
showRecyclerViewItem(null); // get root folder list
|
showRecyclerViewItem(null); // get root folder
|
||||||
|
|
||||||
builder.setTitle("Select Directory");
|
builder.setTitle("Select Directory");
|
||||||
builder.setMessage("Please select a directory.");
|
builder.setMessage("Please select a directory.");
|
||||||
|
@ -54,9 +58,12 @@ public class LacertaSelectDirDialog extends DialogFragment {
|
||||||
|
|
||||||
private void showRecyclerViewItem(String parent) {
|
private void showRecyclerViewItem(String parent) {
|
||||||
lacertaLibrary.getFolderList(parent).thenAccept(listItems -> {
|
lacertaLibrary.getFolderList(parent).thenAccept(listItems -> {
|
||||||
|
getActivity().runOnUiThread(() -> {
|
||||||
|
int currentCount = adapter.getItemCount();
|
||||||
|
adapter.notifyItemRangeRemoved(0, currentCount);
|
||||||
adapter.setListItems(listItems);
|
adapter.setListItems(listItems);
|
||||||
adapter.notifyDataSetChanged();
|
adapter.notifyItemRangeInserted(0, listItems.size());
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@ import java.util.ArrayList;
|
||||||
|
|
||||||
import one.nem.lacerta.model.ListItem;
|
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;
|
ArrayList<ListItem> listItems;
|
||||||
LacertaSelectDirDialogEventListener listener;
|
LacertaSelectDirDialogEventListener listener;
|
||||||
|
@ -25,14 +25,15 @@ public class SelectDirDialogItemAdapter extends RecyclerView.Adapter<SelectDirDi
|
||||||
this.listItems = listItems;
|
this.listItems = listItems;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
@Override
|
@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);
|
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
|
@Override
|
||||||
public void onBindViewHolder(ViewHolder holder, int position) {
|
public void onBindViewHolder(SelectDirDialogItemViewHolder holder, int position) {
|
||||||
ListItem listItem = listItems.get(position);
|
ListItem listItem = listItems.get(position);
|
||||||
holder.title.setText(listItem.getTitle());
|
holder.title.setText(listItem.getTitle());
|
||||||
holder.description.setText(listItem.getDescription());
|
holder.description.setText(listItem.getDescription());
|
||||||
|
@ -43,16 +44,16 @@ public class SelectDirDialogItemAdapter extends RecyclerView.Adapter<SelectDirDi
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getItemCount() {
|
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 title;
|
||||||
TextView description;
|
TextView description;
|
||||||
|
|
||||||
|
|
||||||
public ViewHolder(@NonNull View itemView) {
|
public SelectDirDialogItemViewHolder(@NonNull View itemView) {
|
||||||
super(itemView);
|
super(itemView);
|
||||||
|
|
||||||
title = itemView.findViewById(one.nem.lacerta.shared.ui.R.id.item_title);
|
title = itemView.findViewById(one.nem.lacerta.shared.ui.R.id.item_title);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user