Adjusted EditGroupMembers to match iOS and fixed up save attachment commentary / logic

This commit is contained in:
alansley 2024-08-28 13:55:04 +10:00
parent ae7164ecbb
commit 413bc0be4b
10 changed files with 38 additions and 36 deletions

View File

@ -408,7 +408,7 @@ public class MediaPreviewActivity extends PassphraseRequiredActionBarActivity im
MediaItem mediaItem = getCurrentMediaItem(); MediaItem mediaItem = getCurrentMediaItem();
if (mediaItem == null) return; if (mediaItem == null) return;
SaveAttachmentTask.showWarningDialog(this, 1, () -> { SaveAttachmentTask.showOneTimeWarningDialogOrSave(this, 1, () -> {
Permissions.with(this) Permissions.with(this)
.request(android.Manifest.permission.WRITE_EXTERNAL_STORAGE) .request(android.Manifest.permission.WRITE_EXTERNAL_STORAGE)
.maxSdkVersion(Build.VERSION_CODES.P) .maxSdkVersion(Build.VERSION_CODES.P)

View File

@ -29,7 +29,6 @@ import network.loki.messenger.R
import network.loki.messenger.databinding.ActivityWebrtcBinding import network.loki.messenger.databinding.ActivityWebrtcBinding
import org.apache.commons.lang3.time.DurationFormatUtils import org.apache.commons.lang3.time.DurationFormatUtils
import org.session.libsession.messaging.contacts.Contact import org.session.libsession.messaging.contacts.Contact
import org.session.libsession.utilities.Address
import org.session.libsession.utilities.StringSubstitutionConstants.APP_NAME_KEY import org.session.libsession.utilities.StringSubstitutionConstants.APP_NAME_KEY
import org.session.libsession.utilities.TextSecurePreferences import org.session.libsession.utilities.TextSecurePreferences
import org.session.libsession.utilities.truncateIdForDisplay import org.session.libsession.utilities.truncateIdForDisplay
@ -207,7 +206,6 @@ class WebRtcCallActivity : PassphraseRequiredActionBarActivity() {
} }
} }
// Substitute "Session" into the "{app_name} Call" text // Substitute "Session" into the "{app_name} Call" text
val sessionCallTV = findViewById<TextView>(R.id.sessionCallText) val sessionCallTV = findViewById<TextView>(R.id.sessionCallText)
sessionCallTV?.text = Phrase.from(this, R.string.callsSessionCall).put(APP_NAME_KEY, getString(R.string.app_name)).format() sessionCallTV?.text = Phrase.from(this, R.string.callsSessionCall).put(APP_NAME_KEY, getString(R.string.app_name)).format()

View File

@ -103,6 +103,7 @@ import org.session.libsignal.utilities.guava.Optional
import org.session.libsignal.utilities.hexEncodedPrivateKey import org.session.libsignal.utilities.hexEncodedPrivateKey
import org.thoughtcrime.securesms.ApplicationContext import org.thoughtcrime.securesms.ApplicationContext
import org.thoughtcrime.securesms.PassphraseRequiredActionBarActivity import org.thoughtcrime.securesms.PassphraseRequiredActionBarActivity
import org.thoughtcrime.securesms.SessionDialogBuilder
import org.thoughtcrime.securesms.attachments.ScreenshotObserver import org.thoughtcrime.securesms.attachments.ScreenshotObserver
import org.thoughtcrime.securesms.audio.AudioRecorder import org.thoughtcrime.securesms.audio.AudioRecorder
import org.thoughtcrime.securesms.components.emoji.RecentEmojiPageModel import org.thoughtcrime.securesms.components.emoji.RecentEmojiPageModel
@ -2229,6 +2230,11 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
return return
} }
// Before saving an attachment, regardless of Android API version or permissions, we always want to ensure
// 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. // 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 // 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.. // If we already have permission to write to external storage then just get on with it & return..
@ -2239,20 +2245,19 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
if (hasPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE)) { if (hasPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
saveAttachments(message) saveAttachments(message)
return return
} else {
/* Do nothing - which means we continue on to the SaveAttachmentTask part below where we ask for permissions */
} }
} else { } else {
// On more modern versions of Android on API 30+ WRITE_EXTERNAL_STORAGE is no longer used and we can just // On more modern versions of Android on API 30+ WRITE_EXTERNAL_STORAGE is no longer used and we can just
// save files to the public directories like "Downloads", "Pictures" etc. - but... we would still like to // save files to the public directories like "Downloads", "Pictures" etc.
// inform the user just _once_ that saving attachments means that other apps can access them - so we'll
val haveWarned = TextSecurePreferences.getHaveWarnedUserAboutSavingAttachments(this)
if (haveWarned) {
saveAttachments(message) saveAttachments(message)
return return
} }
} }
// ..otherwise we must ask for it first. // ..otherwise we must ask for it first (only on Android APIs up to 28).
SaveAttachmentTask.showWarningDialog(this) { SaveAttachmentTask.showOneTimeWarningDialogOrSave(this) {
Permissions.with(this) Permissions.with(this)
.request(Manifest.permission.WRITE_EXTERNAL_STORAGE) .request(Manifest.permission.WRITE_EXTERNAL_STORAGE)
.maxSdkVersion(Build.VERSION_CODES.P) // P is 28 .maxSdkVersion(Build.VERSION_CODES.P) // P is 28
@ -2262,6 +2267,7 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
.onAnyDenied { .onAnyDenied {
endActionMode() endActionMode()
// If permissions were denied inform the user that we can't proceed without them and offer to take the user to Settings
showSessionDialog { showSessionDialog {
title(R.string.permissionsRequired) title(R.string.permissionsRequired)

View File

@ -16,6 +16,7 @@
*/ */
package org.thoughtcrime.securesms.conversation.v2.utilities; package org.thoughtcrime.securesms.conversation.v2.utilities;
import static com.google.android.gms.common.util.CollectionUtils.listOf;
import static org.session.libsession.utilities.StringSubstitutionConstants.APP_NAME_KEY; import static org.session.libsession.utilities.StringSubstitutionConstants.APP_NAME_KEY;
import android.Manifest; import android.Manifest;
@ -256,9 +257,9 @@ public class AttachmentManager {
} }
Context c = activity.getApplicationContext(); Context c = activity.getApplicationContext();
String needStoragePermissionTxt = Phrase.from(c, R.string.permissionsStorageSend)
.put(APP_NAME_KEY, c.getString(R.string.app_name)) String needStoragePermissionTxt = Phrase.from(c, R.string.permissionsStorageSend).put(APP_NAME_KEY, c.getString(R.string.app_name)).format().toString();
.format().toString();
String storagePermissionDeniedTxt = Phrase.from(c, R.string.permissionsStorageSaveDenied) String storagePermissionDeniedTxt = Phrase.from(c, R.string.permissionsStorageSaveDenied)
.put(APP_NAME_KEY, c.getString(R.string.app_name)) .put(APP_NAME_KEY, c.getString(R.string.app_name))
.format().toString(); .format().toString();

View File

@ -3,6 +3,8 @@ package org.thoughtcrime.securesms.groups
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import android.os.Bundle import android.os.Bundle
import android.text.SpannableString
import android.text.style.StyleSpan
import android.view.Menu import android.view.Menu
import android.view.MenuItem import android.view.MenuItem
import android.view.View import android.view.View
@ -175,10 +177,6 @@ class EditClosedGroupActivity : PassphraseRequiredActionBarActivity() {
originalMembers.clear() originalMembers.clear()
originalMembers.addAll(members + zombies) originalMembers.addAll(members + zombies)
updateMembers() updateMembers()
// Now that we have the group members we can update the text on the member count
val memberCountTV = findViewById<TextView>(R.id.editGroupMemberCount)
memberCountTV.text = resources.getQuantityString(R.plurals.members, members.size, members.size)
} }
override fun onLoaderReset(loader: Loader<GroupMembers>) { override fun onLoaderReset(loader: Loader<GroupMembers>) {

View File

@ -5,6 +5,7 @@ import android.content.Context
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.ui.platform.ComposeView import androidx.compose.ui.platform.ComposeView
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import com.squareup.phrase.Phrase
import org.thoughtcrime.securesms.ui.theme.SessionMaterialTheme import org.thoughtcrime.securesms.ui.theme.SessionMaterialTheme
fun Activity.setComposeContent(content: @Composable () -> Unit) { fun Activity.setComposeContent(content: @Composable () -> Unit) {

View File

@ -44,7 +44,7 @@ class SaveAttachmentTask @JvmOverloads constructor(context: Context, count: Int
@JvmStatic @JvmStatic
@JvmOverloads @JvmOverloads
fun showWarningDialog(context: Context, count: Int = 1, onAcceptListener: () -> Unit = {}) { fun showOneTimeWarningDialogOrSave(context: Context, count: Int = 1, onAcceptListener: () -> Unit = {}) {
// If we've already warned the user that saved attachments can be accessed by other apps // If we've already warned the user that saved attachments can be accessed by other apps
// then we'll just perform the save.. // then we'll just perform the save..
val haveWarned = TextSecurePreferences.getHaveWarnedUserAboutSavingAttachments(context) val haveWarned = TextSecurePreferences.getHaveWarnedUserAboutSavingAttachments(context)
@ -58,10 +58,7 @@ class SaveAttachmentTask @JvmOverloads constructor(context: Context, count: Int
iconAttribute(R.attr.dialog_alert_icon) iconAttribute(R.attr.dialog_alert_icon)
text(context.getString(R.string.attachmentsWarning)) text(context.getString(R.string.attachmentsWarning))
dangerButton(R.string.save) { dangerButton(R.string.save) {
// Regardless of Android API version, we'll always warn the user that saved attachments // Set our 'haveWarned' SharedPref and perform the save on accept
// can be accessed by other apps - but we'll only ever do this ONCE. When the user accepts
// this warning and agrees to proceed we write a shared pref flag and will never show this
// warning again due to the early-exit condition at the top of this method.
TextSecurePreferences.setHaveWarnedUserAboutSavingAttachments(context) TextSecurePreferences.setHaveWarnedUserAboutSavingAttachments(context)
onAcceptListener() onAcceptListener()
} }

View File

@ -112,7 +112,7 @@
android:layout_marginEnd="@dimen/small_spacing" android:layout_marginEnd="@dimen/small_spacing"
android:layout_marginBottom="@dimen/small_spacing" android:layout_marginBottom="@dimen/small_spacing"
android:layout_weight="1" android:layout_weight="1"
android:text="{count} members" android:text="@string/groupMembers"
android:textColor="?android:textColorPrimary" android:textColor="?android:textColorPrimary"
android:textSize="@dimen/medium_font_size" /> android:textSize="@dimen/medium_font_size" />

View File

@ -2,6 +2,7 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android" <menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"> xmlns:app="http://schemas.android.com/apk/res-auto">
<!-- TODO: To match iOS this should display as "Done" - but here on Android it displays as "DONE" - style change req'd? -->
<item <item
android:title="@string/done" android:title="@string/done"
android:id="@+id/doneButton" android:id="@+id/doneButton"

View File

@ -5,7 +5,7 @@
<item <item
android:id="@+id/action_apply" android:id="@+id/action_apply"
android:title="@string/set" android:title="@string/done"
android:contentDescription="@string/AccessibilityId_set" android:contentDescription="@string/AccessibilityId_set"
app:showAsAction="always|withText" /> app:showAsAction="always|withText" />