Attempt to fix custom emoji freeze bug
This commit is contained in:
parent
05ddc762c7
commit
5e9e626012
|
@ -0,0 +1,60 @@
|
|||
package com.keylesspalace.tusky.view
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Context
|
||||
import android.os.Build
|
||||
import android.text.Layout
|
||||
import android.text.Spannable
|
||||
import android.util.AttributeSet
|
||||
import android.util.Log
|
||||
import androidx.emoji.widget.EmojiAppCompatTextView
|
||||
import com.keylesspalace.tusky.R
|
||||
import com.keylesspalace.tusky.entity.Emoji
|
||||
import com.keylesspalace.tusky.util.EmojiSpan
|
||||
import com.keylesspalace.tusky.util.LinkHelper
|
||||
import com.keylesspalace.tusky.util.emojify
|
||||
|
||||
/*
|
||||
* This is a TextView that changes break strategy to simple
|
||||
* if there is too much custom emojis
|
||||
*
|
||||
* Fixes Android performance bug
|
||||
*/
|
||||
|
||||
class CustomEmojiTextView
|
||||
@JvmOverloads constructor(context:Context,
|
||||
attrs: AttributeSet? = null,
|
||||
defStyleAttr: Int = 0
|
||||
): EmojiAppCompatTextView(context, attrs, defStyleAttr) {
|
||||
private var oldBreakStrategy = 1 // Layout.BREAK_STRATEGY_HIGH_QUALITY
|
||||
|
||||
@SuppressLint("WrongConstant")
|
||||
override fun setText(text: CharSequence?, type: BufferType?) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
var overridden = false
|
||||
|
||||
// don't change if break strategy already simple
|
||||
if(text is Spannable && breakStrategy != Layout.BREAK_STRATEGY_SIMPLE) {
|
||||
val spans = text.getSpans(0, text.length, EmojiSpan::class.java)
|
||||
|
||||
if (spans.size >= SPAN_LIMIT) {
|
||||
oldBreakStrategy = breakStrategy
|
||||
breakStrategy = Layout.BREAK_STRATEGY_SIMPLE
|
||||
overridden = true
|
||||
|
||||
Log.d("CustomEmojiTextView", "break strategy overriden!");
|
||||
}
|
||||
}
|
||||
|
||||
if(!overridden)
|
||||
breakStrategy = oldBreakStrategy
|
||||
}
|
||||
|
||||
super.setText(text, type)
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val SPAN_LIMIT = 100 // heuristics
|
||||
}
|
||||
}
|
||||
|
|
@ -87,13 +87,14 @@
|
|||
app:layout_constraintBaseline_toBaselineOf="@id/status_display_name"
|
||||
tools:text="13:37" />
|
||||
|
||||
<androidx.emoji.widget.EmojiTextView
|
||||
<com.keylesspalace.tusky.view.CustomEmojiTextView
|
||||
android:id="@+id/status_content"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="8dp"
|
||||
android:focusable="true"
|
||||
android:hyphenationFrequency="full"
|
||||
android:breakStrategy="high_quality"
|
||||
android:importantForAccessibility="no"
|
||||
android:lineSpacingMultiplier="1.1"
|
||||
android:textColor="?android:textColorPrimary"
|
||||
|
|
|
@ -124,7 +124,7 @@
|
|||
app:layout_constrainedHeight="true"
|
||||
tools:text="13:37" />
|
||||
|
||||
<androidx.emoji.widget.EmojiTextView
|
||||
<com.keylesspalace.tusky.view.CustomEmojiTextView
|
||||
android:id="@+id/status_content_warning_description"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
|
@ -159,7 +159,7 @@
|
|||
tools:text="@string/status_content_warning_show_more"
|
||||
tools:visibility="visible" />
|
||||
|
||||
<androidx.emoji.widget.EmojiTextView
|
||||
<com.keylesspalace.tusky.view.CustomEmojiTextView
|
||||
android:id="@+id/status_content"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
|
|
|
@ -46,13 +46,14 @@
|
|||
tools:ignore="ContentDescription" />
|
||||
</FrameLayout>
|
||||
|
||||
<androidx.emoji.widget.EmojiTextView
|
||||
<com.keylesspalace.tusky.view.CustomEmojiTextView
|
||||
android:id="@+id/content"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingTop="@dimen/chat_message_v_padding"
|
||||
android:textColor="@color/textColorPrimary"
|
||||
android:textSize="?attr/status_text_large"
|
||||
android:breakStrategy="simple"
|
||||
android:paddingStart="@dimen/chat_message_h_padding"
|
||||
android:paddingEnd="50dp"
|
||||
android:paddingBottom="@dimen/chat_message_v_padding"
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
android:orientation="vertical"
|
||||
app:layout_constraintGuide_begin="8dp" />
|
||||
|
||||
<androidx.emoji.widget.EmojiTextView
|
||||
<com.keylesspalace.tusky.view.CustomEmojiTextView
|
||||
android:id="@+id/statusContentWarningDescription"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
|
@ -49,7 +49,7 @@
|
|||
tools:text="@string/status_content_warning_show_more"
|
||||
tools:visibility="visible" />
|
||||
|
||||
<androidx.emoji.widget.EmojiTextView
|
||||
<com.keylesspalace.tusky.view.CustomEmojiTextView
|
||||
android:id="@+id/statusContent"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
|
|
|
@ -131,11 +131,12 @@
|
|||
app:layout_constraintTop_toBottomOf="@+id/status_display_name"
|
||||
tools:text="Reply to a1batross" />
|
||||
|
||||
<androidx.emoji.widget.EmojiTextView
|
||||
<com.keylesspalace.tusky.view.CustomEmojiTextView
|
||||
android:id="@+id/status_content_warning_description"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:hyphenationFrequency="full"
|
||||
android:breakStrategy="high_quality"
|
||||
android:importantForAccessibility="no"
|
||||
android:lineSpacingMultiplier="1.1"
|
||||
android:textColor="?android:textColorPrimary"
|
||||
|
@ -171,13 +172,14 @@
|
|||
tools:text="@string/status_content_warning_show_more"
|
||||
tools:visibility="visible" />
|
||||
|
||||
<androidx.emoji.widget.EmojiTextView
|
||||
<com.keylesspalace.tusky.view.CustomEmojiTextView
|
||||
android:id="@+id/status_content"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="8dp"
|
||||
android:focusable="true"
|
||||
android:hyphenationFrequency="full"
|
||||
android:breakStrategy="high_quality"
|
||||
android:importantForAccessibility="no"
|
||||
android:lineSpacingMultiplier="1.1"
|
||||
android:textColor="?android:textColorPrimary"
|
||||
|
|
|
@ -95,12 +95,13 @@
|
|||
app:layout_constraintTop_toBottomOf="@+id/status_avatar"
|
||||
tools:text="Reply to a1batross" />
|
||||
|
||||
<androidx.emoji.widget.EmojiTextView
|
||||
<com.keylesspalace.tusky.view.CustomEmojiTextView
|
||||
android:id="@+id/status_content_warning_description"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="8dp"
|
||||
android:hyphenationFrequency="full"
|
||||
android:breakStrategy="high_quality"
|
||||
android:importantForAccessibility="no"
|
||||
android:lineSpacingMultiplier="1.1"
|
||||
android:textColor="?android:textColorPrimary"
|
||||
|
@ -129,7 +130,7 @@
|
|||
app:layout_constraintTop_toBottomOf="@+id/status_content_warning_description"
|
||||
tools:text="@string/status_content_warning_show_more" />
|
||||
|
||||
<androidx.emoji.widget.EmojiTextView
|
||||
<com.keylesspalace.tusky.view.CustomEmojiTextView
|
||||
android:id="@+id/status_content"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
|
@ -137,6 +138,7 @@
|
|||
android:layout_marginBottom="4dp"
|
||||
android:focusable="true"
|
||||
android:hyphenationFrequency="full"
|
||||
android:breakStrategy="high_quality"
|
||||
android:importantForAccessibility="no"
|
||||
android:lineSpacingMultiplier="1.1"
|
||||
android:textColor="?android:textColorPrimary"
|
||||
|
|
|
@ -72,13 +72,14 @@
|
|||
|
||||
</RelativeLayout>
|
||||
|
||||
<androidx.emoji.widget.EmojiTextView
|
||||
<com.keylesspalace.tusky.view.CustomEmojiTextView
|
||||
android:id="@+id/notification_content_warning_description"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/status_name_bar"
|
||||
android:layout_toEndOf="@id/notification_status_avatar"
|
||||
android:hyphenationFrequency="full"
|
||||
android:breakStrategy="high_quality"
|
||||
android:lineSpacingMultiplier="1.1"
|
||||
android:textColor="?android:textColorTertiary"
|
||||
android:textSize="?attr/status_text_medium"
|
||||
|
@ -103,13 +104,14 @@
|
|||
style="@style/TuskyButton.Outlined"
|
||||
android:textSize="?attr/status_text_medium" />
|
||||
|
||||
<androidx.emoji.widget.EmojiTextView
|
||||
<com.keylesspalace.tusky.view.CustomEmojiTextView
|
||||
android:id="@+id/notification_content"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/notification_content_warning_button"
|
||||
android:layout_toEndOf="@+id/notification_status_avatar"
|
||||
android:hyphenationFrequency="full"
|
||||
android:breakStrategy="high_quality"
|
||||
android:lineSpacingMultiplier="1.1"
|
||||
android:paddingBottom="10dp"
|
||||
android:textColor="?android:textColorTertiary"
|
||||
|
|
|
@ -46,13 +46,14 @@
|
|||
tools:ignore="ContentDescription" />
|
||||
</FrameLayout>
|
||||
|
||||
<androidx.emoji.widget.EmojiTextView
|
||||
<com.keylesspalace.tusky.view.CustomEmojiTextView
|
||||
android:id="@+id/content"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingTop="@dimen/chat_message_v_padding"
|
||||
android:textColor="@color/textColorPrimary"
|
||||
android:textSize="?attr/status_text_large"
|
||||
android:breakStrategy="simple"
|
||||
android:paddingStart="@dimen/chat_message_h_padding"
|
||||
android:paddingEnd="50dp"
|
||||
android:paddingBottom="@dimen/chat_message_v_padding"
|
||||
|
|
Loading…
Reference in New Issue