Skip to content

Add support for emotes in flairs #1054

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 20, 2025

Conversation

bharatknv
Copy link
Contributor

Adds #1042

@bharatknv
Copy link
Contributor Author

This is incomplete. I want to limit the emote height so it can't be taller than 2x the height of the text (or whatever multiple looks good).

Currently I'm just halving the emote and it mostly works with my device and font size but that's obviously an imperfect solution.

@QuantumBadger , Any thoughts on what the best way to do this would be?

@bharatknv
Copy link
Contributor Author

The best solution I came up with is this:

final int TEXT_SIZE = 11; // Text size in sp
final float MAX_IMAGE_HEIGHT_MULTIPLE = 2.0F; // emote can only be 2x the size of the text


final float maxHeight = TypedValue.applyDimension(
  TypedValue.COMPLEX_UNIT_SP, 
  PrefsUtility.appearance_fontscale_comment_headers() * 
    TEXT_SIZE * 
    MAX_IMAGE_HEIGHT_MULTIPLE, 
  activity.getBaseContext().getResources().getDisplayMetrics());

if (image.getHeight() > maxHeight) {
      final float imageAspectRatio = (float) image.getHeight() / image.getWidth();
      
      final float newImageWidth = maxHeight / imageAspectRatio;
      
      image = Bitmap.createScaledBitmap(image,
		      Math.round(newImageWidth),
		      Math.round(maxHeight),
		      true);
}

I got the text size from reddit_comment.xml. I'd like to get it programmatically instead of hard-coding it but I don't see an obvious way to do that.

@QuantumBadger
Copy link
Owner

Thank you for this @bharatknv and sorry for the very delayed response, there's a backlog of PRs that I'm just now clearing up!

The best solution I came up with is this

That looks fine to me. I've adjusted maxImageHeightMultiple to 1.0, and also vertically centred the emotes. Will merge soon once the CI passes.

@QuantumBadger QuantumBadger merged commit ded02b3 into QuantumBadger:master Apr 20, 2025
1 check passed
QuantumBadger added a commit that referenced this pull request Apr 20, 2025
QuantumBadger added a commit that referenced this pull request Apr 20, 2025
QuantumBadger added a commit that referenced this pull request Apr 20, 2025
@QuantumBadger
Copy link
Owner

Merged and changelog updated -- thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants