Commit e5e292b8 authored by iman Fauzi's avatar iman Fauzi

fix conflict

parents 1e05ef17 4443b63a
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="JDK" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">
......
......@@ -6,7 +6,7 @@ android {
defaultConfig {
applicationId "com.yono.messeripos"
minSdkVersion 22
minSdkVersion 23
targetSdkVersion 30
versionCode 1
versionName "1.0"
......
......@@ -17,7 +17,10 @@
android:roundIcon="@mipmap/ic_launcher_new_icon"
android:supportsRtl="true"
android:theme="@style/AppTheme.appbar">
<activity android:name=".InvoiceActivity"></activity>
<activity
android:name=".HistoryActivity"
android:theme="@style/AppTheme.appbar" />
<activity android:name=".InvoiceActivity" />
<activity
android:name=".LoginActivity"
android:theme="@style/AppTheme.appbar" />
......
......@@ -26,8 +26,6 @@ import com.yono.messeripos.models.MainViewModelsCart;
import com.yono.messeripos.models.ProductCartModels;
import com.yono.messeripos.response.OrdersResponse;
import com.google.android.material.snackbar.Snackbar;
import java.util.List;
import java.util.Objects;
......@@ -59,9 +57,9 @@ public class CartActivity extends AppCompatActivity {
toolbars.setNavigationOnClickListener(view -> onBackPressed());
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);
recyclerView.setLayoutManager(llm);
......@@ -70,42 +68,42 @@ public class CartActivity extends AppCompatActivity {
modelsCart = new ViewModelProvider(this).get(MainViewModelsCart.class);
modelsCart.getCartProduct().observe(this, new Observer<List<ProductCartModels>>() {
@Override
public void onChanged(List<ProductCartModels> productCartModels) {
if (productCartModels != null){
dataCart = productCartModels;
cartAdapter.setCartAdapter(CartActivity.this, productCartModels);
recyclerView.setAdapter(cartAdapter);
}
}
});
cartAdapter.setListener(new CartAdapter.CartListener() {
@Override
public void onDelete(ProductCartModels productCartModels) {
modelsCart.deleteCart(productCartModels);
}
@Override
public void onUpdateQuantityPlus(ProductCartModels productCartModels) {
productCartModels.setQuantity_orders(productCartModels.getQuantity_orders()+1);
modelsCart.getCartProduct().observe(this, new Observer<List<ProductCartModels>>() {
@Override
public void onChanged(List<ProductCartModels> productCartModels) {
if (productCartModels != null) {
dataCart = productCartModels;
cartAdapter.setCartAdapter(CartActivity.this, productCartModels);
recyclerView.setAdapter(cartAdapter);
}
}
});
cartAdapter.setListener(new CartAdapter.CartListener() {
@Override
public void onDelete(ProductCartModels productCartModels) {
modelsCart.deleteCart(productCartModels);
}
@Override
public void onUpdateQuantityPlus(ProductCartModels productCartModels) {
productCartModels.setQuantity_orders(productCartModels.getQuantity_orders() + 1);
modelsCart.updateCart(productCartModels);
}
}
@Override
public void onUpdateQuantityMinus(ProductCartModels productCartModels) {
if (productCartModels.getQuantity_orders() > 1) {
productCartModels.setQuantity_orders(productCartModels.getQuantity_orders()-1);
modelsCart.updateCart(productCartModels);
}
}
@Override
public void onUpdateQuantityMinus(ProductCartModels productCartModels) {
if (productCartModels.getQuantity_orders() > 1) {
productCartModels.setQuantity_orders(productCartModels.getQuantity_orders() - 1);
modelsCart.updateCart(productCartModels);
}
}
@Override
public void onCheckout(ProductCartModels productCartModels) {
}
});
@Override
public void onCheckout(ProductCartModels productCartModels) {
}
});
btnCheckout.setOnClickListener(new View.OnClickListener() {
@Override
......@@ -116,16 +114,17 @@ public class CartActivity extends AppCompatActivity {
OrdersResponse ordersResponse = new OrdersResponse();
List<ProductCartModels> productCartModels;
Log.d("Data cart checkout", "onClick: "+dataCart);
for (ProductCartModels pd : dataCart){
Log.d("Data cart checkout", "onClick: " + dataCart);
for (ProductCartModels pd : dataCart) {
ordersResponse.setOrders_id(pd.getId_orders());
}
ordersResponse.setProduct_cart(dataCart);
modelsCart.insertOrders(ordersResponse);
progressDialog.dismiss();
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putBoolean(SplashScreen.CHECKOUT, true);
editor.putBoolean(MainActivity.CHECKOUT, true);
if(editor.commit()){
startActivity(new Intent(CartActivity.this, PaymentActivity.class));
finish();
......
package com.yono.messeripos;
import android.Manifest;
import android.content.CursorLoader;
import android.content.Intent;
import android.database.Cursor;
......@@ -61,6 +62,9 @@ public class FormProductActivity extends AppCompatActivity {
"Oreo"
};
private String[] permissions = new String[]{Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE};
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
......@@ -68,6 +72,7 @@ public class FormProductActivity extends AppCompatActivity {
binding.btnAdd.setText("Add New Prooduct");
productModels = new ProductModels();
requestPermissions(permissions, REQUEST_PERMISSIONS);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
Window w = getWindow();
......
package com.yono.messeripos;
import androidx.appcompat.app.AppCompatActivity;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.Window;
import android.view.WindowManager;
import com.google.android.material.appbar.MaterialToolbar;
import com.yono.messeripos.adapter.TransactionAdapter;
import com.yono.messeripos.models.MainViewModels;
import com.yono.messeripos.models.PaymentsModels;
import com.yono.messeripos.response.DataResponse;
import com.yono.messeripos.utils.Utils;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
public class HistoryActivity extends AppCompatActivity {
TransactionAdapter transactionAdapter;
PaymentsModels paymentsModels;
MainViewModels mainViewModels;
RecyclerView recyclerView;
Utils utils = new Utils();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_history);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
Window w = getWindow();
w.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
}
MaterialToolbar toolbars = findViewById(R.id.cAppBar);
recyclerView = findViewById(R.id.rvHistory);
recyclerView.addItemDecoration(utils.dividerItemDecoration(HistoryActivity.this));
transactionAdapter = new TransactionAdapter();
mainViewModels = new ViewModelProvider(this).get(MainViewModels.class);
setSupportActionBar(toolbars);
Objects.requireNonNull(getSupportActionBar()).setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setTitle("All Transaction");
toolbars.setNavigationOnClickListener(view -> onBackPressed());
mainViewModels.getAllTransactions().observe(HistoryActivity.this,
new Observer<DataResponse<List<PaymentsModels>>>() {
@Override
public void onChanged(DataResponse<List<PaymentsModels>> listDataResponse) {
ArrayList<PaymentsModels> newData = new ArrayList<>();
newData.addAll(listDataResponse.getData());
transactionAdapter.setTransactionAdapter(HistoryActivity.this, newData);
/*
* SET RECYCLE VIEW MANAGER DISINI
* GUNAKAN LINEARLAYOUT MANAGER VERTICAL UNTUK SETTING LAYOUT MANAGER
*
* SET RECYCLEVIEW ADAPTER DENGAN TRANSACTION ADAPTER
*
* UNTUK BISA CLICK CARD VIEW NYA
* PANGGIL ADAPTERNYA KEMUDIAN .setList.....
* SILAHKAN PINDAH KE ACTIVITY SELANJUTNYA PADA ON.....
* */
}
});
}
}
\ No newline at end of file
......@@ -4,6 +4,7 @@ import androidx.appcompat.app.AppCompatActivity;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;
import androidx.lifecycle.ViewModelProviders;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
......@@ -15,41 +16,59 @@ import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.Toolbar;
import com.google.android.material.appbar.MaterialToolbar;
import com.google.android.material.snackbar.Snackbar;
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.models.MainViewModels;
import com.yono.messeripos.models.MainViewModelsCart;
import com.yono.messeripos.models.PaymentsModels;
import com.yono.messeripos.models.ProductCartModels;
import com.yono.messeripos.response.PaymentResponse;
import com.yono.messeripos.utils.Utils;
import java.util.ArrayList;
import java.util.List;
import static com.yono.messeripos.MainActivity.checkout;
public class PaymentActivity extends AppCompatActivity {
private ArrayList<PaymentResponse> paymentResponses = new ArrayList<>();
public static String methodPay="";
private Button btnPay;
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
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
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) {
Window w = getWindow();
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);
setSupportActionBar(toolbars);
DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(this, DividerItemDecoration.VERTICAL);
mainViewModels = new ViewModelProvider(PaymentActivity.this).get(MainViewModelsCart.class);
mainViewModels.getCartProduct().observe(this, new Observer<List<ProductCartModels>>() {
@Override
......@@ -57,7 +76,18 @@ public class PaymentActivity extends AppCompatActivity {
String js = new Gson().toJson(productCartModels);
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());
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 {
btnPay.setOnClickListener(new View.OnClickListener() {
@Override
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 {
SharedPreferences sharedPreferences;
public static final String MY_SHARED_PREFERENCES = "my_shared_preferences";
public static final String SESSION = "session";
public static final String CHECKOUT = "checkout";
public static Boolean session;
public static Boolean checkout;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
......@@ -50,7 +48,6 @@ public class SplashScreen extends AppCompatActivity {
}, 700);
sharedPreferences = getSharedPreferences(MY_SHARED_PREFERENCES, Context.MODE_PRIVATE);
session = sharedPreferences.getBoolean(SESSION, false);
checkout = sharedPreferences.getBoolean(CHECKOUT, false);
......
......@@ -15,6 +15,7 @@ import com.google.gson.Gson;
import com.yono.messeripos.CartActivity;
import com.yono.messeripos.R;
import com.yono.messeripos.databinding.ItemCartBinding;
import com.yono.messeripos.databinding.ItemCheckoutBinding;
import com.yono.messeripos.models.CartModels;
import com.yono.messeripos.models.CategoryModels;
import com.yono.messeripos.models.ProductCartModels;
......@@ -66,6 +67,7 @@ public class CartAdapter extends RecyclerView.Adapter<CartAdapter.MyViewHolder>
parent,
false
);
return new MyViewHolder(itemCartBinding);
}
......@@ -90,17 +92,17 @@ public class CartAdapter extends RecyclerView.Adapter<CartAdapter.MyViewHolder>
@SuppressLint("SetTextI18n")
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();
binding.setCarts(cartModels);
binding.setPrice(utils.convertPrice("Rp. ", cartModels.getPrice_orders()));
binding.setSubTotal(utils.convertPrice("Rp. ", subtotal));
binding.etQty.setText(Long.toString(cartModels.getQuantity_orders()));
binding.btDelete.setOnClickListener(view -> {
listener.onDelete(cartModels);
});
// set edit text qty
binding.etQty.setText(Long.toString(cartModels.getQuantity_orders()));
......@@ -113,6 +115,11 @@ public class CartAdapter extends RecyclerView.Adapter<CartAdapter.MyViewHolder>
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));
}
}
}
......@@ -2,42 +2,31 @@ package com.yono.messeripos.adapter;
import android.annotation.SuppressLint;
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;
import android.widget.Filter;
import android.widget.Filterable;
import androidx.annotation.NonNull;
import androidx.databinding.DataBindingUtil;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.RecyclerView;
import com.yono.messeripos.MainActivity;
import com.yono.messeripos.R;
import com.yono.messeripos.databinding.ItemListBinding;
import androidx.fragment.app.FragmentActivity;
import androidx.lifecycle.ViewModelProvider;
import androidx.lifecycle.ViewModelProviders;
import androidx.recyclerview.widget.RecyclerView;
import com.google.gson.Gson;
import com.yono.messeripos.MainActivity;
import com.yono.messeripos.R;
import com.yono.messeripos.databinding.ItemListBinding;
import com.yono.messeripos.models.CartModels;
import com.yono.messeripos.models.MainViewModelsCart;
import com.yono.messeripos.models.ProductCartModels;
import com.yono.messeripos.models.ProductModels;
import com.yono.messeripos.utils.Utils;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.util.ArrayList;
public class ProductAdapter extends RecyclerView.Adapter<ProductAdapter.MyViewHolder> {
public class ProductAdapter extends RecyclerView.Adapter<ProductAdapter.MyViewHolder> implements Filterable {
private ArrayList<ProductModels> productModels = new ArrayList<>();
private ArrayList<ProductModels> productModelsFiltered = new ArrayList<>();
Context context;
MainViewModelsCart mainViewModelsCart;
Utils utils = new Utils();
public interface ProductListener {
......@@ -58,10 +47,42 @@ public class ProductAdapter extends RecyclerView.Adapter<ProductAdapter.MyViewHo
public void setProduct(Context context, ArrayList<ProductModels> productModels) {
this.productModels = productModels;
this.context = context;
mainViewModelsCart = ViewModelProviders.of((FragmentActivity) context).get(MainViewModelsCart.class);
this.productModelsFiltered = productModels;
notifyDataSetChanged();
}
@Override
public Filter getFilter() {
return new Filter() {
@Override
protected FilterResults performFiltering(CharSequence charSequence) {
String charString = charSequence.toString();
if (charString.isEmpty()) {
productModelsFiltered = productModels;
} else {
ArrayList<ProductModels> filteredList = new ArrayList<>();
for (ProductModels prdk : productModels) {
if (prdk.getProductName().toLowerCase().contains(charString.toLowerCase())) {
filteredList.add(prdk);
}
}
productModelsFiltered = filteredList;
}
FilterResults filterResults = new FilterResults();
filterResults.values = productModelsFiltered;
return filterResults;
}
@Override
protected void publishResults(CharSequence charSequence, FilterResults filterResults) {
productModelsFiltered = (ArrayList<ProductModels>) filterResults.values;
notifyDataSetChanged();
}
};
}
@NonNull
@Override
public ProductAdapter.MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
......@@ -77,12 +98,12 @@ public class ProductAdapter extends RecyclerView.Adapter<ProductAdapter.MyViewHo
@Override
public void onBindViewHolder(@NonNull ProductAdapter.MyViewHolder holder, int position) {
holder.bindData(productModels.get(position));
holder.bindData(productModelsFiltered.get(position));
}
@Override
public int getItemCount() {
return productModels.size();
return productModelsFiltered.size();
}
public class MyViewHolder extends RecyclerView.ViewHolder {
......
package com.yono.messeripos.adapter;
import android.content.Context;
import android.os.Build;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;
import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.RecyclerView;
import com.yono.messeripos.R;
import com.yono.messeripos.databinding.ItemHistoryBinding;
import com.yono.messeripos.models.PaymentsModels;
import com.yono.messeripos.models.ProductCartModels;
import com.yono.messeripos.utils.Utils;
import java.util.ArrayList;
public class TransactionAdapter extends RecyclerView.Adapter<TransactionAdapter.MyViewHolder> {
private ArrayList<PaymentsModels> paymentsModels = new ArrayList<>();
Context context;
Utils utils = new Utils();
public interface TransactionListener {
void onShowDetail(PaymentsModels paymentsModels);
}
private TransactionListener listener;
public void setListener(TransactionListener listener) {
this.listener = listener;
}
public void setTransactionAdapter(Context context, ArrayList<PaymentsModels> paymentsModels){
this.paymentsModels = paymentsModels;
this.context = context;
notifyDataSetChanged();
}
@NonNull
@Override
public TransactionAdapter.MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
ItemHistoryBinding itemHistoryBinding = DataBindingUtil.inflate(
LayoutInflater.from(parent.getContext()),
R.layout.item_history,
parent,
false
);
return new MyViewHolder(itemHistoryBinding);
}
@RequiresApi(api = Build.VERSION_CODES.O)
@Override
public void onBindViewHolder(@NonNull TransactionAdapter.MyViewHolder holder, int position) {
holder.binData(paymentsModels.get(position));
}
@Override
public int getItemCount() {
return paymentsModels.size();
}
public class MyViewHolder extends RecyclerView.ViewHolder {
ItemHistoryBinding itemHistoryBinding;
public MyViewHolder(@NonNull ItemHistoryBinding itemView) {
super(itemView.getRoot());
this.itemHistoryBinding = itemView;
}
@RequiresApi(api = Build.VERSION_CODES.O)
public void binData(PaymentsModels paymentsModels){
itemHistoryBinding.setTransaction(paymentsModels);
itemHistoryBinding.setDate(utils.convertDate(paymentsModels.getUpdatedAt()));
itemHistoryBinding.cvHistory.setOnClickListener(view -> listener.onShowDetail(paymentsModels));
}
}
}
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
}
package com.yono.messeripos.api.service;
import com.yono.messeripos.api.ApiHelper;
import com.yono.messeripos.models.PaymentsModels;
import com.yono.messeripos.response.DataResponse;
import java.util.List;
import retrofit2.Call;
import retrofit2.http.GET;
public interface TransactionService {
@GET(ApiHelper.VERSI_API_1+"payments")
Call<DataResponse<List<PaymentsModels>>> getAllTransaction();
}
......@@ -4,14 +4,18 @@ import android.util.Log;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.Transformations;
import androidx.lifecycle.ViewModel;
import androidx.lifecycle.ViewModelProvider;
import com.google.gson.Gson;
import com.yono.messeripos.api.client.Client;
import com.yono.messeripos.api.service.CategoryServise;
import com.yono.messeripos.api.service.ProductService;
import com.yono.messeripos.api.service.TransactionService;
import com.yono.messeripos.api.service.UsersService;
import com.yono.messeripos.response.DataResponse;
import com.yono.messeripos.utils.Utils;
import java.util.ArrayList;
import java.util.List;
......@@ -25,13 +29,19 @@ public class MainViewModels extends ViewModel {
MutableLiveData<DataResponse<List<ProductModels>>> productByCategory;
MutableLiveData<DataResponse<List<CategoryModels>>> categoryList;
MutableLiveData<DataResponse<UsersModels>> usersLogin;
MutableLiveData<DataResponse<List<PaymentsModels>>> transactions;
private MainViewModels mainViewModels;
Client client = new Client();
Utils utils = new Utils();
public MainViewModels(){
productList = new MutableLiveData<>();
categoryList = new MutableLiveData<>();
productByCategory = new MutableLiveData<>();
transactions = new MutableLiveData<>();
}
public LiveData<DataResponse<List<ProductModels<CategoryModels>>>> getProduct(){
......@@ -49,6 +59,34 @@ public class MainViewModels extends ViewModel {
return productByCategory;
}
public LiveData<DataResponse<List<PaymentsModels>>> getAllTransactions(){
getDataTransaction();
return transactions;
}
private void getDataTransaction() {
TransactionService transactionService = client.Client(TransactionService.class);
transactionService.getAllTransaction().enqueue(new Callback<DataResponse<List<PaymentsModels>>>() {
@Override
public void onResponse(Call<DataResponse<List<PaymentsModels>>> call,
Response<DataResponse<List<PaymentsModels>>> response) {
Log.i("Get all transaction", "onResponse: "+utils.convertGson(response.body()));
if (response.body() != null){
transactions.setValue(response.body());
}else{
transactions = null;
}
}
@Override
public void onFailure(Call<DataResponse<List<PaymentsModels>>> call, Throwable t) {
Log.e("Error get transaction", "onFailure: ",t );
transactions = null;
}
});
}
private void getDataProductByCategory(int id) {
CategoryServise categoryServise = client.Client(CategoryServise.class);
......
package com.yono.messeripos.models;
import com.google.gson.annotations.SerializedName;
public class PaymentsModels {
@SerializedName("order_code")
private String orderId;
@SerializedName("payment_type")
private String paymentType;
@SerializedName("bank")
private String bank;
@SerializedName("gross_amount")
private long grossAmount;
@SerializedName("transaction_status")
private String transactionStatus;
@SerializedName("created_at")
private String createdAt;
@SerializedName("updated_at")
private String updatedAt;
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;
}
public String getTransactionStatus() {
return transactionStatus;
}
public void setTransactionStatus(String transactionStatus) {
this.transactionStatus = transactionStatus;
}
public String getCreatedAt() {
return createdAt;
}
public void setCreatedAt(String createdAt) {
this.createdAt = createdAt;
}
public String getUpdatedAt() {
return updatedAt;
}
public void setUpdatedAt(String updatedAt) {
this.updatedAt = updatedAt;
}
}
package com.yono.messeripos.utils;
import android.content.Context;
import android.os.Build;
import androidx.annotation.RequiresApi;
import androidx.recyclerview.widget.DividerItemDecoration;
import com.google.gson.Gson;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.Locale;
public class Utils {
public String convertPrice(String mataUang, int nilai ){
......@@ -36,4 +48,29 @@ public class Utils {
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
return timeStamp;
}
public String convertGson(Object object){
String js = new Gson().toJson(object);
return js;
}
public DividerItemDecoration dividerItemDecoration(Context context){
DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(context, DividerItemDecoration.VERTICAL);
return dividerItemDecoration;
}
@RequiresApi(api = Build.VERSION_CODES.O)
public String convertDate(String date){
DateTimeFormatter dateTimeFormatter =
DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")
.withZone(ZoneId.of("UTC"));
LocalDateTime localDateTime = LocalDateTime
.parse(date, dateTimeFormatter);
DateTimeFormatter localFormatter = DateTimeFormatter
.ofPattern("EEEE, dd MM yyyy", new Locale("id", "ID"));
String localDate = localDateTime.format(localFormatter);
return localDate;
}
}
......@@ -21,28 +21,6 @@
app:layoutManager="androidx.recyclerview.widget.GridLayoutManager"
tools:listitem="@layout/item_cart" />
<!-- <androidx.recyclerview.widget.RecyclerView-->
<!-- android:id="@+id/rvCart"-->
<!-- android:layout_width="match_parent"-->
<!-- android:layout_height="match_parent"-->
<!-- app:layoutManager="androidx.recyclerview.widget.GridLayoutManager"-->
<!-- tools:listitem="@layout/item_cart"-->
<!-- android:layout_above="@+id/btCheckout"-->
<!-- />-->
<!-- <com.google.android.material.button.MaterialButton-->
<!-- android:id="@+id/btCheckout"-->
<!-- android:layout_width="match_parent"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:text="@string/title_checkout"-->
<!-- android:padding="15dp"-->
<!-- android:textSize="16sp"-->
<!-- android:layout_margin="10dp"-->
<!-- android:layout_below="@id/rvCart"-->
<!-- android:layout_alignParentBottom="true"-->
<!-- android:layout_alignWithParentIfMissing="true"/>-->
<com.google.android.material.button.MaterialButton
android:id="@+id/btCheckout"
android:layout_width="match_parent"
......@@ -56,4 +34,4 @@
android:textColor="@android:color/white"
android:textStyle="bold" />
</RelativeLayout>
\ No newline at end of file
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".HistoryActivity">
<include
android:id="@+id/cAppBar"
layout="@layout/app_bar" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="600dp"
android:layout_below="@+id/cAppBar">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rvHistory"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/cAppBar"
tools:listitem="@layout/item_history" />
</ScrollView>
<com.google.android.material.button.MaterialButton
android:id="@+id/btShow"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/title_next"
android:padding="15dp"
android:textSize="16sp"
android:layout_alignParentBottom="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
</RelativeLayout>
\ No newline at end of file
......@@ -48,7 +48,7 @@
android:id="@+id/btCheckout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/title_checkout"
android:text="@string/title_success"
android:padding="15dp"
android:textSize="16sp"
android:layout_margin="10dp"
......
......@@ -37,6 +37,7 @@
>
<EditText
android:id="@+id/etSearchProduct"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#fff"
......
<?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
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<data>
<variable
name="transaction"
type="com.yono.messeripos.models.PaymentsModels" />
<variable
name="date"
type="String" />
</data>
<com.google.android.material.card.MaterialCardView
android:id="@+id/cvHistory"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:ignore="MissingConstraints">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="12dp">
<com.google.android.material.textview.MaterialTextView
android:id="@+id/tvPay"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/roboto"
android:textSize="24sp"
app:layout_constraintStart_toStartOf="parent"
android:textColor="@android:color/black"
android:textStyle="bold"
android:textAllCaps="true"
tools:text="@string/hint_pay"
android:text="@{transaction.paymentType}"
app:layout_constraintTop_toTopOf="parent" />
<com.google.android.material.textview.MaterialTextView
android:id="@+id/tvDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/roboto"
android:textSize="16sp"
tools:text="@tools:sample/date/ddmmyy"
android:text="@{date}"
app:layout_constraintStart_toStartOf="@id/tvPay"
app:layout_constraintTop_toBottomOf="@+id/tvPay" />
<com.google.android.material.textview.MaterialTextView
android:id="@+id/tvOrder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/roboto"
android:textSize="16sp"
android:text="@{transaction.orderId}"
tools:text="#6821739123"
app:layout_constraintStart_toStartOf="@id/tvDate"
app:layout_constraintTop_toBottomOf="@+id/tvDate" />
<com.google.android.material.textview.MaterialTextView
android:id="@+id/tvHistory"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="84dp"
android:backgroundTint="#8555DA"
android:text="@{transaction.transactionStatus}"
tools:text="@tools:sample/first_names"
android:textColor="#fff"
android:background="#C60000"
app:layout_constraintEnd_toEndOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.card.MaterialCardView>
</layout>
\ No newline at end of file
......@@ -20,4 +20,10 @@
android:title="Create Product"
app:showAsAction="never" />
<item
android:id="@+id/allTransaction"
android:orderInCategory="100"
android:title="All Transaction"
app:showAsAction="never" />
</menu>
\ No newline at end of file
......@@ -23,6 +23,9 @@
<string name="stock">Stock</string>
<string name="add">Add</string>
<string name="hint_billing">Billing</string>
<string name="title_success">Success</string>
<string name="hint_pay">cash</string>
<string name="title_next">next</string>
<string-array name="planets_array">
<item>Mercury</item>
......
......@@ -6,7 +6,6 @@
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:fontFamily">@font/roboto</item>
<item name="android:windowLightStatusBar">false</item>
<item name="android:actionBarStyle">@style/ThemeActionBar</item>
<item name="android:windowActionBarOverlay">false</item>
<item name="android:windowTranslucentStatus">true</item>
......@@ -18,12 +17,12 @@
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:windowLightStatusBar">false</item>
<item name="android:actionBarStyle">@style/ThemeActionBar</item>
<item name="android:windowActionBarOverlay">false</item>
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
<item name="windowActionBarOverlay">true</item>
<item name="android:fontFamily">@font/poppins_medium</item>
<item name="actionBarStyle">@style/ThemeActionBar</item>
</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