File tree Expand file tree Collapse file tree
src/main/java/seedu/address/ui Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -174,18 +174,22 @@ private void initializeProfile() {
174174 .sorted (Comparator .comparing (tag -> tag .tagName ))
175175 .forEach (tag -> tags .getChildren ().add (new Label (tag .tagName )));
176176 try {
177- this .imgProfile .setImage (retrieveImage ());
177+ Image clientProfileImage = retrieveImage (client .getName ().fullName );
178+ if (clientProfileImage .getException () == null ) {
179+ // no exception means client profile image existed
180+ this .imgProfile .setImage (clientProfileImage );
181+ }
178182 } catch (NullPointerException | IllegalArgumentException e ) {
183+ assert false : "Should not reach here" ;
179184 logger .info ("Invalid image url, using default image\n Exception: " + e );
180185 }
181186
182187 }
183188
184- private Image retrieveImage () {
185- // Set image based on client's name first character. Skipping if invalid url found.
186- // Just to make the app a bit nicer with real human image
187- return new Image ("/images/profile-"
188- + ((client .getName ().fullName .toLowerCase ().charAt (0 ) - 'a' ) / 6 + 1 ) + ".jpg" );
189+ private Image retrieveImage (String fullname ) {
190+ // find image based on client's fullname, in lower case, dashed. Example: Alex Yeoh -> profile-alex-yeoh.jpg
191+ String sluggedName = String .join ("-" , fullname .split ("\\ s+" )).toLowerCase ();
192+ return new Image ("file:data/images/profile-" + sluggedName + ".jpg" );
189193 }
190194
191195 @ SuppressWarnings ("unchecked" )
You can’t perform that action at this time.
0 commit comments