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 Jun 25, 2024
2 parents dfe6255 + 9c075fa commit e4724d6
Show file tree
Hide file tree
Showing 10 changed files with 96 additions and 62 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 = "10.13.1"
def verCode = 1180
def verCode = 1181


def officialVer = "10.13.1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2670,6 +2670,10 @@ public static int getPhotoSize() {
return photoSize;
}

public static int getPhotoSizeOld() {
return 1280;
}

/*public static void clearCursorDrawable(EditText editText) {
if (editText == null) {
return;
Expand Down
12 changes: 3 additions & 9 deletions TMessagesProj/src/main/java/org/telegram/messenger/Emoji.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,18 +86,16 @@ public class Emoji {

private final static int MAX_RECENT_EMOJI_COUNT = 48;

private static boolean isSelectedCustomEmojiPack;
private static File emojiFile;
private static boolean isSelectedEmojiPack;

private static void reloadCache() {
isSelectedCustomEmojiPack = EmojiHelper.getInstance().isSelectedCustomEmojiPack();
emojiFile = EmojiHelper.getInstance().getCurrentEmojiPackOffline();
isSelectedEmojiPack = !EmojiHelper.getInstance().getEmojiPack().equals("default") && emojiFile != null && emojiFile.exists();
}

public static boolean isSelectedCustomPack() {
return isSelectedCustomEmojiPack || isSelectedEmojiPack || NekoConfig.useSystemEmoji.Bool();
return isSelectedEmojiPack || NekoConfig.useSystemEmoji.Bool();
}

public static void reloadEmoji() {
Expand Down Expand Up @@ -147,7 +145,7 @@ private static void loadEmoji(final byte page, final short page2) {
loadingEmoji[page][page2] = true;
Utilities.globalQueue.postRunnable(() -> {
final Bitmap bitmap;
if (NekoConfig.useSystemEmoji.Bool() || isSelectedCustomEmojiPack) {
if (NekoConfig.useSystemEmoji.Bool() || isSelectedEmojiPack) {
int emojiSize = 66;
bitmap = Bitmap.createBitmap(emojiSize, emojiSize, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
Expand All @@ -160,11 +158,7 @@ private static void loadEmoji(final byte page, final short page2) {
emojiSize
);
} else {
if (isSelectedEmojiPack) {
bitmap = loadBitmap(emojiFile.getAbsolutePath() + "/" + String.format(Locale.US, "%d_%d.png", page, page2), false);
} else {
bitmap = loadBitmap("emoji/" + String.format(Locale.US, "%d_%d.png", page, page2));
}
bitmap = loadBitmap("emoji/" + String.format(Locale.US, "%d_%d.png", page, page2));
}
if (bitmap != null) {
emojiBmp[page][page2] = bitmap;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6747,6 +6747,19 @@ public void prepareImportStickers(String title, String shortName, String sofrwar
}).start();
}

public void removeBigPhotoSizes(TLRPC.TL_photo photo, Boolean isEncrypted) {
if (!isEncrypted || photo == null) {
return;
}
ArrayList<TLRPC.PhotoSize> sizes = new ArrayList<>();
for (TLRPC.PhotoSize size: photo.sizes) {
if (size != null && size.w <= AndroidUtilities.getPhotoSizeOld() && size.h <= AndroidUtilities.getPhotoSizeOld()) {
sizes.add(size);
}
}
photo.sizes = sizes;
}

public TLRPC.TL_photo generatePhotoSizes(String path, Uri imageUri) {
return generatePhotoSizes(null, path, imageUri);
}
Expand All @@ -6761,6 +6774,14 @@ public TLRPC.TL_photo generatePhotoSizes(TLRPC.TL_photo photo, String path, Uri
if (size != null) {
sizes.add(size);
}

// ===== Nagram Hook start =====
size = ImageLoader.scaleAndSaveImage(bitmap, AndroidUtilities.getPhotoSizeOld(), AndroidUtilities.getPhotoSizeOld(), true, 80, false, 101, 101);
if (size != null) {
sizes.add(size);
}
// ===== Nagram Hook end =====

size = ImageLoader.scaleAndSaveImage(bitmap, AndroidUtilities.getPhotoSize(), AndroidUtilities.getPhotoSize(), true, 80, false, 101, 101);
if (size != null) {
sizes.add(size);
Expand Down Expand Up @@ -8002,6 +8023,11 @@ public static void prepareSendingMedia(AccountInstance accountInstance, ArrayLis
worker.sync = new CountDownLatch(1);
mediaSendThreadPool.execute(() -> {
worker.photo = accountInstance.getSendMessagesHelper().generatePhotoSizes(info.path, info.uri);

// ===== Nagram Hook start =====
accountInstance.getSendMessagesHelper().removeBigPhotoSizes(worker.photo, isEncrypted);
// ===== Nagram Hook end =====

if (isEncrypted && info.canDeleteAfter) {
new File(info.path).delete();
}
Expand Down Expand Up @@ -8561,6 +8587,11 @@ public static void prepareSendingMedia(AccountInstance accountInstance, ArrayLis
}
if (photo == null) {
photo = accountInstance.getSendMessagesHelper().generatePhotoSizes(info.path, info.uri);

// ===== Nagram Hook start =====
accountInstance.getSendMessagesHelper().removeBigPhotoSizes(photo, isEncrypted);
// ===== Nagram Hook end =====

if (isEncrypted && info.canDeleteAfter) {
new File(info.path).delete();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import org.telegram.messenger.AndroidUtilities;
import org.telegram.messenger.ApplicationLoader;
import org.telegram.messenger.BuildVars;
import org.telegram.messenger.ChatObject;
import org.telegram.messenger.LocaleController;
import org.telegram.messenger.MessagesController;
Expand All @@ -27,6 +28,7 @@
import org.telegram.ui.Components.BottomSheetWithRecyclerListView;
import org.telegram.ui.Components.CubicBezierInterpolator;
import org.telegram.ui.Components.LayoutHelper;
import org.telegram.ui.Components.Premium.PremiumNotAvailableBottomSheet;
import org.telegram.ui.Components.Premium.PremiumPreviewBottomSheet;
import org.telegram.ui.Components.Premium.boosts.adapters.BoostAdapter;
import org.telegram.ui.Components.Premium.boosts.cells.ActionBtnCell;
Expand Down Expand Up @@ -187,6 +189,14 @@ public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newStat
updateRows(false, false);
actionBtn = new ActionBtnCell(getContext(), resourcesProvider);
actionBtn.setOnClickListener(v -> {

// ---- nagram start ----
if (BuildVars.IS_BILLING_UNAVAILABLE) {
fragment.showDialog(new PremiumNotAvailableBottomSheet(fragment));
return;
}
// ---- nagram end ----

if (actionBtn.isLoading()) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

import org.telegram.messenger.AndroidUtilities;
import org.telegram.messenger.BillingController;
import org.telegram.messenger.BuildVars;
import org.telegram.messenger.NotificationCenter;
import org.telegram.messenger.R;
import org.telegram.messenger.UserConfig;
Expand All @@ -40,6 +41,7 @@
import org.telegram.ui.Components.ColoredImageSpan;
import org.telegram.ui.Components.LayoutHelper;
import org.telegram.ui.Components.Premium.PremiumGradient;
import org.telegram.ui.Components.Premium.PremiumNotAvailableBottomSheet;
import org.telegram.ui.Components.Premium.PremiumPreviewBottomSheet;
import org.telegram.ui.Components.Premium.boosts.cells.DurationWithDiscountCell;
import org.telegram.ui.Components.Premium.boosts.cells.selector.SelectorBtnCell;
Expand Down Expand Up @@ -248,6 +250,14 @@ private void init() {
buttonContainer.setBackgroundColor(Theme.getColor(Theme.key_dialogBackground, resourcesProvider));
actionBtn = new GradientButtonWithCounterView(getContext(), true, resourcesProvider);
actionBtn.setOnClickListener(v -> {

// ---- nagram start ----
if (BuildVars.IS_BILLING_UNAVAILABLE && getBaseFragment() != null) {
getBaseFragment().showDialog(new PremiumNotAvailableBottomSheet(getBaseFragment()));
return;
}
// ---- nagram end ----

if (actionBtn.isLoading()) {
return;
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@
import java.util.stream.Collectors;

import tw.nekomimi.nekogram.NekoConfig;
import tw.nekomimi.nekogram.helpers.UnzipHelper;

@SuppressWarnings("ResultOfMethodCallIgnored")
public class EmojiHelper extends BaseRemoteHelper implements NotificationCenter.NotificationCenterDelegate {
private static final String EMOJI_TAG = "emojiv1";
private static final String EMOJI_TAG = "emojiv2";
private static final String EMOJI_FONT_AOSP = "NotoColorEmoji.ttf";
private static final int EMOJI_COUNT = 3538;
private static final String EMOJI_FONT_NAME = "font.ttf";
private static final int EMOJI_COUNT = 1;
private static final String EMOJI_PACKS_FILE_DIR;
private static final Runnable invalidateUiRunnable = () -> NotificationCenter.getGlobalInstance().postNotificationName(NotificationCenter.emojiLoaded);
private static final String[] previewEmojis = {
Expand Down Expand Up @@ -313,7 +313,7 @@ public Typeface getSystemEmojiTypeface() {
}

private Typeface getSelectedTypeface() {
EmojiPackBase pack = getEmojiCustomPacksInfo()
EmojiPackBase pack = getEmojiPacksInfoAll()
.parallelStream()
.filter(emojiPackInfo -> emojiPackInfo.packId.equals(emojiPack))
.findFirst()
Expand Down Expand Up @@ -406,12 +406,21 @@ public ArrayList<EmojiPackBase> getEmojiCustomPacksInfo() {
.collect(Collectors.toCollection(ArrayList::new));
}

public ArrayList<EmojiPackBase> getEmojiPacksInfoAll() {
ArrayList<EmojiPackInfo> emojiPacksInfo = getEmojiPacksInfo();
ArrayList<EmojiPackBase> emojiCustomPacksInfo = getEmojiCustomPacksInfo();
ArrayList<EmojiPackBase> newList = new ArrayList<>();
newList.addAll(emojiPacksInfo);
newList.addAll(emojiCustomPacksInfo);
return newList;
}

public boolean isInstalledOldVersion(String emojiID, int version) {
return getAllVersions(emojiID, version).size() > 0;
return !getAllVersions(emojiID, version).isEmpty();
}

public boolean isInstalledOffline(String emojiID) {
return getAllVersions(emojiID, -1).size() > 0;
return !getAllVersions(emojiID, -1).isEmpty();
}

public ArrayList<File> getAllVersions(String emojiID) {
Expand Down Expand Up @@ -475,7 +484,18 @@ public boolean isEmojiPackDownloading(EmojiPackInfo pack) {
public void installDownloadedEmoji(EmojiPackInfo pack, boolean update) {
var emojiDir = EmojiHelper.getEmojiDir(pack.packId, pack.packVersion);
emojiDir.mkdir();
UnzipHelper.unzip(pack.fileLocation, emojiDir, () -> {
File old = new File(pack.fileLocation);
File newFile = new File(emojiDir, EMOJI_FONT_NAME);
if (old.isFile() && old.exists() && old.canRead()) {
try (FileInputStream inputStream = new FileInputStream(old)) {
AndroidUtilities.copyFile(inputStream, newFile);
} catch (IOException e) {
e.printStackTrace();
}
if (newFile.isFile() && newFile.exists() && newFile.canRead()) {
loadingEmojiPacks.remove(pack.fileLocation);
pack.fileLocation = newFile.toString();
}
if (isPackInstalled(pack)) {
if (update) {
EmojiHelper.getInstance().deleteOldVersions(pack);
Expand All @@ -484,10 +504,8 @@ public void installDownloadedEmoji(EmojiPackInfo pack, boolean update) {
}
reloadEmoji();
}
callProgressChanged(pack, true, 100, pack.fileSize);
loadingEmojiPacks.remove(pack.fileLocation);
});
callProgressChanged(pack, false, 100, pack.fileSize);
}
callProgressChanged(pack, true, 100, pack.fileSize);
}

public EmojiPackBase installEmoji(File emojiFile) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ private void getNewVersionMessagesCallback(Delegate delegate, Update json,
update.url = json.url;
update.flags |= 4;
}
if (NekoXConfig.autoUpdateReleaseChannel == 0 && !update.can_not_skip) {
delegate.onTLResponse(null, null);
return;
}
if (response != null) {
var res = (TLRPC.messages_Messages) response;
getMessagesController().removeDeletedMessagesFromArray(CHANNEL_METADATA_ID, res.messages);
Expand Down Expand Up @@ -175,10 +179,6 @@ public void checkNewVersionAvailable(Delegate delegate) {
}

public void checkNewVersionAvailable(Delegate delegate, boolean updateAlways_) {
if (NekoXConfig.autoUpdateReleaseChannel == 0) {
delegate.onTLResponse(null, null);
return;
}
updateAlways = updateAlways_;
load(delegate);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -918,6 +918,7 @@ public int getItemViewType(int position) {

@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
View view = holder.itemView;
AbstractConfigCell a = cellGroup.rows.get(position);
if (a != null) {
if (a instanceof ConfigCellCustom) {
Expand All @@ -929,6 +930,9 @@ public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
} else if (position == cellGroup.rows.indexOf(doubleTapActionRow)) {
textCell.setTextAndValue(LocaleController.getString("DoubleTapAction", R.string.DoubleTapAction), DoubleTap.doubleTapActionMap.get(NaConfig.INSTANCE.getDoubleTapAction().Int()), true);
}
} else if (view instanceof EmojiSetCell) {
EmojiSetCell v1 = (EmojiSetCell) view;
v1.setData(EmojiHelper.getInstance().getCurrentEmojiPackInfo(), false, true);
}
} else {
// Default binds
Expand Down Expand Up @@ -970,7 +974,6 @@ public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType
break;
case ConfigCellCustom.CUSTOM_ITEM_EmojiSet:
view = emojiSetCell = new EmojiSetCell(mContext, false);
emojiSetCell.setData(EmojiHelper.getInstance().getCurrentEmojiPackInfo(), false, true);
view.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
break;
}
Expand Down

0 comments on commit e4724d6

Please sign in to comment.