mirror of
https://github.com/Nezumi-2711/PRM392.git
synced 2026-09-23 04:09:54 +00:00
Upload Foodify-Client
This commit is contained in:
@@ -0,0 +1,154 @@
|
||||
package com.waterbase.foodify;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.ActionBar;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.EditText;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.google.firebase.database.DatabaseReference;
|
||||
import com.google.firebase.database.FirebaseDatabase;
|
||||
import com.waterbase.foodify.Common.Common;
|
||||
import com.waterbase.foodify.Database.Database;
|
||||
import com.waterbase.foodify.Model.Order;
|
||||
import com.waterbase.foodify.Model.Request;
|
||||
import com.waterbase.foodify.ViewHolder.CartAdapter;
|
||||
|
||||
import java.text.NumberFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import info.hoang8f.widget.FButton;
|
||||
|
||||
public class Cart extends AppCompatActivity {
|
||||
|
||||
RecyclerView recyclerView;
|
||||
RecyclerView.LayoutManager layoutManager;
|
||||
|
||||
FirebaseDatabase database;
|
||||
DatabaseReference requests;
|
||||
|
||||
TextView txtTotalPrice;
|
||||
FButton btnPlace;
|
||||
|
||||
List<Order> cart = new ArrayList<>();
|
||||
CartAdapter adapter;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_cart);
|
||||
|
||||
//Firebase
|
||||
database = FirebaseDatabase.getInstance();
|
||||
requests = database.getReference("Requests");
|
||||
|
||||
//Init
|
||||
recyclerView = (RecyclerView) findViewById(R.id.listCart);
|
||||
recyclerView.setHasFixedSize(true);
|
||||
layoutManager = new LinearLayoutManager(this);
|
||||
recyclerView.setLayoutManager(layoutManager);
|
||||
|
||||
txtTotalPrice = (TextView) findViewById(R.id.total);
|
||||
btnPlace = (FButton) findViewById(R.id.btnPlaceOrder);
|
||||
|
||||
btnPlace.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
showAlertDialog();
|
||||
}
|
||||
});
|
||||
|
||||
loadListFood();
|
||||
|
||||
setTitle("Giỏ hàng");
|
||||
// calling the action bar
|
||||
ActionBar actionBar = getSupportActionBar();
|
||||
|
||||
// showing the back button in action bar
|
||||
actionBar.setDisplayHomeAsUpEnabled(true);
|
||||
}
|
||||
|
||||
private void showAlertDialog() {
|
||||
AlertDialog.Builder alertDialog = new AlertDialog.Builder(Cart.this);
|
||||
alertDialog.setTitle("One more step!");
|
||||
alertDialog.setMessage("Enter your address: ");
|
||||
|
||||
final EditText edtAddress = new EditText(Cart.this);
|
||||
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
|
||||
LinearLayout.LayoutParams.MATCH_PARENT,
|
||||
LinearLayout.LayoutParams.MATCH_PARENT
|
||||
);
|
||||
edtAddress.setLayoutParams(lp);
|
||||
alertDialog.setView(edtAddress); //Add edit text to Dialog
|
||||
alertDialog.setIcon(R.drawable.ic_baseline_shopping_cart_24);
|
||||
|
||||
alertDialog.setPositiveButton("YES", new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
//Create new Request
|
||||
Request request = new Request(
|
||||
Common.currentUser.getPhone(),
|
||||
Common.currentUser.getName(),
|
||||
edtAddress.getText().toString(),
|
||||
txtTotalPrice.getText().toString(),
|
||||
cart
|
||||
);
|
||||
|
||||
//Summit to Firebase
|
||||
//We will using System.CurrentMilli to key
|
||||
requests.child(String.valueOf(System.currentTimeMillis())).setValue(request);
|
||||
|
||||
//Delete Cart
|
||||
new Database(getBaseContext()).cleanCart();
|
||||
Toast.makeText(Cart.this, "Đặt hàng thành công!", Toast.LENGTH_SHORT).show();
|
||||
finish();
|
||||
}
|
||||
});
|
||||
|
||||
alertDialog.setNegativeButton("NO", new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
|
||||
alertDialog.show();
|
||||
}
|
||||
|
||||
private void loadListFood() {
|
||||
cart = new Database(this).getCarts();
|
||||
adapter = new CartAdapter(cart, this);
|
||||
recyclerView.setAdapter(adapter);
|
||||
|
||||
//Calculate total price
|
||||
float total = 0;
|
||||
for(Order order:cart)
|
||||
total += (Float.parseFloat(order.getPrice()))*(Float.parseFloat(order.getQuantity()));
|
||||
Locale locale = new Locale("vi", "VN");
|
||||
NumberFormat fmt = NumberFormat.getCurrencyInstance(locale);
|
||||
|
||||
txtTotalPrice.setText(fmt.format(total));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case android.R.id.home:
|
||||
this.finish();
|
||||
return true;
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.waterbase.foodify.Common;
|
||||
|
||||
import com.waterbase.foodify.Model.User;
|
||||
|
||||
public class Common {
|
||||
public static User currentUser;
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package com.waterbase.foodify.Database;
|
||||
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.database.sqlite.SQLiteQueryBuilder;
|
||||
|
||||
import com.readystatesoftware.sqliteasset.SQLiteAssetHelper;
|
||||
import com.waterbase.foodify.Model.Order;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Database extends SQLiteAssetHelper {
|
||||
|
||||
private static final String DB_NAME="EatItDB.db";
|
||||
private static final int DB_VER=1;
|
||||
public Database(Context context) {
|
||||
super(context, DB_NAME, null, DB_VER);
|
||||
}
|
||||
|
||||
public List<Order> getCarts() {
|
||||
SQLiteDatabase db = getReadableDatabase();
|
||||
SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
|
||||
|
||||
String[] sqlSelect = {"ProductName", "ProductId", "Quantity", "Price", "Discount"};
|
||||
String sqlTable="OrderDetail";
|
||||
|
||||
qb.setTables(sqlTable);
|
||||
Cursor c = qb.query(db, sqlSelect, null, null, null, null, null);
|
||||
|
||||
final List<Order> result = new ArrayList<>();
|
||||
if(c.moveToFirst()) {
|
||||
do {
|
||||
result.add(new Order(c.getString(c.getColumnIndexOrThrow("ProductId")),
|
||||
c.getString(c.getColumnIndexOrThrow("ProductName")),
|
||||
c.getString(c.getColumnIndexOrThrow("Quantity")),
|
||||
c.getString(c.getColumnIndexOrThrow("Price")),
|
||||
c.getString(c.getColumnIndexOrThrow("Discount"))
|
||||
));
|
||||
} while(c.moveToNext());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public void addToCart(Order order) {
|
||||
SQLiteDatabase db = getReadableDatabase();
|
||||
String query = String.format("INSERT INTO OrderDetail(ProductId, ProductName, Quantity, Price,Discount) VALUES ('%s', '%s','%s','%s','%s');",
|
||||
order.getProductId(),
|
||||
order.getProductName(),
|
||||
order.getQuantity(),
|
||||
order.getPrice(),
|
||||
order.getDiscount());
|
||||
db.execSQL(query);
|
||||
}
|
||||
|
||||
public void cleanCart() {
|
||||
SQLiteDatabase db = getReadableDatabase();
|
||||
String query = String.format("DELETE FROM OrderDetail");
|
||||
db.execSQL(query);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,131 @@
|
||||
package com.waterbase.foodify;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.ActionBar;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.cepheuen.elegantnumberbutton.view.ElegantNumberButton;
|
||||
import com.google.android.material.appbar.CollapsingToolbarLayout;
|
||||
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
||||
import com.google.firebase.database.DataSnapshot;
|
||||
import com.google.firebase.database.DatabaseError;
|
||||
import com.google.firebase.database.DatabaseReference;
|
||||
import com.google.firebase.database.FirebaseDatabase;
|
||||
import com.google.firebase.database.ValueEventListener;
|
||||
import com.squareup.picasso.Picasso;
|
||||
import com.waterbase.foodify.Database.Database;
|
||||
import com.waterbase.foodify.Model.Food;
|
||||
import com.waterbase.foodify.Model.Order;
|
||||
|
||||
public class FoodDetail extends AppCompatActivity {
|
||||
|
||||
|
||||
TextView food_name, food_price, food_description;
|
||||
ImageView food_image;
|
||||
CollapsingToolbarLayout collapsingToolbarLayout;
|
||||
FloatingActionButton btnCart;
|
||||
ElegantNumberButton numberButton;
|
||||
|
||||
String foodId = "";
|
||||
|
||||
FirebaseDatabase database;
|
||||
DatabaseReference foods;
|
||||
|
||||
Food currentFood;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_food_detail);
|
||||
|
||||
//Firebase
|
||||
database = FirebaseDatabase.getInstance();
|
||||
foods = database.getReference("Foods");
|
||||
|
||||
//Init view
|
||||
numberButton = (ElegantNumberButton) findViewById(R.id.number_button);
|
||||
btnCart = (FloatingActionButton) findViewById(R.id.btnCart);
|
||||
|
||||
btnCart.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
new Database(getBaseContext()).addToCart(new Order(
|
||||
foodId,
|
||||
currentFood.getName(),
|
||||
numberButton.getNumber(),
|
||||
currentFood.getPrice(),
|
||||
currentFood.getDiscount()
|
||||
));
|
||||
|
||||
Toast.makeText(FoodDetail.this, "Added to Cart", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
|
||||
food_description = (TextView) findViewById(R.id.food_description);
|
||||
food_name = (TextView) findViewById(R.id.food_name);
|
||||
food_price = (TextView) findViewById(R.id.food_price);
|
||||
food_image = (ImageView) findViewById(R.id.img_food);
|
||||
|
||||
collapsingToolbarLayout = (CollapsingToolbarLayout) findViewById(R.id.collapsing);
|
||||
collapsingToolbarLayout.setExpandedTitleTextAppearance(R.style.ExpandedAppbar);
|
||||
collapsingToolbarLayout.setCollapsedTitleTextAppearance(R.style.CollapsedAppbar);
|
||||
|
||||
//Get Food Id from Intent
|
||||
if(getIntent() != null)
|
||||
foodId = getIntent().getStringExtra("FoodId");
|
||||
if(!foodId.isEmpty()) {
|
||||
getDetailFood(foodId);
|
||||
}
|
||||
|
||||
setTitle("Chi tiết");
|
||||
|
||||
// calling the action bar
|
||||
ActionBar actionBar = getSupportActionBar();
|
||||
|
||||
// showing the back button in action bar
|
||||
actionBar.setDisplayHomeAsUpEnabled(true);
|
||||
|
||||
}
|
||||
|
||||
private void getDetailFood(String foodId) {
|
||||
foods.child(foodId).addValueEventListener(new ValueEventListener() {
|
||||
@Override
|
||||
public void onDataChange(DataSnapshot dataSnapshot) {
|
||||
currentFood = dataSnapshot.getValue(Food.class);
|
||||
|
||||
//Set Image
|
||||
Picasso.with(getBaseContext()).load(currentFood.getImage()).into(food_image);
|
||||
|
||||
collapsingToolbarLayout.setTitle(currentFood.getName());
|
||||
|
||||
food_price.setText(currentFood.getPrice());
|
||||
|
||||
food_name.setText(currentFood.getName());
|
||||
|
||||
food_description.setText(currentFood.getDescription());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCancelled(DatabaseError databaseError) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case android.R.id.home:
|
||||
this.finish();
|
||||
return true;
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,210 @@
|
||||
package com.waterbase.foodify;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.ActionBar;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.text.Editable;
|
||||
import android.text.TextWatcher;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.firebase.ui.database.FirebaseRecyclerAdapter;
|
||||
import com.google.firebase.database.DataSnapshot;
|
||||
import com.google.firebase.database.DatabaseError;
|
||||
import com.google.firebase.database.DatabaseReference;
|
||||
import com.google.firebase.database.FirebaseDatabase;
|
||||
import com.google.firebase.database.ValueEventListener;
|
||||
import com.mancj.materialsearchbar.MaterialSearchBar;
|
||||
import com.squareup.picasso.Picasso;
|
||||
import com.waterbase.foodify.Interface.ItemClickListener;
|
||||
import com.waterbase.foodify.Model.Food;
|
||||
import com.waterbase.foodify.ViewHolder.FoodViewHolder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class FoodList extends AppCompatActivity {
|
||||
|
||||
RecyclerView recyclerView;
|
||||
RecyclerView.LayoutManager layoutManager;
|
||||
|
||||
FirebaseDatabase database;
|
||||
DatabaseReference foodList;
|
||||
|
||||
String categoryId = "", categoryName = "";
|
||||
|
||||
FirebaseRecyclerAdapter<Food, FoodViewHolder> adapter;
|
||||
|
||||
//Search functionality
|
||||
FirebaseRecyclerAdapter<Food, FoodViewHolder> searchAdapter;
|
||||
List<String> suggestList = new ArrayList<>();
|
||||
MaterialSearchBar materialSearchBar;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_food_list);
|
||||
|
||||
//Firebase
|
||||
database = FirebaseDatabase.getInstance();
|
||||
foodList = database.getReference("Foods");
|
||||
|
||||
recyclerView = (RecyclerView) findViewById(R.id.recyler_food);
|
||||
recyclerView.setHasFixedSize(true);
|
||||
layoutManager = new LinearLayoutManager(this);
|
||||
recyclerView.setLayoutManager(layoutManager);
|
||||
|
||||
//Get Intent here
|
||||
if(getIntent() != null)
|
||||
categoryId = getIntent().getStringExtra("CategoryId");
|
||||
categoryName = getIntent().getStringExtra("CategoryName");
|
||||
if(!categoryId.isEmpty() && categoryId != null) {
|
||||
loadListFood(categoryId);
|
||||
}
|
||||
|
||||
//Search
|
||||
materialSearchBar = (MaterialSearchBar) findViewById(R.id.searchBar);
|
||||
materialSearchBar.setHint("Enter your food");
|
||||
loadSuggest();
|
||||
materialSearchBar.setLastSuggestions(suggestList);
|
||||
materialSearchBar.setCardViewElevation(10);
|
||||
materialSearchBar.addTextChangeListener(new TextWatcher() {
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
//When user type their text, we will change suggest list
|
||||
|
||||
List<String> suggest = new ArrayList<String>();
|
||||
for(String search:suggestList) {
|
||||
if(search.toLowerCase().contains(materialSearchBar.getText().toLowerCase()))
|
||||
suggest.add(search);
|
||||
}
|
||||
materialSearchBar.setLastSuggestions(suggest);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
|
||||
}
|
||||
});
|
||||
materialSearchBar.setOnSearchActionListener(new MaterialSearchBar.OnSearchActionListener() {
|
||||
@Override
|
||||
public void onSearchStateChanged(boolean enabled) {
|
||||
//When search bar is close
|
||||
//Restore original adapter
|
||||
if(!enabled)
|
||||
recyclerView.setAdapter(adapter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSearchConfirmed(CharSequence text) {
|
||||
//When search finish
|
||||
//Show result of search adapter
|
||||
startSearch(text);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onButtonClicked(int buttonCode) {
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
setTitle(categoryName);
|
||||
|
||||
// calling the action bar
|
||||
ActionBar actionBar = getSupportActionBar();
|
||||
|
||||
// showing the back button in action bar
|
||||
actionBar.setDisplayHomeAsUpEnabled(true);
|
||||
}
|
||||
|
||||
private void startSearch(CharSequence text) {
|
||||
searchAdapter = new FirebaseRecyclerAdapter<Food, FoodViewHolder>(
|
||||
Food.class,
|
||||
R.layout.food_item,
|
||||
FoodViewHolder.class,
|
||||
foodList.orderByChild("Name").equalTo(text.toString())
|
||||
) {
|
||||
@Override
|
||||
protected void populateViewHolder(FoodViewHolder viewHolder, Food model, int i) {
|
||||
viewHolder.food_name.setText(model.getName());
|
||||
Picasso.with(getBaseContext()).load(model.getImage()).into(viewHolder.food_image);
|
||||
|
||||
viewHolder.setItemClickListener(new ItemClickListener() {
|
||||
@Override
|
||||
public void onClick(View view, int position, boolean isLongClick) {
|
||||
//Start Activity
|
||||
Intent foodDetail = new Intent(FoodList.this, FoodDetail.class);
|
||||
foodDetail.putExtra("FoodId", searchAdapter.getRef(position).getKey()); // Send Food Id to new activity
|
||||
startActivity(foodDetail);
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
recyclerView.setAdapter(searchAdapter); //Set adapter for Recycler View is Search result
|
||||
}
|
||||
|
||||
private void loadSuggest() {
|
||||
foodList.orderByChild("MenuId").equalTo(categoryId)
|
||||
.addValueEventListener(new ValueEventListener() {
|
||||
@Override
|
||||
public void onDataChange(DataSnapshot dataSnapshot) {
|
||||
for(DataSnapshot postSnapshot: dataSnapshot.getChildren()){
|
||||
Food item = postSnapshot.getValue(Food.class);
|
||||
suggestList.add(item.getName());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCancelled(DatabaseError databaseError) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void loadListFood(String categoryId){
|
||||
adapter = new FirebaseRecyclerAdapter<Food, FoodViewHolder>(Food.class, R.layout.food_item,
|
||||
FoodViewHolder.class, foodList.orderByChild("MenuId").equalTo(categoryId) // like: Select * from Foods where MenuId = 'categoryId'
|
||||
) {
|
||||
@Override
|
||||
protected void populateViewHolder(FoodViewHolder viewHolder, Food model, int position) {
|
||||
viewHolder.food_name.setText(model.getName());
|
||||
Picasso.with(getBaseContext()).load(model.getImage()).into(viewHolder.food_image);
|
||||
|
||||
final Food local = model;
|
||||
viewHolder.setItemClickListener(new ItemClickListener() {
|
||||
@Override
|
||||
public void onClick(View view, int position, boolean isLongClick) {
|
||||
//Start Activity
|
||||
Intent foodDetail = new Intent(FoodList.this, FoodDetail.class);
|
||||
foodDetail.putExtra("FoodId", adapter.getRef(position).getKey()); // Send Food Id to new activity
|
||||
startActivity(foodDetail);
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
//Set Adapter
|
||||
recyclerView.setAdapter(adapter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case android.R.id.home:
|
||||
this.finish();
|
||||
return true;
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,129 @@
|
||||
package com.waterbase.foodify;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.ActionBarDrawerToggle;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
import androidx.core.view.GravityCompat;
|
||||
import androidx.drawerlayout.widget.DrawerLayout;
|
||||
import androidx.navigation.ui.AppBarConfiguration;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.firebase.ui.database.FirebaseRecyclerAdapter;
|
||||
import com.google.android.material.navigation.NavigationView;
|
||||
import com.google.firebase.database.DatabaseReference;
|
||||
import com.google.firebase.database.FirebaseDatabase;
|
||||
import com.squareup.picasso.Picasso;
|
||||
import com.waterbase.foodify.Common.Common;
|
||||
import com.waterbase.foodify.Interface.ItemClickListener;
|
||||
import com.waterbase.foodify.Model.Category;
|
||||
import com.waterbase.foodify.ViewHolder.MenuViewHolder;
|
||||
|
||||
|
||||
public class Home extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener{
|
||||
|
||||
FirebaseDatabase database;
|
||||
DatabaseReference category;
|
||||
|
||||
RecyclerView recyler_menu;
|
||||
RecyclerView.LayoutManager layoutManager;
|
||||
FirebaseRecyclerAdapter<Category, MenuViewHolder> adapter;
|
||||
|
||||
private AppBarConfiguration mAppBarConfiguration;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
setContentView(R.layout.activity_home);
|
||||
|
||||
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
|
||||
toolbar.setTitle("Menu");
|
||||
setSupportActionBar(toolbar);
|
||||
|
||||
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
|
||||
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.app_name, R.string.app_name);
|
||||
drawer.setDrawerListener(toggle);
|
||||
toggle.syncState();
|
||||
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
|
||||
navigationView.setNavigationItemSelectedListener(this);
|
||||
|
||||
|
||||
//Init database
|
||||
database = FirebaseDatabase.getInstance();
|
||||
category = database.getReference("Category");
|
||||
|
||||
//Load menu
|
||||
recyler_menu = (RecyclerView) findViewById(R.id.recyler_menu);
|
||||
recyler_menu.setHasFixedSize(true);
|
||||
layoutManager = new LinearLayoutManager(this);
|
||||
recyler_menu.setLayoutManager(layoutManager);
|
||||
|
||||
loadMenu();
|
||||
|
||||
//Set name for user
|
||||
View headerView = navigationView.getHeaderView(0);
|
||||
TextView navUserName = (TextView) headerView.findViewById(R.id.txtFullName);
|
||||
navUserName.setText(Common.currentUser.getName());
|
||||
}
|
||||
|
||||
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) {
|
||||
viewHolder.txtMenuName.setText(model.getName());
|
||||
Picasso.with(getBaseContext()).load(model.getImage())
|
||||
.into(viewHolder.imageView);
|
||||
viewHolder.setItemClickListener(new ItemClickListener() {
|
||||
@Override
|
||||
public void onClick(View view, int position, boolean isLongClick) {
|
||||
//Get Category Id and send to new Activity
|
||||
Intent foodList = new Intent(getBaseContext(), FoodList.class);
|
||||
foodList.putExtra("CategoryId", adapter.getRef(position).getKey());
|
||||
foodList.putExtra("CategoryName", model.getName());
|
||||
startActivity(foodList);
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
recyler_menu.setAdapter(adapter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
// Inflate the menu; this adds items to the action bar if it is present.
|
||||
getMenuInflater().inflate(R.menu.home, menu);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
|
||||
int id = item.getItemId();
|
||||
|
||||
if(id == R.id.nav_cart) {
|
||||
Intent cartIntent = new Intent(Home.this, Cart.class);
|
||||
startActivity(cartIntent);
|
||||
} else if (id == R.id.nav_order) {
|
||||
Intent orderIntent = new Intent(Home.this, OrderStatus.class);
|
||||
startActivity(orderIntent);
|
||||
} else if (id == R.id.nav_log_out) {
|
||||
Intent signIn = new Intent(Home.this, SignIn.class);
|
||||
signIn.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
||||
startActivity(signIn);
|
||||
finish();
|
||||
}
|
||||
|
||||
DrawerLayout drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
|
||||
drawerLayout.closeDrawer(GravityCompat.START);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.waterbase.foodify.Interface;
|
||||
|
||||
import android.view.View;
|
||||
|
||||
public interface ItemClickListener {
|
||||
void onClick(View view, int position, boolean isLongClick);
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.waterbase.foodify.Model;
|
||||
|
||||
public class Category {
|
||||
private String Name;
|
||||
private String Image;
|
||||
|
||||
public Category() {
|
||||
}
|
||||
|
||||
public Category(String name, String image) {
|
||||
Name = name;
|
||||
Image = image;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return Name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
Name = name;
|
||||
}
|
||||
|
||||
public String getImage() {
|
||||
return Image;
|
||||
}
|
||||
|
||||
public void setImage(String image) {
|
||||
Image = image;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package com.waterbase.foodify.Model;
|
||||
|
||||
public class Food {
|
||||
private String Name, Image, Description, Price, Discount, MenuId;
|
||||
|
||||
public Food() {}
|
||||
|
||||
public Food(String name, String image, String description, String price, String discount, String menuId) {
|
||||
Name = name;
|
||||
Image = image;
|
||||
Description = description;
|
||||
Price = price;
|
||||
Discount = discount;
|
||||
MenuId = menuId;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return Name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
Name = name;
|
||||
}
|
||||
|
||||
public String getImage() {
|
||||
return Image;
|
||||
}
|
||||
|
||||
public void setImage(String image) {
|
||||
Image = image;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return Description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
Description = description;
|
||||
}
|
||||
|
||||
public String getPrice() {
|
||||
return Price;
|
||||
}
|
||||
|
||||
public void setPrice(String price) {
|
||||
Price = price;
|
||||
}
|
||||
|
||||
public String getDiscount() {
|
||||
return Discount;
|
||||
}
|
||||
|
||||
public void setDiscount(String discount) {
|
||||
Discount = discount;
|
||||
}
|
||||
|
||||
public String getMenuId() {
|
||||
return MenuId;
|
||||
}
|
||||
|
||||
public void setMenuId(String menuId) {
|
||||
MenuId = menuId;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package com.waterbase.foodify.Model;
|
||||
|
||||
public class Order {
|
||||
|
||||
private String ProductId;
|
||||
private String ProductName;
|
||||
private String Quantity;
|
||||
private String Price;
|
||||
private String Discount;
|
||||
|
||||
public Order() {
|
||||
}
|
||||
|
||||
public Order(String productId, String productName, String quantity, String price, String discount) {
|
||||
ProductId = productId;
|
||||
ProductName = productName;
|
||||
Quantity = quantity;
|
||||
Price = price;
|
||||
Discount = discount;
|
||||
}
|
||||
|
||||
public String getProductId() {
|
||||
return ProductId;
|
||||
}
|
||||
|
||||
public void setProductId(String productId) {
|
||||
ProductId = productId;
|
||||
}
|
||||
|
||||
public String getProductName() {
|
||||
return ProductName;
|
||||
}
|
||||
|
||||
public void setProductName(String productName) {
|
||||
ProductName = productName;
|
||||
}
|
||||
|
||||
public String getQuantity() {
|
||||
return Quantity;
|
||||
}
|
||||
|
||||
public void setQuantity(String quantity) {
|
||||
Quantity = quantity;
|
||||
}
|
||||
|
||||
public String getPrice() {
|
||||
return Price;
|
||||
}
|
||||
|
||||
public void setPrice(String price) {
|
||||
Price = price;
|
||||
}
|
||||
|
||||
public String getDiscount() {
|
||||
return Discount;
|
||||
}
|
||||
|
||||
public void setDiscount(String discount) {
|
||||
Discount = discount;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
package com.waterbase.foodify.Model;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Request {
|
||||
private String phone;
|
||||
private String name;
|
||||
private String address;
|
||||
private String total;
|
||||
private String status;
|
||||
private List<Order> foods; // list of food order
|
||||
|
||||
public Request() {
|
||||
}
|
||||
|
||||
public Request(String phone, String name, String address, String total, List<Order> foods) {
|
||||
this.phone = phone;
|
||||
this.name = name;
|
||||
this.address = address;
|
||||
this.total = total;
|
||||
this.foods = foods;
|
||||
this.status = "0"; // Default is 0, 0: Placed, 1: Shipping, 2: Shipped
|
||||
}
|
||||
|
||||
public String getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(String status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public String getPhone() {
|
||||
return phone;
|
||||
}
|
||||
|
||||
public void setPhone(String phone) {
|
||||
this.phone = phone;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
public void setAddress(String address) {
|
||||
this.address = address;
|
||||
}
|
||||
|
||||
public String getTotal() {
|
||||
return total;
|
||||
}
|
||||
|
||||
public void setTotal(String total) {
|
||||
this.total = total;
|
||||
}
|
||||
|
||||
public List<Order> getFoods() {
|
||||
return foods;
|
||||
}
|
||||
|
||||
public void setFoods(List<Order> foods) {
|
||||
this.foods = foods;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package com.waterbase.foodify.Model;
|
||||
|
||||
public class User {
|
||||
|
||||
private String Name;
|
||||
private String Password;
|
||||
private String Phone;
|
||||
private String IsStaff;
|
||||
|
||||
public User(){}
|
||||
|
||||
public User(String name, String password){
|
||||
Name = name;
|
||||
Password = password;
|
||||
IsStaff = "false";
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return Name;
|
||||
}
|
||||
|
||||
public String getIsStaff() {
|
||||
return IsStaff;
|
||||
}
|
||||
|
||||
public void setIsStaff(String isStaff) {
|
||||
IsStaff = isStaff;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
Name = name;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return Password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
Password = password;
|
||||
}
|
||||
|
||||
public String getPhone() {
|
||||
return Phone;
|
||||
}
|
||||
|
||||
public void setPhone(String phone) {
|
||||
Phone = phone;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
package com.waterbase.foodify;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.ActionBar;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.MenuItem;
|
||||
|
||||
import com.firebase.ui.database.FirebaseRecyclerAdapter;
|
||||
import com.google.firebase.database.DatabaseReference;
|
||||
import com.google.firebase.database.FirebaseDatabase;
|
||||
import com.waterbase.foodify.Common.Common;
|
||||
import com.waterbase.foodify.Model.Request;
|
||||
import com.waterbase.foodify.ViewHolder.OrderViewHolder;
|
||||
|
||||
public class OrderStatus extends AppCompatActivity {
|
||||
|
||||
public RecyclerView recyclerView;
|
||||
public RecyclerView.LayoutManager layoutManager;
|
||||
|
||||
FirebaseRecyclerAdapter<Request, OrderViewHolder> adapter;
|
||||
|
||||
FirebaseDatabase database;
|
||||
DatabaseReference requests;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_order_status);
|
||||
|
||||
//Firebase
|
||||
database = FirebaseDatabase.getInstance();
|
||||
requests = database.getReference("Requests");
|
||||
|
||||
recyclerView = (RecyclerView) findViewById(R.id.listOrders);
|
||||
recyclerView.setHasFixedSize(true);
|
||||
layoutManager = new LinearLayoutManager(this);
|
||||
recyclerView.setLayoutManager(layoutManager);
|
||||
|
||||
loadOrders(Common.currentUser.getPhone());
|
||||
|
||||
setTitle("Tình trạng đơn hàng");
|
||||
// calling the action bar
|
||||
ActionBar actionBar = getSupportActionBar();
|
||||
|
||||
// showing the back button in action bar
|
||||
actionBar.setDisplayHomeAsUpEnabled(true);
|
||||
}
|
||||
|
||||
private void loadOrders(String phone) {
|
||||
adapter = new FirebaseRecyclerAdapter<Request, OrderViewHolder>(
|
||||
Request.class,
|
||||
R.layout.order_layout,
|
||||
OrderViewHolder.class,
|
||||
requests.orderByChild("phone")
|
||||
.equalTo(phone)
|
||||
) {
|
||||
@Override
|
||||
protected void populateViewHolder(OrderViewHolder orderViewHolder, Request model, int i) {
|
||||
orderViewHolder.txtOrderId.setText(adapter.getRef(i).getKey());
|
||||
orderViewHolder.txtOrderStatus.setText(converCodeToStatus(model.getStatus()));
|
||||
orderViewHolder.txtOrderAddress.setText(model.getAddress());
|
||||
orderViewHolder.txtOrderPhone.setText(model.getPhone());
|
||||
}
|
||||
};
|
||||
recyclerView.setAdapter(adapter);
|
||||
}
|
||||
|
||||
private String converCodeToStatus(String status) {
|
||||
if(status.equals("0"))
|
||||
return "Placed";
|
||||
else if(status.equals("1"))
|
||||
return "On my way";
|
||||
else
|
||||
return "Shipped";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case android.R.id.home:
|
||||
this.finish();
|
||||
return true;
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
package com.waterbase.foodify;
|
||||
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Typeface;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import com.google.firebase.database.DataSnapshot;
|
||||
import com.google.firebase.database.DatabaseError;
|
||||
import com.google.firebase.database.DatabaseReference;
|
||||
import com.google.firebase.database.FirebaseDatabase;
|
||||
import com.google.firebase.database.ValueEventListener;
|
||||
import com.waterbase.foodify.Common.Common;
|
||||
import com.waterbase.foodify.Model.User;
|
||||
|
||||
public class SignIn extends AppCompatActivity {
|
||||
|
||||
EditText edtPhone, edtPassword;
|
||||
Button btnSignIn;
|
||||
TextView txtAppName;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_sign_in);
|
||||
|
||||
edtPassword = (EditText) findViewById(R.id.edtPassword);
|
||||
edtPhone = (EditText) findViewById(R.id.edtPhone);
|
||||
btnSignIn = (Button) findViewById(R.id.btnSignIn);
|
||||
|
||||
txtAppName = (TextView) findViewById(R.id.txtAppName);
|
||||
|
||||
Typeface face = Typeface.createFromAsset(getAssets(), "fonts/NABILA.TTF");
|
||||
txtAppName.setTypeface(face);
|
||||
|
||||
//Init Firebase
|
||||
FirebaseDatabase database = FirebaseDatabase.getInstance();
|
||||
final DatabaseReference table_user = database.getReference("User");
|
||||
|
||||
btnSignIn.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
||||
final ProgressDialog mDialog = new ProgressDialog(SignIn.this);
|
||||
mDialog.setMessage("Please waiting...");
|
||||
mDialog.show();
|
||||
|
||||
table_user.addListenerForSingleValueEvent(new ValueEventListener() {
|
||||
|
||||
|
||||
@Override
|
||||
public void onDataChange(DataSnapshot dataSnapshot) {
|
||||
//Check phone and password is null or not
|
||||
if(!edtPhone.getText().toString().isEmpty() && !edtPassword.getText().toString().isEmpty()){
|
||||
//Check if user not in database
|
||||
if(dataSnapshot.child(edtPhone.getText().toString()).exists()){
|
||||
//Get User information
|
||||
mDialog.dismiss();
|
||||
User user = dataSnapshot.child(edtPhone.getText().toString()).getValue(User.class);
|
||||
user.setPhone(edtPhone.getText().toString());
|
||||
if(user.getPassword().equals(edtPassword.getText().toString())){
|
||||
Intent homeIntent = new Intent(SignIn.this, Home.class);
|
||||
Common.currentUser = user;
|
||||
startActivity(homeIntent);
|
||||
finish();
|
||||
} else {
|
||||
Toast.makeText(SignIn.this, "Số điện thoại hoặc mật khẩu không đúng. Xin vui lòng thử lại!", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
} else {
|
||||
mDialog.dismiss();
|
||||
Toast.makeText(SignIn.this, "Số điện thoại chưa được đăng ký. Vui lòng đăng ký để sử dụng!", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
} else{
|
||||
mDialog.dismiss();
|
||||
Toast.makeText(SignIn.this, "Số điện thoại và mật khẩu không được để trống. Vui lòng thử lại!", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCancelled(DatabaseError databaseError) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void register(View view) {
|
||||
startActivity(new Intent(SignIn.this, com.waterbase.foodify.SignUp.class));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
package com.waterbase.foodify;
|
||||
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Typeface;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import com.google.firebase.database.DataSnapshot;
|
||||
import com.google.firebase.database.DatabaseError;
|
||||
import com.google.firebase.database.DatabaseReference;
|
||||
import com.google.firebase.database.FirebaseDatabase;
|
||||
import com.google.firebase.database.ValueEventListener;
|
||||
import com.waterbase.foodify.Model.User;
|
||||
|
||||
public class SignUp extends AppCompatActivity {
|
||||
|
||||
EditText edtPhone, edtName, edtPassword;
|
||||
Button btnSignUp;
|
||||
TextView txtAppName;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_sign_up);
|
||||
|
||||
edtName = (EditText) findViewById(R.id.txtFullName);
|
||||
edtPassword = (EditText) findViewById(R.id.edtPassword);
|
||||
edtPhone = (EditText) findViewById(R.id.edtPhone);
|
||||
|
||||
btnSignUp = (Button) findViewById(R.id.btnSignUp);
|
||||
|
||||
txtAppName = (TextView) findViewById(R.id.txtAppName);
|
||||
|
||||
Typeface face = Typeface.createFromAsset(getAssets(), "fonts/NABILA.TTF");
|
||||
txtAppName.setTypeface(face);
|
||||
|
||||
//Init Firebase
|
||||
FirebaseDatabase database = FirebaseDatabase.getInstance();
|
||||
final DatabaseReference table_user = database.getReference("User");
|
||||
|
||||
btnSignUp.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
final ProgressDialog mDialog = new ProgressDialog(SignUp.this);
|
||||
mDialog.setMessage("Please waiting...");
|
||||
mDialog.show();
|
||||
|
||||
table_user.addListenerForSingleValueEvent(new ValueEventListener() {
|
||||
@Override
|
||||
public void onDataChange(DataSnapshot dataSnapshot) {
|
||||
//Check if already user phone
|
||||
if(dataSnapshot.child(edtPhone.getText().toString()).exists()) {
|
||||
mDialog.dismiss();
|
||||
Toast.makeText(SignUp.this, "Phone Number is already register!", Toast.LENGTH_SHORT).show();
|
||||
finish();
|
||||
}
|
||||
else {
|
||||
mDialog.dismiss();
|
||||
User user = new User(edtName.getText().toString(), edtPassword.getText().toString());
|
||||
table_user.child(edtPhone.getText().toString()).setValue(user);
|
||||
Toast.makeText(SignUp.this, "Sign up successfully!", Toast.LENGTH_SHORT).show();
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCancelled(DatabaseError databaseError) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void login(View view) {
|
||||
startActivity(new Intent(SignUp.this, SignIn.class));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
package com.waterbase.foodify.ViewHolder;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
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.amulyakhare.textdrawable.TextDrawable;
|
||||
import com.waterbase.foodify.Interface.ItemClickListener;
|
||||
import com.waterbase.foodify.Model.Order;
|
||||
import com.waterbase.foodify.R;
|
||||
|
||||
import org.w3c.dom.Text;
|
||||
|
||||
import java.text.NumberFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
class CartViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
|
||||
|
||||
public TextView txt_card_item, txt_price;
|
||||
public ImageView img_cart_count;
|
||||
|
||||
private ItemClickListener itemClickListener;
|
||||
|
||||
public void setTxt_card_item(TextView txt_card_item) {
|
||||
this.txt_card_item = txt_card_item;
|
||||
}
|
||||
|
||||
public CartViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
txt_card_item = (TextView) itemView.findViewById(R.id.cart_item_name);
|
||||
txt_price = (TextView) itemView.findViewById(R.id.cart_item_Price);
|
||||
img_cart_count = (ImageView) itemView.findViewById(R.id.cart_item_count);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public class CartAdapter extends RecyclerView.Adapter<CartViewHolder>{
|
||||
|
||||
private List<Order> listData = new ArrayList<>();
|
||||
private Context context;
|
||||
|
||||
public CartAdapter(List<Order> listData, Context context) {
|
||||
this.listData = listData;
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public CartViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
LayoutInflater inflater = LayoutInflater.from(context);
|
||||
View itemView = inflater.inflate(R.layout.cart_layout, parent, false);
|
||||
return new CartViewHolder(itemView);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull CartViewHolder holder, int position) {
|
||||
TextDrawable drawable = TextDrawable.builder().buildRound("" + listData.get(position).getQuantity(), Color.RED);
|
||||
holder.img_cart_count.setImageDrawable(drawable);
|
||||
|
||||
Locale locale = new Locale("vi", "VN");
|
||||
NumberFormat fmt = NumberFormat.getCurrencyInstance(locale);
|
||||
float price = (Float.parseFloat(listData.get(position).getPrice()))*(Float.parseFloat(listData.get(position).getQuantity()));
|
||||
holder.txt_price.setText(fmt.format(price));
|
||||
|
||||
holder.txt_card_item.setText(listData.get(position).getProductName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return listData.size();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.waterbase.foodify.ViewHolder;
|
||||
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.waterbase.foodify.Interface.ItemClickListener;
|
||||
import com.waterbase.foodify.R;
|
||||
|
||||
public class FoodViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
|
||||
|
||||
public TextView food_name;
|
||||
public ImageView food_image;
|
||||
|
||||
private ItemClickListener itemClickListener;
|
||||
|
||||
public void setItemClickListener(ItemClickListener itemClickListener) {
|
||||
this.itemClickListener = itemClickListener;
|
||||
}
|
||||
|
||||
public FoodViewHolder(@NonNull View itemView) {
|
||||
super(itemView);
|
||||
|
||||
food_name = (TextView) itemView.findViewById(R.id.food_name);
|
||||
food_image = (ImageView) itemView.findViewById(R.id.food_image);
|
||||
|
||||
itemView.setOnClickListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
itemClickListener.onClick(v, getAdapterPosition(), false);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.waterbase.foodify.ViewHolder;
|
||||
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.waterbase.foodify.Interface.ItemClickListener;
|
||||
import com.waterbase.foodify.R;
|
||||
|
||||
public class MenuViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
|
||||
|
||||
public TextView txtMenuName;
|
||||
public ImageView imageView;
|
||||
|
||||
private ItemClickListener itemClickListener;
|
||||
|
||||
public MenuViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
|
||||
txtMenuName = (TextView) itemView.findViewById(R.id.menu_name);
|
||||
imageView = (ImageView) itemView.findViewById(R.id.menu_image);
|
||||
|
||||
itemView.setOnClickListener(this);
|
||||
}
|
||||
|
||||
public void setItemClickListener(ItemClickListener itemClickListener) {
|
||||
this.itemClickListener = itemClickListener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
itemClickListener.onClick(v, getAdapterPosition(), false);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.waterbase.foodify.ViewHolder;
|
||||
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.waterbase.foodify.Interface.ItemClickListener;
|
||||
import com.waterbase.foodify.R;
|
||||
|
||||
public class OrderViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
|
||||
|
||||
public TextView txtOrderId, txtOrderStatus, txtOrderPhone, txtOrderAddress;
|
||||
|
||||
private ItemClickListener itemClickListener;
|
||||
|
||||
public OrderViewHolder(@NonNull View itemView) {
|
||||
super(itemView);
|
||||
|
||||
txtOrderAddress = (TextView) itemView.findViewById(R.id.order_address);
|
||||
txtOrderId = (TextView) itemView.findViewById(R.id.order_id);
|
||||
txtOrderStatus = (TextView) itemView.findViewById(R.id.order_status);
|
||||
txtOrderPhone = (TextView) itemView.findViewById(R.id.order_phone);
|
||||
|
||||
itemView.setOnClickListener(this);
|
||||
}
|
||||
|
||||
public void setItemClickListener(ItemClickListener itemClickListener) {
|
||||
this.itemClickListener = itemClickListener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
itemClickListener.onClick(v, getAdapterPosition(), false);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package com.waterbase.foodify;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.graphics.Typeface;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
public class Welcome extends AppCompatActivity {
|
||||
|
||||
Button btnSignIn, btnSignUp;
|
||||
TextView txtSlogan, txtAppName;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_welcome);
|
||||
|
||||
btnSignIn = (Button) findViewById(R.id.btnSignIn);
|
||||
btnSignUp = (Button) findViewById(R.id.btnSignUp);
|
||||
|
||||
txtSlogan = (TextView) findViewById(R.id.txtSlogan);
|
||||
txtAppName = (TextView)findViewById(R.id.txtAppName);
|
||||
Typeface face = Typeface.createFromAsset(getAssets(), "fonts/NABILA.TTF");
|
||||
txtSlogan.setTypeface(face);
|
||||
txtAppName.setTypeface(face);
|
||||
|
||||
|
||||
btnSignIn.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent signIn = new Intent(Welcome.this, SignIn.class);
|
||||
startActivity(signIn);
|
||||
}
|
||||
});
|
||||
|
||||
btnSignUp.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent signUp = new Intent(Welcome.this, SignUp.class);
|
||||
startActivity(signUp);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user