mirror of
https://github.com/seven332/EhViewer
synced 2026-12-01 11:38:03 +08:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bc2b21b0f5 | ||
|
|
ec132440e7 | ||
|
|
9d49973504 | ||
|
|
016ec23fbd | ||
|
|
59d141fc8e | ||
|
|
3d3c3a9273 | ||
|
|
c580938806 | ||
|
|
3904406d74 | ||
|
|
879b8fa50a | ||
|
|
7228736c95 | ||
|
|
e8eb126135 | ||
|
|
0eb86e37e6 | ||
|
|
eff2ed94fe | ||
|
|
fb2011a408 | ||
|
|
a442578927 | ||
|
|
673735ab2e | ||
|
|
f1bab7e3d4 | ||
|
|
1d5b26ee51 | ||
|
|
a1a82b0ce9 | ||
|
|
5b961d71b8 | ||
|
|
0353c1cebb | ||
|
|
7b07bdc51f | ||
|
|
cf1ac32e17 | ||
|
|
bb28dd97cc | ||
|
|
a33bd63e6e | ||
|
|
a0b786b2a6 | ||
|
|
9dd39412d4 | ||
|
|
3fdf9453ef |
No files matched your search
@@ -57,7 +57,7 @@ Here is the libraries
|
||||
|
||||
# License
|
||||
|
||||
Copyright (C) 2014-2016 Hippo Seven
|
||||
Copyright (C) 2014-2019 Hippo Seven
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
||||
+6
-7
@@ -10,8 +10,8 @@ android {
|
||||
applicationId "com.hippo.ehviewer"
|
||||
minSdkVersion 14
|
||||
targetSdkVersion 28
|
||||
versionCode 91
|
||||
versionName "1.3.4"
|
||||
versionCode 93
|
||||
versionName "1.4.0"
|
||||
vectorDrawables.useSupportLibrary = true
|
||||
resConfigs "zh", "zh-rCN", "zh-rHK", "zh-rTW",
|
||||
"es", "ja", "ko", "fr", "de"
|
||||
@@ -71,14 +71,14 @@ dependencies {
|
||||
implementation "com.android.support:design:$supportLibrary"
|
||||
implementation 'com.google.firebase:firebase-core:16.0.6'
|
||||
implementation 'com.crashlytics.sdk.android:crashlytics:2.9.8'
|
||||
implementation 'com.github.seven332:a7zip:4a484317b0'
|
||||
implementation 'com.github.amlcurran.showcaseview:library:5.4.3'
|
||||
implementation 'com.github.seven332.a7zip:extract-lite:d4ddec5793'
|
||||
implementation 'com.github.seven332:android-recaptcha:2bbb3459a8'
|
||||
implementation 'com.github.seven332:android-resource:0.1.0'
|
||||
implementation 'com.github.seven332:animator:0.1.0'
|
||||
implementation 'com.github.seven332:beerbelly:0.1.4'
|
||||
implementation 'com.github.seven332:conaco:0.1.5-eh'
|
||||
implementation 'com.github.seven332:drawerlayout:0.2.1'
|
||||
implementation 'com.github.seven332:drawerlayout:ea2bb388f0'
|
||||
implementation 'com.github.seven332:easyrecyclerview:0.1.1'
|
||||
implementation 'com.github.seven332:glgallery:0.1.2'
|
||||
implementation 'com.github.seven332:glview:0.1.0'
|
||||
@@ -95,7 +95,7 @@ dependencies {
|
||||
implementation 'com.github.seven332:yorozuya-thread:0.1.1'
|
||||
implementation 'com.github.seven332:yorozuya-collect:0.1.4'
|
||||
implementation 'com.h6ah4i.android.widget.advrecyclerview:advrecyclerview:0.11.0'
|
||||
implementation 'com.squareup.okhttp3:okhttp:3.12.0'
|
||||
implementation 'com.squareup.okhttp3:okhttp:3.12.1'
|
||||
implementation 'org.ccil.cowan.tagsoup:tagsoup:1.2.1'
|
||||
implementation 'org.greenrobot:greendao:2.2.1'
|
||||
implementation 'org.jsoup:jsoup:1.11.3'
|
||||
@@ -107,11 +107,10 @@ dependencies {
|
||||
configurations.all {
|
||||
resolutionStrategy {
|
||||
force 'com.github.seven332:glgallery:bb2a43fdd5'
|
||||
force 'com.github.seven332:glview:cc3f18d1b2'
|
||||
force 'com.github.seven332:glview:0b2bbb8032'
|
||||
force 'com.github.seven332:glview-image:69930e924e'
|
||||
force 'com.github.seven332:image:09b43c0c68'
|
||||
|
||||
exclude group: 'com.github.seven332', module: 'okhttp'
|
||||
exclude group: 'com.squareup.okio', module: 'okio'
|
||||
}
|
||||
}
|
||||
@@ -39,6 +39,8 @@
|
||||
android:largeHeap="true"
|
||||
android:networkSecurityConfig="@xml/network_security_config">
|
||||
|
||||
<meta-data android:name="android.max_aspect" android:value="2.1"/>
|
||||
|
||||
<activity
|
||||
android:name="com.hippo.ehviewer.ui.MainActivity"
|
||||
android:configChanges="screenSize|uiMode"
|
||||
|
||||
@@ -156,4 +156,19 @@ public class AppConfig {
|
||||
IOUtils.closeQuietly(os);
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static File getFilesDir(String name) {
|
||||
File dir = sContext.getFilesDir();
|
||||
if (dir == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
dir = new File(dir, name);
|
||||
if (dir.isDirectory() || dir.mkdirs()) {
|
||||
return dir;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -31,7 +31,9 @@ import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.util.LruCache;
|
||||
import android.util.Log;
|
||||
import com.getkeepsafe.relinker.ReLinker;
|
||||
import com.hippo.a7zip.A7Zip;
|
||||
import com.hippo.a7zip.A7ZipExtractLite;
|
||||
import com.hippo.beerbelly.SimpleDiskCache;
|
||||
import com.hippo.conaco.Conaco;
|
||||
import com.hippo.content.RecordingApplication;
|
||||
@@ -50,6 +52,7 @@ import com.hippo.text.Html;
|
||||
import com.hippo.unifile.UniFile;
|
||||
import com.hippo.util.BitmapUtils;
|
||||
import com.hippo.util.ExceptionUtils;
|
||||
import com.hippo.util.IoThreadPoolExecutor;
|
||||
import com.hippo.util.ReadableTime;
|
||||
import com.hippo.yorozuya.FileUtils;
|
||||
import com.hippo.yorozuya.IntIdGenerator;
|
||||
@@ -75,6 +78,8 @@ public class EhApplication extends RecordingApplication {
|
||||
private static final boolean DEBUG_PRINT_IMAGE_COUNT = false;
|
||||
private static final long DEBUG_PRINT_INTERVAL = 3000L;
|
||||
|
||||
private static EhApplication instance;
|
||||
|
||||
private final IntIdGenerator mIdGenerator = new IntIdGenerator();
|
||||
private final HashMap<Integer, Object> mGlobalStuffMap = new HashMap<>();
|
||||
private EhCookieStore mEhCookieStore;
|
||||
@@ -89,9 +94,15 @@ public class EhApplication extends RecordingApplication {
|
||||
|
||||
private final List<Activity> mActivityList = new ArrayList<>();
|
||||
|
||||
public static EhApplication getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
@SuppressLint("StaticFieldLeak")
|
||||
@Override
|
||||
public void onCreate() {
|
||||
instance = this;
|
||||
|
||||
super.onCreate();
|
||||
|
||||
GetText.initialize(this);
|
||||
@@ -105,7 +116,7 @@ public class EhApplication extends RecordingApplication {
|
||||
EhEngine.initialize();
|
||||
BitmapUtils.initialize(this);
|
||||
Image.initialize(this);
|
||||
A7Zip.initialize(this);
|
||||
A7Zip.loadLibrary(A7ZipExtractLite.LIBRARY, libname -> ReLinker.loadLibrary(EhApplication.this, libname));
|
||||
|
||||
if (EhDB.needMerge()) {
|
||||
EhDB.mergeOldDB(this);
|
||||
@@ -140,7 +151,7 @@ public class EhApplication extends RecordingApplication {
|
||||
|
||||
return null;
|
||||
}
|
||||
}.doInBackground();
|
||||
}.executeOnExecutor(IoThreadPoolExecutor.getInstance());
|
||||
|
||||
// Check app update
|
||||
update();
|
||||
@@ -382,4 +393,14 @@ public class EhApplication extends RecordingApplication {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Avoid crash on some "energy saving" devices
|
||||
@Override
|
||||
public void unbindService(ServiceConnection conn) {
|
||||
try {
|
||||
super.unbindService(conn);
|
||||
} catch (Throwable t) {
|
||||
ExceptionUtils.throwIfFatal(t);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -340,6 +340,13 @@ public class Settings {
|
||||
return getBoolean(KEY_SHOW_GALLERY_PAGES, DEFAULT_SHOW_GALLERY_PAGES);
|
||||
}
|
||||
|
||||
public static final String KEY_SHOW_TAG_TRANSLATIONS = "show_tag_translations";
|
||||
private static final boolean DEFAULT_SHOW_TAG_TRANSLATIONS = false;
|
||||
|
||||
public static boolean getShowTagTranslations() {
|
||||
return getBoolean(KEY_SHOW_TAG_TRANSLATIONS, DEFAULT_SHOW_TAG_TRANSLATIONS);
|
||||
}
|
||||
|
||||
public static final String KEY_DEFAULT_CATEGORIES = "default_categories";
|
||||
public static final int DEFAULT_DEFAULT_CATEGORIES = EhUtils.ALL_CATEGORY;
|
||||
|
||||
|
||||
@@ -22,15 +22,11 @@ import com.hippo.ehviewer.EhApplication;
|
||||
import com.hippo.ehviewer.client.data.GalleryInfo;
|
||||
import com.hippo.ehviewer.client.exception.CancelledException;
|
||||
import com.hippo.util.ExceptionUtils;
|
||||
import com.hippo.util.IoThreadPoolExecutor;
|
||||
import com.hippo.yorozuya.SimpleHandler;
|
||||
import com.hippo.yorozuya.thread.PriorityThreadFactory;
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.ThreadFactory;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import okhttp3.Call;
|
||||
@@ -64,12 +60,7 @@ public class EhClient {
|
||||
private final OkHttpClient mOkHttpClient;
|
||||
|
||||
public EhClient(Context context) {
|
||||
int poolSize = 3;
|
||||
BlockingQueue<Runnable> requestWorkQueue = new LinkedBlockingQueue<>();
|
||||
ThreadFactory threadFactory = new PriorityThreadFactory(TAG,
|
||||
android.os.Process.THREAD_PRIORITY_BACKGROUND);
|
||||
mRequestThreadPool = new ThreadPoolExecutor(poolSize, poolSize,
|
||||
1L, TimeUnit.SECONDS, requestWorkQueue, threadFactory);
|
||||
mRequestThreadPool = IoThreadPoolExecutor.getInstance();
|
||||
mOkHttpClient = EhApplication.getOkHttpClient(context);
|
||||
}
|
||||
|
||||
|
||||
@@ -209,7 +209,22 @@ public class EhEngine {
|
||||
}
|
||||
}
|
||||
|
||||
if (list.size() > 0 && (TextUtils.isEmpty(list.get(0).uploader) || Settings.getShowJpnTitle() || Settings.getShowGalleryPages() || sEhFilter.needCallApi())) {
|
||||
boolean anyRated = false;
|
||||
for (GalleryInfo info : list) {
|
||||
if (info.rated) {
|
||||
anyRated = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
boolean needFillByApi = list.size() > 0
|
||||
&& (TextUtils.isEmpty(list.get(0).uploader)
|
||||
|| anyRated
|
||||
|| Settings.getShowJpnTitle()
|
||||
|| Settings.getShowGalleryPages()
|
||||
|| sEhFilter.needCallApi());
|
||||
|
||||
if (needFillByApi) {
|
||||
// Fill by api
|
||||
fillGalleryListByApi(task, okHttpClient, list);
|
||||
|
||||
|
||||
@@ -0,0 +1,355 @@
|
||||
/*
|
||||
* Copyright 2019 Hippo Seven
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.hippo.ehviewer.client;
|
||||
|
||||
import android.support.annotation.Nullable;
|
||||
import android.util.Base64;
|
||||
import com.hippo.ehviewer.AppConfig;
|
||||
import com.hippo.ehviewer.EhApplication;
|
||||
import com.hippo.util.IoThreadPoolExecutor;
|
||||
import com.hippo.util.TextUrl;
|
||||
import com.hippo.yorozuya.FileUtils;
|
||||
import com.hippo.yorozuya.IOUtils;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
import okhttp3.Call;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
import okhttp3.ResponseBody;
|
||||
import okio.BufferedSource;
|
||||
import okio.Okio;
|
||||
|
||||
public class EhTagDatabase {
|
||||
|
||||
private final String name;
|
||||
private final byte[] tags;
|
||||
|
||||
public EhTagDatabase(String name, BufferedSource source) throws IOException {
|
||||
this.name = name;
|
||||
int totalBytes = source.readInt();
|
||||
tags = new byte[totalBytes];
|
||||
source.readFully(tags);
|
||||
}
|
||||
|
||||
public String getTranslation(String tag) {
|
||||
return search(tags, tag.getBytes(TextUrl.UTF_8));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private String search(byte[] tags, byte[] tag) {
|
||||
int low = 0;
|
||||
int high = tags.length;
|
||||
while (low < high) {
|
||||
int start = (low + high) / 2;
|
||||
// Look for the starting '\n'
|
||||
while (start > -1 && tags[start] != '\n') {
|
||||
start--;
|
||||
}
|
||||
start++;
|
||||
|
||||
// Look for the middle '\r'.
|
||||
int middle = 1;
|
||||
while (tags[start + middle] != '\r') {
|
||||
middle++;
|
||||
}
|
||||
|
||||
// Look for the ending '\n'
|
||||
int end = middle + 1;
|
||||
while (tags[start + end] != '\n') {
|
||||
end++;
|
||||
}
|
||||
|
||||
int compare;
|
||||
int tagIndex = 0;
|
||||
int curIndex = start;
|
||||
|
||||
for (;;) {
|
||||
int tagByte = tag[tagIndex] & 0xff;
|
||||
int curByte = tags[curIndex] & 0xff;
|
||||
compare = tagByte - curByte;
|
||||
if (compare != 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
tagIndex++;
|
||||
curIndex++;
|
||||
if (tagIndex == tag.length && curIndex == start + middle) {
|
||||
break;
|
||||
}
|
||||
if (tagIndex == tag.length) {
|
||||
compare = -1;
|
||||
break;
|
||||
}
|
||||
if (curIndex == start + middle) {
|
||||
compare = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (compare < 0) {
|
||||
high = start - 1;
|
||||
} else if (compare > 0) {
|
||||
low = start + end + 1;
|
||||
} else {
|
||||
byte[] bytes = Base64.decode(tags, start + middle + 1, end - middle - 1, Base64.DEFAULT);
|
||||
return new String(bytes, TextUrl.UTF_8);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
private static final String[] METADATA_ZH_CN = new String[] {
|
||||
"tag-translations-zh-rCN.sha1",
|
||||
"https://github.com/seven332/EhViewer/raw/tag-translations/tag-translations/tag-translations-zh-rCN.sha1",
|
||||
"tag-translations-zh-rCN",
|
||||
"https://github.com/seven332/EhViewer/raw/tag-translations/tag-translations/tag-translations-zh-rCN",
|
||||
};
|
||||
|
||||
private static final Map<String, String> NAMESPACE_TO_PREFIX = new HashMap<>();
|
||||
|
||||
static {
|
||||
NAMESPACE_TO_PREFIX.put("artist", "a:");
|
||||
NAMESPACE_TO_PREFIX.put("character", "c:");
|
||||
NAMESPACE_TO_PREFIX.put("female", "f:");
|
||||
NAMESPACE_TO_PREFIX.put("group", "g:");
|
||||
NAMESPACE_TO_PREFIX.put("language", "l:");
|
||||
NAMESPACE_TO_PREFIX.put("male", "m:");
|
||||
NAMESPACE_TO_PREFIX.put("misc", "");
|
||||
NAMESPACE_TO_PREFIX.put("parody", "p:");
|
||||
NAMESPACE_TO_PREFIX.put("reclass", "r:");
|
||||
}
|
||||
|
||||
private static volatile EhTagDatabase instance;
|
||||
// TODO more lock for different language
|
||||
private static Lock lock = new ReentrantLock();
|
||||
|
||||
@Nullable
|
||||
public static EhTagDatabase getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static String namespaceToPrefix(String namespace) {
|
||||
return NAMESPACE_TO_PREFIX.get(namespace);
|
||||
}
|
||||
|
||||
private static String[] getMetadata() {
|
||||
Locale locale = Locale.getDefault();
|
||||
if ("zh".equals(locale.getLanguage()) && "CN".equals(locale.getCountry())) {
|
||||
return METADATA_ZH_CN;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean isPossible() {
|
||||
return getMetadata() != null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static byte[] getFileContent(File file, int length) {
|
||||
try (BufferedSource source = Okio.buffer(Okio.source(file))) {
|
||||
byte[] content = new byte[length];
|
||||
source.readFully(content);
|
||||
return content;
|
||||
} catch (IOException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static byte[] getFileSha1(File file) {
|
||||
try (InputStream is = new FileInputStream(file)) {
|
||||
MessageDigest digest = MessageDigest.getInstance("SHA-1");
|
||||
int n;
|
||||
byte[] buffer = new byte[4 * 1024];
|
||||
while ((n = is.read(buffer)) != -1) {
|
||||
digest.update(buffer, 0, n);
|
||||
}
|
||||
return digest.digest();
|
||||
} catch (IOException e) {
|
||||
return null;
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean equals(byte[] b1, byte[] b2) {
|
||||
if (b1 == null && b2 == null) {
|
||||
return true;
|
||||
}
|
||||
if (b1 == null || b2 == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (b1.length != b2.length) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int i = 0; i < b1.length; i++) {
|
||||
if (b1[i] != b2[i]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static boolean checkData(File sha1File, File dataFile) {
|
||||
byte[] s1 = getFileContent(sha1File, 20);
|
||||
if (s1 == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
byte[] s2 = getFileSha1(dataFile);
|
||||
if (s2 == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return equals(s1, s2);
|
||||
}
|
||||
|
||||
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()) {
|
||||
if (!response.isSuccessful()) {
|
||||
return false;
|
||||
}
|
||||
ResponseBody body = response.body();
|
||||
if (body == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try (InputStream is = body.byteStream(); OutputStream os = new FileOutputStream(file)) {
|
||||
IOUtils.copy(is, os);
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static void update() {
|
||||
String[] urls = getMetadata();
|
||||
if (urls == null || urls.length != 4) {
|
||||
// Clear tags if it's not possible
|
||||
instance = null;
|
||||
return;
|
||||
}
|
||||
|
||||
String sha1Name = urls[0];
|
||||
String sha1Url = urls[1];
|
||||
String dataName = urls[2];
|
||||
String dataUrl = urls[3];
|
||||
|
||||
// Clear tags if name if different
|
||||
EhTagDatabase tmp = instance;
|
||||
if (tmp != null && !tmp.name.equals(dataName)) {
|
||||
instance = null;
|
||||
}
|
||||
|
||||
IoThreadPoolExecutor.getInstance().execute(() -> {
|
||||
if (!lock.tryLock()) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
File dir = AppConfig.getFilesDir("tag-translations");
|
||||
if (dir == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Check current sha1 and current data
|
||||
File sha1File = new File(dir, sha1Name);
|
||||
File dataFile = new File(dir, dataName);
|
||||
if (!checkData(sha1File, dataFile)) {
|
||||
FileUtils.delete(sha1File);
|
||||
FileUtils.delete(dataFile);
|
||||
}
|
||||
|
||||
// Read current EhTagDatabase
|
||||
if (instance == null && dataFile.exists()) {
|
||||
try (BufferedSource source = Okio.buffer(Okio.source(dataFile))) {
|
||||
instance = new EhTagDatabase(dataName, source);
|
||||
} catch (IOException e) {
|
||||
FileUtils.delete(sha1File);
|
||||
FileUtils.delete(dataFile);
|
||||
}
|
||||
}
|
||||
|
||||
OkHttpClient client = EhApplication.getOkHttpClient(EhApplication.getInstance());
|
||||
|
||||
// Save new sha1
|
||||
File tempSha1File = new File(dir, sha1Name + ".tmp");
|
||||
if (!save(client, sha1Url, tempSha1File)) {
|
||||
FileUtils.delete(tempSha1File);
|
||||
return;
|
||||
}
|
||||
|
||||
// Check new sha1 and current data
|
||||
if (checkData(tempSha1File, dataFile)) {
|
||||
// The data is the same
|
||||
FileUtils.delete(tempSha1File);
|
||||
return;
|
||||
}
|
||||
|
||||
// Save new data
|
||||
File tempDataFile = new File(dir, dataName + ".tmp");
|
||||
if (!save(client, dataUrl, tempDataFile)) {
|
||||
FileUtils.delete(tempDataFile);
|
||||
return;
|
||||
}
|
||||
|
||||
// Check new sha1 and new data
|
||||
if (!checkData(tempSha1File, tempDataFile)) {
|
||||
FileUtils.delete(tempSha1File);
|
||||
FileUtils.delete(tempDataFile);
|
||||
return;
|
||||
}
|
||||
|
||||
// Replace current sha1 and current data with new sha1 and new data
|
||||
FileUtils.delete(sha1File);
|
||||
FileUtils.delete(dataFile);
|
||||
tempSha1File.renameTo(sha1File);
|
||||
tempDataFile.renameTo(dataFile);
|
||||
|
||||
// Read new EhTagDatabase
|
||||
try (BufferedSource source = Okio.buffer(Okio.source(dataFile))) {
|
||||
instance = new EhTagDatabase(dataName, source);
|
||||
} catch (IOException e) {
|
||||
// Ignore
|
||||
}
|
||||
} finally {
|
||||
lock.unlock();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -121,6 +121,8 @@ public class GalleryInfo implements Parcelable {
|
||||
*/
|
||||
public String simpleLanguage;
|
||||
|
||||
public boolean rated;
|
||||
|
||||
public final void generateSLang() {
|
||||
if (simpleTags != null) {
|
||||
generateSLangFromTags();
|
||||
|
||||
@@ -308,7 +308,7 @@ public class ListUrlBuilder implements Cloneable, Parcelable {
|
||||
} else if ("f_search".equals(key)) {
|
||||
try {
|
||||
keyword = URLDecoder.decode(value, "utf-8");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
} catch (UnsupportedEncodingException | IllegalArgumentException e) {
|
||||
// Ignore
|
||||
}
|
||||
} else if ("advsearch".equals(key)) {
|
||||
|
||||
@@ -56,7 +56,7 @@ public class FavoritesParser {
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
Element fp = fps.get(i);
|
||||
countArray[i] = ParserUtils.parseInt(fp.child(0).text());
|
||||
countArray[i] = ParserUtils.parseInt(fp.child(0).text(), 0);
|
||||
catArray[i] = ParserUtils.trim(fp.child(2).text());
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
|
||||
@@ -19,6 +19,7 @@ package com.hippo.ehviewer.client.parser;
|
||||
import com.hippo.ehviewer.client.EhUtils;
|
||||
import com.hippo.ehviewer.client.data.GalleryInfo;
|
||||
|
||||
import com.hippo.yorozuya.NumberUtils;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
@@ -43,8 +44,8 @@ public class GalleryApiParser {
|
||||
gi.category = EhUtils.getCategory(g.getString("category"));
|
||||
gi.thumb = EhUtils.handleThumbUrlResolution(g.getString("thumb"));
|
||||
gi.uploader = g.getString("uploader");
|
||||
gi.posted = ParserUtils.formatDate(ParserUtils.parseLong(g.getString("posted")) * 1000);
|
||||
gi.rating = Float.parseFloat(g.getString("rating"));
|
||||
gi.posted = ParserUtils.formatDate(ParserUtils.parseLong(g.getString("posted"), 0) * 1000);
|
||||
gi.rating = NumberUtils.parseFloatSafely(g.getString("rating"), 0.0f);
|
||||
// tags
|
||||
JSONArray tagJa = g.getJSONArray("tags");
|
||||
int tagLength = tagJa.length();
|
||||
@@ -53,7 +54,7 @@ public class GalleryApiParser {
|
||||
tags[j] = tagJa.getString(j);
|
||||
}
|
||||
gi.simpleTags = tags;
|
||||
gi.pages = Integer.parseInt(g.getString("filecount"));
|
||||
gi.pages = NumberUtils.parseIntSafely(g.getString("filecount"), 0);
|
||||
gi.generateSLang();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -109,13 +109,16 @@ public class GalleryDetailParser {
|
||||
private static void parseDetail(GalleryDetail gd, Document d, String body) throws ParseException {
|
||||
Matcher matcher = PATTERN_DETAIL.matcher(body);
|
||||
if (matcher.find()) {
|
||||
gd.gid = Long.parseLong(matcher.group(1));
|
||||
gd.gid = NumberUtils.parseLongSafely(matcher.group(1), -1L);
|
||||
gd.token = matcher.group(2);
|
||||
gd.apiUid = NumberUtils.parseLongSafely(matcher.group(3), -1L);
|
||||
gd.apiKey = matcher.group(4);
|
||||
} else {
|
||||
throw new ParseException("Can't parse gallery detail", body);
|
||||
}
|
||||
if (gd.gid == -1L) {
|
||||
throw new ParseException("Can't parse gallery detail", body);
|
||||
}
|
||||
|
||||
matcher = PATTERN_TORRENT.matcher(body);
|
||||
if (matcher.find()) {
|
||||
@@ -494,7 +497,7 @@ public class GalleryDetailParser {
|
||||
Matcher m = PATTERN_PREVIEW_PAGES.matcher(body);
|
||||
int previewPages = -1;
|
||||
if (m.find()) {
|
||||
previewPages = ParserUtils.parseInt(m.group(1));
|
||||
previewPages = ParserUtils.parseInt(m.group(1), -1);
|
||||
}
|
||||
|
||||
if (previewPages <= 0) {
|
||||
@@ -508,12 +511,18 @@ public class GalleryDetailParser {
|
||||
* Parse pages with regular expressions
|
||||
*/
|
||||
public static int parsePages(String body) throws ParseException {
|
||||
int pages = -1;
|
||||
|
||||
Matcher m = PATTERN_PAGES.matcher(body);
|
||||
if (m.find()) {
|
||||
return ParserUtils.parseInt(m.group(1));
|
||||
} else {
|
||||
pages = ParserUtils.parseInt(m.group(1), -1);
|
||||
}
|
||||
|
||||
if (pages < 0) {
|
||||
throw new ParseException("Parse pages error", body);
|
||||
}
|
||||
|
||||
return pages;
|
||||
}
|
||||
|
||||
public static PreviewSet parsePreviewSet(Document d, String body) throws ParseException {
|
||||
@@ -571,7 +580,10 @@ public class GalleryDetailParser {
|
||||
LargePreviewSet largePreviewSet = new LargePreviewSet();
|
||||
|
||||
while (m.find()) {
|
||||
int index = ParserUtils.parseInt(m.group(2)) - 1;
|
||||
int index = ParserUtils.parseInt(m.group(2), 0) - 1;
|
||||
if (index < 0) {
|
||||
continue;
|
||||
}
|
||||
String imageUrl = ParserUtils.trim(m.group(3));
|
||||
String pageUrl = ParserUtils.trim(m.group(1));
|
||||
if (Settings.getFixThumbUrl()) {
|
||||
@@ -594,10 +606,23 @@ public class GalleryDetailParser {
|
||||
Matcher m = PATTERN_NORMAL_PREVIEW.matcher(body);
|
||||
NormalPreviewSet normalPreviewSet = new NormalPreviewSet();
|
||||
while (m.find()) {
|
||||
normalPreviewSet.addItem(ParserUtils.parseInt(m.group(6)) - 1,
|
||||
ParserUtils.trim(m.group(3)), ParserUtils.parseInt((m.group(4))), 0,
|
||||
ParserUtils.parseInt(m.group(1)), ParserUtils.parseInt(m.group(2)),
|
||||
ParserUtils.trim(m.group(5)));
|
||||
int position = ParserUtils.parseInt(m.group(6), 0) - 1;
|
||||
if (position < 0) {
|
||||
continue;
|
||||
}
|
||||
String imageUrl = ParserUtils.trim(m.group(3));
|
||||
int xOffset = ParserUtils.parseInt(m.group(4), 0);
|
||||
int yOffset = 0;
|
||||
int width = ParserUtils.parseInt(m.group(1), 0);
|
||||
if (width <= 0) {
|
||||
continue;
|
||||
}
|
||||
int height = ParserUtils.parseInt(m.group(2), 0);
|
||||
if (height <= 0) {
|
||||
continue;
|
||||
}
|
||||
String pageUrl = ParserUtils.trim(m.group(5));
|
||||
normalPreviewSet.addItem(position, imageUrl, xOffset, yOffset, width, height, pageUrl);
|
||||
}
|
||||
|
||||
if (normalPreviewSet.size() == 0) {
|
||||
|
||||
@@ -20,6 +20,7 @@ import android.support.annotation.Nullable;
|
||||
|
||||
import com.hippo.ehviewer.client.EhUrl;
|
||||
|
||||
import com.hippo.yorozuya.NumberUtils;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@@ -33,7 +34,7 @@ public final class GalleryDetailUrlParser {
|
||||
"https?://(?:" + EhUrl.DOMAIN_EX + "|" + EhUrl.DOMAIN_E + "|" + EhUrl.DOMAIN_LOFI + ")/(?:g|mpv)/(\\d+)/([0-9a-f]{10})");
|
||||
|
||||
private static final Pattern URL_PATTERN = Pattern.compile(
|
||||
"(\\d+)/([0-9a-f]{10})");
|
||||
"(\\d+)/([0-9a-f]{10})(?:[^0-9a-f]|$)");
|
||||
|
||||
@Nullable
|
||||
public static Result parse(String url) {
|
||||
@@ -50,8 +51,11 @@ public final class GalleryDetailUrlParser {
|
||||
Matcher m = pattern.matcher(url);
|
||||
if (m.find()) {
|
||||
Result result = new Result();
|
||||
result.gid = Long.parseLong(m.group(1));
|
||||
result.gid = NumberUtils.parseLongSafely(m.group(1), -1L);
|
||||
result.token = m.group(2);
|
||||
if (result.gid < 0) {
|
||||
return null;
|
||||
}
|
||||
return result;
|
||||
} else {
|
||||
return null;
|
||||
|
||||
@@ -60,18 +60,17 @@ public class GalleryListParser {
|
||||
|
||||
private static String parseRating(String ratingStyle) {
|
||||
Matcher m = PATTERN_RATING.matcher(ratingStyle);
|
||||
int num1;
|
||||
int num2;
|
||||
int num1 = Integer.MIN_VALUE;
|
||||
int num2 = Integer.MIN_VALUE;
|
||||
int rate = 5;
|
||||
String re;
|
||||
if (m.find()) {
|
||||
num1 = ParserUtils.parseInt(m.group().replace("px", ""));
|
||||
} else {
|
||||
return null;
|
||||
num1 = ParserUtils.parseInt(m.group().replace("px", ""), Integer.MIN_VALUE);
|
||||
}
|
||||
if (m.find()) {
|
||||
num2 = ParserUtils.parseInt(m.group().replace("px", ""));
|
||||
} else {
|
||||
num2 = ParserUtils.parseInt(m.group().replace("px", ""), Integer.MIN_VALUE);
|
||||
}
|
||||
if (num1 == Integer.MIN_VALUE || num2 == Integer.MIN_VALUE) {
|
||||
return null;
|
||||
}
|
||||
rate = rate - num1 / 16;
|
||||
@@ -163,6 +162,8 @@ public class GalleryListParser {
|
||||
Element it4r = JsoupUtils.getElementByClass(e, "it4r");
|
||||
if (null != it4r) {
|
||||
gi.rating = NumberUtils.parseFloatSafely(parseRating(it4r.attr("style")), -1.0f);
|
||||
// TODO The gallery may be rated even if it has one of these classes
|
||||
gi.rated = it4r.hasClass("irr") || it4r.hasClass("irg") || it4r.hasClass("irb");
|
||||
} else {
|
||||
Log.w(TAG, "Can't parse gallery info rating");
|
||||
gi.rating = -1.0f;
|
||||
|
||||
@@ -18,6 +18,7 @@ package com.hippo.ehviewer.client.parser;
|
||||
|
||||
import android.support.annotation.Nullable;
|
||||
import com.hippo.ehviewer.client.EhUrl;
|
||||
import com.hippo.yorozuya.NumberUtils;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@@ -47,9 +48,12 @@ public final class GalleryPageUrlParser {
|
||||
Matcher m = pattern.matcher(url);
|
||||
if (m.find()) {
|
||||
Result result = new Result();
|
||||
result.gid = Long.parseLong(m.group(2));
|
||||
result.gid = NumberUtils.parseLongSafely(m.group(2), -1L);
|
||||
result.pToken = m.group(1);
|
||||
result.page = Integer.parseInt(m.group(3)) - 1;
|
||||
result.page = NumberUtils.parseIntSafely(m.group(3), 0) - 1;
|
||||
if (result.gid < 0 || result.page < 0) {
|
||||
return null;
|
||||
}
|
||||
return result;
|
||||
} else {
|
||||
return null;
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package com.hippo.ehviewer.client.parser;
|
||||
|
||||
import com.hippo.yorozuya.NumberUtils;
|
||||
import com.hippo.yorozuya.StringUtils;
|
||||
|
||||
import java.text.DateFormat;
|
||||
@@ -39,11 +40,15 @@ public class ParserUtils {
|
||||
return StringUtils.unescapeXml(str).trim();
|
||||
}
|
||||
|
||||
public static int parseInt(String str) {
|
||||
return Integer.parseInt(trim(str).replace(",", ""));
|
||||
public static int parseInt(String str, int defValue) {
|
||||
return NumberUtils.parseIntSafely(trim(str).replace(",", ""), defValue);
|
||||
}
|
||||
|
||||
public static long parseLong(String str) {
|
||||
return Long.parseLong(trim(str).replace(",", ""));
|
||||
public static long parseLong(String str, long defValue) {
|
||||
return NumberUtils.parseLongSafely(trim(str).replace(",", ""), defValue);
|
||||
}
|
||||
|
||||
public static float parseFloat(String str, float defValue) {
|
||||
return NumberUtils.parseFloatSafely(trim(str).replace(",", ""), defValue);
|
||||
}
|
||||
}
|
||||
@@ -32,6 +32,7 @@ import com.hippo.ehviewer.spider.SpiderInfo;
|
||||
import com.hippo.ehviewer.spider.SpiderQueen;
|
||||
import com.hippo.image.Image;
|
||||
import com.hippo.unifile.UniFile;
|
||||
import com.hippo.util.IoThreadPoolExecutor;
|
||||
import com.hippo.yorozuya.ConcurrentPool;
|
||||
import com.hippo.yorozuya.MathUtils;
|
||||
import com.hippo.yorozuya.ObjectUtils;
|
||||
@@ -295,6 +296,9 @@ public class DownloadManager implements SpiderQueen.OnSpiderListener {
|
||||
}
|
||||
// Make sure download is running
|
||||
ensureDownload();
|
||||
|
||||
// Add it to history
|
||||
EhDB.putHistoryInfo(info);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -611,7 +615,7 @@ public class DownloadManager implements SpiderQueen.OnSpiderListener {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}.execute();
|
||||
}.executeOnExecutor(IoThreadPoolExecutor.getInstance());
|
||||
}
|
||||
|
||||
// Update in DB
|
||||
|
||||
@@ -18,15 +18,16 @@ package com.hippo.ehviewer.gallery;
|
||||
|
||||
import com.hippo.a7zip.ArchiveException;
|
||||
import com.hippo.a7zip.InArchive;
|
||||
import com.hippo.a7zip.InStream;
|
||||
import com.hippo.a7zip.PropID;
|
||||
import com.hippo.a7zip.PropType;
|
||||
import com.hippo.a7zip.SequentialOutStream;
|
||||
import com.hippo.unifile.UniRandomAccessFile;
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import okio.Store;
|
||||
import okio.UniRandomAccessFileStore;
|
||||
|
||||
class A7ZipArchive implements Closeable {
|
||||
|
||||
@@ -69,8 +70,8 @@ class A7ZipArchive implements Closeable {
|
||||
}
|
||||
|
||||
static A7ZipArchive create(UniRandomAccessFile file) throws ArchiveException {
|
||||
Store store = new UniRandomAccessFileStore(file);
|
||||
InArchive archive = InArchive.create(store);
|
||||
InStream store = new UniRandomAccessFileInStream(file);
|
||||
InArchive archive = InArchive.open(store);
|
||||
if ((archive.getArchivePropertyType(PropID.ENCRYPTED) == PropType.BOOL && archive.getArchiveBooleanProperty(PropID.ENCRYPTED))
|
||||
|| (archive.getArchivePropertyType(PropID.SOLID) == PropType.BOOL && archive.getArchiveBooleanProperty(PropID.SOLID))
|
||||
|| (archive.getArchivePropertyType(PropID.IS_VOLUME) == PropType.BOOL && archive.getArchiveBooleanProperty(PropID.IS_VOLUME))) {
|
||||
@@ -96,7 +97,60 @@ class A7ZipArchive implements Closeable {
|
||||
}
|
||||
|
||||
void extract(OutputStream os) throws ArchiveException {
|
||||
archive.extractEntry(index, os);
|
||||
archive.extractEntry(index, new OutputStreamSequentialOutStream(os));
|
||||
}
|
||||
}
|
||||
|
||||
private static class UniRandomAccessFileInStream implements InStream {
|
||||
|
||||
private UniRandomAccessFile file;
|
||||
|
||||
public UniRandomAccessFileInStream(UniRandomAccessFile file) {
|
||||
this.file = file;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void seek(long pos) throws IOException {
|
||||
file.seek(pos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long tell() throws IOException {
|
||||
return file.getFilePointer();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long size() throws IOException {
|
||||
return file.length();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int read(byte[] b, int off, int len) throws IOException {
|
||||
return file.read(b, off, len);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
file.close();
|
||||
}
|
||||
}
|
||||
|
||||
private static class OutputStreamSequentialOutStream implements SequentialOutStream {
|
||||
|
||||
private OutputStream stream;
|
||||
|
||||
public OutputStreamSequentialOutStream(OutputStream stream) {
|
||||
this.stream = stream;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(byte[] b, int off, int len) throws IOException {
|
||||
stream.write(b, off, len);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
stream.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -88,6 +88,7 @@ class Pipe {
|
||||
public void close() {
|
||||
synchronized (Pipe.this) {
|
||||
inClosed = true;
|
||||
Pipe.this.notifyAll();
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -141,6 +142,7 @@ class Pipe {
|
||||
public void close() {
|
||||
synchronized (Pipe.this) {
|
||||
outClosed = true;
|
||||
Pipe.this.notifyAll();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -30,6 +30,7 @@ import android.util.AttributeSet;
|
||||
import com.hippo.ehviewer.EhApplication;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.preference.DialogPreference;
|
||||
import com.hippo.util.IoThreadPoolExecutor;
|
||||
import com.hippo.yorozuya.IntIdGenerator;
|
||||
|
||||
public abstract class TaskPreference extends DialogPreference {
|
||||
@@ -62,7 +63,7 @@ public abstract class TaskPreference extends DialogPreference {
|
||||
mTask = onCreateTask();
|
||||
mTask.setPreference(this);
|
||||
mTaskId = ((EhApplication) getContext().getApplicationContext()).putGlobalStuff(mTask);
|
||||
mTask.execute();
|
||||
mTask.executeOnExecutor(IoThreadPoolExecutor.getInstance());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -53,6 +53,7 @@ import com.hippo.streampipe.InputStreamPipe;
|
||||
import com.hippo.streampipe.OutputStreamPipe;
|
||||
import com.hippo.unifile.UniFile;
|
||||
import com.hippo.util.ExceptionUtils;
|
||||
import com.hippo.util.IoThreadPoolExecutor;
|
||||
import com.hippo.yorozuya.IOUtils;
|
||||
import com.hippo.yorozuya.MathUtils;
|
||||
import com.hippo.yorozuya.OSUtils;
|
||||
@@ -669,7 +670,7 @@ public final class SpiderQueen implements Runnable {
|
||||
writeSpiderInfoToLocal(spiderInfo);
|
||||
return null;
|
||||
}
|
||||
}.execute();
|
||||
}.executeOnExecutor(IoThreadPoolExecutor.getInstance());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -42,9 +42,13 @@ import com.hippo.ehviewer.ui.scene.BaseScene;
|
||||
import com.hippo.text.Html;
|
||||
import com.hippo.unifile.UniFile;
|
||||
import com.hippo.util.ExceptionUtils;
|
||||
import com.hippo.util.IoThreadPoolExecutor;
|
||||
import com.hippo.yorozuya.FileUtils;
|
||||
import com.hippo.yorozuya.IOUtils;
|
||||
|
||||
import com.hippo.yorozuya.collect.LongList;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
@@ -65,7 +69,7 @@ public final class CommonOperations {
|
||||
public static void checkUpdate(Activity activity, boolean feedback) {
|
||||
if (!UPDATING) {
|
||||
UPDATING = true;
|
||||
new UpdateTask(activity, feedback).execute();
|
||||
new UpdateTask(activity, feedback).executeOnExecutor(IoThreadPoolExecutor.getInstance());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -281,11 +285,37 @@ public final class CommonOperations {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO Add context if activity and context are different style
|
||||
public static void startDownload(final MainActivity activity, final GalleryInfo galleryInfo, boolean forceDefault) {
|
||||
startDownload(activity, Collections.singletonList(galleryInfo), forceDefault);
|
||||
}
|
||||
|
||||
// TODO Add context if activity and context are different style
|
||||
public static void startDownload(final MainActivity activity, final List<GalleryInfo> galleryInfos, boolean forceDefault) {
|
||||
final DownloadManager dm = EhApplication.getDownloadManager(activity);
|
||||
|
||||
boolean justStart = forceDefault || dm.containDownloadInfo(galleryInfo.gid);
|
||||
LongList toStart = new LongList();
|
||||
List<GalleryInfo> toAdd = new ArrayList<>();
|
||||
for (GalleryInfo gi : galleryInfos) {
|
||||
if (dm.containDownloadInfo(gi.gid)) {
|
||||
toStart.add(gi.gid);
|
||||
} else {
|
||||
toAdd.add(gi);
|
||||
}
|
||||
}
|
||||
|
||||
if (!toStart.isEmpty()) {
|
||||
Intent intent = new Intent(activity, DownloadService.class);
|
||||
intent.setAction(DownloadService.ACTION_START_RANGE);
|
||||
intent.putExtra(DownloadService.KEY_GID_LIST, toStart);
|
||||
activity.startService(intent);
|
||||
}
|
||||
|
||||
if (toAdd.isEmpty()) {
|
||||
activity.showTip(R.string.added_to_download_list, BaseScene.LENGTH_SHORT);
|
||||
return;
|
||||
}
|
||||
|
||||
boolean justStart = forceDefault;
|
||||
String label = null;
|
||||
// Get default download label
|
||||
if (!justStart && Settings.getHasDefaultDownloadLabel()) {
|
||||
@@ -299,12 +329,14 @@ public final class CommonOperations {
|
||||
}
|
||||
|
||||
if (justStart) {
|
||||
// Already in download list or get default label
|
||||
Intent intent = new Intent(activity, DownloadService.class);
|
||||
intent.setAction(DownloadService.ACTION_START);
|
||||
intent.putExtra(DownloadService.KEY_LABEL, label);
|
||||
intent.putExtra(DownloadService.KEY_GALLERY_INFO, galleryInfo);
|
||||
activity.startService(intent);
|
||||
// Got default label
|
||||
for (GalleryInfo gi : toAdd) {
|
||||
Intent intent = new Intent(activity, DownloadService.class);
|
||||
intent.setAction(DownloadService.ACTION_START);
|
||||
intent.putExtra(DownloadService.KEY_LABEL, label);
|
||||
intent.putExtra(DownloadService.KEY_GALLERY_INFO, gi);
|
||||
activity.startService(intent);
|
||||
}
|
||||
// Notify
|
||||
activity.showTip(R.string.added_to_download_list, BaseScene.LENGTH_SHORT);
|
||||
} else {
|
||||
@@ -330,11 +362,13 @@ public final class CommonOperations {
|
||||
}
|
||||
}
|
||||
// Start download
|
||||
Intent intent = new Intent(activity, DownloadService.class);
|
||||
intent.setAction(DownloadService.ACTION_START);
|
||||
intent.putExtra(DownloadService.KEY_LABEL, label);
|
||||
intent.putExtra(DownloadService.KEY_GALLERY_INFO, galleryInfo);
|
||||
activity.startService(intent);
|
||||
for (GalleryInfo gi : toAdd) {
|
||||
Intent intent = new Intent(activity, DownloadService.class);
|
||||
intent.setAction(DownloadService.ACTION_START);
|
||||
intent.putExtra(DownloadService.KEY_LABEL, label);
|
||||
intent.putExtra(DownloadService.KEY_GALLERY_INFO, gi);
|
||||
activity.startService(intent);
|
||||
}
|
||||
// Save settings
|
||||
if (builder.isChecked()) {
|
||||
Settings.putHasDefaultDownloadLabel(true);
|
||||
|
||||
@@ -48,6 +48,7 @@ import com.hippo.ehviewer.AppConfig;
|
||||
import com.hippo.ehviewer.EhApplication;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.Settings;
|
||||
import com.hippo.ehviewer.client.EhTagDatabase;
|
||||
import com.hippo.ehviewer.client.EhUrlOpener;
|
||||
import com.hippo.ehviewer.client.EhUtils;
|
||||
import com.hippo.ehviewer.client.data.ListUrlBuilder;
|
||||
@@ -362,6 +363,8 @@ public final class MainActivity extends StageActivity
|
||||
} else {
|
||||
onRestore(savedInstanceState);
|
||||
}
|
||||
|
||||
EhTagDatabase.update();
|
||||
}
|
||||
|
||||
private String getThemeText() {
|
||||
@@ -626,6 +629,20 @@ public final class MainActivity extends StageActivity
|
||||
}
|
||||
}
|
||||
|
||||
public void setDrawerGestureBlocker(DrawerLayout.GestureBlocker gestureBlocker) {
|
||||
if (mDrawerLayout != null) {
|
||||
mDrawerLayout.setGestureBlocker(gestureBlocker);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isDrawersVisible() {
|
||||
if (mDrawerLayout != null) {
|
||||
return mDrawerLayout.isDrawersVisible();
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public void setNavCheckedItem(@IdRes int resId) {
|
||||
mNavCheckedItem = resId;
|
||||
if (mNavView != null) {
|
||||
@@ -647,7 +664,7 @@ public final class MainActivity extends StageActivity
|
||||
public void showTip(CharSequence message, int length) {
|
||||
if (null != mDrawerLayout) {
|
||||
Snackbar.make(mDrawerLayout, message,
|
||||
length == BaseScene.LENGTH_LONG ? Snackbar.LENGTH_LONG : Snackbar.LENGTH_SHORT).show();
|
||||
length == BaseScene.LENGTH_LONG ? 5000 : 3000).show();
|
||||
} else {
|
||||
Toast.makeText(this, message,
|
||||
length == BaseScene.LENGTH_LONG ? Toast.LENGTH_LONG : Toast.LENGTH_SHORT).show();
|
||||
|
||||
@@ -24,6 +24,7 @@ import android.preference.PreferenceFragment;
|
||||
import com.hippo.ehviewer.EhApplication;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.Settings;
|
||||
import com.hippo.ehviewer.client.EhTagDatabase;
|
||||
|
||||
public class EhFragment extends PreferenceFragment
|
||||
implements Preference.OnPreferenceChangeListener {
|
||||
@@ -39,6 +40,7 @@ public class EhFragment extends PreferenceFragment
|
||||
Preference listMode = findPreference(Settings.KEY_LIST_MODE);
|
||||
Preference detailSize = findPreference(Settings.KEY_DETAIL_SIZE);
|
||||
Preference thumbSize = findPreference(Settings.KEY_THUMB_SIZE);
|
||||
Preference showTagTranslations = findPreference(Settings.KEY_SHOW_TAG_TRANSLATIONS);
|
||||
|
||||
theme.setOnPreferenceChangeListener(this);
|
||||
applyNavBarThemeColor.setOnPreferenceChangeListener(this);
|
||||
@@ -46,10 +48,15 @@ public class EhFragment extends PreferenceFragment
|
||||
listMode.setOnPreferenceChangeListener(this);
|
||||
detailSize.setOnPreferenceChangeListener(this);
|
||||
thumbSize.setOnPreferenceChangeListener(this);
|
||||
showTagTranslations.setOnPreferenceChangeListener(this);
|
||||
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
|
||||
getPreferenceScreen().removePreference(applyNavBarThemeColor);
|
||||
}
|
||||
|
||||
if (!EhTagDatabase.isPossible()) {
|
||||
getPreferenceScreen().removePreference(showTagTranslations);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -71,6 +78,10 @@ public class EhFragment extends PreferenceFragment
|
||||
getActivity().setResult(Activity.RESULT_OK);
|
||||
} else if (Settings.KEY_THUMB_SIZE.equals(key)) {
|
||||
getActivity().setResult(Activity.RESULT_OK);
|
||||
} else if (Settings.KEY_SHOW_TAG_TRANSLATIONS.equals(key)) {
|
||||
if (Boolean.TRUE.equals(newValue)) {
|
||||
EhTagDatabase.update();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -26,13 +26,13 @@ import android.support.annotation.Nullable;
|
||||
import android.support.annotation.StringRes;
|
||||
import android.support.annotation.StyleRes;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
import android.support.v4.widget.DrawerLayout;
|
||||
import android.util.SparseArray;
|
||||
import android.view.ContextThemeWrapper;
|
||||
import android.view.Gravity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import com.hippo.drawerlayout.DrawerLayout;
|
||||
import com.hippo.ehviewer.Analytics;
|
||||
import com.hippo.ehviewer.ui.MainActivity;
|
||||
import com.hippo.scene.SceneFragment;
|
||||
@@ -111,6 +111,22 @@ public abstract class BaseScene extends SceneFragment {
|
||||
}
|
||||
}
|
||||
|
||||
public void setDrawerGestureBlocker(DrawerLayout.GestureBlocker gestureBlocker) {
|
||||
FragmentActivity activity = getActivity();
|
||||
if (activity instanceof MainActivity) {
|
||||
((MainActivity) activity).setDrawerGestureBlocker(gestureBlocker);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isDrawersVisible() {
|
||||
FragmentActivity activity = getActivity();
|
||||
if (activity instanceof MainActivity) {
|
||||
return ((MainActivity) activity).isDrawersVisible();
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param resId 0 for clear
|
||||
*/
|
||||
|
||||
@@ -84,6 +84,7 @@ import com.hippo.streampipe.InputStreamPipe;
|
||||
import com.hippo.unifile.UniFile;
|
||||
import com.hippo.util.ApiHelper;
|
||||
import com.hippo.util.DrawableManager;
|
||||
import com.hippo.util.IoThreadPoolExecutor;
|
||||
import com.hippo.view.ViewTransition;
|
||||
import com.hippo.widget.FabLayout;
|
||||
import com.hippo.widget.LoadImageView;
|
||||
@@ -935,7 +936,7 @@ public class DownloadsScene extends ToolbarScene
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}.execute(files);
|
||||
}.executeOnExecutor(IoThreadPoolExecutor.getInstance(), files);
|
||||
}
|
||||
|
||||
private class DeleteDialogHelper implements DialogInterface.OnClickListener {
|
||||
|
||||
@@ -63,6 +63,7 @@ import com.hippo.ehviewer.client.EhUrl;
|
||||
import com.hippo.ehviewer.client.data.FavListUrlBuilder;
|
||||
import com.hippo.ehviewer.client.data.GalleryInfo;
|
||||
import com.hippo.ehviewer.client.parser.FavoritesParser;
|
||||
import com.hippo.ehviewer.ui.CommonOperations;
|
||||
import com.hippo.ehviewer.ui.MainActivity;
|
||||
import com.hippo.ehviewer.ui.annotation.DrawerLifeCircle;
|
||||
import com.hippo.ehviewer.ui.annotation.ViewLifeCircle;
|
||||
@@ -762,7 +763,18 @@ public class FavoritesScene extends BaseScene implements
|
||||
}
|
||||
|
||||
switch (position) {
|
||||
case 0: { // Delete
|
||||
case 0: { // Download
|
||||
Activity activity = getActivity2();
|
||||
if (activity != null) {
|
||||
CommonOperations.startDownload(getActivity2(), mModifyGiList, false);
|
||||
}
|
||||
mModifyGiList.clear();
|
||||
if (mRecyclerView != null && mRecyclerView.isInCustomChoice()) {
|
||||
mRecyclerView.outOfCustomChoiceMode();
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 1: { // Delete
|
||||
DeleteDialogHelper helper = new DeleteDialogHelper();
|
||||
new AlertDialog.Builder(context)
|
||||
.setTitle(R.string.delete_favorites_dialog_title)
|
||||
@@ -772,7 +784,7 @@ public class FavoritesScene extends BaseScene implements
|
||||
.show();
|
||||
break;
|
||||
}
|
||||
case 1: { // Move
|
||||
case 2: { // Move
|
||||
MoveDialogHelper helper = new MoveDialogHelper();
|
||||
// First is local favorite, the other 10 is cloud favorite
|
||||
String[] array = new String[11];
|
||||
|
||||
@@ -744,7 +744,7 @@ public final class GalleryCommentsScene extends ToolbarScene
|
||||
|
||||
@Override
|
||||
public void onFailure(Exception e) {
|
||||
showTip(getContent().getString(R.string.comment_failed) + "\n" + ExceptionUtils.getReadableString(e), LENGTH_SHORT);
|
||||
showTip(getContent().getString(R.string.comment_failed) + "\n" + ExceptionUtils.getReadableString(e), LENGTH_LONG);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -778,7 +778,7 @@ public final class GalleryCommentsScene extends ToolbarScene
|
||||
|
||||
@Override
|
||||
public void onFailure(Exception e) {
|
||||
showTip(R.string.vote_failed, LENGTH_SHORT);
|
||||
showTip(R.string.vote_failed, LENGTH_LONG);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -44,8 +44,10 @@ import android.util.Pair;
|
||||
import android.view.Gravity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.ViewParent;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ImageView;
|
||||
@@ -56,6 +58,7 @@ import android.widget.TextView;
|
||||
import com.hippo.android.resource.AttrResources;
|
||||
import com.hippo.beerbelly.BeerBelly;
|
||||
import com.hippo.drawable.RoundSideRectDrawable;
|
||||
import com.hippo.drawerlayout.DrawerLayout;
|
||||
import com.hippo.ehviewer.AppConfig;
|
||||
import com.hippo.ehviewer.EhApplication;
|
||||
import com.hippo.ehviewer.EhDB;
|
||||
@@ -66,6 +69,7 @@ import com.hippo.ehviewer.client.EhCacheKeyFactory;
|
||||
import com.hippo.ehviewer.client.EhClient;
|
||||
import com.hippo.ehviewer.client.EhFilter;
|
||||
import com.hippo.ehviewer.client.EhRequest;
|
||||
import com.hippo.ehviewer.client.EhTagDatabase;
|
||||
import com.hippo.ehviewer.client.EhUrl;
|
||||
import com.hippo.ehviewer.client.EhUtils;
|
||||
import com.hippo.ehviewer.client.data.GalleryComment;
|
||||
@@ -355,11 +359,6 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean needShowLeftDrawer() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
@@ -429,6 +428,35 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
|
||||
Context context = getContext2();
|
||||
AssertUtils.assertNotNull(context);
|
||||
|
||||
View actionsScrollView = ViewUtils.$$(view, R.id.actions_scroll_view);
|
||||
setDrawerGestureBlocker(new DrawerLayout.GestureBlocker() {
|
||||
private void transformPointToViewLocal(int[] point, View child) {
|
||||
ViewParent viewParent = child.getParent();
|
||||
|
||||
while (viewParent instanceof View) {
|
||||
View view = (View) viewParent;
|
||||
point[0] += view.getScrollX() - child.getLeft();
|
||||
point[1] += view.getScrollY() - child.getTop();
|
||||
|
||||
if (view instanceof DrawerLayout) {
|
||||
break;
|
||||
}
|
||||
|
||||
child = view;
|
||||
viewParent = child.getParent();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldBlockGesture(MotionEvent ev) {
|
||||
int[] point = new int[] {(int) ev.getX(), (int) ev.getY()};
|
||||
transformPointToViewLocal(point, actionsScrollView);
|
||||
return !isDrawersVisible()
|
||||
&& point[0] > 0 && point[0] < actionsScrollView.getWidth()
|
||||
&& point[1] > 0 && point[1] < actionsScrollView.getHeight();
|
||||
}
|
||||
});
|
||||
|
||||
Drawable drawable = DrawableManager.getVectorDrawable(context, R.drawable.big_sad_pandroid);
|
||||
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
|
||||
mTip.setCompoundDrawables(null, drawable, null, null);
|
||||
@@ -550,6 +578,8 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
|
||||
AssertUtils.assertNotNull(context);
|
||||
EhApplication.getDownloadManager(context).removeDownloadInfoListener(this);
|
||||
|
||||
setDrawerGestureBlocker(null);
|
||||
|
||||
mTip = null;
|
||||
mViewTransition = null;
|
||||
|
||||
@@ -839,6 +869,7 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
|
||||
mNoTags.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
EhTagDatabase ehTags = Settings.getShowTagTranslations() ? EhTagDatabase.getInstance() : null;
|
||||
int colorTag = AttrResources.getAttrColor(context, R.attr.tagBackgroundColor);
|
||||
int colorName = AttrResources.getAttrColor(context, R.attr.tagGroupBackgroundColor);
|
||||
for (GalleryTagGroup tg : tagGroups) {
|
||||
@@ -846,18 +877,34 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
|
||||
ll.setOrientation(LinearLayout.HORIZONTAL);
|
||||
mTags.addView(ll);
|
||||
|
||||
String readableTagName = null;
|
||||
if (ehTags != null) {
|
||||
readableTagName = ehTags.getTranslation("n:" + tg.groupName);
|
||||
}
|
||||
|
||||
TextView tgName = (TextView) inflater.inflate(R.layout.item_gallery_tag, ll, false);
|
||||
ll.addView(tgName);
|
||||
tgName.setText(tg.groupName);
|
||||
tgName.setText(readableTagName != null ? readableTagName : tg.groupName);
|
||||
tgName.setBackgroundDrawable(new RoundSideRectDrawable(colorName));
|
||||
|
||||
String prefix = EhTagDatabase.namespaceToPrefix(tg.groupName);
|
||||
if (prefix == null) {
|
||||
prefix = "";
|
||||
}
|
||||
|
||||
AutoWrapLayout awl = new AutoWrapLayout(context);
|
||||
ll.addView(awl, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||
for (int j = 0, z = tg.size(); j < z; j++) {
|
||||
TextView tag = (TextView) inflater.inflate(R.layout.item_gallery_tag, awl, false);
|
||||
awl.addView(tag);
|
||||
String tagStr = tg.getTagAt(j);
|
||||
tag.setText(tagStr);
|
||||
|
||||
String readableTag = null;
|
||||
if (ehTags != null) {
|
||||
readableTag = ehTags.getTranslation(prefix + tagStr);
|
||||
}
|
||||
|
||||
tag.setText(readableTag != null ? readableTag : tagStr);
|
||||
tag.setBackgroundDrawable(new RoundSideRectDrawable(colorTag));
|
||||
tag.setTag(R.id.tag, tg.groupName + ":" + tagStr);
|
||||
tag.setOnClickListener(this);
|
||||
@@ -1194,7 +1241,7 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
|
||||
return;
|
||||
}
|
||||
if (mGalleryDetail.apiUid < 0) {
|
||||
showTip(R.string.sign_in_first, LENGTH_SHORT);
|
||||
showTip(R.string.sign_in_first, LENGTH_LONG);
|
||||
return;
|
||||
}
|
||||
ArchiveListDialogHelper helper = new ArchiveListDialogHelper();
|
||||
@@ -1209,7 +1256,7 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
|
||||
return;
|
||||
}
|
||||
if (mGalleryDetail.apiUid < 0) {
|
||||
showTip(R.string.sign_in_first, LENGTH_SHORT);
|
||||
showTip(R.string.sign_in_first, LENGTH_LONG);
|
||||
return;
|
||||
}
|
||||
RateDialogHelper helper = new RateDialogHelper();
|
||||
@@ -1580,7 +1627,7 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
|
||||
@Override
|
||||
public void onFailure(Exception e) {
|
||||
showTip(mAddOrRemove ? R.string.remove_from_favorite_failure :
|
||||
R.string.add_to_favorite_failure, LENGTH_SHORT);
|
||||
R.string.add_to_favorite_failure, LENGTH_LONG);
|
||||
GalleryDetailScene scene = getScene();
|
||||
if (scene != null) {
|
||||
scene.onModifyFavoritesFailure(mAddOrRemove);
|
||||
@@ -1615,9 +1662,9 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
|
||||
@Override
|
||||
public void onFailure(Exception e) {
|
||||
if (e instanceof NoHAtHClientException) {
|
||||
showTip(R.string.download_archive_failure_no_hath, LENGTH_SHORT);
|
||||
showTip(R.string.download_archive_failure_no_hath, LENGTH_LONG);
|
||||
} else {
|
||||
showTip(R.string.download_archive_failure, LENGTH_SHORT);
|
||||
showTip(R.string.download_archive_failure, LENGTH_LONG);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1984,7 +2031,7 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
|
||||
@Override
|
||||
public void onFailure(Exception e) {
|
||||
e.printStackTrace();
|
||||
showTip(R.string.rate_failed, LENGTH_SHORT);
|
||||
showTip(R.string.rate_failed, LENGTH_LONG);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -655,14 +655,14 @@ public final class GalleryListScene extends BaseScene
|
||||
|
||||
// Can't add image search as quick search
|
||||
if (ListUrlBuilder.MODE_IMAGE_SEARCH == urlBuilder.getMode()) {
|
||||
showTip(R.string.image_search_not_quick_search, LENGTH_SHORT);
|
||||
showTip(R.string.image_search_not_quick_search, LENGTH_LONG);
|
||||
return;
|
||||
}
|
||||
|
||||
// Check duplicate
|
||||
for (QuickSearch q: list) {
|
||||
if (urlBuilder.equalsQuickSearch(q)) {
|
||||
showTip(getString(R.string.duplicate_quick_search, q.name), LENGTH_SHORT);
|
||||
showTip(getString(R.string.duplicate_quick_search, q.name), LENGTH_LONG);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -1545,7 +1545,7 @@ public final class GalleryListScene extends BaseScene
|
||||
|
||||
@Override
|
||||
public void onFailure(Exception e) {
|
||||
showTip(R.string.add_to_favorite_failure, LENGTH_SHORT);
|
||||
showTip(R.string.add_to_favorite_failure, LENGTH_LONG);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -433,7 +433,7 @@ public class GalleryPreviewsScene extends ToolbarScene implements EasyRecyclerVi
|
||||
mDialog = null;
|
||||
}
|
||||
} else {
|
||||
showTip(R.string.error_out_of_range, LENGTH_SHORT);
|
||||
showTip(R.string.error_out_of_range, LENGTH_LONG);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -450,7 +450,7 @@ public class HistoryScene extends ToolbarScene
|
||||
|
||||
@Override
|
||||
public void onFailure(Exception e) {
|
||||
showTip(R.string.add_to_favorite_failure, LENGTH_SHORT);
|
||||
showTip(R.string.add_to_favorite_failure, LENGTH_LONG);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -24,7 +24,8 @@ import com.hippo.widget.DrawerView;
|
||||
|
||||
public class EhDrawerView extends DrawerView implements DrawerLayoutChild {
|
||||
|
||||
private int mFitPaddingTop;
|
||||
private int mWindowPaddingTop;
|
||||
private int mWindowPaddingBottom;
|
||||
|
||||
public EhDrawerView(Context context) {
|
||||
super(context);
|
||||
@@ -39,17 +40,18 @@ public class EhDrawerView extends DrawerView implements DrawerLayoutChild {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFitPadding(int top, int bottom) {
|
||||
mFitPaddingTop = top;
|
||||
public void onGetWindowPadding(int top, int bottom) {
|
||||
mWindowPaddingTop = top;
|
||||
mWindowPaddingBottom = bottom;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLayoutPaddingTop() {
|
||||
return mFitPaddingTop;
|
||||
public int getAdditionalTopMargin() {
|
||||
return mWindowPaddingTop;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLayoutPaddingBottom() {
|
||||
return 0;
|
||||
public int getAdditionalBottomMargin() {
|
||||
return mWindowPaddingBottom;
|
||||
}
|
||||
}
|
||||
@@ -30,7 +30,8 @@ public class EhNavigationView extends LinearLayout implements DrawerLayoutChild
|
||||
private static final int SCRIM_COLOR = 0x44000000;
|
||||
private static final boolean DRAW_SCRIM = Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP;
|
||||
private Paint mPaint;
|
||||
private int mFitPaddingTop;
|
||||
private int mWindowPaddingTop;
|
||||
private int mWindowPaddingBottom;
|
||||
|
||||
public EhNavigationView(Context context) {
|
||||
super(context);
|
||||
@@ -57,27 +58,28 @@ public class EhNavigationView extends LinearLayout implements DrawerLayoutChild
|
||||
public void draw(@NonNull Canvas canvas) {
|
||||
super.draw(canvas);
|
||||
|
||||
if (DRAW_SCRIM && mFitPaddingTop > 0) {
|
||||
if (DRAW_SCRIM && mWindowPaddingTop > 0) {
|
||||
if (null == mPaint) {
|
||||
mPaint = new Paint();
|
||||
mPaint.setColor(SCRIM_COLOR);
|
||||
}
|
||||
canvas.drawRect(0, 0, getWidth(), mFitPaddingTop, mPaint);
|
||||
canvas.drawRect(0, 0, getWidth(), mWindowPaddingTop, mPaint);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFitPadding(int top, int bottom) {
|
||||
mFitPaddingTop = top;
|
||||
public void onGetWindowPadding(int top, int bottom) {
|
||||
mWindowPaddingTop = top;
|
||||
mWindowPaddingBottom = bottom;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLayoutPaddingTop() {
|
||||
public int getAdditionalTopMargin() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLayoutPaddingBottom() {
|
||||
return 0;
|
||||
public int getAdditionalBottomMargin() {
|
||||
return mWindowPaddingBottom;
|
||||
}
|
||||
}
|
||||
@@ -24,7 +24,8 @@ import com.hippo.scene.StageLayout;
|
||||
|
||||
public class EhStageLayout extends StageLayout implements DrawerLayoutChild {
|
||||
|
||||
private int mFitPaddingTop;
|
||||
private int mWindowPaddingTop;
|
||||
private int mWindowPaddingBottom;
|
||||
|
||||
public EhStageLayout(Context context) {
|
||||
super(context);
|
||||
@@ -39,17 +40,18 @@ public class EhStageLayout extends StageLayout implements DrawerLayoutChild {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFitPadding(int top, int bottom) {
|
||||
mFitPaddingTop = top;
|
||||
public void onGetWindowPadding(int top, int bottom) {
|
||||
mWindowPaddingTop = top;
|
||||
mWindowPaddingBottom = bottom;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLayoutPaddingTop() {
|
||||
return mFitPaddingTop;
|
||||
public int getAdditionalTopMargin() {
|
||||
return mWindowPaddingTop;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLayoutPaddingBottom() {
|
||||
return 0;
|
||||
public int getAdditionalBottomMargin() {
|
||||
return mWindowPaddingBottom;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* Copyright 2019 Hippo Seven
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.hippo.ehviewer.widget;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.util.AttributeSet;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.widget.LoadImageView;
|
||||
|
||||
public class FixedThumb extends LoadImageView {
|
||||
|
||||
private float minAspect;
|
||||
private float maxAspect;
|
||||
|
||||
public FixedThumb(Context context) {
|
||||
super(context);
|
||||
init(context, null, 0, 0);
|
||||
}
|
||||
|
||||
public FixedThumb(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
init(context, attrs, 0, 0);
|
||||
}
|
||||
|
||||
public FixedThumb(Context context, AttributeSet attrs, int defStyle) {
|
||||
super(context, attrs, defStyle);
|
||||
init(context, attrs, defStyle, 0);
|
||||
}
|
||||
|
||||
private void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
||||
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.FixedThumb, defStyleAttr, defStyleRes);
|
||||
minAspect = a.getFloat(R.styleable.FixedThumb_minAspect, 0.0f);
|
||||
maxAspect = a.getFloat(R.styleable.FixedThumb_maxAspect, 0.0f);
|
||||
a.recycle();
|
||||
}
|
||||
|
||||
public void setFix(float minAspect, float maxAspect) {
|
||||
this.minAspect = minAspect;
|
||||
this.maxAspect = maxAspect;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPreSetImageDrawable(Drawable drawable, boolean isTarget) {
|
||||
if (isTarget && drawable != null) {
|
||||
int width = drawable.getIntrinsicWidth();
|
||||
int height = drawable.getIntrinsicHeight();
|
||||
if (width > 0 && height > 0) {
|
||||
float aspect = (float) width / (float) height;
|
||||
if (aspect < maxAspect && aspect > minAspect) {
|
||||
setScaleType(ScaleType.CENTER_CROP);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
setScaleType(ScaleType.FIT_CENTER);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPreSetImageResource(int resId, boolean isTarget) {
|
||||
setScaleType(ScaleType.FIT_CENTER);
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,7 @@ package com.hippo.ehviewer.widget;
|
||||
import android.content.ContentValues;
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.database.SQLException;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.database.sqlite.SQLiteOpenHelper;
|
||||
import android.text.TextUtils;
|
||||
@@ -69,19 +70,24 @@ public final class SearchDatabase {
|
||||
}
|
||||
sb.append(" ORDER BY ").append(COLUMN_DATE).append(" DESC")
|
||||
.append(" LIMIT ").append(limit);
|
||||
Cursor cursor = mDatabase.rawQuery(sb.toString(), null);
|
||||
int queryIndex = cursor.getColumnIndex(COLUMN_QUERY);
|
||||
if (cursor.moveToFirst()) {
|
||||
while (!cursor.isAfterLast()) {
|
||||
String suggestion = cursor.getString(queryIndex);
|
||||
if (!prefix.equals(suggestion)) {
|
||||
queryList.add(suggestion);
|
||||
|
||||
try {
|
||||
Cursor cursor = mDatabase.rawQuery(sb.toString(), null);
|
||||
int queryIndex = cursor.getColumnIndex(COLUMN_QUERY);
|
||||
if (cursor.moveToFirst()) {
|
||||
while (!cursor.isAfterLast()) {
|
||||
String suggestion = cursor.getString(queryIndex);
|
||||
if (!prefix.equals(suggestion)) {
|
||||
queryList.add(suggestion);
|
||||
}
|
||||
cursor.moveToNext();
|
||||
}
|
||||
cursor.moveToNext();
|
||||
}
|
||||
cursor.close();
|
||||
return queryList.toArray(new String[queryList.size()]);
|
||||
} catch (SQLException e) {
|
||||
return new String[0];
|
||||
}
|
||||
cursor.close();
|
||||
return queryList.toArray(new String[queryList.size()]);
|
||||
}
|
||||
|
||||
public void addQuery(final String query) {
|
||||
|
||||
@@ -23,11 +23,20 @@ import okhttp3.Request;
|
||||
|
||||
public class ChromeRequestBuilder extends Request.Builder {
|
||||
|
||||
private static final String CHROME_USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) " +
|
||||
"AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.103 Safari/537.36";
|
||||
private static final String CHROME_USER_AGENT =
|
||||
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) " +
|
||||
"AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36";
|
||||
|
||||
private static final String CHROME_ACCEPT =
|
||||
"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
|
||||
|
||||
private static final String CHROME_ACCEPT_LANGUAGE =
|
||||
"en-US,en;q=0.5";
|
||||
|
||||
public ChromeRequestBuilder(String url) throws MalformedURLException {
|
||||
url(new URL(url));
|
||||
addHeader("User-Agent", CHROME_USER_AGENT);
|
||||
addHeader("Accept", CHROME_ACCEPT);
|
||||
addHeader("Accept-Language", CHROME_ACCEPT_LANGUAGE);
|
||||
}
|
||||
}
|
||||
@@ -713,11 +713,13 @@ class HtmlToSpannedConverter implements ContentHandler {
|
||||
where, len,
|
||||
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
} else {
|
||||
int c = getHtmlColor(f.mColor);
|
||||
if (c != -1) {
|
||||
try {
|
||||
int c = getHtmlColor(f.mColor);
|
||||
text.setSpan(new ForegroundColorSpan(c | 0xFF000000),
|
||||
where, len,
|
||||
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
} catch (IllegalArgumentException e) {
|
||||
// Ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -906,16 +908,19 @@ class HtmlToSpannedConverter implements ContentHandler {
|
||||
*/
|
||||
@ColorInt
|
||||
public static int getHtmlColor(@NonNull String colorString) {
|
||||
if (colorString.charAt(0) == '#') {
|
||||
if ((colorString.length() == 7 || colorString.length() == 9) && colorString.charAt(0) == '#') {
|
||||
// Use a long to avoid rollovers on #ffXXXXXX
|
||||
long color = Long.parseLong(colorString.substring(1), 16);
|
||||
long color;
|
||||
try {
|
||||
color = Long.parseLong(colorString.substring(1), 16);
|
||||
} catch (NumberFormatException e) {
|
||||
throw new IllegalArgumentException("Unknown color: " + colorString);
|
||||
}
|
||||
if (colorString.length() == 7) {
|
||||
// Set the alpha value
|
||||
color |= 0x00000000ff000000;
|
||||
} else if (colorString.length() != 9) {
|
||||
throw new IllegalArgumentException("Unknown color: " + colorString);
|
||||
}
|
||||
return (int)color;
|
||||
return (int) color;
|
||||
} else if (colorString.startsWith("rgb(") && colorString.endsWith(")")) {
|
||||
String str = colorString.substring(4, colorString.length() - 1);
|
||||
String[] colors = str.split("[\\s]*,[\\s]*");
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* Copyright 2019 Hippo Seven
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.hippo.util;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
import com.hippo.yorozuya.thread.PriorityThreadFactory;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.RejectedExecutionException;
|
||||
import java.util.concurrent.RejectedExecutionHandler;
|
||||
import java.util.concurrent.ThreadFactory;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class IoThreadPoolExecutor extends ThreadPoolExecutor {
|
||||
|
||||
private final static ThreadPoolExecutor INSTANCE =
|
||||
IoThreadPoolExecutor.newInstance(3, 32, 1L, TimeUnit.SECONDS,
|
||||
new PriorityThreadFactory("IO",android.os.Process.THREAD_PRIORITY_BACKGROUND));
|
||||
|
||||
private IoThreadPoolExecutor(
|
||||
int corePoolSize,
|
||||
int maximumPoolSize,
|
||||
long keepAliveTime,
|
||||
TimeUnit unit,
|
||||
BlockingQueue<Runnable> workQueue,
|
||||
ThreadFactory threadFactory,
|
||||
RejectedExecutionHandler handler
|
||||
) {
|
||||
super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue, threadFactory, handler);
|
||||
}
|
||||
|
||||
public static ThreadPoolExecutor getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
private static ThreadPoolExecutor newInstance(
|
||||
int corePoolSize,
|
||||
int maximumPoolSize,
|
||||
long keepAliveTime,
|
||||
TimeUnit unit,
|
||||
ThreadFactory threadFactory
|
||||
) {
|
||||
ThreadQueue queue = new ThreadQueue();
|
||||
PutRunnableBackHandler handler = new PutRunnableBackHandler();
|
||||
IoThreadPoolExecutor executor = new IoThreadPoolExecutor(
|
||||
corePoolSize, maximumPoolSize, keepAliveTime, unit, queue, threadFactory, handler);
|
||||
queue.setThreadPoolExecutor(executor);
|
||||
return executor;
|
||||
}
|
||||
|
||||
private static class ThreadQueue extends LinkedBlockingQueue<Runnable> {
|
||||
|
||||
private ThreadPoolExecutor executor;
|
||||
|
||||
void setThreadPoolExecutor(ThreadPoolExecutor executor) {
|
||||
this.executor = executor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean offer(@NonNull Runnable o) {
|
||||
int allWorkingThreads = executor.getActiveCount() + super.size();
|
||||
return allWorkingThreads < executor.getPoolSize() && super.offer(o);
|
||||
}
|
||||
}
|
||||
|
||||
public static class PutRunnableBackHandler implements RejectedExecutionHandler {
|
||||
public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
|
||||
try {
|
||||
executor.getQueue().put(r);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RejectedExecutionException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -20,11 +20,14 @@ import android.text.Spannable;
|
||||
import android.text.SpannableString;
|
||||
import android.text.style.URLSpan;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public final class TextUrl {
|
||||
|
||||
public static final Charset UTF_8 = Charset.forName("UTF-8");
|
||||
|
||||
private static final Pattern URL_PATTERN = Pattern.compile("(http|https)://[a-z0-9A-Z%-]+(\\.[a-z0-9A-Z%-]+)+(:\\d{1,5})?(/[a-zA-Z0-9-_~:#@!&',;=%/\\*\\.\\?\\+\\$\\[\\]\\(\\)]+)?/?");
|
||||
|
||||
public static CharSequence handleTextUrl(CharSequence content) {
|
||||
|
||||
@@ -239,11 +239,13 @@ public class LoadImageView extends FixedAspectImageView implements Unikery<Image
|
||||
|
||||
public void load(Drawable drawable) {
|
||||
unload();
|
||||
onPreSetImageDrawable(drawable, true);
|
||||
setImageDrawable(drawable);
|
||||
}
|
||||
|
||||
public void load(@DrawableRes int id) {
|
||||
unload();
|
||||
onPreSetImageResource(id, true);
|
||||
setImageResource(id);
|
||||
}
|
||||
|
||||
@@ -290,6 +292,7 @@ public class LoadImageView extends FixedAspectImageView implements Unikery<Image
|
||||
drawable = new PreciselyClipDrawable(drawable, mOffsetX, mOffsetY, mClipWidth, mClipHeight);
|
||||
}
|
||||
|
||||
onPreSetImageDrawable(drawable, true);
|
||||
if ((source == Conaco.SOURCE_DISK || source == Conaco.SOURCE_NETWORK) && isShown()) {
|
||||
Drawable[] layers = new Drawable[2];
|
||||
layers[0] = new ColorDrawable(Color.TRANSPARENT);
|
||||
@@ -308,7 +311,9 @@ public class LoadImageView extends FixedAspectImageView implements Unikery<Image
|
||||
public void onFailure() {
|
||||
mFailed = true;
|
||||
clearDrawable();
|
||||
setImageDrawable(DrawableManager.getVectorDrawable(getContext(), R.drawable.image_failed));
|
||||
Drawable drawable = DrawableManager.getVectorDrawable(getContext(), R.drawable.image_failed);
|
||||
onPreSetImageDrawable(drawable, true);
|
||||
setImageDrawable(drawable);
|
||||
if (mRetryType == RETRY_TYPE_CLICK) {
|
||||
setOnClickListener(this);
|
||||
} else if (mRetryType == RETRY_TYPE_LONG_CLICK) {
|
||||
@@ -362,4 +367,8 @@ public class LoadImageView extends FixedAspectImageView implements Unikery<Image
|
||||
load(mKey, mUrl, mContainer, true);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void onPreSetImageDrawable(Drawable drawable, boolean isTarget) { }
|
||||
|
||||
public void onPreSetImageResource(int resId, boolean isTarget) { }
|
||||
}
|
||||
@@ -1,99 +0,0 @@
|
||||
/*
|
||||
* Copyright 2018 Hippo Seven
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package okio;
|
||||
|
||||
import static okio.Util.checkOffsetAndCount;
|
||||
|
||||
import com.hippo.unifile.UniRandomAccessFile;
|
||||
import java.io.IOException;
|
||||
|
||||
public class UniRandomAccessFileStore implements Store {
|
||||
|
||||
private UniRandomAccessFile file;
|
||||
private Timeout timeout;
|
||||
|
||||
public UniRandomAccessFileStore(UniRandomAccessFile file) {
|
||||
this(file, new Timeout());
|
||||
}
|
||||
|
||||
public UniRandomAccessFileStore(UniRandomAccessFile file, Timeout timeout) {
|
||||
this.file = file;
|
||||
this.timeout = timeout;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void seek(long position) throws IOException {
|
||||
file.seek(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long tell() throws IOException {
|
||||
return file.getFilePointer();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long size() throws IOException {
|
||||
return file.length();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long read(Buffer sink, long byteCount) throws IOException {
|
||||
if (byteCount < 0) throw new IllegalArgumentException("byteCount < 0: " + byteCount);
|
||||
if (byteCount == 0) return 0;
|
||||
timeout.throwIfReached();
|
||||
Segment tail = sink.writableSegment(1);
|
||||
int maxToCopy = (int) Math.min(byteCount, Segment.SIZE - tail.limit);
|
||||
int bytesRead = file.read(tail.data, tail.limit, maxToCopy);
|
||||
if (bytesRead == -1) return -1;
|
||||
tail.limit += bytesRead;
|
||||
sink.size += bytesRead;
|
||||
return bytesRead;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(Buffer source, long byteCount) throws IOException {
|
||||
checkOffsetAndCount(source.size, 0, byteCount);
|
||||
while (byteCount > 0) {
|
||||
timeout.throwIfReached();
|
||||
Segment head = source.head;
|
||||
int toCopy = (int) Math.min(byteCount, head.limit - head.pos);
|
||||
file.write(head.data, head.pos, toCopy);
|
||||
|
||||
head.pos += toCopy;
|
||||
byteCount -= toCopy;
|
||||
source.size -= toCopy;
|
||||
|
||||
if (head.pos == head.limit) {
|
||||
source.head = head.pop();
|
||||
SegmentPool.recycle(head);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void flush() { }
|
||||
|
||||
@Override
|
||||
public Timeout timeout() {
|
||||
return timeout;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
file.close();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
~ Copyright 2019 Hippo Seven
|
||||
~
|
||||
~ Licensed under the Apache License, Version 2.0 (the "License");
|
||||
~ you may not use this file except in compliance with the License.
|
||||
~ You may obtain a copy of the License at
|
||||
~
|
||||
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||
~
|
||||
~ Unless required by applicable law or agreed to in writing, software
|
||||
~ distributed under the License is distributed on an "AS IS" BASIS,
|
||||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
~ See the License for the specific language governing permissions and
|
||||
~ limitations under the License.
|
||||
-->
|
||||
|
||||
<vector
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:height="24dp"
|
||||
android:width="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
|
||||
<path
|
||||
android:fillColor="@color/primary_drawable_dark"
|
||||
android:pathData="@string/pd_download"/>
|
||||
|
||||
</vector>
|
||||
@@ -25,14 +25,14 @@
|
||||
android:paddingBottom="@dimen/keyline_margin">
|
||||
|
||||
<HorizontalScrollView
|
||||
android:id="@+id/actions_scroll_view"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:paddingLeft="@dimen/keyline_margin"
|
||||
android:paddingRight="@dimen/keyline_margin"
|
||||
android:clipToPadding="false"
|
||||
android:scrollbars="none"
|
||||
android:overScrollMode="never">
|
||||
android:scrollbars="none">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
|
||||
@@ -27,10 +27,13 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<com.hippo.widget.LoadImageView
|
||||
<com.hippo.ehviewer.widget.FixedThumb
|
||||
android:id="@+id/thumb"
|
||||
android:layout_width="@dimen/gallery_list_thumb_width"
|
||||
android:layout_height="@dimen/gallery_list_thumb_height"/>
|
||||
android:layout_height="@dimen/gallery_list_thumb_height"
|
||||
app:retryType="longClick"
|
||||
app:minAspect="0.333"
|
||||
app:maxAspect="1.333"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/title"
|
||||
|
||||
@@ -26,11 +26,13 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<com.hippo.widget.LoadImageView
|
||||
<com.hippo.ehviewer.widget.FixedThumb
|
||||
android:id="@+id/thumb"
|
||||
android:layout_width="@dimen/gallery_list_thumb_width"
|
||||
android:layout_height="@dimen/gallery_list_thumb_height"
|
||||
app:retryType="click"/>
|
||||
app:retryType="click"
|
||||
app:minAspect="0.333"
|
||||
app:maxAspect="1.333"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/title"
|
||||
|
||||
@@ -21,13 +21,15 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<com.hippo.widget.LoadImageView
|
||||
<com.hippo.ehviewer.widget.FixedThumb
|
||||
xmlns:auto="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/image"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
auto:aspect="0.667"
|
||||
auto:retryType="longClick"/>
|
||||
auto:retryType="longClick"
|
||||
auto:minAspect="0.5"
|
||||
auto:maxAspect="0.8"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text"
|
||||
|
||||
@@ -44,6 +44,13 @@
|
||||
android:paddingRight="@dimen/corner_fab_margin"
|
||||
android:paddingBottom="@dimen/corner_fab_margin">
|
||||
|
||||
<android.support.design.widget.FloatingActionButton
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
app:srcCompat="@drawable/v_download_dark_x24"
|
||||
app:backgroundTint="?attr/widgetColorThemeAccent"
|
||||
style="@style/Widget.Design.FloatingActionButton.Mini"/>
|
||||
|
||||
<android.support.design.widget.FloatingActionButton
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
|
||||
@@ -433,6 +433,8 @@
|
||||
<string name="settings_eh_show_jpn_title_summary_off">显示默认标题。一般是英文标题</string>
|
||||
<string name="settings_eh_show_gallery_pages">显示画廊页数</string>
|
||||
<string name="settings_eh_show_gallery_pages_summary">在画廊列表中显示页数。这会使获取画廊列表花费更多时间</string>
|
||||
<string name="settings_eh_show_tag_translations">显示标签翻译</string>
|
||||
<string name="settings_eh_show_tag_translations_summary">显示翻译后的标签而非原始文字(需花费时间来下载数据文件)</string>
|
||||
<string name="settings_eh_filter">过滤</string>
|
||||
<string name="settings_eh_filter_summary">过滤标题,上传者,标签和标签组</string>
|
||||
<string name="settings_eh_cellular_network_warning">移动网络警告</string>
|
||||
|
||||
@@ -432,6 +432,8 @@
|
||||
<string name="settings_eh_show_jpn_title_summary_off">顯示默認標題。一般是英文標題</string>
|
||||
<string name="settings_eh_show_gallery_pages">顯示畫廊頁數</string>
|
||||
<string name="settings_eh_show_gallery_pages_summary">在畫廊列表中顯示頁數。這會使獲取畫廊列表花費更多時間</string>
|
||||
<string name="settings_eh_show_tag_translations">顯示標籤翻譯</string>
|
||||
<string name="settings_eh_show_tag_translations_summary">顯示翻譯後的標籤而非原始文字(需花費時間來下載數據文件)</string>
|
||||
<string name="settings_eh_filter">過濾</string>
|
||||
<string name="settings_eh_filter_summary">過濾標題,上傳者,標籤和標籤組</string>
|
||||
<string name="settings_eh_cellular_network_warning">移動網絡警告</string>
|
||||
|
||||
@@ -432,6 +432,8 @@
|
||||
<string name="settings_eh_show_jpn_title_summary_off">顯示預設的標題。通常是英文的</string>
|
||||
<string name="settings_eh_show_gallery_pages">顯示圖庫頁數</string>
|
||||
<string name="settings_eh_show_gallery_pages_summary">在圖庫列表中顯示頁數。這會使取得圖庫列表時間增加</string>
|
||||
<string name="settings_eh_show_tag_translations">顯示標籤翻譯</string>
|
||||
<string name="settings_eh_show_tag_translations_summary">顯示翻譯後的標籤而非原始文字(需花費時間來下載資料檔案)</string>
|
||||
<string name="settings_eh_filter">篩選</string>
|
||||
<string name="settings_eh_filter_summary">篩選標題,上傳者,標籤和標籤命名空間</string>
|
||||
<string name="settings_eh_cellular_network_warning">行動數據警告</string>
|
||||
|
||||
@@ -92,6 +92,11 @@
|
||||
</attr>
|
||||
</declare-styleable>
|
||||
|
||||
<declare-styleable name="FixedThumb">
|
||||
<attr name="minAspect" format="float"/>
|
||||
<attr name="maxAspect" format="float"/>
|
||||
</declare-styleable>
|
||||
|
||||
<declare-styleable name="CheckTextView">
|
||||
<attr name="maskColor" format="color"/>
|
||||
</declare-styleable>
|
||||
|
||||
@@ -476,6 +476,8 @@
|
||||
<string name="settings_eh_show_jpn_title_summary_off">Show default titles, which are usually in English.</string>
|
||||
<string name="settings_eh_show_gallery_pages">Show gallery pages</string>
|
||||
<string name="settings_eh_show_gallery_pages_summary">Display the number of pages in the gallery list. It takes more time to load the gallery list</string>
|
||||
<string name="settings_eh_show_tag_translations">Show tag translations</string>
|
||||
<string name="settings_eh_show_tag_translations_summary">Show tag translations instead of the original text (It takes time to download the data file)</string>
|
||||
<string name="settings_eh_filter">Filter</string>
|
||||
<string name="settings_eh_filter_summary">Filter by title, uploader, tag and tag namespace</string>
|
||||
<string name="settings_eh_cellular_network_warning">Cellular network warning</string>
|
||||
|
||||
@@ -106,6 +106,12 @@
|
||||
android:summary="@string/settings_eh_show_gallery_pages_summary"
|
||||
android:defaultValue="false"/>
|
||||
|
||||
<com.hippo.preference.SwitchPreference
|
||||
android:key="show_tag_translations"
|
||||
android:title="@string/settings_eh_show_tag_translations"
|
||||
android:summary="@string/settings_eh_show_tag_translations_summary"
|
||||
android:defaultValue="false"/>
|
||||
|
||||
<com.hippo.preference.ActivityPreference
|
||||
android:key="filter"
|
||||
android:title="@string/settings_eh_filter"
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright 2019 Hippo Seven
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.hippo.ehviewer.client;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import okio.BufferedSource;
|
||||
import okio.Okio;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
@Config(manifest = Config.NONE)
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class EhTagDatabaseTest {
|
||||
|
||||
@Test
|
||||
public void readTheList() throws IOException {
|
||||
InputStream resource = EhTagDatabaseTest.class.getResourceAsStream("EhTagDatabaseTest");
|
||||
if (resource == null) return;
|
||||
|
||||
EhTagDatabase db;
|
||||
try (BufferedSource source = Okio.buffer(Okio.source(resource))) {
|
||||
db = new EhTagDatabase("EhTagDatabaseTest", source);
|
||||
}
|
||||
|
||||
assertEquals("a", db.getTranslation("1"));
|
||||
assertEquals("ab", db.getTranslation("12"));
|
||||
assertEquals("abc", db.getTranslation("123"));
|
||||
assertEquals("abcd", db.getTranslation("1234"));
|
||||
assertEquals("1", db.getTranslation("a"));
|
||||
assertEquals("12", db.getTranslation("ab"));
|
||||
assertEquals("123", db.getTranslation("abc"));
|
||||
assertEquals("1234", db.getTranslation("abcd"));
|
||||
assertNull(db.getTranslation("21"));
|
||||
}
|
||||
}
|
||||
@@ -43,6 +43,7 @@ public class GalleryDetailUrlParserTest {
|
||||
{ "530350/8b3c7e4a21", false, false, 530350, "8b3c7e4a21" },
|
||||
{ "g/530350/8b3c7e4a21", false, false, 530350, "8b3c7e4a21" },
|
||||
{ "530350b/8b3c7e4a21", false, true, 0, null },
|
||||
{ "530350/8b3c7e4a211", false, true, 0, null },
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Binary file not shown.
+1
-1
@@ -8,7 +8,7 @@ buildscript {
|
||||
maven { url "https://jitpack.io" }
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:3.2.1'
|
||||
classpath 'com.android.tools.build:gradle:3.3.0'
|
||||
classpath 'com.google.gms:google-services:4.2.0'
|
||||
classpath 'io.fabric.tools:gradle:1.26.1'
|
||||
classpath 'com.github.seven332:android-chinese-string-gradle-plugin:0.1.0'
|
||||
|
||||
+6
-6
@@ -1,6 +1,6 @@
|
||||
#Sat Oct 06 17:54:20 CST 2018
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
|
||||
#Wed Jan 16 18:10:40 CST 2019
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.3-all.zip
|
||||
Reference in new issue
Block a user