Commit dbe88ca2 authored by Muhammad Suryono's avatar Muhammad Suryono

op

parent a4b049bd
<component name="ProjectCodeStyleConfiguration"> <component name="ProjectCodeStyleConfiguration">
<code_scheme name="Project" version="173"> <code_scheme name="Project" version="173">
<DBN-PSQL>
<case-options enabled="true">
<option name="KEYWORD_CASE" value="lower" />
<option name="FUNCTION_CASE" value="lower" />
<option name="PARAMETER_CASE" value="lower" />
<option name="DATATYPE_CASE" value="lower" />
<option name="OBJECT_CASE" value="preserve" />
</case-options>
<formatting-settings enabled="false" />
</DBN-PSQL>
<DBN-SQL>
<case-options enabled="true">
<option name="KEYWORD_CASE" value="lower" />
<option name="FUNCTION_CASE" value="lower" />
<option name="PARAMETER_CASE" value="lower" />
<option name="DATATYPE_CASE" value="lower" />
<option name="OBJECT_CASE" value="preserve" />
</case-options>
<formatting-settings enabled="false">
<option name="STATEMENT_SPACING" value="one_line" />
<option name="CLAUSE_CHOP_DOWN" value="chop_down_if_statement_long" />
<option name="ITERATION_ELEMENTS_WRAPPING" value="chop_down_if_not_single" />
</formatting-settings>
</DBN-SQL>
<DBN-PSQL> <DBN-PSQL>
<case-options enabled="true"> <case-options enabled="true">
<option name="KEYWORD_CASE" value="lower" /> <option name="KEYWORD_CASE" value="lower" />
......
...@@ -21,10 +21,14 @@ import androidx.recyclerview.widget.LinearLayoutManager; ...@@ -21,10 +21,14 @@ import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
import com.google.android.material.appbar.MaterialToolbar; import com.google.android.material.appbar.MaterialToolbar;
import com.google.android.material.button.MaterialButton;
import com.google.android.material.textview.MaterialTextView;
import com.yono.messeripos.adapter.CartAdapter; import com.yono.messeripos.adapter.CartAdapter;
import com.yono.messeripos.models.MainViewModelsCart; import com.yono.messeripos.models.MainViewModelsCart;
import com.yono.messeripos.models.PaymentsModels;
import com.yono.messeripos.models.ProductCartModels; import com.yono.messeripos.models.ProductCartModels;
import com.yono.messeripos.response.OrdersResponse; import com.yono.messeripos.response.OrdersResponse;
import com.yono.messeripos.utils.Utils;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
...@@ -39,6 +43,10 @@ public class CartActivity extends AppCompatActivity { ...@@ -39,6 +43,10 @@ public class CartActivity extends AppCompatActivity {
List<ProductCartModels> dataCart = null; List<ProductCartModels> dataCart = null;
public static Boolean statusPost; public static Boolean statusPost;
SharedPreferences sharedPreferences; SharedPreferences sharedPreferences;
public static MaterialTextView grandToral;
Utils utils = new Utils();
public static long GrandTotal = 0;
MaterialButton btnSaveCart;
@RequiresApi(api = Build.VERSION_CODES.N) @RequiresApi(api = Build.VERSION_CODES.N)
@Override @Override
...@@ -46,6 +54,11 @@ public class CartActivity extends AppCompatActivity { ...@@ -46,6 +54,11 @@ public class CartActivity extends AppCompatActivity {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_cart); setContentView(R.layout.activity_cart);
Button btnCheckout; Button btnCheckout;
grandToral = findViewById(R.id.tvHarga);
btnSaveCart = findViewById(R.id.btSave);
actionSaveCart();
Window w = getWindow(); Window w = getWindow();
w.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); w.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
sharedPreferences = getSharedPreferences(SplashScreen.MY_SHARED_PREFERENCES, Context.MODE_PRIVATE); sharedPreferences = getSharedPreferences(SplashScreen.MY_SHARED_PREFERENCES, Context.MODE_PRIVATE);
...@@ -83,6 +96,10 @@ public class CartActivity extends AppCompatActivity { ...@@ -83,6 +96,10 @@ public class CartActivity extends AppCompatActivity {
}); });
// grandToral.setText(utils.convertPrice("Rp. ", utils.grandTotal));
cartAdapter.setListener(new CartAdapter.CartListener() { cartAdapter.setListener(new CartAdapter.CartListener() {
@Override @Override
public void onDelete(ProductCartModels productCartModels) { public void onDelete(ProductCartModels productCartModels) {
...@@ -136,4 +153,25 @@ public class CartActivity extends AppCompatActivity { ...@@ -136,4 +153,25 @@ public class CartActivity extends AppCompatActivity {
}); });
} }
private void actionSaveCart() {
modelsCart.getCartByOrderId(orderId).observe(this, new Observer<List<ProductCartModels>>() {
@Override
public void onChanged(List<ProductCartModels> productCartModels) {
long grossAmount = 0;
for (ProductCartModels pd:productCartModels){
grossAmount = grossAmount + (pd.getQuantity_orders()*pd.getPrice_orders());
}
PaymentsModels paymentsModels = new PaymentsModels();
paymentsModels.setGrossAmount(grossAmount);
paymentsModels.setBank("None");
paymentsModels.setPaymentType("Pending");
paymentsModels.setOrderId(orderId);
paymentsModels.setTransactionStatus("Pending");
modelsCart.insertPayments(paymentsModels);
}
});
}
} }
\ No newline at end of file
...@@ -2,8 +2,10 @@ package com.yono.messeripos; ...@@ -2,8 +2,10 @@ package com.yono.messeripos;
import android.Manifest; import android.Manifest;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.app.ProgressDialog; import android.app.ProgressDialog;
import android.content.CursorLoader; import android.content.CursorLoader;
import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.database.Cursor; import android.database.Cursor;
import android.graphics.Bitmap; import android.graphics.Bitmap;
...@@ -12,22 +14,17 @@ import android.net.Uri; ...@@ -12,22 +14,17 @@ import android.net.Uri;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.os.Environment; import android.os.Environment;
import android.os.PersistableBundle;
import android.provider.MediaStore; import android.provider.MediaStore;
import android.provider.Settings;
import android.util.Base64; import android.util.Base64;
import android.util.Log; import android.util.Log;
import android.view.Window; import android.view.Window;
import android.view.WindowManager; import android.view.WindowManager;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.Toast;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi; import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import androidx.core.content.ContextCompat;
import androidx.core.content.FileProvider; import androidx.core.content.FileProvider;
import androidx.databinding.DataBindingUtil; import androidx.databinding.DataBindingUtil;
import androidx.lifecycle.Observer; import androidx.lifecycle.Observer;
...@@ -46,20 +43,14 @@ import com.yono.messeripos.utils.Utils; ...@@ -46,20 +43,14 @@ import com.yono.messeripos.utils.Utils;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.File; import java.io.File;
import java.nio.ByteBuffer;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.HashMap;
import java.util.List; import java.util.List;
import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.RequestBody;
import retrofit2.Call; import retrofit2.Call;
import retrofit2.Callback; import retrofit2.Callback;
import retrofit2.Response; import retrofit2.Response;
import retrofit2.http.Multipart;
public class FormProductActivity extends AppCompatActivity { public class FormProductActivity extends AppCompatActivity {
...@@ -72,24 +63,8 @@ public class FormProductActivity extends AppCompatActivity { ...@@ -72,24 +63,8 @@ public class FormProductActivity extends AppCompatActivity {
private static final int REQUEST_IMAGE_CAPTURE = 1; private static final int REQUEST_IMAGE_CAPTURE = 1;
private static final int REQUEST_PERMISSIONS = 448; private static final int REQUEST_PERMISSIONS = 448;
private boolean isUpdate = false; private boolean isUpdate = false;
String kondisi_spin;
String locationPath = null; String locationPath = null;
int idCategorySelected = 0;
private static final String[] ANDROID_VERSIONS = {
"Cupcake",
"Donut",
"Eclair",
"Froyo",
"Gingerbread",
"Honeycomb",
"Ice Cream Sandwich",
"Jelly Bean",
"KitKat",
"Lollipop",
"Marshmallow",
"Nougat",
"Oreo"
};
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};
...@@ -115,12 +90,30 @@ public class FormProductActivity extends AppCompatActivity { ...@@ -115,12 +90,30 @@ public class FormProductActivity extends AppCompatActivity {
w.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); w.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
} }
ProductModels productModelsIntent = getIntent().getParcelableExtra(MainActivity.DATA_PRODUCT);
MaterialToolbar toolbars = findViewById(R.id.topAppBarForm); MaterialToolbar toolbars = findViewById(R.id.topAppBarForm);
setSupportActionBar(toolbars); setSupportActionBar(toolbars);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true); if (getSupportActionBar() != null){
getSupportActionBar().setTitle("Add Product"); getSupportActionBar().setDisplayHomeAsUpEnabled(true);
toolbars.setNavigationOnClickListener(view -> onBackPressed()); getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setTitle("Add Product");
toolbars.setNavigationOnClickListener(view -> onBackPressed());
}
if (productModelsIntent != null){
isUpdate = true;
productModels.setProductName(productModelsIntent.getProductName());
productModels.setPriceProduct(productModelsIntent.getPriceProduct());
productModels.setStockProduct(productModelsIntent.getStockProduct());
productModels.setImageProduct(productModelsIntent.getImageProduct());
binding.btnAdd.setText("UPDATE PRODUCT");
}else{
productModelsIntent = new ProductModels("",0,0, utils.convertImageBase64Resource(getResources(), R.drawable.logo_32));
}
binding.cvProduct.setOnClickListener(view -> openFile()); binding.cvProduct.setOnClickListener(view -> openFile());
binding.btnAdd.setOnClickListener(view -> saveProduct()); binding.btnAdd.setOnClickListener(view -> saveProduct());
...@@ -129,7 +122,29 @@ public class FormProductActivity extends AppCompatActivity { ...@@ -129,7 +122,29 @@ public class FormProductActivity extends AppCompatActivity {
categoryModels = new ArrayList<>(); categoryModels = new ArrayList<>();
categoryModels.add("SELECT CATEGORY"); categoryModels.add("SELECT CATEGORY");
setSpinner(); setSpinner();
setSelectedSpinner();
}
private void setSelectedSpinner() {
binding.listCategory.setOnItemSelectedListener(new MaterialSpinner.OnItemSelectedListener() {
@Override
public void onItemSelected(MaterialSpinner view, int position, long id, Object item) {
utils.toastMessage(FormProductActivity.this, ""+position);
Log.i("Object", "onItemSelected: "+item);
mainViewModels.getCategory().observe(FormProductActivity.this, new Observer<DataResponse<List<CategoryModels>>>() {
@Override
public void onChanged(DataResponse<List<CategoryModels>> listDataResponse) {
List<CategoryModels> cat = listDataResponse.getData();
for (CategoryModels cM : cat){
if (cM.getNameCategory() == item){
idCategorySelected = cM.getIdCategory();
}
}
}
});
}
});
} }
private void setSpinner() { private void setSpinner() {
...@@ -159,9 +174,44 @@ public class FormProductActivity extends AppCompatActivity { ...@@ -159,9 +174,44 @@ public class FormProductActivity extends AppCompatActivity {
File fileImage = new File(locationPath); File fileImage = new File(locationPath);
Log.i("save", "saveProduct: "+locationPath); Log.i("save", "saveProduct: "+locationPath);
if (fileImage.exists()){ if (fileImage.exists()){
progressDialog.show(); if (
// Toast.makeText(this, productModels.getImageProduct()+" "+productModels.getProductName(), Toast.LENGTH_LONG).show(); !productModels.getProductName().isEmpty() ||
utils.toastMessage(FormProductActivity.this, utils.convertGson(productModels)); productModels.getPriceProduct() != 0 ||
productModels.getStockProduct() != 0
){
progressDialog.show();
ProductService productService = client.Client(ProductService.class);
Log.i("data_post", "saveProduct: "+utils.convertGson(productModels));
productService.postProduct(productModels).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()));
if (response.body() != null){
new AlertDialog.Builder(FormProductActivity.this)
.setCancelable(false)
.setTitle("Add New Product")
.setMessage("Add new product success")
.setPositiveButton("Oke", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
startActivity(new Intent(FormProductActivity.this, MainActivity.class));
finish();
}
}).show();
}else{
new AlertDialog.Builder(FormProductActivity.this)
.setTitle("Add New Product")
.setMessage("Add new product failed, try again!").show();
}
progressDialog.dismiss();
}
@Override
public void onFailure(Call<DataResponse<ProductModels>> call, Throwable t) {
t.printStackTrace();
}
});
}
} }
} }
...@@ -211,16 +261,14 @@ public class FormProductActivity extends AppCompatActivity { ...@@ -211,16 +261,14 @@ public class FormProductActivity extends AppCompatActivity {
if (requestCode == 100 && resultCode == RESULT_OK && data != null) { if (requestCode == 100 && resultCode == RESULT_OK && data != null) {
Uri selectedImage = data.getData(); Uri selectedImage = data.getData();
binding.setPhoto(getRealPathFromURI(selectedImage)); binding.setPhoto(utils.convertImageBase64File(getRealPathFromURI(selectedImage)));
locationPath = getRealPathFromURI(selectedImage); locationPath = getRealPathFromURI(selectedImage);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] imageBytes = baos.toByteArray(); binding.ivProduct.setImageBitmap(utils.decodeImageBase64(utils.convertImageBase64File(getRealPathFromURI(selectedImage))));
imageBytes = Base64.decode(utils.convertImageBase64File(getRealPathFromURI(selectedImage)), Base64.DEFAULT); productModels.setImageProduct(getRealPathFromURI(selectedImage));
Bitmap decodeImages = BitmapFactory.decodeByteArray(imageBytes,0,imageBytes.length); // utils.convertImageBase64File(getRealPathFromURI(selectedImage))
binding.ivProduct.setImageBitmap(decodeImages);
productModels.setImageProduct(utils.convertImageBase64File(getRealPathFromURI(selectedImage)));
} }
} }
......
...@@ -67,6 +67,9 @@ public class MainActivity extends AppCompatActivity { ...@@ -67,6 +67,9 @@ public class MainActivity extends AppCompatActivity {
public static String orderId; public static String orderId;
private static final String ORDER_ID = "orderId"; private static final String ORDER_ID = "orderId";
Client client = new Client(); Client client = new Client();
public static ArrayList<ProductModels> productModelsArrayList = new ArrayList<>();
public static final String DATA_PRODUCT = "DATA_PRODUCT";
ProgressDialog progressDialog;
@SuppressLint("LongLogTag") @SuppressLint("LongLogTag")
@Override @Override
...@@ -86,6 +89,12 @@ public class MainActivity extends AppCompatActivity { ...@@ -86,6 +89,12 @@ public class MainActivity extends AppCompatActivity {
sharedPreferences = getSharedPreferences(SplashScreen.MY_SHARED_PREFERENCES, Context.MODE_PRIVATE); sharedPreferences = getSharedPreferences(SplashScreen.MY_SHARED_PREFERENCES, Context.MODE_PRIVATE);
checkout = sharedPreferences.getBoolean(CHECKOUT,false); checkout = sharedPreferences.getBoolean(CHECKOUT,false);
orderId = sharedPreferences.getString(ORDER_ID,""); orderId = sharedPreferences.getString(ORDER_ID,"");
progressDialog = new ProgressDialog(MainActivity.this);
progressDialog.setMessage("Loading...");
Log.i("ORDER ID", "onCreate: "+orderId);
toolbar = findViewById(R.id.topAppBar);
mainViewModels = ViewModelProviders.of(this).get(MainViewModels.class);
if (orderId.isEmpty()) if (orderId.isEmpty())
{ {
...@@ -96,33 +105,22 @@ public class MainActivity extends AppCompatActivity { ...@@ -96,33 +105,22 @@ public class MainActivity extends AppCompatActivity {
} }
} }
Log.i("ORDER ID", "onCreate: "+orderId);
toolbar = findViewById(R.id.topAppBar);
mainViewModels = ViewModelProviders.of(this).get(MainViewModels.class);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
Window w = getWindow(); Window w = getWindow();
w.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); w.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
} }
binding.etSearchProduct.addTextChangedListener(new TextWatcher() { functionSearch();
@Override toolbarSetOnItemClicked();
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { mainViewModelsGettCategory();
imageEmptyGetProducts();
} mainViewModelsGetProduct();
productAdapterListener();
@Override categoryAdapterListener();
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { }
productAdapter.getFilter().filter(charSequence);
}
@Override
public void afterTextChanged(Editable editable) {
}
});
private void toolbarSetOnItemClicked() {
toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() { toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
@Override @Override
public boolean onMenuItemClick(MenuItem item) { public boolean onMenuItemClick(MenuItem item) {
...@@ -155,7 +153,10 @@ public class MainActivity extends AppCompatActivity { ...@@ -155,7 +153,10 @@ public class MainActivity extends AppCompatActivity {
return true; return true;
} }
}); });
}
private void mainViewModelsGettCategory() {
mainViewModels.getCategory().observe(this, new Observer<DataResponse<List<CategoryModels>>>() { mainViewModels.getCategory().observe(this, new Observer<DataResponse<List<CategoryModels>>>() {
@Override @Override
public void onChanged(DataResponse<List<CategoryModels>> listDataResponse) { public void onChanged(DataResponse<List<CategoryModels>> listDataResponse) {
...@@ -179,7 +180,9 @@ public class MainActivity extends AppCompatActivity { ...@@ -179,7 +180,9 @@ public class MainActivity extends AppCompatActivity {
Log.d("Get data from category", "Response " + js); Log.d("Get data from category", "Response " + js);
} }
}); });
}
private void imageEmptyGetProducts() {
binding.imgEmpty.setOnClickListener(new View.OnClickListener() { binding.imgEmpty.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
...@@ -213,14 +216,17 @@ public class MainActivity extends AppCompatActivity { ...@@ -213,14 +216,17 @@ public class MainActivity extends AppCompatActivity {
}); });
} }
}); });
}
private void mainViewModelsGetProduct() {
progressDialog.show();
mainViewModels.getProduct().observe(this, new Observer<DataResponse<List<ProductModels<CategoryModels>>>>() { mainViewModels.getProduct().observe(this, new Observer<DataResponse<List<ProductModels<CategoryModels>>>>() {
@Override @Override
public void onChanged(DataResponse<List<ProductModels<CategoryModels>>> listDataResponse) { public void onChanged(DataResponse<List<ProductModels<CategoryModels>>> listDataResponse) {
if (listDataResponse != null) { progressDialog.dismiss();
if (listDataResponse.getData().size() != 0) {
List<ProductModels<CategoryModels>> productModels = listDataResponse.getData(); List<ProductModels<CategoryModels>> productModels = listDataResponse.getData();
ArrayList<ProductModels> productModelsArrayList = new ArrayList<>(); productModelsArrayList.clear();
productModelsArrayList.addAll(productModels); productModelsArrayList.addAll(productModels);
showLoading(false); showLoading(false);
if (productModelsArrayList.isEmpty()){ if (productModelsArrayList.isEmpty()){
...@@ -234,25 +240,28 @@ public class MainActivity extends AppCompatActivity { ...@@ -234,25 +240,28 @@ public class MainActivity extends AppCompatActivity {
} }
} }
String js = new Gson().toJson(listDataResponse);
Log.d("Get data from products", "Response " + js);
} }
}); });
}
private void productAdapterListener() {
productAdapter.setListener(new ProductAdapter.ProductListener() { productAdapter.setListener(new ProductAdapter.ProductListener() {
@Override @Override
public void onUpdate(ProductModels product) { public void onUpdate(ProductModels product) {
startActivity(new Intent(MainActivity.this,
FormProductActivity.class).putExtra(DATA_PRODUCT, product));
} }
@Override @Override
public void onDelete(ProductModels product) { public void onDelete(ProductModels product, int position) {
ProductService productService = client.Client(ProductService.class); ProductService productService = client.Client(ProductService.class);
productService.deleteProducts(product.getIdProduct()).enqueue(new Callback<DataResponse<ProductModels>>() { productService.deleteProducts(product.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) {
productModelsArrayList.remove(position);
binding.rvProduct.removeViewAt(position);
productAdapter.notifyItemRemoved(position);
productAdapter.notifyItemRangeChanged(position, productModelsArrayList.size());
} }
@Override @Override
...@@ -293,9 +302,9 @@ public class MainActivity extends AppCompatActivity { ...@@ -293,9 +302,9 @@ public class MainActivity extends AppCompatActivity {
}); });
} }
}); });
ProgressDialog progressDialog = new ProgressDialog(MainActivity.this); }
progressDialog.setMessage("Loading...");
private void categoryAdapterListener() {
categoryAdapter.setListener(new CategoryAdapter.CategoryListener() { categoryAdapter.setListener(new CategoryAdapter.CategoryListener() {
@Override @Override
public void onGetProduct(CategoryModels categoryModels) { public void onGetProduct(CategoryModels categoryModels) {
...@@ -315,8 +324,7 @@ public class MainActivity extends AppCompatActivity { ...@@ -315,8 +324,7 @@ public class MainActivity extends AppCompatActivity {
mainViewModels.getProduct().observe(MainActivity.this, new Observer<DataResponse<List<ProductModels<CategoryModels>>>>() { mainViewModels.getProduct().observe(MainActivity.this, new Observer<DataResponse<List<ProductModels<CategoryModels>>>>() {
@Override @Override
public void onChanged(DataResponse<List<ProductModels<CategoryModels>>> listDataResponse) { public void onChanged(DataResponse<List<ProductModels<CategoryModels>>> listDataResponse) {
ArrayList<ProductModels> productModelsArrayList = new ArrayList<>(); productModelsArrayList.clear();
productModelsArrayList.addAll(listDataResponse.getData()); productModelsArrayList.addAll(listDataResponse.getData());
progressDialog.dismiss(); progressDialog.dismiss();
binding.rvProduct.setVisibility(View.VISIBLE); binding.rvProduct.setVisibility(View.VISIBLE);
...@@ -338,8 +346,7 @@ public class MainActivity extends AppCompatActivity { ...@@ -338,8 +346,7 @@ public class MainActivity extends AppCompatActivity {
@Override @Override
public void onChanged(DataResponse<List<ProductModels>> listDataResponse) { public void onChanged(DataResponse<List<ProductModels>> listDataResponse) {
if (listDataResponse != null) { if (listDataResponse != null) {
ArrayList<ProductModels> productModelsArrayList = new ArrayList<>(); productModelsArrayList.clear();
productModelsArrayList.addAll(listDataResponse.getData()); productModelsArrayList.addAll(listDataResponse.getData());
progressDialog.dismiss(); progressDialog.dismiss();
showLoading(false); showLoading(false);
...@@ -363,6 +370,25 @@ public class MainActivity extends AppCompatActivity { ...@@ -363,6 +370,25 @@ public class MainActivity extends AppCompatActivity {
}); });
} }
private void functionSearch() {
binding.etSearchProduct.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
productAdapter.getFilter().filter(charSequence);
}
@Override
public void afterTextChanged(Editable editable) {
}
});
}
private void updateFinish() { private void updateFinish() {
status_update = false; status_update = false;
binding.topAppBar.setVisibility(View.VISIBLE); binding.topAppBar.setVisibility(View.VISIBLE);
......
...@@ -13,6 +13,7 @@ import androidx.recyclerview.widget.RecyclerView; ...@@ -13,6 +13,7 @@ import androidx.recyclerview.widget.RecyclerView;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.yono.messeripos.CartActivity; import com.yono.messeripos.CartActivity;
import com.yono.messeripos.MainActivity;
import com.yono.messeripos.R; import com.yono.messeripos.R;
import com.yono.messeripos.databinding.ItemCartBinding; import com.yono.messeripos.databinding.ItemCartBinding;
import com.yono.messeripos.databinding.ItemCheckoutBinding; import com.yono.messeripos.databinding.ItemCheckoutBinding;
...@@ -97,6 +98,9 @@ public class CartAdapter extends RecyclerView.Adapter<CartAdapter.MyViewHolder> ...@@ -97,6 +98,9 @@ public class CartAdapter extends RecyclerView.Adapter<CartAdapter.MyViewHolder>
* */ * */
subtotal = cartModels.getPrice_orders() * cartModels.getQuantity_orders(); subtotal = cartModels.getPrice_orders() * cartModels.getQuantity_orders();
utils.grandTotal = utils.grandTotal + (cartModels.getPrice_orders() * cartModels.getQuantity_orders());
Log.i("Grand Total", "bindData: "+utils.grandTotal);
CartActivity.grandToral.setText(utils.convertPrice("Rp. ", utils.grandTotal));
binding.setCarts(cartModels); binding.setCarts(cartModels);
binding.setPrice(utils.convertPrice("Rp. ", cartModels.getPrice_orders())); binding.setPrice(utils.convertPrice("Rp. ", cartModels.getPrice_orders()));
......
...@@ -2,6 +2,7 @@ package com.yono.messeripos.adapter; ...@@ -2,6 +2,7 @@ package com.yono.messeripos.adapter;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.content.Context; import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
...@@ -32,7 +33,7 @@ public class ProductAdapter extends RecyclerView.Adapter<ProductAdapter.MyViewHo ...@@ -32,7 +33,7 @@ public class ProductAdapter extends RecyclerView.Adapter<ProductAdapter.MyViewHo
public interface ProductListener { public interface ProductListener {
void onUpdate(ProductModels product); void onUpdate(ProductModels product);
void onDelete(ProductModels product); void onDelete(ProductModels product, int position);
void onAddCart(ProductModels product); void onAddCart(ProductModels product);
} }
...@@ -149,7 +150,12 @@ public class ProductAdapter extends RecyclerView.Adapter<ProductAdapter.MyViewHo ...@@ -149,7 +150,12 @@ public class ProductAdapter extends RecyclerView.Adapter<ProductAdapter.MyViewHo
} }
}); });
binding.btnDelete.setOnClickListener(view -> listener.onDelete(products)); binding.btnDelete.setOnClickListener(view -> {
Log.i("position", "bindData: "+getAdapterPosition());
listener.onDelete(products, getAdapterPosition());
});
binding.btnEdit.setOnClickListener(view -> listener.onUpdate(products));
} }
} }
} }
package com.yono.messeripos.api.service; package com.yono.messeripos.api.service;
import com.yono.messeripos.api.ApiHelper; import com.yono.messeripos.api.ApiHelper;
import com.yono.messeripos.models.PaymentsModels;
import com.yono.messeripos.response.DataResponse;
import retrofit2.Call; import retrofit2.Call;
import retrofit2.http.Body;
import retrofit2.http.POST; import retrofit2.http.POST;
public interface PaymentService { public interface PaymentService {
// @POST(ApiHelper.VERSI_API_1+"payment") @POST(ApiHelper.VERSI_API_1+"payment")
// Call Call<DataResponse<PaymentsModels>> postFromCart(@Body PaymentsModels paymentsModels);
} }
...@@ -11,6 +11,7 @@ import java.util.List; ...@@ -11,6 +11,7 @@ import java.util.List;
import okhttp3.MultipartBody; import okhttp3.MultipartBody;
import okhttp3.RequestBody; import okhttp3.RequestBody;
import retrofit2.Call; import retrofit2.Call;
import retrofit2.http.Body;
import retrofit2.http.DELETE; import retrofit2.http.DELETE;
import retrofit2.http.GET; import retrofit2.http.GET;
import retrofit2.http.Multipart; import retrofit2.http.Multipart;
...@@ -19,21 +20,15 @@ import retrofit2.http.Part; ...@@ -19,21 +20,15 @@ import retrofit2.http.Part;
import retrofit2.http.Path; import retrofit2.http.Path;
public interface ProductService { public interface ProductService {
@GET(ApiHelper.VERSI_API_1+"product-categories") @GET(ApiHelper.VERSI_API_1+"products")
Call<DataResponse<List<ProductModels<CategoryModels>>>> getProducts(); Call<DataResponse<List<ProductModels<CategoryModels>>>> getProducts();
@DELETE(ApiHelper.VERSI_API_1+"product/{id}") @DELETE(ApiHelper.VERSI_API_1+"product/{id}")
Call<DataResponse<ProductModels>> deleteProducts(@Path("id") int id); Call<DataResponse<ProductModels>> deleteProducts(@Path("id") int id);
@Multipart
@POST(ApiHelper.VERSI_API_1+"product") @POST(ApiHelper.VERSI_API_1+"product")
Call<HashMap<String, Object>> postProduct( Call<DataResponse<ProductModels>> postProduct(@Body ProductModels productModels);
@Part MultipartBody.Part image,
@Part("name") RequestBody name,
@Part("price") RequestBody price,
@Part("stock") RequestBody stock,
@Part("category_id") RequestBody category_id
);
@Multipart @Multipart
@POST(ApiHelper.VERSI_API_1+"product") @POST(ApiHelper.VERSI_API_1+"product")
......
...@@ -39,6 +39,7 @@ public abstract class LocalDatabase extends RoomDatabase { ...@@ -39,6 +39,7 @@ public abstract class LocalDatabase extends RoomDatabase {
return INSTANCE; return INSTANCE;
} }
@NonNull @NonNull
@Override @Override
protected SupportSQLiteOpenHelper createOpenHelper(DatabaseConfiguration config) { protected SupportSQLiteOpenHelper createOpenHelper(DatabaseConfiguration config) {
......
...@@ -152,10 +152,11 @@ public class MainViewModels extends ViewModel { ...@@ -152,10 +152,11 @@ public class MainViewModels extends ViewModel {
private void getProductList() { private void getProductList() {
ProductService productService = client.Client(ProductService.class); ProductService productService = client.Client(ProductService.class);
Log.i("TAG", "getProductList: dari get product");
productService.getProducts().enqueue(new Callback<DataResponse<List<ProductModels<CategoryModels>>>>() { productService.getProducts().enqueue(new Callback<DataResponse<List<ProductModels<CategoryModels>>>>() {
@Override @Override
public void onResponse(Call<DataResponse<List<ProductModels<CategoryModels>>>> call, Response<DataResponse<List<ProductModels<CategoryModels>>>> response) { public void onResponse(Call<DataResponse<List<ProductModels<CategoryModels>>>> call, Response<DataResponse<List<ProductModels<CategoryModels>>>> response) {
Log.i("Get products", "onResponse: "+utils.convertGson(response.body()));
if (response.body() != null){ if (response.body() != null){
productList.setValue(response.body()); productList.setValue(response.body());
}else{ }else{
......
...@@ -8,12 +8,16 @@ import androidx.annotation.NonNull; ...@@ -8,12 +8,16 @@ import androidx.annotation.NonNull;
import androidx.lifecycle.AndroidViewModel; import androidx.lifecycle.AndroidViewModel;
import androidx.lifecycle.LiveData; import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData; import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.Observer;
import androidx.lifecycle.Transformations; import androidx.lifecycle.Transformations;
import androidx.room.Dao;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.yono.messeripos.CartActivity; import com.yono.messeripos.CartActivity;
import com.yono.messeripos.MainActivity;
import com.yono.messeripos.api.client.Client; import com.yono.messeripos.api.client.Client;
import com.yono.messeripos.api.service.OrdersService; import com.yono.messeripos.api.service.OrdersService;
import com.yono.messeripos.api.service.PaymentService;
import com.yono.messeripos.repositories.CartRepositories; import com.yono.messeripos.repositories.CartRepositories;
import com.yono.messeripos.response.DataResponse; import com.yono.messeripos.response.DataResponse;
import com.yono.messeripos.response.OrdersResponse; import com.yono.messeripos.response.OrdersResponse;
...@@ -29,6 +33,7 @@ import static com.yono.messeripos.CartActivity.statusPost; ...@@ -29,6 +33,7 @@ import static com.yono.messeripos.CartActivity.statusPost;
public class MainViewModelsCart extends AndroidViewModel { public class MainViewModelsCart extends AndroidViewModel {
private MutableLiveData<ProductCartModels> cart = new MutableLiveData<>(); private MutableLiveData<ProductCartModels> cart = new MutableLiveData<>();
private LiveData<List<ProductCartModels>> productsLive; private LiveData<List<ProductCartModels>> productsLive;
private Client client;
private CartRepositories cartRepositories; private CartRepositories cartRepositories;
...@@ -44,6 +49,7 @@ public class MainViewModelsCart extends AndroidViewModel { ...@@ -44,6 +49,7 @@ public class MainViewModelsCart extends AndroidViewModel {
cartRepositories = new CartRepositories(application); cartRepositories = new CartRepositories(application);
productsLive = cartRepositories.getDataCart(); productsLive = cartRepositories.getDataCart();
client = new Client();
} }
...@@ -55,6 +61,25 @@ public class MainViewModelsCart extends AndroidViewModel { ...@@ -55,6 +61,25 @@ public class MainViewModelsCart extends AndroidViewModel {
public void updateQtyCart(long qty, long id){cartRepositories.updateQty(qty, id);} public void updateQtyCart(long qty, long id){cartRepositories.updateQty(qty, id);}
public void insertPayments(){
}
public void insertPayments(PaymentsModels paymentsModels){
PaymentService paymentService = client.Client(PaymentService.class);
paymentService.postFromCart(paymentsModels).enqueue(new Callback<DataResponse<PaymentsModels>>() {
@Override
public void onResponse(Call<DataResponse<PaymentsModels>> call, Response<DataResponse<PaymentsModels>> response) {
}
@Override
public void onFailure(Call<DataResponse<PaymentsModels>> call, Throwable t) {
}
});
}
public void insertOrders(OrdersResponse ordersResponse){ public void insertOrders(OrdersResponse ordersResponse){
Client client = new Client(); Client client = new Client();
OrdersService ordersService = client.Client(OrdersService.class); OrdersService ordersService = client.Client(OrdersService.class);
......
package com.yono.messeripos.models; package com.yono.messeripos.models;
import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils; import android.text.TextUtils;
import android.widget.ImageView; import android.widget.ImageView;
...@@ -10,10 +12,12 @@ import com.bumptech.glide.request.RequestOptions; ...@@ -10,10 +12,12 @@ import com.bumptech.glide.request.RequestOptions;
import com.google.gson.annotations.SerializedName; import com.google.gson.annotations.SerializedName;
import com.yono.messeripos.R; import com.yono.messeripos.R;
import com.yono.messeripos.api.ApiHelper; import com.yono.messeripos.api.ApiHelper;
import com.yono.messeripos.utils.Utils;
import java.io.File; import java.io.File;
public class ProductModels<T> { public class ProductModels<T> implements Parcelable {
@SerializedName("id") @SerializedName("id")
private int idProduct; private int idProduct;
...@@ -29,8 +33,28 @@ public class ProductModels<T> { ...@@ -29,8 +33,28 @@ public class ProductModels<T> {
@SerializedName("image") @SerializedName("image")
private String imageProduct; private String imageProduct;
@SerializedName("category") @SerializedName("category_id")
private T categoryProduct; private int categoryProduct;
protected ProductModels(Parcel in) {
idProduct = in.readInt();
productName = in.readString();
priceProduct = in.readInt();
stockProduct = in.readInt();
imageProduct = in.readString();
}
public static final Creator<ProductModels> CREATOR = new Creator<ProductModels>() {
@Override
public ProductModels createFromParcel(Parcel in) {
return new ProductModels(in);
}
@Override
public ProductModels[] newArray(int size) {
return new ProductModels[size];
}
};
public int getIdProduct() { public int getIdProduct() {
return idProduct; return idProduct;
...@@ -64,11 +88,11 @@ public class ProductModels<T> { ...@@ -64,11 +88,11 @@ public class ProductModels<T> {
this.stockProduct = stockProduct; this.stockProduct = stockProduct;
} }
public T getCategoryProduct() { public int getCategoryProduct() {
return categoryProduct; return categoryProduct;
} }
public void setCategoryProduct(T categoryProduct) { public void setCategoryProduct(int categoryProduct) {
this.categoryProduct = categoryProduct; this.categoryProduct = categoryProduct;
} }
...@@ -80,26 +104,50 @@ public class ProductModels<T> { ...@@ -80,26 +104,50 @@ public class ProductModels<T> {
this.imageProduct = imageProduct; this.imageProduct = imageProduct;
} }
public ProductModels() {
}
public ProductModels(String productName, int priceProduct, int stockProduct, String imageProduct) {
this.productName = productName;
this.priceProduct = priceProduct;
this.stockProduct = stockProduct;
this.imageProduct = imageProduct;
}
@BindingAdapter("url") @BindingAdapter("url")
public static void setImage(ImageView view, String url){ public static void setImage(ImageView view, String url){
if (ApiHelper.BASE_URL_IMAGE+url == null){ Utils utils = new Utils();
view.setImageResource(R.drawable.ic_meser); if (TextUtils.isEmpty(url) || url.length() < 1000){
view.setImageResource(R.drawable.ic_meser_create);
}else{ }else{
Glide.with(view) // Glide.with(view)
.applyDefaultRequestOptions(new RequestOptions().placeholder(R.drawable.skeleton).error(R.drawable.skeleton)) // .applyDefaultRequestOptions(new RequestOptions().placeholder(R.drawable.skeleton).error(R.drawable.skeleton))
.load(ApiHelper.BASE_URL_IMAGE+url) // .load(ApiHelper.BASE_URL_IMAGE+url)
.into(view); // .into(view);
view.setImageBitmap(utils.decodeImageBase64(url));
} }
} }
@BindingAdapter("path") @BindingAdapter("path")
public static void setPathImage(ImageView view, String path) { public static void setPathImage(ImageView view, String path) {
Utils utils = new Utils();
if (TextUtils.isEmpty(path)) view.setImageResource(R.drawable.ic_meser_create); if (TextUtils.isEmpty(path)) view.setImageResource(R.drawable.ic_meser_create);
else { else {
File file = new File(path); view.setImageBitmap(utils.decodeImageBase64(path));
if (file.exists()) Glide.with(view).load(file).into(view);
else view.setImageResource(R.drawable.ic_meser_create);
} }
} }
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel parcel, int i) {
parcel.writeInt(idProduct);
parcel.writeString(productName);
parcel.writeInt(priceProduct);
parcel.writeInt(stockProduct);
parcel.writeString(imageProduct);
}
} }
...@@ -4,6 +4,7 @@ import android.app.Application; ...@@ -4,6 +4,7 @@ import android.app.Application;
import android.util.Log; import android.util.Log;
import androidx.lifecycle.LiveData; import androidx.lifecycle.LiveData;
import androidx.room.Dao;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.yono.messeripos.daos.CartDaos; import com.yono.messeripos.daos.CartDaos;
...@@ -19,7 +20,9 @@ public class CartRepositories { ...@@ -19,7 +20,9 @@ public class CartRepositories {
public CartRepositories(Application application){ public CartRepositories(Application application){
LocalDatabase db = LocalDatabase.geDatabase(application); LocalDatabase db = LocalDatabase.geDatabase(application);
cartDaos = db.cartDaos(); cartDaos = db.cartDaos();
products = cartDaos.getCart(); products = cartDaos.getCart();
Log.d("Data cart", "Response "+products); Log.d("Data cart", "Response "+products);
} }
......
package com.yono.messeripos.utils; package com.yono.messeripos.utils;
import android.content.Context; import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.BitmapFactory; import android.graphics.BitmapFactory;
import android.os.Build; import android.os.Build;
...@@ -10,6 +11,7 @@ import android.widget.Toast; ...@@ -10,6 +11,7 @@ import android.widget.Toast;
import androidx.annotation.RequiresApi; import androidx.annotation.RequiresApi;
import androidx.recyclerview.widget.DividerItemDecoration; import androidx.recyclerview.widget.DividerItemDecoration;
import com.bumptech.glide.load.engine.Resource;
import com.google.gson.Gson; import com.google.gson.Gson;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
...@@ -23,6 +25,9 @@ import java.util.Date; ...@@ -23,6 +25,9 @@ import java.util.Date;
import java.util.Locale; import java.util.Locale;
public class Utils { public class Utils {
public long grandTotal = 0;
public String convertPrice(String mataUang, int nilai ){ public String convertPrice(String mataUang, int nilai ){
DecimalFormat rupiah = (DecimalFormat) DecimalFormat.getCurrencyInstance(); DecimalFormat rupiah = (DecimalFormat) DecimalFormat.getCurrencyInstance();
DecimalFormatSymbols format = new DecimalFormatSymbols(); DecimalFormatSymbols format = new DecimalFormatSymbols();
...@@ -92,4 +97,28 @@ public class Utils { ...@@ -92,4 +97,28 @@ public class Utils {
public void toastMessage(Context context, String message){ public void toastMessage(Context context, String message){
Toast.makeText(context, message, Toast.LENGTH_LONG).show(); Toast.makeText(context, message, Toast.LENGTH_LONG).show();
} }
public String convertImageBase64Resource(Resources resource, int id){
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] b = baos.toByteArray();
Bitmap bitmap = BitmapFactory.decodeResource(resource, id);
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);
String encodeImage = Base64.encodeToString(b, Base64.DEFAULT);
return encodeImage;
}
public Bitmap decodeImageBase64(String source){
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] imageBytes = baos.toByteArray();
imageBytes = Base64.decode(source, Base64.DEFAULT);
Bitmap decodeImages = BitmapFactory.decodeByteArray(imageBytes,0,imageBytes.length);
return decodeImages;
}
public long grandTotalCart(){
return grandTotal;
}
} }
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