한윤범

user profile update

......@@ -13,9 +13,15 @@ import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
public class Main2Activity extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener {
private FirebaseAuth firebaseAuth;
private FirebaseUser mCurrentUser;
@Override
protected void onCreate(Bundle savedInstanceState) {
......@@ -24,7 +30,6 @@ public class Main2Activity extends AppCompatActivity
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
......@@ -33,6 +38,9 @@ public class Main2Activity extends AppCompatActivity
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
firebaseAuth = FirebaseAuth.getInstance();
mCurrentUser = firebaseAuth.getCurrentUser();
}
@Override
......@@ -69,6 +77,8 @@ public class Main2Activity extends AppCompatActivity
private void displaySelectedScreen(int id){
String mail = mCurrentUser.getEmail();
Fragment fragment = null;
switch (id){
......@@ -82,9 +92,15 @@ public class Main2Activity extends AppCompatActivity
fragment = new Community();
break;
case R.id.nav_manage:
if(mail.contains("gmail.com")) {
finish();
startActivity(new Intent(getApplicationContext(), ProfileActivityGmail.class));
}
else{
finish();
startActivity(new Intent(getApplicationContext(), ProfileActivity.class));
}
}
if(fragment != null){
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
......
......@@ -16,11 +16,14 @@ import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
public class MainActivity extends AppCompatActivity implements View.OnClickListener{
private Button buttonRegister;
private EditText editTextName;
private EditText editTextEmail;
private EditText editTextPassword;
private TextView textViewSignIn;
......@@ -28,6 +31,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
private ProgressDialog progressDialog;
private FirebaseAuth firebaseAuth;
private DatabaseReference mDatabase;
@Override
protected void onCreate(Bundle savedInstanceState) {
......@@ -37,6 +41,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
progressDialog = new ProgressDialog(MainActivity.this);
firebaseAuth = FirebaseAuth.getInstance();
mDatabase = FirebaseDatabase.getInstance().getReference().child("Users");
if(firebaseAuth.getCurrentUser() != null){
//profile activity here
......@@ -46,6 +51,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
buttonRegister = (Button) findViewById(R.id.buttonRegister);
editTextName = (EditText) findViewById(R.id.editTextName);
editTextEmail = (EditText) findViewById(R.id.editTextEmail);
editTextPassword = (EditText) findViewById(R.id.editTextPassword);
......@@ -56,8 +62,14 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
}
private void registerUser(){
String email = editTextEmail.getText().toString().trim();
String password = editTextPassword.getText().toString().trim();
final String name = editTextName.getText().toString().trim();
final String email = editTextEmail.getText().toString().trim();
final String password = editTextPassword.getText().toString().trim();
if(TextUtils.isEmpty(name)){
Toast.makeText(this, "이름을 입력하세요", Toast.LENGTH_SHORT).show();
return;
}
if(TextUtils.isEmpty(email)){
//email is empty
......@@ -86,6 +98,9 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
public void onComplete(@NonNull Task<AuthResult> task) {
if(task.isSuccessful()){
finish();
DatabaseReference newPost = mDatabase.push();
newPost.child("name").setValue(name);
newPost.child("email").setValue(email);
startActivity(new Intent(getApplicationContext(), Main2Activity.class));
}else{
Toast.makeText(MainActivity.this, "등록할 수 없습니다.", Toast.LENGTH_SHORT).show();
......
......@@ -16,6 +16,7 @@ import android.widget.Toast;
import com.google.android.gms.tasks.OnSuccessListener;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.storage.FirebaseStorage;
......@@ -38,6 +39,8 @@ public class PostActivity extends AppCompatActivity {
private StorageReference mStorage;
private DatabaseReference mDatabase;
private FirebaseAuth firebaseAuth;
private FirebaseUser mCurrentUser;
private DatabaseReference mDatabaseUser;
private ProgressDialog mProgress;
......@@ -59,6 +62,8 @@ public class PostActivity extends AppCompatActivity {
mStorage = FirebaseStorage.getInstance().getReference();
mDatabase = FirebaseDatabase.getInstance().getReference().child("Blog");
firebaseAuth = FirebaseAuth.getInstance();
mCurrentUser = firebaseAuth.getCurrentUser();
mDatabaseUser = FirebaseDatabase.getInstance().getReference().child("Users").child(mCurrentUser.getUid());
mProgress = new ProgressDialog(this);
......@@ -99,7 +104,7 @@ public class PostActivity extends AppCompatActivity {
newPost.child("title").setValue(title_val);
newPost.child("desc").setValue(desc_val);
newPost.child("image").setValue(downloadUrl.toString());
newPost.child("uid").setValue(firebaseAuth.getCurrentUser());
newPost.child("uid").setValue(mCurrentUser.getUid());
mProgress.dismiss();
......
package com.example.user.firebaseauthdemo;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.database.DatabaseReference;
......@@ -18,13 +22,15 @@ public class ProfileActivity extends AppCompatActivity implements View.OnClickLi
private FirebaseAuth firebaseAuth;
private TextView textViewUserEmail;
private TextView textViewUserName;
private Button buttonLogout;
private DatabaseReference databaseReference;
private EditText editTextName, editTextAddress;
private EditText resetPassword, resetPasswordRe;
private Button buttonSave;
public static final String TAG = "HELPLIST";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
......@@ -37,27 +43,35 @@ public class ProfileActivity extends AppCompatActivity implements View.OnClickLi
databaseReference = FirebaseDatabase.getInstance().getReference().child("UserInfo");
editTextAddress = (EditText) findViewById(R.id.editTextAddress);
editTextName = (EditText)findViewById(R.id.editTextName);
resetPassword = (EditText) findViewById(R.id.resetPassword);
resetPasswordRe = (EditText)findViewById(R.id.resetPasswordRe);
buttonSave = (Button)findViewById(R.id.buttonSave);
FirebaseUser user = firebaseAuth.getCurrentUser();
textViewUserEmail = (TextView) findViewById(R.id.textViewUserEmail);
textViewUserEmail.setText("Welcome " + user.getEmail());
textViewUserName = (TextView) findViewById(R.id.textViewUserName);
textViewUserName.setText(" Welcome " + user.getDisplayName());
buttonLogout = (Button)findViewById(R.id.buttonLogout);
buttonLogout.setOnClickListener(this);
buttonSave.setOnClickListener(this);
}
private void saveUserInformation(){
String name = editTextName.getText().toString().trim();
String add = editTextAddress.getText().toString().trim();
UserInformation userInformation = new UserInformation(name, add);
String password = resetPassword.getText().toString().trim();
String passwordRe = resetPasswordRe.getText().toString().trim();
if(password == passwordRe){
FirebaseUser user = firebaseAuth.getCurrentUser();
databaseReference.child(user.getUid()).setValue(userInformation);
user.updatePassword(password)
.addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if(task.isSuccessful()){
Log.d(TAG, "user password updated.");
}
}
});
}
Toast.makeText(this, "저장되었습니다.", Toast.LENGTH_LONG).show();
}
......
package com.example.user.firebaseauthdemo;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
/**
* Created by HYB on 2017. 10. 19..
*/
public class ProfileActivityGmail extends AppCompatActivity implements View.OnClickListener{
private FirebaseAuth firebaseAuth;
private TextView textViewGmail;
private Button buttonLogout;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_profile_simple_login);
firebaseAuth = FirebaseAuth.getInstance();
if(firebaseAuth.getCurrentUser() == null){
finish();
startActivity(new Intent(this,LoginActivity.class));
}
FirebaseUser user = firebaseAuth.getCurrentUser();
textViewGmail = (TextView) findViewById(R.id.textViewUserGmail);
textViewGmail.setText(" Welcome " + user.getEmail());
buttonLogout = (Button)findViewById(R.id.buttonLogout);
buttonLogout.setOnClickListener(this);
}
@Override
public void onClick(View view) {
if(view == buttonLogout) {
firebaseAuth.signOut();
finish();
startActivity(new Intent(this, LoginActivity.class));
}
}
}
......@@ -26,6 +26,16 @@
<EditText
android:layout_margin="15dp"
android:inputType="textPersonName"
android:hint="Enter your name"
android:id="@+id/editTextName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:layout_editor_absoluteY="0dp"
tools:layout_editor_absoluteX="8dp" />
<EditText
android:layout_margin="15dp"
android:inputType="textEmailAddress"
android:hint="Enter your email"
android:id="@+id/editTextEmail"
......@@ -44,6 +54,7 @@
tools:layout_editor_absoluteY="0dp"
tools:layout_editor_absoluteX="8dp" />
<Button
android:layout_margin="15dp"
android:id="@+id/buttonRegister"
......
......@@ -15,7 +15,7 @@
<TextView
android:layout_margin="15dp"
android:id="@+id/textViewUserEmail"
android:id="@+id/textViewUserName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
......@@ -23,14 +23,14 @@
android:layout_gravity="center_horizontal"/>
<EditText
android:id="@+id/editTextName"
android:hint="이름을 입력해 주세요"
android:id="@+id/resetPassword"
android:hint="수정할 비밀번호"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<EditText
android:id="@+id/editTextAddress"
android:hint="주소를 입력해 주세요"
android:id="@+id/resetPasswordRe"
android:hint="수정할 비밀번호를 다시 입력하세요"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
......@@ -39,7 +39,7 @@
android:id="@+id/buttonSave"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="정보 저장" />
android:text="저장하기" />
<Button
android:id="@+id/buttonLogout"
......
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.user.firebaseauthdemo.ProfileActivity">
<LinearLayout
android:layout_width="368dp"
android:layout_height="495dp"
android:orientation="vertical"
tools:layout_editor_absoluteX="8dp"
tools:layout_editor_absoluteY="8dp">
<TextView
android:layout_margin="15dp"
android:id="@+id/textViewUserGmail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="TextView"
android:layout_gravity="center_horizontal"/>
<Button
android:id="@+id/buttonLogout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="로그아웃" />
</LinearLayout>
</android.support.constraint.ConstraintLayout>