optimize image saving to server

master
saad.siddiq 2024-12-09 17:23:02 +05:00
parent f986f0a821
commit 6e8b32edaa
14 changed files with 203 additions and 62 deletions

View File

@ -18,6 +18,7 @@
tools:ignore="ScopedStorage" /> tools:ignore="ScopedStorage" />
<application <application
android:name=".utils.MyApplication"
android:allowBackup="true" android:allowBackup="true"
android:allowClearUserData="true" android:allowClearUserData="true"
android:dataExtractionRules="@xml/data_extraction_rules" android:dataExtractionRules="@xml/data_extraction_rules"

View File

@ -14,11 +14,13 @@ import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat; import androidx.core.view.WindowInsetsCompat;
import com.utopiaindustries.qualitycontrol.R; import com.utopiaindustries.qualitycontrol.R;
import com.utopiaindustries.qualitycontrol.helper.Helper;
import com.utopiaindustries.qualitycontrol.helper.Preference;
import com.utopiaindustries.qualitycontrol.models.QualitySaveResponse; import com.utopiaindustries.qualitycontrol.models.QualitySaveResponse;
public class SummaryActivity extends AppCompatActivity { public class SummaryActivity extends AppCompatActivity {
TextView txtPercentage, txtCutting, txtStitching, txtChecking, txtPacking, txtSubStore; TextView txtPercentage, txtCutting, txtStitching, txtChecking, txtPacking, txtSubStore, txtReportId;
String overallPercentage; String overallPercentage;
ImageView img_back; ImageView img_back;
QualitySaveResponse qualitySaveResponse; QualitySaveResponse qualitySaveResponse;
@ -42,12 +44,18 @@ public class SummaryActivity extends AppCompatActivity {
txtChecking.setText(qualitySaveResponse.getChecking()); txtChecking.setText(qualitySaveResponse.getChecking());
txtPacking.setText(qualitySaveResponse.getPacking()); txtPacking.setText(qualitySaveResponse.getPacking());
txtSubStore.setText(qualitySaveResponse.getSub_Store()); txtSubStore.setText(qualitySaveResponse.getSub_Store());
txtReportId.setText(String.format("Report ID: %s", qualitySaveResponse.getReportId()));
img_back.setOnClickListener(new View.OnClickListener() { img_back.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
clearPreferences();
finish(); finish();
Intent intent = new Intent(SummaryActivity.this, HomeActivity.class); Intent intent = new Intent(SummaryActivity.this, HomeActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent); startActivity(intent);
} }
}); });
@ -72,5 +80,42 @@ public class SummaryActivity extends AppCompatActivity {
txtChecking = findViewById(R.id.txt_checking_percentage); txtChecking = findViewById(R.id.txt_checking_percentage);
txtPacking = findViewById(R.id.txt_packing_percentage); txtPacking = findViewById(R.id.txt_packing_percentage);
txtSubStore = findViewById(R.id.txt_substore_percentage); txtSubStore = findViewById(R.id.txt_substore_percentage);
txtReportId = findViewById(R.id.txt_report_id);
}
public void clearPreferences() {
try {
Preference.remove(Helper.project_file, Helper.departmentId, SummaryActivity.this);
Preference.remove(Helper.project_file, Helper.departmentName, SummaryActivity.this);
Preference.remove(Helper.project_file, Helper.locationSiteId, SummaryActivity.this);
Preference.remove(Helper.project_file, Helper.locationSiteName, SummaryActivity.this);
Preference.remove(Helper.project_file, Helper.unitId, SummaryActivity.this);
Preference.remove(Helper.project_file, Helper.unitName, SummaryActivity.this);
Preference.remove(Helper.project_file, Helper.floorId, SummaryActivity.this);
Preference.remove(Helper.project_file, Helper.floorName, SummaryActivity.this);
Helper.RemoveArrayList(Helper.listCutting, SummaryActivity.this);
Helper.RemoveArrayList(Helper.listStitching, SummaryActivity.this);
Helper.RemoveArrayList(Helper.listChecking, SummaryActivity.this);
Helper.RemoveArrayList(Helper.listPacking, SummaryActivity.this);
Helper.RemoveArrayList(Helper.listSubStore, SummaryActivity.this);
}
catch (Exception ex) {
Log.e("Exception: ",""+ ex.getMessage());
}
}
@Override
public void onBackPressed() {
super.onBackPressed();
clearPreferences();
finish();
Intent intent = new Intent(SummaryActivity.this, HomeActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
} }
} }

View File

