Skip to content

Commit

Permalink
Aula 186 - Salvando dados do usuário
Browse files Browse the repository at this point in the history
  • Loading branch information
daniloamsilva committed Aug 7, 2018
1 parent 39b3fbc commit ba62d63
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;

import br.com.whatsappandroid.cursoandroid.whatsapp2.R;
import br.com.whatsappandroid.cursoandroid.whatsapp2.config.ConfiguracaoFirebase;
Expand Down Expand Up @@ -60,6 +61,11 @@ private void cadastrarUsuario(){
public void onComplete(@NonNull Task<AuthResult> task) {
if( task.isSuccessful() ){
Toast.makeText(CadastroUsuarioActivity.this, "Sucesso ao cadastrar usuário", Toast.LENGTH_LONG ).show();

FirebaseUser usuarioFirebase = task.getResult().getUser();
usuario.setId(usuarioFirebase.getUid());
usuario.salvar();

}else{
Toast.makeText(CadastroUsuarioActivity.this, "Erro ao cadastrar usuário", Toast.LENGTH_LONG ).show();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,11 @@

public class LoginActivity extends AppCompatActivity {

private DatabaseReference referenciaFirebase;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);

referenciaFirebase = ConfiguracaoFirebase.getFirebase();
referenciaFirebase.child("pontos").setValue(800);

}

public void abrirCadastroUsuario(View view){
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package br.com.whatsappandroid.cursoandroid.whatsapp2.model;

import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.Exclude;

import br.com.whatsappandroid.cursoandroid.whatsapp2.config.ConfiguracaoFirebase;

public class Usuario {

private String id;
Expand All @@ -10,6 +15,12 @@ public class Usuario {
public Usuario() {
}

public void salvar(){
DatabaseReference referenciaFirebase = ConfiguracaoFirebase.getFirebase();
referenciaFirebase.child("usuarios").child( getId() ).setValue( this );
}

@Exclude
public String getId() {
return id;
}
Expand All @@ -34,6 +45,7 @@ public void setEmail(String email) {
this.email = email;
}

@Exclude
public String getSenha() {
return senha;
}
Expand Down
9 changes: 6 additions & 3 deletions app/src/main/res/layout/activity_cadastro_usuario.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
android:layout_marginTop="244dp"
android:ems="10"
android:hint="Digite seu nome"
android:inputType="textPersonName" />
android:inputType="textPersonName"
android:textColor="@android:color/white" />

<EditText
android:id="@+id/edit_cadastro_email"
Expand All @@ -40,7 +41,8 @@
android:layout_marginBottom="211dp"
android:ems="10"
android:hint="Digite seu e-mail"
android:inputType="textEmailAddress" />
android:inputType="textEmailAddress"
android:textColor="@android:color/white" />

<EditText
android:id="@+id/edit_cadastro_senha"
Expand All @@ -51,7 +53,8 @@
android:layout_marginBottom="157dp"
android:ems="10"
android:hint="Digite sua senha"
android:inputType="textPassword" />
android:inputType="textPassword"
android:textColor="@android:color/white" />

<Button
android:id="@+id/bt_cadastrar"
Expand Down
6 changes: 4 additions & 2 deletions app/src/main/res/layout/activity_login.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,26 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginTop="249dp"
android:ems="10"
android:hint="Digite seu e-mail"
android:inputType="textEmailAddress"
android:layout_alignParentRight="true" />
android:textColor="@android:color/white" />

<EditText
android:id="@+id/edit_login_senha"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/edit_login_email"
android:layout_alignParentBottom="true"
android:layout_alignStart="@+id/edit_login_email"
android:layout_marginBottom="200dp"
android:ems="10"
android:hint="Digite sua senha"
android:inputType="textPassword"
android:layout_alignLeft="@+id/edit_login_email" />
android:textColor="@android:color/white" />

<Button
android:id="@+id/bt_logar"
Expand Down

0 comments on commit ba62d63

Please sign in to comment.