mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-27 20:15:21 +00:00
Moved block/unblock string selection logic into ViewModel and fixed a comment
This commit is contained in:
parent
736b5313e6
commit
dfebe6f3f9
@ -2234,19 +2234,14 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
|
||||
// that we've warned the user just _once_ that any attachments they save can be accessed by other apps.
|
||||
val haveWarned = TextSecurePreferences.getHaveWarnedUserAboutSavingAttachments(this)
|
||||
if (haveWarned) {
|
||||
|
||||
// On Android versions below 30 we require the WRITE_EXTERNAL_STORAGE permission to save attachments.
|
||||
// However, we would like to on more recent Android API versions there is scoped storage
|
||||
// If we already have permission to write to external storage then just get on with it & return..
|
||||
//
|
||||
// Android versions will j
|
||||
if (Build.VERSION.SDK_INT < 30) {
|
||||
// Save the attachment(s) then bail if we already have permission to do so
|
||||
if (hasPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
|
||||
saveAttachments(message)
|
||||
return
|
||||
} else {
|
||||
/* Do nothing - which means we continue on to the SaveAttachmentTask part below where we ask for permissions */
|
||||
/* If we don't have the permission then do nothing - which means we continue on to the SaveAttachmentTask part below where we ask for permissions */
|
||||
}
|
||||
} else {
|
||||
// On more modern versions of Android on API 30+ WRITE_EXTERNAL_STORAGE is no longer used and we can just
|
||||
|
@ -1,19 +1,11 @@
|
||||
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
|
||||
|
||||
@ -29,27 +21,7 @@ class BlockedContactsActivity: PassphraseRequiredActionBarActivity() {
|
||||
private fun unblock() {
|
||||
showSessionDialog {
|
||||
title(viewModel.getTitle(this@BlockedContactsActivity))
|
||||
|
||||
val contactsToUnblock = viewModel.state.selectedItems
|
||||
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)
|
||||
|
||||
text(viewModel.getText(context, viewModel.state.selectedItems))
|
||||
dangerButton(R.string.blockUnblock, R.string.AccessibilityId_unblockConfirm) { viewModel.unblock() }
|
||||
cancelButton()
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import app.cash.copper.flow.observeQuery
|
||||
import com.squareup.phrase.Phrase
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import kotlinx.coroutines.Dispatchers.IO
|
||||
import kotlinx.coroutines.Dispatchers.Main
|
||||
@ -18,6 +19,8 @@ import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.plus
|
||||
import kotlinx.coroutines.withContext
|
||||
import network.loki.messenger.R
|
||||
import org.session.libsession.utilities.StringSubstitutionConstants.COUNT_KEY
|
||||
import org.session.libsession.utilities.StringSubstitutionConstants.NAME_KEY
|
||||
import org.session.libsession.utilities.recipients.Recipient
|
||||
import org.thoughtcrime.securesms.database.DatabaseContentProviders
|
||||
import org.thoughtcrime.securesms.database.Storage
|
||||
@ -74,6 +77,26 @@ class BlockedContactsViewModel @Inject constructor(private val storage: Storage)
|
||||
|
||||
fun getTitle(context: Context): String = context.getString(R.string.blockUnblock)
|
||||
|
||||
// Method to get the appropriate text to display when unblocking 1, 2, or several contacts
|
||||
fun getText(context: Context, contactsToUnblock: Set<Recipient>): String {
|
||||
return when (contactsToUnblock.size) {
|
||||
// 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()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun getMessage(context: Context): String = context.getString(R.string.blockUnblock)
|
||||
|
||||
fun toggle(selectable: SelectableItem<Recipient>) {
|
||||
|
Loading…
Reference in New Issue
Block a user