@ -76,8 +76,8 @@ public class ItemStepsAdapter extends RecyclerView.Adapter<ItemStepsAdapter.Item
// Set data // Set data
holder.et_remarks.setText(currentItem.getRemarks()); holder.et_remarks.setText(currentItem.getRemarks());
holder.tvPercentage.setText(currentItem.getPercentage()); holder.tvPercentage.setText(currentItem.getPercentage());
//Log.e("Spinner-selection: ",""+currentItem.getSelectedOption());
holder.scoreTextview.setText(String.valueOf(currentItem.getSelectedOption())); holder.scoreTextview.setText(String.valueOf(dropdownOptions.get(currentItem.getSelectedOption())));
if (currentItem.getImageUri() != null) { if (currentItem.getImageUri() != null) {
@ -162,8 +162,8 @@ public class ItemStepsAdapter extends RecyclerView.Adapter<ItemStepsAdapter.Item
@Override @Override
public void onItemClick(AdapterView<?> parent, View view, int sub_position, long id) { public void onItemClick(AdapterView<?> parent, View view, int sub_position, long id) {
currentItem.setSelectedOption(sub_position + 1); currentItem.setSelectedOption(sub_position);
currentItem.setRating(sub_position + 1); currentItem.setRating(Integer.parseInt(parent.getItemAtPosition(sub_position).toString()));
selectedValue = Double.parseDouble(parent.getItemAtPosition(sub_position).toString()); selectedValue = Double.parseDouble(parent.getItemAtPosition(sub_position).toString());
percentage = (selectedValue / 5) * 100; percentage = (selectedValue / 5) * 100;

View File

@ -229,7 +229,7 @@ public class CheckingFragment extends Fragment implements EasyPermissions.Permis
if (!imageList.isEmpty()) { if (!imageList.isEmpty()) {
sharedViewModel.setCheckingImageList(imageList); sharedViewModel.setCheckingImageList(imageList);
}*/ }*/
((HomeActivity) getActivity()).navigateToFragment(new PackingFragment(), true); ((HomeActivity) requireActivity()).navigateToFragment(new PackingFragment(), true);
// } // }
} }
}); });

View File

@ -282,7 +282,7 @@ public class CuttingFragment extends Fragment implements EasyPermissions.Permiss
sharedViewModel.setCuttingImageList(imageList); sharedViewModel.setCuttingImageList(imageList);
}*/ }*/
((HomeActivity) getActivity()).navigateToFragment(new StitchingFragment(), true); ((HomeActivity) requireActivity()).navigateToFragment(new StitchingFragment(), true);
// } // }

View File

@ -243,7 +243,7 @@ public class PackingFragment extends Fragment implements EasyPermissions.Permiss
if (!imageList.isEmpty()) { if (!imageList.isEmpty()) {
sharedViewModel.setPackingImageList(imageList); sharedViewModel.setPackingImageList(imageList);
}*/ }*/
((HomeActivity) getActivity()).navigateToFragment(new SubStoreFragment(), true); ((HomeActivity) requireActivity()).navigateToFragment(new SubStoreFragment(), true);
// } // }
} }
}); });

View File

@ -243,7 +243,7 @@ public class StitchingFragment extends Fragment implements EasyPermissions.Permi
if (!imageList.isEmpty()) { if (!imageList.isEmpty()) {
sharedViewModel.setStitchingImageList(imageList); sharedViewModel.setStitchingImageList(imageList);
}*/ }*/
((HomeActivity) getActivity()).navigateToFragment(new CheckingFragment(), true); ((HomeActivity) requireActivity()).navigateToFragment(new CheckingFragment(), true);
// } // }
} }
}); });

View File

