The problem I have with Authentication is that it takes up so much time and returns the result maybe after 10 minutes. I ended up skipping the authentication most of the time in my app using the manifest file.
With firebase firestore I am unable to get any data back and the log with Firebase filtered gives me below.
2022-11-03 05:30:59.981 453-473/? W/TransactionTracing: Could not find layer id -1 2022-11-03 05:31:00.114 453-473/? W/TransactionTracing: Could not find layer handle 0x7f187c234bf0
Kindly refer to the below codes and please let me know if I've done any wrong implementations.
Am I using the correct imports?
import android.util.Log;
import com.example.xstudies.static_data.dataString;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.firestore.CollectionReference;
import com.google.firebase.firestore.FirebaseFirestore;
import com.google.firebase.firestore.QueryDocumentSnapshot;
import com.google.firebase.firestore.QuerySnapshot;
FirebaseAuth mAuth;
FirebaseFirestore db;
ProgressBar progressBar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
mAuth = FirebaseAuth.getInstance();
db = FirebaseFirestore.getInstance();
private void logIn() {
String userEmail = email.getText().toString();
String userPassword = password.getText().toString();
Toast.makeText(this, "now trying ", Toast.LENGTH_SHORT).show();
if(!userEmail.isEmpty() && !userPassword.isEmpty()){
mAuth.signInWithEmailAndPassword(userEmail,userPassword)
.addOnCompleteListener(new OnCompleteListener<AuthResult>(){
@Override
public void onComplete(@NonNull Task<AuthResult> task){
if(task.isSuccessful()){
// progressBar.setVisibility(View.GONE);
// Toast.makeText(LoginActivity.this,"Login Successfull",
Toast.LENGTH_SHORT).show();
startActivity(new Intent(LoginActivity.this, MainActivity.class));
finish();
}
else{
Toast.makeText(LoginActivity.this,"Error"+ task.isSuccessful(),
Toast.LENGTH_SHORT).show();
progressBar.setVisibility(View.GONE);
}
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Toast.makeText(LoginActivity.this,"error"+e.getLocalizedMessage(),Toast.LENGTH_SHORT).show();
}
})
.addOnCanceledListener(new OnCanceledListener(){
@Override
public void onCanceled() {
Toast.makeText(LoginActivity.this,"Canceled",Toast.LENGTH_SHORT).show();
}
});
}
}
//for the Firestore query please refer to below
db.collection
("Products").whereEqualTo("isFeatured",true ).get()
.addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
@Override
public void onComplete(@NonNull Task<QuerySnapshot> task) {
if (task.isSuccessful()) {
for (QueryDocumentSnapshot document : task.getResult()) {
// Log.d(TAG, document.getId() + " => " + document.getData());
MyProducts popularItem = document.toObject(MyProducts.class);
// Toast.makeText(getActivity(), popularItem.getName(),
Toast.LENGTH_SHORT).show();
AbstractCollection<MyProducts> popularModelList = null;
popularModelList.add(popularItem);
featuredAdapter.notifyDataSetChanged();
// Toast.makeText(getActivity(), (String)
document.get("name"),Toast.LENGTH_SHORT).show();
}
} else {
Toast.makeText(getActivity(), "Error" + task.getException(),
Toast.LENGTH_SHORT).show();
}
}
});