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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user