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
@@ -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()) } }
}
}