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);
}
Aggregations