Commit 5ce1aee8 authored by Ahmad Abi Mulya's avatar Ahmad Abi Mulya
parents 0020fa87 d5c598da
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.yourcashiertest"> package="com.example.yourcashiertest">
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-feature <uses-feature
android:name="android.hardware.camera" android:name="android.hardware.camera"
android:required="true" /> android:required="true" />
...@@ -19,23 +21,23 @@ ...@@ -19,23 +21,23 @@
android:theme="@style/AppTheme2"> android:theme="@style/AppTheme2">
<activity <activity
android:name=".activities.SkActivity" android:name=".activities.SkActivity"
android:screenOrientation="portrait"/> android:screenOrientation="portrait" />
<activity <activity
android:name=".activities.WelcomeActivity" android:name=".activities.WelcomeActivity"
android:screenOrientation="portrait"/> android:screenOrientation="portrait" />
<activity <activity
android:name=".activities.ForgetPassword" android:name=".activities.ForgetPassword"
android:screenOrientation="portrait"/> android:screenOrientation="portrait" />
<activity <activity
android:name=".activities.RegisterActivity" android:name=".activities.RegisterActivity"
android:screenOrientation="portrait"/> android:screenOrientation="portrait" />
<activity <activity
android:name=".activities.StatusPayment" android:name=".activities.StatusPayment"
android:screenOrientation="portrait"/> android:screenOrientation="portrait" />
<activity <activity
android:name=".activities.SplashActivity" android:name=".activities.SplashActivity"
android:theme="@style/AppTheme2" android:screenOrientation="portrait"
android:screenOrientation="portrait"> android:theme="@style/AppTheme2">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />
...@@ -44,19 +46,20 @@ ...@@ -44,19 +46,20 @@
</activity> </activity>
<activity <activity
android:name=".activities.PaymentActivity" android:name=".activities.PaymentActivity"
android:screenOrientation="portrait"/> android:screenOrientation="portrait" />
<activity <activity
android:name=".activities.CartActivity" android:name=".activities.CartActivity"
android:screenOrientation="portrait"/> android:screenOrientation="portrait" />
<activity <activity
android:name=".activities.MainActivity" android:name=".activities.MainActivity"
android:screenOrientation="portrait"/> android:screenOrientation="portrait" />
<activity <activity
android:name=".activities.ProductActivity" android:name=".activities.ProductActivity"
android:screenOrientation="portrait"/> android:screenOrientation="portrait" />
<activity <activity
android:name=".activities.LoginActivity" android:name=".activities.LoginActivity"
android:screenOrientation="portrait"/> android:screenOrientation="portrait" />
<provider <provider
android:name="androidx.core.content.FileProvider" android:name="androidx.core.content.FileProvider"
android:authorities="com.example.yourcashiertest.fileprovider" android:authorities="com.example.yourcashiertest.fileprovider"
......
...@@ -2,7 +2,6 @@ package com.example.yourcashiertest.activities; ...@@ -2,7 +2,6 @@ package com.example.yourcashiertest.activities;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import androidx.databinding.DataBindingUtil; import androidx.databinding.DataBindingUtil;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider; import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.LinearLayoutManager;
......
...@@ -14,12 +14,8 @@ import android.widget.Toast; ...@@ -14,12 +14,8 @@ import android.widget.Toast;
import com.example.yourcashiertest.R; import com.example.yourcashiertest.R;
import com.example.yourcashiertest.databinding.ActivityForgetPasswordBinding; import com.example.yourcashiertest.databinding.ActivityForgetPasswordBinding;
import com.example.yourcashiertest.models.Password; import com.example.yourcashiertest.models.Password;
import com.example.yourcashiertest.models.User;
import com.example.yourcashiertest.utils.ViewUtil;
import com.example.yourcashiertest.viewmodels.UserViewModel; import com.example.yourcashiertest.viewmodels.UserViewModel;
import java.util.List;
public class ForgetPassword extends AppCompatActivity { public class ForgetPassword extends AppCompatActivity {
ActivityForgetPasswordBinding binding; ActivityForgetPasswordBinding binding;
......
...@@ -19,6 +19,7 @@ import android.widget.PopupMenu; ...@@ -19,6 +19,7 @@ import android.widget.PopupMenu;
import android.widget.Toast; import android.widget.Toast;
import com.example.yourcashiertest.R; import com.example.yourcashiertest.R;
import com.example.yourcashiertest.adapters.CategoryAdapter;
import com.example.yourcashiertest.adapters.ProductAdapter; import com.example.yourcashiertest.adapters.ProductAdapter;
import com.example.yourcashiertest.databinding.ActivityMainBinding; import com.example.yourcashiertest.databinding.ActivityMainBinding;
import com.example.yourcashiertest.entities.Cart; import com.example.yourcashiertest.entities.Cart;
...@@ -26,6 +27,7 @@ import com.example.yourcashiertest.entities.Product; ...@@ -26,6 +27,7 @@ import com.example.yourcashiertest.entities.Product;
import com.example.yourcashiertest.viewmodels.CartViewModel; import com.example.yourcashiertest.viewmodels.CartViewModel;
import com.example.yourcashiertest.viewmodels.ProductViewModel; import com.example.yourcashiertest.viewmodels.ProductViewModel;
import java.util.ArrayList;
import java.util.List; import java.util.List;
...@@ -55,6 +57,7 @@ public class MainActivity extends AppCompatActivity { ...@@ -55,6 +57,7 @@ public class MainActivity extends AppCompatActivity {
prefManager = new PrefManager(this); prefManager = new PrefManager(this);
ProductAdapter adapter = new ProductAdapter(); ProductAdapter adapter = new ProductAdapter();
CategoryAdapter categoryAdapter = new CategoryAdapter();
binding = DataBindingUtil.setContentView(this, R.layout.activity_main); binding = DataBindingUtil.setContentView(this, R.layout.activity_main);
cartViewModel = new ViewModelProvider(this).get(CartViewModel.class); cartViewModel = new ViewModelProvider(this).get(CartViewModel.class);
...@@ -109,10 +112,22 @@ public class MainActivity extends AppCompatActivity { ...@@ -109,10 +112,22 @@ public class MainActivity extends AppCompatActivity {
popupMenu.show(); popupMenu.show();
}); });
// binding.rvCategory.setLayoutManager(new LinearLayoutManager(MainActivity.this, LinearLayoutManager.HORIZONTAL, false)); binding.rvCategory.setLayoutManager(new LinearLayoutManager(MainActivity.this,
LinearLayoutManager.HORIZONTAL, false));
binding.rvCategory.setAdapter(categoryAdapter);
binding.rvProducts.setAdapter(adapter); binding.rvProducts.setAdapter(adapter);
viewModel = new ViewModelProvider(this).get(ProductViewModel.class); 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<>();
for (int i = 0; i < products.size(); i++){
list.add(products.get(i).getCategory());
}
categoryAdapter.setCategories(list);
});
categoryAdapter.setListener(category -> viewModel.filter(category));
adapter.setListener(new ProductAdapter.ProductListener() { adapter.setListener(new ProductAdapter.ProductListener() {
@Override @Override
......
package com.example.yourcashiertest.adapters;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.RecyclerView;
import com.example.yourcashiertest.R;
import com.example.yourcashiertest.databinding.CategoryItemBinding;
import java.util.ArrayList;
import java.util.List;
public class CategoryAdapter extends RecyclerView.Adapter<CategoryAdapter.ViewHolder> {
List<String> categories = new ArrayList<>();
public interface CategoryListener{
void onClickItem(String category);
}
private CategoryListener listener;
public void setListener(CategoryListener listener){
this.listener = listener;
}
public void setCategories(List<String> categories) {
this.categories = categories;
notifyDataSetChanged();
}
@NonNull
@Override
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
return new CategoryAdapter.ViewHolder(
DataBindingUtil.inflate(
LayoutInflater.from(parent.getContext()),
R.layout.category_item,
parent,
false
)
);
}
@Override
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
holder.bindData(categories.get(position), listener);
}
@Override
public int getItemCount() {
return categories.size();
}
public class ViewHolder extends RecyclerView.ViewHolder {
CategoryItemBinding binding;
public ViewHolder(@NonNull CategoryItemBinding binding) {
super(binding.getRoot());
this.binding = binding;
}
public void bindData(String category, CategoryListener listener){
binding.setCategory(category);
binding.cvCategory.setOnClickListener(v -> listener.onClickItem(category));
}
}
}
package com.example.yourcashiertest.adapters; package com.example.yourcashiertest.adapters;
import android.graphics.Color;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.ViewGroup; import android.view.ViewGroup;
...@@ -87,6 +88,15 @@ public class ProductAdapter extends RecyclerView.Adapter<ProductAdapter.ViewHold ...@@ -87,6 +88,15 @@ public class ProductAdapter extends RecyclerView.Adapter<ProductAdapter.ViewHold
rupiah.setDecimalFormatSymbols(format); rupiah.setDecimalFormatSymbols(format);
binding.setPrice(rupiah.format(product.getPrice())); binding.setPrice(rupiah.format(product.getPrice()));
if (product.getQuantity() > 0 ) {
binding.setStock("Available");
binding.tvStock.setTextColor(Color.parseColor("#009688"));
} else {
binding.setStock("Sold Out");
binding.tvStock.setTextColor(Color.parseColor("#BD0303"));
binding.vAdd.setEnabled(false);
}
binding.ivUpdate.setOnClickListener(view -> listener.onUpdate(product)); binding.ivUpdate.setOnClickListener(view -> listener.onUpdate(product));
binding.ivDelete.setOnClickListener(view -> listener.onDelete(product)); binding.ivDelete.setOnClickListener(view -> listener.onDelete(product));
......
...@@ -17,7 +17,7 @@ public interface ProductDao { ...@@ -17,7 +17,7 @@ public interface ProductDao {
@Query("SELECT * FROM products ORDER BY id DESC") @Query("SELECT * FROM products ORDER BY id DESC")
public LiveData<List<Product>> getProducts(); public LiveData<List<Product>> getProducts();
@Query("SELECT * FROM products WHERE name LIKE :query ORDER BY id DESC") @Query("SELECT * FROM products WHERE name LIKE :query OR category LIKE:query ORDER BY id DESC")
public LiveData<List<Product>> getFilteredProducts(String query); public LiveData<List<Product>> getFilteredProducts(String query);
@Insert(onConflict = OnConflictStrategy.IGNORE) @Insert(onConflict = OnConflictStrategy.IGNORE)
......
...@@ -19,6 +19,7 @@ public class ProductViewModel extends AndroidViewModel { ...@@ -19,6 +19,7 @@ public class ProductViewModel extends AndroidViewModel {
private MutableLiveData<String> photo = new MutableLiveData<>(""); private MutableLiveData<String> photo = new MutableLiveData<>("");
private MutableLiveData<String> query = new MutableLiveData<>("%"); private MutableLiveData<String> query = new MutableLiveData<>("%");
private MutableLiveData<String> category = new MutableLiveData<>("%");
private MutableLiveData<Product> product = new MutableLiveData<>(); private MutableLiveData<Product> product = new MutableLiveData<>();
private LiveData<List<Product>> products; private LiveData<List<Product>> products;
...@@ -44,7 +45,6 @@ public class ProductViewModel extends AndroidViewModel { ...@@ -44,7 +45,6 @@ public class ProductViewModel extends AndroidViewModel {
super(application); super(application);
repository = new ProductRepository(application); repository = new ProductRepository(application);
products = Transformations.switchMap(query, s -> repository.filteredProducts(s)); products = Transformations.switchMap(query, s -> repository.filteredProducts(s));
} }
......
...@@ -128,22 +128,21 @@ ...@@ -128,22 +128,21 @@
android:imeOptions="actionSearch" android:imeOptions="actionSearch"
android:inputType="textCapWords" android:inputType="textCapWords"
android:textSize="@dimen/text_default" /> android:textSize="@dimen/text_default" />
<!-- <androidx.recyclerview.widget.RecyclerView--> <androidx.recyclerview.widget.RecyclerView
<!-- android:id="@+id/rvCategory"--> android:id="@+id/rvCategory"
<!-- android:layout_width="match_parent"--> android:layout_width="match_parent"
<!-- android:layout_height="0dp"--> android:layout_height="wrap_content"
<!-- tools:listitem="@layout/category_item"--> app:layout_constraintStart_toStartOf="parent"
<!-- app:layout_constraintStart_toStartOf="parent"--> app:layout_constraintEnd_toEndOf="parent"
<!-- app:layout_constraintEnd_toEndOf="parent"--> app:layout_constraintTop_toBottomOf="@id/rectangle_4"
<!-- app:layout_constraintTop_toBottomOf="@id/rectangle_4"--> app:layout_constraintBottom_toTopOf="@id/rvProducts"
<!-- app:layout_constraintBottom_toTopOf="@id/rvProducts"--> />
<!-- />-->
<androidx.recyclerview.widget.RecyclerView <androidx.recyclerview.widget.RecyclerView
android:id="@+id/rvProducts" android:id="@+id/rvProducts"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="0dp" android:layout_height="0dp"
android:layout_marginVertical="15dp" app:layout_constraintTop_toBottomOf="@id/rvCategory"
app:layout_constraintTop_toBottomOf="@id/rectangle_4"
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"
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
<com.google.android.material.card.MaterialCardView <com.google.android.material.card.MaterialCardView
android:id="@+id/cvCategory" android:id="@+id/cvCategory"
android:layout_width="match_parent" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:backgroundTint="@color/colorPrimaryDark" android:backgroundTint="@color/colorPrimaryDark"
android:clickable="true" android:clickable="true"
...@@ -31,17 +31,16 @@ ...@@ -31,17 +31,16 @@
app:layout_constraintEnd_toEndOf="parent"> app:layout_constraintEnd_toEndOf="parent">
<RelativeLayout <RelativeLayout
android:layout_width="match_parent" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:paddingHorizontal="20dp"> android:paddingHorizontal="15dp">
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="Example" android:text="@{category}"
android:textStyle="bold" android:textSize="18sp"
android:textSize="20sp" tools:text="@tools:sample/lorem"
android:textColor="#fff" android:textColor="#fff"
tools:text="elizabeth"
android:layout_centerInParent="true"/> android:layout_centerInParent="true"/>
</RelativeLayout> </RelativeLayout>
</com.google.android.material.card.MaterialCardView> </com.google.android.material.card.MaterialCardView>
......
...@@ -16,6 +16,10 @@ ...@@ -16,6 +16,10 @@
<variable <variable
name="visibility" name="visibility"
type="boolean" /> type="boolean" />
<variable
name="stock"
type="String" />
</data> </data>
<com.google.android.material.card.MaterialCardView <com.google.android.material.card.MaterialCardView
...@@ -79,6 +83,7 @@ ...@@ -79,6 +83,7 @@
android:layout_marginTop="8dp" android:layout_marginTop="8dp"
android:maxLength="20" android:maxLength="20"
android:maxLines="1" android:maxLines="1"
tools:text="Burger mekdi bk"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.45" app:layout_constraintHorizontal_bias="0.45"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
...@@ -91,15 +96,12 @@ ...@@ -91,15 +96,12 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@{product.description}" android:text="@{product.description}"
android:layout_marginTop="8dp" android:layout_marginTop="8dp"
android:layout_marginBottom="8dp" android:layout_marginBottom="@dimen/space_default"
android:maxLength="40" android:maxLength="40"
android:maxLines="2" android:maxLines="2"
tools:text="@tools:sample/lorem"
app:layout_constraintTop_toBottomOf="@id/tv_name" app:layout_constraintTop_toBottomOf="@id/tv_name"
app:layout_constraintBottom_toTopOf="@id/tv_price" app:layout_constraintBottom_toTopOf="@id/tv_price" />
app:layout_constraintEnd_toEndOf="@+id/tv_name"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="@+id/tv_name"
app:layout_constraintVertical_bias="0.045" />
<TextView <TextView
android:id="@+id/tv_price" android:id="@+id/tv_price"
...@@ -107,11 +109,22 @@ ...@@ -107,11 +109,22 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@{price}" android:text="@{price}"
android:textStyle="bold" android:textStyle="bold"
tools:text="rp.200000"
android:layout_marginTop="@dimen/space_default"
app:layout_constraintTop_toBottomOf="@id/tv_desc"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintVertical_bias="0.0" />
<TextView
android:id="@+id/tvStock"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@{stock}"
android:textStyle="bold"
tools:text="Available"
android:layout_marginTop="8dp" android:layout_marginTop="8dp"
app:layout_constraintBottom_toTopOf="@id/v_add" app:layout_constraintTop_toBottomOf="@+id/tv_price"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="@+id/tv_desc"
app:layout_constraintVertical_bias="0.0" /> app:layout_constraintVertical_bias="0.0" />
<com.google.android.material.button.MaterialButton <com.google.android.material.button.MaterialButton
...@@ -120,7 +133,8 @@ ...@@ -120,7 +133,8 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="50dp" android:layout_height="50dp"
android:padding="5dp" android:padding="5dp"
android:layout_marginTop="8dp" android:layout_marginTop="@dimen/space_default"
app:layout_constraintTop_toBottomOf="@+id/tvStock"
app:cornerRadius="5dp" app:cornerRadius="5dp"
app:icon="@drawable/ic_baseline_add_shopping_cart_24" app:icon="@drawable/ic_baseline_add_shopping_cart_24"
app:iconGravity="textStart" app:iconGravity="textStart"
......
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
<color name="dot_light_screen2">#A9A9A9</color> <color name="dot_light_screen2">#A9A9A9</color>
<color name="dot_light_screen3">#A9A9A9</color> <color name="dot_light_screen3">#A9A9A9</color>
<color name="dot_light_screen4">#A9A9A9</color> <color name="dot_light_screen4">#A9A9A9</color>
<array name="array_dot_active"> <array name="array_dot_active">
<item>@color/dot_light_screen1</item> <item>@color/dot_light_screen1</item>
<item>@color/dot_light_screen2</item> <item>@color/dot_light_screen2</item>
......
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