Fix revealing spoilers in text stories.
This commit is contained in:
parent
e19c7efbfe
commit
3a341eee19
8 changed files with 17 additions and 6 deletions
|
@ -69,6 +69,7 @@ object SpoilerAnnotation {
|
|||
if (text is Spannable) {
|
||||
Selection.removeSelection(text)
|
||||
}
|
||||
widget.text = text
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3,7 +3,6 @@ package org.thoughtcrime.securesms.longmessage;
|
|||
import android.graphics.PorterDuff;
|
||||
import android.os.Bundle;
|
||||
import android.text.SpannableString;
|
||||
import android.text.method.LinkMovementMethod;
|
||||
import android.text.style.URLSpan;
|
||||
import android.text.util.Linkify;
|
||||
import android.util.TypedValue;
|
||||
|
@ -29,6 +28,7 @@ import org.thoughtcrime.securesms.conversation.colors.ColorizerView;
|
|||
import org.thoughtcrime.securesms.keyvalue.SignalStore;
|
||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||
import org.thoughtcrime.securesms.util.LinkUtil;
|
||||
import org.thoughtcrime.securesms.util.LongClickMovementMethod;
|
||||
import org.thoughtcrime.securesms.util.Projection;
|
||||
import org.thoughtcrime.securesms.util.ThemeUtil;
|
||||
import org.thoughtcrime.securesms.util.views.Stub;
|
||||
|
@ -131,7 +131,7 @@ public class LongMessageFragment extends FullScreenDialogFragment {
|
|||
|
||||
bubble.setVisibility(View.VISIBLE);
|
||||
text.setText(styledBody);
|
||||
text.setMovementMethod(LinkMovementMethod.getInstance());
|
||||
text.setMovementMethod(LongClickMovementMethod.getInstance(getContext()));
|
||||
text.setTextSize(TypedValue.COMPLEX_UNIT_SP, SignalStore.settings().getMessageFontSize());
|
||||
if (!message.get().getMessageRecord().isOutgoing()) {
|
||||
text.setMentionBackgroundTint(ContextCompat.getColor(requireContext(), ThemeUtil.isDarkTheme(requireActivity()) ? R.color.core_grey_60 : R.color.core_grey_20));
|
||||
|
|
|
@ -140,7 +140,7 @@ data class StoryTextPostModel(
|
|||
val useLargeThumbnail = source.text.isBlank()
|
||||
|
||||
view.setTypeface(typeface)
|
||||
view.bindFromStoryTextPost(source.storyTextPost, source.bodyRanges)
|
||||
view.bindFromStoryTextPost(source.storySentAtMillis, source.storyTextPost, source.bodyRanges)
|
||||
view.bindLinkPreview(linkPreview, useLargeThumbnail, loadThumbnail = false)
|
||||
view.postAdjustLinkPreviewTranslationY()
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@ import org.thoughtcrime.securesms.linkpreview.LinkPreviewViewModel
|
|||
import org.thoughtcrime.securesms.mediasend.v2.text.TextStoryPostCreationState
|
||||
import org.thoughtcrime.securesms.mediasend.v2.text.TextStoryScale
|
||||
import org.thoughtcrime.securesms.mediasend.v2.text.TextStoryTextWatcher
|
||||
import org.thoughtcrime.securesms.util.LongClickMovementMethod
|
||||
import org.thoughtcrime.securesms.util.concurrent.ListenableFuture
|
||||
import org.thoughtcrime.securesms.util.visible
|
||||
import java.util.Locale
|
||||
|
@ -47,6 +48,7 @@ class StoryTextPostView @JvmOverloads constructor(
|
|||
|
||||
init {
|
||||
TextStoryTextWatcher.install(textView)
|
||||
textView.movementMethod = LongClickMovementMethod.getInstance(context)
|
||||
}
|
||||
|
||||
fun getLinkPreviewThumbnailWidth(useLargeThumbnail: Boolean): Int {
|
||||
|
@ -122,7 +124,7 @@ class StoryTextPostView @JvmOverloads constructor(
|
|||
postAdjustLinkPreviewTranslationY()
|
||||
}
|
||||
|
||||
fun bindFromStoryTextPost(storyTextPost: StoryTextPost, bodyRanges: BodyRangeList?) {
|
||||
fun bindFromStoryTextPost(id: Long, storyTextPost: StoryTextPost, bodyRanges: BodyRangeList?) {
|
||||
visible = true
|
||||
linkPreviewView.visible = false
|
||||
|
||||
|
@ -134,7 +136,7 @@ class StoryTextPostView @JvmOverloads constructor(
|
|||
} else {
|
||||
val body = SpannableString(storyTextPost.body)
|
||||
if (font == TextFont.REGULAR && bodyRanges != null) {
|
||||
MessageStyler.style(System.currentTimeMillis(), bodyRanges, body)
|
||||
MessageStyler.style(id, bodyRanges, body)
|
||||
}
|
||||
setText(body, false)
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ import kotlin.time.Duration
|
|||
|
||||
sealed class StoryPostState {
|
||||
data class TextPost(
|
||||
val storyTextPostId: Long = 0L,
|
||||
val storyTextPost: StoryTextPost? = null,
|
||||
val linkPreview: LinkPreview? = null,
|
||||
val typeface: Typeface? = null,
|
||||
|
|
|
@ -90,6 +90,7 @@ class StoryPostViewModel(private val repository: StoryTextPostRepository) : View
|
|||
|
||||
store.update {
|
||||
StoryPostState.TextPost(
|
||||
storyTextPostId = record.id,
|
||||
storyTextPost = text,
|
||||
linkPreview = linkPreview,
|
||||
typeface = t,
|
||||
|
|
|
@ -21,7 +21,7 @@ class StoryTextLoader(
|
|||
) {
|
||||
|
||||
fun load() {
|
||||
text.bindFromStoryTextPost(state.storyTextPost!!, state.bodyRanges)
|
||||
text.bindFromStoryTextPost(state.storyTextPostId, state.storyTextPost!!, state.bodyRanges)
|
||||
text.bindLinkPreview(state.linkPreview, state.storyTextPost.body.isBlank())
|
||||
text.postAdjustLinkPreviewTranslationY()
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@ import androidx.core.content.ContextCompat;
|
|||
|
||||
import org.thoughtcrime.securesms.R;
|
||||
import org.thoughtcrime.securesms.components.spoiler.SpoilerAnnotation;
|
||||
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
|
||||
|
@ -116,6 +117,11 @@ public class LongClickMovementMethod extends LinkMovementMethod {
|
|||
return super.onTouchEvent(widget, buffer, event);
|
||||
}
|
||||
|
||||
/** This signature is available in the base class and can lead to the wrong instance being returned. */
|
||||
public static LongClickMovementMethod getInstance() {
|
||||
return getInstance(ApplicationDependencies.getApplication());
|
||||
}
|
||||
|
||||
public static LongClickMovementMethod getInstance(Context context) {
|
||||
if (sInstance == null) {
|
||||
sInstance = new LongClickMovementMethod(context.getApplicationContext());
|
||||
|
|
Loading…
Add table
Reference in a new issue