Skip to content

Commit f852d44

Browse files
authored
Merge pull request #36 from pulkit4tech/add_profile_pic
#33 : Added Profile Pic
2 parents 4d088ac + 891fe7a commit f852d44

File tree

8 files changed

+40
-11
lines changed

8 files changed

+40
-11
lines changed

.idea/libraries/glide_3_7_0.xml

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ dependencies {
3636
compile 'com.google.code.gson:gson:2.8.0'
3737
compile 'com.android.volley:volley:1.0.0'
3838
compile 'com.google.android.gms:play-services:10.0.1'
39+
compile 'com.github.bumptech.glide:glide:3.7.0'
3940
}
4041

4142
apply plugin: 'com.google.gms.google-services'

app/src/main/java/com/pulkit4tech/privy/MainActivity.java

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,11 @@
2222
import android.view.Menu;
2323
import android.view.MenuItem;
2424
import android.view.View;
25+
import android.widget.ImageView;
2526
import android.widget.TextView;
2627

28+
import com.bumptech.glide.Glide;
29+
import com.bumptech.glide.load.engine.DiskCacheStrategy;
2730
import com.google.android.gms.auth.api.Auth;
2831
import com.google.android.gms.auth.api.signin.GoogleSignInAccount;
2932
import com.google.android.gms.auth.api.signin.GoogleSignInOptions;
@@ -58,8 +61,9 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
5861
private SharedPreferences mSharedPreferences;
5962
private String NAME = "user_name";
6063
private String EMAIL = "email_id";
64+
private String PROFILE_PIC_URL = "profile_pic_url";
6165
private String LOGGED_IN = "logged_in";
62-
// private ImageView profileImg;
66+
private ImageView profileImg;
6367
private TextView userName, emailId;
6468

6569
@Override
@@ -107,7 +111,7 @@ private void setUpNavigationDrawer() {
107111

108112
private void setUpNavigationHeader() {
109113
View nav_head = navigationView.getHeaderView(0);
110-
// profileImg = (ImageView) nav_head.findViewById(R.id.profile_pic);
114+
profileImg = (ImageView) nav_head.findViewById(R.id.profile_pic);
111115
userName = (TextView) nav_head.findViewById(R.id.user_name);
112116
emailId = (TextView) nav_head.findViewById(R.id.email_id);
113117

@@ -118,6 +122,12 @@ private void setUpNavigationHeaderValue() {
118122
// TODO : Set Profile Image
119123
userName.setText(mSharedPreferences.getString(NAME, getString(R.string.sign_in)));
120124
emailId.setText(mSharedPreferences.getString(EMAIL, ""));
125+
Glide.with(mContext).load(mSharedPreferences.getString(PROFILE_PIC_URL, ""))
126+
.thumbnail(0.5f)
127+
.crossFade()
128+
.diskCacheStrategy(DiskCacheStrategy.ALL)
129+
.error(R.mipmap.ic_launcher)
130+
.into(profileImg);
121131

122132
changeSignInSignOutOption();
123133
}
@@ -174,7 +184,6 @@ private void setGoogleApiClientInfo() {
174184
// Testing Google Sign in
175185
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
176186
.requestEmail()
177-
.requestProfile()
178187
.build();
179188

180189
// Build a GoogleApiClient with access to the Google Sign-In API and the
@@ -340,8 +349,12 @@ private void addLoginInfo(GoogleSignInAccount acct) {
340349
// TODO : add Profile Picture
341350
SharedPreferences.Editor editor = mSharedPreferences.edit();
342351
editor.putBoolean(LOGGED_IN, true);
343-
editor.putString(NAME, acct.getDisplayName());
344-
editor.putString(EMAIL, acct.getEmail());
352+
if (acct.getDisplayName() != null)
353+
editor.putString(NAME, acct.getDisplayName());
354+
if (acct.getEmail() != null)
355+
editor.putString(EMAIL, acct.getEmail());
356+
if (acct.getPhotoUrl() != null)
357+
editor.putString(PROFILE_PIC_URL, acct.getPhotoUrl().toString());
345358
editor.commit();
346359

347360
snackMsg(getString(R.string.sign_in_msg));
4.58 KB
Loading
5.88 KB
Loading

app/src/main/res/layout/app_bar_main.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@
2828
android:id="@+id/fab"
2929
android:layout_width="wrap_content"
3030
android:layout_height="wrap_content"
31-
android:layout_gravity="bottom|end"
32-
android:layout_margin="@dimen/fab_margin"
31+
android:layout_gravity="bottom|start"
32+
android:layout_marginBottom="@dimen/fab_margin_bottom"
33+
android:layout_marginStart="@dimen/fab_margin_start"
3334
app:srcCompat="@drawable/google"
3435
app:backgroundTint="@android:color/white"
3536
/>

app/src/main/res/layout/nav_header_main.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
android:layout_width="wrap_content"
1818
android:layout_height="wrap_content"
1919
android:paddingTop="@dimen/nav_header_vertical_spacing"
20+
2021
app:srcCompat="@android:drawable/sym_def_app_icon" />
2122

2223
<TextView

app/src/main/res/values/dimens.xml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
<resources xmlns:tools="http://schemas.android.com/tools">
22
<!-- Default screen margins, per the Android Design guidelines. -->
3-
<dimen name="activity_horizontal_margin">16dp</dimen>
4-
<dimen name="nav_header_height">160dp</dimen>
5-
<dimen name="activity_vertical_margin">16dp</dimen>
3+
<dimen name="activity_horizontal_margin">16sp</dimen>
4+
<dimen name="nav_header_height">160sp</dimen>
5+
<dimen name="activity_vertical_margin">16sp</dimen>
66
<dimen name="nav_header_vertical_spacing">16sp</dimen>
7-
<dimen name="fab_margin">16sp</dimen>
7+
88
<!--Floating action button-->
99
<dimen name="design_fab_image_size" tools:override="true">36dp</dimen>
10+
<dimen name="fab_margin_bottom">30sp</dimen>
11+
<dimen name="fab_margin_start">10sp</dimen>
1012
</resources>

0 commit comments

Comments
 (0)