Main activity responsible for managing the UI and navigation between fragments in the Contacts List app.
- Initializes the activity when created.
- Sets content view to "activity_main" layout.
- Initializes the fragment manager.
- Adds ContactsFragment to the activity.
- Callback method triggered when the user wants to add a new contact.
- Replaces the current fragment with CreateContactFragment, allowing the user to create a new contact.
- Callback method triggered when the user selects a contact.
- Replaces the current fragment with DetailsFragment, displaying details of the selected contact.
- Callback method triggered when the user cancels creating a new contact.
- Removes the current CreateContactFragment from the back stack, returning to the previous fragment.
- Callback method triggered when the user finishes creating a new contact.
- Removes the current CreateContactFragment from the back stack, returning to the previous fragment.
Fragment responsible for fetching contacts data from an API and populating a RecyclerView.
- Inflates the layout for the fragment.
- Returns the root view.
- Sets up the fragment's UI components and functionality.
- Sets the title of the activity to "Contacts".
- Initializes RecyclerView and its adapter.
- Calls getContactsApi() to fetch contacts data.
- Sets OnClickListener for the "Add Contact" button to navigate to CreateContactFragment.
- Makes a GET request to fetch contacts data from the API.
- Parses the JSON response to populate the contacts list.
- Notifies the adapter of data changes to update the RecyclerView.
- Makes a POST request to delete a contact using its ID.
- If successful, re-fetches the contacts data to update the list.
- Displays a toast message if the deletion is unsuccessful.
RecyclerView adapter for displaying contacts.
- Inflates the layout for each contact list item.
- Binds contact data to the ViewHolder.
- Returns the total number of contacts.
ViewHolder class for individual contact items.
- Binds contact data to the ViewHolder's views.
- Sets OnClickListener for clicking on a contact item to navigate to its details.
- Sets OnClickListener for clicking on the delete icon to delete the contact.
Interface for communication with the hosting activity.
- gotoAddContact(): Navigates to the Add Contact screen.
- gotoContactDetails(Contact contact): Navigates to the details screen of a specific contact.
Fragment responsible for adding a new contact by making a POST request to the API.
- Inflates the layout for the fragment.
- Returns the root view.
- Sets up the fragment's UI components and functionality.
- Sets the title of the activity to "Add Contact".
- Sets OnClickListener for the "Cancel" button.
- Sets OnClickListener for the "Submit" button to validate input fields and call createContact().
- Makes a POST request to create a new contact using the provided details.
- Displays a success message and notifies the hosting activity upon successful creation.
- Displays an error message if the creation is unsuccessful.
Interface for communication with the hosting activity.
- cancelCreateContact(): Notifies the hosting activity to cancel creating a new contact.
- doneCreateContact(): Notifies the hosting activity upon successful creation of a new contact.
Represents a contact object retrieved from the API response.
- Contact(JSONObject jsonObject): Constructs a Contact object from a JSON object received from the API response.
- Parses the JSON object to extract contact details such as ID, name, email, phone, and phone type.
Implements Serializable interface to allow Contact objects to be serialized and passed between components in Android applications.
Represents a fragment to display detailed information about a contact.
- DetailsFragment(): Default constructor.
- newInstance(Contact contact): Creates a new instance of DetailsFragment with the provided contact object as an argument.
- ARG_PARAM_CONTACT: Key for passing the contact object as an argument to the fragment.
- onCreate(Bundle savedInstanceState): Initializes the fragment and retrieves the contact object from the arguments bundle.
- onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState): Inflates the layout for the fragment.
- onViewCreated(View view, Bundle savedInstanceState): Called after the fragment's view has been created. Sets up the UI components with the contact details.
- textViewName: Displays the contact name.
- textViewEmail: Displays the contact email.
- textViewPhone: Displays the contact phone number.
- textViewPhoneType: Displays the type of phone number (e.g., CELL, HOME, OFFICE).
All APIs Tested Using Postman