Skip to content

Commit

Permalink
✨ Edit Profile Details
Browse files Browse the repository at this point in the history
  • Loading branch information
adithya321 committed Mar 7, 2017
1 parent 249c1ae commit 78bdd03
Show file tree
Hide file tree
Showing 8 changed files with 266 additions and 9 deletions.
3 changes: 2 additions & 1 deletion app/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
/src/release/res/values/google_maps_api.xml
*.apk
ignore.xml
google-services.json
google-services.json
fabric.properties
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 1
versionName "1.0"
versionCode 2
versionName "1.2.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@
android:name=".activities.SearchActivity"
android:theme="@style/EventsTheme" />
<meta-data
android:name="com.crashlytics.ApiKey"
android:name="io.fabric.ApiKey"
android:value="327685d013652e58a2cb3571746ced9f0a54aab3" />
</application>
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,30 @@

package com.pimp.instincts.activities;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.widget.TextInputEditText;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
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;
import com.google.firebase.database.FirebaseDatabase;
import com.pimp.instincts.R;
import com.pimp.instincts.model.User;
import com.pimp.instincts.utils.LogHelper;

import net.glxn.qrgen.android.QRCode;

Expand All @@ -37,9 +50,26 @@
import it.auron.library.vcard.VCard;

public class ProfileActivity extends AppCompatActivity {
private static final String TAG = LogHelper.makeLogTag(ProfileActivity.class);

@BindView(R.id.qr_image_view)
ImageView qrImageView;
@BindView(R.id.toolbar)
Toolbar toolbar;
@BindView(R.id.name_et)
TextInputEditText nameEt;
@BindView(R.id.college_et)
EditText collegeEt;
@BindView(R.id.department_et)
EditText departmentEt;
@BindView(R.id.year_et)
EditText yearEt;
@BindView(R.id.mobile_et)
EditText mobileEt;

private FirebaseUser currentUser;
private DatabaseReference databaseReference;
private SharedPreferences sharedPreferences;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -55,6 +85,16 @@ protected void onCreate(Bundle savedInstanceState) {
VCard vCard = new VCard();
vCard.setName(firebaseUser.getUid());
qrImageView.setImageBitmap(QRCode.from(vCard.buildString()).bitmap());

databaseReference = FirebaseDatabase.getInstance().getReference();
currentUser = FirebaseAuth.getInstance().getCurrentUser();
sharedPreferences = getSharedPreferences("user", MODE_PRIVATE);

try {
populateProfile();
} catch (Exception e) {
LogHelper.e(TAG, e.toString());
}
}

@Override
Expand All @@ -74,9 +114,65 @@ public boolean onOptionsItemSelected(MenuItem item) {
onBackPressed();
break;
case R.id.action_info:
Toast.makeText(this, "Info", Toast.LENGTH_SHORT).show();
final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
alertDialogBuilder
.setMessage("Show this QR Code at the registration desk to complete " +
"general registration. You will have to pay the respective amount " +
"for each event at its location.")
.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
}).show();
break;
}
return super.onOptionsItemSelected(item);
}

public void populateProfile() {
nameEt.setText(sharedPreferences.getString("name", ""));
collegeEt.setText(sharedPreferences.getString("college", ""));
departmentEt.setText(sharedPreferences.getString("department", ""));
yearEt.setText(sharedPreferences.getString("year", ""));
mobileEt.setText(sharedPreferences.getString("mobile", ""));
}

public void updateOnClick(View view) {
try {
if (yearEt.getText().toString().trim().equals(""))
yearEt.setText("0");

User user = new User(currentUser.getUid(),
nameEt.getText().toString(),
currentUser.getEmail(),
collegeEt.getText().toString(),
departmentEt.getText().toString(),
Integer.parseInt(yearEt.getText().toString()),
mobileEt.getText().toString(), false);

SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString("name", nameEt.getText().toString());
editor.putString("college", collegeEt.getText().toString());
editor.putString("department", departmentEt.getText().toString());
editor.putString("year", yearEt.getText().toString());
editor.putString("mobile", mobileEt.getText().toString());
editor.apply();

Toast.makeText(this, "Updating...", Toast.LENGTH_LONG).show();
databaseReference.child("users").child(currentUser.getUid()).setValue(user)
.addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if (!task.isSuccessful()) {
Toast.makeText(ProfileActivity.this,
task.getException().getMessage().toString(),
Toast.LENGTH_LONG).show();
} else {
Toast.makeText(ProfileActivity.this, "Updated.", Toast.LENGTH_LONG).show();
}
}
});
} catch (Exception e) {
Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.widget.FloatingActionButton;
Expand Down Expand Up @@ -249,7 +250,16 @@ public void onComplete(@NonNull Task<AuthResult> task) {
collegeEt.getText().toString(),
departmentEt.getText().toString(),
Integer.parseInt(yearEt.getText().toString()),
mobileEt.getText().toString());
mobileEt.getText().toString(), false);

