Add shop detail screen

This commit is contained in:
Nezumi
2023-03-08 11:30:45 +07:00
parent e1b00117b6
commit 05871d7006
19 changed files with 460 additions and 17 deletions
+3
View File
@@ -15,6 +15,9 @@
android:theme="@style/Theme.Foodify"
tools:replace="android:theme"
tools:targetApi="31">
<activity
android:name=".Activity.ShopDetailActivity"
android:exported="false" />
<activity
android:name=".Activity.OrderDetailActivity"
android:exported="false" />
@@ -188,6 +188,14 @@ public class FoodDetailActivity extends AppCompatActivity {
}
}
});
//Move to shop detail screen when onClick
shopName_txt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
startActivity(new Intent(FoodDetailActivity.this, ShopDetailActivity.class));
}
});
}
private Basket getFoodExistInBasket(String foodId){
@@ -0,0 +1,64 @@
package com.capstone.foodify.Activity;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import com.capstone.foodify.Model.Food.Food;
import com.capstone.foodify.Model.Food.FoodFavoriteAdapter;
import com.capstone.foodify.Model.Food.FoodShopAdapter;
import com.capstone.foodify.R;
import com.google.android.material.appbar.CollapsingToolbarLayout;
import com.squareup.picasso.Picasso;
import java.util.ArrayList;
import java.util.List;
public class ShopDetailActivity extends AppCompatActivity {
private List<Food> listFood = new ArrayList<>();
ImageView imageShop, back_image;
RecyclerView recycler_view_food_shop;
FoodShopAdapter adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_shop_detail);
//Init Component
imageShop = findViewById(R.id.image_shop);
recycler_view_food_shop = findViewById(R.id.recycler_view_food_shop);
back_image = findViewById(R.id.back_image);
adapter = new FoodShopAdapter();
//Init temp data
Picasso.get().load("https://firebasestorage.googleapis.com/v0/b/foodify-55954.appspot.com/o/Free%20Food%20Advertising%20Banner%20Template.jpg?alt=media&token=8b836fd7-f18f-46c6-a14f-27680e51a1d5").into(imageShop);
for(int i = 1; i <= 10; i++){
listFood.add(new Food("https://images.unsplash.com/photo-1546069901-ba9599a7e63c?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxleHBsb3JlLWZlZWR8MXx8fGVufDB8fHx8&w=1000&q=80", "Food " + i, "50.000đ"));
}
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
recycler_view_food_shop.setLayoutManager(linearLayoutManager);
RecyclerView.ItemDecoration itemDecoration = new DividerItemDecoration(this, DividerItemDecoration.VERTICAL);
recycler_view_food_shop.addItemDecoration(itemDecoration);
adapter.setData(listFood);
recycler_view_food_shop.setAdapter(adapter);
back_image.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
onBackPressed();
}
});
}
}
@@ -147,8 +147,6 @@ public class SearchFragment extends Fragment {
foodAdapter.setData(listFoodSearch);
foodAdapter.notifyDataSetChanged();
hideProgressBarAndShowEndOfListText();
Toast.makeText(getContext(), "List food search: " + foodData.size(), Toast.LENGTH_SHORT).show();
}
private void getListCategory() {
@@ -9,6 +9,7 @@ public class Food implements Comparable<Food>{
private String description;
private String shopName;
private String reviewCount;
private String quantity_sold;
public Food() {
}
public Food(String id, String img, String name, String price, String shopName) {
@@ -19,6 +20,12 @@ public class Food implements Comparable<Food>{
this.shopName = shopName;
}
public Food(String img, String name, String price) {
this.img = img;
this.name = name;
this.price = price;
}
public String getId() {
return id;
}
@@ -68,6 +75,14 @@ public class Food implements Comparable<Food>{
this.reviewCount = reviewCount;
}
public String getQuantity_sold() {
return quantity_sold;
}
public void setQuantity_sold(String quantity_sold) {
this.quantity_sold = quantity_sold;
}
@Override
public int compareTo(Food food) {
if(getName().isEmpty() || food.getName().isEmpty()){
@@ -2,7 +2,6 @@ package com.capstone.foodify.Model.Food;
import android.content.Context;
import android.content.Intent;
import android.text.Layout;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@@ -17,9 +16,7 @@ import com.capstone.foodify.Common;
import com.capstone.foodify.R;
import com.squareup.picasso.Picasso;
import java.text.NumberFormat;
import java.util.List;
import java.util.Locale;
public class FoodAdapter extends RecyclerView.Adapter<FoodAdapter.FoodViewHolder>{
@@ -39,7 +36,7 @@ public class FoodAdapter extends RecyclerView.Adapter<FoodAdapter.FoodViewHolder
@NonNull
@Override
public FoodViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_foods, parent, false);
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_food, parent, false);
return new FoodViewHolder(view);
}
@@ -14,9 +14,7 @@ import com.capstone.foodify.Common;
import com.capstone.foodify.R;
import com.squareup.picasso.Picasso;
import java.text.NumberFormat;
import java.util.List;
import java.util.Locale;
public class FoodSearchAdapter extends RecyclerView.Adapter<FoodSearchAdapter.FoodViewHolder>{
@@ -36,7 +34,7 @@ public class FoodSearchAdapter extends RecyclerView.Adapter<FoodSearchAdapter.Fo
@NonNull
@Override
public FoodViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_foods_search, parent, false);
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_food_search, parent, false);
return new FoodViewHolder(view);
}
@@ -0,0 +1,71 @@
package com.capstone.foodify.Model.Food;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.capstone.foodify.R;
import com.google.android.material.appbar.CollapsingToolbarLayout;
import com.squareup.picasso.Picasso;
import java.util.List;
public class FoodShopAdapter extends RecyclerView.Adapter<FoodShopAdapter.FoodShopViewHolder> {
private List<Food> listFoodShop;
public FoodShopAdapter() {
}
public void setData(List<Food> listFoodShop){
this.listFoodShop = listFoodShop;
}
@NonNull
@Override
public FoodShopViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_food_shop, parent, false);
return new FoodShopViewHolder(view);
}
@Override
public void onBindViewHolder(@NonNull FoodShopViewHolder holder, int position) {
Food food = listFoodShop.get(position);
if(food == null)
return;
Picasso.get().load(food.getImg()).into(holder.imageView);
holder.foodName.setText(food.getName());
holder.quantitySoldOut.setText("1.2k đã bán");
holder.price.setText(food.getPrice());
}
@Override
public int getItemCount() {
if(listFoodShop != null)
return listFoodShop.size();
return 0;
}
public class FoodShopViewHolder extends RecyclerView.ViewHolder {
ImageView imageView;
TextView foodName, quantitySoldOut, price;
public FoodShopViewHolder(@NonNull View itemView) {
super(itemView);
imageView = itemView.findViewById(R.id.image_view);
foodName = itemView.findViewById(R.id.food_name_text_view);
quantitySoldOut = itemView.findViewById(R.id.quantity_sold_out);
price = itemView.findViewById(R.id.price_text_view);
}
}
}
@@ -1,15 +1,16 @@
package com.capstone.foodify.Model.Shop;
import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.capstone.foodify.Activity.ShopDetailActivity;
import com.capstone.foodify.R;
import java.util.List;
@@ -32,7 +33,7 @@ public class ShopAdapter extends RecyclerView.Adapter<ShopAdapter.ShopViewHolder
@NonNull
@Override
public ShopViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_restaurant, parent, false);
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_shop, parent, false);
return new ShopViewHolder(view);
}
@@ -44,6 +45,12 @@ public class ShopAdapter extends RecyclerView.Adapter<ShopAdapter.ShopViewHolder
return;
holder.imgView.setImageResource(shop.getResourceId());
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
context.startActivity(new Intent(context, ShopDetailActivity.class));
}
});
}
@Override
@@ -0,0 +1,142 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Activity.ShopDetailActivity"
>
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/app_bar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/Theme.Foodify"
>
<com.google.android.material.appbar.CollapsingToolbarLayout
android:id="@+id/collapsing"
android:layout_width="wrap_content"
android:layout_height="250dp"
android:fitsSystemWindows="true"
app:layout_scrollFlags="scroll|exitUntilCollapsed|snap"
app:contentScrim="@color/primaryDarkColor"
app:title="Shop Name"
android:theme="@style/CustomToolbarTheme"
>
<ImageView
android:id="@+id/image_shop"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
/>
<ImageView
android:id="@+id/back_image"
android:layout_width="28dp"
android:layout_height="wrap_content"
android:src="@drawable/back_button"
android:layout_marginStart="10dp"
android:layout_marginTop="25dp"
android:background="@drawable/circle_button"
android:translationZ="90dp"
android:padding="8dp"/>
<androidx.appcompat.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"/>
</com.google.android.material.appbar.CollapsingToolbarLayout>
</com.google.android.material.appbar.AppBarLayout>
<androidx.core.widget.NestedScrollView
android:id="@+id/food_detail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior"
>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<TextView
android:id="@+id/student_shop_text_view"
android:text="Student Shop"
android:fontFamily="@font/bebas"
android:textColor="@color/red"
android:layout_marginTop="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
/>
<TextView
android:id="@+id/description_text_view"
android:text="Description"
android:textSize="18sp"
android:fontFamily="@font/bebas"
android:textColor="@color/black"
android:layout_marginTop="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
/>
<TextView
android:id="@+id/content_description_text_view"
android:text="@string/text_description"
android:textColor="@color/gray"
android:fontFamily="@font/opensans"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
app:layout_constraintTop_toBottomOf="@id/description_text_view"
app:layout_constraintStart_toStartOf="parent"
/>
<View
android:id="@+id/line"
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="#c0c0c0"
android:layout_marginTop="5dp"
app:layout_constraintTop_toBottomOf="@id/content_description_text_view"
/>
<TextView
android:id="@+id/textView"
android:text="Danh sách các món ăn"
android:fontFamily="@font/bebas"
android:textColor="@color/black"
android:textSize="20sp"
android:layout_marginTop="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@id/content_description_text_view"
app:layout_constraintStart_toStartOf="parent"
/>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_view_food_shop"
tools:listitem="@layout/item_food_shop"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@id/textView"
app:layout_constraintStart_toStartOf="parent"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.core.widget.NestedScrollView>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
+2 -2
View File
@@ -77,7 +77,7 @@
android:layout_height="wrap_content"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
android:orientation="horizontal"
tools:listitem="@layout/list_foods"
tools:listitem="@layout/item_food"
app:layout_constraintTop_toBottomOf="@id/recycler_view_restaurant"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
@@ -104,7 +104,7 @@
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
android:orientation="horizontal"
android:contentDescription="@string/description"
tools:listitem="@layout/list_restaurant"
tools:listitem="@layout/item_shop"
app:layout_constraintTop_toBottomOf="@id/restaurant_text"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
+1 -1
View File
@@ -46,7 +46,7 @@
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_view_search"
tools:listitem="@layout/list_foods"
tools:listitem="@layout/item_food"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
+134
View File
@@ -0,0 +1,134 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/red"
android:layout_margin="10dp"
>
<TextView
android:textColor="@color/white"
android:fontFamily="@font/opensans"
android:text="@string/delete"
android:textSize="20sp"
android:textStyle="bold"
android:layout_toStartOf="@id/img_delete"
android:layout_centerVertical="true"
android:layout_marginEnd="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<ImageView
android:id="@+id/img_delete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/baseline_delete_24"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:layout_marginEnd="10dp"
tools:ignore="ContentDescription" />
</RelativeLayout>
<!--Layout foreground-->
<LinearLayout
android:id="@+id/layout_foreground"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:background="@color/white"
android:layout_margin="5dp"
>
<ImageView
android:id="@+id/image_view"
android:layout_width="110dp"
android:layout_height="110dp"
android:src="@drawable/food"
android:scaleType="centerCrop"
app:riv_corner_radius="10dip"
tools:ignore="ContentDescription" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<TextView
android:id="@+id/food_name_text_view"
android:text="@string/food_name"
android:textSize="18sp"
android:textColor="@color/black"
android:fontFamily="@font/opensans"
android:layout_width="match_parent"
android:layout_height="47dp"
android:layout_marginStart="5dp"
android:layout_marginTop="5dp"
android:layout_marginEnd="10dp"
app:layout_constraintStart_toEndOf="@id/image_view"
app:layout_constraintTop_toTopOf="parent"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="0.6"
android:layout_marginStart="5dp"
>
<TextView
android:id="@+id/quantity_sold_out"
android:text="1.2k đã bán"
android:textSize="16sp"
android:textColor="@color/gray"
android:fontFamily="@font/opensans"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
app:layout_constraintStart_toEndOf="@id/image_view"
app:layout_constraintTop_toBottomOf="@id/text_view_1"
/>
<TextView
android:id="@+id/price_text_view"
android:text="$5.00"
android:textSize="25sp"
android:textColor="@color/primaryColor"
android:fontFamily="@font/bebas"
android:layout_width="220dp"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
/>
</LinearLayout>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/basket_icon"
android:layout_gravity="center_vertical"
/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</FrameLayout>
+1 -1
View File
@@ -25,7 +25,7 @@
android:layout_marginTop="10dp"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
android:orientation="horizontal"
tools:listitem="@layout/list_foods"
tools:listitem="@layout/item_food"
app:layout_constraintTop_toBottomOf="@id/menuTitle"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
+1
View File
@@ -4,6 +4,7 @@
<color name="white">#FFFFFFFF</color>
<color name="primaryColor">#ff8084</color>
<color name="primaryDarkColor">#CF2E33</color>
<color name="gray">#A3A3A3</color>
<color name="secondary">#F99928</color>
<color name="grayLight">#ACA5A5</color>
+7 -2
View File
@@ -5,8 +5,6 @@
<item name="colorPrimary">@color/primaryColor</item>
<item name="colorPrimaryVariant">@color/primaryColor</item>
<item name="colorOnPrimary">@color/white</item>
<!-- Secondary brand color. -->
<item name="colorOnSecondary">@color/black</item>
<!-- Status bar color. -->
<item name="android:statusBarColor">?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. -->
@@ -15,6 +13,13 @@
<item name="android:textColorHint">@color/grayLight</item>
</style>
<style name="CustomToolbarTheme" parent="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<!-- HERE ARE THE CHANGES - Change color of different texts -->
<item name="android:textColorPrimary">@color/white</item>
<item name="colorControlNormal">@color/white</item>
</style>
<style name="DefaultSolid" parent="Widget.MaterialComponents.Button">
<item name="shapeAppearanceOverlay">@style/ShapeAppearance.FoodifyApp.Button.Rounded</item>
</style>