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" />
<application
android:name=".utils.MyApplication"
android:allowBackup="true"
android:allowClearUserData="true"
android:dataExtractionRules="@xml/data_extraction_rules"

View File

@ -14,11 +14,13 @@ import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
import com.utopiaindustries.qualitycontrol.R;
import com.utopiaindustries.qualitycontrol.helper.Helper;
import com.utopiaindustries.qualitycontrol.helper.Preference;
import com.utopiaindustries.qualitycontrol.models.QualitySaveResponse;
public class SummaryActivity extends AppCompatActivity {
TextView txtPercentage, txtCutting, txtStitching, txtChecking, txtPacking, txtSubStore;
TextView txtPercentage, txtCutting, txtStitching, txtChecking, txtPacking, txtSubStore, txtReportId;
String overallPercentage;
ImageView img_back;
QualitySaveResponse qualitySaveResponse;
@ -42,12 +44,18 @@ public class SummaryActivity extends AppCompatActivity {
txtChecking.setText(qualitySaveResponse.getChecking());
txtPacking.setText(qualitySaveResponse.getPacking());
txtSubStore.setText(qualitySaveResponse.getSub_Store());
txtReportId.setText(String.format("Report ID: %s", qualitySaveResponse.getReportId()));
img_back.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
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);
}
});
@ -72,5 +80,42 @@ public class SummaryActivity extends AppCompatActivity {
txtChecking = findViewById(R.id.txt_checking_percentage);
txtPacking = findViewById(R.id.txt_packing_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
holder.et_remarks.setText(currentItem.getRemarks());
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) {
@ -162,8 +162,8 @@ public class ItemStepsAdapter extends RecyclerView.Adapter<ItemStepsAdapter.Item
@Override
public void onItemClick(AdapterView<?> 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;

View File

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

View File

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

View File

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

View File

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

View File

@ -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<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
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,17 +574,28 @@ public class SubStoreFragment extends Fragment implements EasyPermissions.Permis
}
public void showProgressDialog() {
if (getActivity() != null && isAdded()) {
ProgressDialogFragment progressDialog = new ProgressDialogFragment();
progressDialog.setCancelable(false);
progressDialog.show(requireActivity().getSupportFragmentManager(), "progressDialog");
progressDialog.show(getActivity().getSupportFragmentManager(), "progressDialog");
}
else {
Log.e("Dialog-Activity",": null");
}
}
public void dismissProgressDialog() {
ProgressDialogFragment progressDialog = (ProgressDialogFragment) requireActivity().getSupportFragmentManager().findFragmentByTag("progressDialog");
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());
@ -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,6 +102,7 @@ public class Helper {
}
static public void RemoveArrayList(String key, Context context) {
if (context != null) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
if (prefs.contains(key)) { // Check if the key exists
SharedPreferences.Editor editor = prefs.edit();
@ -109,10 +110,12 @@ public class Helper {
editor.apply(); // Apply changes
///Log.e("SharedPreferences", "Key '" + key + "' removed successfully.");
} else {
//Log.e("SharedPreferences", "Key '" + key + "' does not exist.");
Log.e("SharedPreferences", "Key '" + key + "' does not exist.");
}
}
}
//for department, site, unit, floor
public static <T> void saveList(List<T> list, String key, Context context) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);

View File

@ -68,10 +68,13 @@ public class Preference {
public static void remove(String fileName, String key, Context context) {
// perform validation etc..
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..
getPrefs(fileName,context).edit().clear().apply();

View File

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

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_height="wrap_content"
android:padding="10dp"
android:layout_marginStart="10dp"
android:layout_marginStart="5dp"
app:layout_constraintBottom_toBottomOf="@+id/toolbar"
app:layout_constraintStart_toStartOf="@+id/toolbar"
app:layout_constraintTop_toTopOf="@+id/toolbar"
app:srcCompat="@drawable/arrow_back" />
app:srcCompat="@drawable/icon_home" />
<TextView
android:id="@+id/textView2"
@ -73,23 +73,23 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="15dp"
android:layout_marginTop="20dp"
android:layout_marginTop="25dp"
android:text="Cutting %"
android:textSize="@dimen/_13sdp"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/toolbar" />
app:layout_constraintTop_toBottomOf="@+id/txt_report_id" />
<TextView
android:id="@+id/txt_cutting_percentage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginTop="25dp"
android:layout_marginEnd="15dp"
android:text="TextView"
android:textSize="@dimen/_13sdp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/toolbar" />
app:layout_constraintTop_toBottomOf="@+id/txt_report_id" />
<TextView
android:id="@+id/textView5"
@ -195,5 +195,21 @@
app:layout_constraintStart_toStartOf="parent"
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>