public void onClick(View view) {
String msg= edit_chat.getText().toString();
if (msg.equals("")){
return;
}
if (msg.length()==MAX_MESSAGE_LENGTMAH){
return;
}
databaseReference.push().setValue(msg);
}
});
public void onClick(View view) {
String msg= edit_chat.getText().toString();
if (msg.equals("")){
return;
}
if (msg.length()==MAX_MESSAGE_LENGTMAH){
return;
}
databaseReference.push().setValue(msg);
}
});
public class LoginActivity extends AppCompatActivity {
private Button button_next_login,button_login_very;
private EditText login_code_very,login_phone;
private TextView login_title2;
private PhoneAuthProvider.OnVerificationStateChangedCallbacks mCallbacks;
private String mVerificationId;
private PhoneAuthProvider.ForceResendingToken mResendToken;
private FirebaseAuth mAuth;
private ProgressDialog loadingBar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
button_login_very=(Button) findViewById(R.id.button_login_very);
button_next_login=(Button) findViewById(R.id.button_next_login);
login_code_very=(EditText) findViewById(R.id.login_code_very);
login_phone=(EditText) findViewById(R.id.login_phone);
login_title2=(TextView) findViewById(R.id.login_title2);
mAuth=FirebaseAuth.getInstance();
loadingBar=new ProgressDialog(this);
button_next_login.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String phoneNumber = login_phone.getText().toString();
if(TextUtils.isEmpty(phoneNumber)) {
Toast.makeText(LoginActivity.this, "Введите номер", Toast.LENGTH_SHORT).show();
}
else {
loadingBar.setTitle("Проверка номеера");
loadingBar.setMessage("подождите");
loadingBar.setCanceledOnTouchOutside(false);
loadingBar.show();
PhoneAuthOptions options =
PhoneAuthOptions.newBuilder(mAuth)
.setPhoneNumber(phoneNumber) // Phone number to verify
.setTimeout(60L, TimeUnit.SECONDS) // Timeout and unit
.setActivity(LoginActivity.this) // Activity (for callback binding)
.setCallbacks(mCallbacks) // OnVerificationStateChangedCallbacks
.build();
PhoneAuthProvider.verifyPhoneNumber(options);
}
}
});
button_login_very.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String verificationCode=login_code_very.getText().toString();
if (TextUtils.isEmpty((CharSequence) login_code_very)) {
loadingBar.setTitle("Проверка кода");
loadingBar.setMessage("подождите");
loadingBar.setCanceledOnTouchOutside(false);
loadingBar.show();
PhoneAuthCredential credential = PhoneAuthProvider.getCredential(mVerificationId, String.valueOf(login_code_very));
signInWithPhoneAuthCredential(credential);
} else {
Toast.makeText(LoginActivity.this, "Введите код", Toast.LENGTH_SHORT).show();
}
}
});
mCallbacks=new PhoneAuthProvider.OnVerificationStateChangedCallbacks() {
@Override
public void onVerificationCompleted(@NonNull PhoneAuthCredential phoneAuthCredential) {
signInWithPhoneAuthCredential(phoneAuthCredential);
}
@Override
public void onVerificationFailed(@NonNull FirebaseException e) {
loadingBar.dismiss();
Toast.makeText(LoginActivity.this, "error", Toast.LENGTH_SHORT).show();
button_next_login.setVisibility(View.VISIBLE);
button_login_very.setVisibility(View.INVISIBLE);
login_code_very.setVisibility(View.INVISIBLE);
login_phone.setVisibility(View.VISIBLE);
login_title2.setVisibility(View.VISIBLE);
}
@Override
public void onCodeSent(@NonNull String verificationId,
@NonNull PhoneAuthProvider.ForceResendingToken token) {
mVerificationId = verificationId;
mResendToken = token;
loadingBar.dismiss();
Toast.makeText(LoginActivity.this, "Код отправлен", Toast.LENGTH_SHORT).show();
button_next_login.setVisibility(View.INVISIBLE);
button_login_very.setVisibility(View.VISIBLE);
login_code_very.setVisibility(View.VISIBLE);
login_phone.setVisibility(View.INVISIBLE);
login_title2.setVisibility(View.INVISIBLE);
}
};
}
private void signInWithPhoneAuthCredential(PhoneAuthCredential credential) {
mAuth.signInWithCredential(credential)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
loadingBar.dismiss();
Toast.makeText(LoginActivity.this, "Проверка пройдена", Toast.LENGTH_SHORT).show();
Intent mainIntent=new Intent(LoginActivity.this,MainActivity.class);
startActivity(mainIntent);
finish();
} else {
Toast.makeText(LoginActivity.this, "произошла ошибка", Toast.LENGTH_SHORT).show();
}
};
});
}
}
public class RegisterActivity extends AppCompatActivity {
private Button button_vxod ,button_reguest;
private EditText Email_input, password_input;
private TextView text_register ;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);
Email_input=(EditText) findViewById(R.id.Email_input);
password_input=(EditText) findViewById(R.id.password_input);
button_reguest=(Button) findViewById(R.id.button_reguest);
button_vxod=(Button) findViewById(R.id.button_vxod);
text_register=(TextView) findViewById(R.id.text_register);
text_register.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
text_register.setVisibility(View.INVISIBLE);
button_reguest.setVisibility(View.INVISIBLE);
button_vxod.setVisibility(View.VISIBLE);
}
});
}
}
private void RegisterDriver(String email, String password)
{
loadingBar.setTitle("Регистрация водителя");
loadingBar.setMessage("Пожалуйста дождитесь загрузки");
loadingBar.show();
mAuth.createUserWithEmailAndPassword(email,password).addOnCompleteListener((task) -> {
if (task.isSuccessful())
{
Toast.makeText(DriverRegLogActivity.this, "Регистрация прошла успешно!", Toast.LENGTH_SHORT).show();
loadingBar.dismiss();
Intent driverIntent=new Intent(DriverRegLogActivity.this,DriversMapActivity.class);
startActivity(driverIntent);
}
else
{
Toast.makeText(DriverRegLogActivity.this, "Ошибка", Toast.LENGTH_SHORT).show();
loadingBar.dismiss();
}
});
}
private void LoginDriver(String email, String password)
{
loadingBar.setTitle("Вход водителя");
loadingBar.setMessage("Пожалуйста дождитесь загрузки");
loadingBar.show();
mAuth.signInWithEmailAndPassword(email,password).addOnCompleteListener((task) -> {
if (task.isSuccessful())
{
Toast.makeText(DriverRegLogActivity.this, "Успешный вход!", Toast.LENGTH_SHORT).show();
loadingBar.dismiss();
Intent driverIntent=new Intent(DriverRegLogActivity.this,DriversMapActivity.class);
startActivity(driverIntent);
}
else
{
Toast.makeText(DriverRegLogActivity.this, "Ошибка", Toast.LENGTH_SHORT).show();
loadingBar.dismiss();
}
});
}
}