forked from upstream-mirrors/quik
Allow clicking anywhere in row to click through to conversation
This commit is contained in:
@@ -31,6 +31,7 @@ import com.moez.QKSMS.mapper.CursorToRecipient
|
||||
import com.moez.QKSMS.model.Contact
|
||||
import com.moez.QKSMS.model.Conversation
|
||||
import com.moez.QKSMS.model.Message
|
||||
import com.moez.QKSMS.model.Recipient
|
||||
import com.moez.QKSMS.model.SearchResult
|
||||
import com.moez.QKSMS.util.tryOrNull
|
||||
import io.realm.Case
|
||||
@@ -153,6 +154,13 @@ class ConversationRepositoryImpl @Inject constructor(
|
||||
.findAll()
|
||||
}
|
||||
|
||||
override fun getRecipient(recipientId: Long): Recipient? {
|
||||
return Realm.getDefaultInstance()
|
||||
.where(Recipient::class.java)
|
||||
.equalTo("id", recipientId)
|
||||
.findFirst()
|
||||
}
|
||||
|
||||
override fun getThreadId(recipient: String): Long? {
|
||||
return getThreadId(listOf(recipient))
|
||||
}
|
||||
|
||||
@@ -37,4 +37,4 @@ open class Recipient(
|
||||
?: PhoneNumberUtils.formatNumber(address, Locale.getDefault().country)
|
||||
?: address
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
package com.moez.QKSMS.repository
|
||||
|
||||
import com.moez.QKSMS.model.Conversation
|
||||
import com.moez.QKSMS.model.Recipient
|
||||
import com.moez.QKSMS.model.SearchResult
|
||||
import io.realm.RealmResults
|
||||
|
||||
@@ -50,6 +51,8 @@ interface ConversationRepository {
|
||||
*/
|
||||
fun getConversations(vararg threadIds: Long): RealmResults<Conversation>
|
||||
|
||||
fun getRecipient(recipientId: Long): Recipient?
|
||||
|
||||
fun getThreadId(recipient: String): Long?
|
||||
|
||||
fun getThreadId(recipients: Collection<String>): Long?
|
||||
|
||||
@@ -238,6 +238,13 @@ class Navigator @Inject constructor(
|
||||
startActivityExternal(intent)
|
||||
}
|
||||
|
||||
fun showContact(lookupKey: String) {
|
||||
val intent = Intent(Intent.ACTION_VIEW)
|
||||
.setData(Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_LOOKUP_URI, lookupKey))
|
||||
|
||||
startActivityExternal(intent)
|
||||
}
|
||||
|
||||
fun saveVcard(uri: Uri) {
|
||||
val intent = Intent(Intent.ACTION_VIEW)
|
||||
.setDataAndType(uri, "text/x-vcard")
|
||||
|
||||
@@ -19,8 +19,6 @@
|
||||
package com.moez.QKSMS.common.widget
|
||||
|
||||
import android.content.Context
|
||||
import android.net.Uri
|
||||
import android.provider.ContactsContract
|
||||
import android.telephony.PhoneNumberUtils
|
||||
import android.util.AttributeSet
|
||||
import android.view.View
|
||||
@@ -32,19 +30,15 @@ import com.moez.QKSMS.common.util.Colors
|
||||
import com.moez.QKSMS.common.util.extensions.setBackgroundTint
|
||||
import com.moez.QKSMS.common.util.extensions.setTint
|
||||
import com.moez.QKSMS.injection.appComponent
|
||||
import com.moez.QKSMS.listener.ContactAddedListener
|
||||
import com.moez.QKSMS.model.Contact
|
||||
import com.moez.QKSMS.model.Recipient
|
||||
import com.moez.QKSMS.util.GlideApp
|
||||
import com.uber.autodispose.android.ViewScopeProvider
|
||||
import com.uber.autodispose.autoDisposable
|
||||
import kotlinx.android.synthetic.main.avatar_view.view.*
|
||||
import javax.inject.Inject
|
||||
|
||||
class AvatarView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : FrameLayout(context, attrs) {
|
||||
|
||||
@Inject lateinit var colors: Colors
|
||||
@Inject lateinit var contactAddedListener: ContactAddedListener
|
||||
@Inject lateinit var navigator: Navigator
|
||||
|
||||
/**
|
||||
@@ -71,24 +65,6 @@ class AvatarView @JvmOverloads constructor(context: Context, attrs: AttributeSet
|
||||
|
||||
setBackgroundResource(R.drawable.circle)
|
||||
clipToOutline = true
|
||||
|
||||
setOnClickListener {
|
||||
if (lookupKey.isNullOrEmpty()) {
|
||||
address?.let { address ->
|
||||
// Allow the user to add the contact
|
||||
navigator.addContact(address)
|
||||
|
||||
// Listen for contact changes
|
||||
contactAddedListener.listen(address)
|
||||
.autoDisposable(ViewScopeProvider.from(this))
|
||||
.subscribe()
|
||||
}
|
||||
} else {
|
||||
val uri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_LOOKUP_URI, lookupKey)
|
||||
ContactsContract.QuickContact.showQuickContact(context, this@AvatarView, uri,
|
||||
ContactsContract.QuickContact.MODE_MEDIUM, null)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+2
@@ -91,6 +91,8 @@ class ConversationInfoController(
|
||||
showBackButton(true)
|
||||
}
|
||||
|
||||
override fun recipientClicks(): Observable<Long> = recipientAdapter.clicks
|
||||
|
||||
override fun nameClicks(): Observable<*> = name.clicks()
|
||||
|
||||
override fun nameChanges(): Observable<String> = nameChangeSubject
|
||||
|
||||
+24
@@ -18,18 +18,23 @@
|
||||
*/
|
||||
package com.moez.QKSMS.feature.conversationinfo
|
||||
|
||||
import android.content.Context
|
||||
import androidx.lifecycle.Lifecycle
|
||||
import com.moez.QKSMS.common.Navigator
|
||||
import com.moez.QKSMS.common.base.QkPresenter
|
||||
import com.moez.QKSMS.extensions.asObservable
|
||||
import com.moez.QKSMS.extensions.mapNotNull
|
||||
import com.moez.QKSMS.interactor.DeleteConversations
|
||||
import com.moez.QKSMS.interactor.MarkArchived
|
||||
import com.moez.QKSMS.interactor.MarkUnarchived
|
||||
import com.moez.QKSMS.listener.ContactAddedListener
|
||||
import com.moez.QKSMS.manager.PermissionManager
|
||||
import com.moez.QKSMS.model.Conversation
|
||||
import com.moez.QKSMS.repository.ConversationRepository
|
||||
import com.moez.QKSMS.repository.MessageRepository
|
||||
import com.uber.autodispose.android.lifecycle.scope
|
||||
import com.uber.autodispose.autoDisposable
|
||||
import io.reactivex.Observable
|
||||
import io.reactivex.rxkotlin.plusAssign
|
||||
import io.reactivex.rxkotlin.withLatestFrom
|
||||
import io.reactivex.subjects.BehaviorSubject
|
||||
@@ -40,6 +45,8 @@ import javax.inject.Named
|
||||
class ConversationInfoPresenter @Inject constructor(
|
||||
@Named("threadId") threadId: Long,
|
||||
messageRepo: MessageRepository,
|
||||
private val contactAddedListener: ContactAddedListener,
|
||||
private val context: Context,
|
||||
private val conversationRepo: ConversationRepository,
|
||||
private val deleteConversations: DeleteConversations,
|
||||
private val markArchived: MarkArchived,
|
||||
@@ -97,6 +104,23 @@ class ConversationInfoPresenter @Inject constructor(
|
||||
override fun bindIntents(view: ConversationInfoView) {
|
||||
super.bindIntents(view)
|
||||
|
||||
// Add or display the contact
|
||||
view.recipientClicks()
|
||||
.mapNotNull(conversationRepo::getRecipient)
|
||||
.flatMap { recipient ->
|
||||
val lookupKey = recipient.contact?.lookupKey
|
||||
if (lookupKey != null) {
|
||||
navigator.showContact(lookupKey)
|
||||
Observable.empty<Unit>()
|
||||
} else {
|
||||
// Allow the user to add the contact, then listen for changes
|
||||
navigator.addContact(recipient.address)
|
||||
contactAddedListener.listen(recipient.address)
|
||||
}
|
||||
}
|
||||
.autoDisposable(view.scope(Lifecycle.Event.ON_DESTROY)) // ... this should be the default
|
||||
.subscribe()
|
||||
|
||||
// Show the conversation title dialog
|
||||
view.nameClicks()
|
||||
.withLatestFrom(conversation) { _, conversation -> conversation }
|
||||
|
||||
+1
@@ -23,6 +23,7 @@ import io.reactivex.Observable
|
||||
|
||||
interface ConversationInfoView : QkViewContract<ConversationInfoState> {
|
||||
|
||||
fun recipientClicks(): Observable<Long>
|
||||
fun nameClicks(): Observable<*>
|
||||
fun nameChanges(): Observable<String>
|
||||
fun notificationClicks(): Observable<*>
|
||||
|
||||
+6
-9
@@ -22,21 +22,22 @@ import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.moez.QKSMS.R
|
||||
import com.moez.QKSMS.common.Navigator
|
||||
import com.moez.QKSMS.common.base.QkRealmAdapter
|
||||
import com.moez.QKSMS.common.base.QkViewHolder
|
||||
import com.moez.QKSMS.common.util.extensions.setVisible
|
||||
import com.moez.QKSMS.model.Recipient
|
||||
import io.reactivex.disposables.CompositeDisposable
|
||||
import io.reactivex.subjects.PublishSubject
|
||||
import io.reactivex.subjects.Subject
|
||||
import kotlinx.android.synthetic.main.conversation_recipient_list_item.view.*
|
||||
import javax.inject.Inject
|
||||
|
||||
class ConversationRecipientAdapter @Inject constructor(
|
||||
private val navigator: Navigator
|
||||
) : QkRealmAdapter<Recipient>() {
|
||||
class ConversationRecipientAdapter @Inject constructor() : QkRealmAdapter<Recipient>() {
|
||||
|
||||
var threadId: Long = 0L
|
||||
|
||||
val clicks: Subject<Long> = PublishSubject.create()
|
||||
|
||||
private val disposables = CompositeDisposable()
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): QkViewHolder {
|
||||
@@ -45,11 +46,7 @@ class ConversationRecipientAdapter @Inject constructor(
|
||||
return QkViewHolder(view).apply {
|
||||
view.setOnClickListener {
|
||||
val recipient = getItem(adapterPosition) ?: return@setOnClickListener
|
||||
if (recipient.contact == null) {
|
||||
navigator.addContact(recipient.address)
|
||||
} else {
|
||||
view.avatar.callOnClick()
|
||||
}
|
||||
clicks.onNext(recipient.id)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user