mirror of https://github.com/NekoX-Dev/NekoX.git
Allow loading custom emoji
This commit is contained in:
parent
ac47e574e0
commit
55edb6bde4
|
@ -30,11 +30,14 @@ import android.view.ViewGroup;
|
|||
import android.widget.TextView;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.zip.ZipFile;
|
||||
import java.util.zip.ZipInputStream;
|
||||
|
||||
import tw.nekomimi.nekogram.EmojiProvider;
|
||||
import tw.nekomimi.nekogram.NekoConfig;
|
||||
|
@ -129,7 +132,14 @@ public class Emoji {
|
|||
}
|
||||
Bitmap bitmap = null;
|
||||
try {
|
||||
InputStream is = ApplicationLoader.applicationContext.getAssets().open("emoji/" + String.format(Locale.US, "%d_%d.png", page, page2));
|
||||
InputStream is;
|
||||
String entry = "emoji/" + String.format(Locale.US, "%d_%d.png", page, page2);
|
||||
if (NekomuraConfig.useCustomEmoji.Bool()) {
|
||||
entry = "custom_emoji/" + entry;
|
||||
is = new FileInputStream(new File(ApplicationLoader.applicationContext.getFilesDir(), entry));
|
||||
} else {
|
||||
is = ApplicationLoader.applicationContext.getAssets().open(entry);
|
||||
}
|
||||
BitmapFactory.Options opts = new BitmapFactory.Options();
|
||||
opts.inJustDecodeBounds = false;
|
||||
opts.inSampleSize = imageResize;
|
||||
|
|
|
@ -149,7 +149,6 @@ public class SharedConfig {
|
|||
public static boolean showNotificationsForAllAccounts = true;
|
||||
public static int repeatMode;
|
||||
public static boolean allowBigEmoji;
|
||||
public static boolean useSystemEmoji;
|
||||
public static int fontSize = 12;
|
||||
public static int bubbleRadius = 3;
|
||||
public static int ivFontSize = 12;
|
||||
|
@ -1206,7 +1205,6 @@ public class SharedConfig {
|
|||
bubbleRadius = preferences.getInt("bubbleRadius", 3);
|
||||
ivFontSize = preferences.getInt("iv_font_size", fontSize);
|
||||
allowBigEmoji = preferences.getBoolean("allowBigEmoji", true);
|
||||
useSystemEmoji = preferences.getBoolean("useSystemEmoji", false);
|
||||
streamMedia = preferences.getBoolean("streamMedia", true);
|
||||
saveStreamMedia = preferences.getBoolean("saveStreamMedia", true);
|
||||
smoothKeyboard = preferences.getBoolean("smoothKeyboard2", true);
|
||||
|
@ -1821,6 +1819,13 @@ public class SharedConfig {
|
|||
editor.commit();
|
||||
}
|
||||
|
||||
public static void setSmoothKeyboard(boolean smoothKeyboard) {
|
||||
SharedPreferences preferences = MessagesController.getGlobalMainSettings();
|
||||
SharedPreferences.Editor editor = preferences.edit();
|
||||
editor.putBoolean("smoothKeyboard2", smoothKeyboard);
|
||||
editor.commit();
|
||||
}
|
||||
|
||||
public static void togglePauseMusicOnRecord() {
|
||||
pauseMusicOnRecord = !pauseMusicOnRecord;
|
||||
SharedPreferences preferences = MessagesController.getGlobalMainSettings();
|
||||
|
|
|
@ -4,18 +4,28 @@ import android.animation.Animator;
|
|||
import android.animation.AnimatorListenerAdapter;
|
||||
import android.animation.AnimatorSet;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.ParcelFileDescriptor;
|
||||
import android.os.Parcelable;
|
||||
import android.provider.DocumentsContract;
|
||||
import android.view.Gravity;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import org.telegram.messenger.AndroidUtilities;
|
||||
import org.telegram.messenger.ApplicationLoader;
|
||||
import org.telegram.messenger.FileLog;
|
||||
import org.telegram.messenger.LocaleController;
|
||||
import org.telegram.messenger.MediaController;
|
||||
import org.telegram.messenger.R;
|
||||
import org.telegram.messenger.SharedConfig;
|
||||
import org.telegram.tgnet.TLRPC;
|
||||
|
@ -37,12 +47,16 @@ import org.telegram.ui.Components.LayoutHelper;
|
|||
import org.telegram.ui.Components.RecyclerListView;
|
||||
import org.telegram.ui.Components.UndoView;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.util.ArrayList;
|
||||
import kotlin.Unit;
|
||||
|
||||
import tw.nekomimi.nekogram.PopupBuilder;
|
||||
import tw.nekomimi.nekogram.utils.ZipUtil;
|
||||
import tw.nekomimi.nkmr.NekomuraConfig;
|
||||
import tw.nekomimi.nkmr.CellGroup;
|
||||
import tw.nekomimi.nkmr.NekomuraUtil;
|
||||
import tw.nekomimi.nkmr.cells.AbstractCell;
|
||||
import tw.nekomimi.nkmr.cells.*;
|
||||
|
||||
|
@ -59,6 +73,8 @@ public class NekoExperimentalSettingsActivity extends BaseFragment {
|
|||
private final CellGroup cellGroup = new CellGroup(this);
|
||||
|
||||
private final AbstractCell header1 = cellGroup.appendCell(new NekomuraTGHeader(LocaleController.getString("Experiment")));
|
||||
private final AbstractCell useSystemEmojiRow = cellGroup.appendCell(new NekomuraTGTextCheck(NekomuraConfig.useSystemEmoji));
|
||||
private final AbstractCell useCustomEmojiRow = cellGroup.appendCell(new NekomuraTGTextCheck(NekomuraConfig.useCustomEmoji));
|
||||
private final AbstractCell smoothKeyboardRow = cellGroup.appendCell(new NekomuraTGTextCheck(NekomuraConfig.smoothKeyboard));
|
||||
private final AbstractCell increaseVoiceMessageQualityRow = cellGroup.appendCell(new NekomuraTGTextCheck(NekomuraConfig.increaseVoiceMessageQuality));
|
||||
private final AbstractCell mediaPreviewRow = cellGroup.appendCell(new NekomuraTGTextCheck(NekomuraConfig.mediaPreview));
|
||||
|
@ -188,9 +204,7 @@ public class NekoExperimentalSettingsActivity extends BaseFragment {
|
|||
// Cells: Set OnSettingChanged Callbacks
|
||||
cellGroup.callBackSettingsChanged = (key, newValue) -> {
|
||||
if (key.equals(NekomuraConfig.smoothKeyboard.getKey())) {
|
||||
if ((boolean) newValue != NekomuraConfig.smoothKeyboard.Bool()) {
|
||||
SharedConfig.toggleSmoothKeyboard();
|
||||
}
|
||||
SharedConfig.setSmoothKeyboard((boolean) newValue);
|
||||
if (SharedConfig.smoothKeyboard && getParentActivity() != null) {
|
||||
getParentActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
|
||||
}
|
||||
|
@ -208,8 +222,18 @@ public class NekoExperimentalSettingsActivity extends BaseFragment {
|
|||
tooltip.setInfoText(AndroidUtilities.replaceTags(LocaleController.formatString("EnableStickerPinTip", R.string.EnableStickerPinTip)));
|
||||
tooltip.showWithAction(0, UndoView.ACTION_CACHE_WAS_CLEARED, null, null);
|
||||
}
|
||||
}
|
||||
} else if (key.equals(NekomuraConfig.useCustomEmoji.getKey())) {
|
||||
// Check
|
||||
if (!(boolean) newValue) return;
|
||||
NekomuraConfig.useCustomEmoji.setConfigBool(false);
|
||||
|
||||
// Open picker
|
||||
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
|
||||
intent.addCategory(Intent.CATEGORY_OPENABLE);
|
||||
intent.setType("application/zip");
|
||||
Activity act = getParentActivity();
|
||||
act.startActivityFromChild(act, intent, 114);
|
||||
}
|
||||
};
|
||||
|
||||
//Cells: Set ListAdapter
|
||||
|
@ -221,6 +245,40 @@ public class NekoExperimentalSettingsActivity extends BaseFragment {
|
|||
return fragmentView;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityResultFragment(int requestCode, int resultCode, Intent data) {
|
||||
if (requestCode == 114 && resultCode == Activity.RESULT_OK) {
|
||||
try {
|
||||
// copy emoji zip
|
||||
Uri uri = data.getData();
|
||||
String zipPath = MediaController.copyFileToCache(uri, "file");
|
||||
|
||||
if (zipPath == null || zipPath.isEmpty()) {
|
||||
throw new Exception("zip copy failed");
|
||||
}
|
||||
|
||||
//dirs
|
||||
File dir = new File(ApplicationLoader.applicationContext.getFilesDir(), "custom_emoji");
|
||||
if (dir.exists()) {
|
||||
NekomuraUtil.deleteDirectory(dir);
|
||||
}
|
||||
dir.mkdir();
|
||||
|
||||
//process zip
|
||||
ZipUtil.unzip(new FileInputStream(zipPath), dir);
|
||||
if (!new File(ApplicationLoader.applicationContext.getFilesDir(), "custom_emoji/emoji/0_0.png").exists()) {
|
||||
throw new Exception(LocaleController.getString("useCustomEmojiInvalid"));
|
||||
}
|
||||
NekomuraConfig.useCustomEmoji.setConfigBool(true);
|
||||
} catch (Exception e) {
|
||||
FileLog.e(e);
|
||||
NekomuraConfig.useCustomEmoji.setConfigBool(false);
|
||||
Toast.makeText(ApplicationLoader.applicationContext, "Failed: " + e.toString(), Toast.LENGTH_LONG).show();
|
||||
}
|
||||
listAdapter.notifyItemChanged(cellGroup.rows.indexOf(useCustomEmojiRow));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
|
|
|
@ -126,7 +126,6 @@ public class NekoGeneralSettingsActivity extends BaseFragment {
|
|||
private final AbstractCell header5 = cellGroup.appendCell(new NekomuraTGHeader(LocaleController.getString("Appearance")));
|
||||
private final AbstractCell typefaceRow = cellGroup.appendCell(new NekomuraTGTextCheck(NekomuraConfig.typeface));
|
||||
private final AbstractCell useDefaultThemeRow = cellGroup.appendCell(new NekomuraTGTextCheck(NekomuraConfig.useDefaultTheme));
|
||||
private final AbstractCell useSystemEmojiRow = cellGroup.appendCell(new NekomuraTGTextCheck(NekomuraConfig.useSystemEmoji));
|
||||
private final AbstractCell transparentStatusBarRow = cellGroup.appendCell(new NekomuraTGTextCheck(NekomuraConfig.transparentStatusBar));
|
||||
private final AbstractCell appBarShadowRow = cellGroup.appendCell(new NekomuraTGTextCheck(NekomuraConfig.disableAppBarShadow));
|
||||
private final AbstractCell newYearRow = cellGroup.appendCell(new NekomuraTGTextCheck(NekomuraConfig.newYear));
|
||||
|
|
|
@ -43,6 +43,7 @@ public class NekomuraConfig {
|
|||
public static ConfigItem unreadBadgeOnBackButton = addConfig("unreadBadgeOnBackButton", configTypeBool, false);
|
||||
public static ConfigItem customPublicProxyIP = addConfig("customPublicProxyIP", configTypeString, "");
|
||||
public static ConfigItem update_download_soucre = addConfig("update_download_soucre", configTypeInt, 0); // 0: Github 1: Channel 2:CDNDrive
|
||||
public static ConfigItem useCustomEmoji = addConfig("useCustomEmoji", configTypeBool, false);
|
||||
|
||||
// From NekoConfig
|
||||
// TODO sort
|
||||
|
|
|
@ -166,4 +166,14 @@ public class NekomuraUtil {
|
|||
return out.toByteArray();
|
||||
}
|
||||
|
||||
public static boolean deleteDirectory(File directoryToBeDeleted) {
|
||||
File[] allContents = directoryToBeDeleted.listFiles();
|
||||
if (allContents != null) {
|
||||
for (File file : allContents) {
|
||||
deleteDirectory(file);
|
||||
}
|
||||
}
|
||||
return directoryToBeDeleted.delete();
|
||||
}
|
||||
|
||||
}
|
|
@ -27,6 +27,12 @@ public class NekomuraTGTextCheck extends AbstractCell {
|
|||
this.subtitle = subtitle;
|
||||
}
|
||||
|
||||
public NekomuraTGTextCheck(ConfigItem bind, String subtitle, String customTitle) {
|
||||
this.bindConfig = bind;
|
||||
this.title = customTitle;
|
||||
this.subtitle = subtitle;
|
||||
}
|
||||
|
||||
public int getType() {
|
||||
return CellGroup.ITEM_TYPE_TEXT_CHECK;
|
||||
}
|
||||
|
|
|
@ -257,6 +257,8 @@
|
|||
<string name="DeleteDownloadedFileSucceed">已删除</string>
|
||||
<string name="DeleteDownloadedFileExternal">外部文件被跳过。</string>
|
||||
<string name="update_download_soucre">选择更新源</string>
|
||||
<string name="useCustomEmoji">使用自定义 emoji</string>
|
||||
<string name="useCustomEmojiInvalid">不是有效的 emoji zip 文件</string>
|
||||
|
||||
<string name="valuesLargeAvatarInDrawer">Telegram 默认\n使用头像作为背景\n使用大只头像作为背景</string>
|
||||
</resources>
|
|
@ -254,6 +254,8 @@
|
|||
<string name="DeleteDownloadedFileSucceed">Deleted</string>
|
||||
<string name="DeleteDownloadedFileExternal">External file is skipped.</string>
|
||||
<string name="update_download_soucre">Select download soucre</string>
|
||||
<string name="useCustomEmoji">Use Custom Emoji</string>
|
||||
<string name="useCustomEmojiInvalid">Not a vaild emoji zip.</string>
|
||||
|
||||
<string name="valuesLargeAvatarInDrawer">Telegram Default\nAvatar as background\nBig avatar as background</string>
|
||||
<string name="hideSponsoredMessage">Hide sponsored messages</string>
|
||||
|
|
Loading…
Reference in New Issue