mirror of
https://github.com/quik-sms/quik.git
synced 2026-11-16 19:18:52 +01:00
+153
@@ -0,0 +1,153 @@
|
||||
package com.moez.QKSMS.feature.conversationinfo
|
||||
|
||||
import android.content.Context
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import androidx.core.view.isVisible
|
||||
import com.jakewharton.rxbinding2.view.clicks
|
||||
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.Colors
|
||||
import com.moez.QKSMS.common.util.extensions.setTint
|
||||
import com.moez.QKSMS.common.util.extensions.setVisible
|
||||
import com.moez.QKSMS.extensions.isVideo
|
||||
import com.moez.QKSMS.feature.conversationinfo.ConversationInfoItem.*
|
||||
import com.moez.QKSMS.util.GlideApp
|
||||
import io.reactivex.subjects.PublishSubject
|
||||
import io.reactivex.subjects.Subject
|
||||
import kotlinx.android.synthetic.main.conversation_info_settings.*
|
||||
import kotlinx.android.synthetic.main.conversation_media_list_item.*
|
||||
import kotlinx.android.synthetic.main.conversation_recipient_list_item.*
|
||||
import javax.inject.Inject
|
||||
|
||||
class ConversationInfoAdapter @Inject constructor(
|
||||
private val context: Context,
|
||||
private val colors: Colors
|
||||
) : QkAdapter<ConversationInfoItem>() {
|
||||
|
||||
val recipientClicks: Subject<Long> = PublishSubject.create()
|
||||
val recipientLongClicks: Subject<Long> = PublishSubject.create()
|
||||
val themeClicks: Subject<Long> = PublishSubject.create()
|
||||
val nameClicks: Subject<Unit> = PublishSubject.create()
|
||||
val notificationClicks: Subject<Unit> = PublishSubject.create()
|
||||
val archiveClicks: Subject<Unit> = PublishSubject.create()
|
||||
val blockClicks: Subject<Unit> = PublishSubject.create()
|
||||
val deleteClicks: Subject<Unit> = PublishSubject.create()
|
||||
val mediaClicks: Subject<Long> = PublishSubject.create()
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): QkViewHolder {
|
||||
val inflater = LayoutInflater.from(parent.context)
|
||||
return when (viewType) {
|
||||
0 -> QkViewHolder(inflater.inflate(R.layout.conversation_recipient_list_item, parent, false)).apply {
|
||||
itemView.setOnClickListener {
|
||||
val item = getItem(adapterPosition) as? ConversationInfoRecipient
|
||||
item?.value?.id?.run(recipientClicks::onNext)
|
||||
}
|
||||
|
||||
itemView.setOnLongClickListener {
|
||||
val item = getItem(adapterPosition) as? ConversationInfoRecipient
|
||||
item?.value?.id?.run(recipientLongClicks::onNext)
|
||||
true
|
||||
}
|
||||
|
||||
theme.setOnClickListener {
|
||||
val item = getItem(adapterPosition) as? ConversationInfoRecipient
|
||||
item?.value?.id?.run(themeClicks::onNext)
|
||||
}
|
||||
}
|
||||
|
||||
1 -> QkViewHolder(inflater.inflate(R.layout.conversation_info_settings, parent, false)).apply {
|
||||
groupName.clicks().subscribe(nameClicks)
|
||||
notifications.clicks().subscribe(notificationClicks)
|
||||
archive.clicks().subscribe(archiveClicks)
|
||||
block.clicks().subscribe(blockClicks)
|
||||
delete.clicks().subscribe(deleteClicks)
|
||||
}
|
||||
|
||||
2 -> QkViewHolder(inflater.inflate(R.layout.conversation_media_list_item, parent, false)).apply {
|
||||
itemView.setOnClickListener {
|
||||
val item = getItem(adapterPosition) as? ConversationInfoMedia
|
||||
item?.value?.id?.run(mediaClicks::onNext)
|
||||
}
|
||||
}
|
||||
|
||||
else -> throw IllegalStateException()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: QkViewHolder, position: Int) {
|
||||
when (val item = getItem(position)) {
|
||||
is ConversationInfoRecipient -> {
|
||||
val recipient = item.value
|
||||
holder.avatar.setRecipient(recipient)
|
||||
|
||||
holder.name.text = recipient.contact?.name ?: recipient.address
|
||||
|
||||
holder.address.text = recipient.address
|
||||
holder.address.setVisible(recipient.contact != null)
|
||||
|
||||
holder.add.setVisible(recipient.contact == null)
|
||||
|
||||
val theme = colors.theme(recipient)
|
||||
holder.theme.setTint(theme.theme)
|
||||
}
|
||||
|
||||
is ConversationInfoSettings -> {
|
||||
holder.groupName.isVisible = item.recipients.size > 1
|
||||
holder.groupName.summary = item.name
|
||||
|
||||
holder.notifications.isEnabled = !item.blocked
|
||||
|
||||
holder.archive.isEnabled = !item.blocked
|
||||
holder.archive.title = context.getString(when (item.archived) {
|
||||
true -> R.string.info_unarchive
|
||||
false -> R.string.info_archive
|
||||
})
|
||||
|
||||
holder.block.title = context.getString(when (item.blocked) {
|
||||
true -> R.string.info_unblock
|
||||
false -> R.string.info_block
|
||||
})
|
||||
}
|
||||
|
||||
is ConversationInfoMedia -> {
|
||||
val part = item.value
|
||||
|
||||
GlideApp.with(context)
|
||||
.load(part.getUri())
|
||||
.fitCenter()
|
||||
.into(holder.thumbnail)
|
||||
|
||||
holder.video.isVisible = part.isVideo()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun getItemViewType(position: Int): Int {
|
||||
return when (data[position]) {
|
||||
is ConversationInfoRecipient -> 0
|
||||
is ConversationInfoSettings -> 1
|
||||
is ConversationInfoMedia -> 2
|
||||
}
|
||||
}
|
||||
|
||||
override fun areItemsTheSame(old: ConversationInfoItem, new: ConversationInfoItem): Boolean {
|
||||
return when {
|
||||
old is ConversationInfoRecipient && new is ConversationInfoRecipient -> {
|
||||
old.value.id == new.value.id
|
||||
}
|
||||
|
||||
old is ConversationInfoSettings && new is ConversationInfoSettings -> {
|
||||
true
|
||||
}
|
||||
|
||||
old is ConversationInfoMedia && new is ConversationInfoMedia -> {
|
||||
old.value.id == new.value.id
|
||||
}
|
||||
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+23
-52
@@ -20,15 +20,13 @@ package com.moez.QKSMS.feature.conversationinfo
|
||||
|
||||
import android.view.View
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.recyclerview.widget.GridLayoutManager
|
||||
import com.bluelinelabs.conductor.RouterTransaction
|
||||
import com.jakewharton.rxbinding2.view.clicks
|
||||
import com.moez.QKSMS.R
|
||||
import com.moez.QKSMS.common.Navigator
|
||||
import com.moez.QKSMS.common.QkChangeHandler
|
||||
import com.moez.QKSMS.common.base.QkController
|
||||
import com.moez.QKSMS.common.util.extensions.animateLayoutChanges
|
||||
import com.moez.QKSMS.common.util.extensions.scrapViews
|
||||
import com.moez.QKSMS.common.util.extensions.setVisible
|
||||
import com.moez.QKSMS.common.widget.FieldDialog
|
||||
import com.moez.QKSMS.feature.blocking.BlockingDialog
|
||||
import com.moez.QKSMS.feature.conversationinfo.injection.ConversationInfoModule
|
||||
@@ -49,9 +47,7 @@ class ConversationInfoController(
|
||||
@Inject override lateinit var presenter: ConversationInfoPresenter
|
||||
@Inject lateinit var blockingDialog: BlockingDialog
|
||||
@Inject lateinit var navigator: Navigator
|
||||
@Inject lateinit var recipientAdapter: ConversationRecipientAdapter
|
||||
@Inject lateinit var mediaAdapter: ConversationMediaAdapter
|
||||
@Inject lateinit var itemDecoration: GridSpacingItemDecoration
|
||||
@Inject lateinit var adapter: ConversationInfoAdapter
|
||||
|
||||
private val nameDialog: FieldDialog by lazy {
|
||||
FieldDialog(activity!!, activity!!.getString(R.string.info_name), nameChangeSubject::onNext)
|
||||
@@ -71,16 +67,17 @@ class ConversationInfoController(
|
||||
}
|
||||
|
||||
override fun onViewCreated() {
|
||||
items.postDelayed({ items?.animateLayoutChanges = true }, 100)
|
||||
|
||||
recipients.adapter = recipientAdapter
|
||||
|
||||
media.adapter = mediaAdapter
|
||||
media.addItemDecoration(itemDecoration)
|
||||
recyclerView.adapter = adapter
|
||||
recyclerView.addItemDecoration(GridSpacingItemDecoration(adapter, activity!!))
|
||||
recyclerView.layoutManager = GridLayoutManager(activity, 3).apply {
|
||||
spanSizeLookup = object : GridLayoutManager.SpanSizeLookup() {
|
||||
override fun getSpanSize(position: Int): Int = if (adapter.getItemViewType(position) == 2) 1 else 3
|
||||
}
|
||||
}
|
||||
|
||||
themedActivity?.theme
|
||||
?.autoDisposable(scope())
|
||||
?.subscribe { recipients.scrapViews() }
|
||||
?.subscribe { recyclerView.scrapViews() }
|
||||
}
|
||||
|
||||
override fun onAttach(view: View) {
|
||||
@@ -90,53 +87,27 @@ class ConversationInfoController(
|
||||
showBackButton(true)
|
||||
}
|
||||
|
||||
override fun recipientClicks(): Observable<Long> = recipientAdapter.recipientClicks
|
||||
|
||||
override fun recipientLongClicks(): Observable<Long> = recipientAdapter.recipientLongClicks
|
||||
|
||||
override fun themeClicks(): Observable<Long> = recipientAdapter.themeClicks
|
||||
|
||||
override fun nameClicks(): Observable<*> = name.clicks()
|
||||
|
||||
override fun nameChanges(): Observable<String> = nameChangeSubject
|
||||
|
||||
override fun notificationClicks(): Observable<*> = notifications.clicks()
|
||||
|
||||
override fun archiveClicks(): Observable<*> = archive.clicks()
|
||||
|
||||
override fun blockClicks(): Observable<*> = block.clicks()
|
||||
|
||||
override fun deleteClicks(): Observable<*> = delete.clicks()
|
||||
|
||||
override fun confirmDelete(): Observable<*> = confirmDeleteSubject
|
||||
|
||||
override fun render(state: ConversationInfoState) {
|
||||
if (state.hasError) {
|
||||
activity?.finish()
|
||||
return
|
||||
}
|
||||
|
||||
recipientAdapter.updateData(state.recipients)
|
||||
|
||||
name.setVisible(state.recipients?.size ?: 0 >= 2)
|
||||
name.summary = state.name
|
||||
|
||||
notifications.isEnabled = !state.blocked
|
||||
|
||||
archive.isEnabled = !state.blocked
|
||||
archive.title = activity?.getString(when (state.archived) {
|
||||
true -> R.string.info_unarchive
|
||||
false -> R.string.info_archive
|
||||
})
|
||||
|
||||
block.title = activity?.getString(when (state.blocked) {
|
||||
true -> R.string.info_unblock
|
||||
false -> R.string.info_block
|
||||
})
|
||||
|
||||
mediaAdapter.updateData(state.media)
|
||||
adapter.data = state.data
|
||||
}
|
||||
|
||||
override fun recipientClicks(): Observable<Long> = adapter.recipientClicks
|
||||
override fun recipientLongClicks(): Observable<Long> = adapter.recipientLongClicks
|
||||
override fun themeClicks(): Observable<Long> = adapter.themeClicks
|
||||
override fun nameClicks(): Observable<*> = adapter.nameClicks
|
||||
override fun nameChanges(): Observable<String> = nameChangeSubject
|
||||
override fun notificationClicks(): Observable<*> = adapter.notificationClicks
|
||||
override fun archiveClicks(): Observable<*> = adapter.archiveClicks
|
||||
override fun blockClicks(): Observable<*> = adapter.blockClicks
|
||||
override fun deleteClicks(): Observable<*> = adapter.deleteClicks
|
||||
override fun confirmDelete(): Observable<*> = confirmDeleteSubject
|
||||
override fun mediaClicks(): Observable<Long> = adapter.mediaClicks
|
||||
|
||||
override fun showNameDialog(name: String) = nameDialog.setText(name).show()
|
||||
|
||||
override fun showThemePicker(recipientId: Long) {
|
||||
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
package com.moez.QKSMS.feature.conversationinfo
|
||||
|
||||
import com.moez.QKSMS.model.MmsPart
|
||||
import com.moez.QKSMS.model.Recipient
|
||||
import io.realm.RealmList
|
||||
|
||||
sealed class ConversationInfoItem {
|
||||
|
||||
data class ConversationInfoRecipient(val value: Recipient) : ConversationInfoItem()
|
||||
|
||||
data class ConversationInfoSettings(
|
||||
val name: String,
|
||||
val recipients: RealmList<Recipient>,
|
||||
val archived: Boolean,
|
||||
val blocked: Boolean
|
||||
) : ConversationInfoItem()
|
||||
|
||||
data class ConversationInfoMedia(val value: MmsPart) : ConversationInfoItem()
|
||||
|
||||
}
|
||||
+25
-21
@@ -27,6 +27,8 @@ import com.moez.QKSMS.common.util.ClipboardUtils
|
||||
import com.moez.QKSMS.common.util.extensions.makeToast
|
||||
import com.moez.QKSMS.extensions.asObservable
|
||||
import com.moez.QKSMS.extensions.mapNotNull
|
||||
import com.moez.QKSMS.feature.conversationinfo.ConversationInfoItem.ConversationInfoMedia
|
||||
import com.moez.QKSMS.feature.conversationinfo.ConversationInfoItem.ConversationInfoRecipient
|
||||
import com.moez.QKSMS.interactor.DeleteConversations
|
||||
import com.moez.QKSMS.interactor.MarkArchived
|
||||
import com.moez.QKSMS.interactor.MarkUnarchived
|
||||
@@ -37,6 +39,7 @@ import com.moez.QKSMS.repository.MessageRepository
|
||||
import com.uber.autodispose.android.lifecycle.scope
|
||||
import com.uber.autodispose.autoDisposable
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
import io.reactivex.rxkotlin.Observables
|
||||
import io.reactivex.rxkotlin.plusAssign
|
||||
import io.reactivex.rxkotlin.withLatestFrom
|
||||
import io.reactivex.subjects.BehaviorSubject
|
||||
@@ -55,7 +58,7 @@ class ConversationInfoPresenter @Inject constructor(
|
||||
private val navigator: Navigator,
|
||||
private val permissionManager: PermissionManager
|
||||
) : QkPresenter<ConversationInfoView, ConversationInfoState>(
|
||||
ConversationInfoState(threadId = threadId, media = messageRepo.getPartsForConversation(threadId))
|
||||
ConversationInfoState(threadId = threadId)
|
||||
) {
|
||||
|
||||
private val conversation: Subject<Conversation> = BehaviorSubject.create()
|
||||
@@ -77,29 +80,25 @@ class ConversationInfoPresenter @Inject constructor(
|
||||
disposables += markUnarchived
|
||||
disposables += deleteConversations
|
||||
|
||||
// Update the recipients whenever they change
|
||||
disposables += conversation
|
||||
.map { conversation -> conversation.recipients }
|
||||
.distinctUntilChanged()
|
||||
.subscribe { recipients -> newState { copy(recipients = recipients) } }
|
||||
val partsObservable = messageRepo.getPartsForConversation(threadId)
|
||||
.asObservable()
|
||||
.filter { parts -> parts.isLoaded && parts.isValid}
|
||||
|
||||
// Update conversation title whenever it changes
|
||||
disposables += conversation
|
||||
.map { conversation -> conversation.name }
|
||||
.distinctUntilChanged()
|
||||
.subscribe { name -> newState { copy(name = name) } }
|
||||
disposables += Observables
|
||||
.combineLatest(conversation, partsObservable) { conversation, parts ->
|
||||
val data = mutableListOf<ConversationInfoItem>()
|
||||
|
||||
// Update the view's archived state whenever it changes
|
||||
disposables += conversation
|
||||
.map { conversation -> conversation.archived }
|
||||
.distinctUntilChanged()
|
||||
.subscribe { archived -> newState { copy(archived = archived) } }
|
||||
data += conversation.recipients.map(::ConversationInfoRecipient)
|
||||
data += ConversationInfoItem.ConversationInfoSettings(
|
||||
name = conversation.name,
|
||||
recipients = conversation.recipients,
|
||||
archived = conversation.archived,
|
||||
blocked = conversation.blocked)
|
||||
data += parts.map(::ConversationInfoMedia)
|
||||
|
||||
// Update the view's blocked state whenever it changes
|
||||
disposables += conversation
|
||||
.map { conversation -> conversation.blocked }
|
||||
.distinctUntilChanged()
|
||||
.subscribe { blocked -> newState { copy(blocked = blocked) } }
|
||||
newState { copy(data = data) }
|
||||
}
|
||||
.subscribe()
|
||||
}
|
||||
|
||||
override fun bindIntents(view: ConversationInfoView) {
|
||||
@@ -180,6 +179,11 @@ class ConversationInfoPresenter @Inject constructor(
|
||||
.withLatestFrom(conversation) { _, conversation -> conversation }
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { conversation -> deleteConversations.execute(listOf(conversation.id)) }
|
||||
|
||||
// Media
|
||||
view.mediaClicks()
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe(navigator::showMedia)
|
||||
}
|
||||
|
||||
}
|
||||
+2
-11
@@ -18,17 +18,8 @@
|
||||
*/
|
||||
package com.moez.QKSMS.feature.conversationinfo
|
||||
|
||||
import com.moez.QKSMS.model.MmsPart
|
||||
import com.moez.QKSMS.model.Recipient
|
||||
import io.realm.RealmList
|
||||
import io.realm.RealmResults
|
||||
|
||||
data class ConversationInfoState(
|
||||
val name: String = "",
|
||||
val recipients: RealmList<Recipient>? = null,
|
||||
val threadId: Long = 0,
|
||||
val archived: Boolean = false,
|
||||
val blocked: Boolean = false,
|
||||
val media: RealmResults<MmsPart>? = null,
|
||||
val data: List<ConversationInfoItem> = listOf(),
|
||||
val hasError: Boolean = false
|
||||
)
|
||||
)
|
||||
|
||||
+1
@@ -33,6 +33,7 @@ interface ConversationInfoView : QkViewContract<ConversationInfoState> {
|
||||
fun blockClicks(): Observable<*>
|
||||
fun deleteClicks(): Observable<*>
|
||||
fun confirmDelete(): Observable<*>
|
||||
fun mediaClicks(): Observable<Long>
|
||||
|
||||
fun showNameDialog(name: String)
|
||||
fun showThemePicker(recipientId: Long)
|
||||
|
||||
-63
@@ -1,63 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
|
||||
*
|
||||
* This file is part of QKSMS.
|
||||
*
|
||||
* QKSMS is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* QKSMS is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.moez.QKSMS.feature.conversationinfo
|
||||
|
||||
import android.content.Context
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
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.extensions.isVideo
|
||||
import com.moez.QKSMS.model.MmsPart
|
||||
import com.moez.QKSMS.util.GlideApp
|
||||
import kotlinx.android.synthetic.main.conversation_media_list_item.*
|
||||
import kotlinx.android.synthetic.main.conversation_media_list_item.view.*
|
||||
import javax.inject.Inject
|
||||
|
||||
class ConversationMediaAdapter @Inject constructor(
|
||||
private val context: Context,
|
||||
private val navigator: Navigator
|
||||
) : QkRealmAdapter<MmsPart>() {
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): QkViewHolder {
|
||||
val inflater = LayoutInflater.from(parent.context)
|
||||
val view = inflater.inflate(R.layout.conversation_media_list_item, parent, false)
|
||||
return QkViewHolder(view).apply {
|
||||
view.thumbnail.setOnClickListener {
|
||||
val part = getItem(adapterPosition) ?: return@setOnClickListener
|
||||
navigator.showMedia(part.id)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: QkViewHolder, position: Int) {
|
||||
val part = getItem(position) ?: return
|
||||
|
||||
GlideApp.with(context)
|
||||
.load(part.getUri())
|
||||
.fitCenter()
|
||||
.into(holder.thumbnail)
|
||||
|
||||
holder.video.setVisible(part.isVideo())
|
||||
}
|
||||
|
||||
}
|
||||
-82
@@ -1,82 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
|
||||
*
|
||||
* This file is part of QKSMS.
|
||||
*
|
||||
* QKSMS is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* QKSMS is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.moez.QKSMS.feature.conversationinfo
|
||||
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import com.moez.QKSMS.R
|
||||
import com.moez.QKSMS.common.base.QkRealmAdapter
|
||||
import com.moez.QKSMS.common.base.QkViewHolder
|
||||
import com.moez.QKSMS.common.util.Colors
|
||||
import com.moez.QKSMS.common.util.extensions.setTint
|
||||
import com.moez.QKSMS.common.util.extensions.setVisible
|
||||
import com.moez.QKSMS.model.Recipient
|
||||
import io.reactivex.subjects.PublishSubject
|
||||
import io.reactivex.subjects.Subject
|
||||
import kotlinx.android.synthetic.main.conversation_recipient_list_item.*
|
||||
import kotlinx.android.synthetic.main.conversation_recipient_list_item.view.*
|
||||
import javax.inject.Inject
|
||||
|
||||
class ConversationRecipientAdapter @Inject constructor(
|
||||
private val colors: Colors
|
||||
) : QkRealmAdapter<Recipient>() {
|
||||
|
||||
val recipientClicks: Subject<Long> = PublishSubject.create()
|
||||
val recipientLongClicks: Subject<Long> = PublishSubject.create()
|
||||
val themeClicks: Subject<Long> = PublishSubject.create()
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): QkViewHolder {
|
||||
val layoutInflater = LayoutInflater.from(parent.context)
|
||||
val view = layoutInflater.inflate(R.layout.conversation_recipient_list_item, parent, false)
|
||||
return QkViewHolder(view).apply {
|
||||
view.setOnClickListener {
|
||||
val recipient = getItem(adapterPosition) ?: return@setOnClickListener
|
||||
recipientClicks.onNext(recipient.id)
|
||||
}
|
||||
|
||||
view.setOnLongClickListener {
|
||||
val recipient = getItem(adapterPosition) ?: return@setOnLongClickListener false
|
||||
recipientLongClicks.onNext(recipient.id)
|
||||
return@setOnLongClickListener true
|
||||
}
|
||||
|
||||
view.theme.setOnClickListener {
|
||||
val recipient = getItem(adapterPosition) ?: return@setOnClickListener
|
||||
themeClicks.onNext(recipient.id)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: QkViewHolder, position: Int) {
|
||||
val recipient = getItem(position) ?: return
|
||||
|
||||
holder.avatar.setRecipient(recipient)
|
||||
|
||||
holder.name.text = recipient.contact?.name ?: recipient.address
|
||||
|
||||
holder.address.text = recipient.address
|
||||
holder.address.setVisible(recipient.contact != null)
|
||||
|
||||
holder.add.setVisible(recipient.contact == null)
|
||||
|
||||
val theme = colors.theme(recipient)
|
||||
holder.theme.setTint(theme.theme)
|
||||
}
|
||||
|
||||
}
|
||||
+16
-6
@@ -23,9 +23,13 @@ import android.graphics.Rect
|
||||
import android.view.View
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.moez.QKSMS.common.util.extensions.dpToPx
|
||||
import javax.inject.Inject
|
||||
import com.moez.QKSMS.feature.conversationinfo.ConversationInfoItem.ConversationInfoMedia
|
||||
import com.moez.QKSMS.feature.conversationinfo.ConversationInfoItem.ConversationInfoRecipient
|
||||
|
||||
class GridSpacingItemDecoration @Inject constructor(context: Context) : RecyclerView.ItemDecoration() {
|
||||
class GridSpacingItemDecoration(
|
||||
private val adapter: ConversationInfoAdapter,
|
||||
private val context: Context
|
||||
) : RecyclerView.ItemDecoration() {
|
||||
|
||||
private val spanCount = 3
|
||||
private val spacing = 2.dpToPx(context)
|
||||
@@ -34,13 +38,19 @@ class GridSpacingItemDecoration @Inject constructor(context: Context) : Recycler
|
||||
super.getItemOffsets(outRect, view, parent, state)
|
||||
|
||||
val position = parent.getChildAdapterPosition(view)
|
||||
val column = position % spanCount
|
||||
val item = adapter.getItem(position)
|
||||
|
||||
outRect.left = column * spacing / spanCount
|
||||
outRect.right = spacing - (column + 1) * spacing / spanCount
|
||||
if (item is ConversationInfoRecipient && adapter.getItem(position + 1) !is ConversationInfoRecipient) {
|
||||
outRect.bottom = 8.dpToPx(context)
|
||||
} else if (item is ConversationInfoMedia) {
|
||||
val firstPartIndex = adapter.data.indexOfFirst { it is ConversationInfoMedia }
|
||||
val localPartIndex = position - firstPartIndex
|
||||
|
||||
val column = localPartIndex % spanCount
|
||||
|
||||
if (position >= spanCount) {
|
||||
outRect.top = spacing
|
||||
outRect.left = column * spacing / spanCount
|
||||
outRect.right = spacing - (column + 1) * spacing / spanCount
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -17,91 +17,11 @@
|
||||
~ You should have received a copy of the GNU General Public License
|
||||
~ along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
|
||||
-->
|
||||
<androidx.core.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
<androidx.recyclerview.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/recyclerView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:layoutManager="android.support.v7.widget.LinearLayoutManager"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/toolbar">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/items"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/recipients"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingTop="8dp"
|
||||
android:paddingBottom="8dp"
|
||||
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
|
||||
tools:layout_height="72dp"
|
||||
tools:listitem="@layout/conversation_recipient_list_item" />
|
||||
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:background="?android:attr/divider" />
|
||||
|
||||
<com.moez.QKSMS.common.widget.PreferenceView
|
||||
android:id="@+id/name"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:visibility="gone"
|
||||
app:icon="@drawable/ic_people_black_24dp"
|
||||
app:title="@string/info_name" />
|
||||
|
||||
<com.moez.QKSMS.common.widget.PreferenceView
|
||||
android:id="@+id/notifications"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:icon="@drawable/ic_notifications_black_24dp"
|
||||
app:title="@string/info_notifications" />
|
||||
|
||||
<com.moez.QKSMS.common.widget.PreferenceView
|
||||
android:id="@+id/archive"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:icon="@drawable/ic_archive_black_24dp"
|
||||
app:title="@string/info_archive" />
|
||||
|
||||
<com.moez.QKSMS.common.widget.PreferenceView
|
||||
android:id="@+id/block"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:icon="@drawable/ic_block_black_24dp"
|
||||
app:title="@string/info_block" />
|
||||
|
||||
<com.moez.QKSMS.common.widget.PreferenceView
|
||||
android:id="@+id/delete"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:icon="@drawable/ic_delete_white_24dp"
|
||||
app:title="@string/info_delete" />
|
||||
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_marginBottom="16dp"
|
||||
android:background="?android:attr/divider" />
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/media"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:nestedScrollingEnabled="false"
|
||||
app:layoutManager="androidx.recyclerview.widget.GridLayoutManager"
|
||||
app:spanCount="3"
|
||||
tools:listitem="@layout/conversation_media_list_item" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</androidx.core.widget.NestedScrollView>
|
||||
android:clipChildren="false"
|
||||
android:clipToPadding="false"
|
||||
android:paddingTop="8dp"
|
||||
android:paddingBottom="8dp" />
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
~ 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/>.
|
||||
-->
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:background="?android:attr/divider" />
|
||||
|
||||
<com.moez.QKSMS.common.widget.PreferenceView
|
||||
android:id="@+id/groupName"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:visibility="gone"
|
||||
app:icon="@drawable/ic_people_black_24dp"
|
||||
app:title="@string/info_name" />
|
||||
|
||||
<com.moez.QKSMS.common.widget.PreferenceView
|
||||
android:id="@+id/notifications"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:icon="@drawable/ic_notifications_black_24dp"
|
||||
app:title="@string/info_notifications" />
|
||||
|
||||
<com.moez.QKSMS.common.widget.PreferenceView
|
||||
android:id="@+id/archive"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:icon="@drawable/ic_archive_black_24dp"
|
||||
app:title="@string/info_archive" />
|
||||
|
||||
<com.moez.QKSMS.common.widget.PreferenceView
|
||||
android:id="@+id/block"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:icon="@drawable/ic_block_black_24dp"
|
||||
app:title="@string/info_block" />
|
||||
|
||||
<com.moez.QKSMS.common.widget.PreferenceView
|
||||
android:id="@+id/delete"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:icon="@drawable/ic_delete_white_24dp"
|
||||
app:title="@string/info_delete" />
|
||||
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:layout_marginTop="8dp"
|
||||
android:background="?android:attr/divider" />
|
||||
|
||||
</LinearLayout>
|
||||
@@ -22,11 +22,10 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<com.moez.QKSMS.common.widget.SquareImageView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
<com.moez.QKSMS.common.widget.SquareImageView
|
||||
android:id="@+id/thumbnail"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:background="?android:attr/divider"
|
||||
android:scaleType="centerCrop"
|
||||
tools:src="@tools:sample/backgrounds/scenic" />
|
||||
|
||||
Reference in New Issue
Block a user