@ -1,6 +1,8 @@
package com.utopiaindustries.qualitycontrol.fragments; package com.utopiaindustries.qualitycontrol.fragments;
import android.Manifest; import android.Manifest;
import android.app.Activity;
import android.app.Application;
import android.content.ActivityNotFoundException; import android.content.ActivityNotFoundException;
import android.content.Context; import android.content.Context;
import android.content.Intent; 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.Helper;
import com.utopiaindustries.qualitycontrol.helper.Preference; import com.utopiaindustries.qualitycontrol.helper.Preference;
import com.utopiaindustries.qualitycontrol.utils.ImageSelectionListener; import com.utopiaindustries.qualitycontrol.utils.ImageSelectionListener;
import com.utopiaindustries.qualitycontrol.utils.MyApplication;
import com.utopiaindustries.qualitycontrol.utils.ProgressDialogFragment; import com.utopiaindustries.qualitycontrol.utils.ProgressDialogFragment;
import com.utopiaindustries.qualitycontrol.viewmodels.HomeViewModel; import com.utopiaindustries.qualitycontrol.viewmodels.HomeViewModel;
import com.utopiaindustries.qualitycontrol.viewmodels.ItemModel; import com.utopiaindustries.qualitycontrol.viewmodels.ItemModel;
@ -83,6 +86,7 @@ public class SubStoreFragment extends Fragment implements EasyPermissions.Permis
private int selectedPosition = -1; private int selectedPosition = -1;
HomeViewModel homeViewModel; HomeViewModel homeViewModel;
private int deletePosition = -1; private int deletePosition = -1;
Context mContext;
// Activity Result Launcher for Gallery // Activity Result Launcher for Gallery
private final ActivityResultLauncher<Intent> imagePickerLauncher = private final ActivityResultLauncher<Intent> 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 @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) { Bundle savedInstanceState) {
@ -273,35 +284,45 @@ public class SubStoreFragment extends Fragment implements EasyPermissions.Permis
homeViewModel.getUserLiveData().observe(getActivity(), qcResponse -> { homeViewModel.getUserLiveData().observe(getActivity(), qcResponse -> {
if (qcResponse != null) { 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()); try {
Preference.remove(Helper.project_file, Helper.locationSiteName, getActivity()); 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.locationSiteId, requireActivity());
Preference.remove(Helper.project_file, Helper.unitName, getActivity()); Preference.remove(Helper.project_file, Helper.locationSiteName, requireActivity());
Preference.remove(Helper.project_file, Helper.floorId, getActivity()); Preference.remove(Helper.project_file, Helper.unitId, requireActivity());
Preference.remove(Helper.project_file, Helper.floorName, getActivity()); Preference.remove(Helper.project_file, Helper.unitName, requireActivity());
Helper.RemoveArrayList(Helper.listCutting, getActivity()); Preference.remove(Helper.project_file, Helper.floorId, requireActivity());
Helper.RemoveArrayList(Helper.listStitching, getActivity()); Preference.remove(Helper.project_file, Helper.floorName, requireActivity());
Helper.RemoveArrayList(Helper.listChecking, getActivity());
Helper.RemoveArrayList(Helper.listPacking, getActivity());
Helper.RemoveArrayList(Helper.listSubStore, getActivity());
//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(); Context context = getActivity() != null ? getActivity() : MyApplication.getInstance().getApplicationContext();
Intent intent = new Intent(getActivity(), SummaryActivity.class);
Intent intent = new Intent(context, SummaryActivity.class);
intent.putExtra("Percentage", qcResponse.getOverAllPercentage()); intent.putExtra("Percentage", qcResponse.getOverAllPercentage());
intent.putExtra("Summary", qcResponse); 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() { public void showProgressDialog() {
ProgressDialogFragment progressDialog = new ProgressDialogFragment(); if (getActivity() != null && isAdded()) {
progressDialog.setCancelable(false); ProgressDialogFragment progressDialog = new ProgressDialogFragment();
progressDialog.show(requireActivity().getSupportFragmentManager(), "progressDialog"); progressDialog.setCancelable(false);
progressDialog.show(getActivity().getSupportFragmentManager(), "progressDialog");
}
else {
Log.e("Dialog-Activity",": null");
}
} }
public void dismissProgressDialog() { public void dismissProgressDialog() {
ProgressDialogFragment progressDialog = (ProgressDialogFragment) requireActivity().getSupportFragmentManager().findFragmentByTag("progressDialog"); if (getActivity() != null && isAdded()) {
if (progressDialog != null) { ProgressDialogFragment progressDialog = (ProgressDialogFragment) getActivity().getSupportFragmentManager().findFragmentByTag("progressDialog");
progressDialog.dismiss(); if (progressDialog != null) {
progressDialog.dismiss();
}
}
else {
Log.e("Dialog-Activity",": null");
} }
} }
public void showImageDialog() { public void showImageDialog() {
AlertDialog.Builder builder = new AlertDialog.Builder(requireContext()); 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); View dialogView = inflater.inflate(R.layout.dialog_select_image, null);
builder.setView(dialogView); builder.setView(dialogView);
@ -612,15 +644,15 @@ public class SubStoreFragment extends Fragment implements EasyPermissions.Permis
List<ItemModel> updatedItemList = itemModelList; // Or adapter.getItemList() List<ItemModel> updatedItemList = itemModelList; // Or adapter.getItemList()
/*for (ItemModel item : updatedItemList) { /*for (ItemModel item : updatedItemList) {
Log.e("AdapterData", "ProcessId: " + item.getProcessId() + Log.e("AdapterData", "ProcessId: " + item.getProcessId() +
", StepId: " + item.getStepId() + ", StepId: " + item.getStepId() +
", SpinnerSelection: " + item.getSelectedOption() + ", SpinnerSelection: " + item.getSelectedOption() +
", Rating: " + item.getRating() + ", Rating: " + item.getRating() +
", Percentage: " + item.getPercentage() + ", Percentage: " + item.getPercentage() +
", Remarks: " + item.getRemarks() + ", Remarks: " + item.getRemarks() +
", ImageList: " + item.getImageArrayList()); ", ImageList: " + item.getImageArrayList());
}*/ }*/
Helper.saveArrayList(itemModelList, Helper.listSubStore, getActivity()); Helper.saveArrayList(itemModelList, Helper.listSubStore, getActivity());
//viewModel.appendToQualityControlItemList(itemModelList); //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;
}
} }

View File

@ -102,15 +102,18 @@ public class Helper {
} }
static public void RemoveArrayList(String key, Context context) { static public void RemoveArrayList(String key, Context context) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); if (context != null) {
if (prefs.contains(key)) { // Check if the key exists SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
SharedPreferences.Editor editor = prefs.edit(); if (prefs.contains(key)) { // Check if the key exists
editor.remove(key); // Remove the key-value pair SharedPreferences.Editor editor = prefs.edit();
editor.apply(); // Apply changes editor.remove(key); // Remove the key-value pair
///Log.e("SharedPreferences", "Key '" + key + "' removed successfully."); editor.apply(); // Apply changes
} else { ///Log.e("SharedPreferences", "Key '" + key + "' removed successfully.");
//Log.e("SharedPreferences", "Key '" + key + "' does not exist."); } else {
Log.e("SharedPreferences", "Key '" + key + "' does not exist.");
}
} }
} }
//for department, site, unit, floor //for department, site, unit, floor

