Skip to content
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

Contest #154 #188

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import android.content.Context;
import android.graphics.Canvas;
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import android.view.HapticFeedbackConstants;
import android.view.MotionEvent;
import android.view.View;
Expand Down Expand Up @@ -47,6 +49,7 @@
import org.thunderdog.challegram.navigation.NavigationController;
import org.thunderdog.challegram.navigation.ViewController;
import org.thunderdog.challegram.player.TGPlayerController;
import org.thunderdog.challegram.telegram.Tdlib;
import org.thunderdog.challegram.telegram.TdlibManager;
import org.thunderdog.challegram.telegram.TdlibUi;
import org.thunderdog.challegram.theme.Theme;
Expand All @@ -64,6 +67,7 @@
import org.thunderdog.challegram.widget.SparseDrawableView;

import java.util.List;
import java.util.Map;

import me.vkryl.android.AnimatorUtils;
import me.vkryl.android.ViewUtils;
Expand Down Expand Up @@ -479,7 +483,7 @@ private boolean onMessageClickImpl (float x, float y, @Nullable TdApi.ChatMember
StringList strings = new StringList(6);
Object tag = fillMessageOptions(m, msg, sender, ids, icons, strings, false);
if (!ids.isEmpty()) {
m.showMessageOptions(msg, ids.get(), strings.get(), icons.get(), tag, sender, false);
m.showMessageOptions(msg,ids.get(), strings.get(), icons.get(), tag, sender, false);
return true;
}
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ public PreviewMessage (int date, int after, boolean out, int senderUserId, TdApi
this.content = content;
}
}

