From 79d7f16c675741d0e7b4b5ba9392d21168007ca5 Mon Sep 17 00:00:00 2001 From: "saad.siddiq" Date: Mon, 10 Mar 2025 15:50:58 +0500 Subject: [PATCH] AQL chart implementation --- .idea/.name | 1 + .idea/deploymentTargetSelector.xml | 10 + .idea/vcs.xml | 6 + GitLOCStats.txt | Bin 0 -> 130 bytes app/src/main/AndroidManifest.xml | 2 +- .../qualitychecker/apiservice/ApiService.java | 4 + .../apiservice/RetrofitClient.java | 4 +- .../qualitychecker/db/DatabaseHelper.java | 35 + .../db/InspectionLabelRepository.java | 128 +++ .../models/InspectionLabel.java | 65 ++ .../models/InspectionLabelResponse.java | 33 + .../models/InspectionReportItem.java | 165 ++- .../qualitychecker/models/QualityLabel.java | 65 ++ .../callback/SaveInspectionLabelCallBack.java | 5 + .../service/InspectionReportService.java | 40 + .../ui/activities/HomeActivity.java | 33 + .../ui/adapter/ReportAdapter.java | 22 +- .../ui/fragments/FirstStepFragment.java | 899 +++++++++++----- .../ui/fragments/ThirdStepFragment.java | 30 +- .../main/res/layout/fragment_first_step.xml | 958 +++++++++++------- .../main/res/layout/fragment_third_step.xml | 12 +- .../main/res/xml/network_security_config.xml | 1 + 22 files changed, 1850 insertions(+), 668 deletions(-) create mode 100644 .idea/.name create mode 100644 .idea/deploymentTargetSelector.xml create mode 100644 .idea/vcs.xml create mode 100644 GitLOCStats.txt create mode 100644 app/src/main/java/com/utopiaindustries/qualitychecker/db/InspectionLabelRepository.java create mode 100644 app/src/main/java/com/utopiaindustries/qualitychecker/models/InspectionLabel.java create mode 100644 app/src/main/java/com/utopiaindustries/qualitychecker/models/InspectionLabelResponse.java create mode 100644 app/src/main/java/com/utopiaindustries/qualitychecker/models/QualityLabel.java create mode 100644 app/src/main/java/com/utopiaindustries/qualitychecker/models/callback/SaveInspectionLabelCallBack.java diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 0000000..97053dc --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +QualityChecker \ No newline at end of file diff --git a/.idea/deploymentTargetSelector.xml b/.idea/deploymentTargetSelector.xml new file mode 100644 index 0000000..b268ef3 --- /dev/null +++ b/.idea/deploymentTargetSelector.xml @@ -0,0 +1,10 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/GitLOCStats.txt b/GitLOCStats.txt new file mode 100644 index 0000000000000000000000000000000000000000..fece1aaaf6cc0a612e694ccdd624b37169c749f6 GIT binary patch literal 130 zcmezWFO;E}A(f$sA&()EAs5I}V5k9NUxs|3NC`s*l<&ik3FM~&)haMJGNb@uDiA}| cBFnh|#dCnT1c$sc(8NTbN$FsDUIs1(0Jgdp&j0`b literal 0 HcmV?d00001 diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 3c2a98c..4fd93b0 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -40,7 +40,7 @@ android:name=".ui.activities.MainActivity" android:exported="true" android:screenOrientation="portrait" - android:windowSoftInputMode="adjustResize"> + android:windowSoftInputMode="stateHidden|adjustPan"> > fetchSkuCheckpoints( ); + + @GET("rest/uic/inspection-report/get-inspection-label") + Call fetchAllInspectionLabels(); } diff --git a/app/src/main/java/com/utopiaindustries/qualitychecker/apiservice/RetrofitClient.java b/app/src/main/java/com/utopiaindustries/qualitychecker/apiservice/RetrofitClient.java index 2db4921..86c5693 100644 --- a/app/src/main/java/com/utopiaindustries/qualitychecker/apiservice/RetrofitClient.java +++ b/app/src/main/java/com/utopiaindustries/qualitychecker/apiservice/RetrofitClient.java @@ -19,8 +19,8 @@ import retrofit2.Retrofit; import retrofit2.converter.gson.GsonConverterFactory; public class RetrofitClient { - private final static String BASE_URL = "https://portal.utopiaindustries.pk/uind/"; - // private final static String BASE_URL = "http://192.168.90.27:8080/uind/";//"http://192.168.91.16:8080/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 static Retrofit retrofit; diff --git a/app/src/main/java/com/utopiaindustries/qualitychecker/db/DatabaseHelper.java b/app/src/main/java/com/utopiaindustries/qualitychecker/db/DatabaseHelper.java index 10db032..4c3f6ea 100644 --- a/app/src/main/java/com/utopiaindustries/qualitychecker/db/DatabaseHelper.java +++ b/app/src/main/java/com/utopiaindustries/qualitychecker/db/DatabaseHelper.java @@ -27,6 +27,21 @@ public class DatabaseHelper extends SQLiteOpenHelper { public static final String PRODUCT_COLUMN_CATEGORY = "category"; public static final String PRODUCT_COLUMN_FNSKU = "fnsku"; + //Table and Column for Inspection Label + public static final String INSPECTION_LABEL_TABLE_NAME = "inspection_label"; + public static final String INSPECTION_LABEL_COLUMN_ID = "id"; + public static final String INSPECTION_LABEL_COLUMN_MIN_LOT_SIZE = "minLotSize"; + public static final String INSPECTION_LABEL_COLUMN_MAX_LOT_SIZE = "maxLotSize"; + public static final String INSPECTION_LABEL_COLUMN_INSPECTION_LEVEL = "inspectionLevel"; + public static final String INSPECTION_LABEL_COLUMN_SAMPLE_CODE = "sampleCode"; + + //Table and Column for Quality Label + public static final String QUALITY_LABEL_TABLE_NAME = "quality_label"; + public static final String QUALITY_LABEL_COLUMN_ID = "id"; + public static final String QUALITY_LABEL_COLUMN_SAMPLE_CODE = "sampleCode"; + public static final String QUALITY_LABEL_COLUMN_SAMPLE_SIZE = "sampleSize"; + public static final String QUALITY_LABEL_COLUMN_QUALITY_LEVEL = "qualityLevel"; + public static final String QUALITY_LABEL_COLUMN_NO_ACCEPTED_DEFECTS = "noOfAcceptedDefects"; /* * dimension table @@ -153,6 +168,22 @@ public class DatabaseHelper extends SQLiteOpenHelper { CHECKPOINT_SKU_STANDARD + " TEXT," + "PRIMARY KEY (" + CHECKPOINT_SKU_SKU + ", " + CHECKPOINT_SKU_MARKETPLACE + ", " + CHECKPOINT_SKU_CHECKPOINT_ID + "))"; + String CREATE_INSPECTION_LABEL_TABLE = "CREATE TABLE " + INSPECTION_LABEL_TABLE_NAME + " (" + + INSPECTION_LABEL_COLUMN_ID + " INTEGER NOT NULL," + + INSPECTION_LABEL_COLUMN_MIN_LOT_SIZE + " INTEGER NOT NULL," + + INSPECTION_LABEL_COLUMN_MAX_LOT_SIZE + " INTEGER NOT NULL," + + INSPECTION_LABEL_COLUMN_INSPECTION_LEVEL + " INTEGER NOT NULL," + + INSPECTION_LABEL_COLUMN_SAMPLE_CODE + " TEXT NOT NULL )"; + + String CREATE_QUALITY_LABEL_TABLE = "CREATE TABLE " + QUALITY_LABEL_TABLE_NAME + " (" + + QUALITY_LABEL_COLUMN_ID + " INTEGER NOT NULL," + + QUALITY_LABEL_COLUMN_SAMPLE_CODE + " TEXT NOT NULL," + + QUALITY_LABEL_COLUMN_SAMPLE_SIZE + " INTEGER NOT NULL," + + QUALITY_LABEL_COLUMN_QUALITY_LEVEL + " REAL NOT NULL," + + QUALITY_LABEL_COLUMN_NO_ACCEPTED_DEFECTS + " INTEGER NOT NULL )"; + + + db.execSQL( CREATE_PRODUCT_TABLE ); db.execSQL( CREATE_INSPECTION_DIMENSION_TABLE ); db.execSQL( CREATE_CHECKPOINT_TABLE ); @@ -161,6 +192,8 @@ public class DatabaseHelper extends SQLiteOpenHelper { db.execSQL( CREATE_REPORT_TABLE ); db.execSQL( CREATE_DRAFT_REPORT_TABLE); db.execSQL( CREATE_SKU_CHECKPOINT_TABLE ); + db.execSQL( CREATE_INSPECTION_LABEL_TABLE ); + db.execSQL( CREATE_QUALITY_LABEL_TABLE ); } @Override @@ -173,6 +206,8 @@ public class DatabaseHelper extends SQLiteOpenHelper { db.execSQL( "DROP TABLE IF EXISTS " + REPORT_TABLE_NAME ); db.execSQL( "DROP TABLE IF EXISTS " + DRAFT_REPORT_TABLE_NAME ); db.execSQL( "DROP TABLE IF EXISTS " + CHECKPOINT_SKU_TABLE_NAME ); + db.execSQL( "DROP TABLE IF EXISTS " + INSPECTION_LABEL_TABLE_NAME ); + db.execSQL( "DROP TABLE IF EXISTS " + QUALITY_LABEL_TABLE_NAME ); onCreate(db); } } diff --git a/app/src/main/java/com/utopiaindustries/qualitychecker/db/InspectionLabelRepository.java b/app/src/main/java/com/utopiaindustries/qualitychecker/db/InspectionLabelRepository.java new file mode 100644 index 0000000..79d581b --- /dev/null +++ b/app/src/main/java/com/utopiaindustries/qualitychecker/db/InspectionLabelRepository.java @@ -0,0 +1,128 @@ +package com.utopiaindustries.qualitychecker.db; + +import static com.utopiaindustries.qualitychecker.db.DatabaseHelper.INSPECTION_LABEL_COLUMN_ID; +import static com.utopiaindustries.qualitychecker.db.DatabaseHelper.PRODUCT_COLUMN_ASIN; +import static com.utopiaindustries.qualitychecker.db.DatabaseHelper.QUALITY_LABEL_COLUMN_ID; + +import android.content.ContentValues; +import android.content.Context; +import android.database.Cursor; +import android.database.sqlite.SQLiteDatabase; + +import com.utopiaindustries.qualitychecker.models.InspectionLabel; +import com.utopiaindustries.qualitychecker.models.Product; +import com.utopiaindustries.qualitychecker.models.QualityLabel; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; + +public class InspectionLabelRepository { + private final DatabaseHelper dbHelper; + private final SQLiteDatabase database; + private final ExecutorService executorService; + + + public InspectionLabelRepository(Context context) { + dbHelper = new DatabaseHelper(context); + database = dbHelper.getWritableDatabase(); + executorService = Executors.newSingleThreadExecutor(); + } + + /* + * Insert list of inspection labels in batch + * */ + public void insertInspectionLabels( List inspectionLabels, List qualityLabels) { + executorService.execute(() -> { + database.beginTransaction(); + try { + //Inspection Label + for (InspectionLabel inspectionLabel : inspectionLabels) { + ContentValues ivalues = new ContentValues(); + ivalues.put(INSPECTION_LABEL_COLUMN_ID, inspectionLabel.getId()); + ivalues.put(DatabaseHelper.INSPECTION_LABEL_COLUMN_MIN_LOT_SIZE, inspectionLabel.getMinLotSize()); + ivalues.put(DatabaseHelper.INSPECTION_LABEL_COLUMN_MAX_LOT_SIZE, inspectionLabel.getMaxLotSize()); + ivalues.put(DatabaseHelper.INSPECTION_LABEL_COLUMN_INSPECTION_LEVEL, inspectionLabel.getInspectionLevel()); + ivalues.put(DatabaseHelper.INSPECTION_LABEL_COLUMN_SAMPLE_CODE, inspectionLabel.getSampleCode()); + + database.insertWithOnConflict(DatabaseHelper.INSPECTION_LABEL_TABLE_NAME, null, ivalues, SQLiteDatabase.CONFLICT_REPLACE); + } + + //Quality Label + for (QualityLabel qualityLabel : qualityLabels) { + ContentValues qvalues = new ContentValues(); + qvalues.put(QUALITY_LABEL_COLUMN_ID, qualityLabel.getId()); + qvalues.put(DatabaseHelper.QUALITY_LABEL_COLUMN_SAMPLE_CODE, qualityLabel.getSampleCode()); + qvalues.put(DatabaseHelper.QUALITY_LABEL_COLUMN_SAMPLE_SIZE, qualityLabel.getSampleSize()); + qvalues.put(DatabaseHelper.QUALITY_LABEL_COLUMN_QUALITY_LEVEL, qualityLabel.getQualityLevel()); + qvalues.put(DatabaseHelper.QUALITY_LABEL_COLUMN_NO_ACCEPTED_DEFECTS, qualityLabel.getNoOfAcceptedDefects()); + + database.insertWithOnConflict(DatabaseHelper.QUALITY_LABEL_TABLE_NAME, null, qvalues, SQLiteDatabase.CONFLICT_REPLACE); + } + + database.setTransactionSuccessful(); + } finally { + database.endTransaction(); + close(); + } + }); + } + + + /* + * Get list of inspection labels from database + * */ + public List getInspectionLabels() { + List inspectionLabels = new ArrayList<>(); + Cursor cursor = database.query(DatabaseHelper.INSPECTION_LABEL_TABLE_NAME, new String[]{INSPECTION_LABEL_COLUMN_ID, + DatabaseHelper.INSPECTION_LABEL_COLUMN_MIN_LOT_SIZE, DatabaseHelper.INSPECTION_LABEL_COLUMN_MAX_LOT_SIZE, + DatabaseHelper.INSPECTION_LABEL_COLUMN_INSPECTION_LEVEL, DatabaseHelper.INSPECTION_LABEL_COLUMN_SAMPLE_CODE}, + null, null, null, null, null); + if (cursor != null && cursor.moveToFirst()) { + do { + InspectionLabel inspectionLabel = new InspectionLabel(); + inspectionLabel.setId(cursor.getInt(0)); + inspectionLabel.setMinLotSize(cursor.getInt(1)); + inspectionLabel.setMaxLotSize(cursor.getInt(2)); + inspectionLabel.setInspectionLevel(cursor.getInt(3)); + inspectionLabel.setSampleCode(cursor.getString(4)); + inspectionLabels.add(inspectionLabel); + } while (cursor.moveToNext()); + cursor.close(); + } + return inspectionLabels; + } + + /* + * Get list of quality labels from database + * */ + public List getQualityLabels() { + List qualityLabels = new ArrayList<>(); + Cursor cursor = database.query(DatabaseHelper.QUALITY_LABEL_TABLE_NAME, new String[]{QUALITY_LABEL_COLUMN_ID, + DatabaseHelper.QUALITY_LABEL_COLUMN_SAMPLE_CODE, DatabaseHelper.QUALITY_LABEL_COLUMN_SAMPLE_SIZE, + DatabaseHelper.QUALITY_LABEL_COLUMN_QUALITY_LEVEL, DatabaseHelper.QUALITY_LABEL_COLUMN_NO_ACCEPTED_DEFECTS}, + null, null, null, null, null); + if (cursor != null && cursor.moveToFirst()) { + do { + QualityLabel qualityLabel = new QualityLabel(); + qualityLabel.setId(cursor.getInt(0)); + qualityLabel.setSampleCode(cursor.getString(1)); + qualityLabel.setSampleSize(cursor.getInt(2)); + qualityLabel.setQualityLevel(cursor.getDouble(3)); + qualityLabel.setNoOfAcceptedDefects(cursor.getInt(4)); + qualityLabels.add(qualityLabel); + } while (cursor.moveToNext()); + cursor.close(); + } + return qualityLabels; + } + + /* + * Close the database + */ + public void close() { + dbHelper.close(); + executorService.shutdown(); + } +} diff --git a/app/src/main/java/com/utopiaindustries/qualitychecker/models/InspectionLabel.java b/app/src/main/java/com/utopiaindustries/qualitychecker/models/InspectionLabel.java new file mode 100644 index 0000000..c8bc215 --- /dev/null +++ b/app/src/main/java/com/utopiaindustries/qualitychecker/models/InspectionLabel.java @@ -0,0 +1,65 @@ + +package com.utopiaindustries.qualitychecker.models; + +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + +public class InspectionLabel { + + @SerializedName("id") + @Expose + private Integer id; + @SerializedName("minLotSize") + @Expose + private Integer minLotSize; + @SerializedName("maxLotSize") + @Expose + private Integer maxLotSize; + @SerializedName("inspectionLevel") + @Expose + private Integer inspectionLevel; + @SerializedName("sampleCode") + @Expose + private String sampleCode; + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public Integer getMinLotSize() { + return minLotSize; + } + + public void setMinLotSize(Integer minLotSize) { + this.minLotSize = minLotSize; + } + + public Integer getMaxLotSize() { + return maxLotSize; + } + + public void setMaxLotSize(Integer maxLotSize) { + this.maxLotSize = maxLotSize; + } + + public Integer getInspectionLevel() { + return inspectionLevel; + } + + public void setInspectionLevel(Integer inspectionLevel) { + this.inspectionLevel = inspectionLevel; + } + + public String getSampleCode() { + return sampleCode; + } + + public void setSampleCode(String sampleCode) { + this.sampleCode = sampleCode; + } + +} diff --git a/app/src/main/java/com/utopiaindustries/qualitychecker/models/InspectionLabelResponse.java b/app/src/main/java/com/utopiaindustries/qualitychecker/models/InspectionLabelResponse.java new file mode 100644 index 0000000..8ca8d66 --- /dev/null +++ b/app/src/main/java/com/utopiaindustries/qualitychecker/models/InspectionLabelResponse.java @@ -0,0 +1,33 @@ + +package com.utopiaindustries.qualitychecker.models; + +import java.util.List; +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + +public class InspectionLabelResponse { + + @SerializedName("qualityLabel") + @Expose + private List qualityLabel; + @SerializedName("inspectionLabel") + @Expose + private List inspectionLabel; + + public List getQualityLabel() { + return qualityLabel; + } + + public void setQualityLabel(List qualityLabel) { + this.qualityLabel = qualityLabel; + } + + public List getInspectionLabel() { + return inspectionLabel; + } + + public void setInspectionLabel(List inspectionLabel) { + this.inspectionLabel = inspectionLabel; + } + +} diff --git a/app/src/main/java/com/utopiaindustries/qualitychecker/models/InspectionReportItem.java b/app/src/main/java/com/utopiaindustries/qualitychecker/models/InspectionReportItem.java index 214d074..3cb79e3 100644 --- a/app/src/main/java/com/utopiaindustries/qualitychecker/models/InspectionReportItem.java +++ b/app/src/main/java/com/utopiaindustries/qualitychecker/models/InspectionReportItem.java @@ -31,12 +31,27 @@ public class InspectionReportItem implements Serializable { private float packsSelected; private float piecesSelected; - private float checkedCartonsSelected; - private float checkedPacksSelected; - private float checkedPiecesSelected; + private float cartonWeight; + private float cartonLength; + private float cartonHeight; + private float cartonWidth; + private float packWeight; + private float packWidth; + private float packLength; + private float packHeight; + private long sampleSize; + private long inspectionLevel; + private long minorQualityLevel; + private long majorQualityLevel; + + private int aqlSampleSize; + + private int checkedCartonsSelected; + private int checkedPacksSelected; + private int checkedPiecesSelected; private String packingDetails; - private String sampleSize; + //private String sampleSize; private String dateAdded; // wrapper private List checkPoints; @@ -236,11 +251,11 @@ public class InspectionReportItem implements Serializable { this.piecesSelected = piecesSelected; } - public String getSampleSize() { + public long getSampleSize() { return sampleSize; } - public void setSampleSize(String sampleSize) { + public void setSampleSize(long sampleSize) { this.sampleSize = sampleSize; } @@ -260,34 +275,129 @@ public class InspectionReportItem implements Serializable { this.fnsku = fnsku; } - public float getCheckedCartonsSelected() { + public int getCheckedCartonsSelected() { return checkedCartonsSelected; } - public void setCheckedCartonsSelected(float checkedCartonsSelected) { + public void setCheckedCartonsSelected(int checkedCartonsSelected) { this.checkedCartonsSelected = checkedCartonsSelected; } - public float getCheckedPacksSelected() { + public int getCheckedPacksSelected() { return checkedPacksSelected; } - public void setCheckedPacksSelected(float checkedPacksSelected) { + public void setCheckedPacksSelected(int checkedPacksSelected) { this.checkedPacksSelected = checkedPacksSelected; } - public float getCheckedPiecesSelected() { + public int getCheckedPiecesSelected() { return checkedPiecesSelected; } - public void setCheckedPiecesSelected(float checkedPiecesSelected) { + public void setCheckedPiecesSelected(int checkedPiecesSelected) { this.checkedPiecesSelected = checkedPiecesSelected; } - @NonNull + public long getMajorQualityLevel() { + return majorQualityLevel; + } + + public void setMajorQualityLevel(long majorQualityLevel) { + this.majorQualityLevel = majorQualityLevel; + } + + public long getMinorQualityLevel() { + return minorQualityLevel; + } + + public void setMinorQualityLevel(long minorQualityLevel) { + this.minorQualityLevel = minorQualityLevel; + } + + public long getInspectionLevel() { + return inspectionLevel; + } + + public void setInspectionLevel(long inspectionLevel) { + this.inspectionLevel = inspectionLevel; + } + + public float getPackHeight() { + return packHeight; + } + + public void setPackHeight(float packHeight) { + this.packHeight = packHeight; + } + + public float getPackLength() { + return packLength; + } + + public void setPackLength(float packLength) { + this.packLength = packLength; + } + + public float getPackWidth() { + return packWidth; + } + + public void setPackWidth(float packWidth) { + this.packWidth = packWidth; + } + + public float getPackWeight() { + return packWeight; + } + + public void setPackWeight(float packWeight) { + this.packWeight = packWeight; + } + + public float getCartonWidth() { + return cartonWidth; + } + + public void setCartonWidth(float cartonWidth) { + this.cartonWidth = cartonWidth; + } + + public float getCartonHeight() { + return cartonHeight; + } + + public void setCartonHeight(float cartonHeight) { + this.cartonHeight = cartonHeight; + } + + public float getCartonLength() { + return cartonLength; + } + + public void setCartonLength(float cartonLength) { + this.cartonLength = cartonLength; + } + + public float getCartonWeight() { + return cartonWeight; + } + + public void setCartonWeight(float cartonWeight) { + this.cartonWeight = cartonWeight; + } + + public int getAqlSampleSize() { + return aqlSampleSize; + } + + public void setAqlSampleSize(int aqlSampleSize) { + this.aqlSampleSize = aqlSampleSize; + } + @Override public String toString() { - return "InspectionAuditReportItem{" + + return "InspectionReportItem{" + "id=" + id + ", reportId=" + reportId + ", asin='" + asin + '\'' + @@ -301,8 +411,35 @@ public class InspectionReportItem implements Serializable { ", smColor='" + smColor + '\'' + ", smSize='" + smSize + '\'' + ", smItemName='" + smItemName + '\'' + + ", orderNumber='" + orderNumber + '\'' + + ", article='" + article + '\'' + + ", totalPresentPieces=" + totalPresentPieces + + ", totalPresentPacks=" + totalPresentPacks + + ", totalPresentCartons=" + totalPresentCartons + + ", cartonsSelected=" + cartonsSelected + + ", packsSelected=" + packsSelected + + ", piecesSelected=" + piecesSelected + + ", cartonWeight=" + cartonWeight + + ", cartonLength=" + cartonLength + + ", cartonHeight=" + cartonHeight + + ", cartonWidth=" + cartonWidth + + ", packWeight=" + packWeight + + ", packWidth=" + packWidth + + ", packLength=" + packLength + + ", packHeight=" + packHeight + + ", sampleSize=" + sampleSize + + ", inspectionLevel=" + inspectionLevel + + ", minorQualityLevel=" + minorQualityLevel + + ", majorQualityLevel=" + majorQualityLevel + + ", aqlSampleSize=" + aqlSampleSize + + ", checkedCartonsSelected=" + checkedCartonsSelected + + ", checkedPacksSelected=" + checkedPacksSelected + + ", checkedPiecesSelected=" + checkedPiecesSelected + + ", packingDetails='" + packingDetails + '\'' + + ", dateAdded='" + dateAdded + '\'' + ", checkPoints=" + checkPoints + ", dimensions=" + dimensions + + ", fnsku='" + fnsku + '\'' + '}'; } } diff --git a/app/src/main/java/com/utopiaindustries/qualitychecker/models/QualityLabel.java b/app/src/main/java/com/utopiaindustries/qualitychecker/models/QualityLabel.java new file mode 100644 index 0000000..134bfb6 --- /dev/null +++ b/app/src/main/java/com/utopiaindustries/qualitychecker/models/QualityLabel.java @@ -0,0 +1,65 @@ + +package com.utopiaindustries.qualitychecker.models; + +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + +public class QualityLabel { + + @SerializedName("id") + @Expose + private Integer id; + @SerializedName("sampleCode") + @Expose + private String sampleCode; + @SerializedName("sampleSize") + @Expose + private Integer sampleSize; + @SerializedName("qualityLevel") + @Expose + private Double qualityLevel; + @SerializedName("noOfAcceptedDefects") + @Expose + private Integer noOfAcceptedDefects; + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getSampleCode() { + return sampleCode; + } + + public void setSampleCode(String sampleCode) { + this.sampleCode = sampleCode; + } + + public Integer getSampleSize() { + return sampleSize; + } + + public void setSampleSize(Integer sampleSize) { + this.sampleSize = sampleSize; + } + + public Double getQualityLevel() { + return qualityLevel; + } + + public void setQualityLevel(Double qualityLevel) { + this.qualityLevel = qualityLevel; + } + + public Integer getNoOfAcceptedDefects() { + return noOfAcceptedDefects; + } + + public void setNoOfAcceptedDefects(Integer noOfAcceptedDefects) { + this.noOfAcceptedDefects = noOfAcceptedDefects; + } + +} diff --git a/app/src/main/java/com/utopiaindustries/qualitychecker/models/callback/SaveInspectionLabelCallBack.java b/app/src/main/java/com/utopiaindustries/qualitychecker/models/callback/SaveInspectionLabelCallBack.java new file mode 100644 index 0000000..8d63784 --- /dev/null +++ b/app/src/main/java/com/utopiaindustries/qualitychecker/models/callback/SaveInspectionLabelCallBack.java @@ -0,0 +1,5 @@ +package com.utopiaindustries.qualitychecker.models.callback; + +public interface SaveInspectionLabelCallBack extends SaveCallback { + +} diff --git a/app/src/main/java/com/utopiaindustries/qualitychecker/service/InspectionReportService.java b/app/src/main/java/com/utopiaindustries/qualitychecker/service/InspectionReportService.java index 8fad9cd..1b08824 100644 --- a/app/src/main/java/com/utopiaindustries/qualitychecker/service/InspectionReportService.java +++ b/app/src/main/java/com/utopiaindustries/qualitychecker/service/InspectionReportService.java @@ -12,6 +12,7 @@ import com.utopiaindustries.qualitychecker.db.CheckpointRepository; import com.utopiaindustries.qualitychecker.db.DefectRepository; import com.utopiaindustries.qualitychecker.db.DimensionRepository; import com.utopiaindustries.qualitychecker.db.InspectionCheckpointSkuRepository; +import com.utopiaindustries.qualitychecker.db.InspectionLabelRepository; import com.utopiaindustries.qualitychecker.db.ItemRepository; import com.utopiaindustries.qualitychecker.db.ProductRepository; import com.utopiaindustries.qualitychecker.db.ReportRepository; @@ -21,6 +22,7 @@ import com.utopiaindustries.qualitychecker.models.InspectionDefect; import com.utopiaindustries.qualitychecker.models.InspectionDimension; import com.utopiaindustries.qualitychecker.models.InspectionItemCheckPoint; import com.utopiaindustries.qualitychecker.models.InspectionItemDefect; +import com.utopiaindustries.qualitychecker.models.InspectionLabelResponse; import com.utopiaindustries.qualitychecker.models.InspectionReport; import com.utopiaindustries.qualitychecker.models.InspectionReportWrapper; import com.utopiaindustries.qualitychecker.models.ItemUnit; @@ -29,6 +31,7 @@ import com.utopiaindustries.qualitychecker.models.callback.SaveCheckpointCallbac import com.utopiaindustries.qualitychecker.models.callback.SaveDefectCallback; import com.utopiaindustries.qualitychecker.models.callback.SaveDimensionCallback; import com.utopiaindustries.qualitychecker.models.callback.SaveDraftReportCallback; +import com.utopiaindustries.qualitychecker.models.callback.SaveInspectionLabelCallBack; import com.utopiaindustries.qualitychecker.models.callback.SaveItemCallback; import com.utopiaindustries.qualitychecker.models.callback.SaveProductCallBack; import com.utopiaindustries.qualitychecker.models.callback.SaveReportCallback; @@ -275,6 +278,13 @@ public class InspectionReportService { }).start(); } + public void fetchAndPopulateInspectionLabel( SaveInspectionLabelCallBack callback, + InspectionLabelRepository repository){ + new Thread(() -> { + populateInspectionLabels( callback, repository ); + }).start(); + } + public void fetchAndPopulateDimensions( SaveDimensionCallback callback, DimensionRepository repository ){ new Thread(() -> { @@ -338,6 +348,36 @@ public class InspectionReportService { } ); } + + private void populateInspectionLabels( SaveInspectionLabelCallBack callback, + InspectionLabelRepository repository ){ + apiService.fetchAllInspectionLabels().enqueue( + new Callback() { + @Override + public void onResponse(Call call, + Response response) { + if (response.isSuccessful()) { + try { + System.out.println( response.body() ); + callback.onSuccess(); + assert response.body() != null; + repository.insertInspectionLabels( response.body().getInspectionLabel(), response.body().getQualityLabel() ); + } catch ( Exception ex ){ + callback.onFailure(new Exception( ex.getMessage() ) ); + } + } else { + callback.onFailure(new Exception("API call failed with status code: " + response.code())); + } + } + @Override + public void onFailure(Call call, Throwable t) { + System.out.println(t); + callback.onFailure(t); + } + } + ); + } + private void populateDimensions( SaveDimensionCallback callback, DimensionRepository repository ){ diff --git a/app/src/main/java/com/utopiaindustries/qualitychecker/ui/activities/HomeActivity.java b/app/src/main/java/com/utopiaindustries/qualitychecker/ui/activities/HomeActivity.java index 5385dac..3ba59ef 100644 --- a/app/src/main/java/com/utopiaindustries/qualitychecker/ui/activities/HomeActivity.java +++ b/app/src/main/java/com/utopiaindustries/qualitychecker/ui/activities/HomeActivity.java @@ -34,6 +34,7 @@ import com.utopiaindustries.qualitychecker.db.CheckpointRepository; import com.utopiaindustries.qualitychecker.db.DefectRepository; import com.utopiaindustries.qualitychecker.db.DimensionRepository; import com.utopiaindustries.qualitychecker.db.InspectionCheckpointSkuRepository; +import com.utopiaindustries.qualitychecker.db.InspectionLabelRepository; import com.utopiaindustries.qualitychecker.db.ItemRepository; import com.utopiaindustries.qualitychecker.db.ProductRepository; import com.utopiaindustries.qualitychecker.models.EmployeePhoto; @@ -41,6 +42,7 @@ import com.utopiaindustries.qualitychecker.models.InspectionReport; import com.utopiaindustries.qualitychecker.models.callback.SaveCheckpointCallback; import com.utopiaindustries.qualitychecker.models.callback.SaveDefectCallback; import com.utopiaindustries.qualitychecker.models.callback.SaveDimensionCallback; +import com.utopiaindustries.qualitychecker.models.callback.SaveInspectionLabelCallBack; import com.utopiaindustries.qualitychecker.models.callback.SaveItemCallback; import com.utopiaindustries.qualitychecker.models.callback.SaveProductCallBack; import com.utopiaindustries.qualitychecker.notification.NotificationHelper; @@ -195,6 +197,7 @@ public class HomeActivity extends AppCompatActivity implements View.OnClickListe fetchAndPopulateDefectsData(); fetchAndPopulateUnitsData(); fetchAndPopulateSkuCheckpointsData(); + fetchAndPopulateInspectionLevelData(); } else { Toast.makeText( this, "network not available", Toast.LENGTH_LONG ).show(); } @@ -267,6 +270,36 @@ public class HomeActivity extends AppCompatActivity implements View.OnClickListe }, new ProductRepository( this ) ); } + /* + * fetch and update inspection label + * */ + private void fetchAndPopulateInspectionLevelData() { + + NotificationHelper.showProductNotification( + this, + "Utopia QA App", + "Fetching Inspection Label."); + inspectionReportService.fetchAndPopulateInspectionLabel( new SaveInspectionLabelCallBack() { + @Override + public void onSuccess() { + Toast.makeText( HomeActivity.this, "Inspection Labels successfully synced", Toast.LENGTH_LONG ).show(); + NotificationHelper.showProductNotification( + HomeActivity.this, + "Utopia QA App", + "Inspection Labels successfully synced"); + } + + @Override + public void onFailure(Throwable throwable) { + Toast.makeText( HomeActivity.this, "Error in Inspection Labels syncing " + throwable.getMessage(), Toast.LENGTH_LONG ).show(); + NotificationHelper.showProductNotification( + HomeActivity.this, + "Utopia QA App", + "Error in Inspection Labels syncing" ); + } + }, new InspectionLabelRepository( this ) ); + } + private void fetchAndPopulateDimensionsData(){ NotificationHelper.showProductNotification( this, diff --git a/app/src/main/java/com/utopiaindustries/qualitychecker/ui/adapter/ReportAdapter.java b/app/src/main/java/com/utopiaindustries/qualitychecker/ui/adapter/ReportAdapter.java index c8fa762..9f1cd20 100644 --- a/app/src/main/java/com/utopiaindustries/qualitychecker/ui/adapter/ReportAdapter.java +++ b/app/src/main/java/com/utopiaindustries/qualitychecker/ui/adapter/ReportAdapter.java @@ -69,16 +69,20 @@ public class ReportAdapter extends // Format the date in 12-hour format String formattedDateTime = displayDateFormat.format( date ); dateTv.setText( formattedDateTime ); - if( report.getReportResult().equalsIgnoreCase("FAILED") ){ - status.setBackgroundResource( R.drawable.failed_bg ); + + if (report.getReportResult() != null && !report.getReportResult().isEmpty()) { + if( report.getReportResult().equalsIgnoreCase("FAILED") ){ + status.setBackgroundResource( R.drawable.failed_bg ); + } + if( report.getReportResult().equalsIgnoreCase("PASSED") ){ + status.setBackgroundResource( R.drawable.passed_bg ); + } + if( report.getReportResult().equalsIgnoreCase("ON_HOLD") ){ + status.setBackgroundResource( R.drawable.hold_bg ); + } + status.setText( report.getReportResult() ); } - if( report.getReportResult().equalsIgnoreCase("PASSED") ){ - status.setBackgroundResource( R.drawable.passed_bg ); - } - if( report.getReportResult().equalsIgnoreCase("ON_HOLD") ){ - status.setBackgroundResource( R.drawable.hold_bg ); - } - status.setText( report.getReportResult() ); + } } } diff --git a/app/src/main/java/com/utopiaindustries/qualitychecker/ui/fragments/FirstStepFragment.java b/app/src/main/java/com/utopiaindustries/qualitychecker/ui/fragments/FirstStepFragment.java index 7ddb6df..906ad31 100644 --- a/app/src/main/java/com/utopiaindustries/qualitychecker/ui/fragments/FirstStepFragment.java +++ b/app/src/main/java/com/utopiaindustries/qualitychecker/ui/fragments/FirstStepFragment.java @@ -8,6 +8,7 @@ import android.os.Handler; import android.os.Looper; import android.text.Editable; import android.text.TextWatcher; +import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -37,14 +38,17 @@ import com.utopiaindustries.qualitychecker.apiservice.ApiService; import com.utopiaindustries.qualitychecker.apiservice.ApiServiceFactory; import com.utopiaindustries.qualitychecker.db.DimensionRepository; import com.utopiaindustries.qualitychecker.db.InspectionCheckpointSkuRepository; +import com.utopiaindustries.qualitychecker.db.InspectionLabelRepository; import com.utopiaindustries.qualitychecker.db.ProductRepository; import com.utopiaindustries.qualitychecker.db.ReportRepository; import com.utopiaindustries.qualitychecker.models.InspectionCheckpointSku; import com.utopiaindustries.qualitychecker.models.InspectionDimension; +import com.utopiaindustries.qualitychecker.models.InspectionLabel; import com.utopiaindustries.qualitychecker.models.InspectionReport; import com.utopiaindustries.qualitychecker.models.InspectionReportItem; import com.utopiaindustries.qualitychecker.models.InspectionReportWrapper; import com.utopiaindustries.qualitychecker.models.Product; +import com.utopiaindustries.qualitychecker.models.QualityLabel; import com.utopiaindustries.qualitychecker.models.callback.SaveDraftReportCallback; import com.utopiaindustries.qualitychecker.notification.NotificationHelper; import com.utopiaindustries.qualitychecker.service.InspectionReportService; @@ -68,28 +72,35 @@ import retrofit2.Response; public class FirstStepFragment extends Fragment implements View.OnClickListener { - private NavController navController; - private Button leftFab,rightFab,showHistoryBtn, btnDraft; - private EditText sku,boxCarton,itemPerBox,pieces,packagingDetails,boxCartonSelected,itemPerBoxSelected,piecesSelected, checkedBoxCartonSelected, checkedItemPerBoxSelected, checkedPiecesSelected; - private Spinner markerplace,modelNumber,title,color,size; - private CheckBox fri,refri; - private ImageButton searchSku,scanBtn; + private NavController navController; + private Button leftFab, rightFab, showHistoryBtn, btnDraft; + private EditText sku, boxCarton, itemPerBox, pieces, packagingDetails, boxCartonSelected, itemPerBoxSelected, piecesSelected, checkedBoxCartonSelected, checkedItemPerBoxSelected, checkedPiecesSelected; + private Spinner markerplace, modelNumber, title, color, size, sp_inspectionLevel, sp_qLevelMajor, sp_qLevelMinor; + private CheckBox fri, refri; + private ImageButton searchSku, scanBtn; private TextView profileName; private ImageView profileImage; private ApiService apiService; private Store store; private InspectionReportService inspectionReportService; + private EditText aqlSampleSize, cartonWeight, cartonLength, cartonWidth, cartonHeight; + private EditText packWeight, packLength, packWidth, packHeight; + TextView txtTesting; - List sizes = Collections.singletonList("[Size]"); - List colors = Collections.singletonList("[Color]"); - List titles = Collections.singletonList("[Title]"); + List sizes = Collections.singletonList("[Size]"); + List colors = Collections.singletonList("[Color]"); + List titles = Collections.singletonList("[Title]"); List modelNumbers = Collections.singletonList("[Model Number]"); List marketplaces = Collections.singletonList("[ Marketplace ]"); + String inspectionLevel, qualityLevelMajor, qualityLevelMinor; + List inspectionLabelList = new ArrayList<>(); + List qualityLabelList = new ArrayList<>(); + @Nullable @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { - View view = inflater.inflate(R.layout.fragment_first_step , container, false ); + View view = inflater.inflate(R.layout.fragment_first_step, container, false); //System.out.println("onCreateView---------->"); SharedPreferences sharedPreferences = getContext().getSharedPreferences("login_prefs", Context.MODE_PRIVATE); long draftReportId = Long.parseLong(sharedPreferences.getString("draftReportId", null)); @@ -97,7 +108,7 @@ public class FirstStepFragment extends Fragment implements View.OnClickListener store = Store.getInstance(); if (draftReportId > 0) { - ReportRepository repository = new ReportRepository( getContext() ); + ReportRepository repository = new ReportRepository(getContext()); InspectionReportWrapper report = repository.findDraftReportById(Long.parseLong(String.valueOf(draftReportId))); InspectionReport inspectionReport = getSingleReport(report); @@ -106,52 +117,52 @@ public class FirstStepFragment extends Fragment implements View.OnClickListener //System.out.println("Report-SKU: " + store.getReport().getItems().get(0).getFnsku()); } - initializeViews( view ); + initializeViews(view); apiService = ApiServiceFactory.getApiService(); inspectionReportService = InspectionReportService.getInstance(); // set on click listener - leftFab.setOnClickListener( this ); - rightFab.setOnClickListener( this ); - searchSku.setOnClickListener( this ); - btnDraft.setOnClickListener( this); - scanBtn.setOnClickListener( this ); - showHistoryBtn.setOnClickListener( this ); - populateItem( store.getProducts(), true ); - prePopulateData( store.getProducts() ); + leftFab.setOnClickListener(this); + rightFab.setOnClickListener(this); + searchSku.setOnClickListener(this); + btnDraft.setOnClickListener(this); + scanBtn.setOnClickListener(this); + showHistoryBtn.setOnClickListener(this); + populateItem(store.getProducts(), true); + prePopulateData(store.getProducts()); updateProfileViews(); - // sku.setText(store.getReport().getItems().get(0).getFnsku()); + // sku.setText(store.getReport().getItems().get(0).getFnsku()); if (draftReportId > 0) { String selectedString = store.getReport().getItems().get(0).getMarketplace(); int index = marketplaces.indexOf(selectedString); markerplace.setSelection(index); - if( sku.getText() != null ){ - populateProductDataOnSelection( sku.getText().toString(), "", true ); - store.setCheckpointSkus( new ArrayList<>() ); - populateSkuCheckpointsParams( store.getReport().getItems().get(0).getSku(), + if (sku.getText() != null) { + populateProductDataOnSelection(sku.getText().toString(), "", true); + store.setCheckpointSkus(new ArrayList<>()); + populateSkuCheckpointsParams(store.getReport().getItems().get(0).getSku(), store.getReport().getItems().get(0).getMarketplace()); } } fri.setOnCheckedChangeListener((buttonView, isChecked) -> { - if( isChecked ){ - store.getReport().setFri( true ); - refri.setChecked( false ); + if (isChecked) { + store.getReport().setFri(true); + refri.setChecked(false); } else { - store.getReport().setFri( false ); - refri.setChecked( true ); + store.getReport().setFri(false); + refri.setChecked(true); } }); refri.setOnCheckedChangeListener((buttonView, isChecked) -> { - if( isChecked ){ - store.getReport().setFri( false ); - fri.setChecked( false ); + if (isChecked) { + store.getReport().setFri(false); + fri.setChecked(false); } else { - store.getReport().setFri( true ); - fri.setChecked( true ); + store.getReport().setFri(true); + fri.setChecked(true); } }); @@ -160,10 +171,10 @@ public class FirstStepFragment extends Fragment implements View.OnClickListener @Override public void onItemSelected(AdapterView parent, View view, int position, long id) { - if( parent.getItemAtPosition( position ) != null ){ - String marketplaceOption = parent.getItemAtPosition( position ).toString(); - store.getReport().getItems().get(0).setMarketplace( marketplaceOption ); - System.out.println( marketplaceOption ); + if (parent.getItemAtPosition(position) != null) { + String marketplaceOption = parent.getItemAtPosition(position).toString(); + store.getReport().getItems().get(0).setMarketplace(marketplaceOption); + System.out.println(marketplaceOption); populateProductDataOnSelection( store.getReport().getItems().get(0).getFnsku(), marketplaceOption, @@ -182,13 +193,80 @@ public class FirstStepFragment extends Fragment implements View.OnClickListener } }); + //Inspection Level + sp_inspectionLevel.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { + @Override + public void onItemSelected(AdapterView parent, View view, int position, long id) { + if (parent.getItemAtPosition(position) != null) { + inspectionLevel = parent.getItemAtPosition(position).toString(); + + store.getReport().getItems().get(0).setInspectionLevel((long) Double.parseDouble(inspectionLevel)); + + checkedBoxCartonSelected.setText(""); + checkedItemPerBoxSelected.setText(""); + checkedPiecesSelected.setText(""); + aqlSampleSize.setText(""); + } + } + + @Override + public void onNothingSelected(AdapterView parent) { + store.getReport().getItems().get(0).setInspectionLevel(0); + } + }); + + //Quality Level Major + sp_qLevelMajor.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { + @Override + public void onItemSelected(AdapterView parent, View view, int position, long id) { + if (parent.getItemAtPosition(position) != null) { + qualityLevelMajor = parent.getItemAtPosition(position).toString(); + + store.getReport().getItems().get(0).setMajorQualityLevel((long) Double.parseDouble(qualityLevelMajor)); + + checkedBoxCartonSelected.setText(""); + checkedItemPerBoxSelected.setText(""); + checkedPiecesSelected.setText(""); + aqlSampleSize.setText(""); + + } + } + + @Override + public void onNothingSelected(AdapterView parent) { + store.getReport().getItems().get(0).setMajorQualityLevel(0); + } + }); + + //Quality Level Minor + sp_qLevelMinor.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { + @Override + public void onItemSelected(AdapterView parent, View view, int position, long id) { + if (parent.getItemAtPosition(position) != null) { + qualityLevelMinor = parent.getItemAtPosition(position).toString(); + + store.getReport().getItems().get(0).setMinorQualityLevel((long) Double.parseDouble(qualityLevelMinor)); + + checkedBoxCartonSelected.setText(""); + checkedItemPerBoxSelected.setText(""); + checkedPiecesSelected.setText(""); + aqlSampleSize.setText(""); + } + } + + @Override + public void onNothingSelected(AdapterView parent) { + store.getReport().getItems().get(0).setMinorQualityLevel(0); + } + }); + // title title.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView parent, View view, int position, long id) { - if( parent.getItemAtPosition( position ) != null ){ - String titleOption = parent.getItemAtPosition( position ).toString(); - store.getReport().getItems().get(0).setTitle( titleOption ); + if (parent.getItemAtPosition(position) != null) { + String titleOption = parent.getItemAtPosition(position).toString(); + store.getReport().getItems().get(0).setTitle(titleOption); } } @@ -202,9 +280,9 @@ public class FirstStepFragment extends Fragment implements View.OnClickListener modelNumber.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView parent, View view, int position, long id) { - if( parent.getItemAtPosition( position ) != null ){ - String modelOption = parent.getItemAtPosition( position ).toString(); - store.getReport().getItems().get(0).setModelNumber( modelOption ); + if (parent.getItemAtPosition(position) != null) { + String modelOption = parent.getItemAtPosition(position).toString(); + store.getReport().getItems().get(0).setModelNumber(modelOption); } } @@ -218,9 +296,9 @@ public class FirstStepFragment extends Fragment implements View.OnClickListener color.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView parent, View view, int position, long id) { - if( parent.getItemAtPosition( position ) != null ){ - String colorOption = parent.getItemAtPosition( position ).toString(); - store.getReport().getItems().get(0).setSmColor( colorOption ); + if (parent.getItemAtPosition(position) != null) { + String colorOption = parent.getItemAtPosition(position).toString(); + store.getReport().getItems().get(0).setSmColor(colorOption); } } @@ -234,9 +312,9 @@ public class FirstStepFragment extends Fragment implements View.OnClickListener size.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView parent, View view, int position, long id) { - if( parent.getItemAtPosition( position ) != null ){ - String sizeOption = parent.getItemAtPosition( position ).toString(); - store.getReport().getItems().get(0).setSmSize( sizeOption ); + if (parent.getItemAtPosition(position) != null) { + String sizeOption = parent.getItemAtPosition(position).toString(); + store.getReport().getItems().get(0).setSmSize(sizeOption); } } @@ -261,8 +339,7 @@ public class FirstStepFragment extends Fragment implements View.OnClickListener int boxCount = Integer.parseInt(s.toString()); if (itemPerBox.getText().toString().isEmpty() || pieces.getText().toString().isEmpty()) { Toast.makeText(getContext(), "Enter Item/Pieces Per box", Toast.LENGTH_SHORT).show(); - } - else { + } else { packsCount = (int) store.getProducts().get(0).getItemPerPack(); piecesCount = (int) store.getProducts().get(0).getItemPerBox(); @@ -273,9 +350,9 @@ public class FirstStepFragment extends Fragment implements View.OnClickListener piecesSelected.setText(String.valueOf(totalPieces)); } - store.getReport().getItems().get(0).setCartonsSelected( Long.parseLong( s.toString() ) ); - } catch ( Exception e ){ - store.getReport().getItems().get(0).setCartonsSelected( 0 ); + store.getReport().getItems().get(0).setCartonsSelected(Long.parseLong(s.toString())); + } catch (Exception e) { + store.getReport().getItems().get(0).setCartonsSelected(0); } } @@ -299,8 +376,7 @@ public class FirstStepFragment extends Fragment implements View.OnClickListener int boxCount = Integer.parseInt(s.toString()); if (itemPerBox.getText().toString().isEmpty() || pieces.getText().toString().isEmpty()) { Toast.makeText(getContext(), "Enter Item/Pieces Per box", Toast.LENGTH_SHORT).show(); - } - else { + } else { packsCount = (int) store.getProducts().get(0).getItemPerPack(); piecesCount = (int) store.getProducts().get(0).getItemPerBox(); @@ -311,9 +387,9 @@ public class FirstStepFragment extends Fragment implements View.OnClickListener checkedPiecesSelected.setText(String.valueOf(totalPieces)); } - store.getReport().getItems().get(0).setCheckedCartonsSelected( Long.parseLong( s.toString() ) ); - } catch ( Exception e ){ - store.getReport().getItems().get(0).setCheckedCartonsSelected( 0 ); + store.getReport().getItems().get(0).setCheckedCartonsSelected(Integer.parseInt(s.toString())); + } catch (Exception e) { + store.getReport().getItems().get(0).setCheckedCartonsSelected(0); } } @@ -332,9 +408,9 @@ public class FirstStepFragment extends Fragment implements View.OnClickListener @Override public void onTextChanged(CharSequence s, int start, int before, int count) { try { - store.getReport().getItems().get(0).setPacksSelected( Long.parseLong( s.toString() ) ); - } catch ( Exception e ){ - store.getReport().getItems().get(0).setPacksSelected( 0 ); + store.getReport().getItems().get(0).setPacksSelected(Long.parseLong(s.toString())); + } catch (Exception e) { + store.getReport().getItems().get(0).setPacksSelected(0); } } @@ -354,9 +430,9 @@ public class FirstStepFragment extends Fragment implements View.OnClickListener @Override public void onTextChanged(CharSequence s, int start, int before, int count) { try { - store.getReport().getItems().get(0).setCheckedPacksSelected( Long.parseLong( s.toString() ) ); - } catch ( Exception e ){ - store.getReport().getItems().get(0).setCheckedPacksSelected( 0 ); + store.getReport().getItems().get(0).setCheckedPacksSelected(Integer.parseInt(s.toString())); + } catch (Exception e) { + store.getReport().getItems().get(0).setCheckedPacksSelected(0); } } @@ -375,9 +451,9 @@ public class FirstStepFragment extends Fragment implements View.OnClickListener @Override public void onTextChanged(CharSequence s, int start, int before, int count) { try { - store.getReport().getItems().get(0).setPiecesSelected( Long.parseLong( s.toString() ) ); - } catch ( Exception e ){ - store.getReport().getItems().get(0).setPiecesSelected( 0 ); + store.getReport().getItems().get(0).setPiecesSelected(Long.parseLong(s.toString())); + } catch (Exception e) { + store.getReport().getItems().get(0).setPiecesSelected(0); } } @@ -397,9 +473,44 @@ public class FirstStepFragment extends Fragment implements View.OnClickListener @Override public void onTextChanged(CharSequence s, int start, int before, int count) { try { - store.getReport().getItems().get(0).setCheckedPiecesSelected( Long.parseLong( s.toString() ) ); - } catch ( Exception e ){ - store.getReport().getItems().get(0).setCheckedPiecesSelected( 0 ); + store.getReport().getItems().get(0).setCheckedPiecesSelected(Integer.parseInt(s.toString())); + } catch (Exception e) { + store.getReport().getItems().get(0).setCheckedPiecesSelected(0); + } + + try { + //calculate aql sample size + //Log.e("ItemPresentedDetails-pieces: ", "" + s.toString()); + //Log.e("ItemPresentedDetails-inspectionLevel: ", "" + inspectionLevel); + if (!s.toString().isEmpty()) { + trackSampleCode(Integer.parseInt(s.toString()), (int) Double.parseDouble(inspectionLevel), Double.parseDouble(qualityLevelMajor), Double.parseDouble(qualityLevelMinor)); + } + } + catch (Exception e) { + e.printStackTrace(); + } + + } + + @Override + public void afterTextChanged(Editable s) { + + } + }); + + //Carton Weight + cartonWeight.addTextChangedListener(new TextWatcher() { + @Override + public void beforeTextChanged(CharSequence s, int start, int count, int after) { + + } + + @Override + public void onTextChanged(CharSequence s, int start, int before, int count) { + try { + store.getReport().getItems().get(0).setCartonWeight(Float.parseFloat(s.toString())); + } catch (Exception e) { + store.getReport().getItems().get(0).setCartonWeight(0); } } @@ -409,6 +520,181 @@ public class FirstStepFragment extends Fragment implements View.OnClickListener } }); + //Carton Length + cartonLength.addTextChangedListener(new TextWatcher() { + @Override + public void beforeTextChanged(CharSequence s, int start, int count, int after) { + + } + + @Override + public void onTextChanged(CharSequence s, int start, int before, int count) { + try { + store.getReport().getItems().get(0).setCartonLength(Float.parseFloat(s.toString())); + } catch (Exception e) { + store.getReport().getItems().get(0).setCartonLength(0); + } + } + + @Override + public void afterTextChanged(Editable s) { + + } + }); + + //Carton Width + cartonWidth.addTextChangedListener(new TextWatcher() { + @Override + public void beforeTextChanged(CharSequence s, int start, int count, int after) { + + } + + @Override + public void onTextChanged(CharSequence s, int start, int before, int count) { + try { + store.getReport().getItems().get(0).setCartonWidth(Float.parseFloat(s.toString())); + } catch (Exception e) { + store.getReport().getItems().get(0).setCartonWidth(0); + } + } + + @Override + public void afterTextChanged(Editable s) { + + } + }); + + //Carton Height + cartonHeight.addTextChangedListener(new TextWatcher() { + @Override + public void beforeTextChanged(CharSequence s, int start, int count, int after) { + + } + + @Override + public void onTextChanged(CharSequence s, int start, int before, int count) { + try { + store.getReport().getItems().get(0).setCartonHeight(Float.parseFloat(s.toString())); + } catch (Exception e) { + store.getReport().getItems().get(0).setCartonHeight(0); + } + } + + @Override + public void afterTextChanged(Editable s) { + + } + }); + + //Pack Weight + packWeight.addTextChangedListener(new TextWatcher() { + @Override + public void beforeTextChanged(CharSequence s, int start, int count, int after) { + + } + + @Override + public void onTextChanged(CharSequence s, int start, int before, int count) { + try { + store.getReport().getItems().get(0).setPackWeight(Float.parseFloat(s.toString())); + } catch (Exception e) { + store.getReport().getItems().get(0).setPackWeight(0); + }} + + @Override + public void afterTextChanged(Editable s) { + + } + }); + + //Pack Length + packLength.addTextChangedListener(new TextWatcher() { + @Override + public void beforeTextChanged(CharSequence s, int start, int count, int after) { + + } + + @Override + public void onTextChanged(CharSequence s, int start, int before, int count) { + try { + store.getReport().getItems().get(0).setPackLength(Float.parseFloat(s.toString())); + } catch (Exception e) { + store.getReport().getItems().get(0).setPackLength(0); + } + } + + @Override + public void afterTextChanged(Editable s) { + + } + }); + + //Pack Width + packWidth.addTextChangedListener(new TextWatcher() { + @Override + public void beforeTextChanged(CharSequence s, int start, int count, int after) { + + } + + @Override + public void onTextChanged(CharSequence s, int start, int before, int count) { + try { + store.getReport().getItems().get(0).setPackWidth(Float.parseFloat(s.toString())); + } catch (Exception e) { + store.getReport().getItems().get(0).setPackWidth(0); + } + } + + @Override + public void afterTextChanged(Editable s) { + + } + }); + + //Pack Height + packHeight.addTextChangedListener(new TextWatcher() { + @Override + public void beforeTextChanged(CharSequence s, int start, int count, int after) { + + } + + @Override + public void onTextChanged(CharSequence s, int start, int before, int count) { + try { + store.getReport().getItems().get(0).setPackHeight(Float.parseFloat(s.toString())); + } catch (Exception e) { + store.getReport().getItems().get(0).setPackHeight(0); + } + } + + @Override + public void afterTextChanged(Editable s) { + + } + }); + + aqlSampleSize.addTextChangedListener(new TextWatcher() { + @Override + public void beforeTextChanged(CharSequence s, int start, int count, int after) { + + } + + @Override + public void onTextChanged(CharSequence s, int start, int before, int count) { + try { + store.getReport().getItems().get(0).setSampleSize(Long.parseLong(s.toString())); + } catch (Exception e) { + store.getReport().getItems().get(0).setSampleSize(0); + } + } + + @Override + public void afterTextChanged(Editable s) { + + } + }); + + // generalRemarks.addTextChangedListener(new TextWatcher() { // @Override // public void beforeTextChanged(CharSequence s, int start, int count, int after) { @@ -446,13 +732,13 @@ public class FirstStepFragment extends Fragment implements View.OnClickListener @Override public void onClick(View v) { - navController = Navigation.findNavController( requireView() ); + navController = Navigation.findNavController(requireView()); if (v.getId() == R.id.button_draft_first) { //--Draft Incomplete Report //Log.e("sku: ",""+sku.getText().toString()); //Log.e("Market-place: ",""+store.getReport().getItems().get(0).getMarketplace()); - if(!sku.getText().toString().isEmpty() && !store.getReport().getItems().get(0).getMarketplace().equalsIgnoreCase("[ Marketplace ]")) { + if (!sku.getText().toString().isEmpty() && !store.getReport().getItems().get(0).getMarketplace().equalsIgnoreCase("[ Marketplace ]")) { if (store.getReport() != null) { inspectionReportService.saveDraftInLocalDb(getContext(), store.getReport(), new SaveDraftReportCallback() { @Override @@ -489,309 +775,347 @@ public class FirstStepFragment extends Fragment implements View.OnClickListener } }); } - } - else { - Toast.makeText(getContext(),"Please enter or scan sku details", Toast.LENGTH_SHORT).show(); + } else { + Toast.makeText(getContext(), "Please enter or scan sku details", Toast.LENGTH_SHORT).show(); } //--- } - if( v.getId() == R.id.button_left_frag_1 ){ - if( getActivity() != null ){ + if (v.getId() == R.id.button_left_frag_1) { + if (getActivity() != null) { getActivity().finish(); } } - if( v.getId() == R.id.button_right_frag_1 ){ + if (v.getId() == R.id.button_right_frag_1) { if (!sku.getText().toString().isEmpty() && !store.getReport().getItems().get(0).getMarketplace().equalsIgnoreCase("[ Marketplace ]")) { - navController.navigate( R.id.action_firstStepFragment_to_secondStepFragment ); - } - else { - Toast.makeText(getContext(),"Please enter or scan sku details", Toast.LENGTH_SHORT).show(); + navController.navigate(R.id.action_firstStepFragment_to_secondStepFragment); + } else { + Toast.makeText(getContext(), "Please enter or scan sku details", Toast.LENGTH_SHORT).show(); } } - if( v.getId() == R.id.search_sku_btn ){ - if( sku.getText() != null && !sku.getText().toString().isEmpty() ){ - populateProductDataOnSelection( sku.getText().toString(), "", true ); - store.setCheckpointSkus( new ArrayList<>() ); - populateSkuCheckpointsParams( store.getReport().getItems().get(0).getSku(), + if (v.getId() == R.id.search_sku_btn) { + if (sku.getText() != null && !sku.getText().toString().isEmpty()) { + populateProductDataOnSelection(sku.getText().toString(), "", true); + store.setCheckpointSkus(new ArrayList<>()); + populateSkuCheckpointsParams(store.getReport().getItems().get(0).getSku(), store.getReport().getItems().get(0).getMarketplace()); } } - if( v.getId() == R.id.scan_sku_btn ){ - IntentIntegrator integrator = new IntentIntegrator( getActivity() ); + if (v.getId() == R.id.scan_sku_btn) { + IntentIntegrator integrator = new IntentIntegrator(getActivity()); integrator.setCaptureActivity(CaptureActivity.class); - integrator.setOrientationLocked( true ); - integrator.setBarcodeImageEnabled( true ); + integrator.setOrientationLocked(true); + integrator.setBarcodeImageEnabled(true); integrator.initiateScan(); } - if( v.getId() == R.id.button_show_history ){ - openItemHistoryDialog(); + if (v.getId() == R.id.button_show_history) { + openItemHistoryDialog(); } } - private void populateSkuCheckpointsParams( String sku, String marketplace ){ - if( sku != null && ! sku.isEmpty() && marketplace != null && ! marketplace.isEmpty() ){ - List checkpointSkus = new InspectionCheckpointSkuRepository( getContext() ) - .findBySkuAndMarketplace( sku, marketplace ); - System.out.println( checkpointSkus ); - store.setCheckpointSkus( checkpointSkus ); + private void populateSkuCheckpointsParams(String sku, String marketplace) { + if (sku != null && !sku.isEmpty() && marketplace != null && !marketplace.isEmpty()) { + List checkpointSkus = new InspectionCheckpointSkuRepository(getContext()) + .findBySkuAndMarketplace(sku, marketplace); + System.out.println(checkpointSkus); + store.setCheckpointSkus(checkpointSkus); } } - private void populateProductDataOnSelection( String fnsku, String marketplace , boolean populateMarketplace){ + private void populateProductDataOnSelection(String fnsku, String marketplace, boolean populateMarketplace) { // setting the product details - if( fnsku != null ){ + if (fnsku != null) { String fnskuStr = fnsku.trim(); - List products = new ProductRepository( getContext() ).getProductBySkuOrAsin( fnskuStr, marketplace ); - System.out.println( products ); - Product product = products.stream().findFirst().orElse( new Product() ); - store.getReport().getItems().get(0).setSku( product.getSku() ); - store.getReport().getItems().get(0).setAsin( product.getAsin() ); - store.getReport().getItems().get(0).setFnsku( fnskuStr ); - populateItem( products, populateMarketplace ); - store.setProducts( products ); - if( product.getCategory() != null ){ - List dimensions = new DimensionRepository( getContext() ).findByCategory( + List products = new ProductRepository(getContext()).getProductBySkuOrAsin(fnskuStr, marketplace); + System.out.println(products); + Product product = products.stream().findFirst().orElse(new Product()); + store.getReport().getItems().get(0).setSku(product.getSku()); + store.getReport().getItems().get(0).setAsin(product.getAsin()); + store.getReport().getItems().get(0).setFnsku(fnskuStr); + populateItem(products, populateMarketplace); + store.setProducts(products); + if (product.getCategory() != null) { + List dimensions = new DimensionRepository(getContext()).findByCategory( product.getCategory() ); - store.setDimensionList( dimensions ); + store.setDimensionList(dimensions); } } } - private void prePopulateData( List products ){ - System.out.println("prePopulateData: " + store.getReport().getItems().get(0).getFnsku()); - fri.setChecked( store.getReport().getFri() ); - refri.setChecked( ! store.getReport().getFri() ); - // sku - sku.setText( store.getReport().getItems().get(0).getFnsku() ); - System.out.println( products ); - System.out.println( store.getReport().getItems().get(0) ); - if( ! products.isEmpty() ){ - List modelNumbers = products.stream().map( Product::getModelNumber ).distinct().collect(Collectors.toList()) ; + private void prePopulateData(List products) { + System.out.println("prePopulateData: " + store.getReport().getItems().get(0).getFnsku()); + fri.setChecked(store.getReport().getFri()); + refri.setChecked(!store.getReport().getFri()); + // sku + sku.setText(store.getReport().getItems().get(0).getFnsku()); + System.out.println(products); + System.out.println(store.getReport().getItems().get(0)); + + if (!products.isEmpty()) { + List modelNumbers = products.stream().map(Product::getModelNumber).distinct().collect(Collectors.toList()); String defaultModelSelection = store.getReport().getItems().get(0).getModelNumber(); - int defaultModelSelectionIndex = modelNumbers.indexOf( defaultModelSelection ); - modelNumber.setSelection( defaultModelSelectionIndex ); + int defaultModelSelectionIndex = modelNumbers.indexOf(defaultModelSelection); + modelNumber.setSelection(defaultModelSelectionIndex); } - if( ! products.isEmpty() ){ - List titles = products.stream().map( Product::getTitle ).distinct().collect(Collectors.toList()) ; + if (!products.isEmpty()) { + List titles = products.stream().map(Product::getTitle).distinct().collect(Collectors.toList()); String defaultTitleSelection = store.getReport().getItems().get(0).getTitle(); - int defaultTitleSelectionIndex = titles.indexOf( defaultTitleSelection ); - title.setSelection( defaultTitleSelectionIndex ); + int defaultTitleSelectionIndex = titles.indexOf(defaultTitleSelection); + title.setSelection(defaultTitleSelectionIndex); } } - private void populateItem( List products , boolean populateMarketplace){ - if( populateMarketplace ){ - populateMarketplaces( products ); + private void populateItem(List products, boolean populateMarketplace) { + if (populateMarketplace) { + populateMarketplaces(products); System.out.println("in"); } - populateModelNumber(products ); - populateTitle( products ); - populateColor( products ); - populateSize( products ); - populateItemPresentedDetails( products ); + populateModelNumber(products); + populateTitle(products); + populateColor(products); + populateSize(products); + populateItemPresentedDetails(products); } - private void populateItemPresentedDetails( List products ){ - try{ - if( ! products.isEmpty() ){ - Product product = products.get( 0 ); - String inventory = String.valueOf( product.getInventory() ); - String itemPerBoxText = String.valueOf( product.getInventory() * product.getItemPerPack() ); - String boxCartonText = String.valueOf( ( product.getInventory() / product.getItemPerBox() ) ); + private void populateItemPresentedDetails(List products) { + try { + if (!products.isEmpty()) { + Product product = products.get(0); + String inventory = String.valueOf(product.getInventory()); + String itemPerBoxText = String.valueOf(product.getInventory() * product.getItemPerPack()); + String boxCartonText = String.valueOf((product.getInventory() / product.getItemPerBox())); - @SuppressLint("DefaultLocale") String packagingDetailsText = String.format("%d Item per Pack, %d Pack per Box", product.getItemPerPack(), product.getItemPerBox() ); - itemPerBox.setText( inventory ); - pieces.setText( itemPerBoxText ); - boxCarton.setText( boxCartonText ); - packagingDetails.setText( packagingDetailsText ); + @SuppressLint("DefaultLocale") String packagingDetailsText = String.format("%d Item per Pack, %d Pack per Box", product.getItemPerPack(), product.getItemPerBox()); + itemPerBox.setText(inventory); + pieces.setText(itemPerBoxText); + boxCarton.setText(boxCartonText); + packagingDetails.setText(packagingDetailsText); - boxCartonSelected.setText( String.valueOf( store.getReport().getItems().get(0).getCartonsSelected() )); - itemPerBoxSelected.setText( String.valueOf( store.getReport().getItems().get(0).getPacksSelected() ) ); - piecesSelected.setText( String.valueOf( store.getReport().getItems().get(0).getPiecesSelected() ) ); + boxCartonSelected.setText(String.valueOf(store.getReport().getItems().get(0).getCartonsSelected())); + itemPerBoxSelected.setText(String.valueOf(store.getReport().getItems().get(0).getPacksSelected())); + piecesSelected.setText(String.valueOf(store.getReport().getItems().get(0).getPiecesSelected())); - checkedBoxCartonSelected.setText( String.valueOf( store.getReport().getItems().get(0).getCheckedCartonsSelected() )); - checkedItemPerBoxSelected.setText( String.valueOf( store.getReport().getItems().get(0).getCheckedPacksSelected() ) ); - checkedPiecesSelected.setText( String.valueOf( store.getReport().getItems().get(0).getCheckedPiecesSelected() ) ); + checkedBoxCartonSelected.setText(String.valueOf(store.getReport().getItems().get(0).getCheckedCartonsSelected())); + checkedItemPerBoxSelected.setText(String.valueOf(store.getReport().getItems().get(0).getCheckedPacksSelected())); + checkedPiecesSelected.setText(String.valueOf(store.getReport().getItems().get(0).getCheckedPiecesSelected())); + cartonWeight.setText(String.valueOf(store.getReport().getItems().get(0).getCartonWeight())); + cartonLength.setText(String.valueOf(store.getReport().getItems().get(0).getCartonLength())); + cartonWidth.setText(String.valueOf(store.getReport().getItems().get(0).getCartonWidth())); + cartonHeight.setText(String.valueOf(store.getReport().getItems().get(0).getCartonHeight())); - // generalRemarks.setText( store.getReport().getItems().get(0).getSampleSize() ); + 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())); - store.getReport().getItems().get(0).setTotalPresentPieces( Long.parseLong( inventory ) ); - store.getReport().getItems().get(0).setTotalPresentPacks( Long.parseLong( itemPerBoxText ) ); - store.getReport().getItems().get(0).setTotalPresentCartons( Long.parseLong( boxCartonText ) ); - store.getReport().getItems().get(0).setPackingDetails( packagingDetailsText ); + aqlSampleSize.setText(String.valueOf(store.getReport().getItems().get(0).getSampleSize())); + + // generalRemarks.setText( store.getReport().getItems().get(0).getSampleSize() ); + + store.getReport().getItems().get(0).setTotalPresentPieces(Long.parseLong(inventory)); + store.getReport().getItems().get(0).setTotalPresentPacks(Long.parseLong(itemPerBoxText)); + store.getReport().getItems().get(0).setTotalPresentCartons(Long.parseLong(boxCartonText)); + store.getReport().getItems().get(0).setPackingDetails(packagingDetailsText); } - } catch ( Exception e){ - itemPerBox.setText( "0" ); - pieces.setText( "0" ); - boxCarton.setText( "0" ); - packagingDetails.setText( "" ); + } catch (Exception e) { + itemPerBox.setText("0"); + pieces.setText("0"); + boxCarton.setText("0"); + packagingDetails.setText(""); } } - private void populateSize( List products ){ + private void populateSize(List products) { - if( ! products.isEmpty() ){ - sizes = products.stream().map( Product::getSmSize ).distinct().filter(Objects::nonNull).collect(Collectors.toList() ); + if (!products.isEmpty()) { + sizes = products.stream().map(Product::getSmSize).distinct().filter(Objects::nonNull).collect(Collectors.toList()); } - if( !sizes.isEmpty() ){ - ArrayAdapter adapter = new ArrayAdapter<>( Objects.requireNonNull(getContext() ), - android.R.layout.simple_spinner_dropdown_item, sizes.toArray( new String[0]) ); - size.setAdapter( adapter ); + if (!sizes.isEmpty()) { + ArrayAdapter adapter = new ArrayAdapter<>(Objects.requireNonNull(getContext()), + android.R.layout.simple_spinner_dropdown_item, sizes.toArray(new String[0])); + size.setAdapter(adapter); // String sizeOption = (String) size.getSelectedItem(); - store.getReport().getItems().get(0).setSmSize( sizeOption ); + store.getReport().getItems().get(0).setSmSize(sizeOption); } } - private void populateColor( List products ){ + private void populateColor(List products) { - if( ! products.isEmpty() ){ - colors = products.stream().map( Product::getSmColor ).distinct().filter(Objects::nonNull).collect(Collectors.toList() ); + if (!products.isEmpty()) { + colors = products.stream().map(Product::getSmColor).distinct().filter(Objects::nonNull).collect(Collectors.toList()); } - if( !colors.isEmpty() ){ + if (!colors.isEmpty()) { - ArrayAdapter adapter = new ArrayAdapter<>( Objects.requireNonNull(getContext() ), - android.R.layout.simple_spinner_dropdown_item, colors.toArray( new String[0]) ); - color.setAdapter( adapter ); + ArrayAdapter adapter = new ArrayAdapter<>(Objects.requireNonNull(getContext()), + android.R.layout.simple_spinner_dropdown_item, colors.toArray(new String[0])); + color.setAdapter(adapter); String colorOption = (String) color.getSelectedItem(); - store.getReport().getItems().get(0).setSmColor( colorOption ); + store.getReport().getItems().get(0).setSmColor(colorOption); } } - private void populateTitle( List products ){ + private void populateTitle(List products) { - if( ! products.isEmpty() ){ - titles = products.stream().map( Product::getTitle ).distinct().filter(Objects::nonNull).collect(Collectors.toList()) ; + if (!products.isEmpty()) { + titles = products.stream().map(Product::getTitle).distinct().filter(Objects::nonNull).collect(Collectors.toList()); } - if( !titles.isEmpty() ){ - ArrayAdapter adapter = new ArrayAdapter<>( getContext(), android.R.layout.simple_spinner_dropdown_item, titles.toArray( new String[0] )); - title.setAdapter( adapter ); + if (!titles.isEmpty()) { + ArrayAdapter adapter = new ArrayAdapter<>(getContext(), android.R.layout.simple_spinner_dropdown_item, titles.toArray(new String[0])); + title.setAdapter(adapter); String titleOption = (String) title.getSelectedItem(); - store.getReport().getItems().get(0).setTitle( titleOption ); + store.getReport().getItems().get(0).setTitle(titleOption); } } - private void populateModelNumber( List products ){ + private void populateModelNumber(List products) { - if( ! products.isEmpty() ){ - modelNumbers = products.stream().map( Product::getModelNumber ).distinct().filter(Objects::nonNull).collect(Collectors.toList() ) ; + if (!products.isEmpty()) { + modelNumbers = products.stream().map(Product::getModelNumber).distinct().filter(Objects::nonNull).collect(Collectors.toList()); } - if( !modelNumbers.isEmpty() ){ - ArrayAdapter adapter = new ArrayAdapter<>( getContext(), android.R.layout.simple_spinner_dropdown_item, modelNumbers.toArray(new String[0] )); - modelNumber.setAdapter( adapter ); + if (!modelNumbers.isEmpty()) { + ArrayAdapter adapter = new ArrayAdapter<>(getContext(), android.R.layout.simple_spinner_dropdown_item, modelNumbers.toArray(new String[0])); + modelNumber.setAdapter(adapter); String modelOption = (String) modelNumber.getSelectedItem(); - store.getReport().getItems().get(0).setModelNumber( modelOption ); + store.getReport().getItems().get(0).setModelNumber(modelOption); } } - private void populateMarketplaces( List products ){ + private void populateMarketplaces(List products) { - if( ! products.isEmpty() ){ - marketplaces = products.stream().map( Product::getMarketplace ).distinct().filter(Objects::nonNull).collect(Collectors.toList() ); + if (!products.isEmpty()) { + marketplaces = products.stream().map(Product::getMarketplace).distinct().filter(Objects::nonNull).collect(Collectors.toList()); } - if( ! marketplaces.isEmpty()){ - ArrayAdapter adapter = new ArrayAdapter<>( getContext(), android.R.layout.simple_spinner_dropdown_item, marketplaces.toArray(new String[0] )); - markerplace.setAdapter( adapter ); + if (!marketplaces.isEmpty()) { + ArrayAdapter adapter = new ArrayAdapter<>(getContext(), android.R.layout.simple_spinner_dropdown_item, marketplaces.toArray(new String[0])); + markerplace.setAdapter(adapter); // String marketplaceOption = (String) markerplace.getSelectedItem(); - store.getReport().getItems().get(0).setMarketplace( marketplaceOption ); + store.getReport().getItems().get(0).setMarketplace(marketplaceOption); } + + String[] inspectionLevelArray = {"1", "2", "3"}; + String[] inspectionLevelQuality = {"1.0", "1.5", "2.5", "4.0"}; + ArrayAdapter adapterInspectionLevel = new ArrayAdapter<>(getContext(), android.R.layout.simple_spinner_dropdown_item, inspectionLevelArray); + sp_inspectionLevel.setAdapter(adapterInspectionLevel); + + ArrayAdapter adapterLevelMajor = new ArrayAdapter<>(getContext(), android.R.layout.simple_spinner_dropdown_item, inspectionLevelQuality); + sp_qLevelMajor.setAdapter(adapterLevelMajor); + + ArrayAdapter adapterLevelMinor = new ArrayAdapter<>(getContext(), android.R.layout.simple_spinner_dropdown_item, inspectionLevelQuality); + sp_qLevelMinor.setAdapter(adapterLevelMinor); } /* - * initialize views - * */ - private void initializeViews( View view ){ - leftFab = view.findViewById( R.id.button_left_frag_1 ); - rightFab = view.findViewById( R.id.button_right_frag_1 ); + * initialize views + * */ + private void initializeViews(View view) { + leftFab = view.findViewById(R.id.button_left_frag_1); + rightFab = view.findViewById(R.id.button_right_frag_1); btnDraft = view.findViewById(R.id.button_draft_first); - markerplace = view.findViewById( R.id.marketplace ); - sku = view.findViewById( R.id.sku ); - modelNumber = view.findViewById( R.id.model_number ); - title = view.findViewById( R.id.title ); - color = view.findViewById( R.id.color ); - size = view.findViewById( R.id.size ); - boxCarton = view.findViewById( R.id. box_carton ); - itemPerBox = view.findViewById( R.id.item_per_box ); - pieces = view.findViewById( R.id.pieces ); - packagingDetails = view.findViewById( R.id.packaging ); - boxCartonSelected = view.findViewById( R.id.box_carton_selected ); - itemPerBoxSelected = view.findViewById( R.id.item_per_box_selected ); - piecesSelected = view.findViewById( R.id.pieces_selected ); + markerplace = view.findViewById(R.id.marketplace); + sp_inspectionLevel = view.findViewById(R.id.sp_inspectionLevel); + sp_qLevelMajor = view.findViewById(R.id.sp_qLevelMajor); + sp_qLevelMinor = view.findViewById(R.id.sp_qLevelMinor); + sku = view.findViewById(R.id.sku); + modelNumber = view.findViewById(R.id.model_number); + title = view.findViewById(R.id.title); + color = view.findViewById(R.id.color); + size = view.findViewById(R.id.size); + boxCarton = view.findViewById(R.id.box_carton); + itemPerBox = view.findViewById(R.id.item_per_box); + pieces = view.findViewById(R.id.pieces); + packagingDetails = view.findViewById(R.id.packaging); + boxCartonSelected = view.findViewById(R.id.box_carton_selected); + itemPerBoxSelected = view.findViewById(R.id.item_per_box_selected); + piecesSelected = view.findViewById(R.id.pieces_selected); + + txtTesting = view.findViewById(R.id.txtTesting); + + aqlSampleSize = view.findViewById(R.id.et_aql_sample_size); + + cartonWeight = view.findViewById(R.id.et_carton_weight); + cartonLength = view.findViewById(R.id.et_carton_length); + cartonWidth = view.findViewById(R.id.et_carton_width); + cartonHeight = view.findViewById(R.id.et_carton_height); + + packWeight = view.findViewById(R.id.et_pack_weight); + packLength = view.findViewById(R.id.et_pack_length); + packWidth = view.findViewById(R.id.et_pack_width); + packHeight = view.findViewById(R.id.et_pack_height); checkedBoxCartonSelected = view.findViewById(R.id.checked_box_carton_selected); checkedItemPerBoxSelected = view.findViewById(R.id.checked_item_per_box_selected); checkedPiecesSelected = view.findViewById(R.id.checked_pieces_selected); - fri = view.findViewById( R.id.fri ); - refri = view.findViewById( R.id.refri ); - searchSku = view.findViewById( R.id.search_sku_btn ); - profileName= view.findViewById( R.id.first_step_name ); - profileImage = view.findViewById( R.id.first_step_profile_image ); - scanBtn = view.findViewById( R.id.scan_sku_btn ); - showHistoryBtn = view.findViewById( R.id.button_show_history ); + fri = view.findViewById(R.id.fri); + refri = view.findViewById(R.id.refri); + searchSku = view.findViewById(R.id.search_sku_btn); + profileName = view.findViewById(R.id.first_step_name); + profileImage = view.findViewById(R.id.first_step_profile_image); + scanBtn = view.findViewById(R.id.scan_sku_btn); + showHistoryBtn = view.findViewById(R.id.button_show_history); } - public void onBarcodeScanResult( String result ){ - if( result != null && ! result.isEmpty() ){ - store.getReport().getItems().get(0).setSku( result ); + public void onBarcodeScanResult(String result) { + if (result != null && !result.isEmpty()) { + store.getReport().getItems().get(0).setSku(result); System.out.println("SKU-2: " + store.getReport().getItems().get(0).getFnsku()); - sku.setText( result ); + sku.setText(result); } } private void openItemHistoryDialog() { - LayoutInflater inflater = LayoutInflater.from( getContext() ); - View dialogView = inflater.inflate( R.layout.item_history, null); + LayoutInflater inflater = LayoutInflater.from(getContext()); + View dialogView = inflater.inflate(R.layout.item_history, null); // recycler view - RecyclerView itemHistoryRecyclerView = dialogView.findViewById( R.id.item_history_recyclerview ); - LinearLayoutManager layoutManager = new LinearLayoutManager( getContext() ); - itemHistoryRecyclerView.setLayoutManager( layoutManager ); - AlertDialog.Builder builder = new AlertDialog.Builder( Objects.requireNonNull(getContext()) ); + RecyclerView itemHistoryRecyclerView = dialogView.findViewById(R.id.item_history_recyclerview); + LinearLayoutManager layoutManager = new LinearLayoutManager(getContext()); + itemHistoryRecyclerView.setLayoutManager(layoutManager); + AlertDialog.Builder builder = new AlertDialog.Builder(Objects.requireNonNull(getContext())); // set adapter - ItemHistoryAdapter itemHistoryAdapter = new ItemHistoryAdapter( new ArrayList<>()); - itemHistoryRecyclerView.setAdapter( itemHistoryAdapter ); + ItemHistoryAdapter itemHistoryAdapter = new ItemHistoryAdapter(new ArrayList<>()); + itemHistoryRecyclerView.setAdapter(itemHistoryAdapter); builder.setView(dialogView) .setTitle("Item History") - .setPositiveButton( "OK",(dialog, which) -> { + .setPositiveButton("OK", (dialog, which) -> { dialog.dismiss(); - } ) + }) .setNegativeButton("Cancel", (dialog, which) -> { // Handle Cancel button click dialog.dismiss(); }); - if( store.getReport().getItems().get(0).getSku() != null ){ - apiService.fetchItemsLogs( store.getReport().getItems().get(0).getSku() ).enqueue( + if (store.getReport().getItems().get(0).getSku() != null) { + apiService.fetchItemsLogs(store.getReport().getItems().get(0).getSku()).enqueue( new Callback>() { @SuppressLint("NotifyDataSetChanged") @Override public void onResponse(Call> call, Response> response) { - if( response.isSuccessful() && response.body() != null ){ + if (response.isSuccessful() && response.body() != null) { // set adapter - System.out.println( response.body() ); - ItemHistoryAdapter itemHistoryAdapter = new ItemHistoryAdapter( response.body() ); - itemHistoryRecyclerView.setAdapter( itemHistoryAdapter ); + System.out.println(response.body()); + ItemHistoryAdapter itemHistoryAdapter = new ItemHistoryAdapter(response.body()); + itemHistoryRecyclerView.setAdapter(itemHistoryAdapter); itemHistoryAdapter.notifyDataSetChanged(); } } @Override public void onFailure(Call> call, Throwable t) { - System.out.println( t.getMessage() ); + System.out.println(t.getMessage()); } } ); @@ -801,12 +1125,12 @@ public class FirstStepFragment extends Fragment implements View.OnClickListener dialog.show(); } - private void updateProfileViews( ) throws NullPointerException{ + private void updateProfileViews() throws NullPointerException { SharedPreferences sharedPreferences = getActivity().getSharedPreferences("login_prefs", Context.MODE_PRIVATE); - profileName.setText( sharedPreferences.getString("name", null ) ); - Glide.with( getContext() ) - .load( store.getProfileImage( ) ) - .into( profileImage ); + profileName.setText(sharedPreferences.getString("name", null)); + Glide.with(getContext()) + .load(store.getProfileImage()) + .into(profileImage); } private InspectionReport getSingleReport(InspectionReportWrapper wrapper) { @@ -833,4 +1157,69 @@ public class FirstStepFragment extends Fragment implements View.OnClickListener return report; } + + private void trackSampleCode(int itemPresentedPieces, int inspectionLevel, double selectedLevelMajor, double selectedLevelMinor) { + try { + String sampleCode = ""; + double levelMajor = 0.0, levelMinor = 0.0; + int sampleSizeMajor = 0; + int sampleSizeMinor = 0; + List inspectionGeneralLabels = new InspectionLabelRepository(getContext()).getInspectionLabels(); + List inspectionAcceptableQualities = new InspectionLabelRepository(getContext()).getQualityLabels(); + + //for sample code + for (InspectionLabel label : inspectionGeneralLabels) { + if (label.getInspectionLevel() == inspectionLevel && + label.getMinLotSize() <= itemPresentedPieces && + label.getMaxLotSize() >= itemPresentedPieces) { + sampleCode = label.getSampleCode(); + //Log.e("sampleCode: ",""+sampleCode); + break; + } + } + + //For level major + for (QualityLabel quality : inspectionAcceptableQualities) { + if (quality.getQualityLevel() == selectedLevelMajor && Objects.equals(quality.getSampleCode(), sampleCode)) { + levelMajor = quality.getNoOfAcceptedDefects(); + sampleSizeMajor = quality.getSampleSize(); + } + + //For Level Minor + if (quality.getQualityLevel() == selectedLevelMinor && + Objects.equals(quality.getSampleCode(), sampleCode)) { + levelMinor = quality.getNoOfAcceptedDefects(); + sampleSizeMinor = quality.getSampleSize(); + } + } + + String testDetails = "Item Presented Pieces: " + itemPresentedPieces + + "\nInspection Level: " + inspectionLevel + + "\nSelected Level Major: " + selectedLevelMajor + + "\nSelected Level Minor: " + selectedLevelMinor + + "\nSample Code: " + sampleCode + + "\nLevel Major Defects: " + levelMajor + + "\nLevel Minor Defects: " + levelMinor + + "\nSampleSizeMajor: " + sampleSizeMajor + + "\nSampleSizeMinor: " + sampleSizeMinor; + + txtTesting.setText(testDetails); + Log.e("SampleSizeMajor: ",""+sampleSizeMajor); + aqlSampleSize.setText(String.valueOf(sampleSizeMajor)); + + store.getReport().getItems().get(0).setSampleSize(sampleSizeMajor); + store.getReport().getItems().get(0).setMajorQualityLevel((long) levelMajor); + store.getReport().getItems().get(0).setMinorQualityLevel((long) levelMinor); + } + catch (Exception e) { + e.printStackTrace(); + } + + + /*if (minorInspectionAcceptableQuality != null && majorInspectionAcceptableQuality != null) { + minorAcceptedCriteriaFromAqlMap.put(item.getId(), minorInspectionAcceptableQuality.getNoOfAcceptedDefects()); + majorAcceptedCriteriaFromAqlMap.put(item.getId(), majorInspectionAcceptableQuality.getNoOfAcceptedDefects()); + }*/ + + } } diff --git a/app/src/main/java/com/utopiaindustries/qualitychecker/ui/fragments/ThirdStepFragment.java b/app/src/main/java/com/utopiaindustries/qualitychecker/ui/fragments/ThirdStepFragment.java index 050fd05..edaff84 100644 --- a/app/src/main/java/com/utopiaindustries/qualitychecker/ui/fragments/ThirdStepFragment.java +++ b/app/src/main/java/com/utopiaindustries/qualitychecker/ui/fragments/ThirdStepFragment.java @@ -8,6 +8,7 @@ import android.os.Handler; import android.os.Looper; import android.text.Editable; import android.text.TextWatcher; +import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -65,11 +66,11 @@ public class ThirdStepFragment extends Fragment implements View.OnClickListener private InspectionReportService inspectionReportService; private RecyclerView vocRecyclerView,itemDimensionsRecyclerView; private Store store; - private Spinner resultSpinner; + //private Spinner resultSpinner; private ApiService apiService; private EditText generalRemarks, etQualityAuditor, etProdRepresentative, etQcRepresentative; - private TextView minorCountTv,majorCountTv,criticalCountTv; + private TextView minorCountTv,majorCountTv,criticalCountTv, resultStatus; @Nullable @Override @@ -268,6 +269,7 @@ public class ThirdStepFragment extends Fragment implements View.OnClickListener Handler handler = new Handler(Looper.getMainLooper()); handler.post(() -> { + Log.e("Report-ToString: ",""+store.getReport().toString()); SharedPreferences sharedPreferences = getContext().getSharedPreferences("login_prefs", Context.MODE_PRIVATE); long draftReportId = Long.parseLong(sharedPreferences.getString("draftReportId", null)); @@ -360,12 +362,12 @@ public class ThirdStepFragment extends Fragment implements View.OnClickListener etProdRepresentative.setText(store.getReport().getProductionRepresentative()); etQcRepresentative.setText(store.getReport().getQcRepresentative()); - ArrayAdapter adapter = new ArrayAdapter<>( getContext(), + /*ArrayAdapter adapter = new ArrayAdapter<>( getContext(), android.R.layout.simple_spinner_item, inspectionReportService.getReportResult() ); - resultSpinner.setAdapter( adapter ); + resultSpinner.setAdapter( adapter );*/ - String defaultSelection = store.getReport().getReportResult(); + /*String defaultSelection = store.getReport().getReportResult(); int defaultIndexResultIndex = inspectionReportService.getReportResult().indexOf( defaultSelection ); resultSpinner.setSelection( defaultIndexResultIndex ); @@ -380,7 +382,7 @@ public class ThirdStepFragment extends Fragment implements View.OnClickListener public void onNothingSelected(AdapterView parent) { } - }); + });*/ minorCountTv.setText( String.valueOf(0) ); majorCountTv.setText( String.valueOf(0) ) ; @@ -413,6 +415,19 @@ public class ThirdStepFragment extends Fragment implements View.OnClickListener minorCountTv.setText( String.format("Minor : %d", minor ) ); majorCountTv.setText( String.format("Major : %d", major ) ) ; criticalCountTv.setText( String.format("Critical : %d", crirical ) ); + + long minorInspection = store.getReport().getItems().get(0).getMinorQualityLevel(); + long majorInspection = store.getReport().getItems().get(0).getMinorQualityLevel(); + if((long) minor <= minorInspection + && (long) major <= majorInspection + && (long) crirical == 0) { + resultStatus.setText("Passed"); + store.getReport().setReportResult( "Passed" ); + } + else{ + resultStatus.setText("Failed"); + store.getReport().setReportResult( "Failed" ); + } } } @@ -476,7 +491,8 @@ public class ThirdStepFragment extends Fragment implements View.OnClickListener profileImage = view.findViewById( R.id.third_step_profile_image ); profileName = view.findViewById( R.id.third_profile_name ); vocRecyclerView = view.findViewById( R.id.voc_recyclerview ); - resultSpinner = view.findViewById( R.id.result_spinner ); + // resultSpinner = view.findViewById( R.id.result_spinner ); + resultStatus = view.findViewById( R.id.result_status); generalRemarks = view.findViewById( R.id.general_remarks ); itemDimensionsRecyclerView = view.findViewById( R.id.item_dimensions_recyclerview ); minorCountTv = view.findViewById( R.id.minor_count ); diff --git a/app/src/main/res/layout/fragment_first_step.xml b/app/src/main/res/layout/fragment_first_step.xml index 6d3ac90..4daea70 100644 --- a/app/src/main/res/layout/fragment_first_step.xml +++ b/app/src/main/res/layout/fragment_first_step.xml @@ -1,446 +1,649 @@ + android:paddingBottom="10dp" + android:paddingLeft="5dp" + android:paddingRight="5dp" + android:paddingTop="5dp" + android:scrollbars="vertical"> - - + android:orientation="vertical"> + + + android:textStyle="bold" /> + android:textStyle="bold|italic" /> + + + + +