Change draft functionality

Release new version 1.8
main
saad.siddiq 2025-06-19 15:25:24 +05:00
parent 08d62cbc01
commit b2cf9380a0
9 changed files with 148 additions and 25 deletions

View File

@ -10,8 +10,8 @@ android {
applicationId "com.utopiaindustries.qualitychecker" applicationId "com.utopiaindustries.qualitychecker"
minSdk 24 minSdk 24
targetSdk 34 targetSdk 34
versionCode 8 versionCode 9
versionName "1.7" versionName "1.8"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
} }

View File

@ -20,7 +20,7 @@ import retrofit2.converter.gson.GsonConverterFactory;
public class RetrofitClient { public class RetrofitClient {
private final static String BASE_URL = "https://portal.utopiaindustries.pk/uind/"; private final static String BASE_URL = "https://portal.utopiaindustries.pk/uind/";
//private final static String BASE_URL = "http://192.168.91.44:8081/uind/";//"http://192.168.91.44:8081/uind/";//"http://192.168.90.27:8080/uind/";//"http://192.168.91.16:8080/uind/"; //private final static String BASE_URL = "http://192.168.91.44:8081/uind/";
private static Retrofit retrofit; private static Retrofit retrofit;

View File

@ -6,6 +6,7 @@ import static com.utopiaindustries.qualitychecker.db.DatabaseHelper.DRAFT_REPORT
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.content.ContentValues; import android.content.ContentValues;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences;
import android.database.Cursor; import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteDatabase;
import android.util.Log; import android.util.Log;
@ -23,10 +24,12 @@ public class ReportRepository {
private final DatabaseHelper dbHelper; private final DatabaseHelper dbHelper;
private SQLiteDatabase database; private SQLiteDatabase database;
private final ExecutorService executorService; private final ExecutorService executorService;
private Context cxt;
public ReportRepository(Context context) { public ReportRepository(Context context) {
dbHelper = new DatabaseHelper(context); dbHelper = new DatabaseHelper(context);
executorService = Executors.newSingleThreadExecutor(); executorService = Executors.newSingleThreadExecutor();
cxt = context;
} }
private void openDatabase() { private void openDatabase() {
@ -116,20 +119,35 @@ public class ReportRepository {
} }
public void insertDraft(InspectionReportWrapper wrapper, String fnsku) { public void insertDraft(InspectionReportWrapper wrapper, String fnsku) {
System.out.println("Report-ID: "+ wrapper.getId()); //System.out.println("Report-ID: "+ wrapper.getId());
long[] recordId = new long[1];
executeSafely(() -> { executeSafely(() -> {
openDatabase(); openDatabase();
database.beginTransaction(); database.beginTransaction();
try { try {
ContentValues values = new ContentValues(); ContentValues values = new ContentValues();
if (wrapper.getId() != 0) { if (wrapper.getId() != 0) {
System.out.println("final-insertion: " + wrapper.getId()); //System.out.println("final-insertion: " + wrapper.getId());
values.put(DatabaseHelper.DRAFT_REPORT_COLUMN_ID, wrapper.getId()); values.put(DatabaseHelper.DRAFT_REPORT_COLUMN_ID, wrapper.getId());
//Log.e("RecordId-Existing: ",""+wrapper.getId());
recordId[0] = wrapper.getId();
} }
values.put(DatabaseHelper.DRAFT_REPORT_COLUMN_CONTENT, wrapper.getContent()); values.put(DatabaseHelper.DRAFT_REPORT_COLUMN_CONTENT, wrapper.getContent());
values.put(DatabaseHelper.DRAFT_REPORT_COLUMN_SYNCED, wrapper.isSynced()); values.put(DatabaseHelper.DRAFT_REPORT_COLUMN_SYNCED, wrapper.isSynced());
database.insertWithOnConflict(DRAFT_REPORT_TABLE_NAME, null, values, SQLiteDatabase.CONFLICT_REPLACE); //database.insertWithOnConflict(DRAFT_REPORT_TABLE_NAME, null, values, SQLiteDatabase.CONFLICT_REPLACE);
long rowId = database.insertWithOnConflict(DRAFT_REPORT_TABLE_NAME, null, values, SQLiteDatabase.CONFLICT_REPLACE);
database.setTransactionSuccessful(); database.setTransactionSuccessful();
if (wrapper.getId() == 0 && rowId != -1) {
//Log.e("RecordId-New: ", "" + rowId);
recordId[0] = rowId;
}
SharedPreferences sharedPreferences = cxt.getSharedPreferences("login_prefs", Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString("draftReportId", String.valueOf(recordId[0]));
editor.apply();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} finally { } finally {

View File

@ -536,6 +536,10 @@ public class FirstStepFragment extends Fragment implements View.OnClickListener
if (!s.toString().isEmpty() && s.toString() != null) { if (!s.toString().isEmpty() && s.toString() != null) {
trackSampleCode(Integer.parseInt(s.toString()), (int) Double.parseDouble(inspectionLevel), Double.parseDouble(qualityLevelMajor), Double.parseDouble(qualityLevelMinor)); trackSampleCode(Integer.parseInt(s.toString()), (int) Double.parseDouble(inspectionLevel), Double.parseDouble(qualityLevelMajor), Double.parseDouble(qualityLevelMinor));
} }
else {
aqlSampleSize.setText("");
}
} }
catch (Exception e) { catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
@ -734,6 +738,10 @@ public class FirstStepFragment extends Fragment implements View.OnClickListener
public void onTextChanged(CharSequence s, int start, int before, int count) { public void onTextChanged(CharSequence s, int start, int before, int count) {
try { try {
store.getReport().getItems().get(0).setSampleSize(Long.parseLong(s.toString())); store.getReport().getItems().get(0).setSampleSize(Long.parseLong(s.toString()));
/*if (!s.toString().isEmpty() && s.toString() != null) {
trackSampleCodeWithSampleSize((int) Double.parseDouble(inspectionLevel), Double.parseDouble(qualityLevelMajor), Double.parseDouble(qualityLevelMinor),Integer.parseInt(s.toString()));
}*/
} catch (Exception e) { } catch (Exception e) {
store.getReport().getItems().get(0).setSampleSize(0); store.getReport().getItems().get(0).setSampleSize(0);
} }
@ -805,7 +813,7 @@ public class FirstStepFragment extends Fragment implements View.OnClickListener
editor.putString("draftReportId", "0"); editor.putString("draftReportId", "0");
editor.apply(); editor.apply();
Objects.requireNonNull(getActivity()).finish(); //Objects.requireNonNull(getActivity()).finish();
NotificationHelper.showNotification(Objects.requireNonNull(getContext()), NotificationHelper.showNotification(Objects.requireNonNull(getContext()),
"Utopia QA App", "Utopia QA App",
"Report is successfully drafted"); "Report is successfully drafted");
@ -977,23 +985,36 @@ public class FirstStepFragment extends Fragment implements View.OnClickListener
//Log.e("Carton: ",""+String.valueOf(store.getReport().getItems().get(0).getCartonsSelected())); //Log.e("Carton: ",""+String.valueOf(store.getReport().getItems().get(0).getCartonsSelected()));
boxCartonSelected.setText(String.valueOf(store.getReport().getItems().get(0).getCartonsSelected())); boxCartonSelected.setText(store.getReport().getItems().get(0).getCartonsSelected() != 0
? String.valueOf(store.getReport().getItems().get(0).getCartonsSelected()) : "");
//itemPerBoxSelected.setText(String.valueOf(store.getReport().getItems().get(0).getPacksSelected())); //itemPerBoxSelected.setText(String.valueOf(store.getReport().getItems().get(0).getPacksSelected()));
//piecesSelected.setText(String.valueOf(store.getReport().getItems().get(0).getPiecesSelected())); //piecesSelected.setText(String.valueOf(store.getReport().getItems().get(0).getPiecesSelected()));
checkedBoxCartonSelected.setText(String.valueOf(store.getReport().getItems().get(0).getCheckedCartonsSelected())); checkedBoxCartonSelected.setText(store.getReport().getItems().get(0).getCheckedCartonsSelected() != 0
? String.valueOf(store.getReport().getItems().get(0).getCheckedCartonsSelected()) : "");
//checkedItemPerBoxSelected.setText(String.valueOf(store.getReport().getItems().get(0).getCheckedPacksSelected())); //checkedItemPerBoxSelected.setText(String.valueOf(store.getReport().getItems().get(0).getCheckedPacksSelected()));
//checkedPiecesSelected.setText(String.valueOf(store.getReport().getItems().get(0).getCheckedPiecesSelected())); //checkedPiecesSelected.setText(String.valueOf(store.getReport().getItems().get(0).getCheckedPiecesSelected()));
cartonWeight.setText(String.valueOf(store.getReport().getItems().get(0).getCartonWeight())); cartonWeight.setText(store.getReport().getItems().get(0).getCartonWeight() != 0.0f
cartonLength.setText(String.valueOf(store.getReport().getItems().get(0).getCartonLength())); ? String.valueOf(store.getReport().getItems().get(0).getCartonWeight()) : "");
cartonWidth.setText(String.valueOf(store.getReport().getItems().get(0).getCartonWidth())); cartonLength.setText(store.getReport().getItems().get(0).getCartonLength() != 0.0f
cartonHeight.setText(String.valueOf(store.getReport().getItems().get(0).getCartonHeight())); ? String.valueOf(store.getReport().getItems().get(0).getCartonLength()) : "");
cartonWidth.setText(store.getReport().getItems().get(0).getCartonWidth() != 0.0f
? String.valueOf(store.getReport().getItems().get(0).getCartonWidth()) : "");
cartonHeight.setText(store.getReport().getItems().get(0).getCartonHeight() != 0.0f
? String.valueOf(store.getReport().getItems().get(0).getCartonHeight()) : "");
packWeight.setText(store.getReport().getItems().get(0).getPackWeight() != 0.0f
? String.valueOf(store.getReport().getItems().get(0).getPackWeight()) : "");
packLength.setText(store.getReport().getItems().get(0).getPackLength() != 0.0f
? String.valueOf(store.getReport().getItems().get(0).getPackLength()) : "");
packWidth.setText(store.getReport().getItems().get(0).getPackWidth() != 0.0f
? String.valueOf(store.getReport().getItems().get(0).getPackWidth()) : "");
packHeight.setText(store.getReport().getItems().get(0).getPackHeight() != 0.0f
? String.valueOf(store.getReport().getItems().get(0).getPackHeight()) : "");
packWeight.setText(String.valueOf(store.getReport().getItems().get(0).getPackWeight()));
packLength.setText(String.valueOf(store.getReport().getItems().get(0).getPackLength()));
packWidth.setText(String.valueOf(store.getReport().getItems().get(0).getPackWidth()));
packHeight.setText(String.valueOf(store.getReport().getItems().get(0).getPackHeight()));
aqlSampleSize.setText(String.valueOf(store.getReport().getItems().get(0).getSampleSize())); aqlSampleSize.setText(String.valueOf(store.getReport().getItems().get(0).getSampleSize()));
@ -1320,6 +1341,56 @@ public class FirstStepFragment extends Fragment implements View.OnClickListener
} }
private void trackSampleCodeWithSampleSize(int inspectionLevel, double selectedLevelMajor, double selectedLevelMinor, int aqlSampleSizeValue) {
try {
String sampleCode = "";
double levelMajor = 0.0, levelMinor = 0.0;
int sampleSizeMajor = 0;
int sampleSizeMinor = 0;
List<InspectionLabel> inspectionGeneralLabels = new InspectionLabelRepository(getContext()).getInspectionLabels();
List<QualityLabel> inspectionAcceptableQualities = new InspectionLabelRepository(getContext()).getQualityLabels();
// Now determine the sample code based on aqlSampleSizeValue
outerLoop:
for (InspectionLabel label : inspectionGeneralLabels) {
if (label.getInspectionLevel() == inspectionLevel) {
// Look for the QualityLabel that matches the desired sample size and sample code
for (QualityLabel quality : inspectionAcceptableQualities) {
if (Objects.equals(quality.getSampleCode(), label.getSampleCode()) &&
quality.getSampleSize() == aqlSampleSizeValue) {
sampleCode = label.getSampleCode();
break outerLoop;
}
}
}
}
// For level major and minor
for (QualityLabel quality : inspectionAcceptableQualities) {
if (Objects.equals(quality.getSampleCode(), sampleCode)) {
if (quality.getQualityLevel() == selectedLevelMajor) {
levelMajor = quality.getNoOfAcceptedDefects();
sampleSizeMajor = quality.getSampleSize();
}
if (quality.getQualityLevel() == selectedLevelMinor) {
levelMinor = quality.getNoOfAcceptedDefects();
sampleSizeMinor = quality.getSampleSize();
}
}
}
//store.getReport().getItems().get(0).setSampleSize(sampleSizeMajor);
store.getReport().getItems().get(0).setLevelMajorDefects((int) levelMajor);
store.getReport().getItems().get(0).setLevelMinorDefects((int) levelMinor);
} catch (Exception e) {
e.printStackTrace();
}
}
/*@Override /*@Override
public void onResume() { public void onResume() {
super.onResume(); super.onResume();

View File

@ -61,7 +61,7 @@ public class SecondStepFragment extends Fragment
implements View.OnClickListener { implements View.OnClickListener {
private NavController navController; private NavController navController;
private Button leftFab, rightFab, draftFab, moveToBottom; private Button leftFab, rightFab, draftFab, moveToBottom, closeBtn;
private RecyclerView recyclerView; private RecyclerView recyclerView;
private CheckPointAdapter adapter; private CheckPointAdapter adapter;
private TextView profileName; private TextView profileName;
@ -84,6 +84,7 @@ public class SecondStepFragment extends Fragment
draftFab = view.findViewById(R.id.button_draft_second); draftFab = view.findViewById(R.id.button_draft_second);
leftFab = view.findViewById(R.id.button_left_frag_2); leftFab = view.findViewById(R.id.button_left_frag_2);
rightFab = view.findViewById(R.id.button_right_frag_2); rightFab = view.findViewById(R.id.button_right_frag_2);
closeBtn = view.findViewById(R.id.button_close);
moveToBottom = view.findViewById(R.id.button_move_to_bottom); moveToBottom = view.findViewById(R.id.button_move_to_bottom);
recyclerView = view.findViewById(R.id.check_point_recycler_view); recyclerView = view.findViewById(R.id.check_point_recycler_view);
profileName = view.findViewById(R.id.second_profile_name); profileName = view.findViewById(R.id.second_profile_name);
@ -130,6 +131,7 @@ public class SecondStepFragment extends Fragment
leftFab.setOnClickListener(this); leftFab.setOnClickListener(this);
rightFab.setOnClickListener(this); rightFab.setOnClickListener(this);
draftFab.setOnClickListener(this); draftFab.setOnClickListener(this);
closeBtn.setOnClickListener(this);
moveToBottom.setOnClickListener(this); moveToBottom.setOnClickListener(this);
updateProfileViews(); updateProfileViews();
return view; return view;
@ -156,7 +158,7 @@ public class SecondStepFragment extends Fragment
editor.putString("draftReportId", "0"); editor.putString("draftReportId", "0");
editor.apply(); editor.apply();
// progressBar.setVisibility(View.INVISIBLE); // progressBar.setVisibility(View.INVISIBLE);
Objects.requireNonNull(getActivity()).finish(); //Objects.requireNonNull(getActivity()).finish();
NotificationHelper.showNotification(Objects.requireNonNull(getContext()), NotificationHelper.showNotification(Objects.requireNonNull(getContext()),
"Utopia QA App", "Utopia QA App",
"Report is successfully drafted"); "Report is successfully drafted");
@ -194,6 +196,12 @@ public class SecondStepFragment extends Fragment
Log.e("Fab-Button","click"); Log.e("Fab-Button","click");
scrollToBottom(); scrollToBottom();
} }
if (v.getId() == R.id.button_close) {
if (getActivity() != null) {
getActivity().finish();
}
}
} }
public void onImagePickerResult(int requestCode, int resultCode, Intent data) { public void onImagePickerResult(int requestCode, int resultCode, Intent data) {

View File

@ -87,7 +87,7 @@ import retrofit2.Response;
public class ThirdStepFragment extends Fragment implements View.OnClickListener { public class ThirdStepFragment extends Fragment implements View.OnClickListener {
private NavController navController; private NavController navController;
private Button backBtn, nextBtn, openDimensionDialog, btnDraft; private Button backBtn, nextBtn, openDimensionDialog, btnDraft, closeBtn;
private ImageButton imagePicker, deleteImage; private ImageButton imagePicker, deleteImage;
private TextView profileName; private TextView profileName;
private ImageView profileImage; private ImageView profileImage;
@ -411,7 +411,7 @@ public class ThirdStepFragment extends Fragment implements View.OnClickListener
editor.putString("draftReportId", "0"); editor.putString("draftReportId", "0");
editor.apply(); editor.apply();
// progressBar.setVisibility(View.INVISIBLE); // progressBar.setVisibility(View.INVISIBLE);
Objects.requireNonNull(getActivity()).finish(); //Objects.requireNonNull(getActivity()).finish();
NotificationHelper.showNotification(Objects.requireNonNull(getContext()), NotificationHelper.showNotification(Objects.requireNonNull(getContext()),
"Utopia QA App", "Utopia QA App",
"Report is successfully drafted"); "Report is successfully drafted");
@ -442,6 +442,12 @@ public class ThirdStepFragment extends Fragment implements View.OnClickListener
if (v.getId() == R.id.button_open_dimension) { if (v.getId() == R.id.button_open_dimension) {
openDimensionDialog(); openDimensionDialog();
} }
if (v.getId() == R.id.button_close) {
if (getActivity() != null) {
getActivity().finish();
}
}
} }
/*private void saveReportDirectlyToServer(Store store) { /*private void saveReportDirectlyToServer(Store store) {
@ -784,6 +790,7 @@ public class ThirdStepFragment extends Fragment implements View.OnClickListener
backBtn = view.findViewById(R.id.button_left_frag_3); backBtn = view.findViewById(R.id.button_left_frag_3);
nextBtn = view.findViewById(R.id.button_right_frag_3); nextBtn = view.findViewById(R.id.button_right_frag_3);
btnDraft = view.findViewById(R.id.button_draft_third); btnDraft = view.findViewById(R.id.button_draft_third);
closeBtn = view.findViewById(R.id.button_close);
imagePicker = view.findViewById(R.id.image_picker); imagePicker = view.findViewById(R.id.image_picker);
deleteImage = view.findViewById(R.id.delete_image); deleteImage = view.findViewById(R.id.delete_image);
imageRecyclerView = view.findViewById(R.id.imageRecyclerView); imageRecyclerView = view.findViewById(R.id.imageRecyclerView);
@ -865,6 +872,7 @@ public class ThirdStepFragment extends Fragment implements View.OnClickListener
nextBtn.setOnClickListener(this); nextBtn.setOnClickListener(this);
backBtn.setOnClickListener(this); backBtn.setOnClickListener(this);
btnDraft.setOnClickListener(this); btnDraft.setOnClickListener(this);
closeBtn.setOnClickListener(this);
openDimensionDialog.setOnClickListener(this); openDimensionDialog.setOnClickListener(this);
} }

View File

@ -734,18 +734,18 @@
android:id="@+id/button_left_frag_1" android:id="@+id/button_left_frag_1"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_alignBaseline="@id/button_draft_first" android:layout_alignBaseline="@id/button_show_history"
android:layout_marginEnd="16dp" android:layout_marginEnd="16dp"
android:layout_toStartOf="@id/button_draft_first" android:layout_toStartOf="@id/button_show_history"
android:text="Close" /> android:text="Close" />
<Button <Button
android:id="@+id/button_show_history" android:id="@+id/button_show_history"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_alignBaseline="@id/button_left_frag_1" android:layout_alignBaseline="@id/button_draft_first"
android:layout_marginEnd="16dp" android:layout_marginEnd="16dp"
android:layout_toStartOf="@id/button_left_frag_1" android:layout_toStartOf="@id/button_draft_first"
android:text="History" /> android:text="History" />
</RelativeLayout> </RelativeLayout>

View File

@ -195,6 +195,15 @@
android:layout_marginEnd="16dp" android:layout_marginEnd="16dp"
android:layout_toStartOf="@id/button_left_frag_2" android:layout_toStartOf="@id/button_left_frag_2"
android:text="Move to Bottom" /> android:text="Move to Bottom" />
<Button
android:id="@+id/button_close"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@id/button_move_to_bottom"
android:layout_marginEnd="16dp"
android:layout_toStartOf="@id/button_move_to_bottom"
android:text="Close" />
</RelativeLayout> </RelativeLayout>

View File

@ -855,6 +855,15 @@
android:layout_toStartOf="@id/button_left_frag_3" android:layout_toStartOf="@id/button_left_frag_3"
android:text="Add Dimensions" /> android:text="Add Dimensions" />
<Button
android:id="@+id/button_close"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@id/button_open_dimension"
android:layout_marginEnd="16dp"
android:layout_toStartOf="@id/button_open_dimension"
android:text="Close" />
</RelativeLayout> </RelativeLayout>
<ProgressBar <ProgressBar