title: How to Add Data to Firestore From RecyclerView Adapter?
body: <p>I know there're solutions for similar issues, but my case is somehow more complicated.</p>
  
  <p>I have a <code>FoodMenuActivity</code> which contains a <code>RecyclerView</code> and a <code>Button</code>. The <code>RecyclerView</code> shows the menu and <code>ElegantNumberButton</code> to select item quantity. The <code>Button</code> is supposed to <code>Intent</code> to <code>SummaryActivity</code> and at the same time add selected items and quantities to Firestore.</p>
  
  <p>Here's part of <code>FoodMenuAdapter</code> :</p>
  
  <pre><code>public class FoodMenuAdapter extends FirestoreRecyclerAdapter&lt;FoodMenu, FoodMenuAdapter.FoodMenuHolder&gt; {
  
      public String foodName;
      public int foodQuantity;
      public int price;
      public int parentStoreId;
      public int quantityPrice;
  
      private static final String TAG = "FoodMenuAdapter";
  
      private Map&lt;String, Object&gt; map = new HashMap&lt;&gt;();
  
      public FoodMenuAdapter(@NonNull FirestoreRecyclerOptions options) {
          super(options);
      }
  
      @Override
      protected void onBindViewHolder(@NonNull final FoodMenuHolder holder, final int position, @NonNull FoodMenu model) {
          foodName = model.getFoodName();
          price = model.getPrice();
          parentStoreId = model.getParentStoreId();
  
          holder.foodNameView.setText(foodName);
          holder.priceView.setText("NT$"+String.valueOf(price));
  
          holder.btnQuantity.setOnValueChangeListener(new ElegantNumberButton.OnValueChangeListener() {
              @Override
              public void onValueChange(ElegantNumberButton view, int oldValue, int newValue) {
                  foodQuantity = Integer.parseInt(holder.btnQuantity.getNumber());
                  quantityPrice = foodQuantity*price;
  
                  map.put("parentStoreId", parentStoreId);
                  map.put("foodName", foodName);
                  map.put("foodQuantity", foodQuantity);
              }
          });
      }
  }
  </code></pre>
  
  <p><code>FoodMenuActivity</code></p>
  
  <pre><code>public class FoodMenuActivity extends AppCompatActivity {
  
      private static final String TAG = "FoodMenuActivity";
  
      private String parentPath;
      private String foodMenuPath = "menu";
      private Button btnConfirm;
  
      FirebaseFirestore db = FirebaseFirestore.getInstance();
  
      private CollectionReference foodMenuRef;
      private FoodMenuAdapter foodMenuAdapter;
      private ArrayList&lt;HashMap&lt;String,String&gt;&gt; listMap =  new ArrayList&lt;HashMap&lt;String, String&gt;&gt;();
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_food_menu);
  
          btnConfirm = findViewById(R.id.btn_confirm);
  
          btnConfirm.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  String foodName = foodMenuAdapter.foodName;
                  int foodQuantity = foodMenuAdapter.foodQuantity;
                  int price = foodMenuAdapter.price;
                  int parentStoreId = foodMenuAdapter.parentStoreId;
  
                  Toast.makeText(FoodMenuActivity.this, "foodName : "+foodName+" foodQuantity : "+foodQuantity, Toast.LENGTH_SHORT).show();
              }
          });
  
          setUpRecyclerView();
      }
  }
  </code></pre>
  
  <p><code>activity_food_menu</code></p>
  
  <pre><code>&lt;android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      tools:context=".FoodMenuActivity"&gt;
  
      &lt;android.support.v7.widget.RecyclerView
          android:id="@+id/recycler_view"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:paddingBottom="68dp"&gt;
      &lt;/android.support.v7.widget.RecyclerView&gt;
  
      &lt;Button
          android:id="@+id/btn_confirm"
          android:layout_width="match_parent"
          android:layout_height="60dp"
          android:layout_gravity="bottom"
          android:layout_marginTop="8dp"
          android:layout_marginBottom="8dp"
          android:layout_marginStart="8dp"
          android:layout_marginEnd="8dp"
          android:text="add to cart"/&gt;
  &lt;/android.support.design.widget.CoordinatorLayout&gt;
  </code></pre>
  
  <p><code>food_menu_item</code></p>
  
  <pre><code>&lt;android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      xmlns:app="http://schemas.android.com/apk/res-auto"&gt;
  
      &lt;RelativeLayout
          android:layout_width="match_parent"
          android:layout_height="match_parent"&gt;
  
          &lt;TextView
              android:id="@+id/food_name_view"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_alignParentStart="true"
              android:layout_centerVertical="true"
              android:maxLines="1"
              android:textAppearance="@style/TextAppearance.AppCompat.Large"/&gt;
  
          &lt;TextView
              android:id="@+id/price_view"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_toLeftOf="@id/btn_quantity"
              android:layout_centerVertical="true"/&gt;
  
          &lt;com.cepheuen.elegantnumberbutton.view.ElegantNumberButton
              android:id="@+id/btn_quantity"
              android:layout_width="80dp"
              android:layout_height="48dp"
              android:layout_toLeftOf="@id/btn_add_to_cart"
              android:layout_centerVertical="true"
              app:initialNumber="0"&gt;
          &lt;/com.cepheuen.elegantnumberbutton.view.ElegantNumberButton&gt;
  
      &lt;/RelativeLayout&gt;
  
  &lt;/android.support.v7.widget.CardView&gt;
  </code></pre>
  
  <p>My instinct told me to store the data in <code>Map</code>, but I have no idea how to. Is there any other way to save the state of the items with non-zero quantities?</p>
  
  <p>My goal is when <code>btnConfirm</code> onClicked, the app goes to <code>SummaryActivity</code>, which shows all the selected items with item names and quantities. And add these data to <code>Firestore</code> at the same time.</p>