Skip to content

Commit

Permalink
feat: support choose new sticker short name
Browse files Browse the repository at this point in the history
  • Loading branch information
omg-xtao committed Apr 3, 2024
1 parent 83ef19c commit 400d457
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 9 deletions.
Expand Up @@ -917,10 +917,15 @@ public void didReceivedNotification(int id, int account, Object... args) {
}

public void uploadStickerFile(String path, VideoEditedInfo videoEditedInfo, String emoji, CharSequence stickerPackName, boolean addToFavorite, TLRPC.StickerSet stickerSet, TLRPC.Document replacedSticker) {
uploadStickerFile(path, videoEditedInfo, emoji, stickerPackName, addToFavorite, stickerSet, replacedSticker, "");
}

public void uploadStickerFile(String path, VideoEditedInfo videoEditedInfo, String emoji, CharSequence stickerPackName, boolean addToFavorite, TLRPC.StickerSet stickerSet, TLRPC.Document replacedSticker, CharSequence stickerShortPackName) {
AndroidUtilities.runOnUIThread(() -> {
stickerUploader = new StickerUploader();
stickerUploader.emoji = emoji;
stickerUploader.path = stickerUploader.finalPath = path;
stickerUploader.stickerShortPackName = stickerShortPackName;
stickerUploader.stickerPackName = stickerPackName;
stickerUploader.addToFavorite = addToFavorite;
stickerUploader.stickerSet = stickerSet;
Expand Down Expand Up @@ -1003,7 +1008,7 @@ private void afterUploadingMedia() {
TLRPC.TL_stickers_createStickerSet req = new TLRPC.TL_stickers_createStickerSet();
req.user_id = new TLRPC.TL_inputUserSelf();
req.title = stickerUploader.stickerPackName.toString();
req.short_name = "";
req.short_name = stickerUploader.stickerShortPackName != null ? stickerUploader.stickerShortPackName.toString() : "";
req.stickers.add(stickerUploader.tlInputStickerSetItem);
ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
if (response instanceof TLRPC.TL_messages_stickerSet) {
Expand Down Expand Up @@ -1036,6 +1041,7 @@ private static class StickerUploader {
public String path;
public String finalPath;
public String emoji;
public CharSequence stickerShortPackName;
public CharSequence stickerPackName;
public TLRPC.TL_inputStickerSetItem tlInputStickerSetItem;
public TLRPC.TL_messageMediaDocument mediaDocument;
Expand Down
Expand Up @@ -142,6 +142,91 @@ public void afterTextChanged(Editable s) {
});
}

public static void showShortNameEditorDialog(Theme.ResourcesProvider resourcesProvider, Context context, Utilities.Callback<CharSequence> callback) {
AlertDialog.Builder builder = new AlertDialog.Builder(context, resourcesProvider);
builder.setTitle(LocaleController.getString(R.string.NewStickerPack));
builder.setMessage(LocaleController.getString(R.string.StickersChooseShortNameForStickerPack));
FrameLayout frameLayout = new FrameLayout(context);
frameLayout.setPadding(dp(24), 0, dp(20), 0);
final EditTextBoldCursor editText = new EditTextBoldCursor(context) {
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(dp(50), MeasureSpec.EXACTLY));
}
};
editText.setTextColor(getThemedColor(Theme.key_dialogTextBlack, resourcesProvider));
editText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);
editText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
editText.setTextColor(getThemedColor(Theme.key_dialogTextBlack, resourcesProvider));
editText.setHandlesColor(getThemedColor(Theme.key_chat_TextSelectionCursor, resourcesProvider));
editText.setHeaderHintColor(getThemedColor(Theme.key_windowBackgroundWhiteBlueHeader, resourcesProvider));
editText.setSingleLine(true);
editText.setFocusable(true);
InputFilter[] inputFilters = new InputFilter[2];
final int maxLength = 50;
inputFilters[0] = new InputFilter.LengthFilter(maxLength);
inputFilters[1] = (source, start, end, dest, dstart, dend) -> {
for (int i = start; i < end; i++) {
if (Character.isWhitespace(source.charAt(i))) {
return "";
}
}
return source;
};
editText.setFilters(inputFilters);
editText.setLineColors(getThemedColor(Theme.key_windowBackgroundWhiteInputField, resourcesProvider), getThemedColor(Theme.key_windowBackgroundWhiteInputFieldActivated, resourcesProvider), getThemedColor(Theme.key_text_RedRegular, resourcesProvider));
editText.setImeOptions(EditorInfo.IME_ACTION_DONE);
editText.setBackground(null);
editText.requestFocus();
editText.setPadding(dp(LocaleController.isRTL ? 28 : 0), 0, dp(LocaleController.isRTL ? 0 : 28), 0);
frameLayout.addView(editText);

NumberTextView checkTextView = new NumberTextView(context);
checkTextView.setCenterAlign(true);
checkTextView.setTextSize(15);
checkTextView.setNumber(maxLength, false);
checkTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteGrayText4));
checkTextView.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO);
frameLayout.addView(checkTextView, LayoutHelper.createFrame(26, 20, (LocaleController.isRTL ? Gravity.LEFT : Gravity.RIGHT) | Gravity.CENTER_VERTICAL, 0, 2, 4, 0));
editText.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {

}

