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 ...@@ -17,17 +17,8 @@ import chat.rocket.android.helper.MessageParser
import chat.rocket.android.infrastructure.LocalRepository import chat.rocket.android.infrastructure.LocalRepository
import chat.rocket.android.infrastructure.SharedPrefsLocalRepository import chat.rocket.android.infrastructure.SharedPrefsLocalRepository
import chat.rocket.android.push.GroupedPush import chat.rocket.android.push.GroupedPush
import chat.rocket.android.server.domain.AccountsRepository import chat.rocket.android.push.PushManager
import chat.rocket.android.server.domain.ChatRoomsRepository import chat.rocket.android.server.domain.*
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.server.infraestructure.MemoryChatRoomsRepository import chat.rocket.android.server.infraestructure.MemoryChatRoomsRepository
import chat.rocket.android.server.infraestructure.MemoryMessagesRepository import chat.rocket.android.server.infraestructure.MemoryMessagesRepository
import chat.rocket.android.server.infraestructure.MemoryRoomRepository import chat.rocket.android.server.infraestructure.MemoryRoomRepository
...@@ -275,4 +266,16 @@ class AppModule { ...@@ -275,4 +266,16 @@ class AppModule {
@Provides @Provides
@Singleton @Singleton
fun provideGroupedPush() = GroupedPush() 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 ...@@ -4,6 +4,7 @@ import android.app.NotificationManager
import android.content.BroadcastReceiver import android.content.BroadcastReceiver
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import android.support.v4.app.NotificationManagerCompat
import android.support.v4.app.RemoteInput import android.support.v4.app.RemoteInput
import android.widget.Toast import android.widget.Toast
import chat.rocket.android.R import chat.rocket.android.R
...@@ -26,6 +27,8 @@ class DirectReplyReceiver : BroadcastReceiver() { ...@@ -26,6 +27,8 @@ class DirectReplyReceiver : BroadcastReceiver() {
lateinit var factory: ConnectionManagerFactory lateinit var factory: ConnectionManagerFactory
@Inject @Inject
lateinit var groupedPushes: GroupedPush lateinit var groupedPushes: GroupedPush
@Inject
lateinit var pushManager: PushManager
override fun onReceive(context: Context, intent: Intent) { override fun onReceive(context: Context, intent: Intent) {
AndroidInjection.inject(this, context) AndroidInjection.inject(this, context)
...@@ -33,18 +36,22 @@ class DirectReplyReceiver : BroadcastReceiver() { ...@@ -33,18 +36,22 @@ class DirectReplyReceiver : BroadcastReceiver() {
val message = intent.getParcelableExtra<PushMessage>(EXTRA_PUSH_MESSAGE) val message = intent.getParcelableExtra<PushMessage>(EXTRA_PUSH_MESSAGE)
message?.let { message?.let {
launch(UI) { launch(UI) {
val manager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
val notificationId = it.notificationId.toInt()
val hostname = it.info.host
try { try {
println(it) println(it)
sendMessage(it, extractReplyMessage(intent)) sendMessage(it, extractReplyMessage(intent))
val manager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager clearNotificationsByHostAndNotificationId(hostname, notificationId)
clearNotificationsByHostAndNotificationId(it.info.host, it.notificationId.toInt()) manager.cancel(notificationId)
manager.cancel(it.notificationId.toInt())
val feedback = context.getString(R.string.notif_success_sending, it.title) val feedback = context.getString(R.string.notif_success_sending, it.title)
Toast.makeText(context, feedback, Toast.LENGTH_SHORT).show() Toast.makeText(context, feedback, Toast.LENGTH_SHORT).show()
} catch (ex: RocketChatException) { } catch (ex: RocketChatException) {
Timber.e(ex) Timber.e(ex)
val feedback = context.getString(R.string.notif_error_sending) val feedback = context.getString(R.string.notif_error_sending)
Toast.makeText(context, feedback, Toast.LENGTH_SHORT).show() Toast.makeText(context, feedback, Toast.LENGTH_SHORT).show()
clearNotificationsByHostAndNotificationId(hostname, notificationId)
pushManager.showNotification(it)
} }
} }
} }
......
...@@ -82,7 +82,7 @@ class PushManager @Inject constructor( ...@@ -82,7 +82,7 @@ class PushManager @Inject constructor(
} }
@SuppressLint("NewApi") @SuppressLint("NewApi")
private suspend fun showNotification(pushMessage: PushMessage) { suspend fun showNotification(pushMessage: PushMessage) {
if (!hasAccount(pushMessage.info.host)) { if (!hasAccount(pushMessage.info.host)) {
Timber.d("ignoring push message: $pushMessage") Timber.d("ignoring push message: $pushMessage")
return 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