Commit 57c631b0 authored by Ahmad Abi Mulya's avatar Ahmad Abi Mulya

fix issue double category and add all category filter

parent 17865116
......@@ -8,7 +8,9 @@ import androidx.recyclerview.widget.LinearLayoutManager;
import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Toast;
import com.example.yourcashiertest.R;
import com.example.yourcashiertest.adapters.CartAdapter;
......@@ -61,9 +63,17 @@ public class CartActivity extends AppCompatActivity {
adapter.setCartListener(new CartAdapter.CartListener() {
@Override
public void onIncrease(Cart cart) {
Log.d("stock1", ""+product.getQuantity());
Log.d("qty1", ""+cart.getQty());
if(product.getQuantity() < cart.getQty()){
Log.d("stock2", ""+product.getQuantity());
Log.d("qty2", ""+cart.getQty());
cart.setQty(cart.getQty() + 1);
cart.setPrice(cart.getRealPrice() * cart.getQty());
cartViewModel.updateCart(cart);
}else{
Toast.makeText(getApplicationContext(),"Product stock is not enough", Toast.LENGTH_LONG).show();
}
}
@Override
......@@ -71,7 +81,7 @@ public class CartActivity extends AppCompatActivity {
cart.setQty(cart.getQty() - 1);
cart.setPrice(cart.getRealPrice() * cart.getQty());
cartViewModel.updateCart(cart);
if (cart.getQty() <= 0){
if (cart.getQty() < 1){
cartViewModel.deleteCart(cart);
}
}
......
......@@ -19,6 +19,7 @@ import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.PopupMenu;
import android.widget.Toast;
......@@ -134,12 +135,11 @@ public class MainActivity extends AppCompatActivity {
Set<String> set = new HashSet<>();
List<String> category = new ArrayList<>();
for (int i = 0; i < product.size(); i++){
set.add(product.get(i).getCategory());
set.add(product.get(i).getCategory().toLowerCase());
}
category.addAll(set);
categoryAdapter.setCategories(category);
categoryAdapter.setListener(c -> viewModel.filter(c.toLowerCase()));
categoryAdapter.setListener(c -> viewModel.filter(c));
adapter.setListener(new ProductAdapter.ProductListener() {
@Override
public void onUpdate(Product product) {
......@@ -229,4 +229,5 @@ public class MainActivity extends AppCompatActivity {
super.onDestroy();
binding = null;
}
}
\ No newline at end of file
......@@ -67,7 +67,7 @@ public class ProductActivity extends AppCompatActivity{
fixProduct.setPhoto(file.getAbsolutePath());
}
fixProduct.setName(binding.etProduct.getText().toString());
fixProduct.setCategory(binding.etCategory.getText().toString());
fixProduct.setCategory(binding.etCategory.getText().toString().toLowerCase());
fixProduct.setDescription(binding.etDescription.getText().toString());
fixProduct.setPrice(Long.parseLong(TextUtils.
isEmpty(binding.etPrice.getText().toString()) ? "0" : binding.etPrice.getText().toString()));
......
......@@ -36,8 +36,6 @@ public class RegisterActivity extends AppCompatActivity {
if(binding.etUsername.getText().toString().length() == 0 || binding.etPassword.getText().toString().length() == 0
|| binding.etEmail.getText().toString().length() == 0 ||binding.etPhoneNumber.getText().toString().length() == 0){
Toast.makeText(getApplicationContext(), "Please input All Required Data", Toast.LENGTH_SHORT).show();
}else if(!binding.etPassword.getText().toString().matches("[A-Za-z0-9]+")){
binding.etPassword.setError("Passwords can only contain Alphanumeric");
}else if(binding.etPassword.getText().toString().length() < 8) {
binding.etPassword.setError("Password length cannot be less than 8 characters");
}else if(!binding.etPassword.getText().toString().equals(binding.etConfirmPassword.getText().toString())){
......
......@@ -126,11 +126,44 @@
android:imeOptions="actionSearch"
android:inputType="textCapWords"
android:textSize="@dimen/text_default" />
<com.google.android.material.card.MaterialCardView
android:id="@+id/cvAllCategory"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:backgroundTint="@color/colorPrimaryDark"
android:layout_marginLeft="15dp"
android:checkable="true"
android:clickable="true"
android:clipToPadding="true"
android:focusable="true"
app:cardCornerRadius="10dp"
app:layout_constraintBottom_toTopOf="@id/rvProducts"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/rectangle_4">
<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="all"
android:textColor="#fff"
android:textSize="18sp"
tools:text="@tools:sample/lorem" />
</RelativeLayout>
</com.google.android.material.card.MaterialCardView>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rvCategory"
android:layout_width="match_parent"
android:layout_width="300dp"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
android:layout_marginStart="8dp"
app:layout_constraintStart_toEndOf="@id/cvAllCategory"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/rectangle_4"
app:layout_constraintBottom_toTopOf="@id/rvProducts"
......
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