- ui bugs fixed

main
saif 2024-09-26 12:20:20 +05:00
parent 76b4ddbc6f
commit 4668ef5259
11 changed files with 142 additions and 81 deletions

View File

@ -37,21 +37,21 @@
android:name=".ui.activities.MainActivity"
android:exported="true"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateAlwaysVisible|adjustResize">
android:windowSoftInputMode="adjustResize">
</activity>
<activity
android:name=".ui.activities.HomeActivity"
android:exported="true"
android:theme="@style/AppTheme"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateAlwaysVisible|adjustResize">
android:windowSoftInputMode="adjustPan|adjustResize">
</activity>
<activity
android:name=".ui.activities.LoginActivity"
android:exported="true"
android:theme="@style/AppTheme"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateAlwaysVisible|adjustResize">
android:windowSoftInputMode="adjustPan|adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />

View File

@ -71,6 +71,7 @@ public class DatabaseHelper extends SQLiteOpenHelper {
* */
public static final String CHECKPOINT_SKU_TABLE_NAME = "checkpoint_sku";
public static final String CHECKPOINT_SKU_SKU = "sku";
public static final String CHECKPOINT_SKU_MARKETPLACE = "marketplace";
public static final String CHECKPOINT_SKU_CHECKPOINT_ID = "checkpoint_id";
public static final String CHECKPOINT_SKU_STANDARD = "standard";
@ -130,9 +131,10 @@ public class DatabaseHelper extends SQLiteOpenHelper {
String CREATE_SKU_CHECKPOINT_TABLE = "CREATE TABLE " + CHECKPOINT_SKU_TABLE_NAME + " (" +
CHECKPOINT_SKU_SKU + " TEXT NOT NULL," +
CHECKPOINT_SKU_MARKETPLACE + " TEXT NOT NULL," +
CHECKPOINT_SKU_CHECKPOINT_ID + " INTEGER NOT NULL," +
CHECKPOINT_SKU_STANDARD + " TEXT," +
"PRIMARY KEY (" + CHECKPOINT_SKU_SKU + ", " + CHECKPOINT_SKU_CHECKPOINT_ID + "))";
"PRIMARY KEY (" + CHECKPOINT_SKU_SKU + ", " + CHECKPOINT_SKU_MARKETPLACE + ", " + CHECKPOINT_SKU_CHECKPOINT_ID + "))";
db.execSQL( CREATE_PRODUCT_TABLE );
db.execSQL( CREATE_INSPECTION_DIMENSION_TABLE );

View File

@ -33,6 +33,7 @@ public class InspectionCheckpointSkuRepository {
for ( InspectionCheckpointSku checkPoint : checkPoints ) {
ContentValues values = new ContentValues();
values.put(DatabaseHelper.CHECKPOINT_SKU_SKU, checkPoint.getSku() );
values.put(DatabaseHelper.CHECKPOINT_SKU_MARKETPLACE, checkPoint.getMarketplace() );
values.put(DatabaseHelper.CHECKPOINT_SKU_CHECKPOINT_ID, checkPoint.getCheckpointId() );
values.put(DatabaseHelper.CHECKPOINT_SKU_STANDARD, checkPoint.getStandard() );
database.insertWithOnConflict(DatabaseHelper.CHECKPOINT_SKU_TABLE_NAME, null, values, SQLiteDatabase.CONFLICT_REPLACE);
@ -46,10 +47,10 @@ public class InspectionCheckpointSkuRepository {
}
@SuppressLint("Range")
public List<InspectionCheckpointSku> findBySku(String sku ){
public List<InspectionCheckpointSku> findBySkuAndMarketplace(String sku, String marketplace ){
String selection = DatabaseHelper.CHECKPOINT_SKU_SKU + "=?";
String[] selectionArgs = {sku};
String selection = DatabaseHelper.CHECKPOINT_SKU_SKU + "=? AND " + DatabaseHelper.CHECKPOINT_SKU_MARKETPLACE + "=?";
String[] selectionArgs = {sku,marketplace};
Cursor cursor = database.query( DatabaseHelper.CHECKPOINT_SKU_TABLE_NAME,
null,
@ -64,6 +65,7 @@ public class InspectionCheckpointSkuRepository {
do {
InspectionCheckpointSku checkpointSku = new InspectionCheckpointSku();
checkpointSku.setSku( cursor.getString( cursor.getColumnIndex( DatabaseHelper.CHECKPOINT_SKU_SKU )));
checkpointSku.setMarketplace( cursor.getString( cursor.getColumnIndex( DatabaseHelper.CHECKPOINT_SKU_MARKETPLACE )));
checkpointSku.setCheckpointId( cursor.getLong(cursor.getColumnIndex( DatabaseHelper.CHECKPOINT_SKU_CHECKPOINT_ID )));
checkpointSku.setStandard( cursor.getString(cursor.getColumnIndex(DatabaseHelper.CHECKPOINT_SKU_STANDARD )));
checkpointSkus.add( checkpointSku );
@ -90,6 +92,7 @@ public class InspectionCheckpointSkuRepository {
do {
InspectionCheckpointSku checkPoint = new InspectionCheckpointSku();
checkPoint.setSku(cursor.getString( cursor.getColumnIndex(DatabaseHelper.CHECKPOINT_SKU_SKU )));
checkPoint.setMarketplace( cursor.getString( cursor.getColumnIndex( DatabaseHelper.CHECKPOINT_SKU_MARKETPLACE )));
checkPoint.setCheckpointId(cursor.getLong(cursor.getColumnIndex(DatabaseHelper.CHECKPOINT_SKU_CHECKPOINT_ID) ));
checkPoint.setStandard(cursor.getString(cursor.getColumnIndex(DatabaseHelper.CHECKPOINT_SKU_STANDARD )));
checkPoints.add( checkPoint );

View File

@ -5,14 +5,16 @@ public class InspectionCheckpointSku {
private String sku;
private long checkpointId;
private String standard;
private String marketplace;
public InspectionCheckpointSku() {
}
public InspectionCheckpointSku(String sku, long checkpointId, String standard) {
public InspectionCheckpointSku(String sku, long checkpointId, String standard, String marketplace) {
this.sku = sku;
this.checkpointId = checkpointId;
this.standard = standard;
this.marketplace = marketplace;
}
public String getSku() {
@ -38,4 +40,22 @@ public class InspectionCheckpointSku {
public void setStandard(String standard) {
this.standard = standard;
}
public String getMarketplace() {
return marketplace;
}
public void setMarketplace(String marketplace) {
this.marketplace = marketplace;
}
@Override
public String toString() {
return "InspectionCheckpointSku{" +
"sku='" + sku + '\'' +
", checkpointId=" + checkpointId +
", standard='" + standard + '\'' +
", marketplace='" + marketplace + '\'' +
'}';
}
}

View File

@ -7,6 +7,7 @@ import android.content.SharedPreferences;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.view.View;
import android.view.ViewTreeObserver;
import android.widget.Toast;
import androidx.activity.EdgeToEdge;

View File

@ -13,6 +13,7 @@ import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
@ -74,7 +75,8 @@ public class CheckPointAdapter extends
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
InspectionItemCheckPoint checkPoint = checkPointList.get( position );
holder.bind(checkPoints, defects, defectTypes, checkPoint, checkpointSkus, context );
holder.setIsRecyclable(false);
//holder.setIsRecyclable(false);
// spinner on change
{
holder.checkpointSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@ -96,21 +98,7 @@ public class CheckPointAdapter extends
}
// checkboxes on change
{
holder.okCheckBox.setOnCheckedChangeListener((buttonView, isChecked) -> {
if (isChecked) {
holder.linearLayout.setVisibility(View.INVISIBLE);
}
checkPoint.setChecked ( false );
holder.noCheckBox.setChecked( !isChecked );
});
holder.noCheckBox.setOnCheckedChangeListener((buttonView, isChecked) -> {
if (isChecked) {
holder.linearLayout.setVisibility(View.VISIBLE);
}
checkPoint.setChecked( true );
holder.okCheckBox.setChecked( !isChecked );
});
holder.setUpCheckboxesListeners( checkPoint );
}
// remarks on change
{
@ -154,6 +142,9 @@ public class CheckPointAdapter extends
private final TextView selectedImage,standard;
private final ImageView imagePreview;
private final RecyclerView defectRecyclerView;
private TextWatcher remarksTextWatcher;
private CompoundButton.OnCheckedChangeListener okCheckboxListener;
private CompoundButton.OnCheckedChangeListener noCheckboxListener;
public ViewHolder(@NonNull View itemView) {
super(itemView);
@ -178,8 +169,27 @@ public class CheckPointAdapter extends
InspectionItemCheckPoint data,
List<InspectionCheckpointSku> checkpointSkus,
Context context ) {
// initialize recyclerview
if ( remarksTextWatcher != null) {
remarks.removeTextChangedListener(remarksTextWatcher);
}
if( okCheckboxListener != null ){
okCheckBox.setOnCheckedChangeListener( null );
}
if( noCheckboxListener != null ){
noCheckBox.setOnCheckedChangeListener( null );
}
remarks.setText( data.getRemarks() );
imagePreview.setImageBitmap( null );
selectedImage.setText( "" );
if( data.getFile() != null && data.getFile().length > 0 && data.getImagePath() != null && ! data.getImagePath().isEmpty() ){
Bitmap bitmap = BitmapFactory.decodeByteArray( data.getFile(), 0 , data.getFile().length );
imagePreview.setImageBitmap( bitmap );
selectedImage.setText( data.getImagePath() );
}
// initialize recyclerview
List<String> checkPointsList = checkPoints.stream().map(InspectionCheckPoint::getTitle).collect(Collectors.toList());
// Populate checklist Spinner dropdown
@ -188,13 +198,11 @@ public class CheckPointAdapter extends
spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
checkpointSpinner.setAdapter(spinnerAdapter);
// Pre populate
String defaultSelectedItem = data.getTitle();
int defaultPosition = checkPointsList.indexOf(defaultSelectedItem);
checkpointSpinner.setSelection(defaultPosition);
remarks.setText( data.getRemarks() );
okCheckBox.setChecked( data.getChecked() );
noCheckBox.setChecked( ! data.getChecked());
@ -204,12 +212,6 @@ public class CheckPointAdapter extends
linearLayout.setVisibility(View.VISIBLE);
}
selectedImage.setText( data.getImagePath() );
if( data.getFile() != null ){
Bitmap bitmap = BitmapFactory.decodeByteArray( data.getFile(), 0 , data.getFile().length );
imagePreview.setImageBitmap( bitmap );
}
InspectionCheckPoint cp = checkPoints.stream().filter(c -> c.getTitle().equalsIgnoreCase(defaultSelectedItem)).findFirst().orElse( new InspectionCheckPoint());
// set standard
if( checkpointSkus != null ){
@ -220,9 +222,11 @@ public class CheckPointAdapter extends
if( cpSku.getStandard() != null && ! cpSku.getStandard().isEmpty() ){
standard.setText( cpSku.getStandard() );
} else {
if( standard.getParent() != null ){
((ViewGroup) standard.getParent() ).removeView( standard );
}
}
}
defectRecyclerView.setLayoutManager( new LinearLayoutManager( context ) );
DefectsAdapter defectsAdapter = new DefectsAdapter(data, defectTypeOptions, defects, cp);
defectRecyclerView.setAdapter( defectsAdapter );
@ -235,20 +239,11 @@ public class CheckPointAdapter extends
.collect(Collectors.toList());
List<String> defectList = filteredDefects.stream().map(InspectionDefect::getDefect).collect(Collectors.toList());
// Populate defect Spinner dropdown
// ArrayAdapter<String> defectSpinnerAdapter = new ArrayAdapter<>(defectsSpinner.getContext(),
// android.R.layout.simple_spinner_item, defectList);
// defectSpinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
// defectsSpinner.setAdapter(defectSpinnerAdapter);
//
// String defaultDefectSelectedItem = data.getDefectTitle();
// int defaultSelectedDefectPosition = defectList.indexOf(defaultDefectSelectedItem);
// defectsSpinner.setSelection(defaultSelectedDefectPosition);
}
public void setupRemarksListener(InspectionItemCheckPoint checkPoint) {
// Remarks EditText listener
remarks.addTextChangedListener(new TextWatcher() {
remarksTextWatcher = new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@ -261,7 +256,30 @@ public class CheckPointAdapter extends
@Override
public void afterTextChanged(Editable s) {
}
});
};
remarks.addTextChangedListener( remarksTextWatcher );
}
public void setUpCheckboxesListeners( InspectionItemCheckPoint checkPoint ){
okCheckboxListener = (buttonView, isChecked) -> {
if (isChecked) {
linearLayout.setVisibility(View.INVISIBLE);
}
checkPoint.setChecked ( false );
noCheckBox.setChecked( !isChecked );
};
noCheckboxListener = (buttonView, isChecked) -> {
if (isChecked) {
linearLayout.setVisibility(View.VISIBLE);
}
checkPoint.setChecked( true );
okCheckBox.setChecked( !isChecked );
};
okCheckBox.setOnCheckedChangeListener( okCheckboxListener );
noCheckBox.setOnCheckedChangeListener( noCheckboxListener );
}
}
}

View File

@ -101,7 +101,6 @@ public class DefectsAdapter extends RecyclerView.Adapter<DefectsAdapter.DefectVi
populateDefectOptionsSpinner( holder );
populateQuantity( holder );
// Populate defect type Spinner dropdown
{
holder.defectTypeSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
@ -133,28 +132,7 @@ public class DefectsAdapter extends RecyclerView.Adapter<DefectsAdapter.DefectVi
// }
// });
holder.quantity.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) {
if( s == null || s.toString().isEmpty() ){
checkPoint.getQuantities().set( position , 0F );
} else {
checkPoint.getQuantities().set( position , Float.parseFloat( s.toString() ));
}
}
@Override
public void afterTextChanged(Editable s) {
}
});
holder.setUpQuantityListener( checkPoint, position );
holder.deleteBtn.setOnClickListener(v-> {
System.out.println( holder.getAdapterPosition() );
@ -185,6 +163,8 @@ public class DefectsAdapter extends RecyclerView.Adapter<DefectsAdapter.DefectVi
private ImageButton deleteBtn;
private EditText quantity;
private TextWatcher quantityTextWatcher;
public DefectViewHolder(@NonNull View itemView) {
super(itemView);
defectSpinner = itemView.findViewById( R.id.defect_spinner );
@ -193,5 +173,33 @@ public class DefectsAdapter extends RecyclerView.Adapter<DefectsAdapter.DefectVi
quantity = itemView.findViewById( R.id.defect_quantity );
}
public void setUpQuantityListener( InspectionItemCheckPoint checkPoint, int position ){
if ( quantityTextWatcher != null) {
quantity.removeTextChangedListener( quantityTextWatcher );
}
quantityTextWatcher = 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) {
}
@Override
public void afterTextChanged(Editable s) {
if( s == null || s.toString().isEmpty() ){
checkPoint.getQuantities().set( position , 0F );
} else {
checkPoint.getQuantities().set( position , Float.parseFloat( s.toString() ));
}
}
};
quantity.addTextChangedListener( quantityTextWatcher );
}
}
}

View File

@ -119,6 +119,10 @@ public class FirstStepFragment extends Fragment implements View.OnClickListener
marketplaceOption,
false
);
populateSkuCheckpointsParams(
store.getReport().getItems().get(0).getSku(),
marketplaceOption
);
}
}
@ -293,7 +297,9 @@ public class FirstStepFragment extends Fragment implements View.OnClickListener
if( v.getId() == R.id.search_sku_btn ){
if( sku.getText() != null ){
populateProductDataOnSelection( sku.getText().toString(), "", true );
populateSkuCheckpointsParams( store.getReport().getItems().get(0).getSku() );
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 ){
@ -308,10 +314,10 @@ public class FirstStepFragment extends Fragment implements View.OnClickListener
}
}
private void populateSkuCheckpointsParams( String sku ){
if( sku != null && ! sku.isEmpty() ){
private void populateSkuCheckpointsParams( String sku, String marketplace ){
if( sku != null && ! sku.isEmpty() && marketplace != null && ! marketplace.isEmpty() ){
List<InspectionCheckpointSku> checkpointSkus = new InspectionCheckpointSkuRepository( getContext() )
.findBySku( sku );
.findBySkuAndMarketplace( sku, marketplace );
System.out.println( checkpointSkus );
store.setCheckpointSkus( checkpointSkus );
}
@ -341,7 +347,7 @@ public class FirstStepFragment extends Fragment implements View.OnClickListener
fri.setChecked( store.getReport().getFri() );
refri.setChecked( ! store.getReport().getFri() );
// sku
sku.setText( store.getReport().getItems().get(0).getSku() );
sku.setText( store.getReport().getItems().get(0).getFnsku() );
System.out.println( products );
System.out.println( store.getReport().getItems().get(0) );

View File

@ -7,12 +7,15 @@ import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.graphics.Rect;
import android.net.Uri;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
@ -112,6 +115,7 @@ public class SecondStepFragment extends Fragment
public void onImagePickerResult(int requestCode, int resultCode, Intent data) {
if ( resultCode == RESULT_OK && data != null ) {
try {
System.out.println( requestCode );
ImageProcessor imageProcessor = new ImageProcessor();
Uri selectedImageUri = data.getData();
assert selectedImageUri != null;

View File

@ -84,7 +84,7 @@
android:layout_height="match_parent"
android:layout_weight="1"
android:textAlignment="center"
android:text="image">
android:text="">
</TextView>
<ImageButton

View File

@ -131,7 +131,6 @@
app:layout_constraintTop_toBottomOf="@+id/guide_lne"
app:layout_constraintVertical_bias="0.008" />
</LinearLayout>
<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"