Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ import org.session.libsession.utilities.TextSecurePreferences.Companion.SEEN_DON
import org.session.libsession.utilities.TextSecurePreferences.Companion.SELECTED_ACCENT_COLOR
import org.session.libsession.utilities.TextSecurePreferences.Companion.SELECTED_STYLE
import org.session.libsession.utilities.TextSecurePreferences.Companion.SEND_WITH_ENTER
import org.session.libsession.utilities.TextSecurePreferences.Companion.USE_SYSTEM_EMOJI
import org.session.libsession.utilities.TextSecurePreferences.Companion.SET_FORCE_CURRENT_USER_PRO
import org.session.libsession.utilities.TextSecurePreferences.Companion.SET_FORCE_INCOMING_MESSAGE_PRO
import org.session.libsession.utilities.TextSecurePreferences.Companion.SET_FORCE_OTHER_USERS_PRO
Expand Down Expand Up @@ -341,6 +342,8 @@ interface TextSecurePreferences {

fun setSendWithEnterEnabled(enabled: Boolean)
fun isSendWithEnterEnabled() : Boolean
fun setUseSystemEmojiEnabled(enabled: Boolean)
fun isUseSystemEmojiEnabled(): Boolean
fun updateBooleanFromKey(key : String, value : Boolean)

var deprecationStateOverride: String?
Expand Down Expand Up @@ -408,6 +411,7 @@ interface TextSecurePreferences {
const val LAST_VACUUM_TIME = "pref_last_vacuum_time"
const val AUTOPLAY_AUDIO_MESSAGES = "pref_autoplay_audio"
const val SEND_WITH_ENTER = "pref_enter_sends"
const val USE_SYSTEM_EMOJI = "pref_use_system_emoji"
const val FINGERPRINT_KEY_GENERATED = "fingerprint_key_generated"
const val SELECTED_ACCENT_COLOR = "selected_accent_color"
const val LAST_VERSION_CHECK = "pref_last_version_check"
Expand Down Expand Up @@ -571,6 +575,17 @@ interface TextSecurePreferences {
return getBooleanPreference(context, THREAD_TRIM_ENABLED, true)
}

@JvmStatic
fun isUseSystemEmojiEnabled(context: Context): Boolean {
return getBooleanPreference(context, USE_SYSTEM_EMOJI, false)
}

@JvmStatic
fun setUseSystemEmojiEnabled(context: Context, enabled: Boolean) {
setBooleanPreference(context, USE_SYSTEM_EMOJI, enabled)
_events.tryEmit(USE_SYSTEM_EMOJI)
}

@JvmStatic
fun getBooleanPreference(context: Context, key: String?, defaultValue: Boolean): Boolean {
return getDefaultSharedPreferences(context).getBoolean(key, defaultValue)
Expand Down Expand Up @@ -1549,6 +1564,15 @@ class AppTextSecurePreferences @Inject constructor(
return getBooleanPreference(SEND_WITH_ENTER, false)
}

override fun setUseSystemEmojiEnabled(enabled: Boolean) {
setBooleanPreference(USE_SYSTEM_EMOJI, enabled)
_events.tryEmit(USE_SYSTEM_EMOJI)
}

override fun isUseSystemEmojiEnabled(): Boolean {
return getBooleanPreference(USE_SYSTEM_EMOJI, false)
}

override fun updateBooleanFromKey(key: String, value: Boolean) {
setBooleanPreference(key, value)
_events.tryEmit(key)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@
import android.graphics.drawable.Drawable;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.TextPaint;
import android.text.TextUtils;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import org.session.libsession.utilities.FutureTaskListener;
import org.session.libsession.utilities.TextSecurePreferences;
import org.session.libsignal.utilities.Log;
import org.thoughtcrime.securesms.components.emoji.parsing.EmojiDrawInfo;
import org.thoughtcrime.securesms.components.emoji.parsing.EmojiParser;
Expand Down Expand Up @@ -52,7 +54,7 @@ public class EmojiProvider {
@NonNull TextView tv,
boolean jumboEmoji)
{
if (matches == null || text == null || tv.isInEditMode()) return null;
if (matches == null || text == null || tv.isInEditMode() || TextSecurePreferences.isUseSystemEmojiEnabled(tv.getContext())) return null;
SpannableStringBuilder builder = new SpannableStringBuilder(text);

for (EmojiParser.Candidate candidate : matches) {
Expand All @@ -76,6 +78,10 @@ public class EmojiProvider {
return null;
}

if (TextSecurePreferences.isUseSystemEmojiEnabled(context)) {
return new SystemEmojiDrawable(context, emoji.toString());
}

EmojiDrawInfo drawInfo = EmojiSource.getLatest().getEmojiTree().getEmoji(emoji, 0, emoji.length());
return getEmojiDrawable(context, drawInfo, null, jumboEmoji);
}
Expand Down Expand Up @@ -202,4 +208,78 @@ public void setAlpha(int alpha) { }
public void setColorFilter(ColorFilter cf) { }
}

/**
* Renders a single emoji using the device's native system font at full vector resolution.
*/
static final class SystemEmojiDrawable extends Drawable {
private final String emoji;
private final int intrinsicSize;
private final TextPaint textPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
private final Rect textBounds = new Rect();

SystemEmojiDrawable(@NonNull Context context, @NonNull String emoji) {
this.emoji = emoji;
this.intrinsicSize = Math.round(32f * context.getResources().getDisplayMetrics().density);
this.textPaint.setTextAlign(Paint.Align.LEFT);
}

@Override
public int getIntrinsicWidth() {
return intrinsicSize;
}

@Override
public int getIntrinsicHeight() {
return intrinsicSize;
}

@Override
public void draw(@NonNull Canvas canvas) {
final Rect bounds = getBounds();
final int width = bounds.width();
final int height = bounds.height();
if (width <= 0 || height <= 0) {
return;
}

final int targetSize = Math.min(width, height);
float textSize = targetSize * 0.85f;
textPaint.setTextSize(textSize);
textPaint.getTextBounds(emoji, 0, emoji.length(), textBounds);

final float maxAllowed = targetSize * 0.90f;
if (textBounds.width() > maxAllowed || textBounds.height() > maxAllowed) {
final float maxDim = Math.max(textBounds.width(), textBounds.height());
if (maxDim > 0) {
textSize *= maxAllowed / maxDim;
textPaint.setTextSize(textSize);
textPaint.getTextBounds(emoji, 0, emoji.length(), textBounds);
}
}

final float x = bounds.exactCenterX() - textBounds.exactCenterX();
final float y = !textBounds.isEmpty()
? bounds.exactCenterY() - textBounds.exactCenterY()
: bounds.exactCenterY() - ((textPaint.ascent() + textPaint.descent()) / 2f);
canvas.drawText(emoji, 0, emoji.length(), x, y, textPaint);
}

@Override
public int getOpacity() {
return PixelFormat.TRANSLUCENT;
}

@Override
public void setAlpha(int alpha) {
textPaint.setAlpha(alpha);
invalidateSelf();
}

@Override
public void setColorFilter(@Nullable ColorFilter cf) {
textPaint.setColorFilter(cf);
invalidateSelf();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import network.loki.messenger.R;
import org.thoughtcrime.securesms.components.emoji.EmojiProvider.EmojiDrawable;
import org.thoughtcrime.securesms.components.emoji.parsing.EmojiParser;
import org.session.libsession.utilities.TextSecurePreferences;
import org.session.libsession.utilities.Util;

public class EmojiTextView extends AppCompatTextView {
Expand Down Expand Up @@ -72,7 +73,9 @@ public EmojiTextView(Context context, AttributeSet attrs, int defStyleAttr) {
previousOverflowText = overflowText;
previousBufferType = type;

if (candidates == null || candidates.size() == 0) {
boolean useSystemEmoji = TextSecurePreferences.isUseSystemEmojiEnabled(getContext());

if (candidates == null || candidates.size() == 0 || useSystemEmoji) {
super.setText(
new SpannableStringBuilder(text != null ? text : "")
.append(overflowText != null ? overflowText : ""),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,32 @@ private fun ConversationsPreference(
Spacer(modifier = Modifier.height(LocalDimensions.current.smallSpacing))
}

item {
CategoryCell(
modifier = Modifier,
title = "Emojis"
) {
SwitchActionRowItem(
modifier = Modifier.fillMaxWidth(),
title = annotatedStringResource("Use System Emojis"),
subtitle = annotatedStringResource("Render crisp, high-resolution emojis using your device's native font instead of compressed spritesheets"),
subtitleStyle = LocalType.current.large,
checked = uiState.useSystemEmoji,
qaTag = R.string.qa_preferences_use_system_emojis,
switchQaTag = R.string.qa_preferences_use_system_emojis_toggle,
onCheckedChange = { isEnabled ->
sendCommand(
ChatsPreferenceViewModel.Commands.ToggleUseSystemEmoji(
isEnabled
)
)
}
)
}

Spacer(modifier = Modifier.height(LocalDimensions.current.smallSpacing))
}

item {
CategoryCell(
modifier = Modifier,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ class ChatsPreferenceViewModel @Inject constructor(
prefs.observeBooleanKey(TextSecurePreferences.THREAD_TRIM_ENABLED, default = false),
prefs.observeBooleanKey(TextSecurePreferences.SEND_WITH_ENTER, default = false),
prefs.observeBooleanKey(TextSecurePreferences.AUTOPLAY_AUDIO_MESSAGES, default = false),
) { trim, enter, autoplay ->
prefs.observeBooleanKey(TextSecurePreferences.USE_SYSTEM_EMOJI, default = false),
) { trim, enter, autoplay, systemEmoji ->
UIState(
trimThreads = trim,
sendWithEnter = enter,
autoplayAudioMessage = autoplay
autoplayAudioMessage = autoplay,
useSystemEmoji = systemEmoji
)
}.stateIn(
scope = viewModelScope,
Expand All @@ -34,6 +36,7 @@ class ChatsPreferenceViewModel @Inject constructor(
trimThreads = prefs.isThreadLengthTrimmingEnabled(),
sendWithEnter = prefs.isSendWithEnterEnabled(),
autoplayAudioMessage = prefs.isAutoplayAudioMessagesEnabled(),
useSystemEmoji = prefs.isUseSystemEmojiEnabled(),
)
)

Expand All @@ -42,18 +45,21 @@ class ChatsPreferenceViewModel @Inject constructor(
is Commands.ToggleTrimThreads -> prefs.setThreadLengthTrimmingEnabled(command.isEnabled)
is Commands.ToggleSendWithEnter -> prefs.setSendWithEnterEnabled(command.isEnabled)
is Commands.ToggleAutoplayAudioMessages -> prefs.setAutoplayAudioMessages(command.isEnabled)
is Commands.ToggleUseSystemEmoji -> prefs.setUseSystemEmojiEnabled(command.isEnabled)
}
}

sealed interface Commands {
data class ToggleTrimThreads(val isEnabled: Boolean) : Commands
data class ToggleSendWithEnter(val isEnabled: Boolean) : Commands
data class ToggleAutoplayAudioMessages(val isEnabled: Boolean) : Commands
data class ToggleUseSystemEmoji(val isEnabled: Boolean) : Commands
}

data class UIState(
val trimThreads: Boolean = false,
val sendWithEnter: Boolean = false,
val autoplayAudioMessage: Boolean = false
val autoplayAudioMessage: Boolean = false,
val useSystemEmoji: Boolean = false
)
}
2 changes: 2 additions & 0 deletions content-descriptions/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,8 @@
<string name="qa_preferences_send_with_enter_toggle">preferences-option-send-with-enter_toggle</string>
<string name="qa_preferences_autoplay_audio">preferences-option-autoplay-audio</string>
<string name="qa_preferences_autoplay_audio_toggle">preferences-option-autoplay-audio-toggle</string>
<string name="qa_preferences_use_system_emojis">preferences-option-use-system-emojis</string>
<string name="qa_preferences_use_system_emojis_toggle">preferences-option-use-system-emojis-toggle</string>
<string name="qa_preferences_option_blocked_contacts">preferences-option-blocked-contacts</string>
<string name="qa_preferences_option_notification_privacy">preferences-option-notification-privacy</string>
<string name="qa_preferences_ringtone">preferences-option-ringtone</string>
Expand Down