Implemented task SS-79 to only provide a save attachment menu option when the attachment download is complete

This commit is contained in:
alansley
2024-08-02 12:15:42 +10:00
parent 20662c8222
commit ba2d0275e4
4 changed files with 17 additions and 11 deletions

View File

@@ -2146,9 +2146,11 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
override fun saveAttachment(messages: Set<MessageRecord>) {
val message = messages.first() as MmsMessageRecord
// Do not allow the user to download a file attachment before it has finished downloading
// Note: The save option is only added to the menu in ConversationReactionOverlay.getMenuActionItems
// if the attachment has finished downloading, so we don't really have to check for message.isMediaPending
// here - but we'll do it anyway and bail should that be the case as a defensive programming strategy.
if (message.isMediaPending) {
Toast.makeText(this, resources.getString(R.string.conversation_activity__wait_until_attachment_has_finished_downloading), Toast.LENGTH_LONG).show()
Log.w(TAG, "Somehow we were asked to download an attachment before it had finished downloading - aborting download.")
return
}

View File

@@ -39,6 +39,7 @@ import org.session.libsession.snode.SnodeAPI
import org.session.libsession.utilities.StringSubstitutionConstants.TIME_LARGE_KEY
import org.session.libsession.utilities.TextSecurePreferences.Companion.getLocalNumber
import org.session.libsession.utilities.ThemeUtil
import org.session.libsignal.utilities.Log
import org.thoughtcrime.securesms.components.emoji.EmojiImageView
import org.thoughtcrime.securesms.components.emoji.RecentEmojiPageModel
import org.thoughtcrime.securesms.components.menu.ActionItem
@@ -564,9 +565,17 @@ class ConversationReactionOverlay : FrameLayout {
if (message.isSyncFailed) {
items += ActionItem(R.attr.menu_reply_icon, R.string.resync, { handleActionItemClicked(Action.RESYNC) })
}
// Save media
if (message.isMms && (message as MediaMmsMessageRecord).containsMediaSlide()) {
items += ActionItem(R.attr.menu_save_icon, R.string.save, { handleActionItemClicked(Action.DOWNLOAD) }, R.string.AccessibilityId_save_attachment)
// Save media..
if (message.isMms) {
// ..but only provide the save option if the there is a media attachment which has finished downloading.
val mmsMessage = message as MediaMmsMessageRecord
if (mmsMessage.containsMediaSlide() && !mmsMessage.isMediaPending) {
items += ActionItem(R.attr.menu_save_icon,
R.string.save,
{ handleActionItemClicked(Action.DOWNLOAD) },
R.string.AccessibilityId_save_attachment
)
}
}
backgroundView.visibility = VISIBLE
foregroundView.visibility = VISIBLE