4
4
import android .content .Intent ;
5
5
import android .content .SharedPreferences ;
6
6
import android .content .pm .PackageManager ;
7
+ import android .graphics .Bitmap ;
7
8
import android .support .annotation .NonNull ;
8
9
import android .support .design .widget .CoordinatorLayout ;
9
10
import android .support .design .widget .FloatingActionButton ;
13
14
import android .support .v4 .app .Fragment ;
14
15
import android .os .Bundle ;
15
16
import android .support .v4 .app .FragmentTransaction ;
17
+ import android .support .v4 .graphics .drawable .RoundedBitmapDrawable ;
18
+ import android .support .v4 .graphics .drawable .RoundedBitmapDrawableFactory ;
16
19
import android .support .v4 .view .GravityCompat ;
17
20
import android .support .v4 .widget .DrawerLayout ;
18
21
import android .support .v7 .app .ActionBarDrawerToggle ;
27
30
28
31
import com .bumptech .glide .Glide ;
29
32
import com .bumptech .glide .load .engine .DiskCacheStrategy ;
33
+ import com .bumptech .glide .request .target .BitmapImageViewTarget ;
30
34
import com .google .android .gms .auth .api .Auth ;
31
35
import com .google .android .gms .auth .api .signin .GoogleSignInAccount ;
32
36
import com .google .android .gms .auth .api .signin .GoogleSignInOptions ;
@@ -76,6 +80,8 @@ protected void onCreate(Bundle savedInstanceState) {
76
80
if (savedInstanceState == null ) {
77
81
setUpInfo ();
78
82
}
83
+
84
+ loadMapFragment ();
79
85
}
80
86
81
87
@ Override
@@ -91,9 +97,6 @@ private void setUpInfo() {
91
97
if (checkIfLoggedIn ()) {
92
98
fab .hide ();
93
99
}
94
-
95
- navigationView .getMenu ().getItem (0 ).setChecked (true );
96
- loadMapFragment ();
97
100
}
98
101
99
102
private void setUpNavigationDrawer () {
@@ -119,26 +122,39 @@ private void setUpNavigationHeader() {
119
122
}
120
123
121
124
private void setUpNavigationHeaderValue () {
122
- userName .setText (mSharedPreferences .getString (NAME , getString ( R . string . sign_in ) ));
125
+ userName .setText (mSharedPreferences .getString (NAME , "" ));
123
126
emailId .setText (mSharedPreferences .getString (EMAIL , "" ));
127
+ loadProfilePic ();
128
+
129
+ changeSignInSignOutOption ();
130
+ }
131
+
132
+ private void loadProfilePic () {
124
133
Glide .with (mContext ).load (mSharedPreferences .getString (PROFILE_PIC_URL , "" ))
125
- .override ( 150 , 150 )
134
+ .asBitmap ( )
126
135
.fitCenter ()
127
- .crossFade ()
128
136
.diskCacheStrategy (DiskCacheStrategy .ALL )
129
- .error (R .mipmap .ic_launcher )
130
- .into (profileImg );
131
-
132
- changeSignInSignOutOption ();
137
+ .error (R .drawable .default_avatar )
138
+ .into (new BitmapImageViewTarget (profileImg ) {
139
+ @ Override
140
+ protected void setResource (Bitmap resource ) {
141
+ RoundedBitmapDrawable circularBitmapDrawable =
142
+ RoundedBitmapDrawableFactory .create (mContext .getResources (), resource );
143
+ circularBitmapDrawable .setCircular (true );
144
+ profileImg .setImageDrawable (circularBitmapDrawable );
145
+ }
146
+ });
133
147
}
134
148
135
149
private void changeSignInSignOutOption () {
136
150
Menu menu = navigationView .getMenu ();
137
151
MenuItem sign_in_out_item = menu .findItem (R .id .nav_sign_in_out );
138
152
if (checkIfLoggedIn ()) {
139
153
sign_in_out_item .setTitle (R .string .sign_out );
154
+ sign_in_out_item .setIcon (this .getResources ().getDrawable (R .drawable .sign_out ));
140
155
} else {
141
156
sign_in_out_item .setTitle (R .string .sign_in );
157
+ sign_in_out_item .setIcon (this .getResources ().getDrawable (R .drawable .sign_in ));
142
158
}
143
159
}
144
160
@@ -233,27 +249,27 @@ public void onBackPressed() {
233
249
}
234
250
}
235
251
236
- @ Override
237
- public boolean onCreateOptionsMenu (Menu menu ) {
238
- // Inflate the menu; this adds items to the action bar if it is present.
239
- getMenuInflater ().inflate (R .menu .main , menu );
240
- return true ;
241
- }
242
-
243
- @ Override
244
- public boolean onOptionsItemSelected (MenuItem item ) {
245
- // Handle action bar item clicks here. The action bar will
246
- // automatically handle clicks on the Home/Up button, so long
247
- // as you specify a parent activity in AndroidManifest.xml.
248
- int id = item .getItemId ();
249
-
250
- //noinspection SimplifiableIfStatement
251
- if (id == R .id .action_settings ) {
252
- return true ;
253
- }
254
-
255
- return super .onOptionsItemSelected (item );
256
- }
252
+ // @Override
253
+ // public boolean onCreateOptionsMenu(Menu menu) {
254
+ // // Inflate the menu; this adds items to the action bar if it is present.
255
+ // getMenuInflater().inflate(R.menu.main, menu);
256
+ // return true;
257
+ // }
258
+ //
259
+ // @Override
260
+ // public boolean onOptionsItemSelected(MenuItem item) {
261
+ // // Handle action bar item clicks here. The action bar will
262
+ // // automatically handle clicks on the Home/Up button, so long
263
+ // // as you specify a parent activity in AndroidManifest.xml.
264
+ // int id = item.getItemId();
265
+ //
266
+ // //noinspection SimplifiableIfStatement
267
+ // if (id == R.id.action_settings) {
268
+ // return true;
269
+ // }
270
+ //
271
+ // return super.onOptionsItemSelected(item);
272
+ // }
257
273
258
274
@ SuppressWarnings ("StatementWithEmptyBody" )
259
275
@ Override
@@ -268,15 +284,38 @@ public boolean onNavigationItemSelected(MenuItem item) {
268
284
loadAddNewPrivyActivity ();
269
285
closeDrawer ();
270
286
} else if (id == R .id .nav_sign_in_out ) {
271
- if (checkIfLoggedIn ())
287
+ if (checkIfLoggedIn ()) {
272
288
signOut ();
273
- else
289
+ } else {
274
290
startGoogleSignInActivity (RC_SIGN_IN );
291
+ }
292
+ } else if (id == R .id .nav_share ) {
293
+ shareApp ();
294
+ closeDrawer ();
295
+ } else if (id == R .id .nav_feedback ) {
296
+ sendFeedBack ();
297
+ closeDrawer ();
275
298
}
276
- //TODO : Add other conditions
277
299
return true ;
278
300
}
279
301
302
+ private void sendFeedBack () {
303
+ Intent Email = new Intent (Intent .ACTION_SEND );
304
+ Email .setType ("text/email" );
305
+ Email .putExtra (Intent .EXTRA_EMAIL , new String []{getString (R .string .app_feedback_mail )});
306
+ Email .putExtra (Intent .EXTRA_SUBJECT , getString (R .string .feedback_subject ));
307
+ startActivity (Intent .createChooser (Email , getString (R .string .send_feedback_msg )));
308
+ }
309
+
310
+ private void shareApp () {
311
+ Intent sendIntent = new Intent ();
312
+ sendIntent .setAction (Intent .ACTION_SEND );
313
+ sendIntent .putExtra (Intent .EXTRA_TEXT ,
314
+ getString (R .string .social_share_msg ));
315
+ sendIntent .setType ("text/plain" );
316
+ startActivity (sendIntent );
317
+ }
318
+
280
319
private void closeDrawer () {
281
320
DrawerLayout drawer = (DrawerLayout ) findViewById (R .id .drawer_layout );
282
321
drawer .closeDrawer (GravityCompat .START );
@@ -285,7 +324,8 @@ private void closeDrawer() {
285
324
@ Override
286
325
protected void onPostResume () {
287
326
super .onPostResume ();
288
- loadMapFragment ();
327
+ // if(checkLocationEnabledPermission())
328
+ // loadMapFragment();
289
329
}
290
330
291
331
@ Override
@@ -352,7 +392,6 @@ private void handleSignInResult(GoogleSignInResult result) {
352
392
}
353
393
354
394
private void addLoginInfo (GoogleSignInAccount acct ) {
355
- // TODO : add Profile Picture
356
395
SharedPreferences .Editor editor = mSharedPreferences .edit ();
357
396
editor .putBoolean (LOGGED_IN , true );
358
397
if (acct .getDisplayName () != null )
@@ -403,6 +442,7 @@ private void loadAddNewPrivyActivity() {
403
442
}
404
443
405
444
private void loadMapFragment () {
445
+ navigationView .getMenu ().getItem (0 ).setChecked (true );
406
446
if (!checkLocationEnabledPermission ()) {
407
447
ActivityCompat .requestPermissions (this , new String []{android .Manifest .permission .ACCESS_FINE_LOCATION }, MY_PERMISSIONS_REQUEST_FINE_LOCATIONS );
408
448
} else {
0 commit comments