mirror of
https://github.com/quik-sms/quik.git
synced 2026-11-22 13:48:52 +01:00
Merged MessagesActivity and ComposeActivity
This commit is contained in:
@@ -46,7 +46,6 @@
|
|||||||
</activity>
|
</activity>
|
||||||
<activity android:name="com.moez.QKSMS.presentation.messages.MessagesActivity" />
|
<activity android:name="com.moez.QKSMS.presentation.messages.MessagesActivity" />
|
||||||
<activity android:name=".presentation.settings.SettingsActivity" />
|
<activity android:name=".presentation.settings.SettingsActivity" />
|
||||||
<activity android:name=".presentation.compose.ComposeActivity" />
|
|
||||||
|
|
||||||
<receiver android:name=".receiver.DefaultSmsChangedReceiver">
|
<receiver android:name=".receiver.DefaultSmsChangedReceiver">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package com.moez.QKSMS.common.di
|
package com.moez.QKSMS.common.di
|
||||||
|
|
||||||
import com.moez.QKSMS.common.util.ContactImageLoader
|
import com.moez.QKSMS.common.util.ContactImageLoader
|
||||||
import com.moez.QKSMS.presentation.compose.ComposeViewModel
|
|
||||||
import com.moez.QKSMS.presentation.compose.DetailedChipView
|
import com.moez.QKSMS.presentation.compose.DetailedChipView
|
||||||
import com.moez.QKSMS.presentation.main.ConversationsAdapter
|
import com.moez.QKSMS.presentation.main.ConversationsAdapter
|
||||||
import com.moez.QKSMS.presentation.main.MainActivity
|
import com.moez.QKSMS.presentation.main.MainActivity
|
||||||
@@ -36,7 +35,6 @@ interface AppComponent {
|
|||||||
fun inject(view: AvatarView)
|
fun inject(view: AvatarView)
|
||||||
|
|
||||||
fun inject(viewModel: MainViewModel)
|
fun inject(viewModel: MainViewModel)
|
||||||
fun inject(viewModel: ComposeViewModel)
|
|
||||||
fun inject(viewModel: MessagesViewModel)
|
fun inject(viewModel: MessagesViewModel)
|
||||||
fun inject(viewModel: SettingsViewModel)
|
fun inject(viewModel: SettingsViewModel)
|
||||||
|
|
||||||
|
|||||||
@@ -4,8 +4,6 @@ import android.arch.lifecycle.ViewModel
|
|||||||
import android.arch.lifecycle.ViewModelProvider
|
import android.arch.lifecycle.ViewModelProvider
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import com.moez.QKSMS.presentation.compose.ComposeActivity
|
|
||||||
import com.moez.QKSMS.presentation.compose.ComposeViewModel
|
|
||||||
import com.moez.QKSMS.presentation.main.MainViewModel
|
import com.moez.QKSMS.presentation.main.MainViewModel
|
||||||
import com.moez.QKSMS.presentation.messages.MessagesActivity
|
import com.moez.QKSMS.presentation.messages.MessagesActivity
|
||||||
import com.moez.QKSMS.presentation.messages.MessagesViewModel
|
import com.moez.QKSMS.presentation.messages.MessagesViewModel
|
||||||
@@ -23,7 +21,7 @@ class Navigator @Inject constructor(val context: Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun showCompose() {
|
fun showCompose() {
|
||||||
val intent = Intent(context, ComposeActivity::class.java)
|
val intent = Intent(context, MessagesActivity::class.java)
|
||||||
startActivity(intent)
|
startActivity(intent)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -48,10 +46,6 @@ class Navigator @Inject constructor(val context: Context) {
|
|||||||
MainViewModel()
|
MainViewModel()
|
||||||
}
|
}
|
||||||
|
|
||||||
ComposeViewModel::class.java -> {
|
|
||||||
ComposeViewModel()
|
|
||||||
}
|
|
||||||
|
|
||||||
MessagesViewModel::class.java -> {
|
MessagesViewModel::class.java -> {
|
||||||
val threadId = intent.getLongExtra("threadId", 0)
|
val threadId = intent.getLongExtra("threadId", 0)
|
||||||
MessagesViewModel(threadId)
|
MessagesViewModel(threadId)
|
||||||
|
|||||||
@@ -1,51 +0,0 @@
|
|||||||
package com.moez.QKSMS.presentation.compose
|
|
||||||
|
|
||||||
import android.os.Bundle
|
|
||||||
import android.support.v7.widget.LinearLayoutManager
|
|
||||||
import com.google.android.flexbox.FlexboxLayoutManager
|
|
||||||
import com.moez.QKSMS.R
|
|
||||||
import com.moez.QKSMS.data.model.Contact
|
|
||||||
import com.moez.QKSMS.presentation.base.QkActivity
|
|
||||||
import io.reactivex.subjects.PublishSubject
|
|
||||||
import io.reactivex.subjects.Subject
|
|
||||||
import kotlinx.android.synthetic.main.compose_activity.*
|
|
||||||
import kotlinx.android.synthetic.main.toolbar_chips.*
|
|
||||||
|
|
||||||
class ComposeActivity : QkActivity<ComposeViewModel>(), ComposeView {
|
|
||||||
|
|
||||||
override val viewModelClass = ComposeViewModel::class
|
|
||||||
|
|
||||||
override val queryChangedIntent: Subject<CharSequence> = PublishSubject.create()
|
|
||||||
override val chipSelectedIntent: Subject<Contact> = PublishSubject.create()
|
|
||||||
override val chipDeletedIntent: Subject<Contact> = PublishSubject.create()
|
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
|
||||||
super.onCreate(savedInstanceState)
|
|
||||||
setContentView(R.layout.compose_activity)
|
|
||||||
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
|
||||||
viewModel.bindView(this)
|
|
||||||
|
|
||||||
chips.layoutManager = FlexboxLayoutManager(this)
|
|
||||||
contacts.layoutManager = LinearLayoutManager(this)
|
|
||||||
|
|
||||||
window.callback = ComposeWindowCallback(window.callback, this)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun render(state: ComposeState) {
|
|
||||||
if (chips.adapter == null && state.selectedContacts != null) {
|
|
||||||
val adapter = ChipsAdapter(this, chips, state.selectedContacts)
|
|
||||||
adapter.chipDeleted.subscribe { chipDeletedIntent.onNext(it) }
|
|
||||||
adapter.textChanges.subscribe { queryChangedIntent.onNext(it) }
|
|
||||||
|
|
||||||
chips.adapter = adapter
|
|
||||||
}
|
|
||||||
|
|
||||||
if (contacts.adapter == null && state.contacts != null) {
|
|
||||||
val adapter = ContactAdapter(this, state.contacts)
|
|
||||||
adapter.contactSelected.subscribe { chipSelectedIntent.onNext(it) }
|
|
||||||
|
|
||||||
contacts.adapter = adapter
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
package com.moez.QKSMS.presentation.compose
|
|
||||||
|
|
||||||
import com.moez.QKSMS.data.model.Contact
|
|
||||||
import io.reactivex.Flowable
|
|
||||||
|
|
||||||
data class ComposeState(
|
|
||||||
val contacts: Flowable<List<Contact>>? = null,
|
|
||||||
val selectedContacts: Flowable<List<Contact>>? = null
|
|
||||||
)
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
package com.moez.QKSMS.presentation.compose
|
|
||||||
|
|
||||||
import com.moez.QKSMS.data.model.Contact
|
|
||||||
import com.moez.QKSMS.presentation.base.QkView
|
|
||||||
import io.reactivex.subjects.Subject
|
|
||||||
|
|
||||||
interface ComposeView : QkView<ComposeState> {
|
|
||||||
|
|
||||||
val queryChangedIntent: Subject<CharSequence>
|
|
||||||
val chipSelectedIntent: Subject<Contact>
|
|
||||||
val chipDeletedIntent: Subject<Contact>
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,67 +0,0 @@
|
|||||||
package com.moez.QKSMS.presentation.compose
|
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import android.telephony.PhoneNumberUtils
|
|
||||||
import com.moez.QKSMS.common.di.AppComponentManager
|
|
||||||
import com.moez.QKSMS.data.model.Contact
|
|
||||||
import com.moez.QKSMS.data.repository.ContactRepository
|
|
||||||
import com.moez.QKSMS.presentation.base.QkViewModel
|
|
||||||
import io.reactivex.BackpressureStrategy
|
|
||||||
import io.reactivex.Flowable
|
|
||||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
|
||||||
import io.reactivex.rxkotlin.plusAssign
|
|
||||||
import io.reactivex.schedulers.Schedulers
|
|
||||||
import io.reactivex.subjects.BehaviorSubject
|
|
||||||
import io.reactivex.subjects.Subject
|
|
||||||
import javax.inject.Inject
|
|
||||||
|
|
||||||
|
|
||||||
class ComposeViewModel : QkViewModel<ComposeView, ComposeState>(ComposeState()) {
|
|
||||||
|
|
||||||
@Inject lateinit var context: Context
|
|
||||||
@Inject lateinit var contactsRepo: ContactRepository
|
|
||||||
|
|
||||||
private val contactsSubject: Subject<List<Contact>> = BehaviorSubject.create()
|
|
||||||
private val selectedContactsReducer: Subject<(List<Contact>) -> List<Contact>> = BehaviorSubject.create()
|
|
||||||
|
|
||||||
private val contacts: List<Contact>
|
|
||||||
|
|
||||||
init {
|
|
||||||
AppComponentManager.appComponent.inject(this)
|
|
||||||
|
|
||||||
contacts = contactsRepo.getContacts()
|
|
||||||
|
|
||||||
val contactsFlowable = contactsSubject.toFlowable(BackpressureStrategy.BUFFER)
|
|
||||||
|
|
||||||
val selectedContacts: Flowable<List<Contact>> = selectedContactsReducer
|
|
||||||
.scan(listOf<Contact>(), { previousState, reducer -> reducer(previousState) })
|
|
||||||
.toFlowable(BackpressureStrategy.BUFFER)
|
|
||||||
|
|
||||||
newState { it.copy(contacts = contactsFlowable, selectedContacts = selectedContacts) }
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun bindView(view: ComposeView) {
|
|
||||||
super.bindView(view)
|
|
||||||
|
|
||||||
intents += view.queryChangedIntent
|
|
||||||
.toFlowable(BackpressureStrategy.LATEST)
|
|
||||||
.map { query -> query.toString() }
|
|
||||||
.map { query ->
|
|
||||||
contacts.filter { contact ->
|
|
||||||
contact.name.contains(query, true) || PhoneNumberUtils.compare(contact.address, query)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.subscribeOn(Schedulers.computation())
|
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
|
||||||
.subscribe { contacts -> contactsSubject.onNext(contacts) }
|
|
||||||
|
|
||||||
intents += view.chipSelectedIntent.subscribe { contact ->
|
|
||||||
selectedContactsReducer.onNext { it.toMutableList().apply { add(contact) } }
|
|
||||||
}
|
|
||||||
|
|
||||||
intents += view.chipDeletedIntent.subscribe { contact ->
|
|
||||||
selectedContactsReducer.onNext { it.filterNot { it == contact } }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -4,18 +4,25 @@ import android.app.AlertDialog
|
|||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.support.v7.widget.LinearLayoutManager
|
import android.support.v7.widget.LinearLayoutManager
|
||||||
import android.support.v7.widget.RecyclerView
|
import android.support.v7.widget.RecyclerView
|
||||||
|
import android.view.View
|
||||||
|
import com.google.android.flexbox.FlexboxLayoutManager
|
||||||
import com.jakewharton.rxbinding2.view.clicks
|
import com.jakewharton.rxbinding2.view.clicks
|
||||||
import com.jakewharton.rxbinding2.widget.textChanges
|
import com.jakewharton.rxbinding2.widget.textChanges
|
||||||
import com.moez.QKSMS.R
|
import com.moez.QKSMS.R
|
||||||
import com.moez.QKSMS.common.di.AppComponentManager
|
import com.moez.QKSMS.common.di.AppComponentManager
|
||||||
import com.moez.QKSMS.common.util.ThemeManager
|
import com.moez.QKSMS.common.util.ThemeManager
|
||||||
import com.moez.QKSMS.common.util.extensions.setTint
|
import com.moez.QKSMS.common.util.extensions.setTint
|
||||||
|
import com.moez.QKSMS.data.model.Contact
|
||||||
import com.moez.QKSMS.data.model.Message
|
import com.moez.QKSMS.data.model.Message
|
||||||
import com.moez.QKSMS.presentation.base.QkActivity
|
import com.moez.QKSMS.presentation.base.QkActivity
|
||||||
|
import com.moez.QKSMS.presentation.compose.ChipsAdapter
|
||||||
|
import com.moez.QKSMS.presentation.compose.ComposeWindowCallback
|
||||||
|
import com.moez.QKSMS.presentation.compose.ContactAdapter
|
||||||
import io.reactivex.subjects.PublishSubject
|
import io.reactivex.subjects.PublishSubject
|
||||||
import io.reactivex.subjects.Subject
|
import io.reactivex.subjects.Subject
|
||||||
import io.realm.RealmResults
|
import io.realm.RealmResults
|
||||||
import kotlinx.android.synthetic.main.message_list_activity.*
|
import kotlinx.android.synthetic.main.message_list_activity.*
|
||||||
|
import kotlinx.android.synthetic.main.toolbar_chips.*
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
|
||||||
@@ -26,6 +33,9 @@ class MessagesActivity : QkActivity<MessagesViewModel>(), MessagesView {
|
|||||||
private lateinit var layoutManager: LinearLayoutManager
|
private lateinit var layoutManager: LinearLayoutManager
|
||||||
|
|
||||||
override val viewModelClass = MessagesViewModel::class
|
override val viewModelClass = MessagesViewModel::class
|
||||||
|
override val queryChangedIntent: Subject<CharSequence> = PublishSubject.create()
|
||||||
|
override val chipSelectedIntent: Subject<Contact> = PublishSubject.create()
|
||||||
|
override val chipDeletedIntent: Subject<Contact> = PublishSubject.create()
|
||||||
override val copyTextIntent: Subject<Message> = PublishSubject.create()
|
override val copyTextIntent: Subject<Message> = PublishSubject.create()
|
||||||
override val forwardMessageIntent: Subject<Message> = PublishSubject.create()
|
override val forwardMessageIntent: Subject<Message> = PublishSubject.create()
|
||||||
override val deleteMessageIntent: Subject<Message> = PublishSubject.create()
|
override val deleteMessageIntent: Subject<Message> = PublishSubject.create()
|
||||||
@@ -40,16 +50,39 @@ class MessagesActivity : QkActivity<MessagesViewModel>(), MessagesView {
|
|||||||
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
||||||
viewModel.bindView(this)
|
viewModel.bindView(this)
|
||||||
|
|
||||||
|
chips.layoutManager = FlexboxLayoutManager(this)
|
||||||
|
contacts.layoutManager = LinearLayoutManager(this)
|
||||||
|
|
||||||
|
window.callback = ComposeWindowCallback(window.callback, this)
|
||||||
|
|
||||||
layoutManager = LinearLayoutManager(this)
|
layoutManager = LinearLayoutManager(this)
|
||||||
layoutManager.stackFromEnd = true
|
layoutManager.stackFromEnd = true
|
||||||
messageList.layoutManager = layoutManager
|
messageList.layoutManager = layoutManager
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun render(state: MessagesState) {
|
override fun render(state: MessagesState) {
|
||||||
|
toolbarTitle.visibility = if (state.editingMode) View.GONE else View.VISIBLE
|
||||||
|
chips.visibility = if (state.editingMode) View.VISIBLE else View.GONE
|
||||||
|
contacts.visibility = if (state.editingMode) View.VISIBLE else View.GONE
|
||||||
|
|
||||||
|
if (chips.adapter == null && state.selectedContacts != null) {
|
||||||
|
val adapter = ChipsAdapter(this, chips, state.selectedContacts)
|
||||||
|
adapter.chipDeleted.subscribe { chipDeletedIntent.onNext(it) }
|
||||||
|
adapter.textChanges.subscribe { queryChangedIntent.onNext(it) }
|
||||||
|
|
||||||
|
chips.adapter = adapter
|
||||||
|
}
|
||||||
|
|
||||||
|
if (contacts.adapter == null && state.contacts != null) {
|
||||||
|
val adapter = ContactAdapter(this, state.contacts)
|
||||||
|
adapter.contactSelected.subscribe { chipSelectedIntent.onNext(it) }
|
||||||
|
|
||||||
|
contacts.adapter = adapter
|
||||||
|
}
|
||||||
|
|
||||||
if (title != state.title) title = state.title
|
if (title != state.title) title = state.title
|
||||||
if (messageList.adapter == null && state.messages?.isValid == true) messageList.adapter = createAdapter(state.messages)
|
if (messageList.adapter == null && state.messages?.isValid == true) messageList.adapter = createAdapter(state.messages)
|
||||||
if (message.text.toString() != state.draft) message.setText(state.draft)
|
if (message.text.toString() != state.draft) message.setText(state.draft)
|
||||||
if (state.hasError) finish()
|
|
||||||
|
|
||||||
send.setTint(if (state.canSend) themeManager.color else resources.getColor(R.color.textTertiary))
|
send.setTint(if (state.canSend) themeManager.color else resources.getColor(R.color.textTertiary))
|
||||||
send.isEnabled = state.canSend
|
send.isEnabled = state.canSend
|
||||||
|
|||||||
@@ -1,12 +1,16 @@
|
|||||||
package com.moez.QKSMS.presentation.messages
|
package com.moez.QKSMS.presentation.messages
|
||||||
|
|
||||||
|
import com.moez.QKSMS.data.model.Contact
|
||||||
import com.moez.QKSMS.data.model.Message
|
import com.moez.QKSMS.data.model.Message
|
||||||
|
import io.reactivex.Flowable
|
||||||
import io.realm.RealmResults
|
import io.realm.RealmResults
|
||||||
|
|
||||||
data class MessagesState(
|
data class MessagesState(
|
||||||
|
val editingMode: Boolean = false,
|
||||||
|
val contacts: Flowable<List<Contact>>? = null,
|
||||||
|
val selectedContacts: Flowable<List<Contact>>? = null,
|
||||||
val title: String = "",
|
val title: String = "",
|
||||||
val messages: RealmResults<Message>? = null,
|
val messages: RealmResults<Message>? = null,
|
||||||
val draft: String = "",
|
val draft: String = "",
|
||||||
val canSend: Boolean = false,
|
val canSend: Boolean = false
|
||||||
val hasError: Boolean = false
|
|
||||||
)
|
)
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.moez.QKSMS.presentation.messages
|
package com.moez.QKSMS.presentation.messages
|
||||||
|
|
||||||
|
import com.moez.QKSMS.data.model.Contact
|
||||||
import com.moez.QKSMS.data.model.Message
|
import com.moez.QKSMS.data.model.Message
|
||||||
import com.moez.QKSMS.presentation.base.QkView
|
import com.moez.QKSMS.presentation.base.QkView
|
||||||
import io.reactivex.Observable
|
import io.reactivex.Observable
|
||||||
@@ -7,6 +8,9 @@ import io.reactivex.subjects.Subject
|
|||||||
|
|
||||||
interface MessagesView : QkView<MessagesState> {
|
interface MessagesView : QkView<MessagesState> {
|
||||||
|
|
||||||
|
val queryChangedIntent: Subject<CharSequence>
|
||||||
|
val chipSelectedIntent: Subject<Contact>
|
||||||
|
val chipDeletedIntent: Subject<Contact>
|
||||||
val copyTextIntent: Subject<Message>
|
val copyTextIntent: Subject<Message>
|
||||||
val forwardMessageIntent: Subject<Message>
|
val forwardMessageIntent: Subject<Message>
|
||||||
val deleteMessageIntent: Subject<Message>
|
val deleteMessageIntent: Subject<Message>
|
||||||
|
|||||||
@@ -1,27 +1,42 @@
|
|||||||
package com.moez.QKSMS.presentation.messages
|
package com.moez.QKSMS.presentation.messages
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.telephony.PhoneNumberUtils
|
||||||
import com.moez.QKSMS.R
|
import com.moez.QKSMS.R
|
||||||
import com.moez.QKSMS.common.di.AppComponentManager
|
import com.moez.QKSMS.common.di.AppComponentManager
|
||||||
import com.moez.QKSMS.common.util.ClipboardUtils
|
import com.moez.QKSMS.common.util.ClipboardUtils
|
||||||
import com.moez.QKSMS.common.util.extensions.makeToast
|
import com.moez.QKSMS.common.util.extensions.makeToast
|
||||||
|
import com.moez.QKSMS.data.model.Contact
|
||||||
import com.moez.QKSMS.data.model.Conversation
|
import com.moez.QKSMS.data.model.Conversation
|
||||||
|
import com.moez.QKSMS.data.repository.ContactRepository
|
||||||
import com.moez.QKSMS.data.repository.MessageRepository
|
import com.moez.QKSMS.data.repository.MessageRepository
|
||||||
import com.moez.QKSMS.domain.interactor.DeleteMessage
|
import com.moez.QKSMS.domain.interactor.DeleteMessage
|
||||||
import com.moez.QKSMS.domain.interactor.MarkRead
|
import com.moez.QKSMS.domain.interactor.MarkRead
|
||||||
import com.moez.QKSMS.domain.interactor.SendMessage
|
import com.moez.QKSMS.domain.interactor.SendMessage
|
||||||
import com.moez.QKSMS.presentation.base.QkViewModel
|
import com.moez.QKSMS.presentation.base.QkViewModel
|
||||||
|
import io.reactivex.BackpressureStrategy
|
||||||
|
import io.reactivex.Flowable
|
||||||
|
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||||
import io.reactivex.rxkotlin.plusAssign
|
import io.reactivex.rxkotlin.plusAssign
|
||||||
|
import io.reactivex.schedulers.Schedulers
|
||||||
|
import io.reactivex.subjects.BehaviorSubject
|
||||||
|
import io.reactivex.subjects.Subject
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
class MessagesViewModel(val threadId: Long) : QkViewModel<MessagesView, MessagesState>(MessagesState()) {
|
class MessagesViewModel(val threadId: Long) : QkViewModel<MessagesView, MessagesState>(MessagesState(editingMode = threadId == 0L)) {
|
||||||
|
|
||||||
@Inject lateinit var context: Context
|
@Inject lateinit var context: Context
|
||||||
|
@Inject lateinit var contactsRepo: ContactRepository
|
||||||
@Inject lateinit var messageRepo: MessageRepository
|
@Inject lateinit var messageRepo: MessageRepository
|
||||||
@Inject lateinit var sendMessage: SendMessage
|
@Inject lateinit var sendMessage: SendMessage
|
||||||
@Inject lateinit var markRead: MarkRead
|
@Inject lateinit var markRead: MarkRead
|
||||||
@Inject lateinit var deleteMessage: DeleteMessage
|
@Inject lateinit var deleteMessage: DeleteMessage
|
||||||
|
|
||||||
|
private val contactsSubject: Subject<List<Contact>> = BehaviorSubject.create()
|
||||||
|
private val selectedContactsReducer: Subject<(List<Contact>) -> List<Contact>> = BehaviorSubject.create()
|
||||||
|
|
||||||
|
private val contacts: List<Contact>
|
||||||
|
|
||||||
private var conversation: Conversation? = null
|
private var conversation: Conversation? = null
|
||||||
|
|
||||||
init {
|
init {
|
||||||
@@ -40,16 +55,45 @@ class MessagesViewModel(val threadId: Long) : QkViewModel<MessagesView, Messages
|
|||||||
val messages = messageRepo.getMessages(threadId)
|
val messages = messageRepo.getMessages(threadId)
|
||||||
newState { it.copy(title = title, messages = messages) }
|
newState { it.copy(title = title, messages = messages) }
|
||||||
}
|
}
|
||||||
false -> newState { it.copy(hasError = true) }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
contacts = contactsRepo.getContacts()
|
||||||
|
|
||||||
|
val contactsFlowable = contactsSubject.toFlowable(BackpressureStrategy.BUFFER)
|
||||||
|
|
||||||
|
val selectedContacts: Flowable<List<Contact>> = selectedContactsReducer
|
||||||
|
.scan(listOf<Contact>(), { previousState, reducer -> reducer(previousState) })
|
||||||
|
.toFlowable(BackpressureStrategy.BUFFER)
|
||||||
|
|
||||||
|
newState { it.copy(contacts = contactsFlowable, selectedContacts = selectedContacts) }
|
||||||
|
|
||||||
dataChanged()
|
dataChanged()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun bindView(view: MessagesView) {
|
override fun bindView(view: MessagesView) {
|
||||||
super.bindView(view)
|
super.bindView(view)
|
||||||
|
|
||||||
|
intents += view.queryChangedIntent
|
||||||
|
.toFlowable(BackpressureStrategy.LATEST)
|
||||||
|
.map { query -> query.toString() }
|
||||||
|
.map { query ->
|
||||||
|
contacts.filter { contact ->
|
||||||
|
contact.name.contains(query, true) || PhoneNumberUtils.compare(contact.address, query)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.subscribeOn(Schedulers.computation())
|
||||||
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
|
.subscribe { contacts -> contactsSubject.onNext(contacts) }
|
||||||
|
|
||||||
|
intents += view.chipSelectedIntent.subscribe { contact ->
|
||||||
|
selectedContactsReducer.onNext { it.toMutableList().apply { add(contact) } }
|
||||||
|
}
|
||||||
|
|
||||||
|
intents += view.chipDeletedIntent.subscribe { contact ->
|
||||||
|
selectedContactsReducer.onNext { it.filterNot { it == contact } }
|
||||||
|
}
|
||||||
|
|
||||||
intents += view.textChangedIntent.subscribe { text ->
|
intents += view.textChangedIntent.subscribe { text ->
|
||||||
newState { it.copy(draft = text.toString(), canSend = text.isNotEmpty()) }
|
newState { it.copy(draft = text.toString(), canSend = text.isNotEmpty()) }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,29 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:orientation="vertical">
|
|
||||||
|
|
||||||
<include layout="@layout/toolbar_chips" />
|
|
||||||
|
|
||||||
<FrameLayout
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent">
|
|
||||||
|
|
||||||
<android.support.v7.widget.RecyclerView
|
|
||||||
android:id="@+id/contacts"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:clipChildren="false"
|
|
||||||
android:clipToPadding="false"
|
|
||||||
android:paddingBottom="8dp"
|
|
||||||
android:paddingTop="8dp" />
|
|
||||||
|
|
||||||
<View
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="8dp"
|
|
||||||
android:background="@drawable/ab_shadow" />
|
|
||||||
|
|
||||||
</FrameLayout>
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
@@ -6,7 +6,7 @@
|
|||||||
android:background="@color/backgroundLight"
|
android:background="@color/backgroundLight"
|
||||||
android:orientation="vertical">
|
android:orientation="vertical">
|
||||||
|
|
||||||
<include layout="@layout/toolbar" />
|
<include layout="@layout/toolbar_chips" />
|
||||||
|
|
||||||
<FrameLayout
|
<FrameLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
@@ -23,6 +23,15 @@
|
|||||||
android:paddingTop="8dp"
|
android:paddingTop="8dp"
|
||||||
tools:listitem="@layout/message_list_item_out" />
|
tools:listitem="@layout/message_list_item_out" />
|
||||||
|
|
||||||
|
<android.support.v7.widget.RecyclerView
|
||||||
|
android:id="@+id/contacts"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:clipChildren="false"
|
||||||
|
android:clipToPadding="false"
|
||||||
|
android:paddingBottom="8dp"
|
||||||
|
android:paddingTop="8dp" />
|
||||||
|
|
||||||
<View
|
<View
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="8dp"
|
android:layout_height="8dp"
|
||||||
|
|||||||
@@ -5,12 +5,21 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:background="@color/white"
|
android:background="@color/white"
|
||||||
android:gravity="center_vertical"
|
android:gravity="center_vertical"
|
||||||
android:minHeight="56dp">
|
android:minHeight="56dp"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/toolbarTitle"
|
android:id="@+id/toolbarTitle"
|
||||||
android:layout_width="0dp"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="0dp" />
|
android:layout_height="match_parent"
|
||||||
|
android:background="@null"
|
||||||
|
android:gravity="left|center_vertical"
|
||||||
|
android:maxLines="1"
|
||||||
|
android:singleLine="true"
|
||||||
|
android:textColor="@color/textPrimary"
|
||||||
|
android:textColorHint="@color/textTertiary"
|
||||||
|
android:textSize="20sp"
|
||||||
|
tools:text="Conversations" />
|
||||||
|
|
||||||
<android.support.v7.widget.RecyclerView
|
<android.support.v7.widget.RecyclerView
|
||||||
android:id="@+id/chips"
|
android:id="@+id/chips"
|
||||||
|
|||||||
Reference in New Issue
Block a user