content: package com.example.hp.myapplication;
  
  import android.app.ProgressDialog;
  import android.support.v7.app.AppCompatActivity;
  import android.os.Bundle;
  import android.view.View;
  import android.widget.Button;
  import android.widget.Toast;
  
  import com.example.hp.myapplication.Model.User;
  import com.google.firebase.database.DataSnapshot;
  import com.google.firebase.database.DatabaseError;
  import com.google.firebase.database.DatabaseReference;
  import com.google.firebase.database.FirebaseDatabase;
  import com.google.firebase.database.ValueEventListener;
  import com.rengwuxian.materialedittext.MaterialEditText;
  
  public class SignUp extends AppCompatActivity {
          MaterialEditText edtName,edtPhone,edtPassword;
          Button btnSignUp;
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_sign_up);
  
          edtName = (MaterialEditText)findViewById(R.id.Name);
          edtPhone = (MaterialEditText)findViewById(R.id.edtPhone);
          edtPassword = (MaterialEditText)findViewById(R.id.edtPassword);
          btnSignUp = (Button)findViewById(R.id.btnSignUp);
  
          FirebaseDatabase database = FirebaseDatabase.getInstance();
          final DatabaseReference table_user = database.getReference("User");
  
          btnSignUp.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
  
                  final ProgressDialog progressDialog = new ProgressDialog(SignUp.this);
                  progressDialog.setMessage("Please wait..!");
                  progressDialog.show();
  
                  table_user.addValueEventListener(new ValueEventListener() {
                      @Override
                      public void onDataChange(DataSnapshot dataSnapshot) {
  
                          if(dataSnapshot.child(edtPhone.getText().toString()).exists()){
                              progressDialog.dismiss();
                              Toast.makeText(SignUp.this,"User already exists!",Toast.LENGTH_SHORT).show();
                          }
                          else {
                              progressDialog.dismiss();
                              User user = new User(edtName.getText().toString(),edtPassword.getText().toString());
                              table_user.child(edtPhone.getText().toString()).setValue(user);
                              Toast.makeText(SignUp.this,"SignUp successfully! " ,Toast.LENGTH_SHORT).show();
                              finish();
  
                          }
                      }
  
                      @Override
                      public void onCancelled(DatabaseError databaseError) {
  
                      }
                  });
              }
          });
      }
  }
  