diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 227a17c..b4d9259 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -9,6 +9,7 @@ + diff --git a/app/src/main/java/com/utopiaindustries/qc_android/activities/QCTerryActivity.java b/app/src/main/java/com/utopiaindustries/qc_android/activities/QCTerryActivity.java index 452ce48..19d515b 100644 --- a/app/src/main/java/com/utopiaindustries/qc_android/activities/QCTerryActivity.java +++ b/app/src/main/java/com/utopiaindustries/qc_android/activities/QCTerryActivity.java @@ -19,7 +19,8 @@ import androidx.navigation.Navigation; import com.utopiaindustries.qc_android.R; import com.utopiaindustries.qc_android.db.CheckpointRepository; import com.utopiaindustries.qc_android.models.InspectionCheckPoint; -import com.utopiaindustries.qc_android.viewmodels.DataEntryViewModel; +import com.utopiaindustries.qc_android.models.DataEntryModel; +import com.utopiaindustries.qc_android.utils.AppDataManager; import java.util.ArrayList; import java.util.List; @@ -28,7 +29,7 @@ public class QCTerryActivity extends AppCompatActivity { private NavController navController; private List checkPointList = new ArrayList<>(); - private DataEntryViewModel viewModel; + private DataEntryModel dataEntryModel; @Override protected void onCreate(Bundle savedInstanceState) { @@ -49,7 +50,8 @@ public class QCTerryActivity extends AppCompatActivity { private void initializeLayout() { - viewModel = new ViewModelProvider(this).get(DataEntryViewModel.class); + dataEntryModel = AppDataManager.getInstance().getCurrentDataEntry(); + loadCheckPoints(); // Setup Navigation @@ -99,7 +101,7 @@ public class QCTerryActivity extends AppCompatActivity { checkPointList.add(item); }*/ - viewModel.setCheckPointList(checkPointList); + dataEntryModel.setCheckPointList(checkPointList); } private void setStatusBarColor() { diff --git a/app/src/main/java/com/utopiaindustries/qc_android/adapters/CheckPointAdapter.java b/app/src/main/java/com/utopiaindustries/qc_android/adapters/CheckPointAdapter.java index 0093df5..153f5bc 100644 --- a/app/src/main/java/com/utopiaindustries/qc_android/adapters/CheckPointAdapter.java +++ b/app/src/main/java/com/utopiaindustries/qc_android/adapters/CheckPointAdapter.java @@ -31,9 +31,9 @@ public class CheckPointAdapter extends RecyclerView.Adapter requestMultiplePermissionsLauncher; - // Activity Result Launchers - private ActivityResultLauncher cameraLauncher; - private ActivityResultLauncher galleryLauncher; - - private ImageView imageView; - private Button btnCamera, btnGallery; - private Uri photoUri; - - private static final int PENDING_CAMERA = 1; - private static final int PENDING_GALLERY = 2; - private int pendingAction = 0; - - + private DataEntryModel dataEntryModel; @Nullable @Override @@ -64,40 +29,33 @@ public class FragmentQcTerryOne extends Fragment { // Inflate the layout View view = inflater.inflate(R.layout.fragment_qc_terry_one, container, false); + initializeLayouts(view); + + return view; + } + + public void initializeLayouts(View view) { + dataEntryModel = AppDataManager.getInstance().getCurrentDataEntry(); // Initialize views edtFirstName = view.findViewById(R.id.edtFirstName); edtLastName = view.findViewById(R.id.edtLastName); edtEmail = view.findViewById(R.id.edtEmail); btnNext = view.findViewById(R.id.btnNext); - - imageView = view.findViewById(R.id.imageView); - btnCamera = view.findViewById(R.id.btnCamera); - btnGallery = view.findViewById(R.id.btnGallery); - - return view; } @Override public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); - // Initialize ViewModel - viewModel = new ViewModelProvider(requireActivity()).get(DataEntryViewModel.class); - // Load existing data if any - if (viewModel.getFirstName().getValue() != null) { - edtFirstName.setText(viewModel.getFirstName().getValue()); + if (dataEntryModel.getFirstName() != null) { + edtFirstName.setText(dataEntryModel.getFirstName()); } - if (viewModel.getLastName().getValue() != null) { - edtLastName.setText(viewModel.getLastName().getValue()); + if (dataEntryModel.getLastName() != null) { + edtLastName.setText(dataEntryModel.getLastName()); } - if (viewModel.getEmail().getValue() != null) { - edtEmail.setText(viewModel.getEmail().getValue()); - } - - if (viewModel.getSelectedImageUri().getValue() != null) { - photoUri = viewModel.getSelectedImageUri().getValue(); - imageView.setImageURI(photoUri); + if (dataEntryModel.getEmail() != null) { + edtEmail.setText(dataEntryModel.getEmail()); } // Setup button click @@ -105,189 +63,14 @@ public class FragmentQcTerryOne extends Fragment { @Override public void onClick(View v) { // Save data to ViewModel - viewModel.setFirstName(edtFirstName.getText().toString()); - viewModel.setLastName(edtLastName.getText().toString()); - viewModel.setEmail(edtEmail.getText().toString()); + dataEntryModel.setFirstName(edtFirstName.getText().toString()); + dataEntryModel.setLastName(edtLastName.getText().toString()); + dataEntryModel.setEmail(edtEmail.getText().toString()); // Navigate to next screen Navigation.findNavController(v) .navigate(R.id.action_fragmentOne_to_fragmentTwo); } }); - - // Initialize Activity Result Launchers - initializeLaunchers(); - - btnCamera.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - checkPermissionAndOpenCamera(); - } - }); - - btnGallery.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - checkPermissionAndOpenGallery(); - } - }); } - - private void initializeLaunchers() { - - requestMultiplePermissionsLauncher = registerForActivityResult( - new ActivityResultContracts.RequestMultiplePermissions(), - new ActivityResultCallback>() { - @Override - public void onActivityResult(Map result) { - boolean allGranted = true; - for (Boolean granted : result.values()) { - if (!granted) { - allGranted = false; - break; - } - } - - if (allGranted) { - // All permissions granted, proceed based on what was requested - if (pendingAction == PENDING_CAMERA) { - openCamera(); - } else if (pendingAction == PENDING_GALLERY) { - openGallery(); - } - } else { - // Some permissions denied - Toast.makeText(getContext(), "Permissions denied", Toast.LENGTH_SHORT).show(); - } - } - }); - // Camera launcher - cameraLauncher = registerForActivityResult( - new ActivityResultContracts.StartActivityForResult(), - result -> { - if (result.getResultCode() == getActivity().RESULT_OK && photoUri != null) { - imageView.setImageURI(photoUri); - viewModel.setSelectedImageUri(photoUri); - } - }); - - // Gallery launcher - galleryLauncher = registerForActivityResult( - new ActivityResultContracts.GetContent(), - uri -> { - if (uri != null) { - imageView.setImageURI(uri); - viewModel.setSelectedImageUri(uri); - } - }); - } - - /** - * Check permissions and open camera - */ - private void checkPermissionAndOpenCamera() { - String[] requiredPermissions = getRequiredCameraPermissions(); - - if (hasPermissions(requiredPermissions)) { - openCamera(); - } else { - pendingAction = PENDING_CAMERA; - requestMultiplePermissionsLauncher.launch(requiredPermissions); - } - } - - /** - * Check permissions and open gallery - */ - private void checkPermissionAndOpenGallery() { - String[] requiredPermissions = getRequiredGalleryPermissions(); - - if (hasPermissions(requiredPermissions)) { - openGallery(); - } else { - pendingAction = PENDING_GALLERY; - requestMultiplePermissionsLauncher.launch(requiredPermissions); - } - } - - /** - * Get required permissions for camera - */ - private String[] getRequiredCameraPermissions() { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { - // Android 13+ - Camera only (storage permission not needed for camera) - return new String[]{Manifest.permission.CAMERA}; - } else { - // Android 12 and below - Camera + storage for saving photo - return new String[]{ - Manifest.permission.CAMERA, - Manifest.permission.WRITE_EXTERNAL_STORAGE - }; - } - } - - /** - * Get required permissions for gallery - */ - private String[] getRequiredGalleryPermissions() { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { - // Android 13+ uses READ_MEDIA_IMAGES - return new String[]{Manifest.permission.READ_MEDIA_IMAGES}; - } else { - // Android 12 and below use READ_EXTERNAL_STORAGE - return new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}; - } - } - - /** - * Check if all permissions are granted - */ - private boolean hasPermissions(String[] permissions) { - for (String permission : permissions) { - if (ContextCompat.checkSelfPermission(requireContext(), permission) - != PackageManager.PERMISSION_GRANTED) { - return false; - } - } - return true; - } - - private void openCamera() { - try { - File photoFile = createImageFile(); - photoUri = FileProvider.getUriForFile( - requireContext(), - requireContext().getPackageName() + ".provider", - photoFile - ); - - Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); - cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoUri); - cameraLauncher.launch(cameraIntent); - - } catch (IOException e) { - e.printStackTrace(); - Toast.makeText(getContext(), "Error creating file", Toast.LENGTH_SHORT).show(); - } - } - - private void openGallery() { - galleryLauncher.launch("image/*"); - } - - private File createImageFile() throws IOException { - // Create an image file name - String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.getDefault()).format(new Date()); - String imageFileName = "JPEG_" + timeStamp + "_"; - - File storageDir = requireContext().getExternalFilesDir(null); - File image = File.createTempFile( - imageFileName, /* prefix */ - ".jpg", /* suffix */ - storageDir /* directory */ - ); - - return image; - } - } diff --git a/app/src/main/java/com/utopiaindustries/qc_android/fragments/FragmentQcTerryThree.java b/app/src/main/java/com/utopiaindustries/qc_android/fragments/FragmentQcTerryThree.java index 0e168dc..b342260 100644 --- a/app/src/main/java/com/utopiaindustries/qc_android/fragments/FragmentQcTerryThree.java +++ b/app/src/main/java/com/utopiaindustries/qc_android/fragments/FragmentQcTerryThree.java @@ -1,6 +1,7 @@ package com.utopiaindustries.qc_android.fragments; import android.os.Bundle; +import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -12,17 +13,17 @@ import android.widget.Toast; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.fragment.app.Fragment; -import androidx.lifecycle.ViewModelProvider; import com.utopiaindustries.qc_android.R; -import com.utopiaindustries.qc_android.viewmodels.DataEntryViewModel; +import com.utopiaindustries.qc_android.models.DataEntryModel; +import com.utopiaindustries.qc_android.utils.AppDataManager; public class FragmentQcTerryThree extends Fragment { - private EditText edtCompany, edtPosition, edtSalary; + private EditText edtCompany, edtPosition; private Button btnSubmit; private TextView tvSummary; - private DataEntryViewModel viewModel; + private DataEntryModel dataEntryModel; @Nullable @Override @@ -30,27 +31,30 @@ public class FragmentQcTerryThree extends Fragment { @Nullable Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_qc_terry_three, container, false); - edtCompany = view.findViewById(R.id.edtCompany); - edtPosition = view.findViewById(R.id.edtPosition); - edtSalary = view.findViewById(R.id.edtSalary); - btnSubmit = view.findViewById(R.id.btnSubmit); - tvSummary = view.findViewById(R.id.tvSummary); + initializeLayouts(view); return view; } + public void initializeLayouts(View view) { + dataEntryModel = AppDataManager.getInstance().getCurrentDataEntry(); + + edtCompany = view.findViewById(R.id.edtCompany); + edtPosition = view.findViewById(R.id.edtPosition); + btnSubmit = view.findViewById(R.id.btnSubmit); + tvSummary = view.findViewById(R.id.tvSummary); + } + @Override public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); - viewModel = new ViewModelProvider(requireActivity()).get(DataEntryViewModel.class); - // Load existing data - if (viewModel.getCompany().getValue() != null) { - edtCompany.setText(viewModel.getCompany().getValue()); + if (dataEntryModel.getCompany() != null) { + edtCompany.setText(dataEntryModel.getCompany()); } - if (viewModel.getPosition().getValue() != null) { - edtPosition.setText(viewModel.getPosition().getValue()); + if (dataEntryModel.getPosition() != null) { + edtPosition.setText(dataEntryModel.getPosition()); } // Display summary from previous screens @@ -71,8 +75,8 @@ public class FragmentQcTerryThree extends Fragment { } // Save final data - viewModel.setCompany(edtCompany.getText().toString()); - viewModel.setPosition(edtPosition.getText().toString()); + dataEntryModel.setCompany(edtCompany.getText().toString()); + dataEntryModel.setPosition(edtPosition.getText().toString()); // Submit data submitData(); @@ -84,33 +88,33 @@ public class FragmentQcTerryThree extends Fragment { StringBuilder summary = new StringBuilder(); summary.append("Summary:\n\n"); - if (viewModel.getFirstName().getValue() != null && - !viewModel.getFirstName().getValue().isEmpty()) { + if (dataEntryModel.getFirstName() != null && + !dataEntryModel.getFirstName().isEmpty()) { summary.append("Name: ") - .append(viewModel.getFirstName().getValue()) + .append(dataEntryModel.getFirstName()) .append(" ") - .append(viewModel.getLastName().getValue()) + .append(dataEntryModel.getLastName()) .append("\n"); } - if (viewModel.getEmail().getValue() != null && - !viewModel.getEmail().getValue().isEmpty()) { + if (dataEntryModel.getEmail() != null && + !dataEntryModel.getEmail().isEmpty()) { summary.append("Email: ") - .append(viewModel.getEmail().getValue()) + .append(dataEntryModel.getEmail()) .append("\n"); } - if (viewModel.getAddress().getValue() != null && - !viewModel.getAddress().getValue().isEmpty()) { + if (dataEntryModel.getAddress() != null && + !dataEntryModel.getAddress().isEmpty()) { summary.append("Address: ") - .append(viewModel.getAddress().getValue()) + .append(dataEntryModel.getAddress()) .append("\n"); } - if (viewModel.getCity().getValue() != null && - !viewModel.getCity().getValue().isEmpty()) { + if (dataEntryModel.getCity() != null && + !dataEntryModel.getCity().isEmpty()) { summary.append("City: ") - .append(viewModel.getCity().getValue()) + .append(dataEntryModel.getCity()) .append("\n"); } @@ -120,11 +124,12 @@ public class FragmentQcTerryThree extends Fragment { private void submitData() { // Show success message Toast.makeText(getActivity(), "Data submitted successfully!", Toast.LENGTH_SHORT).show(); - + DataEntryModel dataEntryModel = AppDataManager.getInstance().getCurrentDataEntry(); + Log.e("DataEntryModel: " ,""+dataEntryModel); // Update UI - btnSubmit.setText("Submitted ✓"); - btnSubmit.setEnabled(false); - btnSubmit.setBackgroundColor(getResources().getColor(android.R.color.darker_gray)); + //btnSubmit.setText("Submitted ✓"); + //btnSubmit.setEnabled(false); + //btnSubmit.setBackgroundColor(getResources().getColor(android.R.color.darker_gray)); // You would typically: // 1. Send data to API/backend diff --git a/app/src/main/java/com/utopiaindustries/qc_android/fragments/FragmentQcTerryTwo.java b/app/src/main/java/com/utopiaindustries/qc_android/fragments/FragmentQcTerryTwo.java index 256c61f..b4626b2 100644 --- a/app/src/main/java/com/utopiaindustries/qc_android/fragments/FragmentQcTerryTwo.java +++ b/app/src/main/java/com/utopiaindustries/qc_android/fragments/FragmentQcTerryTwo.java @@ -15,8 +15,6 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.Button; -import android.widget.EditText; -import android.widget.ImageView; import android.widget.TextView; import android.widget.Toast; @@ -38,7 +36,8 @@ import com.utopiaindustries.qc_android.R; import com.utopiaindustries.qc_android.adapters.CheckPointAdapter; import com.utopiaindustries.qc_android.helper.Helper; import com.utopiaindustries.qc_android.models.InspectionCheckPoint; -import com.utopiaindustries.qc_android.viewmodels.DataEntryViewModel; +import com.utopiaindustries.qc_android.models.DataEntryModel; +import com.utopiaindustries.qc_android.utils.AppDataManager; import java.io.File; import java.io.IOException; @@ -48,12 +47,11 @@ import java.util.Date; import java.util.List; import java.util.Locale; import java.util.Map; -import java.util.Objects; -public class FragmentQcTerryTwo extends Fragment implements CheckPointAdapter.OnCheckPointClickListener{ +public class FragmentQcTerryTwo extends Fragment implements CheckPointAdapter.OnCheckPointClickListener { private Button btnNext; - private DataEntryViewModel viewModel; + private DataEntryModel dataEntryModel; private CheckPointAdapter adapter; private List checkPointList = new ArrayList<>(); private RecyclerView recyclerView; @@ -82,6 +80,8 @@ public class FragmentQcTerryTwo extends Fragment implements CheckPointAdapter.On } public void initializeLayouts(View view) { + dataEntryModel = AppDataManager.getInstance().getCurrentDataEntry(); + recyclerView = view.findViewById(R.id.check_point_recycler_view); btnNext = view.findViewById(R.id.btnNext); @@ -91,9 +91,7 @@ public class FragmentQcTerryTwo extends Fragment implements CheckPointAdapter.On public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); - viewModel = new ViewModelProvider(requireActivity()).get(DataEntryViewModel.class); - - checkPointList.addAll(viewModel.getCheckPointList().getValue()); + checkPointList.addAll(dataEntryModel.getCheckPointList()); // Setup RecyclerView recyclerView.setLayoutManager(new LinearLayoutManager(getActivity())); adapter = new CheckPointAdapter(getActivity(), checkPointList, this); @@ -111,7 +109,6 @@ public class FragmentQcTerryTwo extends Fragment implements CheckPointAdapter.On }*/ - btnNext.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { @@ -133,49 +130,48 @@ public class FragmentQcTerryTwo extends Fragment implements CheckPointAdapter.On alertForPictures(getActivity(), position); } - @Override + /*@Override public void onImageClicked(int parentPosition, int imagePosition, Uri imageUri) { // Handle image click - maybe show in full screen // showImageFullScreen(imageUri); - } + }*/ @Override - public void onImageDeleteClicked(int parentPosition, int imagePosition) { + public void onImageDeleteClicked(int parentPosition) { // Remove image from checkpoint - //adapter.removeImageFromCheckPoint(parentPosition, imagePosition); + if (!checkPointList.get(parentPosition).getImages().isEmpty()) { + checkPointList.get(parentPosition).getImages().remove(checkPointList.get(parentPosition).getImages().size() - 1); + adapter.notifyItemChanged(parentPosition); + dataEntryModel.setCheckPointList(checkPointList); + } else { + System.out.println("The list is empty"); + } } - @Override + /*@Override public void onDeleteAllImagesClicked(int position) { - } + }*/ @Override public void onRemarksChanged(int position, String remarks) { - // Update remarks in the model - Log.e("Pos: ",""+position); - Log.e("Remarks: ",""+remarks); - InspectionCheckPoint item = checkPointList.get(position); - item.setRemarks(remarks); - viewModel.setCheckPointList(checkPointList); - Log.e("ViewModel: ",""+viewModel.getCheckPointList().getValue()); + + dataEntryModel.setCheckPointList(checkPointList); + Log.e("ViewModel: ", "" + dataEntryModel.getCheckPointList()); } @Override public void onCheckBoxChanged(int position, boolean isOkChecked, boolean isNoChecked) { - // Handle checkbox changes - InspectionCheckPoint item = checkPointList.get(position); - item.setOkChecked(isOkChecked); - item.setNoChecked(isNoChecked); - viewModel.setCheckPointList(checkPointList); + + dataEntryModel.setCheckPointList(checkPointList); } - private void openImagePicker(int position) { + /*private void openImagePicker(int position) { // Open camera or gallery // After getting image URI: // Uri imageUri = ...; // adapter.addImageToCheckPoint(position, imageUri); - } + }*/ public void alertForPictures(Context con, int position) { ViewGroup viewGroup = requireActivity().findViewById(android.R.id.content); @@ -248,7 +244,7 @@ public class FragmentQcTerryTwo extends Fragment implements CheckPointAdapter.On result -> { if (result.getResultCode() == getActivity().RESULT_OK && photoUri != null) { //imageView.setImageURI(photoUri); - viewModel.setSelectedImageUri(photoUri); + dataEntryModel.setSelectedImageUri(photoUri); Helper.uriToByteArrayAsync( getContext(), @@ -258,7 +254,7 @@ public class FragmentQcTerryTwo extends Fragment implements CheckPointAdapter.On requireActivity().runOnUiThread(() -> { checkPointList.get(currentPosition).addImage(compressedImage); adapter.notifyItemChanged(currentPosition); - viewModel.setCheckPointList(checkPointList); + dataEntryModel.setCheckPointList(checkPointList); currentPosition = -1; }); }, @@ -277,7 +273,7 @@ public class FragmentQcTerryTwo extends Fragment implements CheckPointAdapter.On uri -> { if (uri != null) { //imageView.setImageURI(uri); - viewModel.setSelectedImageUri(uri); + dataEntryModel.setSelectedImageUri(uri); Helper.uriToByteArrayAsync( getContext(), @@ -287,7 +283,7 @@ public class FragmentQcTerryTwo extends Fragment implements CheckPointAdapter.On requireActivity().runOnUiThread(() -> { checkPointList.get(currentPosition).addImage(compressedImage); adapter.notifyItemChanged(currentPosition); - viewModel.setCheckPointList(checkPointList); + dataEntryModel.setCheckPointList(checkPointList); currentPosition = -1; }); }, diff --git a/app/src/main/java/com/utopiaindustries/qc_android/models/DataEntryModel.java b/app/src/main/java/com/utopiaindustries/qc_android/models/DataEntryModel.java new file mode 100644 index 0000000..4fe86f9 --- /dev/null +++ b/app/src/main/java/com/utopiaindustries/qc_android/models/DataEntryModel.java @@ -0,0 +1,143 @@ +package com.utopiaindustries.qc_android.models; + +import android.net.Uri; + +import java.util.ArrayList; +import java.util.List; + +public class DataEntryModel { + + private static final long serialVersionUID = 1L; + // Personal Info + private String firstName; + private String lastName; + private String email; + + // Address Info + private String address; + private String city; + + // Employment Info + private String company; + private String position; + + private Uri selectedImageUri; + private List checkPointList = new ArrayList<>(); + + // Constructor + public DataEntryModel() { + // Default constructor + } + + // Copy constructor + public DataEntryModel(DataEntryModel other) { + this.firstName = other.firstName; + this.lastName = other.lastName; + this.email = other.email; + this.address = other.address; + this.city = other.city; + this.company = other.company; + this.position = other.position; + this.selectedImageUri = other.selectedImageUri; + this.checkPointList = new ArrayList<>(other.checkPointList); + } + + public List getCheckPointList() { + return checkPointList; + } + + public void setCheckPointList(List checkPointList) { + this.checkPointList = checkPointList; + } + + public Uri getSelectedImageUri() { + return selectedImageUri; + } + + public void setSelectedImageUri(Uri selectedImageUri) { + this.selectedImageUri = selectedImageUri; + } + + public String getPosition() { + return position; + } + + public void setPosition(String position) { + this.position = position; + } + + public String getCompany() { + return company; + } + + public void setCompany(String company) { + this.company = company; + } + + public String getCity() { + return city; + } + + public void setCity(String city) { + this.city = city; + } + + public String getAddress() { + return address; + } + + public void setAddress(String address) { + this.address = address; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public void clear() { + firstName = null; + lastName = null; + email = null; + address = null; + city = null; + company = null; + position = null; + selectedImageUri = null; + checkPointList.clear(); + } + + @Override + public String toString() { + return "DataEntryModel{" + + "firstName='" + firstName + '\'' + + ", lastName='" + lastName + '\'' + + ", email='" + email + '\'' + + ", address='" + address + '\'' + + ", city='" + city + '\'' + + ", company='" + company + '\'' + + ", position='" + position + '\'' + + ", selectedImageUri=" + selectedImageUri + + ", checkPointListSize=" + checkPointList + + '}'; + } +} diff --git a/app/src/main/java/com/utopiaindustries/qc_android/utils/AppDataManager.java b/app/src/main/java/com/utopiaindustries/qc_android/utils/AppDataManager.java new file mode 100644 index 0000000..7e3cb72 --- /dev/null +++ b/app/src/main/java/com/utopiaindustries/qc_android/utils/AppDataManager.java @@ -0,0 +1,32 @@ +package com.utopiaindustries.qc_android.utils; + +import com.utopiaindustries.qc_android.models.DataEntryModel; + +public class AppDataManager { + + private static AppDataManager instance; + private DataEntryModel currentDataEntry; + + private AppDataManager() { + currentDataEntry = new DataEntryModel(); + } + + public static AppDataManager getInstance() { + if (instance == null) { + instance = new AppDataManager(); + } + return instance; + } + + public DataEntryModel getCurrentDataEntry() { + return currentDataEntry; + } + + public void setCurrentDataEntry(DataEntryModel dataEntry) { + this.currentDataEntry = dataEntry; + } + + public void clearCurrentDataEntry() { + currentDataEntry = new DataEntryModel(); + } +} diff --git a/app/src/main/java/com/utopiaindustries/qc_android/utils/NotificationHelper.java b/app/src/main/java/com/utopiaindustries/qc_android/utils/NotificationHelper.java new file mode 100644 index 0000000..85785d2 --- /dev/null +++ b/app/src/main/java/com/utopiaindustries/qc_android/utils/NotificationHelper.java @@ -0,0 +1,83 @@ +package com.utopiaindustries.qc_android.utils; + +import android.app.NotificationChannel; +import android.app.NotificationManager; +import android.content.Context; +import android.os.Build; + +import androidx.core.app.NotificationCompat; + +import com.utopiaindustries.qc_android.R; + +public class NotificationHelper { + + private static final String CHANNEL_ID = "00112233"; + private static final String CHANNEL_NAME = "QC_App_Channel"; + private static final String CHANNEL_DESCRIPTION = "Channel_for_qc_app"; + private static final String PRODUCT_CHANNEL_ID = "675463133"; + private static final String PRODUCT_CHANNEL_NAME= "QC_PRODUCT_NOTIFICATION_CHANNEL"; + public static final String PRODUCT_CHANNEL_DESCRIPTION = "QC_CHANNEL_FOR_PRODUCT"; + + + public static void showNotification(Context context, String title, String message) { + NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); + + // Create a notification channel for devices running Android Oreo (API 26) and higher + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + NotificationChannel channel = new NotificationChannel(CHANNEL_ID, CHANNEL_NAME, NotificationManager.IMPORTANCE_DEFAULT); + channel.setDescription(CHANNEL_DESCRIPTION); + notificationManager.createNotificationChannel(channel); + } + + // Build the notification + NotificationCompat.Builder builder = new NotificationCompat.Builder(context, CHANNEL_ID) + .setSmallIcon(R.drawable.utopia_svg_logo) // Set your notification icon here + .setContentTitle(title) + .setContentText(message) + .setPriority(NotificationCompat.PRIORITY_DEFAULT); + + // Show the notification + notificationManager.notify(0, builder.build()); + } + + public static void showProductNotification(Context context, String title, String message) { + NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); + + // Create a notification channel for devices running Android Oreo (API 26) and higher + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + NotificationChannel channel = new NotificationChannel(PRODUCT_CHANNEL_ID, PRODUCT_CHANNEL_NAME, NotificationManager.IMPORTANCE_DEFAULT); + channel.setDescription(PRODUCT_CHANNEL_DESCRIPTION); + notificationManager.createNotificationChannel(channel); + } + + // Build the notification + NotificationCompat.Builder builder = new NotificationCompat.Builder(context, PRODUCT_CHANNEL_ID) + .setSmallIcon(R.drawable.utopia_svg_logo) // Set your notification icon here + .setContentTitle(title) + .setContentText(message) + .setPriority(NotificationCompat.PRIORITY_HIGH ); + + // Show the notification + notificationManager.notify(0, builder.build()); + } + + public static void showNotificationForReportUpload(Context context, int notificationId, String title, String message) { + NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + NotificationChannel channel = new NotificationChannel(CHANNEL_ID, CHANNEL_NAME, NotificationManager.IMPORTANCE_DEFAULT); + channel.setDescription(CHANNEL_DESCRIPTION); + notificationManager.createNotificationChannel(channel); + } + + NotificationCompat.Builder builder = new NotificationCompat.Builder(context, CHANNEL_ID) + .setSmallIcon(R.drawable.utopia_svg_logo) + .setContentTitle(title) + .setContentText(message) + .setStyle(new NotificationCompat.BigTextStyle().bigText(message)) // Allow long messages + .setPriority(NotificationCompat.PRIORITY_DEFAULT); + + notificationManager.notify(notificationId, builder.build()); + } + +} diff --git a/app/src/main/java/com/utopiaindustries/qc_android/viewmodels/DataEntryViewModel.java b/app/src/main/java/com/utopiaindustries/qc_android/viewmodels/DataEntryViewModel.java deleted file mode 100644 index e410880..0000000 --- a/app/src/main/java/com/utopiaindustries/qc_android/viewmodels/DataEntryViewModel.java +++ /dev/null @@ -1,106 +0,0 @@ -package com.utopiaindustries.qc_android.viewmodels; - -import android.net.Uri; - -import androidx.lifecycle.LiveData; -import androidx.lifecycle.MutableLiveData; -import androidx.lifecycle.ViewModel; - -import com.utopiaindustries.qc_android.models.InspectionCheckPoint; - -import java.util.ArrayList; -import java.util.List; - -public class DataEntryViewModel extends ViewModel { - - // Personal Info - private MutableLiveData firstName = new MutableLiveData<>(); - private MutableLiveData lastName = new MutableLiveData<>(); - private MutableLiveData email = new MutableLiveData<>(); - - // Address Info - private MutableLiveData address = new MutableLiveData<>(); - private MutableLiveData city = new MutableLiveData<>(); - - // Employment Info - private MutableLiveData company = new MutableLiveData<>(); - private MutableLiveData position = new MutableLiveData<>(); - - private MutableLiveData selectedImageUri = new MutableLiveData<>(); - - private MutableLiveData> checkPointList = - new MutableLiveData<>(new ArrayList<>()); - - // Getters and Setters - public LiveData getFirstName() { - return firstName; - } - - public void setFirstName(String firstName) { - this.firstName.setValue(firstName); - } - - public LiveData getLastName() { - return lastName; - } - - public void setLastName(String lastName) { - this.lastName.setValue(lastName); - } - - public LiveData getEmail() { - return email; - } - - public void setEmail(String email) { - this.email.setValue(email); - } - - public LiveData getAddress() { - return address; - } - - public void setAddress(String address) { - this.address.setValue(address); - } - - public LiveData getCity() { - return city; - } - - public void setCity(String city) { - this.city.setValue(city); - } - - public LiveData getCompany() { - return company; - } - - public void setCompany(String company) { - this.company.setValue(company); - } - - public LiveData getPosition() { - return position; - } - - public void setPosition(String position) { - this.position.setValue(position); - } - - public MutableLiveData getSelectedImageUri() { - return selectedImageUri; - } - - public void setSelectedImageUri(Uri uri) { - selectedImageUri.setValue(uri); - } - - public LiveData> getCheckPointList() { - return checkPointList; - } - - public void setCheckPointList(List list) { - checkPointList.setValue(list); - } -} diff --git a/app/src/main/res/drawable/utopia_svg_logo.xml b/app/src/main/res/drawable/utopia_svg_logo.xml new file mode 100644 index 0000000..4afe746 --- /dev/null +++ b/app/src/main/res/drawable/utopia_svg_logo.xml @@ -0,0 +1,73 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout-sw800dp/fragment_qc_terry_one.xml b/app/src/main/res/layout-sw800dp/fragment_qc_terry_one.xml index 8ca4088..e07e72a 100644 --- a/app/src/main/res/layout-sw800dp/fragment_qc_terry_one.xml +++ b/app/src/main/res/layout-sw800dp/fragment_qc_terry_one.xml @@ -10,16 +10,16 @@ android:layout_height="wrap_content" android:background="@color/theme_color" android:minHeight="?attr/actionBarSize" - android:theme="?attr/actionBarTheme" > + android:theme="?attr/actionBarTheme"> @@ -27,11 +27,11 @@ + android:orientation="vertical" + android:padding="10dp"> - - - - -