forked from upstream-mirrors/quik
Revert "Implement ViewBinding"
This reverts commit 37d8c45379.
# Conflicts:
# build.gradle
# presentation/src/main/java/com/moez/QKSMS/common/widget/AvatarView.kt
# presentation/src/main/java/com/moez/QKSMS/common/widget/TextInputDialog.kt
# presentation/src/main/java/com/moez/QKSMS/feature/compose/ComposeActivity.kt
# presentation/src/main/java/com/moez/QKSMS/feature/compose/MessagesAdapter.kt
# presentation/src/main/java/com/moez/QKSMS/feature/conversationinfo/ConversationInfoController.kt
# presentation/src/main/java/com/moez/QKSMS/feature/conversations/ConversationsAdapter.kt
# presentation/src/main/java/com/moez/QKSMS/feature/main/MainActivity.kt
# presentation/src/main/java/com/moez/QKSMS/feature/settings/SettingsController.kt
This commit is contained in:
@@ -19,13 +19,12 @@
|
||||
package com.moez.QKSMS.feature.compose
|
||||
|
||||
import android.content.Context
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import androidx.viewbinding.ViewBinding
|
||||
import com.bumptech.glide.Glide
|
||||
import com.moez.QKSMS.R
|
||||
import com.moez.QKSMS.common.base.QkAdapter
|
||||
import com.moez.QKSMS.common.base.QkViewHolder
|
||||
import com.moez.QKSMS.databinding.AttachmentContactListItemBinding
|
||||
import com.moez.QKSMS.databinding.AttachmentImageListItemBinding
|
||||
import com.moez.QKSMS.extensions.mapNotNull
|
||||
import com.moez.QKSMS.model.Attachment
|
||||
import ezvcard.Ezvcard
|
||||
@@ -34,11 +33,14 @@ import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
import io.reactivex.schedulers.Schedulers
|
||||
import io.reactivex.subjects.PublishSubject
|
||||
import io.reactivex.subjects.Subject
|
||||
import kotlinx.android.synthetic.main.attachment_contact_list_item.*
|
||||
import kotlinx.android.synthetic.main.attachment_image_list_item.*
|
||||
import kotlinx.android.synthetic.main.attachment_image_list_item.view.*
|
||||
import javax.inject.Inject
|
||||
|
||||
class AttachmentAdapter @Inject constructor(
|
||||
private val context: Context
|
||||
) : QkAdapter<Attachment, ViewBinding>() {
|
||||
) : QkAdapter<Attachment>() {
|
||||
|
||||
companion object {
|
||||
private const val VIEW_TYPE_IMAGE = 0
|
||||
@@ -47,42 +49,38 @@ class AttachmentAdapter @Inject constructor(
|
||||
|
||||
val attachmentDeleted: Subject<Attachment> = PublishSubject.create()
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): QkViewHolder<ViewBinding> {
|
||||
val holder: QkViewHolder<ViewBinding> = when (viewType) {
|
||||
VIEW_TYPE_IMAGE -> QkViewHolder(parent, AttachmentImageListItemBinding::inflate)
|
||||
VIEW_TYPE_CONTACT -> QkViewHolder(parent, AttachmentContactListItemBinding::inflate)
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): QkViewHolder {
|
||||
val inflater = LayoutInflater.from(parent.context)
|
||||
val view = when (viewType) {
|
||||
VIEW_TYPE_IMAGE -> inflater.inflate(R.layout.attachment_image_list_item, parent, false)
|
||||
.apply { thumbnailBounds.clipToOutline = true }
|
||||
|
||||
VIEW_TYPE_CONTACT -> inflater.inflate(R.layout.attachment_contact_list_item, parent, false)
|
||||
|
||||
else -> null!! // Impossible
|
||||
}
|
||||
|
||||
return holder.apply {
|
||||
if (binding is AttachmentImageListItemBinding) {
|
||||
binding.thumbnailBounds.clipToOutline = true
|
||||
}
|
||||
|
||||
binding.root.setOnClickListener {
|
||||
return QkViewHolder(view).apply {
|
||||
view.setOnClickListener {
|
||||
val attachment = getItem(adapterPosition)
|
||||
attachmentDeleted.onNext(attachment)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: QkViewHolder<ViewBinding>, position: Int) {
|
||||
override fun onBindViewHolder(holder: QkViewHolder, position: Int) {
|
||||
val attachment = getItem(position)
|
||||
|
||||
when {
|
||||
attachment is Attachment.Image && holder.binding is AttachmentImageListItemBinding -> {
|
||||
Glide.with(context)
|
||||
.load(attachment.getUri())
|
||||
.into(holder.binding.thumbnail)
|
||||
}
|
||||
when (attachment) {
|
||||
is Attachment.Image -> Glide.with(context)
|
||||
.load(attachment.getUri())
|
||||
.into(holder.thumbnail)
|
||||
|
||||
attachment is Attachment.Contact && holder.binding is AttachmentContactListItemBinding -> {
|
||||
Observable.just(attachment.vCard)
|
||||
.mapNotNull { vCard -> Ezvcard.parse(vCard).first() }
|
||||
.subscribeOn(Schedulers.computation())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe { vcard -> holder.binding.name.text = vcard.formattedName.value }
|
||||
}
|
||||
is Attachment.Contact -> Observable.just(attachment.vCard)
|
||||
.mapNotNull { vCard -> Ezvcard.parse(vCard).first() }
|
||||
.subscribeOn(Schedulers.computation())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe { vcard -> holder.name?.text = vcard.formattedName.value }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -55,8 +55,6 @@ 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.common.util.extensions.viewBinding
|
||||
import com.moez.QKSMS.databinding.ComposeActivityBinding
|
||||
import com.moez.QKSMS.feature.compose.editing.ChipsAdapter
|
||||
import com.moez.QKSMS.feature.contacts.ContactsActivity
|
||||
import com.moez.QKSMS.model.Attachment
|
||||
@@ -67,6 +65,7 @@ import dagger.android.AndroidInjection
|
||||
import io.reactivex.Observable
|
||||
import io.reactivex.subjects.PublishSubject
|
||||
import io.reactivex.subjects.Subject
|
||||
import kotlinx.android.synthetic.main.compose_activity.*
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.*
|
||||
import javax.inject.Inject
|
||||
@@ -95,29 +94,28 @@ class ComposeActivity : QkThemedActivity(), ComposeView {
|
||||
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 { binding.sendAsGroupBackground.clicks() }
|
||||
override val sendAsGroupIntent by lazy { sendAsGroupBackground.clicks() }
|
||||
override val messageClickIntent: Subject<Long> by lazy { messageAdapter.clicks }
|
||||
override val messagePartClickIntent: Subject<Long> by lazy { messageAdapter.partClicks }
|
||||
override val messagesSelectedIntent by lazy { messageAdapter.selectionChanges }
|
||||
override val cancelSendingIntent: Subject<Long> by lazy { messageAdapter.cancelSending }
|
||||
override val attachmentDeletedIntent: Subject<Attachment> by lazy { attachmentAdapter.attachmentDeleted }
|
||||
override val textChangedIntent by lazy { binding.message.textChanges() }
|
||||
override val attachIntent by lazy { Observable.merge(binding.attach.clicks(), binding.attachingBackground.clicks()) }
|
||||
override val cameraIntent by lazy { Observable.merge(binding.camera.clicks(), binding.cameraLabel.clicks()) }
|
||||
override val galleryIntent by lazy { Observable.merge(binding.gallery.clicks(), binding.galleryLabel.clicks()) }
|
||||
override val scheduleIntent by lazy { Observable.merge(binding.schedule.clicks(), binding.scheduleLabel.clicks()) }
|
||||
override val attachContactIntent by lazy { Observable.merge(binding.contact.clicks(), binding.contactLabel.clicks()) }
|
||||
override val textChangedIntent by lazy { message.textChanges() }
|
||||
override val attachIntent by lazy { Observable.merge(attach.clicks(), attachingBackground.clicks()) }
|
||||
override val cameraIntent by lazy { Observable.merge(camera.clicks(), cameraLabel.clicks()) }
|
||||
override val galleryIntent by lazy { Observable.merge(gallery.clicks(), galleryLabel.clicks()) }
|
||||
override val scheduleIntent by lazy { Observable.merge(schedule.clicks(), scheduleLabel.clicks()) }
|
||||
override val attachContactIntent by lazy { Observable.merge(contact.clicks(), contactLabel.clicks()) }
|
||||
override val attachmentSelectedIntent: Subject<Uri> = PublishSubject.create()
|
||||
override val contactSelectedIntent: Subject<Uri> = PublishSubject.create()
|
||||
override val inputContentIntent by lazy { binding.message.inputContentSelected }
|
||||
override val inputContentIntent by lazy { message.inputContentSelected }
|
||||
override val scheduleSelectedIntent: Subject<Long> = PublishSubject.create()
|
||||
override val changeSimIntent by lazy { binding.sim.clicks() }
|
||||
override val scheduleCancelIntent by lazy { binding.scheduledCancel.clicks() }
|
||||
override val sendIntent by lazy { binding.send.clicks() }
|
||||
override val changeSimIntent by lazy { sim.clicks() }
|
||||
override val scheduleCancelIntent by lazy { scheduledCancel.clicks() }
|
||||
override val sendIntent by lazy { send.clicks() }
|
||||
override val viewQksmsPlusIntent: Subject<Unit> = PublishSubject.create()
|
||||
override val backPressedIntent: Subject<Unit> = PublishSubject.create()
|
||||
|
||||
private val binding by viewBinding(ComposeActivityBinding::inflate)
|
||||
private val viewModel by lazy { ViewModelProviders.of(this, viewModelFactory)[ComposeViewModel::class.java] }
|
||||
|
||||
private var cameraDestination: Uri? = null
|
||||
@@ -125,33 +123,33 @@ class ComposeActivity : QkThemedActivity(), ComposeView {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
AndroidInjection.inject(this)
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(binding.root)
|
||||
setContentView(R.layout.compose_activity)
|
||||
showBackButton(true)
|
||||
viewModel.bindView(this)
|
||||
|
||||
binding.contentView.layoutTransition = LayoutTransition().apply {
|
||||
contentView.layoutTransition = LayoutTransition().apply {
|
||||
disableTransitionType(LayoutTransition.CHANGING)
|
||||
}
|
||||
|
||||
chipsAdapter.view = binding.chips
|
||||
chipsAdapter.view = chips
|
||||
|
||||
binding.chips.itemAnimator = null
|
||||
binding.chips.layoutManager = FlexboxLayoutManager(this)
|
||||
chips.itemAnimator = null
|
||||
chips.layoutManager = FlexboxLayoutManager(this)
|
||||
|
||||
messageAdapter.autoScrollToStart(binding.messageList)
|
||||
messageAdapter.emptyView = binding.messagesEmpty
|
||||
messageAdapter.autoScrollToStart(messageList)
|
||||
messageAdapter.emptyView = messagesEmpty
|
||||
|
||||
binding.messageList.setHasFixedSize(true)
|
||||
binding.messageList.adapter = messageAdapter
|
||||
messageList.setHasFixedSize(true)
|
||||
messageList.adapter = messageAdapter
|
||||
|
||||
binding.attachments.adapter = attachmentAdapter
|
||||
attachments.adapter = attachmentAdapter
|
||||
|
||||
binding.message.supportsInputContent = true
|
||||
message.supportsInputContent = true
|
||||
|
||||
theme
|
||||
.doOnNext { binding.loading.setTint(it.theme) }
|
||||
.doOnNext { binding.attach.setBackgroundTint(it.theme) }
|
||||
.doOnNext { binding.attach.setTint(it.textPrimary) }
|
||||
.doOnNext { loading.setTint(it.theme) }
|
||||
.doOnNext { attach.setBackgroundTint(it.theme) }
|
||||
.doOnNext { attach.setTint(it.textPrimary) }
|
||||
.doOnNext { messageAdapter.theme = it }
|
||||
.autoDisposable(scope())
|
||||
.subscribe()
|
||||
@@ -160,7 +158,7 @@ class ComposeActivity : QkThemedActivity(), ComposeView {
|
||||
|
||||
// These theme attributes don't apply themselves on API 21
|
||||
if (Build.VERSION.SDK_INT <= 22) {
|
||||
binding.messageBackground.setBackgroundTint(resolveThemeColor(R.attr.bubbleColor))
|
||||
messageBackground.setBackgroundTint(resolveThemeColor(R.attr.bubbleColor))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -188,59 +186,59 @@ class ComposeActivity : QkThemedActivity(), ComposeView {
|
||||
else -> state.conversationtitle
|
||||
}
|
||||
|
||||
binding.toolbarSubtitle.setVisible(state.query.isNotEmpty())
|
||||
binding.toolbarSubtitle.text = getString(R.string.compose_subtitle_results, state.searchSelectionPosition,
|
||||
toolbarSubtitle.setVisible(state.query.isNotEmpty())
|
||||
toolbarSubtitle.text = getString(R.string.compose_subtitle_results, state.searchSelectionPosition,
|
||||
state.searchResults)
|
||||
|
||||
binding.toolbarTitle.setVisible(!state.editingMode)
|
||||
binding.chips.setVisible(state.editingMode)
|
||||
binding.composeBar.setVisible(!state.loading)
|
||||
toolbarTitle.setVisible(!state.editingMode)
|
||||
chips.setVisible(state.editingMode)
|
||||
composeBar.setVisible(!state.loading)
|
||||
|
||||
// Don't set the adapters unless needed
|
||||
if (state.editingMode && binding.chips.adapter == null) binding.chips.adapter = chipsAdapter
|
||||
if (state.editingMode && chips.adapter == null) chips.adapter = chipsAdapter
|
||||
|
||||
binding.toolbar.menu.findItem(R.id.add)?.isVisible = state.editingMode
|
||||
binding.toolbar.menu.findItem(R.id.call)?.isVisible = !state.editingMode && state.selectedMessages == 0
|
||||
toolbar.menu.findItem(R.id.add)?.isVisible = state.editingMode
|
||||
toolbar.menu.findItem(R.id.call)?.isVisible = !state.editingMode && state.selectedMessages == 0
|
||||
&& state.query.isEmpty()
|
||||
binding.toolbar.menu.findItem(R.id.info)?.isVisible = !state.editingMode && state.selectedMessages == 0
|
||||
toolbar.menu.findItem(R.id.info)?.isVisible = !state.editingMode && state.selectedMessages == 0
|
||||
&& state.query.isEmpty()
|
||||
binding.toolbar.menu.findItem(R.id.copy)?.isVisible = !state.editingMode && state.selectedMessages > 0
|
||||
binding.toolbar.menu.findItem(R.id.details)?.isVisible = !state.editingMode && state.selectedMessages == 1
|
||||
binding.toolbar.menu.findItem(R.id.delete)?.isVisible = !state.editingMode && state.selectedMessages > 0
|
||||
binding.toolbar.menu.findItem(R.id.forward)?.isVisible = !state.editingMode && state.selectedMessages == 1
|
||||
binding.toolbar.menu.findItem(R.id.previous)?.isVisible = state.selectedMessages == 0 && state.query.isNotEmpty()
|
||||
binding.toolbar.menu.findItem(R.id.next)?.isVisible = state.selectedMessages == 0 && state.query.isNotEmpty()
|
||||
binding.toolbar.menu.findItem(R.id.clear)?.isVisible = state.selectedMessages == 0 && state.query.isNotEmpty()
|
||||
toolbar.menu.findItem(R.id.copy)?.isVisible = !state.editingMode && state.selectedMessages > 0
|
||||
toolbar.menu.findItem(R.id.details)?.isVisible = !state.editingMode && state.selectedMessages == 1
|
||||
toolbar.menu.findItem(R.id.delete)?.isVisible = !state.editingMode && state.selectedMessages > 0
|
||||
toolbar.menu.findItem(R.id.forward)?.isVisible = !state.editingMode && state.selectedMessages == 1
|
||||
toolbar.menu.findItem(R.id.previous)?.isVisible = state.selectedMessages == 0 && state.query.isNotEmpty()
|
||||
toolbar.menu.findItem(R.id.next)?.isVisible = state.selectedMessages == 0 && state.query.isNotEmpty()
|
||||
toolbar.menu.findItem(R.id.clear)?.isVisible = state.selectedMessages == 0 && state.query.isNotEmpty()
|
||||
|
||||
chipsAdapter.data = state.selectedChips
|
||||
|
||||
binding.loading.setVisible(state.loading)
|
||||
loading.setVisible(state.loading)
|
||||
|
||||
binding.sendAsGroup.setVisible(state.editingMode && state.selectedChips.size >= 2)
|
||||
binding.sendAsGroupSwitch.isChecked = state.sendAsGroup
|
||||
sendAsGroup.setVisible(state.editingMode && state.selectedChips.size >= 2)
|
||||
sendAsGroupSwitch.isChecked = state.sendAsGroup
|
||||
|
||||
binding.messageList.setVisible(!state.editingMode || state.sendAsGroup || state.selectedChips.size == 1)
|
||||
messageList.setVisible(!state.editingMode || state.sendAsGroup || state.selectedChips.size == 1)
|
||||
messageAdapter.data = state.messages
|
||||
messageAdapter.highlight = state.searchSelectionId
|
||||
|
||||
binding.scheduledGroup.isVisible = state.scheduled != 0L
|
||||
binding.scheduledTime.text = dateFormatter.getScheduledTimestamp(state.scheduled)
|
||||
scheduledGroup.isVisible = state.scheduled != 0L
|
||||
scheduledTime.text = dateFormatter.getScheduledTimestamp(state.scheduled)
|
||||
|
||||
binding.attachments.setVisible(state.attachments.isNotEmpty())
|
||||
attachments.setVisible(state.attachments.isNotEmpty())
|
||||
attachmentAdapter.data = state.attachments
|
||||
|
||||
binding.attach.animate().rotation(if (state.attaching) 135f else 0f).start()
|
||||
binding.attaching.isVisible = state.attaching
|
||||
attach.animate().rotation(if (state.attaching) 135f else 0f).start()
|
||||
attaching.isVisible = state.attaching
|
||||
|
||||
binding.counter.text = state.remaining
|
||||
binding.counter.setVisible(binding.counter.text.isNotBlank())
|
||||
counter.text = state.remaining
|
||||
counter.setVisible(counter.text.isNotBlank())
|
||||
|
||||
binding.sim.setVisible(state.subscription != null)
|
||||
binding.sim.contentDescription = getString(R.string.compose_sim_cd, state.subscription?.displayName)
|
||||
binding.simIndex.text = state.subscription?.simSlotIndex?.plus(1)?.toString()
|
||||
sim.setVisible(state.subscription != null)
|
||||
sim.contentDescription = getString(R.string.compose_sim_cd, state.subscription?.displayName)
|
||||
simIndex.text = state.subscription?.simSlotIndex?.plus(1)?.toString()
|
||||
|
||||
binding.send.isEnabled = state.canSend
|
||||
binding.send.imageAlpha = if (state.canSend) 255 else 128
|
||||
send.isEnabled = state.canSend
|
||||
send.imageAlpha = if (state.canSend) 255 else 128
|
||||
}
|
||||
|
||||
override fun clearSelection() = messageAdapter.clearSelection()
|
||||
@@ -282,7 +280,7 @@ class ComposeActivity : QkThemedActivity(), ComposeView {
|
||||
}, calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH)).show()
|
||||
|
||||
// On some devices, the keyboard can cover the date picker
|
||||
binding.message.hideKeyboard()
|
||||
message.hideKeyboard()
|
||||
}
|
||||
|
||||
override fun requestContact() {
|
||||
@@ -293,7 +291,7 @@ class ComposeActivity : QkThemedActivity(), ComposeView {
|
||||
}
|
||||
|
||||
override fun showContacts(sharing: Boolean, chips: List<Recipient>) {
|
||||
binding.message.hideKeyboard()
|
||||
message.hideKeyboard()
|
||||
val serialized = HashMap(chips.associate { chip -> chip.address to chip.contact?.lookupKey })
|
||||
val intent = Intent(this, ContactsActivity::class.java)
|
||||
.putExtra(ContactsActivity.SharingKey, sharing)
|
||||
@@ -302,12 +300,12 @@ class ComposeActivity : QkThemedActivity(), ComposeView {
|
||||
}
|
||||
|
||||
override fun themeChanged() {
|
||||
binding.messageList.scrapViews()
|
||||
messageList.scrapViews()
|
||||
}
|
||||
|
||||
override fun showKeyboard() {
|
||||
binding.message.postDelayed({
|
||||
binding.message.showKeyboard()
|
||||
message.postDelayed({
|
||||
message.showKeyboard()
|
||||
}, 200)
|
||||
}
|
||||
|
||||
@@ -332,19 +330,19 @@ class ComposeActivity : QkThemedActivity(), ComposeView {
|
||||
}
|
||||
|
||||
override fun setDraft(draft: String) {
|
||||
binding.message.setText(draft)
|
||||
binding.message.setSelection(draft.length)
|
||||
message.setText(draft)
|
||||
message.setSelection(draft.length)
|
||||
}
|
||||
|
||||
override fun scrollToMessage(id: Long) {
|
||||
messageAdapter.data?.second
|
||||
?.indexOfLast { message -> message.id == id }
|
||||
?.takeIf { position -> position != -1 }
|
||||
?.let(binding.messageList::scrollToPosition)
|
||||
?.let(messageList::scrollToPosition)
|
||||
}
|
||||
|
||||
override fun showQksmsPlusSnackbar(message: Int) {
|
||||
Snackbar.make(binding.contentView, message, Snackbar.LENGTH_LONG).run {
|
||||
Snackbar.make(contentView, message, Snackbar.LENGTH_LONG).run {
|
||||
setAction(R.string.button_more) { viewQksmsPlusIntent.onNext(Unit) }
|
||||
setActionTextColor(colors.theme().theme)
|
||||
show()
|
||||
|
||||
@@ -46,7 +46,6 @@ import com.moez.QKSMS.common.util.extensions.setPadding
|
||||
import com.moez.QKSMS.common.util.extensions.setTint
|
||||
import com.moez.QKSMS.common.util.extensions.setVisible
|
||||
import com.moez.QKSMS.compat.SubscriptionManagerCompat
|
||||
import com.moez.QKSMS.databinding.MessageListItemInBinding
|
||||
import com.moez.QKSMS.extensions.isSmil
|
||||
import com.moez.QKSMS.extensions.isText
|
||||
import com.moez.QKSMS.feature.compose.BubbleUtils.canGroup
|
||||
@@ -60,6 +59,15 @@ import com.moez.QKSMS.util.Preferences
|
||||
import io.reactivex.subjects.PublishSubject
|
||||
import io.reactivex.subjects.Subject
|
||||
import io.realm.RealmResults
|
||||
import kotlinx.android.synthetic.main.message_list_item_in.*
|
||||
import kotlinx.android.synthetic.main.message_list_item_in.attachments
|
||||
import kotlinx.android.synthetic.main.message_list_item_in.body
|
||||
import kotlinx.android.synthetic.main.message_list_item_in.sim
|
||||
import kotlinx.android.synthetic.main.message_list_item_in.simIndex
|
||||
import kotlinx.android.synthetic.main.message_list_item_in.status
|
||||
import kotlinx.android.synthetic.main.message_list_item_in.timestamp
|
||||
import kotlinx.android.synthetic.main.message_list_item_in.view.*
|
||||
import kotlinx.android.synthetic.main.message_list_item_out.*
|
||||
import java.util.*
|
||||
import java.util.concurrent.TimeUnit
|
||||
import javax.inject.Inject
|
||||
@@ -74,7 +82,7 @@ class MessagesAdapter @Inject constructor(
|
||||
private val phoneNumberUtils: PhoneNumberUtils,
|
||||
private val prefs: Preferences,
|
||||
private val textViewStyler: TextViewStyler
|
||||
) : QkRealmAdapter<Message, MessageListItemInBinding>() {
|
||||
) : QkRealmAdapter<Message>() {
|
||||
|
||||
companion object {
|
||||
private const val VIEW_TYPE_MESSAGE_IN = 0
|
||||
@@ -130,7 +138,7 @@ class MessagesAdapter @Inject constructor(
|
||||
* this a unique viewType even though it uses the same view, so that regular messages
|
||||
* don't need clipToOutline set to true, and they don't need to worry about images
|
||||
*/
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): QkViewHolder<MessageListItemInBinding> {
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): QkViewHolder {
|
||||
|
||||
// Use the parent's context to inflate the layout, otherwise link clicks will crash the app
|
||||
val layoutInflater = LayoutInflater.from(parent.context)
|
||||
@@ -144,26 +152,24 @@ class MessagesAdapter @Inject constructor(
|
||||
view = layoutInflater.inflate(R.layout.message_list_item_in, parent, false)
|
||||
}
|
||||
|
||||
val binding = MessageListItemInBinding.bind(view)
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
binding.body.hyphenationFrequency = Layout.HYPHENATION_FREQUENCY_NONE
|
||||
view.body.hyphenationFrequency = Layout.HYPHENATION_FREQUENCY_NONE
|
||||
}
|
||||
|
||||
val partsAdapter = partsAdapterProvider.get()
|
||||
partsAdapter.clicks.subscribe(partClicks)
|
||||
binding.attachments.adapter = partsAdapter
|
||||
binding.attachments.setRecycledViewPool(partsViewPool)
|
||||
binding.body.forwardTouches(view)
|
||||
view.attachments.adapter = partsAdapter
|
||||
view.attachments.setRecycledViewPool(partsViewPool)
|
||||
view.body.forwardTouches(view)
|
||||
|
||||
return QkViewHolder(binding).apply {
|
||||
return QkViewHolder(view).apply {
|
||||
view.setOnClickListener {
|
||||
val message = getItem(adapterPosition) ?: return@setOnClickListener
|
||||
when (toggleSelection(message.id, false)) {
|
||||
true -> view.isActivated = isSelected(message.id)
|
||||
false -> {
|
||||
clicks.onNext(message.id)
|
||||
expanded[message.id] = binding.status.visibility != View.VISIBLE
|
||||
expanded[message.id] = view.status.visibility != View.VISIBLE
|
||||
notifyItemChanged(adapterPosition)
|
||||
}
|
||||
}
|
||||
@@ -177,7 +183,7 @@ class MessagesAdapter @Inject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: QkViewHolder<MessageListItemInBinding>, position: Int) {
|
||||
override fun onBindViewHolder(holder: QkViewHolder, position: Int) {
|
||||
val message = getItem(position) ?: return
|
||||
val previous = if (position == 0) null else getItem(position - 1)
|
||||
val next = if (position == itemCount - 1) null else getItem(position + 1)
|
||||
@@ -188,10 +194,10 @@ class MessagesAdapter @Inject constructor(
|
||||
}
|
||||
|
||||
// Update the selected state
|
||||
holder.binding.root.isActivated = isSelected(message.id) || highlight == message.id
|
||||
holder.containerView.isActivated = isSelected(message.id) || highlight == message.id
|
||||
|
||||
// Bind the cancel view
|
||||
holder.binding.cancel.let { cancel ->
|
||||
holder.cancel?.let { cancel ->
|
||||
val isCancellable = message.isSending() && message.date > System.currentTimeMillis()
|
||||
cancel.setVisible(isCancellable)
|
||||
cancel.clicks().subscribe { cancelSending.onNext(message.id) }
|
||||
@@ -219,25 +225,26 @@ class MessagesAdapter @Inject constructor(
|
||||
val timeSincePrevious = TimeUnit.MILLISECONDS.toMinutes(message.date - (previous?.date ?: 0))
|
||||
val subscription = subs.find { sub -> sub.subscriptionId == message.subId }
|
||||
|
||||
holder.binding.timestamp.text = dateFormatter.getMessageTimestamp(message.date)
|
||||
holder.binding.simIndex.text = subscription?.simSlotIndex?.plus(1)?.toString()
|
||||
holder.timestamp.text = dateFormatter.getMessageTimestamp(message.date)
|
||||
holder.simIndex.text = subscription?.simSlotIndex?.plus(1)?.toString()
|
||||
|
||||
holder.binding.timestamp.setVisible(timeSincePrevious >= BubbleUtils.TIMESTAMP_THRESHOLD
|
||||
holder.timestamp.setVisible(timeSincePrevious >= BubbleUtils.TIMESTAMP_THRESHOLD
|
||||
|| message.subId != previous?.subId && subscription != null)
|
||||
holder.binding.sim.setVisible(message.subId != previous?.subId && subscription != null && subs.size > 1)
|
||||
holder.binding.simIndex.setVisible(message.subId != previous?.subId && subscription != null && subs.size > 1)
|
||||
|
||||
holder.sim.setVisible(message.subId != previous?.subId && subscription != null && subs.size > 1)
|
||||
holder.simIndex.setVisible(message.subId != previous?.subId && subscription != null && subs.size > 1)
|
||||
|
||||
// Bind the grouping
|
||||
val media = message.parts.filter { !it.isSmil() && !it.isText() }
|
||||
holder.binding.root.setPadding(bottom = if (canGroup(message, next)) 0 else 16.dpToPx(context))
|
||||
holder.containerView.setPadding(bottom = if (canGroup(message, next)) 0 else 16.dpToPx(context))
|
||||
|
||||
// Bind the avatar and bubble colour
|
||||
if (!message.isMe()) {
|
||||
holder.binding.avatar.setRecipient(contactCache[message.address])
|
||||
holder.binding.avatar.setVisible(!canGroup(message, next), View.INVISIBLE)
|
||||
holder.avatar.setRecipient(contactCache[message.address])
|
||||
holder.avatar.setVisible(!canGroup(message, next), View.INVISIBLE)
|
||||
|
||||
holder.binding.body.setTextColor(theme.textPrimary)
|
||||
holder.binding.body.setBackgroundTint(theme.theme)
|
||||
holder.body.setTextColor(theme.textPrimary)
|
||||
holder.body.setBackgroundTint(theme.theme)
|
||||
}
|
||||
|
||||
// Bind the body text
|
||||
@@ -263,29 +270,29 @@ class MessagesAdapter @Inject constructor(
|
||||
}
|
||||
}
|
||||
val emojiOnly = messageText.isNotBlank() && messageText.matches(EMOJI_REGEX)
|
||||
textViewStyler.setTextSize(holder.binding.body, when (emojiOnly) {
|
||||
textViewStyler.setTextSize(holder.body, when (emojiOnly) {
|
||||
true -> TextViewStyler.SIZE_EMOJI
|
||||
false -> TextViewStyler.SIZE_PRIMARY
|
||||
})
|
||||
|
||||
holder.binding.body.text = messageText
|
||||
holder.binding.body.setVisible(message.isSms() || messageText.isNotBlank())
|
||||
holder.binding.body.setBackgroundResource(getBubble(
|
||||
holder.body.text = messageText
|
||||
holder.body.setVisible(message.isSms() || messageText.isNotBlank())
|
||||
holder.body.setBackgroundResource(getBubble(
|
||||
emojiOnly = emojiOnly,
|
||||
canGroupWithPrevious = canGroup(message, previous) || media.isNotEmpty(),
|
||||
canGroupWithNext = canGroup(message, next),
|
||||
isMe = message.isMe()))
|
||||
|
||||
// Bind the attachments
|
||||
val partsAdapter = holder.binding.attachments.adapter as PartsAdapter
|
||||
val partsAdapter = holder.attachments.adapter as PartsAdapter
|
||||
partsAdapter.theme = theme
|
||||
partsAdapter.setData(message, previous, next, holder)
|
||||
}
|
||||
|
||||
private fun bindStatus(holder: QkViewHolder<MessageListItemInBinding>, message: Message, next: Message?) {
|
||||
private fun bindStatus(holder: QkViewHolder, message: Message, next: Message?) {
|
||||
val age = TimeUnit.MILLISECONDS.toMinutes(System.currentTimeMillis() - message.date)
|
||||
|
||||
holder.binding.status.text = when {
|
||||
holder.status.text = when {
|
||||
message.isSending() -> context.getString(R.string.message_status_sending)
|
||||
message.isDelivered() -> context.getString(R.string.message_status_delivered,
|
||||
dateFormatter.getTimestamp(message.dateSent))
|
||||
@@ -299,7 +306,7 @@ class MessagesAdapter @Inject constructor(
|
||||
else -> dateFormatter.getTimestamp(message.date)
|
||||
}
|
||||
|
||||
holder.binding.status.setVisible(when {
|
||||
holder.status.setVisible(when {
|
||||
expanded[message.id] == true -> true
|
||||
message.isSending() -> true
|
||||
message.isFailedMessage() -> true
|
||||
|
||||
@@ -20,6 +20,7 @@ package com.moez.QKSMS.feature.compose.editing
|
||||
|
||||
import android.content.Context
|
||||
import android.os.Build
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import android.widget.RelativeLayout
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
@@ -29,35 +30,37 @@ import com.moez.QKSMS.common.base.QkViewHolder
|
||||
import com.moez.QKSMS.common.util.extensions.dpToPx
|
||||
import com.moez.QKSMS.common.util.extensions.resolveThemeColor
|
||||
import com.moez.QKSMS.common.util.extensions.setBackgroundTint
|
||||
import com.moez.QKSMS.databinding.ContactChipBinding
|
||||
import com.moez.QKSMS.model.Recipient
|
||||
import io.reactivex.subjects.PublishSubject
|
||||
import kotlinx.android.synthetic.main.contact_chip.*
|
||||
import javax.inject.Inject
|
||||
|
||||
class ChipsAdapter @Inject constructor() : QkAdapter<Recipient, ContactChipBinding>() {
|
||||
class ChipsAdapter @Inject constructor() : QkAdapter<Recipient>() {
|
||||
|
||||
var view: RecyclerView? = null
|
||||
val chipDeleted: PublishSubject<Recipient> = PublishSubject.create<Recipient>()
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): QkViewHolder<ContactChipBinding> {
|
||||
return QkViewHolder(parent, ContactChipBinding::inflate).apply {
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): QkViewHolder {
|
||||
val inflater = LayoutInflater.from(parent.context)
|
||||
val view = inflater.inflate(R.layout.contact_chip, parent, false)
|
||||
return QkViewHolder(view).apply {
|
||||
// These theme attributes don't apply themselves on API 21
|
||||
if (Build.VERSION.SDK_INT <= 22) {
|
||||
binding.content.setBackgroundTint(parent.context.resolveThemeColor(R.attr.bubbleColor))
|
||||
content.setBackgroundTint(view.context.resolveThemeColor(R.attr.bubbleColor))
|
||||
}
|
||||
|
||||
binding.root.setOnClickListener {
|
||||
view.setOnClickListener {
|
||||
val chip = getItem(adapterPosition)
|
||||
showDetailedChip(parent.context, chip)
|
||||
showDetailedChip(view.context, chip)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: QkViewHolder<ContactChipBinding>, position: Int) {
|
||||
override fun onBindViewHolder(holder: QkViewHolder, position: Int) {
|
||||
val recipient = getItem(position)
|
||||
|
||||
holder.binding.avatar.setRecipient(recipient)
|
||||
holder.binding.name.text = recipient.contact?.name?.takeIf { it.isNotBlank() } ?: recipient.address
|
||||
holder.avatar.setRecipient(recipient)
|
||||
holder.name.text = recipient.contact?.name?.takeIf { it.isNotBlank() } ?: recipient.address
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -73,9 +76,8 @@ class ChipsAdapter @Inject constructor() : QkAdapter<Recipient, ContactChipBindi
|
||||
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||
ViewGroup.LayoutParams.WRAP_CONTENT)
|
||||
|
||||
layoutParams.topMargin = 32.dpToPx(context)
|
||||
layoutParams.topMargin = 24.dpToPx(context)
|
||||
layoutParams.marginStart = 56.dpToPx(context)
|
||||
layoutParams.marginEnd = 8.dpToPx(context)
|
||||
|
||||
rootView.addView(detailedChipView, layoutParams)
|
||||
detailedChipView.show()
|
||||
|
||||
+63
-58
@@ -18,6 +18,7 @@
|
||||
*/
|
||||
package com.moez.QKSMS.feature.compose.editing
|
||||
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
@@ -27,7 +28,6 @@ import com.moez.QKSMS.common.base.QkViewHolder
|
||||
import com.moez.QKSMS.common.util.Colors
|
||||
import com.moez.QKSMS.common.util.extensions.forwardTouches
|
||||
import com.moez.QKSMS.common.util.extensions.setTint
|
||||
import com.moez.QKSMS.databinding.ContactListItemBinding
|
||||
import com.moez.QKSMS.extensions.associateByNotNull
|
||||
import com.moez.QKSMS.model.Contact
|
||||
import com.moez.QKSMS.model.ContactGroup
|
||||
@@ -38,12 +38,14 @@ import io.reactivex.disposables.CompositeDisposable
|
||||
import io.reactivex.rxkotlin.plusAssign
|
||||
import io.reactivex.subjects.PublishSubject
|
||||
import io.reactivex.subjects.Subject
|
||||
import kotlinx.android.synthetic.main.contact_list_item.*
|
||||
import kotlinx.android.synthetic.main.contact_list_item.view.*
|
||||
import javax.inject.Inject
|
||||
|
||||
class ComposeItemAdapter @Inject constructor(
|
||||
private val colors: Colors,
|
||||
private val conversationRepo: ConversationRepository
|
||||
) : QkAdapter<ComposeItem, ContactListItemBinding>() {
|
||||
) : QkAdapter<ComposeItem>() {
|
||||
|
||||
val clicks: Subject<ComposeItem> = PublishSubject.create()
|
||||
val longClicks: Subject<ComposeItem> = PublishSubject.create()
|
||||
@@ -57,19 +59,22 @@ class ComposeItemAdapter @Inject constructor(
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): QkViewHolder<ContactListItemBinding> {
|
||||
return QkViewHolder(parent, ContactListItemBinding::inflate).apply {
|
||||
binding.icon.setTint(colors.theme().theme)
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): QkViewHolder {
|
||||
val layoutInflater = LayoutInflater.from(parent.context)
|
||||
val view = layoutInflater.inflate(R.layout.contact_list_item, parent, false)
|
||||
|
||||
binding.numbers.setRecycledViewPool(numbersViewPool)
|
||||
binding.numbers.adapter = PhoneNumberAdapter()
|
||||
binding.numbers.forwardTouches(binding.root)
|
||||
view.icon.setTint(colors.theme().theme)
|
||||
|
||||
binding.root.setOnClickListener {
|
||||
view.numbers.setRecycledViewPool(numbersViewPool)
|
||||
view.numbers.adapter = PhoneNumberAdapter()
|
||||
view.numbers.forwardTouches(view)
|
||||
|
||||
return QkViewHolder(view).apply {
|
||||
view.setOnClickListener {
|
||||
val item = getItem(adapterPosition)
|
||||
clicks.onNext(item)
|
||||
}
|
||||
binding.root.setOnLongClickListener {
|
||||
view.setOnLongClickListener {
|
||||
val item = getItem(adapterPosition)
|
||||
longClicks.onNext(item)
|
||||
true
|
||||
@@ -77,7 +82,7 @@ class ComposeItemAdapter @Inject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: QkViewHolder<ContactListItemBinding>, position: Int) {
|
||||
override fun onBindViewHolder(holder: QkViewHolder, position: Int) {
|
||||
val prevItem = if (position > 0) getItem(position - 1) else null
|
||||
val item = getItem(position)
|
||||
|
||||
@@ -90,92 +95,92 @@ class ComposeItemAdapter @Inject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
private fun bindNew(holder: QkViewHolder<ContactListItemBinding>, contact: Contact) {
|
||||
holder.binding.index.isVisible = false
|
||||
private fun bindNew(holder: QkViewHolder, contact: Contact) {
|
||||
holder.index.isVisible = false
|
||||
|
||||
holder.binding.icon.isVisible = false
|
||||
holder.icon.isVisible = false
|
||||
|
||||
holder.binding.avatar.recipients = listOf(createRecipient(contact))
|
||||
holder.avatar.recipients = listOf(createRecipient(contact))
|
||||
|
||||
holder.binding.title.text = contact.numbers.joinToString { it.address }
|
||||
holder.title.text = contact.numbers.joinToString { it.address }
|
||||
|
||||
holder.binding.subtitle.isVisible = false
|
||||
holder.subtitle.isVisible = false
|
||||
|
||||
holder.binding.numbers.isVisible = false
|
||||
holder.numbers.isVisible = false
|
||||
}
|
||||
|
||||
private fun bindRecent(holder: QkViewHolder<ContactListItemBinding>, conversation: Conversation, prev: ComposeItem?) {
|
||||
holder.binding.index.isVisible = false
|
||||
private fun bindRecent(holder: QkViewHolder, conversation: Conversation, prev: ComposeItem?) {
|
||||
holder.index.isVisible = false
|
||||
|
||||
holder.binding.icon.isVisible = prev !is ComposeItem.Recent
|
||||
holder.binding.icon.setImageResource(R.drawable.ic_history_black_24dp)
|
||||
holder.icon.isVisible = prev !is ComposeItem.Recent
|
||||
holder.icon.setImageResource(R.drawable.ic_history_black_24dp)
|
||||
|
||||
holder.binding.avatar.recipients = conversation.recipients
|
||||
holder.avatar.recipients = conversation.recipients
|
||||
|
||||
holder.binding.title.text = conversation.getTitle()
|
||||
holder.title.text = conversation.getTitle()
|
||||
|
||||
holder.binding.subtitle.isVisible = conversation.recipients.size > 1 && conversation.name.isBlank()
|
||||
holder.binding.subtitle.text = conversation.recipients.joinToString(", ") { recipient ->
|
||||
holder.subtitle.isVisible = conversation.recipients.size > 1 && conversation.name.isBlank()
|
||||
holder.subtitle.text = conversation.recipients.joinToString(", ") { recipient ->
|
||||
recipient.contact?.name ?: recipient.address
|
||||
}
|
||||
holder.binding.subtitle.collapseEnabled = conversation.recipients.size > 1
|
||||
holder.subtitle.collapseEnabled = conversation.recipients.size > 1
|
||||
|
||||
holder.binding.numbers.isVisible = conversation.recipients.size == 1
|
||||
(holder.binding.numbers.adapter as PhoneNumberAdapter).data = conversation.recipients
|
||||
holder.numbers.isVisible = conversation.recipients.size == 1
|
||||
(holder.numbers.adapter as PhoneNumberAdapter).data = conversation.recipients
|
||||
.mapNotNull { recipient -> recipient.contact }
|
||||
.flatMap { contact -> contact.numbers }
|
||||
}
|
||||
|
||||
private fun bindStarred(holder: QkViewHolder<ContactListItemBinding>, contact: Contact, prev: ComposeItem?) {
|
||||
holder.binding.index.isVisible = false
|
||||
private fun bindStarred(holder: QkViewHolder, contact: Contact, prev: ComposeItem?) {
|
||||
holder.index.isVisible = false
|
||||
|
||||
holder.binding.icon.isVisible = prev !is ComposeItem.Starred
|
||||
holder.binding.icon.setImageResource(R.drawable.ic_star_black_24dp)
|
||||
holder.icon.isVisible = prev !is ComposeItem.Starred
|
||||
holder.icon.setImageResource(R.drawable.ic_star_black_24dp)
|
||||
|
||||
holder.binding.avatar.recipients = listOf(createRecipient(contact))
|
||||
holder.avatar.recipients = listOf(createRecipient(contact))
|
||||
|
||||
holder.binding.title.text = contact.name
|
||||
holder.title.text = contact.name
|
||||
|
||||
holder.binding.subtitle.isVisible = false
|
||||
holder.subtitle.isVisible = false
|
||||
|
||||
holder.binding.numbers.isVisible = true
|
||||
(holder.binding.numbers.adapter as PhoneNumberAdapter).data = contact.numbers
|
||||
holder.numbers.isVisible = true
|
||||
(holder.numbers.adapter as PhoneNumberAdapter).data = contact.numbers
|
||||
}
|
||||
|
||||
private fun bindGroup(holder: QkViewHolder<ContactListItemBinding>, group: ContactGroup, prev: ComposeItem?) {
|
||||
holder.binding.index.isVisible = false
|
||||
private fun bindGroup(holder: QkViewHolder, group: ContactGroup, prev: ComposeItem?) {
|
||||
holder.index.isVisible = false
|
||||
|
||||
holder.binding.icon.isVisible = prev !is ComposeItem.Group
|
||||
holder.binding.icon.setImageResource(R.drawable.ic_people_black_24dp)
|
||||
holder.icon.isVisible = prev !is ComposeItem.Group
|
||||
holder.icon.setImageResource(R.drawable.ic_people_black_24dp)
|
||||
|
||||
holder.binding.avatar.recipients = group.contacts.map(::createRecipient)
|
||||
holder.avatar.recipients = group.contacts.map(::createRecipient)
|
||||
|
||||
holder.binding.title.text = group.title
|
||||
holder.title.text = group.title
|
||||
|
||||
holder.binding.subtitle.isVisible = true
|
||||
holder.binding.subtitle.text = group.contacts.joinToString(", ") { it.name }
|
||||
holder.binding.subtitle.collapseEnabled = group.contacts.size > 1
|
||||
holder.subtitle.isVisible = true
|
||||
holder.subtitle.text = group.contacts.joinToString(", ") { it.name }
|
||||
holder.subtitle.collapseEnabled = group.contacts.size > 1
|
||||
|
||||
holder.binding.numbers.isVisible = false
|
||||
holder.numbers.isVisible = false
|
||||
}
|
||||
|
||||
private fun bindPerson(holder: QkViewHolder<ContactListItemBinding>, contact: Contact, prev: ComposeItem?) {
|
||||
holder.binding.index.isVisible = true
|
||||
holder.binding.index.text = if (contact.name.getOrNull(0)?.isLetter() == true) contact.name[0].toString() else "#"
|
||||
holder.binding.index.isVisible = prev !is ComposeItem.Person ||
|
||||
private fun bindPerson(holder: QkViewHolder, contact: Contact, prev: ComposeItem?) {
|
||||
holder.index.isVisible = true
|
||||
holder.index.text = if (contact.name.getOrNull(0)?.isLetter() == true) contact.name[0].toString() else "#"
|
||||
holder.index.isVisible = prev !is ComposeItem.Person ||
|
||||
(contact.name[0].isLetter() && !contact.name[0].equals(prev.value.name[0], ignoreCase = true)) ||
|
||||
(!contact.name[0].isLetter() && prev.value.name[0].isLetter())
|
||||
|
||||
holder.binding.icon.isVisible = false
|
||||
holder.icon.isVisible = false
|
||||
|
||||
holder.binding.avatar.recipients = listOf(createRecipient(contact))
|
||||
holder.avatar.recipients = listOf(createRecipient(contact))
|
||||
|
||||
holder.binding.title.text = contact.name
|
||||
holder.title.text = contact.name
|
||||
|
||||
holder.binding.subtitle.isVisible = false
|
||||
holder.subtitle.isVisible = false
|
||||
|
||||
holder.binding.numbers.isVisible = true
|
||||
(holder.binding.numbers.adapter as PhoneNumberAdapter).data = contact.numbers
|
||||
holder.numbers.isVisible = true
|
||||
(holder.numbers.adapter as PhoneNumberAdapter).data = contact.numbers
|
||||
}
|
||||
|
||||
private fun createRecipient(contact: Contact): Recipient {
|
||||
|
||||
+14
-23
@@ -19,53 +19,44 @@
|
||||
package com.moez.QKSMS.feature.compose.editing
|
||||
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import android.view.View
|
||||
import android.view.animation.AlphaAnimation
|
||||
import androidx.constraintlayout.widget.ConstraintLayout
|
||||
import android.widget.RelativeLayout
|
||||
import com.moez.QKSMS.R
|
||||
import com.moez.QKSMS.common.util.Colors
|
||||
import com.moez.QKSMS.common.util.extensions.dpToPx
|
||||
import com.moez.QKSMS.common.util.extensions.setBackgroundTint
|
||||
import com.moez.QKSMS.common.util.extensions.setTint
|
||||
import com.moez.QKSMS.common.util.extensions.viewBinding
|
||||
import com.moez.QKSMS.databinding.ContactChipDetailedBinding
|
||||
import com.moez.QKSMS.injection.appComponent
|
||||
import com.moez.QKSMS.model.Recipient
|
||||
import kotlinx.android.synthetic.main.contact_chip_detailed.view.*
|
||||
import javax.inject.Inject
|
||||
|
||||
class DetailedChipView(context: Context, attrs: AttributeSet? = null) : ConstraintLayout(context, attrs) {
|
||||
class DetailedChipView(context: Context) : RelativeLayout(context) {
|
||||
|
||||
@Inject lateinit var colors: Colors
|
||||
|
||||
private val binding = viewBinding(ContactChipDetailedBinding::inflate)
|
||||
|
||||
init {
|
||||
if (!isInEditMode) {
|
||||
appComponent.inject(this)
|
||||
visibility = View.GONE
|
||||
}
|
||||
View.inflate(context, R.layout.contact_chip_detailed, this)
|
||||
appComponent.inject(this)
|
||||
|
||||
setOnClickListener { hide() }
|
||||
setBackgroundResource(R.drawable.rounded_rectangle_2dp)
|
||||
|
||||
elevation = 8.dpToPx(context) .toFloat()
|
||||
// updateLayoutParams<LinearLayout.LayoutParams> { setMargins(8.dpToPx(context) ) }
|
||||
visibility = View.GONE
|
||||
|
||||
isFocusable = true
|
||||
isFocusableInTouchMode = true
|
||||
}
|
||||
|
||||
fun setRecipient(recipient: Recipient) {
|
||||
binding.avatar.setRecipient(recipient)
|
||||
binding.name.text = recipient.contact?.name?.takeIf { it.isNotBlank() } ?: recipient.address
|
||||
binding.info.text = recipient.address
|
||||
avatar.setRecipient(recipient)
|
||||
name.text = recipient.contact?.name?.takeIf { it.isNotBlank() } ?: recipient.address
|
||||
info.text = recipient.address
|
||||
|
||||
colors.theme(recipient).let { theme ->
|
||||
setBackgroundTint(theme.theme)
|
||||
binding.name.setTextColor(theme.textPrimary)
|
||||
binding.info.setTextColor(theme.textTertiary)
|
||||
binding.delete.setTint(theme.textPrimary)
|
||||
card.setBackgroundTint(theme.theme)
|
||||
name.setTextColor(theme.textPrimary)
|
||||
info.setTextColor(theme.textTertiary)
|
||||
delete.setTint(theme.textPrimary)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,7 +77,7 @@ class DetailedChipView(context: Context, attrs: AttributeSet? = null) : Constrai
|
||||
}
|
||||
|
||||
fun setOnDeleteListener(listener: (View) -> Unit) {
|
||||
binding.delete.setOnClickListener(listener)
|
||||
delete.setOnClickListener(listener)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+12
-8
@@ -18,23 +18,27 @@
|
||||
*/
|
||||
package com.moez.QKSMS.feature.compose.editing
|
||||
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import com.moez.QKSMS.R
|
||||
import com.moez.QKSMS.common.base.QkAdapter
|
||||
import com.moez.QKSMS.common.base.QkViewHolder
|
||||
import com.moez.QKSMS.databinding.ContactNumberListItemBinding
|
||||
import com.moez.QKSMS.model.PhoneNumber
|
||||
import kotlinx.android.synthetic.main.contact_number_list_item.*
|
||||
|
||||
class PhoneNumberAdapter : QkAdapter<PhoneNumber, ContactNumberListItemBinding>() {
|
||||
class PhoneNumberAdapter : QkAdapter<PhoneNumber>() {
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): QkViewHolder<ContactNumberListItemBinding> {
|
||||
return QkViewHolder(parent, ContactNumberListItemBinding::inflate)
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): QkViewHolder {
|
||||
val inflater = LayoutInflater.from(parent.context)
|
||||
val view = inflater.inflate(R.layout.contact_number_list_item, parent, false)
|
||||
return QkViewHolder(view)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: QkViewHolder<ContactNumberListItemBinding>, position: Int) {
|
||||
override fun onBindViewHolder(holder: QkViewHolder, position: Int) {
|
||||
val number = getItem(position)
|
||||
|
||||
holder.binding.address.text = number.address
|
||||
holder.binding.type.text = number.type
|
||||
holder.address.text = number.address
|
||||
holder.type.text = number.type
|
||||
}
|
||||
|
||||
override fun areItemsTheSame(old: PhoneNumber, new: PhoneNumber): Boolean {
|
||||
@@ -45,4 +49,4 @@ class PhoneNumberAdapter : QkAdapter<PhoneNumber, ContactNumberListItemBinding>(
|
||||
return old.type == new.type && old.address == new.address
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
+15
-10
@@ -19,21 +19,24 @@
|
||||
package com.moez.QKSMS.feature.compose.editing
|
||||
|
||||
import android.content.Context
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import com.moez.QKSMS.R
|
||||
import com.moez.QKSMS.common.base.QkAdapter
|
||||
import com.moez.QKSMS.common.base.QkViewHolder
|
||||
import com.moez.QKSMS.common.util.extensions.forwardTouches
|
||||
import com.moez.QKSMS.databinding.PhoneNumberListItemBinding
|
||||
import com.moez.QKSMS.extensions.Optional
|
||||
import com.moez.QKSMS.model.PhoneNumber
|
||||
import io.reactivex.subjects.BehaviorSubject
|
||||
import io.reactivex.subjects.Subject
|
||||
import kotlinx.android.synthetic.main.phone_number_list_item.*
|
||||
import kotlinx.android.synthetic.main.radio_preference_view.*
|
||||
import kotlinx.android.synthetic.main.radio_preference_view.view.*
|
||||
import javax.inject.Inject
|
||||
|
||||
class PhoneNumberPickerAdapter @Inject constructor(
|
||||
private val context: Context
|
||||
) : QkAdapter<PhoneNumber, PhoneNumberListItemBinding>() {
|
||||
) : QkAdapter<PhoneNumber>() {
|
||||
|
||||
val selectedItemChanges: Subject<Optional<Long>> = BehaviorSubject.create()
|
||||
|
||||
@@ -45,23 +48,25 @@ class PhoneNumberPickerAdapter @Inject constructor(
|
||||
selectedItemChanges.onNext(Optional(value))
|
||||
}
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): QkViewHolder<PhoneNumberListItemBinding> {
|
||||
return QkViewHolder(parent, PhoneNumberListItemBinding::inflate).apply {
|
||||
binding.number.binding.radioButton.forwardTouches(itemView)
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): QkViewHolder {
|
||||
val inflater = LayoutInflater.from(parent.context)
|
||||
val view = inflater.inflate(R.layout.phone_number_list_item, parent, false)
|
||||
return QkViewHolder(view).apply {
|
||||
radioButton.forwardTouches(itemView)
|
||||
|
||||
binding.root.setOnClickListener {
|
||||
view.setOnClickListener {
|
||||
val phoneNumber = getItem(adapterPosition)
|
||||
selectedItem = phoneNumber.id
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: QkViewHolder<PhoneNumberListItemBinding>, position: Int) {
|
||||
override fun onBindViewHolder(holder: QkViewHolder, position: Int) {
|
||||
val phoneNumber = getItem(position)
|
||||
|
||||
holder.binding.number.binding.radioButton.isChecked = phoneNumber.id == selectedItem
|
||||
holder.binding.number.binding.titleView.text = phoneNumber.address
|
||||
holder.binding.number.binding.summaryView.text = when (phoneNumber.isDefault) {
|
||||
holder.number.radioButton.isChecked = phoneNumber.id == selectedItem
|
||||
holder.number.titleView.text = phoneNumber.address
|
||||
holder.number.summaryView.text = when (phoneNumber.isDefault) {
|
||||
true -> context.getString(R.string.compose_number_picker_default, phoneNumber.type)
|
||||
false -> phoneNumber.type
|
||||
}
|
||||
|
||||
@@ -28,37 +28,35 @@ import com.moez.QKSMS.common.util.Colors
|
||||
import com.moez.QKSMS.common.util.extensions.resolveThemeColor
|
||||
import com.moez.QKSMS.common.util.extensions.setBackgroundTint
|
||||
import com.moez.QKSMS.common.util.extensions.setTint
|
||||
import com.moez.QKSMS.databinding.MmsFileListItemBinding
|
||||
import com.moez.QKSMS.feature.compose.BubbleUtils
|
||||
import com.moez.QKSMS.model.Message
|
||||
import com.moez.QKSMS.model.MmsPart
|
||||
import io.reactivex.Observable
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
import io.reactivex.schedulers.Schedulers
|
||||
import kotlinx.android.synthetic.main.mms_file_list_item.*
|
||||
import javax.inject.Inject
|
||||
|
||||
class FileBinder @Inject constructor(
|
||||
colors: Colors,
|
||||
private val context: Context
|
||||
) : PartBinder<MmsFileListItemBinding>(MmsFileListItemBinding::inflate) {
|
||||
class FileBinder @Inject constructor(colors: Colors, private val context: Context) : PartBinder() {
|
||||
|
||||
override val partLayout = R.layout.mms_file_list_item
|
||||
override var theme = colors.theme()
|
||||
|
||||
// This is the last binder we check. If we're here, we can bind the part
|
||||
override fun canBindPart(part: MmsPart) = true
|
||||
|
||||
@SuppressLint("CheckResult")
|
||||
override fun bindPartInternal(
|
||||
holder: QkViewHolder<MmsFileListItemBinding>,
|
||||
override fun bindPart(
|
||||
holder: QkViewHolder,
|
||||
part: MmsPart,
|
||||
message: Message,
|
||||
canGroupWithPrevious: Boolean,
|
||||
canGroupWithNext: Boolean
|
||||
) {
|
||||
BubbleUtils.getBubble(false, canGroupWithPrevious, canGroupWithNext, message.isMe())
|
||||
.let(holder.binding.fileBackground::setBackgroundResource)
|
||||
.let(holder.fileBackground::setBackgroundResource)
|
||||
|
||||
holder.binding.root.setOnClickListener { clicks.onNext(part.id) }
|
||||
holder.containerView.setOnClickListener { clicks.onNext(part.id) }
|
||||
|
||||
Observable.just(part.getUri())
|
||||
.map(context.contentResolver::openInputStream)
|
||||
@@ -73,23 +71,23 @@ class FileBinder @Inject constructor(
|
||||
}
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe { size -> holder.binding.size.text = size }
|
||||
.subscribe { size -> holder.size.text = size }
|
||||
|
||||
holder.binding.filename.text = part.name
|
||||
holder.filename.text = part.name
|
||||
|
||||
val params = holder.binding.fileBackground.layoutParams as FrameLayout.LayoutParams
|
||||
val params = holder.fileBackground.layoutParams as FrameLayout.LayoutParams
|
||||
if (!message.isMe()) {
|
||||
holder.binding.fileBackground.layoutParams = params.apply { gravity = Gravity.START }
|
||||
holder.binding.fileBackground.setBackgroundTint(theme.theme)
|
||||
holder.binding.icon.setTint(theme.textPrimary)
|
||||
holder.binding.filename.setTextColor(theme.textPrimary)
|
||||
holder.binding.size.setTextColor(theme.textTertiary)
|
||||
holder.fileBackground.layoutParams = params.apply { gravity = Gravity.START }
|
||||
holder.fileBackground.setBackgroundTint(theme.theme)
|
||||
holder.icon.setTint(theme.textPrimary)
|
||||
holder.filename.setTextColor(theme.textPrimary)
|
||||
holder.size.setTextColor(theme.textTertiary)
|
||||
} else {
|
||||
holder.binding.fileBackground.layoutParams = params.apply { gravity = Gravity.END }
|
||||
holder.binding.fileBackground.setBackgroundTint(holder.binding.root.context.resolveThemeColor(R.attr.bubbleColor))
|
||||
holder.binding.icon.setTint(holder.binding.root.context.resolveThemeColor(android.R.attr.textColorSecondary))
|
||||
holder.binding.filename.setTextColor(holder.binding.root.context.resolveThemeColor(android.R.attr.textColorPrimary))
|
||||
holder.binding.size.setTextColor(holder.binding.root.context.resolveThemeColor(android.R.attr.textColorTertiary))
|
||||
holder.fileBackground.layoutParams = params.apply { gravity = Gravity.END }
|
||||
holder.fileBackground.setBackgroundTint(holder.containerView.context.resolveThemeColor(R.attr.bubbleColor))
|
||||
holder.icon.setTint(holder.containerView.context.resolveThemeColor(android.R.attr.textColorSecondary))
|
||||
holder.filename.setTextColor(holder.containerView.context.resolveThemeColor(android.R.attr.textColorPrimary))
|
||||
holder.size.setTextColor(holder.containerView.context.resolveThemeColor(android.R.attr.textColorTertiary))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -19,45 +19,44 @@
|
||||
package com.moez.QKSMS.feature.compose.part
|
||||
|
||||
import android.content.Context
|
||||
import com.moez.QKSMS.R
|
||||
import com.moez.QKSMS.common.base.QkViewHolder
|
||||
import com.moez.QKSMS.common.util.Colors
|
||||
import com.moez.QKSMS.common.util.extensions.setVisible
|
||||
import com.moez.QKSMS.common.widget.BubbleImageView
|
||||
import com.moez.QKSMS.databinding.MmsPreviewListItemBinding
|
||||
import com.moez.QKSMS.extensions.isImage
|
||||
import com.moez.QKSMS.extensions.isVideo
|
||||
import com.moez.QKSMS.model.Message
|
||||
import com.moez.QKSMS.model.MmsPart
|
||||
import com.moez.QKSMS.util.GlideApp
|
||||
import kotlinx.android.synthetic.main.mms_preview_list_item.*
|
||||
import javax.inject.Inject
|
||||
|
||||
class MediaBinder @Inject constructor(
|
||||
colors: Colors,
|
||||
private val context: Context
|
||||
) : PartBinder<MmsPreviewListItemBinding>(MmsPreviewListItemBinding::inflate) {
|
||||
class MediaBinder @Inject constructor(colors: Colors, private val context: Context) : PartBinder() {
|
||||
|
||||
override val partLayout = R.layout.mms_preview_list_item
|
||||
override var theme = colors.theme()
|
||||
|
||||
override fun canBindPart(part: MmsPart) = part.isImage() || part.isVideo()
|
||||
|
||||
override fun bindPartInternal(
|
||||
holder: QkViewHolder<MmsPreviewListItemBinding>,
|
||||
override fun bindPart(
|
||||
holder: QkViewHolder,
|
||||
part: MmsPart,
|
||||
message: Message,
|
||||
canGroupWithPrevious: Boolean,
|
||||
canGroupWithNext: Boolean
|
||||
) {
|
||||
holder.binding.video.setVisible(part.isVideo())
|
||||
holder.binding.root.setOnClickListener { clicks.onNext(part.id) }
|
||||
holder.video.setVisible(part.isVideo())
|
||||
holder.containerView.setOnClickListener { clicks.onNext(part.id) }
|
||||
|
||||
holder.binding.thumbnail.bubbleStyle = when {
|
||||
holder.thumbnail.bubbleStyle = when {
|
||||
!canGroupWithPrevious && canGroupWithNext -> if (message.isMe()) BubbleImageView.Style.OUT_FIRST else BubbleImageView.Style.IN_FIRST
|
||||
canGroupWithPrevious && canGroupWithNext -> if (message.isMe()) BubbleImageView.Style.OUT_MIDDLE else BubbleImageView.Style.IN_MIDDLE
|
||||
canGroupWithPrevious && !canGroupWithNext -> if (message.isMe()) BubbleImageView.Style.OUT_LAST else BubbleImageView.Style.IN_LAST
|
||||
else -> BubbleImageView.Style.ONLY
|
||||
}
|
||||
|
||||
GlideApp.with(context).load(part.getUri()).fitCenter().into(holder.binding.thumbnail)
|
||||
GlideApp.with(context).load(part.getUri()).fitCenter().into(holder.thumbnail)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -18,9 +18,6 @@
|
||||
*/
|
||||
package com.moez.QKSMS.feature.compose.part
|
||||
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import androidx.viewbinding.ViewBinding
|
||||
import com.moez.QKSMS.common.base.QkViewHolder
|
||||
import com.moez.QKSMS.common.util.Colors
|
||||
import com.moez.QKSMS.model.Message
|
||||
@@ -28,36 +25,18 @@ import com.moez.QKSMS.model.MmsPart
|
||||
import io.reactivex.subjects.PublishSubject
|
||||
import io.reactivex.subjects.Subject
|
||||
|
||||
abstract class PartBinder<Binding : ViewBinding>(
|
||||
val bindingInflater: (LayoutInflater, ViewGroup, Boolean) -> Binding
|
||||
) {
|
||||
abstract class PartBinder {
|
||||
|
||||
val clicks: Subject<Long> = PublishSubject.create()
|
||||
|
||||
abstract val partLayout: Int
|
||||
|
||||
abstract var theme: Colors.Theme
|
||||
|
||||
fun <T: ViewBinding> bindPart(
|
||||
holder: QkViewHolder<T>,
|
||||
part: MmsPart,
|
||||
message: Message,
|
||||
canGroupWithPrevious: Boolean,
|
||||
canGroupWithNext: Boolean
|
||||
): Boolean {
|
||||
val castHolder = holder as? QkViewHolder<Binding>
|
||||
|
||||
if (!canBindPart(part) || castHolder == null) {
|
||||
return false
|
||||
}
|
||||
|
||||
bindPartInternal(castHolder, part, message, canGroupWithPrevious, canGroupWithNext)
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
abstract fun canBindPart(part: MmsPart): Boolean
|
||||
|
||||
protected abstract fun bindPartInternal(
|
||||
holder: QkViewHolder<Binding>,
|
||||
abstract fun bindPart(
|
||||
holder: QkViewHolder,
|
||||
part: MmsPart,
|
||||
message: Message,
|
||||
canGroupWithPrevious: Boolean,
|
||||
|
||||
@@ -18,20 +18,20 @@
|
||||
*/
|
||||
package com.moez.QKSMS.feature.compose.part
|
||||
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.viewbinding.ViewBinding
|
||||
import com.moez.QKSMS.common.base.QkAdapter
|
||||
import com.moez.QKSMS.common.base.QkViewHolder
|
||||
import com.moez.QKSMS.common.util.Colors
|
||||
import com.moez.QKSMS.common.util.extensions.forwardTouches
|
||||
import com.moez.QKSMS.databinding.MessageListItemInBinding
|
||||
import com.moez.QKSMS.extensions.isSmil
|
||||
import com.moez.QKSMS.extensions.isText
|
||||
import com.moez.QKSMS.feature.compose.BubbleUtils.canGroup
|
||||
import com.moez.QKSMS.model.Message
|
||||
import com.moez.QKSMS.model.MmsPart
|
||||
import io.reactivex.Observable
|
||||
import kotlinx.android.synthetic.main.message_list_item_in.*
|
||||
import javax.inject.Inject
|
||||
|
||||
class PartsAdapter @Inject constructor(
|
||||
@@ -39,7 +39,7 @@ class PartsAdapter @Inject constructor(
|
||||
fileBinder: FileBinder,
|
||||
mediaBinder: MediaBinder,
|
||||
vCardBinder: VCardBinder
|
||||
) : QkAdapter<MmsPart, ViewBinding>() {
|
||||
) : QkAdapter<MmsPart>() {
|
||||
|
||||
private val partBinders = listOf(mediaBinder, vCardBinder, fileBinder)
|
||||
|
||||
@@ -54,31 +54,34 @@ class PartsAdapter @Inject constructor(
|
||||
private lateinit var message: Message
|
||||
private var previous: Message? = null
|
||||
private var next: Message? = null
|
||||
private var holder: QkViewHolder<MessageListItemInBinding>? = null
|
||||
private var holder: QkViewHolder? = null
|
||||
private var bodyVisible: Boolean = true
|
||||
|
||||
fun setData(message: Message, previous: Message?, next: Message?, holder: QkViewHolder<MessageListItemInBinding>) {
|
||||
fun setData(message: Message, previous: Message?, next: Message?, holder: QkViewHolder) {
|
||||
this.message = message
|
||||
this.previous = previous
|
||||
this.next = next
|
||||
this.holder = holder
|
||||
this.bodyVisible = holder.binding.body.visibility == View.VISIBLE
|
||||
this.bodyVisible = holder.body.visibility == View.VISIBLE
|
||||
this.data = message.parts.filter { !it.isSmil() && !it.isText() }
|
||||
}
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): QkViewHolder<ViewBinding> {
|
||||
return QkViewHolder(parent, partBinders[viewType].bindingInflater).apply {
|
||||
holder?.binding?.root?.let(binding.root::forwardTouches)
|
||||
}
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): QkViewHolder {
|
||||
val layout = partBinders.getOrNull(viewType)?.partLayout ?: 0
|
||||
val view = LayoutInflater.from(parent.context).inflate(layout, parent, false)
|
||||
holder?.containerView?.let(view::forwardTouches)
|
||||
return QkViewHolder(view)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: QkViewHolder<ViewBinding>, position: Int) {
|
||||
override fun onBindViewHolder(holder: QkViewHolder, position: Int) {
|
||||
val part = data[position]
|
||||
|
||||
val canGroupWithPrevious = canGroup(message, previous) || position > 0
|
||||
val canGroupWithNext = canGroup(message, next) || position < itemCount - 1 || bodyVisible
|
||||
|
||||
partBinders.find { binder -> binder.bindPart(holder, part, message, canGroupWithPrevious, canGroupWithNext) }
|
||||
partBinders
|
||||
.firstOrNull { it.canBindPart(part) }
|
||||
?.bindPart(holder, part, message, canGroupWithPrevious, canGroupWithNext)
|
||||
}
|
||||
|
||||
override fun getItemViewType(position: Int): Int {
|
||||
|
||||
@@ -27,7 +27,6 @@ import com.moez.QKSMS.common.util.Colors
|
||||
import com.moez.QKSMS.common.util.extensions.resolveThemeColor
|
||||
import com.moez.QKSMS.common.util.extensions.setBackgroundTint
|
||||
import com.moez.QKSMS.common.util.extensions.setTint
|
||||
import com.moez.QKSMS.databinding.MmsVcardListItemBinding
|
||||
import com.moez.QKSMS.extensions.isVCard
|
||||
import com.moez.QKSMS.extensions.mapNotNull
|
||||
import com.moez.QKSMS.feature.compose.BubbleUtils
|
||||
@@ -37,49 +36,48 @@ import ezvcard.Ezvcard
|
||||
import io.reactivex.Observable
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
import io.reactivex.schedulers.Schedulers
|
||||
import kotlinx.android.synthetic.main.mms_vcard_list_item.*
|
||||
import javax.inject.Inject
|
||||
|
||||
class VCardBinder @Inject constructor(
|
||||
colors: Colors,
|
||||
private val context: Context
|
||||
) : PartBinder<MmsVcardListItemBinding>(MmsVcardListItemBinding::inflate) {
|
||||
class VCardBinder @Inject constructor(colors: Colors, private val context: Context) : PartBinder() {
|
||||
|
||||
override val partLayout = R.layout.mms_vcard_list_item
|
||||
override var theme = colors.theme()
|
||||
|
||||
override fun canBindPart(part: MmsPart) = part.isVCard()
|
||||
|
||||
override fun bindPartInternal(
|
||||
holder: QkViewHolder<MmsVcardListItemBinding>,
|
||||
override fun bindPart(
|
||||
holder: QkViewHolder,
|
||||
part: MmsPart,
|
||||
message: Message,
|
||||
canGroupWithPrevious: Boolean,
|
||||
canGroupWithNext: Boolean
|
||||
) {
|
||||
BubbleUtils.getBubble(false, canGroupWithPrevious, canGroupWithNext, message.isMe())
|
||||
.let(holder.binding.vCardBackground::setBackgroundResource)
|
||||
.let(holder.vCardBackground::setBackgroundResource)
|
||||
|
||||
holder.binding.root.setOnClickListener { clicks.onNext(part.id) }
|
||||
holder.containerView.setOnClickListener { clicks.onNext(part.id) }
|
||||
|
||||
Observable.just(part.getUri())
|
||||
.map(context.contentResolver::openInputStream)
|
||||
.mapNotNull { inputStream -> inputStream.use { Ezvcard.parse(it).first() } }
|
||||
.subscribeOn(Schedulers.computation())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe { vcard -> holder.binding.name?.text = vcard.formattedName.value }
|
||||
.subscribe { vcard -> holder.name?.text = vcard.formattedName.value }
|
||||
|
||||
val params = holder.binding.vCardBackground.layoutParams as FrameLayout.LayoutParams
|
||||
val params = holder.vCardBackground.layoutParams as FrameLayout.LayoutParams
|
||||
if (!message.isMe()) {
|
||||
holder.binding.vCardBackground.layoutParams = params.apply { gravity = Gravity.START }
|
||||
holder.binding.vCardBackground.setBackgroundTint(theme.theme)
|
||||
holder.binding.vCardAvatar.setTint(theme.textPrimary)
|
||||
holder.binding.name.setTextColor(theme.textPrimary)
|
||||
holder.binding.label.setTextColor(theme.textTertiary)
|
||||
holder.vCardBackground.layoutParams = params.apply { gravity = Gravity.START }
|
||||
holder.vCardBackground.setBackgroundTint(theme.theme)
|
||||
holder.vCardAvatar.setTint(theme.textPrimary)
|
||||
holder.name.setTextColor(theme.textPrimary)
|
||||
holder.label.setTextColor(theme.textTertiary)
|
||||
} else {
|
||||
holder.binding.vCardBackground.layoutParams = params.apply { gravity = Gravity.END }
|
||||
holder.binding.vCardBackground.setBackgroundTint(holder.binding.root.context.resolveThemeColor(R.attr.bubbleColor))
|
||||
holder.binding.vCardAvatar.setTint(holder.binding.root.context.resolveThemeColor(android.R.attr.textColorSecondary))
|
||||
holder.binding.name.setTextColor(holder.binding.root.context.resolveThemeColor(android.R.attr.textColorPrimary))
|
||||
holder.binding.label.setTextColor(holder.binding.root.context.resolveThemeColor(android.R.attr.textColorTertiary))
|
||||
holder.vCardBackground.layoutParams = params.apply { gravity = Gravity.END }
|
||||
holder.vCardBackground.setBackgroundTint(holder.containerView.context.resolveThemeColor(R.attr.bubbleColor))
|
||||
holder.vCardAvatar.setTint(holder.containerView.context.resolveThemeColor(android.R.attr.textColorSecondary))
|
||||
holder.name.setTextColor(holder.containerView.context.resolveThemeColor(android.R.attr.textColorPrimary))
|
||||
holder.label.setTextColor(holder.containerView.context.resolveThemeColor(android.R.attr.textColorTertiary))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user