@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {

}

@Override
public void afterTextChanged(Editable s) {
checkTextView.setNumber(maxLength - Character.codePointCount(s, 0, s.length()), true);
}
});
builder.setView(frameLayout);
builder.setCustomViewOffset(4);
builder.setPositiveButton(LocaleController.getString(R.string.Done), (dialog, i) -> {
CharSequence text = editText.getText().toString().trim();
AndroidUtilities.hideKeyboard(editText);
dialog.dismiss();
callback.run(text);
});
builder.setNegativeButton(LocaleController.getString(R.string.Cancel), (dialog, which) -> {
AndroidUtilities.hideKeyboard(editText);
dialog.dismiss();
});
AlertDialog alertDialog = builder.show();
alertDialog.setDismissDialogByButtons(false);
editText.setOnEditorActionListener((view1, i, keyEvent) -> {
if (i == EditorInfo.IME_ACTION_DONE) {
alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).callOnClick();
return true;
}
return false;
});
}

public static void showDeleteForEveryOneDialog(TLRPC.StickerSet set, Theme.ResourcesProvider resourcesProvider, Context context, Runnable callback) {
if (set == null) return;
AlertDialog alertDialog = new AlertDialog.Builder(context, resourcesProvider)
Expand Down
Expand Up @@ -143,7 +143,7 @@ default void stickerSetSelected(TLRPC.StickerSet set, String emoji) {

}

default void newStickerPackSelected(CharSequence name, String emoji) {
default void newStickerPackSelected(CharSequence short_name, CharSequence name, String emoji) {

}

Expand Down Expand Up @@ -356,11 +356,13 @@ public void run() {
reactionsWindow.dismiss();
}
if (stickerSetCovered instanceof TLRPC.TL_stickerSetNoCovered) {
StickersDialogs.showNameEditorDialog(null, resourcesProvider, containerView.getContext(), arg -> {
delegate.newStickerPackSelected(arg, reactionsLayout.getSelectedEmoji());
if (popupWindow != null) {
popupWindow.dismiss();
}
StickersDialogs.showShortNameEditorDialog(resourcesProvider, containerView.getContext(), short_name -> {
StickersDialogs.showNameEditorDialog(null, resourcesProvider, containerView.getContext(), arg -> {
delegate.newStickerPackSelected(short_name, arg, reactionsLayout.getSelectedEmoji());
if (popupWindow != null) {
popupWindow.dismiss();
}
});
});
return;
}
Expand Down
4 changes: 2 additions & 2 deletions TMessagesProj/src/main/java/org/telegram/ui/PhotoViewer.java
Expand Up @@ -7420,8 +7420,8 @@ public void stickerSetSelected(TLRPC.StickerSet stickerSet, String emoji) {
}

@Override
public void newStickerPackSelected(CharSequence name, String emoji) {
stickerMakerView.uploadStickerFile(fullStickerPath, finalVideoEditedInfo, emoji, name, false, null, null);
public void newStickerPackSelected(CharSequence short_name, CharSequence name, String emoji) {
stickerMakerView.uploadStickerFile(fullStickerPath, finalVideoEditedInfo, emoji, name, false, null, null, short_name);
}

@Override
Expand Down
1 change: 1 addition & 0 deletions TMessagesProj/src/main/res/values/strings_na.xml
Expand Up @@ -133,4 +133,5 @@
<string name="PushServiceTypeInAppDialog">Show resident notifications</string>
<string name="PushServiceTypeUnifiedGateway">Unified Push Gateway</string>
<string name="SendMp4DocumentAsVideo">Send mp4 document as video</string>
<string name="StickersChooseShortNameForStickerPack">Choose a short name for your pack.</string>
</resources>

0 comments on commit 400d457

Please sign in to comment.