Browse Source

Notifications init

pull/24/head
Ezerous 7 years ago
parent
commit
c3a8086eda
  1. 5
      app/build.gradle
  2. 7
      app/src/main/AndroidManifest.xml
  3. 10
      app/src/main/java/gr/thmmy/mthmmy/activities/BookmarkActivity.java
  4. 72
      app/src/main/java/gr/thmmy/mthmmy/services/FirebaseService.java
  5. 9
      app/src/main/res/drawable/ic_notification_off.xml
  6. 5
      app/src/main/res/drawable/ic_notification_on.xml
  7. 4
      app/src/main/res/layout/activity_bookmark_board_row.xml
  8. 42
      app/src/main/res/layout/activity_bookmark_topic_row.xml
  9. 1
      app/src/main/res/values/strings.xml
  10. 4
      build.gradle

5
app/build.gradle

@ -37,8 +37,9 @@ dependencies {
implementation 'com.android.support:support-v4:27.1.1' implementation 'com.android.support:support-v4:27.1.1'
implementation 'com.android.support:cardview-v7:27.1.1' implementation 'com.android.support:cardview-v7:27.1.1'
implementation 'com.android.support:recyclerview-v7:27.1.1' implementation 'com.android.support:recyclerview-v7:27.1.1'
implementation 'com.google.firebase:firebase-core:15.0.0' implementation 'com.google.firebase:firebase-core:15.0.2'
implementation 'com.crashlytics.sdk.android:crashlytics:2.9.1' implementation 'com.google.firebase:firebase-messaging:15.0.2'
implementation 'com.crashlytics.sdk.android:crashlytics:2.9.2'
implementation 'com.squareup.okhttp3:okhttp:3.10.0' implementation 'com.squareup.okhttp3:okhttp:3.10.0'
implementation 'com.squareup.picasso:picasso:2.5.2' implementation 'com.squareup.picasso:picasso:2.5.2'
implementation 'com.jakewharton.picasso:picasso2-okhttp3-downloader:1.1.0' implementation 'com.jakewharton.picasso:picasso2-okhttp3-downloader:1.1.0'

7
app/src/main/AndroidManifest.xml

@ -119,6 +119,13 @@
<service <service
android:name=".services.DownloadService" android:name=".services.DownloadService"
android:exported="false" /> android:exported="false" />
<service
android:name=".services.FirebaseService"
android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>
<receiver <receiver
android:name=".receiver.Receiver" android:name=".receiver.Receiver"

10
app/src/main/java/gr/thmmy/mthmmy/activities/BookmarkActivity.java

@ -67,7 +67,7 @@ public class BookmarkActivity extends BaseActivity {
for (final Bookmark bookmarkedBoard : getBoardsBookmarked()) { for (final Bookmark bookmarkedBoard : getBoardsBookmarked()) {
if (bookmarkedBoard != null && bookmarkedBoard.getTitle() != null) { if (bookmarkedBoard != null && bookmarkedBoard.getTitle() != null) {
final LinearLayout row = (LinearLayout) layoutInflater.inflate( final LinearLayout row = (LinearLayout) layoutInflater.inflate(
R.layout.activity_bookmark_row, bookmarksLinearView, false); R.layout.activity_bookmark_board_row, bookmarksLinearView, false);
row.setOnClickListener(new View.OnClickListener() { row.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
@ -116,7 +116,7 @@ public class BookmarkActivity extends BaseActivity {
for (final Bookmark bookmarkedTopic : getTopicsBookmarked()) { for (final Bookmark bookmarkedTopic : getTopicsBookmarked()) {
if (bookmarkedTopic != null && bookmarkedTopic.getTitle() != null) { if (bookmarkedTopic != null && bookmarkedTopic.getTitle() != null) {
final LinearLayout row = (LinearLayout) layoutInflater.inflate( final LinearLayout row = (LinearLayout) layoutInflater.inflate(
R.layout.activity_bookmark_row, bookmarksLinearView, false); R.layout.activity_bookmark_topic_row, bookmarksLinearView, false);
row.setOnClickListener(new View.OnClickListener() { row.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
@ -131,6 +131,12 @@ public class BookmarkActivity extends BaseActivity {
} }
}); });
((TextView) row.findViewById(R.id.bookmark_title)).setText(bookmarkedTopic.getTitle()); ((TextView) row.findViewById(R.id.bookmark_title)).setText(bookmarkedTopic.getTitle());
(row.findViewById(R.id.toggle_notification)).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//TODO
}
});
(row.findViewById(R.id.remove_bookmark)).setOnClickListener(new View.OnClickListener() { (row.findViewById(R.id.remove_bookmark)).setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {

72
app/src/main/java/gr/thmmy/mthmmy/services/FirebaseService.java

@ -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());
}
}

9
app/src/main/res/drawable/ic_notification_off.xml

@ -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>

5
app/src/main/res/drawable/ic_notification_on.xml

@ -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>

4
app/src/main/res/layout/activity_bookmark_row.xml → app/src/main/res/layout/activity_bookmark_board_row.xml

@ -4,7 +4,7 @@
android:id="@+id/bookmark_row" android:id="@+id/bookmark_row"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground" android:background="?android:attr/selectableItemBackground"
android:clickable="true" android:clickable="true"
android:focusable="true" android:focusable="true"
android:gravity="center_vertical" android:gravity="center_vertical"
@ -27,7 +27,7 @@
android:id="@+id/remove_bookmark" android:id="@+id/remove_bookmark"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground" android:background="?android:attr/selectableItemBackground"
android:contentDescription="@string/remove_bookmark" android:contentDescription="@string/remove_bookmark"
android:src="@drawable/ic_remove_circle"/> android:src="@drawable/ic_remove_circle"/>
</LinearLayout> </LinearLayout>

42
app/src/main/res/layout/activity_bookmark_topic_row.xml

@ -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>

1
app/src/main/res/values/strings.xml

@ -90,4 +90,5 @@
<string name="fa_sticky">&#xf249;</string> <string name="fa_sticky">&#xf249;</string>
<string name="fa_folder">&#xf07b;</string> <string name="fa_folder">&#xf07b;</string>
<string name="fa_circle">&#xf111;</string> <string name="fa_circle">&#xf111;</string>
<string name="toggle_notification">Toggle Notification</string>
</resources> </resources>

4
build.gradle

@ -9,8 +9,8 @@ buildscript {
google() google()
} }
dependencies { dependencies {
classpath 'com.android.tools.build:gradle:3.1.1' classpath 'com.android.tools.build:gradle:3.1.2'
classpath 'com.google.gms:google-services:3.2.0' classpath 'com.google.gms:google-services:3.3.0'
classpath 'io.fabric.tools:gradle:1.25.1' classpath 'io.fabric.tools:gradle:1.25.1'
} }
} }

Loading…
Cancel
Save