Search in sources :

Example 6 with Transaction

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);
}
Also used : DatabaseError(com.google.firebase.database.DatabaseError) Transaction(com.example.asus.onlinecanteen.model.Transaction) ValueEventListener(com.google.firebase.database.ValueEventListener) DataSnapshot(com.google.firebase.database.DataSnapshot)

Example 7 with Transaction

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;
    }
}
Also used : Transaction(com.example.asus.onlinecanteen.model.Transaction) OrderAdapter(com.example.asus.onlinecanteen.adapter.OrderAdapter)

Example 8 with Transaction

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);
    }
}
Also used : DatabaseError(com.google.firebase.database.DatabaseError) Transaction(com.example.asus.onlinecanteen.model.Transaction) DataSnapshot(com.google.firebase.database.DataSnapshot) ChildEventListener(com.google.firebase.database.ChildEventListener)

Example 9 with Transaction

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;
}
Also used : Transaction(com.example.asus.onlinecanteen.model.Transaction) OrderAdapter(com.example.asus.onlinecanteen.adapter.OrderAdapter) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) ListView(android.widget.ListView)

Example 10 with Transaction

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);
    }
}
Also used : DatabaseError(com.google.firebase.database.DatabaseError) Transaction(com.example.asus.onlinecanteen.model.Transaction) DataSnapshot(com.google.firebase.database.DataSnapshot) ChildEventListener(com.google.firebase.database.ChildEventListener)

Aggregations

Transaction (com.example.asus.onlinecanteen.model.Transaction)13 DataSnapshot (com.google.firebase.database.DataSnapshot)8 DatabaseError (com.google.firebase.database.DatabaseError)8 ValueEventListener (com.google.firebase.database.ValueEventListener)5 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)4 Intent (android.content.Intent)3 View (android.view.View)3 ChildEventListener (com.google.firebase.database.ChildEventListener)3 ArrayList (java.util.ArrayList)3 DividerItemDecoration (android.support.v7.widget.DividerItemDecoration)2 RecyclerView (android.support.v7.widget.RecyclerView)2 ListView (android.widget.ListView)2 TextView (android.widget.TextView)2 OrderAdapter (com.example.asus.onlinecanteen.adapter.OrderAdapter)2 TransactionHistoryAdapter (com.example.asus.onlinecanteen.adapter.TransactionHistoryAdapter)2 WalletUtil (com.example.asus.onlinecanteen.utils.WalletUtil)2 HashMap (java.util.HashMap)2 DialogInterface (android.content.DialogInterface)1 AlertDialog (android.support.v7.app.AlertDialog)1 CartActivityAdapter (com.example.asus.onlinecanteen.adapter.CartActivityAdapter)1