In my project when a user presses on a button it sets the variable clicked = true
and changes TextView colour to orange, the variable clicked
is stored to a database in Firebase Firestore and fetched when activity is started. When I close the app and run it, the variable clicked
is returned as true but it does not apply to my if
statement and returns the TextView colour to default.
@Override
protected void onStart(){
super.onStart();
DocumentReference documentReference = ffstore.collection("user_progress").document(userId);
documentReference.addSnapshotListener(this, new EventListener<DocumentSnapshot>() {
@Override
public void onEvent(@Nullable DocumentSnapshot documentSnapshot, @Nullable FirebaseFirestoreException e) {
if (userAuth.getCurrentUser() != null){
if (documentSnapshot.getBoolean("introOption_1_clicked") != null) {
clicked = (documentSnapshot.getBoolean("introOption_1_clicked"));
Log.i("Message", "Clicked is true "+ clicked);
} else {
}
} else {
}
}
});
if (introOption1Class.returnintroFinishOp1Btn() == true) {
progressTxt.setText("Finished");
progressTxt.setTextColor(Color.parseColor("#20df9a"));
Log.i("MessageTF", "Op1");
} else if (clicked == true) {
progressTxt.setText("Started");
progressTxt.setTextColor(Color.parseColor("#ffb000"));
Log.i("MessageTF", "Op2");
} else if (introOption2Class.returnintroFinishOp2Btn() == true && clicked == true) {
progressTxt.setText("Finished");
progressTxt.setTextColor(Color.parseColor("#20df9a"));
Log.i("MessageTF", "Op3");
}
}