content: package com.example.hp.myapplication;
  
  import android.content.DialogInterface;
  import android.support.v7.app.AlertDialog;
  import android.support.v7.app.AppCompatActivity;
  import android.os.Bundle;
  import android.support.v7.widget.LinearLayoutManager;
  import android.support.v7.widget.RecyclerView;
  import android.view.View;
  import android.widget.Button;
  import android.widget.EditText;
  import android.widget.LinearLayout;
  import android.widget.TextView;
  import android.widget.Toast;
  
  import com.example.hp.myapplication.Common.Common;
  import com.example.hp.myapplication.Database.Database;
  import com.example.hp.myapplication.Model.Order;
  import com.example.hp.myapplication.Model.Request;
  import com.example.hp.myapplication.ViewHolder.CartAdapter;
  import com.google.firebase.database.DatabaseReference;
  import com.google.firebase.database.FirebaseDatabase;
  
  import java.text.NumberFormat;
  import java.util.ArrayList;
  import java.util.List;
  import java.util.Locale;
  
  public class Cart extends AppCompatActivity {
  
      RecyclerView recyclerView;
      RecyclerView.LayoutManager layoutManager;
      FirebaseDatabase database;
      DatabaseReference requests;
  
      TextView txtTotalPrice;
      Button btnPlace;
  
  
      List<Order> cart = new ArrayList<>();
      CartAdapter adapter;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_cart);
  
          database = FirebaseDatabase.getInstance();
          requests = database.getReference("Requests");
  
          //Init
  
          recyclerView = (RecyclerView)findViewById(R.id.listCart);
          recyclerView.setHasFixedSize(true);
          layoutManager = new LinearLayoutManager(this);
          recyclerView.setLayoutManager(layoutManager);
  
          txtTotalPrice = (TextView)findViewById(R.id.total);
          btnPlace = (Button)findViewById(R.id.btnPlaceOrder);
  
          btnPlace.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  showAlertDialog();
              }
          });
          loadListFood();
      }
  
      private void showAlertDialog() {
              AlertDialog.Builder builder = new AlertDialog.Builder(Cart.this);
              builder.setTitle("One More Step!");
              builder.setMessage("Enter Your Address:");
  
              final EditText edtAddress = new EditText(Cart.this);
              LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
                      LinearLayout.LayoutParams.MATCH_PARENT,
                      LinearLayout.LayoutParams.MATCH_PARENT
              );
              edtAddress.setLayoutParams(lp);
              builder.setView(edtAddress);
              builder.setIcon(R.drawable.ic_shopping_cart_black_24dp);
              builder.setPositiveButton("YES", new DialogInterface.OnClickListener() {
                  @Override
                  public void onClick(DialogInterface dialog, int which) {
  //create new request
                      Request request = new Request(
                              Common.currentUser.getPhone(),
                              Common.currentUser.getName(),
                              edtAddress.getText().toString(),
                              txtTotalPrice.getText().toString(),
                              cart
                      );
                      //submit to firebase
                      //currentMilli to key
                      requests.child(String.valueOf(System.currentTimeMillis())).setValue(request);
                      //delete cart
                      new Database(getBaseContext()).cleanCart();
                      Toast.makeText(Cart.this, "Your  Order has been Confirmed!", Toast.LENGTH_SHORT).show();
                      finish();
                  }
              });
              builder.show();
          }
  
      private void loadListFood() {
          cart = new Database(this).getCarts();
          adapter = new CartAdapter(cart,this);
          recyclerView.setAdapter(adapter);
  
          //total price
          int total = 0;
          for(Order order:cart)
              total+=(Integer.parseInt(order.getPrice()))*(Integer.parseInt(order.getQuantity()));
          Locale locale = new Locale("en","US");
          NumberFormat fmt = NumberFormat.getCurrencyInstance(locale);
  
          txtTotalPrice.setText(fmt.format(total));
  
      }
  }
  