Display qkreply popup when message is received

This commit is contained in:
Moez Bhatti
2018-03-28 00:49:31 -04:00
parent 48193b09c8
commit 16d49e8e64
13 changed files with 286 additions and 3 deletions
@@ -67,6 +67,11 @@
<activity android:name="feature.conversationinfo.ConversationInfoActivity" />
<activity android:name="feature.notificationprefs.NotificationPrefsActivity" />
<activity android:name="feature.blocked.BlockedActivity" />
<activity
android:name="feature.qkreply.QkReplyActivity"
android:excludeFromRecents="true"
android:taskAffinity=""
android:theme="@style/AppThemeLightDialog" />
<receiver android:name="receiver.DefaultSmsChangedReceiver">
<intent-filter>
@@ -43,6 +43,7 @@ import feature.notificationprefs.NotificationPrefsActivity
import feature.notificationprefs.NotificationPrefsViewModel
import feature.plus.PlusActivity
import feature.plus.PlusViewModel
import feature.qkreply.QkReplyViewModel
import feature.settings.SettingsActivity
import feature.settings.SettingsViewModel
import feature.setup.SetupActivity
@@ -187,6 +188,7 @@ class Navigator @Inject constructor(private val context: Context, private val no
ConversationInfoViewModel::class.java -> ConversationInfoViewModel(intent)
GalleryViewModel::class.java -> GalleryViewModel(intent)
NotificationPrefsViewModel::class.java -> NotificationPrefsViewModel(intent)
QkReplyViewModel::class.java -> QkReplyViewModel(intent)
SettingsViewModel::class.java -> SettingsViewModel()
BlockedViewModel::class.java -> BlockedViewModel()
ThemePickerViewModel::class.java -> ThemePickerViewModel(intent)
@@ -25,6 +25,7 @@ import com.moez.QKSMS.R
import com.uber.autodispose.android.lifecycle.scope
import com.uber.autodispose.kotlin.autoDisposable
import common.util.Colors
import common.util.extensions.setBackgroundTint
import io.reactivex.rxkotlin.Observables
import io.reactivex.subjects.BehaviorSubject
import io.reactivex.subjects.Subject
@@ -57,7 +58,8 @@ abstract class QkThemedActivity<VM : QkViewModel<*, *>> : QkActivity<VM>() {
@SuppressLint("InlinedApi")
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
colors.appThemeResources
getAppThemeResourcesObservable()
.autoDisposable(scope())
.subscribe { res -> setTheme(res) }
@@ -101,7 +103,12 @@ abstract class QkThemedActivity<VM : QkViewModel<*, *>> : QkActivity<VM>() {
colors.toolbarColor
.autoDisposable(scope(Lifecycle.Event.ON_DESTROY))
.subscribe { color -> toolbar?.setBackgroundColor(color) }
.subscribe { color -> toolbar?.setBackgroundTint(color) }
}
/**
* This can be overridden in case an activity does not want to use the default themes
*/
open fun getAppThemeResourcesObservable() = colors.appThemeResources
}
@@ -74,6 +74,15 @@ class Colors @Inject constructor(private val context: Context, private val prefs
}
})
val appDialogThemeResources = Observables.combineLatest(prefs.night.asObservable(), prefs.black.asObservable(),
{ night, black ->
when {
night && black -> R.style.AppThemeBlackDialog
night && !black -> R.style.AppThemeDarkDialog
else -> R.style.AppThemeLightDialog
}
})
val popupThemeResource = Observables.combineLatest(prefs.night.asObservable(), prefs.black.asObservable(),
{ night, black ->
when {
@@ -33,6 +33,7 @@ import android.support.v4.app.RemoteInput
import android.support.v4.app.TaskStackBuilder
import com.moez.QKSMS.R
import feature.compose.ComposeActivity
import feature.qkreply.QkReplyActivity
import receiver.MarkReadReceiver
import receiver.MarkSeenReceiver
import receiver.RemoteMessagingReceiver
@@ -97,6 +98,9 @@ class NotificationManagerImpl @Inject constructor(
style.addMessage(message.getSummary(), message.date, name)
}
val intent = Intent(context, QkReplyActivity::class.java).putExtra("threadId", threadId).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
context.startActivity(intent)
val contentIntent = Intent(context, ComposeActivity::class.java).putExtra("threadId", threadId)
val taskStackBuilder = TaskStackBuilder.create(context)
taskStackBuilder.addParentStack(ComposeActivity::class.java)
@@ -0,0 +1,65 @@
/*
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
*
* This file is part of QKSMS.
*
* QKSMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QKSMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package feature.qkreply
import android.os.Bundle
import android.view.ViewGroup
import android.view.Window
import android.view.WindowManager
import com.moez.QKSMS.R
import com.uber.autodispose.android.lifecycle.scope
import com.uber.autodispose.kotlin.autoDisposable
import common.base.QkThemedActivity
import common.util.extensions.setBackgroundTint
import injection.appComponent
import kotlinx.android.synthetic.main.qkreply_activity.*
class QkReplyActivity : QkThemedActivity<QkReplyViewModel>(), QkReplyView {
override val viewModelClass = QkReplyViewModel::class
init {
appComponent.inject(this)
}
override fun onCreate(savedInstanceState: Bundle?) {
supportRequestWindowFeature(Window.FEATURE_NO_TITLE)
super.onCreate(savedInstanceState)
setFinishOnTouchOutside(true)
setContentView(R.layout.qkreply_activity)
window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND)
window.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
viewModel.bindView(this)
toolbar.clipToOutline = true
colors.composeBackground
.autoDisposable(scope())
.subscribe { color -> background.setBackgroundTint(color) }
}
override fun render(state: QkReplyState) {
title = state.title
}
override fun getAppThemeResourcesObservable() = colors.appDialogThemeResources
}
@@ -0,0 +1,27 @@
/*
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
*
* This file is part of QKSMS.
*
* QKSMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QKSMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package feature.qkreply
import io.realm.RealmResults
import model.Message
data class QkReplyState(
val title: String = "",
val data: RealmResults<Message>? = null
)
@@ -0,0 +1,23 @@
/*
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
*
* This file is part of QKSMS.
*
* QKSMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QKSMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package feature.qkreply
import common.base.QkView
interface QkReplyView : QkView<QkReplyState>
@@ -0,0 +1,46 @@
/*
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
*
* This file is part of QKSMS.
*
* QKSMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QKSMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package feature.qkreply
import android.content.Intent
import common.base.QkViewModel
import injection.appComponent
import io.reactivex.rxkotlin.plusAssign
import model.Conversation
import repository.MessageRepository
import util.extensions.asObservable
import javax.inject.Inject
class QkReplyViewModel(intent: Intent) : QkViewModel<QkReplyView, QkReplyState>(QkReplyState()) {
@Inject lateinit var messageRepo: MessageRepository
init {
appComponent.inject(this)
val threadId = intent.getLongExtra("threadId", -1)
disposables += messageRepo.getConversationAsync(threadId)
.asObservable<Conversation>()
.filter { it.isLoaded }
.filter { it.isValid }
.subscribe { conversation -> newState { it.copy(title = conversation.getTitle()) } }
}
}
@@ -44,6 +44,8 @@ import feature.notificationprefs.NotificationPrefsActivity
import feature.notificationprefs.NotificationPrefsViewModel
import feature.plus.PlusActivity
import feature.plus.PlusViewModel
import feature.qkreply.QkReplyActivity
import feature.qkreply.QkReplyViewModel
import feature.settings.SettingsActivity
import feature.settings.SettingsViewModel
import feature.setup.SetupActivity
@@ -80,6 +82,7 @@ interface AppComponent {
fun inject(activity: GalleryActivity)
fun inject(activity: NotificationPrefsActivity)
fun inject(activity: PlusActivity)
fun inject(activity: QkReplyActivity)
fun inject(activity: SettingsActivity)
fun inject(activity: ThemePickerActivity)
@@ -117,6 +120,7 @@ interface AppComponent {
fun inject(viewModel: GalleryViewModel)
fun inject(viewModel: NotificationPrefsViewModel)
fun inject(viewModel: PlusViewModel)
fun inject(viewModel: QkReplyViewModel)
fun inject(viewModel: SettingsViewModel)
fun inject(viewModel: ThemePickerViewModel)
@@ -27,10 +27,10 @@
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
style="@style/Toolbar"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:minHeight="56dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
@@ -0,0 +1,69 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
~
~ This file is part of QKSMS.
~
~ QKSMS is free software: you can redistribute it and/or modify
~ it under the terms of the GNU General Public License as published by
~ the Free Software Foundation, either version 3 of the License, or
~ (at your option) any later version.
~
~ QKSMS is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
~ GNU General Public License for more details.
~
~ You should have received a copy of the GNU General Public License
~ along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
-->
<android.support.constraint.ConstraintLayout android:id="@+id/background"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="24dp"
android:background="@drawable/rounded_rectangle_4dp"
android:clipChildren="false"
android:clipToPadding="false"
android:elevation="8dp"
tools:context="feature.qkreply.QkReplyActivity">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
style="@style/Toolbar"
android:background="@drawable/rounded_rectangle_top_4dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<common.widget.QkTextView
android:id="@+id/toolbarTitle"
style="@style/ToolbarText"
tools:text="Conversations" />
</android.support.v7.widget.Toolbar>
<android.support.v7.widget.RecyclerView
android:id="@+id/messages"
android:layout_width="0dp"
android:layout_height="200dp"
android:paddingBottom="8dp"
android:paddingTop="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/toolbar"
tools:listitem="@layout/message_list_item_out" />
<View
android:layout_width="0dp"
android:layout_height="8dp"
android:background="@drawable/ab_shadow"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/toolbar" />
</android.support.constraint.ConstraintLayout>
@@ -27,6 +27,12 @@
<item name="windowActionBar">false</item>
</style>
<style name="AppThemeLightDialog" parent="Theme.AppCompat.Light.Dialog">
<item name="android:windowBackground">@android:color/transparent</item>
<item name="actionBarPopupTheme">@style/PopupThemeLight</item>
<item name="windowActionBar">false</item>
</style>
<style name="AppThemeDark" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowBackground">@color/backgroundDark</item>
<item name="android:windowContentTransitions">true</item>
@@ -36,6 +42,12 @@
<item name="windowActionBar">false</item>
</style>
<style name="AppThemeDarkDialog" parent="Theme.AppCompat.Dialog">
<item name="android:windowBackground">@android:color/transparent</item>
<item name="actionBarPopupTheme">@style/PopupThemeDark</item>
<item name="windowActionBar">false</item>
</style>
<style name="AppThemeBlack" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowBackground">@color/black</item>
<item name="android:windowContentTransitions">true</item>
@@ -45,6 +57,12 @@
<item name="windowActionBar">false</item>
</style>
<style name="AppThemeBlackDialog" parent="Theme.AppCompat.Dialog">
<item name="android:windowBackground">@android:color/transparent</item>
<item name="actionBarPopupTheme">@style/PopupThemeBlack</item>
<item name="windowActionBar">false</item>
</style>
<style name="TextPrimary">
<item name="android:textSize">16sp</item>
<item name="textColor">primary</item>
@@ -86,6 +104,10 @@
<style name="Toolbar">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">56dp</item>
<!-- This needs to be set so that we can tint the toolbar and not change the background
resource. This is mainly so that QkReplyActivity can call setClipToOutline -->
<item name="android:background">@color/black</item>
<item name="android:gravity">center_vertical</item>
</style>