Skip to content

Commit 1ae20bf

Browse files
committed
Merge branch 'v2.0'
2 parents 6e52b13 + 8b5b345 commit 1ae20bf

File tree

63 files changed

+2657
-121
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+2657
-121
lines changed

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ android {
4646
targetCompatibility JavaVersion.VERSION_1_8
4747
}
4848

49-
viewBinding {
50-
enabled = true
49+
buildFeatures {
50+
viewBinding = true
5151
}
5252
}
5353

app/src/main/java/com/simonesestito/shopsqueue/FcmReceiverService.java

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,11 @@
3333

3434
import com.google.firebase.messaging.FirebaseMessagingService;
3535
import com.google.firebase.messaging.RemoteMessage;
36+
import com.simonesestito.shopsqueue.api.DateJsonAdapter;
3637
import com.simonesestito.shopsqueue.api.dto.Booking;
3738
import com.simonesestito.shopsqueue.api.dto.BookingWithCount;
3839
import com.simonesestito.shopsqueue.api.dto.FcmToken;
40+
import com.simonesestito.shopsqueue.api.dto.ShoppingList;
3941
import com.simonesestito.shopsqueue.api.service.FcmService;
4042
import com.simonesestito.shopsqueue.ui.MainActivity;
4143
import com.squareup.moshi.Moshi;
@@ -50,9 +52,13 @@ public class FcmReceiverService extends FirebaseMessagingService {
5052
private static final String KEY_MESSAGE_DATA = "data";
5153
private static final String MESSAGE_TYPE_QUEUE_NOTICE = "queue-notice";
5254
private static final String MESSAGE_TYPE_BOOKING_CANCELLED = "booking-cancelled";
55+
private static final String MESSAGE_TYPE_ORDER_READY = "order-ready";
56+
private static final String MESSAGE_TYPE_ORDER_CANCELLED = "order-cancelled";
5357
private static final String NOTIFICATION_CHANNEL_BOOKINGS_NOTICE_ID = "bookings-notice";
58+
private static final String NOTIFICATION_CHANNEL_ORDERS_NOTICE_ID = "orders-notice";
5459
@Inject FcmService fcmService;
5560
@Inject SharedPreferencesStore sharedPreferencesStore;
61+
@Inject DateJsonAdapter dateJsonAdapter;
5662

5763
@Override
5864
public void onCreate() {
@@ -90,11 +96,17 @@ public void onMessageReceived(@NonNull RemoteMessage remoteMessage) {
9096
return;
9197

9298
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
93-
NotificationChannel channel = new NotificationChannel(
99+
NotificationChannel bookingsChannel = new NotificationChannel(
94100
NOTIFICATION_CHANNEL_BOOKINGS_NOTICE_ID,
95101
getString(R.string.notification_channel_booking_notice),
96102
NotificationManager.IMPORTANCE_HIGH);
97-
notificationManager.createNotificationChannel(channel);
103+
notificationManager.createNotificationChannel(bookingsChannel);
104+
105+
NotificationChannel ordersChannel = new NotificationChannel(
106+
NOTIFICATION_CHANNEL_ORDERS_NOTICE_ID,
107+
getString(R.string.notification_channel_orders_notice),
108+
NotificationManager.IMPORTANCE_HIGH);
109+
notificationManager.createNotificationChannel(ordersChannel);
98110
}
99111

100112
switch (messageType != null ? messageType : "null") {
@@ -104,6 +116,12 @@ public void onMessageReceived(@NonNull RemoteMessage remoteMessage) {
104116
case MESSAGE_TYPE_BOOKING_CANCELLED:
105117
handleBookingCancellation(jsonData);
106118
break;
119+
case MESSAGE_TYPE_ORDER_READY:
120+
handleOrderReady(jsonData);
121+
break;
122+
case MESSAGE_TYPE_ORDER_CANCELLED:
123+
handleOrderCancellation(jsonData);
124+
break;
107125
default:
108126
Log.e(TAG, "Received payload with unknown type: " + messageType);
109127
}
@@ -112,7 +130,7 @@ public void onMessageReceived(@NonNull RemoteMessage remoteMessage) {
112130
private void handleQueueNotice(String jsonString) {
113131
BookingWithCount data = parseJson(jsonString, BookingWithCount.class);
114132
if (data == null) {
115-
Log.e(TAG, "Received payload with empty Booking data");
133+
Log.e(TAG, "Received payload with invalid Booking data");
116134
return;
117135
}
118136

@@ -134,7 +152,7 @@ private void handleQueueNotice(String jsonString) {
134152
private void handleBookingCancellation(String jsonString) {
135153
Booking data = parseJson(jsonString, Booking.class);
136154
if (data == null) {
137-
Log.e(TAG, "Received payload with empty Booking data");
155+
Log.e(TAG, "Received payload with invalid Booking data");
138156
return;
139157
}
140158

@@ -145,13 +163,42 @@ private void handleBookingCancellation(String jsonString) {
145163
);
146164
}
147165

166+
private void handleOrderReady(String json) {
167+
ShoppingList data = parseJson(json, ShoppingList.class);
168+
if (data == null) {
169+
Log.e(TAG, "Received payload with invalid ShoppingList data");
170+
return;
171+
}
172+
173+
showNotification(
174+
data.getId() + 100_000,
175+
data.getShop().getName(),
176+
getString(R.string.notification_order_ready_message)
177+
);
178+
}
179+
180+
private void handleOrderCancellation(String json) {
181+
ShoppingList data = parseJson(json, ShoppingList.class);
182+
if (data == null) {
183+
Log.e(TAG, "Received payload with invalid ShoppingList data");
184+
return;
185+
}
186+
187+
showNotification(
188+
data.getId() + 100_000,
189+
data.getShop().getName(),
190+
getString(R.string.notification_order_cancelled_message)
191+
);
192+
}
193+
148194
@Nullable
149195
private <T> T parseJson(String json, Class<T> clazz) {
150196
if (json == null || json.isEmpty())
151197
return null;
152198

153199
try {
154200
return new Moshi.Builder()
201+
.add(dateJsonAdapter)
155202
.build()
156203
.adapter(clazz)
157204
.fromJson(json);
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright 2020 Simone Sestito
3+
* This file is part of Shops Queue.
4+
*
5+
* Shops Queue is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* Shops Queue is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with Shops Queue. If not, see <http://www.gnu.org/licenses/>.
17+
*/
18+
19+
package com.simonesestito.shopsqueue.api.dto;
20+
21+
public class NewProduct {
22+
private String name;
23+
private String ean;
24+
private double price;
25+
26+
public NewProduct(String name, String ean, double price) {
27+
this.name = name;
28+
this.ean = ean;
29+
this.price = price;
30+
}
31+
32+
public String getName() {
33+
return name;
34+
}
35+
36+
public void setName(String name) {
37+
this.name = name;
38+
}
39+
40+
public String getEan() {
41+
return ean;
42+
}
43+
44+
public void setEan(String ean) {
45+
this.ean = ean;
46+
}
47+
48+
public double getPrice() {
49+
return price;
50+
}
51+
52+
public void setPrice(double price) {
53+
this.price = price;
54+
}
55+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright 2020 Simone Sestito
3+
* This file is part of Shops Queue.
4+
*
5+
* Shops Queue is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* Shops Queue is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with Shops Queue. If not, see <http://www.gnu.org/licenses/>.
17+
*/
18+
19+
package com.simonesestito.shopsqueue.api.dto;
20+
21+
public class NewShoppingList {
22+
private int[] productIds;
23+
24+
public NewShoppingList(int[] productIds) {
25+
this.productIds = productIds;
26+
}
27+
28+
public int[] getProductIds() {
29+
return productIds;
30+
}
31+
32+
public void setProductIds(int[] productIds) {
33+
this.productIds = productIds;
34+
}
35+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* Copyright 2020 Simone Sestito
3+
* This file is part of Shops Queue.
4+
*
5+
* Shops Queue is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* Shops Queue is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with Shops Queue. If not, see <http://www.gnu.org/licenses/>.
17+
*/
18+
19+
package com.simonesestito.shopsqueue.api.dto;
20+
21+
import com.simonesestito.shopsqueue.model.Identifiable;
22+
23+
public class Product implements Identifiable {
24+
private int id;
25+
private String name;
26+
private String ean;
27+
private double price;
28+
29+
public int getId() {
30+
return id;
31+
}
32+
33+
public void setId(int id) {
34+
this.id = id;
35+
}
36+
37+
public String getName() {
38+
return name;
39+
}
40+
41+
public void setName(String name) {
42+
this.name = name;
43+
}
44+
45+
public String getEan() {
46+
return ean;
47+
}
48+
49+
public void setEan(String ean) {
50+
this.ean = ean;
51+
}
52+
53+
public double getPrice() {
54+
return price;
55+
}
56+
57+
public void setPrice(double price) {
58+
this.price = price;
59+
}
60+
}

0 commit comments

Comments
 (0)