1

I have done all the codes that I thought would help, my code is as follows:

MashavaCards.java

public class MashavaCards extends AppCompatActivity {
    private RecyclerView recyclerView;
    private DatabaseReference mDatabase;
    private FirebaseAuth mAuth;
    private FirebaseAuth.AuthStateListener mAuthListener;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_mashava_cards);

        getSupportActionBar().hide();

        recyclerView = (RecyclerView) findViewById(R.id.recyclerview_mashava);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        recyclerView.setHasFixedSize(true);

        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
        linearLayoutManager.setReverseLayout(true);
        linearLayoutManager.setStackFromEnd(true);
        recyclerView.setLayoutManager(linearLayoutManager);

        mDatabase = FirebaseDatabase.getInstance().getReference().child("Sales").child("Mashava");

        mAuth = FirebaseAuth.getInstance();
        mAuthListener = new FirebaseAuth.AuthStateListener() {
            @Override
            public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
                if (mAuth.getCurrentUser() == null) {
                    Intent loginIntent = new Intent(MashavaCards.this, LoginEmail.class);
                    loginIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
                    startActivity(loginIntent);
                }
            }
        };
    }

    @Override
    protected void onStart() {
        super.onStart();
        Toast.makeText(this, "Loading...",Toast.LENGTH_SHORT).show();
        mAuth.addAuthStateListener(mAuthListener);
        FirebaseRecyclerAdapter<MashavaData, BlogzoneViewHolder> FBRA = new FirebaseRecyclerAdapter<MashavaData, MashavaCards.BlogzoneViewHolder>(
                MashavaData.class,
                R.layout.card_items,
                MashavaCards.BlogzoneViewHolder.class,
                mDatabase

        ) {
            @Override
            protected void populateViewHolder(MashavaCards.BlogzoneViewHolder viewHolder, MashavaData model, int position) {
                final String post_key = getRef(position).getKey().toString();
                viewHolder.setTime(model.getTime());

                viewHolder.setDate(model.getDate());
                viewHolder.setSupervisor(model.getSupervisor());


                viewHolder.mView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                           Intent singleActivity = new Intent(MashavaCards.this, MashavaDaily.class);
                           singleActivity.putExtra("PostID", post_key);
                           startActivity(singleActivity);
                    }
                });
            }
        };
        recyclerView.setAdapter(FBRA);
    }

    public static class BlogzoneViewHolder extends RecyclerView.ViewHolder {
        View mView;

        public BlogzoneViewHolder(View itemView) {
            super(itemView);
            mView = itemView;
        }

        public void setTime(long time) {
            TextView post_time = mView.findViewById(R.id.card_time);
            post_time.setText(DateUtils.getRelativeTimeSpanString(time, System.currentTimeMillis(), DateUtils.MINUTE_IN_MILLIS));
        }

        public void setDate(String date) {
            TextView shift_date = mView.findViewById(R.id.card_date);
            shift_date.setText(date);
        }

        public void setSupervisor(String supervisor) {
            TextView post_supervisor = mView.findViewById(R.id.card_supervisor);
            post_supervisor.setText(supervisor);

        }
    }
}

MashavaData.java

import java.util.Date;

/**
 * Created by EKENE on 11/4/2017.
 */

public class MashavaData {

    private Double op1, op2, op3, cp1, cp2, cp3, ot1, ot2, ot3, ct1, ct2, ct3, petrolprice, dieselprice, cash, expenses, drawdown;
    private String date, supervisor, attandants, shift;
    private long time;

    public MashavaData(String date, String supervisor, String attandants, String shift, Double op1, Double op2, Double op3, Double cp1, Double cp2, Double cp3, Double ot1, Double ot2, Double ot3, Double ct1, Double ct2, Double ct3, Double petrolprice, Double dieselprice, Double cash, Double expenses, Double drawdown ) {
        this.time = new Date().getTime();
        this.op1 = op1;
        this.op2 = op2;
        this.op3 = op3;
        this.cp1 = cp1;
        this.cp2 = cp2;
        this.cp3 = cp3;
        this.ot1 = ot1;
        this.ot2 = ot2;
        this.ot3 = ot3;
        this.ct1 = ct1;
        this.ct2 = ct2;
        this.ct3 = ct3;

        this.petrolprice = petrolprice;
        this.dieselprice=dieselprice;
        this.date = date;
        this.cash =cash;
        this.expenses = expenses;
        this.drawdown = drawdown;
        this.supervisor = supervisor;
        this.attandants = attandants;
        this.shift = shift;
    }

    public MashavaData() {
    }

    public long getTime() {return time;}

    public void setTime(long time){this.time=time;}

    public Double getOp1() {
        return op1;
    }

    public Double getOp2() {
        return op2;
    }

    public Double getOp3() {
        return op3;
    }

    public Double getCp1() {
        return cp1;
    }

    public Double getCp2() {
        return cp2;
    }

    public Double getCp3() {
        return cp3;
    }

    public Double getOt1() {
        return ot1;
    }

    public Double getOt2() {
        return ot2;
    }

