use of com.example.asus.onlinecanteen.model.Transaction in project OnlineCanteen by josephgunawan97.
the class OrderAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(final ViewHolder holder, int position) {
// Get Transaction Item
final Transaction transaction = transactionHistory.get(position);
FirebaseDatabase.getInstance().getReference().child("users").child(transaction.getUid()).addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
transaction.setName(dataSnapshot.child("name").getValue().toString());
holder.userNameTextView.setText(dataSnapshot.child("name").getValue().toString());
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
holder.transactionDateTextView.setText(Transaction.getPurchasedDateString(transaction.getPurchaseDate()));
holder.paymentAmountTextView.setText("Rp " + String.valueOf(transaction.getTotalPrice()));
holder.locationTextView.setText("Location: " + transaction.getLocation());
if (transaction.getDeliveryStatus() == 1) {
holder.bg.setBackgroundColor(Color.LTGRAY);
} else
holder.bg.setBackgroundColor(Color.WHITE);
}
use of com.example.asus.onlinecanteen.model.Transaction in project OnlineCanteen by josephgunawan97.
the class MerchantOrderListFragment method detachDatabaseReadListener.
private void detachDatabaseReadListener() {
if (eventListener != null) {
adapter.notifyDataSetChanged();
transactions = new ArrayList<Transaction>();
adapter = new OrderAdapter(transactions);
databaseProducts.removeEventListener(eventListener);
eventListener = null;
}
}
use of com.example.asus.onlinecanteen.model.Transaction in project OnlineCanteen by josephgunawan97.
the class MerchantOrderListFragment method attachDatabaseReadListener.
private void attachDatabaseReadListener() {
if (eventListener == null) {
eventListener = new ChildEventListener() {
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
Transaction newTransaction = dataSnapshot.getValue(Transaction.class);
if (merchant.getUid().equals(newTransaction.getSid()))
adapter.add(newTransaction);
}
@Override
public void onChildChanged(DataSnapshot dataSnapshot, String s) {
Transaction newTransaction = dataSnapshot.getValue(Transaction.class);
if (merchant.getUid().equals(newTransaction.getSid()))
adapter.add(newTransaction);
}
@Override
public void onChildRemoved(DataSnapshot dataSnapshot) {
}
@Override
public void onChildMoved(DataSnapshot dataSnapshot, String s) {
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
};
databaseTransaction.addChildEventListener(eventListener);
}
}
use of com.example.asus.onlinecanteen.model.Transaction in project OnlineCanteen by josephgunawan97.
the class MerchantOrderListFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_main_activity_merchant_order, container, false);
// Inflate the layout for this fragment
swipeLayout = (SwipeRefreshLayout) view.findViewById(R.id.swiperefresh);
swipeLayout.setOnRefreshListener(this);
swipeLayout.setColorSchemeResources(R.color.colorPrimary, R.color.colorPrimaryDark, R.color.colorPrimaryLight);
// Initialize References
databaseTransaction = FirebaseDatabase.getInstance().getReference("transactions");
databaseProducts = FirebaseDatabase.getInstance().getReference("products");
databaseStore = FirebaseDatabase.getInstance().getReference("store");
transactions = new ArrayList<Transaction>();
adapter = new OrderAdapter(transactions);
firebaseAuth = FirebaseAuth.getInstance();
merchant = firebaseAuth.getCurrentUser();
recyclerView = view.findViewById(R.id.list);
layoutManager = new LinearLayoutManager(view.getContext());
recyclerView.setLayoutManager(layoutManager);
recyclerView.setAdapter(adapter);
return view;
}
use of com.example.asus.onlinecanteen.model.Transaction in project OnlineCanteen by josephgunawan97.
the class TransactionCurrentOrderFragment 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);
}
}
Aggregations