Skip to content

Commit

Permalink
Merge branch 'dev' into m_10.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
omg-xtao committed Feb 15, 2024
2 parents 9387057 + 8b14fd8 commit 61d9f4b
Show file tree
Hide file tree
Showing 12 changed files with 397 additions and 19 deletions.
2 changes: 1 addition & 1 deletion TMessagesProj/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ apply plugin: "com.android.application"
apply plugin: "kotlin-android"

def verName = "10.6.4"
def verCode = 1158
def verCode = 1159


def officialVer = "10.6.4"
Expand Down
22 changes: 16 additions & 6 deletions TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -16958,10 +16958,16 @@ private void addToSelectedMessages(MessageObject messageObject, boolean outside,
ActionBarMenuItem selectItem = actionBar.createActionMode().getItem(nkactionbarbtn_selectBetween);
ActionBarMenuItem combineMessageItem = actionBar.createActionMode().getItem(combine_message);

ActionBarMenuSubItem saveToDownloadsItem = actionModeOtherItem.getSubItem(save_to);
ActionBarMenuSubItem saveMessageItem = actionModeOtherItem.getSubItem(nkbtn_savemessage);
ActionBarMenuSubItem forwardNoQuoteItem = actionModeOtherItem.getSubItem(nkbtn_forward_noquote);
ActionBarMenuSubItem starItem = actionModeOtherItem.getSubItem(star);
ActionBarMenuSubItem saveToDownloadsItem = null;
ActionBarMenuSubItem saveMessageItem = null;
ActionBarMenuSubItem forwardNoQuoteItem = null;
ActionBarMenuSubItem starItem = null;
if (actionModeOtherItem != null) {
saveToDownloadsItem = actionModeOtherItem.getSubItem(save_to);
saveMessageItem = actionModeOtherItem.getSubItem(nkbtn_savemessage);
forwardNoQuoteItem = actionModeOtherItem.getSubItem(nkbtn_forward_noquote);
starItem = actionModeOtherItem.getSubItem(star);
}

boolean noforwards = getMessagesController().isChatNoForwards(currentChat) || hasSelectedNoforwardsMessage();
boolean canForward = chatMode != MODE_SCHEDULED && cantForwardMessagesCount == 0 && !noforwards;
Expand Down Expand Up @@ -17249,7 +17255,9 @@ public void onAnimationCancel(Animator animation) {

if (translateItem != null)
translateItem.setVisibility(selectedMessagesCanCopyIds[0].size() + selectedMessagesCanCopyIds[1].size() > 0);
actionModeOtherItem.setSubItemVisibility(nkbtn_sharemessage, selectedMessagesCanCopyIds[0].size() + selectedMessagesCanCopyIds[1].size() > 0);
if (actionModeOtherItem != null) {
actionModeOtherItem.setSubItemVisibility(nkbtn_sharemessage, selectedMessagesCanCopyIds[0].size() + selectedMessagesCanCopyIds[1].size() > 0);
}

boolean allowPin = false;
if (currentChat != null) {
Expand All @@ -17267,7 +17275,9 @@ public void onAnimationCancel(Animator animation) {
}
}
}
actionModeOtherItem.setSubItemVisibility(nkbtn_unpin, allowPin);
if (actionModeOtherItem != null) {
actionModeOtherItem.setSubItemVisibility(nkbtn_unpin, allowPin);
}
}
}
updateSelectedMessageReactions();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@

import java.util.Locale;

import tw.nekomimi.nekogram.TextViewEffects;
import tw.nekomimi.nekogram.helpers.remote.UpdateHelper;

