Commit 1ec17828 authored by Trio Saputra's avatar Trio Saputra
parents 83941788 a5fd849d
......@@ -43,6 +43,7 @@ public class ForgetPassword extends AppCompatActivity {
password.setNewPassword(binding.etNewPw.getText().toString());
userViewModel.resetPassword(users.get(i).getId() , password);
binding.setLoading(false);
Toast.makeText(ForgetPassword.this, "Reset Password Success", Toast.LENGTH_LONG).show();
startActivity(new Intent(ForgetPassword.this, LoginActivity.class));
finish();
return;
......
......@@ -44,6 +44,7 @@ public class LoginActivity extends AppCompatActivity {
binding.setLoading(true);
viewModel.setListUser();
launchMain();
finish();
}
});
}
......
......@@ -10,11 +10,13 @@ import androidx.recyclerview.widget.LinearLayoutManager;
import android.Manifest;
import android.annotation.SuppressLint;
import android.app.Application;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.widget.PopupMenu;
import android.widget.Toast;
......@@ -24,6 +26,7 @@ import com.example.yourcashiertest.adapters.ProductAdapter;
import com.example.yourcashiertest.databinding.ActivityMainBinding;
import com.example.yourcashiertest.entities.Cart;
import com.example.yourcashiertest.entities.Product;
import com.example.yourcashiertest.repositories.ProductRepository;
import com.example.yourcashiertest.viewmodels.CartViewModel;
import com.example.yourcashiertest.viewmodels.ProductViewModel;
......@@ -117,16 +120,16 @@ public class MainActivity extends AppCompatActivity {
binding.rvProducts.setAdapter(adapter);
viewModel = new ViewModelProvider(this).get(ProductViewModel.class);
viewModel.getProducts().observe(this, adapter::setProducts);
viewModel.getProducts().observe(this, products -> {
adapter.setProducts(products);
List<String> list = new ArrayList<>();
List<String> category = new ArrayList<>();
for (int i = 0; i < products.size(); i++){
list.add(products.get(i).getCategory());
category.add(products.get(i).getCategory().toLowerCase());
}
categoryAdapter.setCategories(list);
categoryAdapter.setCategories(category);
});
categoryAdapter.setListener(category -> viewModel.filter(category));
categoryAdapter.setListener(category -> viewModel.filter(category.toLowerCase()));
adapter.setListener(new ProductAdapter.ProductListener() {
@Override
......
......@@ -4,6 +4,8 @@ import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatActivity;
import androidx.databinding.DataBindingUtil;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.annotation.SuppressLint;
import android.content.Intent;
......@@ -13,20 +15,25 @@ import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import com.example.yourcashiertest.R;
import com.example.yourcashiertest.adapters.PaymentAdapter;
import com.example.yourcashiertest.databinding.ActivityPaymentBinding;
import com.example.yourcashiertest.models.ResponsePayment;
import com.example.yourcashiertest.utils.Convert;
import com.example.yourcashiertest.utils.ViewUtil;
import com.example.yourcashiertest.viewmodels.CartViewModel;
import java.util.ArrayList;
public class PaymentActivity extends AppCompatActivity {
ActivityPaymentBinding binding;
public static String paymentMethod = "";
public static String REFUND = "refund";
public int refund;
public int amount;
CartViewModel cartViewModel;
public String payment = "";
public static final String PAY_WITH = "pay_with";
private ArrayList<ResponsePayment> responsePayments = new ArrayList<>();
@SuppressLint("ResourceAsColor")
@RequiresApi(api = Build.VERSION_CODES.N)
......@@ -39,36 +46,23 @@ public class PaymentActivity extends AppCompatActivity {
amount = getIntent().getIntExtra(CartActivity.PRICE, 0);
binding.setAmount(Convert.changeToCurrency(amount));
// binding.rvPayment.setLayoutManager(new LinearLayoutManager(this, RecyclerView.VERTICAL, false));
responsePayments.add(new ResponsePayment("https://i.ibb.co/yfcFMHc/undraw-wallet-aym5.png", "Cash"));
responsePayments.add(new ResponsePayment("https://i.ibb.co/qNnKh5n/undraw-Credit-card-re-blml.png", "Card"));
binding.cbCash.setOnClickListener(v -> {
if (binding.getCheckCash()){
binding.setCheckCash(false);
binding.cvCash.setCardBackgroundColor(0);
payment = "";
}else {
binding.setCheckCash(true);
binding.cvCash.setCardBackgroundColor(R.color.blue);
payment = "Cash";
}
});
binding.cbCard.setOnClickListener(v -> {
if (binding.getCheckCard()){
binding.setCheckCard(false);
binding.cvCard.setCardBackgroundColor(0);
payment = "";
}else {
binding.setCheckCard(true);
binding.cvCard.setCardBackgroundColor(R.color.blue);
payment = "Card";
}
});
PaymentAdapter adapter = new PaymentAdapter(responsePayments, this);
binding.rvPayment.setAdapter(adapter);
adapter.setListener(responsePayments -> {
paymentMethod = responsePayments.getBank();
binding.btnPay.setEnabled(true);
});
}
public void btnPay(View view) {
if (TextUtils.isEmpty(binding.etAmountPaid.getText().toString())){
ViewUtil.showMessage(view, "Please input Amount Paid by Customer!");
}else if (payment.equals("")){
}else if (paymentMethod.equals("")){
ViewUtil.showMessage(view, "Please choose type payment");
} else {
int amountPaid = Integer.parseInt(binding.etAmountPaid.getText().toString());
......@@ -76,15 +70,13 @@ public class PaymentActivity extends AppCompatActivity {
ViewUtil.showMessage(view, "AmountPaid doesn't less than total price");
} else {
refund = amountPaid - amount;
startActivity(new Intent(PaymentActivity.this, StatusPayment.class).putExtra(REFUND, refund).putExtra(PAY_WITH, payment));
startActivity(new Intent(PaymentActivity.this, StatusPayment.class).putExtra(REFUND, refund).putExtra(PAY_WITH, paymentMethod));
cartViewModel.clear();
finish();
}
}
}
@Override
protected void onDestroy() {
super.onDestroy();
......
......@@ -15,7 +15,6 @@ import android.os.Environment;
import android.provider.MediaStore;
import android.text.TextUtils;
import android.util.Log;
import com.example.yourcashiertest.R;
import com.example.yourcashiertest.databinding.ActivityProductBinding;
import com.example.yourcashiertest.entities.Product;
......
......@@ -19,7 +19,6 @@ import java.util.List;
public class CartAdapter extends RecyclerView.Adapter<CartAdapter.ViewHolder> {
private List<Cart> carts = new ArrayList<>();
public interface CartListener{
void onIncrease(Cart cart);
void onDecrease(Cart cart);
......
package com.example.yourcashiertest.adapters;
import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RadioButton;
import androidx.annotation.NonNull;
import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.RecyclerView;
import com.example.yourcashiertest.R;
import com.example.yourcashiertest.activities.PaymentActivity;
import com.example.yourcashiertest.databinding.PaymentItemBinding;
import com.example.yourcashiertest.models.ResponsePayment;
import java.util.ArrayList;
public class PaymentAdapter extends RecyclerView.Adapter<PaymentAdapter.ViewHolder> {
private ArrayList<ResponsePayment> responsePayments;
Context context;
int getPosition = -1;
public interface PaymentListener {
void onSelectPayment(ResponsePayment responsePayment);
}
private PaymentListener listener;
public void setListener(PaymentListener listener) {
this.listener = listener;
}
public PaymentAdapter(ArrayList<ResponsePayment> responsePayments, PaymentActivity paymentActivity) {
this.responsePayments = responsePayments;
this.context = paymentActivity;
}
@NonNull
@Override
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
PaymentItemBinding paymentItemBinding = DataBindingUtil.inflate(
LayoutInflater.from(parent.getContext()),
R.layout.payment_item,
parent,
false
);
return new ViewHolder(paymentItemBinding);
}
@Override
public void onBindViewHolder (@NonNull PaymentAdapter.ViewHolder holder,int position){
holder.binData(responsePayments.get(position));
holder.radioButton.setChecked(position == getPosition);
}
@Override
public int getItemCount () {
return responsePayments.size();
}
public class ViewHolder extends RecyclerView.ViewHolder{
PaymentItemBinding binding;
RadioButton radioButton;
public ViewHolder(@NonNull PaymentItemBinding itemView) {
super(itemView.getRoot());
this.binding = itemView;
this.radioButton = itemView.rbPayment;
}
@SuppressLint("ResourceAsColor")
public void binData(ResponsePayment responsePayment){
binding.setPayment(responsePayment);
binding.setLogo(responsePayment.getUrl());
binding.cvPayment.setOnClickListener(view ->{
getPosition = getAdapterPosition();
notifyDataSetChanged();
listener.onSelectPayment(responsePayment);});
}
}
}
......@@ -17,6 +17,9 @@ public interface ProductDao {
@Query("SELECT * FROM products ORDER BY id DESC")
public LiveData<List<Product>> getProducts();
// @Query("SELECT category FROM products")
// public LiveData<List<Product>> getAllCategory();
@Query("SELECT * FROM products WHERE name LIKE :query OR category LIKE:query ORDER BY id DESC")
public LiveData<List<Product>> getFilteredProducts(String query);
......
package com.example.yourcashiertest.models;
import android.widget.ImageView;
import androidx.databinding.BindingAdapter;
import com.bumptech.glide.Glide;
public class ResponsePayment {
private String url;
private String bank;
private boolean isSelected;
public boolean isSelected() {
return isSelected;
}
public void setSelected(boolean selected) {
isSelected = selected;
}
public ResponsePayment(String url, String bank) {
this.url = url;
this.bank = bank;
}
public void setUrl(String url) {
this.url = url;
}
public String getUrl() {
return url;
}
public String getBank() {
return bank;
}
public void setBank(String bank) {
this.bank = bank;
}
@BindingAdapter("img_bank")
public static void loadImage(ImageView view, String url) {
Glide.with(view.getContext())
.load(url)
.into(view);
}
}
......@@ -37,5 +37,6 @@ public class ProductRepository {
public LiveData<List<Product>> filteredProducts(String s) {
return productDao.getFilteredProducts(s);
}
}
......@@ -19,7 +19,6 @@ public class ProductViewModel extends AndroidViewModel {
private MutableLiveData<String> photo = new MutableLiveData<>("");
private MutableLiveData<String> query = new MutableLiveData<>("%");
private MutableLiveData<String> category = new MutableLiveData<>("%");
private MutableLiveData<Product> product = new MutableLiveData<>();
private LiveData<List<Product>> products;
......
......@@ -32,7 +32,7 @@
android:gravity="top"
android:text="@string/payment"
android:textAppearance="@style/payment"
app:layout_constraintBottom_toTopOf="@id/cvCash"
app:layout_constraintBottom_toTopOf="@id/rvPayment"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
......@@ -47,105 +47,37 @@
android:gravity="center"
android:text="@{amount}"
android:textSize="24dp"
app:layout_constraintBottom_toTopOf="@id/rvPayment"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.902"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvPayment"
app:layout_constraintVertical_bias="0.0" />
<com.google.android.material.card.MaterialCardView
android:id="@+id/cvCash"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_marginTop="20dp"
android:clickable="true"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tvTotal">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="100dp"
android:paddingVertical="5dp">
<ImageView
android:id="@+id/iv_cash"
android:layout_width="150dp"
android:layout_height="0dp"
android:layout_marginStart="4dp"
android:src="@drawable/ic_undraw_wallet"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="1.0" />
<CheckBox
android:id="@+id/cbCash"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="20dp"
android:buttonTint="@color/black"
android:text="Cash"
android:checked="@{checkCash}"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.card.MaterialCardView>
<com.google.android.material.card.MaterialCardView
android:id="@+id/cvCard"
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rvPayment"
android:layout_width="match_parent"
android:layout_height="100dp"
android:clickable="true"
android:layout_marginTop="20dp"
android:layout_height="wrap_content"
android:padding="@dimen/space_small"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toTopOf="@id/tvAmountPaid"
app:layout_constraintHorizontal_bias="0.666"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/cvCash"
app:layout_constraintVertical_bias="0.04000002">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingVertical="5dp">
<ImageView
android:id="@+id/iv_card"
android:layout_width="150dp"
android:layout_height="0dp"
android:src="@drawable/ic_undraw_credit_card"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<CheckBox
android:id="@+id/cbCard"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="20dp"
android:buttonTint="@color/black"
android:text="Card"
android:checked="@{checkCard}"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.card.MaterialCardView>
tools:listitem="@layout/payment_item" />
<TextView
android:id="@+id/tvAmountPaid"
android:layout_width="100dp"
android:layout_height="30dp"
android:layout_marginTop="208dp"
android:layout_marginBottom="70dp"
android:layout_marginBottom="20dp"
android:gravity="start"
android:text="Amount paid"
app:layout_constraintBottom_toTopOf="@id/etAmountPaid"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/cvCard" />
app:layout_constraintStart_toStartOf="parent" />
<EditText
android:id="@+id/etAmountPaid"
......
......@@ -18,30 +18,32 @@
<com.google.android.material.card.MaterialCardView
android:id="@+id/cvCategory"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_height="30dp"
android:backgroundTint="@color/colorPrimaryDark"
android:checkable="true"
android:clickable="true"
android:clipToPadding="true"
android:focusable="true"
android:checkable="true"
app:cardCornerRadius="10dp"
android:clipToPadding="true"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent">
app:layout_constraintTop_toTopOf="parent">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingHorizontal="15dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="center"
android:text="@{category}"
android:textSize="18sp"
tools:text="@tools:sample/lorem"
android:textColor="#fff"
android:layout_centerInParent="true"/>
android:textSize="18sp"
tools:text="@tools:sample/lorem" />
</RelativeLayout>
</com.google.android.material.card.MaterialCardView>
</androidx.constraintlayout.widget.ConstraintLayout>
......
<?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">
<data>
<variable
name="logo"
type="String" />
<variable
name="payment"
type="com.example.yourcashiertest.models.ResponsePayment" />
</data>
<com.google.android.material.card.MaterialCardView
android:id="@+id/cvPayment"
android:clickable="true"
android:focusable="true"
android:checkable="true"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_marginVertical="10dp"
android:layout_marginHorizontal="2dp"
app:layout_constraintTop_toTopOf="parent"
app:strokeWidth="1dp">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="15dp">
<ImageView
android:id="@+id/ivLogo"
android:layout_width="120dp"
android:layout_height="100dp"
android:src="@drawable/ic_undraw_wallet"
app:img_bank="@{logo}"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>
<RadioButton
android:id="@+id/rbPayment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:buttonTint="@color/colorPrimary"
android:enabled="false"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.card.MaterialCardView>
</layout>
\ 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