content: package io.agora.api.example;
  
  import static io.agora.api.example.common.model.Examples.ADVANCED;
  import static io.agora.api.example.common.model.Examples.BASIC;
  
  import android.content.Context;
  import android.content.Intent;
  import android.os.Bundle;
  import android.view.LayoutInflater;
  import android.view.Menu;
  import android.view.MenuInflater;
  import android.view.MenuItem;
  import android.view.View;
  import android.view.ViewGroup;
  
  import androidx.annotation.NonNull;
  import androidx.fragment.app.Fragment;
  import androidx.recyclerview.widget.GridLayoutManager;
  import androidx.recyclerview.widget.LinearLayoutManager;
  import androidx.recyclerview.widget.RecyclerView;
  
  import io.agora.api.example.annotation.Example;
  import io.agora.api.example.common.adapter.ExampleSection;
  import io.agora.api.example.common.model.Examples;
  import io.github.luizgrp.sectionedrecyclerviewadapter.SectionedRecyclerViewAdapter;
  
  /**
   * A fragment representing a list of Items.
   * <p/>
   * Activities containing this fragment MUST implement the {@link OnListFragmentInteractionListener}
   * interface.
   */
  public class MainFragment extends Fragment {
      //  Customize parameter argument names
      private static final String ARG_COLUMN_COUNT = "column-count";
      // Customize parameters
      private int mColumnCount = 1;
      private OnListFragmentInteractionListener mListener;
  
      /**
       * Mandatory empty constructor for the fragment manager to instantiate the
       * fragment (e.g. upon screen orientation changes).
       */
      public MainFragment() {
      }
  
      /**
       * New instance main fragment.
       *
       * @param columnCount the column count
       * @return the main fragment
       */
      @SuppressWarnings("unused")
      public static MainFragment newInstance(int columnCount) {
          MainFragment fragment = new MainFragment();
          Bundle args = new Bundle();
          args.putInt(ARG_COLUMN_COUNT, columnCount);
          fragment.setArguments(args);
          return fragment;
      }
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setHasOptionsMenu(true);
          if (getArguments() != null) {
              mColumnCount = getArguments().getInt(ARG_COLUMN_COUNT);
          }
      }
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
                               Bundle savedInstanceState) {
          View view = inflater.inflate(R.layout.fragment_main, container, false);
  
          // Set the adapter
          if (view instanceof RecyclerView) {
              Context context = view.getContext();
              RecyclerView recyclerView = (RecyclerView) view;
              if (mColumnCount <= 1) {
                  recyclerView.setLayoutManager(new LinearLayoutManager(context));
              } else {
                  recyclerView.setLayoutManager(new GridLayoutManager(context, mColumnCount));
              }
              SectionedRecyclerViewAdapter sectionedAdapter = new SectionedRecyclerViewAdapter();
              sectionedAdapter.addSection(new ExampleSection(BASIC, Examples.ITEM_MAP.get(BASIC), mListener));
              sectionedAdapter.addSection(new ExampleSection(ADVANCED, Examples.ITEM_MAP.get(ADVANCED), mListener));
              recyclerView.setAdapter(sectionedAdapter);
          }
          return view;
      }
  
  
      @Override
      public void onAttach(Context context) {
          super.onAttach(context);
          if (context instanceof OnListFragmentInteractionListener) {
              mListener = (OnListFragmentInteractionListener) context;
          } else {
              throw new RuntimeException(context.toString()
                      + " must implement OnListFragmentInteractionListener");
          }
      }
  
      @Override
      public void onDetach() {
          super.onDetach();
          mListener = null;
      }
  
      /**
       * This interface must be implemented by activities that contain this
       * fragment to allow an interaction in this fragment to be communicated
       * to the activity and potentially other fragments contained in that
       * activity.
       * <p/>
       * See the Android Training lesson <a href=
       * "http://developer.android.com/training/basics/fragments/communicating.html"
       * >Communicating with Other Fragments</a> for more information.
       */
      public interface OnListFragmentInteractionListener {
          /**
           * Update argument type and name.
           *
           * @param item the item
           */
          void onListFragmentInteraction(Example item);
      }
  
      @Override
      public void onCreateOptionsMenu(@NonNull Menu menu, @NonNull MenuInflater inflater) {
          super.onCreateOptionsMenu(menu, inflater);
          inflater.inflate(R.menu.menu_main_activity, menu);
      }
  
      @Override
      public boolean onOptionsItemSelected(@NonNull MenuItem item) {
          if (item.getItemId() == R.id.setting) {
              startActivity(new Intent(requireContext(), SettingActivity.class));
              return true;
          }
          return super.onOptionsItemSelected(item);
      }
  }
  