Search in sources :

Example 1 with OrderDetailAdapter

use of com.example.asus.onlinecanteen.adapter.OrderDetailAdapter in project OnlineCanteen by josephgunawan97.

the class MerchantOrderDetailActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_merchant_order_detail);
    firebaseDatabase = FirebaseDatabase.getInstance();
    reference = firebaseDatabase.getReference("transactions");
    intent = getIntent();
    pos = intent.getIntExtra("Position", 0);
    transactionHistory = (ArrayList<Transaction>) intent.getSerializableExtra("Transaction");
    transaction = transactionHistory.get(pos);
    mAuth = FirebaseAuth.getInstance();
    // Initialize views
    transactiondate = findViewById(R.id.transaction_date);
    username = findViewById(R.id.username);
    location = findViewById(R.id.user_location);
    grandTotal = findViewById(R.id.transaction_detail_amount);
    orderStatus = findViewById(R.id.order_status);
    acceptButton = findViewById(R.id.acceptOrder);
    declineButton = findViewById(R.id.declineOrder);
    scanQR = findViewById(R.id.scan_qr);
    if (transaction.getDeliveryStatus() == 0) {
        acceptButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                WalletUtil walletUtil = new WalletUtil();
                walletUtil.debitAmount(mAuth.getCurrentUser().getUid(), transaction.getTotalPrice());
                Toast.makeText(getApplicationContext(), "Order accepted", Toast.LENGTH_LONG).show();
                Query query = reference.orderByChild("purchaseDate").equalTo(transaction.getPurchaseDate());
                query.addListenerForSingleValueEvent(new ValueEventListener() {

                    @Override
                    public void onDataChange(DataSnapshot snapshot) {
                        for (DataSnapshot child : snapshot.getChildren()) {
                            child.getRef().child("deliveryStatus").setValue(1);
                        }
                    }

                    @Override
                    public void onCancelled(DatabaseError databaseError) {
                    }
                });
                Intent intent = new Intent(MerchantOrderDetailActivity.this, MainActivityMerchant.class);
                startActivity(intent);
                finish();
            }
        });
        declineButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                Toast.makeText(getApplicationContext(), "Order declined", Toast.LENGTH_LONG).show();
                Query query = reference.orderByChild("purchaseDate").equalTo(transaction.getPurchaseDate());
                query.addListenerForSingleValueEvent(new ValueEventListener() {

                    @Override
                    public void onDataChange(DataSnapshot snapshot) {
                        for (DataSnapshot child : snapshot.getChildren()) {
                            child.getRef().child("deliveryStatus").setValue(4);
                        }
                    }

                    @Override
                    public void onCancelled(DatabaseError databaseError) {
                    }
                });
                Intent intent = new Intent(MerchantOrderDetailActivity.this, MainActivityMerchant.class);
                startActivity(intent);
                finish();
            }
        });
    } else {
        acceptButton.setClickable(false);
        acceptButton.getBackground().setColorFilter(Color.GRAY, PorterDuff.Mode.MULTIPLY);
        declineButton.setClickable(false);
        declineButton.getBackground().setColorFilter(Color.GRAY, PorterDuff.Mode.MULTIPLY);
    }
    scanQR.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent i = new Intent(getApplicationContext(), QrActivity.class);
            i.putExtra("Location", "order");
            i.putExtra("Transaction", transactionHistory);
            i.putExtra("Position", pos);
            startActivityForResult(i, SECOND_ACTIVITY_REQUEST_CODE);
        }
    });
    // Set views
    transactiondate.setText(Transaction.getPurchasedDateString(transaction.getPurchaseDate()));
    username.setText(transaction.getName());
    location.setText(transaction.getLocation());
    grandTotal.setText("Rp " + String.valueOf(transaction.getTotalPrice()));
    // TO BE CHANGED LATER
    orderStatus.setText(statusString(transaction.getDeliveryStatus()));
    // Adapter for order items list
    detailAdapter = new OrderDetailAdapter(transaction.getItems());
    itemsRecyclerView = findViewById(R.id.transaction_detail_items);
    layoutManager = new LinearLayoutManager(getApplicationContext());
    itemsRecyclerView.setLayoutManager(layoutManager);
    itemsRecyclerView.setAdapter(detailAdapter);
}
Also used : Query(com.google.firebase.database.Query) Intent(android.content.Intent) DataSnapshot(com.google.firebase.database.DataSnapshot) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) DatabaseError(com.google.firebase.database.DatabaseError) Transaction(com.example.asus.onlinecanteen.model.Transaction) OrderDetailAdapter(com.example.asus.onlinecanteen.adapter.OrderDetailAdapter) ValueEventListener(com.google.firebase.database.ValueEventListener) WalletUtil(com.example.asus.onlinecanteen.utils.WalletUtil)

Aggregations

Intent (android.content.Intent)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 RecyclerView (android.support.v7.widget.RecyclerView)1 View (android.view.View)1 TextView (android.widget.TextView)1 OrderDetailAdapter (com.example.asus.onlinecanteen.adapter.OrderDetailAdapter)1 Transaction (com.example.asus.onlinecanteen.model.Transaction)1 WalletUtil (com.example.asus.onlinecanteen.utils.WalletUtil)1 DataSnapshot (com.google.firebase.database.DataSnapshot)1 DatabaseError (com.google.firebase.database.DatabaseError)1 Query (com.google.firebase.database.Query)1 ValueEventListener (com.google.firebase.database.ValueEventListener)1