聊天内点击配置导入

This commit is contained in:
世界 2020-04-02 02:14:35 +08:00
parent f92cf1265d
commit 0c85d6f4fc
No known key found for this signature in database
GPG Key ID: CD109927C34A63C4
4 changed files with 186 additions and 111 deletions

View File

@ -179,12 +179,15 @@ import org.telegram.ui.Components.URLSpanUserMention;
import org.telegram.ui.Components.UndoView;
import org.telegram.ui.Components.voip.VoIPHelper;
import kotlin.text.StringsKt;
import tw.nekomimi.nekogram.MessageDetailsActivity;
import tw.nekomimi.nekogram.MessageHelper;
import tw.nekomimi.nekogram.NekoConfig;
import tw.nekomimi.nekogram.NekoXConfig;
import tw.nekomimi.nekogram.translator.TranslateBottomSheet;
import tw.nekomimi.nekogram.translator.Translator;
import tw.nekomimi.nekogram.utils.AlertUtil;
import tw.nekomimi.nekogram.utils.UIUtil;
import java.io.BufferedWriter;
import java.io.File;
@ -1915,7 +1918,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
if (scrimView != null && (child == pagedownButton || child == mentiondownButton || child == floatingDateView || child == fireworksOverlay)) {
return false;
}
if (getTag(BlurBehindDrawable.TAG_DRAWING_AS_BACKGROUND) != null ) {
if (getTag(BlurBehindDrawable.TAG_DRAWING_AS_BACKGROUND) != null) {
boolean needBlur;
if (((int) getTag(BlurBehindDrawable.TAG_DRAWING_AS_BACKGROUND)) == BlurBehindDrawable.STATIC_CONTENT) {
needBlur = child == actionBar;
@ -1925,7 +1928,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
if (!needBlur) {
return false;
}
} else if (getTag(BlurBehindDrawable.TAG_DRAWING_AS_BACKGROUND) == null && instantCameraView.blurFullyDrawing()) {
} else if (getTag(BlurBehindDrawable.TAG_DRAWING_AS_BACKGROUND) == null && instantCameraView.blurFullyDrawing()) {
boolean needBlur = child == actionBar || child == chatListView || child == pinnedMessageView || child == fragmentContextView;
if (needBlur) {
return false;
@ -2418,7 +2421,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
private void setNonNoveTranslation(int y) {
contentView.setTranslationY(y);
actionBar.setTranslationY(0);
// instantCameraView.setTranslationY(instantCameraView.getBottom() - chatListView.getBottom() + chatListView.getTranslationY());
// instantCameraView.setTranslationY(instantCameraView.getBottom() - chatListView.getBottom() + chatListView.getTranslationY());
contentView.setBackgroundTranslation(0);
if (pinnedMessageView != null) {
pinnedMessageView.setTranslationY(0);
@ -2440,7 +2443,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
if (chatAttachAlert != null && chatAttachAlert.isShowing() || chatActivityEnterView.isPopupShowing()) {
setNonNoveTranslation(y);
} else {
// instantCameraView.setTranslationY(instantCameraView.getBottom() - chatListView.getBottom() + chatListView.getTranslationY());
// instantCameraView.setTranslationY(instantCameraView.getBottom() - chatListView.getBottom() + chatListView.getTranslationY());
actionBar.setTranslationY(y);
contentView.setBackgroundTranslation(y);
if (pinnedMessageView != null) {
@ -3107,13 +3110,13 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
nextPosition = p - 1;
}
if (chatMessageCell.willRemoved) {
View view = chatScrollHelper.positionToOldView.get(nextPosition);
if (view != null) {
if (child.getTranslationY() != 0) {
canvas.restore();
}
return result;
}
View view = chatScrollHelper.positionToOldView.get(nextPosition);
if (view != null) {
if (child.getTranslationY() != 0) {
canvas.restore();
}
return result;
}
} else {
ViewHolder holder = chatListView.findViewHolderForAdapterPosition(nextPosition);
if (holder != null) {
@ -7930,7 +7933,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
int maxNegativeUnreadId = Integer.MAX_VALUE;
int maxUnreadDate = Integer.MIN_VALUE;
int lastVisibleId = currentEncryptedChat != null ? Integer.MAX_VALUE : Integer.MIN_VALUE;
int recyclerChatViewHeight = contentView.getHeightWithKeyboard() - (inPreviewMode ? 0 : AndroidUtilities.dp(48)) - chatListView.getTop();
int recyclerChatViewHeight = contentView.getHeightWithKeyboard() - (inPreviewMode ? 0 : AndroidUtilities.dp(48)) - chatListView.getTop();
pollsToCheck.clear();
for (int a = 0; a < count; a++) {
View view = chatListView.getChildAt(a);
@ -8747,6 +8750,8 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
return 10;
} else if (mime.endsWith("/xml")) {
return 5;
} else if (mime.endsWith("/json")) {
return 21;
} else if (!messageObject.isNewGif() && mime.endsWith("/mp4") || mime.endsWith("/png") || mime.endsWith("/jpg") || mime.endsWith("/jpeg")) {
return 6;
}
@ -8812,6 +8817,9 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
if (mime != null && mime.endsWith("text/xml")) {
return 5;
}
if (mime != null && mime.endsWith("/json")) {
return 21;
}
}
if (messageObject.messageOwner.ttl <= 0) {
return 4;
@ -14084,6 +14092,21 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
items.add(LocaleController.getString("ShareFile", R.string.ShareFile));
options.add(6);
icons.add(R.drawable.msg_shareout);
} else if (type == 21) {
items.add(LocaleController.getString("ImportProxyList", R.string.ImportProxyList));
options.add(5);
icons.add(R.drawable.proxy_on);
items.add(LocaleController.getString("SaveToDownloads", R.string.SaveToDownloads));
options.add(10);
icons.add(R.drawable.msg_download);
if (NekoConfig.showDeleteDownloadedFile) {
items.add(LocaleController.getString("DeleteDownloadedFile", R.string.DeleteDownloadedFile));
options.add(91);
icons.add(R.drawable.menu_clearcache);
}
items.add(LocaleController.getString("ShareFile", R.string.ShareFile));
options.add(6);
icons.add(R.drawable.msg_shareout);
} else if (type == 6) {
items.add(LocaleController.getString("SaveToGallery", R.string.SaveToGallery));
options.add(7);
@ -14284,6 +14307,10 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
items.add(LocaleController.getString("ApplyThemeFile", R.string.ApplyThemeFile));
options.add(5);
icons.add(R.drawable.msg_theme);
} else if (type == 21) {
items.add(LocaleController.getString("ImportProxyList", R.string.ImportProxyList));
options.add(5);
icons.add(R.drawable.proxy_on);
} else if (type == 7) {
items.add(LocaleController.getString("AddToStickers", R.string.AddToStickers));
options.add(9);
@ -14897,7 +14924,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
showDialog(builder.create());
}
} else {
} else if (locFile.getName().toLowerCase().endsWith("xml")) {
if (LocaleController.getInstance().applyLanguageFile(locFile, currentAccount)) {
presentFragment(new LanguageSelectActivity());
} else {
@ -14913,6 +14940,19 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
showDialog(builder.create());
}
} else if (locFile.getName().toLowerCase().endsWith("json")) {
File finalLocFile = locFile;
AlertUtil.showComfirm(getParentActivity(),
LocaleController.getString("ImportProxyList", R.string.ImportProxyList),
LocaleController.getString("ImportProxyList", R.string.ImportProxyListConfirm),
LocaleController.getString("OK", R.string.OK), false, (d,v) -> {
String status = ProxyListActivity.processProxyListFile(getParentActivity(), finalLocFile);
if (!StringsKt.isBlank(status)) {
presentFragment(new ProxyListActivity(status));
}
});
}
}
break;
@ -16636,6 +16676,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
}
private Toast currentToast;
@Override
public void didPressImage(ChatMessageCell cell, float x, float y) {
MessageObject message = cell.getMessageObject();
@ -16737,6 +16778,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
}
}
}
@Override
public void didPressInstantButton(ChatMessageCell cell, int type) {
MessageObject messageObject = cell.getMessageObject();

View File

@ -76,6 +76,7 @@ import java.util.List;
import java.util.Map;
import java.util.TreeSet;
import kotlin.text.StringsKt;
import okhttp3.HttpUrl;
import tw.nekomimi.nekogram.ShadowsocksRSettingsActivity;
import tw.nekomimi.nekogram.ShadowsocksSettingsActivity;
@ -234,6 +235,15 @@ public class ProxyListActivity extends BaseFragment implements NotificationCente
}
}
public ProxyListActivity() {
}
private String alert;
public ProxyListActivity(String alert) {
this.alert = alert;
}
@Override
public boolean onFragmentCreate() {
super.onFragmentCreate();
@ -250,6 +260,10 @@ public class ProxyListActivity extends BaseFragment implements NotificationCente
updateRows(true);
if (!StringsKt.isBlank(alert)) {
AlertUtil.showSimpleAlert(getParentActivity(),alert);
}
return true;
}
@ -276,114 +290,130 @@ public class ProxyListActivity extends BaseFragment implements NotificationCente
private int menu_import_json = 13;
private int menu_delete_all = 14;
private void processProxyList(ArrayList<String> files) {
public void processProxyList(ArrayList<String> files) {
for (String proxyListFilePath : files) {
File proxyListFile = new File(proxyListFilePath);
try {
processProxyListFile(getParentActivity(),proxyListFile);
if (proxyListFile.length() > 2 * 1024 * 1024L) {
}
throw new IllegalArgumentException("file too large.");
}
}
public static String processProxyListFile(Context ctx,File proxyListFile) {
JSONObject proxyRootObject = new JSONObject(FileUtil.readUtf8String(proxyListFile));
try {
if (proxyRootObject.isNull("nekox_proxy_list_verion")) {
if (proxyListFile.length() > 2 * 1024 * 1024L) {
throw new IllegalArgumentException("not a nekox proxy list file.");
}
int version = proxyRootObject.getInt("nekox_proxy_list_verion");
if (version == 1) {
if (proxyRootObject.isNull("proxies")) {
throw new IllegalArgumentException("proxies array not found.");
}
JSONArray proxyArray = proxyRootObject.getJSONArray("proxies");
if (proxyArray.length() == 0) {
throw new IllegalArgumentException("Empty proxy list.");
}
for (int index = 0; index < proxyArray.length(); index++) {
String proxyUrl = proxyArray.getString(index);
LinkedList<String> imported = new LinkedList<>();
LinkedHashMap<String, String> errors = new LinkedHashMap<>();
try {
imported.add(ProxyUtil.importInBackground(proxyUrl).getTitle());
} catch (Exception ex) {
errors.put(proxyUrl, ex.getMessage());
}
StringBuilder status = new StringBuilder();
if (!imported.isEmpty()) {
status.append(LocaleController.getString("ImportedProxies", R.string.ImportedProxies));
for (String success : imported) {
status.append("\n").append(success);
}
if (!errors.isEmpty()) {
status.append("\n\n");
}
}
if (!errors.isEmpty()) {
status.append(LocaleController.getString("", R.string.ErrorsInImport));
for (Map.Entry<String, String> error : errors.entrySet()) {
status.append("\n").append(error.getKey()).append(": ").append(error.getValue());
}
}
AlertUtil.showSimpleAlert(getParentActivity(), status.toString());
}
} else {
throw new IllegalArgumentException("invalid proxy list version " + version + ".");
}
} catch (Exception e) {
AlertUtil.showSimpleAlert(getParentActivity(), LocaleController.getString("InvalidProxyFile", R.string.InvalidProxyFile) + proxyListFilePath + "\n\n" + e.getMessage());
throw new IllegalArgumentException("file too large.");
}
JSONObject proxyRootObject = new JSONObject(FileUtil.readUtf8String(proxyListFile));
if (proxyRootObject.isNull("nekox_proxy_list_verion")) {
throw new IllegalArgumentException("not a nekox proxy list file.");
}
int version = proxyRootObject.getInt("nekox_proxy_list_verion");
if (version == 1) {
if (proxyRootObject.isNull("proxies")) {
throw new IllegalArgumentException("proxies array not found.");
}
JSONArray proxyArray = proxyRootObject.getJSONArray("proxies");
if (proxyArray.length() == 0) {
throw new IllegalArgumentException("Empty proxy list.");
}
for (int index = 0; index < proxyArray.length(); index++) {
String proxyUrl = proxyArray.getString(index);
LinkedList<String> imported = new LinkedList<>();
LinkedHashMap<String, String> errors = new LinkedHashMap<>();
try {
imported.add(ProxyUtil.importInBackground(proxyUrl).getTitle());
} catch (Exception ex) {
errors.put(proxyUrl, ex.getMessage());
}
StringBuilder status = new StringBuilder();
if (!imported.isEmpty()) {
status.append(LocaleController.getString("ImportedProxies", R.string.ImportedProxies));
for (String success : imported) {
status.append("\n").append(success);
}
if (!errors.isEmpty()) {
status.append("\n\n");
}
}
if (!errors.isEmpty()) {
status.append(LocaleController.getString("", R.string.ErrorsInImport));
for (Map.Entry<String, String> error : errors.entrySet()) {
status.append("\n").append(error.getKey()).append(": ").append(error.getValue());
}
}
if (imported.isEmpty()) {
AlertUtil.showSimpleAlert(ctx,status.toString());
} else {
return status.toString();
}
}
} else {
throw new IllegalArgumentException("invalid proxy list version " + version + ".");
}
} catch (Exception e) {
AlertUtil.showSimpleAlert(ctx, LocaleController.getString("InvalidProxyFile", R.string.InvalidProxyFile) + proxyListFile.getPath() + "\n\n" + e.getMessage());
}
return null;
}
@Override
@ -406,10 +436,7 @@ public class ProxyListActivity extends BaseFragment implements NotificationCente
SharedConfig.saveProxyList();
updateRows(true);
} else if (id == menu_export_json) {
if (SharedConfig.proxyList.isEmpty()) {
AlertUtil.showSimpleAlert(getParentActivity(), LocaleController.getString("NoProxy", R.string.NoProxy));
return;
}
File cacheFile = new File(ApplicationLoader.applicationContext.getExternalCacheDir(), "NekoX-Proxy-List-" + new Date().toLocaleString() + ".json");
try {
@ -428,6 +455,11 @@ public class ProxyListActivity extends BaseFragment implements NotificationCente
}
if (proxyArray.length() == 0) {
AlertUtil.showSimpleAlert(getParentActivity(), LocaleController.getString("NoProxy", R.string.NoProxy));
return;
}
listRoot.put("proxies", proxyArray);
FileUtil.writeUtf8String(listRoot.toString(4), cacheFile);

View File

@ -32,7 +32,7 @@ object AlertUtil {
builder.setTitle(LocaleController.getString("NekoX", R.string.NekoX))
builder.setMessage(text)
builder.setPositiveButton(LocaleController.getString("Ok", R.string.OK), null);
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
builder.show()

View File

@ -102,7 +102,8 @@
<string name="ReorderByPing">Reorder servers by ping</string>
<string name="ExportProxies">Export servers to file</string>
<string name="ImportProxies">Import servers from file</string>
<string name="SendProxyListTo">Do you want to send proxy list to **%1$s**?</string>
<string name="ImportProxyList">Import proxy servers</string>
<string name="ImportProxyListConfirm">Are you sure you want to **import proxy servers**?</string>
<string name="InvalidProxyFile">Invalid proxy list file: </string>
<string name="ImportedProxies">Imported proxy servers: </string>