Commit 67cf5ded authored by Muhammad Suryono's avatar Muhammad Suryono

Update_in _newbranch

parent 2bdd3c75
...@@ -36,6 +36,7 @@ import retrofit2.Callback; ...@@ -36,6 +36,7 @@ import retrofit2.Callback;
import retrofit2.Response; import retrofit2.Response;
import static com.yono.messeripos.MainActivity.CHECKOUT; import static com.yono.messeripos.MainActivity.CHECKOUT;
import static com.yono.messeripos.MainActivity.ORDER_ID;
import static com.yono.messeripos.MainActivity.orderId; import static com.yono.messeripos.MainActivity.orderId;
public class BottomSheets extends BottomSheetDialogFragment { public class BottomSheets extends BottomSheetDialogFragment {
...@@ -48,7 +49,7 @@ public class BottomSheets extends BottomSheetDialogFragment { ...@@ -48,7 +49,7 @@ public class BottomSheets extends BottomSheetDialogFragment {
Client client = new Client(); Client client = new Client();
public static long grossAmount; public static long grossAmount;
SharedPreferences sharedPreferences; SharedPreferences sharedPreferences;
BottomSheetBehavior bottomSheetBehavior; public static BottomSheetBehavior bottomSheetBehavior;
RelativeLayout layoutFormCash; RelativeLayout layoutFormCash;
PaymentsModels paymentsModels; PaymentsModels paymentsModels;
...@@ -80,7 +81,7 @@ public class BottomSheets extends BottomSheetDialogFragment { ...@@ -80,7 +81,7 @@ public class BottomSheets extends BottomSheetDialogFragment {
totalHarga = v.findViewById(R.id.totalHarga); totalHarga = v.findViewById(R.id.totalHarga);
utils = new Utils(); utils = new Utils();
bottomSheetBehavior = BottomSheetBehavior.from(layoutFormCash); bottomSheetBehavior = BottomSheetBehavior.from(layoutFormCash);
// sharedPreferences = getActivity().getSharedPreferences(MainActivity.ORDER_ID, Context.MODE_PRIVATE); sharedPreferences = getActivity().getSharedPreferences(MainActivity.MY_SHARED_PREFERENCES, Context.MODE_PRIVATE);
bottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED); bottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
long ga = paymentsModels.getGrossAmount(); long ga = paymentsModels.getGrossAmount();
String setCurrency = utils.convertPrice("Rp.", ga); String setCurrency = utils.convertPrice("Rp.", ga);
...@@ -147,7 +148,7 @@ public class BottomSheets extends BottomSheetDialogFragment { ...@@ -147,7 +148,7 @@ public class BottomSheets extends BottomSheetDialogFragment {
private void bayar(View view) { private void bayar(View view) {
// String orderId, String paymentType, String bank, long grossAmount // String orderId, String paymentType, String bank, long grossAmount
PaymentsModels paymentsModels = new PaymentsModels( PaymentsModels paymentsModels = new PaymentsModels(
MainActivity.orderId, sharedPreferences.getString(ORDER_ID, ""),
"cash", "cash",
"none", "none",
grossAmount grossAmount
...@@ -157,10 +158,11 @@ public class BottomSheets extends BottomSheetDialogFragment { ...@@ -157,10 +158,11 @@ public class BottomSheets extends BottomSheetDialogFragment {
paymentService.postFromCart(paymentsModels).enqueue(new Callback<DataResponse<PaymentsModels>>() { paymentService.postFromCart(paymentsModels).enqueue(new Callback<DataResponse<PaymentsModels>>() {
@Override @Override
public void onResponse(Call<DataResponse<PaymentsModels>> call, Response<DataResponse<PaymentsModels>> response) { public void onResponse(Call<DataResponse<PaymentsModels>> call, Response<DataResponse<PaymentsModels>> response) {
Log.i("CASH", "onResponse: "+utils.convertGson(response.body()));
if (response.body() != null){ if (response.body() != null){
SharedPreferences.Editor editor = PaymentActivity.sharedPreferences.edit(); SharedPreferences.Editor editor = PaymentActivity.sharedPreferences.edit();
editor.putBoolean(CHECKOUT, false); editor.putBoolean(CHECKOUT, false);
editor.putString(orderId, ""); editor.putString(ORDER_ID, "");
if (editor.commit()){ if (editor.commit()){
Intent i = new Intent(getActivity(), MainActivity.class); Intent i = new Intent(getActivity(), MainActivity.class);
view.getContext().startActivity(i); view.getContext().startActivity(i);
......
...@@ -71,6 +71,7 @@ public class CartActivity extends AppCompatActivity { ...@@ -71,6 +71,7 @@ public class CartActivity extends AppCompatActivity {
Button btnCheckout; Button btnCheckout;
CardView cardView; CardView cardView;
PaymentsModels paymentsModelsIntent; PaymentsModels paymentsModelsIntent;
public static final String CODE_SEND_CHECKOUT_HISTORY = "data_hcheckout_history";
@RequiresApi(api = Build.VERSION_CODES.N) @RequiresApi(api = Build.VERSION_CODES.N)
@Override @Override
...@@ -122,14 +123,17 @@ public class CartActivity extends AppCompatActivity { ...@@ -122,14 +123,17 @@ public class CartActivity extends AppCompatActivity {
Log.i("GET CART", "onCreate: "+paymentsModelsIntent); Log.i("GET CART", "onCreate: "+paymentsModelsIntent);
if (paymentsModelsIntent == null){ if (paymentsModelsIntent == null){
modelsCart = new ViewModelProvider(this).get(MainViewModelsCart.class); modelsCart = new ViewModelProvider(this).get(MainViewModelsCart.class);
modelsCart.getCartById(orderId).observe(this, new Observer<List<ProductCartModels>>() { modelsCart.getCartById(sharedPreferences.getString(ORDER_ID,"")).observe(this, new Observer<List<ProductCartModels>>() {
@Override @Override
public void onChanged(List<ProductCartModels> productCartModels) { public void onChanged(List<ProductCartModels> productCartModels) {
Log.i("TAG", "onChanged: "+utils.convertGson(productCartModels));
if (!productCartModels.isEmpty()) { if (!productCartModels.isEmpty()) {
Log.i("TAG_DALAM", "onChanged: "+sharedPreferences.getString(ORDER_ID, ""));
dataCart = productCartModels; dataCart = productCartModels;
cartAdapter.setCartAdapter(CartActivity.this, productCartModels); cartAdapter.setCartAdapter(CartActivity.this, productCartModels);
recyclerView.setAdapter(cartAdapter); recyclerView.setAdapter(cartAdapter);
}else { }else {
Log.i("TAG_LUAR", "onChanged: "+utils.convertGson(productCartModels));
cartEmptyText.setVisibility(View.VISIBLE); cartEmptyText.setVisibility(View.VISIBLE);
cartEmptyImage.setVisibility(View.VISIBLE); cartEmptyImage.setVisibility(View.VISIBLE);
cardView.setVisibility(View.GONE); cardView.setVisibility(View.GONE);
...@@ -139,38 +143,23 @@ public class CartActivity extends AppCompatActivity { ...@@ -139,38 +143,23 @@ public class CartActivity extends AppCompatActivity {
}); });
}else{ }else{
Log.i("ADA_DATA", "onCreate: "+utils.convertGson(paymentsModelsIntent)); Log.i("ADA_DATA", "onCreate: "+utils.convertGson(paymentsModelsIntent));
Client client = new Client(); modelsCart.getCartById(paymentsModelsIntent.getOrderId()).observe(this, new Observer<List<ProductCartModels>>() {
OrdersService ordersService = client.Client(OrdersService.class);
// modelsCart = new ViewModelProvider(this).get(MainViewModelsCart.class);
// modelsCart.getCartById(paymentsModelsIntent.getOrderId()).observe(this, new Observer<List<ProductCartModels>>() {
// @Override
// public void onChanged(List<ProductCartModels> productCartModels) {
// Log.i("ADA_DATA1", "onCreate: "+utils.convertGson(paymentsModelsIntent.getOrderId()));
// Log.i("ADA_DATA2", "onCreate: "+utils.convertGson(productCartModels));
// if (!productCartModels.isEmpty()) {
// dataCart = productCartModels;
// cartAdapter.setCartAdapter(CartActivity.this, productCartModels);
// recyclerView.setAdapter(cartAdapter);
// }else {
// cartEmptyText.setVisibility(View.VISIBLE);
// cartEmptyImage.setVisibility(View.VISIBLE);
// cardView.setVisibility(View.GONE);
// recyclerView.setVisibility(View.GONE);
// }
// }
// });
ordersService.getOrdersProductById(paymentsModelsIntent.getOrderId()).enqueue(new Callback<DataResponse<OrdersResponse<List<ProductModels>>>>() {
@Override @Override
public void onResponse(Call<DataResponse<OrdersResponse<List<ProductModels>>>> call, Response<DataResponse<OrdersResponse<List<ProductModels>>>> response) { public void onChanged(List<ProductCartModels> productCartModels) {
Log.i("TAG", "onResponse: "+utils.convertGson(response.body().getData())); if (!productCartModels.isEmpty()) {
dataCart = productCartModels;
cartAdapter.setCartAdapter(CartActivity.this, productCartModels);
recyclerView.setAdapter(cartAdapter);
}else {
cartEmptyText.setVisibility(View.VISIBLE);
cartEmptyImage.setVisibility(View.VISIBLE);
cardView.setVisibility(View.GONE);
recyclerView.setVisibility(View.GONE);
} }
@Override
public void onFailure(Call<DataResponse<OrdersResponse<List<ProductModels>>>> call, Throwable t) {
Log.e("error", "onFailure: "+t.getMessage(),t );
} }
}); });
} }
...@@ -221,10 +210,16 @@ public class CartActivity extends AppCompatActivity { ...@@ -221,10 +210,16 @@ public class CartActivity extends AppCompatActivity {
SharedPreferences.Editor editor = sharedPreferences.edit(); SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putBoolean(MainActivity.CHECKOUT, true); editor.putBoolean(MainActivity.CHECKOUT, true);
if(editor.commit()){ if(editor.commit()){
Log.i("FROM_CHECKOUT_INTENT", "onClick: "+utils.convertGson(paymentsModelsIntent));
if (paymentsModelsIntent != null){
startActivity(new Intent(CartActivity.this, PaymentActivity.class)
.putExtra(CODE_SEND_CHECKOUT_HISTORY, paymentsModelsIntent));
}else{
startActivity(new Intent(CartActivity.this, PaymentActivity.class)); startActivity(new Intent(CartActivity.this, PaymentActivity.class));
finish(); finish();
} }
} }
}
}); });
} }
...@@ -242,9 +237,10 @@ public class CartActivity extends AppCompatActivity { ...@@ -242,9 +237,10 @@ public class CartActivity extends AppCompatActivity {
grossAmount = grossAmount + (pd.getQuantity_orders()*pd.getPrice_orders()); grossAmount = grossAmount + (pd.getQuantity_orders()*pd.getPrice_orders());
paymentsModels.setGrossAmount(grossAmount); paymentsModels.setGrossAmount(grossAmount);
} }
Log.i("ORDER_ID_SAVE", "onCreate: "+sharedPreferences.getString(ORDER_ID,"").toString());
paymentsModels.setBank(""); paymentsModels.setBank("");
paymentsModels.setPaymentType("pending"); paymentsModels.setPaymentType("pending");
paymentsModels.setOrderId(orderId); paymentsModels.setOrderId(sharedPreferences.getString(ORDER_ID, ""));
paymentsModels.setTransactionStatus("pending"); paymentsModels.setTransactionStatus("pending");
Log.i("Convert Input", "onChanged: "+utils.convertGson(paymentsModels)); Log.i("Convert Input", "onChanged: "+utils.convertGson(paymentsModels));
PaymentService paymentService = client.Client(PaymentService.class); PaymentService paymentService = client.Client(PaymentService.class);
......
...@@ -7,10 +7,15 @@ import android.view.ViewGroup; ...@@ -7,10 +7,15 @@ import android.view.ViewGroup;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.lifecycle.ViewModelProvider;
import com.google.android.material.bottomsheet.BottomSheetDialogFragment; import com.google.android.material.bottomsheet.BottomSheetDialogFragment;
import com.yono.messeripos.models.MainViewModels;
import com.yono.messeripos.models.MainViewModelsCart;
public class FormCategory extends BottomSheetDialogFragment { public class FormCategory extends BottomSheetDialogFragment {
MainViewModels mainViewModels;
public FormCategory() { public FormCategory() {
} }
...@@ -21,6 +26,9 @@ public class FormCategory extends BottomSheetDialogFragment { ...@@ -21,6 +26,9 @@ public class FormCategory extends BottomSheetDialogFragment {
View v = inflater.inflate(R.layout.form_category, View v = inflater.inflate(R.layout.form_category,
container, false); container, false);
mainViewModels = new ViewModelProvider(getActivity()).get(MainViewModels.class);
return v; return v;
} }
} }
...@@ -69,6 +69,7 @@ public class FormProductActivity extends AppCompatActivity { ...@@ -69,6 +69,7 @@ public class FormProductActivity extends AppCompatActivity {
ProgressDialog progressDialog; ProgressDialog progressDialog;
Client client = new Client(); Client client = new Client();
ProductModels productModelsIntent; ProductModels productModelsIntent;
List<String> categorySelect = new ArrayList<>();
@Override @Override
public void onCreate(@Nullable Bundle savedInstanceState) { public void onCreate(@Nullable Bundle savedInstanceState) {
...@@ -118,13 +119,13 @@ public class FormProductActivity extends AppCompatActivity { ...@@ -118,13 +119,13 @@ public class FormProductActivity extends AppCompatActivity {
binding.cvProduct.setOnClickListener(view -> openFile()); binding.cvProduct.setOnClickListener(view -> openFile());
binding.btnAdd.setOnClickListener(view -> saveProduct()); binding.btnAdd.setOnClickListener(view -> saveProduct());
binding.btnAddCategory.setOnClickListener(view -> addCategory());
//spinner //spinner
categoryModels = new ArrayList<>(); categoryModels = new ArrayList<>();
categoryModels.add("SELECT CATEGORY"); categoryModels.add("SELECT CATEGORY");
setSpinner(); setSpinner();
setSelectedSpinner(); setSelectedSpinner();
addCategory();
} }
private void addCategory() { private void addCategory() {
...@@ -137,19 +138,7 @@ public class FormProductActivity extends AppCompatActivity { ...@@ -137,19 +138,7 @@ public class FormProductActivity extends AppCompatActivity {
binding.listCategory.setOnItemSelectedListener(new MaterialSpinner.OnItemSelectedListener() { binding.listCategory.setOnItemSelectedListener(new MaterialSpinner.OnItemSelectedListener() {
@Override @Override
public void onItemSelected(MaterialSpinner view, int position, long id, Object item) { public void onItemSelected(MaterialSpinner view, int position, long id, Object item) {
utils.toastMessage(FormProductActivity.this, ""+position); categorySelect.add(item.toString());
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();
}
}
}
});
} }
}); });
} }
...@@ -174,7 +163,7 @@ public class FormProductActivity extends AppCompatActivity { ...@@ -174,7 +163,7 @@ public class FormProductActivity extends AppCompatActivity {
productModels.setProductName(binding.etName.getText().toString()); productModels.setProductName(binding.etName.getText().toString());
productModels.setPriceProduct(Integer.parseInt(binding.etPrice.getText().toString())); productModels.setPriceProduct(Integer.parseInt(binding.etPrice.getText().toString()));
productModels.setStockProduct(Integer.parseInt(binding.etStock.getText().toString())); productModels.setStockProduct(Integer.parseInt(binding.etStock.getText().toString()));
productModels.setCategoryProduct(binding.listCategory.getSelectedIndex()); productModels.setCategoryProduct(getCategory(categoryModels.get(0)));
if (isUpdate){ if (isUpdate){
...@@ -271,6 +260,10 @@ public class FormProductActivity extends AppCompatActivity { ...@@ -271,6 +260,10 @@ public class FormProductActivity extends AppCompatActivity {
} }
} }
private int getCategory(String s) {
return 1;
}
private void openFile(){ private void openFile(){
requestPermissions(permissions, REQUEST_PERMISSIONS); requestPermissions(permissions, REQUEST_PERMISSIONS);
Intent i = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI); Intent i = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
......
...@@ -85,11 +85,13 @@ public class HistoryActivity extends AppCompatActivity { ...@@ -85,11 +85,13 @@ public class HistoryActivity extends AppCompatActivity {
transactionAdapter.setListener(new TransactionAdapter.TransactionListener() { transactionAdapter.setListener(new TransactionAdapter.TransactionListener() {
@Override @Override
public void onShowDetail(PaymentsModels paymentsModels) { public void onShowDetail(PaymentsModels paymentsModels) {
if (paymentsModels.getPaymentType().equals("bank_transfer") && paymentsModels.getTransactionStatus().equals("settlement")){ if (paymentsModels.getPaymentType().equals("bank_transfer")
&& paymentsModels.getTransactionStatus().equals("settlement")){
new AlertDialog.Builder(HistoryActivity.this) new AlertDialog.Builder(HistoryActivity.this)
.setTitle("Transaction") .setTitle("Transaction")
.setMessage("Transaction success!").show(); .setMessage("Transaction success!").show();
}else if (paymentsModels.getPaymentType().equals("bank_transfer") && paymentsModels.getTransactionStatus().equals("pending")){ }else if (paymentsModels.getPaymentType().equals("bank_transfer")
&& paymentsModels.getTransactionStatus().equals("pending")){
new AlertDialog.Builder(HistoryActivity.this) new AlertDialog.Builder(HistoryActivity.this)
.setTitle("Transaction") .setTitle("Transaction")
.setMessage("Waiting payment!").show(); .setMessage("Waiting payment!").show();
......
...@@ -77,7 +77,7 @@ public class MainActivity extends AppCompatActivity { ...@@ -77,7 +77,7 @@ public class MainActivity extends AppCompatActivity {
Client client = new Client(); Client client = new Client();
public static ArrayList<ProductModels> productModelsArrayList = new ArrayList<>(); public static ArrayList<ProductModels> productModelsArrayList = new ArrayList<>();
public static final String DATA_PRODUCT = "DATA_PRODUCT"; public static final String DATA_PRODUCT = "DATA_PRODUCT";
public static final String MY_SHARED_PREFERENCES = "my_shared_preferences"; public static final String MY_SHARED_PREFERENCES = "main_sahred";
ProgressDialog progressDialog; ProgressDialog progressDialog;
MaterialButton btnAddCart; MaterialButton btnAddCart;
SkeletonScreen skeletonCategory; SkeletonScreen skeletonCategory;
...@@ -107,7 +107,7 @@ public class MainActivity extends AppCompatActivity { ...@@ -107,7 +107,7 @@ public class MainActivity extends AppCompatActivity {
orderId = sharedPreferences.getString(ORDER_ID,""); orderId = sharedPreferences.getString(ORDER_ID,"");
progressDialog = new ProgressDialog(MainActivity.this); progressDialog = new ProgressDialog(MainActivity.this);
progressDialog.setMessage("Loading..."); progressDialog.setMessage("Loading...");
Log.i("ORDER ID", "onCreate: "+orderId); Log.i("ORDER ID", "onCreate: "+sharedPreferences.getString(ORDER_ID,"").toString());
toolbar = findViewById(R.id.topAppBar); toolbar = findViewById(R.id.topAppBar);
mainViewModels = ViewModelProviders.of(this).get(MainViewModels.class); mainViewModels = ViewModelProviders.of(this).get(MainViewModels.class);
...@@ -116,7 +116,8 @@ public class MainActivity extends AppCompatActivity { ...@@ -116,7 +116,8 @@ public class MainActivity extends AppCompatActivity {
SharedPreferences.Editor editor = sharedPreferences.edit(); SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString(ORDER_ID,"MES-ORDER"+utils.timeStamp()); editor.putString(ORDER_ID,"MES-ORDER"+utils.timeStamp());
if (editor.commit()){ if (editor.commit()){
// Toast.makeText(MainActivity.this, orderId, Toast.LENGTH_LONG).show(); Log.i("ORDER ID", "onCreate: "+sharedPreferences.getString(ORDER_ID,"").toString());
Toast.makeText(MainActivity.this, sharedPreferences.getString(ORDER_ID,"").toString(), Toast.LENGTH_LONG).show();
} }
} }
...@@ -149,8 +150,8 @@ public class MainActivity extends AppCompatActivity { ...@@ -149,8 +150,8 @@ public class MainActivity extends AppCompatActivity {
}else if (id == R.id.update){ }else if (id == R.id.update){
status_update = true; status_update = true;
// binding.topAppBar.setVisibility(View.GONE); // binding.topAppBar.setVisibility(View.GONE);
binding.tvCategory.setVisibility(View.GONE); // binding.tvCategory.setVisibility(View.GONE);
binding.rvCategory.setVisibility(View.GONE); // binding.rvCategory.setVisibility(View.GONE);
// binding.appBarUpdate.setVisibility(View.VISIBLE); // binding.appBarUpdate.setVisibility(View.VISIBLE);
MaterialToolbar toolbars = findViewById(R.id.topAppBar); MaterialToolbar toolbars = findViewById(R.id.topAppBar);
...@@ -161,6 +162,7 @@ public class MainActivity extends AppCompatActivity { ...@@ -161,6 +162,7 @@ public class MainActivity extends AppCompatActivity {
toolbars.setNavigationOnClickListener(view -> updateFinish()); toolbars.setNavigationOnClickListener(view -> updateFinish());
productAdapter.notifyDataSetChanged(); productAdapter.notifyDataSetChanged();
categoryAdapter.notifyDataSetChanged();
}else if (id == R.id.create) { }else if (id == R.id.create) {
startActivity(new Intent(getApplicationContext(), FormProductActivity.class)); startActivity(new Intent(getApplicationContext(), FormProductActivity.class));
}else if (id == R.id.allTransaction){ }else if (id == R.id.allTransaction){
...@@ -398,6 +400,16 @@ public class MainActivity extends AppCompatActivity { ...@@ -398,6 +400,16 @@ public class MainActivity extends AppCompatActivity {
}); });
} }
} }
@Override
public void onUpdateCategory(CategoryModels categoryModels) {
}
@Override
public void onDeleteCategory(CategoryModels categoryModels) {
}
}); });
} }
......
...@@ -69,6 +69,7 @@ public class PaymentActivity extends AppCompatActivity { ...@@ -69,6 +69,7 @@ public class PaymentActivity extends AppCompatActivity {
ProgressDialog progressDialog; ProgressDialog progressDialog;
BottomSheetBehavior bottomSheetBank; BottomSheetBehavior bottomSheetBank;
RelativeLayout qrcodeLayoutBank; RelativeLayout qrcodeLayoutBank;
PaymentsModels paymentsModelsIntent;
...@@ -83,13 +84,12 @@ public class PaymentActivity extends AppCompatActivity { ...@@ -83,13 +84,12 @@ public class PaymentActivity extends AppCompatActivity {
} }
sharedPreferences = getSharedPreferences(MainActivity.MY_SHARED_PREFERENCES, Context.MODE_PRIVATE); sharedPreferences = getSharedPreferences(MainActivity.MY_SHARED_PREFERENCES, Context.MODE_PRIVATE);
paymentsModelsIntent = getIntent().getParcelableExtra(CartActivity.CODE_SEND_CHECKOUT_HISTORY);
paymentsModels = new PaymentsModels(); paymentsModels = new PaymentsModels();
checkoutAdapter = new CheckoutAdapter(); checkoutAdapter = new CheckoutAdapter();
recyclerView = findViewById(R.id.rvItem); recyclerView = findViewById(R.id.rvItem);
grandTotal = findViewById(R.id.grand_total); grandTotal = findViewById(R.id.grand_total);
qrcodeLayoutBank = findViewById(R.id.qrCodeForm);
bottomSheetBank = BottomSheetBehavior.from(qrcodeLayoutBank);
progressDialog = new ProgressDialog(PaymentActivity.this); progressDialog = new ProgressDialog(PaymentActivity.this);
progressDialog.setMessage("Loading..."); progressDialog.setMessage("Loading...");
progressDialog.setCancelable(false); progressDialog.setCancelable(false);
...@@ -98,7 +98,11 @@ public class PaymentActivity extends AppCompatActivity { ...@@ -98,7 +98,11 @@ public class PaymentActivity extends AppCompatActivity {
setSupportActionBar(toolbars); setSupportActionBar(toolbars);
DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(this, DividerItemDecoration.VERTICAL); DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(this, DividerItemDecoration.VERTICAL);
mainViewModels = new ViewModelProvider(PaymentActivity.this).get(MainViewModelsCart.class); mainViewModels = new ViewModelProvider(PaymentActivity.this).get(MainViewModelsCart.class);
mainViewModels.getCartById(orderId).observe(this, new Observer<List<ProductCartModels>>() {
Log.i("IN_HISTORY", "onCreate: "+utils.convertGson(paymentsModelsIntent));
if (paymentsModelsIntent == null){
mainViewModels.getCartById(sharedPreferences.getString(ORDER_ID, "")).observe(this, new Observer<List<ProductCartModels>>() {
@Override @Override
public void onChanged(List<ProductCartModels> productCartModels) { public void onChanged(List<ProductCartModels> productCartModels) {
String js = new Gson().toJson(productCartModels); String js = new Gson().toJson(productCartModels);
...@@ -108,6 +112,7 @@ public class PaymentActivity extends AppCompatActivity { ...@@ -108,6 +112,7 @@ public class PaymentActivity extends AppCompatActivity {
total = total + pd.getPrice_orders()*pd.getQuantity_orders(); total = total + pd.getPrice_orders()*pd.getQuantity_orders();
} }
if (productCartModels.size() !=0){
getSupportActionBar().setTitle(productCartModels.get(0).getId_orders()); getSupportActionBar().setTitle(productCartModels.get(0).getId_orders());
paymentsModels.setOrderId(productCartModels.get(0).getId_orders()); paymentsModels.setOrderId(productCartModels.get(0).getId_orders());
paymentsModels.setGrossAmount(total); paymentsModels.setGrossAmount(total);
...@@ -117,10 +122,35 @@ public class PaymentActivity extends AppCompatActivity { ...@@ -117,10 +122,35 @@ public class PaymentActivity extends AppCompatActivity {
recyclerView.addItemDecoration(dividerItemDecoration); recyclerView.addItemDecoration(dividerItemDecoration);
grandTotal.setText(utils.convertPrice("Rp. ", total)); grandTotal.setText(utils.convertPrice("Rp. ", total));
} }
}
}); });
}else{
mainViewModels.getCartById(paymentsModelsIntent.getOrderId()).observe(this, new Observer<List<ProductCartModels>>() {
@Override
public void onChanged(List<ProductCartModels> productCartModels) {
String js = new Gson().toJson(productCartModels);
Log.i("On Intent_CHANGE", "onChanged: "+paymentsModels.getOrderId());
bottomSheet = new BottomSheets(paymentsModels); for (ProductCartModels pd : productCartModels){
total = total + pd.getPrice_orders()*pd.getQuantity_orders();
}
if (productCartModels.size() != 0){
getSupportActionBar().setTitle(productCartModels.get(0).getId_orders());
paymentsModels.setOrderId(productCartModels.get(0).getId_orders());
paymentsModels.setGrossAmount(total);
checkoutAdapter.setCheckoutAdapter(PaymentActivity.this, productCartModels);
recyclerView.setLayoutManager(new LinearLayoutManager(PaymentActivity.this, RecyclerView.VERTICAL, false));
recyclerView.setAdapter(checkoutAdapter);
recyclerView.addItemDecoration(dividerItemDecoration);
grandTotal.setText(utils.convertPrice("Rp. ", total));
}
}
});
}
bottomSheet = new BottomSheets(paymentsModels);
RecyclerView rvPayment = findViewById(R.id.rvPayment); RecyclerView rvPayment = findViewById(R.id.rvPayment);
...@@ -143,34 +173,6 @@ public class PaymentActivity extends AppCompatActivity { ...@@ -143,34 +173,6 @@ public class PaymentActivity extends AppCompatActivity {
}); });
bottomSheetBank.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
@Override
public void onStateChanged(@NonNull View bottomSheet, int newState) {
switch (newState) {
case BottomSheetBehavior.STATE_HIDDEN:
break;
case BottomSheetBehavior.STATE_EXPANDED:
break;
case BottomSheetBehavior.STATE_COLLAPSED:
break;
case BottomSheetBehavior.STATE_DRAGGING:
break;
case BottomSheetBehavior.STATE_SETTLING:
break;
}
}
@Override
public void onSlide(@NonNull View bottomSheet, float slideOffset) {
if (bottomSheetBank.getState() != BottomSheetBehavior.STATE_EXPANDED) {
bottomSheetBank.setState(BottomSheetBehavior.STATE_EXPANDED);
} else {
bottomSheetBank.setState(BottomSheetBehavior.STATE_COLLAPSED);
}
}
});
btnPay.setOnClickListener(new View.OnClickListener() { btnPay.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
...@@ -179,10 +181,11 @@ public class PaymentActivity extends AppCompatActivity { ...@@ -179,10 +181,11 @@ public class PaymentActivity extends AppCompatActivity {
Log.i("CASH", "onClick: "+utils.convertGson(paymentsModels)); Log.i("CASH", "onClick: "+utils.convertGson(paymentsModels));
bottomSheet = new BottomSheets(paymentsModels); bottomSheet = new BottomSheets(paymentsModels);
bottomSheet.setCancelable(false);
bottomSheet.show(getSupportFragmentManager(), bottomSheet.show(getSupportFragmentManager(),
"ModalBottomSheet"); "ModalBottomSheet");
}else{ }else{
bottomSheetBank.setState(BottomSheetBehavior.STATE_EXPANDED); // bottomSheetBank.setState(BottomSheetBehavior.STATE_EXPANDED);
// progressDialog.show(); // progressDialog.show();
// Client client = new Client(); // Client client = new Client();
// paymentsModels.setPaymentType("bank_transfer"); // paymentsModels.setPaymentType("bank_transfer");
......
...@@ -10,6 +10,7 @@ import androidx.annotation.NonNull; ...@@ -10,6 +10,7 @@ import androidx.annotation.NonNull;
import androidx.databinding.DataBindingUtil; import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
import com.yono.messeripos.MainActivity;
import com.yono.messeripos.R; import com.yono.messeripos.R;
import com.yono.messeripos.databinding.ItemCategoryBinding; import com.yono.messeripos.databinding.ItemCategoryBinding;
import com.yono.messeripos.models.CategoryModels; import com.yono.messeripos.models.CategoryModels;
...@@ -24,6 +25,10 @@ public class CategoryAdapter extends RecyclerView.Adapter<CategoryAdapter.MyView ...@@ -24,6 +25,10 @@ public class CategoryAdapter extends RecyclerView.Adapter<CategoryAdapter.MyView
public interface CategoryListener { public interface CategoryListener {
void onGetProduct(CategoryModels categoryModels); void onGetProduct(CategoryModels categoryModels);
void onUpdateCategory(CategoryModels categoryModels);
void onDeleteCategory(CategoryModels categoryModels);
} }
private CategoryListener listener; private CategoryListener listener;
...@@ -73,6 +78,21 @@ public class CategoryAdapter extends RecyclerView.Adapter<CategoryAdapter.MyView ...@@ -73,6 +78,21 @@ public class CategoryAdapter extends RecyclerView.Adapter<CategoryAdapter.MyView
binding.setCategory(categoryModels); binding.setCategory(categoryModels);
binding.cvCategory.setOnClickListener(view -> listener.onGetProduct(categoryModels)); binding.cvCategory.setOnClickListener(view -> listener.onGetProduct(categoryModels));
binding.categoryDelete.setOnClickListener(view -> listener.onDeleteCategory(categoryModels));
binding.categoryUpdate.setOnClickListener(view -> listener.onUpdateCategory(categoryModels));
if (!MainActivity.status_update) {
binding.categoryDelete.setVisibility(View.GONE);
binding.categoryUpdate.setVisibility(View.GONE);
}else{
if (getAdapterPosition() == 0){
binding.categoryUpdate.setVisibility(View.GONE);
binding.categoryDelete.setVisibility(View.GONE);
}else{
binding.categoryUpdate.setVisibility(View.VISIBLE);
binding.categoryDelete.setVisibility(View.VISIBLE);
}
}
} }
} }
} }
...@@ -8,7 +8,9 @@ import com.yono.messeripos.response.DataResponse; ...@@ -8,7 +8,9 @@ import com.yono.messeripos.response.DataResponse;
import java.util.List; import java.util.List;
import retrofit2.Call; import retrofit2.Call;
import retrofit2.http.Body;
import retrofit2.http.GET; import retrofit2.http.GET;
import retrofit2.http.POST;
import retrofit2.http.Path; import retrofit2.http.Path;
import retrofit2.http.Query; import retrofit2.http.Query;
...@@ -18,4 +20,7 @@ public interface CategoryServise { ...@@ -18,4 +20,7 @@ public interface CategoryServise {
@GET(ApiHelper.VERSI_API_1+"product-category-id/{id}") @GET(ApiHelper.VERSI_API_1+"product-category-id/{id}")
Call<DataResponse<List<ProductModels>>> getCategoryById(@Path("id") int id); Call<DataResponse<List<ProductModels>>> getCategoryById(@Path("id") int id);
@POST(ApiHelper.VERSI_API_1+"category")
Call<DataResponse<CategoryModels>> addCategory(@Body CategoryModels categoryModels);
} }
...@@ -19,5 +19,5 @@ public interface OrdersService { ...@@ -19,5 +19,5 @@ public interface OrdersService {
Call<DataResponse> postOrders(@Body OrdersResponse cartPost); Call<DataResponse> postOrders(@Body OrdersResponse cartPost);
@GET(ApiHelper.VERSI_API_1+"order-products/{id}") @GET(ApiHelper.VERSI_API_1+"order-products/{id}")
Call<DataResponse<OrdersResponse<List<ProductModels>>>> getOrdersProductById(@Path("id") String id); Call<DataResponse<List<ProductModels>>> getOrdersProductById(@Path("id") String id);
} }
...@@ -54,6 +54,10 @@ public class MainViewModels extends ViewModel { ...@@ -54,6 +54,10 @@ public class MainViewModels extends ViewModel {
return categoryList; return categoryList;
} }
public void postCategory(CategoryModels categoryModels){
saveCategory(categoryModels);
}
public LiveData<DataResponse<List<ProductModels>>> getProductByCategory(int id){ public LiveData<DataResponse<List<ProductModels>>> getProductByCategory(int id){
getDataProductByCategory(id); getDataProductByCategory(id);
return productByCategory; return productByCategory;
...@@ -64,6 +68,22 @@ public class MainViewModels extends ViewModel { ...@@ -64,6 +68,22 @@ public class MainViewModels extends ViewModel {
return transactions; return transactions;
} }
private void saveCategory(CategoryModels categoryModels) {
CategoryServise categoryServise = client.Client(CategoryServise.class);
categoryServise.addCategory(categoryModels).enqueue(new Callback<DataResponse<CategoryModels>>() {
@Override
public void onResponse(Call<DataResponse<CategoryModels>> call, Response<DataResponse<CategoryModels>> response) {
Log.i("Add Categiry", "onResponse: "+utils.convertGson(response.body()));
}
@Override
public void onFailure(Call<DataResponse<CategoryModels>> call, Throwable t) {
Log.e("error add", "onFailure: ",t );
}
});
}
public void deleteProducts(int id){ public void deleteProducts(int id){
ProductService productService = client.Client(ProductService.class); ProductService productService = client.Client(ProductService.class);
productService.deleteProducts(id).enqueue(new Callback<DataResponse<ProductModels>>() { productService.deleteProducts(id).enqueue(new Callback<DataResponse<ProductModels>>() {
......
...@@ -11,9 +11,6 @@ ...@@ -11,9 +11,6 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:gravity="center_horizontal" android:gravity="center_horizontal"
android:orientation="vertical" android:orientation="vertical"
app:behavior_hideable="true"
app:behavior_peekHeight="56dp"
app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior"
style="@style/AppModalStyle" style="@style/AppModalStyle"
android:padding="16dp"> android:padding="16dp">
......
...@@ -87,5 +87,4 @@ ...@@ -87,5 +87,4 @@
</RelativeLayout> </RelativeLayout>
<include layout="@layout/activity_q_r_code"/>
</androidx.coordinatorlayout.widget.CoordinatorLayout> </androidx.coordinatorlayout.widget.CoordinatorLayout>
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="380dp" android:layout_height="wrap_content"
app:behavior_hideable="true" app:behavior_hideable="true"
app:behavior_peekHeight="56dp" app:behavior_peekHeight="56dp"
android:background="#efefef" android:background="#efefef"
...@@ -26,6 +26,8 @@ ...@@ -26,6 +26,8 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="Va_Text" android:text="Va_Text"
android:textSize="20sp"
android:textStyle="bold"
android:layout_below="@id/qr_image" android:layout_below="@id/qr_image"
android:layout_centerInParent="true" android:layout_centerInParent="true"
/> />
......
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_below="@id/tvAddCategory" android:layout_below="@id/tvAddCategory"
android:hint="Category Name" android:hint="Category Name"
android:inputType="number" android:inputType="text"
android:imeOptions="actionDone"/> android:imeOptions="actionDone"/>
<Button <Button
......
...@@ -12,7 +12,6 @@ ...@@ -12,7 +12,6 @@
<androidx.constraintlayout.widget.ConstraintLayout <androidx.constraintlayout.widget.ConstraintLayout
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:paddingVertical="10dp"
android:layout_marginHorizontal="3dp"> android:layout_marginHorizontal="3dp">
<com.google.android.material.card.MaterialCardView <com.google.android.material.card.MaterialCardView
...@@ -26,7 +25,6 @@ ...@@ -26,7 +25,6 @@
android:clipToPadding="true" android:clipToPadding="true"
android:background="@drawable/ic_rounded_circle" android:background="@drawable/ic_rounded_circle"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"> app:layout_constraintEnd_toEndOf="parent">
...@@ -58,6 +56,30 @@ ...@@ -58,6 +56,30 @@
</RelativeLayout> </RelativeLayout>
</com.google.android.material.card.MaterialCardView> </com.google.android.material.card.MaterialCardView>
<com.google.android.material.button.MaterialButton
android:id="@+id/categoryDelete"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="DELETE"
android:textSize="10sp"
android:textAlignment="textStart"
app:layout_constraintTop_toBottomOf="@id/cvCategory"
android:backgroundTint="@android:color/holo_red_dark"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"/>
<com.google.android.material.button.MaterialButton
android:id="@+id/categoryUpdate"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="UPDATE"
android:textSize="10sp"
android:textAlignment="textEnd"
app:layout_constraintTop_toBottomOf="@id/cvCategory"
android:backgroundTint="@color/colorGreen"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
</layout> </layout>
...@@ -66,7 +66,7 @@ ...@@ -66,7 +66,7 @@
android:layout_marginEnd="10dp" android:layout_marginEnd="10dp"
app:layout_constraintBottom_toTopOf="@id/btnDelete" app:layout_constraintBottom_toTopOf="@id/btnDelete"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
android:backgroundTint="#4CAF50" android:backgroundTint="@color/colorGreen"
android:text="UPDATE"/> android:text="UPDATE"/>
<TextView <TextView
......
...@@ -11,4 +11,5 @@ ...@@ -11,4 +11,5 @@
<color name="badge_available">#9DED87</color> <color name="badge_available">#9DED87</color>
<color name="colorLine">#dfdfdf</color> <color name="colorLine">#dfdfdf</color>
<color name="colorRed">#F81A1A</color> <color name="colorRed">#F81A1A</color>
<color name="colorGreen">#4CAF50</color>
</resources> </resources>
\ No newline at end of file
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