Skip to content

Commit

Permalink
fix: remote emoji pack
Browse files Browse the repository at this point in the history
  • Loading branch information
omg-xtao committed Jun 25, 2024
1 parent 000c6e4 commit 9c075fa
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 57 deletions.
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

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 @@ -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 9c075fa

Please sign in to comment.