content: package com.absolutelycold.axgle;
  
  import android.content.Context;
  import android.os.Bundle;
  
  import androidx.annotation.Nullable;
  
  import com.google.android.material.bottomsheet.BottomSheetDialogFragment;
  
  import androidx.fragment.app.Fragment;
  import androidx.recyclerview.widget.LinearLayoutManager;
  import androidx.recyclerview.widget.RecyclerView;
  
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.TextView;
  
  import java.util.ArrayList;
  
  /**
   * <p>A fragment that shows a list of items as a modal bottom sheet.</p>
   * <p>You can show this modal bottom sheet from your activity like this:</p>
   * <pre>
   *     OrderDialogFragment.newInstance(30).show(getSupportFragmentManager(), "dialog");
   * </pre>
   * <p>You activity (or fragment) needs to implement {@link OrderDialogFragment.Listener}.</p>
   */
  public class OrderDialogFragment extends BottomSheetDialogFragment {
  
      private static final String ARG_ITEM_COUNT = "item_count";
      public static final String TAG = "order_dialog";
      private Listener mListener;
  
      public static OrderDialogFragment newInstance(ArrayList<String> orderList) {
          final OrderDialogFragment fragment = new OrderDialogFragment();
          final Bundle args = new Bundle();
          args.putStringArrayList(ARG_ITEM_COUNT, orderList);
          fragment.setArguments(args);
          return fragment;
      }
  
  
      @Nullable
      @Override
      public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
                               @Nullable Bundle savedInstanceState) {
          return inflater.inflate(R.layout.fragment_oder_list_dialog, container, false);
      }
  
      @Override
      public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
          final RecyclerView recyclerView = (RecyclerView) view;
          recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
          recyclerView.setAdapter(new ItemAdapter(getArguments().getStringArrayList(ARG_ITEM_COUNT)));
      }
  
      @Override
      public void onAttach(Context context) {
          super.onAttach(context);
          final Fragment parent = getParentFragment();
          if (parent != null) {
              mListener = (Listener) parent;
          } else {
              mListener = (Listener) context;
          }
      }
  
      @Override
      public void onDetach() {
          mListener = null;
          super.onDetach();
      }
  
      public interface Listener {
          void onSortOptionSelected(int position);
      }
  
      private class ViewHolder extends RecyclerView.ViewHolder {
  
          final TextView text;
  
          ViewHolder(LayoutInflater inflater, ViewGroup parent) {
              super(inflater.inflate(R.layout.fragment_order_dialog_options, parent, false));
              text = (TextView) itemView.findViewById(R.id.order_option);
              text.setOnClickListener(new View.OnClickListener() {
                  @Override
                  public void onClick(View v) {
                      if (mListener != null) {
                          mListener. onSortOptionSelected(getAdapterPosition());
                          dismiss();
                      }
                  }
              });
          }
  
      }
  
      private class ItemAdapter extends RecyclerView.Adapter<ViewHolder> {
  
          private ArrayList<String> order_list;
  
          ItemAdapter(ArrayList<String> itemCount) {
              this.order_list = itemCount;
          }
  
          @Override
          public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
              return new ViewHolder(LayoutInflater.from(parent.getContext()), parent);
          }
  
          @Override
          public void onBindViewHolder(ViewHolder holder, int position) {
              holder.text.setText(order_list.get(position));
          }
  
          @Override
          public int getItemCount() {
              return order_list.size();
          }
  
      }
  
  }
  