mirror of
https://github.com/Nezumi-2711/PRM392.git
synced 2026-09-22 13:48:29 +00:00
Update Firebase library
This commit is contained in:
@@ -63,7 +63,7 @@ dependencies {
|
||||
implementation 'com.github.d-max:spots-dialog:0.7@aar'
|
||||
|
||||
implementation 'com.squareup.picasso:picasso:2.5.2'
|
||||
implementation 'com.firebaseui:firebase-ui-database:1.2.0'
|
||||
implementation 'com.firebaseui:firebase-ui-database:3.2.0'
|
||||
implementation 'io.paperdb:paperdb:2.1'
|
||||
implementation 'com.github.rey5137:material:1.2.4'
|
||||
|
||||
|
||||
@@ -19,6 +19,9 @@
|
||||
android:theme="@style/Theme.Foodify"
|
||||
tools:replace="android:theme"
|
||||
tools:targetApi="31">
|
||||
<activity
|
||||
android:name=".ShowComment"
|
||||
android:exported="false" />
|
||||
<activity
|
||||
android:name=".ChangePassword"
|
||||
android:exported="false" />
|
||||
@@ -28,7 +31,6 @@
|
||||
<activity
|
||||
android:name=".VerifyPhone"
|
||||
android:exported="false" />
|
||||
|
||||
<activity
|
||||
android:name=".OrderStatus"
|
||||
android:exported="false" />
|
||||
@@ -57,8 +59,7 @@
|
||||
<activity
|
||||
android:name=".Welcome"
|
||||
android:exported="true"
|
||||
android:theme="@style/Theme.Foodify.NoActionBar"
|
||||
>
|
||||
android:theme="@style/Theme.Foodify.NoActionBar">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
@@ -71,7 +72,6 @@
|
||||
<action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
|
||||
</intent-filter>
|
||||
</service>
|
||||
|
||||
<service
|
||||
android:name=".Service.MyFirebaseMessaging"
|
||||
android:exported="false">
|
||||
@@ -79,7 +79,6 @@
|
||||
<action android:name="com.google.firebase.MESSAGING_EVENT" />
|
||||
</intent-filter>
|
||||
</service>
|
||||
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
@@ -15,6 +15,8 @@ public class Common {
|
||||
private static final String BASE_URL = "https://fcm.googleapis.com/";
|
||||
private static final String GOOGLE_API_URL = "https://maps.googleapis.com/";
|
||||
|
||||
public static final String INTENT_FOOD_ID = "FoodId";
|
||||
|
||||
public static APIService getFCMService(){
|
||||
return RetrofitClient.getClient(BASE_URL).create(APIService.class);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.waterbase.foodify;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
@@ -15,6 +16,8 @@ import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import com.andremion.counterfab.CounterFab;
|
||||
import com.cepheuen.elegantnumberbutton.view.ElegantNumberButton;
|
||||
import com.google.android.gms.tasks.OnCompleteListener;
|
||||
import com.google.android.gms.tasks.Task;
|
||||
import com.google.android.material.appbar.CollapsingToolbarLayout;
|
||||
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
||||
import com.google.firebase.database.DataSnapshot;
|
||||
@@ -34,6 +37,7 @@ import com.waterbase.foodify.Model.Rating;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import info.hoang8f.widget.FButton;
|
||||
import io.github.inflationx.calligraphy3.CalligraphyConfig;
|
||||
import io.github.inflationx.calligraphy3.CalligraphyInterceptor;
|
||||
import io.github.inflationx.viewpump.ViewPump;
|
||||
@@ -56,6 +60,8 @@ public class FoodDetail extends AppCompatActivity implements RatingDialogListene
|
||||
DatabaseReference foods;
|
||||
DatabaseReference ratingTbl;
|
||||
|
||||
FButton btnShowComment;
|
||||
|
||||
Food currentFood;
|
||||
|
||||
@Override
|
||||
@@ -78,6 +84,16 @@ public class FoodDetail extends AppCompatActivity implements RatingDialogListene
|
||||
|
||||
setContentView(R.layout.activity_food_detail);
|
||||
|
||||
btnShowComment = findViewById(R.id.btnShowComment);
|
||||
btnShowComment.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent intent = new Intent(FoodDetail.this, ShowComment.class);
|
||||
intent.putExtra(Common.INTENT_FOOD_ID, foodId);
|
||||
startActivity(intent);
|
||||
}
|
||||
});
|
||||
|
||||
//Firebase
|
||||
database = FirebaseDatabase.getInstance();
|
||||
foods = database.getReference("Foods");
|
||||
@@ -239,26 +255,35 @@ public class FoodDetail extends AppCompatActivity implements RatingDialogListene
|
||||
foodId,
|
||||
String.valueOf(value),
|
||||
comments);
|
||||
ratingTbl.child(Common.currentUser.getPhone()).addValueEventListener(new ValueEventListener() {
|
||||
@Override
|
||||
public void onDataChange(DataSnapshot dataSnapshot) {
|
||||
if (dataSnapshot.child(Common.currentUser.getPhone()).exists()) {
|
||||
//Remove old feedback
|
||||
ratingTbl.child(Common.currentUser.getPhone()).removeValue();
|
||||
//Update new feedback
|
||||
ratingTbl.child(Common.currentUser.getPhone()).setValue(rating);
|
||||
} else {
|
||||
|
||||
//Update new value
|
||||
ratingTbl.child(Common.currentUser.getPhone()).setValue(rating);
|
||||
}
|
||||
Toast.makeText(FoodDetail.this, "Cảm ơn bạn đã đánh giá món ăn!", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCancelled(DatabaseError databaseError) {
|
||||
|
||||
}
|
||||
});
|
||||
ratingTbl.push()
|
||||
.setValue(rating)
|
||||
.addOnCompleteListener(new OnCompleteListener<Void>() {
|
||||
@Override
|
||||
public void onComplete(@NonNull Task<Void> task) {
|
||||
Toast.makeText(FoodDetail.this, "Cảm ơn bạn đã đánh giá!", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
// ratingTbl.child(Common.currentUser.getPhone()).addValueEventListener(new ValueEventListener() {
|
||||
// @Override
|
||||
// public void onDataChange(DataSnapshot dataSnapshot) {
|
||||
// if (dataSnapshot.child(Common.currentUser.getPhone()).exists()) {
|
||||
// //Remove old feedback
|
||||
// ratingTbl.child(Common.currentUser.getPhone()).removeValue();
|
||||
// //Update new feedback
|
||||
// ratingTbl.child(Common.currentUser.getPhone()).setValue(rating);
|
||||
// } else {
|
||||
//
|
||||
// //Update new value
|
||||
// ratingTbl.child(Common.currentUser.getPhone()).setValue(rating);
|
||||
// }
|
||||
// Toast.makeText(FoodDetail.this, "Cảm ơn bạn đã đánh giá món ăn!", Toast.LENGTH_SHORT).show();
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onCancelled(DatabaseError databaseError) {
|
||||
//
|
||||
// }
|
||||
// });
|
||||
}
|
||||
}
|
||||
@@ -12,15 +12,19 @@ import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.text.Editable;
|
||||
import android.text.TextWatcher;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.firebase.ui.database.FirebaseRecyclerAdapter;
|
||||
import com.firebase.ui.database.FirebaseRecyclerOptions;
|
||||
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.Query;
|
||||
import com.google.firebase.database.ValueEventListener;
|
||||
import com.mancj.materialsearchbar.MaterialSearchBar;
|
||||
import com.squareup.picasso.Picasso;
|
||||
@@ -195,15 +199,22 @@ public class FoodList extends AppCompatActivity {
|
||||
actionBar.setDisplayHomeAsUpEnabled(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
loadListFood(categoryId);
|
||||
}
|
||||
|
||||
private void startSearch(CharSequence text) {
|
||||
searchAdapter = new FirebaseRecyclerAdapter<Food, FoodViewHolder>(
|
||||
Food.class,
|
||||
R.layout.food_item,
|
||||
FoodViewHolder.class,
|
||||
foodList.orderByChild("Name").equalTo(text.toString())
|
||||
) {
|
||||
//Create query by name
|
||||
Query searchByName = foodList.orderByChild("Name").equalTo(text.toString());
|
||||
//Create options with query
|
||||
FirebaseRecyclerOptions<Food> foodOptions = new FirebaseRecyclerOptions.Builder<Food>()
|
||||
.setQuery(searchByName, Food.class)
|
||||
.build();
|
||||
searchAdapter = new FirebaseRecyclerAdapter<Food, FoodViewHolder>(foodOptions) {
|
||||
@Override
|
||||
protected void populateViewHolder(FoodViewHolder viewHolder, Food model, int i) {
|
||||
protected void onBindViewHolder(@NonNull FoodViewHolder viewHolder, int i, @NonNull Food model) {
|
||||
viewHolder.food_name.setText(model.getName());
|
||||
Picasso.with(getBaseContext()).load(model.getImage()).into(viewHolder.food_image);
|
||||
|
||||
@@ -217,7 +228,17 @@ public class FoodList extends AppCompatActivity {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public FoodViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
View itemView = LayoutInflater.from(parent.getContext())
|
||||
.inflate(R.layout.food_item, parent, false);
|
||||
return new FoodViewHolder(itemView);
|
||||
}
|
||||
};
|
||||
|
||||
searchAdapter.startListening();
|
||||
recyclerView.setAdapter(searchAdapter); //Set adapter for Recycler View is Search result
|
||||
}
|
||||
|
||||
@@ -240,11 +261,16 @@ public class FoodList extends AppCompatActivity {
|
||||
}
|
||||
|
||||
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'
|
||||
) {
|
||||
//Create query by category Id
|
||||
Query searchByName = foodList.orderByChild("menuId").equalTo(categoryId);
|
||||
//Create Options with query
|
||||
FirebaseRecyclerOptions<Food> foodOptions = new FirebaseRecyclerOptions.Builder<Food>()
|
||||
.setQuery(searchByName, Food.class)
|
||||
.build();
|
||||
|
||||
adapter = new FirebaseRecyclerAdapter<Food, FoodViewHolder>(foodOptions) {
|
||||
@Override
|
||||
protected void populateViewHolder(FoodViewHolder viewHolder, Food model, int position) {
|
||||
protected void onBindViewHolder(@NonNull FoodViewHolder viewHolder, int position, @NonNull Food model) {
|
||||
viewHolder.food_name.setText(model.getName());
|
||||
viewHolder.food_price.setText(String.format("%s đ", model.getPrice()));
|
||||
Picasso.with(getBaseContext()).load(model.getImage()).into(viewHolder.food_image);
|
||||
@@ -254,7 +280,7 @@ public class FoodList extends AppCompatActivity {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
new Database(getBaseContext()).addToCart(new Order(
|
||||
adapter.getRef(position).getKey(),
|
||||
adapter.getRef(viewHolder.getAdapterPosition()).getKey(),
|
||||
model.getName(),
|
||||
"1",
|
||||
model.getPrice(),
|
||||
@@ -274,12 +300,12 @@ public class FoodList extends AppCompatActivity {
|
||||
viewHolder.fav_image.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if(!localDB.isFavorite(adapter.getRef(position).getKey())){
|
||||
localDB.addToFavorites(adapter.getRef(position).getKey());
|
||||
if(!localDB.isFavorite(adapter.getRef(viewHolder.getAdapterPosition()).getKey())){
|
||||
localDB.addToFavorites(adapter.getRef(viewHolder.getAdapterPosition()).getKey());
|
||||
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();
|
||||
} else {
|
||||
localDB.removeFromFavorites(adapter.getRef(position).getKey());
|
||||
localDB.removeFromFavorites(adapter.getRef(viewHolder.getAdapterPosition()).getKey());
|
||||
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();
|
||||
}
|
||||
@@ -296,13 +322,32 @@ public class FoodList extends AppCompatActivity {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public FoodViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
View itemView = LayoutInflater.from(parent.getContext())
|
||||
.inflate(R.layout.food_item, parent, false);
|
||||
return new FoodViewHolder(itemView);
|
||||
}
|
||||
};
|
||||
|
||||
//Set Adapter
|
||||
recyclerView.setAdapter(adapter);
|
||||
adapter.startListening();
|
||||
swipeRefreshLayout.setRefreshing(false);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
super.onStop();
|
||||
if(adapter == null) {
|
||||
adapter.stopListening();
|
||||
searchAdapter.stopListening();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
|
||||
@@ -8,6 +8,7 @@ import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.animation.AnimationUtils;
|
||||
import android.view.animation.LayoutAnimationController;
|
||||
import android.widget.TextView;
|
||||
@@ -26,6 +27,7 @@ import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
||||
|
||||
import com.andremion.counterfab.CounterFab;
|
||||
import com.firebase.ui.database.FirebaseRecyclerAdapter;
|
||||
import com.firebase.ui.database.FirebaseRecyclerOptions;
|
||||
import com.google.android.gms.tasks.OnCompleteListener;
|
||||
import com.google.android.gms.tasks.OnFailureListener;
|
||||
import com.google.android.gms.tasks.Task;
|
||||
@@ -145,9 +147,13 @@ public class Home extends AppCompatActivity implements NavigationView.OnNavigati
|
||||
database = FirebaseDatabase.getInstance();
|
||||
category = database.getReference("Category");
|
||||
|
||||
adapter = new FirebaseRecyclerAdapter<Category, MenuViewHolder>(Category.class, R.layout.menu_item, MenuViewHolder.class, category) {
|
||||
FirebaseRecyclerOptions<Category> options = new FirebaseRecyclerOptions.Builder<Category>()
|
||||
.setQuery(category, Category.class)
|
||||
.build();
|
||||
|
||||
adapter = new FirebaseRecyclerAdapter<Category, MenuViewHolder>(options) {
|
||||
@Override
|
||||
protected void populateViewHolder(MenuViewHolder viewHolder, Category model, int position) {
|
||||
protected void onBindViewHolder(@NonNull MenuViewHolder viewHolder, int i, @NonNull Category model) {
|
||||
viewHolder.txtMenuName.setText(model.getName());
|
||||
Picasso.with(getBaseContext()).load(model.getImage())
|
||||
.into(viewHolder.imageView);
|
||||
@@ -163,8 +169,18 @@ public class Home extends AppCompatActivity implements NavigationView.OnNavigati
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public MenuViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
View itemView = LayoutInflater.from(parent.getContext())
|
||||
.inflate(R.layout.menu_item, parent, false);
|
||||
return new MenuViewHolder(itemView);
|
||||
}
|
||||
};
|
||||
|
||||
adapter.startListening();
|
||||
|
||||
//Init paper
|
||||
Paper.init(this);
|
||||
|
||||
@@ -184,9 +200,16 @@ public class Home extends AppCompatActivity implements NavigationView.OnNavigati
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
super.onStop();
|
||||
adapter.stopListening();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
adapter.startListening();
|
||||
fab.setCount(new Database(this).getCountCart());
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,10 @@ package com.waterbase.foodify;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.ActionBar;
|
||||
@@ -11,8 +14,10 @@ import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.firebase.ui.database.FirebaseRecyclerAdapter;
|
||||
import com.firebase.ui.database.FirebaseRecyclerOptions;
|
||||
import com.google.firebase.database.DatabaseReference;
|
||||
import com.google.firebase.database.FirebaseDatabase;
|
||||
import com.google.firebase.database.Query;
|
||||
import com.waterbase.foodify.Common.Common;
|
||||
import com.waterbase.foodify.Model.Request;
|
||||
import com.waterbase.foodify.ViewHolder.OrderViewHolder;
|
||||
@@ -77,24 +82,41 @@ public class OrderStatus extends AppCompatActivity {
|
||||
}
|
||||
|
||||
private void loadOrders(String phone) {
|
||||
adapter = new FirebaseRecyclerAdapter<Request, OrderViewHolder>(
|
||||
Request.class,
|
||||
R.layout.order_layout,
|
||||
OrderViewHolder.class,
|
||||
requests.orderByChild("phone")
|
||||
.equalTo(phone)
|
||||
) {
|
||||
|
||||
Query getOrderByUser = requests.orderByChild("phone")
|
||||
.equalTo(phone);
|
||||
|
||||
FirebaseRecyclerOptions<Request> orderOptions = new FirebaseRecyclerOptions.Builder<Request>()
|
||||
.setQuery(getOrderByUser, Request.class)
|
||||
.build();
|
||||
|
||||
adapter = new FirebaseRecyclerAdapter<Request, OrderViewHolder>(orderOptions) {
|
||||
@Override
|
||||
protected void populateViewHolder(OrderViewHolder orderViewHolder, Request model, int i) {
|
||||
protected void onBindViewHolder(@NonNull OrderViewHolder orderViewHolder, int i, @NonNull Request model) {
|
||||
orderViewHolder.txtOrderId.setText(adapter.getRef(i).getKey());
|
||||
orderViewHolder.txtOrderStatus.setText(Common.convertCodeToStatus(model.getStatus()));
|
||||
orderViewHolder.txtOrderAddress.setText(model.getAddress());
|
||||
orderViewHolder.txtOrderPhone.setText(model.getPhone());
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public OrderViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
View itemView = LayoutInflater.from(parent.getContext())
|
||||
.inflate(R.layout.order_layout, parent, false);
|
||||
return new OrderViewHolder(itemView);
|
||||
}
|
||||
};
|
||||
adapter.startListening();
|
||||
recyclerView.setAdapter(adapter);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
super.onStop();
|
||||
adapter.stopListening();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
package com.waterbase.foodify;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
|
||||
import com.firebase.ui.database.FirebaseRecyclerAdapter;
|
||||
import com.google.firebase.database.DatabaseReference;
|
||||
import com.google.firebase.database.FirebaseDatabase;
|
||||
import com.google.firebase.database.Query;
|
||||
import com.waterbase.foodify.Common.Common;
|
||||
import com.waterbase.foodify.Model.Rating;
|
||||
import com.waterbase.foodify.ViewHolder.ShowCommentViewHolder;
|
||||
|
||||
import io.github.inflationx.calligraphy3.CalligraphyConfig;
|
||||
import io.github.inflationx.calligraphy3.CalligraphyInterceptor;
|
||||
import io.github.inflationx.viewpump.ViewPump;
|
||||
import io.github.inflationx.viewpump.ViewPumpContextWrapper;
|
||||
|
||||
public class ShowComment extends AppCompatActivity {
|
||||
|
||||
RecyclerView recyclerView;
|
||||
RecyclerView.LayoutManager layoutManager;
|
||||
|
||||
FirebaseDatabase database;
|
||||
DatabaseReference ratingTbl;
|
||||
|
||||
SwipeRefreshLayout mSwipeRefreshLayout;
|
||||
|
||||
FirebaseRecyclerAdapter<Rating, ShowCommentViewHolder> adapter;
|
||||
|
||||
String foodId = "";
|
||||
|
||||
|
||||
@Override
|
||||
protected void attachBaseContext(Context newBase) {
|
||||
super.attachBaseContext(ViewPumpContextWrapper.wrap(newBase));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
super.onStop();
|
||||
if(adapter != null)
|
||||
adapter.stopListening();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
//Set font all activity
|
||||
ViewPump.init(ViewPump.builder()
|
||||
.addInterceptor(new CalligraphyInterceptor(
|
||||
new CalligraphyConfig.Builder()
|
||||
.setDefaultFontPath("fonts/font.ttf")
|
||||
.setFontAttrId(io.github.inflationx.calligraphy3.R.attr.fontPath)
|
||||
.build()))
|
||||
.build());
|
||||
|
||||
setContentView(R.layout.activity_show_comment);
|
||||
|
||||
//Firebase
|
||||
database = FirebaseDatabase.getInstance();
|
||||
ratingTbl = database.getReference("Rating");
|
||||
|
||||
recyclerView = findViewById(R.id.recyclerComment);
|
||||
layoutManager = new LinearLayoutManager(this);
|
||||
recyclerView.setLayoutManager(layoutManager);
|
||||
|
||||
//Swipe Layout
|
||||
mSwipeRefreshLayout = findViewById(R.id.swipe_layout);
|
||||
mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
|
||||
@Override
|
||||
public void onRefresh() {
|
||||
if(getIntent() != null)
|
||||
foodId = getIntent().getStringExtra(Common.INTENT_FOOD_ID);
|
||||
if(!foodId.isEmpty() && foodId != null)
|
||||
{
|
||||
Query query = ratingTbl.orderByChild("foodId").equalTo(foodId);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.waterbase.foodify.ViewHolder;
|
||||
|
||||
import android.view.View;
|
||||
import android.widget.RatingBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.waterbase.foodify.R;
|
||||
|
||||
public class ShowCommentViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
public TextView txtUserPhone, txtComment;
|
||||
public RatingBar ratingBar;
|
||||
|
||||
public ShowCommentViewHolder(@NonNull View itemView) {
|
||||
super(itemView);
|
||||
txtComment = itemView.findViewById(R.id.txtComment);
|
||||
txtUserPhone = itemView.findViewById(R.id.txtUserPhone);
|
||||
ratingBar = itemView.findViewById(R.id.ratingBar);
|
||||
}
|
||||
}
|
||||
@@ -175,6 +175,21 @@
|
||||
|
||||
</androidx.cardview.widget.CardView>
|
||||
|
||||
<info.hoang8f.widget.FButton
|
||||
android:id="@+id/btnShowComment"
|
||||
android:text="Hiển thị bình luận"
|
||||
android:textColor="@color/white"
|
||||
android:layout_marginRight="8dp"
|
||||
android:layout_marginLeft="8dp"
|
||||
android:layout_margin="8dp"
|
||||
app:fButtonColor="#34eba1"
|
||||
app:shadowColor="#1e7854"
|
||||
app:shadowEnabled="true"
|
||||
app:shadowHeight="5dp"
|
||||
app:cornerRadius="4dp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".ShowComment">
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/recyclerComment"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
></androidx.recyclerview.widget.RecyclerView>
|
||||
|
||||
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
|
||||
@@ -0,0 +1,54 @@
|
||||
<?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="10dp"
|
||||
app:cardCornerRadius="8dp"
|
||||
>
|
||||
|
||||
<LinearLayout
|
||||
android:orientation="vertical"
|
||||
android:layout_margin="8dp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
>
|
||||
|
||||
<LinearLayout
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/txtUserPhone"
|
||||
android:text="User Phone"
|
||||
android:textSize="20sp"
|
||||
android:textStyle="bold"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
/>
|
||||
|
||||
<RatingBar
|
||||
android:id="@+id/ratingBar"
|
||||
style="?android:attr/ratingBarStyleSmall"
|
||||
android:layout_marginLeft="150dp"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:rating="3"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
/>
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/txtComment"
|
||||
android:text="Comment"
|
||||
android:textSize="16sp"
|
||||
android:textStyle="italic"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</androidx.cardview.widget.CardView>
|
||||
Reference in New Issue
Block a user