Commit 56aecc45 authored by iman Fauzi's avatar iman Fauzi

Merge branch 'dev' of https://git.mdd.co.id:44195/muhammadsuryono/meser into dev

parents 3a088d6e 440344c6
......@@ -29,6 +29,7 @@ import androidx.lifecycle.ViewModelProviders;
import com.google.android.material.appbar.MaterialToolbar;
import com.google.android.material.bottomsheet.BottomSheetDialogFragment;
import com.google.zxing.common.StringUtils;
import com.jaredrummler.materialspinner.MaterialSpinner;
import com.yono.messeripos.api.client.Client;
import com.yono.messeripos.api.service.CategoryServise;
......@@ -55,7 +56,7 @@ import retrofit2.Response;
public class FormProductActivity extends AppCompatActivity {
FormProductBinding binding;
ProductModels productModels;
ProductModels productModels, productModelsSave;
File file;
MainViewModels mainViewModels;
MaterialSpinner spinner;
......@@ -66,7 +67,7 @@ public class FormProductActivity extends AppCompatActivity {
String locationPath = null;
int idCategorySelected = 0;
public int id = 0;
public String categoryName = "";
public String categoryName = null;
private String[] permissions = new String[]{Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE};
......@@ -85,6 +86,7 @@ public class FormProductActivity extends AppCompatActivity {
binding.btnAdd.setText("Add New Product");
productModels = new ProductModels();
productModelsSave = new ProductModels();
mainViewModels = ViewModelProviders.of(this).get(MainViewModels.class);
progressDialog = new ProgressDialog(FormProductActivity.this);
progressDialog.setMessage("Loading...");
......@@ -111,17 +113,17 @@ public class FormProductActivity extends AppCompatActivity {
if (productModelsIntent != null){
isUpdate = true;
productModels.setProductName(productModelsIntent.getProductName());
productModels.setPriceProduct(productModelsIntent.getPriceProduct());
productModels.setStockProduct(productModelsIntent.getStockProduct());
productModels.setImageProduct(productModelsIntent.getImageProduct());
productModelsSave.setProductName(productModelsIntent.getProductName());
productModelsSave.setPriceProduct(productModelsIntent.getPriceProduct());
productModelsSave.setStockProduct(productModelsIntent.getStockProduct());
productModelsSave.setImageProduct(productModelsIntent.getImageProduct());
binding.setProductForm(productModelsIntent);
binding.setPhoto(productModelsIntent.getImageProduct());
binding.btnAdd.setText("UPDATE PRODUCT");
}else{
productModelsIntent = new ProductModels("",0,0, utils.convertImageBase64Resource(getResources(), R.drawable.logo_32));
new ProductModels("",0,0, utils.convertImageBase64Resource(getResources(), R.drawable.logo_32));
}
binding.cvProduct.setOnClickListener(view -> openFile());
......@@ -129,6 +131,7 @@ public class FormProductActivity extends AppCompatActivity {
binding.btnAddCategory.setOnClickListener(view -> addCategory());
//spinner
setSpinner("");
setSelectedSpinner();
setAddListenerCategory();
......@@ -189,11 +192,14 @@ public class FormProductActivity extends AppCompatActivity {
List<String> str = new ArrayList<>();
categoryModels = new ArrayList<>();
Log.i("GET_CATEGORY", "setSpinner: "+utils.convertGson(productModelsIntent));
if (productModelsIntent.getCategoryProduct() == 0){
str.add("SELECT CATEGORY");
}else{
str.add(getCategoryById(productModelsIntent.getIdProduct()));
}
// if (productModelsIntent == null){
// str.add("SELECT CATEGORY");
// }else{
// getCategoryById(productModelsIntent.getIdProduct());
// categoryName = ""
// str.add(categoryName);
// }
str.add("SELECT CATEGORY");
mainViewModels.getCategory().observe(this, listDataResponse -> {
progressDialog.dismiss();
for (CategoryModels cd: listDataResponse.getData()){
......@@ -218,27 +224,38 @@ public class FormProductActivity extends AppCompatActivity {
}
private void saveProduct(){
productModels.setProductName(binding.etName.getText().toString());
productModels.setPriceProduct(Integer.parseInt(binding.etPrice.getText().toString()));
productModels.setStockProduct(Integer.parseInt(binding.etStock.getText().toString()));
productModels.setCategoryProduct(getCategory(categorySelect.get(0)));
productModelsSave = new ProductModels();
productModelsSave.setProductName(binding.etName.getText().toString());
productModelsSave.setPriceProduct(Integer.parseInt(binding.etPrice.getText().toString()));
productModelsSave.setStockProduct(Integer.parseInt(binding.etStock.getText().toString()));
productModelsSave.setCategoryProduct(getCategory(categorySelect.get(0)));
if (productModelsIntent == null){
productModelsSave.setImageProduct(productModels.getImageProduct());
}else{
if (productModels.getImageProduct() == null){
productModelsSave.setImageProduct(productModelsIntent.getImageProduct());
}else{
productModelsSave.setImageProduct(productModels.getImageProduct());
}
}
Log.i("SAVEPRODUCT", "saveProduct: "+utils.convertGson(productModelsSave));
if (isUpdate){
Log.i("update_path", "saveProduct: "+locationPath);
if (
!productModels.getProductName().isEmpty() ||
productModels.getPriceProduct() != 0 ||
productModels.getStockProduct() != 0
!productModelsSave.getProductName().isEmpty() ||
productModelsSave.getPriceProduct() != 0 ||
productModelsSave.getStockProduct() != 0
){
progressDialog.setCancelable(false);
progressDialog.show();
ProductService productService = client.Client(ProductService.class);
Log.i("data_post", "saveProduct: "+utils.convertGson(productModels));
productService.updateProduct(productModels, productModelsIntent.getIdProduct()).enqueue(new Callback<DataResponse<ProductModels>>() {
Log.i("data_post", "saveProduct: "+utils.convertGson(productModelsSave));
productService.updateProduct(productModelsSave, productModelsIntent.getIdProduct()).enqueue(new Callback<DataResponse<ProductModels>>() {
@Override
public void onResponse(Call<DataResponse<ProductModels>> call, Response<DataResponse<ProductModels>> response) {
Log.i("Success Post", "onResponse: "+utils.convertGson(response.body()));
Log.i("Success Post", "onResponse: "+utils.convertGson(response));
if (response.body() != null){
new AlertDialog.Builder(FormProductActivity.this)
.setCancelable(false)
......@@ -273,15 +290,16 @@ public class FormProductActivity extends AppCompatActivity {
Log.i("save", "saveProduct: "+locationPath);
if (fileImage.exists()){
if (
!productModels.getProductName().isEmpty() ||
productModels.getPriceProduct() != 0 ||
productModels.getStockProduct() != 0
!productModelsSave.getProductName().isEmpty() ||
productModelsSave.getPriceProduct() != 0 ||
productModelsSave.getStockProduct() != 0
){
progressDialog.setCancelable(false);
progressDialog.show();
ProductService productService = client.Client(ProductService.class);
Log.i("data_post", "saveProduct: "+utils.convertGson(productModels));
productService.postProduct(productModels).enqueue(new Callback<DataResponse<ProductModels>>() {
Log.i("data_post", "saveProduct: "+utils.convertGson(productModelsSave.getProductName()+productModelsSave.getStockProduct()+productModelsSave.getPriceProduct()));
Log.i("IMAGE", "saveProduct: "+utils.convertGson(productModelsSave.getImageProduct()));
productService.postProduct(productModelsSave).enqueue(new Callback<DataResponse<ProductModels>>() {
@Override
public void onResponse(Call<DataResponse<ProductModels>> call, Response<DataResponse<ProductModels>> response) {
Log.i("Success Post", "onResponse: "+utils.convertGson(response.body()));
......@@ -327,6 +345,7 @@ public class FormProductActivity extends AppCompatActivity {
public void onResponse(Call<DataResponse<List<CategoryModels>>> call, Response<DataResponse<List<CategoryModels>>> response) {
Log.i("CHDJHD", "getCategory: "+utils.convertGson(response.body()));
id = response.body().getData().get(0).getIdCategory();
productModels.setCategoryProduct(id);
}
@Override
......@@ -343,7 +362,9 @@ public class FormProductActivity extends AppCompatActivity {
@Override
public void onResponse(Call<DataResponse<CategoryModels>> call, Response<DataResponse<CategoryModels>> response) {
Log.i("ER", "onResponse: "+utils.convertGson(response.body()));
categoryName = response.body().getData().getNameCategory();
if (categoryName.isEmpty()){
categoryName = response.body().getData().getNameCategory();
}
}
@Override
......@@ -351,6 +372,7 @@ public class FormProductActivity extends AppCompatActivity {
}
});
Log.i("CategoryName", "getCategoryById: "+categoryName);
return categoryName;
}
......
......@@ -133,7 +133,7 @@ public class Utils {
Bitmap decodeImages = BitmapFactory.decodeByteArray(imageBytes,0,imageBytes.length);
// Bitmap bf = BitmapFactory.decodeFile(source, options);
Log.i("Size bitmap", "decodeImageBase64: "+decodeImages.getByteCount());
// Log.i("Size bitmap", "decodeImageBase64: "+decodeImages.getByteCount());
return decodeImages;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment