Search in sources :

Example 1 with TopUp

use of com.example.asus.onlinecanteen.model.TopUp in project OnlineCanteen by josephgunawan97.

the class AdminConfirmTopUpActivity method attachDatabaseReadListener.

private void attachDatabaseReadListener() {
    if (EventListener == null) {
        EventListener = new ChildEventListener() {

            @Override
            public void onChildAdded(DataSnapshot dataSnapshot, String s) {
                TopUp topUp = dataSnapshot.getValue(TopUp.class);
                Log.i(AdminConfirmTopUpActivity.class.getSimpleName(), "TES LOG " + topUp.getUid());
                adapter.addTopUp(topUp);
            }

            @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) {
            }
        };
        TopUpUtil.query().addChildEventListener(EventListener);
    }
}
Also used : TopUp(com.example.asus.onlinecanteen.model.TopUp) DatabaseError(com.google.firebase.database.DatabaseError) DataSnapshot(com.google.firebase.database.DataSnapshot) ChildEventListener(com.google.firebase.database.ChildEventListener)

Example 2 with TopUp

use of com.example.asus.onlinecanteen.model.TopUp in project OnlineCanteen by josephgunawan97.

the class AdminConfirmTopUpActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_admin_check_top_up_request);
    getSupportActionBar().setTitle("Confirm Top Up");
    topups = new ArrayList<TopUp>();
    adapter = new TopUpAdapter(topups);
    recyclerView = (RecyclerView) findViewById(R.id.request_recycler_view);
    layoutManager = new LinearLayoutManager(this);
    recyclerView.setLayoutManager(layoutManager);
    recyclerView.setAdapter(adapter);
}
Also used : TopUp(com.example.asus.onlinecanteen.model.TopUp) TopUpAdapter(com.example.asus.onlinecanteen.adapter.TopUpAdapter) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager)

Example 3 with TopUp

use of com.example.asus.onlinecanteen.model.TopUp in project OnlineCanteen by josephgunawan97.

the class RequestTopUpActivity method uploadImage.

// To upload image
private void uploadImage() {
    final Map topUp = new HashMap();
    database = FirebaseDatabase.getInstance().getReference("topuprequest");
    final StorageReference profileImageRef = FirebaseStorage.getInstance().getReference("topuprequest/" + System.currentTimeMillis() + ".jpg");
    if (imageUri != null) {
        profileImageRef.putFile(imageUri).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {

            @Override
            public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
                @SuppressWarnings("VisibleForTests") Uri downloadUrl = taskSnapshot.getDownloadUrl();
                String transferproofUrl = downloadUrl.toString();
                TopUp topUp = new TopUp(transferName.getText().toString(), userID, transferproofUrl.toString(), bankName.getText().toString(), Integer.parseInt(amount.getText().toString()));
                database.push().setValue(topUp);
            }
        }).addOnFailureListener(new OnFailureListener() {

            @Override
            public void onFailure(@NonNull Exception e) {
                Toast.makeText(getApplicationContext(), "Image failed to upload", Toast.LENGTH_LONG).show();
            }
        });
    }
}
Also used : TopUp(com.example.asus.onlinecanteen.model.TopUp) StorageReference(com.google.firebase.storage.StorageReference) HashMap(java.util.HashMap) Uri(android.net.Uri) UploadTask(com.google.firebase.storage.UploadTask) HashMap(java.util.HashMap) Map(java.util.Map) OnSuccessListener(com.google.android.gms.tasks.OnSuccessListener) OnFailureListener(com.google.android.gms.tasks.OnFailureListener)

Example 4 with TopUp

use of com.example.asus.onlinecanteen.model.TopUp in project OnlineCanteen by josephgunawan97.

