Skip to content

Commit

Permalink
feat: Show time hint
Browse files Browse the repository at this point in the history
Thanks to @NekoUpdates
  • Loading branch information
tehcneko authored and omg-xtao committed May 3, 2024
1 parent ce7457c commit 77368aa
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 4 deletions.
10 changes: 10 additions & 0 deletions TMessagesProj/src/main/java/org/telegram/ui/ActionBar/Theme.java
Expand Up @@ -3343,6 +3343,11 @@ public void run() {
public static Drawable[] chat_pollHintDrawable = new Drawable[2];
public static Drawable[] chat_psaHelpDrawable = new Drawable[2];

public static Drawable chat_editDrawable;

public static Drawable chat_timeHintSentDrawable;
public static Drawable chat_timeHintForwardDrawable;

public static Drawable chat_msgCallUpGreenDrawable;
public static Drawable chat_msgCallDownRedDrawable;
public static Drawable chat_msgCallDownGreenDrawable;
Expand Down Expand Up @@ -8834,6 +8839,11 @@ public static void createChatResources(Context context, boolean fontsOnly) {
chat_psaHelpDrawable[a] = resources.getDrawable(R.drawable.msg_psa).mutate();
}

chat_editDrawable = resources.getDrawable(R.drawable.msg_edit).mutate();

chat_timeHintSentDrawable = resources.getDrawable(R.drawable.msg_check_s).mutate();
chat_timeHintForwardDrawable = resources.getDrawable(R.drawable.mini_forwarded).mutate();

calllog_msgCallUpRedDrawable = resources.getDrawable(R.drawable.ic_call_made_green_18dp).mutate();
calllog_msgCallUpGreenDrawable = resources.getDrawable(R.drawable.ic_call_made_green_18dp).mutate();
calllog_msgCallDownRedDrawable = resources.getDrawable(R.drawable.ic_call_received_green_18dp).mutate();
Expand Down
Expand Up @@ -1319,7 +1319,7 @@ class LoadingDrawableLocation {
private float drawTimeY;
public StaticLayout timeLayout;
public int timeWidth;
private int timeTextWidth;
public int timeTextWidth;
public int timeX;
public int signWidth;
private CharSequence currentTimeString;
Expand Down Expand Up @@ -3005,9 +3005,6 @@ private void resetContactButtonsPressedState() {
}

private boolean checkDateMotionEvent(MotionEvent event) {
if (!currentMessageObject.isImportedForward()) {
return false;
}
int x = (int) event.getX();
int y = (int) event.getY();

Expand Down
39 changes: 39 additions & 0 deletions TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java
Expand Up @@ -474,6 +474,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
private FrameLayout searchGoToBeginningButton;
private ImageView searchGoToBeginningButtonArrow;

private HintView2 timeHint;
private HintView2 savedMessagesHint;
private HintView2 savedMessagesSearchHint;
private HintView2 savedMessagesTagHint;
Expand Down Expand Up @@ -6393,6 +6394,9 @@ public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
AndroidUtilities.cancelRunOnUIThread(ChatActivity.this::checkBotMessageHint);
AndroidUtilities.runOnUIThread(ChatActivity.this::checkBotMessageHint, 2000);
}
if (timeHint != null && timeHint.shown()) {
timeHint.hide();
}
if (chatActivityEnterView != null) {
chatActivityEnterView.hideHints();
}
Expand Down Expand Up @@ -8497,6 +8501,37 @@ private void showBotMessageHint(ChatMessageCell cell, boolean byClick) {
});
}

private void showTimeHint(ChatMessageCell cell) {
if (cell == null || cell.timeLayout == null || cell.getMessageObject() == null ||
cell.getMessageObject().messageOwner == null ||
(chatMode != MODE_DEFAULT && chatMode != MODE_PINNED && chatMode != MODE_SAVED) ||
(NekoConfig.hideTimeForSticker.Bool() && cell.getMessageObject().isAnyKindOfSticker()) ||
(NaConfig.INSTANCE.getRealHideTimeForSticker().Bool() && cell.getMessageObject().isAnyKindOfSticker())
) {
return;
}
if (timeHint != null) {
var hint = timeHint;
hint.setOnHiddenListener(() -> contentView.removeView(hint));
hint.hide();
timeHint = null;
}
timeHint = new HintView2(getContext(), HintView2.DIRECTION_BOTTOM)
.setMultilineText(true)
.setDuration(2000);

timeHint.setText(MessageHelper.INSTANCE.getTimeHintText(cell.getMessageObject()));
timeHint.setMaxWidthPx(contentView.getMeasuredWidth());
contentView.addView(timeHint, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 120, Gravity.TOP | Gravity.FILL_HORIZONTAL, 16, 0, 16, 0));
contentView.post(() -> {
var loc = new int[2];
cell.getLocationInWindow(loc);
timeHint.setTranslationY(loc[1] - timeHint.getTop() - dp(120) + cell.getTimeY());
timeHint.setJointPx(0, -dp(16) + loc[0] + cell.timeX + cell.timeWidth - cell.timeTextWidth / 2f + cell.signWidth / 2f);
timeHint.show();
});
}

