Commit 77bd59af authored by Wahyu Wibowo's avatar Wahyu Wibowo

crud product

parent 8e558b90
package com.example.yourcashiertest.daos; package com.example.yourcashiertest.daos;
import androidx.lifecycle.LiveData;
import androidx.room.Dao;
import androidx.room.Delete;
import androidx.room.Insert;
import androidx.room.OnConflictStrategy;
import androidx.room.Query;
import androidx.room.Update;
import com.example.yourcashiertest.entities.Product;
import java.util.List;
@Dao
public interface ProductDao { public interface ProductDao {
@Query("SELECT * FROM products ORDER BY id DESC")
public LiveData<List<Product>> getProducts();
@Query("SELECT * FROM products WHERE name LIKE :query ORDER BY id DESC")
public LiveData<List<Product>> getFilteredProducts(String query);
@Insert(onConflict = OnConflictStrategy.IGNORE)
public void insertProduct(Product product);
@Update
public void updateProduct(Product product);
@Delete
public void deleteProduct(Product product);
} }
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<corners
android:radius="50dp"/>
<stroke
android:width="0.5dp"
android:color="#45E1D1" />
<solid android:color="#45E1D1" />
</shape>
\ No newline at end of file
...@@ -7,6 +7,10 @@ ...@@ -7,6 +7,10 @@
<variable <variable
name="photo" name="photo"
type="String" /> type="String" />
<variable
name="viewModel"
type="com.example.yourcashiertest.viewmodels.ProductViewModel" />
</data> </data>
<LinearLayout <LinearLayout
......
...@@ -58,7 +58,7 @@ ...@@ -58,7 +58,7 @@
app:layout_constraintVertical_bias="1.0" /> app:layout_constraintVertical_bias="1.0" />
<View <View
android:id="@+id/rectangle_1" android:id="@+id/v_add"
android:layout_width="78dp" android:layout_width="78dp"
android:layout_height="40dp" android:layout_height="40dp"
android:layout_alignParentLeft="true" android:layout_alignParentLeft="true"
...@@ -77,9 +77,9 @@ ...@@ -77,9 +77,9 @@
android:layout_height="10dp" android:layout_height="10dp"
android:layout_marginStart="8dp" android:layout_marginStart="8dp"
android:background="@drawable/minus" android:background="@drawable/minus"
app:layout_constraintBottom_toBottomOf="@+id/rectangle_1" app:layout_constraintBottom_toBottomOf="@+id/v_add"
app:layout_constraintStart_toStartOf="@+id/rectangle_1" app:layout_constraintStart_toStartOf="@+id/v_add"
app:layout_constraintTop_toTopOf="@+id/rectangle_1" app:layout_constraintTop_toTopOf="@+id/v_add"
app:layout_constraintVertical_bias="0.566" /> app:layout_constraintVertical_bias="0.566" />
<Button <Button
...@@ -88,9 +88,9 @@ ...@@ -88,9 +88,9 @@
android:layout_height="10dp" android:layout_height="10dp"
android:layout_marginEnd="8dp" android:layout_marginEnd="8dp"
android:background="@drawable/plus" android:background="@drawable/plus"
app:layout_constraintBottom_toBottomOf="@+id/rectangle_1" app:layout_constraintBottom_toBottomOf="@+id/v_add"
app:layout_constraintEnd_toEndOf="@+id/rectangle_1" app:layout_constraintEnd_toEndOf="@+id/v_add"
app:layout_constraintTop_toTopOf="@+id/rectangle_1" app:layout_constraintTop_toTopOf="@+id/v_add"
app:layout_constraintVertical_bias="0.533" /> app:layout_constraintVertical_bias="0.533" />
<TextView <TextView
...@@ -98,10 +98,10 @@ ...@@ -98,10 +98,10 @@
android:layout_width="10dp" android:layout_width="10dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="2" android:text="2"
app:layout_constraintBottom_toBottomOf="@+id/rectangle_1" app:layout_constraintBottom_toBottomOf="@+id/v_add"
app:layout_constraintEnd_toStartOf="@+id/btn_add" app:layout_constraintEnd_toStartOf="@+id/btn_add"
app:layout_constraintStart_toEndOf="@+id/btn_min" app:layout_constraintStart_toEndOf="@+id/btn_min"
app:layout_constraintTop_toTopOf="@+id/rectangle_1" /> app:layout_constraintTop_toTopOf="@+id/v_add" />
<View <View
android:layout_width="match_parent" android:layout_width="match_parent"
......
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<com.google.android.material.card.MaterialCardView <layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools">
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.constraintlayout.widget.ConstraintLayout <data>
<variable
name="product"
type="com.example.yourcashiertest.entities.Product" />
<variable
name="price"
type="String" />
</data>
<com.google.android.material.card.MaterialCardView
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="wrap_content">
<ImageView <androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/imageView5" android:layout_width="match_parent"
android:layout_width="wrap_content" android:padding="10dp"
android:layout_height="wrap_content" android:layout_height="match_parent">
android:background="@drawable/elips"
app:layout_constraintBottom_toBottomOf="parent" <ImageView
app:layout_constraintEnd_toEndOf="parent" android:id="@+id/iv_product"
app:layout_constraintHorizontal_bias="0.452" android:layout_width="wrap_content"
app:layout_constraintStart_toStartOf="parent" android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent" android:background="@drawable/elips"
app:layout_constraintVertical_bias="0.026" app:layout_constraintBottom_toBottomOf="parent"
tools:srcCompat="@tools:sample/avatars" /> app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.452"
<TextView app:layout_constraintStart_toStartOf="parent"
android:id="@+id/tv_name" app:layout_constraintTop_toTopOf="parent"
android:layout_width="wrap_content" app:layout_constraintVertical_bias="0.026"
android:layout_height="wrap_content" tools:srcCompat="@tools:sample/avatars" />
android:text="Burger Medium"
app:layout_constraintBottom_toBottomOf="parent" <TextView
app:layout_constraintEnd_toEndOf="parent" android:id="@+id/tv_name"
app:layout_constraintHorizontal_bias="0.45" android:layout_width="match_parent"
app:layout_constraintStart_toStartOf="parent" android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@+id/imageView5" android:text="@string/name"
app:layout_constraintVertical_bias="0.089" /> android:layout_margin="20dp"
</androidx.constraintlayout.widget.ConstraintLayout> android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
</com.google.android.material.card.MaterialCardView> app:layout_constraintEnd_toEndOf="parent"
\ No newline at end of file app:layout_constraintHorizontal_bias="0.45"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/iv_product"
app:layout_constraintVertical_bias="0.089" />
<TextView
android:id="@+id/tv_desc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:text="@string/deskripsi"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="@+id/tv_name"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="@+id/tv_name"
app:layout_constraintTop_toBottomOf="@+id/tv_name"
app:layout_constraintVertical_bias="0.045" />
<TextView
android:id="@+id/tv_price"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/price"
android:layout_marginTop="3dp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.055"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tv_desc"
app:layout_constraintVertical_bias="0.038" />
<View
android:id="@+id/v_add"
android:layout_width="70dp"
android:layout_height="30dp"
android:background="@drawable/btn_shape"
app:layout_constraintBottom_toBottomOf="@+id/tv_price"
app:layout_constraintEnd_toEndOf="@+id/tv_name"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toEndOf="@+id/tv_price"
app:layout_constraintTop_toTopOf="@+id/tv_price"
app:layout_constraintVertical_bias="0.0" />
<ImageView
android:id="@+id/iv_add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="@+id/v_add"
app:layout_constraintEnd_toEndOf="@+id/v_add"
app:layout_constraintStart_toStartOf="@+id/v_add"
app:layout_constraintTop_toTopOf="@+id/v_add"
app:srcCompat="@drawable/ic_baseline_add_24" />
</androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.card.MaterialCardView>
</layout>
\ No newline at end of file
...@@ -17,4 +17,7 @@ ...@@ -17,4 +17,7 @@
<string name="rp_500_000">Rp. 500.000</string> <string name="rp_500_000">Rp. 500.000</string>
<string name="pay">Pay</string> <string name="pay">Pay</string>
<string name="checkout">Checkout</string> <string name="checkout">Checkout</string>
<string name="deskripsi">Burger medium with tomato and meet.</string>
<string name="name">Burger Medium</string>
<string name="price">$600.00</string>
</resources> </resources>
\ 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