mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-23 18:15:22 +00:00
Addressed changes to fix SS-64 / QA-146 - unblocking contacts modal & toast adjustments
This commit is contained in:
parent
e812527358
commit
e3d4870d81
@ -772,7 +772,12 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
|
||||
val recipient = viewModel.recipient?.takeUnless { it.isGroupRecipient } ?: return
|
||||
binding.blockedBannerTextView.text = applicationContext.getString(R.string.blockBlockedDescription)
|
||||
binding.blockedBanner.isVisible = recipient.isBlocked
|
||||
binding.blockedBanner.setOnClickListener { viewModel.unblock() }
|
||||
binding.blockedBanner.setOnClickListener {
|
||||
viewModel.unblock()
|
||||
// Unblock confirmation toast added as per SS-64
|
||||
val txt = Phrase.from(applicationContext, R.string.blockUnblockedUser).put(NAME_KEY, recipient.name).format().toString()
|
||||
Toast.makeText(applicationContext, txt, Toast.LENGTH_LONG).show()
|
||||
}
|
||||
}
|
||||
|
||||
private fun setUpOutdatedClientBanner() {
|
||||
@ -1244,9 +1249,7 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
|
||||
viewModel.unblock()
|
||||
|
||||
// Unblock confirmation toast added as per SS-64
|
||||
val txt = Phrase.from(context, R.string.blockUnblockedUser)
|
||||
.put(NAME_KEY, recipient.name).
|
||||
format().toString()
|
||||
val txt = Phrase.from(context, R.string.blockUnblockedUser).put(NAME_KEY, recipient.name).format().toString()
|
||||
Toast.makeText(context, txt, Toast.LENGTH_LONG).show()
|
||||
}
|
||||
cancelButton()
|
||||
|
@ -1,11 +1,19 @@
|
||||
package org.thoughtcrime.securesms.preferences
|
||||
|
||||
import android.content.Context
|
||||
import android.os.Bundle
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import android.widget.Toast
|
||||
import androidx.activity.viewModels
|
||||
import androidx.core.view.isVisible
|
||||
import com.squareup.phrase.Phrase
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import network.loki.messenger.R
|
||||
import network.loki.messenger.databinding.ActivityBlockedContactsBinding
|
||||
import org.session.libsession.utilities.StringSubstitutionConstants.COUNT_KEY
|
||||
import org.session.libsession.utilities.StringSubstitutionConstants.NAME_KEY
|
||||
import org.session.libsignal.utilities.Log
|
||||
import org.thoughtcrime.securesms.PassphraseRequiredActionBarActivity
|
||||
import org.thoughtcrime.securesms.showSessionDialog
|
||||
|
||||
@ -18,11 +26,68 @@ class BlockedContactsActivity: PassphraseRequiredActionBarActivity() {
|
||||
|
||||
val adapter: BlockedContactsAdapter by lazy { BlockedContactsAdapter(viewModel) }
|
||||
|
||||
// Method to show a sequence of toasts one after the other
|
||||
fun showToastSequence(toastStrings: List<String>, toastLengthSetting: Int,context: Context) {
|
||||
val handler = Handler(Looper.getMainLooper())
|
||||
|
||||
val delayStepMilliseconds = when (toastLengthSetting) {
|
||||
Toast.LENGTH_SHORT -> 2000L
|
||||
Toast.LENGTH_LONG -> 3500L
|
||||
else -> {
|
||||
Log.w("BlockContactsActivity", "Invalid toast length setting - using Toast.LENGTH_SHORT")
|
||||
2000L
|
||||
}
|
||||
}
|
||||
|
||||
var delayMilliseconds = 0L
|
||||
toastStrings.forEach { message ->
|
||||
handler.postDelayed( { Toast.makeText(context, message, Toast.LENGTH_SHORT).show() }, delayMilliseconds)
|
||||
delayMilliseconds += delayStepMilliseconds // Increment delay by the duration of a Toast message
|
||||
}
|
||||
}
|
||||
|
||||
fun unblock() {
|
||||
showSessionDialog {
|
||||
title(viewModel.getTitle(this@BlockedContactsActivity))
|
||||
text(viewModel.getMessage(this@BlockedContactsActivity))
|
||||
button(R.string.theContinue) { viewModel.unblock() }
|
||||
|
||||
|
||||
val contactsToUnblock = viewModel.state.selectedItems
|
||||
|
||||
// Get the names of each person to unblock for later user in the toast(s)
|
||||
// Note: We must do this before `viewModel.unblock`
|
||||
//val contactsToUnblockNames = contactsToUnblock.map { it.name }
|
||||
|
||||
val numContactsToUnblock = contactsToUnblock.size
|
||||
val txt = when (numContactsToUnblock) {
|
||||
// Note: We do not have to handle 0 because if no contacts are chosen then the unblock button is deactivated
|
||||
1 -> Phrase.from(context, R.string.blockUnblockName)
|
||||
.put(NAME_KEY, contactsToUnblock.elementAt(0).name)
|
||||
.format().toString()
|
||||
2 -> Phrase.from(context, R.string.blockUnblockNameTwo)
|
||||
.put(NAME_KEY, contactsToUnblock.elementAt(0).name)
|
||||
.format().toString()
|
||||
else -> {
|
||||
val othersCount = contactsToUnblock.size - 1
|
||||
Phrase.from(context, R.string.blockUnblockNameMultiple)
|
||||
.put(NAME_KEY, contactsToUnblock.elementAt(0).name)
|
||||
.put(COUNT_KEY, othersCount)
|
||||
.format().toString()
|
||||
}
|
||||
}
|
||||
|
||||
text(txt)
|
||||
|
||||
button(R.string.theContinue) {
|
||||
// Show individual toasts for each unblocked user (we don't have suitable strings to do it as a single toast)
|
||||
val contactsToUnblockNames = contactsToUnblock.map { it.name }
|
||||
val toastStrings = mutableListOf<String>()
|
||||
for (name in contactsToUnblockNames) {
|
||||
toastStrings.add(Phrase.from(context, R.string.blockUnblockedUser).put(NAME_KEY, name).format().toString())
|
||||
}
|
||||
showToastSequence(toastStrings, Toast.LENGTH_SHORT, this@BlockedContactsActivity)
|
||||
|
||||
viewModel.unblock()
|
||||
}
|
||||
cancelButton()
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Button
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:contentDescription="@string/AccessibilityId_conversationsBlockedContacts"
|
||||
style="@style/Widget.Session.Button.Common.Borderless"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
@ -9,6 +8,7 @@
|
||||
android:layout_marginHorizontal="@dimen/large_spacing"
|
||||
android:layout_marginVertical="@dimen/medium_spacing"
|
||||
android:text="@string/conversationsBlockedContacts"
|
||||
android:contentDescription="@string/AccessibilityId_conversationsBlockedContacts"
|
||||
android:textColor="?danger"
|
||||
android:textSize="16sp"
|
||||
android:textStyle="bold"
|
||||
|
Loading…
Reference in New Issue
Block a user