mirror of
https://github.com/lacerta-doc/Lacerta.git
synced 2024-11-23 00:13:16 +00:00
コード移植
This commit is contained in:
parent
45fcd95e6f
commit
afa3460b24
|
@ -0,0 +1,70 @@
|
||||||
|
package one.nem.lacerta.component.common;
|
||||||
|
|
||||||
|
import android.app.Dialog;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import androidx.appcompat.widget.Toolbar;
|
||||||
|
import androidx.fragment.app.DialogFragment;
|
||||||
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
import dagger.hilt.android.AndroidEntryPoint;
|
||||||
|
import one.nem.lacerta.data.LacertaLibrary;
|
||||||
|
|
||||||
|
@AndroidEntryPoint
|
||||||
|
public class LacertaSelectDirDialog extends DialogFragment {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
LacertaLibrary lacertaLibrary;
|
||||||
|
|
||||||
|
private SelectDirDialogItemAdapter adapter;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||||
|
MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(getActivity());
|
||||||
|
LayoutInflater inflater = requireActivity().getLayoutInflater();
|
||||||
|
View view = inflater.inflate(one.nem.lacerta.shared.ui.R.layout.lacerta_dialog_select_dir, null);
|
||||||
|
|
||||||
|
RecyclerView recyclerView = view.findViewById(one.nem.lacerta.shared.ui.R.id.select_dir_recycler_view);
|
||||||
|
recyclerView.setHasFixedSize(true);
|
||||||
|
|
||||||
|
showRecyclerViewItem(null); // get root folder list
|
||||||
|
|
||||||
|
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()));
|
||||||
|
|
||||||
|
Toolbar toolbar = view.findViewById(one.nem.lacerta.shared.ui.R.id.select_dir_toolbar);
|
||||||
|
toolbar.setNavigationOnClickListener(v -> {
|
||||||
|
Toast.makeText(getContext(), "Called", Toast.LENGTH_SHORT).show();
|
||||||
|
dismiss();
|
||||||
|
});
|
||||||
|
|
||||||
|
builder.setView(view);
|
||||||
|
|
||||||
|
builder.setTitle("Select Directory");
|
||||||
|
builder.setMessage("Please select a directory.");
|
||||||
|
builder.setPositiveButton("OK", null);
|
||||||
|
builder.setNegativeButton("Cancel", null);
|
||||||
|
return builder.create();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void showRecyclerViewItem(String parent) {
|
||||||
|
lacertaLibrary.getFolderList(parent).thenAccept(listItems -> {
|
||||||
|
adapter.setListItems(listItems);
|
||||||
|
adapter.notifyDataSetChanged();
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,5 @@
|
||||||
|
package one.nem.lacerta.component.common;
|
||||||
|
|
||||||
|
public interface LacertaSelectDirDialogEventListener {
|
||||||
|
void onDirSelected(String name, String itemId);
|
||||||
|
}
|
|
@ -0,0 +1,63 @@
|
||||||
|
package one.nem.lacerta.component.common;
|
||||||
|
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import one.nem.lacerta.model.ListItem;
|
||||||
|
|
||||||
|
public class SelectDirDialogItemAdapter extends RecyclerView.Adapter<SelectDirDialogItemAdapter.ViewHolder> {
|
||||||
|
|
||||||
|
ArrayList<ListItem> listItems;
|
||||||
|
LacertaSelectDirDialogEventListener listener;
|
||||||
|
|
||||||
|
public SelectDirDialogItemAdapter(LacertaSelectDirDialogEventListener listener) {
|
||||||
|
this.listener = listener;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setListItems(ArrayList<ListItem> listItems) {
|
||||||
|
this.listItems = listItems;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ViewHolder 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBindViewHolder(ViewHolder holder, int position) {
|
||||||
|
ListItem listItem = listItems.get(position);
|
||||||
|
holder.title.setText(listItem.getTitle());
|
||||||
|
holder.description.setText(listItem.getDescription());
|
||||||
|
holder.itemView.setOnClickListener(v -> {
|
||||||
|
listener.onDirSelected(listItem.getTitle(), listItem.getItemId());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getItemCount() {
|
||||||
|
return listItems.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
public class ViewHolder extends RecyclerView.ViewHolder {
|
||||||
|
|
||||||
|
TextView title;
|
||||||
|
TextView description;
|
||||||
|
|
||||||
|
|
||||||
|
public ViewHolder(@NonNull View itemView) {
|
||||||
|
super(itemView);
|
||||||
|
|
||||||
|
title = itemView.findViewById(one.nem.lacerta.shared.ui.R.id.item_title);
|
||||||
|
description = itemView.findViewById(one.nem.lacerta.shared.ui.R.id.item_description);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user