Commit 3a91f0c8 authored by Leonardo Aramaki's avatar Leonardo Aramaki

Show error Toast when reply fails and show the notification again

parent aa0f574b
......@@ -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
......@@ -275,4 +266,16 @@ class AppModule {
@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
......@@ -4,6 +4,7 @@ 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
......@@ -26,6 +27,8 @@ class DirectReplyReceiver : BroadcastReceiver() {
lateinit var factory: ConnectionManagerFactory
@Inject
lateinit var groupedPushes: GroupedPush
@Inject
lateinit var pushManager: PushManager
override fun onReceive(context: Context, intent: Intent) {
AndroidInjection.inject(this, context)
......@@ -33,18 +36,22 @@ class DirectReplyReceiver : BroadcastReceiver() {
val message = intent.getParcelableExtra<PushMessage>(EXTRA_PUSH_MESSAGE)
message?.let {
launch(UI) {
val manager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
val notificationId = it.notificationId.toInt()
val hostname = it.info.host
try {
println(it)
sendMessage(it, extractReplyMessage(intent))
val manager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
clearNotificationsByHostAndNotificationId(it.info.host, it.notificationId.toInt())
manager.cancel(it.notificationId.toInt())
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)
}
}
}
......
......@@ -82,7 +82,7 @@ class PushManager @Inject constructor(
}
@SuppressLint("NewApi")
private suspend fun showNotification(pushMessage: PushMessage) {
suspend fun showNotification(pushMessage: PushMessage) {
if (!hasAccount(pushMessage.info.host)) {
Timber.d("ignoring push message: $pushMessage")
return
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment