From 6e8b32edaaa6edaa4cd2dd44a8c5c4dcd940e41c Mon Sep 17 00:00:00 2001 From: "saad.siddiq" Date: Mon, 9 Dec 2024 17:23:02 +0500 Subject: [PATCH] optimize image saving to server --- app/src/main/AndroidManifest.xml | 1 + .../activities/SummaryActivity.java | 47 ++++++- .../adapters/ItemStepsAdapter.java | 8 +- .../fragments/CheckingFragment.java | 2 +- .../fragments/CuttingFragment.java | 2 +- .../fragments/PackingFragment.java | 2 +- .../fragments/StitchingFragment.java | 2 +- .../fragments/SubStoreFragment.java | 118 ++++++++++++------ .../qualitycontrol/helper/Helper.java | 19 +-- .../qualitycontrol/helper/Preference.java | 7 +- .../models/QualitySaveResponse.java | 12 ++ .../qualitycontrol/utils/MyApplication.java | 17 +++ app/src/main/res/drawable/icon_home.png | Bin 0 -> 215 bytes app/src/main/res/layout/activity_summary.xml | 28 ++++- 14 files changed, 203 insertions(+), 62 deletions(-) create mode 100644 app/src/main/java/com/utopiaindustries/qualitycontrol/utils/MyApplication.java create mode 100644 app/src/main/res/drawable/icon_home.png diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index e4fd563..bf18b94 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -18,6 +18,7 @@ tools:ignore="ScopedStorage" /> parent, View view, int sub_position, long id) { - currentItem.setSelectedOption(sub_position + 1); - currentItem.setRating(sub_position + 1); + currentItem.setSelectedOption(sub_position); + currentItem.setRating(Integer.parseInt(parent.getItemAtPosition(sub_position).toString())); selectedValue = Double.parseDouble(parent.getItemAtPosition(sub_position).toString()); percentage = (selectedValue / 5) * 100; diff --git a/app/src/main/java/com/utopiaindustries/qualitycontrol/fragments/CheckingFragment.java b/app/src/main/java/com/utopiaindustries/qualitycontrol/fragments/CheckingFragment.java index bb9d729..0c911c3 100644 --- a/app/src/main/java/com/utopiaindustries/qualitycontrol/fragments/CheckingFragment.java +++ b/app/src/main/java/com/utopiaindustries/qualitycontrol/fragments/CheckingFragment.java @@ -229,7 +229,7 @@ public class CheckingFragment extends Fragment implements EasyPermissions.Permis if (!imageList.isEmpty()) { sharedViewModel.setCheckingImageList(imageList); }*/ - ((HomeActivity) getActivity()).navigateToFragment(new PackingFragment(), true); + ((HomeActivity) requireActivity()).navigateToFragment(new PackingFragment(), true); // } } }); diff --git a/app/src/main/java/com/utopiaindustries/qualitycontrol/fragments/CuttingFragment.java b/app/src/main/java/com/utopiaindustries/qualitycontrol/fragments/CuttingFragment.java index 9a2e36b..a2bc377 100644 --- a/app/src/main/java/com/utopiaindustries/qualitycontrol/fragments/CuttingFragment.java +++ b/app/src/main/java/com/utopiaindustries/qualitycontrol/fragments/CuttingFragment.java @@ -282,7 +282,7 @@ public class CuttingFragment extends Fragment implements EasyPermissions.Permiss sharedViewModel.setCuttingImageList(imageList); }*/ - ((HomeActivity) getActivity()).navigateToFragment(new StitchingFragment(), true); + ((HomeActivity) requireActivity()).navigateToFragment(new StitchingFragment(), true); // } diff --git a/app/src/main/java/com/utopiaindustries/qualitycontrol/fragments/PackingFragment.java b/app/src/main/java/com/utopiaindustries/qualitycontrol/fragments/PackingFragment.java index 8776737..8ac4e3c 100644 --- a/app/src/main/java/com/utopiaindustries/qualitycontrol/fragments/PackingFragment.java +++ b/app/src/main/java/com/utopiaindustries/qualitycontrol/fragments/PackingFragment.java @@ -243,7 +243,7 @@ public class PackingFragment extends Fragment implements EasyPermissions.Permiss if (!imageList.isEmpty()) { sharedViewModel.setPackingImageList(imageList); }*/ - ((HomeActivity) getActivity()).navigateToFragment(new SubStoreFragment(), true); + ((HomeActivity) requireActivity()).navigateToFragment(new SubStoreFragment(), true); // } } }); diff --git a/app/src/main/java/com/utopiaindustries/qualitycontrol/fragments/StitchingFragment.java b/app/src/main/java/com/utopiaindustries/qualitycontrol/fragments/StitchingFragment.java index cd78ec8..3e8ba00 100644 --- a/app/src/main/java/com/utopiaindustries/qualitycontrol/fragments/StitchingFragment.java +++ b/app/src/main/java/com/utopiaindustries/qualitycontrol/fragments/StitchingFragment.java @@ -243,7 +243,7 @@ public class StitchingFragment extends Fragment implements EasyPermissions.Permi if (!imageList.isEmpty()) { sharedViewModel.setStitchingImageList(imageList); }*/ - ((HomeActivity) getActivity()).navigateToFragment(new CheckingFragment(), true); + ((HomeActivity) requireActivity()).navigateToFragment(new CheckingFragment(), true); // } } }); diff --git a/app/src/main/java/com/utopiaindustries/qualitycontrol/fragments/SubStoreFragment.java b/app/src/main/java/com/utopiaindustries/qualitycontrol/fragments/SubStoreFragment.java index 001ca49..3faab37 100644 --- a/app/src/main/java/com/utopiaindustries/qualitycontrol/fragments/SubStoreFragment.java +++ b/app/src/main/java/com/utopiaindustries/qualitycontrol/fragments/SubStoreFragment.java @@ -1,6 +1,8 @@ package com.utopiaindustries.qualitycontrol.fragments; import android.Manifest; +import android.app.Activity; +import android.app.Application; import android.content.ActivityNotFoundException; import android.content.Context; import android.content.Intent; @@ -42,6 +44,7 @@ import com.utopiaindustries.qualitycontrol.adapters.ItemStepsAdapter; import com.utopiaindustries.qualitycontrol.helper.Helper; import com.utopiaindustries.qualitycontrol.helper.Preference; import com.utopiaindustries.qualitycontrol.utils.ImageSelectionListener; +import com.utopiaindustries.qualitycontrol.utils.MyApplication; import com.utopiaindustries.qualitycontrol.utils.ProgressDialogFragment; import com.utopiaindustries.qualitycontrol.viewmodels.HomeViewModel; import com.utopiaindustries.qualitycontrol.viewmodels.ItemModel; @@ -83,6 +86,7 @@ public class SubStoreFragment extends Fragment implements EasyPermissions.Permis private int selectedPosition = -1; HomeViewModel homeViewModel; private int deletePosition = -1; + Context mContext; // Activity Result Launcher for Gallery private final ActivityResultLauncher imagePickerLauncher = @@ -154,6 +158,13 @@ public class SubStoreFragment extends Fragment implements EasyPermissions.Permis } }); + @Override + public void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + setRetainInstance(true); + } + @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { @@ -273,35 +284,45 @@ public class SubStoreFragment extends Fragment implements EasyPermissions.Permis homeViewModel.getUserLiveData().observe(getActivity(), qcResponse -> { if (qcResponse != null) { - /*Log.e("qcResponse: ", "" + qcResponse); - Log.e("","Status: " + qcResponse.getStatus() + " Message: " + qcResponse.getMessage() + " Percentage: " + qcResponse.getOverAllPercentage()); - Log.e("","Cut: " + qcResponse.getCutting() + " Stitch: " + qcResponse.getStiching() + " Check: " + qcResponse.getChecking()); - Log.e("","Pack: " + qcResponse.getPacking() + " Substore: " + qcResponse.getSub_Store());*/ - Preference.remove(Helper.project_file, Helper.departmentId, getActivity()); - Preference.remove(Helper.project_file, Helper.departmentName, getActivity()); - Preference.remove(Helper.project_file, Helper.locationSiteId, getActivity()); - Preference.remove(Helper.project_file, Helper.locationSiteName, getActivity()); + try { + Preference.remove(Helper.project_file, Helper.departmentId, requireActivity()); + Preference.remove(Helper.project_file, Helper.departmentName, requireActivity()); - Preference.remove(Helper.project_file, Helper.unitId, getActivity()); - Preference.remove(Helper.project_file, Helper.unitName, getActivity()); + Preference.remove(Helper.project_file, Helper.locationSiteId, requireActivity()); + Preference.remove(Helper.project_file, Helper.locationSiteName, requireActivity()); - Preference.remove(Helper.project_file, Helper.floorId, getActivity()); - Preference.remove(Helper.project_file, Helper.floorName, getActivity()); + Preference.remove(Helper.project_file, Helper.unitId, requireActivity()); + Preference.remove(Helper.project_file, Helper.unitName, requireActivity()); - Helper.RemoveArrayList(Helper.listCutting, getActivity()); - Helper.RemoveArrayList(Helper.listStitching, getActivity()); - Helper.RemoveArrayList(Helper.listChecking, getActivity()); - Helper.RemoveArrayList(Helper.listPacking, getActivity()); - Helper.RemoveArrayList(Helper.listSubStore, getActivity()); + Preference.remove(Helper.project_file, Helper.floorId, requireActivity()); + Preference.remove(Helper.project_file, Helper.floorName, requireActivity()); - //Preference.setMyStringPref(Helper.project_file, Helper.InProcess, getActivity(), "false"); + Helper.RemoveArrayList(Helper.listCutting, requireActivity()); + Helper.RemoveArrayList(Helper.listStitching, requireActivity()); + Helper.RemoveArrayList(Helper.listChecking, requireActivity()); + Helper.RemoveArrayList(Helper.listPacking, requireActivity()); + Helper.RemoveArrayList(Helper.listSubStore, requireActivity()); + } + catch (Exception ex) { + Log.e("Exception: ",""+ ex.getMessage()); + } - getActivity().finish(); - Intent intent = new Intent(getActivity(), SummaryActivity.class); + Context context = getActivity() != null ? getActivity() : MyApplication.getInstance().getApplicationContext(); + + Intent intent = new Intent(context, SummaryActivity.class); intent.putExtra("Percentage", qcResponse.getOverAllPercentage()); intent.putExtra("Summary", qcResponse); - startActivity(intent); + + if (context instanceof Application) { + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + } + + context.startActivity(intent); + + if (getActivity() != null) { + getActivity().finish(); + } } }); } @@ -553,21 +574,32 @@ public class SubStoreFragment extends Fragment implements EasyPermissions.Permis } public void showProgressDialog() { - ProgressDialogFragment progressDialog = new ProgressDialogFragment(); - progressDialog.setCancelable(false); - progressDialog.show(requireActivity().getSupportFragmentManager(), "progressDialog"); + if (getActivity() != null && isAdded()) { + ProgressDialogFragment progressDialog = new ProgressDialogFragment(); + progressDialog.setCancelable(false); + progressDialog.show(getActivity().getSupportFragmentManager(), "progressDialog"); + } + else { + Log.e("Dialog-Activity",": null"); + } + } public void dismissProgressDialog() { - ProgressDialogFragment progressDialog = (ProgressDialogFragment) requireActivity().getSupportFragmentManager().findFragmentByTag("progressDialog"); - if (progressDialog != null) { - progressDialog.dismiss(); + if (getActivity() != null && isAdded()) { + ProgressDialogFragment progressDialog = (ProgressDialogFragment) getActivity().getSupportFragmentManager().findFragmentByTag("progressDialog"); + if (progressDialog != null) { + progressDialog.dismiss(); + } + } + else { + Log.e("Dialog-Activity",": null"); } } public void showImageDialog() { AlertDialog.Builder builder = new AlertDialog.Builder(requireContext()); - LayoutInflater inflater = requireActivity().getLayoutInflater(); + LayoutInflater inflater = requireActivity().getLayoutInflater(); View dialogView = inflater.inflate(R.layout.dialog_select_image, null); builder.setView(dialogView); @@ -612,15 +644,15 @@ public class SubStoreFragment extends Fragment implements EasyPermissions.Permis List updatedItemList = itemModelList; // Or adapter.getItemList() - /*for (ItemModel item : updatedItemList) { - Log.e("AdapterData", "ProcessId: " + item.getProcessId() + - ", StepId: " + item.getStepId() + - ", SpinnerSelection: " + item.getSelectedOption() + - ", Rating: " + item.getRating() + - ", Percentage: " + item.getPercentage() + - ", Remarks: " + item.getRemarks() + - ", ImageList: " + item.getImageArrayList()); - }*/ + /*for (ItemModel item : updatedItemList) { + Log.e("AdapterData", "ProcessId: " + item.getProcessId() + + ", StepId: " + item.getStepId() + + ", SpinnerSelection: " + item.getSelectedOption() + + ", Rating: " + item.getRating() + + ", Percentage: " + item.getPercentage() + + ", Remarks: " + item.getRemarks() + + ", ImageList: " + item.getImageArrayList()); + }*/ Helper.saveArrayList(itemModelList, Helper.listSubStore, getActivity()); //viewModel.appendToQualityControlItemList(itemModelList); @@ -659,4 +691,16 @@ public class SubStoreFragment extends Fragment implements EasyPermissions.Permis }); } + + @Override + public void onAttach(@NonNull Context context) { + super.onAttach(context); + mContext = context; + } + + @Override + public void onDetach() { + super.onDetach(); + mContext = null; + } } \ No newline at end of file diff --git a/app/src/main/java/com/utopiaindustries/qualitycontrol/helper/Helper.java b/app/src/main/java/com/utopiaindustries/qualitycontrol/helper/Helper.java index ebe11d8..23645ca 100644 --- a/app/src/main/java/com/utopiaindustries/qualitycontrol/helper/Helper.java +++ b/app/src/main/java/com/utopiaindustries/qualitycontrol/helper/Helper.java @@ -102,15 +102,18 @@ public class Helper { } static public void RemoveArrayList(String key, Context context) { - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); - if (prefs.contains(key)) { // Check if the key exists - SharedPreferences.Editor editor = prefs.edit(); - editor.remove(key); // Remove the key-value pair - editor.apply(); // Apply changes - ///Log.e("SharedPreferences", "Key '" + key + "' removed successfully."); - } else { - //Log.e("SharedPreferences", "Key '" + key + "' does not exist."); + if (context != null) { + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); + if (prefs.contains(key)) { // Check if the key exists + SharedPreferences.Editor editor = prefs.edit(); + editor.remove(key); // Remove the key-value pair + editor.apply(); // Apply changes + ///Log.e("SharedPreferences", "Key '" + key + "' removed successfully."); + } else { + Log.e("SharedPreferences", "Key '" + key + "' does not exist."); + } } + } //for department, site, unit, floor diff --git a/app/src/main/java/com/utopiaindustries/qualitycontrol/helper/Preference.java b/app/src/main/java/com/utopiaindustries/qualitycontrol/helper/Preference.java index 33844d9..43f4391 100644 --- a/app/src/main/java/com/utopiaindustries/qualitycontrol/helper/Preference.java +++ b/app/src/main/java/com/utopiaindustries/qualitycontrol/helper/Preference.java @@ -68,9 +68,12 @@ public class Preference { public static void remove(String fileName, String key, Context context) { // perform validation etc.. - if (getPrefs(fileName,context).contains(key)) { - getPrefs(fileName,context).edit().remove(key).apply(); + if (context != null) { + if (getPrefs(fileName,context).contains(key)) { + getPrefs(fileName,context).edit().remove(key).apply(); + } } + } public static void removeAll(String fileName, Context context) { // perform validation etc.. diff --git a/app/src/main/java/com/utopiaindustries/qualitycontrol/models/QualitySaveResponse.java b/app/src/main/java/com/utopiaindustries/qualitycontrol/models/QualitySaveResponse.java index af5efa9..01175f5 100644 --- a/app/src/main/java/com/utopiaindustries/qualitycontrol/models/QualitySaveResponse.java +++ b/app/src/main/java/com/utopiaindustries/qualitycontrol/models/QualitySaveResponse.java @@ -40,6 +40,10 @@ public class QualitySaveResponse implements Serializable { @Expose private String Sub_Store; + @SerializedName("reportId") + @Expose + private String ReportId; + public String getOverAllPercentage() { return overAllPercentage; } @@ -103,4 +107,12 @@ public class QualitySaveResponse implements Serializable { public void setSub_Store(String sub_Store) { Sub_Store = sub_Store; } + + public String getReportId() { + return ReportId; + } + + public void setReportId(String reportId) { + ReportId = reportId; + } } diff --git a/app/src/main/java/com/utopiaindustries/qualitycontrol/utils/MyApplication.java b/app/src/main/java/com/utopiaindustries/qualitycontrol/utils/MyApplication.java new file mode 100644 index 0000000..7167d2f --- /dev/null +++ b/app/src/main/java/com/utopiaindustries/qualitycontrol/utils/MyApplication.java @@ -0,0 +1,17 @@ +package com.utopiaindustries.qualitycontrol.utils; + +import android.app.Application; + +public class MyApplication extends Application { + private static MyApplication instance; + + @Override + public void onCreate() { + super.onCreate(); + instance = this; // Store the instance of the Application + } + + public static MyApplication getInstance() { + return instance; + } +} diff --git a/app/src/main/res/drawable/icon_home.png b/app/src/main/res/drawable/icon_home.png new file mode 100644 index 0000000000000000000000000000000000000000..c81b39a018ca05ff15f69eec482ec36ce997df16 GIT binary patch literal 215 zcmeAS@N?(olHy`uVBq!ia0vp^Dj>|k0wldT1B8LpJWm(L5Rc<;FYV=ZaFA#( + app:srcCompat="@drawable/icon_home" /> + app:layout_constraintTop_toBottomOf="@+id/txt_report_id" /> + app:layout_constraintTop_toBottomOf="@+id/txt_report_id" /> + + \ No newline at end of file