forked from upstream-mirrors/quik
Show blocking reason if available
This commit is contained in:
@@ -57,7 +57,7 @@ class BlockingDialog @Inject constructor(
|
||||
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 (block) {
|
||||
markBlocked.execute(conversationIds)
|
||||
markBlocked.execute(MarkBlocked.Params(conversationIds, prefs.blockingManager.get(), null))
|
||||
blockingManager.block(addresses).subscribe()
|
||||
} else {
|
||||
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
|
||||
// conversations blocked and exit
|
||||
when (block) {
|
||||
true -> markBlocked.execute(conversationIds)
|
||||
true -> markBlocked.execute(MarkBlocked.Params(conversationIds, prefs.blockingManager.get(), null))
|
||||
false -> markUnblocked.execute(conversationIds)
|
||||
}
|
||||
} else {
|
||||
@@ -77,7 +77,7 @@ class BlockingDialog @Inject constructor(
|
||||
}
|
||||
|
||||
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(
|
||||
@@ -109,7 +109,7 @@ class BlockingDialog @Inject constructor(
|
||||
.setMessage(message)
|
||||
.setPositiveButton(R.string.button_continue) { _, _ ->
|
||||
if (block) {
|
||||
markBlocked.execute(conversationIds)
|
||||
markBlocked.execute(MarkBlocked.Params(conversationIds, prefs.blockingManager.get(), null))
|
||||
blockingManager.block(addresses).subscribe()
|
||||
} else {
|
||||
markUnblocked.execute(conversationIds)
|
||||
|
||||
+1
-1
@@ -117,6 +117,6 @@ class BlockingManagerPresenter @Inject constructor(
|
||||
|
||||
private fun getAddressesToBlock(client: BlockingClient) = conversationRepo.getBlockedConversations()
|
||||
.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
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.Typeface
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import androidx.core.view.isVisible
|
||||
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.DateFormatter
|
||||
import com.moez.QKSMS.common.util.extensions.resolveThemeColor
|
||||
import com.moez.QKSMS.model.Conversation
|
||||
import com.moez.QKSMS.util.Preferences
|
||||
import io.reactivex.subjects.PublishSubject
|
||||
import kotlinx.android.synthetic.main.blocked_list_item.view.*
|
||||
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()
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): QkViewHolder {
|
||||
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 {
|
||||
view.setOnClickListener {
|
||||
val conversation = getItem(adapterPosition) ?: return@setOnClickListener
|
||||
@@ -60,6 +76,22 @@ class BlockedMessagesAdapter @Inject constructor() : QkRealmAdapter<Conversation
|
||||
view.avatars.contacts = conversation.recipients
|
||||
view.title.collapseEnabled = conversation.recipients.size > 1
|
||||
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_height="wrap_content"
|
||||
android:background="?attr/selectableItemBackground"
|
||||
android:paddingStart="16dp"
|
||||
android:paddingTop="8dp"
|
||||
android:paddingEnd="16dp"
|
||||
android:paddingBottom="8dp">
|
||||
android:paddingBottom="8dp"
|
||||
app:layout_constraintVertical_chainStyle="packed">
|
||||
|
||||
<com.moez.QKSMS.common.widget.GroupAvatarView
|
||||
android:id="@+id/avatars"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
android:layout_marginStart="16dp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
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
|
||||
android:id="@+id/title"
|
||||
style="@style/TextPrimary"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingStart="16dp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
app:layout_constraintBottom_toTopOf="@id/blocker"
|
||||
app:layout_constraintEnd_toStartOf="@id/date"
|
||||
app:layout_constraintHorizontal_bias="0"
|
||||
app:layout_constraintStart_toEndOf="@id/avatars"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:textSize="primary"
|
||||
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