SharedPreferences sharedPreferences = getSharedPreferences("user", MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString("name", nameEt.getText().toString());
editor.putString("college", collegeEt.getText().toString());
editor.putString("department", departmentEt.getText().toString());
editor.putString("year", yearEt.getText().toString());
editor.putString("mobile", mobileEt.getText().toString());
editor.apply();

databaseReference.child("users").child(currentUser.getUid()).setValue(user);

Expand Down
14 changes: 12 additions & 2 deletions app/src/main/java/com/pimp/instincts/model/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,21 @@ public class User {
private String department;
private int year;
private String mobile;
private boolean paid;

public User() {
// Default constructor required for calls to DataSnapshot.getValue(User.class)
}

public User(String id, String name, String email, String college, String department, int year,
String mobile) {
public User(String id, String name, String email, String college, String department, int year, String mobile, boolean paid) {
this.id = id;
this.name = name;
this.email = email;
this.college = college;
this.department = department;
this.year = year;
this.mobile = mobile;
this.paid = paid;
}

public String getId() {
Expand Down Expand Up @@ -99,6 +100,14 @@ public void setMobile(String mobile) {
this.mobile = mobile;
}

public boolean isPaid() {
return paid;
}

public void setPaid(boolean paid) {
this.paid = paid;
}

@Override
public String toString() {
return "User{" +
Expand All @@ -109,6 +118,7 @@ public String toString() {
", department='" + department + '\'' +
", year=" + year +
", mobile='" + mobile + '\'' +
", paid=" + paid +
'}';
}
}
27 changes: 27 additions & 0 deletions app/src/main/res/drawable/ic_save.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<!--
~ Instincts
~ Copyright (C) 2017 Adithya J
~
~ This program is free software: you can redistribute it and/or modify
~ it under the terms of the GNU General Public License as published by
~ the Free Software Foundation, either version 3 of the License, or
~ (at your option) any later version.
~
~ This program is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
~ GNU General Public License for more details.
~
~ You should have received a copy of the GNU General Public License
~ along with this program. If not, see <http://www.gnu.org/licenses/>
-->

<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportHeight="24.0"
android:viewportWidth="24.0">
<path
android:fillColor="#FFFFFFFF"
android:pathData="M17,3L5,3c-1.11,0 -2,0.9 -2,2v14c0,1.1 0.89,2 2,2h14c1.1,0 2,-0.9 2,-2L21,7l-4,-4zM12,19c-1.66,0 -3,-1.34 -3,-3s1.34,-3 3,-3 3,1.34 3,3 -1.34,3 -3,3zM15,9L5,9L5,5h10v4z" />
</vector>
115 changes: 114 additions & 1 deletion app/src/main/res/layout/activity_profile.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,118 @@
<ImageView
android:id="@+id/qr_image_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
android:layout_height="0dp"
android:layout_weight="1"
android:padding="8dp" />

<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:textColorHint="#f0f7f4"
android:theme="@style/TextLabel">

<android.support.design.widget.TextInputEditText
android:id="@+id/name_et"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/selector_bg_edit_2"
android:hint="@string/name"
android:inputType="textPersonName"
android:paddingBottom="2dp"
android:textColor="#f0f7f4"
android:textCursorDrawable="@drawable/bg_input_cursor_2" />
</android.support.design.widget.TextInputLayout>

<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:textColorHint="#f0f7f4"
android:theme="@style/TextLabel">

<EditText
android:id="@+id/college_et"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/selector_bg_edit_2"
android:hint="@string/college"
android:inputType="textPersonName"
android:paddingBottom="2dp"
android:textColor="#f0f7f4"
android:textCursorDrawable="@drawable/bg_input_cursor_2" />
</android.support.design.widget.TextInputLayout>

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

<android.support.design.widget.TextInputLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:layout_weight="1"
android:textColorHint="#f0f7f4"
android:theme="@style/TextLabel">

<EditText
android:id="@+id/department_et"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/selector_bg_edit_2"
android:hint="@string/department"
android:inputType="textPersonName"
android:paddingBottom="2dp"
android:textColor="#f0f7f4"
android:textCursorDrawable="@drawable/bg_input_cursor_2" />
</android.support.design.widget.TextInputLayout>

<android.support.design.widget.TextInputLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:layout_weight="1"
android:textColorHint="#f0f7f4"
android:theme="@style/TextLabel">

<EditText
android:id="@+id/year_et"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/selector_bg_edit_2"
android:hint="@string/year"
android:inputType="number"
android:paddingBottom="2dp"
android:textColor="#f0f7f4"
android:textCursorDrawable="@drawable/bg_input_cursor_2" />
</android.support.design.widget.TextInputLayout>
</LinearLayout>

<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:textColorHint="#f0f7f4"
android:theme="@style/TextLabel">

<EditText
android:id="@+id/mobile_et"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/selector_bg_edit_2"
android:hint="@string/mobile"
android:inputType="phone"
android:paddingBottom="2dp"
android:textColor="#f0f7f4"
android:textCursorDrawable="@drawable/bg_input_cursor_2" />
</android.support.design.widget.TextInputLayout>

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:layout_margin="8dp"
android:onClick="updateOnClick"
android:src="@drawable/ic_save"
android:text="UPDATE" />
</LinearLayout>

0 comments on commit 78bdd03

Please sign in to comment.