Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
AloqaIM-Android
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
AloqaIM-Android
Commits
d31d2921
Commit
d31d2921
authored
Sep 26, 2017
by
Filipe de Lima Brito
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update PushNotificationHandler.java
parent
af841018
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
44 additions
and
10 deletions
+44
-10
PushNotificationHandler.java
...ava/chat/rocket/android/push/PushNotificationHandler.java
+44
-10
No files found.
app/src/main/java/chat/rocket/android/push/PushNotificationHandler.java
View file @
d31d2921
...
...
@@ -39,6 +39,7 @@ import java.util.Random;
import
chat.rocket.android.activity.MainActivity
;
import
chat.rocket.android.helper.ServerPolicyHelper
;
import
chat.rocket.android.service.ConnectivityManager
;
import
chat.rocket.android.widget.helper.AvatarHelper
;
import
chat.rocket.core.models.ServerInfo
;
public
class
PushNotificationHandler
implements
PushConstants
{
...
...
@@ -497,7 +498,7 @@ public class PushNotificationHandler implements PushConstants {
setNotification
(
notId
,
""
);
NotificationCompat
.
BigPictureStyle
bigPicture
=
new
NotificationCompat
.
BigPictureStyle
();
bigPicture
.
bigPicture
(
getBitmapFromURL
(
extras
.
getString
(
PICTURE
)));
bigPicture
.
bigPicture
(
getBitmapFromURL
(
extras
.
getString
(
PICTURE
)
,
null
,
null
));
bigPicture
.
setBigContentTitle
(
fromHtml
(
extras
.
getString
(
TITLE
)));
bigPicture
.
setSummaryText
(
fromHtml
(
extras
.
getString
(
SUMMARY_TEXT
)));
...
...
@@ -566,7 +567,7 @@ public class PushNotificationHandler implements PushConstants {
setNotification
(
notId
,
""
);
Notification
.
BigPictureStyle
bigPicture
=
new
Notification
.
BigPictureStyle
();
bigPicture
.
bigPicture
(
getBitmapFromURL
(
extras
.
getString
(
PICTURE
)));
bigPicture
.
bigPicture
(
getBitmapFromURL
(
extras
.
getString
(
PICTURE
)
,
null
,
null
));
bigPicture
.
setBigContentTitle
(
fromHtml
(
extras
.
getString
(
TITLE
)));
bigPicture
.
setSummaryText
(
fromHtml
(
extras
.
getString
(
SUMMARY_TEXT
)));
...
...
@@ -726,13 +727,22 @@ public class PushNotificationHandler implements PushConstants {
private
void
setNotificationLargeIcon
(
Context
context
,
Bundle
extras
,
String
packageName
,
Resources
resources
,
NotificationCompat
.
Builder
builder
)
{
String
gcmLargeIcon
=
extras
.
getString
(
IMAGE
);
// from gcm
String
hostname
=
getHostname
(
extras
);
String
username
=
getSenderUsername
(
extras
);
String
gcmLargeIcon
;
if
(
username
!=
null
&&
!
username
.
isEmpty
())
{
gcmLargeIcon
=
"https://"
+
hostname
+
"/avatar/"
+
username
;
}
else
{
gcmLargeIcon
=
extras
.
getString
(
IMAGE
);
// from gcm
}
if
(
gcmLargeIcon
==
null
||
""
.
equals
(
gcmLargeIcon
))
{
return
;
}
if
(
gcmLargeIcon
.
startsWith
(
"http://"
)
||
gcmLargeIcon
.
startsWith
(
"https://"
))
{
builder
.
setLargeIcon
(
getBitmapFromURL
(
gcmLargeIcon
));
builder
.
setLargeIcon
(
getBitmapFromURL
(
gcmLargeIcon
,
username
,
context
));
Log
.
d
(
LOG_TAG
,
"using remote large-icon from gcm"
);
}
else
{
AssetManager
assetManager
=
context
.
getAssets
();
...
...
@@ -757,13 +767,22 @@ public class PushNotificationHandler implements PushConstants {
private
void
setNotificationLargeIcon
(
Context
context
,
Bundle
extras
,
String
packageName
,
Resources
resources
,
Notification
.
Builder
builder
)
{
String
gcmLargeIcon
=
extras
.
getString
(
IMAGE
);
// from gcm
String
hostname
=
getHostname
(
extras
);
String
username
=
getSenderUsername
(
extras
);
String
gcmLargeIcon
;
if
(
username
!=
null
&&
!
username
.
isEmpty
())
{
gcmLargeIcon
=
"https://"
+
hostname
+
"/avatar/"
+
username
;
}
else
{
gcmLargeIcon
=
extras
.
getString
(
IMAGE
);
// from gcm
}
if
(
gcmLargeIcon
==
null
||
""
.
equals
(
gcmLargeIcon
))
{
return
;
}
if
(
gcmLargeIcon
.
startsWith
(
"http://"
)
||
gcmLargeIcon
.
startsWith
(
"https://"
))
{
builder
.
setLargeIcon
(
getBitmapFromURL
(
gcmLargeIcon
));
builder
.
setLargeIcon
(
getBitmapFromURL
(
gcmLargeIcon
,
username
,
context
));
Log
.
d
(
LOG_TAG
,
"using remote large-icon from gcm"
);
}
else
{
AssetManager
assetManager
=
context
.
getAssets
();
...
...
@@ -854,17 +873,23 @@ public class PushNotificationHandler implements PushConstants {
intent
.
putExtra
(
NOT_ID
,
notId
);
}
public
Bitmap
getBitmapFromURL
(
String
strURL
)
{
public
Bitmap
getBitmapFromURL
(
String
strURL
,
String
username
,
Context
context
)
{
try
{
URL
url
=
new
URL
(
strURL
);
HttpURLConnection
connection
=
(
HttpURLConnection
)
url
.
openConnection
();
connection
.
setDoInput
(
true
);
connection
.
connect
();
InputStream
input
=
connection
.
getInputStream
();
return
BitmapFactory
.
decodeStream
(
input
);
Bitmap
bitmap
=
BitmapFactory
.
decodeStream
(
input
);
if
(
bitmap
==
null
&&
username
!=
null
&&
context
!=
null
)
{
return
AvatarHelper
.
INSTANCE
.
getTextBitmap
(
username
,
context
);
}
return
bitmap
;
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
return
null
;
e
.
printStackTrace
();
return
null
;
}
}
...
...
@@ -937,6 +962,15 @@ public class PushNotificationHandler implements PushConstants {
}
}
private
String
getSenderUsername
(
Bundle
extras
)
{
try
{
JSONObject
jsonObject
=
new
JSONObject
(
extras
.
getString
(
"ejson"
,
"[]"
));
return
jsonObject
.
getJSONObject
(
"sender"
).
optString
(
"username"
);
}
catch
(
JSONException
e
)
{
return
null
;
}
}
private
boolean
isValidHostname
(
Context
context
,
String
hostname
)
{
final
List
<
ServerInfo
>
serverInfoList
=
ConnectivityManager
.
getInstance
(
context
.
getApplicationContext
()).
getServerList
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment