Commit 440344c6 authored by Muhammad Suryono's avatar Muhammad Suryono

Update

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