Store complete report to server
parent
0d3b90ffd8
commit
8934c58ba6
|
@ -42,5 +42,6 @@ dependencies {
|
|||
implementation libs.converter.gson
|
||||
implementation libs.glide
|
||||
implementation libs.easypermissions
|
||||
implementation(libs.preference)
|
||||
|
||||
}
|
|
@ -1,24 +1,44 @@
|
|||
package com.utopiaindustries.qualitycontrol.adapters;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.net.Uri;
|
||||
import android.os.Environment;
|
||||
import android.provider.MediaStore;
|
||||
import android.text.Editable;
|
||||
import android.text.TextWatcher;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.AutoCompleteTextView;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.core.content.FileProvider;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.request.RequestOptions;
|
||||
import com.utopiaindustries.qualitycontrol.R;
|
||||
import com.utopiaindustries.qualitycontrol.utils.ImageSelectionListener;
|
||||
import com.utopiaindustries.qualitycontrol.viewmodels.ItemModel;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class ItemStepsAdapter extends RecyclerView.Adapter<ItemStepsAdapter.ItemViewHolder> {
|
||||
|
||||
|
@ -26,10 +46,12 @@ public class ItemStepsAdapter extends RecyclerView.Adapter<ItemStepsAdapter.Item
|
|||
private final List<ItemModel> items;
|
||||
private final List<String> dropdownOptions = new ArrayList<>();
|
||||
double percentage = 0.0, selectedValue = 0.0;
|
||||
private final ImageSelectionListener imageSelectionListener;
|
||||
|
||||
public ItemStepsAdapter(Context context, List<ItemModel> items) {
|
||||
public ItemStepsAdapter(Context context, List<ItemModel> items, ImageSelectionListener listener) {
|
||||
this.context = context;
|
||||
this.items = items;
|
||||
this.imageSelectionListener = listener;
|
||||
|
||||
dropdownOptions.add("1");
|
||||
dropdownOptions.add("2");
|
||||
|
@ -49,6 +71,22 @@ public class ItemStepsAdapter extends RecyclerView.Adapter<ItemStepsAdapter.Item
|
|||
public void onBindViewHolder(@NonNull ItemViewHolder holder, int position) {
|
||||
ItemModel currentItem = items.get(position);
|
||||
|
||||
// Set data
|
||||
holder.et_remarks.setText(currentItem.getRemarks());
|
||||
holder.tvPercentage.setText(currentItem.getPercentage());
|
||||
//Log.e("Spinner-selection: ",""+currentItem.getSelectedOption());
|
||||
holder.scoreTextview.setText(String.valueOf(currentItem.getSelectedOption()));
|
||||
|
||||
if (currentItem.getImageUri() != null) {
|
||||
|
||||
Glide.with(context)
|
||||
.load(currentItem.getImageUri()) // Glide will handle the decoding and placeholder
|
||||
.placeholder(R.drawable.img_load)
|
||||
.apply(new RequestOptions().centerCrop())
|
||||
.into(holder.imageView);
|
||||
|
||||
}
|
||||
|
||||
currentItem.setStepId(position + 1);
|
||||
switch (position) {
|
||||
case 0:
|
||||
|
@ -94,6 +132,15 @@ public class ItemStepsAdapter extends RecyclerView.Adapter<ItemStepsAdapter.Item
|
|||
}
|
||||
});
|
||||
|
||||
holder.imageView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (imageSelectionListener != null) {
|
||||
imageSelectionListener.onSelectImage(holder.getAdapterPosition()); // Notify the fragment
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
ScoreSpinnerAdapter scoreSpinnerAdapter = new ScoreSpinnerAdapter(context, dropdownOptions);
|
||||
holder.scoreTextview.setAdapter(scoreSpinnerAdapter);
|
||||
|
||||
|
@ -121,6 +168,7 @@ public class ItemStepsAdapter extends RecyclerView.Adapter<ItemStepsAdapter.Item
|
|||
TextView tvItemName, tvPercentage;
|
||||
AutoCompleteTextView scoreTextview;
|
||||
EditText et_remarks;
|
||||
ImageView imageView;
|
||||
|
||||
public ItemViewHolder(@NonNull View itemView) {
|
||||
super(itemView);
|
||||
|
@ -128,7 +176,55 @@ public class ItemStepsAdapter extends RecyclerView.Adapter<ItemStepsAdapter.Item
|
|||
scoreTextview = itemView.findViewById(R.id.score_textview);
|
||||
tvPercentage = itemView.findViewById(R.id.tv_percentage);
|
||||
et_remarks = itemView.findViewById(R.id.et_remarks);
|
||||
imageView = itemView.findViewById(R.id.img1);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void uriToByteArrayAsync(
|
||||
Context context,
|
||||
Uri uri,
|
||||
int targetSizeInKB,
|
||||
Consumer<byte[]> onSuccess,
|
||||
Consumer<Exception> onError
|
||||
) {
|
||||
new Thread(() -> {
|
||||
try {
|
||||
int targetSizeInBytes = targetSizeInKB * 1024;
|
||||
|
||||
// Load the image as a Bitmap without scaling
|
||||
Bitmap bitmap;
|
||||
try (InputStream inputStream = context.getContentResolver().openInputStream(uri)) {
|
||||
bitmap = BitmapFactory.decodeStream(inputStream);
|
||||
}
|
||||
|
||||
if (bitmap == null) {
|
||||
throw new IOException("Failed to decode image from URI.");
|
||||
}
|
||||
|
||||
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
||||
int minQuality = 10;
|
||||
int maxQuality = 100;
|
||||
int quality = maxQuality;
|
||||
|
||||
// Binary search for the best quality that meets the target size
|
||||
while (minQuality <= maxQuality) {
|
||||
byteArrayOutputStream.reset();
|
||||
bitmap.compress(Bitmap.CompressFormat.JPEG, quality, byteArrayOutputStream);
|
||||
|
||||
int byteSize = byteArrayOutputStream.size();
|
||||
if (byteSize > targetSizeInBytes) {
|
||||
maxQuality = quality - 1;
|
||||
} else {
|
||||
minQuality = quality + 1;
|
||||
}
|
||||
quality = (minQuality + maxQuality) / 2;
|
||||
}
|
||||
|
||||
onSuccess.accept(byteArrayOutputStream.toByteArray());
|
||||
} catch (IOException e) {
|
||||
onError.accept(e);
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package com.utopiaindustries.qualitycontrol.apiservice;
|
||||
|
||||
import com.utopiaindustries.qualitycontrol.models.QualityControlResponse;
|
||||
import com.utopiaindustries.qualitycontrol.models.QualitySaveResponse;
|
||||
import com.utopiaindustries.qualitycontrol.viewmodels.QualityControl;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -21,8 +23,8 @@ public interface ApiService {
|
|||
Call<QualityControlResponse> isUserAuthenticated();
|
||||
|
||||
|
||||
/*@POST("rest/application/save-truck-load")
|
||||
Call<PickResponse> pickTruckLoad(
|
||||
@Body PickupRequest request
|
||||
);*/
|
||||
@POST("rest/uic/quality-control/save-quality-control")
|
||||
Call<QualitySaveResponse> saveQualityControlReport(
|
||||
@Body QualityControl request
|
||||
);
|
||||
}
|
||||
|
|
|
@ -39,6 +39,8 @@ import com.utopiaindustries.qualitycontrol.R;
|
|||
import com.utopiaindustries.qualitycontrol.activities.HomeActivity;
|
||||
import com.utopiaindustries.qualitycontrol.adapters.ImageAdapter;
|
||||
import com.utopiaindustries.qualitycontrol.adapters.ItemStepsAdapter;
|
||||
import com.utopiaindustries.qualitycontrol.helper.Helper;
|
||||
import com.utopiaindustries.qualitycontrol.utils.ImageSelectionListener;
|
||||
import com.utopiaindustries.qualitycontrol.utils.QualityControlViewModel;
|
||||
import com.utopiaindustries.qualitycontrol.viewmodels.ItemModel;
|
||||
|
||||
|
@ -48,6 +50,7 @@ import java.io.IOException;
|
|||
import java.io.InputStream;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
@ -57,7 +60,8 @@ import pub.devrel.easypermissions.AfterPermissionGranted;
|
|||
import pub.devrel.easypermissions.AppSettingsDialog;
|
||||
import pub.devrel.easypermissions.EasyPermissions;
|
||||
|
||||
public class CheckingFragment extends Fragment implements EasyPermissions.PermissionCallbacks{
|
||||
public class CheckingFragment extends Fragment implements EasyPermissions.PermissionCallbacks,
|
||||
ImageSelectionListener {
|
||||
|
||||
RecyclerView recyclerView, imageRecyclerView;
|
||||
ImageAdapter imageAdapter;
|
||||
|
@ -70,13 +74,16 @@ public class CheckingFragment extends Fragment implements EasyPermissions.Permis
|
|||
ImageButton imagePicker, deleteImage;
|
||||
EditText etPercentage, etRemarks;
|
||||
QualityControlViewModel viewModel;
|
||||
List<ItemModel> itemModelList = new ArrayList<>();
|
||||
ItemStepsAdapter adapter;
|
||||
private int selectedPosition = -1;
|
||||
|
||||
// Activity Result Launcher for Gallery
|
||||
private final ActivityResultLauncher<Intent> imagePickerLauncher =
|
||||
registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), result -> {
|
||||
if (result.getResultCode() == requireActivity().RESULT_OK && result.getData() != null) {
|
||||
Uri selectedImage = result.getData().getData();
|
||||
if (selectedImage != null) {
|
||||
if (selectedPosition != -1 && selectedImage != null) {
|
||||
//imageView.setImageURI(selectedImage);
|
||||
Log.e("Selected-Image: ", "" + selectedImage);
|
||||
|
||||
|
@ -87,9 +94,11 @@ public class CheckingFragment extends Fragment implements EasyPermissions.Permis
|
|||
compressedImage -> {
|
||||
// Handle the compressed image here, e.g., display it
|
||||
requireActivity().runOnUiThread(() -> {
|
||||
//store.getReport().getItems().get(0).getCheckPoints().get(requestCode).addImageList(compressedImage);
|
||||
imageList.add(compressedImage);
|
||||
imageAdapter.notifyDataSetChanged();
|
||||
itemModelList.get(selectedPosition).setImageUri(compressedImage);
|
||||
List<byte[]> tempList = new ArrayList<>();
|
||||
tempList.add(compressedImage);
|
||||
itemModelList.get(selectedPosition).setImageArrayList(tempList);
|
||||
adapter.notifyItemChanged(selectedPosition);
|
||||
});
|
||||
},
|
||||
error -> {
|
||||
|
@ -115,9 +124,11 @@ public class CheckingFragment extends Fragment implements EasyPermissions.Permis
|
|||
compressedImage -> {
|
||||
// Handle the compressed image here, e.g., display it
|
||||
requireActivity().runOnUiThread(() -> {
|
||||
//store.getReport().getItems().get(0).getCheckPoints().get(requestCode).addImageList(compressedImage);
|
||||
imageList.add(compressedImage);
|
||||
imageAdapter.notifyDataSetChanged();
|
||||
itemModelList.get(selectedPosition).setImageUri(compressedImage);
|
||||
List<byte[]> tempList = new ArrayList<>();
|
||||
tempList.add(compressedImage);
|
||||
itemModelList.get(selectedPosition).setImageArrayList(tempList);
|
||||
adapter.notifyItemChanged(selectedPosition);
|
||||
});
|
||||
},
|
||||
error -> {
|
||||
|
@ -156,14 +167,35 @@ public class CheckingFragment extends Fragment implements EasyPermissions.Permis
|
|||
itemList.add(new Item("Safety", 0));*/
|
||||
|
||||
//New Implemented------------------
|
||||
List<ItemModel> itemModelList = new ArrayList<>();
|
||||
for (int i = 1; i < 7; i++) {
|
||||
itemModelList.add(new ItemModel(3,i,0,"0","",0));
|
||||
}
|
||||
if (Helper.getArrayList("ListChecking", getActivity()) != null) {
|
||||
itemModelList.clear();
|
||||
itemModelList.addAll(Helper.getArrayList("ListChecking", getActivity()));
|
||||
Log.e("itemModelList-size: ",""+itemModelList.size());
|
||||
|
||||
ItemStepsAdapter adapter = new ItemStepsAdapter(getActivity(), itemModelList);
|
||||
if (itemModelList != null) {
|
||||
adapter = new ItemStepsAdapter(getActivity(), itemModelList,this);
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
|
||||
recyclerView.setAdapter(adapter);
|
||||
}
|
||||
else {
|
||||
for (int i = 1; i < 7; i++) {
|
||||
itemModelList.add(new ItemModel(3,i,0,"0","",0,null, null));
|
||||
}
|
||||
|
||||
adapter = new ItemStepsAdapter(getActivity(), itemModelList,this);
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
|
||||
recyclerView.setAdapter(adapter);
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (int i = 1; i < 7; i++) {
|
||||
itemModelList.add(new ItemModel(3,i,0,"0","",0, null, null));
|
||||
}
|
||||
adapter = new ItemStepsAdapter(getActivity(), itemModelList, this);
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
|
||||
recyclerView.setAdapter(adapter);
|
||||
}
|
||||
|
||||
//----------------------------------
|
||||
|
||||
imageAdapter = new ImageAdapter(imageList, getActivity());
|
||||
|
@ -180,11 +212,15 @@ public class CheckingFragment extends Fragment implements EasyPermissions.Permis
|
|||
", SpinnerSelection: " + item.getSelectedOption() +
|
||||
", Rating: " + item.getRating() +
|
||||
", Percentage: " + item.getPercentage() +
|
||||
", Remarks: " + item.getRemarks());
|
||||
", Remarks: " + item.getRemarks() +
|
||||
", ImageList: " + item.getImageArrayList());
|
||||
}
|
||||
|
||||
Helper.saveArrayList(itemModelList, "ListChecking",getActivity());
|
||||
viewModel.appendToQualityControlItemList(itemModelList);
|
||||
|
||||
List<ItemModel> updatedItemListP = new ArrayList<>(Helper.getArrayList("ListChecking", getActivity()));
|
||||
|
||||
/* if (etRemarks.getText().toString().isEmpty()) {
|
||||
Toast.makeText(getActivity(), "Please enter remarks", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
@ -447,4 +483,21 @@ public class CheckingFragment extends Fragment implements EasyPermissions.Permis
|
|||
EasyPermissions.requestPermissions(this, getString(R.string.rationale_camera), GALLERY_REQUEST, perms);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSelectImage(int position) {
|
||||
selectedPosition = position;
|
||||
|
||||
// Show dialog to choose between camera and gallery
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(requireContext());
|
||||
builder.setTitle("Select Image")
|
||||
.setItems(new String[]{"Camera", "Gallery"}, (dialog, which) -> {
|
||||
if (which == 0) { // Camera
|
||||
openCamera();
|
||||
} else { // Gallery
|
||||
openGallery();
|
||||
}
|
||||
})
|
||||
.show();
|
||||
}
|
||||
}
|
|
@ -42,6 +42,7 @@ import com.utopiaindustries.qualitycontrol.adapters.ItemStepsAdapter;
|
|||
import com.utopiaindustries.qualitycontrol.helper.Helper;
|
||||
import com.utopiaindustries.qualitycontrol.models.QualityControlProcessStep;
|
||||
import com.utopiaindustries.qualitycontrol.models.QualityControlResponse;
|
||||
import com.utopiaindustries.qualitycontrol.utils.ImageSelectionListener;
|
||||
import com.utopiaindustries.qualitycontrol.utils.QualityControlViewModel;
|
||||
import com.utopiaindustries.qualitycontrol.viewmodels.ItemModel;
|
||||
|
||||
|
@ -51,6 +52,7 @@ import java.io.IOException;
|
|||
import java.io.InputStream;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
@ -60,7 +62,8 @@ import pub.devrel.easypermissions.AfterPermissionGranted;
|
|||
import pub.devrel.easypermissions.AppSettingsDialog;
|
||||
import pub.devrel.easypermissions.EasyPermissions;
|
||||
|
||||
public class CuttingFragment extends Fragment implements EasyPermissions.PermissionCallbacks {
|
||||
public class CuttingFragment extends Fragment implements EasyPermissions.PermissionCallbacks,
|
||||
ImageSelectionListener {
|
||||
|
||||
RecyclerView recyclerView, imageRecyclerView;
|
||||
ImageAdapter imageAdapter;
|
||||
|
@ -74,13 +77,16 @@ public class CuttingFragment extends Fragment implements EasyPermissions.Permiss
|
|||
QualityControlResponse qualityControlResponse;
|
||||
QualityControlViewModel viewModel;
|
||||
EditText etPercentage, etRemarks;
|
||||
List<ItemModel> itemModelList = new ArrayList<>();
|
||||
ItemStepsAdapter adapter;
|
||||
private int selectedPosition = -1;
|
||||
|
||||
// Activity Result Launcher for Gallery
|
||||
private final ActivityResultLauncher<Intent> imagePickerLauncher =
|
||||
registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), result -> {
|
||||
if (result.getResultCode() == requireActivity().RESULT_OK && result.getData() != null) {
|
||||
Uri selectedImage = result.getData().getData();
|
||||
if (selectedImage != null) {
|
||||
if (selectedPosition != -1 && selectedImage != null) {
|
||||
//imageView.setImageURI(selectedImage);
|
||||
Log.e("Selected-Image: ", "" + selectedImage);
|
||||
|
||||
|
@ -91,9 +97,11 @@ public class CuttingFragment extends Fragment implements EasyPermissions.Permiss
|
|||
compressedImage -> {
|
||||
// Handle the compressed image here, e.g., display it
|
||||
requireActivity().runOnUiThread(() -> {
|
||||
//store.getReport().getItems().get(0).getCheckPoints().get(requestCode).addImageList(compressedImage);
|
||||
imageList.add(compressedImage);
|
||||
imageAdapter.notifyDataSetChanged();
|
||||
itemModelList.get(selectedPosition).setImageUri(compressedImage);
|
||||
List<byte[]> tempList = new ArrayList<>();
|
||||
tempList.add(compressedImage);
|
||||
itemModelList.get(selectedPosition).setImageArrayList(tempList);
|
||||
adapter.notifyItemChanged(selectedPosition);
|
||||
});
|
||||
},
|
||||
error -> {
|
||||
|
@ -119,9 +127,11 @@ public class CuttingFragment extends Fragment implements EasyPermissions.Permiss
|
|||
compressedImage -> {
|
||||
// Handle the compressed image here, e.g., display it
|
||||
requireActivity().runOnUiThread(() -> {
|
||||
//store.getReport().getItems().get(0).getCheckPoints().get(requestCode).addImageList(compressedImage);
|
||||
imageList.add(compressedImage);
|
||||
imageAdapter.notifyDataSetChanged();
|
||||
itemModelList.get(selectedPosition).setImageUri(compressedImage);
|
||||
List<byte[]> tempList = new ArrayList<>();
|
||||
tempList.add(compressedImage);
|
||||
itemModelList.get(selectedPosition).setImageArrayList(tempList);
|
||||
adapter.notifyItemChanged(selectedPosition);
|
||||
});
|
||||
},
|
||||
error -> {
|
||||
|
@ -164,14 +174,35 @@ public class CuttingFragment extends Fragment implements EasyPermissions.Permiss
|
|||
recyclerView.setAdapter(adapter);*/
|
||||
|
||||
//New Implemented------------------
|
||||
List<ItemModel> itemModelList = new ArrayList<>();
|
||||
for (int i = 1; i < 7; i++) {
|
||||
itemModelList.add(new ItemModel(1,i,0,"0","",0));
|
||||
}
|
||||
|
||||
ItemStepsAdapter adapter = new ItemStepsAdapter(getActivity(), itemModelList);
|
||||
Log.e("Check-Cut: ",""+Helper.getArrayList("ListCutting", getActivity()));
|
||||
if (Helper.getArrayList("ListCutting", getActivity()) != null) {
|
||||
itemModelList.clear();
|
||||
itemModelList.addAll(Helper.getArrayList("ListCutting", getActivity()));
|
||||
Log.e("itemModelList-size: ", "" + itemModelList.size());
|
||||
|
||||
if (itemModelList != null) {
|
||||
adapter = new ItemStepsAdapter(getActivity(), itemModelList, this);
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
|
||||
recyclerView.setAdapter(adapter);
|
||||
} else {
|
||||
for (int i = 1; i < 7; i++) {
|
||||
itemModelList.add(new ItemModel(1, i, 0, "0", "", 0, null,null));
|
||||
}
|
||||
|
||||
adapter = new ItemStepsAdapter(getActivity(), itemModelList, this);
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
|
||||
recyclerView.setAdapter(adapter);
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (int i = 1; i < 7; i++) {
|
||||
itemModelList.add(new ItemModel(1,i,0,"0","",0, null, null));
|
||||
}
|
||||
adapter = new ItemStepsAdapter(getActivity(), itemModelList, this);
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
|
||||
recyclerView.setAdapter(adapter);
|
||||
}
|
||||
//----------------------------------
|
||||
|
||||
imageAdapter = new ImageAdapter(imageList, getActivity());
|
||||
|
@ -188,13 +219,13 @@ public class CuttingFragment extends Fragment implements EasyPermissions.Permiss
|
|||
", SpinnerSelection: " + item.getSelectedOption() +
|
||||
", Rating: " + item.getRating() +
|
||||
", Percentage: " + item.getPercentage() +
|
||||
", Remarks: " + item.getRemarks());
|
||||
", Remarks: " + item.getRemarks() +
|
||||
", ImageList: " + item.getImageArrayList());
|
||||
}
|
||||
|
||||
Helper.saveArrayList(itemModelList, "ListCutting", getActivity());
|
||||
viewModel.appendToQualityControlItemList(itemModelList);
|
||||
|
||||
|
||||
|
||||
/*Log.e("Cutting: ","----------------");
|
||||
Log.e("Sort: ",""+sharedViewModel.getCuttingSort());
|
||||
Log.e("Set-Order: ",""+sharedViewModel.getCuttingSetInOrder());
|
||||
|
@ -289,11 +320,11 @@ public class CuttingFragment extends Fragment implements EasyPermissions.Permiss
|
|||
imageRecyclerView = view.findViewById(R.id.imageRecyclerView);
|
||||
imageRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity(), LinearLayoutManager.HORIZONTAL, false));
|
||||
|
||||
qualityControlResponse = Helper.getPreferenceObjectJson(getActivity().getApplicationContext(), "qcResponse");
|
||||
/*qualityControlResponse = Helper.getPreferenceObjectJson(getActivity().getApplicationContext(), "qcResponse");
|
||||
|
||||
if (!qualityControlResponse.getQualityControlProcessSteps().isEmpty()) {
|
||||
qualityControlProcessStepList.addAll(qualityControlResponse.getQualityControlProcessSteps());
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -514,4 +545,22 @@ public class CuttingFragment extends Fragment implements EasyPermissions.Permiss
|
|||
new AppSettingsDialog.Builder(this).build().show();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSelectImage(int position) {
|
||||
selectedPosition = position;
|
||||
|
||||
// Show dialog to choose between camera and gallery
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(requireContext());
|
||||
builder.setTitle("Select Image")
|
||||
.setItems(new String[]{"Camera", "Gallery"}, (dialog, which) -> {
|
||||
if (which == 0) {
|
||||
openCamera();
|
||||
} else {
|
||||
openGallery();
|
||||
}
|
||||
})
|
||||
.show();
|
||||
|
||||
}
|
||||
}
|
|
@ -29,6 +29,7 @@ import com.utopiaindustries.qualitycontrol.adapters.FloorAdapter;
|
|||
import com.utopiaindustries.qualitycontrol.adapters.LocationSitesAdapter;
|
||||
import com.utopiaindustries.qualitycontrol.adapters.UnitAdapter;
|
||||
import com.utopiaindustries.qualitycontrol.helper.Helper;
|
||||
import com.utopiaindustries.qualitycontrol.helper.Preference;
|
||||
import com.utopiaindustries.qualitycontrol.models.Department;
|
||||
import com.utopiaindustries.qualitycontrol.models.LocationFloor;
|
||||
import com.utopiaindustries.qualitycontrol.models.LocationSite;
|
||||
|
@ -48,7 +49,7 @@ import java.util.stream.Collectors;
|
|||
|
||||
public class HomeFragment extends Fragment implements DepartmentItemAdapter.OnItemClickListener{
|
||||
|
||||
AutoCompleteTextView locationSiteTextview, departmentTextView, unitTextview, floorTextview;
|
||||
AutoCompleteTextView locationSiteTextview, unitTextview, floorTextview;
|
||||
TextView txtCurrentDate;
|
||||
LoginViewModel loginViewModel;
|
||||
Button nextButton;
|
||||
|
@ -57,15 +58,18 @@ public class HomeFragment extends Fragment implements DepartmentItemAdapter.OnIt
|
|||
UnitAdapter unitAdapter;
|
||||
FloorAdapter floorAdapter;
|
||||
|
||||
ArrayList<LocationUnit> locationUnitList = new ArrayList<>();
|
||||
ArrayList<LocationFloor> locationFloorList = new ArrayList<>();
|
||||
ArrayList<LocationSite> locationSiteList = new ArrayList<>();
|
||||
ArrayList<Department> departmentList = new ArrayList<>();
|
||||
ArrayList<QualityControlProcess> qualityControlProcessList = new ArrayList<>();
|
||||
ArrayList<LocationSite> locationSiteList = new ArrayList<>();
|
||||
|
||||
ArrayList<LocationUnit> locationUnitList = new ArrayList<>();
|
||||
ArrayList<LocationUnit> locationUnitListFiltered = new ArrayList<>();
|
||||
|
||||
ArrayList<LocationFloor> locationFloorList = new ArrayList<>();
|
||||
ArrayList<LocationFloor> locationFloorListFiltered = new ArrayList<>();
|
||||
|
||||
EditText searchEditText;
|
||||
RecyclerView recyclerView;
|
||||
List<Department> itemList, filteredList;
|
||||
List<Department> filteredList;
|
||||
private DepartmentItemAdapter departmentItemAdapter;
|
||||
QualityControlViewModel viewModel;
|
||||
|
||||
|
@ -74,8 +78,6 @@ public class HomeFragment extends Fragment implements DepartmentItemAdapter.OnIt
|
|||
|
||||
View view = inflater.inflate(R.layout.fragment_home, container, false);
|
||||
|
||||
//Log.e("onCreateView: ","====================");
|
||||
|
||||
initializeLayout(view);
|
||||
|
||||
String date = new SimpleDateFormat("EEEE, MMM d, yyyy", Locale.getDefault()).format(new Date());
|
||||
|
@ -85,91 +87,66 @@ public class HomeFragment extends Fragment implements DepartmentItemAdapter.OnIt
|
|||
@Override
|
||||
public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
|
||||
LocationSite clickedItem = locationSiteList.get(position);
|
||||
//Log.e("Item-----------: ", clickedItem.getTitle());
|
||||
unitTextview.setText("Select Unit");
|
||||
//floorTextview.clearListSelection();
|
||||
floorTextview.setText("Select Floor");
|
||||
|
||||
viewModel.setLocation(String.valueOf(clickedItem.getId()));
|
||||
Preference.setMyStringPref(Helper.project_file,Helper.locationSiteId,getActivity(),String.valueOf(clickedItem.getId()));
|
||||
Preference.setMyStringPref(Helper.project_file,Helper.locationSiteName,getActivity(),String.valueOf(clickedItem.getTitle()));
|
||||
|
||||
if (!locationUnitList.isEmpty()) {
|
||||
List<LocationUnit> filteredUnitItems = locationUnitList.stream()
|
||||
.filter(item -> Objects.equals(item.getSiteId(), clickedItem.getId()))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
//Log.e("Filtered-size: ",""+filteredUnitItems.size());
|
||||
|
||||
locationUnitList.clear();
|
||||
locationUnitList.addAll(filteredUnitItems);
|
||||
locationUnitListFiltered.clear();
|
||||
locationUnitListFiltered.addAll(filteredUnitItems);
|
||||
unitAdapter = new UnitAdapter(getActivity(), filteredUnitItems);
|
||||
unitTextview.setAdapter(unitAdapter);
|
||||
|
||||
// Print filtered items
|
||||
for (LocationUnit item : filteredUnitItems) {
|
||||
//Log.e("Unit-Title: ", item.getTitle());
|
||||
}
|
||||
}
|
||||
|
||||
/*if (!locationFloorList.isEmpty()) {
|
||||
List<LocationFloor> filteredItems = locationFloorList.stream()
|
||||
.filter(item -> Objects.equals(item.getSiteId(), clickedItem.getId()))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
Log.e("Filtered-size: ",""+filteredItems.size());
|
||||
|
||||
floorAdapter = new FloorAdapter(getActivity(), filteredItems);
|
||||
floorTextview.setAdapter(floorAdapter);
|
||||
|
||||
// Print filtered items
|
||||
for (LocationFloor item : filteredItems) {
|
||||
Log.e("Floor-Title: ", item.getTitle());
|
||||
}
|
||||
/*for (LocationUnit item : filteredUnitItems) {
|
||||
Log.e("Unit: ", "ID: " + item.getId() + "Title: " + item.getTitle());
|
||||
}*/
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
unitTextview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
LocationUnit clickedItem = locationUnitList.get(position);
|
||||
//Log.e("Item--unit-----: ", clickedItem.getTitle());
|
||||
LocationUnit clickedItem = locationUnitListFiltered.get(position);
|
||||
|
||||
viewModel.setUnit(String.valueOf(clickedItem.getId()));
|
||||
int targetSiteId = Integer.parseInt(viewModel.getLocation());
|
||||
Log.e("SiteId: ",""+targetSiteId);
|
||||
Log.e("UnitId: ",""+clickedItem.getId());
|
||||
Log.e("location-floor-list-size: ",""+locationFloorList.size());
|
||||
Preference.setMyStringPref(Helper.project_file,Helper.unitId,getActivity(),String.valueOf(clickedItem.getId()));
|
||||
Preference.setMyStringPref(Helper.project_file,Helper.unitName,getActivity(),String.valueOf(clickedItem.getTitle()));
|
||||
int targetSiteId = Integer.parseInt(Preference.getMyStringPref(Helper.project_file,Helper.locationSiteId,getActivity()));
|
||||
//Log.e("SiteId: ",""+targetSiteId);
|
||||
//Log.e("UnitId: ",""+clickedItem.getId());
|
||||
|
||||
if (!locationFloorList.isEmpty()) {
|
||||
List<LocationFloor> filteredList = locationFloorList.stream()
|
||||
List<LocationFloor> filteredFloorsList = locationFloorList.stream()
|
||||
.filter(floor -> floor.getSiteId() == targetSiteId && Objects.equals(floor.getUnitId(), clickedItem.getId()))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
floorAdapter = new FloorAdapter(getActivity(), filteredList);
|
||||
locationFloorListFiltered.clear();
|
||||
locationFloorListFiltered.addAll(filteredFloorsList);
|
||||
floorAdapter = new FloorAdapter(getActivity(), filteredFloorsList);
|
||||
floorTextview.setAdapter(floorAdapter);
|
||||
|
||||
// Print filtered list
|
||||
for (LocationFloor floor : filteredList) {
|
||||
Log.e("floor: ", floor.getTitle());
|
||||
}
|
||||
/*for (LocationFloor floor : filteredFloorsList) {
|
||||
Log.e("floor: ", "Id: " + floor.getId() + "Title: " + floor.getTitle());
|
||||
}*/
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/* departmentTextView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
|
||||
String item = adapterView.getItemAtPosition(position).toString();
|
||||
Log.e("Item-----------: ", "" + item);
|
||||
|
||||
|
||||
}
|
||||
});*/
|
||||
|
||||
floorTextview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
|
||||
LocationFloor clickedItem = locationFloorList.get(position);
|
||||
Log.e("Item-----------: ", clickedItem.getTitle());
|
||||
LocationFloor clickedItem = locationFloorListFiltered.get(position);
|
||||
viewModel.setFloor(String.valueOf(clickedItem.getId()));
|
||||
|
||||
Preference.setMyStringPref(Helper.project_file,Helper.floorId,getActivity(),String.valueOf(clickedItem.getId()));
|
||||
Preference.setMyStringPref(Helper.project_file,Helper.floorName,getActivity(),String.valueOf(clickedItem.getTitle()));
|
||||
|
||||
}
|
||||
});
|
||||
|
@ -177,8 +154,20 @@ public class HomeFragment extends Fragment implements DepartmentItemAdapter.OnIt
|
|||
nextButton.setOnClickListener(v -> {
|
||||
if (getActivity() instanceof HomeActivity) {
|
||||
viewModel.setFromViewModel(true);
|
||||
String siteID = Preference.getMyStringPref(Helper.project_file,Helper.locationSiteId,getActivity());
|
||||
String unitId = Preference.getMyStringPref(Helper.project_file,Helper.unitId,getActivity());
|
||||
String departId = Preference.getMyStringPref(Helper.project_file,Helper.departmentId,getActivity());
|
||||
String floorId = Preference.getMyStringPref(Helper.project_file,Helper.floorId,getActivity());
|
||||
Log.e("AdapterData", "siteID: " + siteID +
|
||||
", unitId: " + unitId +
|
||||
", departId: " + departId +
|
||||
", floorId: " + floorId );
|
||||
|
||||
if (isValidate(departId,siteID,unitId,floorId)) {
|
||||
((HomeActivity) getActivity()).navigateToFragment(new CuttingFragment(), true);
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
searchEditText.addTextChangedListener(new TextWatcher() {
|
||||
|
@ -191,18 +180,14 @@ public class HomeFragment extends Fragment implements DepartmentItemAdapter.OnIt
|
|||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
filterList(s.toString());
|
||||
|
||||
|
||||
if (s.length() > 0) {
|
||||
Log.e("filterList","0.1");
|
||||
if (viewModel.isFromViewModel()) {
|
||||
recyclerView.setVisibility(View.GONE);
|
||||
}
|
||||
else {
|
||||
recyclerView.setVisibility(View.VISIBLE); // Show the list when typing
|
||||
}
|
||||
|
||||
} else {
|
||||
Log.e("filterList","0.21");
|
||||
recyclerView.setVisibility(View.GONE); // Hide when no text is entered
|
||||
}
|
||||
}
|
||||
|
@ -227,7 +212,7 @@ public class HomeFragment extends Fragment implements DepartmentItemAdapter.OnIt
|
|||
|
||||
txtCurrentDate = view.findViewById(R.id.txt_current_date);
|
||||
locationSiteTextview = view.findViewById(R.id.location_textview);
|
||||
//departmentTextView = view.findViewById(R.id.department_textview);
|
||||
|
||||
unitTextview = view.findViewById(R.id.unit_textview);
|
||||
floorTextview = view.findViewById(R.id.floor_textview);
|
||||
nextButton = view.findViewById(R.id.btn_next);
|
||||
|
@ -255,14 +240,18 @@ public class HomeFragment extends Fragment implements DepartmentItemAdapter.OnIt
|
|||
if (qcResponse != null) {
|
||||
|
||||
Helper.setPreferenceObject(getActivity().getApplicationContext(), qcResponse, "qcResponse");
|
||||
|
||||
if (!Preference.getMyStringPref(Helper.project_file, Helper.departmentName, getActivity()).equalsIgnoreCase("default")) {
|
||||
searchEditText.setText(Preference.getMyStringPref(Helper.project_file, Helper.departmentName, getActivity()));
|
||||
locationSiteTextview.setText(Preference.getMyStringPref(Helper.project_file, Helper.locationSiteName,getActivity()));
|
||||
unitTextview.setText(Preference.getMyStringPref(Helper.project_file, Helper.unitName, getActivity()));
|
||||
floorTextview.setText(Preference.getMyStringPref(Helper.project_file, Helper.floorName, getActivity()));
|
||||
}
|
||||
|
||||
if (!qcResponse.getLocationSites().isEmpty()) {
|
||||
|
||||
viewModel.setLocationSiteList(qcResponse.getLocationSites());
|
||||
|
||||
locationSiteList.addAll(qcResponse.getLocationSites());
|
||||
Log.e("locationSiteList-size: ",""+locationSiteList.size());
|
||||
|
||||
locationSitesAdapter = new LocationSitesAdapter(getActivity(), locationSiteList);
|
||||
locationSiteTextview.setAdapter(locationSitesAdapter);
|
||||
|
@ -272,10 +261,7 @@ public class HomeFragment extends Fragment implements DepartmentItemAdapter.OnIt
|
|||
if (!qcResponse.getDepartments().isEmpty()) {
|
||||
|
||||
viewModel.setDepartmentList(qcResponse.getDepartments());
|
||||
|
||||
departmentList.addAll(qcResponse.getDepartments());
|
||||
Log.e("departmentList-size: ",""+departmentList.size());
|
||||
|
||||
filteredList = new ArrayList<>(departmentList);
|
||||
|
||||
// Set up RecyclerView
|
||||
|
@ -285,33 +271,23 @@ public class HomeFragment extends Fragment implements DepartmentItemAdapter.OnIt
|
|||
}
|
||||
|
||||
if (!qcResponse.getLocationFloors().isEmpty()) {
|
||||
|
||||
viewModel.setFloorList(qcResponse.getLocationFloors());
|
||||
|
||||
locationFloorList.addAll(qcResponse.getLocationFloors());
|
||||
Log.e("locationFloorList-size: ",""+locationFloorList.size());
|
||||
}
|
||||
|
||||
if (!qcResponse.getLocationUnits().isEmpty()) {
|
||||
|
||||
viewModel.setUnitList(qcResponse.getLocationUnits());
|
||||
|
||||
locationUnitList.addAll(qcResponse.getLocationUnits());
|
||||
Log.e("locationUnitList-size: ",""+locationUnitList.size());
|
||||
}
|
||||
|
||||
|
||||
|
||||
} else {
|
||||
Toast.makeText(getActivity(), "Login Failed", Toast.LENGTH_SHORT).show();
|
||||
Toast.makeText(getActivity(), "Fetching Records Failed", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
|
||||
if (viewModel.getLocationSiteList().isEmpty()) {
|
||||
/*if (viewModel.getLocationSiteList().isEmpty()) {
|
||||
loginViewModel.getQualityControlData();
|
||||
}
|
||||
else {
|
||||
|
||||
//location list
|
||||
locationSiteList.addAll(viewModel.getLocationSiteList());
|
||||
Log.e("locationSiteList-size: ",""+locationSiteList.size());
|
||||
|
@ -340,8 +316,20 @@ public class HomeFragment extends Fragment implements DepartmentItemAdapter.OnIt
|
|||
|
||||
recyclerView.setVisibility(View.GONE);
|
||||
|
||||
}*/
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
|
||||
Log.e("onResume: ","HomeFragment");
|
||||
departmentList.clear();
|
||||
locationSiteList.clear();
|
||||
locationUnitList.clear();
|
||||
locationFloorList.clear();
|
||||
loginViewModel.getQualityControlData();
|
||||
}
|
||||
|
||||
public void showProgressDialog() {
|
||||
|
@ -359,16 +347,14 @@ public class HomeFragment extends Fragment implements DepartmentItemAdapter.OnIt
|
|||
}
|
||||
|
||||
private void filterList(String query) {
|
||||
Log.e("filterList","1");
|
||||
if (filteredList != null) {
|
||||
filteredList.clear();
|
||||
if (query.isEmpty()) {
|
||||
// Hide the RecyclerView when there's no query
|
||||
recyclerView.setVisibility(View.GONE);
|
||||
Log.e("filterList","2");
|
||||
} else {
|
||||
// Show RecyclerView when there's a query
|
||||
recyclerView.setVisibility(View.VISIBLE);
|
||||
Log.e("filterList","3");
|
||||
|
||||
for (Department item : departmentList) {
|
||||
if (item.getTitle().toLowerCase().contains(query.toLowerCase())) {
|
||||
|
@ -379,9 +365,44 @@ public class HomeFragment extends Fragment implements DepartmentItemAdapter.OnIt
|
|||
departmentItemAdapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onItemClick(Department item) {
|
||||
Toast.makeText(getActivity(), "Selected: " + item.getTitle(), Toast.LENGTH_SHORT).show();
|
||||
//Toast.makeText(getActivity(), "Selected: " + item.getTitle(), Toast.LENGTH_SHORT).show();
|
||||
viewModel.setDepartmentId(item.getId());
|
||||
Preference.setMyStringPref(Helper.project_file,Helper.departmentId,getActivity(),String.valueOf(item.getId()));
|
||||
Preference.setMyStringPref(Helper.project_file,Helper.departmentName,getActivity(),String.valueOf(item.getTitle()));
|
||||
}
|
||||
|
||||
public boolean isValidate(String departId, String siteId, String unitId, String floorId) {
|
||||
boolean returnValue = true;
|
||||
String message = "";
|
||||
|
||||
if (departId.isEmpty() || departId.equalsIgnoreCase("default")) {
|
||||
message = "Please select Department";
|
||||
returnValue = false;
|
||||
}
|
||||
|
||||
if (siteId.isEmpty() || siteId.equalsIgnoreCase("default")) {
|
||||
message = "Please select Location Site";
|
||||
returnValue = false;
|
||||
}
|
||||
|
||||
if (unitId.isEmpty() || unitId.equalsIgnoreCase("default")) {
|
||||
message = "Please select Unit.";
|
||||
returnValue = false;
|
||||
}
|
||||
|
||||
if (floorId.isEmpty() || floorId.equalsIgnoreCase("default")) {
|
||||
message = "Please select Floor.";
|
||||
returnValue = false;
|
||||
}
|
||||
|
||||
if (!returnValue) {
|
||||
Toast.makeText(getActivity(),message,Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
}
|
|
@ -39,6 +39,8 @@ import com.utopiaindustries.qualitycontrol.R;
|
|||
import com.utopiaindustries.qualitycontrol.activities.HomeActivity;
|
||||
import com.utopiaindustries.qualitycontrol.adapters.ImageAdapter;
|
||||
import com.utopiaindustries.qualitycontrol.adapters.ItemStepsAdapter;
|
||||
import com.utopiaindustries.qualitycontrol.helper.Helper;
|
||||
import com.utopiaindustries.qualitycontrol.utils.ImageSelectionListener;
|
||||
import com.utopiaindustries.qualitycontrol.utils.QualityControlViewModel;
|
||||
import com.utopiaindustries.qualitycontrol.viewmodels.ItemModel;
|
||||
|
||||
|
@ -48,6 +50,7 @@ import java.io.IOException;
|
|||
import java.io.InputStream;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
@ -57,7 +60,8 @@ import pub.devrel.easypermissions.AfterPermissionGranted;
|
|||
import pub.devrel.easypermissions.AppSettingsDialog;
|
||||
import pub.devrel.easypermissions.EasyPermissions;
|
||||
|
||||
public class PackingFragment extends Fragment implements EasyPermissions.PermissionCallbacks{
|
||||
public class PackingFragment extends Fragment implements EasyPermissions.PermissionCallbacks,
|
||||
ImageSelectionListener {
|
||||
|
||||
RecyclerView recyclerView, imageRecyclerView;
|
||||
ImageAdapter imageAdapter;
|
||||
|
@ -71,13 +75,16 @@ public class PackingFragment extends Fragment implements EasyPermissions.Permiss
|
|||
ArrayList<byte[]> imageList = new ArrayList<>();
|
||||
EditText etPercentage, etRemarks;
|
||||
QualityControlViewModel viewModel;
|
||||
List<ItemModel> itemModelList = new ArrayList<>();
|
||||
ItemStepsAdapter adapter;
|
||||
private int selectedPosition = -1;
|
||||
|
||||
// Activity Result Launcher for Gallery
|
||||
private final ActivityResultLauncher<Intent> imagePickerLauncher =
|
||||
registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), result -> {
|
||||
if (result.getResultCode() == requireActivity().RESULT_OK && result.getData() != null) {
|
||||
Uri selectedImage = result.getData().getData();
|
||||
if (selectedImage != null) {
|
||||
if (selectedPosition != -1 && selectedImage != null) {
|
||||
//imageView.setImageURI(selectedImage);
|
||||
Log.e("Selected-Image: ", "" + selectedImage);
|
||||
|
||||
|
@ -88,9 +95,11 @@ public class PackingFragment extends Fragment implements EasyPermissions.Permiss
|
|||
compressedImage -> {
|
||||
// Handle the compressed image here, e.g., display it
|
||||
requireActivity().runOnUiThread(() -> {
|
||||
//store.getReport().getItems().get(0).getCheckPoints().get(requestCode).addImageList(compressedImage);
|
||||
imageList.add(compressedImage);
|
||||
imageAdapter.notifyDataSetChanged();
|
||||
itemModelList.get(selectedPosition).setImageUri(compressedImage);
|
||||
List<byte[]> tempList = new ArrayList<>();
|
||||
tempList.add(compressedImage);
|
||||
itemModelList.get(selectedPosition).setImageArrayList(tempList);
|
||||
adapter.notifyItemChanged(selectedPosition);
|
||||
});
|
||||
},
|
||||
error -> {
|
||||
|
@ -116,9 +125,11 @@ public class PackingFragment extends Fragment implements EasyPermissions.Permiss
|
|||
compressedImage -> {
|
||||
// Handle the compressed image here, e.g., display it
|
||||
requireActivity().runOnUiThread(() -> {
|
||||
//store.getReport().getItems().get(0).getCheckPoints().get(requestCode).addImageList(compressedImage);
|
||||
imageList.add(compressedImage);
|
||||
imageAdapter.notifyDataSetChanged();
|
||||
itemModelList.get(selectedPosition).setImageUri(compressedImage);
|
||||
List<byte[]> tempList = new ArrayList<>();
|
||||
tempList.add(compressedImage);
|
||||
itemModelList.get(selectedPosition).setImageArrayList(tempList);
|
||||
adapter.notifyItemChanged(selectedPosition);
|
||||
});
|
||||
},
|
||||
error -> {
|
||||
|
@ -157,14 +168,35 @@ public class PackingFragment extends Fragment implements EasyPermissions.Permiss
|
|||
itemList.add(new Item("Safety", 0));*/
|
||||
|
||||
//New Implemented------------------
|
||||
List<ItemModel> itemModelList = new ArrayList<>();
|
||||
for (int i = 1; i < 7; i++) {
|
||||
itemModelList.add(new ItemModel(4,i,0,"0","",0));
|
||||
}
|
||||
if (Helper.getArrayList("ListPacking", getActivity()) != null) {
|
||||
itemModelList.clear();
|
||||
itemModelList.addAll(Helper.getArrayList("ListPacking", getActivity()));
|
||||
Log.e("itemModelList-size: ",""+itemModelList.size());
|
||||
|
||||
ItemStepsAdapter adapter = new ItemStepsAdapter(getActivity(), itemModelList);
|
||||
if (itemModelList != null) {
|
||||
adapter = new ItemStepsAdapter(getActivity(), itemModelList,this);
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
|
||||
recyclerView.setAdapter(adapter);
|
||||
}
|
||||
else {
|
||||
for (int i = 1; i < 7; i++) {
|
||||
itemModelList.add(new ItemModel(4,i,0,"0","",0,null, null));
|
||||
}
|
||||
|
||||
adapter = new ItemStepsAdapter(getActivity(), itemModelList,this);
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
|
||||
recyclerView.setAdapter(adapter);
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (int i = 1; i < 7; i++) {
|
||||
itemModelList.add(new ItemModel(4,i,0,"0","",0, null, null));
|
||||
}
|
||||
adapter = new ItemStepsAdapter(getActivity(), itemModelList, this);
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
|
||||
recyclerView.setAdapter(adapter);
|
||||
}
|
||||
|
||||
//----------------------------------
|
||||
|
||||
imageAdapter = new ImageAdapter(imageList, getActivity());
|
||||
|
@ -194,11 +226,15 @@ public class PackingFragment extends Fragment implements EasyPermissions.Permiss
|
|||
", SpinnerSelection: " + item.getSelectedOption() +
|
||||
", Rating: " + item.getRating() +
|
||||
", Percentage: " + item.getPercentage() +
|
||||
", Remarks: " + item.getRemarks());
|
||||
", Remarks: " + item.getRemarks() +
|
||||
", ImageList: " + item.getImageArrayList());
|
||||
}
|
||||
|
||||
Helper.saveArrayList(itemModelList, "ListPacking",getActivity());
|
||||
viewModel.appendToQualityControlItemList(itemModelList);
|
||||
|
||||
List<ItemModel> updatedItemListP = new ArrayList<>(Helper.getArrayList("ListPacking", getActivity()));
|
||||
|
||||
/*if (etRemarks.getText().toString().isEmpty()) {
|
||||
Toast.makeText(getActivity(), "Please enter remarks", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
@ -448,4 +484,21 @@ public class PackingFragment extends Fragment implements EasyPermissions.Permiss
|
|||
EasyPermissions.requestPermissions(this, getString(R.string.rationale_camera), GALLERY_REQUEST, perms);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSelectImage(int position) {
|
||||
selectedPosition = position;
|
||||
|
||||
// Show dialog to choose between camera and gallery
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(requireContext());
|
||||
builder.setTitle("Select Image")
|
||||
.setItems(new String[]{"Camera", "Gallery"}, (dialog, which) -> {
|
||||
if (which == 0) { // Camera
|
||||
openCamera();
|
||||
} else { // Gallery
|
||||
openGallery();
|
||||
}
|
||||
})
|
||||
.show();
|
||||
}
|
||||
}
|
|
@ -39,7 +39,9 @@ import com.utopiaindustries.qualitycontrol.R;
|
|||
import com.utopiaindustries.qualitycontrol.activities.HomeActivity;
|
||||
import com.utopiaindustries.qualitycontrol.adapters.ImageAdapter;
|
||||
import com.utopiaindustries.qualitycontrol.adapters.ItemStepsAdapter;
|
||||
import com.utopiaindustries.qualitycontrol.helper.Helper;
|
||||
import com.utopiaindustries.qualitycontrol.models.Item;
|
||||
import com.utopiaindustries.qualitycontrol.utils.ImageSelectionListener;
|
||||
import com.utopiaindustries.qualitycontrol.utils.QualityControlViewModel;
|
||||
import com.utopiaindustries.qualitycontrol.viewmodels.ItemModel;
|
||||
|
||||
|
@ -49,6 +51,7 @@ import java.io.IOException;
|
|||
import java.io.InputStream;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
@ -58,7 +61,8 @@ import pub.devrel.easypermissions.AfterPermissionGranted;
|
|||
import pub.devrel.easypermissions.AppSettingsDialog;
|
||||
import pub.devrel.easypermissions.EasyPermissions;
|
||||
|
||||
public class StitchingFragment extends Fragment implements EasyPermissions.PermissionCallbacks{
|
||||
public class StitchingFragment extends Fragment implements EasyPermissions.PermissionCallbacks,
|
||||
ImageSelectionListener {
|
||||
|
||||
RecyclerView recyclerView, imageRecyclerView;
|
||||
ImageAdapter imageAdapter;
|
||||
|
@ -73,13 +77,16 @@ public class StitchingFragment extends Fragment implements EasyPermissions.Permi
|
|||
ArrayList<byte[]> imageList = new ArrayList<>();
|
||||
EditText etPercentage, etRemarks;
|
||||
QualityControlViewModel viewModel;
|
||||
List<ItemModel> itemModelList = new ArrayList<>();
|
||||
ItemStepsAdapter adapter;
|
||||
private int selectedPosition = -1;
|
||||
|
||||
// Activity Result Launcher for Gallery
|
||||
private final ActivityResultLauncher<Intent> imagePickerLauncher =
|
||||
registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), result -> {
|
||||
if (result.getResultCode() == requireActivity().RESULT_OK && result.getData() != null) {
|
||||
Uri selectedImage = result.getData().getData();
|
||||
if (selectedImage != null) {
|
||||
if (selectedPosition != -1 && selectedImage != null) {
|
||||
//imageView.setImageURI(selectedImage);
|
||||
Log.e("Selected-Image: ", "" + selectedImage);
|
||||
|
||||
|
@ -90,9 +97,11 @@ public class StitchingFragment extends Fragment implements EasyPermissions.Permi
|
|||
compressedImage -> {
|
||||
// Handle the compressed image here, e.g., display it
|
||||
requireActivity().runOnUiThread(() -> {
|
||||
//store.getReport().getItems().get(0).getCheckPoints().get(requestCode).addImageList(compressedImage);
|
||||
imageList.add(compressedImage);
|
||||
imageAdapter.notifyDataSetChanged();
|
||||
itemModelList.get(selectedPosition).setImageUri(compressedImage);
|
||||
List<byte[]> tempList = new ArrayList<>();
|
||||
tempList.add(compressedImage);
|
||||
itemModelList.get(selectedPosition).setImageArrayList(tempList);
|
||||
adapter.notifyItemChanged(selectedPosition);
|
||||
});
|
||||
},
|
||||
error -> {
|
||||
|
@ -118,9 +127,11 @@ public class StitchingFragment extends Fragment implements EasyPermissions.Permi
|
|||
compressedImage -> {
|
||||
// Handle the compressed image here, e.g., display it
|
||||
requireActivity().runOnUiThread(() -> {
|
||||
//store.getReport().getItems().get(0).getCheckPoints().get(requestCode).addImageList(compressedImage);
|
||||
imageList.add(compressedImage);
|
||||
imageAdapter.notifyDataSetChanged();
|
||||
itemModelList.get(selectedPosition).setImageUri(compressedImage);
|
||||
List<byte[]> tempList = new ArrayList<>();
|
||||
tempList.add(compressedImage);
|
||||
itemModelList.get(selectedPosition).setImageArrayList(tempList);
|
||||
adapter.notifyItemChanged(selectedPosition);
|
||||
});
|
||||
},
|
||||
error -> {
|
||||
|
@ -150,28 +161,41 @@ public class StitchingFragment extends Fragment implements EasyPermissions.Permi
|
|||
|
||||
initializeLayout(view);
|
||||
|
||||
List<Item> itemList = new ArrayList<>();
|
||||
itemList.add(new Item("Sort", 0));
|
||||
itemList.add(new Item("Set in Order", 0));
|
||||
itemList.add(new Item("Shine", 0));
|
||||
itemList.add(new Item("Standardize", 0));
|
||||
itemList.add(new Item("Sustain", 0));
|
||||
itemList.add(new Item("Safety", 0));
|
||||
|
||||
// Set up RecyclerView
|
||||
/*ItemStitchingAdapter adapter = new ItemStitchingAdapter(getActivity(), itemList, sharedViewModel);
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
|
||||
recyclerView.setAdapter(adapter);*/
|
||||
|
||||
//New Implemented------------------
|
||||
List<ItemModel> itemModelList = new ArrayList<>();
|
||||
for (int i = 1; i < 7; i++) {
|
||||
itemModelList.add(new ItemModel(2,i,0,"0","",0));
|
||||
}
|
||||
if (Helper.getArrayList("ListStitching", getActivity()) != null) {
|
||||
itemModelList.clear();
|
||||
itemModelList.addAll(Helper.getArrayList("ListStitching", getActivity()));
|
||||
Log.e("itemModelList-size: ",""+itemModelList.size());
|
||||
|
||||
ItemStepsAdapter adapter = new ItemStepsAdapter(getActivity(), itemModelList);
|
||||
if (itemModelList != null) {
|
||||
adapter = new ItemStepsAdapter(getActivity(), itemModelList, this);
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
|
||||
recyclerView.setAdapter(adapter);
|
||||
}
|
||||
else {
|
||||
for (int i = 1; i < 7; i++) {
|
||||
itemModelList.add(new ItemModel(2,i,0,"0","",0,null, null));
|
||||
}
|
||||
|
||||
adapter = new ItemStepsAdapter(getActivity(), itemModelList,this);
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
|
||||
recyclerView.setAdapter(adapter);
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (int i = 1; i < 7; i++) {
|
||||
itemModelList.add(new ItemModel(2,i,0,"0","",0, null, null));
|
||||
}
|
||||
adapter = new ItemStepsAdapter(getActivity(), itemModelList, this);
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
|
||||
recyclerView.setAdapter(adapter);
|
||||
}
|
||||
|
||||
//----------------------------------
|
||||
|
||||
imageAdapter = new ImageAdapter(imageList, getActivity());
|
||||
|
@ -201,11 +225,16 @@ public class StitchingFragment extends Fragment implements EasyPermissions.Permi
|
|||
", SpinnerSelection: " + item.getSelectedOption() +
|
||||
", Rating: " + item.getRating() +
|
||||
", Percentage: " + item.getPercentage() +
|
||||
", Remarks: " + item.getRemarks());
|
||||
", Remarks: " + item.getRemarks() +
|
||||
", ImageList: " + item.getImageArrayList());
|
||||
}
|
||||
|
||||
Helper.saveArrayList(itemModelList, "ListStitching",getActivity());
|
||||
viewModel.appendToQualityControlItemList(itemModelList);
|
||||
|
||||
List<ItemModel> updatedItemListP = new ArrayList<>(Helper.getArrayList("ListStitching", getActivity()));
|
||||
|
||||
|
||||
/*if (etRemarks.getText().toString().isEmpty()) {
|
||||
Toast.makeText(getActivity(), "Please enter remarks", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
@ -455,4 +484,21 @@ public class StitchingFragment extends Fragment implements EasyPermissions.Permi
|
|||
EasyPermissions.requestPermissions(this, getString(R.string.rationale_camera), GALLERY_REQUEST, perms);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSelectImage(int position) {
|
||||
selectedPosition = position;
|
||||
|
||||
// Show dialog to choose between camera and gallery
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(requireContext());
|
||||
builder.setTitle("Select Image")
|
||||
.setItems(new String[]{"Camera", "Gallery"}, (dialog, which) -> {
|
||||
if (which == 0) { // Camera
|
||||
openCamera();
|
||||
} else { // Gallery
|
||||
openGallery();
|
||||
}
|
||||
})
|
||||
.show();
|
||||
}
|
||||
}
|
|
@ -36,10 +36,18 @@ import android.widget.TextView;
|
|||
import android.widget.Toast;
|
||||
|
||||
import com.utopiaindustries.qualitycontrol.R;
|
||||
import com.utopiaindustries.qualitycontrol.activities.SummaryActivity;
|
||||
import com.utopiaindustries.qualitycontrol.adapters.ImageAdapter;
|
||||
import com.utopiaindustries.qualitycontrol.adapters.ItemStepsAdapter;
|
||||
import com.utopiaindustries.qualitycontrol.helper.Helper;
|
||||
import com.utopiaindustries.qualitycontrol.helper.Preference;
|
||||
import com.utopiaindustries.qualitycontrol.utils.ImageSelectionListener;
|
||||
import com.utopiaindustries.qualitycontrol.utils.ProgressDialogFragment;
|
||||
import com.utopiaindustries.qualitycontrol.utils.QualityControlViewModel;
|
||||
import com.utopiaindustries.qualitycontrol.viewmodels.HomeViewModel;
|
||||
import com.utopiaindustries.qualitycontrol.viewmodels.ItemModel;
|
||||
import com.utopiaindustries.qualitycontrol.viewmodels.LoginViewModel;
|
||||
import com.utopiaindustries.qualitycontrol.viewmodels.QualityControl;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
|
@ -47,6 +55,7 @@ import java.io.IOException;
|
|||
import java.io.InputStream;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
@ -56,7 +65,8 @@ import pub.devrel.easypermissions.AfterPermissionGranted;
|
|||
import pub.devrel.easypermissions.AppSettingsDialog;
|
||||
import pub.devrel.easypermissions.EasyPermissions;
|
||||
|
||||
public class SubStoreFragment extends Fragment implements EasyPermissions.PermissionCallbacks{
|
||||
public class SubStoreFragment extends Fragment implements EasyPermissions.PermissionCallbacks,
|
||||
ImageSelectionListener {
|
||||
|
||||
RecyclerView recyclerView, imageRecyclerView;
|
||||
ImageAdapter imageAdapter;
|
||||
|
@ -71,13 +81,17 @@ public class SubStoreFragment extends Fragment implements EasyPermissions.Permis
|
|||
ArrayList<byte[]> imageList = new ArrayList<>();
|
||||
EditText etPercentage, etRemarks;
|
||||
QualityControlViewModel viewModel;
|
||||
List<ItemModel> itemModelList = new ArrayList<>();
|
||||
ItemStepsAdapter adapter;
|
||||
private int selectedPosition = -1;
|
||||
HomeViewModel homeViewModel;
|
||||
|
||||
// Activity Result Launcher for Gallery
|
||||
private final ActivityResultLauncher<Intent> imagePickerLauncher =
|
||||
registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), result -> {
|
||||
if (result.getResultCode() == requireActivity().RESULT_OK && result.getData() != null) {
|
||||
Uri selectedImage = result.getData().getData();
|
||||
if (selectedImage != null) {
|
||||
if (selectedPosition != -1 && selectedImage != null) {
|
||||
//imageView.setImageURI(selectedImage);
|
||||
|
||||
uriToByteArrayAsync(
|
||||
|
@ -87,9 +101,11 @@ public class SubStoreFragment extends Fragment implements EasyPermissions.Permis
|
|||
compressedImage -> {
|
||||
// Handle the compressed image here, e.g., display it
|
||||
requireActivity().runOnUiThread(() -> {
|
||||
//store.getReport().getItems().get(0).getCheckPoints().get(requestCode).addImageList(compressedImage);
|
||||
imageList.add(compressedImage);
|
||||
imageAdapter.notifyDataSetChanged();
|
||||
itemModelList.get(selectedPosition).setImageUri(compressedImage);
|
||||
List<byte[]> tempList = new ArrayList<>();
|
||||
tempList.add(compressedImage);
|
||||
itemModelList.get(selectedPosition).setImageArrayList(tempList);
|
||||
adapter.notifyItemChanged(selectedPosition);
|
||||
});
|
||||
},
|
||||
error -> {
|
||||
|
@ -115,9 +131,11 @@ public class SubStoreFragment extends Fragment implements EasyPermissions.Permis
|
|||
compressedImage -> {
|
||||
// Handle the compressed image here, e.g., display it
|
||||
requireActivity().runOnUiThread(() -> {
|
||||
//store.getReport().getItems().get(0).getCheckPoints().get(requestCode).addImageList(compressedImage);
|
||||
imageList.add(compressedImage);
|
||||
imageAdapter.notifyDataSetChanged();
|
||||
itemModelList.get(selectedPosition).setImageUri(compressedImage);
|
||||
List<byte[]> tempList = new ArrayList<>();
|
||||
tempList.add(compressedImage);
|
||||
itemModelList.get(selectedPosition).setImageArrayList(tempList);
|
||||
adapter.notifyItemChanged(selectedPosition);
|
||||
});
|
||||
},
|
||||
error -> {
|
||||
|
@ -155,14 +173,35 @@ public class SubStoreFragment extends Fragment implements EasyPermissions.Permis
|
|||
itemList.add(new Item("Safety", 0));*/
|
||||
|
||||
//New Implemented------------------
|
||||
List<ItemModel> itemModelList = new ArrayList<>();
|
||||
for (int i = 1; i < 7; i++) {
|
||||
itemModelList.add(new ItemModel(5,i,0,"0","",0));
|
||||
}
|
||||
if (Helper.getArrayList("ListSubStore", getActivity()) != null) {
|
||||
itemModelList.clear();
|
||||
itemModelList.addAll(Helper.getArrayList("ListSubStore", getActivity()));
|
||||
Log.e("itemModelList-size: ",""+itemModelList.size());
|
||||
|
||||
ItemStepsAdapter adapter = new ItemStepsAdapter(getActivity(), itemModelList);
|
||||
if (itemModelList != null) {
|
||||
adapter = new ItemStepsAdapter(getActivity(), itemModelList, this);
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
|
||||
recyclerView.setAdapter(adapter);
|
||||
}
|
||||
else {
|
||||
for (int i = 1; i < 7; i++) {
|
||||
itemModelList.add(new ItemModel(5,i,0,"0","",0, null, null));
|
||||
}
|
||||
|
||||
adapter = new ItemStepsAdapter(getActivity(), itemModelList, this);
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
|
||||
recyclerView.setAdapter(adapter);
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (int i = 1; i < 7; i++) {
|
||||
itemModelList.add(new ItemModel(5,i,0,"0","",0, null, null));
|
||||
}
|
||||
adapter = new ItemStepsAdapter(getActivity(), itemModelList, this);
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
|
||||
recyclerView.setAdapter(adapter);
|
||||
}
|
||||
|
||||
//----------------------------------
|
||||
|
||||
imageAdapter = new ImageAdapter(imageList, getActivity());
|
||||
|
@ -194,23 +233,46 @@ public class SubStoreFragment extends Fragment implements EasyPermissions.Permis
|
|||
", SpinnerSelection: " + item.getSelectedOption() +
|
||||
", Rating: " + item.getRating() +
|
||||
", Percentage: " + item.getPercentage() +
|
||||
", Remarks: " + item.getRemarks());
|
||||
", Remarks: " + item.getRemarks() +
|
||||
", ImageList: " + item.getImageArrayList());
|
||||
}
|
||||
|
||||
Helper.saveArrayList(itemModelList, "ListSubStore",getActivity());
|
||||
viewModel.appendToQualityControlItemList(itemModelList);
|
||||
|
||||
List<ItemModel> finalList = viewModel.getQualityControlItemList();
|
||||
for (ItemModel item : finalList) {
|
||||
int siteID = Integer.parseInt(Preference.getMyStringPref(Helper.project_file,Helper.locationSiteId,getActivity()));
|
||||
int unitId = Integer.parseInt(Preference.getMyStringPref(Helper.project_file,Helper.unitId,getActivity()));
|
||||
int departId = Integer.parseInt(Preference.getMyStringPref(Helper.project_file,Helper.departmentId,getActivity()));
|
||||
int floorId = Integer.parseInt(Preference.getMyStringPref(Helper.project_file,Helper.floorId,getActivity()));
|
||||
|
||||
List<ItemModel> tempList = new ArrayList<>();
|
||||
tempList.addAll(Helper.getArrayList("ListCutting",getActivity()));
|
||||
tempList.addAll(Helper.getArrayList("ListStitching",getActivity()));
|
||||
tempList.addAll(Helper.getArrayList("ListChecking",getActivity()));
|
||||
tempList.addAll(Helper.getArrayList("ListPacking",getActivity()));
|
||||
tempList.addAll(Helper.getArrayList("ListSubStore",getActivity()));
|
||||
|
||||
QualityControl qualityControl = new QualityControl(siteID,unitId,departId,floorId,tempList);
|
||||
|
||||
/*Log.e("AdapterData", "siteID: " + siteID +
|
||||
", unitId: " + unitId +
|
||||
", departId: " + departId +
|
||||
", floorId: " + floorId );
|
||||
|
||||
Log.e("------------------","------------");*/
|
||||
|
||||
/*for (ItemModel item : tempList) {
|
||||
Log.e("AdapterData", "ProcessId: " + item.getProcessId() +
|
||||
", StepId: " + item.getStepId() +
|
||||
", SpinnerSelection: " + item.getSelectedOption() +
|
||||
", Rating: " + item.getRating() +
|
||||
", Percentage: " + item.getPercentage() +
|
||||
", Remarks: " + item.getRemarks());
|
||||
", Remarks: " + item.getRemarks() +
|
||||
", ImageList: " + item.getImageArrayList() +
|
||||
", Image: " + Arrays.toString(item.getImageUri()));
|
||||
}*/
|
||||
|
||||
Log.e("------------------","---------------------");
|
||||
|
||||
}
|
||||
homeViewModel.saveQualityControlData(qualityControl);
|
||||
|
||||
});
|
||||
|
||||
|
@ -225,6 +287,7 @@ public class SubStoreFragment extends Fragment implements EasyPermissions.Permis
|
|||
private void initializeLayout(View view) {
|
||||
|
||||
viewModel = new ViewModelProvider(requireActivity()).get(QualityControlViewModel.class);
|
||||
homeViewModel = new ViewModelProvider(requireActivity()).get(HomeViewModel.class);
|
||||
|
||||
etPercentage = view.findViewById(R.id.et_percentage);
|
||||
etRemarks = view.findViewById(R.id.et_remarks);
|
||||
|
@ -234,6 +297,33 @@ public class SubStoreFragment extends Fragment implements EasyPermissions.Permis
|
|||
recyclerView = view.findViewById(R.id.recycler_view_substore);
|
||||
imageRecyclerView = view.findViewById(R.id.imageRecyclerView);
|
||||
imageRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity(), LinearLayoutManager.HORIZONTAL, false));
|
||||
|
||||
homeViewModel.getLoadingState().observe(getActivity(), isLoading -> {
|
||||
if (isLoading != null && isLoading) {
|
||||
showProgressDialog();
|
||||
} else {
|
||||
dismissProgressDialog();
|
||||
}
|
||||
});
|
||||
|
||||
homeViewModel.getErrorMessage().observe(getActivity(), errorResponse -> {
|
||||
if (errorResponse.isEmpty()) {
|
||||
Toast.makeText(getActivity(), "Something went wrong", Toast.LENGTH_SHORT).show();
|
||||
} else {
|
||||
Toast.makeText(getActivity(), errorResponse, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
homeViewModel.getUserLiveData().observe(getActivity(), qcResponse -> {
|
||||
if (qcResponse != null) {
|
||||
Log.e("qcResponse: ",""+qcResponse);
|
||||
Log.e("","Status: " + qcResponse.getStatus() + "Message: " + qcResponse.getMessage() + "Percentage: " + qcResponse.getOverAllPercentage());
|
||||
/*getActivity().finish();
|
||||
Intent intent = new Intent(getActivity(), SummaryActivity.class);
|
||||
startActivity(intent);*/
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -449,4 +539,34 @@ public class SubStoreFragment extends Fragment implements EasyPermissions.Permis
|
|||
EasyPermissions.requestPermissions(this, getString(R.string.rationale_camera), GALLERY_REQUEST, perms);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSelectImage(int position) {
|
||||
selectedPosition = position;
|
||||
|
||||
// Show dialog to choose between camera and gallery
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(requireContext());
|
||||
builder.setTitle("Select Image")
|
||||
.setItems(new String[]{"Camera", "Gallery"}, (dialog, which) -> {
|
||||
if (which == 0) { // Camera
|
||||
openCamera();
|
||||
} else { // Gallery
|
||||
openGallery();
|
||||
}
|
||||
})
|
||||
.show();
|
||||
}
|
||||
|
||||
public void showProgressDialog() {
|
||||
ProgressDialogFragment progressDialog = new ProgressDialogFragment();
|
||||
progressDialog.setCancelable(false);
|
||||
progressDialog.show(getActivity().getSupportFragmentManager(), "progressDialog");
|
||||
}
|
||||
|
||||
public void dismissProgressDialog() {
|
||||
ProgressDialogFragment progressDialog = (ProgressDialogFragment) getActivity().getSupportFragmentManager().findFragmentByTag("progressDialog");
|
||||
if (progressDialog != null) {
|
||||
progressDialog.dismiss();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -4,16 +4,31 @@ import android.content.Context;
|
|||
import android.content.SharedPreferences;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkInfo;
|
||||
import android.preference.PreferenceManager;
|
||||
import androidx.preference.PreferenceManager;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.utopiaindustries.qualitycontrol.models.QualityControlResponse;
|
||||
import com.utopiaindustries.qualitycontrol.viewmodels.ItemModel;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Helper {
|
||||
|
||||
public static final String project_file = "Quality-Control";
|
||||
|
||||
public static final String departmentId = "departId";
|
||||
public static final String departmentName = "departName";
|
||||
public static final String locationSiteId = "locationSiteId";
|
||||
public static final String locationSiteName = "locationSiteName";
|
||||
public static final String unitId = "unitId";
|
||||
public static final String unitName = "unitName";
|
||||
public static final String floorId = "floorId";
|
||||
public static final String floorName = "floorName";
|
||||
|
||||
public static boolean isValidEmail(CharSequence target) {
|
||||
return !TextUtils.isEmpty(target) && android.util.Patterns.EMAIL_ADDRESS.matcher(target).matches();
|
||||
}
|
||||
|
@ -44,4 +59,28 @@ public class Helper {
|
|||
QualityControlResponse selectedUser = gson.fromJson(json, QualityControlResponse.class);
|
||||
return selectedUser;
|
||||
}
|
||||
|
||||
static public void saveArrayList(List<ItemModel> list, String key, Context context){
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
SharedPreferences.Editor editor = prefs.edit();
|
||||
Gson gson = new Gson();
|
||||
String json = gson.toJson(list);
|
||||
editor.putString(key, json);
|
||||
editor.apply();
|
||||
|
||||
}
|
||||
|
||||
static public List<ItemModel> getArrayList(String key, Context context){
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
|
||||
// Check if the key exists
|
||||
if (!prefs.contains(key)) {
|
||||
return null; // Return null if the key doesn't exist
|
||||
}
|
||||
|
||||
Gson gson = new Gson();
|
||||
String json = prefs.getString(key, null);
|
||||
Type type = new TypeToken<ArrayList<ItemModel>>() {}.getType();
|
||||
return gson.fromJson(json, type);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
package com.utopiaindustries.qualitycontrol.models;
|
||||
|
||||
import com.google.gson.annotations.Expose;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class QualitySaveResponse {
|
||||
|
||||
@SerializedName("overAllPercentage")
|
||||
@Expose
|
||||
private String overAllPercentage;
|
||||
|
||||
@SerializedName("status")
|
||||
@Expose
|
||||
private String status;
|
||||
|
||||
@SerializedName("message")
|
||||
@Expose
|
||||
private String message;
|
||||
|
||||
public String getOverAllPercentage() {
|
||||
return overAllPercentage;
|
||||
}
|
||||
|
||||
public void setOverAllPercentage(String overAllPercentage) {
|
||||
this.overAllPercentage = overAllPercentage;
|
||||
}
|
||||
|
||||
public String getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(String status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
package com.utopiaindustries.qualitycontrol.utils;
|
||||
|
||||
public interface ImageSelectionListener {
|
||||
|
||||
void onSelectImage(int position);
|
||||
}
|
|
@ -0,0 +1,76 @@
|
|||
package com.utopiaindustries.qualitycontrol.viewmodels;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
import androidx.lifecycle.ViewModel;
|
||||
|
||||
import com.utopiaindustries.qualitycontrol.apiservice.ApiService;
|
||||
import com.utopiaindustries.qualitycontrol.apiservice.ApiServiceFactory;
|
||||
import com.utopiaindustries.qualitycontrol.models.QualityControlResponse;
|
||||
import com.utopiaindustries.qualitycontrol.models.QualitySaveResponse;
|
||||
|
||||
import retrofit2.Call;
|
||||
import retrofit2.Callback;
|
||||
import retrofit2.Response;
|
||||
|
||||
public class HomeViewModel extends ViewModel {
|
||||
|
||||
private MutableLiveData<QualitySaveResponse> userLiveData;
|
||||
private MutableLiveData<String> errorLiveData;
|
||||
private MutableLiveData<Boolean> isLoading;
|
||||
private ApiService apiService;
|
||||
|
||||
public HomeViewModel() {
|
||||
apiService = ApiServiceFactory.getApiService();
|
||||
userLiveData = new MutableLiveData<>();
|
||||
errorLiveData = new MutableLiveData<>();
|
||||
isLoading = new MutableLiveData<>();
|
||||
}
|
||||
|
||||
public LiveData<QualitySaveResponse> getUserLiveData() {
|
||||
return userLiveData;
|
||||
}
|
||||
|
||||
public LiveData<Boolean> getLoadingState() {
|
||||
|
||||
return isLoading;
|
||||
}
|
||||
|
||||
public LiveData<String> getErrorMessage() {
|
||||
return errorLiveData;
|
||||
}
|
||||
|
||||
public void saveQualityControlData(QualityControl qualityControl) {
|
||||
isLoading.setValue(true);
|
||||
apiService.saveQualityControlReport(qualityControl).enqueue(new Callback<QualitySaveResponse>() {
|
||||
@Override
|
||||
public void onResponse(Call<QualitySaveResponse> call, Response<QualitySaveResponse> response) {
|
||||
Log.e("onResponse: ",""+response);
|
||||
isLoading.setValue(false);
|
||||
if (response.isSuccessful() && response.body() != null) {
|
||||
Log.e("onResponse-success: ",""+response);
|
||||
userLiveData.setValue(response.body());
|
||||
} else {
|
||||
errorLiveData.setValue(response.message());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<QualitySaveResponse> call, Throwable t) {
|
||||
Log.e("onResponse-fail: ",""+t.getMessage());
|
||||
isLoading.setValue(false);
|
||||
errorLiveData.setValue(t.getMessage());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public LiveData<QualitySaveResponse> getUser() {
|
||||
return userLiveData;
|
||||
}
|
||||
|
||||
public LiveData<String> getError() {
|
||||
return errorLiveData;
|
||||
}
|
||||
}
|
|
@ -1,6 +1,9 @@
|
|||
package com.utopiaindustries.qualitycontrol.viewmodels;
|
||||
|
||||
import android.net.Uri;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ItemModel {
|
||||
|
||||
|
@ -10,18 +13,21 @@ public class ItemModel {
|
|||
private String percentage;
|
||||
private String remarks;
|
||||
private int selectedOption;
|
||||
//private ArrayList<byte[]> cuttingImageList;
|
||||
private byte[] imageByteArray;
|
||||
private List<byte[]> files;
|
||||
|
||||
public ItemModel() {
|
||||
}
|
||||
|
||||
public ItemModel(int processId, int stepId, int rating, String percentage, String remarks, int selectedOption) {
|
||||
public ItemModel(int processId, int stepId, int rating, String percentage, String remarks, int selectedOption, byte[] imageByteArray, List<byte[]> imageArrayList) {
|
||||
this.processId = processId;
|
||||
this.stepId = stepId;
|
||||
this.rating = rating;
|
||||
this.percentage = percentage;
|
||||
this.remarks = remarks;
|
||||
this.selectedOption = selectedOption;
|
||||
this.imageByteArray = imageByteArray;
|
||||
this.files = imageArrayList;
|
||||
}
|
||||
|
||||
public int getProcessId() {
|
||||
|
@ -71,4 +77,20 @@ public class ItemModel {
|
|||
public void setRating(int rating) {
|
||||
this.rating = rating;
|
||||
}
|
||||
|
||||
public byte[] getImageUri() {
|
||||
return imageByteArray;
|
||||
}
|
||||
|
||||
public void setImageUri(byte[] imageUri) {
|
||||
this.imageByteArray = imageUri;
|
||||
}
|
||||
|
||||
public List<byte[]> getImageArrayList() {
|
||||
return files;
|
||||
}
|
||||
|
||||
public void setImageArrayList(List<byte[]> imageArrayList) {
|
||||
this.files = imageArrayList;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,80 @@
|
|||
package com.utopiaindustries.qualitycontrol.viewmodels;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class QualityControl {
|
||||
|
||||
private int siteId;
|
||||
private int unitId;
|
||||
private int departmentId;
|
||||
private int floorId;
|
||||
private List<ItemModel> qualityControlItemList;
|
||||
|
||||
public QualityControl(int siteId, int floorId, int departmentId, int unitId, List<ItemModel> qualityControlItemList) {
|
||||
this.siteId = siteId;
|
||||
this.qualityControlItemList = qualityControlItemList;
|
||||
this.floorId = floorId;
|
||||
this.departmentId = departmentId;
|
||||
this.unitId = unitId;
|
||||
}
|
||||
|
||||
public QualityControl() {
|
||||
}
|
||||
|
||||
public int getSiteId() {
|
||||
return siteId;
|
||||
}
|
||||
|
||||
public void setSiteId(int siteId) {
|
||||
this.siteId = siteId;
|
||||
}
|
||||
|
||||
public int getUnitId() {
|
||||
return unitId;
|
||||
}
|
||||
|
||||
public void setUnitId(int unitId) {
|
||||
this.unitId = unitId;
|
||||
}
|
||||
|
||||
public int getDepartmentId() {
|
||||
return departmentId;
|
||||
}
|
||||
|
||||
public void setDepartmentId(int departmentId) {
|
||||
this.departmentId = departmentId;
|
||||
}
|
||||
|
||||
public int getFloorId() {
|
||||
return floorId;
|
||||
}
|
||||
|
||||
public void setFloorId(int floorId) {
|
||||
this.floorId = floorId;
|
||||
}
|
||||
|
||||
public List<ItemModel> getQualityControlItemList() {
|
||||
return qualityControlItemList;
|
||||
}
|
||||
|
||||
public void setQualityControlItemList(List<ItemModel> qualityControlItemList) {
|
||||
this.qualityControlItemList = qualityControlItemList;
|
||||
}
|
||||
|
||||
public void appendToQualityControlItemList(List<ItemModel> items) {
|
||||
if (items != null) {
|
||||
qualityControlItemList.addAll(items);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "QualityControl{" +
|
||||
"siteId=" + siteId +
|
||||
", unitId=" + unitId +
|
||||
", departmentId=" + departmentId +
|
||||
", floorId=" + floorId +
|
||||
", qualityControlItemList=" + qualityControlItemList +
|
||||
'}';
|
||||
}
|
||||
}
|
|
@ -40,6 +40,7 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:visibility="gone"
|
||||
android:weightSum="1">
|
||||
|
||||
<TextView
|
||||
|
|
|
@ -40,6 +40,7 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:visibility="gone"
|
||||
android:weightSum="1">
|
||||
|
||||
<TextView
|
||||
|
|
|
@ -40,6 +40,7 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:visibility="gone"
|
||||
android:weightSum="1">
|
||||
|
||||
<TextView
|
||||
|
|
|
@ -40,6 +40,7 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:visibility="gone"
|
||||
android:weightSum="1">
|
||||
|
||||
<TextView
|
||||
|
|
|
@ -40,6 +40,7 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:visibility="gone"
|
||||
android:weightSum="1">
|
||||
|
||||
<TextView
|
||||
|
|
|
@ -12,6 +12,7 @@ lifecycleViewmodel = "2.8.7"
|
|||
material = "1.12.0"
|
||||
activity = "1.9.3"
|
||||
constraintlayout = "2.2.0"
|
||||
preference = "1.2.1"
|
||||
retrofit = "8.6.1"
|
||||
retrofitVersion = "2.9.0"
|
||||
|
||||
|
@ -28,6 +29,7 @@ lifecycle-viewmodel = { module = "androidx.lifecycle:lifecycle-viewmodel", versi
|
|||
material = { group = "com.google.android.material", name = "material", version.ref = "material" }
|
||||
activity = { group = "androidx.activity", name = "activity", version.ref = "activity" }
|
||||
constraintlayout = { group = "androidx.constraintlayout", name = "constraintlayout", version.ref = "constraintlayout" }
|
||||
preference = { module = "androidx.preference:preference", version.ref = "preference" }
|
||||
retrofit = { module = "com.squareup.retrofit2:retrofit", version.ref = "retrofit" }
|
||||
retrofit-v290 = { module = "com.squareup.retrofit2:retrofit", version.ref = "retrofitVersion" }
|
||||
|
||||
|
|
Loading…
Reference in New Issue