Some magic for notifications

Signed-off-by: Mario Danic <mario@lovelyhq.com>
This commit is contained in:
Mario Danic 2018-08-10 00:41:13 +02:00
parent 7f63476669
commit 28780d2a3b
11 changed files with 134 additions and 49 deletions

View File

@ -162,7 +162,7 @@ public class CallItem extends AbstractFlexibleItem<CallItem.RoomItemViewHolder>
GlideApp.with(NextcloudTalkApplication.getSharedApplication().getApplicationContext())
.asBitmap()
.diskCacheStrategy(DiskCacheStrategy.NONE)
.load(R.drawable.ic_group_white_24px)
.load(R.drawable.ic_people_group_white_24px)
.centerInside()
.override(avatarSize, avatarSize)
.apply(RequestOptions.bitmapTransform(new CircleCrop()))

View File

@ -245,7 +245,7 @@ public class ConversationItem extends AbstractFlexibleItem<ConversationItem.Conv
GlideApp.with(context)
.asBitmap()
.diskCacheStrategy(DiskCacheStrategy.NONE)
.load(R.drawable.ic_group_white_24px)
.load(R.drawable.ic_people_group_white_24px)
.centerInside()
.override(avatarSize, avatarSize)
.apply(RequestOptions.bitmapTransform(new CircleCrop()))

View File

