From df646522f9f8b6a5ca4cbff6420435a0c862791f Mon Sep 17 00:00:00 2001 From: tanguoyang <64419996+tanguoyang@users.noreply.github.com> Date: Mon, 18 Mar 2024 17:50:53 +0800 Subject: [PATCH 01/13] Add profile picture --- src/main/java/seedu/address/MainApp.java | 1 + .../address/logic/commands/EditCommand.java | 10 ++++++- .../logic/parser/AddCommandParser.java | 8 +++-- .../seedu/address/logic/parser/CliSyntax.java | 2 ++ .../address/logic/parser/ParserUtil.java | 11 +++++++ .../seedu/address/model/person/Person.java | 7 ++++- .../address/model/util/SampleDataUtil.java | 15 ++++++---- .../address/storage/JsonAdaptedPerson.java | 5 +++- .../java/seedu/address/ui/PersonCard.java | 23 +++++++++++++++ src/main/resources/view/PersonListCard.fxml | 29 ++++++++++--------- 10 files changed, 85 insertions(+), 26 deletions(-) diff --git a/src/main/java/seedu/address/MainApp.java b/src/main/java/seedu/address/MainApp.java index 3d6bd06d5af..5be8365fbfb 100644 --- a/src/main/java/seedu/address/MainApp.java +++ b/src/main/java/seedu/address/MainApp.java @@ -168,6 +168,7 @@ protected UserPrefs initPrefs(UserPrefsStorage storage) { return initializedPrefs; } + @Override public void start(Stage primaryStage) { logger.info("Starting AddressBook " + MainApp.VERSION); diff --git a/src/main/java/seedu/address/logic/commands/EditCommand.java b/src/main/java/seedu/address/logic/commands/EditCommand.java index 06112d89ae8..172e258903b 100644 --- a/src/main/java/seedu/address/logic/commands/EditCommand.java +++ b/src/main/java/seedu/address/logic/commands/EditCommand.java @@ -110,9 +110,10 @@ private static Person createEditedPerson(Person personToEdit, EditPersonDescript editPersonDescriptor.getGitHubUsername().orElse(personToEdit.getGitHubUsername()); Set updatedTechStack = editPersonDescriptor.getTechStack().orElse(personToEdit.getTechStack()); Set updatedTags = editPersonDescriptor.getTags().orElse(personToEdit.getTags()); + String profilePictureURL = editPersonDescriptor.getProfilePictureURL().orElse(personToEdit.getProfilePictureURL()); return new Person(updatedName, updatedPhone, updatedEmail, updatedAddress, updatedGitHubUsername, - updatedTechStack, updatedTags); + updatedTechStack, updatedTags, profilePictureURL); } @Override @@ -152,6 +153,8 @@ public static class EditPersonDescriptor { private Set techStack; private Set tags; + private String profilePictureURL; + public EditPersonDescriptor() {} /** @@ -166,6 +169,7 @@ public EditPersonDescriptor(EditPersonDescriptor toCopy) { setGitHubUsername(toCopy.gitHubUsername); setTechStack(toCopy.techStack); setTags(toCopy.tags); + setProfilePictureURL(toCopy.profilePictureURL); } /** @@ -215,6 +219,10 @@ public Optional getGitHubUsername() { return Optional.ofNullable(gitHubUsername); } + public void setProfilePictureURL(String url) {this.profilePictureURL = url; } + + public Optional getProfilePictureURL() {return Optional.ofNullable(this.profilePictureURL);} + /** * Sets {@code techStack} to this object's {@code techStack}. * A defensive copy of {@code techStack} is used internally. diff --git a/src/main/java/seedu/address/logic/parser/AddCommandParser.java b/src/main/java/seedu/address/logic/parser/AddCommandParser.java index 9c0f55e04a4..ef003d2eaa3 100644 --- a/src/main/java/seedu/address/logic/parser/AddCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/AddCommandParser.java @@ -8,6 +8,7 @@ import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE; import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG; import static seedu.address.logic.parser.CliSyntax.PREFIX_TECH_STACK; +import static seedu.address.logic.parser.CliSyntax.PREFIX_PROFILE_PICTURE; import java.util.Set; import java.util.stream.Stream; @@ -36,7 +37,7 @@ public class AddCommandParser implements Parser { public AddCommand parse(String args) throws ParseException { ArgumentMultimap argMultimap = ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ADDRESS, - PREFIX_GITHUB_USERNAME, PREFIX_TECH_STACK, PREFIX_TAG); + PREFIX_GITHUB_USERNAME, PREFIX_TECH_STACK, PREFIX_TAG, PREFIX_PROFILE_PICTURE); if (!arePrefixesPresent(argMultimap, PREFIX_NAME, PREFIX_ADDRESS, PREFIX_GITHUB_USERNAME, PREFIX_PHONE, PREFIX_EMAIL) @@ -45,7 +46,7 @@ public AddCommand parse(String args) throws ParseException { } argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ADDRESS, - PREFIX_GITHUB_USERNAME); + PREFIX_GITHUB_USERNAME, PREFIX_PROFILE_PICTURE); Name name = ParserUtil.parseName(argMultimap.getValue(PREFIX_NAME).get()); Phone phone = ParserUtil.parsePhone(argMultimap.getValue(PREFIX_PHONE).get()); Email email = ParserUtil.parseEmail(argMultimap.getValue(PREFIX_EMAIL).get()); @@ -54,8 +55,9 @@ public AddCommand parse(String args) throws ParseException { Address address = ParserUtil.parseAddress(argMultimap.getValue(PREFIX_ADDRESS).get()); Set techStackList = ParserUtil.parseTechStacks(argMultimap.getAllValues(PREFIX_TECH_STACK)); Set tagList = ParserUtil.parseTags(argMultimap.getAllValues(PREFIX_TAG)); + String profilePictureURL = ParserUtil.parseProfilePictureURL(argMultimap.getValue(PREFIX_PROFILE_PICTURE).get()); - Person person = new Person(name, phone, email, address, gitHubUsername, techStackList, tagList); + Person person = new Person(name, phone, email, address, gitHubUsername, techStackList, tagList, profilePictureURL ); return new AddCommand(person); } diff --git a/src/main/java/seedu/address/logic/parser/CliSyntax.java b/src/main/java/seedu/address/logic/parser/CliSyntax.java index 55ab48255e2..2d00f0eb618 100644 --- a/src/main/java/seedu/address/logic/parser/CliSyntax.java +++ b/src/main/java/seedu/address/logic/parser/CliSyntax.java @@ -14,4 +14,6 @@ public class CliSyntax { public static final Prefix PREFIX_TECH_STACK = new Prefix("ts/"); public static final Prefix PREFIX_TAG = new Prefix("t/"); + public static final Prefix PREFIX_PROFILE_PICTURE = new Prefix("/pp"); + } diff --git a/src/main/java/seedu/address/logic/parser/ParserUtil.java b/src/main/java/seedu/address/logic/parser/ParserUtil.java index 357d5fbe301..138d65bc663 100644 --- a/src/main/java/seedu/address/logic/parser/ParserUtil.java +++ b/src/main/java/seedu/address/logic/parser/ParserUtil.java @@ -82,6 +82,17 @@ public static Address parseAddress(String address) throws ParseException { return new Address(trimmedAddress); } + /** + * Parses a {@code String profilePictureURL} into an {@code String}. + * Leading and trailing whitespaces will be trimmed. + * + * @throws ParseException if the given {@code address} is invalid. + */ + public static String parseProfilePictureURL(String profilePictureURLArgument) { + requireNonNull(profilePictureURLArgument); + return profilePictureURLArgument.trim(); + } + /** * Parses a {@code String address} into an {@code Address}. * Leading and trailing whitespaces will be trimmed. diff --git a/src/main/java/seedu/address/model/person/Person.java b/src/main/java/seedu/address/model/person/Person.java index 4e278d6b74c..ef97bffb9de 100644 --- a/src/main/java/seedu/address/model/person/Person.java +++ b/src/main/java/seedu/address/model/person/Person.java @@ -28,13 +28,16 @@ public class Person { private final Set techStack = new HashSet<>(); private final Set tags = new HashSet<>(); + private String profilePictureURL; + /** * Every field must be present and not null. */ public Person(Name name, Phone phone, Email email, Address address, GitHubUsername gitHubUsername, - Set techStack, Set tags) { + Set techStack, Set tags, String profilePictureURL ) { requireAllNonNull(name, phone, email, address, tags); this.name = name; + this.profilePictureURL = profilePictureURL; this.phone = phone; this.email = email; this.address = address; @@ -55,6 +58,8 @@ public Email getEmail() { return email; } + public String getProfilePictureURL() {return profilePictureURL; } + public Address getAddress() { return address; } diff --git a/src/main/java/seedu/address/model/util/SampleDataUtil.java b/src/main/java/seedu/address/model/util/SampleDataUtil.java index b9b9d8c18f3..e6d08cb927f 100644 --- a/src/main/java/seedu/address/model/util/SampleDataUtil.java +++ b/src/main/java/seedu/address/model/util/SampleDataUtil.java @@ -20,26 +20,29 @@ * Contains utility methods for populating {@code AddressBook} with sample data. */ public class SampleDataUtil { + + final static String SAMPLE_PROFILE_PICTURE_URL = "https://static.vecteezy.com/system/resources/previews/019/766/19" + + "8/non_2x/apple-logo-apple-icon-transparent-free-png.png"; public static Person[] getSamplePersons() { return new Person[] { new Person(new Name("Alex Yeoh"), new Phone("87438807"), new Email("alexyeoh@example.com"), new Address("Blk 30 Geylang Street 29, #06-40"), new GitHubUsername("alexYeohhh"), - getTechStackSet("React"), getTagSet("friends")), + getTechStackSet("React"), getTagSet("friends"), SAMPLE_PROFILE_PICTURE_URL), new Person(new Name("Bernice Yu"), new Phone("99272758"), new Email("berniceyu@example.com"), new Address("Blk 30 Lorong 3 Serangoon Gardens, #07-18"), new GitHubUsername("Berney-Yu"), - getTechStackSet("Docker"), getTagSet("colleagues", "friends")), + getTechStackSet("Docker"), getTagSet("colleagues", "friends"), SAMPLE_PROFILE_PICTURE_URL), new Person(new Name("Charlotte Oliveiro"), new Phone("93210283"), new Email("charlotte@example.com"), new Address("Blk 11 Ang Mo Kio Street 74, #11-04"), new GitHubUsername("Charloove666"), - getTechStackSet("JavaScript", "C++"), getTagSet("neighbours")), + getTechStackSet("JavaScript", "C++"), getTagSet("neighbours"), SAMPLE_PROFILE_PICTURE_URL), new Person(new Name("David Li"), new Phone("91031282"), new Email("lidavid@example.com"), new Address("Blk 436 Serangoon Gardens Street 26, #16-43"), new GitHubUsername("DavidLi987"), - getTechStackSet("C#"), getTagSet("family")), + getTechStackSet("C#"), getTagSet("family"), SAMPLE_PROFILE_PICTURE_URL), new Person(new Name("Irfan Ibrahim"), new Phone("92492021"), new Email("irfan@example.com"), new Address("Blk 47 Tampines Street 20, #17-35"), new GitHubUsername("IrfyIb"), - getTechStackSet("SQL", "Django"), getTagSet("classmates")), + getTechStackSet("SQL", "Django"), getTagSet("classmates"), SAMPLE_PROFILE_PICTURE_URL), new Person(new Name("Roy Balakrishnan"), new Phone("92624417"), new Email("royb@example.com"), new Address("Blk 45 Aljunied Street 85, #11-31"), new GitHubUsername("BalaRoyy"), - getTechStackSet("Python"), getTagSet("colleagues")) + getTechStackSet("Python"), getTagSet("colleagues"), SAMPLE_PROFILE_PICTURE_URL) }; } diff --git a/src/main/java/seedu/address/storage/JsonAdaptedPerson.java b/src/main/java/seedu/address/storage/JsonAdaptedPerson.java index bdc4269ac51..aed3172bbd2 100644 --- a/src/main/java/seedu/address/storage/JsonAdaptedPerson.java +++ b/src/main/java/seedu/address/storage/JsonAdaptedPerson.java @@ -34,6 +34,9 @@ class JsonAdaptedPerson { private final List techStack = new ArrayList<>(); private final List tags = new ArrayList<>(); + final static String SAMPLE_PROFILE_PICTURE_URL = "https://static.vecteezy.com/system/resources/previews/019/766/19" + + "8/non_2x/apple-logo-apple-icon-transparent-free-png.png"; + /** * Constructs a {@code JsonAdaptedPerson} with the given person details. */ @@ -134,7 +137,7 @@ public Person toModelType() throws IllegalValueException { final Set modelTags = new HashSet<>(personTags); return new Person(modelName, modelPhone, modelEmail, modelAddress, modelGitHubUsername, modelTechStack, - modelTags); + modelTags, SAMPLE_PROFILE_PICTURE_URL); } } diff --git a/src/main/java/seedu/address/ui/PersonCard.java b/src/main/java/seedu/address/ui/PersonCard.java index 64e4441fe97..853e088ea9e 100644 --- a/src/main/java/seedu/address/ui/PersonCard.java +++ b/src/main/java/seedu/address/ui/PersonCard.java @@ -4,10 +4,16 @@ import javafx.fxml.FXML; import javafx.scene.control.Label; +import javafx.scene.image.Image; +import javafx.scene.image.ImageView; import javafx.scene.layout.FlowPane; import javafx.scene.layout.HBox; import javafx.scene.layout.Region; import seedu.address.model.person.Person; +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import java.net.URLConnection; /** * An UI component that displays information of a {@code Person}. @@ -45,12 +51,15 @@ public class PersonCard extends UiPart { @FXML private HBox tags; + @FXML + private ImageView profilePicture; /** * Creates a {@code PersonCode} with the given {@code Person} and index to display. */ public PersonCard(Person person, int displayedIndex) { super(FXML); this.person = person; + profilePicture.setImage(new Image(person.getProfilePictureURL())); id.setText(displayedIndex + ". "); name.setText(person.getName().fullName); phone.setText("Phone: " + person.getPhone().value); @@ -65,4 +74,18 @@ public PersonCard(Person person, int displayedIndex) { .sorted(Comparator.comparing(tag-> tag.tagName)) .forEach(tag -> tags.getChildren().add(new Label(tag.tagName))); } + + private Image loadImage(String imageUrl) { + try { + URL url = new URL(imageUrl); + URLConnection connection = url.openConnection(); + try (InputStream inputStream = connection.getInputStream()) { + return new Image(inputStream); + } + } catch (IOException e) { + e.printStackTrace(); + return null; + } + } + } diff --git a/src/main/resources/view/PersonListCard.fxml b/src/main/resources/view/PersonListCard.fxml index 9fe017af8ba..315a57492d1 100644 --- a/src/main/resources/view/PersonListCard.fxml +++ b/src/main/resources/view/PersonListCard.fxml @@ -1,34 +1,32 @@ - - - - - - - + + + + - + - + - + + - + + + From 03869858714bdd4be575a089c4c7040e2b53431e Mon Sep 17 00:00:00 2001 From: tanguoyang <64419996+tanguoyang@users.noreply.github.com> Date: Thu, 21 Mar 2024 17:33:10 +0800 Subject: [PATCH 02/13] Add placeholder profilepicture and fix bugs --- .../address/logic/commands/AddCommand.java | 11 ++----- .../address/logic/commands/EditCommand.java | 33 +++++++------------ .../logic/parser/AddCommandParser.java | 13 +++----- .../seedu/address/logic/parser/CliSyntax.java | 3 +- .../logic/parser/EditCommandParser.java | 16 ++++----- .../address/logic/parser/ParserUtil.java | 13 +++----- .../seedu/address/model/person/Person.java | 8 ++--- .../address/model/person/ProfilePicture.java | 21 ++++++++++++ .../address/model/util/SampleDataUtil.java | 22 +++++-------- .../address/storage/JsonAdaptedPerson.java | 9 ++--- .../java/seedu/address/ui/PersonCard.java | 14 +------- 11 files changed, 67 insertions(+), 96 deletions(-) create mode 100644 src/main/java/seedu/address/model/person/ProfilePicture.java diff --git a/src/main/java/seedu/address/logic/commands/AddCommand.java b/src/main/java/seedu/address/logic/commands/AddCommand.java index 718671cfdc1..ef20fc533bd 100644 --- a/src/main/java/seedu/address/logic/commands/AddCommand.java +++ b/src/main/java/seedu/address/logic/commands/AddCommand.java @@ -1,13 +1,7 @@ package seedu.address.logic.commands; import static java.util.Objects.requireNonNull; -import static seedu.address.logic.parser.CliSyntax.PREFIX_ADDRESS; -import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL; -import static seedu.address.logic.parser.CliSyntax.PREFIX_GITHUB_USERNAME; -import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME; -import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE; -import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG; -import static seedu.address.logic.parser.CliSyntax.PREFIX_TECH_STACK; +import static seedu.address.logic.parser.CliSyntax.*; import seedu.address.commons.util.ToStringBuilder; import seedu.address.logic.Messages; @@ -28,7 +22,8 @@ public class AddCommand extends Command { + PREFIX_PHONE + "PHONE " + PREFIX_EMAIL + "EMAIL " + PREFIX_ADDRESS + "ADDRESS " - + PREFIX_GITHUB_USERNAME + "GITHUB USERNAME " + + PREFIX_GITHUB_USERNAME + "GITHUB_USERNAME " + + PREFIX_PROFILE_PICTURE + "PROFILE_PICTURE" + "[" + PREFIX_TECH_STACK + "TECH STACK]...\n" + "[" + PREFIX_TAG + "TAG]...\n" + "Example: " + COMMAND_WORD + " " diff --git a/src/main/java/seedu/address/logic/commands/EditCommand.java b/src/main/java/seedu/address/logic/commands/EditCommand.java index 172e258903b..4a5125a5970 100644 --- a/src/main/java/seedu/address/logic/commands/EditCommand.java +++ b/src/main/java/seedu/address/logic/commands/EditCommand.java @@ -1,13 +1,7 @@ package seedu.address.logic.commands; import static java.util.Objects.requireNonNull; -import static seedu.address.logic.parser.CliSyntax.PREFIX_ADDRESS; -import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL; -import static seedu.address.logic.parser.CliSyntax.PREFIX_GITHUB_USERNAME; -import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME; -import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE; -import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG; -import static seedu.address.logic.parser.CliSyntax.PREFIX_TECH_STACK; +import static seedu.address.logic.parser.CliSyntax.*; import static seedu.address.model.Model.PREDICATE_SHOW_ALL_PERSONS; import java.util.Collections; @@ -23,12 +17,7 @@ import seedu.address.logic.Messages; import seedu.address.logic.commands.exceptions.CommandException; import seedu.address.model.Model; -import seedu.address.model.person.Address; -import seedu.address.model.person.Email; -import seedu.address.model.person.GitHubUsername; -import seedu.address.model.person.Name; -import seedu.address.model.person.Person; -import seedu.address.model.person.Phone; +import seedu.address.model.person.*; import seedu.address.model.tag.Tag; import seedu.address.model.techstack.TechStack; @@ -48,6 +37,7 @@ public class EditCommand extends Command { + "[" + PREFIX_EMAIL + "EMAIL] " + "[" + PREFIX_ADDRESS + "ADDRESS] " + "[" + PREFIX_GITHUB_USERNAME + "GITHUB USERNAME]" + + "[" + PREFIX_PROFILE_PICTURE + "PROFILE_PICTURE]" + "[" + PREFIX_TECH_STACK + "TECH_STACK...\n" + "[" + PREFIX_TAG + "TAG]...\n" + "Example: " + COMMAND_WORD + " 1 " @@ -110,10 +100,10 @@ private static Person createEditedPerson(Person personToEdit, EditPersonDescript editPersonDescriptor.getGitHubUsername().orElse(personToEdit.getGitHubUsername()); Set updatedTechStack = editPersonDescriptor.getTechStack().orElse(personToEdit.getTechStack()); Set updatedTags = editPersonDescriptor.getTags().orElse(personToEdit.getTags()); - String profilePictureURL = editPersonDescriptor.getProfilePictureURL().orElse(personToEdit.getProfilePictureURL()); + ProfilePicture updatedProfilePicture = editPersonDescriptor.getProfilePicture().orElse(personToEdit.getProfilePicture()); return new Person(updatedName, updatedPhone, updatedEmail, updatedAddress, updatedGitHubUsername, - updatedTechStack, updatedTags, profilePictureURL); + updatedTechStack, updatedTags, updatedProfilePicture); } @Override @@ -153,7 +143,7 @@ public static class EditPersonDescriptor { private Set techStack; private Set tags; - private String profilePictureURL; + private ProfilePicture profilePicture; public EditPersonDescriptor() {} @@ -169,7 +159,7 @@ public EditPersonDescriptor(EditPersonDescriptor toCopy) { setGitHubUsername(toCopy.gitHubUsername); setTechStack(toCopy.techStack); setTags(toCopy.tags); - setProfilePictureURL(toCopy.profilePictureURL); + setProfilePicture(toCopy.profilePicture); } /** @@ -177,7 +167,7 @@ public EditPersonDescriptor(EditPersonDescriptor toCopy) { */ public boolean isAnyFieldEdited() { return CollectionUtil.isAnyNonNull(name, phone, email, address, - gitHubUsername, techStack, tags); + gitHubUsername, techStack, tags, profilePicture); } public void setName(Name name) { @@ -219,9 +209,9 @@ public Optional getGitHubUsername() { return Optional.ofNullable(gitHubUsername); } - public void setProfilePictureURL(String url) {this.profilePictureURL = url; } + public void setProfilePicture(ProfilePicture profilePicture) {this.profilePicture = profilePicture; } - public Optional getProfilePictureURL() {return Optional.ofNullable(this.profilePictureURL);} + public Optional getProfilePicture() {return Optional.ofNullable(this.profilePicture);} /** * Sets {@code techStack} to this object's {@code techStack}. @@ -275,7 +265,8 @@ public boolean equals(Object other) { && Objects.equals(address, otherEditPersonDescriptor.address) && Objects.equals(gitHubUsername, otherEditPersonDescriptor.gitHubUsername) && Objects.equals(techStack, otherEditPersonDescriptor.techStack) - && Objects.equals(tags, otherEditPersonDescriptor.tags); + && Objects.equals(tags, otherEditPersonDescriptor.tags) + && Objects.equals(profilePicture, otherEditPersonDescriptor.profilePicture); } @Override diff --git a/src/main/java/seedu/address/logic/parser/AddCommandParser.java b/src/main/java/seedu/address/logic/parser/AddCommandParser.java index ef003d2eaa3..e2f92c26536 100644 --- a/src/main/java/seedu/address/logic/parser/AddCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/AddCommandParser.java @@ -15,12 +15,7 @@ import seedu.address.logic.commands.AddCommand; import seedu.address.logic.parser.exceptions.ParseException; -import seedu.address.model.person.Address; -import seedu.address.model.person.Email; -import seedu.address.model.person.GitHubUsername; -import seedu.address.model.person.Name; -import seedu.address.model.person.Person; -import seedu.address.model.person.Phone; +import seedu.address.model.person.*; import seedu.address.model.tag.Tag; import seedu.address.model.techstack.TechStack; @@ -37,7 +32,7 @@ public class AddCommandParser implements Parser { public AddCommand parse(String args) throws ParseException { ArgumentMultimap argMultimap = ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ADDRESS, - PREFIX_GITHUB_USERNAME, PREFIX_TECH_STACK, PREFIX_TAG, PREFIX_PROFILE_PICTURE); + PREFIX_GITHUB_USERNAME, PREFIX_PROFILE_PICTURE, PREFIX_TECH_STACK, PREFIX_TAG); if (!arePrefixesPresent(argMultimap, PREFIX_NAME, PREFIX_ADDRESS, PREFIX_GITHUB_USERNAME, PREFIX_PHONE, PREFIX_EMAIL) @@ -55,9 +50,9 @@ public AddCommand parse(String args) throws ParseException { Address address = ParserUtil.parseAddress(argMultimap.getValue(PREFIX_ADDRESS).get()); Set techStackList = ParserUtil.parseTechStacks(argMultimap.getAllValues(PREFIX_TECH_STACK)); Set tagList = ParserUtil.parseTags(argMultimap.getAllValues(PREFIX_TAG)); - String profilePictureURL = ParserUtil.parseProfilePictureURL(argMultimap.getValue(PREFIX_PROFILE_PICTURE).get()); + ProfilePicture profilePicture = ParserUtil.parseProfilePicture(argMultimap.getValue(PREFIX_PROFILE_PICTURE).orElse("")); - Person person = new Person(name, phone, email, address, gitHubUsername, techStackList, tagList, profilePictureURL ); + Person person = new Person(name, phone, email, address, gitHubUsername, techStackList, tagList, profilePicture ); return new AddCommand(person); } diff --git a/src/main/java/seedu/address/logic/parser/CliSyntax.java b/src/main/java/seedu/address/logic/parser/CliSyntax.java index 2d00f0eb618..ff6c3f75a96 100644 --- a/src/main/java/seedu/address/logic/parser/CliSyntax.java +++ b/src/main/java/seedu/address/logic/parser/CliSyntax.java @@ -13,7 +13,6 @@ public class CliSyntax { public static final Prefix PREFIX_GITHUB_USERNAME = new Prefix("g/"); public static final Prefix PREFIX_TECH_STACK = new Prefix("ts/"); public static final Prefix PREFIX_TAG = new Prefix("t/"); - - public static final Prefix PREFIX_PROFILE_PICTURE = new Prefix("/pp"); + public static final Prefix PREFIX_PROFILE_PICTURE = new Prefix("pp/"); } diff --git a/src/main/java/seedu/address/logic/parser/EditCommandParser.java b/src/main/java/seedu/address/logic/parser/EditCommandParser.java index 08de36c2f2f..eb788e7d19a 100644 --- a/src/main/java/seedu/address/logic/parser/EditCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/EditCommandParser.java @@ -2,13 +2,7 @@ import static java.util.Objects.requireNonNull; import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; -import static seedu.address.logic.parser.CliSyntax.PREFIX_ADDRESS; -import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL; -import static seedu.address.logic.parser.CliSyntax.PREFIX_GITHUB_USERNAME; -import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME; -import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE; -import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG; -import static seedu.address.logic.parser.CliSyntax.PREFIX_TECH_STACK; +import static seedu.address.logic.parser.CliSyntax.*; import java.util.Collection; import java.util.Collections; @@ -36,7 +30,7 @@ public EditCommand parse(String args) throws ParseException { requireNonNull(args); ArgumentMultimap argMultimap = ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ADDRESS, - PREFIX_GITHUB_USERNAME, PREFIX_TECH_STACK, PREFIX_TAG); + PREFIX_GITHUB_USERNAME, PREFIX_PROFILE_PICTURE, PREFIX_TECH_STACK, PREFIX_TAG); Index index; @@ -47,7 +41,7 @@ public EditCommand parse(String args) throws ParseException { } argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ADDRESS, - PREFIX_GITHUB_USERNAME); + PREFIX_GITHUB_USERNAME, PREFIX_PROFILE_PICTURE); EditPersonDescriptor editPersonDescriptor = new EditPersonDescriptor(); @@ -67,6 +61,10 @@ public EditCommand parse(String args) throws ParseException { editPersonDescriptor.setAddress( ParserUtil.parseAddress(argMultimap.getValue(PREFIX_GITHUB_USERNAME).get())); } + if (argMultimap.getValue(PREFIX_PROFILE_PICTURE).isPresent()) { + editPersonDescriptor.setProfilePicture(ParserUtil.parseProfilePicture(argMultimap. + getValue(PREFIX_PROFILE_PICTURE).get())); + } parseTechStackForEdit(argMultimap.getAllValues(PREFIX_TECH_STACK)) .ifPresent(editPersonDescriptor::setTechStack); parseTagsForEdit(argMultimap.getAllValues(PREFIX_TAG)).ifPresent(editPersonDescriptor::setTags); diff --git a/src/main/java/seedu/address/logic/parser/ParserUtil.java b/src/main/java/seedu/address/logic/parser/ParserUtil.java index 138d65bc663..941ce40b728 100644 --- a/src/main/java/seedu/address/logic/parser/ParserUtil.java +++ b/src/main/java/seedu/address/logic/parser/ParserUtil.java @@ -9,11 +9,7 @@ import seedu.address.commons.core.index.Index; import seedu.address.commons.util.StringUtil; import seedu.address.logic.parser.exceptions.ParseException; -import seedu.address.model.person.Address; -import seedu.address.model.person.Email; -import seedu.address.model.person.GitHubUsername; -import seedu.address.model.person.Name; -import seedu.address.model.person.Phone; +import seedu.address.model.person.*; import seedu.address.model.tag.Tag; import seedu.address.model.techstack.TechStack; @@ -83,14 +79,13 @@ public static Address parseAddress(String address) throws ParseException { } /** - * Parses a {@code String profilePictureURL} into an {@code String}. + * Parses a {@code String profilePictureURL} into an {@code ProfilePicture}. * Leading and trailing whitespaces will be trimmed. * * @throws ParseException if the given {@code address} is invalid. */ - public static String parseProfilePictureURL(String profilePictureURLArgument) { - requireNonNull(profilePictureURLArgument); - return profilePictureURLArgument.trim(); + public static ProfilePicture parseProfilePicture(String profilePictureURLArgument) { + return new ProfilePicture(profilePictureURLArgument); } /** diff --git a/src/main/java/seedu/address/model/person/Person.java b/src/main/java/seedu/address/model/person/Person.java index ef97bffb9de..8099eac4cbf 100644 --- a/src/main/java/seedu/address/model/person/Person.java +++ b/src/main/java/seedu/address/model/person/Person.java @@ -28,16 +28,16 @@ public class Person { private final Set techStack = new HashSet<>(); private final Set tags = new HashSet<>(); - private String profilePictureURL; + private final ProfilePicture profilePicture; /** * Every field must be present and not null. */ public Person(Name name, Phone phone, Email email, Address address, GitHubUsername gitHubUsername, - Set techStack, Set tags, String profilePictureURL ) { + Set techStack, Set tags, ProfilePicture profilePicture) { requireAllNonNull(name, phone, email, address, tags); this.name = name; - this.profilePictureURL = profilePictureURL; + this.profilePicture = profilePicture; this.phone = phone; this.email = email; this.address = address; @@ -58,7 +58,7 @@ public Email getEmail() { return email; } - public String getProfilePictureURL() {return profilePictureURL; } + public ProfilePicture getProfilePicture() {return profilePicture; } public Address getAddress() { return address; diff --git a/src/main/java/seedu/address/model/person/ProfilePicture.java b/src/main/java/seedu/address/model/person/ProfilePicture.java new file mode 100644 index 00000000000..8b949bdb6ec --- /dev/null +++ b/src/main/java/seedu/address/model/person/ProfilePicture.java @@ -0,0 +1,21 @@ +package seedu.address.model.person; + +import static java.util.Objects.requireNonNull; +import static seedu.address.commons.util.AppUtil.checkArgument; + +public class ProfilePicture { + String DEFAULT_URL = "https://api-prod-minimal-v510.vercel.app/assets/images/avatar/avatar_13.jpg"; + String url; + public ProfilePicture(String url) { + this.url = url; + } + + public String get() { + if (this.url.isBlank()) { + return DEFAULT_URL; + } + return this.url; + } + + +} diff --git a/src/main/java/seedu/address/model/util/SampleDataUtil.java b/src/main/java/seedu/address/model/util/SampleDataUtil.java index e6d08cb927f..18b8c8d3d37 100644 --- a/src/main/java/seedu/address/model/util/SampleDataUtil.java +++ b/src/main/java/seedu/address/model/util/SampleDataUtil.java @@ -6,12 +6,7 @@ import seedu.address.model.AddressBook; import seedu.address.model.ReadOnlyAddressBook; -import seedu.address.model.person.Address; -import seedu.address.model.person.Email; -import seedu.address.model.person.GitHubUsername; -import seedu.address.model.person.Name; -import seedu.address.model.person.Person; -import seedu.address.model.person.Phone; +import seedu.address.model.person.*; import seedu.address.model.tag.Tag; import seedu.address.model.techstack.TechStack; @@ -21,28 +16,27 @@ */ public class SampleDataUtil { - final static String SAMPLE_PROFILE_PICTURE_URL = "https://static.vecteezy.com/system/resources/previews/019/766/19" + - "8/non_2x/apple-logo-apple-icon-transparent-free-png.png"; + public static Person[] getSamplePersons() { return new Person[] { new Person(new Name("Alex Yeoh"), new Phone("87438807"), new Email("alexyeoh@example.com"), new Address("Blk 30 Geylang Street 29, #06-40"), new GitHubUsername("alexYeohhh"), - getTechStackSet("React"), getTagSet("friends"), SAMPLE_PROFILE_PICTURE_URL), + getTechStackSet("React"), getTagSet("friends"), new ProfilePicture("")), new Person(new Name("Bernice Yu"), new Phone("99272758"), new Email("berniceyu@example.com"), new Address("Blk 30 Lorong 3 Serangoon Gardens, #07-18"), new GitHubUsername("Berney-Yu"), - getTechStackSet("Docker"), getTagSet("colleagues", "friends"), SAMPLE_PROFILE_PICTURE_URL), + getTechStackSet("Docker"), getTagSet("colleagues", "friends"),new ProfilePicture("")), new Person(new Name("Charlotte Oliveiro"), new Phone("93210283"), new Email("charlotte@example.com"), new Address("Blk 11 Ang Mo Kio Street 74, #11-04"), new GitHubUsername("Charloove666"), - getTechStackSet("JavaScript", "C++"), getTagSet("neighbours"), SAMPLE_PROFILE_PICTURE_URL), + getTechStackSet("JavaScript", "C++"), getTagSet("neighbours"), new ProfilePicture("")), new Person(new Name("David Li"), new Phone("91031282"), new Email("lidavid@example.com"), new Address("Blk 436 Serangoon Gardens Street 26, #16-43"), new GitHubUsername("DavidLi987"), - getTechStackSet("C#"), getTagSet("family"), SAMPLE_PROFILE_PICTURE_URL), + getTechStackSet("C#"), getTagSet("family"), new ProfilePicture("")), new Person(new Name("Irfan Ibrahim"), new Phone("92492021"), new Email("irfan@example.com"), new Address("Blk 47 Tampines Street 20, #17-35"), new GitHubUsername("IrfyIb"), - getTechStackSet("SQL", "Django"), getTagSet("classmates"), SAMPLE_PROFILE_PICTURE_URL), + getTechStackSet("SQL", "Django"), getTagSet("classmates"),new ProfilePicture("")), new Person(new Name("Roy Balakrishnan"), new Phone("92624417"), new Email("royb@example.com"), new Address("Blk 45 Aljunied Street 85, #11-31"), new GitHubUsername("BalaRoyy"), - getTechStackSet("Python"), getTagSet("colleagues"), SAMPLE_PROFILE_PICTURE_URL) + getTechStackSet("Python"), getTagSet("colleagues"), new ProfilePicture("")) }; } diff --git a/src/main/java/seedu/address/storage/JsonAdaptedPerson.java b/src/main/java/seedu/address/storage/JsonAdaptedPerson.java index aed3172bbd2..75843d5d518 100644 --- a/src/main/java/seedu/address/storage/JsonAdaptedPerson.java +++ b/src/main/java/seedu/address/storage/JsonAdaptedPerson.java @@ -10,12 +10,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; import seedu.address.commons.exceptions.IllegalValueException; -import seedu.address.model.person.Address; -import seedu.address.model.person.Email; -import seedu.address.model.person.GitHubUsername; -import seedu.address.model.person.Name; -import seedu.address.model.person.Person; -import seedu.address.model.person.Phone; +import seedu.address.model.person.*; import seedu.address.model.tag.Tag; import seedu.address.model.techstack.TechStack; @@ -137,7 +132,7 @@ public Person toModelType() throws IllegalValueException { final Set modelTags = new HashSet<>(personTags); return new Person(modelName, modelPhone, modelEmail, modelAddress, modelGitHubUsername, modelTechStack, - modelTags, SAMPLE_PROFILE_PICTURE_URL); + modelTags, new ProfilePicture("")); } } diff --git a/src/main/java/seedu/address/ui/PersonCard.java b/src/main/java/seedu/address/ui/PersonCard.java index 853e088ea9e..2dddc1a6dd6 100644 --- a/src/main/java/seedu/address/ui/PersonCard.java +++ b/src/main/java/seedu/address/ui/PersonCard.java @@ -59,7 +59,7 @@ public class PersonCard extends UiPart { public PersonCard(Person person, int displayedIndex) { super(FXML); this.person = person; - profilePicture.setImage(new Image(person.getProfilePictureURL())); + profilePicture.setImage(new Image(person.getProfilePicture().get())); id.setText(displayedIndex + ". "); name.setText(person.getName().fullName); phone.setText("Phone: " + person.getPhone().value); @@ -75,17 +75,5 @@ public PersonCard(Person person, int displayedIndex) { .forEach(tag -> tags.getChildren().add(new Label(tag.tagName))); } - private Image loadImage(String imageUrl) { - try { - URL url = new URL(imageUrl); - URLConnection connection = url.openConnection(); - try (InputStream inputStream = connection.getInputStream()) { - return new Image(inputStream); - } - } catch (IOException e) { - e.printStackTrace(); - return null; - } - } } From 7438f1824ed41e6a51a5d358900dfc01d3021329 Mon Sep 17 00:00:00 2001 From: tanguoyang <64419996+tanguoyang@users.noreply.github.com> Date: Thu, 21 Mar 2024 23:57:22 +0800 Subject: [PATCH 03/13] Add profile picture tests --- build.gradle | 2 +- .../address/logic/commands/AddCommand.java | 2 +- .../address/logic/commands/EditCommand.java | 33 ++++++++------- .../logic/parser/AddCommandParser.java | 2 + .../logic/parser/EditCommandParser.java | 2 +- .../address/logic/parser/ParserUtil.java | 1 + .../seedu/address/model/contact/Contact.java | 2 + .../address/model/contact/ProfilePicture.java | 19 +++++++-- .../address/model/util/SampleDataUtil.java | 4 +- .../address/storage/JsonAdaptedContact.java | 3 +- .../java/seedu/address/ui/ContactCard.java | 8 +--- .../model/contact/ProfilePictureTest.java | 42 +++++++++++++++++++ .../address/testutil/ContactBuilder.java | 17 ++++---- 13 files changed, 97 insertions(+), 40 deletions(-) create mode 100644 src/test/java/seedu/address/model/contact/ProfilePictureTest.java diff --git a/build.gradle b/build.gradle index 8cd88833649..7eeb77e6d7e 100644 --- a/build.gradle +++ b/build.gradle @@ -21,7 +21,7 @@ repositories { //} test { - // useJUnitPlatform() + useJUnitPlatform() finalizedBy jacocoTestReport } diff --git a/src/main/java/seedu/address/logic/commands/AddCommand.java b/src/main/java/seedu/address/logic/commands/AddCommand.java index 36fac08bed1..44fbfd68f07 100644 --- a/src/main/java/seedu/address/logic/commands/AddCommand.java +++ b/src/main/java/seedu/address/logic/commands/AddCommand.java @@ -23,7 +23,7 @@ public class AddCommand extends Command { + PREFIX_EMAIL + "EMAIL " + PREFIX_ADDRESS + "ADDRESS " + PREFIX_GITHUB_USERNAME + "GITHUB_USERNAME " - + PREFIX_PROFILE_PICTURE + "PROFILE_PICTURE" + + PREFIX_PROFILE_PICTURE + "PROFILE_PICTURE " + "[" + PREFIX_TECH_STACK + "TECH STACK]...\n" + "[" + PREFIX_TAG + "TAG]...\n" + "Example: " + COMMAND_WORD + " " diff --git a/src/main/java/seedu/address/logic/commands/EditCommand.java b/src/main/java/seedu/address/logic/commands/EditCommand.java index 85ebf22aa30..804662df88d 100644 --- a/src/main/java/seedu/address/logic/commands/EditCommand.java +++ b/src/main/java/seedu/address/logic/commands/EditCommand.java @@ -8,6 +8,7 @@ import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE; import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG; import static seedu.address.logic.parser.CliSyntax.PREFIX_TECH_STACK; +import static seedu.address.logic.parser.CliSyntax.PREFIX_PROFILE_PICTURE; import static seedu.address.model.Model.PREDICATE_SHOW_ALL_CONTACTS; import java.util.Collections; @@ -31,6 +32,7 @@ import seedu.address.model.contact.Phone; import seedu.address.model.tag.Tag; import seedu.address.model.techstack.TechStack; +import seedu.address.model.contact.ProfilePicture; /** * Edits the details of an existing contact in the address book. @@ -108,12 +110,12 @@ private static Contact createEditedContact(Contact contactToEdit, EditContactDes Email updatedEmail = editContactDescriptor.getEmail().orElse(contactToEdit.getEmail()); Address updatedAddress = editContactDescriptor.getAddress().orElse(contactToEdit.getAddress()); GitHubUsername updatedGitHubUsername = - editPersonDescriptor.getGitHubUsername().orElse(personToEdit.getGitHubUsername()); - Set updatedTechStack = editPersonDescriptor.getTechStack().orElse(personToEdit.getTechStack()); - Set updatedTags = editPersonDescriptor.getTags().orElse(personToEdit.getTags()); - ProfilePicture updatedProfilePicture = editPersonDescriptor.getProfilePicture().orElse(personToEdit.getProfilePicture()); + editContactDescriptor.getGitHubUsername().orElse(contactToEdit.getGitHubUsername()); + Set updatedTechStack = editContactDescriptor.getTechStack().orElse(contactToEdit.getTechStack()); + Set updatedTags = editContactDescriptor.getTags().orElse(contactToEdit.getTags()); + ProfilePicture updatedProfilePicture = editContactDescriptor.getProfilePicture().orElse(contactToEdit.getProfilePicture()); - return new Person(updatedName, updatedPhone, updatedEmail, updatedAddress, updatedGitHubUsername, + return new Contact(updatedName, updatedPhone, updatedEmail, updatedAddress, updatedGitHubUsername, updatedTechStack, updatedTags, updatedProfilePicture); } @@ -156,7 +158,6 @@ public static class EditContactDescriptor { private ProfilePicture profilePicture; - public EditPersonDescriptor() {} /** * Copy constructor. @@ -173,6 +174,8 @@ public EditContactDescriptor(EditContactDescriptor toCopy) { setProfilePicture(toCopy.profilePicture); } + public EditContactDescriptor() {} + /** * Returns true if at least one field is edited. */ @@ -269,15 +272,15 @@ public boolean equals(Object other) { return false; } - EditPersonDescriptor otherEditPersonDescriptor = (EditPersonDescriptor) other; - return Objects.equals(name, otherEditPersonDescriptor.name) - && Objects.equals(phone, otherEditPersonDescriptor.phone) - && Objects.equals(email, otherEditPersonDescriptor.email) - && Objects.equals(address, otherEditPersonDescriptor.address) - && Objects.equals(gitHubUsername, otherEditPersonDescriptor.gitHubUsername) - && Objects.equals(techStack, otherEditPersonDescriptor.techStack) - && Objects.equals(tags, otherEditPersonDescriptor.tags) - && Objects.equals(profilePicture, otherEditPersonDescriptor.profilePicture); + EditContactDescriptor otherEditContactDescriptor = (EditContactDescriptor) other; + return Objects.equals(name, otherEditContactDescriptor.name) + && Objects.equals(phone, otherEditContactDescriptor.phone) + && Objects.equals(email, otherEditContactDescriptor.email) + && Objects.equals(address, otherEditContactDescriptor.address) + && Objects.equals(gitHubUsername, otherEditContactDescriptor.gitHubUsername) + && Objects.equals(techStack, otherEditContactDescriptor.techStack) + && Objects.equals(tags, otherEditContactDescriptor.tags) + && Objects.equals(profilePicture, otherEditContactDescriptor.profilePicture); } @Override diff --git a/src/main/java/seedu/address/logic/parser/AddCommandParser.java b/src/main/java/seedu/address/logic/parser/AddCommandParser.java index e52076ca2e2..b71f0c57ea0 100644 --- a/src/main/java/seedu/address/logic/parser/AddCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/AddCommandParser.java @@ -10,6 +10,7 @@ import static seedu.address.logic.parser.CliSyntax.PREFIX_TECH_STACK; import static seedu.address.logic.parser.CliSyntax.PREFIX_PROFILE_PICTURE; + import java.util.Set; import java.util.stream.Stream; @@ -21,6 +22,7 @@ import seedu.address.model.contact.Name; import seedu.address.model.contact.Contact; import seedu.address.model.contact.Phone; +import seedu.address.model.contact.ProfilePicture; import seedu.address.model.tag.Tag; import seedu.address.model.techstack.TechStack; diff --git a/src/main/java/seedu/address/logic/parser/EditCommandParser.java b/src/main/java/seedu/address/logic/parser/EditCommandParser.java index cb2dee34005..38f75f51047 100644 --- a/src/main/java/seedu/address/logic/parser/EditCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/EditCommandParser.java @@ -62,7 +62,7 @@ public EditCommand parse(String args) throws ParseException { ParserUtil.parseGitHubUsername(argMultimap.getValue(PREFIX_GITHUB_USERNAME).get())); } if (argMultimap.getValue(PREFIX_PROFILE_PICTURE).isPresent()) { - editPersonDescriptor.setProfilePicture(ParserUtil.parseProfilePicture(argMultimap. + editContactDescriptor.setProfilePicture(ParserUtil.parseProfilePicture(argMultimap. getValue(PREFIX_PROFILE_PICTURE).get())); } parseTechStackForEdit(argMultimap.getAllValues(PREFIX_TECH_STACK)) diff --git a/src/main/java/seedu/address/logic/parser/ParserUtil.java b/src/main/java/seedu/address/logic/parser/ParserUtil.java index 8903f618a24..6686858c4b1 100644 --- a/src/main/java/seedu/address/logic/parser/ParserUtil.java +++ b/src/main/java/seedu/address/logic/parser/ParserUtil.java @@ -14,6 +14,7 @@ import seedu.address.model.contact.GitHubUsername; import seedu.address.model.contact.Name; import seedu.address.model.contact.Phone; +import seedu.address.model.contact.ProfilePicture; import seedu.address.model.tag.Tag; import seedu.address.model.techstack.TechStack; diff --git a/src/main/java/seedu/address/model/contact/Contact.java b/src/main/java/seedu/address/model/contact/Contact.java index d0a8de4d18e..34e9de378f0 100644 --- a/src/main/java/seedu/address/model/contact/Contact.java +++ b/src/main/java/seedu/address/model/contact/Contact.java @@ -9,6 +9,8 @@ import seedu.address.commons.util.ToStringBuilder; import seedu.address.model.tag.Tag; +import seedu.address.model.contact.ProfilePicture; + import seedu.address.model.techstack.TechStack; /** diff --git a/src/main/java/seedu/address/model/contact/ProfilePicture.java b/src/main/java/seedu/address/model/contact/ProfilePicture.java index 8b949bdb6ec..c19f930a20a 100644 --- a/src/main/java/seedu/address/model/contact/ProfilePicture.java +++ b/src/main/java/seedu/address/model/contact/ProfilePicture.java @@ -1,21 +1,34 @@ -package seedu.address.model.person; +package seedu.address.model.contact; + +import java.util.Objects; import static java.util.Objects.requireNonNull; import static seedu.address.commons.util.AppUtil.checkArgument; public class ProfilePicture { - String DEFAULT_URL = "https://api-prod-minimal-v510.vercel.app/assets/images/avatar/avatar_13.jpg"; + final static String DEFAULT_URL = "https://api-prod-minimal-v510.vercel.app/assets/images/avatar/avatar_13.jpg"; String url; public ProfilePicture(String url) { this.url = url; } public String get() { - if (this.url.isBlank()) { + if (this.url == null || this.url.isBlank()) { return DEFAULT_URL; } return this.url; } + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + ProfilePicture that = (ProfilePicture) o; + return Objects.equals(url, that.url); + } + @Override + public int hashCode() { + return Objects.hash(url); + } } diff --git a/src/main/java/seedu/address/model/util/SampleDataUtil.java b/src/main/java/seedu/address/model/util/SampleDataUtil.java index 8e2006d1c1a..aae3cb6830b 100644 --- a/src/main/java/seedu/address/model/util/SampleDataUtil.java +++ b/src/main/java/seedu/address/model/util/SampleDataUtil.java @@ -4,9 +4,6 @@ import java.util.Set; import java.util.stream.Collectors; -import seedu.address.model.AddressBook; -import seedu.address.model.ReadOnlyAddressBook; -import seedu.address.model.person.*; import seedu.address.model.CodeConnect; import seedu.address.model.ReadOnlyCodeConnect; import seedu.address.model.contact.Address; @@ -17,6 +14,7 @@ import seedu.address.model.contact.Phone; import seedu.address.model.tag.Tag; import seedu.address.model.techstack.TechStack; +import seedu.address.model.contact.ProfilePicture; /** diff --git a/src/main/java/seedu/address/storage/JsonAdaptedContact.java b/src/main/java/seedu/address/storage/JsonAdaptedContact.java index 44e8e028974..992664b21ca 100644 --- a/src/main/java/seedu/address/storage/JsonAdaptedContact.java +++ b/src/main/java/seedu/address/storage/JsonAdaptedContact.java @@ -10,7 +10,6 @@ import com.fasterxml.jackson.annotation.JsonProperty; import seedu.address.commons.exceptions.IllegalValueException; -import seedu.address.model.person.*; import seedu.address.model.contact.Address; import seedu.address.model.contact.Contact; import seedu.address.model.contact.Email; @@ -19,7 +18,7 @@ import seedu.address.model.contact.Phone; import seedu.address.model.tag.Tag; import seedu.address.model.techstack.TechStack; - +import seedu.address.model.contact.ProfilePicture; /** * Jackson-friendly version of {@link Contact}. */ diff --git a/src/main/java/seedu/address/ui/ContactCard.java b/src/main/java/seedu/address/ui/ContactCard.java index 9cd343dbeea..be234eb3924 100644 --- a/src/main/java/seedu/address/ui/ContactCard.java +++ b/src/main/java/seedu/address/ui/ContactCard.java @@ -6,16 +6,10 @@ import javafx.scene.control.Label; import javafx.scene.image.Image; import javafx.scene.image.ImageView; -import javafx.scene.layout.FlowPane; import javafx.scene.layout.HBox; import javafx.scene.layout.Region; import seedu.address.logic.MailApp; -import seedu.address.model.person.Person; -import java.io.IOException; -import java.io.InputStream; -import java.net.URL; -import java.net.URLConnection; import seedu.address.model.contact.Contact; /** @@ -64,7 +58,7 @@ public class ContactCard extends UiPart { public ContactCard(Contact contact, int displayedIndex) { super(FXML); this.contact = contact; - profilePicture.setImage(new Image(person.getProfilePicture().get())); + profilePicture.setImage(new Image(contact.getProfilePicture().get())); id.setText(displayedIndex + ". "); name.setText(contact.getName().fullName); phone.setText("Phone: " + contact.getPhone().value); diff --git a/src/test/java/seedu/address/model/contact/ProfilePictureTest.java b/src/test/java/seedu/address/model/contact/ProfilePictureTest.java new file mode 100644 index 00000000000..68ae04f5628 --- /dev/null +++ b/src/test/java/seedu/address/model/contact/ProfilePictureTest.java @@ -0,0 +1,42 @@ +package seedu.address.model.contact; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class ProfilePictureTest { + + @Test + public void constructor_validUrl_success() { + String validUrl = "https://example.com/image.jpg"; + ProfilePicture profilePicture = new ProfilePicture(validUrl); + assertEquals(validUrl, profilePicture.get()); + } + + @Test + public void constructor_blankUrl_returnsDefaultUrl() { + ProfilePicture profilePicture = new ProfilePicture(""); + assertEquals(ProfilePicture.DEFAULT_URL, profilePicture.get()); + } + + @Test + public void constructor_nullUrl_returnsDefaultUrl() { + ProfilePicture profilePicture = new ProfilePicture(null); + assertEquals(ProfilePicture.DEFAULT_URL, profilePicture.get()); + } + + @Test + public void equals_sameUrl_returnsTrue() { + String url = "https://example.com/image.jpg"; + ProfilePicture profilePicture1 = new ProfilePicture(url); + ProfilePicture profilePicture2 = new ProfilePicture(url); + assertEquals(profilePicture1, profilePicture2); + } + + @Test + public void equals_differentUrls_returnsFalse() { + ProfilePicture profilePicture1 = new ProfilePicture("https://example.com/image1.jpg"); + ProfilePicture profilePicture2 = new ProfilePicture("https://example.com/image2.jpg"); + assertEquals(false, profilePicture1.equals(profilePicture2)); + } +} diff --git a/src/test/java/seedu/address/testutil/ContactBuilder.java b/src/test/java/seedu/address/testutil/ContactBuilder.java index ee00f6d92ec..6012ad5f1e3 100644 --- a/src/test/java/seedu/address/testutil/ContactBuilder.java +++ b/src/test/java/seedu/address/testutil/ContactBuilder.java @@ -3,12 +3,7 @@ import java.util.HashSet; import java.util.Set; -import seedu.address.model.contact.Address; -import seedu.address.model.contact.Contact; -import seedu.address.model.contact.Email; -import seedu.address.model.contact.GitHubUsername; -import seedu.address.model.contact.Name; -import seedu.address.model.contact.Phone; +import seedu.address.model.contact.*; import seedu.address.model.tag.Tag; import seedu.address.model.techstack.TechStack; import seedu.address.model.util.SampleDataUtil; @@ -31,6 +26,7 @@ public class ContactBuilder { private GitHubUsername gitHubUsername; private Set techStack; private Set tags; + private ProfilePicture profilePicture; /** * Creates a {@code ContactBuilder} with the default details. @@ -43,6 +39,7 @@ public ContactBuilder() { gitHubUsername = new GitHubUsername(DEFAULT_GITHUB_USERNAME); techStack = new HashSet<>(); tags = new HashSet<>(); + profilePicture = new ProfilePicture(""); } /** @@ -56,6 +53,7 @@ public ContactBuilder(Contact contactToCopy) { gitHubUsername = contactToCopy.getGitHubUsername(); techStack = new HashSet<>(contactToCopy.getTechStack()); tags = new HashSet<>(contactToCopy.getTags()); + profilePicture = new ProfilePicture(""); } /** @@ -114,8 +112,13 @@ public ContactBuilder withGitHubUsername(String gitHubUsername) { return this; } + public ContactBuilder withProfilePicture(String url) { + this.profilePicture = new ProfilePicture(url); + return this; + } + public Contact build() { - return new Contact(name, phone, email, address, gitHubUsername, techStack, tags); + return new Contact(name, phone, email, address, gitHubUsername, techStack, tags, profilePicture); } From 82eae3176dd8e12a3088e39ee9241853373b0293 Mon Sep 17 00:00:00 2001 From: tanguoyang <64419996+tanguoyang@users.noreply.github.com> Date: Fri, 22 Mar 2024 09:54:44 +0800 Subject: [PATCH 04/13] Update UserGuide.md --- docs/UserGuide.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/UserGuide.md b/docs/UserGuide.md index ffa79f3fcc9..9b9bd7f035c 100644 --- a/docs/UserGuide.md +++ b/docs/UserGuide.md @@ -78,7 +78,7 @@ Format: `help` Adds a contact to the address book. -Format: `add n/NAME p/PHONE_NUMBER e/EMAIL a/ADDRESS g/GITHUB_USERNAME [t/TAG] [ts/TECH_STACK]…​` +Format: `add n/NAME p/PHONE_NUMBER e/EMAIL a/ADDRESS g/GITHUB_USERNAME [t/TAG] pp/PROFILE_PICTURE [ts/TECH_STACK]…​` @@ -87,8 +87,8 @@ Format: `add n/NAME p/PHONE_NUMBER e/EMAIL a/ADDRESS g/GITHUB_USERNAME [t/TAG] [ Examples: -- `add n/John Doe p/98765432 e/johnd@example.com a/John street, block 123, #01-01 g/johnDoee` -- `add n/Betsy Crowe t/friend e/betsycrowe@example.com a/Newgate Prison p/1234567 g/betBetty t/criminal ts/Flutter` +- `add n/John Doe p/98765432 e/johnd@example.com a/John street, block 123, #01-01 g/johnDoee pp/www.profilepicture.png` +- `add n/Betsy Crowe t/friend e/betsycrowe@example.com a/Newgate Prison p/1234567 g/betBetty t/criminal ts/Flutter pp/www.profilepicture.png` ### Listing all contacts : `list` @@ -106,7 +106,7 @@ How to use: Click on the contact's email. Edits an existing contact in the address book. -Format: `edit INDEX [n/NAME] [p/PHONE] [e/EMAIL] [a/ADDRESS] [g/GITHUB_USERNAME] [t/TAG]…​ [ts/TECH_STACK]…​` +Format: `edit INDEX [n/NAME] [p/PHONE] [e/EMAIL] [a/ADDRESS] [g/GITHUB_USERNAME] [pp/PROFILE_PICTURE] [t/TAG]…​ [ts/TECH_STACK]…​` - Edits the contact at the specified `INDEX`. The index refers to the index number shown in the displayed contact list. The index **must be a positive integer** 1, 2, 3, …​ - At least one of the optional fields must be provided. From ed59eca97d3e75c60012430c572cb7c26f7118d7 Mon Sep 17 00:00:00 2001 From: tanguoyang <64419996+tanguoyang@users.noreply.github.com> Date: Fri, 22 Mar 2024 09:55:42 +0800 Subject: [PATCH 05/13] disable Junit tests --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 7eeb77e6d7e..400c26ed54c 100644 --- a/build.gradle +++ b/build.gradle @@ -21,7 +21,7 @@ repositories { //} test { - useJUnitPlatform() +// useJUnitPlatform() finalizedBy jacocoTestReport } From ed8488d9b25349dd7b84d17102cda37c855acd22 Mon Sep 17 00:00:00 2001 From: tanguoyang <64419996+tanguoyang@users.noreply.github.com> Date: Fri, 22 Mar 2024 18:15:16 +0800 Subject: [PATCH 06/13] Fix bugs 1. Fix profile picture not being stored 2. Fix invalid profile picture url breaking app 3. Update userguide --- docs/UserGuide.md | 26 +++++++++---------- .../java/seedu/address/logic/Messages.java | 2 ++ .../address/logic/commands/AddCommand.java | 2 ++ .../address/logic/commands/EditCommand.java | 2 +- .../logic/parser/EditCommandParser.java | 9 ++++++- .../seedu/address/model/contact/Contact.java | 5 ++-- .../address/model/contact/ProfilePicture.java | 2 +- .../address/storage/JsonAdaptedContact.java | 10 ++++++- .../java/seedu/address/ui/ContactCard.java | 12 ++++++++- src/main/resources/view/ContactListCard.fxml | 2 +- .../address/testutil/ContactBuilder.java | 11 +++++++- 11 files changed, 61 insertions(+), 22 deletions(-) diff --git a/docs/UserGuide.md b/docs/UserGuide.md index 9b9bd7f035c..f20c9230794 100644 --- a/docs/UserGuide.md +++ b/docs/UserGuide.md @@ -87,8 +87,8 @@ Format: `add n/NAME p/PHONE_NUMBER e/EMAIL a/ADDRESS g/GITHUB_USERNAME [t/TAG] p Examples: -- `add n/John Doe p/98765432 e/johnd@example.com a/John street, block 123, #01-01 g/johnDoee pp/www.profilepicture.png` -- `add n/Betsy Crowe t/friend e/betsycrowe@example.com a/Newgate Prison p/1234567 g/betBetty t/criminal ts/Flutter pp/www.profilepicture.png` +- `add n/John Doe p/98765432 e/johnd@example.com a/John street, block 123, #01-01 g/johnDoee pp/https://api-prod-minimal-v510.vercel.app/assets/images/avatar/avatar_1.jpg` +- `add n/Betsy Crowe t/friend e/betsycrowe@example.com a/Newgate Prison p/1234567 g/betBetty t/criminal ts/Flutter pp/https://api-prod-minimal-v510.vercel.app/assets/images/avatar/avatar_1.jpg` ### Listing all contacts : `list` @@ -232,14 +232,14 @@ _Details coming soon ..._ ## Command summary -| Action | Format, Examples | -|---------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| **Add** | `add n/NAME p/PHONE_NUMBER e/EMAIL a/ADDRESS g/GITHUB_USERNAME [t/TAG] [ts/TECH_STACK]…​`
e.g., `add n/James Ho p/22224444 e/jamesho@example.com a/123, Clementi Rd, 1234665 g/Jamesho123 t/friend t/colleague ts/Java ts/C++` | -| **Clear** | `clear` | -| **Delete** | `delete INDEX`
e.g., `delete 3` | -| **Edit** | `edit INDEX [n/NAME] [p/PHONE_NUMBER] [e/EMAIL] [a/ADDRESS] [g/GITHUB_USERNAME] [t/TAG]…​ [ts/TECH_STACK]…​ `
e.g.,`edit 2 n/James Lee e/jameslee@example.com` | -| **Find** | `find KEYWORD [MORE_KEYWORDS]`
e.g., `find James Jake` | -| **Find by Tags** | `find-tags KEYWORD [MORE_KEYWORDS]`
e.g., `find-tags School Work` | -| **Find Tech Stack** | `find-ts KEYWORD [MORE_KEYWORDS]`
e.g., `find-ts Java Python` | -| **List** | `list` | -| **Help** | `help` | +| Action | Format, Examples | +|---------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| **Add** | `add n/NAME p/PHONE_NUMBER e/EMAIL a/ADDRESS g/GITHUB_USERNAME pp/PROFILE_PICTURE [t/TAG] [ts/TECH_STACK]…​`
e.g., `add n/James Ho p/22224444 e/jamesho@example.com a/123, Clementi Rd, 1234665 g/Jamesho123 pp/https://api-prod-minimal-v510.vercel.app/assets/images/avatar/avatar_1.jpg t/friend t/colleague ts/Java ts/C++` | +| **Clear** | `clear` | +| **Delete** | `delete INDEX`
e.g., `delete 3` | +| **Edit** | `edit INDEX [n/NAME] [p/PHONE_NUMBER] [e/EMAIL] [a/ADDRESS] [g/GITHUB_USERNAME] [t/TAG]…​ [ts/TECH_STACK]…​ `
e.g.,`edit 2 n/James Lee e/jameslee@example.com` | +| **Find** | `find KEYWORD [MORE_KEYWORDS]`
e.g., `find James Jake` | +| **Find by Tags** | `find-tags KEYWORD [MORE_KEYWORDS]`
e.g., `find-tags School Work` | +| **Find Tech Stack** | `find-ts KEYWORD [MORE_KEYWORDS]`
e.g., `find-ts Java Python` | +| **List** | `list` | +| **Help** | `help` | diff --git a/src/main/java/seedu/address/logic/Messages.java b/src/main/java/seedu/address/logic/Messages.java index 65894c75bec..9f37b138bb4 100644 --- a/src/main/java/seedu/address/logic/Messages.java +++ b/src/main/java/seedu/address/logic/Messages.java @@ -45,6 +45,8 @@ public static String format(Contact contact) { .append(contact.getAddress()) .append("; GitHub Username: ") .append(contact.getGitHubUsername()) + .append("; Profile Picture: ") + .append(contact.getProfilePicture()) .append("; Tech Stack: "); contact.getTechStack().forEach(builder::append); builder.append("; Tags: "); diff --git a/src/main/java/seedu/address/logic/commands/AddCommand.java b/src/main/java/seedu/address/logic/commands/AddCommand.java index 44fbfd68f07..591742df049 100644 --- a/src/main/java/seedu/address/logic/commands/AddCommand.java +++ b/src/main/java/seedu/address/logic/commands/AddCommand.java @@ -8,6 +8,7 @@ import seedu.address.logic.commands.exceptions.CommandException; import seedu.address.model.Model; import seedu.address.model.contact.Contact; +import seedu.address.model.contact.ProfilePicture; /** * Adds a contact to the address book. @@ -32,6 +33,7 @@ public class AddCommand extends Command { + PREFIX_EMAIL + "johnd@example.com " + PREFIX_ADDRESS + "311, Clementi Ave 2, #02-25 " + PREFIX_GITHUB_USERNAME + "johndoee123 " + + PREFIX_PROFILE_PICTURE + ProfilePicture.DEFAULT_URL + PREFIX_TECH_STACK + "Java " + PREFIX_TECH_STACK + "Python " + PREFIX_TAG + "friends " diff --git a/src/main/java/seedu/address/logic/commands/EditCommand.java b/src/main/java/seedu/address/logic/commands/EditCommand.java index 804662df88d..53e2adbc105 100644 --- a/src/main/java/seedu/address/logic/commands/EditCommand.java +++ b/src/main/java/seedu/address/logic/commands/EditCommand.java @@ -225,7 +225,7 @@ public Optional getGitHubUsername() { public void setProfilePicture(ProfilePicture profilePicture) {this.profilePicture = profilePicture; } - public Optional getProfilePicture() {return Optional.ofNullable(this.profilePicture);} + public Optional getProfilePicture() { return Optional.ofNullable(this.profilePicture); } /** * Sets {@code techStack} to this object's {@code techStack}. diff --git a/src/main/java/seedu/address/logic/parser/EditCommandParser.java b/src/main/java/seedu/address/logic/parser/EditCommandParser.java index 38f75f51047..3756e52b524 100644 --- a/src/main/java/seedu/address/logic/parser/EditCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/EditCommandParser.java @@ -2,7 +2,14 @@ import static java.util.Objects.requireNonNull; import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; -import static seedu.address.logic.parser.CliSyntax.*; +import static seedu.address.logic.parser.CliSyntax.PREFIX_ADDRESS; +import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME; +import static seedu.address.logic.parser.CliSyntax.PREFIX_PROFILE_PICTURE; +import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE; +import static seedu.address.logic.parser.CliSyntax.PREFIX_GITHUB_USERNAME; +import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG; +import static seedu.address.logic.parser.CliSyntax.PREFIX_TECH_STACK; +import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL; import java.util.Collection; import java.util.Collections; diff --git a/src/main/java/seedu/address/model/contact/Contact.java b/src/main/java/seedu/address/model/contact/Contact.java index 34e9de378f0..6614a193324 100644 --- a/src/main/java/seedu/address/model/contact/Contact.java +++ b/src/main/java/seedu/address/model/contact/Contact.java @@ -9,7 +9,6 @@ import seedu.address.commons.util.ToStringBuilder; import seedu.address.model.tag.Tag; -import seedu.address.model.contact.ProfilePicture; import seedu.address.model.techstack.TechStack; @@ -60,7 +59,7 @@ public Email getEmail() { return email; } - public ProfilePicture getProfilePicture() {return profilePicture; } + public ProfilePicture getProfilePicture() { return profilePicture; } public Address getAddress() { return address; @@ -119,6 +118,7 @@ public boolean equals(Object other) { && email.equals(otherContact.email) && address.equals(otherContact.address) && gitHubUsername.equals(otherContact.gitHubUsername) + && profilePicture.equals(otherContact.profilePicture) && techStack.equals(otherContact.techStack) && tags.equals(otherContact.tags); } @@ -137,6 +137,7 @@ public String toString() { .add("email", email) .add("address", address) .add("github_username", gitHubUsername) + .add("profile_picture", profilePicture) .add("tech_stack", techStack) .add("tags", tags) .toString(); diff --git a/src/main/java/seedu/address/model/contact/ProfilePicture.java b/src/main/java/seedu/address/model/contact/ProfilePicture.java index c19f930a20a..e8f55df39f9 100644 --- a/src/main/java/seedu/address/model/contact/ProfilePicture.java +++ b/src/main/java/seedu/address/model/contact/ProfilePicture.java @@ -6,7 +6,7 @@ import static seedu.address.commons.util.AppUtil.checkArgument; public class ProfilePicture { - final static String DEFAULT_URL = "https://api-prod-minimal-v510.vercel.app/assets/images/avatar/avatar_13.jpg"; + public final static String DEFAULT_URL = "https://api-prod-minimal-v510.vercel.app/assets/images/avatar/avatar_13.jpg"; String url; public ProfilePicture(String url) { this.url = url; diff --git a/src/main/java/seedu/address/storage/JsonAdaptedContact.java b/src/main/java/seedu/address/storage/JsonAdaptedContact.java index 992664b21ca..4397e54fc84 100644 --- a/src/main/java/seedu/address/storage/JsonAdaptedContact.java +++ b/src/main/java/seedu/address/storage/JsonAdaptedContact.java @@ -31,9 +31,13 @@ class JsonAdaptedContact { private final String email; private final String address; private final String gitHubUsername; + private final String profilePicture; + private final List techStack = new ArrayList<>(); private final List tags = new ArrayList<>(); + + final static String SAMPLE_PROFILE_PICTURE_URL = "https://static.vecteezy.com/system/resources/previews/019/766/19" + "8/non_2x/apple-logo-apple-icon-transparent-free-png.png"; @@ -44,6 +48,7 @@ class JsonAdaptedContact { public JsonAdaptedContact(@JsonProperty("name") String name, @JsonProperty("phone") String phone, @JsonProperty("email") String email, @JsonProperty("address") String address, @JsonProperty ("github_username") String gitHubUsername, + @JsonProperty ("profile_picture") String profilePicture, @JsonProperty ("tech_stack") List techStack, @JsonProperty("tags") List tags) { this.name = name; @@ -51,6 +56,7 @@ public JsonAdaptedContact(@JsonProperty("name") String name, @JsonProperty("phon this.email = email; this.address = address; this.gitHubUsername = gitHubUsername; + this.profilePicture = profilePicture; if (techStack != null) { this.techStack.addAll(techStack); } @@ -68,6 +74,7 @@ public JsonAdaptedContact(Contact source) { email = source.getEmail().value; address = source.getAddress().value; gitHubUsername = source.getGitHubUsername().username; + profilePicture = source.getProfilePicture().get(); techStack.addAll(source.getTechStack().stream() .map(JsonAdaptedTechStack::new) .collect(Collectors.toList())); @@ -135,9 +142,10 @@ public Contact toModelType() throws IllegalValueException { final Set modelTechStack = new HashSet<>(personTechStack); final Set modelTags = new HashSet<>(personTags); + final ProfilePicture modelProfilePicture = new ProfilePicture(profilePicture); return new Contact(modelName, modelPhone, modelEmail, modelAddress, modelGitHubUsername, modelTechStack, - modelTags, new ProfilePicture("")); + modelTags, modelProfilePicture); } } diff --git a/src/main/java/seedu/address/ui/ContactCard.java b/src/main/java/seedu/address/ui/ContactCard.java index be234eb3924..34213ea3ca2 100644 --- a/src/main/java/seedu/address/ui/ContactCard.java +++ b/src/main/java/seedu/address/ui/ContactCard.java @@ -11,6 +11,7 @@ import javafx.scene.layout.Region; import seedu.address.logic.MailApp; import seedu.address.model.contact.Contact; +import seedu.address.model.contact.ProfilePicture; /** * An UI component that displays information of a {@code Contact}. @@ -58,7 +59,16 @@ public class ContactCard extends UiPart { public ContactCard(Contact contact, int displayedIndex) { super(FXML); this.contact = contact; - profilePicture.setImage(new Image(contact.getProfilePicture().get())); + + try { + Image image = new Image(contact.getProfilePicture().get()); + profilePicture.setImage(image); + } catch (IllegalArgumentException e) { + // Handle invalid image URL + System.err.println("Invalid image URL: " + contact.getProfilePicture().get()); + profilePicture.setImage(new Image(new ProfilePicture("").get())); + } + id.setText(displayedIndex + ". "); name.setText(contact.getName().fullName); phone.setText("Phone: " + contact.getPhone().value); diff --git a/src/main/resources/view/ContactListCard.fxml b/src/main/resources/view/ContactListCard.fxml index 0c4cd273d0a..e181908d96d 100644 --- a/src/main/resources/view/ContactListCard.fxml +++ b/src/main/resources/view/ContactListCard.fxml @@ -6,6 +6,7 @@ + @@ -14,7 +15,6 @@ -