From 026839041c783e8e770d0e1e1a647eda524a1a47 Mon Sep 17 00:00:00 2001
From: NekoInverter <7741672-NekoInverter@users.noreply.gitlab.com>
Date: Fri, 18 Dec 2020 22:06:06 +0800
Subject: [PATCH] Download tag translations from github directly
---
.../com/hippo/ehviewer/client/EhTagDatabase.java | 14 ++++++++------
app/src/main/res/values-zh-rCN/arrays.xml | 4 ++--
app/src/main/res/values-zh-rHK/arrays.xml | 4 ++--
app/src/main/res/values-zh-rTW/arrays.xml | 4 ++--
4 files changed, 14 insertions(+), 12 deletions(-)
diff --git a/app/src/main/java/com/hippo/ehviewer/client/EhTagDatabase.java b/app/src/main/java/com/hippo/ehviewer/client/EhTagDatabase.java
index c8f58c5c5..563b123de 100644
--- a/app/src/main/java/com/hippo/ehviewer/client/EhTagDatabase.java
+++ b/app/src/main/java/com/hippo/ehviewer/client/EhTagDatabase.java
@@ -23,6 +23,7 @@ import androidx.annotation.Nullable;
import androidx.core.util.Pair;
import com.hippo.ehviewer.AppConfig;
+import com.hippo.ehviewer.EhApplication;
import com.hippo.ehviewer.R;
import com.hippo.util.ExceptionUtils;
import com.hippo.util.IoThreadPoolExecutor;
@@ -58,7 +59,6 @@ public class EhTagDatabase {
private static volatile EhTagDatabase instance;
// TODO more lock for different language
private static final Lock lock = new ReentrantLock();
- private static final OkHttpClient client = new OkHttpClient.Builder().build();
static {
NAMESPACE_TO_PREFIX.put("artist", "a:");
@@ -188,7 +188,7 @@ public class EhTagDatabase {
return equals(s1, s2);
}
- private static boolean save(String url, File file) {
+ private static boolean save(OkHttpClient client, String url, File file) {
Request request = new Request.Builder().url(url).build();
Call call = client.newCall(request);
try (Response response = call.execute()) {
@@ -221,9 +221,9 @@ public class EhTagDatabase {
}
String sha1Name = urls[0];
- String sha1Url = urls[1] + "?_t=" + System.currentTimeMillis();
+ String sha1Url = urls[1];
String dataName = urls[2];
- String dataUrl = urls[3] + "?_t=" + System.currentTimeMillis();
+ String dataUrl = urls[3];
// Clear tags if name if different
EhTagDatabase tmp = instance;
@@ -260,9 +260,11 @@ public class EhTagDatabase {
}
}
+ OkHttpClient client = EhApplication.getOkHttpClient(context);
+
// Save new sha1
File tempSha1File = new File(dir, sha1Name + ".tmp");
- if (!save(sha1Url, tempSha1File)) {
+ if (!save(client, sha1Url, tempSha1File)) {
FileUtils.delete(tempSha1File);
return;
}
@@ -276,7 +278,7 @@ public class EhTagDatabase {
// Save new data
File tempDataFile = new File(dir, dataName + ".tmp");
- if (!save(dataUrl, tempDataFile)) {
+ if (!save(client, dataUrl, tempDataFile)) {
FileUtils.delete(tempDataFile);
return;
}
diff --git a/app/src/main/res/values-zh-rCN/arrays.xml b/app/src/main/res/values-zh-rCN/arrays.xml
index 8013e63e9..621124fc6 100644
--- a/app/src/main/res/values-zh-rCN/arrays.xml
+++ b/app/src/main/res/values-zh-rCN/arrays.xml
@@ -18,9 +18,9 @@
- tag-translations-zh-rCN.sha1
- - https://cdn.jsdelivr.net/gh/Mapaler/EhViewer@tag-translations/tag-translations/tag-translations-zh-rCN.sha1
+ - https://raw.githubusercontent.com/Mapaler/EhViewer/tag-translations/tag-translations/tag-translations-zh-rCN.sha1
- tag-translations-zh-rCN
- - https://cdn.jsdelivr.net/gh/Mapaler/EhViewer@tag-translations/tag-translations/tag-translations-zh-rCN
+ - https://raw.githubusercontent.com/Mapaler/EhViewer/tag-translations/tag-translations/tag-translations-zh-rCN
diff --git a/app/src/main/res/values-zh-rHK/arrays.xml b/app/src/main/res/values-zh-rHK/arrays.xml
index 8013e63e9..621124fc6 100644
--- a/app/src/main/res/values-zh-rHK/arrays.xml
+++ b/app/src/main/res/values-zh-rHK/arrays.xml
@@ -18,9 +18,9 @@
- tag-translations-zh-rCN.sha1
- - https://cdn.jsdelivr.net/gh/Mapaler/EhViewer@tag-translations/tag-translations/tag-translations-zh-rCN.sha1
+ - https://raw.githubusercontent.com/Mapaler/EhViewer/tag-translations/tag-translations/tag-translations-zh-rCN.sha1
- tag-translations-zh-rCN
- - https://cdn.jsdelivr.net/gh/Mapaler/EhViewer@tag-translations/tag-translations/tag-translations-zh-rCN
+ - https://raw.githubusercontent.com/Mapaler/EhViewer/tag-translations/tag-translations/tag-translations-zh-rCN
diff --git a/app/src/main/res/values-zh-rTW/arrays.xml b/app/src/main/res/values-zh-rTW/arrays.xml
index 8013e63e9..621124fc6 100644
--- a/app/src/main/res/values-zh-rTW/arrays.xml
+++ b/app/src/main/res/values-zh-rTW/arrays.xml
@@ -18,9 +18,9 @@
- tag-translations-zh-rCN.sha1
- - https://cdn.jsdelivr.net/gh/Mapaler/EhViewer@tag-translations/tag-translations/tag-translations-zh-rCN.sha1
+ - https://raw.githubusercontent.com/Mapaler/EhViewer/tag-translations/tag-translations/tag-translations-zh-rCN.sha1
- tag-translations-zh-rCN
- - https://cdn.jsdelivr.net/gh/Mapaler/EhViewer@tag-translations/tag-translations/tag-translations-zh-rCN
+ - https://raw.githubusercontent.com/Mapaler/EhViewer/tag-translations/tag-translations/tag-translations-zh-rCN