forked from upstream-mirrors/quik
Show blocking reason if available
This commit is contained in:
@@ -50,15 +50,15 @@ class CallControlBlockingClient @Inject constructor(
|
|||||||
|
|
||||||
override fun getAction(address: String): Single<BlockingClient.Action> = Single.fromCallable {
|
override fun getAction(address: String): Single<BlockingClient.Action> = Single.fromCallable {
|
||||||
val uri = Uri.withAppendedPath(CallControl.LOOKUP_TEXT_URI, address)
|
val uri = Uri.withAppendedPath(CallControl.LOOKUP_TEXT_URI, address)
|
||||||
val blocked = tryOrNull {
|
val blockReason = tryOrNull {
|
||||||
context.contentResolver.query(uri, projection, null, null, null) // Query URI
|
context.contentResolver.query(uri, projection, null, null, null) // Query URI
|
||||||
?.use { cursor -> cursor.map(::LookupResult) } // Map to Result object
|
?.use { cursor -> cursor.map(::LookupResult) } // Map to Result object
|
||||||
?.any { result -> result.blockReason != null } // Check if any are blocked
|
?.find { result -> result.blockReason != null } // Check if any are blocked
|
||||||
} == true // If none are blocked or we errored at some point, return false
|
}?.blockReason // If none are blocked or we errored at some point, return false
|
||||||
|
|
||||||
when (blocked) {
|
when (blockReason) {
|
||||||
true -> BlockingClient.Action.BLOCK
|
null -> BlockingClient.Action.Unblock
|
||||||
false -> BlockingClient.Action.UNBLOCK
|
else -> BlockingClient.Action.Block(blockReason)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -33,8 +33,8 @@ class QksmsBlockingClient @Inject constructor(
|
|||||||
|
|
||||||
override fun getAction(address: String): Single<BlockingClient.Action> = Single.fromCallable {
|
override fun getAction(address: String): Single<BlockingClient.Action> = Single.fromCallable {
|
||||||
when (blockingRepo.isBlocked(address)) {
|
when (blockingRepo.isBlocked(address)) {
|
||||||
true -> BlockingClient.Action.BLOCK
|
true -> BlockingClient.Action.Block()
|
||||||
false -> BlockingClient.Action.UNBLOCK
|
false -> BlockingClient.Action.Unblock
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -59,8 +59,8 @@ class ShouldIAnswerBlockingClient @Inject constructor(
|
|||||||
return Binder(context, address).isBlocked()
|
return Binder(context, address).isBlocked()
|
||||||
.map { blocked ->
|
.map { blocked ->
|
||||||
when (blocked) {
|
when (blocked) {
|
||||||
true -> BlockingClient.Action.BLOCK
|
true -> BlockingClient.Action.Block()
|
||||||
false -> BlockingClient.Action.DO_NOTHING
|
false -> BlockingClient.Action.DoNothing
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ import io.realm.RealmMigration
|
|||||||
class QkRealmMigration : RealmMigration {
|
class QkRealmMigration : RealmMigration {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val SCHEMA_VERSION: Long = 6
|
const val SCHEMA_VERSION: Long = 7
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun migrate(realm: DynamicRealm, oldVersion: Long, newVersion: Long) {
|
override fun migrate(realm: DynamicRealm, oldVersion: Long, newVersion: Long) {
|
||||||
@@ -80,9 +80,17 @@ class QkRealmMigration : RealmMigration {
|
|||||||
version++
|
version++
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (version == 6L) {
|
||||||
|
realm.schema.get("Conversation")
|
||||||
|
?.addField("blockingClient", Integer::class.java)
|
||||||
|
?.addField("blockReason", String::class.java)
|
||||||
|
|
||||||
|
version++
|
||||||
|
}
|
||||||
|
|
||||||
if (version < newVersion) {
|
if (version < newVersion) {
|
||||||
throw IllegalStateException("Migration missing from v$oldVersion to v$newVersion")
|
throw IllegalStateException("Migration missing from v$oldVersion to v$newVersion")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -297,14 +297,19 @@ class ConversationRepositoryImpl @Inject constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun markBlocked(vararg threadIds: Long) {
|
override fun markBlocked(threadIds: List<Long>, blockingClient: Int, blockReason: String?) {
|
||||||
Realm.getDefaultInstance().use { realm ->
|
Realm.getDefaultInstance().use { realm ->
|
||||||
val conversations = realm.where(Conversation::class.java)
|
val conversations = realm.where(Conversation::class.java)
|
||||||
.anyOf("id", threadIds)
|
.anyOf("id", threadIds.toLongArray())
|
||||||
|
.equalTo("blocked", false)
|
||||||
.findAll()
|
.findAll()
|
||||||
|
|
||||||
realm.executeTransaction {
|
realm.executeTransaction {
|
||||||
conversations.forEach { it.blocked = true }
|
conversations.forEach { conversation ->
|
||||||
|
conversation.blocked = true
|
||||||
|
conversation.blockingClient = blockingClient
|
||||||
|
conversation.blockReason = blockReason
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -316,7 +321,11 @@ class ConversationRepositoryImpl @Inject constructor(
|
|||||||
.findAll()
|
.findAll()
|
||||||
|
|
||||||
realm.executeTransaction {
|
realm.executeTransaction {
|
||||||
conversations.forEach { it.blocked = false }
|
conversations.forEach { conversation ->
|
||||||
|
conversation.blocked = false
|
||||||
|
conversation.blockingClient = null
|
||||||
|
conversation.blockReason = null
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ class SyncRepositoryImpl @Inject constructor(
|
|||||||
val realm = Realm.getDefaultInstance()
|
val realm = Realm.getDefaultInstance()
|
||||||
realm.beginTransaction()
|
realm.beginTransaction()
|
||||||
|
|
||||||
var persistedData = realm.where(Conversation::class.java)
|
val persistedData = realm.copyFromRealm(realm.where(Conversation::class.java)
|
||||||
.beginGroup()
|
.beginGroup()
|
||||||
.equalTo("archived", true)
|
.equalTo("archived", true)
|
||||||
.or()
|
.or()
|
||||||
@@ -90,9 +90,14 @@ class SyncRepositoryImpl @Inject constructor(
|
|||||||
.equalTo("pinned", true)
|
.equalTo("pinned", true)
|
||||||
.or()
|
.or()
|
||||||
.isNotEmpty("name")
|
.isNotEmpty("name")
|
||||||
|
.or()
|
||||||
|
.isNotNull("blockingClient")
|
||||||
|
.or()
|
||||||
|
.isNotEmpty("blockReason")
|
||||||
.endGroup()
|
.endGroup()
|
||||||
.findAll()
|
.findAll())
|
||||||
.map { PersistedData(it.id, it.archived, it.blocked, it.pinned, it.name) }
|
.associateBy { conversation -> conversation.id }
|
||||||
|
.toMutableMap()
|
||||||
|
|
||||||
realm.delete(Contact::class.java)
|
realm.delete(Contact::class.java)
|
||||||
realm.delete(Conversation::class.java)
|
realm.delete(Conversation::class.java)
|
||||||
@@ -125,26 +130,26 @@ class SyncRepositoryImpl @Inject constructor(
|
|||||||
|
|
||||||
// Migrate blocked conversations from 2.7.3
|
// Migrate blocked conversations from 2.7.3
|
||||||
val oldBlockedSenders = rxPrefs.getStringSet("pref_key_blocked_senders")
|
val oldBlockedSenders = rxPrefs.getStringSet("pref_key_blocked_senders")
|
||||||
persistedData += oldBlockedSenders.get()
|
oldBlockedSenders.get()
|
||||||
.map { threadIdString -> threadIdString.toLong() }
|
.map { threadIdString -> threadIdString.toLong() }
|
||||||
.filter { threadId -> persistedData.none { it.id == threadId } }
|
.filter { threadId -> !persistedData.contains(threadId) }
|
||||||
.map { threadId -> PersistedData(threadId, false, true, false, "") }
|
.forEach { threadId -> persistedData[threadId] = Conversation(id = threadId, blocked = true) }
|
||||||
|
|
||||||
// Sync conversations
|
// Sync conversations
|
||||||
conversationCursor?.use {
|
conversationCursor?.use {
|
||||||
val conversations = conversationCursor
|
val conversations = conversationCursor.map { cursor ->
|
||||||
.map { cursor ->
|
progress++
|
||||||
progress++
|
syncProgress.onNext(SyncRepository.SyncProgress.Running(max, progress, false))
|
||||||
syncProgress.onNext(SyncRepository.SyncProgress.Running(max, progress, false))
|
cursorToConversation.map(cursor).apply {
|
||||||
cursorToConversation.map(cursor)
|
persistedData[id]?.let { persistedConversation ->
|
||||||
|
archived = persistedConversation.archived
|
||||||
|
blocked = persistedConversation.blocked
|
||||||
|
pinned = persistedConversation.pinned
|
||||||
|
name = persistedConversation.name
|
||||||
|
blockingClient = persistedConversation.blockingClient
|
||||||
|
blockReason = persistedConversation.blockReason
|
||||||
}
|
}
|
||||||
|
}
|
||||||
persistedData.forEach { data ->
|
|
||||||
val conversation = conversations.firstOrNull { conversation -> conversation.id == data.id }
|
|
||||||
conversation?.archived = data.archived
|
|
||||||
conversation?.blocked = data.blocked
|
|
||||||
conversation?.pinned = data.pinned
|
|
||||||
conversation?.name = data.name
|
|
||||||
}
|
}
|
||||||
|
|
||||||
realm.where(Message::class.java)
|
realm.where(Message::class.java)
|
||||||
@@ -152,8 +157,7 @@ class SyncRepositoryImpl @Inject constructor(
|
|||||||
.distinct("threadId")
|
.distinct("threadId")
|
||||||
.findAll()
|
.findAll()
|
||||||
.forEach { message ->
|
.forEach { message ->
|
||||||
val conversation = conversations
|
val conversation = conversations.find { conversation -> conversation.id == message.threadId }
|
||||||
.firstOrNull { conversation -> conversation.id == message.threadId }
|
|
||||||
conversation?.date = message.date
|
conversation?.date = message.date
|
||||||
conversation?.snippet = message.getSummary()
|
conversation?.snippet = message.getSummary()
|
||||||
conversation?.me = message.isMe()
|
conversation?.me = message.isMe()
|
||||||
@@ -165,16 +169,15 @@ class SyncRepositoryImpl @Inject constructor(
|
|||||||
// Sync recipients
|
// Sync recipients
|
||||||
recipientCursor?.use {
|
recipientCursor?.use {
|
||||||
val contacts = realm.copyToRealm(getContacts())
|
val contacts = realm.copyToRealm(getContacts())
|
||||||
val recipients = recipientCursor
|
val recipients = recipientCursor.map { cursor ->
|
||||||
.map { cursor ->
|
progress++
|
||||||
progress++
|
syncProgress.onNext(SyncRepository.SyncProgress.Running(max, progress, false))
|
||||||
syncProgress.onNext(SyncRepository.SyncProgress.Running(max, progress, false))
|
cursorToRecipient.map(cursor).apply {
|
||||||
cursorToRecipient.map(cursor).apply {
|
contact = contacts.firstOrNull { contact ->
|
||||||
contact = contacts.firstOrNull { contact ->
|
contact.numbers.any { phoneNumberUtils.compare(address, it.address) }
|
||||||
contact.numbers.any { phoneNumberUtils.compare(address, it.address) }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
realm.insertOrUpdate(recipients)
|
realm.insertOrUpdate(recipients)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -29,14 +29,14 @@ interface BlockingClient {
|
|||||||
CANT_BLOCK
|
CANT_BLOCK
|
||||||
}
|
}
|
||||||
|
|
||||||
enum class Action {
|
sealed class Action {
|
||||||
BLOCK,
|
class Block(val reason: String? = null) : Action()
|
||||||
UNBLOCK,
|
object Unblock : Action()
|
||||||
|
|
||||||
// We only need these for Should I Answer, because they don't allow us to block numbers in their app directly.
|
// We only need these for Should I Answer, because they don't allow us to block numbers in their app directly.
|
||||||
// This means there's a good chance that if a number is blocked in QK, it won't be blocked there, so we
|
// This means there's a good chance that if a number is blocked in QK, it won't be blocked there, so we
|
||||||
// shouldn't unblock the conversation in that case
|
// shouldn't unblock the conversation in that case
|
||||||
DO_NOTHING
|
object DoNothing : Action()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -25,12 +25,16 @@ import javax.inject.Inject
|
|||||||
class MarkBlocked @Inject constructor(
|
class MarkBlocked @Inject constructor(
|
||||||
private val conversationRepo: ConversationRepository,
|
private val conversationRepo: ConversationRepository,
|
||||||
private val markRead: MarkRead
|
private val markRead: MarkRead
|
||||||
) : Interactor<List<Long>>() {
|
) : Interactor<MarkBlocked.Params>() {
|
||||||
|
|
||||||
override fun buildObservable(params: List<Long>): Flowable<*> {
|
data class Params(val threadIds: List<Long>, val blockingClient: Int, val blockReason: String?)
|
||||||
return Flowable.just(params.toLongArray())
|
|
||||||
.doOnNext { threadIds -> conversationRepo.markBlocked(*threadIds) }
|
override fun buildObservable(params: Params): Flowable<*> {
|
||||||
.flatMap { markRead.buildObservable(params) }
|
return Flowable.just(params)
|
||||||
|
.doOnNext { (threadIds, blockingClient, blockReason) ->
|
||||||
|
conversationRepo.markBlocked(threadIds, blockingClient, blockReason)
|
||||||
|
}
|
||||||
|
.flatMap { (threadIds) -> markRead.buildObservable(threadIds) }
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61,17 +61,17 @@ class ReceiveMms @Inject constructor(
|
|||||||
val shouldDrop = prefs.drop.get()
|
val shouldDrop = prefs.drop.get()
|
||||||
Timber.v("block=$action, drop=$shouldDrop")
|
Timber.v("block=$action, drop=$shouldDrop")
|
||||||
|
|
||||||
if (action == BlockingClient.Action.BLOCK && shouldDrop) {
|
if (action is BlockingClient.Action.Block && shouldDrop) {
|
||||||
messageRepo.deleteMessages(message.id)
|
messageRepo.deleteMessages(message.id)
|
||||||
return@mapNotNull null
|
return@mapNotNull null
|
||||||
}
|
}
|
||||||
|
|
||||||
when (action) {
|
when (action) {
|
||||||
BlockingClient.Action.BLOCK -> {
|
is BlockingClient.Action.Block -> {
|
||||||
messageRepo.markRead(message.threadId)
|
messageRepo.markRead(message.threadId)
|
||||||
conversationRepo.markBlocked(message.threadId)
|
conversationRepo.markBlocked(listOf(message.threadId), prefs.blockingManager.get(), action.reason)
|
||||||
}
|
}
|
||||||
BlockingClient.Action.UNBLOCK -> conversationRepo.markUnblocked(message.threadId)
|
is BlockingClient.Action.Unblock -> conversationRepo.markUnblocked(message.threadId)
|
||||||
else -> Unit
|
else -> Unit
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ class ReceiveSms @Inject constructor(
|
|||||||
Timber.v("block=$action, drop=$shouldDrop")
|
Timber.v("block=$action, drop=$shouldDrop")
|
||||||
|
|
||||||
// If we should drop the message, don't even save it
|
// If we should drop the message, don't even save it
|
||||||
if (action == BlockingClient.Action.BLOCK && shouldDrop) {
|
if (action is BlockingClient.Action.Block && shouldDrop) {
|
||||||
return@mapNotNull null
|
return@mapNotNull null
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,11 +67,11 @@ class ReceiveSms @Inject constructor(
|
|||||||
val message = messageRepo.insertReceivedSms(it.subId, address, body, time)
|
val message = messageRepo.insertReceivedSms(it.subId, address, body, time)
|
||||||
|
|
||||||
when (action) {
|
when (action) {
|
||||||
BlockingClient.Action.BLOCK -> {
|
is BlockingClient.Action.Block -> {
|
||||||
messageRepo.markRead(message.threadId)
|
messageRepo.markRead(message.threadId)
|
||||||
conversationRepo.markBlocked(message.threadId)
|
conversationRepo.markBlocked(listOf(message.threadId), prefs.blockingManager.get(), action.reason)
|
||||||
}
|
}
|
||||||
BlockingClient.Action.UNBLOCK -> conversationRepo.markUnblocked(message.threadId)
|
is BlockingClient.Action.Unblock -> conversationRepo.markUnblocked(message.threadId)
|
||||||
else -> Unit
|
else -> Unit
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -36,6 +36,9 @@ open class Conversation(
|
|||||||
var me: Boolean = false,
|
var me: Boolean = false,
|
||||||
var draft: String = "",
|
var draft: String = "",
|
||||||
|
|
||||||
|
var blockingClient: Int? = null,
|
||||||
|
var blockReason: String? = null,
|
||||||
|
|
||||||
var name: String = "" // For group chats, the user is allowed to set a custom title for the conversation
|
var name: String = "" // For group chats, the user is allowed to set a custom title for the conversation
|
||||||
) : RealmObject() {
|
) : RealmObject() {
|
||||||
|
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ interface ConversationRepository {
|
|||||||
|
|
||||||
fun markUnpinned(vararg threadIds: Long)
|
fun markUnpinned(vararg threadIds: Long)
|
||||||
|
|
||||||
fun markBlocked(vararg threadIds: Long)
|
fun markBlocked(threadIds: List<Long>, blockingClient: Int, blockReason: String?)
|
||||||
|
|
||||||
fun markUnblocked(vararg threadIds: Long)
|
fun markUnblocked(vararg threadIds: Long)
|
||||||
|
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ class BlockingDialog @Inject constructor(
|
|||||||
if (blockingManager.getClientCapability() == BlockingClient.Capability.BLOCK_WITHOUT_PERMISSION) {
|
if (blockingManager.getClientCapability() == BlockingClient.Capability.BLOCK_WITHOUT_PERMISSION) {
|
||||||
// If we can block/unblock in the external manager, then just fire that off and exit
|
// If we can block/unblock in the external manager, then just fire that off and exit
|
||||||
if (block) {
|
if (block) {
|
||||||
markBlocked.execute(conversationIds)
|
markBlocked.execute(MarkBlocked.Params(conversationIds, prefs.blockingManager.get(), null))
|
||||||
blockingManager.block(addresses).subscribe()
|
blockingManager.block(addresses).subscribe()
|
||||||
} else {
|
} else {
|
||||||
markUnblocked.execute(conversationIds)
|
markUnblocked.execute(conversationIds)
|
||||||
@@ -67,7 +67,7 @@ class BlockingDialog @Inject constructor(
|
|||||||
// If all of the addresses are already in their correct state in the blocking manager, just marked the
|
// If all of the addresses are already in their correct state in the blocking manager, just marked the
|
||||||
// conversations blocked and exit
|
// conversations blocked and exit
|
||||||
when (block) {
|
when (block) {
|
||||||
true -> markBlocked.execute(conversationIds)
|
true -> markBlocked.execute(MarkBlocked.Params(conversationIds, prefs.blockingManager.get(), null))
|
||||||
false -> markUnblocked.execute(conversationIds)
|
false -> markUnblocked.execute(conversationIds)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -77,7 +77,7 @@ class BlockingDialog @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun allBlocked(addresses: List<String>): Boolean = addresses.all { address ->
|
private fun allBlocked(addresses: List<String>): Boolean = addresses.all { address ->
|
||||||
blockingManager.getAction(address).blockingGet() == BlockingClient.Action.BLOCK
|
blockingManager.getAction(address).blockingGet() is BlockingClient.Action.Block
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun showDialog(
|
private suspend fun showDialog(
|
||||||
@@ -109,7 +109,7 @@ class BlockingDialog @Inject constructor(
|
|||||||
.setMessage(message)
|
.setMessage(message)
|
||||||
.setPositiveButton(R.string.button_continue) { _, _ ->
|
.setPositiveButton(R.string.button_continue) { _, _ ->
|
||||||
if (block) {
|
if (block) {
|
||||||
markBlocked.execute(conversationIds)
|
markBlocked.execute(MarkBlocked.Params(conversationIds, prefs.blockingManager.get(), null))
|
||||||
blockingManager.block(addresses).subscribe()
|
blockingManager.block(addresses).subscribe()
|
||||||
} else {
|
} else {
|
||||||
markUnblocked.execute(conversationIds)
|
markUnblocked.execute(conversationIds)
|
||||||
|
|||||||
+1
-1
@@ -117,6 +117,6 @@ class BlockingManagerPresenter @Inject constructor(
|
|||||||
|
|
||||||
private fun getAddressesToBlock(client: BlockingClient) = conversationRepo.getBlockedConversations()
|
private fun getAddressesToBlock(client: BlockingClient) = conversationRepo.getBlockedConversations()
|
||||||
.fold(listOf<String>(), { numbers, conversation -> numbers + conversation.recipients.map { it.address } })
|
.fold(listOf<String>(), { numbers, conversation -> numbers + conversation.recipients.map { it.address } })
|
||||||
.filter { number -> client.getAction(number).blockingGet() != BlockingClient.Action.BLOCK }
|
.filter { number -> client.getAction(number).blockingGet() !is BlockingClient.Action.Block }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+34
-2
@@ -18,22 +18,38 @@
|
|||||||
*/
|
*/
|
||||||
package com.moez.QKSMS.feature.blocking.messages
|
package com.moez.QKSMS.feature.blocking.messages
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.graphics.Typeface
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
|
import androidx.core.view.isVisible
|
||||||
import com.moez.QKSMS.R
|
import com.moez.QKSMS.R
|
||||||
import com.moez.QKSMS.common.base.QkRealmAdapter
|
import com.moez.QKSMS.common.base.QkRealmAdapter
|
||||||
import com.moez.QKSMS.common.base.QkViewHolder
|
import com.moez.QKSMS.common.base.QkViewHolder
|
||||||
|
import com.moez.QKSMS.common.util.DateFormatter
|
||||||
|
import com.moez.QKSMS.common.util.extensions.resolveThemeColor
|
||||||
import com.moez.QKSMS.model.Conversation
|
import com.moez.QKSMS.model.Conversation
|
||||||
|
import com.moez.QKSMS.util.Preferences
|
||||||
import io.reactivex.subjects.PublishSubject
|
import io.reactivex.subjects.PublishSubject
|
||||||
import kotlinx.android.synthetic.main.blocked_list_item.view.*
|
import kotlinx.android.synthetic.main.blocked_list_item.view.*
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
class BlockedMessagesAdapter @Inject constructor() : QkRealmAdapter<Conversation>() {
|
class BlockedMessagesAdapter @Inject constructor(
|
||||||
|
private val context: Context,
|
||||||
|
private val dateFormatter: DateFormatter
|
||||||
|
) : QkRealmAdapter<Conversation>() {
|
||||||
|
|
||||||
val clicks: PublishSubject<Long> = PublishSubject.create()
|
val clicks: PublishSubject<Long> = PublishSubject.create()
|
||||||
|
|
||||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): QkViewHolder {
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): QkViewHolder {
|
||||||
val view = LayoutInflater.from(parent.context).inflate(R.layout.blocked_list_item, parent, false)
|
val view = LayoutInflater.from(parent.context).inflate(R.layout.blocked_list_item, parent, false)
|
||||||
|
|
||||||
|
if (viewType == 0) {
|
||||||
|
view.title.setTypeface(view.title.typeface, Typeface.BOLD)
|
||||||
|
view.date.setTypeface(view.date.typeface, Typeface.BOLD)
|
||||||
|
view.date.setTextColor(view.context.resolveThemeColor(android.R.attr.textColorPrimary))
|
||||||
|
}
|
||||||
|
|
||||||
return QkViewHolder(view).apply {
|
return QkViewHolder(view).apply {
|
||||||
view.setOnClickListener {
|
view.setOnClickListener {
|
||||||
val conversation = getItem(adapterPosition) ?: return@setOnClickListener
|
val conversation = getItem(adapterPosition) ?: return@setOnClickListener
|
||||||
@@ -60,6 +76,22 @@ class BlockedMessagesAdapter @Inject constructor() : QkRealmAdapter<Conversation
|
|||||||
view.avatars.contacts = conversation.recipients
|
view.avatars.contacts = conversation.recipients
|
||||||
view.title.collapseEnabled = conversation.recipients.size > 1
|
view.title.collapseEnabled = conversation.recipients.size > 1
|
||||||
view.title.text = conversation.getTitle()
|
view.title.text = conversation.getTitle()
|
||||||
|
view.date.text = dateFormatter.getConversationTimestamp(conversation.date)
|
||||||
|
|
||||||
|
view.blocker.text = when (conversation.blockingClient) {
|
||||||
|
Preferences.BLOCKING_MANAGER_CC -> context.getString(R.string.blocking_manager_call_control_title)
|
||||||
|
Preferences.BLOCKING_MANAGER_SIA -> context.getString(R.string.blocking_manager_sia_title)
|
||||||
|
else -> null
|
||||||
|
}
|
||||||
|
|
||||||
|
view.reason.text = conversation.blockReason
|
||||||
|
view.blocker.isVisible = view.blocker.text.isNotEmpty()
|
||||||
|
view.reason.isVisible = view.blocker.text.isNotEmpty()
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
override fun getItemViewType(position: Int): Int {
|
||||||
|
val conversation = getItem(position)
|
||||||
|
return if (conversation?.read == true) 1 else 0
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
@@ -23,30 +23,73 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:background="?attr/selectableItemBackground"
|
android:background="?attr/selectableItemBackground"
|
||||||
android:paddingStart="16dp"
|
|
||||||
android:paddingTop="8dp"
|
android:paddingTop="8dp"
|
||||||
android:paddingEnd="16dp"
|
android:paddingBottom="8dp"
|
||||||
android:paddingBottom="8dp">
|
app:layout_constraintVertical_chainStyle="packed">
|
||||||
|
|
||||||
<com.moez.QKSMS.common.widget.GroupAvatarView
|
<com.moez.QKSMS.common.widget.GroupAvatarView
|
||||||
android:id="@+id/avatars"
|
android:id="@+id/avatars"
|
||||||
android:layout_width="48dp"
|
android:layout_width="48dp"
|
||||||
android:layout_height="48dp"
|
android:layout_height="48dp"
|
||||||
|
android:layout_marginStart="16dp"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
app:layout_constraintEnd_toStartOf="@id/title"
|
app:layout_constraintEnd_toStartOf="@id/title"
|
||||||
app:layout_constraintHorizontal_bias="0"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintStart_toStartOf="parent" />
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|
||||||
<com.moez.QKSMS.common.widget.QkTextView
|
<com.moez.QKSMS.common.widget.QkTextView
|
||||||
android:id="@+id/title"
|
android:id="@+id/title"
|
||||||
style="@style/TextPrimary"
|
style="@style/TextPrimary"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:paddingStart="16dp"
|
android:layout_marginStart="16dp"
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
android:layout_marginEnd="16dp"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintBottom_toTopOf="@id/blocker"
|
||||||
|
app:layout_constraintEnd_toStartOf="@id/date"
|
||||||
app:layout_constraintHorizontal_bias="0"
|
app:layout_constraintHorizontal_bias="0"
|
||||||
app:layout_constraintStart_toEndOf="@id/avatars"
|
app:layout_constraintStart_toEndOf="@id/avatars"
|
||||||
app:layout_constraintTop_toTopOf="parent"
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
|
app:textSize="primary"
|
||||||
tools:text="@tools:sample/full_names" />
|
tools:text="@tools:sample/full_names" />
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
<com.moez.QKSMS.common.widget.QkTextView
|
||||||
|
android:id="@+id/date"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginEnd="16dp"
|
||||||
|
android:textColor="?android:attr/textColorTertiary"
|
||||||
|
app:layout_constraintBottom_toBottomOf="@id/title"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toEndOf="@id/title"
|
||||||
|
app:layout_constraintTop_toTopOf="@id/title"
|
||||||
|
app:textSize="tertiary"
|
||||||
|
tools:text="Oct 5" />
|
||||||
|
|
||||||
|
<com.moez.QKSMS.common.widget.QkTextView
|
||||||
|
android:id="@+id/blocker"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="16dp"
|
||||||
|
android:layout_marginTop="2dp"
|
||||||
|
android:textColor="?android:attr/textColorTertiary"
|
||||||
|
android:textStyle="bold"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
app:layout_constraintStart_toEndOf="@id/avatars"
|
||||||
|
app:layout_constraintTop_toBottomOf="@id/title"
|
||||||
|
app:textSize="secondary"
|
||||||
|
tools:text="Call Control" />
|
||||||
|
|
||||||
|
<com.moez.QKSMS.common.widget.QkTextView
|
||||||
|
android:id="@+id/reason"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="4dp"
|
||||||
|
android:layout_marginEnd="16dp"
|
||||||
|
android:textColor="?android:attr/textColorTertiary"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toEndOf="@id/blocker"
|
||||||
|
app:layout_constraintTop_toTopOf="@id/blocker"
|
||||||
|
app:textSize="secondary"
|
||||||
|
tools:text="Manually Blocked" />
|
||||||
|
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
|
|||||||
Reference in New Issue
Block a user