@ -447,7 +447,7 @@ public class CallNotificationController extends BaseController {
GlideApp.with(NextcloudTalkApplication.getSharedApplication().getApplicationContext())
.asBitmap()
.diskCacheStrategy(DiskCacheStrategy.NONE)
.load(R.drawable.ic_group_white_24px)
.load(R.drawable.ic_people_group_white_24px)
.centerInside()
.override(avatarSize, avatarSize)
.apply(RequestOptions.bitmapTransform(new CircleCrop()))

View File

@ -72,6 +72,7 @@ import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.security.PrivateKey;
import java.util.Calendar;
import java.util.HashMap;
import java.util.zip.CRC32;
import javax.crypto.Cipher;
@ -99,6 +100,7 @@ public class NotificationJob extends Job {
private DecryptedPushMessage decryptedPushMessage;
private Context context;
private SignatureVerification signatureVerification;
private String conversationType = "";
@NonNull
@Override
@ -233,6 +235,11 @@ public class NotificationJob extends Job {
if (conversation.getType().equals(Conversation.RoomType.ROOM_TYPE_ONE_TO_ONE_CALL)) {
context.startActivity(intent);
} else {
if (conversation.getType().equals(Conversation.RoomType.ROOM_GROUP_CALL)) {
conversationType = "group";
} else {
conversationType = "public";
}
showNotification(intent);
}
}
@ -265,11 +272,6 @@ public class NotificationJob extends Job {
com.nextcloud.talk.models.json.notifications.Notification notification =
notificationOverall.getOcs().getNotification();
// subject: group name
// content -
// group: name of author: message
// user: message
if (notification.getMessageRichParameters() != null &&
notification.getMessageRichParameters().size() > 0) {
decryptedPushMessage.setText(ChatUtils.getParsedMessage(notification.getMessageRich(),
@ -278,6 +280,24 @@ public class NotificationJob extends Job {
decryptedPushMessage.setText(notification.getMessage());
}
HashMap<String, HashMap<String, String>> subjectRichParametersRichParameters = notification
.getSubjectRichParameters();
if (subjectRichParametersRichParameters != null && subjectRichParametersRichParameters
.size() > 0 && subjectRichParametersRichParameters.containsKey("call")
&& subjectRichParametersRichParameters.containsKey("user")) {
HashMap<String, String> callHashMap = subjectRichParametersRichParameters.get("call");
HashMap<String, String> userHashMap = subjectRichParametersRichParameters.get("user");
if (callHashMap.containsKey("call-type")) {
conversationType = callHashMap.get("call-type");
if ("one2one".equals(conversationType)) {
decryptedPushMessage.setSubject(userHashMap.get("name"));
}
}
}
showNotification(intent);
}
@ -294,26 +314,47 @@ public class NotificationJob extends Job {
private void showNotification(Intent intent) {
int smallIcon;
Bitmap largeIcon;
Bitmap largeIcon = null;
String category;
int priority = Notification.PRIORITY_HIGH;
Uri soundUri;
smallIcon = R.drawable.ic_logo;
if (decryptedPushMessage.getType().equals("chat")) {
smallIcon = R.drawable.ic_chat_white_24dp;
category = Notification.CATEGORY_MESSAGE;
} else {
smallIcon = R.drawable.ic_call_white_24dp;
category = Notification.CATEGORY_CALL;
}
switch (conversationType) {
case "one2one":
if (decryptedPushMessage.getType().equals("chat")) {
largeIcon = BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_chat_black_24dp);
} else {
largeIcon = BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_call_black_24dp);
}
break;
case "group":
largeIcon = BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_people_group_black_24px);
break;
case "public":
largeIcon = BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_link_black_24px);
break;
default:
if (decryptedPushMessage.getType().equals("chat")) {
largeIcon = BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_chat_black_24dp);
} else {
largeIcon = BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_call_black_24dp);
}
}
PendingIntent pendingIntent = PendingIntent.getActivity(context,
0, intent, PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_ONE_SHOT);
NotificationManager notificationManager =
(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
largeIcon = BitmapFactory.decodeResource(context.getResources(), smallIcon);
CRC32 crc32 = new CRC32();
Notification.Builder notificationBuilder = new Notification.Builder(context)

View File

@ -0,0 +1,27 @@
<!--
~ Nextcloud Talk application
~
~ @author Mario Danic
~ Copyright (C) 2017-2018 Mario Danic <mario@lovelyhq.com>
~
~ This program is free software: you can redistribute it and/or modify
~ it under the terms of the GNU General Public License as published by
~ the Free Software Foundation, either version 3 of the License, or
~ at your option) any later version.
~
~ This program is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
~ GNU General Public License for more details.
~
~ You should have received a copy of the GNU General Public License
~ along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<vector android:autoMirrored="true" 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="#000000" android:fillType="nonZero"
android:pathData="M13,5.921L9.818,9.105C9.111,9.812 8.781,10.723 8.83,11.562C8.88,12.401 9.263,13.146 9.818,13.701L11.23,12.285C10.663,11.717 10.686,11.065 11.232,10.519L14.414,7.337C14.939,6.812 15.664,6.814 16.186,7.335C16.668,7.891 16.713,8.574 16.182,9.105L15.362,9.925C15.917,10.71 16.007,11.291 15.955,12.16L17.596,10.519C18.833,9.282 18.833,7.154 17.596,5.917C16.36,4.681 14.254,4.706 13,5.921L13,5.921ZM13.707,9.806L12.293,11.224L12.297,11.224C12.847,11.774 12.804,12.482 12.293,12.994L9.111,16.175C8.415,16.767 7.813,16.646 7.342,16.175C6.715,15.549 6.842,14.907 7.342,14.407L8.192,13.56C7.636,12.777 7.543,12.195 7.594,11.328L5.928,12.994C4.689,14.233 4.692,16.354 5.928,17.589C7.163,18.825 9.29,18.825 10.526,17.589L13.707,14.407C14.416,13.699 14.747,12.789 14.698,11.949C14.65,11.109 14.266,10.362 13.709,9.808L13.707,9.806Z"
android:strokeColor="#00000000" android:strokeWidth="1"/>
</vector>

View File

@ -1,36 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Nextcloud Talk application
~
~ @author Mario Danic
~ Copyright (C) 2017-2018 Mario Danic <mario@lovelyhq.com>
~
~ This program is free software: you can redistribute it and/or modify
~ it under the terms of the GNU General Public License as published by
~ the Free Software Foundation, either version 3 of the License, or
~ at your option) any later version.
~
~ This program is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
~ GNU General Public License for more details.
~
~ You should have received a copy of the GNU General Public License
~ along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#000000"
android:pathData="M7.9992,0.999 A6.9994,6.9993,0,0,0,1,7.9986 A6.9994,6.9993,0,0,0,7.9992,14.998
A6.9994,6.9993,0,0,0,11.63,13.974 C12.4902,14.3158,14.4171,15.33,14.8757,14.8919
C15.3549,14.4343,14.3131,12.2803,14.0633,11.4799
A6.9994,6.9993,0,0,0,14.9983,7.9985 A6.9994,6.9993,0,0,0,7.9992,0.9992 Z
M8,3.6601 A4.3401,4.34,0,0,1,12.34,8.0002 A4.3401,4.34,0,0,1,8,12.34
A4.3401,4.34,0,0,1,3.66,8.0002 A4.3401,4.34,0,0,1,8,3.6601 Z" />
</vector>

View File