public class BlockingUpdateView extends FrameLayout implements NotificationCenter.NotificationCenterDelegate {
Expand Down Expand Up @@ -97,7 +98,7 @@ public BlockingUpdateView(final Context context) {
titleTextView.setText(LocaleController.getString("UpdateTelegram", R.string.UpdateTelegram).replace("Telegram", LocaleController.getString("NekoX", R.string.NekoX)));
container.addView(titleTextView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER_HORIZONTAL | Gravity.TOP));

textView = new TextView(context);
textView = new TextViewEffects(context);
textView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
textView.setLinkTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteLinkText));
textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
import org.telegram.ui.ActionBar.Theme;
import org.telegram.ui.Stories.recorder.ButtonWithCounterView;

import tw.nekomimi.nekogram.TextViewEffects;

public class UpdateAppAlertDialog extends BottomSheet {

private TLRPC.TL_help_appUpdate appUpdate;
Expand Down Expand Up @@ -266,7 +268,7 @@ protected void onScrollChanged(int l, int t, int oldl, int oldt) {
messageTextView.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.TOP);
linearLayout.addView(messageTextView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.TOP | Gravity.CENTER_HORIZONTAL, 23, 0, 23, 5));

TextView changelogTextView = new TextView(getContext());
TextView changelogTextView = new TextViewEffects(getContext());
changelogTextView.setTextColor(Theme.getColor(Theme.key_dialogTextBlack));
changelogTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
changelogTextView.setLinkTextColor(Theme.getColor(Theme.key_dialogTextLink));
Expand Down
25 changes: 22 additions & 3 deletions TMessagesProj/src/main/java/org/telegram/ui/ProfileActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,8 @@
import kotlin.Unit;
import libv2ray.Libv2ray;
import tw.nekomimi.nekogram.BackButtonMenuRecent;
import tw.nekomimi.nekogram.helpers.SettingsHelper;
import tw.nekomimi.nekogram.helpers.SettingsSearchResult;
import tw.nekomimi.nekogram.transtale.popupwrapper.AutoTranslatePopupWrapper;
import tw.nekomimi.nekogram.ui.BottomBuilder;
import tw.nekomimi.nekogram.InternalUpdater;
Expand Down Expand Up @@ -11401,7 +11403,7 @@ private void updateSearchArray() {
}