private void hideHints() {
if (savedMessagesTagHint != null && savedMessagesTagHint.shown()) {
savedMessagesTagHint.hide();
Expand Down Expand Up @@ -35155,6 +35190,10 @@ public void videoTimerReached() {

@Override
public void didPressTime(ChatMessageCell cell) {
if (!cell.getMessageObject().isImportedForward()) {
showTimeHint(cell);
return;
}
createUndoView();
if (undoView == null) {
return;
Expand Down
Expand Up @@ -6,6 +6,8 @@ import android.content.Context
import android.graphics.Bitmap
import android.graphics.BitmapFactory
import android.os.Build
import android.text.SpannableStringBuilder
import android.text.Spanned
import android.text.TextUtils
import androidx.core.content.FileProvider
import org.telegram.messenger.AndroidUtilities
Expand All @@ -19,6 +21,7 @@ import org.telegram.messenger.FileLog
import org.telegram.messenger.LocaleController
import org.telegram.messenger.MediaDataController
import org.telegram.messenger.MessageObject
import org.telegram.messenger.R
import org.telegram.messenger.UserConfig
import org.telegram.tgnet.TLRPC.Chat
import org.telegram.tgnet.TLRPC.TL_messageEntityBankCard
Expand All @@ -30,13 +33,19 @@ import org.telegram.tgnet.TLRPC.TL_messageEntityMention
import org.telegram.tgnet.TLRPC.TL_messageEntityPhone
import org.telegram.tgnet.TLRPC.TL_messageEntityUrl
import org.telegram.tgnet.TLRPC.TL_messageMediaPoll
import org.telegram.ui.ActionBar.Theme
import org.telegram.ui.ChatActivity
import org.telegram.ui.Components.ColoredImageSpan
import xyz.nextalone.nagram.NaConfig
import java.io.File
import java.io.FileOutputStream
import java.util.Date


object MessageHelper {

private val spannedStrings = arrayOfNulls<SpannableStringBuilder>(5)

fun getPathToMessage(messageObject: MessageObject): File? {
var path = messageObject.messageOwner.attachPath
if (!TextUtils.isEmpty(path)) {
Expand Down Expand Up @@ -261,4 +270,42 @@ object MessageHelper {
}
return message
}

private fun formatTime(timestamp: Int): String {
return LocaleController.formatString(R.string.formatDateAtTime, LocaleController.getInstance().formatterYear.format(Date(timestamp * 1000L)), LocaleController.getInstance().formatterDay.format(Date(timestamp * 1000L)))
}

fun getTimeHintText(messageObject: MessageObject): CharSequence {
val text = SpannableStringBuilder()
if (spannedStrings[3] == null) {
spannedStrings[3] = SpannableStringBuilder("\u200B")
spannedStrings[3]?.setSpan(ColoredImageSpan(Theme.chat_timeHintSentDrawable), 0, 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
}
text.append(spannedStrings[3])
text.append(' ')
text.append(formatTime(messageObject.messageOwner.date))
if (messageObject.messageOwner.edit_date != 0) {
text.append("\n")
if (spannedStrings[1] == null) {
spannedStrings[1] = SpannableStringBuilder("\u200B")
spannedStrings[1]?.setSpan(ColoredImageSpan(Theme.chat_editDrawable), 0, 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
}
text.append(spannedStrings[1])
text.append(' ')
text.append(formatTime(messageObject.messageOwner.edit_date))
}
if (messageObject.messageOwner.fwd_from != null && messageObject.messageOwner.fwd_from.date != 0) {
text.append("\n")
if (spannedStrings[4] == null) {
spannedStrings[4] = SpannableStringBuilder("\u200B")
val span = ColoredImageSpan(Theme.chat_timeHintForwardDrawable)
span.setSize(AndroidUtilities.dp(12f))
spannedStrings[4]?.setSpan(span, 0, 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
}
text.append(spannedStrings[4])
text.append(' ')
text.append(formatTime(messageObject.messageOwner.fwd_from.date))
}
return text
}
}

0 comments on commit 77368aa

Please sign in to comment.