private static @StringRes int getPreviewStringKey (String key) {
switch (key) {
case "json_1_name": return R.string.json_1_name;
Expand Down Expand Up @@ -1705,4 +1705,4 @@ public boolean canLoadBottom () {
}
return false;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,15 @@ public boolean hasScrolledSinceOpen () {
return hasScrolled;
}

public void updateMessageReaction(long messageId) {
int index = adapter.indexOfMessageContainer(messageId);
if (index != -1) {
TGMessage currentMessage = adapter.getMessage(index);
currentMessage.updateReactions();
invalidateViewAt(index);
}
}

// Search

public void openSearch (TdApi.Chat chat, String query, TdApi.MessageSender sender, TdApi.SearchMessagesFilter filter) {
Expand Down Expand Up @@ -2721,6 +2730,7 @@ public void onMessageInteractionInfoChanged (long chatId, long messageId, @Nulla
updateMessageInteractionInfo(messageId, interactionInfo);
}
});
updateMessageReaction(messageId);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public class StickerSmallView extends View implements FactorAnimator.Target, Des
private @Nullable TGStickerObj sticker;
private Path contour;
private Tdlib tdlib;
private boolean isReaction = false;

public StickerSmallView (Context context) {
super(context);
Expand All @@ -64,6 +65,7 @@ public void init (Tdlib tdlib) {
}

private boolean isAnimation;
private boolean isPreviewEnabled = true;

public void setSticker (@Nullable TGStickerObj sticker) {
this.sticker = sticker;
Expand Down Expand Up @@ -143,6 +145,10 @@ public void setEmojiDisabled () {
emojiDisabled = true;
}

public void setPreviewEnabled(boolean enabled) {
isPreviewEnabled = enabled;
}

@Override
protected void onMeasure (int widthMeasureSpec, int heightMeasureSpec) {
if (isSuggestion) {
Expand Down Expand Up @@ -190,6 +196,14 @@ protected void onDraw (Canvas c) {
}
}

public void setAnimation(boolean isAnimation) {
this.isAnimation = isAnimation;
}

public void setIsReaction(boolean isReaction) {
this.isReaction = isReaction;
}

// Touch

private float startX, startY;
Expand Down Expand Up @@ -243,15 +257,17 @@ public boolean onTouchEvent (MotionEvent e) {
case MotionEvent.ACTION_DOWN: {
startX = e.getX();
startY = e.getY();
openPreviewDelayed();
if (isPreviewEnabled) {
openPreviewDelayed();
}
return true;
}
case MotionEvent.ACTION_CANCEL: {
closePreview(e);
return true;
}
case MotionEvent.ACTION_UP: {
boolean clicked = previewScheduled && !previewOpened;
boolean clicked = (previewScheduled && !previewOpened) || isReaction;
closePreview(e);
if (clicked && callback != null && sticker != null) {
ViewUtils.onClick(this);
Expand Down
77 changes: 72 additions & 5 deletions app/src/main/java/org/thunderdog/challegram/data/TGMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import android.graphics.BitmapFactory;
import android.graphics.BitmapShader;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.RectF;
Expand Down Expand Up @@ -58,6 +59,7 @@
import org.thunderdog.challegram.component.chat.MessagesManager;
import org.thunderdog.challegram.component.chat.MessagesTouchHelperCallback;
import org.thunderdog.challegram.component.chat.ReplyComponent;
import org.thunderdog.challegram.component.sticker.TGStickerObj;
import org.thunderdog.challegram.config.Config;
import org.thunderdog.challegram.config.Device;
import org.thunderdog.challegram.core.Lang;
Expand Down Expand Up @@ -109,6 +111,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;

Expand Down Expand Up @@ -171,6 +174,7 @@ public abstract class TGMessage implements MultipleViewProvider.InvalidateConten

protected TdApi.Message msg;
private int flags;
private Map<TdApi.Reaction, Integer> reactions = null;

protected int mergeTime, mergeIndex;

Expand Down Expand Up @@ -350,6 +354,10 @@ protected TGMessage (MessagesManager manager, TdApi.Message msg) {
if (isHot() && needHotTimer() && msg.ttlExpiresIn < msg.ttl) {
startHotTimer(false);
}
tdlib.getMessageReactions(msg, arg -> {
reactions = arg;
requestLayout();
});
}

private static @NonNull <T> T nonNull (@Nullable T value) {
Expand Down Expand Up @@ -815,6 +823,10 @@ private int computeBubbleHeight () {
if (hasFooter()) {
height += getFooterHeight() + getFooterPaddingTop() + getFooterPaddingBottom();
}

if (reactions != null && !reactions.isEmpty()) {
height += getReactionsPartHeight();
}
height += getBubbleReduceHeight();

return height;
Expand Down Expand Up @@ -1044,6 +1056,9 @@ public int computeHeight () {
if (inlineKeyboard != null && !inlineKeyboard.isEmpty()) {
height += inlineKeyboard.getHeight() + TGInlineKeyboard.getButtonSpacing();
}
if (reactions != null && !reactions.isEmpty()) {
height += Screen.dp(16) + Screen.dp(8);
}
return height;
} else {
int height = pContentY + getContentHeight() + getPaddingBottom() + getExtraPadding();
Expand All @@ -1053,6 +1068,9 @@ public int computeHeight () {
if (hasFooter()) {
height += getFooterHeight() + getFooterPaddingTop() + getFooterPaddingBottom();
}
if (reactions != null && !reactions.isEmpty()) {
height += Screen.dp(16) + Screen.dp(8);
}
return height;
}
}
Expand Down Expand Up @@ -1354,10 +1372,15 @@ private void drawBubble (Canvas c, Paint paint, boolean stroke, int padding) {
return;
}

float reactionsHeigth = 0f;
if (reactions != null && !reactions.isEmpty()) {
reactionsHeigth = Screen.dp(16) + Screen.dp(8);
}

final float left = bubblePathRect.left - padding;
final float top = bubblePathRect.top - padding;
final float right = bubblePathRect.right + padding;
final float bottom = bubblePathRect.bottom + padding;
final float bottom = bubblePathRect.bottom + padding + reactionsHeigth;

final RectF rectF = Paints.getRectF();
if (topLeftRadius != 0) {
Expand Down Expand Up @@ -1865,6 +1888,9 @@ public final void draw (MessageView view, Canvas c, @NonNull ImageReceiver avata
if (useBubbles) {
lineTop = replyData != null ? (topContentEdge + (useBubble() ? xBubblePadding + xBubblePaddingSmall : Screen.dp(8f)) + (useBubbleName() ? getBubbleNameHeight() : 0)) : forwardY;
lineBottom = bottomContentEdge - xBubblePadding - xBubblePaddingSmall - (useBubbleTime() ? getBubbleTimePartHeight() : 0) - getBubbleReduceHeight();
/* if (reactions != null && !reactions.isEmpty()) {
lineBottom -= getReactionsPartHeight();
}*/
mergeBottom = mergeTop = false;
} else {
if ((flags & FLAG_MERGE_FORWARD) != 0 && (flags & FLAG_HEADER_ENABLED) == 0) {
Expand Down Expand Up @@ -2997,6 +3023,9 @@ public Path getBubbleClipPath () {
protected static int getBubbleTimePartHeight () {
return Screen.dp(16f);
}
protected static int getReactionsPartHeight () {
return Screen.dp(16f);
}

protected int getAbsolutelyRealRightContentEdge (View view, int timePartWidth) {
return getActualRightContentEdge() - timePartWidth;
Expand Down Expand Up @@ -3081,7 +3110,10 @@ protected void drawBubbleTimePart (Canvas c, MessageView view) {
startX = getAbsolutelyRealRightContentEdge(view, innerWidth + Screen.dp(11f));
}
int startY = bottomContentEdge - getBubbleTimePartHeight() - getBubbleTimePartOffsetY() - getBubbleReduceHeight();

int reactionY = startY + Screen.dp(15.5f);
if (reactions != null && !reactions.isEmpty()) {
startY += getReactionsPartHeight() + Screen.dp(8f);
}
if (backgroundColor != 0) {
startY -= Screen.dp(4f);
RectF rectF = Paints.getRectF();
Expand Down Expand Up @@ -3114,7 +3146,6 @@ protected void drawBubbleTimePart (Canvas c, MessageView view) {
}
isPinned.draw(c, startX, counterY, Gravity.LEFT, 1f, view, iconColorId);
startX += isPinned.getScaledWidth(Screen.dp(COUNTER_ICON_MARGIN));

if (shouldShowEdited()) {
if (isBeingEdited()) {
Drawables.draw(c, Icons.getClockIcon(iconColorId), startX - Screen.dp(6f), startY + Screen.dp(4.5f) - Screen.dp(5f), iconPaint);
Expand All @@ -3123,7 +3154,6 @@ protected void drawBubbleTimePart (Canvas c, MessageView view) {
}
startX += Icons.getEditedIconWidth() + Screen.dp(2f);
}

if (time != null) {
c.drawText(time, startX, startY + Screen.dp(15.5f), Paints.colorPaint(mTimeBubble(), textColor));
startX += pTimeWidth;
Expand Down Expand Up @@ -3151,6 +3181,7 @@ protected void drawBubbleTimePart (Canvas c, MessageView view) {
}
startX += Icons.getSingleTickWidth();
}
drawReaction(c, view, getActualLeftContentEdge() + Screen.dp(10), reactionY);
}

protected final int computeBubbleTimePartWidth (boolean includePadding) {
Expand Down Expand Up @@ -3261,7 +3292,43 @@ public final void requestAvatar (ImageReceiver receiver) {
}
}


private void drawReaction (Canvas canvas, MessageView view, int startX, int startY) {
if (reactions != null && reactions.size() > 0) {
int i = 0;
for (TdApi.Reaction reaction : reactions.keySet()) {
canvas.save();
float measureText = U.measureText(reactions.get(reaction).toString(), Paints.getTextPaint15());
canvas.translate(startX + i * (Screen.dp(16) + Screen.dp(8) + measureText), startY);
canvas.save();
canvas.restore();
TGStickerObj sticker = new TGStickerObj(tdlib, reaction.staticIcon, "", reaction.staticIcon.type);
ImageFile imageFile = sticker.getImage();
ImageReceiver imageReceiver = new ImageReceiver(view, Screen.dp(16));
imageReceiver.requestFile(imageFile);
imageReceiver.setBounds(0, 0, Screen.dp(16), Screen.dp(16));
imageReceiver.setRadius(-1);
imageReceiver.forceBoundsLayout();
imageReceiver.draw(canvas);
canvas.restore();
canvas.save();
RectF rectF = Paints.getRectF();
rectF.set(startX - Screen.dp(2) + i * (Screen.dp(16) + measureText + Screen.dp(2)), startY - Screen.dp(4) - Screen.dp(2), startX + Screen.dp(16) + Screen.dp(2) + measureText + i * (Screen.dp(16) + measureText + Screen.dp(8)), startY + Screen.dp(22));
//int color = Theme.getColor(isOutgoingBubble() && !useCircleBubble() ? R.id.theme_color_bubbleOut_background : R.id.theme_color_bubbleIn_background);
canvas.drawRoundRect(rectF, Screen.dp(8) * 1f, Screen.dp(8) * 1f, Paints.alphaPaint(Paints.fillingPaint(Color.GRAY), 50));
canvas.drawText(reactions.get(reaction).toString(), startX + Screen.dp(16) + Screen.dp(2) + i * (Screen.dp(16) + measureText + Screen.dp(8)), startY + Screen.dp(14), Paints.getTextPaint15());
canvas.restore();
i++;
}
}
}

public void updateReactions () {
reactions = null;
tdlib.getMessageReactions(msg, arg -> {
reactions = arg;
requestLayout();
});
}

// public static final float IMAGE_CONTENT_DEFAULT_RADIUS = 3f;
// public static final float BUBBLE_MERGE_RADIUS = 6f;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ public boolean open (View view, boolean allowRipple) {
parent.tdlib().ui().openUrl(parent.controller(), url, rippleButton.firstButton().openParameters(view).disableInstantView());
return true;
}

if (mediaWrapper != null && allowRipple && isTelegramType(type)) {
MediaViewController.openFromMessage(parent);
return true;
Expand Down