Skip to content

Commit

Permalink
✨ Populate Profile from Firebase
Browse files Browse the repository at this point in the history
  • Loading branch information
adithya321 committed Mar 8, 2017
1 parent c28c528 commit bd83095
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 4 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ android {
applicationId "com.pimp.instincts"
minSdkVersion 21
targetSdkVersion 25
versionCode 5
versionName "1.3.1"
versionCode 6
versionName "1.3.2"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import android.support.design.widget.TextInputEditText;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
Expand All @@ -37,8 +38,12 @@
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
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.Query;
import com.google.firebase.database.ValueEventListener;
import com.pimp.instincts.R;
import com.pimp.instincts.model.User;
import com.pimp.instincts.utils.LogHelper;
Expand Down Expand Up @@ -70,6 +75,7 @@ public class ProfileActivity extends AppCompatActivity {
private FirebaseUser currentUser;
private DatabaseReference databaseReference;
private SharedPreferences sharedPreferences;
private Boolean paid = null;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand Down Expand Up @@ -134,10 +140,36 @@ public void populateProfile() {
departmentEt.setText(sharedPreferences.getString("department", ""));
yearEt.setText(sharedPreferences.getString("year", ""));
mobileEt.setText(sharedPreferences.getString("mobile", ""));

Query userQuery = databaseReference.child("users").child(currentUser.getUid());
userQuery.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
try {
User user = dataSnapshot.getValue(User.class);
nameEt.setText(user.getName());
collegeEt.setText(user.getCollege());
departmentEt.setText(user.getDepartment());
yearEt.setText(String.valueOf(user.getYear()));
mobileEt.setText(user.getMobile());
paid = user.isPaid();
} catch (Exception e) {
Log.e("populateProfile", e.toString());
}
}

@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}

public void updateOnClick(View view) {
try {
if (paid == null) {
Toast.makeText(this, "Check your Internet Connection", Toast.LENGTH_LONG).show();
return;
}
if (yearEt.getText().toString().trim().equals(""))
yearEt.setText("0");

Expand All @@ -147,7 +179,7 @@ public void updateOnClick(View view) {
collegeEt.getText().toString(),
departmentEt.getText().toString(),
Integer.parseInt(yearEt.getText().toString()),
mobileEt.getText().toString(), false);
mobileEt.getText().toString(), paid);

SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString("name", nameEt.getText().toString());
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/res/layout/activity_profile.xml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
android:layout_height="wrap_content"
android:orientation="horizontal">

<android.support.design.widget.TextInputLayout
android:layout_width="0dp"
Expand Down

0 comments on commit bd83095

Please sign in to comment.