Skip to content

Commit

Permalink
Improved displaying of messages in Replies in chats that are no lon…
Browse files Browse the repository at this point in the history
…ger accessible + Show tooltip over comment button instead of system toast, when possible
  • Loading branch information
vkryl committed Oct 26, 2023
1 parent ec3dec6 commit 35d8e02
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 9 deletions.
1 change: 1 addition & 0 deletions app/src/main/java/org/thunderdog/challegram/data/TD.java
Original file line number Diff line number Diff line change
Expand Up @@ -2683,6 +2683,7 @@ public static String toErrorString (@Nullable TdApi.Object object) {
case "Invalid chat identifier specified": res = R.string.error_ChatInfoNotFound; break;
case "Message must be non-empty": res = R.string.MessageInputEmpty; break;
case "Not Found": res = R.string.error_NotFound; break;
case "Can't access the chat": res = R.string.errorChatInaccessible; break;
case "The maximum number of pinned chats exceeded": return Lang.plural(R.string.ErrorPinnedChatsLimit, TdlibManager.instance().current().pinnedChatsMaxCount());
default: {
String lookup = StringUtils.toCamelCase(message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,10 @@ public boolean contains (float x, float y) {
return rect.contains(Math.round(x), Math.round(y));
}

public void getRect (Rect rect) {
rect.set(this.rect);
}

private static final int FLAG_CAUGHT = 0x01;
private static final int FLAG_BLOCKED = 0x02;

Expand Down
33 changes: 25 additions & 8 deletions app/src/main/java/org/thunderdog/challegram/data/TGMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -1026,9 +1026,9 @@ public final void openMessageThread (@NonNull TdApi.GetMessageThread query, @Nul
boolean needAnimateChanges = needAnimateChanges();
openingComments.setValue(false, needAnimateChanges);
if (isChannel()) {
UI.showToast(R.string.ChannelPostDeleted, Toast.LENGTH_SHORT);
showCommentButtonError(Lang.getString(R.string.ChannelPostDeleted));
} else {
UI.showError(result);
showCommentButtonError(TD.toErrorString(result));
}
break;
}
Expand All @@ -1038,13 +1038,24 @@ public final void openMessageThread (@NonNull TdApi.GetMessageThread query, @Nul
break;
}
openingComments.setValue(false, needAnimateChanges());
UI.showError(result);
showCommentButtonError(TD.toErrorString(result));
break;
}
}
}));
}

private void showCommentButtonError (String text) {
View view = findCurrentView();
if (!needCommentButton() || view == null) {
UI.showToast(text, Toast.LENGTH_SHORT);
return;
}
buildContentHint(view, (targetView, outRect) ->
commentButton.getRect(outRect), false
).show(tdlib, text).hideDelayed();
}

private int computeBubbleHeight () {
int height = getContentHeight();
if (replyData != null && !alignReplyHorizontally()) {
Expand Down Expand Up @@ -7209,18 +7220,24 @@ public TooltipOverlayView.TooltipInfo showContentHint (View view, TooltipOverlay
}

public TooltipOverlayView.TooltipInfo showContentHint (View view, TooltipOverlayView.LocationProvider locationProvider, TdApi.FormattedText text) {
return buildContentHint(view, locationProvider).show(tdlib, text);
return buildContentHint(view, locationProvider, true).show(tdlib, text);
}

public TooltipOverlayView.TooltipBuilder buildContentHint (View view, TooltipOverlayView.LocationProvider locationProvider) {
public TooltipOverlayView.TooltipBuilder buildContentHint (View view, TooltipOverlayView.LocationProvider locationProvider, boolean applyContentOffset) {
return context().tooltipManager().builder(view, currentViews)
.locate((v, outRect) -> {
if (locationProvider != null) {
locationProvider.getTargetBounds(v, outRect);
outRect.offset(getContentX(), getContentY());
if (applyContentOffset) {
outRect.offset(getContentX(), getContentY());
}
} else {
outRect.left = getContentX();
outRect.top = getContentY();
if (applyContentOffset) {
outRect.left = getContentX();
outRect.top = getContentY();
} else {
outRect.left = outRect.top = 0;
}
outRect.right = outRect.left + getContentWidth();
outRect.bottom = outRect.top + getContentHeight();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1433,7 +1433,7 @@ private void showExplanation (View view) {
}
explanationPopup = buildContentHint(view, (targetView, outRect) -> {
outRect.set(0, 0, questionText.getWidth(), questionText.getHeight());
}).icon(R.drawable.baseline_info_24).needBlink(true).chatTextSize(-2f).interceptTouchEvents(true).handleBackPress(true).show(tdlib, formattedText).addListener(this);
}, true).icon(R.drawable.baseline_info_24).needBlink(true).chatTextSize(-2f).interceptTouchEvents(true).handleBackPress(true).show(tdlib, formattedText).addListener(this);
}
}

Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3119,6 +3119,8 @@
<string name="error_ANONYMOUS_REACTIONS_DISABLED">Sorry, anonymous administrators cannot leave reactions or participate in polls.</string>
<string name="error_PEER_ID_INVALID">Sorry, you don\'t have access to this chat or channel.</string>
<string name="error_STICKERSET_INVALID">Sticker set not found or no longer exists.</string>
<string name="error_CHANNEL_PRIVATE">Chat is inaccessible</string>
<string name="errorChatInaccessible">Can\'t access the chat</string>
<string name="error_CHANNELS_TOO_MUCH">Sorry, you are a member of too many groups or channels. Please leave some before joining a new one.</string>
<string name="error_PHONE_NUMBER_BANNED">Sorry, this phone number is banned. Contact us at [email protected] if you need help.</string>
<string name="error_CHANNELS_ADMIN_LOCATED_TOO_MUCH">Sorry, you have too many location-based groups already. Please delete one of your existing ones first.</string>
Expand Down

0 comments on commit 35d8e02

Please sign in to comment.