Made registration using Firebase
. I need that when clicking on the same CardView
different DialogFragment
opens and the condition is whether the user is logged in or not, i.e. by clicking on the CardView
, DialogFragment1
opens in which the user logs in, if everything is successful DialogFragment1
is closed and when the CardView
is pressed again, DialogFragment2 is opened, how to do this?
My dialog through which the user logs in
public class FragmentDialogLogin extends Fragment { public static CardView close_dl, login_LG; public static boolean isRememberUserLogin; CardView registration; public static EditText User_Name_LG; public static EditText User_Password_LG; public static String name; public static String surname; public static String email; FirebaseAuth firebaseAuth; FirebaseDatabase firebaseDatabase; DatabaseReference databaseReference; @SuppressLint("StaticFieldLeak") public static LinearLayout Ll_LG; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { return inflater.inflate(R.layout.fragment_dialog_login, container, false); } @SuppressLint("SetJavaScriptEnabled") @Override public void onViewCreated(@NonNull final View view, @Nullable Bundle savedInstanceState) { firebaseAuth = FirebaseAuth.getInstance(); firebaseDatabase = FirebaseDatabase.getInstance(); databaseReference = firebaseDatabase.getReference("Users"); close_dl = view.findViewById(R.id.close_dl); close_dl.setOnClickListener(v -> { closeDialog(); }); registration = view.findViewById(R.id.registration); registration.setOnClickListener(v -> { int current = DialogAuthorization.VP_dialog_authorization.getCurrentItem(); int totalItems = DialogAuthorization.VP_dialog_authorization.getAdapter().getCount(); if (current < totalItems - 1) { DialogAuthorization.VP_dialog_authorization.setCurrentItem(current + 1, true); } }); User_Name_LG = view.findViewById(R.id.User_Name_LG); User_Password_LG = view.findViewById(R.id.User_Password_LG); login_LG = view.findViewById(R.id.login_LG); login_LG.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { String email = User_Name_LG.getText().toString().trim(); String password = User_Password_LG.getText().toString().trim(); if (TextUtils.isEmpty(email)) { User_Name_LG.setError("Email is Required."); return; } if (TextUtils.isEmpty(password)) { User_Password_LG.setError(getText(R.string.Rink)); return; } if (password.length() < 6) { User_Password_LG.setError("Password Must be >= 6 Characters"); return; } firebaseAuth.signInWithEmailAndPassword(email, password).addOnCompleteListener(new OnCompleteListener<AuthResult>() { @Override public void onComplete(@NonNull Task<AuthResult> task) { if (task.isSuccessful()) { Toast.makeText(getContext(), "Logged in Successfully", Toast.LENGTH_SHORT).show(); DialogProfile dialog = new DialogProfile(); dialog.show(requireFragmentManager(), "DialogProfile"); } else { Toast.makeText(getContext(), "Error ! " + task.getException().getMessage(), Toast.LENGTH_SHORT).show(); } } }); } }); } private void closeDialog() { Fragment prev = requireActivity().getSupportFragmentManager().findFragmentByTag("DialogAuthorization"); if (prev != null) { DialogAuthorization df = (DialogAuthorization) prev; df.dismiss(); } } }
https://stackoverflow.com/questions/66620003/authorized-user-condition-that-opens-another-dialogfragment March 14, 2021 at 08:47AM
没有评论:
发表评论