mirror of
https://github.com/seven332/EhViewer
synced 2026-12-01 03:28:03 +08:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
116f30e496 | ||
|
|
e8d05c273f | ||
|
|
29e3a50cd3 | ||
|
|
1409571ad8 | ||
|
|
8a7e72c412 | ||
|
|
948cb9ef9c | ||
|
|
926391a0fe | ||
|
|
24195430ab | ||
|
|
c9afa597d5 | ||
|
|
adf38af673 | ||
|
|
17f2bb670e | ||
|
|
2293654da8 | ||
|
|
36067c9fac | ||
|
|
8d20621ad4 | ||
|
|
a1d1db14c6 | ||
|
|
44cf2b67d0 | ||
|
|
74c0e478ef | ||
|
|
7496534b30 | ||
|
|
415ffbc21d | ||
|
|
ed4267cb36 | ||
|
|
2de859398b | ||
|
|
62348433df | ||
|
|
b64b14c69a | ||
|
|
28e8e91303 | ||
|
|
44026f0ccc | ||
|
|
95f2d46420 | ||
|
|
8f76f50526 | ||
|
|
ecd215d632 | ||
|
|
b138de9563 | ||
|
|
9bd344cc58 | ||
|
|
ababfd57a6 | ||
|
|
45c760a507 | ||
|
|
e721a6da1f | ||
|
|
9eeba868d5 | ||
|
|
8f3247bac4 | ||
|
|
e5a375c3fe | ||
|
|
8d75752835 | ||
|
|
8af786e687 | ||
|
|
4b1c516b3e | ||
|
|
f32b79ba72 | ||
|
|
92b5f2d766 | ||
|
|
a5767e0fe6 | ||
|
|
2fc48bb726 | ||
|
|
4a5a426fd3 | ||
|
|
06adf8594c | ||
|
|
1ac43e6293 | ||
|
|
ceeb84812b | ||
|
|
bfd85e9bc7 | ||
|
|
8c3796605e | ||
|
|
3214bae157 | ||
|
|
a5b178df49 | ||
|
|
c2a93f2ce4 | ||
|
|
257758b27d | ||
|
|
2681e4a6e6 | ||
|
|
722653ac46 | ||
|
|
cb706941c5 | ||
|
|
195e9a5655 | ||
|
|
ed2043ab7a | ||
|
|
405655d0e2 | ||
|
|
0cead11180 |
No files matched your search
+13
-10
@@ -10,11 +10,14 @@ android {
|
||||
applicationId "com.hippo.ehviewer"
|
||||
minSdkVersion 14
|
||||
targetSdkVersion 28
|
||||
versionCode 87
|
||||
versionName "1.3.0"
|
||||
versionCode 91
|
||||
versionName "1.3.4"
|
||||
vectorDrawables.useSupportLibrary = true
|
||||
resConfigs "zh", "zh-rCN", "zh-rHK", "zh-rTW",
|
||||
"es", "ja", "ko", "fr", "de"
|
||||
ndk {
|
||||
abiFilters "armeabi-v7a", "x86"
|
||||
}
|
||||
}
|
||||
|
||||
compileOptions {
|
||||
@@ -67,13 +70,13 @@ dependencies {
|
||||
implementation "com.android.support:cardview-v7:$supportLibrary"
|
||||
implementation "com.android.support:design:$supportLibrary"
|
||||
implementation 'com.google.firebase:firebase-core:16.0.6'
|
||||
implementation 'com.crashlytics.sdk.android:crashlytics:2.9.7'
|
||||
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: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.commons-compress:android-lite:464e96d3b4'
|
||||
implementation 'com.github.seven332:conaco:0.1.5-eh'
|
||||
implementation 'com.github.seven332:drawerlayout:0.2.1'
|
||||
implementation 'com.github.seven332:easyrecyclerview:0.1.1'
|
||||
@@ -82,17 +85,16 @@ dependencies {
|
||||
implementation 'com.github.seven332:glview-image:0.1.0'
|
||||
implementation 'com.github.seven332:hotspot:0.1.0'
|
||||
implementation 'com.github.seven332:image:0.1.12'
|
||||
implementation 'com.github.seven332.junrar:android-lite:46ecc9630a'
|
||||
implementation 'com.github.seven332:okhttp:3.5.0'
|
||||
implementation 'com.github.seven332:refreshlayout:0.1.0'
|
||||
implementation 'com.github.seven332:ripple:0.1.2'
|
||||
implementation 'com.github.seven332:streampipe:0.1.0'
|
||||
implementation 'com.github.seven332:tuxiang:0.1.2'
|
||||
implementation 'com.github.seven332:unifile:2de815c5ed'
|
||||
implementation 'com.github.seven332:unifile:9ec57bcd8f'
|
||||
implementation 'com.github.seven332:yorozuya:0.1.2'
|
||||
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.9.2'
|
||||
implementation 'com.h6ah4i.android.widget.advrecyclerview:advrecyclerview:0.11.0'
|
||||
implementation 'com.squareup.okhttp3:okhttp:3.12.0'
|
||||
implementation 'org.ccil.cowan.tagsoup:tagsoup:1.2.1'
|
||||
implementation 'org.greenrobot:greendao:2.2.1'
|
||||
@@ -104,9 +106,10 @@ dependencies {
|
||||
|
||||
configurations.all {
|
||||
resolutionStrategy {
|
||||
force 'com.github.seven332:glgallery:c56b14c6fa'
|
||||
force 'com.github.seven332:glview-image:4c744db'
|
||||
force 'com.github.seven332:image:bbf0bbb0a0'
|
||||
force 'com.github.seven332:glgallery:bb2a43fdd5'
|
||||
force 'com.github.seven332:glview:cc3f18d1b2'
|
||||
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'
|
||||
|
||||
@@ -35,6 +35,11 @@ public abstract class PrettyPreferenceActivity extends AppCompatPreferenceActivi
|
||||
|
||||
@Override
|
||||
public void setListAdapter(ListAdapter adapter) {
|
||||
if (adapter == null) {
|
||||
super.setListAdapter(null);
|
||||
return;
|
||||
}
|
||||
|
||||
int count = adapter.getCount();
|
||||
List<PreferenceActivity.Header> headers = new ArrayList<>(count);
|
||||
for (int i = 0; i < count; ++i) {
|
||||
|
||||
@@ -17,14 +17,32 @@
|
||||
package com.hippo.ehviewer;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import com.google.firebase.analytics.FirebaseAnalytics;
|
||||
import com.hippo.scene.SceneFragment;
|
||||
|
||||
|
||||
public final class Analytics {
|
||||
|
||||
private static FirebaseAnalytics analytics;
|
||||
|
||||
private Analytics() {}
|
||||
|
||||
public static void start(Context context) {
|
||||
FirebaseAnalytics.getInstance(context).setUserId(Settings.getUserID());
|
||||
analytics = FirebaseAnalytics.getInstance(context);
|
||||
analytics.setUserId(Settings.getUserID());
|
||||
}
|
||||
|
||||
public static boolean isEnabled() {
|
||||
return analytics != null && Settings.getEnableAnalytics();
|
||||
}
|
||||
|
||||
public static void onSceneView(SceneFragment scene) {
|
||||
if (isEnabled()) {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString("scene_simple_class", scene.getClass().getSimpleName());
|
||||
bundle.putString("scene_class", scene.getClass().getName());
|
||||
analytics.logEvent("scene_view", bundle);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -16,16 +16,22 @@
|
||||
|
||||
package com.hippo.ehviewer;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.content.ComponentCallbacks2;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.ServiceConnection;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Debug;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.util.LruCache;
|
||||
import android.util.Log;
|
||||
import com.hippo.a7zip.A7Zip;
|
||||
import com.hippo.beerbelly.SimpleDiskCache;
|
||||
import com.hippo.conaco.Conaco;
|
||||
import com.hippo.content.RecordingApplication;
|
||||
@@ -43,6 +49,7 @@ import com.hippo.network.StatusCodeException;
|
||||
import com.hippo.text.Html;
|
||||
import com.hippo.unifile.UniFile;
|
||||
import com.hippo.util.BitmapUtils;
|
||||
import com.hippo.util.ExceptionUtils;
|
||||
import com.hippo.util.ReadableTime;
|
||||
import com.hippo.yorozuya.FileUtils;
|
||||
import com.hippo.yorozuya.IntIdGenerator;
|
||||
@@ -59,9 +66,9 @@ import okhttp3.OkHttpClient;
|
||||
public class EhApplication extends RecordingApplication {
|
||||
|
||||
private static final String TAG = EhApplication.class.getSimpleName();
|
||||
private static final String KEY_GLOBAL_STUFF_NEXT_ID = "global_stuff_next_id";
|
||||
|
||||
public static final boolean BETA = false;
|
||||
public static final boolean AUTO_UPDATE = true;
|
||||
|
||||
private static final boolean DEBUG_CONACO = false;
|
||||
private static final boolean DEBUG_PRINT_NATIVE_MEMORY = false;
|
||||
@@ -82,6 +89,7 @@ public class EhApplication extends RecordingApplication {
|
||||
|
||||
private final List<Activity> mActivityList = new ArrayList<>();
|
||||
|
||||
@SuppressLint("StaticFieldLeak")
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
@@ -96,6 +104,8 @@ public class EhApplication extends RecordingApplication {
|
||||
EhDB.initialize(this);
|
||||
EhEngine.initialize();
|
||||
BitmapUtils.initialize(this);
|
||||
Image.initialize(this);
|
||||
A7Zip.initialize(this);
|
||||
|
||||
if (EhDB.needMerge()) {
|
||||
EhDB.mergeOldDB(this);
|
||||
@@ -105,17 +115,32 @@ public class EhApplication extends RecordingApplication {
|
||||
Analytics.start(this);
|
||||
}
|
||||
|
||||
// Disable no media file checker for now. Some devices stuck here.
|
||||
// // Check no media file
|
||||
// UniFile downloadLocation = Settings.getDownloadLocation();
|
||||
// if (Settings.getMediaScan()) {
|
||||
// CommonOperations.removeNoMediaFile(downloadLocation);
|
||||
// } else {
|
||||
// CommonOperations.ensureNoMediaFile(downloadLocation);
|
||||
// }
|
||||
// Do io tasks in new thread
|
||||
new AsyncTask<Void, Void, Void>() {
|
||||
@Override
|
||||
protected Void doInBackground(Void... voids) {
|
||||
// Check no media file
|
||||
try {
|
||||
UniFile downloadLocation = Settings.getDownloadLocation();
|
||||
if (Settings.getMediaScan()) {
|
||||
CommonOperations.removeNoMediaFile(downloadLocation);
|
||||
} else {
|
||||
CommonOperations.ensureNoMediaFile(downloadLocation);
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
ExceptionUtils.throwIfFatal(t);
|
||||
}
|
||||
|
||||
// Clear temp dir
|
||||
clearTempDir();
|
||||
// Clear temp files
|
||||
try {
|
||||
clearTempDir();
|
||||
} catch (Throwable t) {
|
||||
ExceptionUtils.throwIfFatal(t);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}.doInBackground();
|
||||
|
||||
// Check app update
|
||||
update();
|
||||
@@ -128,6 +153,8 @@ public class EhApplication extends RecordingApplication {
|
||||
// Ignore
|
||||
}
|
||||
|
||||
mIdGenerator.setNextId(Settings.getInt(KEY_GLOBAL_STUFF_NEXT_ID, 0));
|
||||
|
||||
if (DEBUG_PRINT_NATIVE_MEMORY || DEBUG_PRINT_IMAGE_COUNT) {
|
||||
debugPrint();
|
||||
}
|
||||
@@ -191,6 +218,7 @@ public class EhApplication extends RecordingApplication {
|
||||
public int putGlobalStuff(@NonNull Object o) {
|
||||
int id = mIdGenerator.nextId();
|
||||
mGlobalStuffMap.put(id, o);
|
||||
Settings.putInt(KEY_GLOBAL_STUFF_NEXT_ID, mIdGenerator.nextId());
|
||||
return id;
|
||||
}
|
||||
|
||||
@@ -332,4 +360,26 @@ public class EhApplication extends RecordingApplication {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// Avoid crash on some "energy saving" devices
|
||||
@Override
|
||||
public ComponentName startService(Intent service) {
|
||||
try {
|
||||
return super.startService(service);
|
||||
} catch (Throwable t) {
|
||||
ExceptionUtils.throwIfFatal(t);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// Avoid crash on some "energy saving" devices
|
||||
@Override
|
||||
public boolean bindService(Intent service, ServiceConnection conn, int flags) {
|
||||
try {
|
||||
return super.bindService(service, conn, flags);
|
||||
} catch (Throwable t) {
|
||||
ExceptionUtils.throwIfFatal(t);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -43,6 +43,7 @@ import com.hippo.ehviewer.dao.LocalFavoritesDao;
|
||||
import com.hippo.ehviewer.dao.QuickSearch;
|
||||
import com.hippo.ehviewer.dao.QuickSearchDao;
|
||||
import com.hippo.ehviewer.download.DownloadManager;
|
||||
import com.hippo.util.ExceptionUtils;
|
||||
import com.hippo.util.SqlUtils;
|
||||
import com.hippo.yorozuya.FileUtils;
|
||||
import com.hippo.yorozuya.IOUtils;
|
||||
@@ -156,7 +157,8 @@ public class EhDB {
|
||||
SQLiteDatabase oldDB;
|
||||
try {
|
||||
oldDB = oldDBHelper.getReadableDatabase();
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -178,7 +180,8 @@ public class EhDB {
|
||||
try {
|
||||
// In 0.6.x version, NaN is stored
|
||||
gi.rating = cursor.getFloat(7);
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
gi.rating = -1.0f;
|
||||
}
|
||||
|
||||
@@ -189,7 +192,8 @@ public class EhDB {
|
||||
}
|
||||
cursor.close();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
// Ignore
|
||||
}
|
||||
|
||||
@@ -219,7 +223,8 @@ public class EhDB {
|
||||
}
|
||||
cursor.close();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
// Ignore
|
||||
}
|
||||
|
||||
@@ -255,7 +260,8 @@ public class EhDB {
|
||||
}
|
||||
cursor.close();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
// Ignore
|
||||
}
|
||||
|
||||
@@ -296,7 +302,8 @@ public class EhDB {
|
||||
}
|
||||
cursor.close();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
// Ignore
|
||||
}
|
||||
|
||||
@@ -325,13 +332,15 @@ public class EhDB {
|
||||
}
|
||||
cursor.close();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
// Ignore
|
||||
}
|
||||
|
||||
try {
|
||||
oldDBHelper.close();
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
// Ignore
|
||||
}
|
||||
}
|
||||
@@ -726,7 +735,8 @@ public class EhDB {
|
||||
}
|
||||
|
||||
return null;
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
// Ignore
|
||||
return context.getString(R.string.cant_read_the_file);
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ import com.hippo.ehviewer.client.data.FavListUrlBuilder;
|
||||
import com.hippo.ehviewer.ui.CommonOperations;
|
||||
import com.hippo.glgallery.GalleryView;
|
||||
import com.hippo.unifile.UniFile;
|
||||
import com.hippo.util.ExceptionUtils;
|
||||
import com.hippo.yorozuya.AssertUtils;
|
||||
import com.hippo.yorozuya.FileUtils;
|
||||
import com.hippo.yorozuya.MathUtils;
|
||||
@@ -633,7 +634,8 @@ public class Settings {
|
||||
builder.encodedQuery(getString(KEY_DOWNLOAD_SAVE_QUERY, null));
|
||||
builder.encodedFragment(getString(KEY_DOWNLOAD_SAVE_FRAGMENT, null));
|
||||
dir = UniFile.fromUri(sContext, builder.build());
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
// Ignore
|
||||
}
|
||||
return dir != null ? dir : UniFile.fromFile(AppConfig.getDefaultDownloadDir());
|
||||
@@ -974,8 +976,8 @@ public class Settings {
|
||||
********************/
|
||||
private static final String KEY_BETA_UPDATE_CHANNEL = "beta_update_channel";
|
||||
private static final boolean DEFAULT_BETA_UPDATE_CHANNEL = EhApplication.BETA;
|
||||
private static final String KEY_AUTO_CHECK_FOR_UPDATES = "auto_check_for_updates";
|
||||
private static final boolean DEFAULT_AUTO_CHECK_FOR_UPDATES = EhApplication.AUTO_UPDATE;
|
||||
private static final String KEY_SKIP_UPDATE_VERSION = "skip_update_version";
|
||||
private static final int DEFAULT_SKIP_UPDATE_VERSION = 0;
|
||||
|
||||
public static boolean getBetaUpdateChannel() {
|
||||
return getBoolean(KEY_BETA_UPDATE_CHANNEL, DEFAULT_BETA_UPDATE_CHANNEL);
|
||||
@@ -985,8 +987,12 @@ public class Settings {
|
||||
putBoolean(KEY_BETA_UPDATE_CHANNEL, value);
|
||||
}
|
||||
|
||||
public static boolean getAutoCheckUpdateEnable() {
|
||||
return getBoolean(KEY_AUTO_CHECK_FOR_UPDATES, DEFAULT_AUTO_CHECK_FOR_UPDATES);
|
||||
public static int getSkipUpdateVersion() {
|
||||
return getInt(KEY_SKIP_UPDATE_VERSION, DEFAULT_SKIP_UPDATE_VERSION);
|
||||
}
|
||||
|
||||
public static void putSkipUpdateVersion(int value) {
|
||||
putInt(KEY_SKIP_UPDATE_VERSION, value);
|
||||
}
|
||||
|
||||
/********************
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package com.hippo.ehviewer;
|
||||
|
||||
import android.content.ActivityNotFoundException;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
@@ -24,11 +23,11 @@ import android.provider.Browser;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.text.TextUtils;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.hippo.ehviewer.client.EhUrlOpener;
|
||||
import com.hippo.ehviewer.ui.MainActivity;
|
||||
import com.hippo.scene.Announcer;
|
||||
import com.hippo.scene.StageActivity;
|
||||
import com.hippo.util.ExceptionUtils;
|
||||
|
||||
public final class UrlOpener {
|
||||
|
||||
@@ -61,7 +60,8 @@ public final class UrlOpener {
|
||||
intent.putExtra(Browser.EXTRA_APPLICATION_ID, context.getPackageName());
|
||||
try {
|
||||
context.startActivity(intent);
|
||||
} catch (ActivityNotFoundException e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
Toast.makeText(context, R.string.error_cant_find_activity, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,13 +18,12 @@ package com.hippo.ehviewer.client;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.AsyncTask;
|
||||
|
||||
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.yorozuya.SimpleHandler;
|
||||
import com.hippo.yorozuya.thread.PriorityThreadFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
@@ -34,7 +33,6 @@ 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;
|
||||
import okhttp3.OkHttpClient;
|
||||
|
||||
@@ -193,7 +191,8 @@ public class EhClient {
|
||||
default:
|
||||
return new IllegalStateException("Can't detect method " + mMethod);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
return e;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,7 +40,10 @@ public class EhDns implements Dns {
|
||||
static {
|
||||
Map<String, InetAddress> map = new HashMap<>();
|
||||
put(map, "e-hentai.org", "104.24.255.11");
|
||||
put(map, "repo.e-hentai.org", "94.100.29.73");
|
||||
put(map, "forums.e-hentai.org", "94.100.18.243");
|
||||
put(map, "ehgt.org", "81.171.14.118");
|
||||
put(map, "ul.ehgt.org", "94.100.24.82");
|
||||
builtInHosts = map;
|
||||
}
|
||||
|
||||
|
||||
@@ -47,6 +47,7 @@ import com.hippo.ehviewer.client.parser.TorrentParser;
|
||||
import com.hippo.ehviewer.client.parser.VoteCommentParser;
|
||||
import com.hippo.ehviewer.client.parser.WhatsHotParser;
|
||||
import com.hippo.network.StatusCodeException;
|
||||
import com.hippo.util.ExceptionUtils;
|
||||
import com.hippo.yorozuya.AssertUtils;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
@@ -88,7 +89,7 @@ public class EhEngine {
|
||||
}
|
||||
|
||||
private static void doThrowException(Call call, int code, @Nullable Headers headers,
|
||||
@Nullable String body, Exception e) throws Exception {
|
||||
@Nullable String body, Throwable e) throws Throwable {
|
||||
if (call.isCanceled()) {
|
||||
throw new CancelledException();
|
||||
}
|
||||
@@ -121,7 +122,7 @@ public class EhEngine {
|
||||
}
|
||||
|
||||
private static void throwException(Call call, int code, @Nullable Headers headers,
|
||||
@Nullable String body, Exception e) throws Exception {
|
||||
@Nullable String body, Throwable e) throws Throwable {
|
||||
try {
|
||||
doThrowException(call, code, headers, body, e);
|
||||
} catch (Throwable error) {
|
||||
@@ -131,7 +132,7 @@ public class EhEngine {
|
||||
}
|
||||
|
||||
public static String signIn(@Nullable EhClient.Task task, OkHttpClient okHttpClient,
|
||||
String username, String password, String recaptchaChallenge, String recaptchaResponse) throws Exception {
|
||||
String username, String password, String recaptchaChallenge, String recaptchaResponse) throws Throwable {
|
||||
FormBody.Builder builder = new FormBody.Builder()
|
||||
.add("UserName", username)
|
||||
.add("PassWord", password)
|
||||
@@ -163,14 +164,15 @@ public class EhEngine {
|
||||
headers = response.headers();
|
||||
body = response.body().string();
|
||||
return SignInParser.parse(body);
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
throwException(call, code, headers, body, e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
public static GalleryListParser.Result getGalleryList(@Nullable EhClient.Task task, OkHttpClient okHttpClient,
|
||||
String url) throws Exception {
|
||||
String url) throws Throwable {
|
||||
Log.d(TAG, url);
|
||||
Request request = new EhRequestBuilder(url, null != task ? task.getEhConfig() : Settings.getEhConfig()).build();
|
||||
Call call = okHttpClient.newCall(request);
|
||||
@@ -190,7 +192,8 @@ public class EhEngine {
|
||||
headers = response.headers();
|
||||
body = response.body().string();
|
||||
result = GalleryListParser.parse(body);
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
throwException(call, code, headers, body, e);
|
||||
throw e;
|
||||
}
|
||||
@@ -230,7 +233,7 @@ public class EhEngine {
|
||||
|
||||
// At least, GalleryInfo contain valid gid and token
|
||||
public static List<GalleryInfo> fillGalleryListByApi(@Nullable EhClient.Task task, OkHttpClient okHttpClient,
|
||||
List<GalleryInfo> galleryInfoList) throws Exception {
|
||||
List<GalleryInfo> galleryInfoList) throws Throwable {
|
||||
// We can only request 25 items one time at most
|
||||
final int MAX_REQUEST_SIZE = 25;
|
||||
List<GalleryInfo> requestItems = new ArrayList<>(MAX_REQUEST_SIZE);
|
||||
@@ -245,7 +248,7 @@ public class EhEngine {
|
||||
}
|
||||
|
||||
private static void doFillGalleryListByApi(@Nullable EhClient.Task task, OkHttpClient okHttpClient,
|
||||
List<GalleryInfo> galleryInfoList) throws Exception {
|
||||
List<GalleryInfo> galleryInfoList) throws Throwable {
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("method", "gdata");
|
||||
JSONArray ja = new JSONArray();
|
||||
@@ -279,14 +282,15 @@ public class EhEngine {
|
||||
headers = response.headers();
|
||||
body = response.body().string();
|
||||
GalleryApiParser.parse(body, galleryInfoList);
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
throwException(call, code, headers, body, e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
public static GalleryDetail getGalleryDetail(@Nullable EhClient.Task task, OkHttpClient okHttpClient,
|
||||
String url) throws Exception {
|
||||
String url) throws Throwable {
|
||||
Log.d(TAG, url);
|
||||
Request request = new EhRequestBuilder(url, null != task ? task.getEhConfig() : Settings.getEhConfig()).build();
|
||||
Call call = okHttpClient.newCall(request);
|
||||
@@ -305,7 +309,8 @@ public class EhEngine {
|
||||
headers = response.headers();
|
||||
body = response.body().string();
|
||||
return GalleryDetailParser.parse(body);
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
throwException(call, code, headers, body, e);
|
||||
throw e;
|
||||
}
|
||||
@@ -313,7 +318,7 @@ public class EhEngine {
|
||||
|
||||
|
||||
public static Pair<PreviewSet, Integer> getPreviewSet(
|
||||
@Nullable EhClient.Task task, OkHttpClient okHttpClient, String url) throws Exception {
|
||||
@Nullable EhClient.Task task, OkHttpClient okHttpClient, String url) throws Throwable {
|
||||
Log.d(TAG, url);
|
||||
Request request = new EhRequestBuilder(url, null != task ? task.getEhConfig() : Settings.getEhConfig()).build();
|
||||
Call call = okHttpClient.newCall(request);
|
||||
@@ -333,7 +338,8 @@ public class EhEngine {
|
||||
body = response.body().string();
|
||||
return Pair.create(GalleryDetailParser.parsePreviewSet(body),
|
||||
GalleryDetailParser.parsePreviewPages(body));
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
throwException(call, code, headers, body, e);
|
||||
throw e;
|
||||
}
|
||||
@@ -341,7 +347,7 @@ public class EhEngine {
|
||||
|
||||
public static RateGalleryParser.Result rateGallery(@Nullable EhClient.Task task,
|
||||
OkHttpClient okHttpClient, long apiUid, String apiKey, long gid,
|
||||
String token, float rating) throws Exception {
|
||||
String token, float rating) throws Throwable {
|
||||
final JSONObject json = new JSONObject();
|
||||
json.put("method", "rategallery");
|
||||
json.put("apiuid", apiUid);
|
||||
@@ -371,14 +377,15 @@ public class EhEngine {
|
||||
headers = response.headers();
|
||||
body = response.body().string();
|
||||
return RateGalleryParser.parse(body);
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
throwException(call, code, headers, body, e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
public static GalleryComment[] commentGallery(@Nullable EhClient.Task task,
|
||||
OkHttpClient okHttpClient, String url, String comment) throws Exception {
|
||||
OkHttpClient okHttpClient, String url, String comment) throws Throwable {
|
||||
FormBody.Builder builder = new FormBody.Builder()
|
||||
.add("commenttext_new", comment);
|
||||
Log.d(TAG, url);
|
||||
@@ -408,14 +415,15 @@ public class EhEngine {
|
||||
}
|
||||
|
||||
return GalleryDetailParser.parseComments(document);
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
throwException(call, code, headers, body, e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
public static String getGalleryToken(@Nullable EhClient.Task task, OkHttpClient okHttpClient,
|
||||
long gid, String gtoken, int page) throws Exception {
|
||||
long gid, String gtoken, int page) throws Throwable {
|
||||
JSONObject json = new JSONObject()
|
||||
.put("method", "gtoken")
|
||||
.put("pagelist", new JSONArray().put(
|
||||
@@ -442,14 +450,15 @@ public class EhEngine {
|
||||
headers = response.headers();
|
||||
body = response.body().string();
|
||||
return GalleryTokenApiParser.parse(body);
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
throwException(call, code, headers, body, e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
public static FavoritesParser.Result getFavorites(@Nullable EhClient.Task task, OkHttpClient okHttpClient,
|
||||
String url, boolean callApi) throws Exception {
|
||||
String url, boolean callApi) throws Throwable {
|
||||
Log.d(TAG, url);
|
||||
Request request = new EhRequestBuilder(url, null != task ? task.getEhConfig() : Settings.getEhConfig()).build();
|
||||
Call call = okHttpClient.newCall(request);
|
||||
@@ -469,7 +478,8 @@ public class EhEngine {
|
||||
headers = response.headers();
|
||||
body = response.body().string();
|
||||
result = FavoritesParser.parse(body);
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
throwException(call, code, headers, body, e);
|
||||
throw e;
|
||||
}
|
||||
@@ -492,7 +502,7 @@ public class EhEngine {
|
||||
* @param note max 250 characters
|
||||
*/
|
||||
public static Void addFavorites(@Nullable EhClient.Task task, OkHttpClient okHttpClient,
|
||||
long gid, String token, int dstCat, String note) throws Exception {
|
||||
long gid, String token, int dstCat, String note) throws Throwable {
|
||||
String catStr;
|
||||
if (dstCat == -1) {
|
||||
catStr = "favdel";
|
||||
@@ -528,7 +538,8 @@ public class EhEngine {
|
||||
headers = response.headers();
|
||||
body = response.body().string();
|
||||
throwException(call, code, headers, body, null);
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
throwException(call, code, headers, body, e);
|
||||
throw e;
|
||||
}
|
||||
@@ -537,7 +548,7 @@ public class EhEngine {
|
||||
}
|
||||
|
||||
public static Void addFavoritesRange(@Nullable EhClient.Task task, OkHttpClient okHttpClient,
|
||||
long[] gidArray, String[] tokenArray, int dstCat) throws Exception {
|
||||
long[] gidArray, String[] tokenArray, int dstCat) throws Throwable {
|
||||
AssertUtils.assertEquals(gidArray.length, tokenArray.length);
|
||||
for (int i = 0, n = gidArray.length; i < n; i++) {
|
||||
addFavorites(task, okHttpClient, gidArray[i], tokenArray[i], dstCat, null);
|
||||
@@ -546,7 +557,7 @@ public class EhEngine {
|
||||
}
|
||||
|
||||
public static FavoritesParser.Result modifyFavorites(@Nullable EhClient.Task task, OkHttpClient okHttpClient,
|
||||
String url, long[] gidArray, int dstCat, boolean callApi) throws Exception {
|
||||
String url, long[] gidArray, int dstCat, boolean callApi) throws Throwable {
|
||||
String catStr;
|
||||
if (dstCat == -1) {
|
||||
catStr = "delete";
|
||||
@@ -582,7 +593,8 @@ public class EhEngine {
|
||||
headers = response.headers();
|
||||
body = response.body().string();
|
||||
result = FavoritesParser.parse(body);
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
throwException(call, code, headers, body, e);
|
||||
throw e;
|
||||
}
|
||||
@@ -600,7 +612,7 @@ public class EhEngine {
|
||||
}
|
||||
|
||||
public static Pair<String, String>[] getTorrentList(@Nullable EhClient.Task task, OkHttpClient okHttpClient,
|
||||
String url) throws Exception {
|
||||
String url) throws Throwable {
|
||||
Log.d(TAG, url);
|
||||
Request request = new EhRequestBuilder(url, null != task ? task.getEhConfig() : Settings.getEhConfig()).build();
|
||||
Call call = okHttpClient.newCall(request);
|
||||
@@ -620,7 +632,8 @@ public class EhEngine {
|
||||
headers = response.headers();
|
||||
body = response.body().string();
|
||||
result = TorrentParser.parse(body);
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
throwException(call, code, headers, body, e);
|
||||
throw e;
|
||||
}
|
||||
@@ -629,7 +642,7 @@ public class EhEngine {
|
||||
}
|
||||
|
||||
public static Pair<String, Pair<String, String>[]> getArchiveList(@Nullable EhClient.Task task, OkHttpClient okHttpClient,
|
||||
String url) throws Exception {
|
||||
String url) throws Throwable {
|
||||
Log.d(TAG, url);
|
||||
Request request = new EhRequestBuilder(url, null != task ? task.getEhConfig() : Settings.getEhConfig()).build();
|
||||
Call call = okHttpClient.newCall(request);
|
||||
@@ -649,7 +662,8 @@ public class EhEngine {
|
||||
headers = response.headers();
|
||||
body = response.body().string();
|
||||
result = ArchiveParser.parse(body);
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
throwException(call, code, headers, body, e);
|
||||
throw e;
|
||||
}
|
||||
@@ -658,7 +672,7 @@ public class EhEngine {
|
||||
}
|
||||
|
||||
public static Void downloadArchive(@Nullable EhClient.Task task, OkHttpClient okHttpClient,
|
||||
long gid, String token, String or, String res) throws Exception {
|
||||
long gid, String token, String or, String res) throws Throwable {
|
||||
if (or == null || or.length() == 0) {
|
||||
throw new EhException("Invalid form param or: " + or);
|
||||
}
|
||||
@@ -688,7 +702,8 @@ public class EhEngine {
|
||||
headers = response.headers();
|
||||
body = response.body().string();
|
||||
throwException(call, code, headers, body, null);
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
throwException(call, code, headers, body, e);
|
||||
throw e;
|
||||
}
|
||||
@@ -702,7 +717,7 @@ public class EhEngine {
|
||||
}
|
||||
|
||||
public static List<GalleryInfo> getWhatsHot(@Nullable EhClient.Task task,
|
||||
OkHttpClient okHttpClient) throws Exception {
|
||||
OkHttpClient okHttpClient) throws Throwable {
|
||||
String url = EhUrl.HOST_E;
|
||||
Log.d(TAG, url);
|
||||
Request request = new EhRequestBuilder(url, null != task ? task.getEhConfig() : Settings.getEhConfig()).build();
|
||||
@@ -723,7 +738,8 @@ public class EhEngine {
|
||||
headers = response.headers();
|
||||
body = response.body().string();
|
||||
list = WhatsHotParser.parse(body);
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
throwException(call, code, headers, body, e);
|
||||
throw e;
|
||||
}
|
||||
@@ -741,7 +757,7 @@ public class EhEngine {
|
||||
}
|
||||
|
||||
private static ProfileParser.Result getProfileInternal(@Nullable EhClient.Task task,
|
||||
OkHttpClient okHttpClient, String url) throws Exception {
|
||||
OkHttpClient okHttpClient, String url) throws Throwable {
|
||||
Log.d(TAG, url);
|
||||
Request request = new EhRequestBuilder(url, null != task ? task.getEhConfig() : Settings.getEhConfig()).build();
|
||||
Call call = okHttpClient.newCall(request);
|
||||
@@ -760,14 +776,15 @@ public class EhEngine {
|
||||
headers = response.headers();
|
||||
body = response.body().string();
|
||||
return ProfileParser.parse(body);
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
throwException(call, code, headers, body, e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
public static ProfileParser.Result getProfile(@Nullable EhClient.Task task,
|
||||
OkHttpClient okHttpClient) throws Exception {
|
||||
OkHttpClient okHttpClient) throws Throwable {
|
||||
String url = EhUrl.URL_FORUMS;
|
||||
Log.d(TAG, url);
|
||||
Request request = new EhRequestBuilder(url, null != task ? task.getEhConfig() : Settings.getEhConfig()).build();
|
||||
@@ -787,14 +804,15 @@ public class EhEngine {
|
||||
headers = response.headers();
|
||||
body = response.body().string();
|
||||
return getProfileInternal(task, okHttpClient, ForumsParser.parse(body));
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
throwException(call, code, headers, body, e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
public static VoteCommentParser.Result voteComment(@Nullable EhClient.Task task, OkHttpClient okHttpClient,
|
||||
long apiUid, String apiKey, long gid, String token, long commentId, int commentVote) throws Exception {
|
||||
long apiUid, String apiKey, long gid, String token, long commentId, int commentVote) throws Throwable {
|
||||
final JSONObject json = new JSONObject();
|
||||
json.put("method", "votecomment");
|
||||
json.put("apiuid", apiUid);
|
||||
@@ -825,7 +843,8 @@ public class EhEngine {
|
||||
headers = response.headers();
|
||||
body = response.body().string();
|
||||
return VoteCommentParser.parse(body, commentVote);
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
throwException(call, code, headers, body, e);
|
||||
throw e;
|
||||
}
|
||||
@@ -835,7 +854,7 @@ public class EhEngine {
|
||||
* @param image Must be jpeg
|
||||
*/
|
||||
public static GalleryListParser.Result imageSearch(@Nullable EhClient.Task task, OkHttpClient okHttpClient,
|
||||
File image, boolean uss, boolean osc, boolean se) throws Exception {
|
||||
File image, boolean uss, boolean osc, boolean se) throws Throwable {
|
||||
MultipartBody.Builder builder = new MultipartBody.Builder();
|
||||
builder.setType(MultipartBody.FORM);
|
||||
builder.addPart(
|
||||
@@ -889,7 +908,8 @@ public class EhEngine {
|
||||
headers = response.headers();
|
||||
body = response.body().string();
|
||||
result = GalleryListParser.parse(body);
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
throwException(call, code, headers, body, e);
|
||||
throw e;
|
||||
}
|
||||
@@ -928,7 +948,7 @@ public class EhEngine {
|
||||
}
|
||||
|
||||
public static GalleryPageParser.Result getGalleryPage(@Nullable EhClient.Task task,
|
||||
OkHttpClient okHttpClient, String url) throws Exception {
|
||||
OkHttpClient okHttpClient, String url) throws Throwable {
|
||||
Log.d(TAG, url);
|
||||
Request request = new EhRequestBuilder(url, null != task ? task.getEhConfig() : Settings.getEhConfig()).build();
|
||||
Call call = okHttpClient.newCall(request);
|
||||
@@ -947,7 +967,8 @@ public class EhEngine {
|
||||
headers = response.headers();
|
||||
body = response.body().string();
|
||||
return GalleryPageParser.parse(body);
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
throwException(call, code, headers, body, e);
|
||||
throw e;
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ public class EhUrl {
|
||||
public static final String UCONFIG_E = HOST_E + "uconfig.php";
|
||||
public static final String UCONFIG_EX = HOST_EX + "uconfig.php";
|
||||
|
||||
private static final String URL_PREFIX_THUMB_E = "https://ehgt.org/t/";
|
||||
private static final String URL_PREFIX_THUMB_E = "https://ul.ehgt.org/";
|
||||
private static final String URL_PREFIX_THUMB_EX = "https://exhentai.org/t/";
|
||||
|
||||
public static String getGalleryDetailUrl(long gid, String token) {
|
||||
|
||||
@@ -21,6 +21,7 @@ import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.client.data.GalleryInfo;
|
||||
import com.hippo.ehviewer.client.exception.EhException;
|
||||
import com.hippo.ehviewer.client.exception.ParseException;
|
||||
import com.hippo.util.ExceptionUtils;
|
||||
import com.hippo.util.JsoupUtils;
|
||||
import com.hippo.yorozuya.AssertUtils;
|
||||
import java.util.List;
|
||||
@@ -58,7 +59,8 @@ public class FavoritesParser {
|
||||
countArray[i] = ParserUtils.parseInt(fp.child(0).text());
|
||||
catArray[i] = ParserUtils.trim(fp.child(2).text());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
e.printStackTrace();
|
||||
throw new ParseException("Parse favorites error", body);
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ package com.hippo.ehviewer.client.parser;
|
||||
|
||||
import com.hippo.ehviewer.client.EhUrl;
|
||||
import com.hippo.ehviewer.client.exception.ParseException;
|
||||
|
||||
import com.hippo.util.ExceptionUtils;
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Document;
|
||||
import org.jsoup.nodes.Element;
|
||||
@@ -31,7 +31,8 @@ public class ForumsParser {
|
||||
Element userlinks = d.getElementById("userlinks");
|
||||
Element child = userlinks.child(0).child(0).child(0);
|
||||
return child.attr("href");
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
throw new ParseException("Parse forums error", body);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,6 @@ package com.hippo.ehviewer.client.parser;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.hippo.ehviewer.Settings;
|
||||
import com.hippo.ehviewer.client.EhUrl;
|
||||
import com.hippo.ehviewer.client.EhUtils;
|
||||
@@ -33,15 +32,10 @@ import com.hippo.ehviewer.client.exception.EhException;
|
||||
import com.hippo.ehviewer.client.exception.OffensiveException;
|
||||
import com.hippo.ehviewer.client.exception.ParseException;
|
||||
import com.hippo.ehviewer.client.exception.PiningException;
|
||||
import com.hippo.util.ExceptionUtils;
|
||||
import com.hippo.util.JsoupUtils;
|
||||
import com.hippo.yorozuya.NumberUtils;
|
||||
import com.hippo.yorozuya.StringUtils;
|
||||
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Document;
|
||||
import org.jsoup.nodes.Element;
|
||||
import org.jsoup.select.Elements;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
@@ -52,6 +46,10 @@ import java.util.Locale;
|
||||
import java.util.TimeZone;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Document;
|
||||
import org.jsoup.nodes.Element;
|
||||
import org.jsoup.select.Elements;
|
||||
|
||||
public class GalleryDetailParser {
|
||||
|
||||
@@ -142,7 +140,8 @@ public class GalleryDetailParser {
|
||||
Element gd1 = gm.getElementById("gd1");
|
||||
try {
|
||||
gd.thumb = parseCoverStyle(StringUtils.trim(gd1.child(0).attr("style")));
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
gd.thumb = "";
|
||||
}
|
||||
|
||||
@@ -168,7 +167,8 @@ public class GalleryDetailParser {
|
||||
String href = gdc.child(0).attr("href");
|
||||
String category = href.substring(href.lastIndexOf('/') + 1);
|
||||
gd.category = EhUtils.getCategory(category);
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
gd.category = EhUtils.UNKNOWN;
|
||||
}
|
||||
|
||||
@@ -193,7 +193,8 @@ public class GalleryDetailParser {
|
||||
for (int i = 0, n = es.size(); i < n; i++) {
|
||||
parseDetailInfo(gd, es.get(i), body);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
// Ignore
|
||||
}
|
||||
|
||||
@@ -235,7 +236,8 @@ public class GalleryDetailParser {
|
||||
gd.favoriteName = StringUtils.trim(gdf.text());
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
throw new ParseException("Can't parse gallery detail", body);
|
||||
}
|
||||
}
|
||||
@@ -317,7 +319,8 @@ public class GalleryDetailParser {
|
||||
}
|
||||
|
||||
return group.size() > 0 ? group : null;
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
@@ -340,7 +343,8 @@ public class GalleryDetailParser {
|
||||
}
|
||||
}
|
||||
return list.toArray(new GalleryTagGroup[list.size()]);
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
e.printStackTrace();
|
||||
return EMPTY_GALLERY_TAG_GROUP_ARRAY;
|
||||
}
|
||||
@@ -412,7 +416,8 @@ public class GalleryDetailParser {
|
||||
// comment
|
||||
comment.comment = JsoupUtils.getElementByClass(element, "c6").html();
|
||||
return comment;
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
@@ -435,7 +440,8 @@ public class GalleryDetailParser {
|
||||
}
|
||||
}
|
||||
return list.toArray(new GalleryComment[list.size()]);
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
e.printStackTrace();
|
||||
return EMPTY_GALLERY_COMMENT_ARRAY;
|
||||
}
|
||||
@@ -474,7 +480,8 @@ public class GalleryDetailParser {
|
||||
try {
|
||||
Elements elements = document.getElementsByClass("ptt").first().child(0).child(0).children();
|
||||
return Integer.parseInt(elements.get(elements.size() - 2).text());
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
e.printStackTrace();
|
||||
throw new ParseException("Can't parse preview pages", body);
|
||||
}
|
||||
@@ -549,7 +556,8 @@ public class GalleryDetailParser {
|
||||
largePreviewSet.addItem(index, imageUrl, pageUrl);
|
||||
}
|
||||
return largePreviewSet;
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
e.printStackTrace();
|
||||
throw new ParseException("Can't parse large preview", body);
|
||||
}
|
||||
|
||||
@@ -19,24 +19,22 @@ package com.hippo.ehviewer.client.parser;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.util.Log;
|
||||
|
||||
import com.hippo.ehviewer.client.EhUtils;
|
||||
import com.hippo.ehviewer.client.data.GalleryInfo;
|
||||
import com.hippo.ehviewer.client.exception.ParseException;
|
||||
import com.hippo.util.ExceptionUtils;
|
||||
import com.hippo.util.JsoupUtils;
|
||||
import com.hippo.yorozuya.NumberUtils;
|
||||
import com.hippo.yorozuya.StringUtils;
|
||||
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Document;
|
||||
import org.jsoup.nodes.Element;
|
||||
import org.jsoup.select.Elements;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Document;
|
||||
import org.jsoup.nodes.Element;
|
||||
import org.jsoup.select.Elements;
|
||||
|
||||
public class GalleryListParser {
|
||||
|
||||
@@ -54,7 +52,8 @@ public class GalleryListParser {
|
||||
try {
|
||||
Elements es = d.getElementsByClass("ptt").first().child(0).child(0).children();
|
||||
return Integer.parseInt(es.get(es.size() - 2).text().trim());
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
throw new ParseException("Can't parse gallery list pages", body);
|
||||
}
|
||||
}
|
||||
@@ -265,7 +264,8 @@ public class GalleryListParser {
|
||||
}
|
||||
}
|
||||
result.galleryInfoList = list;
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
throw new ParseException("Can't parse gallery list", body);
|
||||
}
|
||||
|
||||
@@ -281,7 +281,8 @@ public class GalleryListParser {
|
||||
}
|
||||
}
|
||||
result.galleryInfoList = list;
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
throw new ParseException("Can't parse gallery list", body);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
package com.hippo.ehviewer.client.parser;
|
||||
|
||||
import com.hippo.ehviewer.client.exception.EhException;
|
||||
|
||||
import com.hippo.util.ExceptionUtils;
|
||||
import org.json.JSONObject;
|
||||
|
||||
public class GalleryTokenApiParser {
|
||||
@@ -36,7 +36,8 @@ public class GalleryTokenApiParser {
|
||||
JSONObject jo = new JSONObject(body).getJSONArray("tokenlist").getJSONObject(0);
|
||||
try {
|
||||
return jo.getString("token");
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
throw new EhException(jo.getString("error"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,10 +18,9 @@ package com.hippo.ehviewer.client.parser;
|
||||
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import com.hippo.ehviewer.client.EhUrl;
|
||||
import com.hippo.ehviewer.client.exception.ParseException;
|
||||
|
||||
import com.hippo.util.ExceptionUtils;
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Document;
|
||||
import org.jsoup.nodes.Element;
|
||||
@@ -43,11 +42,13 @@ public class ProfileParser {
|
||||
} else if (!result.avatar.startsWith("http")) {
|
||||
result.avatar = EhUrl.URL_FORUMS + result.avatar;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
Log.i(TAG, "No avatar");
|
||||
}
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
throw new ParseException("Parse forums error", body);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,16 +19,15 @@ package com.hippo.ehviewer.client.parser;
|
||||
import com.hippo.ehviewer.client.EhUtils;
|
||||
import com.hippo.ehviewer.client.data.GalleryInfo;
|
||||
import com.hippo.ehviewer.client.exception.ParseException;
|
||||
import com.hippo.util.ExceptionUtils;
|
||||
import com.hippo.util.JsoupUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Document;
|
||||
import org.jsoup.nodes.Element;
|
||||
import org.jsoup.select.Elements;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class WhatsHotParser {
|
||||
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
@@ -54,7 +53,8 @@ public class WhatsHotParser {
|
||||
galleryInfoList.add(galleryInfo);
|
||||
}
|
||||
return galleryInfoList;
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
throw new ParseException("Parse whats hot error", body);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,102 @@
|
||||
/*
|
||||
* 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.gallery;
|
||||
|
||||
import com.hippo.a7zip.ArchiveException;
|
||||
import com.hippo.a7zip.InArchive;
|
||||
import com.hippo.a7zip.PropID;
|
||||
import com.hippo.a7zip.PropType;
|
||||
import com.hippo.unifile.UniRandomAccessFile;
|
||||
import java.io.Closeable;
|
||||
import java.io.OutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import okio.Store;
|
||||
import okio.UniRandomAccessFileStore;
|
||||
|
||||
class A7ZipArchive implements Closeable {
|
||||
|
||||
private InArchive archive;
|
||||
|
||||
private A7ZipArchive(InArchive archive) {
|
||||
this.archive = archive;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
archive.close();
|
||||
}
|
||||
|
||||
private static boolean isSupportedFilename(String name) {
|
||||
for (String extension : GalleryProvider2.SUPPORT_IMAGE_EXTENSIONS) {
|
||||
if (name.endsWith(extension)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
List<A7ZipArchiveEntry> getArchiveEntries() {
|
||||
List<A7ZipArchiveEntry> entries = new ArrayList<>();
|
||||
|
||||
for (int i = 0, n = archive.getNumberOfEntries(); i < n; i++) {
|
||||
if (!archive.getEntryBooleanProperty(i, PropID.ENCRYPTED)
|
||||
&& !archive.getEntryBooleanProperty(i, PropID.IS_DIR)
|
||||
&& !archive.getEntryBooleanProperty(i, PropID.IS_VOLUME)
|
||||
&& !archive.getEntryBooleanProperty(i, PropID.SOLID)) {
|
||||
String path = archive.getEntryPath(i);
|
||||
if (isSupportedFilename(path.toLowerCase())) {
|
||||
entries.add(new A7ZipArchiveEntry(archive, i, path));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return entries;
|
||||
}
|
||||
|
||||
static A7ZipArchive create(UniRandomAccessFile file) throws ArchiveException {
|
||||
Store store = new UniRandomAccessFileStore(file);
|
||||
InArchive archive = InArchive.create(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))) {
|
||||
throw new ArchiveException("Unsupported archive");
|
||||
}
|
||||
return new A7ZipArchive(archive);
|
||||
}
|
||||
|
||||
static class A7ZipArchiveEntry {
|
||||
|
||||
private InArchive archive;
|
||||
private int index;
|
||||
private String path;
|
||||
|
||||
private A7ZipArchiveEntry(InArchive archive, int index, String path) {
|
||||
this.archive = archive;
|
||||
this.index = index;
|
||||
this.path = path;
|
||||
}
|
||||
|
||||
String getPath() {
|
||||
return path;
|
||||
}
|
||||
|
||||
void extract(OutputStream os) throws ArchiveException {
|
||||
archive.extractEntry(index, os);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2018 Hippo Seven
|
||||
* 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.
|
||||
@@ -21,38 +21,43 @@ import android.net.Uri;
|
||||
import android.os.Process;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import com.hippo.a7zip.ArchiveException;
|
||||
import com.hippo.ehviewer.GetText;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.gallery.archive.Archive;
|
||||
import com.hippo.ehviewer.gallery.archive.ArchiveEntry;
|
||||
import com.hippo.glgallery.GalleryPageView;
|
||||
import com.hippo.image.Image;
|
||||
import com.hippo.unifile.UniFile;
|
||||
import com.hippo.unifile.UniRandomAccessFile;
|
||||
import com.hippo.util.NaturalComparator;
|
||||
import com.hippo.yorozuya.IOUtils;
|
||||
import com.hippo.yorozuya.thread.PriorityThread;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Stack;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
public class ArchiveGalleryProvider extends GalleryProvider2 implements Runnable {
|
||||
public class ArchiveGalleryProvider extends GalleryProvider2 {
|
||||
|
||||
private static final String TAG = ArchiveGalleryProvider.class.getSimpleName();
|
||||
private static final AtomicInteger sIdGenerator = new AtomicInteger();
|
||||
|
||||
private final UniFile file;
|
||||
private final Stack<Integer> requests = new Stack<>();
|
||||
private final AtomicInteger decodingIndex = new AtomicInteger(GalleryPageView.INVALID_INDEX);
|
||||
@Nullable
|
||||
private Thread bgThread;
|
||||
|
||||
private Thread archiveThread;
|
||||
private Thread decodeThread;
|
||||
|
||||
private volatile int size = STATE_WAIT;
|
||||
private String error;
|
||||
|
||||
private final Stack<Integer> requests = new Stack<>();
|
||||
private final AtomicInteger extractingIndex = new AtomicInteger(GalleryPageView.INVALID_INDEX);
|
||||
private final LinkedHashMap<Integer, InputStream> streams = new LinkedHashMap<>();
|
||||
private final AtomicInteger decodingIndex = new AtomicInteger(GalleryPageView.INVALID_INDEX);
|
||||
|
||||
public ArchiveGalleryProvider(Context context, Uri uri) {
|
||||
file = UniFile.fromUri(context, uri);
|
||||
}
|
||||
@@ -61,18 +66,28 @@ public class ArchiveGalleryProvider extends GalleryProvider2 implements Runnable
|
||||
public void start() {
|
||||
super.start();
|
||||
|
||||
bgThread = new PriorityThread(this, TAG + '-' + sIdGenerator.incrementAndGet(),
|
||||
Process.THREAD_PRIORITY_BACKGROUND);
|
||||
bgThread.start();
|
||||
int id = sIdGenerator.incrementAndGet();
|
||||
|
||||
archiveThread = new PriorityThread(
|
||||
new ArchiveTask(), "ArchiveTask" + '-' + id, Process.THREAD_PRIORITY_BACKGROUND);
|
||||
archiveThread.start();
|
||||
|
||||
decodeThread = new PriorityThread(
|
||||
new DecodeTask(), "DecodeTask" + '-' + id, Process.THREAD_PRIORITY_BACKGROUND);
|
||||
decodeThread.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
super.stop();
|
||||
|
||||
if (bgThread != null) {
|
||||
bgThread.interrupt();
|
||||
bgThread = null;
|
||||
if (archiveThread != null) {
|
||||
archiveThread.interrupt();
|
||||
archiveThread = null;
|
||||
}
|
||||
if (decodeThread != null) {
|
||||
decodeThread.interrupt();
|
||||
decodeThread = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,8 +98,14 @@ public class ArchiveGalleryProvider extends GalleryProvider2 implements Runnable
|
||||
|
||||
@Override
|
||||
protected void onRequest(int index) {
|
||||
boolean inDecodeTask;
|
||||
synchronized (streams) {
|
||||
inDecodeTask = streams.keySet().contains(index) || index == decodingIndex.get();
|
||||
}
|
||||
|
||||
synchronized (requests) {
|
||||
if (!requests.contains(index) && index != decodingIndex.get()) {
|
||||
boolean inArchiveTask = requests.contains(index) || index == extractingIndex.get();
|
||||
if (!inArchiveTask && !inDecodeTask) {
|
||||
requests.add(index);
|
||||
requests.notify();
|
||||
}
|
||||
@@ -129,90 +150,132 @@ public class ArchiveGalleryProvider extends GalleryProvider2 implements Runnable
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
UniRandomAccessFile uraf = null;
|
||||
if (file != null) {
|
||||
private class ArchiveTask implements Runnable {
|
||||
@Override
|
||||
public void run() {
|
||||
UniRandomAccessFile uraf = null;
|
||||
if (file != null) {
|
||||
try {
|
||||
uraf = file.createRandomAccessFile("r");
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
if (uraf == null) {
|
||||
size = STATE_ERROR;
|
||||
error = GetText.getString(R.string.error_reading_failed);
|
||||
notifyDataChanged();
|
||||
return;
|
||||
}
|
||||
|
||||
A7ZipArchive archive = null;
|
||||
try {
|
||||
uraf = file.createRandomAccessFile("r");
|
||||
} catch (IOException e) {
|
||||
archive = A7ZipArchive.create(uraf);
|
||||
} catch (ArchiveException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
if (uraf == null) {
|
||||
size = STATE_ERROR;
|
||||
error = GetText.getString(R.string.error_reading_failed);
|
||||
if (archive == null) {
|
||||
size = STATE_ERROR;
|
||||
error = GetText.getString(R.string.error_invalid_archive);
|
||||
notifyDataChanged();
|
||||
return;
|
||||
}
|
||||
|
||||
List<A7ZipArchive.A7ZipArchiveEntry> entries = archive.getArchiveEntries();
|
||||
Collections.sort(entries, naturalComparator);
|
||||
|
||||
// Update size and notify changed
|
||||
size = entries.size();
|
||||
notifyDataChanged();
|
||||
return;
|
||||
}
|
||||
|
||||
Archive archive = null;
|
||||
try {
|
||||
archive = Archive.create(uraf);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (archive == null) {
|
||||
size = STATE_ERROR;
|
||||
error = GetText.getString(R.string.error_invalid_archive);
|
||||
notifyDataChanged();
|
||||
return;
|
||||
}
|
||||
|
||||
List<ArchiveEntry> entries = archive.getArchiveEntries();
|
||||
Collections.sort(entries, naturalComparator);
|
||||
|
||||
// Update size and notify changed
|
||||
size = entries.size();
|
||||
notifyDataChanged();
|
||||
|
||||
while (!Thread.currentThread().isInterrupted()) {
|
||||
int index;
|
||||
synchronized (requests) {
|
||||
if (requests.isEmpty()) {
|
||||
try {
|
||||
requests.wait();
|
||||
} catch (InterruptedException e) {
|
||||
// Interrupted
|
||||
break;
|
||||
while (!Thread.currentThread().isInterrupted()) {
|
||||
int index;
|
||||
synchronized (requests) {
|
||||
if (requests.isEmpty()) {
|
||||
try {
|
||||
requests.wait();
|
||||
} catch (InterruptedException e) {
|
||||
// Interrupted
|
||||
break;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
index = requests.pop();
|
||||
extractingIndex.lazySet(index);
|
||||
}
|
||||
|
||||
// Check index valid
|
||||
if (index < 0 || index >= entries.size()) {
|
||||
extractingIndex.lazySet(GalleryPageView.INVALID_INDEX);
|
||||
notifyPageFailed(index, GetText.getString(R.string.error_out_of_range));
|
||||
continue;
|
||||
}
|
||||
index = requests.pop();
|
||||
decodingIndex.lazySet(index);
|
||||
}
|
||||
|
||||
// Check index valid
|
||||
if (index < 0 || index >= entries.size()) {
|
||||
decodingIndex.lazySet(GalleryPageView.INVALID_INDEX);
|
||||
notifyPageFailed(index, GetText.getString(R.string.error_out_of_range));
|
||||
continue;
|
||||
}
|
||||
Pipe pipe = new Pipe(4 * 1024);
|
||||
|
||||
try {
|
||||
InputStream is = entries.get(index).getInputStream();
|
||||
Image image = Image.decode(is, true);
|
||||
decodingIndex.lazySet(GalleryPageView.INVALID_INDEX);
|
||||
if (image != null) {
|
||||
notifyPageSucceed(index, image);
|
||||
} else {
|
||||
notifyPageFailed(index, GetText.getString(R.string.error_decoding_failed));
|
||||
synchronized (streams) {
|
||||
if (streams.get(index) != null) {
|
||||
continue;
|
||||
}
|
||||
streams.put(index, pipe.getInputStream());
|
||||
streams.notify();
|
||||
}
|
||||
|
||||
try {
|
||||
entries.get(index).extract(pipe.getOutputStream());
|
||||
} catch (ArchiveException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
extractingIndex.lazySet(GalleryPageView.INVALID_INDEX);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
decodingIndex.lazySet(GalleryPageView.INVALID_INDEX);
|
||||
notifyPageFailed(index, GetText.getString(R.string.error_reading_failed));
|
||||
}
|
||||
}
|
||||
|
||||
// Clear
|
||||
IOUtils.closeQuietly(archive);
|
||||
}
|
||||
|
||||
private static Comparator<ArchiveEntry> naturalComparator = new Comparator<ArchiveEntry>() {
|
||||
private class DecodeTask implements Runnable {
|
||||
@Override
|
||||
public void run() {
|
||||
while (!Thread.currentThread().isInterrupted()) {
|
||||
int index;
|
||||
InputStream stream;
|
||||
synchronized (streams) {
|
||||
if (streams.isEmpty()) {
|
||||
try {
|
||||
streams.wait();
|
||||
} catch (InterruptedException e) {
|
||||
// Interrupted
|
||||
break;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
Iterator<Map.Entry<Integer, InputStream>> iterator = streams.entrySet().iterator();
|
||||
Map.Entry<Integer, InputStream> entry = iterator.next();
|
||||
iterator.remove();
|
||||
index = entry.getKey();
|
||||
stream = entry.getValue();
|
||||
decodingIndex.lazySet(index);
|
||||
}
|
||||
|
||||
try {
|
||||
Image image = Image.decode(stream, true);
|
||||
if (image != null) {
|
||||
notifyPageSucceed(index, image);
|
||||
} else {
|
||||
notifyPageFailed(index, GetText.getString(R.string.error_decoding_failed));
|
||||
}
|
||||
} finally {
|
||||
decodingIndex.lazySet(GalleryPageView.INVALID_INDEX);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static Comparator<A7ZipArchive.A7ZipArchiveEntry> naturalComparator = new Comparator<A7ZipArchive.A7ZipArchiveEntry>() {
|
||||
private NaturalComparator comparator = new NaturalComparator();
|
||||
@Override
|
||||
public int compare(ArchiveEntry o1, ArchiveEntry o2) {
|
||||
return comparator.compare(o1.getName(), o2.getName());
|
||||
public int compare(A7ZipArchive.A7ZipArchiveEntry o1, A7ZipArchive.A7ZipArchiveEntry o2) {
|
||||
return comparator.compare(o1.getPath(), o2.getPath());
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,160 @@
|
||||
/*
|
||||
* 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.gallery;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
class Pipe {
|
||||
|
||||
private final int capacity;
|
||||
private final byte[] buffer;
|
||||
|
||||
private int head = 0;
|
||||
private int tail = 0;
|
||||
private boolean full = false;
|
||||
|
||||
private boolean inClosed = false;
|
||||
private boolean outClosed = false;
|
||||
|
||||
private InputStream inputStream = new InputStream() {
|
||||
@Override
|
||||
public int read() throws IOException {
|
||||
synchronized (Pipe.this) {
|
||||
byte[] bytes = new byte[1];
|
||||
if (read(bytes, 0, 1) != -1) {
|
||||
return bytes[0];
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int read(@NonNull byte[] b, int off, int len) throws IOException {
|
||||
synchronized (Pipe.this) {
|
||||
for (;;) {
|
||||
if (inClosed) {
|
||||
throw new IOException("The InputStream is closed");
|
||||
}
|
||||
if (len == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (head == tail && !full) {
|
||||
if (outClosed) {
|
||||
// No bytes available and the OutputStream is closed. So it's the end.
|
||||
return -1;
|
||||
} else {
|
||||
// Wait for OutputStream write bytes
|
||||
try {
|
||||
Pipe.this.wait();
|
||||
} catch (InterruptedException e) {
|
||||
throw new IOException("The thread interrupted", e);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
int read = Math.min(len, (head < tail ? tail : capacity) - head);
|
||||
System.arraycopy(buffer, head, b, off, read);
|
||||
head += read;
|
||||
if (head == capacity) {
|
||||
head = 0;
|
||||
}
|
||||
full = false;
|
||||
Pipe.this.notifyAll();
|
||||
return read;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
synchronized (Pipe.this) {
|
||||
inClosed = true;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private OutputStream outputStream = new OutputStream() {
|
||||
@Override
|
||||
public void write(int b) throws IOException {
|
||||
synchronized (Pipe.this) {
|
||||
byte[] bytes = new byte[] { (byte) b};
|
||||
write(bytes, 0, 1);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NonNull byte[] b, int off, int len) throws IOException {
|
||||
synchronized (Pipe.this) {
|
||||
while (len != 0) {
|
||||
if (outClosed) {
|
||||
throw new IOException("The OutputStream is closed");
|
||||
}
|
||||
if (inClosed) {
|
||||
throw new IOException("The InputStream is closed");
|
||||
}
|
||||
|
||||
if (head == tail && full) {
|
||||
// The buffer is full, wait for InputStream read bytes
|
||||
try {
|
||||
Pipe.this.wait();
|
||||
} catch (InterruptedException e) {
|
||||
throw new IOException("The thread interrupted", e);
|
||||
}
|
||||
} else {
|
||||
int write = Math.min(len, (head <= tail ? capacity : head) - tail);
|
||||
System.arraycopy(b, off, buffer, tail, write);
|
||||
off += write;
|
||||
len -= write;
|
||||
tail += write;
|
||||
if (tail == capacity) {
|
||||
tail = 0;
|
||||
}
|
||||
if (head == tail) {
|
||||
full = true;
|
||||
}
|
||||
Pipe.this.notifyAll();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
synchronized (Pipe.this) {
|
||||
outClosed = true;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Pipe(int capacity) {
|
||||
this.capacity = capacity;
|
||||
this.buffer = new byte[capacity];
|
||||
}
|
||||
|
||||
InputStream getInputStream() {
|
||||
return inputStream;
|
||||
}
|
||||
|
||||
OutputStream getOutputStream() {
|
||||
return outputStream;
|
||||
}
|
||||
}
|
||||
@@ -1,91 +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 com.hippo.ehviewer.gallery.archive;
|
||||
|
||||
import com.hippo.ehviewer.gallery.GalleryProvider2;
|
||||
import com.hippo.unifile.UniRandomAccessFile;
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class Archive implements Closeable {
|
||||
|
||||
private static final byte[] FILE_SIGNATURE_SEVEN_Z = { 0x37, 0x7A, (byte) 0xBC, (byte) 0xAF, 0x27, 0x1C };
|
||||
private static final byte[] FILE_SIGNATURE_ZIP = { 0x50, 0x4B };
|
||||
private static final byte[] FILE_SIGNATURE_RAR = { 0x52, 0x61, 0x72, 0x21, 0x1A, 0x07, 0x00 };
|
||||
|
||||
public abstract List<ArchiveEntry> getArchiveEntries();
|
||||
|
||||
public static Archive create(UniRandomAccessFile file) throws IOException {
|
||||
byte[] bytes = new byte[8];
|
||||
readFully(file, bytes, 8);
|
||||
file.seek(0);
|
||||
|
||||
if (equals(bytes, FILE_SIGNATURE_SEVEN_Z, FILE_SIGNATURE_SEVEN_Z.length)) {
|
||||
return SevenZArchive.create(file);
|
||||
} else if (equals(bytes, FILE_SIGNATURE_ZIP, FILE_SIGNATURE_ZIP.length)) {
|
||||
return ZipArchive.create(file);
|
||||
} else if (equals(bytes, FILE_SIGNATURE_RAR, FILE_SIGNATURE_RAR.length)) {
|
||||
return RarArchive.create(file);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
static boolean isSupportedFilename(String name) {
|
||||
for (String extension : GalleryProvider2.SUPPORT_IMAGE_EXTENSIONS) {
|
||||
if (name.endsWith(extension)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static int readFully(UniRandomAccessFile file, byte[] bytes, int count) throws IOException {
|
||||
if (count <= 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int read = 0;
|
||||
do {
|
||||
int l = file.read(bytes, read, count - read);
|
||||
if (l < 0)
|
||||
break;
|
||||
read += l;
|
||||
} while (read < count);
|
||||
|
||||
if (read == 0) {
|
||||
return -1;
|
||||
} else {
|
||||
return read;
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean equals(byte[] b1, byte[] b2, int size) {
|
||||
if (b1.length < size || b2.length < size) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int i = 0; i < size; i++) {
|
||||
if (b1[i] != b2[i]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1,27 +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 com.hippo.ehviewer.gallery.archive;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
public abstract class ArchiveEntry {
|
||||
|
||||
public abstract String getName();
|
||||
|
||||
public abstract InputStream getInputStream() throws IOException;
|
||||
}
|
||||
@@ -1,198 +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 com.hippo.ehviewer.gallery.archive;
|
||||
|
||||
import com.github.junrar.Volume;
|
||||
import com.github.junrar.VolumeManager;
|
||||
import com.github.junrar.exception.RarException;
|
||||
import com.github.junrar.io.IReadOnlyAccess;
|
||||
import com.github.junrar.rarfile.FileHeader;
|
||||
import com.hippo.unifile.UniRandomAccessFile;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class RarArchive extends Archive {
|
||||
|
||||
private com.github.junrar.Archive file;
|
||||
|
||||
private RarArchive(com.github.junrar.Archive file) {
|
||||
this.file = file;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ArchiveEntry> getArchiveEntries() {
|
||||
List<ArchiveEntry> result = new ArrayList<>();
|
||||
|
||||
for (FileHeader fileHeader : file.getFileHeaders()) {
|
||||
if (isSupportedFilename(fileHeader.getFileNameString().toLowerCase())) {
|
||||
result.add(new RarArchiveEntry(file, fileHeader));
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
file.close();
|
||||
}
|
||||
|
||||
public static Archive create(UniRandomAccessFile file) throws IOException {
|
||||
VolumeManager volumeManager = new UniRandomAccessFileVolumeManager(file);
|
||||
com.github.junrar.Archive archive;
|
||||
try {
|
||||
archive = new com.github.junrar.Archive(volumeManager);
|
||||
if (archive.getMainHeader().isSolid()) {
|
||||
throw new IOException("Solid archive is not supported");
|
||||
}
|
||||
} catch (RarException e) {
|
||||
throw new IOException("Invalid rar archive", e);
|
||||
}
|
||||
return new RarArchive(archive);
|
||||
}
|
||||
|
||||
public static class RarArchiveEntry extends ArchiveEntry {
|
||||
|
||||
private com.github.junrar.Archive file;
|
||||
private FileHeader header;
|
||||
|
||||
private RarArchiveEntry(com.github.junrar.Archive file, FileHeader header) {
|
||||
this.file = file;
|
||||
this.header = header;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return header.getFileNameString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream getInputStream() throws IOException {
|
||||
try {
|
||||
return file.getInputStream(header);
|
||||
} catch (RarException e) {
|
||||
throw new IOException("Can't getInputStream from rar archive", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static class UniRandomAccessFileVolumeManager implements VolumeManager {
|
||||
|
||||
private UniRandomAccessFile file;
|
||||
|
||||
private UniRandomAccessFileVolumeManager(UniRandomAccessFile file) {
|
||||
this.file = file;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Volume nextArchive(com.github.junrar.Archive archive, Volume lastVolume) {
|
||||
if (lastVolume == null) {
|
||||
return new UniRandomAccessFileVolume(archive, file);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static class UniRandomAccessFileVolume implements Volume {
|
||||
|
||||
private com.github.junrar.Archive archive;
|
||||
private UniRandomAccessFile file;
|
||||
|
||||
private UniRandomAccessFileVolume(com.github.junrar.Archive archive, UniRandomAccessFile file) {
|
||||
this.archive = archive;
|
||||
this.file = file;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IReadOnlyAccess getReadOnlyAccess() {
|
||||
return new UniReadOnlyAccessFile(file);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getLength() throws IOException {
|
||||
return file.length();
|
||||
}
|
||||
|
||||
@Override
|
||||
public com.github.junrar.Archive getArchive() {
|
||||
return archive;
|
||||
}
|
||||
}
|
||||
|
||||
private static class UniReadOnlyAccessFile implements IReadOnlyAccess {
|
||||
|
||||
private UniRandomAccessFile file;
|
||||
|
||||
private UniReadOnlyAccessFile(UniRandomAccessFile file) {
|
||||
this.file = file;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getPosition() throws IOException {
|
||||
return file.getFilePointer();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPosition(long pos) throws IOException {
|
||||
file.seek(pos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int read() throws IOException {
|
||||
byte[] b = new byte[1];
|
||||
if (file.read(b) == -1) {
|
||||
return -1;
|
||||
} else {
|
||||
return b[0];
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int read(byte[] buffer, int off, int count) throws IOException {
|
||||
return file.read(buffer, off, count);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int readFully(byte[] buffer, int count) throws IOException {
|
||||
if (count <= 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int read = 0;
|
||||
do {
|
||||
int l = read(buffer, read, count - read);
|
||||
if (l < 0)
|
||||
break;
|
||||
read += l;
|
||||
} while (read < count);
|
||||
|
||||
if (read == 0) {
|
||||
return -1;
|
||||
} else {
|
||||
return read;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
file.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,96 +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 com.hippo.ehviewer.gallery.archive;
|
||||
|
||||
import com.hippo.unifile.UniRandomAccessFile;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import okio.Store;
|
||||
import okio.UniRandomAccessFileStore;
|
||||
import org.apache.commons.compress.archivers.sevenz.SevenZFile;
|
||||
|
||||
public class SevenZArchive extends Archive {
|
||||
|
||||
private SevenZFile file;
|
||||
|
||||
public SevenZArchive(SevenZFile file) {
|
||||
this.file = file;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ArchiveEntry> getArchiveEntries() {
|
||||
List<ArchiveEntry> result = new ArrayList<>();
|
||||
|
||||
for (org.apache.commons.compress.archivers.sevenz.SevenZArchiveEntry archive : file.getEntries()) {
|
||||
if (archive.getSize() != 0
|
||||
&& !archive.isDirectory()
|
||||
&& isSupportedFilename(archive.getName().toLowerCase())) {
|
||||
result.add(new SevenZArchiveEntry(file, archive));
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
file.close();
|
||||
}
|
||||
|
||||
public static Archive create(UniRandomAccessFile file) throws IOException {
|
||||
Store store = new UniRandomAccessFileStore(file);
|
||||
SevenZFile sevenZFile = new SevenZFile(store);
|
||||
|
||||
// Check whether the archive is solid
|
||||
for (org.apache.commons.compress.archivers.sevenz.SevenZArchiveEntry entry : sevenZFile.getEntries()) {
|
||||
if (entry.getSize() != 0
|
||||
&& !entry.isDirectory()
|
||||
&& !entry.isFirstInFolder()) {
|
||||
throw new IOException("Solid archive is not supported");
|
||||
}
|
||||
}
|
||||
|
||||
return new SevenZArchive(sevenZFile);
|
||||
}
|
||||
|
||||
public static class SevenZArchiveEntry extends ArchiveEntry {
|
||||
|
||||
private SevenZFile file;
|
||||
private org.apache.commons.compress.archivers.sevenz.SevenZArchiveEntry entry;
|
||||
|
||||
private SevenZArchiveEntry(
|
||||
SevenZFile file,
|
||||
org.apache.commons.compress.archivers.sevenz.SevenZArchiveEntry entry
|
||||
) {
|
||||
this.file = file;
|
||||
this.entry = entry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return entry.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream getInputStream() throws IOException {
|
||||
file.setEntry(entry);
|
||||
return file.getInputStreamForCurrentEntry();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,86 +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 com.hippo.ehviewer.gallery.archive;
|
||||
|
||||
import com.hippo.unifile.UniRandomAccessFile;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Enumeration;
|
||||
import java.util.List;
|
||||
import okio.Store;
|
||||
import okio.UniRandomAccessFileStore;
|
||||
import org.apache.commons.compress.archivers.zip.ZipFile;
|
||||
|
||||
public class ZipArchive extends Archive {
|
||||
|
||||
private ZipFile file;
|
||||
|
||||
private ZipArchive(ZipFile file) {
|
||||
this.file = file;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ArchiveEntry> getArchiveEntries() {
|
||||
List<ArchiveEntry> result = new ArrayList<>();
|
||||
|
||||
Enumeration<org.apache.commons.compress.archivers.zip.ZipArchiveEntry> entries = file.getEntries();
|
||||
while (entries.hasMoreElements()) {
|
||||
org.apache.commons.compress.archivers.zip.ZipArchiveEntry entry = entries.nextElement();
|
||||
if (isSupportedFilename(entry.getName().toLowerCase())) {
|
||||
result.add(new ZipArchiveEntry(file, entry));
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
file.close();
|
||||
}
|
||||
|
||||
public static Archive create(UniRandomAccessFile file) throws IOException {
|
||||
Store store = new UniRandomAccessFileStore(file);
|
||||
ZipFile zipFile = new ZipFile(store);
|
||||
return new ZipArchive(zipFile);
|
||||
}
|
||||
|
||||
public static class ZipArchiveEntry extends ArchiveEntry {
|
||||
|
||||
private ZipFile file;
|
||||
private org.apache.commons.compress.archivers.zip.ZipArchiveEntry entry;
|
||||
|
||||
private ZipArchiveEntry(
|
||||
ZipFile file,
|
||||
org.apache.commons.compress.archivers.zip.ZipArchiveEntry entry
|
||||
) {
|
||||
this.file = file;
|
||||
this.entry = entry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return entry.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream getInputStream() throws IOException {
|
||||
return file.getInputStream(entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -62,6 +62,9 @@ public class CleanRedundancyPreference extends TaskPreference {
|
||||
// True for cleared
|
||||
private boolean clearFile(UniFile file) {
|
||||
String name = file.getName();
|
||||
if (name == null) {
|
||||
return false;
|
||||
}
|
||||
int index = name.indexOf('-');
|
||||
if (index >= 0) {
|
||||
name = name.substring(0, index);
|
||||
|
||||
@@ -23,7 +23,6 @@ import android.preference.Preference;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.util.AttributeSet;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.hippo.ehviewer.EhApplication;
|
||||
import com.hippo.ehviewer.EhDB;
|
||||
import com.hippo.ehviewer.R;
|
||||
@@ -34,14 +33,13 @@ import com.hippo.ehviewer.download.DownloadManager;
|
||||
import com.hippo.ehviewer.spider.SpiderInfo;
|
||||
import com.hippo.ehviewer.spider.SpiderQueen;
|
||||
import com.hippo.unifile.UniFile;
|
||||
import com.hippo.util.ExceptionUtils;
|
||||
import com.hippo.yorozuya.IOUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import okhttp3.OkHttpClient;
|
||||
|
||||
public class RestoreDownloadPreference extends TaskPreference {
|
||||
@@ -120,6 +118,10 @@ public class RestoreDownloadPreference extends TaskPreference {
|
||||
List<RestoreItem> restoreItemList = new ArrayList<>();
|
||||
|
||||
UniFile[] files = dir.listFiles();
|
||||
if (files == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
for (UniFile file: files) {
|
||||
RestoreItem restoreItem = getRestoreItem(file);
|
||||
if (null != restoreItem) {
|
||||
@@ -133,7 +135,8 @@ public class RestoreDownloadPreference extends TaskPreference {
|
||||
|
||||
try {
|
||||
return EhEngine.fillGalleryListByApi(null, mHttpClient, new ArrayList<GalleryInfo>(restoreItemList));
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -80,6 +80,7 @@ import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import okhttp3.Call;
|
||||
import okhttp3.MediaType;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
@@ -748,7 +749,8 @@ public final class SpiderQueen implements Runnable {
|
||||
spiderInfo.pTokenMap = new SparseArray<>(spiderInfo.pages);
|
||||
readPreviews(body, 0, spiderInfo);
|
||||
return spiderInfo;
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -790,7 +792,8 @@ public final class SpiderQueen implements Runnable {
|
||||
pToken = spiderInfo.pTokenMap.get(index);
|
||||
}
|
||||
return pToken;
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -802,7 +805,8 @@ public final class SpiderQueen implements Runnable {
|
||||
UniFile file = downloadDir.createFile(SPIDER_INFO_FILENAME);
|
||||
try {
|
||||
spiderInfo.write(file.openOutputStream());
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
// Ignore
|
||||
}
|
||||
}
|
||||
@@ -1033,7 +1037,7 @@ public final class SpiderQueen implements Runnable {
|
||||
return pageUrl;
|
||||
}
|
||||
|
||||
private GalleryPageParser.Result getImageUrl(int index, String pageUrl) throws Exception {
|
||||
private GalleryPageParser.Result getImageUrl(int index, String pageUrl) throws Throwable {
|
||||
GalleryPageParser.Result result = EhEngine.getGalleryPage(null, mHttpClient, pageUrl);
|
||||
if (StringUtils.endsWith(result.imageUrl, URL_509_SUFFIX_ARRAY)) {
|
||||
// Get 509
|
||||
@@ -1070,7 +1074,8 @@ public final class SpiderQueen implements Runnable {
|
||||
result = getImageUrl(index, pageUrl);
|
||||
} catch (Image509Exception e) {
|
||||
error = GetText.getString(R.string.error_509);
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
error = ExceptionUtils.getReadableString(e);
|
||||
}
|
||||
if (result == null) {
|
||||
@@ -1121,17 +1126,26 @@ public final class SpiderQueen implements Runnable {
|
||||
|
||||
Call call = mHttpClient.newCall(new EhRequestBuilder(imageUrl).build());
|
||||
Response response = call.execute();
|
||||
ResponseBody responseBody = response.body();
|
||||
|
||||
if (response.code() >= 400) {
|
||||
// Maybe 404
|
||||
response.body().close();
|
||||
response.close();
|
||||
error = "Bad code: " + response.code();
|
||||
continue;
|
||||
}
|
||||
ResponseBody responseBody = response.body();
|
||||
|
||||
if (responseBody == null) {
|
||||
error = "Empty response body";
|
||||
continue;
|
||||
}
|
||||
|
||||
// Get extension
|
||||
String extension = MimeTypeMap.getSingleton().getExtensionFromMimeType(
|
||||
responseBody.contentType().toString());
|
||||
String extension = null;
|
||||
MediaType mediaType = responseBody.contentType();
|
||||
if (mediaType != null) {
|
||||
extension = MimeTypeMap.getSingleton().getExtensionFromMimeType(mediaType.toString());
|
||||
}
|
||||
// Ensure extension
|
||||
if (!Utilities.contain(GalleryProvider2.SUPPORT_IMAGE_EXTENSIONS, extension)) {
|
||||
extension = GalleryProvider2.SUPPORT_IMAGE_EXTENSIONS[0];
|
||||
@@ -1142,7 +1156,7 @@ public final class SpiderQueen implements Runnable {
|
||||
if (null == pipe) {
|
||||
// Can't get pipe
|
||||
error = GetText.getString(R.string.error_write_failed);
|
||||
response.body().close();
|
||||
response.close();
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1157,7 +1171,7 @@ public final class SpiderQueen implements Runnable {
|
||||
while (!Thread.currentThread().isInterrupted()) {
|
||||
int bytesRead = is.read(data);
|
||||
if (bytesRead == -1) {
|
||||
response.body().close();
|
||||
response.close();
|
||||
break;
|
||||
}
|
||||
os.write(data, 0, bytesRead);
|
||||
|
||||
@@ -41,6 +41,7 @@ import com.hippo.ehviewer.download.DownloadService;
|
||||
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.yorozuya.FileUtils;
|
||||
import com.hippo.yorozuya.IOUtils;
|
||||
|
||||
@@ -80,38 +81,50 @@ public final class CommonOperations {
|
||||
mFeedback = feedback;
|
||||
}
|
||||
|
||||
private JSONObject fetchUpdateInfo(String url) throws IOException, JSONException {
|
||||
Log.d(TAG, url);
|
||||
Request request = new Request.Builder().url(url).build();
|
||||
Response response = mHttpClient.newCall(request).execute();
|
||||
return new JSONObject(response.body().string());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JSONObject doInBackground(Void... params) {
|
||||
String url;
|
||||
if (Settings.getBetaUpdateChannel()) {
|
||||
url = "http://www.ehviewer.com/update_beta.json";
|
||||
} else {
|
||||
url = "http://www.ehviewer.com/update.json";
|
||||
}
|
||||
|
||||
try {
|
||||
String url;
|
||||
return fetchUpdateInfo(url);
|
||||
} catch (Throwable e1) {
|
||||
ExceptionUtils.throwIfFatal(e1);
|
||||
|
||||
if (Settings.getBetaUpdateChannel()) {
|
||||
url = "http://www.ehviewer.com/update_beta.json";
|
||||
url = "https://raw.githubusercontent.com/seven332/EhViewer/api/update_beta.json";
|
||||
} else {
|
||||
url = "http://www.ehviewer.com/update.json";
|
||||
url = "https://raw.githubusercontent.com/seven332/EhViewer/api/update.json";
|
||||
}
|
||||
|
||||
try {
|
||||
return fetchUpdateInfo(url);
|
||||
} catch (Throwable e2) {
|
||||
ExceptionUtils.throwIfFatal(e2);
|
||||
return null;
|
||||
}
|
||||
Log.d(TAG, url);
|
||||
Request request = new Request.Builder().url(url).build();
|
||||
Response response = mHttpClient.newCall(request).execute();
|
||||
return new JSONObject(response.body().string());
|
||||
} catch (IOException e) {
|
||||
return null;
|
||||
} catch (JSONException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private void showUpToDateDialog() {
|
||||
if (!mFeedback) {
|
||||
return;
|
||||
}
|
||||
|
||||
new AlertDialog.Builder(mActivity)
|
||||
.setMessage(R.string.update_to_date)
|
||||
.setPositiveButton(android.R.string.ok, null)
|
||||
.show();
|
||||
}
|
||||
|
||||
private void showUpdateDialog(String versionName, String size, CharSequence info, final String url) {
|
||||
private void showUpdateDialog(String versionName, int versionCode, String size, CharSequence info, final String url) {
|
||||
new AlertDialog.Builder(mActivity)
|
||||
.setTitle(R.string.update)
|
||||
.setMessage(mActivity.getString(R.string.update_plain, versionName, size, info))
|
||||
@@ -120,16 +133,22 @@ public final class CommonOperations {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
UrlOpener.openUrl(mActivity, url, false);
|
||||
}
|
||||
})
|
||||
.setNegativeButton(R.string.update_ignore, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
Settings.putSkipUpdateVersion(versionCode);
|
||||
}
|
||||
}).show();
|
||||
}
|
||||
|
||||
|
||||
private void handleResult(JSONObject jo) {
|
||||
if (null == jo || mActivity.isFinishing()) {
|
||||
return;
|
||||
}
|
||||
|
||||
String versionName;
|
||||
int versionCode;
|
||||
String size;
|
||||
CharSequence info;
|
||||
String url;
|
||||
@@ -138,10 +157,12 @@ public final class CommonOperations {
|
||||
PackageManager pm = mActivity.getPackageManager();
|
||||
PackageInfo pi = pm.getPackageInfo(mActivity.getPackageName(), PackageManager.GET_ACTIVITIES);
|
||||
int currentVersionCode = pi.versionCode;
|
||||
int newVersionCode = jo.getInt("version_code");
|
||||
if (currentVersionCode >= newVersionCode) {
|
||||
versionCode = jo.getInt("version_code");
|
||||
if (currentVersionCode >= versionCode) {
|
||||
// Update to date
|
||||
showUpToDateDialog();
|
||||
if (mFeedback) {
|
||||
showUpToDateDialog();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -149,11 +170,14 @@ public final class CommonOperations {
|
||||
size = FileUtils.humanReadableByteCount(jo.getLong("size"), false);
|
||||
info = Html.fromHtml(jo.getString("info"));
|
||||
url = jo.getString("url");
|
||||
} catch (PackageManager.NameNotFoundException | JSONException e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
return;
|
||||
}
|
||||
|
||||
showUpdateDialog(versionName, size, info, url);
|
||||
if (mFeedback || versionCode != Settings.getSkipUpdateVersion()) {
|
||||
showUpdateDialog(versionName, versionCode, size, info, url);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -26,6 +26,7 @@ import android.view.WindowManager;
|
||||
import com.google.firebase.analytics.FirebaseAnalytics;
|
||||
import com.hippo.android.resource.AttrResources;
|
||||
import com.hippo.content.ContextLocalWrapper;
|
||||
import com.hippo.ehviewer.Analytics;
|
||||
import com.hippo.ehviewer.EhApplication;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.Settings;
|
||||
@@ -44,7 +45,7 @@ public abstract class EhActivity extends AppCompatActivity {
|
||||
|
||||
((EhApplication) getApplication()).registerActivity(this);
|
||||
|
||||
if (Settings.getEnableAnalytics()) {
|
||||
if (Analytics.isEnabled()) {
|
||||
FirebaseAnalytics.getInstance(this);
|
||||
}
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ import com.google.firebase.analytics.FirebaseAnalytics;
|
||||
import com.hippo.android.resource.AttrResources;
|
||||
import com.hippo.app.PrettyPreferenceActivity;
|
||||
import com.hippo.content.ContextLocalWrapper;
|
||||
import com.hippo.ehviewer.Analytics;
|
||||
import com.hippo.ehviewer.EhApplication;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.Settings;
|
||||
@@ -45,7 +46,7 @@ public abstract class EhPreferenceActivity extends PrettyPreferenceActivity {
|
||||
|
||||
((EhApplication) getApplication()).registerActivity(this);
|
||||
|
||||
if (Settings.getEnableAnalytics()) {
|
||||
if (Analytics.isEnabled()) {
|
||||
FirebaseAnalytics.getInstance(this);
|
||||
}
|
||||
|
||||
|
||||
@@ -66,6 +66,7 @@ import com.hippo.glgallery.GalleryView;
|
||||
import com.hippo.glgallery.SimpleAdapter;
|
||||
import com.hippo.glview.view.GLRootView;
|
||||
import com.hippo.unifile.UniFile;
|
||||
import com.hippo.util.ExceptionUtils;
|
||||
import com.hippo.util.SystemUiHelper;
|
||||
import com.hippo.widget.ColorView;
|
||||
import com.hippo.yorozuya.AnimationUtils;
|
||||
@@ -429,13 +430,15 @@ public class GalleryActivity extends EhActivity implements SeekBar.OnSeekBarChan
|
||||
public void onWindowFocusChanged(boolean hasFocus) {
|
||||
super.onWindowFocusChanged(hasFocus);
|
||||
|
||||
if (hasFocus && mSystemUiHelper != null) {
|
||||
if (mShowSystemUi) {
|
||||
mSystemUiHelper.show();
|
||||
} else {
|
||||
mSystemUiHelper.hide();
|
||||
SimpleHandler.getInstance().postDelayed(() -> {
|
||||
if (hasFocus && mSystemUiHelper != null) {
|
||||
if (mShowSystemUi) {
|
||||
mSystemUiHelper.show();
|
||||
} else {
|
||||
mSystemUiHelper.hide();
|
||||
}
|
||||
}
|
||||
}
|
||||
}, 300);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -780,6 +783,10 @@ public class GalleryActivity extends EhActivity implements SeekBar.OnSeekBarChan
|
||||
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
if (mGalleryView == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
int screenRotation = mScreenRotation.getSelectedItemPosition();
|
||||
int layoutMode = GalleryView.sanitizeLayoutMode(mReadingDirection.getSelectedItemPosition());
|
||||
int scaleMode = GalleryView.sanitizeScaleMode(mScaleMode.getSelectedItemPosition());
|
||||
@@ -824,11 +831,9 @@ public class GalleryActivity extends EhActivity implements SeekBar.OnSeekBarChan
|
||||
break;
|
||||
}
|
||||
setRequestedOrientation(orientation);
|
||||
if (mGalleryView != null) {
|
||||
mGalleryView.setLayoutMode(layoutMode);
|
||||
mGalleryView.setScaleMode(scaleMode);
|
||||
mGalleryView.setStartPosition(startPosition);
|
||||
}
|
||||
mGalleryView.setLayoutMode(layoutMode);
|
||||
mGalleryView.setScaleMode(scaleMode);
|
||||
mGalleryView.setStartPosition(startPosition);
|
||||
if (keepScreenOn) {
|
||||
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||
} else {
|
||||
@@ -895,7 +900,13 @@ public class GalleryActivity extends EhActivity implements SeekBar.OnSeekBarChan
|
||||
intent.setAction(Intent.ACTION_SEND);
|
||||
intent.putExtra(Intent.EXTRA_STREAM, uri);
|
||||
intent.setType(mimeType);
|
||||
startActivity(Intent.createChooser(intent, getString(R.string.share_image)));
|
||||
|
||||
try {
|
||||
startActivity(Intent.createChooser(intent, getString(R.string.share_image)));
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
Toast.makeText(this, R.string.error_cant_find_activity, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
private void saveImage(int page) {
|
||||
@@ -940,7 +951,12 @@ public class GalleryActivity extends EhActivity implements SeekBar.OnSeekBarChan
|
||||
intent.addCategory(Intent.CATEGORY_OPENABLE);
|
||||
intent.setType("image/*");
|
||||
intent.putExtra(Intent.EXTRA_TITLE, filename);
|
||||
startActivityForResult(intent, WRITE_REQUEST_CODE);
|
||||
try {
|
||||
startActivityForResult(intent, WRITE_REQUEST_CODE);
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
Toast.makeText(this, R.string.error_cant_find_activity, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -251,7 +251,11 @@ public final class MainActivity extends StageActivity
|
||||
|
||||
String action = intent.getAction();
|
||||
if (Intent.ACTION_VIEW.equals(action)) {
|
||||
Announcer announcer = EhUrlOpener.parseUrl(intent.getData().toString());
|
||||
Uri uri = intent.getData();
|
||||
if (uri == null) {
|
||||
return false;
|
||||
}
|
||||
Announcer announcer = EhUrlOpener.parseUrl(uri.toString());
|
||||
if (announcer != null) {
|
||||
startScene(processAnnouncer(announcer));
|
||||
return true;
|
||||
@@ -350,9 +354,7 @@ public final class MainActivity extends StageActivity
|
||||
|
||||
if (savedInstanceState == null) {
|
||||
onInit();
|
||||
if (Settings.getAutoCheckUpdateEnable()) {
|
||||
CommonOperations.checkUpdate(this, false);
|
||||
}
|
||||
CommonOperations.checkUpdate(this, false);
|
||||
checkDownloadLocation();
|
||||
if (Settings.getCellularNetworkWarning()) {
|
||||
checkCellularNetwork();
|
||||
|
||||
@@ -17,8 +17,10 @@
|
||||
package com.hippo.ehviewer.ui;
|
||||
|
||||
import android.hardware.fingerprint.FingerprintManager;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.annotation.RequiresApi;
|
||||
import android.text.TextUtils;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
@@ -62,7 +64,7 @@ public class SetSecurityActivity extends ToolbarActivity implements View.OnClick
|
||||
FingerprintManager fingerprintManager = getSystemService(FingerprintManager.class);
|
||||
// The line below prevents the false positive inspection from Android Studio
|
||||
// noinspection ResourceType
|
||||
if (fingerprintManager.hasEnrolledFingerprints()) {
|
||||
if (fingerprintManager != null && hasEnrolledFingerprints(fingerprintManager)) {
|
||||
mFingerprint.setVisibility(View.VISIBLE);
|
||||
mFingerprint.setChecked(Settings.getEnableFingerprint());
|
||||
}
|
||||
@@ -72,6 +74,16 @@ public class SetSecurityActivity extends ToolbarActivity implements View.OnClick
|
||||
mSet.setOnClickListener(this);
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.M)
|
||||
public static boolean hasEnrolledFingerprints(FingerprintManager fingerprintManager) {
|
||||
try {
|
||||
return fingerprintManager.isHardwareDetected()
|
||||
&& fingerprintManager.hasEnrolledFingerprints();
|
||||
} catch (Throwable e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
package com.hippo.ehviewer.ui.fragment;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.ActivityNotFoundException;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
@@ -28,12 +27,12 @@ import android.preference.PreferenceFragment;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.Settings;
|
||||
import com.hippo.ehviewer.ui.CommonOperations;
|
||||
import com.hippo.ehviewer.ui.DirPickerActivity;
|
||||
import com.hippo.unifile.UniFile;
|
||||
import com.hippo.util.ExceptionUtils;
|
||||
|
||||
public class DownloadFragment extends PreferenceFragment implements
|
||||
Preference.OnPreferenceChangeListener,
|
||||
@@ -145,7 +144,8 @@ public class DownloadFragment extends PreferenceFragment implements
|
||||
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
|
||||
try {
|
||||
startActivityForResult(intent, REQUEST_CODE_PICK_IMAGE_DIR_L);
|
||||
} catch (ActivityNotFoundException e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
Toast.makeText(getActivity(), R.string.error_cant_find_activity, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,6 +33,7 @@ import android.view.Gravity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import com.hippo.ehviewer.Analytics;
|
||||
import com.hippo.ehviewer.ui.MainActivity;
|
||||
import com.hippo.scene.SceneFragment;
|
||||
import com.hippo.util.AppHelper;
|
||||
@@ -261,6 +262,12 @@ public abstract class BaseScene extends SceneFragment {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
Analytics.onSceneView(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(@NonNull Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
|
||||
@@ -391,5 +391,11 @@ public class DownloadLabelsScene extends ToolbarScene {
|
||||
public boolean onCheckCanDrop(int draggingPosition, int dropPosition) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onItemDragStarted(int position) { }
|
||||
|
||||
@Override
|
||||
public void onItemDragFinished(int fromPosition, int toPosition, boolean result) { }
|
||||
}
|
||||
}
|
||||
@@ -929,7 +929,9 @@ public class DownloadsScene extends ToolbarScene
|
||||
@Override
|
||||
protected Void doInBackground(UniFile... params) {
|
||||
for (UniFile file: params) {
|
||||
file.delete();
|
||||
if (file != null) {
|
||||
file.delete();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -605,7 +605,10 @@ public class FavoritesScene extends BaseScene implements
|
||||
if (mRecyclerView != null && mRecyclerView.isInCustomChoice()) {
|
||||
mRecyclerView.toggleItemChecked(position);
|
||||
} else if (mHelper != null) {
|
||||
GalleryInfo gi = mHelper.getDataAt(position);
|
||||
GalleryInfo gi = mHelper.getDataAtEx(position);
|
||||
if (gi == null) {
|
||||
return true;
|
||||
}
|
||||
Bundle args = new Bundle();
|
||||
args.putString(GalleryDetailScene.KEY_ACTION, GalleryDetailScene.ACTION_GALLERY_INFO);
|
||||
args.putParcelable(GalleryDetailScene.KEY_GALLERY_INFO, gi);
|
||||
@@ -751,7 +754,10 @@ public class FavoritesScene extends BaseScene implements
|
||||
SparseBooleanArray stateArray = mRecyclerView.getCheckedItemPositions();
|
||||
for (int i = 0, n = stateArray.size(); i < n; i++) {
|
||||
if (stateArray.valueAt(i)) {
|
||||
mModifyGiList.add(mHelper.getDataAt(stateArray.keyAt(i)));
|
||||
GalleryInfo gi = mHelper.getDataAtEx(stateArray.keyAt(i));
|
||||
if (gi != null) {
|
||||
mModifyGiList.add(gi);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1002,7 +1008,7 @@ public class FavoritesScene extends BaseScene implements
|
||||
@Nullable
|
||||
@Override
|
||||
public GalleryInfo getDataAt(int position) {
|
||||
return null != mHelper ? mHelper.getDataAt(position) : null;
|
||||
return null != mHelper ? mHelper.getDataAtEx(position) : null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ import android.content.res.Resources;
|
||||
import android.graphics.Typeface;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Bundle;
|
||||
import android.os.Looper;
|
||||
import android.os.Parcelable;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
@@ -505,6 +506,13 @@ public final class GalleryCommentsScene extends ToolbarScene
|
||||
return;
|
||||
}
|
||||
|
||||
if (Looper.myLooper() != Looper.getMainLooper()) {
|
||||
// Some devices may run this block in non-UI thread.
|
||||
// It might be a bug of Android OS.
|
||||
// Check it here to avoid crash.
|
||||
return;
|
||||
}
|
||||
|
||||
mEditPanel.setVisibility(View.GONE);
|
||||
((View) mFab).setVisibility(View.VISIBLE);
|
||||
int fabStartX = mEditPanel.getLeft() + (mEditPanel.getWidth() / 2) - (mFab.getWidth() / 2);
|
||||
|
||||
@@ -355,6 +355,11 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean needShowLeftDrawer() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
@@ -1811,7 +1816,13 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
|
||||
r.allowScanningByMediaScanner();
|
||||
r.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
|
||||
DownloadManager dm = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
|
||||
dm.enqueue(r);
|
||||
if (dm != null) {
|
||||
try {
|
||||
dm.enqueue(r);
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (mDialog != null) {
|
||||
|
||||
@@ -832,7 +832,11 @@ public final class GalleryListScene extends BaseScene
|
||||
return false;
|
||||
}
|
||||
|
||||
GalleryInfo gi = mHelper.getDataAt(position);
|
||||
GalleryInfo gi = mHelper.getDataAtEx(position);
|
||||
if (gi == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Bundle args = new Bundle();
|
||||
args.putString(GalleryDetailScene.KEY_ACTION, GalleryDetailScene.ACTION_GALLERY_INFO);
|
||||
args.putParcelable(GalleryDetailScene.KEY_GALLERY_INFO, gi);
|
||||
@@ -946,7 +950,11 @@ public final class GalleryListScene extends BaseScene
|
||||
return false;
|
||||
}
|
||||
|
||||
final GalleryInfo gi = mHelper.getDataAt(position);
|
||||
final GalleryInfo gi = mHelper.getDataAtEx(position);
|
||||
if (gi == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
new AlertDialog.Builder(context)
|
||||
.setTitle(EhUtils.getSuitableTitle(gi))
|
||||
.setItems(R.array.gallery_list_menu_entries, new DialogInterface.OnClickListener() {
|
||||
@@ -1340,7 +1348,7 @@ public final class GalleryListScene extends BaseScene
|
||||
@Nullable
|
||||
@Override
|
||||
public GalleryInfo getDataAt(int position) {
|
||||
return null != mHelper ? mHelper.getDataAt(position) : null;
|
||||
return null != mHelper ? mHelper.getDataAtEx(position) : null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -231,12 +231,14 @@ public class GalleryPreviewsScene extends ToolbarScene implements EasyRecyclerVi
|
||||
public boolean onItemClick(EasyRecyclerView parent, View view, int position, long id) {
|
||||
Context context = getContext2();
|
||||
if (null != context && null != mHelper && null != mGalleryInfo) {
|
||||
GalleryPreview p = mHelper.getDataAt(position);
|
||||
Intent intent = new Intent(context, GalleryActivity.class);
|
||||
intent.setAction(GalleryActivity.ACTION_EH);
|
||||
intent.putExtra(GalleryActivity.KEY_GALLERY_INFO, mGalleryInfo);
|
||||
intent.putExtra(GalleryActivity.KEY_PAGE, p.getPosition());
|
||||
startActivity(intent);
|
||||
GalleryPreview p = mHelper.getDataAtEx(position);
|
||||
if (p != null) {
|
||||
Intent intent = new Intent(context, GalleryActivity.class);
|
||||
intent.setAction(GalleryActivity.ACTION_EH);
|
||||
intent.putExtra(GalleryActivity.KEY_GALLERY_INFO, mGalleryInfo);
|
||||
intent.putExtra(GalleryActivity.KEY_PAGE, p.getPosition());
|
||||
startActivity(intent);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -272,9 +274,11 @@ public class GalleryPreviewsScene extends ToolbarScene implements EasyRecyclerVi
|
||||
@SuppressLint("SetTextI18n")
|
||||
public void onBindViewHolder(GalleryPreviewHolder holder, int position) {
|
||||
if (null != mHelper) {
|
||||
GalleryPreview preview = mHelper.getDataAt(position);
|
||||
preview.load(holder.image);
|
||||
holder.text.setText(Integer.toString(preview.getPosition() + 1));
|
||||
GalleryPreview preview = mHelper.getDataAtEx(position);
|
||||
if (preview != null) {
|
||||
preview.load(holder.image);
|
||||
holder.text.setText(Integer.toString(preview.getPosition() + 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -164,6 +164,9 @@ public class HistoryScene extends ToolbarScene
|
||||
if (null != mLazyList) {
|
||||
mLazyList.close();
|
||||
mLazyList = null;
|
||||
if (mAdapter != null) {
|
||||
mAdapter.notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
if (null != mRecyclerView) {
|
||||
mRecyclerView.stopScroll();
|
||||
@@ -290,6 +293,7 @@ public class HistoryScene extends ToolbarScene
|
||||
|
||||
private class HistoryHolder extends AbstractSwipeableItemViewHolder {
|
||||
|
||||
public final View card;
|
||||
public final LoadImageView thumb;
|
||||
public final TextView title;
|
||||
public final TextView uploader;
|
||||
@@ -301,6 +305,7 @@ public class HistoryScene extends ToolbarScene
|
||||
public HistoryHolder(View itemView) {
|
||||
super(itemView);
|
||||
|
||||
card = itemView.findViewById(R.id.card);
|
||||
thumb = (LoadImageView) itemView.findViewById(R.id.thumb);
|
||||
title = (TextView) itemView.findViewById(R.id.title);
|
||||
uploader = (TextView) itemView.findViewById(R.id.uploader);
|
||||
@@ -312,7 +317,7 @@ public class HistoryScene extends ToolbarScene
|
||||
|
||||
@Override
|
||||
public View getSwipeableContainerView() {
|
||||
return itemView;
|
||||
return card;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -343,7 +348,7 @@ public class HistoryScene extends ToolbarScene
|
||||
|
||||
@Override
|
||||
public HistoryHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
HistoryHolder holder = new HistoryHolder(mInflater.inflate(R.layout.item_gallery_list, parent, false));
|
||||
HistoryHolder holder = new HistoryHolder(mInflater.inflate(R.layout.item_history, parent, false));
|
||||
|
||||
ViewGroup.LayoutParams lp = holder.thumb.getLayoutParams();
|
||||
lp.width = mListThumbWidth;
|
||||
@@ -390,6 +395,9 @@ public class HistoryScene extends ToolbarScene
|
||||
return SwipeableItemConstants.REACTION_CAN_SWIPE_LEFT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSwipeItemStarted(HistoryHolder holder, int position) { }
|
||||
|
||||
@Override
|
||||
public void onSetSwipeBackground(HistoryHolder holder, int position, int type) {}
|
||||
|
||||
@@ -424,7 +432,7 @@ public class HistoryScene extends ToolbarScene
|
||||
HistoryInfo info = mLazyList.get(mPosition);
|
||||
EhDB.deleteHistoryInfo(info);
|
||||
updateLazyList();
|
||||
mAdapter.notifyItemRemoved(mPosition);
|
||||
mAdapter.notifyDataSetChanged();
|
||||
updateView(true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -264,5 +264,11 @@ public final class QuickSearchScene extends ToolbarScene {
|
||||
public boolean onCheckCanDrop(int draggingPosition, int dropPosition) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onItemDragStarted(int position) { }
|
||||
|
||||
@Override
|
||||
public void onItemDragFinished(int fromPosition, int toPosition, boolean result) { }
|
||||
}
|
||||
}
|
||||
@@ -31,6 +31,7 @@ import android.widget.ImageView;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.Settings;
|
||||
import com.hippo.ehviewer.ui.MainActivity;
|
||||
import com.hippo.ehviewer.ui.SetSecurityActivity;
|
||||
import com.hippo.hardware.ShakeDetector;
|
||||
import com.hippo.widget.lockpattern.LockPatternUtils;
|
||||
import com.hippo.widget.lockpattern.LockPatternView;
|
||||
@@ -55,6 +56,7 @@ public class SecurityScene extends SolidScene implements
|
||||
private SensorManager mSensorManager;
|
||||
private Sensor mAccelerometer;
|
||||
private ShakeDetector mShakeDetector;
|
||||
@Nullable
|
||||
private FingerprintManager mFingerprintManager;
|
||||
|
||||
private CancellationSignal mFingerprintCancellationSignal;
|
||||
@@ -234,8 +236,7 @@ public class SecurityScene extends SolidScene implements
|
||||
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
|
||||
&& Settings.getEnableFingerprint()
|
||||
&& mFingerprintManager != null
|
||||
&& mFingerprintManager.isHardwareDetected()
|
||||
&& mFingerprintManager.hasEnrolledFingerprints();
|
||||
&& SetSecurityActivity.hasEnrolledFingerprints(mFingerprintManager);
|
||||
}
|
||||
|
||||
private Runnable mResetFingerprintRunnable = new Runnable() {
|
||||
|
||||
@@ -22,6 +22,7 @@ import android.support.v7.widget.AppCompatEditText;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.MotionEvent;
|
||||
import com.hippo.util.ExceptionUtils;
|
||||
|
||||
public class SearchEditText extends AppCompatEditText {
|
||||
|
||||
@@ -76,7 +77,14 @@ public class SearchEditText extends AppCompatEditText {
|
||||
if (event.getAction() == MotionEvent.ACTION_UP && mListener != null) {
|
||||
mListener.onClick();
|
||||
}
|
||||
return super.onTouchEvent(event);
|
||||
try {
|
||||
return super.onTouchEvent(event);
|
||||
} catch (Throwable t) {
|
||||
// Some devices crash here.
|
||||
// I don't why.
|
||||
ExceptionUtils.throwIfFatal(t);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public interface SearchEditTextListener {
|
||||
|
||||
@@ -22,8 +22,9 @@ import android.content.res.TypedArray;
|
||||
import android.preference.Preference;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
|
||||
import android.widget.Toast;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.util.ExceptionUtils;
|
||||
|
||||
public class ActivityPreference extends Preference {
|
||||
|
||||
@@ -68,6 +69,11 @@ public class ActivityPreference extends Preference {
|
||||
Context context = getContext();
|
||||
Intent intent = new Intent(context, mActivityClazz);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
context.startActivity(intent);
|
||||
try {
|
||||
context.startActivity(intent);
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
Toast.makeText(context, R.string.error_cant_find_activity, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -161,8 +161,10 @@ public abstract class StageActivity extends EhActivity {
|
||||
if (savedInstanceState != null) {
|
||||
mStageId = savedInstanceState.getInt(KEY_STAGE_ID, IntIdGenerator.INVALID_ID);
|
||||
ArrayList<String> list = savedInstanceState.getStringArrayList(KEY_SCENE_TAG_LIST);
|
||||
mSceneTagList.addAll(list);
|
||||
mDelaySceneTagList.addAll(list);
|
||||
if (list != null) {
|
||||
mSceneTagList.addAll(list);
|
||||
mDelaySceneTagList.addAll(list);
|
||||
}
|
||||
mIdGenerator.lazySet(savedInstanceState.getInt(KEY_NEXT_ID));
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,6 @@ package com.hippo.util;
|
||||
import android.app.Activity;
|
||||
import android.app.Dialog;
|
||||
import android.app.Service;
|
||||
import android.content.ActivityNotFoundException;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
@@ -28,7 +27,6 @@ import android.support.annotation.Nullable;
|
||||
import android.view.View;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.hippo.ehviewer.R;
|
||||
|
||||
public class AppHelper {
|
||||
@@ -47,7 +45,8 @@ public class AppHelper {
|
||||
try {
|
||||
from.startActivity(i);
|
||||
return true;
|
||||
} catch (ActivityNotFoundException e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
Toast.makeText(from, R.string.error_cant_find_activity, Toast.LENGTH_SHORT).show();
|
||||
return false;
|
||||
}
|
||||
@@ -63,7 +62,8 @@ public class AppHelper {
|
||||
try {
|
||||
from.startActivity(chooser);
|
||||
return true;
|
||||
} catch (ActivityNotFoundException e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
Toast.makeText(from, R.string.error_cant_find_activity, Toast.LENGTH_SHORT).show();
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ public final class ExceptionUtils {
|
||||
private static final String TAG = ExceptionUtils.class.getSimpleName();
|
||||
|
||||
@NonNull
|
||||
public static String getReadableString(@NonNull Exception e) {
|
||||
public static String getReadableString(@NonNull Throwable e) {
|
||||
e.printStackTrace();
|
||||
if (e instanceof MalformedURLException) {
|
||||
return GetText.getString(R.string.error_invalid_url);
|
||||
@@ -62,4 +62,15 @@ public final class ExceptionUtils {
|
||||
return GetText.getString(R.string.error_unknown);
|
||||
}
|
||||
}
|
||||
|
||||
public static void throwIfFatal(@NonNull Throwable t) {
|
||||
// values here derived from https://github.com/ReactiveX/RxJava/issues/748#issuecomment-32471495
|
||||
if (t instanceof VirtualMachineError) {
|
||||
throw (VirtualMachineError) t;
|
||||
} else if (t instanceof ThreadDeath) {
|
||||
throw (ThreadDeath) t;
|
||||
} else if (t instanceof LinkageError) {
|
||||
throw (LinkageError) t;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -56,10 +56,7 @@ public class NaturalComparator implements Comparator<String> {
|
||||
|
||||
int result;
|
||||
if (isDigit(data1) && isDigit(data2)) {
|
||||
result = Long.compare(Long.valueOf(data1), Long.valueOf(data2));
|
||||
if (result == 0) {
|
||||
result = -Integer.compare(data1.length(), data2.length());
|
||||
}
|
||||
result = compareNumberString(data1, data2);
|
||||
} else {
|
||||
result = data1.compareToIgnoreCase(data2);
|
||||
}
|
||||
@@ -111,4 +108,45 @@ public class NaturalComparator implements Comparator<String> {
|
||||
}
|
||||
return index;
|
||||
}
|
||||
|
||||
private static String removeLeadingZero(String s) {
|
||||
if (s.length() < 1) {
|
||||
return s;
|
||||
}
|
||||
|
||||
// At least keep the last number
|
||||
for (int i = 0, n = s.length() - 1; i < n; i++) {
|
||||
if (s.charAt(i) != '0') {
|
||||
return s.substring(i);
|
||||
}
|
||||
}
|
||||
|
||||
return s.substring(s.length() - 1);
|
||||
}
|
||||
|
||||
private static int compareNumberString(String s1, String s2) {
|
||||
String p1 = removeLeadingZero(s1);
|
||||
String p2 = removeLeadingZero(s2);
|
||||
|
||||
int l1 = p1.length();
|
||||
int l2 = p2.length();
|
||||
|
||||
if (l1 > l2) {
|
||||
return 1;
|
||||
} else if (l1 < l2) {
|
||||
return -1;
|
||||
} else {
|
||||
for (int i = 0; i < l1; i++) {
|
||||
char c1 = p1.charAt(i);
|
||||
char c2 = p2.charAt(i);
|
||||
if (c1 > c2) {
|
||||
return 1;
|
||||
} else if (c1 < c2) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return -Integer.compare(s1.length(), s2.length());
|
||||
}
|
||||
}
|
||||
@@ -40,7 +40,8 @@ public final class PackageUtils {
|
||||
} else {
|
||||
Log.e(TAG, "Can't find signature in package " + packageName);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
Log.e(TAG, "Can't find package " + packageName, e);
|
||||
}
|
||||
return null;
|
||||
|
||||
@@ -44,18 +44,28 @@ public class PermissionRequester {
|
||||
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
ActivityCompat.requestPermissions(activity,
|
||||
new String[]{permission},
|
||||
requestCode);
|
||||
requestPermissions(activity, new String[]{permission}, requestCode);
|
||||
}
|
||||
}).setNegativeButton(android.R.string.cancel, null)
|
||||
.show();
|
||||
} else {
|
||||
ActivityCompat.requestPermissions(activity,
|
||||
new String[]{permission},
|
||||
requestCode);
|
||||
return requestPermissions(activity, new String[]{permission}, requestCode);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean requestPermissions(
|
||||
final Activity activity,
|
||||
final String[] permissions,
|
||||
int requestCode
|
||||
) {
|
||||
try {
|
||||
ActivityCompat.requestPermissions(activity, permissions, requestCode);
|
||||
return true;
|
||||
} catch (Throwable t) {
|
||||
ExceptionUtils.throwIfFatal(t);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -21,6 +21,7 @@ import android.graphics.drawable.Drawable;
|
||||
import android.os.Bundle;
|
||||
import android.os.Parcelable;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
@@ -368,6 +369,15 @@ public class ContentLayout extends FrameLayout {
|
||||
return mData.get(location);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public E getDataAtEx(int location) {
|
||||
if (location >= 0 && location < mData.size()) {
|
||||
return mData.get(location);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return mData.size();
|
||||
}
|
||||
@@ -888,12 +898,13 @@ public class ContentLayout extends FrameLayout {
|
||||
mTipView.setText(bundle.getString(KEY_TIP));
|
||||
|
||||
mSavedDataId = bundle.getInt(KEY_DATA);
|
||||
ArrayList<E> newData = null;
|
||||
EhApplication app = (EhApplication) getContext().getApplicationContext();
|
||||
if (mSavedDataId != IntIdGenerator.INVALID_ID) {
|
||||
ArrayList<E> data = (ArrayList<E>) app.removeGlobalStuff(mSavedDataId);
|
||||
newData = (ArrayList<E>) app.removeGlobalStuff(mSavedDataId);
|
||||
mSavedDataId = IntIdGenerator.INVALID_ID;
|
||||
if (data != null) {
|
||||
mData = data;
|
||||
if (newData != null) {
|
||||
mData = newData;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -902,6 +913,17 @@ public class ContentLayout extends FrameLayout {
|
||||
mStartPage = bundle.getInt(KEY_START_PAGE);
|
||||
mEndPage = bundle.getInt(KEY_END_PAGE);
|
||||
mPages = bundle.getInt(KEY_PAGES);
|
||||
|
||||
notifyDataSetChanged();
|
||||
|
||||
if (newData == null) {
|
||||
mPageDivider.clear();
|
||||
mStartPage = 0;
|
||||
mEndPage = 0;
|
||||
mPages = 0;
|
||||
firstRefresh();
|
||||
}
|
||||
|
||||
return bundle.getParcelable(KEY_SUPER);
|
||||
} else {
|
||||
return state;
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
* 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 com.hippo.widget;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.design.widget.TextInputEditText;
|
||||
import android.util.AttributeSet;
|
||||
import android.widget.TextView;
|
||||
import com.hippo.util.ExceptionUtils;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
// Avoid crash on some Meizu devices
|
||||
// https://github.com/android-in-china/Compatibility/issues/11
|
||||
// https://stackoverflow.com/questions/51891415/nullpointerexception-on-meizu-devices-in-editor-updatecursorpositionmz/52001305
|
||||
public class HackyTextInputEditText extends TextInputEditText {
|
||||
|
||||
private static final boolean HAS_METHOD_UPDATE_CURSOR_POSITION_MZ;
|
||||
private static final Field FIELD_M_HINT;
|
||||
|
||||
static {
|
||||
boolean hasMethodUpdateCursorPositionMz = false;
|
||||
try {
|
||||
Class<?> clazz = ClassLoader.getSystemClassLoader().loadClass("android.widget.Editor");
|
||||
Method[] methods = clazz.getDeclaredMethods();
|
||||
for (Method method : methods) {
|
||||
if ("updateCursorPositionMz".equals(method.getName())) {
|
||||
hasMethodUpdateCursorPositionMz = true;
|
||||
}
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
}
|
||||
|
||||
Field fieldMHint = null;
|
||||
if (hasMethodUpdateCursorPositionMz) {
|
||||
try {
|
||||
fieldMHint = TextView.class.getDeclaredField("mHint");
|
||||
fieldMHint.setAccessible(true);
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
}
|
||||
}
|
||||
|
||||
HAS_METHOD_UPDATE_CURSOR_POSITION_MZ = hasMethodUpdateCursorPositionMz;
|
||||
FIELD_M_HINT = fieldMHint;
|
||||
}
|
||||
|
||||
public HackyTextInputEditText(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getHint() {
|
||||
if (HAS_METHOD_UPDATE_CURSOR_POSITION_MZ && FIELD_M_HINT != null) {
|
||||
try {
|
||||
return getSuperHint();
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
return super.getHint();
|
||||
}
|
||||
} else {
|
||||
return super.getHint();
|
||||
}
|
||||
}
|
||||
|
||||
private CharSequence getSuperHint() throws IllegalAccessException {
|
||||
return (CharSequence) FIELD_M_HINT.get(this);
|
||||
}
|
||||
}
|
||||
@@ -20,6 +20,7 @@ import android.content.Context;
|
||||
import android.support.design.widget.CoordinatorLayout;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.MotionEvent;
|
||||
import com.hippo.util.ExceptionUtils;
|
||||
|
||||
public class SafeCoordinatorLayout extends CoordinatorLayout {
|
||||
|
||||
@@ -39,7 +40,8 @@ public class SafeCoordinatorLayout extends CoordinatorLayout {
|
||||
public boolean onInterceptTouchEvent(MotionEvent ev) {
|
||||
try {
|
||||
return super.onInterceptTouchEvent(ev);
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -48,7 +50,8 @@ public class SafeCoordinatorLayout extends CoordinatorLayout {
|
||||
public boolean onTouchEvent(MotionEvent ev) {
|
||||
try {
|
||||
return super.onTouchEvent(ev);
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,13 +35,13 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:layout_marginTop="16dp">
|
||||
android:layout_marginTop="16dp"
|
||||
android:hint="@string/filter_text">
|
||||
|
||||
<android.support.design.widget.TextInputEditText
|
||||
<com.hippo.widget.HackyTextInputEditText
|
||||
android:id="@+id/edit_text"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/filter_text"
|
||||
android:imeOptions="actionDone"
|
||||
android:inputType="text"
|
||||
android:maxLines="1"
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
android:paddingTop="@dimen/abc_dialog_padding_top_material"
|
||||
android:paddingRight="?attr/dialogPreferredPadding">
|
||||
|
||||
<android.support.design.widget.TextInputEditText
|
||||
<com.hippo.widget.HackyTextInputEditText
|
||||
android:id="@+id/edit_text"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
|
||||
@@ -27,13 +27,13 @@
|
||||
<android.support.design.widget.TextInputLayout
|
||||
android:id="@+id/host_input_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/hosts_host">
|
||||
|
||||
<android.support.design.widget.TextInputEditText
|
||||
<com.hippo.widget.HackyTextInputEditText
|
||||
android:id="@+id/host"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/hosts_host"
|
||||
android:inputType="text"/>
|
||||
|
||||
</android.support.design.widget.TextInputLayout>
|
||||
@@ -41,13 +41,13 @@
|
||||
<android.support.design.widget.TextInputLayout
|
||||
android:id="@+id/ip_input_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/hosts_ip">
|
||||
|
||||
<android.support.design.widget.TextInputEditText
|
||||
<com.hippo.widget.HackyTextInputEditText
|
||||
android:id="@+id/ip"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/hosts_ip"
|
||||
android:inputType="text"/>
|
||||
|
||||
</android.support.design.widget.TextInputLayout>
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
~ 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.
|
||||
-->
|
||||
|
||||
<FrameLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<include
|
||||
layout="@layout/item_gallery_list"
|
||||
android:id="@+id/card"/>
|
||||
|
||||
</FrameLayout>
|
||||
@@ -33,13 +33,13 @@
|
||||
<android.support.design.widget.TextInputLayout
|
||||
android:id="@+id/ip_input_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/ip">
|
||||
|
||||
<android.support.design.widget.TextInputEditText
|
||||
<com.hippo.widget.HackyTextInputEditText
|
||||
android:id="@+id/ip"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/ip"
|
||||
android:inputType="text"/>
|
||||
|
||||
</android.support.design.widget.TextInputLayout>
|
||||
@@ -47,13 +47,13 @@
|
||||
<android.support.design.widget.TextInputLayout
|
||||
android:id="@+id/port_input_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/port">
|
||||
|
||||
<android.support.design.widget.TextInputEditText
|
||||
<com.hippo.widget.HackyTextInputEditText
|
||||
android:id="@+id/port"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/port"
|
||||
android:inputType="numberDecimal"/>
|
||||
|
||||
</android.support.design.widget.TextInputLayout>
|
||||
@@ -61,13 +61,13 @@
|
||||
<android.support.design.widget.TextInputLayout
|
||||
android:id="@+id/passkey_input_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/Passkey">
|
||||
|
||||
<android.support.design.widget.TextInputEditText
|
||||
<com.hippo.widget.HackyTextInputEditText
|
||||
android:id="@+id/passkey"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/Passkey"
|
||||
android:inputType="text"/>
|
||||
|
||||
</android.support.design.widget.TextInputLayout>
|
||||
|
||||
@@ -65,13 +65,13 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:layout_marginTop="@dimen/keyline_margin"
|
||||
android:minWidth="@dimen/single_max_width">
|
||||
android:minWidth="@dimen/single_max_width"
|
||||
android:hint="ipb_member_id">
|
||||
|
||||
<android.support.design.widget.TextInputEditText
|
||||
<com.hippo.widget.HackyTextInputEditText
|
||||
android:id="@+id/ipb_member_id"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="ipb_member_id"
|
||||
android:imeOptions="actionNext"
|
||||
android:inputType="text"
|
||||
android:maxLines="1"
|
||||
@@ -85,13 +85,13 @@
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:minWidth="@dimen/single_max_width">
|
||||
android:minWidth="@dimen/single_max_width"
|
||||
android:hint="ipb_pass_hash">
|
||||
|
||||
<android.support.design.widget.TextInputEditText
|
||||
<com.hippo.widget.HackyTextInputEditText
|
||||
android:id="@+id/ipb_pass_hash"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="ipb_pass_hash"
|
||||
android:imeOptions="actionNext"
|
||||
android:inputType="text"
|
||||
android:maxLines="1"
|
||||
@@ -105,13 +105,13 @@
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:minWidth="@dimen/single_max_width">
|
||||
android:minWidth="@dimen/single_max_width"
|
||||
android:hint="igneous">
|
||||
|
||||
<android.support.design.widget.TextInputEditText
|
||||
<com.hippo.widget.HackyTextInputEditText
|
||||
android:id="@+id/igneous"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="igneous"
|
||||
android:imeOptions="actionDone"
|
||||
android:inputType="text"
|
||||
android:maxLines="1"
|
||||
|
||||
@@ -46,13 +46,13 @@
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:minWidth="@dimen/single_max_width">
|
||||
android:minWidth="@dimen/single_max_width"
|
||||
android:hint="@string/username">
|
||||
|
||||
<android.support.design.widget.TextInputEditText
|
||||
<com.hippo.widget.HackyTextInputEditText
|
||||
android:id="@+id/username"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/username"
|
||||
android:imeOptions="actionNext"
|
||||
android:inputType="text"
|
||||
android:maxLines="1"
|
||||
@@ -66,13 +66,13 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:minWidth="@dimen/single_max_width"
|
||||
android:hint="@string/password"
|
||||
app:passwordToggleEnabled="true">
|
||||
|
||||
<android.support.design.widget.TextInputEditText
|
||||
<com.hippo.widget.HackyTextInputEditText
|
||||
android:id="@+id/password"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/password"
|
||||
android:imeOptions="actionNext"
|
||||
android:inputType="textPassword"
|
||||
android:maxLines="1"
|
||||
@@ -81,31 +81,31 @@
|
||||
</android.support.design.widget.TextInputLayout>
|
||||
|
||||
<android.support.design.widget.TextInputLayout
|
||||
android:id="@+id/recaptcha_layout"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:minWidth="@dimen/single_max_width">
|
||||
android:id="@+id/recaptcha_layout"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:minWidth="@dimen/single_max_width"
|
||||
android:hint="@string/recaptcha">
|
||||
|
||||
<android.support.design.widget.TextInputEditText
|
||||
android:id="@+id/recaptcha"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/recaptcha"
|
||||
android:imeOptions="actionDone"
|
||||
android:inputType="text"
|
||||
android:maxLines="1"
|
||||
android:singleLine="true"/>
|
||||
<com.hippo.widget.HackyTextInputEditText
|
||||
android:id="@+id/recaptcha"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:imeOptions="actionDone"
|
||||
android:inputType="text"
|
||||
android:maxLines="1"
|
||||
android:singleLine="true"/>
|
||||
|
||||
</android.support.design.widget.TextInputLayout>
|
||||
|
||||
<com.hippo.ehviewer.widget.RecaptchaView
|
||||
android:id="@+id/recaptcha_image"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="48dp"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:minWidth="@dimen/single_max_width"
|
||||
android:scaleType="fitCenter"/>
|
||||
android:id="@+id/recaptcha_image"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="48dp"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:minWidth="@dimen/single_max_width"
|
||||
android:scaleType="fitCenter"/>
|
||||
|
||||
<android.support.v4.widget.Space
|
||||
android:layout_width="wrap_content"
|
||||
|
||||
@@ -465,7 +465,6 @@
|
||||
<string name="settings_privacy_about_analytics">Über die Analyse</string>
|
||||
<string name="settings_about_version">Versionnummer</string>
|
||||
<string name="settings_about_check_for_updates">Auf Update überprüfen</string>
|
||||
<string name="settings_about_auto_check_for_updates">Auf Updates automatisch überprüfen</string>
|
||||
<string name="settings_about_beta_update_channel">Beta-Version testen</string>
|
||||
<string name="settings_about_beta_update_channel_summary">Beta-Version kann funktionieren möglicherweise nicht</string>
|
||||
<string name="enable">Aktivieren</string>
|
||||
|
||||
@@ -477,7 +477,6 @@
|
||||
<string name="settings_privacy_about_analytics">Acerca de analytics</string>
|
||||
<string name="settings_about_version">Versión de compilación</string>
|
||||
<string name="settings_about_check_for_updates">Verificar actualizaciones</string>
|
||||
<string name="settings_about_auto_check_for_updates">Verificar automáticamente actualizaciones</string>
|
||||
<string name="settings_about_beta_update_channel">Canal de versiones de prueba</string>
|
||||
<string name="settings_about_beta_update_channel_summary">Las versiones de prueba podrían tener errores</string>
|
||||
|
||||
|
||||
@@ -501,7 +501,6 @@
|
||||
<string name="settings_privacy_about_analytics">A propos de l\'analyse</string>
|
||||
<string name="settings_about_version">Numéro de version</string>
|
||||
<string name="settings_about_check_for_updates">Chercher mise à jour</string>
|
||||
<string name="settings_about_auto_check_for_updates">Chercher les MÀJ automatiquement</string>
|
||||
<string name="settings_about_beta_update_channel">Chaîne de mises à jour beta</string>
|
||||
<string name="settings_about_beta_update_channel_summary">Versions beta riquent de ne pas fonctionner correctement sur votre appareil</string>
|
||||
|
||||
|
||||
@@ -638,7 +638,6 @@
|
||||
<string name="settings_about_changelog">変更履歴</string>
|
||||
<string name="app_language_system">システム言語(既定)</string>
|
||||
<string name="settings_about_telegram">Telegram</string>
|
||||
<string name="settings_about_auto_check_for_updates">更新を自動で確認</string>
|
||||
<string name="download_service">ダウンロードサービス</string>
|
||||
<string name="settings_advanced_built_in_hosts_summary">ホストをアプリ既定のIPにマッピング\nカスタムhosts.txtに上書きされます。</string>
|
||||
<string name="settings_advanced_custom_hosts_title">カスタムhosts.txt</string>
|
||||
|
||||
@@ -497,7 +497,6 @@
|
||||
<string name="settings_privacy_about_analytics">데이터 분석 정보</string>
|
||||
<string name="settings_about_version">빌드 버전</string>
|
||||
<string name="settings_about_check_for_updates">업데이트 확인</string>
|
||||
<string name="settings_about_auto_check_for_updates">업데이트 자동 확인</string>
|
||||
<string name="settings_about_beta_update_channel">베타 업데이트 채널</string>
|
||||
<string name="settings_about_beta_update_channel_summary">베타 버전은 사용자의 기기에서 정상적으로 작동하지 않을 수 있습니다.</string>
|
||||
|
||||
|
||||
@@ -116,6 +116,7 @@
|
||||
<string name="update">更新</string>
|
||||
<string name="update_plain">版本:%1$s\n大小:%2$s\n\n%3$s</string>
|
||||
<string name="update_to_date">EhViewer 已是最新版本</string>
|
||||
<string name="update_ignore">忽略</string>
|
||||
|
||||
<!-- Gallery List -->
|
||||
<string name="gallery_list_search_bar_hint_exhentai">搜索 ExHentai</string>
|
||||
@@ -547,7 +548,6 @@
|
||||
<string name="settings_privacy_about_analytics">关于数据统计</string>
|
||||
<string name="settings_about_version">版本号</string>
|
||||
<string name="settings_about_check_for_updates">检查更新</string>
|
||||
<string name="settings_about_auto_check_for_updates">自动检查更新</string>
|
||||
<string name="settings_about_beta_update_channel">更新测试版</string>
|
||||
<string name="settings_about_beta_update_channel_summary">测试版可能在你的设备上出现不可预知的错误</string>
|
||||
|
||||
|
||||
@@ -116,6 +116,7 @@
|
||||
<string name="update">更新</string>
|
||||
<string name="update_plain">版本:%1$s\n大小:%2$s\n\n%3$s</string>
|
||||
<string name="update_to_date">EhViewer 已是最新版本</string>
|
||||
<string name="update_ignore">忽略</string>
|
||||
|
||||
<!-- Gallery List -->
|
||||
<string name="gallery_list_search_bar_hint_exhentai">搜索 ExHentai</string>
|
||||
|
||||
@@ -116,6 +116,7 @@
|
||||
<string name="update">更新</string>
|
||||
<string name="update_plain">版本:%1$s\n大小:%2$s\n\n%3$s</string>
|
||||
<string name="update_to_date">EhViewer 已是最新版本</string>
|
||||
<string name="update_ignore">忽略</string>
|
||||
|
||||
<!-- Gallery List -->
|
||||
<string name="gallery_list_search_bar_hint_exhentai">在 ExHentai 中搜尋</string>
|
||||
|
||||
@@ -19,5 +19,5 @@
|
||||
|
||||
<bool name="beta">false</bool>
|
||||
<bool name="dad_spin_bars">true</bool>
|
||||
<bool name="auto_check_update">true</bool>
|
||||
|
||||
</resources>
|
||||
@@ -158,6 +158,7 @@
|
||||
<string name="update">Update</string>
|
||||
<string name="update_plain">Version: %1$s\nSize: %2$s\n\n%3$s</string>
|
||||
<string name="update_to_date">You are using the latest version of EhViewer.</string>
|
||||
<string name="update_ignore">Ignore</string>
|
||||
|
||||
<!-- Gallery List -->
|
||||
<string name="gallery_list_search_bar_hint_exhentai">Search ExHentai</string>
|
||||
@@ -593,7 +594,6 @@
|
||||
<string name="settings_privacy_about_analytics">About analytics</string>
|
||||
<string name="settings_about_version">Build version</string>
|
||||
<string name="settings_about_check_for_updates">Check for updates</string>
|
||||
<string name="settings_about_auto_check_for_updates">Auto. check for updates</string>
|
||||
<string name="settings_about_beta_update_channel">Beta update channel</string>
|
||||
<string name="settings_about_beta_update_channel_summary">Beta versions may contain unsolved bugs.</string>
|
||||
|
||||
|
||||
@@ -72,11 +72,6 @@
|
||||
android:summary="@string/settings_about_beta_update_channel_summary"
|
||||
android:defaultValue="@bool/beta"/>
|
||||
|
||||
<com.hippo.preference.SwitchPreference
|
||||
android:key="auto_check_for_updates"
|
||||
android:title="@string/settings_about_auto_check_for_updates"
|
||||
android:defaultValue="@bool/auto_check_update"/>
|
||||
|
||||
<Preference
|
||||
android:key="donate"
|
||||
android:title="@string/settings_about_donate"/>
|
||||
|
||||
@@ -54,6 +54,19 @@ public class NaturalComparatorTest {
|
||||
assertOrder(null, "1");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBigNumber() {
|
||||
assertOrder("1", "22222222222222222222222222222222222222222222222222222222222222222222222");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLeadingZero() {
|
||||
assertOrder("000000000000000001", "1");
|
||||
assertOrder("000000000000000001", "0001");
|
||||
assertOrder("00000000000000000", "0");
|
||||
assertOrder("00000000000000000", "000");
|
||||
}
|
||||
|
||||
private void assertOrder(String s1, String s2) {
|
||||
NaturalComparator comparator = new NaturalComparator();
|
||||
assertTrue(comparator.compare(s1, s2) < 0);
|
||||
|
||||
Reference in new issue
Block a user