mirror of
https://github.com/Nezumi-2711/Foodify.git
synced 2026-09-22 20:00:50 +00:00
Add notification when basket empty
This commit is contained in:
@@ -57,6 +57,8 @@ public class AccountAndProfileActivity extends AppCompatActivity {
|
||||
}
|
||||
|
||||
private void initComponent() {
|
||||
//Init Component
|
||||
|
||||
textInput_email= (TextInputLayout) findViewById(R.id.textInput_email);
|
||||
textInput_phone = (TextInputLayout) findViewById(R.id.textInput_phone);
|
||||
textInput_fullName = (TextInputLayout) findViewById(R.id.textInput_fullName);
|
||||
|
||||
@@ -37,6 +37,7 @@ public class ResetPasswordActivity extends AppCompatActivity {
|
||||
|
||||
textInput_password.setTypeface(bebas);
|
||||
textInput_confirmPassword.setTypeface(bebas);
|
||||
//1587.57
|
||||
}
|
||||
|
||||
private void initComponent() {
|
||||
|
||||
@@ -7,7 +7,9 @@ import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.constraintlayout.widget.ConstraintLayout;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.recyclerview.widget.DividerItemDecoration;
|
||||
import androidx.recyclerview.widget.ItemTouchHelper;
|
||||
@@ -27,11 +29,13 @@ import java.util.List;
|
||||
|
||||
public class BasketFragment extends Fragment implements ItemTouchHelperListener {
|
||||
|
||||
private RecyclerView recyclerView_basket_food;
|
||||
public RecyclerView recyclerView_basket_food;
|
||||
private BasketAdapter adapter;
|
||||
private List<Basket> listBasketFood = new ArrayList<>();
|
||||
private RelativeLayout listBasketFoodView;
|
||||
|
||||
public ConstraintLayout empty_layout;
|
||||
|
||||
public TextView total;
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
@@ -44,6 +48,7 @@ public class BasketFragment extends Fragment implements ItemTouchHelperListener
|
||||
listBasketFoodView = view.findViewById(R.id.list_basket_food_view);
|
||||
adapter = new BasketAdapter(this);
|
||||
total = view.findViewById(R.id.total_text_view);
|
||||
empty_layout = view.findViewById(R.id.empty_layout);
|
||||
|
||||
//Init data
|
||||
total.setText(Common.changeCurrencyUnit(0));
|
||||
@@ -51,6 +56,15 @@ public class BasketFragment extends Fragment implements ItemTouchHelperListener
|
||||
//Get list food in basket
|
||||
getListBasketFood();
|
||||
|
||||
//Check list basket is null or not!
|
||||
if(Common.LIST_BASKET_FOOD.size() > 0){
|
||||
showRecycleViewAndHideNotificationEmpty();
|
||||
} else {
|
||||
hideRecyclerViewAndShowNotificationEmpty();
|
||||
}
|
||||
|
||||
Toast.makeText(getContext(), "List Basket: " + Common.LIST_BASKET_FOOD.size(), Toast.LENGTH_SHORT).show();
|
||||
|
||||
//Set layout recyclerview
|
||||
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getContext());
|
||||
recyclerView_basket_food.setLayoutManager(linearLayoutManager);
|
||||
@@ -64,18 +78,21 @@ public class BasketFragment extends Fragment implements ItemTouchHelperListener
|
||||
return view;
|
||||
}
|
||||
|
||||
private void showRecycleViewAndHideNotificationEmpty(){
|
||||
recyclerView_basket_food.setVisibility(View.VISIBLE);
|
||||
empty_layout.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
private void hideRecyclerViewAndShowNotificationEmpty(){
|
||||
recyclerView_basket_food.setVisibility(View.GONE);
|
||||
empty_layout.setVisibility(View.VISIBLE);
|
||||
}
|
||||
private void getListBasketFood(){
|
||||
//Get list food from basket
|
||||
listBasketFood = Common.LIST_BASKET_FOOD;
|
||||
adapter.setData(listBasketFood);
|
||||
recyclerView_basket_food.setAdapter(adapter);
|
||||
}
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
System.out.println("On Resume Fragment");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSwiped(RecyclerView.ViewHolder viewHolder) {
|
||||
if(viewHolder instanceof BasketAdapter.BasketViewHolder){
|
||||
|
||||
@@ -122,12 +122,35 @@ public class BasketAdapter extends RecyclerView.Adapter<BasketAdapter.BasketView
|
||||
notifyItemRemoved(index);
|
||||
|
||||
calculateTotalPrice();
|
||||
}
|
||||
|
||||
//Show notification empty basket
|
||||
if(listBasketFood.size() == 0){
|
||||
hideRecyclerViewAndShowNotificationEmpty();
|
||||
} else {
|
||||
showRecycleViewAndHideNotificationEmpty();
|
||||
}
|
||||
}
|
||||
public void undoItem(Basket food, int index, Context context){
|
||||
listBasketFood.add(index, food);
|
||||
notifyItemInserted(index);
|
||||
|
||||
calculateTotalPrice();
|
||||
|
||||
////Show notification empty basket
|
||||
if(listBasketFood.size() == 0){
|
||||
hideRecyclerViewAndShowNotificationEmpty();
|
||||
} else {
|
||||
showRecycleViewAndHideNotificationEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
private void showRecycleViewAndHideNotificationEmpty(){
|
||||
basketFragment.recyclerView_basket_food.setVisibility(View.VISIBLE);
|
||||
basketFragment.empty_layout.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
private void hideRecyclerViewAndShowNotificationEmpty(){
|
||||
basketFragment.recyclerView_basket_food.setVisibility(View.GONE);
|
||||
basketFragment.empty_layout.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
<vector android:height="50dp" android:viewportHeight="682.67"
|
||||
android:viewportWidth="682.67" android:width="50dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<group>
|
||||
<clip-path android:pathData="M0,0L682.67,0L682.67,682.67L0,682.67Z"/>
|
||||
<path android:fillColor="#00000000"
|
||||
android:pathData="m152.39,222.67l503.61,-0l-80,280l-354.67,-0c-22.09,-0 -40,17.91 -40,40 0,22.09 17.91,40 40,40l320,-0"
|
||||
android:strokeColor="#000000" android:strokeLineCap="butt"
|
||||
android:strokeLineJoin="miter" android:strokeWidth="40"/>
|
||||
<path android:fillColor="#00000000"
|
||||
android:pathData="M20,182.67C20,160.57 37.91,142.67 60,142.67L101.33,142.67C123.42,142.67 141.33,160.57 141.33,182.67"
|
||||
android:strokeColor="#000000" android:strokeLineCap="butt"
|
||||
android:strokeLineJoin="miter" android:strokeWidth="40"/>
|
||||
<path android:fillColor="#00000000"
|
||||
android:pathData="M221.33,502.67 L140.17,173.07"
|
||||
android:strokeColor="#000000" android:strokeLineCap="butt"
|
||||
android:strokeLineJoin="miter" android:strokeWidth="40"/>
|
||||
<path android:fillColor="#00000000"
|
||||
android:pathData="m341.33,622.67c0,22.09 -17.91,40 -40,40 -22.09,-0 -40,-17.91 -40,-40 0,-22.09 17.91,-40 40,-40C323.42,582.67 341.33,600.58 341.33,622.67Z"
|
||||
android:strokeColor="#000000" android:strokeLineCap="butt"
|
||||
android:strokeLineJoin="miter" android:strokeWidth="40"/>
|
||||
<path android:fillColor="#00000000"
|
||||
android:pathData="m581.33,622.67c0,22.09 -17.91,40 -40,40 -22.09,-0 -40,-17.91 -40,-40 0,-22.09 17.91,-40 40,-40C563.42,582.67 581.33,600.58 581.33,622.67Z"
|
||||
android:strokeColor="#000000" android:strokeLineCap="butt"
|
||||
android:strokeLineJoin="miter" android:strokeWidth="40"/>
|
||||
<path android:fillColor="#00000000"
|
||||
android:pathData="M401.33,60L401.33,20"
|
||||
android:strokeColor="#000000" android:strokeLineCap="square"
|
||||
android:strokeLineJoin="miter" android:strokeWidth="40"/>
|
||||
<path android:fillColor="#00000000"
|
||||
android:pathData="M288.2,106.86 L259.91,78.58"
|
||||
android:strokeColor="#000000" android:strokeLineCap="square"
|
||||
android:strokeLineJoin="miter" android:strokeWidth="40"/>
|
||||
<path android:fillColor="#00000000"
|
||||
android:pathData="M514.47,106.86 L542.75,78.58"
|
||||
android:strokeColor="#000000" android:strokeLineCap="square"
|
||||
android:strokeLineJoin="miter" android:strokeWidth="40"/>
|
||||
</group>
|
||||
</vector>
|
||||
@@ -8,21 +8,66 @@
|
||||
android:id="@+id/list_basket_food_view"
|
||||
>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/linearLayout"
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/recycler_view_basket_food"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:layout_height="wrap_content"
|
||||
tools:listitem="@layout/item_food_basket"
|
||||
android:visibility="gone"
|
||||
/>
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:id="@+id/empty_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_centerHorizontal="true"
|
||||
>
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/recycler_view_basket_food"
|
||||
android:layout_width="match_parent"
|
||||
<ImageView
|
||||
android:id="@+id/image_view"
|
||||
android:src="@drawable/cart_empty"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
tools:listitem="@layout/item_food_basket"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
tools:ignore="ContentDescription" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_view_header"
|
||||
android:text="Quên chưa đặt món rồi nè bạn ơi!"
|
||||
android:fontFamily="@font/opensans"
|
||||
android:textSize="18sp"
|
||||
android:textStyle="bold"
|
||||
android:textColor="@color/black"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="10dp"
|
||||
app:layout_constraintTop_toBottomOf="@id/image_view"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
/>
|
||||
|
||||
</LinearLayout>
|
||||
<TextView
|
||||
android:id="@+id/text_view_description"
|
||||
android:textAlignment="center"
|
||||
android:text="Bạn sẽ nhìn thấy các món ăn tại đây sau khi bỏ những món ăn bạn muốn vào giỏ hàng."
|
||||
android:fontFamily="@font/opensans"
|
||||
android:textSize="15sp"
|
||||
android:textStyle="bold"
|
||||
android:textColor="@color/gray"
|
||||
android:layout_marginTop="5dp"
|
||||
android:layout_marginEnd="40dp"
|
||||
android:layout_marginStart="40dp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constraintTop_toBottomOf="@id/text_view_header"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
/>
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
<androidx.cardview.widget.CardView
|
||||
android:id="@+id/cardView"
|
||||
@@ -30,9 +75,6 @@
|
||||
app:cardBackgroundColor="@color/green"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="100dp"
|
||||
app:layout_constraintTop_toBottomOf="@id/linearLayout"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
>
|
||||
|
||||
<RelativeLayout
|
||||
|
||||
Reference in New Issue
Block a user