Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/dev' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
LiuYi0526 committed Nov 10, 2024
2 parents 561d4c5 + 352bc24 commit d701188
Show file tree
Hide file tree
Showing 8 changed files with 240 additions and 60 deletions.
2 changes: 1 addition & 1 deletion TMessagesProj/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ repositories {
}

def verName = APP_VERSION_NAME
def verCode = 1196
def verCode = 1197


def officialVer = APP_VERSION_NAME
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
import tw.nekomimi.nekogram.utils.AlertUtil;
import tw.nekomimi.nekogram.utils.ProxyUtil;
import xyz.nextalone.nagram.NaConfig;
import xyz.nextalone.nagram.helper.HyperOsHelper;

import static com.google.zxing.common.detector.MathUtils.distance;
import static org.telegram.ui.ActionBar.FloatingToolbar.STYLE_THEME;
Expand Down Expand Up @@ -1413,15 +1414,19 @@ public void invalidate() {
}
}

private static final int TRANSLATE = 3;
public static final int HYPEROS_AI = 3;
private static final int TRANSLATE = 4;
private ActionMode.Callback createActionCallback() {
final ActionMode.Callback callback = new ActionMode.Callback() {
@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
menu.add(Menu.NONE, android.R.id.copy, 0, android.R.string.copy);
menu.add(Menu.NONE, R.id.menu_quote, 1, LocaleController.getString(R.string.Quote));
menu.add(Menu.NONE, android.R.id.selectAll, 2, android.R.string.selectAll);
menu.add(Menu.NONE, TRANSLATE, 3, LocaleController.getString(R.string.TranslateMessage));
if (HyperOsHelper.INSTANCE.isHyperAiAvailable(textSelectionOverlay.getContext())) {
menu.add(Menu.NONE, HYPEROS_AI, HYPEROS_AI, "AI");
}
menu.add(Menu.NONE, TRANSLATE, TRANSLATE, LocaleController.getString(R.string.TranslateMessage));
return true;
}

Expand Down Expand Up @@ -1512,6 +1517,15 @@ public void onFailed(boolean unsupported, @NotNull String message) {
});
}
return true;
} else if (itemId == HYPEROS_AI) {
CharSequence str = getSelectedText();
if (str == null) {
return true;
}
HyperOsHelper.INSTANCE.startHyperOsAiService(textSelectionOverlay, str.toString());
hideActions();
clear(true);
return true;
} else if (itemId == R.id.menu_quote) {
quoteText();
hideActions();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2013,7 +2013,7 @@ public ImageReceiver.BitmapHolder getThumbForPhoto(MessageObject messageObject,

@Override
public boolean cancelButtonPressed() {
if (cameraOpened && cameraView != null) {
if (cameraOpened && cameraView != null && !NekoConfig.disableInstantCamera.Bool()) {
AndroidUtilities.runOnUIThread(() -> {
if (cameraView != null && !parentAlert.isDismissed() && Build.VERSION.SDK_INT >= 21) {
cameraView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_FULLSCREEN);
Expand Down Expand Up @@ -3827,7 +3827,7 @@ private void pauseCameraPreview() {
private void resumeCameraPreview() {
try {
checkCamera(false);
if (cameraView != null) {
if (cameraView != null && !NekoConfig.disableInstantCamera.Bool()) {
CameraController.getInstance().startPreview(cameraView.getCameraSessionObject());
}
} catch (Exception e) {
Expand Down Expand Up @@ -3866,7 +3866,9 @@ public void pauseCamera(boolean pause) {
// afterCameraInitRunnable = null;
// isCameraFrontfaceBeforeEnteringEditMode = null;
// };
showCamera();
if (!NekoConfig.disableInstantCamera.Bool()) {
showCamera();
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import static org.telegram.messenger.AndroidUtilities.dp;
import static org.telegram.messenger.AndroidUtilities.getWallpaperRotation;
import static org.telegram.ui.Cells.TextSelectionHelper.HYPEROS_AI;

import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
Expand Down Expand Up @@ -77,6 +78,7 @@
import java.util.List;

import xyz.nextalone.nagram.NaConfig;
import xyz.nextalone.nagram.helper.HyperOsHelper;

public class EditTextBoldCursor extends EditTextEffects {

Expand Down Expand Up @@ -1219,6 +1221,7 @@ public ActionMode startActionMode(ActionMode.Callback callback) {
if (NaConfig.INSTANCE.getShowTextUndoRedo().Bool()) {
addUndoRedo(floatingActionMode.getMenu());
}
addHyperOsAi(floatingActionMode.getMenu());
floatingActionMode.invalidate();
getViewTreeObserver().addOnPreDrawListener(floatingToolbarPreDrawListener);
invalidate();
Expand All @@ -1228,6 +1231,27 @@ public ActionMode startActionMode(ActionMode.Callback callback) {
}
}

private void addHyperOsAi(Menu menu) {
if (!HyperOsHelper.INSTANCE.isHyperAiAvailable(getContext())) {
return;
}
// Add AI menu item if it doesn't already exist
if (menu.findItem(HYPEROS_AI) == null) {
menu.add(Menu.NONE, HYPEROS_AI, HYPEROS_AI, "AI")
.setAlphabeticShortcut('s')
.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
}
}

@Override
public boolean onTextContextMenuItem(int id) {
if (id == HYPEROS_AI) {
HyperOsHelper.INSTANCE.startHyperOsAiService(this);
return true;
}
return super.onTextContextMenuItem(id);
}

private boolean shouldShowQuoteButton() {
if (!hasSelection() || getSelectionStart() < 0 || getSelectionEnd() < 0 || getSelectionStart() == getSelectionEnd()) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,9 @@
import org.telegram.messenger.MessageObject;
import org.telegram.messenger.R;
import org.telegram.messenger.SvgHelper;
import org.telegram.messenger.browser.Browser;
import org.telegram.tgnet.TLRPC;
import org.telegram.ui.ActionBar.BottomSheet;
import org.telegram.ui.ActionBar.Theme;
import org.telegram.ui.Stories.recorder.ButtonWithCounterView;

import tw.nekomimi.nekogram.TextViewEffects;

Expand Down Expand Up @@ -91,7 +89,7 @@ public BottomSheetCell(Context context, boolean withoutBackground) {
textView[a].setGravity(Gravity.CENTER);
if (hasBackground) {
textView[a].setTextColor(Theme.getColor(Theme.key_featuredStickers_buttonText));
textView[a].setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
textView[a].setTypeface(AndroidUtilities.bold());
} else {
textView[a].setTextColor(Theme.getColor(Theme.key_featuredStickers_addButton));
}
Expand Down Expand Up @@ -230,7 +228,7 @@ protected void onScrollChanged(int l, int t, int oldl, int oldt) {
scrollView.setWillNotDraw(false);
scrollView.setClipToPadding(false);
scrollView.setVerticalScrollBarEnabled(false);
container.addView(scrollView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.LEFT | Gravity.TOP, 0, 0, 0, 127));
container.addView(scrollView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.LEFT | Gravity.TOP, 0, 0, 0, 130));

linearLayout = new LinearLayout(context);
linearLayout.setOrientation(LinearLayout.VERTICAL);
Expand All @@ -251,29 +249,30 @@ protected void onScrollChanged(int l, int t, int oldl, int oldt) {
}

TextView textView = new TextView(context);
textView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
textView.setTypeface(AndroidUtilities.bold());
textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20);
textView.setTextColor(Theme.getColor(Theme.key_dialogTextBlack));
textView.setSingleLine(true);
textView.setEllipsize(TextUtils.TruncateAt.END);
textView.setText(LocaleController.getString("UpdateTelegram", R.string.UpdateTelegram).replace("Telegram", LocaleController.getString("NekoX", R.string.NekoX)));
textView.setText(LocaleController.getString(R.string.AppUpdate));
linearLayout.addView(textView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.TOP | Gravity.CENTER_HORIZONTAL, 23, 16, 23, 0));

TextView messageTextView = new TextView(getContext());
messageTextView.setTextColor(Theme.getColor(Theme.key_dialogTextGray3));
messageTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
messageTextView.setMovementMethod(new AndroidUtilities.LinkMovementMethodMy());
messageTextView.setLinkTextColor(Theme.getColor(Theme.key_dialogTextLink));
messageTextView.setText(LocaleController.formatString("AppUpdateVersionAndSize", R.string.AppUpdateVersionAndSize, appUpdate.version, update.document instanceof TLRPC.TL_document ? AndroidUtilities.formatFileSize(appUpdate.document.size) : "Play Store"));
messageTextView.setText(LocaleController.formatString("AppUpdateVersionAndSize", R.string.AppUpdateVersionAndSize, appUpdate.version, AndroidUtilities.formatFileSize(appUpdate.document.size)));
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 TextViewEffects(getContext());
changelogTextView.setTextColor(Theme.getColor(Theme.key_dialogTextBlack));
changelogTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
changelogTextView.setMovementMethod(new AndroidUtilities.LinkMovementMethodMy());
changelogTextView.setLinkTextColor(Theme.getColor(Theme.key_dialogTextLink));
if (TextUtils.isEmpty(appUpdate.text)) {
changelogTextView.setText(AndroidUtilities.replaceTags(LocaleController.getString("AppUpdateChangelogEmpty", R.string.AppUpdateChangelogEmpty)));
changelogTextView.setText(AndroidUtilities.replaceTags(LocaleController.getString(R.string.AppUpdateChangelogEmpty)));
} else {
SpannableStringBuilder builder = new SpannableStringBuilder(appUpdate.text);
MessageObject.addEntitiesToText(builder, update.entities, false, false, false, false);
Expand All @@ -284,29 +283,25 @@ protected void onScrollChanged(int l, int t, int oldl, int oldt) {
linearLayout.addView(changelogTextView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.TOP, 23, 15, 23, 0));

FrameLayout.LayoutParams frameLayoutParams = new FrameLayout.LayoutParams(LayoutHelper.MATCH_PARENT, AndroidUtilities.getShadowHeight(), Gravity.BOTTOM | Gravity.LEFT);
frameLayoutParams.bottomMargin = AndroidUtilities.dp(127);
frameLayoutParams.bottomMargin = AndroidUtilities.dp(130);
shadow = new View(context);
shadow.setBackgroundColor(Theme.getColor(Theme.key_dialogShadowLine));
shadow.setAlpha(0.0f);
shadow.setTag(1);
container.addView(shadow, frameLayoutParams);

ButtonWithCounterView doneButton = new ButtonWithCounterView(context, true, null);
BottomSheetCell doneButton = new BottomSheetCell(context, false);
doneButton.setText(LocaleController.formatString("AppUpdateDownloadNow", R.string.AppUpdateDownloadNow), false);
doneButton.setOnClickListener(v -> {
if (update.document instanceof TLRPC.TL_document) {
FileLoader.getInstance(accountNum).loadFile(appUpdate.document, "update", FileLoader.PRIORITY_NORMAL, 1);
} else {
Browser.openUrl(context, appUpdate.url);
}
doneButton.background.setOnClickListener(v -> {
FileLoader.getInstance(accountNum).loadFile(appUpdate.document, "update", FileLoader.PRIORITY_NORMAL, 1);
dismiss();
});
container.addView(doneButton, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, Gravity.LEFT | Gravity.BOTTOM, 14, 14, 14, 48 + 8 + 8));
container.addView(doneButton, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 50, Gravity.LEFT | Gravity.BOTTOM, 0, 0, 0, 50));

ButtonWithCounterView scheduleButton = new ButtonWithCounterView(context, false, null);
scheduleButton.setText(LocaleController.getString("AppUpdateRemindMeLater", R.string.AppUpdateRemindMeLater), false);
scheduleButton.setOnClickListener(v -> dismiss());
container.addView(scheduleButton, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, Gravity.LEFT | Gravity.BOTTOM, 14, 14, 14, 8));
BottomSheetCell scheduleButton = new BottomSheetCell(context, true);
scheduleButton.setText(LocaleController.getString(R.string.AppUpdateRemindMeLater), false);
scheduleButton.background.setOnClickListener(v -> dismiss());
container.addView(scheduleButton, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 50, Gravity.LEFT | Gravity.BOTTOM, 0, 0, 0, 0));
}

private void runShadowAnimation(final int num, final boolean show) {
Expand Down Expand Up @@ -348,7 +343,7 @@ private void updateLayout() {
child.getLocationInWindow(location);
int top = location[1] - AndroidUtilities.dp(24);
int newOffset = Math.max(top, 0);
if (location[1] + linearLayout.getMeasuredHeight() <= container.getMeasuredHeight() - AndroidUtilities.dp(110) + containerView.getTranslationY()) {
if (location[1] + linearLayout.getMeasuredHeight() <= container.getMeasuredHeight() - AndroidUtilities.dp(113) + containerView.getTranslationY()) {
runShadowAnimation(0, false);
} else {
runShadowAnimation(0, true);
Expand Down
Loading

0 comments on commit d701188

Please sign in to comment.