View File

@ -68,9 +68,12 @@ public class Preference {
public static void remove(String fileName, String key, Context context) { public static void remove(String fileName, String key, Context context) {
// perform validation etc.. // perform validation etc..
if (getPrefs(fileName,context).contains(key)) { if (context != null) {
getPrefs(fileName,context).edit().remove(key).apply(); if (getPrefs(fileName,context).contains(key)) {
getPrefs(fileName,context).edit().remove(key).apply();
}
} }
} }
public static void removeAll(String fileName, Context context) { public static void removeAll(String fileName, Context context) {
// perform validation etc.. // perform validation etc..

View File

@ -40,6 +40,10 @@ public class QualitySaveResponse implements Serializable {
@Expose @Expose
private String Sub_Store; private String Sub_Store;
@SerializedName("reportId")
@Expose
private String ReportId;
public String getOverAllPercentage() { public String getOverAllPercentage() {
return overAllPercentage; return overAllPercentage;
} }
@ -103,4 +107,12 @@ public class QualitySaveResponse implements Serializable {
public void setSub_Store(String sub_Store) { public void setSub_Store(String sub_Store) {
Sub_Store = sub_Store; Sub_Store = sub_Store;
} }
public String getReportId() {
return ReportId;
}
public void setReportId(String reportId) {
ReportId = reportId;
}
} }

View File

@ -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;
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 215 B

View File

@ -36,11 +36,11 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:padding="10dp" android:padding="10dp"
android:layout_marginStart="10dp" android:layout_marginStart="5dp"
app:layout_constraintBottom_toBottomOf="@+id/toolbar" app:layout_constraintBottom_toBottomOf="@+id/toolbar"
app:layout_constraintStart_toStartOf="@+id/toolbar" app:layout_constraintStart_toStartOf="@+id/toolbar"
app:layout_constraintTop_toTopOf="@+id/toolbar" app:layout_constraintTop_toTopOf="@+id/toolbar"
app:srcCompat="@drawable/arrow_back" /> app:srcCompat="@drawable/icon_home" />
<TextView <TextView
android:id="@+id/textView2" android:id="@+id/textView2"
@ -73,23 +73,23 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="15dp" android:layout_marginStart="15dp"
android:layout_marginTop="20dp" android:layout_marginTop="25dp"
android:text="Cutting %" android:text="Cutting %"
android:textSize="@dimen/_13sdp" android:textSize="@dimen/_13sdp"
android:textStyle="bold" android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/toolbar" /> app:layout_constraintTop_toBottomOf="@+id/txt_report_id" />
<TextView <TextView
android:id="@+id/txt_cutting_percentage" android:id="@+id/txt_cutting_percentage"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="20dp" android:layout_marginTop="25dp"
android:layout_marginEnd="15dp" android:layout_marginEnd="15dp"
android:text="TextView" android:text="TextView"
android:textSize="@dimen/_13sdp" android:textSize="@dimen/_13sdp"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/toolbar" /> app:layout_constraintTop_toBottomOf="@+id/txt_report_id" />
<TextView <TextView
android:id="@+id/textView5" android:id="@+id/textView5"
@ -195,5 +195,21 @@
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView12" /> app:layout_constraintTop_toBottomOf="@+id/textView12" />
<TextView
android:id="@+id/txt_report_id"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="15dp"
android:layout_marginTop="20dp"
android:layout_marginEnd="15dp"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:textStyle="bold"
android:textSize="@dimen/_15sdp"
android:text="TextView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/toolbar" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>