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
901b6289
Commit
901b6289
authored
Dec 11, 2016
by
Yusuke Iwaki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
modify notification to show user avatar.
parent
54da7fb2
Changes
24
Show whitespace changes
Inline
Side-by-side
Showing
24 changed files
with
168 additions
and
64 deletions
+168
-64
Avatar.java
app/src/main/java/chat/rocket/android/helper/Avatar.java
+64
-0
ViewDataCache.java
...c/main/java/chat/rocket/android/helper/ViewDataCache.java
+0
-1
StreamNotifyUserNotifier.java
...rocket/android/notification/StreamNotifyUserNotifier.java
+36
-5
RocketChatWebSocketThread.java
...hat/rocket/android/service/RocketChatWebSocketThread.java
+6
-2
AbstractDDPDocEventSubscriber.java
...et/android/service/ddp/AbstractDDPDocEventSubscriber.java
+4
-2
AbstractBaseSubscriber.java
...cket/android/service/ddp/base/AbstractBaseSubscriber.java
+2
-2
ActiveUsersSubscriber.java
...ocket/android/service/ddp/base/ActiveUsersSubscriber.java
+2
-2
LoginServiceConfigurationSubscriber.java
...service/ddp/base/LoginServiceConfigurationSubscriber.java
+3
-3
UserDataSubscriber.java
...t/rocket/android/service/ddp/base/UserDataSubscriber.java
+2
-2
AbstractStreamNotifyEventSubscriber.java
...rvice/ddp/stream/AbstractStreamNotifyEventSubscriber.java
+3
-3
AbstractStreamNotifyUserEventSubscriber.java
...e/ddp/stream/AbstractStreamNotifyUserEventSubscriber.java
+3
-3
StreamNotifyUserNotification.java
...roid/service/ddp/stream/StreamNotifyUserNotification.java
+3
-3
StreamNotifyUserSubscriptionsChanged.java
...vice/ddp/stream/StreamNotifyUserSubscriptionsChanged.java
+3
-3
StreamRoomMessage.java
.../rocket/android/service/ddp/stream/StreamRoomMessage.java
+3
-3
StreamRoomMessageManager.java
...et/android/service/internal/StreamRoomMessageManager.java
+5
-3
AbstractModelObserver.java
...ocket/android/service/observer/AbstractModelObserver.java
+4
-2
CurrentUserObserver.java
.../rocket/android/service/observer/CurrentUserObserver.java
+5
-5
GetUsersOfRoomsProcedureObserver.java
...id/service/observer/GetUsersOfRoomsProcedureObserver.java
+3
-3
LoadMessageProcedureObserver.java
...ndroid/service/observer/LoadMessageProcedureObserver.java
+3
-3
MethodCallObserver.java
...t/rocket/android/service/observer/MethodCallObserver.java
+3
-2
NewMessageObserver.java
...t/rocket/android/service/observer/NewMessageObserver.java
+3
-3
SessionObserver.java
...chat/rocket/android/service/observer/SessionObserver.java
+4
-3
TokenLoginObserver.java
...t/rocket/android/service/observer/TokenLoginObserver.java
+3
-2
dimens.xml
app/src/main/res/values/dimens.xml
+1
-4
No files found.
app/src/main/java/chat/rocket/android/helper/Avatar.java
View file @
901b6289
package
chat
.
rocket
.
android
.
helper
;
package
chat
.
rocket
.
android
.
helper
;
import
android.content.Context
;
import
android.content.Context
;
import
android.graphics.Bitmap
;
import
android.graphics.Canvas
;
import
android.graphics.Typeface
;
import
android.graphics.Typeface
;
import
android.graphics.drawable.BitmapDrawable
;
import
android.graphics.drawable.Drawable
;
import
android.graphics.drawable.Drawable
;
import
android.os.Handler
;
import
android.os.Looper
;
import
android.widget.ImageView
;
import
android.widget.ImageView
;
import
bolts.Task
;
import
bolts.TaskCompletionSource
;
import
com.amulyakhare.textdrawable.TextDrawable
;
import
com.amulyakhare.textdrawable.TextDrawable
;
import
com.squareup.picasso.Picasso
;
import
com.squareup.picasso.Picasso
;
import
com.squareup.picasso.Target
;
import
java.io.UnsupportedEncodingException
;
import
java.io.UnsupportedEncodingException
;
import
java.net.URLEncoder
;
import
java.net.URLEncoder
;
import
timber.log.Timber
;
import
timber.log.Timber
;
import
static
android
.
R
.
attr
.
bitmap
;
/**
/**
* Helper for rendering user avatar image.
* Helper for rendering user avatar image.
*/
*/
...
@@ -85,4 +95,58 @@ public class Avatar {
...
@@ -85,4 +95,58 @@ public class Avatar {
.
endConfig
()
.
endConfig
()
.
buildRoundRect
(
getInitialsForUser
(
username
),
getColorForUser
(
username
),
round
);
.
buildRoundRect
(
getInitialsForUser
(
username
),
getColorForUser
(
username
),
round
);
}
}
public
Task
<
Bitmap
>
getBitmap
(
Context
context
,
int
size
)
{
TaskCompletionSource
<
Bitmap
>
task
=
new
TaskCompletionSource
<>();
// Picasso can be triggered only on Main Thread.
if
(
Looper
.
myLooper
()
!=
Looper
.
getMainLooper
())
{
new
Handler
(
Looper
.
getMainLooper
()).
post
(()
->
{
getBitmap
(
context
,
size
).
continueWith
(
_task
->
{
if
(
_task
.
isFaulted
())
{
task
.
setError
(
_task
.
getError
());
}
else
{
task
.
setResult
(
_task
.
getResult
());
}
return
null
;
});
});
return
task
.
getTask
();
}
Picasso
.
with
(
context
)
.
load
(
getImageUrl
())
.
error
(
getTextDrawable
(
context
))
.
into
(
new
Target
()
{
@Override
public
void
onBitmapLoaded
(
Bitmap
bitmap
,
Picasso
.
LoadedFrom
from
)
{
if
(
bitmap
!=
null
)
{
task
.
trySetResult
(
bitmap
);
}
}
@Override
public
void
onBitmapFailed
(
Drawable
errorDrawable
)
{
task
.
trySetResult
(
drawableToBitmap
(
errorDrawable
,
size
));
}
@Override
public
void
onPrepareLoad
(
Drawable
placeHolderDrawable
)
{
}
});
return
task
.
getTask
();
}
private
static
Bitmap
drawableToBitmap
(
Drawable
drawable
,
int
size
)
{
if
(
drawable
instanceof
BitmapDrawable
)
{
BitmapDrawable
bitmapDrawable
=
(
BitmapDrawable
)
drawable
;
if
(
bitmapDrawable
.
getBitmap
()
!=
null
)
{
return
bitmapDrawable
.
getBitmap
();
}
}
Bitmap
bitmap
=
Bitmap
.
createBitmap
(
size
,
size
,
Bitmap
.
Config
.
ARGB_8888
);
Canvas
canvas
=
new
Canvas
(
bitmap
);
drawable
.
setBounds
(
0
,
0
,
canvas
.
getWidth
(),
canvas
.
getHeight
());
drawable
.
draw
(
canvas
);
return
bitmap
;
}
}
}
app/src/main/java/chat/rocket/android/helper/ViewDataCache.java
View file @
901b6289
...
@@ -11,7 +11,6 @@ public class ViewDataCache {
...
@@ -11,7 +11,6 @@ public class ViewDataCache {
/**
/**
* stores str if not stored. returns true if already stored.
* stores str if not stored. returns true if already stored.
*/
*/
@DebugLog
public
static
boolean
isStored
(
String
str
,
View
view
)
{
public
static
boolean
isStored
(
String
str
,
View
view
)
{
if
(
view
.
getTag
()
!=
null
&&
view
.
getTag
()
instanceof
String
if
(
view
.
getTag
()
!=
null
&&
view
.
getTag
()
instanceof
String
&&
((
String
)
view
.
getTag
()).
equals
(
str
))
{
&&
((
String
)
view
.
getTag
()).
equals
(
str
))
{
...
...
app/src/main/java/chat/rocket/android/notification/StreamNotifyUserNotifier.java
View file @
901b6289
...
@@ -2,9 +2,13 @@ package chat.rocket.android.notification;
...
@@ -2,9 +2,13 @@ package chat.rocket.android.notification;
import
android.app.Notification
;
import
android.app.Notification
;
import
android.content.Context
;
import
android.content.Context
;
import
android.graphics.Bitmap
;
import
android.support.v4.app.NotificationCompat
;
import
android.support.v4.app.NotificationCompat
;
import
android.support.v4.app.NotificationManagerCompat
;
import
android.support.v4.app.NotificationManagerCompat
;
import
android.support.v4.content.ContextCompat
;
import
bolts.Task
;
import
chat.rocket.android.R
;
import
chat.rocket.android.R
;
import
chat.rocket.android.helper.Avatar
;
import
org.json.JSONObject
;
import
org.json.JSONObject
;
/**
/**
...
@@ -12,12 +16,15 @@ import org.json.JSONObject;
...
@@ -12,12 +16,15 @@ import org.json.JSONObject;
*/
*/
public
class
StreamNotifyUserNotifier
implements
Notifier
{
public
class
StreamNotifyUserNotifier
implements
Notifier
{
private
final
Context
context
;
private
final
Context
context
;
private
final
String
hostname
;
private
final
String
title
;
private
final
String
title
;
private
final
String
text
;
private
final
String
text
;
private
final
JSONObject
payload
;
private
final
JSONObject
payload
;
public
StreamNotifyUserNotifier
(
Context
context
,
String
title
,
String
text
,
JSONObject
payload
)
{
public
StreamNotifyUserNotifier
(
Context
context
,
String
hostname
,
String
title
,
String
text
,
JSONObject
payload
)
{
this
.
context
=
context
;
this
.
context
=
context
;
this
.
hostname
=
hostname
;
this
.
title
=
title
;
this
.
title
=
title
;
this
.
text
=
text
;
this
.
text
=
text
;
this
.
payload
=
payload
;
this
.
payload
=
payload
;
...
@@ -28,8 +35,11 @@ public class StreamNotifyUserNotifier implements Notifier {
...
@@ -28,8 +35,11 @@ public class StreamNotifyUserNotifier implements Notifier {
return
;
return
;
}
}
generateNotificationAsync
().
onSuccess
(
task
->
{
NotificationManagerCompat
.
from
(
context
)
NotificationManagerCompat
.
from
(
context
)
.
notify
(
generateNotificationId
(),
generateNotification
());
.
notify
(
generateNotificationId
(),
task
.
getResult
());
return
null
;
});
}
}
private
boolean
shouldNotify
()
{
private
boolean
shouldNotify
()
{
...
@@ -42,12 +52,34 @@ public class StreamNotifyUserNotifier implements Notifier {
...
@@ -42,12 +52,34 @@ public class StreamNotifyUserNotifier implements Notifier {
return
(
int
)
(
System
.
currentTimeMillis
()
%
Integer
.
MAX_VALUE
);
return
(
int
)
(
System
.
currentTimeMillis
()
%
Integer
.
MAX_VALUE
);
}
}
private
Notification
generateNotification
()
{
private
Task
<
Notification
>
generateNotificationAsync
()
{
int
size
=
context
.
getResources
().
getDimensionPixelSize
(
R
.
dimen
.
notification_avatar_size
);
return
getUsername
()
.
onSuccessTask
(
task
->
new
Avatar
(
hostname
,
task
.
getResult
()).
getBitmap
(
context
,
size
))
.
continueWithTask
(
task
->
{
Bitmap
icon
=
task
.
isFaulted
()
?
null
:
task
.
getResult
();
return
Task
.
forResult
(
generateNotification
(
icon
));
});
}
private
Task
<
String
>
getUsername
()
{
try
{
return
Task
.
forResult
(
payload
.
getJSONObject
(
"sender"
).
getString
(
"username"
));
}
catch
(
Exception
exception
)
{
return
Task
.
forError
(
exception
);
}
}
private
Notification
generateNotification
(
Bitmap
largeIcon
)
{
NotificationCompat
.
Builder
builder
=
new
NotificationCompat
.
Builder
(
context
)
NotificationCompat
.
Builder
builder
=
new
NotificationCompat
.
Builder
(
context
)
.
setContentTitle
(
title
)
.
setContentTitle
(
title
)
.
setContentText
(
text
)
.
setContentText
(
text
)
.
setAutoCancel
(
true
)
.
setAutoCancel
(
true
)
.
setColor
(
ContextCompat
.
getColor
(
context
,
R
.
color
.
colorPrimary
))
.
setSmallIcon
(
R
.
drawable
.
rocket_chat_notification_24dp
);
.
setSmallIcon
(
R
.
drawable
.
rocket_chat_notification_24dp
);
if
(
largeIcon
!=
null
)
{
builder
.
setLargeIcon
(
largeIcon
);
}
if
(
text
.
length
()
>
20
)
{
if
(
text
.
length
()
>
20
)
{
return
new
NotificationCompat
.
BigTextStyle
(
builder
)
return
new
NotificationCompat
.
BigTextStyle
(
builder
)
.
bigText
(
text
)
.
bigText
(
text
)
...
@@ -56,5 +88,4 @@ public class StreamNotifyUserNotifier implements Notifier {
...
@@ -56,5 +88,4 @@ public class StreamNotifyUserNotifier implements Notifier {
return
builder
.
build
();
return
builder
.
build
();
}
}
}
}
}
}
app/src/main/java/chat/rocket/android/service/RocketChatWebSocketThread.java
View file @
901b6289
...
@@ -209,11 +209,15 @@ public class RocketChatWebSocketThread extends HandlerThread {
...
@@ -209,11 +209,15 @@ public class RocketChatWebSocketThread extends HandlerThread {
}
}
listenersRegistered
=
true
;
listenersRegistered
=
true
;
final
ServerConfig
config
=
defaultRealm
.
executeTransactionForRead
(
realm
->
realm
.
where
(
ServerConfig
.
class
).
equalTo
(
"serverConfigId"
,
serverConfigId
).
findFirst
());
final
String
hostname
=
config
.
getHostname
();
for
(
Class
clazz
:
REGISTERABLE_CLASSES
)
{
for
(
Class
clazz
:
REGISTERABLE_CLASSES
)
{
try
{
try
{
Constructor
ctor
=
clazz
.
getConstructor
(
Context
.
class
,
RealmHelper
.
class
,
Constructor
ctor
=
clazz
.
getConstructor
(
Context
.
class
,
String
.
class
,
RealmHelper
.
class
,
DDPClientWraper
.
class
);
DDPClientWraper
.
class
);
Object
obj
=
ctor
.
newInstance
(
appContext
,
serverConfigRealm
,
ddpClient
);
Object
obj
=
ctor
.
newInstance
(
appContext
,
hostname
,
serverConfigRealm
,
ddpClient
);
if
(
obj
instanceof
Registerable
)
{
if
(
obj
instanceof
Registerable
)
{
Registerable
registerable
=
(
Registerable
)
obj
;
Registerable
registerable
=
(
Registerable
)
obj
;
...
...
app/src/main/java/chat/rocket/android/service/ddp/AbstractDDPDocEventSubscriber.java
View file @
901b6289
...
@@ -18,14 +18,16 @@ import timber.log.Timber;
...
@@ -18,14 +18,16 @@ import timber.log.Timber;
public
abstract
class
AbstractDDPDocEventSubscriber
implements
Registerable
{
public
abstract
class
AbstractDDPDocEventSubscriber
implements
Registerable
{
protected
final
Context
context
;
protected
final
Context
context
;
protected
final
String
hostname
;
protected
final
RealmHelper
realmHelper
;
protected
final
RealmHelper
realmHelper
;
protected
final
DDPClientWraper
ddpClient
;
protected
final
DDPClientWraper
ddpClient
;
private
String
subscriptionId
;
private
String
subscriptionId
;
private
Subscription
rxSubscription
;
private
Subscription
rxSubscription
;
protected
AbstractDDPDocEventSubscriber
(
Context
context
,
RealmHelper
realmHelper
,
protected
AbstractDDPDocEventSubscriber
(
Context
context
,
String
hostname
,
DDPClientWraper
ddpClient
)
{
RealmHelper
realmHelper
,
DDPClientWraper
ddpClient
)
{
this
.
context
=
context
;
this
.
context
=
context
;
this
.
hostname
=
hostname
;
this
.
realmHelper
=
realmHelper
;
this
.
realmHelper
=
realmHelper
;
this
.
ddpClient
=
ddpClient
;
this
.
ddpClient
=
ddpClient
;
}
}
...
...
app/src/main/java/chat/rocket/android/service/ddp/base/AbstractBaseSubscriber.java
View file @
901b6289
...
@@ -7,9 +7,9 @@ import chat.rocket.android.service.ddp.AbstractDDPDocEventSubscriber;
...
@@ -7,9 +7,9 @@ import chat.rocket.android.service.ddp.AbstractDDPDocEventSubscriber;
import
org.json.JSONArray
;
import
org.json.JSONArray
;
abstract
class
AbstractBaseSubscriber
extends
AbstractDDPDocEventSubscriber
{
abstract
class
AbstractBaseSubscriber
extends
AbstractDDPDocEventSubscriber
{
protected
AbstractBaseSubscriber
(
Context
context
,
RealmHelper
realmHelper
,
protected
AbstractBaseSubscriber
(
Context
context
,
String
hostname
,
RealmHelper
realmHelper
,
DDPClientWraper
ddpClient
)
{
DDPClientWraper
ddpClient
)
{
super
(
context
,
realmHelper
,
ddpClient
);
super
(
context
,
hostname
,
realmHelper
,
ddpClient
);
}
}
@Override
protected
final
JSONArray
getSubscriptionParams
()
{
@Override
protected
final
JSONArray
getSubscriptionParams
()
{
...
...
app/src/main/java/chat/rocket/android/service/ddp/base/ActiveUsersSubscriber.java
View file @
901b6289
...
@@ -10,9 +10,9 @@ import io.realm.RealmObject;
...
@@ -10,9 +10,9 @@ import io.realm.RealmObject;
* "activeUsers" subscriber.
* "activeUsers" subscriber.
*/
*/
public
class
ActiveUsersSubscriber
extends
AbstractBaseSubscriber
{
public
class
ActiveUsersSubscriber
extends
AbstractBaseSubscriber
{
public
ActiveUsersSubscriber
(
Context
context
,
RealmHelper
realmHelper
,
public
ActiveUsersSubscriber
(
Context
context
,
String
hostname
,
RealmHelper
realmHelper
,
DDPClientWraper
ddpClient
)
{
DDPClientWraper
ddpClient
)
{
super
(
context
,
realmHelper
,
ddpClient
);
super
(
context
,
hostname
,
realmHelper
,
ddpClient
);
}
}
@Override
protected
String
getSubscriptionName
()
{
@Override
protected
String
getSubscriptionName
()
{
...
...
app/src/main/java/chat/rocket/android/service/ddp/base/LoginServiceConfigurationSubscriber.java
View file @
901b6289
...
@@ -10,9 +10,9 @@ import io.realm.RealmObject;
...
@@ -10,9 +10,9 @@ import io.realm.RealmObject;
* meteor.loginServiceConfiguration subscriber
* meteor.loginServiceConfiguration subscriber
*/
*/
public
class
LoginServiceConfigurationSubscriber
extends
AbstractBaseSubscriber
{
public
class
LoginServiceConfigurationSubscriber
extends
AbstractBaseSubscriber
{
public
LoginServiceConfigurationSubscriber
(
Context
context
,
RealmHelper
realmHelper
,
public
LoginServiceConfigurationSubscriber
(
Context
context
,
String
hostname
,
DDPClientWraper
ddpClient
)
{
RealmHelper
realmHelper
,
DDPClientWraper
ddpClient
)
{
super
(
context
,
realmHelper
,
ddpClient
);
super
(
context
,
hostname
,
realmHelper
,
ddpClient
);
}
}
@Override
protected
String
getSubscriptionName
()
{
@Override
protected
String
getSubscriptionName
()
{
...
...
app/src/main/java/chat/rocket/android/service/ddp/base/UserDataSubscriber.java
View file @
901b6289
...
@@ -10,9 +10,9 @@ import io.realm.RealmObject;
...
@@ -10,9 +10,9 @@ import io.realm.RealmObject;
* "userData" subscriber.
* "userData" subscriber.
*/
*/
public
class
UserDataSubscriber
extends
AbstractBaseSubscriber
{
public
class
UserDataSubscriber
extends
AbstractBaseSubscriber
{
public
UserDataSubscriber
(
Context
context
,
RealmHelper
realmHelper
,
public
UserDataSubscriber
(
Context
context
,
String
hostname
,
RealmHelper
realmHelper
,
DDPClientWraper
ddpClient
)
{
DDPClientWraper
ddpClient
)
{
super
(
context
,
realmHelper
,
ddpClient
);
super
(
context
,
hostname
,
realmHelper
,
ddpClient
);
}
}
@Override
protected
String
getSubscriptionName
()
{
@Override
protected
String
getSubscriptionName
()
{
...
...
app/src/main/java/chat/rocket/android/service/ddp/stream/AbstractStreamNotifyEventSubscriber.java
View file @
901b6289
...
@@ -12,9 +12,9 @@ import org.json.JSONObject;
...
@@ -12,9 +12,9 @@ import org.json.JSONObject;
import
timber.log.Timber
;
import
timber.log.Timber
;
abstract
class
AbstractStreamNotifyEventSubscriber
extends
AbstractDDPDocEventSubscriber
{
abstract
class
AbstractStreamNotifyEventSubscriber
extends
AbstractDDPDocEventSubscriber
{
protected
AbstractStreamNotifyEventSubscriber
(
Context
context
,
RealmHelper
realmHelper
,
protected
AbstractStreamNotifyEventSubscriber
(
Context
context
,
String
hostname
,
DDPClientWraper
ddpClient
)
{
RealmHelper
realmHelper
,
DDPClientWraper
ddpClient
)
{
super
(
context
,
realmHelper
,
ddpClient
);
super
(
context
,
hostname
,
realmHelper
,
ddpClient
);
}
}
@Override
protected
final
boolean
shouldTruncateTableOnInitialize
()
{
@Override
protected
final
boolean
shouldTruncateTableOnInitialize
()
{
...
...
app/src/main/java/chat/rocket/android/service/ddp/stream/AbstractStreamNotifyUserEventSubscriber.java
View file @
901b6289
...
@@ -6,9 +6,9 @@ import chat.rocket.android.realm_helper.RealmHelper;
...
@@ -6,9 +6,9 @@ import chat.rocket.android.realm_helper.RealmHelper;
abstract
class
AbstractStreamNotifyUserEventSubscriber
extends
AbstractStreamNotifyEventSubscriber
{
abstract
class
AbstractStreamNotifyUserEventSubscriber
extends
AbstractStreamNotifyEventSubscriber
{
protected
final
String
userId
;
protected
final
String
userId
;
protected
AbstractStreamNotifyUserEventSubscriber
(
Context
context
,
RealmHelper
realmHelper
,
protected
AbstractStreamNotifyUserEventSubscriber
(
Context
context
,
String
hostname
,
DDPClientWraper
ddpClient
,
String
userId
)
{
RealmHelper
realmHelper
,
DDPClientWraper
ddpClient
,
String
userId
)
{
super
(
context
,
realmHelper
,
ddpClient
);
super
(
context
,
hostname
,
realmHelper
,
ddpClient
);
this
.
userId
=
userId
;
this
.
userId
=
userId
;
}
}
...
...
app/src/main/java/chat/rocket/android/service/ddp/stream/StreamNotifyUserNotification.java
View file @
901b6289
...
@@ -11,9 +11,9 @@ import org.json.JSONException;
...
@@ -11,9 +11,9 @@ import org.json.JSONException;
import
org.json.JSONObject
;
import
org.json.JSONObject
;
public
class
StreamNotifyUserNotification
extends
AbstractStreamNotifyUserEventSubscriber
{
public
class
StreamNotifyUserNotification
extends
AbstractStreamNotifyUserEventSubscriber
{
public
StreamNotifyUserNotification
(
Context
context
,
RealmHelper
realmHelper
,
public
StreamNotifyUserNotification
(
Context
context
,
String
hostname
,
RealmHelper
realmHelper
,
DDPClientWraper
ddpClient
,
String
userId
)
{
DDPClientWraper
ddpClient
,
String
userId
)
{
super
(
context
,
realmHelper
,
ddpClient
,
userId
);
super
(
context
,
hostname
,
realmHelper
,
ddpClient
,
userId
);
}
}
@Override
protected
String
getSubscriptionSubParam
()
{
@Override
protected
String
getSubscriptionSubParam
()
{
...
@@ -22,7 +22,7 @@ public class StreamNotifyUserNotification extends AbstractStreamNotifyUserEventS
...
@@ -22,7 +22,7 @@ public class StreamNotifyUserNotification extends AbstractStreamNotifyUserEventS
@Override
protected
void
handleArgs
(
JSONArray
args
)
throws
JSONException
{
@Override
protected
void
handleArgs
(
JSONArray
args
)
throws
JSONException
{
JSONObject
target
=
args
.
getJSONObject
(
args
.
length
()
-
1
);
JSONObject
target
=
args
.
getJSONObject
(
args
.
length
()
-
1
);
Notifier
notifier
=
new
StreamNotifyUserNotifier
(
context
,
Notifier
notifier
=
new
StreamNotifyUserNotifier
(
context
,
hostname
,
target
.
getString
(
"title"
),
target
.
getString
(
"title"
),
target
.
getString
(
"text"
),
target
.
getString
(
"text"
),
target
.
getJSONObject
(
"payload"
));
target
.
getJSONObject
(
"payload"
));
...
...
app/src/main/java/chat/rocket/android/service/ddp/stream/StreamNotifyUserSubscriptionsChanged.java
View file @
901b6289
...
@@ -7,9 +7,9 @@ import chat.rocket.android.realm_helper.RealmHelper;
...
@@ -7,9 +7,9 @@ import chat.rocket.android.realm_helper.RealmHelper;
import
io.realm.RealmObject
;
import
io.realm.RealmObject
;
public
class
StreamNotifyUserSubscriptionsChanged
extends
AbstractStreamNotifyUserEventSubscriber
{
public
class
StreamNotifyUserSubscriptionsChanged
extends
AbstractStreamNotifyUserEventSubscriber
{
public
StreamNotifyUserSubscriptionsChanged
(
Context
context
,
RealmHelper
realmHelper
,
public
StreamNotifyUserSubscriptionsChanged
(
Context
context
,
String
hostname
,
DDPClientWraper
ddpClient
,
String
userId
)
{
RealmHelper
realmHelper
,
DDPClientWraper
ddpClient
,
String
userId
)
{
super
(
context
,
realmHelper
,
ddpClient
,
userId
);
super
(
context
,
hostname
,
realmHelper
,
ddpClient
,
userId
);
}
}
@Override
protected
String
getSubscriptionSubParam
()
{
@Override
protected
String
getSubscriptionSubParam
()
{
...
...
app/src/main/java/chat/rocket/android/service/ddp/stream/StreamRoomMessage.java
View file @
901b6289
...
@@ -14,9 +14,9 @@ import org.json.JSONObject;
...
@@ -14,9 +14,9 @@ import org.json.JSONObject;
public
class
StreamRoomMessage
extends
AbstractStreamNotifyEventSubscriber
{
public
class
StreamRoomMessage
extends
AbstractStreamNotifyEventSubscriber
{
private
String
roomId
;
private
String
roomId
;
public
StreamRoomMessage
(
Context
context
,
RealmHelper
realmHelper
,
DDPClientWraper
ddpClient
,
public
StreamRoomMessage
(
Context
context
,
String
hostname
,
String
roomId
)
{
RealmHelper
realmHelper
,
DDPClientWraper
ddpClient
,
String
roomId
)
{
super
(
context
,
realmHelper
,
ddpClient
);
super
(
context
,
hostname
,
realmHelper
,
ddpClient
);
this
.
roomId
=
roomId
;
this
.
roomId
=
roomId
;
}
}
...
...
app/src/main/java/chat/rocket/android/service/internal/StreamRoomMessageManager.java
View file @
901b6289
...
@@ -15,14 +15,16 @@ public class StreamRoomMessageManager implements Registerable {
...
@@ -15,14 +15,16 @@ public class StreamRoomMessageManager implements Registerable {
private
StreamRoomMessage
streamRoomMessage
;
private
StreamRoomMessage
streamRoomMessage
;
private
final
Context
context
;
private
final
Context
context
;
private
final
String
hostname
;
private
final
RealmHelper
realmHelper
;
private
final
RealmHelper
realmHelper
;
private
final
DDPClientWraper
ddpClient
;
private
final
DDPClientWraper
ddpClient
;
private
final
AbstractRocketChatCacheObserver
cacheObserver
;
private
final
AbstractRocketChatCacheObserver
cacheObserver
;
private
final
Handler
handler
;
private
final
Handler
handler
;
public
StreamRoomMessageManager
(
Context
context
,
RealmHelper
realmHelper
,
public
StreamRoomMessageManager
(
Context
context
,
String
hostname
,
DDPClientWraper
ddpClient
)
{
RealmHelper
realmHelper
,
DDPClientWraper
ddpClient
)
{
this
.
context
=
context
;
this
.
context
=
context
;
this
.
hostname
=
hostname
;
this
.
realmHelper
=
realmHelper
;
this
.
realmHelper
=
realmHelper
;
this
.
ddpClient
=
ddpClient
;
this
.
ddpClient
=
ddpClient
;
...
@@ -37,7 +39,7 @@ public class StreamRoomMessageManager implements Registerable {
...
@@ -37,7 +39,7 @@ public class StreamRoomMessageManager implements Registerable {
private
void
registerStreamNotifyMessage
(
String
roomId
)
{
private
void
registerStreamNotifyMessage
(
String
roomId
)
{
handler
.
post
(()
->
{
handler
.
post
(()
->
{
streamRoomMessage
=
new
StreamRoomMessage
(
context
,
realmHelper
,
ddpClient
,
roomId
);
streamRoomMessage
=
new
StreamRoomMessage
(
context
,
hostname
,
realmHelper
,
ddpClient
,
roomId
);
streamRoomMessage
.
register
();
streamRoomMessage
.
register
();
});
});
}
}
...
...
app/src/main/java/chat/rocket/android/service/observer/AbstractModelObserver.java
View file @
901b6289
...
@@ -11,13 +11,15 @@ abstract class AbstractModelObserver<T extends RealmObject>
...
@@ -11,13 +11,15 @@ abstract class AbstractModelObserver<T extends RealmObject>
implements
Registerable
,
RealmListObserver
.
Query
<
T
>,
RealmListObserver
.
OnUpdateListener
<
T
>
{
implements
Registerable
,
RealmListObserver
.
Query
<
T
>,
RealmListObserver
.
OnUpdateListener
<
T
>
{
protected
final
Context
context
;
protected
final
Context
context
;
protected
final
String
hostname
;
protected
final
RealmHelper
realmHelper
;
protected
final
RealmHelper
realmHelper
;
protected
final
DDPClientWraper
ddpClient
;
protected
final
DDPClientWraper
ddpClient
;
private
final
RealmListObserver
observer
;
private
final
RealmListObserver
observer
;
protected
AbstractModelObserver
(
Context
context
,
RealmHelper
realmHelper
,
protected
AbstractModelObserver
(
Context
context
,
String
hostname
,
DDPClientWraper
ddpClient
)
{
RealmHelper
realmHelper
,
DDPClientWraper
ddpClient
)
{
this
.
context
=
context
;
this
.
context
=
context
;
this
.
hostname
=
hostname
;
this
.
realmHelper
=
realmHelper
;
this
.
realmHelper
=
realmHelper
;
this
.
ddpClient
=
ddpClient
;
this
.
ddpClient
=
ddpClient
;
observer
=
realmHelper
.
createListObserver
(
this
).
setOnUpdateListener
(
this
);
observer
=
realmHelper
.
createListObserver
(
this
).
setOnUpdateListener
(
this
);
...
...
app/src/main/java/chat/rocket/android/service/observer/CurrentUserObserver.java
View file @
901b6289
...
@@ -24,9 +24,9 @@ public class CurrentUserObserver extends AbstractModelObserver<User> {
...
@@ -24,9 +24,9 @@ public class CurrentUserObserver extends AbstractModelObserver<User> {
private
ArrayList
<
Registerable
>
listeners
;
private
ArrayList
<
Registerable
>
listeners
;
public
CurrentUserObserver
(
Context
context
,
RealmHelper
realmHelper
,
public
CurrentUserObserver
(
Context
context
,
String
hostname
,
DDPClientWraper
ddpClient
)
{
RealmHelper
realmHelper
,
DDPClientWraper
ddpClient
)
{
super
(
context
,
realmHelper
,
ddpClient
);
super
(
context
,
hostname
,
realmHelper
,
ddpClient
);
methodCall
=
new
MethodCallHelper
(
realmHelper
,
ddpClient
);
methodCall
=
new
MethodCallHelper
(
realmHelper
,
ddpClient
);
currentUserExists
=
false
;
currentUserExists
=
false
;
}
}
...
@@ -60,14 +60,14 @@ public class CurrentUserObserver extends AbstractModelObserver<User> {
...
@@ -60,14 +60,14 @@ public class CurrentUserObserver extends AbstractModelObserver<User> {
// get and observe Room subscriptions.
// get and observe Room subscriptions.
methodCall
.
getRoomSubscriptions
().
onSuccess
(
task
->
{
methodCall
.
getRoomSubscriptions
().
onSuccess
(
task
->
{
Registerable
listener
=
new
StreamNotifyUserSubscriptionsChanged
(
Registerable
listener
=
new
StreamNotifyUserSubscriptionsChanged
(
context
,
realmHelper
,
ddpClient
,
userId
);
context
,
hostname
,
realmHelper
,
ddpClient
,
userId
);
listener
.
register
();
listener
.
register
();
listeners
.
add
(
listener
);
listeners
.
add
(
listener
);
return
null
;
return
null
;
});
});
Registerable
listener
=
new
StreamNotifyUserNotification
(
Registerable
listener
=
new
StreamNotifyUserNotification
(
context
,
realmHelper
,
ddpClient
,
userId
);
context
,
hostname
,
realmHelper
,
ddpClient
,
userId
);
listener
.
register
();
listener
.
register
();
listeners
.
add
(
listener
);
listeners
.
add
(
listener
);
}
}
...
...
app/src/main/java/chat/rocket/android/service/observer/GetUsersOfRoomsProcedureObserver.java
View file @
901b6289
...
@@ -21,9 +21,9 @@ public class GetUsersOfRoomsProcedureObserver
...
@@ -21,9 +21,9 @@ public class GetUsersOfRoomsProcedureObserver
private
final
MethodCallHelper
methodCall
;
private
final
MethodCallHelper
methodCall
;
public
GetUsersOfRoomsProcedureObserver
(
Context
context
,
RealmHelper
realmHelper
,
public
GetUsersOfRoomsProcedureObserver
(
Context
context
,
String
hostname
,
DDPClientWraper
ddpClient
)
{
RealmHelper
realmHelper
,
DDPClientWraper
ddpClient
)
{
super
(
context
,
realmHelper
,
ddpClient
);
super
(
context
,
hostname
,
realmHelper
,
ddpClient
);
methodCall
=
new
MethodCallHelper
(
realmHelper
,
ddpClient
);
methodCall
=
new
MethodCallHelper
(
realmHelper
,
ddpClient
);
}
}
...
...
app/src/main/java/chat/rocket/android/service/observer/LoadMessageProcedureObserver.java
View file @
901b6289
...
@@ -22,9 +22,9 @@ public class LoadMessageProcedureObserver extends AbstractModelObserver<LoadMess
...
@@ -22,9 +22,9 @@ public class LoadMessageProcedureObserver extends AbstractModelObserver<LoadMess
private
final
MethodCallHelper
methodCall
;
private
final
MethodCallHelper
methodCall
;
public
LoadMessageProcedureObserver
(
Context
context
,
RealmHelper
realmHelper
,
public
LoadMessageProcedureObserver
(
Context
context
,
String
hostname
,
DDPClientWraper
ddpClient
)
{
RealmHelper
realmHelper
,
DDPClientWraper
ddpClient
)
{
super
(
context
,
realmHelper
,
ddpClient
);
super
(
context
,
hostname
,
realmHelper
,
ddpClient
);
methodCall
=
new
MethodCallHelper
(
realmHelper
,
ddpClient
);
methodCall
=
new
MethodCallHelper
(
realmHelper
,
ddpClient
);
}
}
...
...
app/src/main/java/chat/rocket/android/service/observer/MethodCallObserver.java
View file @
901b6289
...
@@ -23,8 +23,9 @@ public class MethodCallObserver extends AbstractModelObserver<MethodCall> {
...
@@ -23,8 +23,9 @@ public class MethodCallObserver extends AbstractModelObserver<MethodCall> {
/**
/**
* constructor.
* constructor.
*/
*/
public
MethodCallObserver
(
Context
context
,
RealmHelper
realmHelper
,
DDPClientWraper
ddpClient
)
{
public
MethodCallObserver
(
Context
context
,
String
hostname
,
super
(
context
,
realmHelper
,
ddpClient
);
RealmHelper
realmHelper
,
DDPClientWraper
ddpClient
)
{
super
(
context
,
hostname
,
realmHelper
,
ddpClient
);
realmHelper
.
executeTransaction
(
realm
->
{
realmHelper
.
executeTransaction
(
realm
->
{
// resume pending operations.
// resume pending operations.
RealmResults
<
MethodCall
>
pendingMethodCalls
=
realm
.
where
(
MethodCall
.
class
)
RealmResults
<
MethodCall
>
pendingMethodCalls
=
realm
.
where
(
MethodCall
.
class
)
...
...
app/src/main/java/chat/rocket/android/service/observer/NewMessageObserver.java
View file @
901b6289
...
@@ -20,9 +20,9 @@ public class NewMessageObserver extends AbstractModelObserver<Message> {
...
@@ -20,9 +20,9 @@ public class NewMessageObserver extends AbstractModelObserver<Message> {
private
final
MethodCallHelper
methodCall
;
private
final
MethodCallHelper
methodCall
;
public
NewMessageObserver
(
Context
context
,
RealmHelper
realmHelper
,
public
NewMessageObserver
(
Context
context
,
String
hostname
,
DDPClientWraper
ddpClient
)
{
RealmHelper
realmHelper
,
DDPClientWraper
ddpClient
)
{
super
(
context
,
realmHelper
,
ddpClient
);
super
(
context
,
hostname
,
realmHelper
,
ddpClient
);
methodCall
=
new
MethodCallHelper
(
realmHelper
,
ddpClient
);
methodCall
=
new
MethodCallHelper
(
realmHelper
,
ddpClient
);
realmHelper
.
executeTransaction
(
realm
->
{
realmHelper
.
executeTransaction
(
realm
->
{
...
...
app/src/main/java/chat/rocket/android/service/observer/SessionObserver.java
View file @
901b6289
...
@@ -25,11 +25,12 @@ public class SessionObserver extends AbstractModelObserver<Session> {
...
@@ -25,11 +25,12 @@ public class SessionObserver extends AbstractModelObserver<Session> {
/**
/**
* constructor.
* constructor.
*/
*/
public
SessionObserver
(
Context
context
,
RealmHelper
realmHelper
,
DDPClientWraper
ddpClient
)
{
public
SessionObserver
(
Context
context
,
String
hostname
,
super
(
context
,
realmHelper
,
ddpClient
);
RealmHelper
realmHelper
,
DDPClientWraper
ddpClient
)
{
super
(
context
,
hostname
,
realmHelper
,
ddpClient
);
count
=
0
;
count
=
0
;
streamNotifyMessage
=
new
StreamRoomMessageManager
(
context
,
realmHelper
,
ddpClient
);
streamNotifyMessage
=
new
StreamRoomMessageManager
(
context
,
hostname
,
realmHelper
,
ddpClient
);
}
}
@Override
public
RealmResults
<
Session
>
queryItems
(
Realm
realm
)
{
@Override
public
RealmResults
<
Session
>
queryItems
(
Realm
realm
)
{
...
...
app/src/main/java/chat/rocket/android/service/observer/TokenLoginObserver.java
View file @
901b6289
...
@@ -14,8 +14,9 @@ public class TokenLoginObserver extends AbstractModelObserver<Session> {
...
@@ -14,8 +14,9 @@ public class TokenLoginObserver extends AbstractModelObserver<Session> {
private
final
MethodCallHelper
methodCall
;
private
final
MethodCallHelper
methodCall
;
public
TokenLoginObserver
(
Context
context
,
RealmHelper
realmHelper
,
DDPClientWraper
ddpClient
)
{
public
TokenLoginObserver
(
Context
context
,
String
hostname
,
super
(
context
,
realmHelper
,
ddpClient
);
RealmHelper
realmHelper
,
DDPClientWraper
ddpClient
)
{
super
(
context
,
hostname
,
realmHelper
,
ddpClient
);
methodCall
=
new
MethodCallHelper
(
realmHelper
,
ddpClient
);
methodCall
=
new
MethodCallHelper
(
realmHelper
,
ddpClient
);
}
}
...
...
app/src/main/res/values/dimens.xml
View file @
901b6289
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<resources>
<resources>
<dimen
name=
"avatar_image_size_normal"
>
24dp
</dimen>
<dimen
name=
"notification_avatar_size"
>
48dp
</dimen>
<dimen
name=
"avatar_image_size_large"
>
48dp
</dimen>
<dimen
name=
"avatar_text_size_normal"
>
11sp
</dimen>
<dimen
name=
"avatar_text_size_large"
>
28sp
</dimen>
</resources>
</resources>
\ No newline at end of file
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