mirror of
https://github.com/Nezumi-2711/Foodify.git
synced 2026-09-22 13:38:41 +00:00
Improve UI - 2
This commit is contained in:
@@ -5,6 +5,7 @@ import android.graphics.Color;
|
|||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
|
import android.widget.LinearLayout;
|
||||||
import android.widget.ProgressBar;
|
import android.widget.ProgressBar;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
@@ -46,10 +47,11 @@ public class FavoriteFoodActivity extends AppCompatActivity implements ItemTouch
|
|||||||
private FoodFavoriteAdapter adapter;
|
private FoodFavoriteAdapter adapter;
|
||||||
private final List<Food> listFavoriteFood = new ArrayList<>();
|
private final List<Food> listFavoriteFood = new ArrayList<>();
|
||||||
private ImageView back_image;
|
private ImageView back_image;
|
||||||
private ConstraintLayout listFavoriteFoodView;
|
private ConstraintLayout listFavoriteFoodView, listFavoriteFoodLayout;
|
||||||
private NestedScrollView nestedScrollView;
|
private NestedScrollView nestedScrollView;
|
||||||
private ProgressBar progressBar;
|
private ProgressBar progressBar;
|
||||||
private TextView endOfListText;
|
private TextView endOfListText;
|
||||||
|
private LinearLayout no_food_favorite_layout;
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
@@ -60,6 +62,8 @@ public class FavoriteFoodActivity extends AppCompatActivity implements ItemTouch
|
|||||||
nestedScrollView = findViewById(R.id.nestedScrollView);
|
nestedScrollView = findViewById(R.id.nestedScrollView);
|
||||||
progressBar = findViewById(R.id.progress_bar);
|
progressBar = findViewById(R.id.progress_bar);
|
||||||
endOfListText = findViewById(R.id.end_of_list_text);
|
endOfListText = findViewById(R.id.end_of_list_text);
|
||||||
|
no_food_favorite_layout = findViewById(R.id.no_food_favorite_layout);
|
||||||
|
listFavoriteFoodLayout = findViewById(R.id.list_favorite_food_layout);
|
||||||
|
|
||||||
//Set event when user scroll down
|
//Set event when user scroll down
|
||||||
if (nestedScrollView != null) {
|
if (nestedScrollView != null) {
|
||||||
@@ -127,6 +131,14 @@ public class FavoriteFoodActivity extends AppCompatActivity implements ItemTouch
|
|||||||
LAST_PAGE = foodData.getPage().isLast();
|
LAST_PAGE = foodData.getPage().isLast();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(listFavoriteFood.size() == 0){
|
||||||
|
listFavoriteFoodLayout.setVisibility(View.GONE);
|
||||||
|
no_food_favorite_layout.setVisibility(View.VISIBLE);
|
||||||
|
} else {
|
||||||
|
listFavoriteFoodLayout.setVisibility(View.VISIBLE);
|
||||||
|
no_food_favorite_layout.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
|
||||||
if(LAST_PAGE){
|
if(LAST_PAGE){
|
||||||
progressBar.setVisibility(View.GONE);
|
progressBar.setVisibility(View.GONE);
|
||||||
endOfListText.setVisibility(View.VISIBLE);
|
endOfListText.setVisibility(View.VISIBLE);
|
||||||
@@ -160,12 +172,20 @@ public class FavoriteFoodActivity extends AppCompatActivity implements ItemTouch
|
|||||||
//Remove Item
|
//Remove Item
|
||||||
adapter.removeItem(foodDelete, indexDelete, this);
|
adapter.removeItem(foodDelete, indexDelete, this);
|
||||||
|
|
||||||
|
if(listFavoriteFood.size() == 0){
|
||||||
|
listFavoriteFoodLayout.setVisibility(View.GONE);
|
||||||
|
no_food_favorite_layout.setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
|
|
||||||
//Show notification food has been delete
|
//Show notification food has been delete
|
||||||
Snackbar snackbar = Snackbar.make(listFavoriteFoodView, foodNameDelete + " remove!", Snackbar.LENGTH_LONG);
|
Snackbar snackbar = Snackbar.make(listFavoriteFoodView, foodNameDelete + " remove!", Snackbar.LENGTH_LONG);
|
||||||
snackbar.setAction("Undo", new View.OnClickListener() {
|
snackbar.setAction("Undo", new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
adapter.undoItem(foodDelete, indexDelete, FavoriteFoodActivity.this);
|
adapter.undoItem(foodDelete, indexDelete, FavoriteFoodActivity.this);
|
||||||
|
|
||||||
|
listFavoriteFoodLayout.setVisibility(View.VISIBLE);
|
||||||
|
no_food_favorite_layout.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
snackbar.setActionTextColor(Color.YELLOW);
|
snackbar.setActionTextColor(Color.YELLOW);
|
||||||
|
|||||||
@@ -280,7 +280,6 @@ public class OrderCheckOutActivity extends AppCompatActivity {
|
|||||||
.setOnClickListener(new OnDialogClickListener() {
|
.setOnClickListener(new OnDialogClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(@NonNull AestheticDialog.Builder builder) {
|
public void onClick(@NonNull AestheticDialog.Builder builder) {
|
||||||
Common.LIST_BASKET_FOOD.clear();
|
|
||||||
startActivity(new Intent(OrderCheckOutActivity.this, MainActivity.class));
|
startActivity(new Intent(OrderCheckOutActivity.this, MainActivity.class));
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,6 +23,8 @@ import java.util.List;
|
|||||||
|
|
||||||
public class BasketAdapter extends RecyclerView.Adapter<BasketAdapter.BasketViewHolder> {
|
public class BasketAdapter extends RecyclerView.Adapter<BasketAdapter.BasketViewHolder> {
|
||||||
|
|
||||||
|
private static int quantity = 0;
|
||||||
|
|
||||||
public List<Basket> listBasketFood;
|
public List<Basket> listBasketFood;
|
||||||
|
|
||||||
private final BasketFragment basketFragment;
|
private final BasketFragment basketFragment;
|
||||||
@@ -46,6 +48,7 @@ public class BasketAdapter extends RecyclerView.Adapter<BasketAdapter.BasketView
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(@NonNull BasketViewHolder holder, int position) {
|
public void onBindViewHolder(@NonNull BasketViewHolder holder, int position) {
|
||||||
|
|
||||||
Basket foodBasket = listBasketFood.get(position);
|
Basket foodBasket = listBasketFood.get(position);
|
||||||
|
|
||||||
if(foodBasket == null)
|
if(foodBasket == null)
|
||||||
@@ -54,7 +57,8 @@ public class BasketAdapter extends RecyclerView.Adapter<BasketAdapter.BasketView
|
|||||||
//Init data
|
//Init data
|
||||||
holder.foodName.setText(foodBasket.getName());
|
holder.foodName.setText(foodBasket.getName());
|
||||||
holder.shopName.setText(foodBasket.getShopName());
|
holder.shopName.setText(foodBasket.getShopName());
|
||||||
holder.quantity.setNumber(foodBasket.getQuantity());
|
holder.value.setText(foodBasket.getQuantity());
|
||||||
|
quantity = Integer.parseInt(foodBasket.getQuantity());
|
||||||
|
|
||||||
//Check value discountPercent
|
//Check value discountPercent
|
||||||
float cost = 0;
|
float cost = 0;
|
||||||
@@ -82,18 +86,30 @@ public class BasketAdapter extends RecyclerView.Adapter<BasketAdapter.BasketView
|
|||||||
//Calculate total price
|
//Calculate total price
|
||||||
calculateTotalPrice();
|
calculateTotalPrice();
|
||||||
|
|
||||||
//Update quantity food when change quantity number
|
holder.increment.setOnClickListener(new View.OnClickListener() {
|
||||||
holder.quantity.setOnValueChangeListener(new ElegantNumberButton.OnValueChangeListener() {
|
|
||||||
@Override
|
@Override
|
||||||
public void onValueChange(ElegantNumberButton view, int oldValue, int newValue) {
|
public void onClick(View v) {
|
||||||
foodBasket.setQuantity(String.valueOf(newValue));
|
quantity++;
|
||||||
|
foodBasket.setQuantity(String.valueOf(quantity));
|
||||||
|
holder.value.setText(String.valueOf(quantity));
|
||||||
|
|
||||||
//Update total price
|
//Update total price
|
||||||
calculateTotalPrice();
|
calculateTotalPrice();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
//Auto delete food when quantity is 0
|
holder.decrement.setOnClickListener(new View.OnClickListener() {
|
||||||
if(newValue == 0){
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
quantity--;
|
||||||
|
if(quantity == 0){
|
||||||
listBasketFood.remove(holder.getAdapterPosition());
|
listBasketFood.remove(holder.getAdapterPosition());
|
||||||
|
} else {
|
||||||
|
foodBasket.setQuantity(String.valueOf(quantity));
|
||||||
|
holder.value.setText(String.valueOf(quantity));
|
||||||
|
|
||||||
|
//Update total price
|
||||||
|
calculateTotalPrice();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -118,10 +134,9 @@ public class BasketAdapter extends RecyclerView.Adapter<BasketAdapter.BasketView
|
|||||||
|
|
||||||
public static class BasketViewHolder extends RecyclerView.ViewHolder{
|
public static class BasketViewHolder extends RecyclerView.ViewHolder{
|
||||||
|
|
||||||
TextView foodName, shopName, price, total, discount;
|
TextView foodName, shopName, price, total, discount, increment, value, decrement;
|
||||||
public LinearLayout layoutForeGround;
|
public LinearLayout layoutForeGround;
|
||||||
ImageView imageView;
|
ImageView imageView;
|
||||||
ElegantNumberButton quantity;
|
|
||||||
|
|
||||||
public BasketViewHolder(@NonNull View itemView) {
|
public BasketViewHolder(@NonNull View itemView) {
|
||||||
super(itemView);
|
super(itemView);
|
||||||
@@ -131,9 +146,12 @@ public class BasketAdapter extends RecyclerView.Adapter<BasketAdapter.BasketView
|
|||||||
shopName = itemView.findViewById(R.id.shop_name_text_view);
|
shopName = itemView.findViewById(R.id.shop_name_text_view);
|
||||||
price = itemView.findViewById(R.id.price_text_view);
|
price = itemView.findViewById(R.id.price_text_view);
|
||||||
imageView = itemView.findViewById(R.id.image_view);
|
imageView = itemView.findViewById(R.id.image_view);
|
||||||
quantity = itemView.findViewById(R.id.quantity);
|
|
||||||
total = itemView.findViewById(R.id.total_text_view);
|
total = itemView.findViewById(R.id.total_text_view);
|
||||||
discount = itemView.findViewById(R.id.discount);
|
discount = itemView.findViewById(R.id.discount);
|
||||||
|
increment = itemView.findViewById(R.id.txt_increment);
|
||||||
|
decrement = itemView.findViewById(R.id.txt_decrement);
|
||||||
|
value = itemView.findViewById(R.id.value);
|
||||||
|
|
||||||
layoutForeGround = itemView.findViewById(R.id.layout_foreground);
|
layoutForeGround = itemView.findViewById(R.id.layout_foreground);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -179,7 +179,7 @@ public class FoodFavoriteAdapter extends RecyclerView.Adapter<FoodFavoriteAdapt
|
|||||||
FoodApiToken.apiService.addFoodToFavorite(Common.CURRENT_USER.getId(), Integer.parseInt(food.getId())).enqueue(new Callback<Food>() {
|
FoodApiToken.apiService.addFoodToFavorite(Common.CURRENT_USER.getId(), Integer.parseInt(food.getId())).enqueue(new Callback<Food>() {
|
||||||
@Override
|
@Override
|
||||||
public void onResponse(Call<Food> call, Response<Food> response) {
|
public void onResponse(Call<Food> call, Response<Food> response) {
|
||||||
Toast.makeText(context, "Đã thêm " + food.getName() + " vào danh sách yêu thích!", Toast.LENGTH_SHORT).show();
|
Toast.makeText(context, "Đã hoàn tác thành công!", Toast.LENGTH_SHORT).show();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Binary file not shown.
|
After Width: | Height: | Size: 8.8 KiB |
@@ -42,41 +42,81 @@
|
|||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<androidx.recyclerview.widget.RecyclerView
|
<androidx.constraintlayout.widget.ConstraintLayout
|
||||||
android:id="@+id/recycler_view_favorite_food"
|
android:id="@+id/list_favorite_food_layout"
|
||||||
tools:listitem="@layout/item_food_favorite"
|
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="15dp"
|
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
|
||||||
app:layout_constraintTop_toBottomOf="@id/text_view_1"
|
app:layout_constraintTop_toBottomOf="@id/text_view_1"
|
||||||
/>
|
|
||||||
|
|
||||||
<ProgressBar
|
|
||||||
android:id="@+id/progress_bar"
|
|
||||||
android:indeterminateTint="@color/primaryColor"
|
|
||||||
app:layout_constraintTop_toBottomOf="@id/recycler_view_favorite_food"
|
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/end_of_list_text"
|
|
||||||
android:text="End of list"
|
|
||||||
android:fontFamily="@font/opensans"
|
|
||||||
android:textColor="@color/grayLight"
|
|
||||||
android:visibility="gone"
|
android:visibility="gone"
|
||||||
app:layout_constraintTop_toBottomOf="@id/progress_bar"
|
>
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
android:id="@+id/recycler_view_favorite_food"
|
||||||
android:layout_width="wrap_content"
|
tools:listitem="@layout/item_food_favorite"
|
||||||
android:layout_height="wrap_content"
|
android:layout_width="match_parent"
|
||||||
/>
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="15dp"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<ProgressBar
|
||||||
|
android:id="@+id/progress_bar"
|
||||||
|
android:indeterminateTint="@color/primaryColor"
|
||||||
|
app:layout_constraintTop_toBottomOf="@id/recycler_view_favorite_food"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/end_of_list_text"
|
||||||
|
android:text="End of list"
|
||||||
|
android:fontFamily="@font/opensans"
|
||||||
|
android:textColor="@color/grayLight"
|
||||||
|
android:visibility="gone"
|
||||||
|
app:layout_constraintTop_toBottomOf="@id/progress_bar"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
/>
|
||||||
|
|
||||||
|
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
|
|
||||||
</androidx.core.widget.NestedScrollView>
|
</androidx.core.widget.NestedScrollView>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/no_food_favorite_layout"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
android:orientation="vertical"
|
||||||
|
>
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:src="@drawable/icon_favorite_food"
|
||||||
|
android:layout_width="120dp"
|
||||||
|
android:layout_height="120dp"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:fontFamily="@font/opensans"
|
||||||
|
android:textColor="@color/grayLight"
|
||||||
|
android:layout_marginTop="10dp"
|
||||||
|
android:text="Oops! Bạn chưa có món ăn yêu thích nào ở đây cả!"
|
||||||
|
android:layout_width="200dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:gravity="center"
|
||||||
|
/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
@@ -88,7 +88,7 @@
|
|||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
android:layout_weight="0.49"
|
android:layout_weight="0.7"
|
||||||
android:layout_marginStart="5dp"
|
android:layout_marginStart="5dp"
|
||||||
>
|
>
|
||||||
|
|
||||||
@@ -133,15 +133,52 @@
|
|||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<com.cepheuen.elegantnumberbutton.view.ElegantNumberButton
|
|
||||||
android:id="@+id/quantity"
|
<LinearLayout
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="match_parent"
|
||||||
app:backGroundColor="@color/white"
|
android:layout_weight="0.3"
|
||||||
app:textColor="@color/primaryColor"
|
>
|
||||||
android:layout_gravity="center_vertical"
|
|
||||||
android:layout_weight="0.5"
|
<TextView
|
||||||
/>
|
android:id="@+id/txt_increment"
|
||||||
|
android:text="+"
|
||||||
|
android:textSize="19sp"
|
||||||
|
android:textColor="@color/primaryColor"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center_vertical"
|
||||||
|
android:gravity="center"
|
||||||
|
android:layout_weight="0.2"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/value"
|
||||||
|
android:text="5"
|
||||||
|
android:textSize="20sp"
|
||||||
|
android:textColor="@color/primaryColor"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center_vertical"
|
||||||
|
android:gravity="center"
|
||||||
|
android:layout_weight="0.6"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/txt_decrement"
|
||||||
|
android:text="-"
|
||||||
|
android:textSize="25sp"
|
||||||
|
android:textColor="@color/primaryColor"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:gravity="center"
|
||||||
|
android:layout_gravity="center_vertical"
|
||||||
|
android:layout_weight="0.2"
|
||||||
|
/>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user