mirror of
https://github.com/Nezumi-2711/PRM392.git
synced 2026-09-22 13:48:29 +00:00
Add animation menu, show amount of order
This commit is contained in:
@@ -69,6 +69,9 @@ dependencies {
|
||||
|
||||
implementation 'io.github.inflationx:calligraphy3:3.1.1'
|
||||
implementation 'io.github.inflationx:viewpump:2.0.3'
|
||||
|
||||
//CounterFAB
|
||||
implementation 'com.github.andremion:counterfab:1.2.2'
|
||||
}
|
||||
|
||||
apply plugin: 'com.google.gms.google-services'
|
||||
@@ -84,4 +84,18 @@ public class Database extends SQLiteAssetHelper {
|
||||
cursor.close();
|
||||
return true;
|
||||
}
|
||||
|
||||
public int getCountCart() {
|
||||
int count = 0;
|
||||
SQLiteDatabase db = getReadableDatabase();
|
||||
String query = String.format("SELECT COUNT(*) FROM OrderDetail");
|
||||
Cursor cursor = db.rawQuery(query, null);
|
||||
if(cursor.moveToFirst()){
|
||||
do {
|
||||
count = cursor.getInt(0);
|
||||
}while (cursor.moveToNext());
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.ActionBar;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import com.andremion.counterfab.CounterFab;
|
||||
import com.cepheuen.elegantnumberbutton.view.ElegantNumberButton;
|
||||
import com.google.android.material.appbar.CollapsingToolbarLayout;
|
||||
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
||||
@@ -44,7 +45,8 @@ public class FoodDetail extends AppCompatActivity implements RatingDialogListene
|
||||
TextView food_name, food_price, food_description;
|
||||
ImageView food_image;
|
||||
CollapsingToolbarLayout collapsingToolbarLayout;
|
||||
FloatingActionButton btnCart, btnRating;
|
||||
FloatingActionButton btnRating;
|
||||
CounterFab btnCart;
|
||||
ElegantNumberButton numberButton;
|
||||
RatingBar ratingBar;
|
||||
|
||||
@@ -83,7 +85,7 @@ public class FoodDetail extends AppCompatActivity implements RatingDialogListene
|
||||
|
||||
//Init view
|
||||
numberButton = (ElegantNumberButton) findViewById(R.id.number_button);
|
||||
btnCart = (FloatingActionButton) findViewById(R.id.btnCart);
|
||||
btnCart = findViewById(R.id.btnCart);
|
||||
btnRating = (FloatingActionButton) findViewById(R.id.btnRating);
|
||||
ratingBar = (RatingBar) findViewById(R.id.ratingBar);
|
||||
|
||||
@@ -105,10 +107,12 @@ public class FoodDetail extends AppCompatActivity implements RatingDialogListene
|
||||
currentFood.getDiscount()
|
||||
));
|
||||
|
||||
Toast.makeText(FoodDetail.this, "Added to Cart", Toast.LENGTH_SHORT).show();
|
||||
Toast.makeText(FoodDetail.this, "Đã thêm vào giỏ hàng!", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
|
||||
btnCart.setCount(new Database(this).getCountCart());
|
||||
|
||||
food_description = (TextView) findViewById(R.id.food_description);
|
||||
food_name = (TextView) findViewById(R.id.food_name);
|
||||
food_price = (TextView) findViewById(R.id.food_price);
|
||||
|
||||
@@ -28,6 +28,7 @@ import com.waterbase.foodify.Common.Common;
|
||||
import com.waterbase.foodify.Database.Database;
|
||||
import com.waterbase.foodify.Interface.ItemClickListener;
|
||||
import com.waterbase.foodify.Model.Food;
|
||||
import com.waterbase.foodify.Model.Order;
|
||||
import com.waterbase.foodify.ViewHolder.FoodViewHolder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -248,6 +249,22 @@ public class FoodList extends AppCompatActivity {
|
||||
viewHolder.food_price.setText(String.format("%s đ", model.getPrice()));
|
||||
Picasso.with(getBaseContext()).load(model.getImage()).into(viewHolder.food_image);
|
||||
|
||||
//Quick Cart
|
||||
viewHolder.quick_cart.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
new Database(getBaseContext()).addToCart(new Order(
|
||||
adapter.getRef(position).getKey(),
|
||||
model.getName(),
|
||||
"1",
|
||||
model.getPrice(),
|
||||
model.getDiscount()
|
||||
));
|
||||
|
||||
Toast.makeText(FoodList.this, "Đã thêm vào giỏ hàng!", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
|
||||
//Add Favorites
|
||||
if(localDB.isFavorite(adapter.getRef(position).getKey()))
|
||||
viewHolder.fav_image.setImageResource(R.drawable.ic_baseline_favorite_24);
|
||||
|
||||
@@ -8,6 +8,8 @@ import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.animation.AnimationUtils;
|
||||
import android.view.animation.LayoutAnimationController;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
@@ -22,10 +24,12 @@ import androidx.recyclerview.widget.GridLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
||||
|
||||
import com.andremion.counterfab.CounterFab;
|
||||
import com.firebase.ui.database.FirebaseRecyclerAdapter;
|
||||
import com.google.android.gms.tasks.OnCompleteListener;
|
||||
import com.google.android.gms.tasks.OnFailureListener;
|
||||
import com.google.android.gms.tasks.Task;
|
||||
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
||||
import com.google.android.material.navigation.NavigationView;
|
||||
import com.google.firebase.database.DatabaseReference;
|
||||
import com.google.firebase.database.FirebaseDatabase;
|
||||
@@ -33,6 +37,7 @@ import com.google.firebase.iid.FirebaseInstanceId;
|
||||
import com.rengwuxian.materialedittext.MaterialEditText;
|
||||
import com.squareup.picasso.Picasso;
|
||||
import com.waterbase.foodify.Common.Common;
|
||||
import com.waterbase.foodify.Database.Database;
|
||||
import com.waterbase.foodify.Interface.ItemClickListener;
|
||||
import com.waterbase.foodify.Model.Category;
|
||||
import com.waterbase.foodify.Model.Token;
|
||||
@@ -60,6 +65,8 @@ public class Home extends AppCompatActivity implements NavigationView.OnNavigati
|
||||
|
||||
SwipeRefreshLayout swipeRefreshLayout;
|
||||
|
||||
CounterFab fab;
|
||||
|
||||
@Override
|
||||
protected void attachBaseContext(Context newBase) {
|
||||
super.attachBaseContext(ViewPumpContextWrapper.wrap(newBase));
|
||||
@@ -85,6 +92,17 @@ public class Home extends AppCompatActivity implements NavigationView.OnNavigati
|
||||
toolbar.setTitle("Menu");
|
||||
setSupportActionBar(toolbar);
|
||||
|
||||
//Floating Action Button
|
||||
fab = findViewById(R.id.fab);
|
||||
fab.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
startActivity(new Intent(Home.this, Cart.class));
|
||||
}
|
||||
});
|
||||
|
||||
fab.setCount(new Database(this).getCountCart());
|
||||
|
||||
//View
|
||||
swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_layout);
|
||||
swipeRefreshLayout.setColorSchemeResources(R.color.colorPrimary,
|
||||
@@ -128,33 +146,6 @@ public class Home extends AppCompatActivity implements NavigationView.OnNavigati
|
||||
database = FirebaseDatabase.getInstance();
|
||||
category = database.getReference("Category");
|
||||
|
||||
//Init paper
|
||||
Paper.init(this);
|
||||
|
||||
//Load menu
|
||||
recyler_menu = (RecyclerView) findViewById(R.id.recyler_menu);
|
||||
recyler_menu.setHasFixedSize(true);
|
||||
// layoutManager = new LinearLayoutManager(this);
|
||||
// recyler_menu.setLayoutManager(layoutManager);
|
||||
recyler_menu.setLayoutManager(new GridLayoutManager(this, 2));
|
||||
|
||||
//Set name for user
|
||||
View headerView = navigationView.getHeaderView(0);
|
||||
TextView navUserName = (TextView) headerView.findViewById(R.id.txtFullName);
|
||||
navUserName.setText(Common.currentUser.getName());
|
||||
|
||||
updateToken(FirebaseInstanceId.getInstance().getToken());
|
||||
|
||||
}
|
||||
|
||||
private void updateToken(String token) {
|
||||
FirebaseDatabase db = FirebaseDatabase.getInstance();
|
||||
DatabaseReference tokens = db.getReference("Tokens");
|
||||
Token data = new Token(token, false);
|
||||
tokens.child(Common.currentUser.getPhone()).setValue(data);
|
||||
}
|
||||
|
||||
private void loadMenu() {
|
||||
adapter = new FirebaseRecyclerAdapter<Category, MenuViewHolder>(Category.class, R.layout.menu_item, MenuViewHolder.class, category) {
|
||||
@Override
|
||||
protected void populateViewHolder(MenuViewHolder viewHolder, Category model, int position) {
|
||||
@@ -174,8 +165,47 @@ public class Home extends AppCompatActivity implements NavigationView.OnNavigati
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
//Init paper
|
||||
Paper.init(this);
|
||||
|
||||
//Load menu
|
||||
recyler_menu = (RecyclerView) findViewById(R.id.recyler_menu);
|
||||
recyler_menu.setLayoutManager(new GridLayoutManager(this, 2));
|
||||
LayoutAnimationController controller = AnimationUtils.loadLayoutAnimation(recyler_menu.getContext(),
|
||||
R.anim.layout_fall_down);
|
||||
recyler_menu.setLayoutAnimation(controller);
|
||||
|
||||
//Set name for user
|
||||
View headerView = navigationView.getHeaderView(0);
|
||||
TextView navUserName = (TextView) headerView.findViewById(R.id.txtFullName);
|
||||
navUserName.setText(Common.currentUser.getName());
|
||||
|
||||
updateToken(FirebaseInstanceId.getInstance().getToken());
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
fab.setCount(new Database(this).getCountCart());
|
||||
}
|
||||
|
||||
private void updateToken(String token) {
|
||||
FirebaseDatabase db = FirebaseDatabase.getInstance();
|
||||
DatabaseReference tokens = db.getReference("Tokens");
|
||||
Token data = new Token(token, false);
|
||||
tokens.child(Common.currentUser.getPhone()).setValue(data);
|
||||
}
|
||||
|
||||
private void loadMenu() {
|
||||
|
||||
recyler_menu.setAdapter(adapter);
|
||||
swipeRefreshLayout.setRefreshing(false);
|
||||
|
||||
//Animation
|
||||
recyler_menu.getAdapter().notifyDataSetChanged();
|
||||
recyler_menu.scheduleLayoutAnimation();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -285,4 +315,5 @@ public class Home extends AppCompatActivity implements NavigationView.OnNavigati
|
||||
AlertDialog dialog = alertDialog.create();
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -13,7 +13,7 @@ import com.waterbase.foodify.R;
|
||||
public class FoodViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
|
||||
|
||||
public TextView food_name, food_price;
|
||||
public ImageView food_image, fav_image;
|
||||
public ImageView food_image, fav_image, quick_cart;
|
||||
|
||||
private ItemClickListener itemClickListener;
|
||||
|
||||
@@ -28,6 +28,7 @@ public class FoodViewHolder extends RecyclerView.ViewHolder implements View.OnCl
|
||||
food_image = (ImageView) itemView.findViewById(R.id.food_image);
|
||||
fav_image = (ImageView) itemView.findViewById(R.id.fav);
|
||||
food_price = (TextView) itemView.findViewById(R.id.food_price);
|
||||
quick_cart = (ImageView) itemView.findViewById(R.id.btn_quick_cart);
|
||||
|
||||
itemView.setOnClickListener(this);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<set xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:duration="@integer/animation_duration_medium">
|
||||
|
||||
<translate
|
||||
android:fromYDelta="-20%"
|
||||
android:toYDelta="0"
|
||||
android:interpolator="@android:anim/decelerate_interpolator"
|
||||
/>
|
||||
|
||||
<alpha
|
||||
android:fromAlpha="0"
|
||||
android:toAlpha="1"
|
||||
android:interpolator="@android:anim/decelerate_interpolator"
|
||||
/>
|
||||
|
||||
<scale
|
||||
android:fromYScale="105%"
|
||||
android:fromXScale="105%"
|
||||
android:toXScale="100%"
|
||||
android:toYScale="100%"
|
||||
android:pivotX="50%"
|
||||
android:pivotY="50%"
|
||||
android:interpolator="@android:anim/decelerate_interpolator"
|
||||
/>
|
||||
</set>
|
||||
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layoutAnimation xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:animation="@anim/item_animation_fall_down"
|
||||
android:delay="15%"
|
||||
android:animationOrder="normal"
|
||||
>
|
||||
|
||||
</layoutAnimation>
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 433 KiB |
@@ -36,12 +36,13 @@
|
||||
|
||||
</com.google.android.material.appbar.AppBarLayout>
|
||||
|
||||
<com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||
<com.andremion.counterfab.CounterFab
|
||||
android:id="@+id/btnCart"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:backgroundTint="@color/white"
|
||||
android:elevation="6dp"
|
||||
android:backgroundTint="#33cf08"
|
||||
app:badgeBackgroundColor="#7df25c"
|
||||
android:src="@drawable/ic_baseline_shopping_cart_24"
|
||||
app:layout_anchor="@id/app_bar_layout"
|
||||
app:layout_anchorGravity="bottom|right|end"
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:fitsSystemWindows="true"
|
||||
android:background="@drawable/background2"
|
||||
tools:openDrawer="start">
|
||||
|
||||
<include
|
||||
|
||||
@@ -22,4 +22,15 @@
|
||||
|
||||
<include layout="@layout/content_home" />
|
||||
|
||||
<com.andremion.counterfab.CounterFab
|
||||
android:id="@+id/fab"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="bottom|end"
|
||||
android:layout_margin="16dp"
|
||||
android:backgroundTint="#33cf08"
|
||||
app:badgeBackgroundColor="#7df25c"
|
||||
app:srcCompat="@drawable/ic_baseline_shopping_cart_24"
|
||||
/>
|
||||
|
||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
||||
@@ -52,12 +52,28 @@
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/food_price"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="$100"
|
||||
android:textSize="20sp" />
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/food_price"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="$100"
|
||||
android:textSize="20sp" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/btn_quick_cart"
|
||||
android:src="@drawable/ic_baseline_shopping_cart_24"
|
||||
app:tint="@color/colorAccent"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_marginRight="7dp"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
/>
|
||||
</RelativeLayout>
|
||||
</LinearLayout>
|
||||
|
||||
</androidx.cardview.widget.CardView>
|
||||
@@ -4,7 +4,7 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:cardElevation="10dp"
|
||||
android:layout_margin="10dp"
|
||||
android:layout_margin="8dp"
|
||||
app:cardCornerRadius="0dp"
|
||||
>
|
||||
|
||||
|
||||
@@ -5,4 +5,6 @@
|
||||
<dimen name="nav_header_vertical_spacing">8dp</dimen>
|
||||
<dimen name="nav_header_height">176dp</dimen>
|
||||
<dimen name="fab_margin">16dp</dimen>
|
||||
|
||||
<integer name="animation_duration_medium">300</integer>
|
||||
</resources>
|
||||
@@ -4,14 +4,14 @@ buildscript {
|
||||
jcenter()
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:7.0.1'
|
||||
classpath 'com.android.tools.build:gradle:7.2.1'
|
||||
classpath 'com.google.gms:google-services:4.3.10'
|
||||
}
|
||||
}
|
||||
|
||||
plugins {
|
||||
id 'com.android.application' version '7.2.0' apply false
|
||||
id 'com.android.library' version '7.2.0' apply false
|
||||
id 'com.android.application' version '7.2.1' apply false
|
||||
id 'com.android.library' version '7.2.1' apply false
|
||||
}
|
||||
|
||||
allprojects {
|
||||
|
||||
Reference in New Issue
Block a user