Add blocked banner

This commit is contained in:
Niels Andriesse 2021-06-24 14:21:05 +10:00
parent ec8d4c9f5d
commit c0429569db
3 changed files with 43 additions and 1 deletions

View File

@ -27,6 +27,7 @@ import kotlinx.android.synthetic.main.view_input_bar_recording.*
import kotlinx.android.synthetic.main.view_input_bar_recording.view.*
import network.loki.messenger.R
import nl.komponents.kovenant.ui.successUi
import org.session.libsession.messaging.contacts.Contact
import org.session.libsession.messaging.mentions.MentionsManager
import org.session.libsession.messaging.open_groups.OpenGroupAPIV2
import org.session.libsession.utilities.recipients.Recipient
@ -120,6 +121,7 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
setUpTypingObserver()
updateSubtitle()
getLatestOpenGroupInfoIfNeeded()
setUpBlockedBanner()
}
private fun setUpRecyclerView() {
@ -203,6 +205,17 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
OpenGroupAPIV2.getMemberCount(openGroup.room, openGroup.server).successUi { updateSubtitle() }
}
private fun setUpBlockedBanner() {
if (thread.isGroupRecipient) { return }
val contactDB = DatabaseFactory.getSessionContactDatabase(this)
val sessionID = thread.address.toString()
val contact = contactDB.getContactWithSessionID(sessionID)
val name = contact?.displayName(Contact.ContactContext.REGULAR) ?: sessionID
blockedBannerTextView.text = resources.getString(R.string.activity_conversation_blocked_banner_text, name)
blockedBanner.isVisible = thread.isBlocked
blockedBanner.setOnClickListener { unblock() }
}
override fun onPrepareOptionsMenu(menu: Menu): Boolean {
ConversationMenuHelper.onPrepareOptionsMenu(menu, menuInflater, thread, this) { onOptionsItemSelected(it) }
super.onPrepareOptionsMenu(menu)
@ -492,6 +505,10 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
lockViewLocation[0] + lockView.width + lockViewHitMargin, lockViewLocation[1] + lockView.height)
return hitRect.contains(x, y)
}
private fun unblock() {
// TODO: Implement
}
// endregion
// region General

View File

@ -1,6 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
<RelativeLayout
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"
android:id="@+id/contentView"
android:layout_width="match_parent"
android:layout_height="match_parent"
@ -135,4 +137,26 @@
android:visibility="gone"
android:layout_alignParentBottom="true" />
<RelativeLayout
android:id="@+id/blockedBanner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/destructive"
android:layout_alignParentTop="true"
android:visibility="gone"
tools:visibility="visible">
<TextView
android:id="@+id/blockedBannerTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_margin="@dimen/medium_spacing"
android:textSize="@dimen/small_font_size"
android:textColor="@color/white"
android:textStyle="bold"
tools:text="Elon is blocked. Unblock them?" />
</RelativeLayout>
</RelativeLayout>

View File

@ -871,4 +871,5 @@
<string name="dialog_download_explanation">Are you sure you want to download media sent by %s?</string>
<string name="dialog_download_button_title">Download</string>
<string name="activity_conversation_blocked_banner_text">%s is blocked. Unblock them?</string>
</resources>