the class TopUpDetailActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.detail_topup_request);
    firebaseDatabase = FirebaseDatabase.getInstance();
    reference = firebaseDatabase.getReference("topuprequest");
    intent = getIntent();
    pos = intent.getIntExtra("Position", 0);
    topupHistory = (ArrayList<TopUp>) intent.getSerializableExtra("topup");
    topUp = topupHistory.get(pos);
    mAuth = FirebaseAuth.getInstance();
    transactiondate = findViewById(R.id.topup_detail_topup_date);
    username = findViewById(R.id.request_name);
    bankname = findViewById(R.id.bank_name);
    transfername = findViewById(R.id.trans_name);
    amount = findViewById(R.id.topup_detail_amount);
    accept = findViewById(R.id.accept_request);
    transferproof = findViewById(R.id.proofdetail);
    transactiondate.setText(topUp.getRequestDateString(topUp.getRequestdate()));
    transfername.setText(topUp.getTransfername());
    bankname.setText(topUp.getBank());
    amount.setText("Top-up Amount : " + Integer.toString(topUp.getAmount()));
    if (topUp.getRequeststatus() == 1) {
        accept.setEnabled(false);
    }
    if (topUp.getProofpicUrl() != null) {
        Glide.with(transferproof.getContext()).load(topUp.getProofpicUrl()).into(transferproof);
    }
    FirebaseDatabase.getInstance().getReference("users").child(topUp.getUid()).addListenerForSingleValueEvent(new ValueEventListener() {

        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            Log.i(TopUpDetailActivity.class.getSimpleName(), "TRANS + " + dataSnapshot.getValue());
            username.setText(dataSnapshot.child("name").getValue().toString());
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {
        }
    });
    accept.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            FirebaseDatabase.getInstance().getReference().child("wallet").child(topUp.getUid()).addListenerForSingleValueEvent(new ValueEventListener() {

                @Override
                public void onDataChange(DataSnapshot dataSnapshot) {
                    WalletUtil walletUtil = new WalletUtil();
                    walletUtil.debitAmount(topUp.getUid(), topUp.getAmount());
                    Toast.makeText(getApplicationContext(), "Request accepted", Toast.LENGTH_LONG).show();
                    updateReq();
                    Intent intent = new Intent(getApplicationContext(), MainActivityAdmin.class);
                    startActivity(intent);
                    finish();
                }

                @Override
                public void onCancelled(DatabaseError databaseError) {
                }
            });
        }
    });
}
Also used : TopUp(com.example.asus.onlinecanteen.model.TopUp) DatabaseError(com.google.firebase.database.DatabaseError) Intent(android.content.Intent) ValueEventListener(com.google.firebase.database.ValueEventListener) DataSnapshot(com.google.firebase.database.DataSnapshot) WalletUtil(com.example.asus.onlinecanteen.utils.WalletUtil) ImageView(android.widget.ImageView) TextView(android.widget.TextView) View(android.view.View)

Example 5 with TopUp

use of com.example.asus.onlinecanteen.model.TopUp in project OnlineCanteen by josephgunawan97.

the class TopUpAdapter method onBindViewHolder.

/**
 * Bind the view with data at the specified position
 * @param holder ViewHolder which should be updated
 * @param position position of items in the adapter
 */
@Override
public void onBindViewHolder(final ViewHolder holder, int position) {
    // Get topup Item
    final TopUp topup = topUpHistory.get(position);
    // Set Information on View
    // topup.setName("TEST");
    Log.i(TopUpAdapter.class.getSimpleName(), "IF+ " + " " + topup.getUid());
    FirebaseDatabase.getInstance().getReference("users").child(topup.getUid()).addValueEventListener(new ValueEventListener() {

        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            // Log.i(MerchantOrderListFragment.class.getSimpleName(),"IF+ "+merchant.getDisplayName() +" "+ trans.getSid());
            holder.NameTextView.setText(dataSnapshot.child("name").getValue().toString());
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {
        }
    });
    holder.topupDateTextView.setText(topup.getRequestDateString(topup.getRequestdate()));
    holder.AmountTextView.setText("Rp " + String.valueOf(topup.getAmount()));
    if (topup.getRequeststatus() == 1) {
        holder.bg.setBackgroundColor(Color.LTGRAY);
    } else
        holder.bg.setBackgroundColor(Color.WHITE);
}
Also used : TopUp(com.example.asus.onlinecanteen.model.TopUp) DatabaseError(com.google.firebase.database.DatabaseError) ValueEventListener(com.google.firebase.database.ValueEventListener) DataSnapshot(com.google.firebase.database.DataSnapshot)

Aggregations

TopUp (com.example.asus.onlinecanteen.model.TopUp)5 DataSnapshot (com.google.firebase.database.DataSnapshot)3 DatabaseError (com.google.firebase.database.DatabaseError)3 ValueEventListener (com.google.firebase.database.ValueEventListener)2 Intent (android.content.Intent)1 Uri (android.net.Uri)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 View (android.view.View)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 TopUpAdapter (com.example.asus.onlinecanteen.adapter.TopUpAdapter)1 WalletUtil (com.example.asus.onlinecanteen.utils.WalletUtil)1 OnFailureListener (com.google.android.gms.tasks.OnFailureListener)1 OnSuccessListener (com.google.android.gms.tasks.OnSuccessListener)1 ChildEventListener (com.google.firebase.database.ChildEventListener)1 StorageReference (com.google.firebase.storage.StorageReference)1 UploadTask (com.google.firebase.storage.UploadTask)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1