Search in sources :

Example 1 with NotificationModel

use of com.manan.dev.ec2018app.Models.NotificationModel in project EC2018App by Manan-YMCA.

the class MyNotificationsActivity method attachDatabaseListener.

private void attachDatabaseListener() {
    if (mChildEventListener == null) {
        mChildEventListener = new ChildEventListener() {

            @Override
            public void onChildAdded(DataSnapshot dataSnapshot, String s) {
                NotificationModel nm = dataSnapshot.getValue(NotificationModel.class);
                updateList(nm);
                progress.dismiss();
            }

            @Override
            public void onChildChanged(DataSnapshot dataSnapshot, String s) {
                try {
                    NotificationModel nm = dataSnapshot.getValue(NotificationModel.class);
                    updateList(nm);
                    progress.dismiss();
                } catch (Exception e) {
                    e.printStackTrace();
                    progress.dismiss();
                }
            }

            @Override
            public void onChildRemoved(DataSnapshot dataSnapshot) {
                NotificationModel nm = dataSnapshot.getValue(NotificationModel.class);
                allNotificationsArrayList.remove(nm);
                progress.dismiss();
            }

            @Override
            public void onChildMoved(DataSnapshot dataSnapshot, String s) {
            }

            @Override
            public void onCancelled(DatabaseError databaseError) {
                progress.dismiss();
            }
        };
        mDatabaseReference.addChildEventListener(mChildEventListener);
    }
}
Also used : DatabaseError(com.google.firebase.database.DatabaseError) DataSnapshot(com.google.firebase.database.DataSnapshot) NotificationModel(com.manan.dev.ec2018app.Models.NotificationModel) ChildEventListener(com.google.firebase.database.ChildEventListener)

Example 2 with NotificationModel

use of com.manan.dev.ec2018app.Models.NotificationModel in project EC2018App by Manan-YMCA.

the class MyNotificationsAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(final MyViewHolder holder, int position) {
    NotificationModel nm = notificationModelArrayList.get(position);
    holder.notificationHeadingTextView.setText(nm.getTextHeading());
    holder.notificationDescriptionTextView.setText(nm.getText());
    holder.logoImageView.setTag(1);
    holder.notifyCardView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // }
            if (holder.logoImageView.getTag().equals(1)) {
                holder.logoImageView.setImageResource(R.drawable.logo_black);
                holder.logoImageView.setTag(2);
            } else {
                holder.logoImageView.setImageResource(R.drawable.logo_300);
                holder.logoImageView.setTag(1);
            }
        }
    });
    Calendar cal = Calendar.getInstance();
    cal.setTimeInMillis(nm.getTime());
    SimpleDateFormat sdf = new SimpleDateFormat("dd MMMM, yy", Locale.ENGLISH);
    String formattedDate = sdf.format(cal.getTime());
    SimpleDateFormat sdf1 = new SimpleDateFormat("kk:mm", Locale.US);
    String formattedTime = sdf1.format(cal.getTime());
    holder.notificationTimeTextView.setText(formattedTime);
    holder.notificationDateTextView.setText(formattedDate);
}
Also used : Calendar(java.util.Calendar) NotificationModel(com.manan.dev.ec2018app.Models.NotificationModel) CardView(android.support.v7.widget.CardView) ImageView(android.widget.ImageView) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) View(android.view.View) SimpleDateFormat(java.text.SimpleDateFormat)

Aggregations

NotificationModel (com.manan.dev.ec2018app.Models.NotificationModel)2 CardView (android.support.v7.widget.CardView)1 RecyclerView (android.support.v7.widget.RecyclerView)1 View (android.view.View)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 ChildEventListener (com.google.firebase.database.ChildEventListener)1 DataSnapshot (com.google.firebase.database.DataSnapshot)1 DatabaseError (com.google.firebase.database.DatabaseError)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Calendar (java.util.Calendar)1