mirror of https://github.com/ThmmyNoLife/mTHMMY
Ezerous
7 years ago
10 changed files with 153 additions and 10 deletions
@ -0,0 +1,72 @@ |
|||||
|
package gr.thmmy.mthmmy.services; |
||||
|
|
||||
|
import android.app.NotificationChannel; |
||||
|
import android.app.NotificationManager; |
||||
|
import android.app.PendingIntent; |
||||
|
import android.content.Context; |
||||
|
import android.content.Intent; |
||||
|
import android.media.RingtoneManager; |
||||
|
import android.net.Uri; |
||||
|
import android.os.Build; |
||||
|
import android.support.v4.app.NotificationCompat; |
||||
|
|
||||
|
import com.google.firebase.messaging.FirebaseMessagingService; |
||||
|
import com.google.firebase.messaging.RemoteMessage; |
||||
|
|
||||
|
import gr.thmmy.mthmmy.R; |
||||
|
import gr.thmmy.mthmmy.activities.topic.TopicActivity; |
||||
|
import timber.log.Timber; |
||||
|
|
||||
|
|
||||
|
public class FirebaseService extends FirebaseMessagingService { |
||||
|
|
||||
|
@Override |
||||
|
public void onMessageReceived(RemoteMessage remoteMessage) { |
||||
|
super.onMessageReceived(remoteMessage); |
||||
|
if (remoteMessage.getData().size() > 0) { |
||||
|
|
||||
|
Timber.i("msg%s", remoteMessage.getData()); |
||||
|
sendNotification("stuff"); |
||||
|
|
||||
|
} |
||||
|
|
||||
|
|
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Create and show a simple notification containing the received FCM message. |
||||
|
*/ |
||||
|
private void sendNotification(String message) { |
||||
|
Intent intent = new Intent(this, TopicActivity.class); |
||||
|
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); |
||||
|
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent, |
||||
|
PendingIntent.FLAG_ONE_SHOT); |
||||
|
|
||||
|
String channelId = "ASdf"; //getString(R.string.default_notification_channel_id);
|
||||
|
Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); |
||||
|
NotificationCompat.Builder notificationBuilder = |
||||
|
new NotificationCompat.Builder(this, channelId) |
||||
|
.setSmallIcon(R.mipmap.ic_launcher) |
||||
|
.setContentTitle("FCM Message") |
||||
|
.setContentText(message) |
||||
|
.setAutoCancel(true) |
||||
|
.setSound(defaultSoundUri) |
||||
|
.setContentIntent(pendingIntent); |
||||
|
|
||||
|
NotificationManager notificationManager = |
||||
|
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); |
||||
|
|
||||
|
// Since android Oreo notification channel is needed.
|
||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { |
||||
|
NotificationChannel channel = new NotificationChannel("Posts", |
||||
|
"New Posts", |
||||
|
NotificationManager.IMPORTANCE_DEFAULT); |
||||
|
|
||||
|
notificationManager.createNotificationChannel(channel); |
||||
|
|
||||
|
} |
||||
|
|
||||
|
|
||||
|
notificationManager.notify(0, notificationBuilder.build()); |
||||
|
} |
||||
|
} |
@ -0,0 +1,9 @@ |
|||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android" |
||||
|
android:width="24dp" |
||||
|
android:height="24dp" |
||||
|
android:viewportWidth="24.0" |
||||
|
android:viewportHeight="24.0"> |
||||
|
<path |
||||
|
android:fillColor="#26A69A" |
||||
|
android:pathData="M12,22c1.1,0 2,-0.9 2,-2h-4c0,1.1 0.9,2 2,2zM18,16v-5c0,-3.07 -1.63,-5.64 -4.5,-6.32L13.5,4c0,-0.83 -0.67,-1.5 -1.5,-1.5s-1.5,0.67 -1.5,1.5v0.68C7.64,5.36 6,7.92 6,11v5l-2,2v1h16v-1l-2,-2zM16,17L8,17v-6c0,-2.48 1.51,-4.5 4,-4.5s4,2.02 4,4.5v6z"/> |
||||
|
</vector> |
@ -0,0 +1,5 @@ |
|||||
|
<vector android:height="24dp" |
||||
|
android:viewportHeight="24.0" android:viewportWidth="24.0" |
||||
|
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android"> |
||||
|
<path android:fillColor="#26A69A" android:pathData="M7.58,4.08L6.15,2.65C3.75,4.48 2.17,7.3 2.03,10.5h2c0.15,-2.65 1.51,-4.97 3.55,-6.42zM19.97,10.5h2c-0.15,-3.2 -1.73,-6.02 -4.12,-7.85l-1.42,1.43c2.02,1.45 3.39,3.77 3.54,6.42zM18,11c0,-3.07 -1.64,-5.64 -4.5,-6.32L13.5,4c0,-0.83 -0.67,-1.5 -1.5,-1.5s-1.5,0.67 -1.5,1.5v0.68C7.63,5.36 6,7.92 6,11v5l-2,2v1h16v-1l-2,-2v-5zM12,22c0.14,0 0.27,-0.01 0.4,-0.04 0.65,-0.14 1.18,-0.58 1.44,-1.18 0.1,-0.24 0.15,-0.5 0.15,-0.78h-4c0.01,1.1 0.9,2 2.01,2z"/> |
||||
|
</vector> |
@ -0,0 +1,42 @@ |
|||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||
|
<LinearLayout |
||||
|
xmlns:android="http://schemas.android.com/apk/res/android" |
||||
|
xmlns:app="http://schemas.android.com/apk/res-auto" |
||||
|
android:id="@+id/bookmark_row" |
||||
|
android:layout_width="match_parent" |
||||
|
android:layout_height="wrap_content" |
||||
|
android:background="?android:attr/selectableItemBackground" |
||||
|
android:clickable="true" |
||||
|
android:focusable="true" |
||||
|
android:gravity="center_vertical" |
||||
|
android:orientation="horizontal" |
||||
|
android:paddingBottom="6dp" |
||||
|
android:paddingEnd="16dp" |
||||
|
android:paddingStart="16dp" |
||||
|
android:paddingTop="6dp"> |
||||
|
|
||||
|
<TextView |
||||
|
android:id="@+id/bookmark_title" |
||||
|
android:layout_width="0dp" |
||||
|
android:layout_height="wrap_content" |
||||
|
android:layout_weight="1" |
||||
|
android:paddingBottom="2dp" |
||||
|
android:textColor="@color/primary_text" |
||||
|
android:textSize="18sp"/> |
||||
|
|
||||
|
<ImageButton |
||||
|
android:id="@+id/toggle_notification" |
||||
|
android:layout_width="wrap_content" |
||||
|
android:layout_height="wrap_content" |
||||
|
android:background="?android:attr/selectableItemBackground" |
||||
|
android:contentDescription="@string/toggle_notification" |
||||
|
app:srcCompat="@drawable/ic_notification_off"/> |
||||
|
|
||||
|
<ImageButton |
||||
|
android:id="@+id/remove_bookmark" |
||||
|
android:layout_width="wrap_content" |
||||
|
android:layout_height="wrap_content" |
||||
|
android:background="?android:attr/selectableItemBackground" |
||||
|
android:contentDescription="@string/remove_bookmark" |
||||
|
android:src="@drawable/ic_remove_circle"/> |
||||
|
</LinearLayout> |
Loading…
Reference in new issue