Skip to content

Commit 9a6247e

Browse files
committed
update play-service to build notifications and send play data to the play activity
1 parent a3f1bb6 commit 9a6247e

File tree

1 file changed

+82
-1
lines changed

1 file changed

+82
-1
lines changed

app/src/main/java/yankov/tsvetilian/watchit/Services/PlayMessagingService.java

Lines changed: 82 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,96 @@
11
package yankov.tsvetilian.watchit.Services;
22

3+
import android.app.NotificationChannel;
4+
import android.app.NotificationManager;
5+
import android.app.PendingIntent;
6+
import android.content.Intent;
7+
import android.os.Build;
8+
import android.support.v4.app.NotificationCompat;
9+
import android.support.v4.app.NotificationManagerCompat;
10+
311
import com.google.firebase.messaging.FirebaseMessagingService;
412
import com.google.firebase.messaging.RemoteMessage;
513

14+
import java.util.Map;
15+
16+
import yankov.tsvetilian.watchit.Activities.PlayerActivity;
17+
import yankov.tsvetilian.watchit.Models.WatchModel;
618
import yankov.tsvetilian.watchit.NetworkHandler;
19+
import yankov.tsvetilian.watchit.R;
720

821
public class PlayMessagingService extends FirebaseMessagingService {
922

1023
@Override
1124
public void onMessageReceived(RemoteMessage remoteMessage) {
12-
//TODO
25+
createWatchObject(remoteMessage.getData());
26+
}
27+
28+
private void createWatchObject(Map<String, String> remoteMessage) {
29+
String seasonCheck = null;
30+
31+
if (!remoteMessage.get("season").equals("null")) {
32+
seasonCheck = remoteMessage.get("season");
33+
}
34+
35+
WatchModel watch = new WatchModel(
36+
remoteMessage.get("name"),
37+
remoteMessage.get("play"),
38+
remoteMessage.get("playFrom"),
39+
remoteMessage.get("sourceName"),
40+
remoteMessage.get("key"),
41+
remoteMessage.get("path"),
42+
remoteMessage.get("poster"),
43+
remoteMessage.get("description"),
44+
remoteMessage.get("time"),
45+
false,
46+
false,
47+
seasonCheck
48+
);
49+
50+
createChannel(watch);
51+
}
52+
53+
private void createChannel(WatchModel watch) {
54+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
55+
NotificationChannel notificationChannel = new NotificationChannel("WATCHIT", "WatchIt Channel", NotificationManager.IMPORTANCE_HIGH);
56+
NotificationManager notificationManager = getSystemService(NotificationManager.class);
57+
if (notificationManager != null) {
58+
notificationManager.createNotificationChannel(notificationChannel);
59+
}
60+
}
61+
62+
buildNotification(watch);
63+
}
64+
65+
private void buildNotification(WatchModel watch) {
66+
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
67+
68+
Intent startPlayer = new Intent(getApplicationContext(), PlayerActivity.class);
69+
startPlayer.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
70+
startPlayer.putExtra("watch", watch);
71+
PendingIntent play = PendingIntent.getActivity(this, 90, startPlayer, PendingIntent.FLAG_UPDATE_CURRENT);
72+
73+
74+
Intent watchLater = new Intent(getApplicationContext(), PlayerActivity.class);
75+
watchLater.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
76+
watchLater.putExtra("later", watch);
77+
PendingIntent later = PendingIntent.getActivity(this, 100, watchLater, PendingIntent.FLAG_UPDATE_CURRENT);
78+
79+
NotificationCompat.Builder notification = new NotificationCompat.Builder(this, "WATCHIT")
80+
.setSmallIcon(R.drawable.ic_play)
81+
.setContentTitle(watch.getPresentableName())
82+
.setContentText(watch.getDescription())
83+
.setContentIntent(play)
84+
.setStyle(new NotificationCompat.BigTextStyle()
85+
.setBigContentTitle(watch.getPresentableName())
86+
.bigText(watch.getDescription())
87+
.setSummaryText(watch.getSourceName()))
88+
.setPriority(NotificationCompat.PRIORITY_HIGH)
89+
.addAction(R.drawable.ic_play, "Play", play)
90+
.addAction(R.drawable.ic_later, "Later", later)
91+
.setAutoCancel(true);
92+
93+
notificationManager.notify(110, notification.build());
1394
}
1495

1596
@Override

0 commit comments

Comments
 (0)