private SearchResult[] onCreateSearchArray() {
return new SearchResult[]{
SearchResult[] arr = new SearchResult[]{
new SearchResult(500, LocaleController.getString("EditName", R.string.EditName), 0, () -> presentFragment(new ChangeNameActivity(resourcesProvider))),
new SearchResult(501, LocaleController.getString("ChangePhoneNumber", R.string.ChangePhoneNumber), 0, () -> presentFragment(new ActionIntroActivity(ActionIntroActivity.ACTION_TYPE_CHANGE_PHONE_NUMBER))),
new SearchResult(502, LocaleController.getString("AddAnotherAccount", R.string.AddAnotherAccount), 0, () -> {
Expand Down Expand Up @@ -11664,6 +11666,22 @@ private SearchResult[] onCreateSearchArray() {
new SearchResult(403, LocaleController.getString("TelegramFAQ", R.string.TelegramFAQ), LocaleController.getString("SettingsHelp", R.string.SettingsHelp), R.drawable.msg2_help, () -> Browser.openUrl(getParentActivity(), LocaleController.getString("TelegramFaqUrl", R.string.TelegramFaqUrl))),
new SearchResult(404, LocaleController.getString("PrivacyPolicy", R.string.PrivacyPolicy), LocaleController.getString("SettingsHelp", R.string.SettingsHelp), R.drawable.msg2_help, () -> Browser.openUrl(getParentActivity(), LocaleController.getString("PrivacyPolicyUrl", R.string.PrivacyPolicyUrl))),
};
ArrayList<SettingsSearchResult> nagramSettings = SettingsHelper.onCreateSearchArray(
fragment -> AndroidUtilities.runOnUIThread(() -> presentFragment(fragment, false, false))
);
ArrayList<SearchResult> list = new ArrayList<>();
for (SettingsSearchResult oldResult: nagramSettings) {
SearchResult result = new SearchResult(
oldResult.guid, oldResult.searchTitle, null, oldResult.path1, oldResult.path2, oldResult.iconResId, oldResult.openRunnable
);
list.add(result);
}
// combine
SearchResult[] result = Arrays.copyOf(arr, arr.length + list.size());
for (int i = 0; i < list.size(); i++) {
result[arr.length + i] = list.get(i);
}
return result;
}

private boolean isPremiumFeatureAvailable(int feature) {
Expand Down Expand Up @@ -11937,12 +11955,13 @@ public void search(String text) {
for (int i = 0; i < searchArgs.length; i++) {
if (searchArgs[i].length() != 0) {
String searchString = searchArgs[i];
int index = title.indexOf(" " + searchString);
int index = title.indexOf(searchString);
if (index < 0 && translitArgs[i] != null) {
searchString = translitArgs[i];
index = title.indexOf(" " + searchString);
index = title.indexOf(searchString);
}
if (index >= 0) {
index -= 1;
if (stringBuilder == null) {
stringBuilder = new SpannableStringBuilder(result.searchTitle);
}
Expand Down
219 changes: 219 additions & 0 deletions TMessagesProj/src/main/java/tw/nekomimi/nekogram/TextViewEffects.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,219 @@
package tw.nekomimi.nekogram;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.graphics.Rect;
import android.graphics.Region;
import android.text.Layout;
import android.text.Spanned;
import android.view.MotionEvent;

import org.telegram.messenger.AndroidUtilities;
import org.telegram.ui.ActionBar.Theme;
import org.telegram.ui.Components.AnimatedEmojiDrawable;
import org.telegram.ui.Components.AnimatedEmojiSpan;
import org.telegram.ui.Components.LinkSpanDrawable;
import org.telegram.ui.Components.spoilers.SpoilerEffect;
import org.telegram.ui.Components.spoilers.SpoilersClickDetector;

import java.util.ArrayList;
import java.util.List;
import java.util.Stack;

public class TextViewEffects extends LinkSpanDrawable.LinksTextView {

private final SpoilersClickDetector clickDetector;
private final List<SpoilerEffect> spoilers = new ArrayList<>();
private final Stack<SpoilerEffect> spoilersPool = new Stack<>();
private boolean isSpoilersRevealed;
private final Path path = new Path();
private Paint xRefPaint;

private int emojiOnlyCount;
private AnimatedEmojiSpan.EmojiGroupedSpans animatedEmojiDrawables;
private Layout lastLayout = null;
private int lastTextLength;

public TextViewEffects(Context context) {
this(context, null);
}

public TextViewEffects(Context context, Theme.ResourcesProvider resourcesProvider) {
super(context, resourcesProvider);

clickDetector = new SpoilersClickDetector(this, spoilers, (eff, x, y) -> {
if (isSpoilersRevealed) return;

eff.setOnRippleEndCallback(() -> post(() -> {
isSpoilersRevealed = true;
invalidateSpoilers();
}));

float rad = (float) Math.sqrt(Math.pow(getWidth(), 2) + Math.pow(getHeight(), 2));
for (SpoilerEffect ef : spoilers)
ef.startRipple(x, y, rad);
});
}

@Override
public boolean dispatchTouchEvent(MotionEvent event) {
if (clickDetector.onTouchEvent(event))
return true;
return super.dispatchTouchEvent(event);
}

public void setText(CharSequence text, int emojiOnlyCount) {
this.emojiOnlyCount = emojiOnlyCount;
super.setText(text);
}

@Override
public void setText(CharSequence text, BufferType type) {
isSpoilersRevealed = false;
super.setText(text, type);
}

@Override
protected void onTextChanged(CharSequence text, int start, int lengthBefore, int lengthAfter) {
super.onTextChanged(text, start, lengthBefore, lengthAfter);
invalidateSpoilers();
}

@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
invalidateSpoilers();
}

@Override
protected void onDetachedFromWindow() {
super.onDetachedFromWindow();

AnimatedEmojiSpan.release(this, animatedEmojiDrawables);
}

@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
updateAnimatedEmoji(false);
}

@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
super.onLayout(changed, left, top, right, bottom);
updateAnimatedEmoji(false);
}

@Override
protected void onDraw(Canvas canvas) {
int pl = getPaddingLeft(), pt = getPaddingTop();

canvas.save();
path.rewind();
for (SpoilerEffect eff : spoilers) {
Rect bounds = eff.getBounds();
path.addRect(bounds.left + pl, bounds.top + pt, bounds.right + pl, bounds.bottom + pt, Path.Direction.CW);
}
canvas.clipPath(path, Region.Op.DIFFERENCE);
updateAnimatedEmoji(false);
super.onDraw(canvas);
if (animatedEmojiDrawables != null) {
AnimatedEmojiSpan.drawAnimatedEmojis(canvas, getLayout(), animatedEmojiDrawables, 0, spoilers, computeVerticalScrollOffset() - AndroidUtilities.dp(6), computeVerticalScrollOffset() + computeVerticalScrollExtent(), 0, 1f);
}
canvas.restore();

canvas.save();
canvas.clipPath(path);
path.rewind();
if (!spoilers.isEmpty()) {
spoilers.get(0).getRipplePath(path);
}
canvas.clipPath(path);
super.onDraw(canvas);
canvas.restore();

if (!spoilers.isEmpty()) {
boolean useAlphaLayer = spoilers.get(0).getRippleProgress() != -1;
if (useAlphaLayer) {
canvas.saveLayer(0, 0, getMeasuredWidth(), getMeasuredHeight(), null, Canvas.ALL_SAVE_FLAG);
} else {
canvas.save();
}
canvas.translate(getPaddingLeft(), getPaddingTop() + AndroidUtilities.dp(2));
for (SpoilerEffect eff : spoilers) {
eff.setColor(getPaint().getColor());
eff.draw(canvas);
}

if (useAlphaLayer) {
path.rewind();
spoilers.get(0).getRipplePath(path);
if (xRefPaint == null) {
xRefPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
xRefPaint.setColor(0xff000000);
xRefPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
}
canvas.drawPath(path, xRefPaint);
}
canvas.restore();
}
}

public void updateAnimatedEmoji(boolean force) {
int newTextLength = (getLayout() == null || getLayout().getText() == null) ? 0 : getLayout().getText().length();
if (force || lastLayout != getLayout() || lastTextLength != newTextLength) {
int cacheType = -1;
switch (emojiOnlyCount) {
case 0:
case 1:
case 2:
case 3:
case 4:
cacheType = AnimatedEmojiDrawable.CACHE_TYPE_MESSAGES_LARGE;
break;
case 5:
case 6:
cacheType = AnimatedEmojiDrawable.CACHE_TYPE_KEYBOARD;
break;
case 7:
case 8:
case 9:
default:
if (emojiOnlyCount > 9) {
cacheType = AnimatedEmojiDrawable.CACHE_TYPE_MESSAGES;
}
break;
}
animatedEmojiDrawables = AnimatedEmojiSpan.update(cacheType, this, animatedEmojiDrawables, getLayout());
lastLayout = getLayout();
lastTextLength = newTextLength;
}
}

private void invalidateSpoilers() {
if (spoilers == null) return;
spoilersPool.addAll(spoilers);
spoilers.clear();

if (isSpoilersRevealed) {
invalidate();
return;
}

Layout layout = getLayout();
if (layout != null && layout.getText() instanceof Spanned) {
if (animatedEmojiDrawables != null) {
animatedEmojiDrawables.recordPositions(false);
}
SpoilerEffect.addSpoilers(this, spoilersPool, spoilers);
if (animatedEmojiDrawables != null) {
animatedEmojiDrawables.recordPositions(true);
}
}
invalidate();
}
}
Loading

0 comments on commit 61d9f4b

Please sign in to comment.