use of com.example.asus.onlinecanteen.model.Transaction in project OnlineCanteen by josephgunawan97.
the class MerchantOrderDetailActivity method updateOrder.
public void updateOrder() {
DatabaseReference productDatabase = FirebaseDatabase.getInstance().getReference();
Log.i(MerchantOrderDetailActivity.class.getSimpleName(), "BEFORE UPDATE TRANS " + value);
productDatabase.child("transactions").orderByChild(value).addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
Transaction transaction = dataSnapshot.getValue(Transaction.class);
HashMap<String, Object> result = new HashMap<>();
// result.put("imageUrl", );
result.put("deliveryStatus", 1);
Log.i(MerchantOrderDetailActivity.class.getSimpleName(), "UPDATE TRANS1 " + reference.child(value).getKey());
reference.child(value).updateChildren(result);
// Log.i(MerchantOrderDetailActivity.class.getSimpleName(), "UPDATE TRANS "+ reference.child(value).ge);
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
detailAdapter.notifyDataSetChanged();
Log.i(MerchantOrderDetailActivity.class.getSimpleName(), "UPDATE TRANS " + transaction.getDeliveryStatus());
}
use of com.example.asus.onlinecanteen.model.Transaction in project OnlineCanteen by josephgunawan97.
the class QrActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mScannerView = new ZXingScannerView(this);
setContentView(mScannerView);
if (ContextCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.CAMERA) == PackageManager.PERMISSION_DENIED)
ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.CAMERA }, MY_CAMERA_REQUEST_CODE);
Intent intent = getIntent();
value = intent.getStringExtra("Location");
if (value.equals("order")) {
pos = intent.getIntExtra("Position", 0);
transactionHistory = (ArrayList<Transaction>) intent.getSerializableExtra("Transaction");
}
}
use of com.example.asus.onlinecanteen.model.Transaction in project OnlineCanteen by josephgunawan97.
the class TransactionHistoryFragment method attachTransactionEventListener.
private void attachTransactionEventListener() {
if (transactionEventListener == null) {
transactionEventListener = new ChildEventListener() {
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
Transaction newTransaction = dataSnapshot.getValue(Transaction.class);
if (newTransaction.getDeliveryStatus() == 3)
adapter.addTransactionHistory(newTransaction);
}
@Override
public void onChildChanged(DataSnapshot dataSnapshot, String s) {
}
@Override
public void onChildRemoved(DataSnapshot dataSnapshot) {
}
@Override
public void onChildMoved(DataSnapshot dataSnapshot, String s) {
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
};
transactionQuery.addChildEventListener(transactionEventListener);
}
}
use of com.example.asus.onlinecanteen.model.Transaction 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);
}
use of com.example.asus.onlinecanteen.model.Transaction in project OnlineCanteen by josephgunawan97.
the class CartActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_cart);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
cart = (ArrayList<Cart>) getIntent().getSerializableExtra("Cart");
cartActivityAdapter = new CartActivityAdapter(this, cart);
mAuth = FirebaseAuth.getInstance();
user = mAuth.getCurrentUser();
walletUtil = new WalletUtil();
notificationRef = FirebaseDatabase.getInstance().getReference().child("notifications");
// Calculating the grand total
for (Cart c : cart) {
total += c.getTotalPrice(c);
}
// Initialize ListView
cartList = findViewById(R.id.cartList);
grandTotal = findViewById(R.id.grandTotal);
deliveryFee = findViewById(R.id.deliveryFee);
orderButton = findViewById(R.id.OrderButton);
locationEditText = findViewById(R.id.userLocation);
// Set views
grandTotal.setText("TOTAL: Rp " + total);
deliveryFee.setText("Delivery Fee : Rp ");
cartList.setAdapter(cartActivityAdapter);
orderButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (!locationEditText.getText().toString().isEmpty()) {
// Make new transaction
walletRef = FirebaseDatabase.getInstance().getReference().child("wallet");
walletRef.child(user.getUid()).addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
if (dataSnapshot.exists()) {
String valueString = dataSnapshot.getValue().toString();
int walletCash = Integer.parseInt(valueString);
// if wallet money >= total
if (walletCash >= total) {
ArrayList<PurchasedItem> items = new ArrayList<>();
for (Cart c : cart) {
PurchasedItem item = new PurchasedItem(c.getProductName(), c.getProductPrice(), c.getQuantity());
items.add(item);
}
Intent intent = getIntent();
Transaction transaction = new Transaction(intent.getStringExtra("Seller"), FirebaseAuth.getInstance().getUid(), items, locationEditText.getText().toString());
TransactionUtil.insert(transaction);
Toast.makeText(getApplicationContext(), "Transcation done", Toast.LENGTH_SHORT).show();
setResult(RESULT_OK);
// Make notification to the seller
HashMap<String, String> notificationData = new HashMap<>();
notificationData.put("from", transaction.getUid());
notificationData.put("type", "new order");
notificationRef.child(transaction.getSid()).push().setValue(notificationData);
// Go back to main menu
finish();
} else {
Toast.makeText(getApplicationContext(), "Not enough wallet cash, please top-up at our counter", Toast.LENGTH_SHORT).show();
finish();
}
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
} else {
// Alert dialog if the location is not filled in
AlertDialog.Builder builder = new AlertDialog.Builder(CartActivity.this);
builder.setMessage("Please enter your location!").setCancelable(false).setNegativeButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
AlertDialog alert = builder.create();
alert.setTitle("Error");
alert.show();
}
}
});
}
Aggregations