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
d8219843
Unverified
Commit
d8219843
authored
Apr 06, 2018
by
Rafael Kellermann Streit
Committed by
GitHub
Apr 06, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1038 from RocketChat/new/direct-reply
[NEW] Direct Reply from notification
parents
18e1cf9e
3e7984fd
Changes
9
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
316 additions
and
76 deletions
+316
-76
AndroidManifest.xml
app/src/main/AndroidManifest.xml
+9
-0
AppModule.kt
.../main/java/chat/rocket/android/dagger/module/AppModule.kt
+16
-12
ReceiverBuilder.kt
...java/chat/rocket/android/dagger/module/ReceiverBuilder.kt
+5
-0
DirectReplyReceiver.kt
...main/java/chat/rocket/android/push/DirectReplyReceiver.kt
+94
-0
DirectReplyReceiverProvider.kt
...a/chat/rocket/android/push/DirectReplyReceiverProvider.kt
+11
-0
PushManager.kt
app/src/main/java/chat/rocket/android/push/PushManager.kt
+166
-64
strings.xml
app/src/main/res/values-hi-rIN/strings.xml
+5
-0
strings.xml
app/src/main/res/values-pt-rBR/strings.xml
+5
-0
strings.xml
app/src/main/res/values/strings.xml
+5
-0
No files found.
app/src/main/AndroidManifest.xml
View file @
d8219843
...
...
@@ -76,6 +76,15 @@
</intent-filter>
</receiver>
<receiver
android:name=
".push.DirectReplyReceiver"
android:enabled=
"true"
android:exported=
"false"
>
<intent-filter>
<action
android:name=
"chat.rocket.android.ACTION_REPLY"
/>
</intent-filter>
</receiver>
<service
android:name=
".push.FirebaseTokenService"
android:exported=
"false"
>
...
...
app/src/main/java/chat/rocket/android/dagger/module/AppModule.kt
View file @
d8219843
...
...
@@ -17,17 +17,8 @@ import chat.rocket.android.helper.MessageParser
import
chat.rocket.android.infrastructure.LocalRepository
import
chat.rocket.android.infrastructure.SharedPrefsLocalRepository
import
chat.rocket.android.push.GroupedPush
import
chat.rocket.android.server.domain.AccountsRepository
import
chat.rocket.android.server.domain.ChatRoomsRepository
import
chat.rocket.android.server.domain.CurrentServerRepository
import
chat.rocket.android.server.domain.GetCurrentServerInteractor
import
chat.rocket.android.server.domain.GetPermissionsInteractor
import
chat.rocket.android.server.domain.MessagesRepository
import
chat.rocket.android.server.domain.MultiServerTokenRepository
import
chat.rocket.android.server.domain.RoomRepository
import
chat.rocket.android.server.domain.SettingsRepository
import
chat.rocket.android.server.domain.TokenRepository
import
chat.rocket.android.server.domain.UsersRepository
import
chat.rocket.android.push.PushManager
import
chat.rocket.android.server.domain.*
import
chat.rocket.android.server.infraestructure.MemoryChatRoomsRepository
import
chat.rocket.android.server.infraestructure.MemoryMessagesRepository
import
chat.rocket.android.server.infraestructure.MemoryRoomRepository
...
...
@@ -270,9 +261,22 @@ class AppModule {
SharedPreferencesAccountsRepository
(
preferences
,
moshi
)
@Provides
fun
provideNotificationManager
(
context
:
Context
):
NotificationManager
=
context
.
systemService
()
fun
provideNotificationManager
(
context
:
Context
):
NotificationManager
=
context
.
getSystemService
(
Context
.
NOTIFICATION_SERVICE
)
as
NotificationManager
@Provides
@Singleton
fun
provideGroupedPush
()
=
GroupedPush
()
@Provides
@Singleton
fun
providePushManager
(
context
:
Context
,
groupedPushes
:
GroupedPush
,
manager
:
NotificationManager
,
moshi
:
Moshi
,
getAccountInteractor
:
GetAccountInteractor
,
getSettingsInteractor
:
GetSettingsInteractor
):
PushManager
{
return
PushManager
(
groupedPushes
,
manager
,
moshi
,
getAccountInteractor
,
getSettingsInteractor
,
context
)
}
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/dagger/module/ReceiverBuilder.kt
View file @
d8219843
package
chat.rocket.android.dagger.module
import
chat.rocket.android.push.DeleteReceiver
import
chat.rocket.android.push.DirectReplyReceiver
import
chat.rocket.android.push.DirectReplyReceiverProvider
import
chat.rocket.android.push.di.DeleteReceiverProvider
import
dagger.Module
import
dagger.android.ContributesAndroidInjector
...
...
@@ -10,4 +12,7 @@ abstract class ReceiverBuilder {
@ContributesAndroidInjector
(
modules
=
[
DeleteReceiverProvider
::
class
])
abstract
fun
bindDeleteReceiver
():
DeleteReceiver
@ContributesAndroidInjector
(
modules
=
[
DirectReplyReceiverProvider
::
class
])
abstract
fun
bindDirectReplyReceiver
():
DirectReplyReceiver
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/push/DirectReplyReceiver.kt
0 → 100644
View file @
d8219843
package
chat.rocket.android.push
import
android.app.NotificationManager
import
android.content.BroadcastReceiver
import
android.content.Context
import
android.content.Intent
import
android.support.v4.app.NotificationManagerCompat
import
android.support.v4.app.RemoteInput
import
android.widget.Toast
import
chat.rocket.android.R
import
chat.rocket.android.server.infraestructure.ConnectionManagerFactory
import
chat.rocket.common.RocketChatException
import
chat.rocket.core.internal.rest.sendMessage
import
dagger.android.AndroidInjection
import
kotlinx.coroutines.experimental.android.UI
import
kotlinx.coroutines.experimental.launch
import
timber.log.Timber
import
java.util.*
import
javax.inject.Inject
/**
* BroadcastReceiver for direct reply on notifications.
*/
class
DirectReplyReceiver
:
BroadcastReceiver
()
{
@Inject
lateinit
var
factory
:
ConnectionManagerFactory
@Inject
lateinit
var
groupedPushes
:
GroupedPush
@Inject
lateinit
var
pushManager
:
PushManager
@Inject
lateinit
var
manager
:
NotificationManager
override
fun
onReceive
(
context
:
Context
,
intent
:
Intent
)
{
AndroidInjection
.
inject
(
this
,
context
)
if
(
ACTION_REPLY
==
intent
.
action
)
{
val
message
=
intent
.
getParcelableExtra
<
PushMessage
>(
EXTRA_PUSH_MESSAGE
)
message
?.
let
{
launch
(
UI
)
{
val
notificationId
=
it
.
notificationId
.
toInt
()
val
hostname
=
it
.
info
.
host
try
{
sendMessage
(
it
,
extractReplyMessage
(
intent
))
clearNotificationsByHostAndNotificationId
(
hostname
,
notificationId
)
manager
.
cancel
(
notificationId
)
val
feedback
=
context
.
getString
(
R
.
string
.
notif_success_sending
,
it
.
title
)
Toast
.
makeText
(
context
,
feedback
,
Toast
.
LENGTH_SHORT
).
show
()
}
catch
(
ex
:
RocketChatException
)
{
Timber
.
e
(
ex
)
val
feedback
=
context
.
getString
(
R
.
string
.
notif_error_sending
)
Toast
.
makeText
(
context
,
feedback
,
Toast
.
LENGTH_SHORT
).
show
()
clearNotificationsByHostAndNotificationId
(
hostname
,
notificationId
)
pushManager
.
showNotification
(
it
)
}
}
}
}
}
private
suspend
fun
sendMessage
(
message
:
PushMessage
,
replyText
:
CharSequence
?)
{
replyText
?.
let
{
reply
->
val
currentServer
=
message
.
info
.
hostname
val
roomId
=
message
.
info
.
roomId
val
connectionManager
=
factory
.
create
(
currentServer
)
val
client
=
connectionManager
.
client
val
id
=
UUID
.
randomUUID
().
toString
()
client
.
sendMessage
(
id
,
roomId
,
reply
.
toString
())
// Do we need to disconnect here?
}
}
private
fun
extractReplyMessage
(
intent
:
Intent
):
CharSequence
?
{
val
bundle
=
RemoteInput
.
getResultsFromIntent
(
intent
)
if
(
bundle
!=
null
)
{
return
bundle
.
getCharSequence
(
REMOTE_INPUT_REPLY
)
}
return
null
}
/**
* Clear notifications by the host they belong to and its unique id.
*/
private
fun
clearNotificationsByHostAndNotificationId
(
host
:
String
,
notificationId
:
Int
)
{
if
(
groupedPushes
.
hostToPushMessageList
.
isNotEmpty
())
{
val
notifications
=
groupedPushes
.
hostToPushMessageList
[
host
]
notifications
?.
let
{
notifications
.
removeAll
{
it
.
notificationId
.
toInt
()
==
notificationId
}
}
}
}
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/push/DirectReplyReceiverProvider.kt
0 → 100644
View file @
d8219843
package
chat.rocket.android.push
import
chat.rocket.android.dagger.module.AppModule
import
dagger.Module
import
dagger.android.ContributesAndroidInjector
@Module
abstract
class
DirectReplyReceiverProvider
{
@ContributesAndroidInjector
(
modules
=
[
AppModule
::
class
])
abstract
fun
provideDirectReplyReceiver
():
DirectReplyReceiver
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/push/PushManager.kt
View file @
d8219843
This diff is collapsed.
Click to expand it.
app/src/main/res/values-hi-rIN/strings.xml
View file @
d8219843
...
...
@@ -181,4 +181,9 @@
<string
name=
"header_direct_messages"
>
प्रत्यक्ष संदेश
</string>
<string
name=
"header_live_chats"
>
Live Chats
</string>
<string
name=
"header_unknown"
>
अज्ञात
</string>
<!--Notifications-->
<string
name=
"notif_action_reply_hint"
>
जवाब
</string>
<string
name=
"notif_error_sending"
>
उत्तर विफल हुआ है। कृपया फिर से प्रयास करें।
</string>
<string
name=
"notif_success_sending"
>
संदेश भेजा गया %1$s!
</string>
</resources>
\ No newline at end of file
app/src/main/res/values-pt-rBR/strings.xml
View file @
d8219843
...
...
@@ -181,4 +181,9 @@
<string
name=
"header_direct_messages"
>
Mensagens diretas
</string>
<string
name=
"header_live_chats"
>
Live Chats
</string>
<string
name=
"header_unknown"
>
Desconhecido
</string>
<!--Notifications-->
<string
name=
"notif_action_reply_hint"
>
RESPONDER
</string>
<string
name=
"notif_error_sending"
>
Falha ao enviar a mensagem.
</string>
<string
name=
"notif_success_sending"
>
Mensagem enviada para %1$s!
</string>
</resources>
\ No newline at end of file
app/src/main/res/values/strings.xml
View file @
d8219843
...
...
@@ -182,4 +182,9 @@
<string
name=
"header_direct_messages"
>
Direct Messages
</string>
<string
name=
"header_live_chats"
>
Live Chats
</string>
<string
name=
"header_unknown"
>
Unknown
</string>
<!--Notifications-->
<string
name=
"notif_action_reply_hint"
>
REPLY
</string>
<string
name=
"notif_error_sending"
>
Reply has failed. Please try again.
</string>
<string
name=
"notif_success_sending"
>
Message sent to %1$s!
</string>
</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