@ -0,0 +1,27 @@
<!--
~ Nextcloud Talk application
~
~ @author Mario Danic
~ Copyright (C) 2017-2018 Mario Danic <mario@lovelyhq.com>
~
~ This program is free software: you can redistribute it and/or modify
~ it under the terms of the GNU General Public License as published by
~ the Free Software Foundation, either version 3 of the License, or
~ at your option) any later version.
~
~ This program is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
~ GNU General Public License for more details.
~
~ You should have received a copy of the GNU General Public License
~ along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<vector android:autoMirrored="true" 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="#FFFFF" android:fillType="nonZero"
android:pathData="M12.729,5C11.044,5 9.833,6.38 9.833,7.702C9.833,9.054 9.93,10.019 10.605,11.08C10.822,11.36 11.074,11.418 11.281,11.659C11.411,12.142 11.513,12.625 11.378,13.107C10.957,13.255 10.557,13.428 10.152,13.59C9.66,13.326 9.09,13.107 8.598,12.914C8.53,12.644 8.579,12.444 8.646,12.19C8.762,12.07 8.868,12.016 8.994,11.901C9.351,11.466 9.37,10.733 9.37,10.212C9.37,9.44 8.675,8.861 7.922,8.861C7.082,8.861 6.474,9.555 6.474,10.212L6.455,10.212C6.455,10.887 6.503,11.37 6.841,11.901C6.938,12.045 7.075,12.07 7.179,12.19C7.244,12.431 7.296,12.673 7.227,12.914C6.61,13.129 6.027,13.397 5.49,13.686C5.085,13.976 5.265,13.862 5.007,14.796C4.888,15.279 6.262,15.501 7.247,15.578C7.198,15.843 7.131,16.196 6.938,16.871C6.629,18.078 11.139,18.512 12.729,18.512C15.074,18.512 18.822,18.072 18.501,16.871C17.999,14.999 18.3,15.221 17.555,14.651C16.503,14.02 15.188,13.525 14.08,13.107C13.935,12.57 14.041,12.171 14.177,11.659C14.403,11.418 14.659,11.312 14.872,11.08C15.537,10.227 15.624,8.741 15.624,7.702C15.624,6.172 14.244,5 12.729,5L12.729,5Z"
android:strokeColor="#00000000" android:strokeWidth="1"/>
</vector>

View File

@ -0,0 +1,26 @@
<!--
~ Nextcloud Talk application
~
~ @author Mario Danic
~ Copyright (C) 2017-2018 Mario Danic <mario@lovelyhq.com>
~
~ This program is free software: you can redistribute it and/or modify
~ it under the terms of the GNU General Public License as published by
~ the Free Software Foundation, either version 3 of the License, or
~ at your option) any later version.
~
~ This program is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
~ GNU General Public License for more details.
~
~ You should have received a copy of the GNU General Public License
~ along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<vector android:autoMirrored="true" android:height="24dp"
android:viewportHeight="16.0" android:viewportWidth="16.0"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FFFFFFFF"
android:pathData="m9.236,2.166 l-3.182,3.184c-0.707,0.707 -1.038,1.618 -0.988,2.457 0.05,0.839 0.433,1.584 0.988,2.139l1.412,-1.416c-0.567,-0.567 -0.544,-1.219 0.002,-1.766l3.181,-3.182c0.525,-0.525 1.251,-0.523 1.772,-0.002 0.482,0.556 0.527,1.238 -0.004,1.77l-0.82,0.82c0.555,0.785 0.645,1.366 0.593,2.234l1.641,-1.641c1.237,-1.237 1.237,-3.365 0,-4.602 -1.236,-1.236 -3.342,-1.211 -4.596,0.004zM9.943,6.051 L8.529,7.469c0,0 0.003,0 0.004,0 0.55,0.55 0.507,1.258 -0.004,1.77l-3.182,3.182c-0.696,0.592 -1.298,0.471 -1.77,0 -0.626,-0.626 -0.5,-1.268 0,-1.768l0.85,-0.847c-0.556,-0.784 -0.648,-1.365 -0.598,-2.232l-1.666,1.666c-1.239,1.239 -1.236,3.36 0,4.596 1.235,1.235 3.362,1.236 4.598,0l3.182,-3.182c0.709,-0.708 1.04,-1.618 0.991,-2.459 -0.048,-0.84 -0.432,-1.586 -0.989,-2.141z"/>
</vector>

View File

@ -39,7 +39,7 @@
android:layout_marginEnd="8dp"
android:layout_marginStart="@dimen/activity_horizontal_margin"
android:contentDescription="@null"
android:src="@drawable/ic_group_black_24px"
android:src="@drawable/ic_public_black_24px"
android:tint="@color/colorPrimary"/>
<TextView