diff --git a/app/build.gradle.kts b/app/build.gradle.kts index fb1fc485..553e6975 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -38,6 +38,10 @@ dependencies { implementation(libs.constraintlayout) implementation("com.google.android.material:material:1.11.0") implementation("androidx.viewpager2:viewpager2:1.1.0") + implementation("com.google.android.material:material:1.11.0") + implementation("androidx.camera:camera-camera2:1.3.0") + implementation("androidx.camera:camera-lifecycle:1.3.0") + implementation("androidx.camera:camera-view:1.3.0") testImplementation(libs.junit) androidTestImplementation(libs.ext.junit) androidTestImplementation(libs.espresso.core) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 9c70dc38..4925314b 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -2,6 +2,16 @@ + + + + + + - - - - - { + Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars()); + v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom); + return insets; + }); + + //get the bottom navbar from the layout + BottomNavigationView bottomNav = findViewById(R.id.bottom_navigation); + + // Load ListFragment by default + loadFragment(new ListFragment()); + bottomNav.setSelectedItemId(R.id.nav_list); + + //when an item in the bar is selected, load the corresponding fragment + bottomNav.setOnItemSelectedListener(item -> { + + if (item.getItemId() == R.id.nav_list) { + loadFragment(new ListFragment()); + return true; + } else if (item.getItemId() == R.id.nav_chat) { + loadFragment(new ChatFragment()); + return true; + } else if (item.getItemId() == R.id.nav_profile) { + loadFragment(new ProfileFragment()); + return true; + } + return false; + }); + } + + //helper function to load a fragment + private void loadFragment(Fragment fragment) { + getSupportFragmentManager() + .beginTransaction() + .replace(R.id.fragment_container, fragment) + .commit(); + } +} \ No newline at end of file diff --git a/app/src/main/java/com/example/petstoremobile/activities/MainActivity.java b/app/src/main/java/com/example/petstoremobile/activities/MainActivity.java index c531b272..e3f23b16 100644 --- a/app/src/main/java/com/example/petstoremobile/activities/MainActivity.java +++ b/app/src/main/java/com/example/petstoremobile/activities/MainActivity.java @@ -55,9 +55,9 @@ public class MainActivity extends AppCompatActivity { return; } - //check if username and password are correct + //check if username and password are correct TODO: Replace with actual login if (username.equals("admin") && password.equals("admin")) { - Intent intent = new Intent(this, PetActivity.class); + Intent intent = new Intent(this, HomeActivity.class); startActivity(intent); Toast.makeText(this, "Login successful", Toast.LENGTH_SHORT).show(); finish(); diff --git a/app/src/main/java/com/example/petstoremobile/activities/PetActivity.java b/app/src/main/java/com/example/petstoremobile/activities/PetActivity.java deleted file mode 100644 index 12530cab..00000000 --- a/app/src/main/java/com/example/petstoremobile/activities/PetActivity.java +++ /dev/null @@ -1,66 +0,0 @@ -package com.example.petstoremobile.activities; - -import android.content.Intent; -import android.os.Bundle; - -import androidx.activity.EdgeToEdge; -import androidx.core.graphics.Insets; -import androidx.core.view.ViewCompat; -import androidx.core.view.WindowInsetsCompat; -import androidx.recyclerview.widget.LinearLayoutManager; -import androidx.recyclerview.widget.RecyclerView; - -import com.example.petstoremobile.R; -import com.example.petstoremobile.activities.detailactivites.PetDetailActivity; -import com.example.petstoremobile.adapters.PetAdapter; -import com.example.petstoremobile.models.Pet; -import com.google.android.material.floatingactionbutton.FloatingActionButton; - -import java.util.ArrayList; -import java.util.List; - -public class PetActivity extends BaseActivity { - - private List petList = new ArrayList<>(); - private PetAdapter adapter; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - EdgeToEdge.enable(this); - setContentView(R.layout.activity_pets); - ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> { - Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars()); - v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom); - return insets; - }); - - loadPetData(); //TODO: Replace this with actual data when backend is working - setupRecyclerView(); - - // Add button opens the add dialog - FloatingActionButton fabAddPet = findViewById(R.id.fabAddPet); - fabAddPet.setOnClickListener(v -> { - Intent intent = new Intent(this, PetDetailActivity.class); - startActivity(intent); - }); - } - - // Loads hardcoded sample data for now TODO: REPLACE THIS WITH A METHOD THAT GETS DATA FROM THE DATABASE - private void loadPetData() { - petList.add(new Pet(1, "Buddy", "Dog", "Labrador", 2, "Available", 500.00)); - petList.add(new Pet(2, "Milo", "Cat", "Persian", 1, "Available", 300.00)); - petList.add(new Pet(3, "Charlie", "Dog", "Golden Retriever", 3, "Available", 550.00)); - petList.add(new Pet(4, "Luna", "Cat", "Siamese", 2, "Adopted", 350.00)); - petList.add(new Pet(5, "Max", "Dog", "Beagle", 1, "Available", 450.00)); - petList.add(new Pet(6, "Bella", "Cat", "Maine Coon", 4, "Available", 400.00)); - } - - //set up the recyclerview and adapter - private void setupRecyclerView() { - RecyclerView recyclerView = findViewById(R.id.recyclerViewPets); - adapter = new PetAdapter(petList, this); - recyclerView.setLayoutManager(new LinearLayoutManager(this)); - recyclerView.setAdapter(adapter); - } -} \ No newline at end of file diff --git a/app/src/main/java/com/example/petstoremobile/activities/ServiceActivity.java b/app/src/main/java/com/example/petstoremobile/activities/ServiceActivity.java deleted file mode 100644 index 07f105d9..00000000 --- a/app/src/main/java/com/example/petstoremobile/activities/ServiceActivity.java +++ /dev/null @@ -1,65 +0,0 @@ -package com.example.petstoremobile.activities; - -import android.content.Intent; -import android.os.Bundle; - -import androidx.activity.EdgeToEdge; -import androidx.core.graphics.Insets; -import androidx.core.view.ViewCompat; -import androidx.core.view.WindowInsetsCompat; -import androidx.recyclerview.widget.LinearLayoutManager; -import androidx.recyclerview.widget.RecyclerView; - -import com.example.petstoremobile.R; -import com.example.petstoremobile.activities.detailactivites.ServiceDetailActivity; -import com.example.petstoremobile.adapters.ServiceAdapter; -import com.example.petstoremobile.models.Service; -import com.google.android.material.floatingactionbutton.FloatingActionButton; - -import java.util.ArrayList; -import java.util.List; - -public class ServiceActivity extends BaseActivity { - - private List serviceList = new ArrayList<>(); - private ServiceAdapter adapter; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - EdgeToEdge.enable(this); - setContentView(R.layout.activity_services); - ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> { - Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars()); - v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom); - return insets; - }); - - loadServiceData(); - setupRecyclerView(); - - // Add button opens the add dialog - FloatingActionButton fabAddService = findViewById(R.id.fabAddService); - fabAddService.setOnClickListener(v -> { - Intent intent = new Intent(this, ServiceDetailActivity.class); - startActivity(intent); - }); - } - - // Loads hardcoded sample data for now TODO: REPLACE THIS WITH A METHOD THAT GETS DATA FROM THE DATABASE - private void loadServiceData() { - serviceList.add(new Service(1, "Pet Grooming", "Full grooming service", 60, 40.00)); - serviceList.add(new Service(2, "Nail Trimming", "Quick nail trim", 15, 10.00)); - serviceList.add(new Service(3, "Bath and Brush", "Bathing and brushing service", 45, 30.00)); - serviceList.add(new Service(4, "Veterinary Checkup", "Complete health examination", 30, 75.00)); - serviceList.add(new Service(5, "Teeth Cleaning", "Professional dental cleaning", 90, 100.00)); - } - - // Set up the RecyclerView and adapter - private void setupRecyclerView() { - RecyclerView recyclerView = findViewById(R.id.recyclerViewServices); - adapter = new ServiceAdapter(serviceList, this); - recyclerView.setLayoutManager(new LinearLayoutManager(this)); - recyclerView.setAdapter(adapter); - } -} \ No newline at end of file diff --git a/app/src/main/java/com/example/petstoremobile/activities/SupplierActivity.java b/app/src/main/java/com/example/petstoremobile/activities/SupplierActivity.java deleted file mode 100644 index 0b0f7f57..00000000 --- a/app/src/main/java/com/example/petstoremobile/activities/SupplierActivity.java +++ /dev/null @@ -1,68 +0,0 @@ -package com.example.petstoremobile.activities; - -import android.content.Intent; -import android.os.Bundle; - -import androidx.activity.EdgeToEdge; -import androidx.core.graphics.Insets; -import androidx.core.view.ViewCompat; -import androidx.core.view.WindowInsetsCompat; -import androidx.recyclerview.widget.LinearLayoutManager; -import androidx.recyclerview.widget.RecyclerView; - -import com.example.petstoremobile.R; -import com.example.petstoremobile.activities.detailactivites.SupplierDetailActivity; -import com.example.petstoremobile.adapters.SupplierAdapter; -import com.example.petstoremobile.models.Supplier; -import com.google.android.material.floatingactionbutton.FloatingActionButton; - -import java.util.ArrayList; -import java.util.List; - -public class SupplierActivity extends BaseActivity { - - private List supplierList = new ArrayList<>(); - private SupplierAdapter adapter; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - EdgeToEdge.enable(this); - setContentView(R.layout.activity_supplier); - - if (findViewById(R.id.main) != null) { - ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> { - Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars()); - v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom); - return insets; - }); - } - - loadSupplierData(); //TODO: Replace this with actual data when backend is working - setupRecyclerView(); - - // Add button opens the add dialog - FloatingActionButton fabAddSupplier = findViewById(R.id.fabAddSupplier); - fabAddSupplier.setOnClickListener(v -> { - Intent intent = new Intent(this, SupplierDetailActivity.class); - startActivity(intent); - }); - } - - // Loads hardcoded sample data for now TODO: REPLACE THIS WITH A METHOD THAT GETS DATA FROM THE DATABASE - private void loadSupplierData() { - supplierList.add(new Supplier(1, "PetCare Inc.", "John", "Doe", "john@petcare.com", "888-555-0101")); - supplierList.add(new Supplier(2, "Happy Tails", "Jane", "Smith", "jane@happytails.com", "888-555-0102")); - supplierList.add(new Supplier(3, "Animal Supplies Co.", "Mike", "Brown", "mike@animalsupplies.com", "888-555-0103")); - supplierList.add(new Supplier(4, "Groomers Choice", "Sarah", "Wilson", "sarah@groomerschoice.com", "888-555-0104")); - supplierList.add(new Supplier(5, "Healthy Pets", "Robert", "Miller", "robert@healthypets.com", "888-555-0105")); - } - - // set up the recyclerview and adapter - private void setupRecyclerView() { - RecyclerView recyclerView = findViewById(R.id.recyclerViewSuppliers); - adapter = new SupplierAdapter(supplierList, this); - recyclerView.setLayoutManager(new LinearLayoutManager(this)); - recyclerView.setAdapter(adapter); - } -} \ No newline at end of file diff --git a/app/src/main/java/com/example/petstoremobile/activities/detailactivites/PetDetailActivity.java b/app/src/main/java/com/example/petstoremobile/activities/detailactivites/PetDetailActivity.java deleted file mode 100644 index b605978d..00000000 --- a/app/src/main/java/com/example/petstoremobile/activities/detailactivites/PetDetailActivity.java +++ /dev/null @@ -1,127 +0,0 @@ -package com.example.petstoremobile.activities.detailactivites; - -import android.os.Bundle; -import android.view.View; -import android.widget.ArrayAdapter; -import android.widget.Button; -import android.widget.EditText; -import android.widget.Spinner; -import android.widget.TextView; -import android.widget.Toast; - -import androidx.activity.EdgeToEdge; -import androidx.appcompat.app.AppCompatActivity; -import androidx.core.graphics.Insets; -import androidx.core.view.ViewCompat; -import androidx.core.view.WindowInsetsCompat; - -import com.example.petstoremobile.R; - -public class PetDetailActivity extends AppCompatActivity { - - private TextView tvMode, tvPetId; - private EditText etPetName, etPetSpecies, etPetBreed, etPetAge, etPetPrice; - private Spinner spinnerPetStatus; - private Button btnSavePet, btnDeletePet, btnBack; - private int petId; - private boolean isEditing = false; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - EdgeToEdge.enable(this); - setContentView(R.layout.activity_pet_detail); - ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> { - Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars()); - v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom); - return insets; - }); - - //set up spinner and get controls from layout - initViews(); - setupSpinner(); - handleIntent(); - - btnBack.setOnClickListener(v -> finish()); - btnSavePet.setOnClickListener(v -> savePet()); - btnDeletePet.setOnClickListener(v -> deletePet()); - } - - //get controls from layout - private void initViews() { - tvMode = findViewById(R.id.tvMode); - tvPetId = findViewById(R.id.tvPetId); - etPetName = findViewById(R.id.etPetName); - etPetSpecies = findViewById(R.id.etPetSpecies); - etPetBreed = findViewById(R.id.etPetBreed); - etPetAge = findViewById(R.id.etPetAge); - etPetPrice = findViewById(R.id.etPetPrice); - spinnerPetStatus = findViewById(R.id.spinnerPetStatus); - btnSavePet = findViewById(R.id.btnSavePet); - btnDeletePet = findViewById(R.id.btnDeletePet); - btnBack = findViewById(R.id.btnBack); - } - - //set up the spinner menu for pet status - private void setupSpinner() { - ArrayAdapter adapter = new ArrayAdapter<>(this, - android.R.layout.simple_spinner_item, - new String[]{"Available", "Adopted"}); - adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); - spinnerPetStatus.setAdapter(adapter); - } - - //check if pet is being edited or added and show the view accordingly - private void handleIntent() { - // Pet is being edited - if (getIntent().hasExtra("petId")) { - // Get pet data from intent and populate fields - isEditing = true; - petId = getIntent().getIntExtra("petId", -1); - tvMode.setText("Edit Pet"); - tvPetId.setText("ID: " + petId); - etPetName.setText(getIntent().getStringExtra("petName")); - etPetSpecies.setText(getIntent().getStringExtra("petSpecies")); - etPetBreed.setText(getIntent().getStringExtra("petBreed")); - etPetAge.setText(String.valueOf(getIntent().getIntExtra("petAge", 0))); - etPetPrice.setText(String.valueOf(getIntent().getDoubleExtra("petPrice", 0.0))); - - // Set spinner selection based on pet status - String status = getIntent().getStringExtra("petStatus"); - if ("Available".equals(status)) { - spinnerPetStatus.setSelection(0); - } else { - spinnerPetStatus.setSelection(1); - } - - //Delete button is visible when editing - btnDeletePet.setVisibility(View.VISIBLE); - } else { - // Pet is being added - // Set default values for add a new pet - isEditing = false; - tvMode.setText("Add Pet"); - tvPetId.setVisibility(View.GONE); - btnDeletePet.setVisibility(View.GONE); - btnSavePet.setText("Add"); - } - } - - //TODO: Method to Update or Add a pet - private void savePet() { - if (isEditing) { - // TODO: Update pet - Toast.makeText(this, "Save functionality not yet implemented with DB", Toast.LENGTH_SHORT).show(); - } else { - // TODO: Add new pet - Toast.makeText(this, "Save functionality not yet implemented with DB", Toast.LENGTH_SHORT).show(); - } - finish(); - } - - //TODO: Method to Delete a pet - private void deletePet() { - Toast.makeText(this, "Delete functionality not yet implemented with DB", Toast.LENGTH_SHORT).show(); - finish(); - } -} \ No newline at end of file diff --git a/app/src/main/java/com/example/petstoremobile/activities/detailactivites/ServiceDetailActivity.java b/app/src/main/java/com/example/petstoremobile/activities/detailactivites/ServiceDetailActivity.java deleted file mode 100644 index c40084df..00000000 --- a/app/src/main/java/com/example/petstoremobile/activities/detailactivites/ServiceDetailActivity.java +++ /dev/null @@ -1,104 +0,0 @@ -package com.example.petstoremobile.activities.detailactivites; - -import android.os.Bundle; -import android.view.View; -import android.widget.Button; -import android.widget.EditText; -import android.widget.TextView; -import android.widget.Toast; - -import androidx.activity.EdgeToEdge; -import androidx.appcompat.app.AppCompatActivity; -import androidx.core.graphics.Insets; -import androidx.core.view.ViewCompat; -import androidx.core.view.WindowInsetsCompat; - -import com.example.petstoremobile.R; - -public class ServiceDetailActivity extends AppCompatActivity { - private TextView tvMode, tvServiceId; - private EditText etServiceName, etServiceDesc, etServiceDuration, etServicePrice; - private Button btnSaveService, btnDeleteService, btnBack; - private int serviceId; - private boolean isEditing = false; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - EdgeToEdge.enable(this); - setContentView(R.layout.activity_service_detail); - ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> { - Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars()); - v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom); - return insets; - }); - - initViews(); - handleIntent(); - - //Set clicks listener for each button - btnBack.setOnClickListener(v -> finish()); - btnSaveService.setOnClickListener(v -> saveService()); - btnDeleteService.setOnClickListener(v -> deleteService()); - } - - //get controls form layout - private void initViews() { - tvMode = findViewById(R.id.tvMode); - tvServiceId = findViewById(R.id.tvServiceId); - etServiceName = findViewById(R.id.etServiceName); - etServiceDesc = findViewById(R.id.etServiceDesc); - etServiceDuration = findViewById(R.id.etServiceDuration); - etServicePrice = findViewById(R.id.etServicePrice); - btnSaveService = findViewById(R.id.btnSaveService); - btnDeleteService = findViewById(R.id.btnDeleteService); - btnBack = findViewById(R.id.btnBack); - } - - //check if service is being edited or added and show the view accordingly - private void handleIntent() { - // Service is being edited - if (getIntent().hasExtra("serviceId")) { - // Get service data from intent and populate fields - isEditing = true; - serviceId = getIntent().getIntExtra("serviceId", -1); - tvMode.setText("Edit Service"); - tvServiceId.setText("ID: " + serviceId); - etServiceName.setText(getIntent().getStringExtra("serviceName")); - etServiceDesc.setText(getIntent().getStringExtra("serviceDesc")); - etServiceDuration.setText(String.valueOf(getIntent().getIntExtra("serviceDuration", 0))); - etServicePrice.setText(String.valueOf(getIntent().getDoubleExtra("servicePrice", 0.0))); - - //Delete button is visible when editing - btnDeleteService.setVisibility(View.VISIBLE); - } else { - // Service is being added - // Set default values for add a new service - isEditing = false; - tvMode.setText("Add Service"); - tvServiceId.setVisibility(View.GONE); - btnDeleteService.setVisibility(View.GONE); - btnSaveService.setText("Add"); - } - } - - //TODO: Method to Update or Add a service - private void saveService() { - if (isEditing) { - // TODO: Update service - Toast.makeText(this, "Save functionality not yet implemented with DB", Toast.LENGTH_SHORT).show(); - } else { - // TODO: Add new service - Toast.makeText(this, "Save functionality not yet implemented with DB", Toast.LENGTH_SHORT).show(); - } - finish(); - } - - //TODO: Method to Delete a service - private void deleteService() { - Toast.makeText(this, "Delete functionality not yet implemented with DB", Toast.LENGTH_SHORT).show(); - finish(); - } -} - - diff --git a/app/src/main/java/com/example/petstoremobile/activities/detailactivites/SupplierDetailActivity.java b/app/src/main/java/com/example/petstoremobile/activities/detailactivites/SupplierDetailActivity.java deleted file mode 100644 index fbd8b0a1..00000000 --- a/app/src/main/java/com/example/petstoremobile/activities/detailactivites/SupplierDetailActivity.java +++ /dev/null @@ -1,104 +0,0 @@ -package com.example.petstoremobile.activities.detailactivites; - -import android.os.Bundle; -import android.view.View; -import android.widget.Button; -import android.widget.EditText; -import android.widget.TextView; -import android.widget.Toast; - -import androidx.activity.EdgeToEdge; -import androidx.appcompat.app.AppCompatActivity; -import androidx.core.graphics.Insets; -import androidx.core.view.ViewCompat; -import androidx.core.view.WindowInsetsCompat; - -import com.example.petstoremobile.R; - -public class SupplierDetailActivity extends AppCompatActivity { - private TextView tvMode, tvSupId; - private EditText etSupCompany, etSupContactFirstName, etSupContactLastName, etSupEmail, etSupPhone; - private Button btnSaveSupplier, btnDeleteSupplier, btnBack; - private int supId; - private boolean isEditing = false; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - EdgeToEdge.enable(this); - setContentView(R.layout.activity_supplier_detail); - ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> { - Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars()); - v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom); - return insets; - }); - - initViews(); - handleIntent(); - - //Set clicks listener for each button - btnBack.setOnClickListener(v -> finish()); - btnSaveSupplier.setOnClickListener(v -> saveSupplier()); - btnDeleteSupplier.setOnClickListener(v -> deleteSupplier()); - } - - //get controls form layout - private void initViews() { - tvMode = findViewById(R.id.tvMode); - tvSupId = findViewById(R.id.tvSupId); - etSupCompany = findViewById(R.id.etSupCompany); - etSupContactFirstName = findViewById(R.id.etSupContactFirstName); - etSupContactLastName = findViewById(R.id.etSupContactLastName); - etSupEmail = findViewById(R.id.etSupEmail); - etSupPhone = findViewById(R.id.etSupPhone); - btnSaveSupplier = findViewById(R.id.btnSaveSupplier); - btnDeleteSupplier = findViewById(R.id.btnDeleteSupplier); - btnBack = findViewById(R.id.btnBack); - } - - //check if supplier is being edited or added and show the view accordingly - private void handleIntent() { - // Supplier is being edited - if (getIntent().hasExtra("supId")) { - // Get supplier data from intent and populate fields - isEditing = true; - supId = getIntent().getIntExtra("supId", -1); - tvMode.setText("Edit Supplier"); - tvSupId.setText("ID: " + supId); - etSupCompany.setText(getIntent().getStringExtra("supCompany")); - etSupContactFirstName.setText(getIntent().getStringExtra("supContactFirstName")); - etSupContactLastName.setText(getIntent().getStringExtra("supContactLastName")); - etSupEmail.setText(getIntent().getStringExtra("supEmail")); - etSupPhone.setText(getIntent().getStringExtra("supPhone")); - - //Delete button is visible when editing - btnDeleteSupplier.setVisibility(View.VISIBLE); - } else { - // Supplier is being added - // Set default values for add a new supplier - isEditing = false; - tvMode.setText("Add Supplier"); - tvSupId.setVisibility(View.GONE); - btnDeleteSupplier.setVisibility(View.GONE); - btnSaveSupplier.setText("Add"); - } - } - - //TODO: Method to Update or Add a supplier - private void saveSupplier() { - if (isEditing) { - // TODO: Update supplier - Toast.makeText(this, "Save functionality not yet implemented with DB", Toast.LENGTH_SHORT).show(); - } else { - // TODO: Add new supplier - Toast.makeText(this, "Save functionality not yet implemented with DB", Toast.LENGTH_SHORT).show(); - } - finish(); - } - - //TODO: Method to Delete a supplier - private void deleteSupplier() { - Toast.makeText(this, "Delete functionality not yet implemented with DB", Toast.LENGTH_SHORT).show(); - finish(); - } -} \ No newline at end of file diff --git a/app/src/main/java/com/example/petstoremobile/activities/AdoptionActivity.java b/app/src/main/java/com/example/petstoremobile/activities/listactivities/AdoptionActivity.java similarity index 86% rename from app/src/main/java/com/example/petstoremobile/activities/AdoptionActivity.java rename to app/src/main/java/com/example/petstoremobile/activities/listactivities/AdoptionActivity.java index df066a91..93db1aec 100644 --- a/app/src/main/java/com/example/petstoremobile/activities/AdoptionActivity.java +++ b/app/src/main/java/com/example/petstoremobile/activities/listactivities/AdoptionActivity.java @@ -1,14 +1,14 @@ -package com.example.petstoremobile.activities; +package com.example.petstoremobile.activities.listactivities; import android.os.Bundle; import androidx.activity.EdgeToEdge; -import androidx.appcompat.app.AppCompatActivity; import androidx.core.graphics.Insets; import androidx.core.view.ViewCompat; import androidx.core.view.WindowInsetsCompat; import com.example.petstoremobile.R; +import com.example.petstoremobile.activities.BaseActivity; public class AdoptionActivity extends BaseActivity { diff --git a/app/src/main/java/com/example/petstoremobile/activities/AppointmentActivity.java b/app/src/main/java/com/example/petstoremobile/activities/listactivities/AppointmentActivity.java similarity index 86% rename from app/src/main/java/com/example/petstoremobile/activities/AppointmentActivity.java rename to app/src/main/java/com/example/petstoremobile/activities/listactivities/AppointmentActivity.java index e8933cf9..eefada95 100644 --- a/app/src/main/java/com/example/petstoremobile/activities/AppointmentActivity.java +++ b/app/src/main/java/com/example/petstoremobile/activities/listactivities/AppointmentActivity.java @@ -1,4 +1,4 @@ -package com.example.petstoremobile.activities; +package com.example.petstoremobile.activities.listactivities; import android.os.Bundle; @@ -8,6 +8,7 @@ import androidx.core.view.ViewCompat; import androidx.core.view.WindowInsetsCompat; import com.example.petstoremobile.R; +import com.example.petstoremobile.activities.BaseActivity; public class AppointmentActivity extends BaseActivity { diff --git a/app/src/main/java/com/example/petstoremobile/activities/InventoryActivity.java b/app/src/main/java/com/example/petstoremobile/activities/listactivities/InventoryActivity.java similarity index 86% rename from app/src/main/java/com/example/petstoremobile/activities/InventoryActivity.java rename to app/src/main/java/com/example/petstoremobile/activities/listactivities/InventoryActivity.java index 00382e2f..08556ad2 100644 --- a/app/src/main/java/com/example/petstoremobile/activities/InventoryActivity.java +++ b/app/src/main/java/com/example/petstoremobile/activities/listactivities/InventoryActivity.java @@ -1,14 +1,14 @@ -package com.example.petstoremobile.activities; +package com.example.petstoremobile.activities.listactivities; import android.os.Bundle; import androidx.activity.EdgeToEdge; -import androidx.appcompat.app.AppCompatActivity; import androidx.core.graphics.Insets; import androidx.core.view.ViewCompat; import androidx.core.view.WindowInsetsCompat; import com.example.petstoremobile.R; +import com.example.petstoremobile.activities.BaseActivity; public class InventoryActivity extends BaseActivity { diff --git a/app/src/main/java/com/example/petstoremobile/activities/ProductActivity.java b/app/src/main/java/com/example/petstoremobile/activities/listactivities/ProductActivity.java similarity index 86% rename from app/src/main/java/com/example/petstoremobile/activities/ProductActivity.java rename to app/src/main/java/com/example/petstoremobile/activities/listactivities/ProductActivity.java index ae481e3c..19241c0b 100644 --- a/app/src/main/java/com/example/petstoremobile/activities/ProductActivity.java +++ b/app/src/main/java/com/example/petstoremobile/activities/listactivities/ProductActivity.java @@ -1,4 +1,4 @@ -package com.example.petstoremobile.activities; +package com.example.petstoremobile.activities.listactivities; import android.os.Bundle; @@ -8,6 +8,7 @@ import androidx.core.view.ViewCompat; import androidx.core.view.WindowInsetsCompat; import com.example.petstoremobile.R; +import com.example.petstoremobile.activities.BaseActivity; public class ProductActivity extends BaseActivity { diff --git a/app/src/main/java/com/example/petstoremobile/adapters/PetAdapter.java b/app/src/main/java/com/example/petstoremobile/adapters/PetAdapter.java index 0974c09a..5fb6ce0e 100644 --- a/app/src/main/java/com/example/petstoremobile/adapters/PetAdapter.java +++ b/app/src/main/java/com/example/petstoremobile/adapters/PetAdapter.java @@ -1,7 +1,5 @@ package com.example.petstoremobile.adapters; -import android.content.Context; -import android.content.Intent; import android.graphics.Color; import android.view.LayoutInflater; import android.view.View; @@ -10,19 +8,23 @@ import android.widget.TextView; import androidx.annotation.NonNull; import androidx.recyclerview.widget.RecyclerView; import com.example.petstoremobile.R; -import com.example.petstoremobile.activities.detailactivites.PetDetailActivity; import com.example.petstoremobile.models.Pet; import java.util.List; public class PetAdapter extends RecyclerView.Adapter { private List petList; - private Context context; + private OnPetClickListener petClickListener; + + // Interface for pet click on recycler view + public interface OnPetClickListener { + void onPetClick(int position); + } //Constructor - public PetAdapter(List petList, Context context) { - this.petList = petList; - this.context = context; + public PetAdapter(List petList, OnPetClickListener petClickListener) { + this.petList = petList; + this.petClickListener = petClickListener; } // Get the controls of each row in recycler view @@ -31,11 +33,11 @@ public class PetAdapter extends RecyclerView.Adapter { public PetViewHolder(@NonNull View v) { super(v); - tvPetName = v.findViewById(R.id.tvPetName); + tvPetName = v.findViewById(R.id.tvPetName); tvPetSpeciesBreed = v.findViewById(R.id.tvPetSpeciesBreed); - tvPetAge = v.findViewById(R.id.tvPetAge); - tvPetPrice = v.findViewById(R.id.tvPetPrice); - tvPetStatus = v.findViewById(R.id.tvPetStatus); + tvPetAge = v.findViewById(R.id.tvPetAge); + tvPetPrice = v.findViewById(R.id.tvPetPrice); + tvPetStatus = v.findViewById(R.id.tvPetStatus); } } @@ -43,7 +45,7 @@ public class PetAdapter extends RecyclerView.Adapter { @NonNull @Override public PetViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { - View v = LayoutInflater.from(context).inflate(R.layout.item_pet, parent, false); + View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_pet, parent, false); return new PetViewHolder(v); } @@ -65,18 +67,8 @@ public class PetAdapter extends RecyclerView.Adapter { holder.tvPetStatus.setBackgroundColor(Color.parseColor("#F44336")); } - //Set click listener for each row - holder.itemView.setOnClickListener(v -> { - Intent intent = new Intent(context, PetDetailActivity.class); - intent.putExtra("petId", pet.getPetId()); - intent.putExtra("petName", pet.getPetName()); - intent.putExtra("petSpecies", pet.getPetSpecies()); - intent.putExtra("petBreed", pet.getPetBreed()); - intent.putExtra("petAge", pet.getPetAge()); - intent.putExtra("petPrice", pet.getPetPrice()); - intent.putExtra("petStatus", pet.getPetStatus()); - context.startActivity(intent); - }); + //when a row is clicked, open the detail view + holder.itemView.setOnClickListener(v -> petClickListener.onPetClick(position)); } @Override diff --git a/app/src/main/java/com/example/petstoremobile/adapters/ServiceAdapter.java b/app/src/main/java/com/example/petstoremobile/adapters/ServiceAdapter.java index 8307b3b4..83450f56 100644 --- a/app/src/main/java/com/example/petstoremobile/adapters/ServiceAdapter.java +++ b/app/src/main/java/com/example/petstoremobile/adapters/ServiceAdapter.java @@ -1,53 +1,53 @@ package com.example.petstoremobile.adapters; -import android.content.Context; -import android.content.Intent; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.TextView; - import androidx.annotation.NonNull; import androidx.recyclerview.widget.RecyclerView; - import com.example.petstoremobile.R; -import com.example.petstoremobile.activities.detailactivites.ServiceDetailActivity; import com.example.petstoremobile.models.Service; - import java.util.List; public class ServiceAdapter extends RecyclerView.Adapter { - private List serviceList; - private Context context; - //Constructor - public ServiceAdapter(List serviceList, Context context) { - this.serviceList = serviceList; - this.context = context; + private List serviceList; + private OnServiceClickListener serviceClickListener; + + // Interface for service click on recycler view + public interface OnServiceClickListener { + void onServiceClick(int position); } - //Get controls of each row in recycler view + //Constructor + public ServiceAdapter(List serviceList, OnServiceClickListener serviceClickListener) { + this.serviceList = serviceList; + this.serviceClickListener = serviceClickListener; + } + + // Get the controls of each row in recycler view public static class ServiceViewHolder extends RecyclerView.ViewHolder { TextView tvServiceName, tvServiceDesc, tvServiceDuration, tvServicePrice; public ServiceViewHolder(@NonNull View v) { super(v); - tvServiceName = v.findViewById(R.id.tvServiceName); - tvServiceDesc = v.findViewById(R.id.tvServiceDesc); + tvServiceName = v.findViewById(R.id.tvServiceName); + tvServiceDesc = v.findViewById(R.id.tvServiceDesc); tvServiceDuration = v.findViewById(R.id.tvServiceDuration); - tvServicePrice = v.findViewById(R.id.tvServicePrice); + tvServicePrice = v.findViewById(R.id.tvServicePrice); } } - //Create a new row view + // Create a new row view @NonNull @Override public ServiceViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { - View v = LayoutInflater.from(context).inflate(R.layout.item_service, parent, false); + View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_service, parent, false); return new ServiceViewHolder(v); } - //Populate the row with service data + //populate the row with service data @Override public void onBindViewHolder(@NonNull ServiceViewHolder holder, int position) { Service service = serviceList.get(position); @@ -57,21 +57,12 @@ public class ServiceAdapter extends RecyclerView.Adapter { - Intent intent = new Intent(context, ServiceDetailActivity.class); - intent.putExtra("serviceId", service.getServiceId()); - intent.putExtra("serviceName", service.getServiceName()); - intent.putExtra("serviceDesc", service.getServiceDesc()); - intent.putExtra("serviceDuration", service.getServiceDuration()); - intent.putExtra("servicePrice", service.getServicePrice()); - context.startActivity(intent); - }); + //when a row is clicked, open the detail view + holder.itemView.setOnClickListener(v -> serviceClickListener.onServiceClick(position)); } @Override public int getItemCount() { return serviceList.size(); } - -} +} \ No newline at end of file diff --git a/app/src/main/java/com/example/petstoremobile/adapters/SupplierAdapter.java b/app/src/main/java/com/example/petstoremobile/adapters/SupplierAdapter.java index 3af54dc5..7b0bf886 100644 --- a/app/src/main/java/com/example/petstoremobile/adapters/SupplierAdapter.java +++ b/app/src/main/java/com/example/petstoremobile/adapters/SupplierAdapter.java @@ -1,32 +1,32 @@ package com.example.petstoremobile.adapters; -import android.content.Context; -import android.content.Intent; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.TextView; - import androidx.annotation.NonNull; import androidx.recyclerview.widget.RecyclerView; - import com.example.petstoremobile.R; -import com.example.petstoremobile.activities.detailactivites.SupplierDetailActivity; import com.example.petstoremobile.models.Supplier; - import java.util.List; public class SupplierAdapter extends RecyclerView.Adapter { - private List supplierList; - private Context context; - //Constructor - public SupplierAdapter(List supplierList, Context context) { - this.supplierList = supplierList; - this.context = context; + private List supplierList; + private OnSupplierClickListener supplierClickListener; + + // Interface for supplier click on recycler view + public interface OnSupplierClickListener { + void onSupplierClick(int position); } - //Get controls of each row in recycler view + //Constructor + public SupplierAdapter(List supplierList, OnSupplierClickListener supplierClickListener) { + this.supplierList = supplierList; + this.supplierClickListener = supplierClickListener; + } + + // Get the controls of each row in recycler view public static class SupplierViewHolder extends RecyclerView.ViewHolder { TextView tvSupCompany, tvSupContactName, tvSupEmail, tvSupPhone; @@ -39,15 +39,15 @@ public class SupplierAdapter extends RecyclerView.Adapter { - Intent intent = new Intent(context, SupplierDetailActivity.class); - intent.putExtra("supId", supplier.getSupId()); - intent.putExtra("supCompany", supplier.getSupCompany()); - intent.putExtra("supContactFirstName", supplier.getSupContactFirstName()); - intent.putExtra("supContactLastName", supplier.getSupContactLastName()); - intent.putExtra("supEmail", supplier.getSupEmail()); - intent.putExtra("supPhone", supplier.getSupPhone()); - context.startActivity(intent); - }); + //when a row is clicked, open the detail view + holder.itemView.setOnClickListener(v -> supplierClickListener.onSupplierClick(position)); } @Override public int getItemCount() { return supplierList.size(); } - -} +} \ No newline at end of file diff --git a/app/src/main/java/com/example/petstoremobile/fragments/ChatFragment.java b/app/src/main/java/com/example/petstoremobile/fragments/ChatFragment.java new file mode 100644 index 00000000..a99bc740 --- /dev/null +++ b/app/src/main/java/com/example/petstoremobile/fragments/ChatFragment.java @@ -0,0 +1,36 @@ +package com.example.petstoremobile.fragments; + +import android.os.Bundle; + +import androidx.fragment.app.Fragment; + +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.Button; +import android.widget.EditText; +import android.widget.LinearLayout; +import android.widget.ScrollView; +import android.widget.TextView; + +import com.example.petstoremobile.R; + + +public class ChatFragment extends Fragment { + + private LinearLayout chatContainer; + private EditText etMessage; + private ScrollView scrollView; + private Button btnSend; + + //TODO: Add functionality for sending messages + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + + View view = inflater.inflate(R.layout.fragment_chat, container, false); + + return view; + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/example/petstoremobile/fragments/ListFragment.java b/app/src/main/java/com/example/petstoremobile/fragments/ListFragment.java new file mode 100644 index 00000000..b7dd1582 --- /dev/null +++ b/app/src/main/java/com/example/petstoremobile/fragments/ListFragment.java @@ -0,0 +1,76 @@ +package com.example.petstoremobile.fragments; + +import android.os.Bundle; + +import androidx.annotation.NonNull; +import androidx.core.view.MenuProvider; +import androidx.fragment.app.Fragment; + +import android.view.LayoutInflater; + +import android.view.Menu; +import android.view.MenuInflater; +import android.view.MenuItem; +import android.view.View; +import android.view.ViewGroup; +import androidx.lifecycle.Lifecycle; + + +import com.example.petstoremobile.R; + +import com.example.petstoremobile.fragments.listfragments.PetFragment; +import com.example.petstoremobile.fragments.listfragments.ServiceFragment; +import com.example.petstoremobile.fragments.listfragments.SupplierFragment; + +//The Fragment for the displaying the list of entities to be viewed +public class ListFragment extends Fragment { + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + View view = inflater.inflate(R.layout.fragment_list, container, false); + + //Display pets fragment by default + if (savedInstanceState == null) { + loadFragment(new PetFragment()); + } + + //create a menu for the user to select what entity to view + requireActivity().addMenuProvider(new MenuProvider() { + + //inflate the menu + @Override + public void onCreateMenu(@NonNull Menu menu, @NonNull MenuInflater menuInflater) { + menuInflater.inflate(R.menu.menu_main, menu); + } + + //handle menu clicks + @Override + public boolean onMenuItemSelected(@NonNull MenuItem menuItem) { + //check what menu item is selected and load the corresponding fragment + if (menuItem.getItemId() == R.id.menu_pets) { + loadFragment(new PetFragment()); + return true; + } else if (menuItem.getItemId() == R.id.menu_services) { + loadFragment(new ServiceFragment()); + return true; + } else if (menuItem.getItemId() == R.id.menu_suppliers) { + loadFragment(new SupplierFragment()); + return true; + } + return false; + } + }, getViewLifecycleOwner(), Lifecycle.State.RESUMED); + + return view; + } + + // helper function to load the fragment into the display + public void loadFragment(Fragment fragment) { + getChildFragmentManager() + .beginTransaction() + .replace(R.id.inner_fragment_container, fragment) + .addToBackStack(null) + .commit(); + } +} \ No newline at end of file diff --git a/app/src/main/java/com/example/petstoremobile/fragments/ProfileFragment.java b/app/src/main/java/com/example/petstoremobile/fragments/ProfileFragment.java new file mode 100644 index 00000000..ea98e150 --- /dev/null +++ b/app/src/main/java/com/example/petstoremobile/fragments/ProfileFragment.java @@ -0,0 +1,24 @@ +package com.example.petstoremobile.fragments; + +import android.os.Bundle; + +import androidx.fragment.app.Fragment; + +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +import com.example.petstoremobile.R; + +public class ProfileFragment extends Fragment { + + + //TODO: Create functionality for profile fragment + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + View view = inflater.inflate(R.layout.fragment_profile, container, false); + + return view; + } +} \ No newline at end of file diff --git a/app/src/main/java/com/example/petstoremobile/fragments/listfragments/PetFragment.java b/app/src/main/java/com/example/petstoremobile/fragments/listfragments/PetFragment.java new file mode 100644 index 00000000..1120f78f --- /dev/null +++ b/app/src/main/java/com/example/petstoremobile/fragments/listfragments/PetFragment.java @@ -0,0 +1,116 @@ +package com.example.petstoremobile.fragments.listfragments; + +import android.os.Bundle; + +import androidx.fragment.app.Fragment; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +import com.example.petstoremobile.R; +import com.example.petstoremobile.adapters.PetAdapter; +import com.example.petstoremobile.fragments.ListFragment; +import com.example.petstoremobile.fragments.listfragments.detailfragments.PetDetailFragment; +import com.example.petstoremobile.models.Pet; +import com.google.android.material.floatingactionbutton.FloatingActionButton; + +import java.util.ArrayList; +import java.util.List; + +public class PetFragment extends Fragment implements PetAdapter.OnPetClickListener { + + private List petList = new ArrayList<>(); + private PetAdapter adapter; + + //load pet view + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + View view = inflater.inflate(R.layout.fragment_pet, container, false); + + loadPetData(); //TODO: Replace this with actual data when backend is working + setupRecyclerView(view); + + //Add button to opens the add dialog + FloatingActionButton fabAddPet = view.findViewById(R.id.fabAddPet); + fabAddPet.setOnClickListener(v -> openPetDetails(-1)); + + return view; + } + + //Open the pet detail view depending on the mode + private void openPetDetails(int position) { + PetDetailFragment detailFragment = new PetDetailFragment(); + + //Make a bundle to pass data to the detail fragment + Bundle args = new Bundle(); + args.putInt("position", position); + + //if editing a pet, add the pet data to the bundle + if (position != -1) { + Pet pet = petList.get(position); + args.putInt("petId", pet.getPetId()); + args.putString("petName", pet.getPetName()); + args.putString("petSpecies", pet.getPetSpecies()); + args.putString("petBreed", pet.getPetBreed()); + args.putInt("petAge", pet.getPetAge()); + args.putString("petStatus", pet.getPetStatus()); + args.putDouble("petPrice", pet.getPetPrice()); + } + + //send the bundle to the detail fragment to display + detailFragment.setArguments(args); + //set the pet fragment to the parent so we refer back to pet view when save or delete is done + detailFragment.setPetFragment(this); + + //get ListFragment to load the the detail view + ListFragment listFragment = (ListFragment) getParentFragment(); + if (listFragment != null) { + listFragment.loadFragment(detailFragment); + } + } + + // Called by PetDetailFragment when save or delete is done + public void onPetSaved(int position, Pet pet) { + if (position == -1) { + petList.add(pet); + adapter.notifyItemInserted(petList.size() - 1); + } else { + petList.set(position, pet); + adapter.notifyItemChanged(position); + } + } + + public void onPetDeleted(int position) { + petList.remove(position); + adapter.notifyItemRemoved(position); + } + + // Called by PetAdapter when a row is clicked to open the details view + @Override + public void onPetClick(int position) { + openPetDetails(position); + } + + // Helper function to get a list of all pets (Loads hardcoded sample data for now) TODO: REPLACE THIS WITH A METHOD THAT GETS DATA FROM THE DATABASE + private void loadPetData() { + petList.clear(); + petList.add(new Pet(1, "Buddy","Dog", "Labrador",2, "Available", 500.00)); + petList.add(new Pet(2, "Milo", "Cat", "Persian",1, "Available", 300.00)); + petList.add(new Pet(3, "Charlie","Dog", "Golden Retriever", 3, "Available", 550.00)); + petList.add(new Pet(4, "Luna", "Cat", "Siamese",2, "Adopted", 350.00)); + petList.add(new Pet(5, "Max", "Dog", "Beagle",1, "Available", 450.00)); + petList.add(new Pet(6, "Bella", "Cat", "Maine Coon",4, "Available", 400.00)); + } + + //set up the recyclerview and adapter + private void setupRecyclerView(View view) { + RecyclerView recyclerView = view.findViewById(R.id.recyclerViewPets); + adapter = new PetAdapter(petList, this); + recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); + recyclerView.setAdapter(adapter); + } +} \ No newline at end of file diff --git a/app/src/main/java/com/example/petstoremobile/fragments/listfragments/ServiceFragment.java b/app/src/main/java/com/example/petstoremobile/fragments/listfragments/ServiceFragment.java new file mode 100644 index 00000000..e68b049d --- /dev/null +++ b/app/src/main/java/com/example/petstoremobile/fragments/listfragments/ServiceFragment.java @@ -0,0 +1,113 @@ +package com.example.petstoremobile.fragments.listfragments; + +import android.os.Bundle; + +import androidx.fragment.app.Fragment; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +import com.example.petstoremobile.R; +import com.example.petstoremobile.adapters.ServiceAdapter; +import com.example.petstoremobile.fragments.ListFragment; +import com.example.petstoremobile.fragments.listfragments.detailfragments.ServiceDetailFragment; +import com.example.petstoremobile.models.Service; +import com.google.android.material.floatingactionbutton.FloatingActionButton; + +import java.util.ArrayList; +import java.util.List; + +public class ServiceFragment extends Fragment implements ServiceAdapter.OnServiceClickListener { + + private List serviceList = new ArrayList<>(); + private ServiceAdapter adapter; + + //load service view + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + View view = inflater.inflate(R.layout.fragment_service, container, false); + + loadServiceData(); //TODO: Replace this with actual data when backend is working + setupRecyclerView(view); + + //Add button to opens the add dialog + FloatingActionButton fabAddService = view.findViewById(R.id.fabAddService); + fabAddService.setOnClickListener(v -> openServiceDetails(-1)); + + return view; + } + + //Open the service detail view depending on the mode + private void openServiceDetails(int position) { + ServiceDetailFragment detailFragment = new ServiceDetailFragment(); + + //Make a bundle to pass data to the detail fragment + Bundle args = new Bundle(); + args.putInt("position", position); + + //if editing a service, add the service data to the bundle + if (position != -1) { + Service service = serviceList.get(position); + args.putInt("serviceId", service.getServiceId()); + args.putString("serviceName", service.getServiceName()); + args.putString("serviceDesc", service.getServiceDesc()); + args.putInt("serviceDuration", service.getServiceDuration()); + args.putDouble("servicePrice", service.getServicePrice()); + } + + //send the bundle to the detail fragment to display + detailFragment.setArguments(args); + //set the service fragment to the parent so we refer back to service view when save or delete is done + detailFragment.setServiceFragment(this); + + //get ListFragment to load the the detail view + ListFragment listFragment = (ListFragment) getParentFragment(); + if (listFragment != null) { + listFragment.loadFragment(detailFragment); + } + } + + // Called by ServiceDetailFragment when save or delete is done + public void onServiceSaved(int position, Service service) { + if (position == -1) { + serviceList.add(service); + adapter.notifyItemInserted(serviceList.size() - 1); + } else { + serviceList.set(position, service); + adapter.notifyItemChanged(position); + } + } + + public void onServiceDeleted(int position) { + serviceList.remove(position); + adapter.notifyItemRemoved(position); + } + + // Called by ServiceAdapter when a row is clicked to open the details view + @Override + public void onServiceClick(int position) { + openServiceDetails(position); + } + + // Helper function to get a list of all services (Loads hardcoded sample data for now) TODO: REPLACE THIS WITH A METHOD THAT GETS DATA FROM THE DATABASE + private void loadServiceData() { + serviceList.clear(); + serviceList.add(new Service(1, "Grooming", "Full grooming for your pet", 60, 50.00)); + serviceList.add(new Service(2, "Vaccination", "Standard vaccinations", 30, 75.00)); + serviceList.add(new Service(3, "Health Checkup", "Comprehensive health exam", 45, 100.00)); + serviceList.add(new Service(4, "Pet Sitting", "Overnight stay for your pet", 1440, 40.00)); + serviceList.add(new Service(5, "Training", "Basic obedience training session", 60, 60.00)); + } + + //set up the recyclerview and adapter + private void setupRecyclerView(View view) { + RecyclerView recyclerView = view.findViewById(R.id.recyclerViewServices); + adapter = new ServiceAdapter(serviceList, this); + recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); + recyclerView.setAdapter(adapter); + } +} \ No newline at end of file diff --git a/app/src/main/java/com/example/petstoremobile/fragments/listfragments/SupplierFragment.java b/app/src/main/java/com/example/petstoremobile/fragments/listfragments/SupplierFragment.java new file mode 100644 index 00000000..d962408f --- /dev/null +++ b/app/src/main/java/com/example/petstoremobile/fragments/listfragments/SupplierFragment.java @@ -0,0 +1,114 @@ +package com.example.petstoremobile.fragments.listfragments; + +import android.os.Bundle; + +import androidx.fragment.app.Fragment; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +import com.example.petstoremobile.R; +import com.example.petstoremobile.adapters.SupplierAdapter; +import com.example.petstoremobile.fragments.ListFragment; +import com.example.petstoremobile.fragments.listfragments.detailfragments.SupplierDetailFragment; +import com.example.petstoremobile.models.Supplier; +import com.google.android.material.floatingactionbutton.FloatingActionButton; + +import java.util.ArrayList; +import java.util.List; + +public class SupplierFragment extends Fragment implements SupplierAdapter.OnSupplierClickListener { + + private List supplierList = new ArrayList<>(); + private SupplierAdapter adapter; + + //load supplier view + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + View view = inflater.inflate(R.layout.fragment_supplier, container, false); + + loadSupplierData(); //TODO: Replace this with actual data when backend is working + setupRecyclerView(view); + + //Add button to opens the add dialog + FloatingActionButton fabAddSupplier = view.findViewById(R.id.fabAddSupplier); + fabAddSupplier.setOnClickListener(v -> openSupplierDetails(-1)); + + return view; + } + + //Open the supplier detail view depending on the mode + private void openSupplierDetails(int position) { + SupplierDetailFragment detailFragment = new SupplierDetailFragment(); + + //Make a bundle to pass data to the detail fragment + Bundle args = new Bundle(); + args.putInt("position", position); + + //if editing a supplier, add the supplier data to the bundle + if (position != -1) { + Supplier supplier = supplierList.get(position); + args.putInt("supId", supplier.getSupId()); + args.putString("supCompany", supplier.getSupCompany()); + args.putString("supContactFirstName", supplier.getSupContactFirstName()); + args.putString("supContactLastName", supplier.getSupContactLastName()); + args.putString("supEmail", supplier.getSupEmail()); + args.putString("supPhone", supplier.getSupPhone()); + } + + //send the bundle to the detail fragment to display + detailFragment.setArguments(args); + //set the supplier fragment to the parent so we refer back to supplier view when save or delete is done + detailFragment.setSupplierFragment(this); + + //get ListFragment to load the the detail view + ListFragment listFragment = (ListFragment) getParentFragment(); + if (listFragment != null) { + listFragment.loadFragment(detailFragment); + } + } + + // Called by SupplierDetailFragment when save or delete is done + public void onSupplierSaved(int position, Supplier supplier) { + if (position == -1) { + supplierList.add(supplier); + adapter.notifyItemInserted(supplierList.size() - 1); + } else { + supplierList.set(position, supplier); + adapter.notifyItemChanged(position); + } + } + + public void onSupplierDeleted(int position) { + supplierList.remove(position); + adapter.notifyItemRemoved(position); + } + + // Called by SupplierAdapter when a row is clicked to open the details view + @Override + public void onSupplierClick(int position) { + openSupplierDetails(position); + } + + // Helper function to get a list of all suppliers (Loads hardcoded sample data for now) TODO: REPLACE THIS WITH A METHOD THAT GETS DATA FROM THE DATABASE + private void loadSupplierData() { + supplierList.clear(); + supplierList.add(new Supplier(1, "Pet Food Co.", "John", "Doe", "john@petfood.com", "123-456-7890")); + supplierList.add(new Supplier(2, "Toy Kingdom", "Jane", "Smith", "jane@toykingdom.com", "987-654-3210")); + supplierList.add(new Supplier(3, "HealthPet", "Robert", "Brown", "robert@healthpet.com", "555-0199-234")); + supplierList.add(new Supplier(4, "Groomers Choice", "Emily", "Davis", "emily@groomers.com", "444-555-6666")); + supplierList.add(new Supplier(5, "Birdy Haven", "Michael", "Wilson", "michael@birdyhaven.com", "111-222-3333")); + } + + //set up the recyclerview and adapter + private void setupRecyclerView(View view) { + RecyclerView recyclerView = view.findViewById(R.id.recyclerViewSuppliers); + adapter = new SupplierAdapter(supplierList, this); + recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); + recyclerView.setAdapter(adapter); + } +} \ No newline at end of file diff --git a/app/src/main/java/com/example/petstoremobile/fragments/listfragments/detailfragments/PetDetailFragment.java b/app/src/main/java/com/example/petstoremobile/fragments/listfragments/detailfragments/PetDetailFragment.java new file mode 100644 index 00000000..b7b89614 --- /dev/null +++ b/app/src/main/java/com/example/petstoremobile/fragments/listfragments/detailfragments/PetDetailFragment.java @@ -0,0 +1,132 @@ +package com.example.petstoremobile.fragments.listfragments.detailfragments; + +import android.os.Bundle; + +import androidx.fragment.app.Fragment; + +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ArrayAdapter; +import android.widget.Button; +import android.widget.EditText; +import android.widget.Spinner; +import android.widget.TextView; +import android.widget.Toast; + +import com.example.petstoremobile.R; +import com.example.petstoremobile.fragments.ListFragment; +import com.example.petstoremobile.fragments.listfragments.PetFragment; + +public class PetDetailFragment extends Fragment { + + private TextView tvMode, tvPetId; + private EditText etPetName, etPetSpecies, etPetBreed, etPetAge, etPetPrice; + private Spinner spinnerPetStatus; + private Button btnSavePet, btnDeletePet, btnBack; + private int petId; + private boolean isEditing = false; + private PetFragment petFragment; + + //set the pet fragment to the parent so we refer back to pet view when save or delete is done + public void setPetFragment(PetFragment fragment) { + this.petFragment = fragment; + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + View view = inflater.inflate(R.layout.fragment_pet_detail, container, false); + + //set up spinner and get controls from layout and display the view depending on the mode + initViews(view); + setupSpinner(); + handleArguments(); + + //set button click listeners + btnBack.setOnClickListener(v -> { + //get the list fragment and pop the back stack to return to the previous view (PetFragment) + ListFragment listFragment = (ListFragment) getParentFragment(); + if (listFragment != null) { + listFragment.getChildFragmentManager().popBackStack(); + } + }); + btnSavePet.setOnClickListener(v -> savePet()); + btnDeletePet.setOnClickListener(v -> deletePet()); + + return view; + } + + //TODO: Method to Update or Add a pet + private void savePet() { + if (isEditing) { + // TODO: Update pet + Toast.makeText(getContext(), "Save functionality not yet implemented with DB", Toast.LENGTH_SHORT).show(); + } else { + // TODO: Add new pet + Toast.makeText(getContext(), "Save functionality not yet implemented with DB", Toast.LENGTH_SHORT).show(); + } + } + + //TODO: Method to Delete a pet + private void deletePet() { + Toast.makeText(getContext(), "Delete functionality not yet implemented with DB", Toast.LENGTH_SHORT).show(); + } + + //helper function to check if pet is being edited or added and show the view accordingly + private void handleArguments() { + // Pet is being edited if the bundle contains a petId + if (getArguments() != null && getArguments().containsKey("petId")) { + // Get pet data from arguments and populate fields + isEditing = true; + petId = getArguments().getInt("petId"); + tvMode.setText("Edit Pet"); + tvPetId.setText("ID: " + petId); + etPetName.setText(getArguments().getString("petName")); + etPetSpecies.setText(getArguments().getString("petSpecies")); + etPetBreed.setText(getArguments().getString("petBreed")); + etPetAge.setText(String.valueOf(getArguments().getInt("petAge"))); + etPetPrice.setText(String.valueOf(getArguments().getDouble("petPrice"))); + String status = getArguments().getString("petStatus"); + if ("Available".equals(status)) { + spinnerPetStatus.setSelection(0); + } else { + spinnerPetStatus.setSelection(1); + } + btnDeletePet.setVisibility(View.VISIBLE); + } else { + // Pet is being added + // Set default values for add a new pet + isEditing = false; + tvMode.setText("Add Pet"); + tvPetId.setVisibility(View.GONE); + btnDeletePet.setVisibility(View.GONE); + btnSavePet.setText("Add"); + } + } + + //helper function to get controls from layout + private void initViews(View view) { + tvMode = view.findViewById(R.id.tvMode); + tvPetId = view.findViewById(R.id.tvPetId); + etPetName = view.findViewById(R.id.etPetName); + etPetSpecies = view.findViewById(R.id.etPetSpecies); + etPetBreed = view.findViewById(R.id.etPetBreed); + etPetAge = view.findViewById(R.id.etPetAge); + etPetPrice = view.findViewById(R.id.etPetPrice); + spinnerPetStatus = view.findViewById(R.id.spinnerPetStatus); + btnSavePet = view.findViewById(R.id.btnSavePet); + btnDeletePet = view.findViewById(R.id.btnDeletePet); + btnBack = view.findViewById(R.id.btnBack); + } + + //helper function to set up the spinner menu for pet status + private void setupSpinner() { + ArrayAdapter adapter = new ArrayAdapter<>(requireContext(), + android.R.layout.simple_spinner_item, + new String[]{"Available", "Adopted"}); + adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + spinnerPetStatus.setAdapter(adapter); + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/example/petstoremobile/fragments/listfragments/detailfragments/ServiceDetailFragment.java b/app/src/main/java/com/example/petstoremobile/fragments/listfragments/detailfragments/ServiceDetailFragment.java new file mode 100644 index 00000000..a696281a --- /dev/null +++ b/app/src/main/java/com/example/petstoremobile/fragments/listfragments/detailfragments/ServiceDetailFragment.java @@ -0,0 +1,109 @@ +package com.example.petstoremobile.fragments.listfragments.detailfragments; + +import android.os.Bundle; + +import androidx.fragment.app.Fragment; + +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.Button; +import android.widget.EditText; +import android.widget.TextView; +import android.widget.Toast; + +import com.example.petstoremobile.R; +import com.example.petstoremobile.fragments.ListFragment; +import com.example.petstoremobile.fragments.listfragments.ServiceFragment; + +public class ServiceDetailFragment extends Fragment { + + private TextView tvMode, tvServiceId; + private EditText etServiceName, etServiceDesc, etServiceDuration, etServicePrice; + private Button btnSaveService, btnDeleteService, btnBack; + private int serviceId; + private boolean isEditing = false; + private ServiceFragment serviceFragment; + + //set the service fragment to the parent so we refer back to service view when save or delete is done + public void setServiceFragment(ServiceFragment fragment) { + this.serviceFragment = fragment; + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + View view = inflater.inflate(R.layout.fragment_service_detail, container, false); + + //get controls from layout and display the view depending on the mode + initViews(view); + handleArguments(); + + //set button click listeners + btnBack.setOnClickListener(v -> { + //get the list fragment and pop the back stack to return to the previous view (ServiceFragment) + ListFragment listFragment = (ListFragment) getParentFragment(); + if (listFragment != null) { + listFragment.getChildFragmentManager().popBackStack(); + } + }); + btnSaveService.setOnClickListener(v -> saveService()); + btnDeleteService.setOnClickListener(v -> deleteService()); + + return view; + } + + //TODO: Method to Update or Add a service + private void saveService() { + if (isEditing) { + // TODO: Update service + Toast.makeText(getContext(), "Save functionality not yet implemented with DB", Toast.LENGTH_SHORT).show(); + } else { + // TODO: Add new service + Toast.makeText(getContext(), "Save functionality not yet implemented with DB", Toast.LENGTH_SHORT).show(); + } + } + + //TODO: Method to Delete a service + private void deleteService() { + Toast.makeText(getContext(), "Delete functionality not yet implemented with DB", Toast.LENGTH_SHORT).show(); + } + + //helper function to check if service is being edited or added and show the view accordingly + private void handleArguments() { + // Service is being edited if the bundle contains a serviceId + if (getArguments() != null && getArguments().containsKey("serviceId")) { + // Get service data from arguments and populate fields + isEditing = true; + serviceId = getArguments().getInt("serviceId"); + tvMode.setText("Edit Service"); + tvServiceId.setText("ID: " + serviceId); + etServiceName.setText(getArguments().getString("serviceName")); + etServiceDesc.setText(getArguments().getString("serviceDesc")); + etServiceDuration.setText(String.valueOf(getArguments().getInt("serviceDuration"))); + etServicePrice.setText(String.valueOf(getArguments().getDouble("servicePrice"))); + btnDeleteService.setVisibility(View.VISIBLE); + } else { + // Service is being added + // Set default values for add a new service + isEditing = false; + tvMode.setText("Add Service"); + tvServiceId.setVisibility(View.GONE); + btnDeleteService.setVisibility(View.GONE); + btnSaveService.setText("Add"); + } + } + + //helper function to get controls from layout + private void initViews(View view) { + tvMode = view.findViewById(R.id.tvMode); + tvServiceId = view.findViewById(R.id.tvServiceId); + etServiceName = view.findViewById(R.id.etServiceName); + etServiceDesc = view.findViewById(R.id.etServiceDesc); + etServiceDuration = view.findViewById(R.id.etServiceDuration); + etServicePrice = view.findViewById(R.id.etServicePrice); + btnSaveService = view.findViewById(R.id.btnSaveService); + btnDeleteService = view.findViewById(R.id.btnDeleteService); + btnBack = view.findViewById(R.id.btnBack); + } +} \ No newline at end of file diff --git a/app/src/main/java/com/example/petstoremobile/fragments/listfragments/detailfragments/SupplierDetailFragment.java b/app/src/main/java/com/example/petstoremobile/fragments/listfragments/detailfragments/SupplierDetailFragment.java new file mode 100644 index 00000000..d13acf08 --- /dev/null +++ b/app/src/main/java/com/example/petstoremobile/fragments/listfragments/detailfragments/SupplierDetailFragment.java @@ -0,0 +1,111 @@ +package com.example.petstoremobile.fragments.listfragments.detailfragments; + +import android.os.Bundle; + +import androidx.fragment.app.Fragment; + +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.Button; +import android.widget.EditText; +import android.widget.TextView; +import android.widget.Toast; + +import com.example.petstoremobile.R; +import com.example.petstoremobile.fragments.ListFragment; +import com.example.petstoremobile.fragments.listfragments.SupplierFragment; + +public class SupplierDetailFragment extends Fragment { + + private TextView tvMode, tvSupId; + private EditText etSupCompany, etSupContactFirstName, etSupContactLastName, etSupEmail, etSupPhone; + private Button btnSaveSupplier, btnDeleteSupplier, btnBack; + private int supId; + private boolean isEditing = false; + private SupplierFragment supplierFragment; + + //set the supplier fragment to the parent so we refer back to supplier view when save or delete is done + public void setSupplierFragment(SupplierFragment fragment) { + this.supplierFragment = fragment; + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + View view = inflater.inflate(R.layout.fragment_supplier_detail, container, false); + + //get controls from layout and display the view depending on the mode + initViews(view); + handleArguments(); + + //set button click listeners + btnBack.setOnClickListener(v -> { + //get the list fragment and pop the back stack to return to the previous view (SupplierFragment) + ListFragment listFragment = (ListFragment) getParentFragment(); + if (listFragment != null) { + listFragment.getChildFragmentManager().popBackStack(); + } + }); + btnSaveSupplier.setOnClickListener(v -> saveSupplier()); + btnDeleteSupplier.setOnClickListener(v -> deleteSupplier()); + + return view; + } + + //TODO: Method to Update or Add a supplier + private void saveSupplier() { + if (isEditing) { + // TODO: Update supplier + Toast.makeText(getContext(), "Save functionality not yet implemented with DB", Toast.LENGTH_SHORT).show(); + } else { + // TODO: Add new supplier + Toast.makeText(getContext(), "Save functionality not yet implemented with DB", Toast.LENGTH_SHORT).show(); + } + } + + //TODO: Method to Delete a supplier + private void deleteSupplier() { + Toast.makeText(getContext(), "Delete functionality not yet implemented with DB", Toast.LENGTH_SHORT).show(); + } + + //helper function to check if supplier is being edited or added and show the view accordingly + private void handleArguments() { + // Supplier is being edited if the bundle contains a supId + if (getArguments() != null && getArguments().containsKey("supId")) { + // Get supplier data from arguments and populate fields + isEditing = true; + supId = getArguments().getInt("supId"); + tvMode.setText("Edit Supplier"); + tvSupId.setText("ID: " + supId); + etSupCompany.setText(getArguments().getString("supCompany")); + etSupContactFirstName.setText(getArguments().getString("supContactFirstName")); + etSupContactLastName.setText(getArguments().getString("supContactLastName")); + etSupEmail.setText(getArguments().getString("supEmail")); + etSupPhone.setText(getArguments().getString("supPhone")); + btnDeleteSupplier.setVisibility(View.VISIBLE); + } else { + // Supplier is being added + // Set default values for add a new supplier + isEditing = false; + tvMode.setText("Add Supplier"); + tvSupId.setVisibility(View.GONE); + btnDeleteSupplier.setVisibility(View.GONE); + btnSaveSupplier.setText("Add"); + } + } + + //helper function to get controls from layout + private void initViews(View view) { + tvMode = view.findViewById(R.id.tvMode); + tvSupId = view.findViewById(R.id.tvSupId); + etSupCompany = view.findViewById(R.id.etSupCompany); + etSupContactFirstName = view.findViewById(R.id.etSupContactFirstName); + etSupContactLastName = view.findViewById(R.id.etSupContactLastName); + etSupEmail = view.findViewById(R.id.etSupEmail); + etSupPhone = view.findViewById(R.id.etSupPhone); + btnSaveSupplier = view.findViewById(R.id.btnSaveSupplier); + btnDeleteSupplier = view.findViewById(R.id.btnDeleteSupplier); + btnBack = view.findViewById(R.id.btnBack); + } +} \ No newline at end of file diff --git a/app/src/main/res/drawable/petstore_logo.png b/app/src/main/res/drawable/petstore_logo.png new file mode 100644 index 00000000..131282c1 Binary files /dev/null and b/app/src/main/res/drawable/petstore_logo.png differ diff --git a/app/src/main/res/drawable/placeholder.png b/app/src/main/res/drawable/placeholder.png new file mode 100644 index 00000000..e7bdbefd Binary files /dev/null and b/app/src/main/res/drawable/placeholder.png differ diff --git a/app/src/main/res/layout/activity_adoption.xml b/app/src/main/res/layout/activity_adoption.xml index d896813f..59413945 100644 --- a/app/src/main/res/layout/activity_adoption.xml +++ b/app/src/main/res/layout/activity_adoption.xml @@ -5,7 +5,7 @@ android:id="@+id/main" android:layout_width="match_parent" android:layout_height="match_parent" - tools:context=".activities.AdoptionActivity"> + tools:context=".activities.listactivities.AdoptionActivity"> + tools:context=".activities.listactivities.AppointmentActivity"> + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_inventory.xml b/app/src/main/res/layout/activity_inventory.xml index a2e7f2cd..0d4d537a 100644 --- a/app/src/main/res/layout/activity_inventory.xml +++ b/app/src/main/res/layout/activity_inventory.xml @@ -5,7 +5,7 @@ android:id="@+id/main" android:layout_width="match_parent" android:layout_height="match_parent" - tools:context=".activities.InventoryActivity"> + tools:context=".activities.listactivities.InventoryActivity"> + android:layout_width="184dp" + android:layout_height="173dp" + android:src="@drawable/petstore_logo" + android:scaleType="fitCenter" /> + tools:context=".activities.listactivities.ProductActivity"> + + + + + + + + + + + + +