forked from upstream-mirrors/quik
Use Recipient instead of Chip
This commit is contained in:
@@ -54,10 +54,10 @@ import com.moez.QKSMS.common.util.extensions.setBackgroundTint
|
||||
import com.moez.QKSMS.common.util.extensions.setTint
|
||||
import com.moez.QKSMS.common.util.extensions.setVisible
|
||||
import com.moez.QKSMS.common.util.extensions.showKeyboard
|
||||
import com.moez.QKSMS.feature.compose.editing.Chip
|
||||
import com.moez.QKSMS.feature.compose.editing.ChipsAdapter
|
||||
import com.moez.QKSMS.feature.contacts.ContactsActivity
|
||||
import com.moez.QKSMS.model.Attachment
|
||||
import com.moez.QKSMS.model.Recipient
|
||||
import com.uber.autodispose.android.lifecycle.scope
|
||||
import com.uber.autodispose.autoDisposable
|
||||
import dagger.android.AndroidInjection
|
||||
@@ -90,7 +90,7 @@ class ComposeActivity : QkThemedActivity(), ComposeView {
|
||||
|
||||
override val activityVisibleIntent: Subject<Boolean> = PublishSubject.create()
|
||||
override val chipsSelectedIntent: Subject<HashMap<String, String?>> = PublishSubject.create()
|
||||
override val chipDeletedIntent: Subject<Chip> by lazy { chipsAdapter.chipDeleted }
|
||||
override val chipDeletedIntent: Subject<Recipient> by lazy { chipsAdapter.chipDeleted }
|
||||
override val menuReadyIntent: Observable<Unit> = menu.map { Unit }
|
||||
override val optionsItemIntent: Subject<Int> = PublishSubject.create()
|
||||
override val sendAsGroupIntent by lazy { sendAsGroupBackground.clicks() }
|
||||
@@ -286,7 +286,7 @@ class ComposeActivity : QkThemedActivity(), ComposeView {
|
||||
startActivityForResult(Intent.createChooser(intent, null), AttachContactRequestCode)
|
||||
}
|
||||
|
||||
override fun showContacts(sharing: Boolean, chips: List<Chip>) {
|
||||
override fun showContacts(sharing: Boolean, chips: List<Recipient>) {
|
||||
message.hideKeyboard()
|
||||
val serialized = HashMap(chips.associate { chip -> chip.address to chip.contact?.lookupKey })
|
||||
val intent = Intent(this, ContactsActivity::class.java)
|
||||
|
||||
@@ -19,17 +19,17 @@
|
||||
package com.moez.QKSMS.feature.compose
|
||||
|
||||
import com.moez.QKSMS.compat.SubscriptionInfoCompat
|
||||
import com.moez.QKSMS.feature.compose.editing.Chip
|
||||
import com.moez.QKSMS.model.Attachment
|
||||
import com.moez.QKSMS.model.Conversation
|
||||
import com.moez.QKSMS.model.Message
|
||||
import com.moez.QKSMS.model.Recipient
|
||||
import io.realm.RealmResults
|
||||
|
||||
data class ComposeState(
|
||||
val hasError: Boolean = false,
|
||||
val editingMode: Boolean = false,
|
||||
val threadId: Long = 0,
|
||||
val selectedChips: List<Chip> = ArrayList(),
|
||||
val selectedChips: List<Recipient> = ArrayList(),
|
||||
val sendAsGroup: Boolean = true,
|
||||
val conversationtitle: String = "",
|
||||
val loading: Boolean = false,
|
||||
|
||||
@@ -22,8 +22,8 @@ import android.net.Uri
|
||||
import androidx.annotation.StringRes
|
||||
import androidx.core.view.inputmethod.InputContentInfoCompat
|
||||
import com.moez.QKSMS.common.base.QkView
|
||||
import com.moez.QKSMS.feature.compose.editing.Chip
|
||||
import com.moez.QKSMS.model.Attachment
|
||||
import com.moez.QKSMS.model.Recipient
|
||||
import io.reactivex.Observable
|
||||
import io.reactivex.subjects.Subject
|
||||
|
||||
@@ -31,7 +31,7 @@ interface ComposeView : QkView<ComposeState> {
|
||||
|
||||
val activityVisibleIntent: Observable<Boolean>
|
||||
val chipsSelectedIntent: Subject<HashMap<String, String?>>
|
||||
val chipDeletedIntent: Subject<Chip>
|
||||
val chipDeletedIntent: Subject<Recipient>
|
||||
val menuReadyIntent: Observable<Unit>
|
||||
val optionsItemIntent: Observable<Int>
|
||||
val sendAsGroupIntent: Observable<*>
|
||||
@@ -61,7 +61,7 @@ interface ComposeView : QkView<ComposeState> {
|
||||
fun requestDefaultSms()
|
||||
fun requestStoragePermission()
|
||||
fun requestSmsPermission()
|
||||
fun showContacts(sharing: Boolean, chips: List<Chip>)
|
||||
fun showContacts(sharing: Boolean, chips: List<Recipient>)
|
||||
fun themeChanged()
|
||||
fun showKeyboard()
|
||||
fun requestCamera()
|
||||
|
||||
@@ -36,7 +36,6 @@ import com.moez.QKSMS.extensions.asObservable
|
||||
import com.moez.QKSMS.extensions.isImage
|
||||
import com.moez.QKSMS.extensions.isVideo
|
||||
import com.moez.QKSMS.extensions.mapNotNull
|
||||
import com.moez.QKSMS.feature.compose.editing.Chip
|
||||
import com.moez.QKSMS.interactor.AddScheduledMessage
|
||||
import com.moez.QKSMS.interactor.CancelDelayedMessage
|
||||
import com.moez.QKSMS.interactor.DeleteMessages
|
||||
@@ -49,6 +48,7 @@ import com.moez.QKSMS.model.Attachment
|
||||
import com.moez.QKSMS.model.Attachments
|
||||
import com.moez.QKSMS.model.Conversation
|
||||
import com.moez.QKSMS.model.Message
|
||||
import com.moez.QKSMS.model.Recipient
|
||||
import com.moez.QKSMS.repository.ContactRepository
|
||||
import com.moez.QKSMS.repository.ConversationRepository
|
||||
import com.moez.QKSMS.repository.MessageRepository
|
||||
@@ -104,10 +104,10 @@ class ComposeViewModel @Inject constructor(
|
||||
) {
|
||||
|
||||
private val attachments: Subject<List<Attachment>> = BehaviorSubject.createDefault(sharedAttachments)
|
||||
private val chipsReducer: Subject<(List<Chip>) -> List<Chip>> = PublishSubject.create()
|
||||
private val chipsReducer: Subject<(List<Recipient>) -> List<Recipient>> = PublishSubject.create()
|
||||
private val conversation: Subject<Conversation> = BehaviorSubject.create()
|
||||
private val messages: Subject<List<Message>> = BehaviorSubject.create()
|
||||
private val selectedChips: Subject<List<Chip>> = BehaviorSubject.createDefault(listOf())
|
||||
private val selectedChips: Subject<List<Recipient>> = BehaviorSubject.createDefault(listOf())
|
||||
private val searchResults: Subject<List<Message>> = BehaviorSubject.create()
|
||||
private val searchSelection: Subject<Long> = BehaviorSubject.createDefault(-1)
|
||||
|
||||
@@ -163,11 +163,11 @@ class ComposeViewModel @Inject constructor(
|
||||
.subscribe(conversation::onNext)
|
||||
|
||||
if (addresses.isNotEmpty()) {
|
||||
selectedChips.onNext(addresses.map { address -> Chip(address) })
|
||||
selectedChips.onNext(addresses.map { address -> Recipient(address = address) })
|
||||
}
|
||||
|
||||
disposables += chipsReducer
|
||||
.scan(listOf<Chip>()) { previousState, reducer -> reducer(previousState) }
|
||||
.scan(listOf<Recipient>()) { previousState, reducer -> reducer(previousState) }
|
||||
.doOnNext { chips -> newState { copy(selectedChips = chips) } }
|
||||
.skipUntil(state.filter { state -> state.editingMode })
|
||||
.takeUntil(state.filter { state -> !state.editingMode })
|
||||
@@ -241,13 +241,19 @@ class ComposeViewModel @Inject constructor(
|
||||
}
|
||||
// Filter out any numbers that are already selected
|
||||
hashmap.filter { (address) ->
|
||||
chips.none { chip -> phoneNumberUtils.compare(address, chip.address) }
|
||||
chips.none { recipient -> phoneNumberUtils.compare(address, recipient.address) }
|
||||
}
|
||||
}
|
||||
.filter { hashmap -> hashmap.isNotEmpty() }
|
||||
.map { hashmap ->
|
||||
hashmap.map { (address, lookupKey) ->
|
||||
Chip(address, lookupKey?.let(contactRepo::getUnmanagedContact))
|
||||
conversationRepo.getRecipients()
|
||||
.asSequence()
|
||||
.filter { recipient -> recipient.contact?.lookupKey == lookupKey }
|
||||
.first { recipient -> phoneNumberUtils.compare(recipient.address, address) }
|
||||
?: Recipient(
|
||||
address = address,
|
||||
contact = lookupKey?.let(contactRepo::getUnmanagedContact))
|
||||
}
|
||||
}
|
||||
.autoDisposable(view.scope())
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2019 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 com.moez.QKSMS.feature.compose.editing
|
||||
|
||||
import com.moez.QKSMS.model.Contact
|
||||
|
||||
data class Chip(
|
||||
val address: String,
|
||||
val contact: Contact? = null
|
||||
)
|
||||
@@ -35,10 +35,10 @@ import io.reactivex.subjects.PublishSubject
|
||||
import kotlinx.android.synthetic.main.contact_chip.*
|
||||
import javax.inject.Inject
|
||||
|
||||
class ChipsAdapter @Inject constructor() : QkAdapter<Chip>() {
|
||||
class ChipsAdapter @Inject constructor() : QkAdapter<Recipient>() {
|
||||
|
||||
var view: RecyclerView? = null
|
||||
val chipDeleted: PublishSubject<Chip> = PublishSubject.create<Chip>()
|
||||
val chipDeleted: PublishSubject<Recipient> = PublishSubject.create<Recipient>()
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): QkViewHolder {
|
||||
val inflater = LayoutInflater.from(parent.context)
|
||||
@@ -57,18 +57,18 @@ class ChipsAdapter @Inject constructor() : QkAdapter<Chip>() {
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: QkViewHolder, position: Int) {
|
||||
val chip = getItem(position)
|
||||
val recipient = getItem(position)
|
||||
|
||||
holder.avatar.setRecipient(Recipient(id = -1, contact = chip.contact))
|
||||
holder.name.text = chip.contact?.name?.takeIf { it.isNotBlank() } ?: chip.address
|
||||
holder.avatar.setRecipient(recipient)
|
||||
holder.name.text = recipient.contact?.name?.takeIf { it.isNotBlank() } ?: recipient.address
|
||||
}
|
||||
|
||||
/**
|
||||
* The [context] has to come from a view, because we're inflating a view that used themed attrs
|
||||
*/
|
||||
private fun showDetailedChip(context: Context, chip: Chip) {
|
||||
private fun showDetailedChip(context: Context, recipient: Recipient) {
|
||||
val detailedChipView = DetailedChipView(context)
|
||||
detailedChipView.setChip(chip)
|
||||
detailedChipView.setRecipient(recipient)
|
||||
|
||||
val rootView = view?.rootView as ViewGroup
|
||||
|
||||
@@ -83,7 +83,7 @@ class ChipsAdapter @Inject constructor() : QkAdapter<Chip>() {
|
||||
detailedChipView.show()
|
||||
|
||||
detailedChipView.setOnDeleteListener {
|
||||
chipDeleted.onNext(chip)
|
||||
chipDeleted.onNext(recipient)
|
||||
detailedChipView.hide()
|
||||
}
|
||||
}
|
||||
|
||||
+7
-7
@@ -45,8 +45,14 @@ class DetailedChipView(context: Context) : RelativeLayout(context) {
|
||||
|
||||
isFocusable = true
|
||||
isFocusableInTouchMode = true
|
||||
}
|
||||
|
||||
colors.theme().let { theme ->
|
||||
fun setRecipient(recipient: Recipient) {
|
||||
avatar.setRecipient(recipient)
|
||||
name.text = recipient.contact?.name?.takeIf { it.isNotBlank() } ?: recipient.address
|
||||
info.text = recipient.address
|
||||
|
||||
colors.theme(recipient).let { theme ->
|
||||
card.setBackgroundTint(theme.theme)
|
||||
name.setTextColor(theme.textPrimary)
|
||||
info.setTextColor(theme.textTertiary)
|
||||
@@ -54,12 +60,6 @@ class DetailedChipView(context: Context) : RelativeLayout(context) {
|
||||
}
|
||||
}
|
||||
|
||||
fun setChip(chip: Chip) {
|
||||
avatar.setRecipient(Recipient(id = -1, contact = chip.contact))
|
||||
name.text = chip.contact?.name?.takeIf { it.isNotBlank() } ?: chip.address
|
||||
info.text = chip.address
|
||||
}
|
||||
|
||||
fun show() {
|
||||
startAnimation(AlphaAnimation(0f, 1f).apply { duration = 200 })
|
||||
|
||||
|
||||
@@ -22,7 +22,6 @@ import android.view.inputmethod.EditorInfo
|
||||
import com.moez.QKSMS.common.base.QkViewModel
|
||||
import com.moez.QKSMS.extensions.mapNotNull
|
||||
import com.moez.QKSMS.extensions.removeAccents
|
||||
import com.moez.QKSMS.feature.compose.editing.Chip
|
||||
import com.moez.QKSMS.feature.compose.editing.ComposeItem
|
||||
import com.moez.QKSMS.feature.compose.editing.PhoneNumberAction
|
||||
import com.moez.QKSMS.filter.ContactFilter
|
||||
@@ -32,6 +31,7 @@ import com.moez.QKSMS.model.Contact
|
||||
import com.moez.QKSMS.model.ContactGroup
|
||||
import com.moez.QKSMS.model.Conversation
|
||||
import com.moez.QKSMS.model.PhoneNumber
|
||||
import com.moez.QKSMS.model.Recipient
|
||||
import com.moez.QKSMS.repository.ContactRepository
|
||||
import com.moez.QKSMS.repository.ConversationRepository
|
||||
import com.moez.QKSMS.util.PhoneNumberUtils
|
||||
@@ -68,7 +68,7 @@ class ContactsViewModel @Inject constructor(
|
||||
.observeOn(Schedulers.io())
|
||||
.map { hashmap ->
|
||||
hashmap.map { (address, lookupKey) ->
|
||||
Chip(address, lookupKey?.let(contactsRepo::getUnmanagedContact))
|
||||
Recipient(address = address, contact = lookupKey?.let(contactsRepo::getUnmanagedContact))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -181,11 +181,10 @@ class ContactsViewModel @Inject constructor(
|
||||
.observeOn(Schedulers.io())
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { (composeItem, force) ->
|
||||
val contacts = composeItem.getContacts()
|
||||
val newChips = contacts.map { contact ->
|
||||
view.finish(HashMap(composeItem.getContacts().associate { contact ->
|
||||
if (contact.numbers.size == 1 || contact.getDefaultNumber() != null && !force) {
|
||||
val number = contact.getDefaultNumber() ?: contact.numbers[0]!!
|
||||
Chip(number.address, contact)
|
||||
val address = contact.getDefaultNumber()?.address ?: contact.numbers[0]!!.address
|
||||
address to contact.lookupKey
|
||||
} else {
|
||||
runBlocking {
|
||||
newState { copy(selectedContact = contact) }
|
||||
@@ -203,12 +202,10 @@ class ContactsViewModel @Inject constructor(
|
||||
setDefaultPhoneNumber.execute(params)
|
||||
}
|
||||
|
||||
Chip(number.address, contact)
|
||||
number.address to contact.lookupKey
|
||||
} ?: return@subscribe
|
||||
}
|
||||
}
|
||||
|
||||
view.finish(HashMap(newChips.associate { chip -> chip.address to chip.contact?.lookupKey }))
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user