Fix show discount price + Add message from server to User

This commit is contained in:
phanhuuloi27
2022-07-02 21:14:34 +07:00
parent 4f9728d2bc
commit 384ee553a3
25 changed files with 358 additions and 35 deletions
@@ -16,6 +16,9 @@
android:supportsRtl="true"
android:theme="@style/Theme.FoodifyServer"
tools:targetApi="31">
<activity
android:name=".SendMessage"
android:exported="false" />
<activity
android:name=".BannerActivity"
android:exported="false" />
@@ -16,6 +16,8 @@ public class Common {
public static User currentUser;
public static Request currentRequest;
public static String topicName = "News";
public static final String UPDATE = "Cập nhật";
public static final String DELETE = "Xoá";
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) {
Intent banner = new Intent(Home.this, BannerActivity.class);
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);
@@ -4,8 +4,27 @@ public class Sender {
public String to;
public Notification notification;
public Sender() {
}
public Sender(String to, Notification notification) {
this.to = to;
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();
}
});
}
});
}
}
@@ -17,9 +17,11 @@ public class MyFirebaseIdService extends FirebaseInstanceIdService {
}
private void updateToServer(String refreshedToken) {
FirebaseDatabase db = FirebaseDatabase.getInstance();
DatabaseReference tokens = db.getReference("Tokens");
Token data = new Token(refreshedToken, true);
tokens.child(Common.currentUser.getPhone()).setValue(data);
if (Common.currentUser != null) {
FirebaseDatabase db = FirebaseDatabase.getInstance();
DatabaseReference tokens = db.getReference("Tokens");
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:icon="@drawable/ic_baseline_laptop_24"
android:title="Banner" />
<item
android:id="@+id/nav_message"
android:icon="@drawable/ic_baseline_message_24"
android:title="Thông báo" />
<item
android:id="@+id/nav_cart"
android:icon="@drawable/ic_baseline_shopping_cart_24"