mirror of
https://github.com/quik-sms/quik.git
synced 2026-11-17 11:38:51 +01:00
Add notification channel support on a per conversation basis
This commit is contained in:
@@ -48,7 +48,7 @@ import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Singleton
|
||||
class Navigator @Inject constructor(val context: Context) {
|
||||
class Navigator @Inject constructor(private val context: Context, private val notificationManager: NotificationManager) {
|
||||
|
||||
private fun startActivity(intent: Intent) {
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
@@ -134,9 +134,14 @@ class Navigator @Inject constructor(val context: Context) {
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.O)
|
||||
fun showNotificationSettings() {
|
||||
fun showNotificationSettings(threadId: Long = 0) {
|
||||
if (threadId != 0L) {
|
||||
notificationManager.createNotificationChannel(threadId)
|
||||
}
|
||||
|
||||
val channelId = notificationManager.buildNotificationChannelId(threadId)
|
||||
val intent = Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS)
|
||||
intent.putExtra(Settings.EXTRA_CHANNEL_ID, NotificationManager.DEFAULT_CHANNEL_ID)
|
||||
intent.putExtra(Settings.EXTRA_CHANNEL_ID, channelId)
|
||||
intent.putExtra(Settings.EXTRA_APP_PACKAGE, context.packageName)
|
||||
startActivity(intent)
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ import javax.inject.Inject
|
||||
class ConversationInfoActivity : QkThemedActivity<ConversationInfoViewModel>(), ConversationInfoView {
|
||||
|
||||
override val viewModelClass = ConversationInfoViewModel::class
|
||||
override val notificationsIntent by lazy { notifications.clicks() }
|
||||
override val archiveIntent by lazy { archive.clicks() }
|
||||
override val deleteIntent by lazy { delete.clicks() }
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ import presentation.common.base.QkView
|
||||
|
||||
interface ConversationInfoView : QkView<ConversationInfoState> {
|
||||
|
||||
val notificationsIntent: Observable<Unit>
|
||||
val archiveIntent: Observable<Unit>
|
||||
val deleteIntent: Observable<Unit>
|
||||
|
||||
|
||||
@@ -34,6 +34,7 @@ import interactor.MarkUnarchived
|
||||
import io.reactivex.Observable
|
||||
import io.reactivex.rxkotlin.plusAssign
|
||||
import io.reactivex.rxkotlin.withLatestFrom
|
||||
import presentation.common.Navigator
|
||||
import presentation.common.base.QkViewModel
|
||||
import javax.inject.Inject
|
||||
|
||||
@@ -44,6 +45,7 @@ class ConversationInfoViewModel(intent: Intent) : QkViewModel<ConversationInfoVi
|
||||
@Inject lateinit var messageRepo: MessageRepository
|
||||
@Inject lateinit var markArchived: MarkArchived
|
||||
@Inject lateinit var markUnarchived: MarkUnarchived
|
||||
@Inject lateinit var navigator: Navigator
|
||||
@Inject lateinit var deleteConversation: DeleteConversation
|
||||
|
||||
private val conversation: Observable<Conversation>
|
||||
@@ -83,6 +85,12 @@ class ConversationInfoViewModel(intent: Intent) : QkViewModel<ConversationInfoVi
|
||||
override fun bindView(view: ConversationInfoView) {
|
||||
super.bindView(view)
|
||||
|
||||
// Show the notifications settings for the conversation
|
||||
view.notificationsIntent
|
||||
.withLatestFrom(conversation, { _, conversation -> conversation })
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { conversation -> navigator.showNotificationSettings(conversation.id) }
|
||||
|
||||
// Toggle the archived state of the conversation
|
||||
view.archiveIntent
|
||||
.withLatestFrom(conversation, { _, conversation -> conversation })
|
||||
|
||||
Reference in New Issue
Block a user