Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class RegisterActivity extends AppCompatActivity {
- @BindView(R.id.register_button) Button mRegisterButton;
- @BindView(R.id.surname_edittext) EditText mSurnameEditText;
- @BindView(R.id.name_text) EditText mNameEditText;
- @BindView(R.id.password_edittext) EditText mPasswordEditText;
- @BindView(R.id.mail_edittext) EditText mMailEditText;
- private FirebaseAuth mAuth;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_register);
- ButterKnife.bind(this);
- mAuth = FirebaseAuth.getInstance();
- }
- @OnClick(R.id.register_button)
- public void register_button(View view){
- RegisterUser();
- }
- private void RegisterUser() {
- String surname = mSurnameEditText.getText().toString().trim();
- String name = mNameEditText.getText().toString().trim();
- String password = mPasswordEditText.getText().toString().trim();
- String mail = mMailEditText.getText().toString().trim();
- if (TextUtils.isEmpty(name)) {
- Toast.makeText(this, "enter the name", Toast.LENGTH_SHORT).show();
- return;
- }
- if (TextUtils.isEmpty(surname)) {
- Toast.makeText(this, "enter the surname", Toast.LENGTH_SHORT).show();
- return;
- }
- if (TextUtils.isEmpty(password)) {
- Toast.makeText(this, "enter the password", Toast.LENGTH_SHORT).show();
- return;
- }
- if (TextUtils.isEmpty(mail)) {
- Toast.makeText(this, "enter the mail", Toast.LENGTH_SHORT).show();
- return;
- }
- mAuth.createUserWithEmailAndPassword(mail,password)
- .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
- @Override
- public void onComplete(@NonNull Task<AuthResult> task) {
- if(task.isSuccessful()){
- Toast.makeText(RegisterActivity.this,"Successfully",Toast.LENGTH_SHORT).show();
- savetheinfo();
- }
- else{
- Toast.makeText(RegisterActivity.this,"Could not registered , please try again...",Toast.LENGTH_SHORT).show();
- }
- }
- });
- }
- private void savetheinfo() {
- FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
- UserProfileChangeRequest profileUpdates = new UserProfileChangeRequest.Builder()
- .setDisplayName(String.valueOf(mNameEditText)).build();
- user.updateProfile(profileUpdates);
- }
- }
- public class ProfileActivity extends AppCompatActivity {
- @BindView(R.id.user_name) TextView mUserName;
- private FirebaseAuth mAuth;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_profile);
- ButterKnife.bind(this);
- mAuth = FirebaseAuth.getInstance();
- FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
- setDataToView(user);
- }
- private void setDataToView(FirebaseUser user) {
- mUserName.setText(user.getDisplayName());
- }
- }
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:gravity="center"
- android:orientation="vertical" >
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:padding="24dp"
- android:text="REGISTER"
- android:layout_marginBottom="50dp"/>
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:gravity="center"
- android:orientation="horizontal">
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="Name: "/>
- <EditText
- android:id="@+id/name_text"
- android:layout_width="100dp"
- android:layout_height="wrap_content" />
- </LinearLayout>
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:gravity="center"
- android:orientation="horizontal">
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="Surname: "/>
- <EditText
- android:id="@+id/surname_edittext"
- android:layout_width="100dp"
- android:layout_height="wrap_content" />
- </LinearLayout>
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:gravity="center"
- android:orientation="horizontal">
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="Mail: "/>
- <EditText
- android:id="@+id/mail_edittext"
- android:layout_width="100dp"
- android:layout_height="wrap_content" />
- </LinearLayout>
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:gravity="center"
- android:orientation="horizontal">
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="Password: "/>
- <EditText
- android:id="@+id/password_edittext"
- android:layout_width="100dp"
- android:layout_height="wrap_content" />
- </LinearLayout>
- <Button
- android:id="@+id/register_button"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="Register"
- android:layout_marginTop="50dp"/>
- </LinearLayout>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement