mirror of
https://github.com/Nezumi-2711/PRM392.git
synced 2026-09-22 13:48:29 +00:00
Fix show discount price + Add message from server to User
This commit is contained in:
Binary file not shown.
@@ -357,7 +357,7 @@ public class Cart extends AppCompatActivity implements GoogleApiClient.Connectio
|
|||||||
//Calculate total price
|
//Calculate total price
|
||||||
float total = 0;
|
float total = 0;
|
||||||
for (Order order : cart)
|
for (Order order : cart)
|
||||||
total += (Float.parseFloat(order.getPrice())) * (Float.parseFloat(order.getQuantity()));
|
total += (Float.parseFloat(order.getPrice())) * (Float.parseFloat(order.getQuantity())) * (100 - Long.parseLong(order.getDiscount()))/100;;
|
||||||
Locale locale = new Locale("vi", "VN");
|
Locale locale = new Locale("vi", "VN");
|
||||||
NumberFormat fmt = NumberFormat.getCurrencyInstance(locale);
|
NumberFormat fmt = NumberFormat.getCurrencyInstance(locale);
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,8 @@ import com.waterbase.foodify.Remote.RetrofitClient;
|
|||||||
public class Common {
|
public class Common {
|
||||||
public static User currentUser;
|
public static User currentUser;
|
||||||
|
|
||||||
|
public static String topicName = "News";
|
||||||
|
|
||||||
private static final String BASE_URL = "https://fcm.googleapis.com/";
|
private static final String BASE_URL = "https://fcm.googleapis.com/";
|
||||||
private static final String GOOGLE_API_URL = "https://maps.googleapis.com/";
|
private static final String GOOGLE_API_URL = "https://maps.googleapis.com/";
|
||||||
|
|
||||||
|
|||||||
@@ -66,21 +66,21 @@ public class Database extends SQLiteAssetHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Favorites
|
//Favorites
|
||||||
public void addToFavorites(String foodId) {
|
public void addToFavorites(String foodId, String userPhone) {
|
||||||
SQLiteDatabase db = getReadableDatabase();
|
SQLiteDatabase db = getReadableDatabase();
|
||||||
String query = String.format("INSERT INTO Favorites(FoodId) VALUES('%s');", foodId);
|
String query = String.format("INSERT INTO Favorites(FoodId,UserPhone) VALUES('%s', '%s');", foodId, userPhone);
|
||||||
db.execSQL(query);
|
db.execSQL(query);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeFromFavorites(String foodId) {
|
public void removeFromFavorites(String foodId, String userPhone) {
|
||||||
SQLiteDatabase db = getReadableDatabase();
|
SQLiteDatabase db = getReadableDatabase();
|
||||||
String query = String.format("DELETE FROM Favorites WHERE FoodId='%s';", foodId);
|
String query = String.format("DELETE FROM Favorites WHERE FoodId='%s' and UserPhone='%s';", foodId, userPhone);
|
||||||
db.execSQL(query);
|
db.execSQL(query);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isFavorite(String foodId) {
|
public boolean isFavorite(String foodId, String userPhone) {
|
||||||
SQLiteDatabase db = getReadableDatabase();
|
SQLiteDatabase db = getReadableDatabase();
|
||||||
String query = String.format("SELECT * FROM Favorites WHERE FoodId='%s'", foodId);
|
String query = String.format("SELECT * FROM Favorites WHERE FoodId='%s' and UserPhone='%s'", foodId, userPhone);
|
||||||
Cursor cursor = db.rawQuery(query, null);
|
Cursor cursor = db.rawQuery(query, null);
|
||||||
if (cursor.getCount() <= 0) {
|
if (cursor.getCount() <= 0) {
|
||||||
cursor.close();
|
cursor.close();
|
||||||
|
|||||||
@@ -11,7 +11,10 @@ import android.content.Context;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.text.Editable;
|
import android.text.Editable;
|
||||||
|
import android.text.SpannableStringBuilder;
|
||||||
|
import android.text.Spanned;
|
||||||
import android.text.TextWatcher;
|
import android.text.TextWatcher;
|
||||||
|
import android.text.style.StrikethroughSpan;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@@ -273,7 +276,25 @@ public class FoodList extends AppCompatActivity {
|
|||||||
@Override
|
@Override
|
||||||
protected void onBindViewHolder(@NonNull FoodViewHolder viewHolder, int position, @NonNull Food model) {
|
protected void onBindViewHolder(@NonNull FoodViewHolder viewHolder, int position, @NonNull Food model) {
|
||||||
viewHolder.food_name.setText(model.getName());
|
viewHolder.food_name.setText(model.getName());
|
||||||
viewHolder.food_price.setText(String.format("%s đ", model.getPrice()));
|
|
||||||
|
if(Integer.parseInt(model.getDiscount()) > 0)
|
||||||
|
{
|
||||||
|
String foodPrice = model.getPrice() + "đ";
|
||||||
|
long newFoodPrice = Long.parseLong(model.getPrice()) - Long.parseLong(model.getPrice())* Long.parseLong(model.getDiscount())/100;
|
||||||
|
SpannableStringBuilder spnBuilder = new SpannableStringBuilder(foodPrice);
|
||||||
|
StrikethroughSpan strikethroughSpan = new StrikethroughSpan();
|
||||||
|
spnBuilder.setSpan(strikethroughSpan, 0, foodPrice.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||||
|
viewHolder.food_price.setText(spnBuilder);
|
||||||
|
viewHolder.newPrice.setText(newFoodPrice+"đ");
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
viewHolder.food_price.setText(String.format("%s đ", model.getPrice()));
|
||||||
|
viewHolder.discount.setVisibility(View.GONE);
|
||||||
|
viewHolder.newPrice.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
viewHolder.discount.setText("- " + model.getDiscount() + "%");
|
||||||
Picasso.with(getBaseContext()).load(model.getImage()).into(viewHolder.food_image);
|
Picasso.with(getBaseContext()).load(model.getImage()).into(viewHolder.food_image);
|
||||||
|
|
||||||
//Quick Cart
|
//Quick Cart
|
||||||
@@ -293,20 +314,21 @@ public class FoodList extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
//Add Favorites
|
//Add Favorites
|
||||||
if(localDB.isFavorite(adapter.getRef(position).getKey()))
|
if(localDB.isFavorite(adapter.getRef(position).getKey(),Common.currentUser.getPhone()))
|
||||||
viewHolder.fav_image.setImageResource(R.drawable.ic_baseline_favorite_24);
|
viewHolder.fav_image.setImageResource(R.drawable.ic_baseline_favorite_24);
|
||||||
|
|
||||||
//Click to change state of Favorites
|
//Click to change state of Favorites
|
||||||
viewHolder.fav_image.setOnClickListener(new View.OnClickListener() {
|
viewHolder.fav_image.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
if(!localDB.isFavorite(adapter.getRef(viewHolder.getAdapterPosition()).getKey())){
|
if(!localDB.isFavorite(adapter.getRef(viewHolder.getAdapterPosition()).getKey(), Common.currentUser.getPhone())){
|
||||||
localDB.addToFavorites(adapter.getRef(viewHolder.getAdapterPosition()).getKey());
|
localDB.addToFavorites(adapter.getRef(viewHolder.getAdapterPosition()).getKey(), Common.currentUser.getPhone());
|
||||||
viewHolder.fav_image.setImageResource(R.drawable.ic_baseline_favorite_24);
|
viewHolder.fav_image.setImageResource(R.drawable.ic_baseline_favorite_24);
|
||||||
Toast.makeText(FoodList.this, model.getName() + " đã thêm vào danh sách yêu thích", Toast.LENGTH_SHORT).show();
|
Toast.makeText(FoodList.this, model.getName() + " đã thêm vào danh sách yêu thích", Toast.LENGTH_SHORT).show();
|
||||||
} else {
|
} else {
|
||||||
localDB.removeFromFavorites(adapter.getRef(viewHolder.getAdapterPosition()).getKey());
|
localDB.removeFromFavorites(adapter.getRef(viewHolder.getAdapterPosition()).getKey(), Common.currentUser.getPhone());
|
||||||
viewHolder.fav_image.setImageResource(R.drawable.ic_baseline_favorite_border_24);
|
viewHolder.fav_image.setImageResource(R.drawable.ic_baseline_favorite_border_24);
|
||||||
Toast.makeText(FoodList.this, model.getName() + " đã xoá khỏi danh sách yêu thích", Toast.LENGTH_SHORT).show();
|
Toast.makeText(FoodList.this, model.getName() + " đã xoá khỏi danh sách yêu thích", Toast.LENGTH_SHORT).show();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import android.content.Context;
|
|||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.text.TextUtils;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
@@ -11,6 +12,7 @@ import android.view.View;
|
|||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.view.animation.AnimationUtils;
|
import android.view.animation.AnimationUtils;
|
||||||
import android.view.animation.LayoutAnimationController;
|
import android.view.animation.LayoutAnimationController;
|
||||||
|
import android.widget.CheckBox;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
@@ -43,6 +45,7 @@ import com.google.firebase.database.DatabaseReference;
|
|||||||
import com.google.firebase.database.FirebaseDatabase;
|
import com.google.firebase.database.FirebaseDatabase;
|
||||||
import com.google.firebase.database.ValueEventListener;
|
import com.google.firebase.database.ValueEventListener;
|
||||||
import com.google.firebase.iid.FirebaseInstanceId;
|
import com.google.firebase.iid.FirebaseInstanceId;
|
||||||
|
import com.google.firebase.messaging.FirebaseMessaging;
|
||||||
import com.rengwuxian.materialedittext.MaterialEditText;
|
import com.rengwuxian.materialedittext.MaterialEditText;
|
||||||
import com.squareup.picasso.Picasso;
|
import com.squareup.picasso.Picasso;
|
||||||
import com.waterbase.foodify.Common.Common;
|
import com.waterbase.foodify.Common.Common;
|
||||||
@@ -321,6 +324,8 @@ public class Home extends AppCompatActivity implements NavigationView.OnNavigati
|
|||||||
showChangePasswordDialog();
|
showChangePasswordDialog();
|
||||||
} else if (id == R.id.nav_home_address) {
|
} else if (id == R.id.nav_home_address) {
|
||||||
showHomeAddressDialog();
|
showHomeAddressDialog();
|
||||||
|
} else if (id == R.id.nav_setting) {
|
||||||
|
showSettingDialog();
|
||||||
}
|
}
|
||||||
else if (id == R.id.nav_log_out) {
|
else if (id == R.id.nav_log_out) {
|
||||||
|
|
||||||
@@ -340,6 +345,47 @@ public class Home extends AppCompatActivity implements NavigationView.OnNavigati
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void showSettingDialog() {
|
||||||
|
AlertDialog.Builder alertDialog = new AlertDialog.Builder(Home.this);
|
||||||
|
alertDialog.setTitle("Cài đặt");
|
||||||
|
|
||||||
|
LayoutInflater inflater = LayoutInflater.from(this);
|
||||||
|
View layout_setting = inflater.inflate(R.layout.setting_layout, null);
|
||||||
|
|
||||||
|
CheckBox ckb_subscribe_new = layout_setting.findViewById(R.id.ckb_sub_new);
|
||||||
|
//Add code remember state of Checkbox
|
||||||
|
Paper.init(this);
|
||||||
|
String isSubscribe = Paper.book().read("sub_new");
|
||||||
|
if(isSubscribe == null || TextUtils.isEmpty(isSubscribe) || isSubscribe.equals("false"))
|
||||||
|
ckb_subscribe_new.setChecked(false);
|
||||||
|
else
|
||||||
|
ckb_subscribe_new.setChecked(true);
|
||||||
|
|
||||||
|
alertDialog.setView(layout_setting);
|
||||||
|
|
||||||
|
alertDialog.setPositiveButton("Xong", new DialogInterface.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
dialog.dismiss();
|
||||||
|
|
||||||
|
if(ckb_subscribe_new.isChecked())
|
||||||
|
{
|
||||||
|
FirebaseMessaging.getInstance().subscribeToTopic(Common.topicName);
|
||||||
|
//Write value
|
||||||
|
Paper.book().write("sub_new", "true");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
FirebaseMessaging.getInstance().unsubscribeFromTopic(Common.topicName);
|
||||||
|
//Write value
|
||||||
|
Paper.book().write("sub_new", "false");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
alertDialog.show();
|
||||||
|
}
|
||||||
|
|
||||||
private void showHomeAddressDialog() {
|
private void showHomeAddressDialog() {
|
||||||
AlertDialog.Builder alertDialog = new AlertDialog.Builder(Home.this);
|
AlertDialog.Builder alertDialog = new AlertDialog.Builder(Home.this);
|
||||||
alertDialog.setTitle("Đặt địa chỉ mặc định");
|
alertDialog.setTitle("Đặt địa chỉ mặc định");
|
||||||
|
|||||||
@@ -17,9 +17,11 @@ public class MyFirebaseIdService extends FirebaseInstanceIdService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void updateTokenToFirebase(String tokenRefreshed) {
|
private void updateTokenToFirebase(String tokenRefreshed) {
|
||||||
FirebaseDatabase db = FirebaseDatabase.getInstance();
|
if (Common.currentUser != null) {
|
||||||
DatabaseReference tokens = db.getReference("Tokens");
|
FirebaseDatabase db = FirebaseDatabase.getInstance();
|
||||||
Token token = new Token(tokenRefreshed, false);
|
DatabaseReference tokens = db.getReference("Tokens");
|
||||||
tokens.child(Common.currentUser.getPhone()).setValue(token);
|
Token token = new Token(tokenRefreshed, false);
|
||||||
|
tokens.child(Common.currentUser.getPhone()).setValue(token);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ import java.util.Locale;
|
|||||||
|
|
||||||
class CartViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnCreateContextMenuListener {
|
class CartViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnCreateContextMenuListener {
|
||||||
|
|
||||||
public TextView txt_card_item, txt_price;
|
public TextView txt_card_item, txt_price, txtDiscount;
|
||||||
public ElegantNumberButton btn_quantity;
|
public ElegantNumberButton btn_quantity;
|
||||||
public ImageView cart_image;
|
public ImageView cart_image;
|
||||||
|
|
||||||
@@ -45,6 +45,7 @@ class CartViewHolder extends RecyclerView.ViewHolder implements View.OnClickList
|
|||||||
super(itemView);
|
super(itemView);
|
||||||
txt_card_item = (TextView) itemView.findViewById(R.id.cart_item_name);
|
txt_card_item = (TextView) itemView.findViewById(R.id.cart_item_name);
|
||||||
txt_price = (TextView) itemView.findViewById(R.id.cart_item_Price);
|
txt_price = (TextView) itemView.findViewById(R.id.cart_item_Price);
|
||||||
|
txtDiscount = (TextView) itemView.findViewById(R.id.txtDiscount);
|
||||||
btn_quantity = (ElegantNumberButton) itemView.findViewById(R.id.btn_quantity);
|
btn_quantity = (ElegantNumberButton) itemView.findViewById(R.id.btn_quantity);
|
||||||
cart_image = (ImageView) itemView.findViewById(R.id.cart_image);
|
cart_image = (ImageView) itemView.findViewById(R.id.cart_image);
|
||||||
|
|
||||||
@@ -102,10 +103,10 @@ public class CartAdapter extends RecyclerView.Adapter<CartViewHolder>{
|
|||||||
float total = 0;
|
float total = 0;
|
||||||
List<Order> orders = new Database(cart).getCarts();
|
List<Order> orders = new Database(cart).getCarts();
|
||||||
for (Order item : orders)
|
for (Order item : orders)
|
||||||
total += (Float.parseFloat(order.getPrice())) * (Float.parseFloat(item.getQuantity()));
|
total += (Float.parseFloat(item.getPrice())) * (Float.parseFloat(item.getQuantity())) * (100 - Long.parseLong(item.getDiscount()))/100;
|
||||||
Locale locale = new Locale("vi", "VN");
|
Locale locale = new Locale("vi", "VN");
|
||||||
NumberFormat fmt = NumberFormat.getCurrencyInstance(locale);
|
NumberFormat fmt = NumberFormat.getCurrencyInstance(locale);
|
||||||
float price = newValue*(Float.parseFloat(order.getPrice()));
|
float price = newValue*(Float.parseFloat(order.getPrice())) * (100 - Long.parseLong(order.getDiscount()))/100;
|
||||||
holder.txt_price.setText(fmt.format(price));
|
holder.txt_price.setText(fmt.format(price));
|
||||||
|
|
||||||
cart.txtTotalPrice.setText(fmt.format(total));
|
cart.txtTotalPrice.setText(fmt.format(total));
|
||||||
@@ -114,8 +115,13 @@ public class CartAdapter extends RecyclerView.Adapter<CartViewHolder>{
|
|||||||
|
|
||||||
Locale locale = new Locale("vi", "VN");
|
Locale locale = new Locale("vi", "VN");
|
||||||
NumberFormat fmt = NumberFormat.getCurrencyInstance(locale);
|
NumberFormat fmt = NumberFormat.getCurrencyInstance(locale);
|
||||||
float price = (Float.parseFloat(listData.get(position).getPrice()))*(Float.parseFloat(listData.get(position).getQuantity()));
|
float price = (Float.parseFloat(listData.get(position).getPrice()))*(Float.parseFloat(listData.get(position).getQuantity())) * (100 - Long.parseLong(listData.get(position).getDiscount()))/100;
|
||||||
holder.txt_price.setText(fmt.format(price));
|
holder.txt_price.setText(fmt.format(price));
|
||||||
|
if(Integer.parseInt(listData.get(position).getDiscount()) > 0)
|
||||||
|
{
|
||||||
|
holder.txtDiscount.setVisibility(View.VISIBLE);
|
||||||
|
holder.txtDiscount.setText("-" + listData.get(position).getDiscount() + "%");
|
||||||
|
}
|
||||||
|
|
||||||
holder.txt_card_item.setText(listData.get(position).getProductName());
|
holder.txt_card_item.setText(listData.get(position).getProductName());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import com.waterbase.foodify.R;
|
|||||||
|
|
||||||
public class FoodViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
|
public class FoodViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
|
||||||
|
|
||||||
public TextView food_name, food_price;
|
public TextView food_name, food_price, discount, newPrice;
|
||||||
public ImageView food_image, fav_image, quick_cart;
|
public ImageView food_image, fav_image, quick_cart;
|
||||||
|
|
||||||
private ItemClickListener itemClickListener;
|
private ItemClickListener itemClickListener;
|
||||||
@@ -28,6 +28,8 @@ public class FoodViewHolder extends RecyclerView.ViewHolder implements View.OnCl
|
|||||||
food_image = (ImageView) itemView.findViewById(R.id.food_image);
|
food_image = (ImageView) itemView.findViewById(R.id.food_image);
|
||||||
fav_image = (ImageView) itemView.findViewById(R.id.fav);
|
fav_image = (ImageView) itemView.findViewById(R.id.fav);
|
||||||
food_price = (TextView) itemView.findViewById(R.id.food_price);
|
food_price = (TextView) itemView.findViewById(R.id.food_price);
|
||||||
|
discount = (TextView) itemView.findViewById(R.id.discount);
|
||||||
|
newPrice = (TextView) itemView.findViewById(R.id.new_Price);
|
||||||
quick_cart = (ImageView) itemView.findViewById(R.id.btn_quick_cart);
|
quick_cart = (ImageView) itemView.findViewById(R.id.btn_quick_cart);
|
||||||
|
|
||||||
itemView.setOnClickListener(this);
|
itemView.setOnClickListener(this);
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
<vector android:height="24dp" android:tint="#000000"
|
||||||
|
android:viewportHeight="24" android:viewportWidth="24"
|
||||||
|
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<path android:fillColor="@android:color/white" android:pathData="M19.14,12.94c0.04,-0.3 0.06,-0.61 0.06,-0.94c0,-0.32 -0.02,-0.64 -0.07,-0.94l2.03,-1.58c0.18,-0.14 0.23,-0.41 0.12,-0.61l-1.92,-3.32c-0.12,-0.22 -0.37,-0.29 -0.59,-0.22l-2.39,0.96c-0.5,-0.38 -1.03,-0.7 -1.62,-0.94L14.4,2.81c-0.04,-0.24 -0.24,-0.41 -0.48,-0.41h-3.84c-0.24,0 -0.43,0.17 -0.47,0.41L9.25,5.35C8.66,5.59 8.12,5.92 7.63,6.29L5.24,5.33c-0.22,-0.08 -0.47,0 -0.59,0.22L2.74,8.87C2.62,9.08 2.66,9.34 2.86,9.48l2.03,1.58C4.84,11.36 4.8,11.69 4.8,12s0.02,0.64 0.07,0.94l-2.03,1.58c-0.18,0.14 -0.23,0.41 -0.12,0.61l1.92,3.32c0.12,0.22 0.37,0.29 0.59,0.22l2.39,-0.96c0.5,0.38 1.03,0.7 1.62,0.94l0.36,2.54c0.05,0.24 0.24,0.41 0.48,0.41h3.84c0.24,0 0.44,-0.17 0.47,-0.41l0.36,-2.54c0.59,-0.24 1.13,-0.56 1.62,-0.94l2.39,0.96c0.22,0.08 0.47,0 0.59,-0.22l1.92,-3.32c0.12,-0.22 0.07,-0.47 -0.12,-0.61L19.14,12.94zM12,15.6c-1.98,0 -3.6,-1.62 -3.6,-3.6s1.62,-3.6 3.6,-3.6s3.6,1.62 3.6,3.6S13.98,15.6 12,15.6z"/>
|
||||||
|
</vector>
|
||||||
@@ -38,16 +38,28 @@
|
|||||||
android:text="Food 01"
|
android:text="Food 01"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content" />
|
android:layout_height="wrap_content" />
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/cart_item_Price"
|
||||||
|
android:layout_marginLeft="10dp"
|
||||||
|
android:gravity="center_vertical|start"
|
||||||
|
android:textAllCaps="true"
|
||||||
|
android:textStyle="italic"
|
||||||
|
android:text="100,000"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/txtDiscount"
|
||||||
|
android:layout_marginLeft="10dp"
|
||||||
|
android:textAllCaps="true"
|
||||||
|
android:textStyle="italic"
|
||||||
|
android:textSize="10sp"
|
||||||
|
android:visibility="gone"
|
||||||
|
android:textColor="@color/red"
|
||||||
|
android:text="-50%"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content" />
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/cart_item_Price"
|
|
||||||
android:layout_marginLeft="10dp"
|
|
||||||
android:gravity="center_vertical|start"
|
|
||||||
android:textAllCaps="true"
|
|
||||||
android:textStyle="italic"
|
|
||||||
android:text="100,000"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content" />
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<com.cepheuen.elegantnumberbutton.view.ElegantNumberButton
|
<com.cepheuen.elegantnumberbutton.view.ElegantNumberButton
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/food_image"
|
android:id="@+id/food_image"
|
||||||
|
android:src="@drawable/bg4"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="0dp"
|
android:layout_height="0dp"
|
||||||
android:layout_weight="4"
|
android:layout_weight="4"
|
||||||
@@ -63,6 +64,27 @@
|
|||||||
android:text="$100"
|
android:text="$100"
|
||||||
android:textSize="20sp" />
|
android:textSize="20sp" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/discount"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="14dp"
|
||||||
|
android:layout_marginLeft="30dp"
|
||||||
|
android:layout_toEndOf="@+id/food_price"
|
||||||
|
android:text="$100"
|
||||||
|
android:textColor="@color/red"
|
||||||
|
android:textSize="10sp" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/new_Price"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginLeft="5dp"
|
||||||
|
android:layout_toEndOf="@+id/discount"
|
||||||
|
android:textStyle="bold"
|
||||||
|
android:text="$100"
|
||||||
|
android:textSize="25sp" />
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/btn_quick_cart"
|
android:id="@+id/btn_quick_cart"
|
||||||
android:src="@drawable/ic_baseline_shopping_cart_24"
|
android:src="@drawable/ic_baseline_shopping_cart_24"
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
|
|
||||||
<com.rengwuxian.materialedittext.MaterialEditText
|
<com.rengwuxian.materialedittext.MaterialEditText
|
||||||
android:id="@+id/edtHomeAddress"
|
android:id="@+id/edtHomeAddress"
|
||||||
android:hint="Home Address"
|
android:hint="Địa chỉ mặc định"
|
||||||
android:inputType="textMultiLine"
|
android:inputType="textMultiLine"
|
||||||
android:textColor="@color/purple_500"
|
android:textColor="@color/purple_500"
|
||||||
android:textColorHint="@color/purple_500"
|
android:textColorHint="@color/purple_500"
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<androidx.cardview.widget.CardView
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_margin="8dp"
|
||||||
|
app:cardElevation="4dp"
|
||||||
|
>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_marginTop="16dp"
|
||||||
|
android:layout_marginBottom="16dp"
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:layout_gravity="center_vertical"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
|
<CheckBox
|
||||||
|
android:id="@+id/ckb_sub_new"
|
||||||
|
android:text="Nhận thông báo từ hệ thống"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</androidx.cardview.widget.CardView>
|
||||||
@@ -25,6 +25,12 @@
|
|||||||
android:title="Đổi mật khẩu"
|
android:title="Đổi mật khẩu"
|
||||||
android:iconTint="@color/white"
|
android:iconTint="@color/white"
|
||||||
/>
|
/>
|
||||||
|
<item
|
||||||
|
android:id="@+id/nav_setting"
|
||||||
|
android:icon="@drawable/ic_baseline_settings_24"
|
||||||
|
android:title="Cài đặt"
|
||||||
|
android:iconTint="@color/white"
|
||||||
|
/>
|
||||||
<item
|
<item
|
||||||
android:id="@+id/nav_log_out"
|
android:id="@+id/nav_log_out"
|
||||||
android:icon="@drawable/ic_baseline_exit_to_app_24"
|
android:icon="@drawable/ic_baseline_exit_to_app_24"
|
||||||
|
|||||||
@@ -17,4 +17,5 @@
|
|||||||
|
|
||||||
<color name="overlayBackground">#7f333639</color>
|
<color name="overlayBackground">#7f333639</color>
|
||||||
<color name="overlayActionBar">#0e0d0e</color>
|
<color name="overlayActionBar">#0e0d0e</color>
|
||||||
|
<color name="red">#FA0202</color>
|
||||||
</resources>
|
</resources>
|
||||||
@@ -16,6 +16,9 @@
|
|||||||
android:supportsRtl="true"
|
android:supportsRtl="true"
|
||||||
android:theme="@style/Theme.FoodifyServer"
|
android:theme="@style/Theme.FoodifyServer"
|
||||||
tools:targetApi="31">
|
tools:targetApi="31">
|
||||||
|
<activity
|
||||||
|
android:name=".SendMessage"
|
||||||
|
android:exported="false" />
|
||||||
<activity
|
<activity
|
||||||
android:name=".BannerActivity"
|
android:name=".BannerActivity"
|
||||||
android:exported="false" />
|
android:exported="false" />
|
||||||
|
|||||||
@@ -16,6 +16,8 @@ public class Common {
|
|||||||
public static User currentUser;
|
public static User currentUser;
|
||||||
public static Request currentRequest;
|
public static Request currentRequest;
|
||||||
|
|
||||||
|
public static String topicName = "News";
|
||||||
|
|
||||||
public static final String UPDATE = "Cập nhật";
|
public static final String UPDATE = "Cập nhật";
|
||||||
public static final String DELETE = "Xoá";
|
public static final String DELETE = "Xoá";
|
||||||
public static final int PICK_IMAGE_REQUEST = 71;
|
public static final int PICK_IMAGE_REQUEST = 71;
|
||||||
|
|||||||
@@ -301,6 +301,9 @@ public class Home extends AppCompatActivity implements NavigationView.OnNavigati
|
|||||||
} else if(id == R.id.nav_banner) {
|
} else if(id == R.id.nav_banner) {
|
||||||
Intent banner = new Intent(Home.this, BannerActivity.class);
|
Intent banner = new Intent(Home.this, BannerActivity.class);
|
||||||
startActivity(banner);
|
startActivity(banner);
|
||||||
|
} else if(id == R.id.nav_message) {
|
||||||
|
Intent banner = new Intent(Home.this, SendMessage.class);
|
||||||
|
startActivity(banner);
|
||||||
}
|
}
|
||||||
|
|
||||||
DrawerLayout drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
|
DrawerLayout drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
|
||||||
|
|||||||
@@ -4,8 +4,27 @@ public class Sender {
|
|||||||
public String to;
|
public String to;
|
||||||
public Notification notification;
|
public Notification notification;
|
||||||
|
|
||||||
|
public Sender() {
|
||||||
|
}
|
||||||
|
|
||||||
public Sender(String to, Notification notification) {
|
public Sender(String to, Notification notification) {
|
||||||
this.to = to;
|
this.to = to;
|
||||||
this.notification = notification;
|
this.notification = notification;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getTo() {
|
||||||
|
return to;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTo(String to) {
|
||||||
|
this.to = to;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Notification getNotification() {
|
||||||
|
return notification;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNotification(Notification notification) {
|
||||||
|
this.notification = notification;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,65 @@
|
|||||||
|
package com.waterbase.foodifyServer;
|
||||||
|
|
||||||
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import com.rengwuxian.materialedittext.MaterialEditText;
|
||||||
|
import com.waterbase.foodifyServer.Common.Common;
|
||||||
|
import com.waterbase.foodifyServer.Model.MyResponse;
|
||||||
|
import com.waterbase.foodifyServer.Model.Notification;
|
||||||
|
import com.waterbase.foodifyServer.Model.Sender;
|
||||||
|
import com.waterbase.foodifyServer.Remote.APIService;
|
||||||
|
|
||||||
|
import info.hoang8f.widget.FButton;
|
||||||
|
import retrofit2.Call;
|
||||||
|
import retrofit2.Callback;
|
||||||
|
import retrofit2.Response;
|
||||||
|
|
||||||
|
public class SendMessage extends AppCompatActivity {
|
||||||
|
|
||||||
|
MaterialEditText edtMessage, edtTitle;
|
||||||
|
FButton btnSend;
|
||||||
|
|
||||||
|
APIService mService;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
setContentView(R.layout.activity_send_message);
|
||||||
|
|
||||||
|
mService = Common.getFCMClient();
|
||||||
|
|
||||||
|
edtMessage = findViewById(R.id.edtMessage);
|
||||||
|
edtTitle = findViewById(R.id.edtTitle);
|
||||||
|
|
||||||
|
btnSend = findViewById(R.id.btnSend);
|
||||||
|
btnSend.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
//Create message
|
||||||
|
Notification notification = new Notification(edtTitle.getText().toString(), edtMessage.getText().toString());
|
||||||
|
|
||||||
|
Sender toTopic = new Sender();
|
||||||
|
toTopic.to = new StringBuilder("/topics/").append(Common.topicName).toString();
|
||||||
|
toTopic.notification = notification;
|
||||||
|
|
||||||
|
mService.sendNotification(toTopic)
|
||||||
|
.enqueue(new Callback<MyResponse>() {
|
||||||
|
@Override
|
||||||
|
public void onResponse(Call<MyResponse> call, Response<MyResponse> response) {
|
||||||
|
if(response.isSuccessful())
|
||||||
|
Toast.makeText(SendMessage.this, "Thông báo đã gửi đến người dùng!", Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFailure(Call<MyResponse> call, Throwable t) {
|
||||||
|
Toast.makeText(SendMessage.this, "" + t.getMessage(), Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
+6
-4
@@ -17,9 +17,11 @@ public class MyFirebaseIdService extends FirebaseInstanceIdService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void updateToServer(String refreshedToken) {
|
private void updateToServer(String refreshedToken) {
|
||||||
FirebaseDatabase db = FirebaseDatabase.getInstance();
|
if (Common.currentUser != null) {
|
||||||
DatabaseReference tokens = db.getReference("Tokens");
|
FirebaseDatabase db = FirebaseDatabase.getInstance();
|
||||||
Token data = new Token(refreshedToken, true);
|
DatabaseReference tokens = db.getReference("Tokens");
|
||||||
tokens.child(Common.currentUser.getPhone()).setValue(data);
|
Token data = new Token(refreshedToken, true);
|
||||||
|
tokens.child(Common.currentUser.getPhone()).setValue(data);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
<vector android:height="24dp" android:tint="#000000"
|
||||||
|
android:viewportHeight="24" android:viewportWidth="24"
|
||||||
|
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<path android:fillColor="@android:color/white" android:pathData="M20,2L4,2c-1.1,0 -1.99,0.9 -1.99,2L2,22l4,-4h14c1.1,0 2,-0.9 2,-2L22,4c0,-1.1 -0.9,-2 -2,-2zM18,14L6,14v-2h12v2zM18,11L6,11L6,9h12v2zM18,8L6,8L6,6h12v2z"/>
|
||||||
|
</vector>
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<RelativeLayout 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"
|
||||||
|
android:background="@drawable/background"
|
||||||
|
tools:context=".SendMessage">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:layout_marginLeft="8dp"
|
||||||
|
android:layout_marginRight="8dp"
|
||||||
|
android:layout_centerInParent="true"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
|
<com.rengwuxian.materialedittext.MaterialEditText
|
||||||
|
android:id="@+id/edtTitle"
|
||||||
|
android:hint="Tiêu đề"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:textColorHint="@color/white"
|
||||||
|
android:textSize="34sp"
|
||||||
|
android:inputType="text"
|
||||||
|
app:met_baseColor="@color/white"
|
||||||
|
app:met_floatingLabel="highlight"
|
||||||
|
app:met_primaryColor="@color/white"
|
||||||
|
app:met_singleLineEllipsis="true"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<com.rengwuxian.materialedittext.MaterialEditText
|
||||||
|
android:id="@+id/edtMessage"
|
||||||
|
android:hint="Nội dung"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:textColorHint="@color/white"
|
||||||
|
android:textColor="@color/white"
|
||||||
|
android:textSize="34sp"
|
||||||
|
android:inputType="textMultiLine"
|
||||||
|
app:met_baseColor="@color/white"
|
||||||
|
app:met_floatingLabel="highlight"
|
||||||
|
app:met_primaryColor="@color/white"
|
||||||
|
app:met_singleLineEllipsis="true"
|
||||||
|
/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<info.hoang8f.widget.FButton
|
||||||
|
android:id="@+id/btnSend"
|
||||||
|
android:text="Gửi thông báo"
|
||||||
|
android:textColor="@color/white"
|
||||||
|
android:layout_marginRight="8dp"
|
||||||
|
android:layout_marginLeft="8dp"
|
||||||
|
android:layout_alignParentBottom="true"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_margin="8dp"
|
||||||
|
app:fButtonColor="@color/btnSignActive"
|
||||||
|
app:shadowColor="@color/black"
|
||||||
|
app:shadowEnabled="true"
|
||||||
|
app:shadowHeight="5dp"
|
||||||
|
app:cornerRadius="4dp"
|
||||||
|
/>
|
||||||
|
|
||||||
|
</RelativeLayout>
|
||||||
@@ -8,6 +8,10 @@
|
|||||||
android:id="@+id/nav_banner"
|
android:id="@+id/nav_banner"
|
||||||
android:icon="@drawable/ic_baseline_laptop_24"
|
android:icon="@drawable/ic_baseline_laptop_24"
|
||||||
android:title="Banner" />
|
android:title="Banner" />
|
||||||
|
<item
|
||||||
|
android:id="@+id/nav_message"
|
||||||
|
android:icon="@drawable/ic_baseline_message_24"
|
||||||
|
android:title="Thông báo" />
|
||||||
<item
|
<item
|
||||||
android:id="@+id/nav_cart"
|
android:id="@+id/nav_cart"
|
||||||
android:icon="@drawable/ic_baseline_shopping_cart_24"
|
android:icon="@drawable/ic_baseline_shopping_cart_24"
|
||||||
|
|||||||
Reference in New Issue
Block a user