Commit e3c02909 authored by Muhammad Suryono's avatar Muhammad Suryono

Fix payment

parent d0f84c04
<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" />
......
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="JDK" project-jdk-type="JavaSDK"> <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" /> <output url="file://$PROJECT_DIR$/build/classes" />
</component> </component>
<component name="ProjectType"> <component name="ProjectType">
......
...@@ -6,7 +6,7 @@ android { ...@@ -6,7 +6,7 @@ android {
defaultConfig { defaultConfig {
applicationId "com.yono.messeripos" applicationId "com.yono.messeripos"
minSdkVersion 22 minSdkVersion 23
targetSdkVersion 30 targetSdkVersion 30
versionCode 1 versionCode 1
versionName "1.0" versionName "1.0"
......
...@@ -11,6 +11,7 @@ import android.view.View; ...@@ -11,6 +11,7 @@ import android.view.View;
import android.view.Window; import android.view.Window;
import android.view.WindowManager; import android.view.WindowManager;
import android.widget.Button; import android.widget.Button;
import android.widget.ListView;
import androidx.annotation.RequiresApi; import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
...@@ -59,9 +60,9 @@ public class CartActivity extends AppCompatActivity { ...@@ -59,9 +60,9 @@ public class CartActivity extends AppCompatActivity {
toolbars.setNavigationOnClickListener(view -> onBackPressed()); toolbars.setNavigationOnClickListener(view -> onBackPressed());
recyclerView = findViewById(R.id.rvCart); recyclerView = findViewById(R.id.rvCart);
cartAdapter = new CartAdapter();
btnCheckout = findViewById(R.id.btCheckout); btnCheckout = findViewById(R.id.btCheckout);
cartAdapter = new CartAdapter();
LinearLayoutManager llm = new LinearLayoutManager(this); LinearLayoutManager llm = new LinearLayoutManager(this);
recyclerView.setLayoutManager(llm); recyclerView.setLayoutManager(llm);
...@@ -126,7 +127,7 @@ public class CartActivity extends AppCompatActivity { ...@@ -126,7 +127,7 @@ public class CartActivity extends AppCompatActivity {
SharedPreferences.Editor editor = sharedPreferences.edit(); SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putBoolean(SplashScreen.CHECKOUT, true); editor.putBoolean(MainActivity.CHECKOUT, true);
if(editor.commit()){ if(editor.commit()){
startActivity(new Intent(CartActivity.this, PaymentActivity.class)); startActivity(new Intent(CartActivity.this, PaymentActivity.class));
finish(); finish();
......
package com.yono.messeripos; package com.yono.messeripos;
import android.Manifest;
import android.content.CursorLoader; import android.content.CursorLoader;
import android.content.Intent; import android.content.Intent;
import android.database.Cursor; import android.database.Cursor;
...@@ -61,6 +62,9 @@ public class FormProductActivity extends AppCompatActivity { ...@@ -61,6 +62,9 @@ public class FormProductActivity extends AppCompatActivity {
"Oreo" "Oreo"
}; };
private String[] permissions = new String[]{Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE};
@Override @Override
public void onCreate(@Nullable Bundle savedInstanceState) { public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
...@@ -68,6 +72,7 @@ public class FormProductActivity extends AppCompatActivity { ...@@ -68,6 +72,7 @@ public class FormProductActivity extends AppCompatActivity {
binding.btnAdd.setText("Add New Prooduct"); binding.btnAdd.setText("Add New Prooduct");
productModels = new ProductModels(); productModels = new ProductModels();
requestPermissions(permissions, REQUEST_PERMISSIONS);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
Window w = getWindow(); Window w = getWindow();
......
...@@ -57,23 +57,29 @@ public class MainActivity extends AppCompatActivity { ...@@ -57,23 +57,29 @@ public class MainActivity extends AppCompatActivity {
MainViewModelsCart mainViewModelsCart; MainViewModelsCart mainViewModelsCart;
public static Boolean cartIsEmpty; public static Boolean cartIsEmpty;
SharedPreferences sharedPreferences; SharedPreferences sharedPreferences;
public static final String CHECKOUT = "checkout";
public static Boolean checkout;
public static Boolean selectCategory = false;
@SuppressLint("LongLogTag") @SuppressLint("LongLogTag")
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
binding = DataBindingUtil.setContentView(this, R.layout.activity_main);
ProductAdapter adapter = new ProductAdapter(); ProductAdapter adapter = new ProductAdapter();
binding = DataBindingUtil.setContentView(this, R.layout.activity_main);
binding.rvProduct.setAdapter(adapter); binding.rvProduct.setAdapter(adapter);
binding.appBarUpdate.setVisibility(View.GONE); binding.appBarUpdate.setVisibility(View.GONE);
Log.i("Status Checkout main activity", "onCreate: "+SplashScreen.checkout);
showLoading(true); showLoading(true);
categoryAdapter = new CategoryAdapter(); categoryAdapter = new CategoryAdapter();
productAdapter = new ProductAdapter(); productAdapter = new ProductAdapter();
mainViewModelsCart = new ViewModelProvider(MainActivity.this).get(MainViewModelsCart.class); mainViewModelsCart = new ViewModelProvider(MainActivity.this).get(MainViewModelsCart.class);
sharedPreferences = getSharedPreferences(SplashScreen.MY_SHARED_PREFERENCES, Context.MODE_PRIVATE); sharedPreferences = getSharedPreferences(SplashScreen.MY_SHARED_PREFERENCES, Context.MODE_PRIVATE);
checkout = sharedPreferences.getBoolean(CHECKOUT,false);
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) {
...@@ -81,13 +87,12 @@ public class MainActivity extends AppCompatActivity { ...@@ -81,13 +87,12 @@ public class MainActivity 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);
} }
toolbar = findViewById(R.id.topAppBar);
toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() { toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
@Override @Override
public boolean onMenuItemClick(MenuItem item) { public boolean onMenuItemClick(MenuItem item) {
int id = item.getItemId(); int id = item.getItemId();
if (id == R.id.menu_cart) { if (id == R.id.menu_cart) {
if (SplashScreen.checkout){ if (checkout){
startActivity(new Intent(getApplicationContext(), PaymentActivity.class)); startActivity(new Intent(getApplicationContext(), PaymentActivity.class));
}else{ }else{
startActivity(new Intent(getApplicationContext(), CartActivity.class)); startActivity(new Intent(getApplicationContext(), CartActivity.class));
...@@ -112,15 +117,18 @@ public class MainActivity extends AppCompatActivity { ...@@ -112,15 +117,18 @@ public class MainActivity extends AppCompatActivity {
} }
}); });
mainViewModels = ViewModelProviders.of(this).get(MainViewModels.class);
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) {
if (listDataResponse != null) { if (listDataResponse != null) {
CategoryModels caModels = new CategoryModels();
caModels.setNameCategory("All");
caModels.setIdCategory(0);
List<CategoryModels> categoryModels = listDataResponse.getData(); List<CategoryModels> categoryModels = listDataResponse.getData();
ArrayList<CategoryModels> categoryModelsArrayList = new ArrayList<>(); ArrayList<CategoryModels> categoryModelsArrayList = new ArrayList<>();
categoryModels.add(0,caModels);
categoryModelsArrayList.addAll(categoryModels); categoryModelsArrayList.addAll(categoryModels);
categoryAdapter.setCategoriAdapter(MainActivity.this, categoryModelsArrayList); categoryAdapter.setCategoriAdapter(MainActivity.this, categoryModelsArrayList);
binding.rvCategory.setLayoutManager(new LinearLayoutManager(MainActivity.this, LinearLayoutManager.HORIZONTAL, false)); binding.rvCategory.setLayoutManager(new LinearLayoutManager(MainActivity.this, LinearLayoutManager.HORIZONTAL, false));
...@@ -133,8 +141,6 @@ public class MainActivity extends AppCompatActivity { ...@@ -133,8 +141,6 @@ public class MainActivity extends AppCompatActivity {
} }
}); });
mainViewModels = ViewModelProviders.of(this).get(MainViewModels.class);
binding.imgEmpty.setOnClickListener(new View.OnClickListener() { binding.imgEmpty.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
...@@ -244,33 +250,70 @@ public class MainActivity extends AppCompatActivity { ...@@ -244,33 +250,70 @@ public class MainActivity extends AppCompatActivity {
showLoading(true); showLoading(true);
ProgressDialog progressDialog = new ProgressDialog(MainActivity.this); ProgressDialog progressDialog = new ProgressDialog(MainActivity.this);
progressDialog.setMessage("Loading..."); progressDialog.setMessage("Loading...");
progressDialog.show(); Log.i("diluar if", "onGetProduct: "+selectCategory);
if (!selectCategory){
progressDialog.show();
}
selectCategory = true;
Log.i("setelah if", "onGetProduct: "+selectCategory);
binding.rvProduct.setVisibility(View.GONE); binding.rvProduct.setVisibility(View.GONE);
mainViewModels.getProductByCategory(categoryModels.getIdCategory()).observe(MainActivity.this, new Observer<DataResponse<List<ProductModels>>>() { if (categoryModels.getIdCategory() == 0){
@Override mainViewModels.getProduct().observe(MainActivity.this, new Observer<DataResponse<List<ProductModels<CategoryModels>>>>() {
public void onChanged(DataResponse<List<ProductModels>> listDataResponse) { @Override
if (listDataResponse != null) { public void onChanged(DataResponse<List<ProductModels<CategoryModels>>> listDataResponse) {
ArrayList<ProductModels> productModelsArrayList = new ArrayList<>(); if (listDataResponse != null) {
ArrayList<ProductModels> productModelsArrayList = new ArrayList<>();
productModelsArrayList.addAll(listDataResponse.getData()); productModelsArrayList.addAll(listDataResponse.getData());
progressDialog.dismiss(); progressDialog.dismiss();
showLoading(false); showLoading(false);
if (productModelsArrayList.isEmpty()) { if (productModelsArrayList.isEmpty()) {
binding.rvProduct.setVisibility(View.GONE); binding.rvProduct.setVisibility(View.GONE);
binding.imgEmpty.setVisibility(View.VISIBLE); binding.imgEmpty.setVisibility(View.VISIBLE);
binding.imgEmpty.bringToFront(); binding.imgEmpty.bringToFront();
} else { selectCategory = false;
binding.rvProduct.setVisibility(View.VISIBLE); Log.i("daidalam get if", "onGetProduct: "+selectCategory);
binding.imgEmpty.setVisibility(View.GONE); } else {
productAdapter.setProduct(MainActivity.this, productModelsArrayList); binding.rvProduct.setVisibility(View.VISIBLE);
binding.rvProduct.setLayoutManager(new GridLayoutManager(MainActivity.this, 2)); binding.imgEmpty.setVisibility(View.GONE);
binding.rvProduct.setAdapter(productAdapter); productAdapter.setProduct(MainActivity.this, productModelsArrayList);
productAdapter.notifyDataSetChanged(); binding.rvProduct.setLayoutManager(new GridLayoutManager(MainActivity.this, 2));
binding.rvProduct.setAdapter(productAdapter);
selectCategory = false;
Log.i("daidalam get else", "onGetProduct: "+selectCategory);
// productAdapter.notifyDataSetChanged();
}
} }
} }
} });
}); selectCategory = false;
}else{
mainViewModels.getProductByCategory(categoryModels.getIdCategory()).observe(MainActivity.this, new Observer<DataResponse<List<ProductModels>>>() {
@Override
public void onChanged(DataResponse<List<ProductModels>> listDataResponse) {
if (listDataResponse != null) {
ArrayList<ProductModels> productModelsArrayList = new ArrayList<>();
productModelsArrayList.addAll(listDataResponse.getData());
progressDialog.dismiss();
showLoading(false);
if (productModelsArrayList.isEmpty()) {
binding.rvProduct.setVisibility(View.GONE);
binding.imgEmpty.setVisibility(View.VISIBLE);
binding.imgEmpty.bringToFront();
} else {
binding.rvProduct.setVisibility(View.VISIBLE);
binding.imgEmpty.setVisibility(View.GONE);
productAdapter.setProduct(MainActivity.this, productModelsArrayList);
binding.rvProduct.setLayoutManager(new GridLayoutManager(MainActivity.this, 2));
binding.rvProduct.setAdapter(productAdapter);
// productAdapter.notifyDataSetChanged();
}
}
}
});
}
} }
}); });
} }
......
...@@ -4,6 +4,7 @@ import androidx.appcompat.app.AppCompatActivity; ...@@ -4,6 +4,7 @@ import androidx.appcompat.app.AppCompatActivity;
import androidx.lifecycle.Observer; import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider; import androidx.lifecycle.ViewModelProvider;
import androidx.lifecycle.ViewModelProviders; import androidx.lifecycle.ViewModelProviders;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
...@@ -15,41 +16,59 @@ import android.view.View; ...@@ -15,41 +16,59 @@ import android.view.View;
import android.view.Window; import android.view.Window;
import android.view.WindowManager; import android.view.WindowManager;
import android.widget.Button; import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import android.widget.Toolbar; import android.widget.Toolbar;
import com.google.android.material.appbar.MaterialToolbar; import com.google.android.material.appbar.MaterialToolbar;
import com.google.android.material.snackbar.Snackbar; import com.google.android.material.snackbar.Snackbar;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.yono.messeripos.adapter.CartAdapter;
import com.yono.messeripos.adapter.CheckoutAdapter;
import com.yono.messeripos.adapter.PaymentAdapter; import com.yono.messeripos.adapter.PaymentAdapter;
import com.yono.messeripos.models.MainViewModels; import com.yono.messeripos.models.MainViewModels;
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.PaymentResponse; import com.yono.messeripos.response.PaymentResponse;
import com.yono.messeripos.utils.Utils;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import static com.yono.messeripos.MainActivity.checkout;
public class PaymentActivity extends AppCompatActivity { public class PaymentActivity extends AppCompatActivity {
private ArrayList<PaymentResponse> paymentResponses = new ArrayList<>(); private ArrayList<PaymentResponse> paymentResponses = new ArrayList<>();
public static String methodPay=""; public static String methodPay="";
private Button btnPay; private Button btnPay;
private MainViewModelsCart mainViewModels; private MainViewModelsCart mainViewModels;
private PaymentsModels paymentsModels;
private long total = 0;
private Utils utils = new Utils();
private RecyclerView recyclerView;
private CheckoutAdapter checkoutAdapter;
private TextView grandTotal;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_payment); setContentView(R.layout.activity_payment);
Log.i("Status Checkout payment", "onCreate: "+SplashScreen.checkout); Log.i("Status Checkout payment", "onCreate: "+checkout);
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);
} }
paymentsModels = new PaymentsModels();
checkoutAdapter = new CheckoutAdapter();
recyclerView = findViewById(R.id.rvItem);
grandTotal = findViewById(R.id.grand_total);
MaterialToolbar toolbars = findViewById(R.id.appbar); MaterialToolbar toolbars = findViewById(R.id.appbar);
setSupportActionBar(toolbars); setSupportActionBar(toolbars);
DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(this, DividerItemDecoration.VERTICAL);
mainViewModels = new ViewModelProvider(PaymentActivity.this).get(MainViewModelsCart.class); mainViewModels = new ViewModelProvider(PaymentActivity.this).get(MainViewModelsCart.class);
mainViewModels.getCartProduct().observe(this, new Observer<List<ProductCartModels>>() { mainViewModels.getCartProduct().observe(this, new Observer<List<ProductCartModels>>() {
@Override @Override
...@@ -57,7 +76,18 @@ public class PaymentActivity extends AppCompatActivity { ...@@ -57,7 +76,18 @@ public class PaymentActivity extends AppCompatActivity {
String js = new Gson().toJson(productCartModels); String js = new Gson().toJson(productCartModels);
Log.i("On payment", "onChanged: "+js); Log.i("On payment", "onChanged: "+js);
for (ProductCartModels pd : productCartModels){
total = total + pd.getPrice_orders()*pd.getQuantity_orders();
}
getSupportActionBar().setTitle(productCartModels.get(0).getId_orders()); 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));
} }
}); });
...@@ -85,7 +115,14 @@ public class PaymentActivity extends AppCompatActivity { ...@@ -85,7 +115,14 @@ public class PaymentActivity extends AppCompatActivity {
btnPay.setOnClickListener(new View.OnClickListener() { btnPay.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
Toast.makeText(getApplicationContext(), methodPay, Toast.LENGTH_LONG).show(); if (methodPay.equals("cash")){
paymentsModels.setPaymentType("cash");
Log.i("CASH", "onClick: "+utils.convertGson(paymentsModels));
}else{
paymentsModels.setPaymentType("bank_transfer");
paymentsModels.setBank(methodPay);
Log.i("BANK", "onClick: "+utils.convertGson(paymentsModels));
}
} }
}); });
} }
......
...@@ -24,9 +24,7 @@ public class SplashScreen extends AppCompatActivity { ...@@ -24,9 +24,7 @@ public class SplashScreen extends AppCompatActivity {
SharedPreferences sharedPreferences; SharedPreferences sharedPreferences;
public static final String MY_SHARED_PREFERENCES = "my_shared_preferences"; public static final String MY_SHARED_PREFERENCES = "my_shared_preferences";
public static final String SESSION = "session"; public static final String SESSION = "session";
public static final String CHECKOUT = "checkout";
public static Boolean session; public static Boolean session;
public static Boolean checkout;
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
...@@ -50,7 +48,6 @@ public class SplashScreen extends AppCompatActivity { ...@@ -50,7 +48,6 @@ public class SplashScreen extends AppCompatActivity {
}, 700); }, 700);
sharedPreferences = getSharedPreferences(MY_SHARED_PREFERENCES, Context.MODE_PRIVATE); sharedPreferences = getSharedPreferences(MY_SHARED_PREFERENCES, Context.MODE_PRIVATE);
session = sharedPreferences.getBoolean(SESSION, false); session = sharedPreferences.getBoolean(SESSION, false);
checkout = sharedPreferences.getBoolean(CHECKOUT, false);
......
...@@ -15,6 +15,7 @@ import com.google.gson.Gson; ...@@ -15,6 +15,7 @@ import com.google.gson.Gson;
import com.yono.messeripos.CartActivity; import com.yono.messeripos.CartActivity;
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.models.CartModels; import com.yono.messeripos.models.CartModels;
import com.yono.messeripos.models.CategoryModels; import com.yono.messeripos.models.CategoryModels;
import com.yono.messeripos.models.ProductCartModels; import com.yono.messeripos.models.ProductCartModels;
...@@ -66,6 +67,7 @@ public class CartAdapter extends RecyclerView.Adapter<CartAdapter.MyViewHolder> ...@@ -66,6 +67,7 @@ public class CartAdapter extends RecyclerView.Adapter<CartAdapter.MyViewHolder>
parent, parent,
false false
); );
return new MyViewHolder(itemCartBinding); return new MyViewHolder(itemCartBinding);
} }
...@@ -90,17 +92,17 @@ public class CartAdapter extends RecyclerView.Adapter<CartAdapter.MyViewHolder> ...@@ -90,17 +92,17 @@ public class CartAdapter extends RecyclerView.Adapter<CartAdapter.MyViewHolder>
@SuppressLint("SetTextI18n") @SuppressLint("SetTextI18n")
public void bindData(ProductCartModels cartModels) { public void bindData(ProductCartModels cartModels) {
binding.setCarts(cartModels); /*
binding.setPrice(utils.convertPrice("Rp. ", cartModels.getPrice_orders())); * Data binding for itemCart in cart activity
* */
subtotal = cartModels.getPrice_orders() * cartModels.getQuantity_orders(); subtotal = cartModels.getPrice_orders() * cartModels.getQuantity_orders();
binding.setCarts(cartModels);
binding.setPrice(utils.convertPrice("Rp. ", cartModels.getPrice_orders()));
binding.setSubTotal(utils.convertPrice("Rp. ", subtotal)); binding.setSubTotal(utils.convertPrice("Rp. ", subtotal));
binding.etQty.setText(Long.toString(cartModels.getQuantity_orders())); binding.etQty.setText(Long.toString(cartModels.getQuantity_orders()));
binding.btDelete.setOnClickListener(view -> {
listener.onDelete(cartModels);
});
// set edit text qty // set edit text qty
binding.etQty.setText(Long.toString(cartModels.getQuantity_orders())); binding.etQty.setText(Long.toString(cartModels.getQuantity_orders()));
...@@ -113,6 +115,11 @@ public class CartAdapter extends RecyclerView.Adapter<CartAdapter.MyViewHolder> ...@@ -113,6 +115,11 @@ public class CartAdapter extends RecyclerView.Adapter<CartAdapter.MyViewHolder>
listener.onUpdateQuantityMinus(cartModels); listener.onUpdateQuantityMinus(cartModels);
}); });
binding.btDelete.setOnClickListener(view -> {
listener.onDelete(cartModels);
});
} }
} }
......
package com.yono.messeripos.adapter;
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.RecyclerView;
import com.yono.messeripos.R;
import com.yono.messeripos.databinding.ItemCartBinding;
import com.yono.messeripos.databinding.ItemCheckoutBinding;
import com.yono.messeripos.models.ProductCartModels;
import com.yono.messeripos.utils.Utils;
import java.util.List;
public class CheckoutAdapter extends RecyclerView.Adapter<CheckoutAdapter.MyViewHolder> {
private List<ProductCartModels> cartModels;
private int price;
Context context;
Utils utils = new Utils();
public void setCheckoutAdapter(Context context, List<ProductCartModels> cartModels) {
this.cartModels = cartModels;
this.context = context;
Log.d("Checkout Adapter: ", String.valueOf(this.cartModels));
notifyDataSetChanged();
}
@NonNull
@Override
public CheckoutAdapter.MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
ItemCheckoutBinding itemCheckoutBinding = DataBindingUtil.inflate(
LayoutInflater.from(parent.getContext()),
R.layout.item_checkout,
parent,
false
);
return new MyViewHolder(itemCheckoutBinding);
}
@Override
public void onBindViewHolder(@NonNull CheckoutAdapter.MyViewHolder holder, int position) {
holder.binData(cartModels.get(position));
}
@Override
public int getItemCount() {
return cartModels.size();
}
public class MyViewHolder extends RecyclerView.ViewHolder {
private long subtotal = 0;
private ItemCheckoutBinding itemCheckoutBinding;
public MyViewHolder(@NonNull ItemCheckoutBinding itemView) {
super(itemView.getRoot());
this.itemCheckoutBinding = itemView;
}
public void binData(ProductCartModels cartModels){
subtotal = cartModels.getPrice_orders() * cartModels.getQuantity_orders();
itemCheckoutBinding.setCheckout(cartModels);
itemCheckoutBinding.setSubtotal(utils.convertPrice("Rp. ", subtotal));
}
}
}
package com.yono.messeripos.api.service;
import com.yono.messeripos.api.ApiHelper;
import retrofit2.Call;
import retrofit2.http.POST;
public interface PaymentService {
// @POST(ApiHelper.VERSI_API_1+"payment")
// Call
}
...@@ -3,5 +3,57 @@ package com.yono.messeripos.models; ...@@ -3,5 +3,57 @@ package com.yono.messeripos.models;
import com.google.gson.annotations.SerializedName; import com.google.gson.annotations.SerializedName;
public class PaymentsModels { public class PaymentsModels {
// @SerializedName("") @SerializedName("order_code")
private String orderId;
@SerializedName("payment_type")
private String paymentType;
@SerializedName("bank")
private String bank;
@SerializedName("gross_amount")
private long grossAmount;
public PaymentsModels() {
}
public PaymentsModels(String orderId, String paymentType, String bank, long grossAmount) {
this.orderId = orderId;
this.paymentType = paymentType;
this.bank = bank;
this.grossAmount = grossAmount;
}
public String getOrderId() {
return orderId;
}
public void setOrderId(String orderId) {
this.orderId = orderId;
}
public String getPaymentType() {
return paymentType;
}
public void setPaymentType(String paymentType) {
this.paymentType = paymentType;
}
public String getBank() {
return bank;
}
public void setBank(String bank) {
this.bank = bank;
}
public long getGrossAmount() {
return grossAmount;
}
public void setGrossAmount(long grossAmount) {
this.grossAmount = grossAmount;
}
} }
package com.yono.messeripos.utils; package com.yono.messeripos.utils;
import com.google.gson.Gson;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols; import java.text.DecimalFormatSymbols;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
...@@ -36,4 +38,9 @@ public class Utils { ...@@ -36,4 +38,9 @@ public class Utils {
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
return timeStamp; return timeStamp;
} }
public String convertGson(Object object){
String js = new Gson().toJson(object);
return js;
}
} }
...@@ -16,12 +16,14 @@ ...@@ -16,12 +16,14 @@
android:id="@+id/rvCart" android:id="@+id/rvCart"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@id/cAppBar"
android:overScrollMode="never" android:overScrollMode="never"
android:padding="12sp" android:padding="1sp"
app:layoutManager="androidx.recyclerview.widget.GridLayoutManager" app:layoutManager="androidx.recyclerview.widget.GridLayoutManager"
tools:listitem="@layout/item_cart" app:layout_constraintBottom_toTopOf="@id/btCheckout"
/> app:layout_constraintTop_toBottomOf="@id/cAppBar"
app:layout_constraintVertical_bias="0.0"
tools:layout_editor_absoluteX="0dp"
tools:listitem="@layout/item_cart" />
<com.google.android.material.button.MaterialButton <com.google.android.material.button.MaterialButton
android:id="@+id/btCheckout" android:id="@+id/btCheckout"
...@@ -30,9 +32,10 @@ ...@@ -30,9 +32,10 @@
android:text="@string/title_checkout" android:text="@string/title_checkout"
android:padding="15dp" android:padding="15dp"
android:textSize="16sp" android:textSize="16sp"
android:layout_margin="10dp" android:layout_alignParentBottom="true"
app:layout_constraintBottom_toBottomOf="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"/>
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<data>
<variable
name="checkout"
type="com.yono.messeripos.models.ProductCartModels" />
<variable
name="subtotal"
type="String" />
</data>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.google.android.material.card.MaterialCardView
android:layout_width="match_parent"
android:layout_height="60dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toBottomOf="parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp">
<TextView
android:id="@+id/itemCheckout"
android:layout_width="200dp"
android:layout_height="wrap_content"
tools:text="@tools:sample/full_names"
android:textSize="20sp"
android:lines="3"
android:text="@{checkout.product_name_orders+` x `+checkout.quantity_orders}"
android:layout_margin="10dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/itemSubTotal"
android:layout_width="200dp"
android:layout_height="wrap_content"
tools:text="@tools:sample/full_names"
android:textSize="20sp"
android:text="@{subtotal}"
android:textColor="@android:color/black"
android:layout_margin="10dp"
app:layout_constraintStart_toEndOf="@id/itemCheckout"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:textAlignment="textEnd" />
</androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.card.MaterialCardView>
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
\ No newline at end of file
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
<item name="colorPrimaryDark">@color/colorPrimaryDark</item> <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item> <item name="colorAccent">@color/colorAccent</item>
<item name="android:fontFamily">@font/roboto</item> <item name="android:fontFamily">@font/roboto</item>
<item name="android:windowLightStatusBar">false</item>
<item name="android:actionBarStyle">@style/ThemeActionBar</item> <item name="android:actionBarStyle">@style/ThemeActionBar</item>
<item name="android:windowActionBarOverlay">false</item> <item name="android:windowActionBarOverlay">false</item>
<item name="android:windowTranslucentStatus">true</item> <item name="android:windowTranslucentStatus">true</item>
...@@ -18,12 +17,12 @@ ...@@ -18,12 +17,12 @@
<item name="colorPrimary">@color/colorPrimary</item> <item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item> <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item> <item name="colorAccent">@color/colorAccent</item>
<item name="android:windowLightStatusBar">false</item>
<item name="android:actionBarStyle">@style/ThemeActionBar</item> <item name="android:actionBarStyle">@style/ThemeActionBar</item>
<item name="android:windowActionBarOverlay">false</item> <item name="android:windowActionBarOverlay">false</item>
<item name="android:windowTranslucentStatus">true</item> <item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item> <item name="android:windowTranslucentNavigation">true</item>
<item name="windowActionBarOverlay">true</item> <item name="windowActionBarOverlay">true</item>
<item name="android:fontFamily">@font/poppins_medium</item>
<item name="actionBarStyle">@style/ThemeActionBar</item> <item name="actionBarStyle">@style/ThemeActionBar</item>
</style> </style>
......
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