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