    public Double getOt3() {
        return ot3;
    }

    public Double getCt1() {
        return ct1;
    }

    public Double getCt2() {
        return ct2;
    }

    public Double getCt3() {
        return ct3;
    }

    public Double getPetrolprice() {
        return petrolprice;
    }

    public Double getDieselprice() {
        return dieselprice;
    }

    public Double getCash() {
        return cash;
    }

    public Double getExpenses() {
        return expenses;
    }

    public Double getDrawdown() {
        return drawdown;
    }

    public String getDate() {
        return date;
    }

    public String getSupervisor() {
        return supervisor;
    }

    public String getAttandants() {
        return attandants;
    }

    public String getShift() {
        return shift;
    }

    ///////////////////////////////////////////////

    public void setOp1(Double op1) {
        this.op1 = op1;
    }

    public void setOp2(Double op2) {
        this.op2 = op2;
    }

    public void setOp3(Double op3) {
        this.op3 = op3;
    }

    public void setCp1(Double cp1) {
        this.cp1 = cp1;
    }

    public void setCp2(Double cp2) {
        this.cp2 = cp2;
    }

    public void setCp3(Double cp3) {
        this.cp3 = cp3;
    }

    public void setOt1(Double ot1) {
        this.ot1 = ot1;
    }

    public void setOt2(Double ot2) {
        this.ot2 = ot2;
    }

    public void setOt3(Double ot3) {
        this.ot3 = ot3;
    }

    public void setCt1(Double ct1) {
        this.ct1 = ct1;
    }

    public void setCt2(Double ct2) {
        this.ct2 = ct2;
    }

    public void setCt3(Double ct3) {
        this.ct3 = ct3;
    }

    public void setPetrolprice(Double petrolprice) {
        this.petrolprice = petrolprice;
    }

    public void setDieselprice(Double dieselprice) {
        this.dieselprice = dieselprice;
    }

    public void setCash(Double cash) {
        this.cash = cash;
    }

    public void setExpenses(Double expenses) {
        this.expenses = expenses;
    }

    public void setDrawdown(Double drawdown) {
        this.drawdown = drawdown;
    }

    public void setDate(String date) {
        this.date = date;
    }

    public void setSupervisor(String supervisor) {
        this.supervisor = supervisor;
    }

    public void setAttandants(String attandants) {
        this.attandants = attandants;
    }

    public void setShift(String shift) {
        this.shift = shift;
    }

}

card_items.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="10dp"
    android:orientation="vertical"
    android:padding="10dp"
    app:cardCornerRadius="8dp">

    <LinearLayout
        android:orientation="horizontal"
        android:weightSum="2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <TextView
            android:id="@+id/card_date"
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:text="Date: 00/00/00"
            android:textColor="#6200EE"
            android:textStyle="bold" />
        <TextView
            android:id="@+id/card_supervisor"
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:text="Supervisor: Name"
            android:textColor="#6200EE"
            android:textStyle="bold"/>
    </LinearLayout>

    <LinearLayout
        android:orientation="horizontal"
        android:weightSum="2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <TextView
            android:id="@+id/card_sales"
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:text="Sales (l): 0000"
            android:textColor="#6200EE"
            android:textStyle="bold" />
        <TextView
            android:id="@+id/card_cash"
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:text="Cash: $00.00"
            android:textColor="#6200EE"
            android:textStyle="bold"/>
    </LinearLayout>

    <LinearLayout
        android:orientation="horizontal"
        android:weightSum="2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <TextView
            android:id="@+id/card_expenses"
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:text="Expenses: $00.00"
            android:textColor="#6200EE"
            android:textStyle="bold" />
        <TextView
            android:id="@+id/card_drawdown"
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:text="Drawdown (l): 0000"
            android:textColor="#6200EE"
            android:textStyle="bold"/>
    </LinearLayout>

    <LinearLayout
        android:orientation="horizontal"
        android:weightSum="2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <TextView
            android:id="@+id/card_comment"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:layout_weight="1"
            android:text="comment sales"
            android:textColor="#6200EE"
            android:textStyle="bold"/>
        <TextView
            android:id="@+id/card_time"
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:text="Posted: 1 hour ago"
            android:textColor="#6200EE"
            android:textStyle="bold"/>
    </LinearLayout>


</LinearLayout>

activity_mashava_cards.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:padding="10dp"
    tools:context=".mashava.MashavaCards">

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/recyclerview_mashava"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

    </androidx.recyclerview.widget.RecyclerView>

</LinearLayout>

Firebase stracture

I have done this code, when I run the app there is nothing displaying, its a blank activity.

Unfortunately I do not have logcat, I can only test the app on my phone.

what is wrong with my code??

Logcat: W/System: Ignoring header X-Firebase-Locale because its value was null

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Coin Chain
  • 51
  • 5
  • I think you miss `firebaseRecyclerOptions` parameter to the Adapter constructor please check https://stackoverflow.com/questions/49383687/how-can-i-retrieve-data-from-firebase-to-my-adapter/49384849 – Zain Apr 07 '21 at 13:36

0 Answers0