mirror of
https://github.com/seven332/EhViewer
synced 2026-11-30 02:58:04 +08:00
Compare commits
174
Commits
0.9.4
...
feature/dict
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d1cac3c1ac | ||
|
|
fbeaf3d5ea | ||
|
|
b4d8168457 | ||
|
|
9561fcf662 | ||
|
|
453a56aa23 | ||
|
|
df108f9678 | ||
|
|
a835ca9547 | ||
|
|
3f4cc46bc1 | ||
|
|
27bc38ae8b | ||
|
|
fd1aca48d6 | ||
|
|
adbb1f11a5 | ||
|
|
4b8e46d220 | ||
|
|
1c45c4b042 | ||
|
|
d33e3c27fc | ||
|
|
189a95e49c | ||
|
|
4e3717fa69 | ||
|
|
97d51b1fc3 | ||
|
|
ba5a554ca8 | ||
|
|
b4095449c1 | ||
|
|
05f9ce59f3 | ||
|
|
793dca3674 | ||
|
|
e10172c09c | ||
|
|
2d65b71fff | ||
|
|
7693275967 | ||
|
|
9d4eadffac | ||
|
|
1bf826a923 | ||
|
|
4866e963de | ||
|
|
2b15c8f620 | ||
|
|
d9265610c3 | ||
|
|
81dce7d297 | ||
|
|
078d086362 | ||
|
|
492d483467 | ||
|
|
d9c1b81eb3 | ||
|
|
a2a9dbcb02 | ||
|
|
97c28c04c5 | ||
|
|
f4d8cbf3a4 | ||
|
|
4291493256 | ||
|
|
ce6cb19e73 | ||
|
|
574d09302e | ||
|
|
f37b479400 | ||
|
|
87c27b6256 | ||
|
|
b3881f8562 | ||
|
|
3f8e872d55 | ||
|
|
3924de80b7 | ||
|
|
7e62673e5a | ||
|
|
69be0c48fb | ||
|
|
9d783fa86d | ||
|
|
28b81a0db0 | ||
|
|
3ac1964069 | ||
|
|
a2241e62a3 | ||
|
|
100a3d872e | ||
|
|
413a17acf1 | ||
|
|
79bc2bcd22 | ||
|
|
c6e45cc080 | ||
|
|
dc1e327caa | ||
|
|
7a215acd18 | ||
|
|
84808429cf | ||
|
|
766c265cd6 | ||
|
|
4cce07e0aa | ||
|
|
e56467dd4d | ||
|
|
90c0d832d7 | ||
|
|
729bef38fb | ||
|
|
59aab0498e | ||
|
|
863170e013 | ||
|
|
e62b86bf7d | ||
|
|
0e018581a0 | ||
|
|
a19f1e2d6d | ||
|
|
987ef9ecf4 | ||
|
|
3de272ae5e | ||
|
|
3ca6b69984 | ||
|
|
084f352d71 | ||
|
|
f4a16b3edd | ||
|
|
e8d8ee8501 | ||
|
|
9a87701ad6 | ||
|
|
cdc8a7aea6 | ||
|
|
247bbec87d | ||
|
|
e839c1e9b5 | ||
|
|
d756b0e451 | ||
|
|
663cb2b5b6 | ||
|
|
3e16c02e50 | ||
|
|
80ca110702 | ||
|
|
5f6a589dd8 | ||
|
|
342028eef1 | ||
|
|
0e96ee7eeb | ||
|
|
3bd52e00d9 | ||
|
|
f612c912a7 | ||
|
|
5dee677ce3 | ||
|
|
19ab3adc9a | ||
|
|
90bfd445d1 | ||
|
|
7493bd57f4 | ||
|
|
629c2bb80d | ||
|
|
4d45d717e2 | ||
|
|
b8e80c6c8c | ||
|
|
efed7776d3 | ||
|
|
56cfc0669b | ||
|
|
6d9ed41382 | ||
|
|
505efbdef6 | ||
|
|
52ab8cebb0 | ||
|
|
e8251ee521 | ||
|
|
d4195c6e5b | ||
|
|
f50975d767 | ||
|
|
4d9452c791 | ||
|
|
474eea094d | ||
|
|
bbb6b634ff | ||
|
|
d5da97141f | ||
|
|
a12f9ba595 | ||
|
|
75944e5a8b | ||
|
|
1aa51a5934 | ||
|
|
092fd6779c | ||
|
|
618dc2b180 | ||
|
|
44a84f2bc2 | ||
|
|
5fb3b61669 | ||
|
|
57a9865d99 | ||
|
|
250e1256b9 | ||
|
|
015bcce8a3 | ||
|
|
b874a259fe | ||
|
|
c8ab84aa9e | ||
|
|
d6efe2c7ba | ||
|
|
46915fed3a | ||
|
|
5d1f599f48 | ||
|
|
9d5877e867 | ||
|
|
e998f80574 | ||
|
|
4faefb3f34 | ||
|
|
c48f282a2d | ||
|
|
d0ad3c158f | ||
|
|
c285562971 | ||
|
|
53ba692375 | ||
|
|
6879c5ea71 | ||
|
|
fa1348860b | ||
|
|
efe4955836 | ||
|
|
ad83f4d3ee | ||
|
|
be129a6147 | ||
|
|
89b224e397 | ||
|
|
97f82d4962 | ||
|
|
4453ddbf07 | ||
|
|
3b9d040881 | ||
|
|
b62b6c7b35 | ||
|
|
045218f8ca | ||
|
|
8b426c72d1 | ||
|
|
51eaa73b9c | ||
|
|
ad081d8192 | ||
|
|
19daaf7ee4 | ||
|
|
643412e11b | ||
|
|
389119c468 | ||
|
|
9b60cdc612 | ||
|
|
203d6134c2 | ||
|
|
87e714aff6 | ||
|
|
125fe0e691 | ||
|
|
0485d9690e | ||
|
|
d7b01d455b | ||
|
|
d7d0c4e250 | ||
|
|
231e463605 | ||
|
|
311185825e | ||
|
|
325cf311df | ||
|
|
cddb51b399 | ||
|
|
c2c98003f1 | ||
|
|
dd6f02395c | ||
|
|
f419264540 | ||
|
|
d7565ce0bb | ||
|
|
095ccf1b55 | ||
|
|
8abefdb6d4 | ||
|
|
0aad8ca1e8 | ||
|
|
0bc4569084 | ||
|
|
337c859040 | ||
|
|
e0cb0fca18 | ||
|
|
b8d5a7d80d | ||
|
|
2ddb234e72 | ||
|
|
19ebd4c28f | ||
|
|
e6367055fb | ||
|
|
ba72dbff7c | ||
|
|
df41c62269 | ||
|
|
a1cea27cdc | ||
|
|
173f01853b | ||
|
|
8568f1c7a0 |
No files matched your search
@@ -1,9 +1,6 @@
|
||||
[submodule "yorozuya"]
|
||||
path = yorozuya
|
||||
url = https://github.com/seven332/Yorozuya
|
||||
[submodule "hotspot"]
|
||||
path = hotspot
|
||||
url = https://github.com/seven332/Hotspot
|
||||
[submodule "easyrecyclerview"]
|
||||
path = easyrecyclerview
|
||||
url = https://github.com/seven332/EasyRecyclerView
|
||||
@@ -13,9 +10,3 @@
|
||||
[submodule "conaco"]
|
||||
path = conaco
|
||||
url = https://github.com/seven332/Conaco
|
||||
[submodule "rippleold"]
|
||||
path = rippleold
|
||||
url = https://github.com/seven332/RippleOld
|
||||
[submodule "unifile"]
|
||||
path = unifile
|
||||
url = https://github.com/seven332/UniFile
|
||||
@@ -14,12 +14,23 @@ An E-Hentai Application for Android.
|
||||
|
||||
# Build
|
||||
|
||||
Windows
|
||||
|
||||
> git clone https://github.com/seven332/EhViewer
|
||||
> cd EhViewer
|
||||
> git submodule update --init
|
||||
> gradlew app:copyNotice
|
||||
> gradlew daogenerator:executeDaoGenerator
|
||||
> gradlew app:assembleDebug
|
||||
|
||||
Linux
|
||||
|
||||
$ git clone https://github.com/seven332/EhViewer
|
||||
$ cd EhViewer
|
||||
$ git submodule update --init
|
||||
$ gradlew app:copyNotice
|
||||
$ gradlew daogenerator:executeDaoGenerator
|
||||
$ gradlew app:assembleDebug
|
||||
$ ./gradlew app:copyNotice
|
||||
$ ./gradlew daogenerator:executeDaoGenerator
|
||||
$ ./gradlew app:assembleDebug
|
||||
|
||||
生成的 apk 文件在 app\build\outputs\apk 目录下
|
||||
|
||||
@@ -72,3 +83,5 @@ Here is the libraries
|
||||
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.
|
||||
|
||||
ic_launcher 图标为 Hippo Seven 所有,所有权利保留
|
||||
+18
-13
@@ -4,15 +4,20 @@ apply plugin: 'com.android.application'
|
||||
|
||||
android {
|
||||
compileSdkVersion 23
|
||||
buildToolsVersion "23.0.2"
|
||||
buildToolsVersion "23.0.3"
|
||||
|
||||
defaultConfig {
|
||||
applicationId "com.hippo.ehviewer"
|
||||
minSdkVersion 16
|
||||
minSdkVersion 14
|
||||
targetSdkVersion 23
|
||||
versionCode 52
|
||||
versionName "0.9.4"
|
||||
versionCode 59
|
||||
versionName "1.0.6"
|
||||
vectorDrawables.useSupportLibrary = true
|
||||
resConfigs "zh", "zh-rCN", "zh-rHK", "zh-rTW"
|
||||
}
|
||||
|
||||
lintOptions {
|
||||
abortOnError true
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
@@ -45,7 +50,7 @@ android {
|
||||
} else {
|
||||
ndkBuilder = 'ndk-build'
|
||||
}
|
||||
commandLine "$ndkDir\\$ndkBuilder",
|
||||
commandLine "$ndkDir/$ndkBuilder",
|
||||
'-C', file('src/main/jni').absolutePath,
|
||||
'-j', Runtime.runtime.availableProcessors()
|
||||
}
|
||||
@@ -69,19 +74,19 @@ dependencies {
|
||||
compile project(':beerbelly')
|
||||
compile project(':conaco')
|
||||
compile project(':easyrecyclerview')
|
||||
compile project(':hotspot')
|
||||
compile project(':okhttp3')
|
||||
compile project(':rippleold')
|
||||
compile project(':unifile')
|
||||
compile project(':yorozuya')
|
||||
compile fileTree(include: ['*.jar'], dir: 'libs')
|
||||
testCompile 'junit:junit:4.12'
|
||||
compile 'com.android.support:appcompat-v7:23.2.1'
|
||||
compile 'com.android.support:customtabs:23.2.1'
|
||||
compile 'com.android.support:design:23.2.1'
|
||||
compile 'com.android.support:appcompat-v7:23.3.0'
|
||||
compile 'com.android.support:design:23.3.0'
|
||||
compile 'com.github.amlcurran.showcaseview:library:5.4.1'
|
||||
compile 'com.h6ah4i.android.widget.advrecyclerview:advrecyclerview:0.8.6'
|
||||
compile 'de.greenrobot:greendao:2.0.0'
|
||||
compile 'com.github.anrwatchdog:anrwatchdog:1.2.0'
|
||||
compile 'com.github.seven332:unifile:0.1.2'
|
||||
compile 'com.github.seven332:drawerLayout:0.1.0'
|
||||
compile 'com.github.seven332:refreshlayout:0.1.0'
|
||||
compile 'com.github.seven332:ripple:0.1.0'
|
||||
compile 'com.h6ah4i.android.widget.advrecyclerview:advrecyclerview:0.8.7'
|
||||
compile 'org.ccil.cowan.tagsoup:tagsoup:1.2.1'
|
||||
compile 'org.jsoup:jsoup:1.8.3'
|
||||
}
|
||||
Binary file not shown.
@@ -27,42 +27,133 @@
|
||||
|
||||
<application
|
||||
android:name="com.hippo.ehviewer.EhApplication"
|
||||
android:allowBackup="true"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:theme="@style/AppTheme">
|
||||
android:theme="@style/AppTheme"
|
||||
android:allowBackup="true"
|
||||
android:fullBackupContent="@xml/backup_scheme"
|
||||
android:largeHeap="true">
|
||||
|
||||
<activity
|
||||
android:name="com.hippo.ehviewer.ui.MainActivity"
|
||||
android:configChanges="screenSize|uiMode"
|
||||
android:theme="@style/AppTheme.Main"
|
||||
android:launchMode="singleTask">
|
||||
android:launchMode="singleTask"
|
||||
android:windowSoftInputMode="stateHidden">
|
||||
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN"/>
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER"/>
|
||||
<category android:name="android.intent.category.DEFAULT"/>
|
||||
</intent-filter>
|
||||
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.VIEW"/>
|
||||
|
||||
<category android:name="android.intent.category.BROWSABLE"/>
|
||||
<category android:name="android.intent.category.DEFAULT"/>
|
||||
|
||||
<category android:name="android.intent.category.BROWSABLE"/>
|
||||
<data android:scheme="http"/>
|
||||
<data android:host="exhentai.org"/>
|
||||
<data android:host="g.e-hentai.org"/>
|
||||
<data android:host="lofi.e-hentai.org"/>
|
||||
</intent-filter>
|
||||
|
||||
<intent-filter android:label="@string/keyword_search">
|
||||
<action android:name="android.intent.action.SEND"/>
|
||||
<category android:name="android.intent.category.DEFAULT"/>
|
||||
<data android:mimeType="text/plain"/>
|
||||
</intent-filter>
|
||||
|
||||
<intent-filter android:label="@string/image_search">
|
||||
<action android:name="android.intent.action.SEND"/>
|
||||
<category android:name="android.intent.category.DEFAULT"/>
|
||||
<data android:mimeType="image/*"/>
|
||||
</intent-filter>
|
||||
|
||||
</activity>
|
||||
|
||||
<activity
|
||||
android:name="com.hippo.ehviewer.ui.DumpBrowsableActivity"
|
||||
android:configChanges="screenSize|uiMode"
|
||||
android:theme="@style/AppTheme.NoActionBar">
|
||||
|
||||
<intent-filter android:priority="-10">
|
||||
<action android:name="android.intent.action.VIEW"/>
|
||||
<category android:name="android.intent.category.DEFAULT"/>
|
||||
<category android:name="android.intent.category.BROWSABLE"/>
|
||||
<data android:scheme="http"/>
|
||||
<data android:host="exhentai.org"/>
|
||||
<data android:host="g.e-hentai.org"/>
|
||||
<data android:host="lofi.e-hentai.org"/>
|
||||
<data android:pathPrefix="/g/"/>
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<activity-alias
|
||||
android:name="com.hippo.ehviewer.ui.DumpBrowsableActivity2"
|
||||
android:targetActivity="com.hippo.ehviewer.ui.DumpBrowsableActivity"
|
||||
android:configChanges="screenSize|uiMode"
|
||||
android:theme="@style/AppTheme.NoActionBar">
|
||||
|
||||
<intent-filter android:priority="-10">
|
||||
<action android:name="android.intent.action.VIEW"/>
|
||||
<category android:name="android.intent.category.DEFAULT"/>
|
||||
<category android:name="android.intent.category.BROWSABLE"/>
|
||||
<data android:scheme="http"/>
|
||||
<data android:host="exhentai.org"/>
|
||||
<data android:host="g.e-hentai.org"/>
|
||||
<data android:host="lofi.e-hentai.org"/>
|
||||
<data android:pathPrefix="/s/"/>
|
||||
</intent-filter>
|
||||
</activity-alias>
|
||||
|
||||
<activity
|
||||
android:name="com.hippo.ehviewer.ui.DictImportActivity"
|
||||
android:configChanges="screenSize|uiMode"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="@string/dict_import"
|
||||
android:launchMode="singleTask"
|
||||
android:theme="@style/AppTheme.Dialog">
|
||||
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.VIEW"/>
|
||||
<category android:name="android.intent.category.DEFAULT"/>
|
||||
<data android:scheme="file"/>
|
||||
<data android:host="*"/>
|
||||
<data android:pathPattern=".*\\.ehdict"/>
|
||||
</intent-filter>
|
||||
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.VIEW"/>
|
||||
<category android:name="android.intent.category.DEFAULT"/>
|
||||
<data android:scheme="file"/>
|
||||
<data android:host="*"/>
|
||||
<data android:mimeType="*/*"/>
|
||||
<data android:pathPattern=".*\\.ehdict"/>
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<activity
|
||||
android:name="com.hippo.ehviewer.ui.GalleryActivity"
|
||||
android:configChanges="screenSize|uiMode"
|
||||
android:theme="@style/AppTheme.Gallery"
|
||||
android:launchMode="singleTask"/>
|
||||
android:launchMode="singleTask">
|
||||
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.VIEW"/>
|
||||
<category android:name="android.intent.category.DEFAULT"/>
|
||||
<data android:scheme="file"/>
|
||||
<data android:host="*"/>
|
||||
<data android:pathPattern=".*\\.zip"/>
|
||||
</intent-filter>
|
||||
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.VIEW"/>
|
||||
<category android:name="android.intent.category.DEFAULT"/>
|
||||
<data android:scheme="file"/>
|
||||
<data android:host="*"/>
|
||||
<data android:mimeType="*/*"/>
|
||||
<data android:pathPattern=".*\\.zip"/>
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<activity
|
||||
android:name="com.hippo.ehviewer.ui.SettingsActivity"
|
||||
@@ -87,6 +178,12 @@
|
||||
android:theme="@style/AppTheme.NoActionBar"
|
||||
android:label="@string/license"/>
|
||||
|
||||
<activity
|
||||
android:name="com.hippo.ehviewer.ui.DictActivity"
|
||||
android:configChanges="screenSize|uiMode"
|
||||
android:theme="@style/AppTheme.NoActionBar"
|
||||
android:label="@string/dict"/>
|
||||
|
||||
<activity
|
||||
android:name="com.hippo.ehviewer.ui.FilterActivity"
|
||||
android:configChanges="screenSize|uiMode"
|
||||
@@ -104,5 +201,10 @@
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="@string/download_service_label"/>
|
||||
|
||||
<service
|
||||
android:name="com.hippo.dict.DictImportService"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="@string/import_dict_service">
|
||||
</service>
|
||||
</application>
|
||||
</manifest>
|
||||
@@ -0,0 +1,240 @@
|
||||
package com.hippo.dict;
|
||||
|
||||
/*
|
||||
* Copyright (C) 2015 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.
|
||||
*/
|
||||
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.database.sqlite.SQLiteOpenHelper;
|
||||
import android.database.sqlite.SQLiteStatement;
|
||||
import android.net.Uri;
|
||||
import android.text.TextUtils;
|
||||
import android.util.JsonReader;
|
||||
import android.util.Log;
|
||||
|
||||
import com.hippo.util.SqlUtils;
|
||||
import com.hippo.yorozuya.ArrayUtils;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
public class DictDatabase {
|
||||
|
||||
private static final String TAG = DictDatabase.class.getSimpleName();
|
||||
private static final boolean DEBUG = false;
|
||||
|
||||
public static final String COLUMN_PARENT = "parent";
|
||||
public static final String COLUMN_DATA = "data";
|
||||
public static final String COLUMN_DICT = "dict_name";
|
||||
|
||||
private static final String DATABASE_NAME = "dict_database.db";
|
||||
private static final String TABLE_DICT = "dictionary";
|
||||
private static final String SEPARATOR = "@@@";
|
||||
private final SQLiteDatabase mDatabase;
|
||||
private static DictDatabase sInstance;
|
||||
|
||||
private String mDictName;
|
||||
private boolean mAbortFlag = false;
|
||||
|
||||
private final AtomicBoolean mBusyFlag = new AtomicBoolean();
|
||||
|
||||
public static DictDatabase getInstance(Context context) {
|
||||
if (sInstance == null) {
|
||||
sInstance = new DictDatabase(context.getApplicationContext());
|
||||
}
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
private DictDatabase(Context context) {
|
||||
DatabaseHelper databaseHelper = new DatabaseHelper(context);
|
||||
mDatabase = databaseHelper.getWritableDatabase();
|
||||
}
|
||||
|
||||
public String[] getSuggestions(String prefix) {
|
||||
if (TextUtils.isEmpty(prefix) || mBusyFlag.get()) {
|
||||
return ArrayUtils.EMPTY_STRING_ARRAY;
|
||||
}
|
||||
|
||||
String command = "SELECT * FROM " + TABLE_DICT + " WHERE " + COLUMN_DATA +
|
||||
" MATCH '" + SqlUtils.sqlEscapeString(prefix) + "' LIMIT 5;";
|
||||
Cursor cursor = mDatabase.rawQuery(command, null);
|
||||
Set<String> queryList = new HashSet<>();
|
||||
int queryIndex = cursor.getColumnIndex(COLUMN_DATA);
|
||||
if (cursor.moveToFirst()) {
|
||||
while (!cursor.isAfterLast()) {
|
||||
String datum = cursor.getString(queryIndex);
|
||||
String data[] = datum.split(SEPARATOR);
|
||||
for (String item : data) {
|
||||
if (TextUtils.isEmpty(item) || datum.equals(prefix)) {
|
||||
continue;
|
||||
}
|
||||
queryList.add(item);
|
||||
}
|
||||
cursor.moveToNext();
|
||||
}
|
||||
}
|
||||
cursor.close();
|
||||
return queryList.toArray(new String[queryList.size()]);
|
||||
}
|
||||
|
||||
public void importDict(Context context, final Uri dictUri, final DictImportService.ProcessListener listener) throws IOException, URISyntaxException {
|
||||
mAbortFlag = false;
|
||||
int itemNum = -1;
|
||||
InputStream inputStream = context.getContentResolver().openInputStream(dictUri);
|
||||
if (null == inputStream) {
|
||||
throw new FileNotFoundException("Can't find " + dictUri);
|
||||
}
|
||||
JsonReader jsonReader = new JsonReader(new InputStreamReader(inputStream, "UTF-8"));
|
||||
|
||||
jsonReader.beginObject();
|
||||
while (jsonReader.hasNext()) {
|
||||
String field = jsonReader.nextName();
|
||||
if (field.equals("dict")) {
|
||||
mDictName = jsonReader.nextString();
|
||||
if (DEBUG) {
|
||||
Log.d(TAG, "[importDict] parse the dict name -- " + mDictName);
|
||||
}
|
||||
} else if (field.equals("num")) {
|
||||
if (TextUtils.isEmpty(mDictName)) {
|
||||
break;
|
||||
}
|
||||
itemNum = jsonReader.nextInt();
|
||||
listener.processTotal(itemNum);
|
||||
if (DEBUG) {
|
||||
Log.d(TAG, "[importDict] parse the item number -- " + itemNum);
|
||||
}
|
||||
} else if (field.equals("data")) {
|
||||
if (TextUtils.isEmpty(mDictName) || itemNum <= 0) {
|
||||
break;
|
||||
}
|
||||
deleteDict(mDictName);
|
||||
parseData(jsonReader, listener);
|
||||
}
|
||||
}
|
||||
jsonReader.endObject();
|
||||
jsonReader.close();
|
||||
listener.processComplete();
|
||||
}
|
||||
|
||||
public void deleteDict(String dict) {
|
||||
if (mBusyFlag.get()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (DEBUG) {
|
||||
Log.d(TAG, "[deleteDict] dict:" + dict);
|
||||
}
|
||||
mDatabase.delete(TABLE_DICT, COLUMN_DICT + "=?", new String[]{dict});
|
||||
}
|
||||
|
||||
public void importAbort() {
|
||||
if (DEBUG) {
|
||||
Log.d(TAG, "[importAbort] set mAbortFlag true");
|
||||
}
|
||||
mAbortFlag = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the database. This version has extra support for using the version field
|
||||
* as a mode flags field, and configures the database columns depending on the mode bits
|
||||
* (features) requested by the extending class.
|
||||
*/
|
||||
private static class DatabaseHelper extends SQLiteOpenHelper {
|
||||
|
||||
public DatabaseHelper(Context context) {
|
||||
super(context, DATABASE_NAME, null, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(SQLiteDatabase db) {
|
||||
db.execSQL("CREATE VIRTUAL TABLE " + TABLE_DICT + " USING fts4 (" +
|
||||
COLUMN_DATA +
|
||||
", " + COLUMN_PARENT +
|
||||
", " + COLUMN_DICT +
|
||||
", tokenize=icu th_ZH" +
|
||||
");");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
|
||||
db.execSQL("DROP TABLE IF EXISTS " + TABLE_DICT);
|
||||
onCreate(db);
|
||||
}
|
||||
}
|
||||
|
||||
private void parseData(JsonReader jsonReader, final DictImportService.ProcessListener listener) throws IOException {
|
||||
mBusyFlag.lazySet(true);
|
||||
int process = 1;
|
||||
SQLiteStatement insStmt = mDatabase.compileStatement("INSERT INTO " + TABLE_DICT + " VALUES (?, ?, ?);");
|
||||
mDatabase.beginTransaction();
|
||||
jsonReader.beginArray();
|
||||
try {
|
||||
while (jsonReader.hasNext()) {
|
||||
synchronized (this) {
|
||||
if (mAbortFlag) {
|
||||
if (DEBUG) {
|
||||
Log.d(TAG, "[parseData] import abort, delete the dict -- " + mDictName);
|
||||
}
|
||||
deleteDict(mDictName);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
parseSingleData(jsonReader, insStmt);
|
||||
listener.process(process);
|
||||
process++;
|
||||
}
|
||||
jsonReader.endArray();
|
||||
mDatabase.setTransactionSuccessful();
|
||||
} finally {
|
||||
mDatabase.endTransaction();
|
||||
mBusyFlag.lazySet(false);
|
||||
}
|
||||
}
|
||||
|
||||
private void parseSingleData(JsonReader jsonReader, SQLiteStatement insStmt) throws IOException {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
String parent = "";
|
||||
sb.append(SEPARATOR);
|
||||
jsonReader.beginObject();
|
||||
while (jsonReader.hasNext()) {
|
||||
String name = jsonReader.nextName();
|
||||
String content = jsonReader.nextString();
|
||||
if (name.equals("parent")) {
|
||||
parent = content;
|
||||
} else {
|
||||
sb.append(content);
|
||||
sb.append(SEPARATOR);
|
||||
}
|
||||
}
|
||||
jsonReader.endObject();
|
||||
|
||||
if (DEBUG) {
|
||||
Log.d(TAG, "[parseSingleData] item:" + parent + " " + sb.toString());
|
||||
}
|
||||
insStmt.bindString(1, sb.toString());
|
||||
insStmt.bindString(2, parent);
|
||||
insStmt.bindString(3, mDictName);
|
||||
insStmt.executeInsert();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,218 @@
|
||||
package com.hippo.dict;
|
||||
|
||||
import android.app.Service;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Binder;
|
||||
import android.os.IBinder;
|
||||
import android.util.Log;
|
||||
|
||||
import com.hippo.util.TextUrl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class DictImportService extends Service {
|
||||
private static final String TAG = "DictImportService";
|
||||
private static final boolean DEBUG = false;
|
||||
|
||||
private DictManager mDictManager;
|
||||
private final List<ProcessListener> mListeners = new ArrayList<>();
|
||||
private ProcessListener mDictProcessListener;
|
||||
private AsyncTask mImportAsyncTask;
|
||||
private DictNotification mDictNotification;
|
||||
|
||||
// current task information
|
||||
private int mItemNum;
|
||||
private Uri mDictUri;
|
||||
private boolean mRunningFlag = false;
|
||||
|
||||
public DictImportService() {}
|
||||
|
||||
private final Binder serviceBinder = new DictImportServiceBinder();
|
||||
|
||||
@Override
|
||||
public IBinder onBind(Intent intent) {
|
||||
return serviceBinder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
mDictManager = new DictManager(this);
|
||||
mDictNotification = new DictNotification(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
|
||||
return super.onStartCommand(intent, flags, startId);
|
||||
}
|
||||
|
||||
public interface ProcessListener {
|
||||
void process(int progress);
|
||||
|
||||
void processTotal(int total);
|
||||
|
||||
void processComplete();
|
||||
}
|
||||
|
||||
public class DictImportServiceBinder extends Binder {
|
||||
public DictImportService getService() {
|
||||
return DictImportService.this;
|
||||
}
|
||||
}
|
||||
|
||||
public void importDict(Uri dictUri) {
|
||||
if (dictUri == null) {
|
||||
// TODO error tip
|
||||
if (DEBUG) {
|
||||
Log.e(TAG, "[importDict] dictUri is null");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (DEBUG) {
|
||||
Log.d(TAG, "[importDict] start import async task");
|
||||
}
|
||||
mImportAsyncTask = new ImportAsyncTask(dictUri).execute();
|
||||
}
|
||||
|
||||
public void abortImport() {
|
||||
if (mImportAsyncTask == null) {
|
||||
if (DEBUG) {
|
||||
Log.e(TAG, "[abortImport] mImportAsyncTask is null");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (DEBUG) {
|
||||
Log.d(TAG, "[abortImport] import abort");
|
||||
}
|
||||
|
||||
// fixme
|
||||
// this i just set a flag to abort the parse thread,it may cause a exception
|
||||
// it there may be a elegant way to shut the worker thread down
|
||||
mDictManager.importAbort();
|
||||
|
||||
// just for service go die
|
||||
mImportAsyncTask.cancel(true);
|
||||
}
|
||||
|
||||
public Uri getUri() {
|
||||
return mDictUri;
|
||||
}
|
||||
|
||||
public int getItemNum() {
|
||||
return mItemNum;
|
||||
}
|
||||
|
||||
public boolean isRunning() {
|
||||
return mRunningFlag;
|
||||
}
|
||||
|
||||
public void setOnProgressListener(ProcessListener onProgressListener) {
|
||||
if (onProgressListener != null) {
|
||||
mListeners.add(onProgressListener);
|
||||
mListeners.remove(mDictNotification.mNotificationListener);
|
||||
mDictNotification.stopNotify();
|
||||
}
|
||||
}
|
||||
|
||||
public void removeOnProgressListener(ProcessListener onProgressListener) {
|
||||
if (onProgressListener != null) {
|
||||
mListeners.remove(onProgressListener);
|
||||
}
|
||||
|
||||
// if there is no listener in listener list,we is in the background mostly
|
||||
// we post the process progress information to a notification
|
||||
if (mListeners.size() == 0 && null != mDictUri) {
|
||||
mDictNotification.setMax(mItemNum);
|
||||
mDictNotification.setFileName(TextUrl.getFileName(mDictUri.toString()));
|
||||
mListeners.add(mDictNotification.mNotificationListener);
|
||||
}
|
||||
}
|
||||
|
||||
class ImportAsyncTask extends AsyncTask<Void, Integer, Void> {
|
||||
|
||||
public ImportAsyncTask(Uri dictUri) {
|
||||
mDictUri = dictUri;
|
||||
mRunningFlag = true;
|
||||
mDictProcessListener = new ProcessListener() {
|
||||
@Override
|
||||
public void process(int progress) {
|
||||
if (DEBUG) {
|
||||
Log.d(TAG, "[process] progress:" + progress);
|
||||
}
|
||||
publishProgress(progress);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processTotal(int total) {
|
||||
if (DEBUG) {
|
||||
Log.d(TAG, "process total " + total);
|
||||
}
|
||||
mItemNum = total;
|
||||
for (ProcessListener listener : mListeners) {
|
||||
listener.processTotal(total);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processComplete() {
|
||||
// we don't do any thing here,let async task handle this
|
||||
if (DEBUG) {
|
||||
Log.d(TAG, "processComplete");
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(Void... voids) {
|
||||
try {
|
||||
mDictManager.importDict(DictImportService.this, mDictUri, mDictProcessListener);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onProgressUpdate(Integer... progress) {
|
||||
super.onProgressUpdate(progress);
|
||||
|
||||
if (DEBUG) {
|
||||
Log.d(TAG, "[onProgressUpdate] process item " + progress[0]);
|
||||
}
|
||||
for (ProcessListener listener : mListeners) {
|
||||
listener.process(progress[0]);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Void aVoid) {
|
||||
super.onPostExecute(aVoid);
|
||||
for (ProcessListener listener : mListeners) {
|
||||
listener.processComplete();
|
||||
}
|
||||
mRunningFlag = false;
|
||||
DictImportService.this.goDie();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCancelled() {
|
||||
super.onCancelled();
|
||||
DictImportService.this.goDie();
|
||||
}
|
||||
}
|
||||
|
||||
public void goDie() {
|
||||
if (DEBUG) {
|
||||
Log.d(TAG, "[goDie] task done or abort,go to die");
|
||||
}
|
||||
this.stopSelf();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package com.hippo.dict;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
// TODO Singleton
|
||||
// TODO Add add-dict callback for DictActivity
|
||||
public class DictManager {
|
||||
|
||||
// pattern for language
|
||||
private static final String enRegEx = "^[0-9a-zA-Z_\\s]+$";
|
||||
// private static final String zhRegEx = "";
|
||||
|
||||
private final DictDatabase mDictDatabase;
|
||||
|
||||
public DictManager(Context context) {
|
||||
mDictDatabase = DictDatabase.getInstance(context);
|
||||
}
|
||||
|
||||
public void importDict(Context context, final Uri dictUri, final DictImportService.ProcessListener listener)
|
||||
throws IOException, URISyntaxException {
|
||||
mDictDatabase.importDict(context, dictUri, listener);
|
||||
}
|
||||
|
||||
public void deletDict(String dict) {
|
||||
mDictDatabase.deleteDict(dict);
|
||||
}
|
||||
|
||||
public String[] getSuggestions(String prefix) {
|
||||
List<String> result = new ArrayList<>();
|
||||
String databaseResult[] = mDictDatabase.getSuggestions(prefix);
|
||||
for (String s : databaseResult) {
|
||||
if (filter(s)) {
|
||||
result.add(s);
|
||||
}
|
||||
}
|
||||
return result.toArray(new String[result.size()]);
|
||||
}
|
||||
|
||||
public void importAbort() {
|
||||
mDictDatabase.importAbort();
|
||||
}
|
||||
|
||||
public boolean filter(String item) {
|
||||
// return true;
|
||||
Pattern en = Pattern.compile(enRegEx);
|
||||
Matcher m = en.matcher(item);
|
||||
return m.matches();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
package com.hippo.dict;
|
||||
|
||||
import android.app.NotificationManager;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.os.SystemClock;
|
||||
import android.support.v7.app.NotificationCompat;
|
||||
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.ui.DictImportActivity;
|
||||
import com.hippo.ehviewer.ui.MainActivity;
|
||||
|
||||
|
||||
public class DictNotification {
|
||||
|
||||
private final Context mContext;
|
||||
private final NotificationManager mNotifyManager;
|
||||
private final NotificationCompat.Builder mBuilder;
|
||||
private int mMax = 100;
|
||||
private final int mId = 1;
|
||||
private long mLastUpdateTime;
|
||||
|
||||
private final PendingIntent mImportIntent;
|
||||
private final PendingIntent mDoneIntent;
|
||||
|
||||
public DictNotification(Context context) {
|
||||
|
||||
mContext = context;
|
||||
mNotifyManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
mBuilder = new NotificationCompat.Builder(mContext);
|
||||
|
||||
mImportIntent = PendingIntent.getActivity(context, 0, new Intent(context, DictImportActivity.class), 0);
|
||||
Intent intent = new Intent(context, MainActivity.class);
|
||||
intent.setAction(Intent.ACTION_MAIN);
|
||||
mDoneIntent = PendingIntent.getActivity(context, 0, intent, 0);
|
||||
|
||||
mBuilder.setContentTitle(mContext.getResources().getString(R.string.dict_import))
|
||||
.setContentText("0/" + mMax)
|
||||
.setSmallIcon(R.drawable.ic_stat_import)
|
||||
.setLargeIcon(BitmapFactory.decodeResource(mContext.getResources(), R.mipmap.ic_launcher))
|
||||
.setContentIntent(mImportIntent)
|
||||
.setOngoing(true);
|
||||
}
|
||||
|
||||
public DictImportService.ProcessListener mNotificationListener = new DictImportService.ProcessListener() {
|
||||
@Override
|
||||
public void process(int progress) {
|
||||
DictNotification.this.notify(progress);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processTotal(int total) {
|
||||
// this may useless
|
||||
mMax = total;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processComplete() {
|
||||
DictNotification.this.notifyDone();
|
||||
}
|
||||
};
|
||||
|
||||
public void setMax(int max) {
|
||||
mMax = max;
|
||||
mBuilder.setContentText("0/" + mMax);
|
||||
}
|
||||
|
||||
public void setFileName(String fileName) {
|
||||
mBuilder.setContentTitle(mContext.getString(R.string.dict_import) + " " + fileName);
|
||||
}
|
||||
|
||||
public void notify(int progress) {
|
||||
// Avoid update frequently
|
||||
long now = SystemClock.currentThreadTimeMillis();
|
||||
if (now - mLastUpdateTime < 500L) {
|
||||
return;
|
||||
}
|
||||
mLastUpdateTime = now;
|
||||
mBuilder.setContentIntent(mImportIntent);
|
||||
mBuilder.setProgress(mMax, progress, false);
|
||||
mBuilder.setContentText(progress + "/" + mMax);
|
||||
mNotifyManager.notify(mId, mBuilder.build());
|
||||
}
|
||||
|
||||
public void notifyDone() {
|
||||
mBuilder.setContentIntent(mDoneIntent);
|
||||
mBuilder.setContentTitle(mContext.getString(R.string.dict_import_successfully));
|
||||
mBuilder.setContentText(mMax + "/" + mMax);
|
||||
mBuilder.setProgress(0, 0, false);
|
||||
mBuilder.setOngoing(false);
|
||||
mBuilder.setAutoCancel(true);
|
||||
mNotifyManager.notify(mId, mBuilder.build());
|
||||
}
|
||||
|
||||
public void stopNotify() {
|
||||
mNotifyManager.cancel(mId);
|
||||
}
|
||||
}
|
||||
@@ -59,6 +59,7 @@ public class BatteryDrawable extends Drawable {
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("SuspiciousNameCombination")
|
||||
protected void onBoundsChange(Rect bounds) {
|
||||
int width = bounds.width();
|
||||
int height = bounds.height();
|
||||
@@ -89,8 +90,9 @@ public class BatteryDrawable extends Drawable {
|
||||
*/
|
||||
@Override
|
||||
public void draw(Canvas canvas) {
|
||||
if (mElect == -1)
|
||||
if (mElect == -1) {
|
||||
return;
|
||||
}
|
||||
|
||||
mElectRect.right = MathUtils.lerp(mStart, mStop, mElect / 100.0f);
|
||||
|
||||
@@ -152,21 +154,22 @@ public class BatteryDrawable extends Drawable {
|
||||
}
|
||||
|
||||
private void updatePaint(boolean warn) {
|
||||
if (warn)
|
||||
if (warn) {
|
||||
mPaint.setColor(mWarningColor);
|
||||
else
|
||||
} else {
|
||||
mPaint.setColor(mColor);
|
||||
}
|
||||
invalidateSelf();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAlpha(int alpha) {
|
||||
// Empty
|
||||
mPaint.setAlpha(alpha);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setColorFilter(ColorFilter cf) {
|
||||
// Empty
|
||||
mPaint.setColorFilter(cf);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -38,7 +38,7 @@ public class DrawerArrowDrawable extends Drawable {
|
||||
|
||||
private final Paint mPaint = new Paint();
|
||||
|
||||
// The angle in degress that the arrow head is inclined at.
|
||||
// The angle in degrees that the arrow head is inclined at.
|
||||
private static final float ARROW_HEAD_ANGLE = (float) Math.toRadians(45);
|
||||
private final float mBarThickness;
|
||||
// The length of top and bottom bars when they merge into an arrow
|
||||
@@ -61,7 +61,7 @@ public class DrawerArrowDrawable extends Drawable {
|
||||
// The interpolated version of the original progress
|
||||
private float mProgress;
|
||||
// the amount that overlaps w/ bar size when rotation is max
|
||||
private float mMaxCutForBarSize;
|
||||
private final float mMaxCutForBarSize;
|
||||
|
||||
/**
|
||||
* @param context used to get the configuration for the drawable from
|
||||
|
||||
@@ -20,9 +20,15 @@ import android.content.Context;
|
||||
import android.os.Environment;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import com.hippo.ehviewer.client.exception.ParseException;
|
||||
import com.hippo.util.ReadableTime;
|
||||
import com.hippo.yorozuya.FileUtils;
|
||||
import com.hippo.yorozuya.IOUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
||||
public class AppConfig {
|
||||
|
||||
@@ -113,4 +119,47 @@ public class AppConfig {
|
||||
public static File createExternalTempFile() {
|
||||
return FileUtils.createTempFile(getExternalTempDir(), null);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static File getTempDir() {
|
||||
File dir = sContext.getCacheDir();
|
||||
File file;
|
||||
if (null != dir && FileUtils.ensureDirectory(file = new File(dir, TEMP))) {
|
||||
return file;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static File createTempFile() {
|
||||
return FileUtils.createTempFile(getTempDir(), null);
|
||||
}
|
||||
|
||||
public static void saveParseErrorBody(ParseException e) {
|
||||
File dir = getExternalParseErrorDir();
|
||||
if (null == dir) {
|
||||
return;
|
||||
}
|
||||
|
||||
File file = new File(dir, ReadableTime.getFilenamableTime(System.currentTimeMillis()) + ".txt");
|
||||
OutputStream os = null;
|
||||
try {
|
||||
os = new FileOutputStream(file);
|
||||
String message = e.getMessage();
|
||||
String body = e.getBody();
|
||||
if (null != message) {
|
||||
os.write(message.getBytes("utf-8"));
|
||||
os.write('\n');
|
||||
}
|
||||
if (null != body) {
|
||||
os.write(body.getBytes("utf-8"));
|
||||
}
|
||||
os.flush();
|
||||
} catch (IOException e1) {
|
||||
// Ignore
|
||||
} finally {
|
||||
IOUtils.closeQuietly(os);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -28,13 +28,15 @@ import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.util.LruCache;
|
||||
import android.util.Log;
|
||||
import android.util.SparseArray;
|
||||
|
||||
import com.github.anrwatchdog.ANRError;
|
||||
import com.github.anrwatchdog.ANRWatchDog;
|
||||
import com.hippo.beerbelly.SimpleDiskCache;
|
||||
import com.hippo.conaco.Conaco;
|
||||
import com.hippo.ehviewer.client.EhClient;
|
||||
import com.hippo.ehviewer.client.EhCookieStore;
|
||||
import com.hippo.ehviewer.client.EhEngine;
|
||||
import com.hippo.ehviewer.client.EhUrl;
|
||||
import com.hippo.ehviewer.client.data.GalleryDetail;
|
||||
import com.hippo.ehviewer.download.DownloadManager;
|
||||
import com.hippo.ehviewer.spider.SpiderDen;
|
||||
@@ -43,31 +45,37 @@ import com.hippo.network.StatusCodeException;
|
||||
import com.hippo.okhttp.CookieDB;
|
||||
import com.hippo.scene.SceneApplication;
|
||||
import com.hippo.text.Html;
|
||||
import com.hippo.unifile.UniFile;
|
||||
import com.hippo.util.BitmapUtils;
|
||||
import com.hippo.util.ReadableTime;
|
||||
import com.hippo.yorozuya.FileUtils;
|
||||
import com.hippo.yorozuya.IntIdGenerator;
|
||||
import com.hippo.yorozuya.SimpleHandler;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.WeakHashMap;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import okhttp3.Cookie;
|
||||
import okhttp3.HttpUrl;
|
||||
import okhttp3.OkHttpClient;
|
||||
|
||||
public class EhApplication extends SceneApplication implements Thread.UncaughtExceptionHandler {
|
||||
|
||||
private static final String TAG = EhApplication.class.getSimpleName();
|
||||
|
||||
public static final boolean BETA = true;
|
||||
public static final boolean BETA = false;
|
||||
|
||||
private static final boolean DEBUG_CONACO = false;
|
||||
private static final boolean DEBUG_NATIVE_MEMORY = false;
|
||||
|
||||
private Thread.UncaughtExceptionHandler mDefaultHandler;
|
||||
|
||||
private final AtomicInteger mIdGenerator = new AtomicInteger();
|
||||
private final SparseArray<Object> mGlobalStuffMap = new SparseArray<>();
|
||||
private final IntIdGenerator mIdGenerator = new IntIdGenerator();
|
||||
private final WeakHashMap<Integer, Object> mGlobalStuffMap = new WeakHashMap<>();
|
||||
private EhCookieStore mEhCookieStore;
|
||||
private EhClient mEhClient;
|
||||
private OkHttpClient mOkHttpClient;
|
||||
@@ -85,6 +93,15 @@ public class EhApplication extends SceneApplication implements Thread.UncaughtEx
|
||||
mDefaultHandler = Thread.getDefaultUncaughtExceptionHandler();
|
||||
Thread.setDefaultUncaughtExceptionHandler(this);
|
||||
|
||||
// Start anr watch dog
|
||||
new ANRWatchDog().setANRListener(new ANRWatchDog.ANRListener() {
|
||||
@Override
|
||||
public void onAppNotResponding(ANRError error) {
|
||||
// Throw RuntimeException, let crash handler do it
|
||||
throw new RuntimeException(error.getCause());
|
||||
}
|
||||
}).start();
|
||||
|
||||
super.onCreate();
|
||||
|
||||
GetText.initialize(this);
|
||||
@@ -97,6 +114,7 @@ public class EhApplication extends SceneApplication implements Thread.UncaughtEx
|
||||
SpiderDen.initialize(this);
|
||||
EhDB.initialize(this);
|
||||
EhEngine.initialize();
|
||||
BitmapUtils.initialize(this);
|
||||
|
||||
if (EhDB.needMerge()) {
|
||||
EhDB.mergeOldDB(this);
|
||||
@@ -106,8 +124,18 @@ public class EhApplication extends SceneApplication implements Thread.UncaughtEx
|
||||
Analytics.start(this);
|
||||
}
|
||||
|
||||
CommonOperations.ensureNoMediaFile(Settings.getDownloadLocation());
|
||||
// Check no media file
|
||||
UniFile downloadLocation = Settings.getDownloadLocation();
|
||||
if (Settings.getMediaScan()) {
|
||||
CommonOperations.removeNoMediaFile(downloadLocation);
|
||||
} else {
|
||||
CommonOperations.ensureNoMediaFile(downloadLocation);
|
||||
}
|
||||
|
||||
// Clear temp dir
|
||||
clearTempDir();
|
||||
|
||||
// Check app update
|
||||
update();
|
||||
|
||||
// Update version code
|
||||
@@ -123,11 +151,45 @@ public class EhApplication extends SceneApplication implements Thread.UncaughtEx
|
||||
}
|
||||
}
|
||||
|
||||
private void clearTempDir() {
|
||||
File dir = AppConfig.getTempDir();
|
||||
if (null != dir) {
|
||||
FileUtils.deleteContent(dir);
|
||||
}
|
||||
dir = AppConfig.getExternalTempDir();
|
||||
if (null != dir) {
|
||||
FileUtils.deleteContent(dir);
|
||||
}
|
||||
}
|
||||
|
||||
private void update() {
|
||||
int version = Settings.getVersionCode();
|
||||
if (version < 52) {
|
||||
Settings.putGuideGallery(true);
|
||||
}
|
||||
if (version < 56) { // Make cookie long live
|
||||
HttpUrl eUrl = HttpUrl.parse(EhUrl.HOST_E);
|
||||
HttpUrl exUrl = HttpUrl.parse(EhUrl.HOST_EX);
|
||||
EhCookieStore cookieStore = getEhCookieStore(this);
|
||||
|
||||
Cookie c;
|
||||
c = cookieStore.get(eUrl, EhCookieStore.KEY_IPD_MEMBER_ID);
|
||||
if (null != c) {
|
||||
cookieStore.add(EhCookieStore.newCookie(c, c.domain(), true, true, true));
|
||||
}
|
||||
c = cookieStore.get(eUrl, EhCookieStore.KEY_IPD_PASS_HASH);
|
||||
if (null != c) {
|
||||
cookieStore.add(EhCookieStore.newCookie(c, c.domain(), true, true, true));
|
||||
}
|
||||
c = cookieStore.get(exUrl, EhCookieStore.KEY_IPD_MEMBER_ID);
|
||||
if (null != c) {
|
||||
cookieStore.add(EhCookieStore.newCookie(c, c.domain(), true, true, true));
|
||||
}
|
||||
c = cookieStore.get(exUrl, EhCookieStore.KEY_IPD_PASS_HASH);
|
||||
if (null != c) {
|
||||
cookieStore.add(EhCookieStore.newCookie(c, c.domain(), true, true, true));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void clearMemoryCache() {
|
||||
@@ -160,13 +222,13 @@ public class EhApplication extends SceneApplication implements Thread.UncaughtEx
|
||||
}
|
||||
|
||||
public int putGlobalStuff(@NonNull Object o) {
|
||||
int id = mIdGenerator.getAndDecrement();
|
||||
int id = mIdGenerator.nextId();
|
||||
mGlobalStuffMap.put(id, o);
|
||||
return id;
|
||||
}
|
||||
|
||||
public boolean containGlobalStuff(int id) {
|
||||
return mGlobalStuffMap.indexOfKey(id) >= 0;
|
||||
return mGlobalStuffMap.containsKey(id);
|
||||
}
|
||||
|
||||
public Object getGlobalStuff(int id) {
|
||||
@@ -174,24 +236,11 @@ public class EhApplication extends SceneApplication implements Thread.UncaughtEx
|
||||
}
|
||||
|
||||
public Object removeGlobalStuff(int id) {
|
||||
int index = mGlobalStuffMap.indexOfKey(id);
|
||||
if (index >= 0) {
|
||||
Object o = mGlobalStuffMap.valueAt(index);
|
||||
mGlobalStuffMap.removeAt(index);
|
||||
return o;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
return mGlobalStuffMap.remove(id);
|
||||
}
|
||||
|
||||
public boolean removeGlobalStuff(Object o) {
|
||||
int index = mGlobalStuffMap.indexOfValue(o);
|
||||
if (index >= 0) {
|
||||
mGlobalStuffMap.removeAt(index);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return mGlobalStuffMap.values().removeAll(Collections.singleton(o));
|
||||
}
|
||||
|
||||
public static EhCookieStore getEhCookieStore(@NonNull Context context) {
|
||||
@@ -306,6 +355,12 @@ public class EhApplication extends SceneApplication implements Thread.UncaughtEx
|
||||
if (!handleException(ex) && mDefaultHandler != null) {
|
||||
mDefaultHandler.uncaughtException(thread, ex);
|
||||
}
|
||||
|
||||
Activity activity = getTopActivity();
|
||||
if (activity != null) {
|
||||
activity.finish();
|
||||
}
|
||||
|
||||
android.os.Process.killProcess(android.os.Process.myPid());
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
@@ -162,7 +162,12 @@ public class EhDB {
|
||||
gi.category = cursor.getInt(4);
|
||||
gi.thumb = cursor.getString(5);
|
||||
gi.uploader = cursor.getString(6);
|
||||
gi.rating = cursor.getFloat(7);
|
||||
try {
|
||||
// In 0.6.x version, NaN is stored
|
||||
gi.rating = cursor.getFloat(7);
|
||||
} catch (Exception e) {
|
||||
gi.rating = -1.0f;
|
||||
}
|
||||
|
||||
map.put(gi.gid, gi);
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.net.Uri;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.annotation.DimenRes;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.util.Log;
|
||||
@@ -55,6 +56,7 @@ public class Settings {
|
||||
|
||||
private static EhConfig loadEhConfig() {
|
||||
EhConfig ehConfig= new EhConfig();
|
||||
ehConfig.imageSize = getImageResolution();
|
||||
ehConfig.excludedLanguages = getExcludedLanguages();
|
||||
ehConfig.defaultCategories = getDefaultCategories();
|
||||
ehConfig.excludedNamespaces = getExcludedTagNamespaces();
|
||||
@@ -253,6 +255,33 @@ public class Settings {
|
||||
return getIntFromStr(KEY_LIST_MODE, DEFAULT_LIST_MODE);
|
||||
}
|
||||
|
||||
public static final String KEY_THUMB_SIZE = "thumb_size";
|
||||
private static final int DEFAULT_THUMB_SIZE = 1;
|
||||
|
||||
public static int getThumbSize() {
|
||||
return getIntFromStr(KEY_THUMB_SIZE, DEFAULT_THUMB_SIZE);
|
||||
}
|
||||
|
||||
@DimenRes
|
||||
public static int getThumbSizeResId() {
|
||||
switch (getThumbSize()) {
|
||||
case 0:
|
||||
return R.dimen.gallery_grid_column_width_large;
|
||||
default:
|
||||
case 1:
|
||||
return R.dimen.gallery_grid_column_width_middle;
|
||||
case 2:
|
||||
return R.dimen.gallery_grid_column_width_small;
|
||||
}
|
||||
}
|
||||
|
||||
public static final String KEY_THUMB_RESOLUTION = "thumb_resolution";
|
||||
private static final int DEFAULT_THUMB_RESOLUTION = 0;
|
||||
|
||||
public static int getThumbResolution() {
|
||||
return getIntFromStr(KEY_THUMB_RESOLUTION, DEFAULT_THUMB_RESOLUTION);
|
||||
}
|
||||
|
||||
private static final String KEY_SHOW_JPN_TITLE = "show_jpn_title";
|
||||
private static final boolean DEFAULT_SHOW_JPN_TITLE = false;
|
||||
|
||||
@@ -368,6 +397,17 @@ public class Settings {
|
||||
/********************
|
||||
****** Read
|
||||
********************/
|
||||
private static final String KEY_SCREEN_ROTATION = "screen_rotation";
|
||||
private static final int DEFAULT_SCREEN_ROTATION = 0;
|
||||
|
||||
public static int getScreenRotation() {
|
||||
return getIntFromStr(KEY_SCREEN_ROTATION, DEFAULT_SCREEN_ROTATION);
|
||||
}
|
||||
|
||||
public static void putScreenRotation(int value) {
|
||||
putIntToStr(KEY_SCREEN_ROTATION, value);
|
||||
}
|
||||
|
||||
private static final String KEY_READING_DIRECTION = "reading_direction";
|
||||
private static final int DEFAULT_READING_DIRECTION = GalleryView.LAYOUT_MODE_RIGHT_TO_LEFT;
|
||||
|
||||
@@ -426,6 +466,17 @@ public class Settings {
|
||||
putBoolean(KEY_SHOW_CLOCK, value);
|
||||
}
|
||||
|
||||
private static final String KEY_SHOW_PROGRESS = "gallery_show_progress";
|
||||
private static final boolean DEFAULT_SHOW_PROGRESS = true;
|
||||
|
||||
public static boolean getShowProgress() {
|
||||
return getBoolean(KEY_SHOW_PROGRESS, DEFAULT_SHOW_PROGRESS);
|
||||
}
|
||||
|
||||
public static void putShowProgress(boolean value) {
|
||||
putBoolean(KEY_SHOW_PROGRESS, value);
|
||||
}
|
||||
|
||||
private static final String KEY_SHOW_BATTERY = "gallery_show_battery";
|
||||
private static final boolean DEFAULT_SHOW_BATTERY = true;
|
||||
|
||||
@@ -448,6 +499,39 @@ public class Settings {
|
||||
putBoolean(KEY_VOLUME_PAGE, value);
|
||||
}
|
||||
|
||||
private static final String KEY_READING_FULLSCREEN = "reading_fullscreen";
|
||||
private static final boolean VALUE_READING_FULLSCREEN = true;
|
||||
|
||||
public static boolean getReadingFullscreen() {
|
||||
return getBoolean(KEY_READING_FULLSCREEN, VALUE_READING_FULLSCREEN);
|
||||
}
|
||||
|
||||
public static void putReadingFullscreen(boolean value) {
|
||||
putBoolean(KEY_READING_FULLSCREEN, value);
|
||||
}
|
||||
|
||||
private static final String KEY_CUSTOM_SCREEN_LIGHTNESS = "custom_screen_lightness";
|
||||
private static final boolean DEFAULT_CUSTOM_SCREEN_LIGHTNESS = false;
|
||||
|
||||
public static boolean getCustomScreenLightness() {
|
||||
return getBoolean(KEY_CUSTOM_SCREEN_LIGHTNESS, DEFAULT_CUSTOM_SCREEN_LIGHTNESS);
|
||||
}
|
||||
|
||||
public static void putCustomScreenLightness(boolean value) {
|
||||
putBoolean(KEY_CUSTOM_SCREEN_LIGHTNESS, value);
|
||||
}
|
||||
|
||||
private static final String KEY_SCREEN_LIGHTNESS = "screen_lightness";
|
||||
private static final int DEFAULT_SCREEN_LIGHTNESS = 50;
|
||||
|
||||
public static int getScreenLightness() {
|
||||
return getInt(KEY_SCREEN_LIGHTNESS, DEFAULT_SCREEN_LIGHTNESS);
|
||||
}
|
||||
|
||||
public static void putScreenLightness(int value) {
|
||||
putInt(KEY_SCREEN_LIGHTNESS, value);
|
||||
}
|
||||
|
||||
/********************
|
||||
****** Download
|
||||
********************/
|
||||
@@ -482,7 +566,18 @@ public class Settings {
|
||||
putString(KEY_DOWNLOAD_SAVE_QUERY, uri.getEncodedQuery());
|
||||
putString(KEY_DOWNLOAD_SAVE_FRAGMENT, uri.getEncodedFragment());
|
||||
|
||||
CommonOperations.ensureNoMediaFile(location);
|
||||
if (getMediaScan()) {
|
||||
CommonOperations.removeNoMediaFile(location);
|
||||
} else {
|
||||
CommonOperations.ensureNoMediaFile(location);
|
||||
}
|
||||
}
|
||||
|
||||
public static final String KEY_MEDIA_SCAN = "media_scan";
|
||||
private static final boolean DEFAULT_MEDIA_SCAN = false;
|
||||
|
||||
public static boolean getMediaScan() {
|
||||
return getBoolean(KEY_MEDIA_SCAN, DEFAULT_MEDIA_SCAN);
|
||||
}
|
||||
|
||||
private static final String KEY_RECENT_DOWNLOAD_LABEL = "recent_download_label";
|
||||
@@ -540,6 +635,19 @@ public class Settings {
|
||||
putIntToStr(KEY_PRELOAD_IMAGE, value);
|
||||
}
|
||||
|
||||
public static final String KEY_IMAGE_RESOLUTION = "image_size";
|
||||
public static final String DEFAULT_IMAGE_RESOLUTION = EhConfig.IMAGE_SIZE_AUTO;
|
||||
|
||||
public static String getImageResolution() {
|
||||
return getString(KEY_IMAGE_RESOLUTION, DEFAULT_IMAGE_RESOLUTION);
|
||||
}
|
||||
|
||||
public static void putImageResolution(String value) {
|
||||
sEhConfig.imageSize = value;
|
||||
sEhConfig.setDirty();
|
||||
putString(KEY_IMAGE_RESOLUTION, value);
|
||||
}
|
||||
|
||||
private static final String KEY_DOWNLOAD_ORIGIN_IMAGE = "download_origin_image";
|
||||
private static final boolean DEFAULT_DOWNLOAD_ORIGIN_IMAGE = false;
|
||||
|
||||
@@ -771,6 +879,13 @@ public class Settings {
|
||||
putString(KEY_SECURITY, value);
|
||||
}
|
||||
|
||||
public static final String KEY_READ_CACHE_SIZE = "read_cache_size";
|
||||
public static final int DEFAULT_READ_CACHE_SIZE = 160;
|
||||
|
||||
public static int getReadCacheSize() {
|
||||
return getIntFromStr(KEY_READ_CACHE_SIZE, DEFAULT_READ_CACHE_SIZE);
|
||||
}
|
||||
|
||||
/********************
|
||||
****** Guide
|
||||
********************/
|
||||
|
||||
@@ -16,14 +16,12 @@
|
||||
|
||||
package com.hippo.ehviewer;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.ActivityNotFoundException;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.provider.Browser;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.customtabs.CustomTabsIntent;
|
||||
import android.text.TextUtils;
|
||||
import android.widget.Toast;
|
||||
|
||||
@@ -31,14 +29,13 @@ 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.CustomTabsHelper;
|
||||
|
||||
public final class UrlOpener {
|
||||
|
||||
private UrlOpener() {
|
||||
}
|
||||
|
||||
public static void openUrl(@NonNull Context context, String url, boolean ehUrl, boolean customTabs) {
|
||||
public static void openUrl(@NonNull Context context, String url, boolean ehUrl) {
|
||||
if (TextUtils.isEmpty(url)) {
|
||||
return;
|
||||
}
|
||||
@@ -59,20 +56,6 @@ public final class UrlOpener {
|
||||
}
|
||||
}
|
||||
|
||||
// CustomTabs
|
||||
if (customTabs && context instanceof Activity) {
|
||||
Activity activity = (Activity) context;
|
||||
String packageName = CustomTabsHelper.getPackageNameToUseFixed(activity);
|
||||
if (packageName != null) {
|
||||
new CustomTabsIntent.Builder()
|
||||
.setToolbarColor(activity.getResources().getColor(R.color.colorPrimary))
|
||||
.setShowTitle(true)
|
||||
.build()
|
||||
.launchUrl(activity, uri);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Intent.ACTION_VIEW
|
||||
intent = new Intent(Intent.ACTION_VIEW, uri);
|
||||
intent.putExtra(Browser.EXTRA_APPLICATION_ID, context.getPackageName());
|
||||
|
||||
@@ -25,6 +25,7 @@ import com.hippo.ehviewer.client.exception.CancelledException;
|
||||
import com.hippo.yorozuya.PriorityThreadFactory;
|
||||
import com.hippo.yorozuya.SimpleHandler;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
@@ -56,6 +57,8 @@ public class EhClient {
|
||||
public static final int METHOD_GET_TORRENT_LIST = 12;
|
||||
public static final int METHOD_GET_WHATS_HOT = 13;
|
||||
public static final int METHOD_GET_PROFILE = 14;
|
||||
public static final int METHOD_VOTE_COMMENT = 15;
|
||||
public static final int METHOD_IMAGE_SEARCH = 16;
|
||||
|
||||
private final ThreadPoolExecutor mRequestThreadPool;
|
||||
private final OkHttpClient mOkHttpClient;
|
||||
@@ -158,7 +161,7 @@ public class EhClient {
|
||||
case METHOD_GET_PREVIEW_SET:
|
||||
return EhEngine.getPreviewSet(this, mOkHttpClient, (String) params[0]);
|
||||
case METHOD_GET_RATE_GALLERY:
|
||||
return EhEngine.rateGallery(this, mOkHttpClient, (Long) params[0], (String) params[1], (Float) params[2]);
|
||||
return EhEngine.rateGallery(this, mOkHttpClient, (Long) params[0], (String) params[1], (Long) params[2], (String) params[3], (Float) params[4]);
|
||||
case METHOD_GET_COMMENT_GALLERY:
|
||||
return EhEngine.commentGallery(this, mOkHttpClient, (String) params[0], (String) params[1]);
|
||||
case METHOD_GET_GALLERY_TOKEN:
|
||||
@@ -177,6 +180,10 @@ public class EhClient {
|
||||
return EhEngine.getWhatsHot(this, mOkHttpClient);
|
||||
case METHOD_GET_PROFILE:
|
||||
return EhEngine.getProfile(this, mOkHttpClient);
|
||||
case METHOD_VOTE_COMMENT:
|
||||
return EhEngine.voteComment(this, mOkHttpClient, (Long) params[0], (String) params[1], (Long) params[2], (String) params[3], (Long) params[4], (Integer) params[5]);
|
||||
case METHOD_IMAGE_SEARCH:
|
||||
return EhEngine.imageSearch(this, mOkHttpClient, (File) params[0], (Boolean) params[1], (Boolean) params[2], (Boolean) params[3]);
|
||||
default:
|
||||
return new IllegalStateException("Can't detect method " + mMethod);
|
||||
}
|
||||
|
||||
@@ -30,8 +30,20 @@ public class EhConfig implements Cloneable {
|
||||
|
||||
/**
|
||||
* The key of load images through the Hentai@Home Network
|
||||
* @see #LOAD_FROM_HAH_YES
|
||||
* @see #LOAD_FROM_HAH_NO
|
||||
*/
|
||||
private static final String KEY_LOAD_FROM_HAH = "uh";
|
||||
/**
|
||||
* The key of Image Size Settings
|
||||
* @see #IMAGE_SIZE_AUTO
|
||||
* @see #IMAGE_SIZE_780X
|
||||
* @see #IMAGE_SIZE_980X
|
||||
* @see #IMAGE_SIZE_1280X
|
||||
* @see #IMAGE_SIZE_1600X
|
||||
* @see #IMAGE_SIZE_2400X
|
||||
*/
|
||||
private static final String KEY_IMAGE_SIZE = "xr";
|
||||
/**
|
||||
* The key of scale images width
|
||||
*/
|
||||
@@ -40,18 +52,42 @@ public class EhConfig implements Cloneable {
|
||||
* The key of scale images height
|
||||
*/
|
||||
private static final String KEY_SCALE_HEIGHT = "ry";
|
||||
/**
|
||||
* The key of Gallery Name Display
|
||||
* @see #GALLERY_TITLE_DEFAULT
|
||||
* @see #GALLERY_TITLE_JAPANESE
|
||||
*/
|
||||
private static final String KEY_GALLERY_TITLE = "tl";
|
||||
/**
|
||||
* The key of the behavior for downloading archiver
|
||||
* @see #ARCHIVER_DOWNLOAD_MAMS
|
||||
* @see #ARCHIVER_DOWNLOAD_MAAS
|
||||
* @see #ARCHIVER_DOWNLOAD_AAMS
|
||||
* @see #ARCHIVER_DOWNLOAD_AAAS
|
||||
*/
|
||||
private static final String KEY_ARCHIVER_DOWNLOAD = "ar";
|
||||
/**
|
||||
* The key of display mode would you like to use on the front and search pages
|
||||
* @see #LAYOUT_MODE_LIST
|
||||
* @see #LAYOUT_MODE_THUMB
|
||||
*/
|
||||
private static final String KEY_LAYOUT_MODE = "dm";
|
||||
/**
|
||||
* The key for show popular
|
||||
* @see #POPULAR_YES
|
||||
* @see #POPULAR_NO
|
||||
*/
|
||||
private static final String KEY_POPULAR = "prn";
|
||||
/**
|
||||
* The key of categories would you like to view as default on the front page
|
||||
*/
|
||||
private static final String KEY_DEFAULT_CATEGORIES = "cats";
|
||||
/**
|
||||
* The key for favorites sort
|
||||
* @see #FAVORITES_SORT_GALLERY_UPDATE_TIME
|
||||
* @see #FAVORITES_SORT_FAVORITED_TIME
|
||||
*/
|
||||
private static final String KEY_FAVORITES_SORT = "fs";
|
||||
/**
|
||||
* The key of exclude certain namespaces from a default tag search
|
||||
*/
|
||||
@@ -62,34 +98,55 @@ public class EhConfig implements Cloneable {
|
||||
private static final String KEY_EXCLUDED_LANGUAGES = "xl";
|
||||
/**
|
||||
* The key of how many results would you like per page for the index/search page and torrent search pages
|
||||
* @see #RESULT_COUNT_25
|
||||
* @see #RESULT_COUNT_50
|
||||
* @see #RESULT_COUNT_100
|
||||
* @see #RESULT_COUNT_200
|
||||
*/
|
||||
private static final String KEY_RESULT_COUNT = "rc";
|
||||
/**
|
||||
* The key of mouse-over thumb
|
||||
* @see #MOUSE_OVER_YES
|
||||
* @see #MOUSE_OVER_NO
|
||||
*/
|
||||
private static final String KEY_MOUSE_OVER = "tl";
|
||||
private static final String KEY_MOUSE_OVER = "lt";
|
||||
/**
|
||||
* The key of preview size
|
||||
* @see #PREVIEW_SIZE_NORMAL
|
||||
* @see #PREVIEW_SIZE_LARGE
|
||||
*/
|
||||
private static final String KEY_PREVIEW_SIZE = "ts";
|
||||
/**
|
||||
* The key of preview row per page
|
||||
* @see #PREVIEW_ROW_4
|
||||
* @see #PREVIEW_ROW_10
|
||||
* @see #PREVIEW_ROW_20
|
||||
* @see #PREVIEW_ROW_40
|
||||
*/
|
||||
private static final String KEY_PREVIEW_ROW = "tr";
|
||||
/**
|
||||
* The key of sort order for gallery comments
|
||||
* @see #COMMENTS_SORT_OLDEST_FIRST
|
||||
* @see #COMMENTS_SORT_RECENT_FIRST
|
||||
* @see #COMMENTS_SORT_HIGHEST_SCORE_FIRST
|
||||
*/
|
||||
private static final String KEY_COMMENTS_SORT = "cs";
|
||||
/**
|
||||
* The key of show gallery comment votes
|
||||
* @see #COMMENTS_VOTES_POP
|
||||
* @see #COMMENTS_VOTES_ALWAYS
|
||||
*/
|
||||
private static final String KEY_COMMENTS_VOTES = "sc";
|
||||
/**
|
||||
* The key of sort order for gallery tags
|
||||
* @see #TAGS_SORT_ALPHABETICAL
|
||||
* @see #TAGS_SORT_POWER
|
||||
*/
|
||||
private static final String KEY_TAGS_SORT = "to";
|
||||
/**
|
||||
* The key of show gallery page numbers
|
||||
* @see #SHOW_GALLERY_INDEX_NO
|
||||
* @see #SHOW_GALLERY_INDEX_YES
|
||||
*/
|
||||
private static final String KEY_SHOW_GALLERY_INDEX = "pn";
|
||||
/**
|
||||
@@ -104,22 +161,33 @@ public class EhConfig implements Cloneable {
|
||||
private static final String KEY_HAH_CLIENT_PASSKEY = "hk";
|
||||
/**
|
||||
* The key of enable Tag Flagging
|
||||
* @see #ENABLE_TAG_FLAGGING_NO
|
||||
* @see #ENABLE_TAG_FLAGGING_YES
|
||||
*/
|
||||
private static final String KEY_ENABLE_TAG_FLAGGING = "tf";
|
||||
/**
|
||||
* The key of always display the original images instead of the resampled versions
|
||||
* @see #ALWAYS_ORIGINAL_NO
|
||||
* @see #ALWAYS_ORIGINAL_YES
|
||||
*/
|
||||
private static final String KEY_ALWAYS_ORIGINAL = "oi";
|
||||
/**
|
||||
* The key of enable the multi-Page Viewer
|
||||
* @see #MULTI_PAGE_NO
|
||||
* @see #MULTI_PAGE_YES
|
||||
*/
|
||||
private static final String KEY_MULTI_PAGE = "qb";
|
||||
/**
|
||||
* The key of multi-Page Viewer Display Style
|
||||
* @see #MULTI_PAGE_STYLE_C
|
||||
* @see #MULTI_PAGE_STYLE_N
|
||||
* @see #MULTI_PAGE_STYLE_Y
|
||||
*/
|
||||
private static final String KEY_MULTI_PAGE_STYLE = "ms";
|
||||
/**
|
||||
* The key of multi-Page Viewer Thumbnail Pane
|
||||
* @see #MULTI_PAGE_THUMB_HIDE
|
||||
* @see #MULTI_PAGE_THUMB_SHOW
|
||||
*/
|
||||
private static final String KEY_MULTI_PAGE_THUMB = "mt";
|
||||
|
||||
@@ -142,6 +210,40 @@ public class EhConfig implements Cloneable {
|
||||
*/
|
||||
public static final String LOAD_FROM_HAH_NO = "n";
|
||||
|
||||
/**
|
||||
* Image Size Auto
|
||||
*/
|
||||
public static final String IMAGE_SIZE_AUTO = "a";
|
||||
/**
|
||||
* Image Size 780x
|
||||
*/
|
||||
public static final String IMAGE_SIZE_780X = "780";
|
||||
/**
|
||||
* Image Size 980x
|
||||
*/
|
||||
public static final String IMAGE_SIZE_980X = "980";
|
||||
/**
|
||||
* Image Size 1280x
|
||||
*/
|
||||
public static final String IMAGE_SIZE_1280X = "1280";
|
||||
/**
|
||||
* Image Size 1600x
|
||||
*/
|
||||
public static final String IMAGE_SIZE_1600X = "1600";
|
||||
/**
|
||||
* Image Size 2400x
|
||||
*/
|
||||
public static final String IMAGE_SIZE_2400X = "2400";
|
||||
|
||||
/**
|
||||
* Default gallery title
|
||||
*/
|
||||
private static final String GALLERY_TITLE_DEFAULT = "r";
|
||||
/**
|
||||
* Japanese gallery title
|
||||
*/
|
||||
private static final String GALLERY_TITLE_JAPANESE = "j";
|
||||
|
||||
/**
|
||||
* Manual Accept, Manual Start
|
||||
*/
|
||||
@@ -168,6 +270,15 @@ public class EhConfig implements Cloneable {
|
||||
*/
|
||||
public static final String LAYOUT_MODE_THUMB = "t";
|
||||
|
||||
/**
|
||||
* Show popular
|
||||
*/
|
||||
private static final String POPULAR_YES = "y";
|
||||
/**
|
||||
* Don't show popular
|
||||
*/
|
||||
private static final String POPULAR_NO = "n";
|
||||
|
||||
public static final int MISC = 0x1;
|
||||
public static final int DOUJINSHI = 0x2;
|
||||
public static final int MANGA = 0x4;
|
||||
@@ -239,6 +350,15 @@ public class EhConfig implements Cloneable {
|
||||
public static final String OTHER_TRANSLATED = "1279";
|
||||
public static final String OTHER_REWRITE = "2303";
|
||||
|
||||
/**
|
||||
* Sort favorites by last gallery update time
|
||||
*/
|
||||
private static final String FAVORITES_SORT_GALLERY_UPDATE_TIME = "p";
|
||||
/**
|
||||
* Sort favorites by favorited time
|
||||
*/
|
||||
private static final String FAVORITES_SORT_FAVORITED_TIME = "f";
|
||||
|
||||
/**
|
||||
* 25 results per page for the index/search page and torrent search pages
|
||||
*/
|
||||
@@ -412,6 +532,14 @@ public class EhConfig implements Cloneable {
|
||||
*/
|
||||
public String loadFromHAH = LOAD_FROM_HAH_YES;
|
||||
|
||||
/**
|
||||
* Image Size<br/>
|
||||
* key: {@link #KEY_IMAGE_SIZE}<br/>
|
||||
* value: {@link #IMAGE_SIZE_AUTO}, {@link #IMAGE_SIZE_780X}, {@link #IMAGE_SIZE_980X},
|
||||
* {@link #IMAGE_SIZE_1280X}, {@link #IMAGE_SIZE_1600X}, {@link #IMAGE_SIZE_2400X}
|
||||
*/
|
||||
public String imageSize = IMAGE_SIZE_AUTO;
|
||||
|
||||
/**
|
||||
* Scale width<br/>
|
||||
* key: {@link #KEY_SCALE_WIDTH}<br/>
|
||||
@@ -426,6 +554,13 @@ public class EhConfig implements Cloneable {
|
||||
*/
|
||||
public int scaleHeight = 0;
|
||||
|
||||
/**
|
||||
* Gallery title<br/>
|
||||
* key: {@link #KEY_GALLERY_TITLE}<br/>
|
||||
* value: {@link #GALLERY_TITLE_DEFAULT}, {@link #GALLERY_TITLE_JAPANESE}
|
||||
*/
|
||||
public String galleryTitle = GALLERY_TITLE_DEFAULT;
|
||||
|
||||
/**
|
||||
* The default behavior for downloading an archiver<br/>
|
||||
* key: {@link #KEY_ARCHIVER_DOWNLOAD}<br/>
|
||||
@@ -442,6 +577,13 @@ public class EhConfig implements Cloneable {
|
||||
*/
|
||||
public String layoutMode = LAYOUT_MODE_LIST;
|
||||
|
||||
/**
|
||||
* Show popular or not<br/>
|
||||
* key: {@link #KEY_POPULAR}<br/>
|
||||
* value: {@link #POPULAR_YES}, {@link #POPULAR_NO}
|
||||
*/
|
||||
public String popular = POPULAR_YES;
|
||||
|
||||
/**
|
||||
* Default categories on the front page<br/>
|
||||
* key: {@link #KEY_DEFAULT_CATEGORIES}<br/>
|
||||
@@ -450,6 +592,13 @@ public class EhConfig implements Cloneable {
|
||||
*/
|
||||
public int defaultCategories = 0;
|
||||
|
||||
/**
|
||||
* <br/>
|
||||
* key: {@link #KEY_FAVORITES_SORT}<br/>
|
||||
* value: {@link #FAVORITES_SORT_GALLERY_UPDATE_TIME}, {@link #FAVORITES_SORT_FAVORITED_TIME}
|
||||
*/
|
||||
public String favoritesSort = FAVORITES_SORT_FAVORITED_TIME;
|
||||
|
||||
/**
|
||||
* Certain namespaces excluded from a default tag search<br/>
|
||||
* key: {@link #KEY_EXCLUDED_NAMESPACES}<br/>
|
||||
@@ -628,11 +777,15 @@ public class EhConfig implements Cloneable {
|
||||
hahClientIp + "%3A" + hahClientPort : "";
|
||||
String hahClientPasskey = null == this.hahClientPasskey ? "" : this.hahClientPasskey;
|
||||
mUconfig = KEY_LOAD_FROM_HAH + "_" + loadFromHAH + "-" +
|
||||
KEY_IMAGE_SIZE + "_" + imageSize + "-" +
|
||||
KEY_SCALE_WIDTH + "_" + scaleWidth + "-" +
|
||||
KEY_SCALE_HEIGHT + "_" + scaleHeight + "-" +
|
||||
KEY_GALLERY_TITLE + "_" + galleryTitle + "-" +
|
||||
KEY_ARCHIVER_DOWNLOAD + "_" + archiverDownload + "-" +
|
||||
KEY_LAYOUT_MODE + "_" + layoutMode + "-" +
|
||||
KEY_POPULAR + "_" + popular + "-" +
|
||||
KEY_DEFAULT_CATEGORIES + "_" + defaultCategories + "-" +
|
||||
KEY_FAVORITES_SORT + "_" + favoritesSort + "-" +
|
||||
KEY_EXCLUDED_NAMESPACES + "_" + excludedNamespaces + "-" +
|
||||
KEY_EXCLUDED_LANGUAGES + "_" + excludedLanguages + "-" +
|
||||
KEY_RESULT_COUNT + "_" + resultCount + "-" +
|
||||
|
||||
@@ -49,11 +49,15 @@ public class EhCookieStore extends CookieDBStore {
|
||||
contain(EhUrl.DOMAIN_EX, KEY_IPD_PASS_HASH);
|
||||
}
|
||||
|
||||
public static Cookie newCookie(Cookie cookie, String newDomain, boolean forcePersistent, boolean forceNotHostOnly) {
|
||||
public static Cookie newCookie(Cookie cookie, String newDomain, boolean forcePersistent,
|
||||
boolean forceLongLive, boolean forceNotHostOnly) {
|
||||
Cookie.Builder builder = new Cookie.Builder();
|
||||
builder.name(cookie.name());
|
||||
builder.value(cookie.value());
|
||||
if (cookie.persistent()) {
|
||||
|
||||
if (forceLongLive) {
|
||||
builder.expiresAt(Long.MAX_VALUE);
|
||||
} else if (cookie.persistent()) {
|
||||
builder.expiresAt(cookie.expiresAt());
|
||||
} else if (forcePersistent) {
|
||||
builder.expiresAt(Long.MAX_VALUE);
|
||||
@@ -125,7 +129,9 @@ public class EhCookieStore extends CookieDBStore {
|
||||
// Save id and hash for exhentai
|
||||
if (KEY_IPD_MEMBER_ID.equals(cookie.name()) ||
|
||||
KEY_IPD_PASS_HASH.equals(cookie.name())) {
|
||||
result.add(newCookie(cookie, EhUrl.DOMAIN_EX, false, false));
|
||||
result.add(newCookie(cookie, EhUrl.DOMAIN_E, true, true, true));
|
||||
result.add(newCookie(cookie, EhUrl.DOMAIN_EX, true, true, true));
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -36,16 +36,16 @@ import com.hippo.ehviewer.client.parser.ForumsParser;
|
||||
import com.hippo.ehviewer.client.parser.GalleryApiParser;
|
||||
import com.hippo.ehviewer.client.parser.GalleryDetailParser;
|
||||
import com.hippo.ehviewer.client.parser.GalleryListParser;
|
||||
import com.hippo.ehviewer.client.parser.GalleryPageParser;
|
||||
import com.hippo.ehviewer.client.parser.GalleryTokenApiParser;
|
||||
import com.hippo.ehviewer.client.parser.ProfileParser;
|
||||
import com.hippo.ehviewer.client.parser.RateGalleryParser;
|
||||
import com.hippo.ehviewer.client.parser.SignInParser;
|
||||
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.ReadableTime;
|
||||
import com.hippo.yorozuya.AssertUtils;
|
||||
import com.hippo.yorozuya.IOUtils;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
@@ -53,9 +53,6 @@ import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Document;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -63,6 +60,7 @@ import okhttp3.Call;
|
||||
import okhttp3.FormBody;
|
||||
import okhttp3.Headers;
|
||||
import okhttp3.MediaType;
|
||||
import okhttp3.MultipartBody;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.RequestBody;
|
||||
@@ -76,10 +74,8 @@ public class EhEngine {
|
||||
private static final String SAD_PANDA_TYPE = "image/gif";
|
||||
private static final String SAD_PANDA_LENGTH = "9615";
|
||||
|
||||
public static final long APIUID = 1363542;
|
||||
public static final String APIKEY = "f4b5407ab1727b9d08d7";
|
||||
|
||||
public static final MediaType JSON = MediaType.parse("application/json; charset=utf-8");
|
||||
public static final MediaType MEDIA_TYPE_JSON = MediaType.parse("application/json; charset=utf-8");
|
||||
private static final MediaType MEDIA_TYPE_JPEG = MediaType.parse("image/jpeg");
|
||||
|
||||
public static EhFilter sEhFilter;
|
||||
|
||||
@@ -87,33 +83,6 @@ public class EhEngine {
|
||||
sEhFilter = EhFilter.getInstance();
|
||||
}
|
||||
|
||||
private static void saveParseErrorBody(ParseException e) {
|
||||
File dir = AppConfig.getExternalParseErrorDir();
|
||||
if (null == dir) {
|
||||
return;
|
||||
}
|
||||
|
||||
File file = new File(dir, ReadableTime.getFilenamableTime(System.currentTimeMillis()) + ".txt");
|
||||
OutputStream os = null;
|
||||
try {
|
||||
os = new FileOutputStream(file);
|
||||
String message = e.getMessage();
|
||||
String body = e.getBody();
|
||||
if (null != message) {
|
||||
os.write(message.getBytes("utf-8"));
|
||||
os.write('\n');
|
||||
}
|
||||
if (null != body) {
|
||||
os.write(body.getBytes("utf-8"));
|
||||
}
|
||||
os.flush();
|
||||
} catch (IOException e1) {
|
||||
// Ignore
|
||||
} finally {
|
||||
IOUtils.closeQuietly(os);
|
||||
}
|
||||
}
|
||||
|
||||
private static void throwException(Call call, int code, @Nullable Headers headers,
|
||||
@Nullable String body, Exception e) throws Exception {
|
||||
if (call.isCanceled()) {
|
||||
@@ -132,7 +101,7 @@ public class EhEngine {
|
||||
throw new EhException(body);
|
||||
} else {
|
||||
if (Settings.getSaveParseErrorBody()) {
|
||||
saveParseErrorBody((ParseException) e);
|
||||
AppConfig.saveParseErrorBody((ParseException) e);
|
||||
}
|
||||
throw new EhException(GetText.getString(R.string.error_parse_error));
|
||||
}
|
||||
@@ -143,7 +112,7 @@ public class EhEngine {
|
||||
}
|
||||
}
|
||||
|
||||
public static String signIn(EhClient.Task task, OkHttpClient okHttpClient,
|
||||
public static String signIn(@Nullable EhClient.Task task, OkHttpClient okHttpClient,
|
||||
String username, String password) throws Exception {
|
||||
FormBody.Builder builder = new FormBody.Builder()
|
||||
.add("UserName", username)
|
||||
@@ -153,13 +122,15 @@ public class EhEngine {
|
||||
.add("temporary_https", "off");
|
||||
String url = EhUrl.API_SIGN_IN;
|
||||
Log.d(TAG, url);
|
||||
Request request = new EhRequestBuilder(url, task.getEhConfig())
|
||||
Request request = new EhRequestBuilder(url, null != task ? task.getEhConfig() : Settings.getEhConfig())
|
||||
.post(builder.build())
|
||||
.build();
|
||||
Call call = okHttpClient.newCall(request);
|
||||
|
||||
// Put call
|
||||
task.setCall(call);
|
||||
if (null != task) {
|
||||
task.setCall(call);
|
||||
}
|
||||
|
||||
String body = null;
|
||||
Headers headers = null;
|
||||
@@ -176,14 +147,16 @@ public class EhEngine {
|
||||
}
|
||||
}
|
||||
|
||||
public static GalleryListParser.Result getGalleryList(EhClient.Task task, OkHttpClient okHttpClient,
|
||||
public static GalleryListParser.Result getGalleryList(@Nullable EhClient.Task task, OkHttpClient okHttpClient,
|
||||
String url) throws Exception {
|
||||
Log.d(TAG, url);
|
||||
Request request = new EhRequestBuilder(url, task.getEhConfig()).build();
|
||||
Request request = new EhRequestBuilder(url, null != task ? task.getEhConfig() : Settings.getEhConfig()).build();
|
||||
Call call = okHttpClient.newCall(request);
|
||||
|
||||
// Put call
|
||||
task.setCall(call);
|
||||
if (null != task) {
|
||||
task.setCall(call);
|
||||
}
|
||||
|
||||
String body = null;
|
||||
Headers headers = null;
|
||||
@@ -230,7 +203,7 @@ public class EhEngine {
|
||||
}
|
||||
|
||||
// At least, GalleryInfo contain valid gid and token
|
||||
public static List<GalleryInfo> fillGalleryListByApi(EhClient.Task task, OkHttpClient okHttpClient,
|
||||
public static List<GalleryInfo> fillGalleryListByApi(@Nullable EhClient.Task task, OkHttpClient okHttpClient,
|
||||
List<GalleryInfo> galleryInfoList) throws Exception {
|
||||
// We can only request 25 items one time at most
|
||||
final int MAX_REQUEST_SIZE = 25;
|
||||
@@ -245,7 +218,7 @@ public class EhEngine {
|
||||
return galleryInfoList;
|
||||
}
|
||||
|
||||
private static void doFillGalleryListByApi(EhClient.Task task, OkHttpClient okHttpClient,
|
||||
private static void doFillGalleryListByApi(@Nullable EhClient.Task task, OkHttpClient okHttpClient,
|
||||
List<GalleryInfo> galleryInfoList) throws Exception {
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("method", "gdata");
|
||||
@@ -262,12 +235,14 @@ public class EhEngine {
|
||||
String url = EhUrl.getApiUrl();
|
||||
Log.d(TAG, url);
|
||||
Request request = new EhRequestBuilder(url)
|
||||
.post(RequestBody.create(JSON, json.toString()))
|
||||
.post(RequestBody.create(MEDIA_TYPE_JSON, json.toString()))
|
||||
.build();
|
||||
Call call = okHttpClient.newCall(request);
|
||||
|
||||
// Put call
|
||||
task.setCall(call);
|
||||
if (null != task) {
|
||||
task.setCall(call);
|
||||
}
|
||||
|
||||
String body = null;
|
||||
Headers headers = null;
|
||||
@@ -284,14 +259,16 @@ public class EhEngine {
|
||||
}
|
||||
}
|
||||
|
||||
public static GalleryDetail getGalleryDetail(EhClient.Task task, OkHttpClient okHttpClient,
|
||||
public static GalleryDetail getGalleryDetail(@Nullable EhClient.Task task, OkHttpClient okHttpClient,
|
||||
String url) throws Exception {
|
||||
Log.d(TAG, url);
|
||||
Request request = new EhRequestBuilder(url, task.getEhConfig()).build();
|
||||
Request request = new EhRequestBuilder(url, null != task ? task.getEhConfig() : Settings.getEhConfig()).build();
|
||||
Call call = okHttpClient.newCall(request);
|
||||
|
||||
// Put call
|
||||
task.setCall(call);
|
||||
if (null != task) {
|
||||
task.setCall(call);
|
||||
}
|
||||
|
||||
String body = null;
|
||||
Headers headers = null;
|
||||
@@ -310,13 +287,15 @@ public class EhEngine {
|
||||
|
||||
|
||||
public static Pair<PreviewSet, Integer> getPreviewSet(
|
||||
EhClient.Task task, OkHttpClient okHttpClient, String url) throws Exception {
|
||||
@Nullable EhClient.Task task, OkHttpClient okHttpClient, String url) throws Exception {
|
||||
Log.d(TAG, url);
|
||||
Request request = new EhRequestBuilder(url, task.getEhConfig()).build();
|
||||
Request request = new EhRequestBuilder(url, null != task ? task.getEhConfig() : Settings.getEhConfig()).build();
|
||||
Call call = okHttpClient.newCall(request);
|
||||
|
||||
// Put call
|
||||
task.setCall(call);
|
||||
if (null != task) {
|
||||
task.setCall(call);
|
||||
}
|
||||
|
||||
String body = null;
|
||||
Headers headers = null;
|
||||
@@ -334,25 +313,28 @@ public class EhEngine {
|
||||
}
|
||||
}
|
||||
|
||||
public static RateGalleryParser.Result rateGallery(EhClient.Task task,
|
||||
OkHttpClient okHttpClient, long gid, String token, float rating) throws Exception {
|
||||
public static RateGalleryParser.Result rateGallery(@Nullable EhClient.Task task,
|
||||
OkHttpClient okHttpClient, long apiUid, String apiKey, long gid,
|
||||
String token, float rating) throws Exception {
|
||||
final JSONObject json = new JSONObject();
|
||||
json.put("method", "rategallery");
|
||||
json.put("apiuid", APIUID);
|
||||
json.put("apikey", APIKEY);
|
||||
json.put("apiuid", apiUid);
|
||||
json.put("apikey", apiKey);
|
||||
json.put("gid", gid);
|
||||
json.put("token", token);
|
||||
json.put("rating", (int) Math.ceil(rating * 2));
|
||||
final RequestBody requestBody = RequestBody.create(JSON, json.toString());
|
||||
final RequestBody requestBody = RequestBody.create(MEDIA_TYPE_JSON, json.toString());
|
||||
String url = EhUrl.getApiUrl();
|
||||
Log.d(TAG, url);
|
||||
Request request = new EhRequestBuilder(url, task.getEhConfig())
|
||||
Request request = new EhRequestBuilder(url, null != task ? task.getEhConfig() : Settings.getEhConfig())
|
||||
.post(requestBody)
|
||||
.build();
|
||||
Call call = okHttpClient.newCall(request);
|
||||
|
||||
// Put call
|
||||
task.setCall(call);
|
||||
if (null != task) {
|
||||
task.setCall(call);
|
||||
}
|
||||
|
||||
String body = null;
|
||||
Headers headers = null;
|
||||
@@ -369,19 +351,21 @@ public class EhEngine {
|
||||
}
|
||||
}
|
||||
|
||||
public static GalleryComment[] commentGallery(EhClient.Task task,
|
||||
public static GalleryComment[] commentGallery(@Nullable EhClient.Task task,
|
||||
OkHttpClient okHttpClient, String url, String comment) throws Exception {
|
||||
FormBody.Builder builder = new FormBody.Builder()
|
||||
.add("commenttext", comment)
|
||||
.add("postcomment", "Post New");
|
||||
Log.d(TAG, url);
|
||||
Request request = new EhRequestBuilder(url, task.getEhConfig())
|
||||
Request request = new EhRequestBuilder(url, null != task ? task.getEhConfig() : Settings.getEhConfig())
|
||||
.post(builder.build())
|
||||
.build();
|
||||
Call call = okHttpClient.newCall(request);
|
||||
|
||||
// Put call
|
||||
task.setCall(call);
|
||||
if (null != task) {
|
||||
task.setCall(call);
|
||||
}
|
||||
|
||||
String body = null;
|
||||
Headers headers = null;
|
||||
@@ -399,22 +383,24 @@ public class EhEngine {
|
||||
}
|
||||
}
|
||||
|
||||
public static String getGalleryToken(EhClient.Task task, OkHttpClient okHttpClient,
|
||||
public static String getGalleryToken(@Nullable EhClient.Task task, OkHttpClient okHttpClient,
|
||||
long gid, String gtoken, int page) throws Exception {
|
||||
JSONObject json = new JSONObject()
|
||||
.put("method", "gtoken")
|
||||
.put("pagelist", new JSONArray().put(
|
||||
new JSONArray().put(gid).put(gtoken).put(page + 1)));
|
||||
final RequestBody requestBody = RequestBody.create(JSON, json.toString());
|
||||
final RequestBody requestBody = RequestBody.create(MEDIA_TYPE_JSON, json.toString());
|
||||
String url = EhUrl.getApiUrl();
|
||||
Log.d(TAG, url);
|
||||
Request request = new EhRequestBuilder(url, task.getEhConfig())
|
||||
Request request = new EhRequestBuilder(url, null != task ? task.getEhConfig() : Settings.getEhConfig())
|
||||
.post(requestBody)
|
||||
.build();
|
||||
Call call = okHttpClient.newCall(request);
|
||||
|
||||
// Put call
|
||||
task.setCall(call);
|
||||
if (null != task) {
|
||||
task.setCall(call);
|
||||
}
|
||||
|
||||
String body = null;
|
||||
Headers headers = null;
|
||||
@@ -431,14 +417,16 @@ public class EhEngine {
|
||||
}
|
||||
}
|
||||
|
||||
public static FavoritesParser.Result getFavorites(EhClient.Task task, OkHttpClient okHttpClient,
|
||||
public static FavoritesParser.Result getFavorites(@Nullable EhClient.Task task, OkHttpClient okHttpClient,
|
||||
String url, boolean callApi) throws Exception {
|
||||
Log.d(TAG, url);
|
||||
Request request = new EhRequestBuilder(url, task.getEhConfig()).build();
|
||||
Request request = new EhRequestBuilder(url, null != task ? task.getEhConfig() : Settings.getEhConfig()).build();
|
||||
Call call = okHttpClient.newCall(request);
|
||||
|
||||
// Put call
|
||||
task.setCall(call);
|
||||
if (null != task) {
|
||||
task.setCall(call);
|
||||
}
|
||||
|
||||
String body = null;
|
||||
Headers headers = null;
|
||||
@@ -466,7 +454,7 @@ public class EhEngine {
|
||||
* @param dstCat -1 for delete, 0 - 9 for cloud favorite, others throw Exception
|
||||
* @param note max 250 characters
|
||||
*/
|
||||
public static Void addFavorites(EhClient.Task task, OkHttpClient okHttpClient,
|
||||
public static Void addFavorites(@Nullable EhClient.Task task, OkHttpClient okHttpClient,
|
||||
long gid, String token, int dstCat, String note) throws Exception {
|
||||
String catStr;
|
||||
if (dstCat == -1) {
|
||||
@@ -481,15 +469,18 @@ public class EhEngine {
|
||||
builder.add("favnote", note != null ? note : "");
|
||||
// submit=Add+to+Favorites is not necessary, just use submit=Apply+Changes all the time
|
||||
builder.add("submit", "Apply Changes");
|
||||
builder.add("update", "1");
|
||||
String url = EhUrl.getAddFavorites(gid, token);
|
||||
Log.d(TAG, url);
|
||||
Request request = new EhRequestBuilder(url, task.getEhConfig())
|
||||
Request request = new EhRequestBuilder(url, null != task ? task.getEhConfig() : Settings.getEhConfig())
|
||||
.post(builder.build())
|
||||
.build();
|
||||
Call call = okHttpClient.newCall(request);
|
||||
|
||||
// Put call
|
||||
task.setCall(call);
|
||||
if (null != task) {
|
||||
task.setCall(call);
|
||||
}
|
||||
|
||||
String body = null;
|
||||
Headers headers = null;
|
||||
@@ -508,7 +499,7 @@ public class EhEngine {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Void addFavoritesRange(EhClient.Task task, OkHttpClient okHttpClient,
|
||||
public static Void addFavoritesRange(@Nullable EhClient.Task task, OkHttpClient okHttpClient,
|
||||
long[] gidArray, String[] tokenArray, int dstCat) throws Exception {
|
||||
AssertUtils.assertEqualsEx(gidArray.length, tokenArray.length);
|
||||
for (int i = 0, n = gidArray.length; i < n; i++) {
|
||||
@@ -517,7 +508,7 @@ public class EhEngine {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static FavoritesParser.Result modifyFavorites(EhClient.Task task, OkHttpClient okHttpClient,
|
||||
public static FavoritesParser.Result modifyFavorites(@Nullable EhClient.Task task, OkHttpClient okHttpClient,
|
||||
String url, long[] gidArray, int dstCat, boolean callApi) throws Exception {
|
||||
String catStr;
|
||||
if (dstCat == -1) {
|
||||
@@ -534,13 +525,15 @@ public class EhEngine {
|
||||
}
|
||||
builder.add("apply", "Apply");
|
||||
Log.d(TAG, url);
|
||||
Request request = new EhRequestBuilder(url, task.getEhConfig())
|
||||
Request request = new EhRequestBuilder(url, null != task ? task.getEhConfig() : Settings.getEhConfig())
|
||||
.post(builder.build())
|
||||
.build();
|
||||
Call call = okHttpClient.newCall(request);
|
||||
|
||||
// Put call
|
||||
task.setCall(call);
|
||||
if (null != task) {
|
||||
task.setCall(call);
|
||||
}
|
||||
|
||||
String body = null;
|
||||
Headers headers = null;
|
||||
@@ -564,14 +557,16 @@ public class EhEngine {
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Pair<String, String>[] getTorrentList(EhClient.Task task, OkHttpClient okHttpClient,
|
||||
public static Pair<String, String>[] getTorrentList(@Nullable EhClient.Task task, OkHttpClient okHttpClient,
|
||||
String url) throws Exception {
|
||||
Log.d(TAG, url);
|
||||
Request request = new EhRequestBuilder(url, task.getEhConfig()).build();
|
||||
Request request = new EhRequestBuilder(url, null != task ? task.getEhConfig() : Settings.getEhConfig()).build();
|
||||
Call call = okHttpClient.newCall(request);
|
||||
|
||||
// Put call
|
||||
task.setCall(call);
|
||||
if (null != task) {
|
||||
task.setCall(call);
|
||||
}
|
||||
|
||||
String body = null;
|
||||
Headers headers = null;
|
||||
@@ -591,15 +586,17 @@ public class EhEngine {
|
||||
return result;
|
||||
}
|
||||
|
||||
public static List<GalleryInfo> getWhatsHot(EhClient.Task task,
|
||||
public static List<GalleryInfo> getWhatsHot(@Nullable EhClient.Task task,
|
||||
OkHttpClient okHttpClient) throws Exception {
|
||||
String url = EhUrl.HOST_G;
|
||||
Log.d(TAG, url);
|
||||
Request request = new EhRequestBuilder(url, task.getEhConfig()).build();
|
||||
Request request = new EhRequestBuilder(url, null != task ? task.getEhConfig() : Settings.getEhConfig()).build();
|
||||
Call call = okHttpClient.newCall(request);
|
||||
|
||||
// Put call
|
||||
task.setCall(call);
|
||||
if (null != task) {
|
||||
task.setCall(call);
|
||||
}
|
||||
|
||||
String body = null;
|
||||
Headers headers = null;
|
||||
@@ -624,14 +621,16 @@ public class EhEngine {
|
||||
return list;
|
||||
}
|
||||
|
||||
private static ProfileParser.Result getProfileInternal(EhClient.Task task,
|
||||
private static ProfileParser.Result getProfileInternal(@Nullable EhClient.Task task,
|
||||
OkHttpClient okHttpClient, String url) throws Exception {
|
||||
Log.d(TAG, url);
|
||||
Request request = new EhRequestBuilder(url, task.getEhConfig()).build();
|
||||
Request request = new EhRequestBuilder(url, null != task ? task.getEhConfig() : Settings.getEhConfig()).build();
|
||||
Call call = okHttpClient.newCall(request);
|
||||
|
||||
// Put call
|
||||
task.setCall(call);
|
||||
if (null != task) {
|
||||
task.setCall(call);
|
||||
}
|
||||
|
||||
String body = null;
|
||||
Headers headers = null;
|
||||
@@ -648,15 +647,17 @@ public class EhEngine {
|
||||
}
|
||||
}
|
||||
|
||||
public static ProfileParser.Result getProfile(EhClient.Task task,
|
||||
public static ProfileParser.Result getProfile(@Nullable EhClient.Task task,
|
||||
OkHttpClient okHttpClient) throws Exception {
|
||||
String url = EhUrl.URL_FORUMS;
|
||||
Log.d(TAG, url);
|
||||
Request request = new EhRequestBuilder(url, task.getEhConfig()).build();
|
||||
Request request = new EhRequestBuilder(url, null != task ? task.getEhConfig() : Settings.getEhConfig()).build();
|
||||
Call call = okHttpClient.newCall(request);
|
||||
|
||||
// Put call
|
||||
task.setCall(call);
|
||||
if (null != task) {
|
||||
task.setCall(call);
|
||||
}
|
||||
|
||||
String body = null;
|
||||
Headers headers = null;
|
||||
@@ -672,4 +673,160 @@ public class EhEngine {
|
||||
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 {
|
||||
final JSONObject json = new JSONObject();
|
||||
json.put("method", "votecomment");
|
||||
json.put("apiuid", apiUid);
|
||||
json.put("apikey", apiKey);
|
||||
json.put("gid", gid);
|
||||
json.put("token", token);
|
||||
json.put("comment_id", commentId);
|
||||
json.put("comment_vote", commentVote);
|
||||
final RequestBody requestBody = RequestBody.create(MEDIA_TYPE_JSON, json.toString());
|
||||
String url = EhUrl.getApiUrl();
|
||||
Log.d(TAG, url);
|
||||
Request request = new EhRequestBuilder(url, null != task ? task.getEhConfig() : Settings.getEhConfig())
|
||||
.post(requestBody)
|
||||
.build();
|
||||
Call call = okHttpClient.newCall(request);
|
||||
|
||||
// Put call
|
||||
if (null != task) {
|
||||
task.setCall(call);
|
||||
}
|
||||
|
||||
String body = null;
|
||||
Headers headers = null;
|
||||
int code = -1;
|
||||
try {
|
||||
Response response = call.execute();
|
||||
code = response.code();
|
||||
headers = response.headers();
|
||||
body = response.body().string();
|
||||
return VoteCommentParser.parse(body, commentVote);
|
||||
} catch (Exception e) {
|
||||
throwException(call, code, headers, body, e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @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 {
|
||||
MultipartBody.Builder builder = new MultipartBody.Builder();
|
||||
builder.setType(MultipartBody.FORM);
|
||||
builder.addPart(
|
||||
Headers.of("Content-Disposition", "form-data; name=\"sfile\"; filename=\"a.jpg\""),
|
||||
RequestBody.create(MEDIA_TYPE_JPEG, image)
|
||||
);
|
||||
if (uss) {
|
||||
builder.addPart(
|
||||
Headers.of("Content-Disposition", "form-data; name=\"fs_similar\""),
|
||||
RequestBody.create(null, "on")
|
||||
);
|
||||
}
|
||||
if (osc) {
|
||||
builder.addPart(
|
||||
Headers.of("Content-Disposition", "form-data; name=\"fs_covers\""),
|
||||
RequestBody.create(null, "on")
|
||||
);
|
||||
}
|
||||
if (se) {
|
||||
builder.addPart(
|
||||
Headers.of("Content-Disposition", "form-data; name=\"fs_exp\""),
|
||||
RequestBody.create(null, "on")
|
||||
);
|
||||
}
|
||||
builder.addPart(
|
||||
Headers.of("Content-Disposition", "form-data; name=\"f_sfile\""),
|
||||
RequestBody.create(null, "File Search")
|
||||
);
|
||||
String url = EhUrl.getImageSearchUrl();
|
||||
Log.d(TAG, url);
|
||||
Request request = new EhRequestBuilder(url, null != task ? task.getEhConfig() : Settings.getEhConfig())
|
||||
.post(builder.build())
|
||||
.build();
|
||||
Call call = okHttpClient.newCall(request);
|
||||
|
||||
// Put call
|
||||
if (null != task) {
|
||||
task.setCall(call);
|
||||
}
|
||||
|
||||
String body = null;
|
||||
Headers headers = null;
|
||||
GalleryListParser.Result result;
|
||||
int code = -1;
|
||||
try {
|
||||
Response response = call.execute();
|
||||
|
||||
Log.d(TAG, "" + response.request().url().toString());
|
||||
|
||||
code = response.code();
|
||||
headers = response.headers();
|
||||
body = response.body().string();
|
||||
result = GalleryListParser.parse(body);
|
||||
} catch (Exception e) {
|
||||
throwException(call, code, headers, body, e);
|
||||
throw e;
|
||||
}
|
||||
|
||||
// Filter title and uploader
|
||||
List<GalleryInfo> list = result.galleryInfoList;
|
||||
for (int i = 0, n = list.size(); i < n; i++) {
|
||||
GalleryInfo info = list.get(i);
|
||||
if (!sEhFilter.filterTitle(info) || !sEhFilter.filterUploader(info)) {
|
||||
list.remove(i);
|
||||
i--;
|
||||
n--;
|
||||
}
|
||||
}
|
||||
|
||||
if (list.size() > 0 && (Settings.getShowJpnTitle() || sEhFilter.needCallApi())) {
|
||||
// Fill by api
|
||||
fillGalleryListByApi(task, okHttpClient, list);
|
||||
|
||||
// Filter tag
|
||||
for (int i = 0, n = list.size(); i < n; i++) {
|
||||
GalleryInfo info = list.get(i);
|
||||
if (!sEhFilter.filterTag(info) || !sEhFilter.filterTagNamespace(info)) {
|
||||
list.remove(i);
|
||||
i--;
|
||||
n--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static GalleryPageParser.Result getGalleryPage(@Nullable EhClient.Task task,
|
||||
OkHttpClient okHttpClient, String url) throws Exception {
|
||||
Log.d(TAG, url);
|
||||
Request request = new EhRequestBuilder(url, null != task ? task.getEhConfig() : Settings.getEhConfig()).build();
|
||||
Call call = okHttpClient.newCall(request);
|
||||
|
||||
// Put call
|
||||
if (null != task) {
|
||||
task.setCall(call);
|
||||
}
|
||||
|
||||
String body = null;
|
||||
Headers headers = null;
|
||||
int code = -1;
|
||||
try {
|
||||
Response response = call.execute();
|
||||
code = response.code();
|
||||
headers = response.headers();
|
||||
body = response.body().string();
|
||||
return GalleryPageParser.parse(body);
|
||||
} catch (Exception e) {
|
||||
throwException(call, code, headers, body, e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
package com.hippo.ehviewer.client;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import com.hippo.ehviewer.Settings;
|
||||
import com.hippo.network.UrlBuilder;
|
||||
|
||||
@@ -29,6 +31,7 @@ public class EhUrl {
|
||||
public static final String DOMAIN_G = "g.e-hentai.org";
|
||||
public static final String DOMAIN_LOFI = "lofi.e-hentai.org";
|
||||
|
||||
public static final String HOST_E = "http://" + DOMAIN_E + "/";
|
||||
public static final String HOST_EX = "http://" + DOMAIN_EX + "/";
|
||||
public static final String HOST_G = "http://" + DOMAIN_G + "/";
|
||||
|
||||
@@ -99,4 +102,15 @@ public class EhUrl {
|
||||
public static String getTagDefinitionUrl(String tag) {
|
||||
return "https://ehwiki.org/wiki/" + tag.replace(' ', '_');
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static String getImageSearchUrl() {
|
||||
switch (Settings.getGallerySite()) {
|
||||
default:
|
||||
case SITE_G:
|
||||
return "http://ul.e-hentai.org/image_lookup.php";
|
||||
case SITE_EX:
|
||||
return "http://ul.exhentai.org/image_lookup.php";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -168,4 +168,31 @@ public class EhUtils {
|
||||
return title;
|
||||
}
|
||||
}
|
||||
|
||||
public static String handleThumbUrlResolution(String url) {
|
||||
if (null == url) {
|
||||
return null;
|
||||
}
|
||||
|
||||
String resolution;
|
||||
switch (Settings.getThumbResolution()) {
|
||||
default:
|
||||
case 0: // Auto
|
||||
return url;
|
||||
case 1: // 250
|
||||
resolution = "250";
|
||||
break;
|
||||
case 2: // 300
|
||||
resolution = "300";
|
||||
break;
|
||||
}
|
||||
|
||||
int index1 = url.lastIndexOf('_');
|
||||
int index2 = url.lastIndexOf('.');
|
||||
if (index1 >= 0 && index2 >= 0 && index1 < index2) {
|
||||
return url.substring(0, index1 + 1) + resolution + url.substring(index2);
|
||||
} else {
|
||||
return url;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -21,6 +21,12 @@ import android.os.Parcelable;
|
||||
|
||||
public class GalleryComment implements Parcelable {
|
||||
|
||||
// 0 for uploader comment. can't vote
|
||||
public long id;
|
||||
public int score;
|
||||
public boolean voteUp;
|
||||
public boolean voteDown;
|
||||
public String voteState;
|
||||
public long time;
|
||||
public String user;
|
||||
public String comment;
|
||||
@@ -32,6 +38,11 @@ public class GalleryComment implements Parcelable {
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
dest.writeLong(this.id);
|
||||
dest.writeInt(this.score);
|
||||
dest.writeByte(voteUp ? (byte) 1 : (byte) 0);
|
||||
dest.writeByte(voteDown ? (byte) 1 : (byte) 0);
|
||||
dest.writeString(this.voteState);
|
||||
dest.writeLong(this.time);
|
||||
dest.writeString(this.user);
|
||||
dest.writeString(this.comment);
|
||||
@@ -41,16 +52,23 @@ public class GalleryComment implements Parcelable {
|
||||
}
|
||||
|
||||
protected GalleryComment(Parcel in) {
|
||||
this.id = in.readLong();
|
||||
this.score = in.readInt();
|
||||
this.voteUp = in.readByte() != 0;
|
||||
this.voteDown = in.readByte() != 0;
|
||||
this.voteState = in.readString();
|
||||
this.time = in.readLong();
|
||||
this.user = in.readString();
|
||||
this.comment = in.readString();
|
||||
}
|
||||
|
||||
public static final Creator<GalleryComment> CREATOR = new Creator<GalleryComment>() {
|
||||
@Override
|
||||
public GalleryComment createFromParcel(Parcel source) {
|
||||
return new GalleryComment(source);
|
||||
}
|
||||
|
||||
@Override
|
||||
public GalleryComment[] newArray(int size) {
|
||||
return new GalleryComment[size];
|
||||
}
|
||||
|
||||
@@ -23,6 +23,8 @@ import java.util.Arrays;
|
||||
|
||||
public class GalleryDetail extends GalleryInfo {
|
||||
|
||||
public long apiUid = -1L;
|
||||
public String apiKey;
|
||||
public int torrentCount;
|
||||
public String torrentUrl;
|
||||
public String parent;
|
||||
|
||||
@@ -19,6 +19,7 @@ package com.hippo.ehviewer.client.data;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.support.annotation.IntDef;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.hippo.ehviewer.client.EhConfig;
|
||||
@@ -62,6 +63,11 @@ public class ListUrlBuilder implements Cloneable, Parcelable {
|
||||
private int mAdvanceSearch = -1;
|
||||
private int mMinRating = -1;
|
||||
|
||||
private String mImagePath;
|
||||
private boolean mUseSimilarityScan;
|
||||
private boolean mOnlySearchCovers;
|
||||
private boolean mShowExpunged;
|
||||
|
||||
/**
|
||||
* Make this ListUrlBuilder point to homepage
|
||||
*/
|
||||
@@ -72,6 +78,10 @@ public class ListUrlBuilder implements Cloneable, Parcelable {
|
||||
mKeyword = null;
|
||||
mAdvanceSearch = -1;
|
||||
mMinRating = -1;
|
||||
mImagePath = null;
|
||||
mUseSimilarityScan = false;
|
||||
mOnlySearchCovers = false;
|
||||
mShowExpunged = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -132,6 +142,39 @@ public class ListUrlBuilder implements Cloneable, Parcelable {
|
||||
mMinRating = minRating;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getImagePath() {
|
||||
return mImagePath;
|
||||
}
|
||||
|
||||
public void setImagePath(String imagePath) {
|
||||
mImagePath = imagePath;
|
||||
}
|
||||
|
||||
public boolean isUseSimilarityScan() {
|
||||
return mUseSimilarityScan;
|
||||
}
|
||||
|
||||
public void setUseSimilarityScan(boolean useSimilarityScan) {
|
||||
mUseSimilarityScan = useSimilarityScan;
|
||||
}
|
||||
|
||||
public boolean isOnlySearchCovers() {
|
||||
return mOnlySearchCovers;
|
||||
}
|
||||
|
||||
public void setOnlySearchCovers(boolean onlySearchCovers) {
|
||||
mOnlySearchCovers = onlySearchCovers;
|
||||
}
|
||||
|
||||
public boolean isShowExpunged() {
|
||||
return mShowExpunged;
|
||||
}
|
||||
|
||||
public void setShowExpunged(boolean showExpunged) {
|
||||
mShowExpunged = showExpunged;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make them the same
|
||||
* @param lub The template
|
||||
@@ -143,6 +186,10 @@ public class ListUrlBuilder implements Cloneable, Parcelable {
|
||||
mKeyword = lub.mKeyword;
|
||||
mAdvanceSearch = lub.mAdvanceSearch;
|
||||
mMinRating = lub.mMinRating;
|
||||
mImagePath = lub.mImagePath;
|
||||
mUseSimilarityScan = lub.mUseSimilarityScan;
|
||||
mOnlySearchCovers = lub.mOnlySearchCovers;
|
||||
mShowExpunged = lub.mShowExpunged;
|
||||
}
|
||||
|
||||
public void set(QuickSearch q) {
|
||||
@@ -151,6 +198,10 @@ public class ListUrlBuilder implements Cloneable, Parcelable {
|
||||
mKeyword = q.keyword;
|
||||
mAdvanceSearch = q.advanceSearch;
|
||||
mMinRating = q.minRating;
|
||||
mImagePath = null;
|
||||
mUseSimilarityScan = false;
|
||||
mOnlySearchCovers = false;
|
||||
mShowExpunged = false;
|
||||
}
|
||||
|
||||
public QuickSearch toQuickSearch() {
|
||||
@@ -413,6 +464,8 @@ public class ListUrlBuilder implements Cloneable, Parcelable {
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
case MODE_IMAGE_SEARCH:
|
||||
return EhUrl.getImageSearchUrl();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -429,22 +482,30 @@ public class ListUrlBuilder implements Cloneable, Parcelable {
|
||||
dest.writeString(this.mKeyword);
|
||||
dest.writeInt(this.mAdvanceSearch);
|
||||
dest.writeInt(this.mMinRating);
|
||||
dest.writeString(this.mImagePath);
|
||||
dest.writeByte(mUseSimilarityScan ? (byte) 1 : (byte) 0);
|
||||
dest.writeByte(mOnlySearchCovers ? (byte) 1 : (byte) 0);
|
||||
dest.writeByte(mShowExpunged ? (byte) 1 : (byte) 0);
|
||||
}
|
||||
|
||||
public ListUrlBuilder() {}
|
||||
public ListUrlBuilder() {
|
||||
}
|
||||
|
||||
@SuppressWarnings("WrongConstant")
|
||||
protected ListUrlBuilder(Parcel in) {
|
||||
mMode = in.readInt();
|
||||
mPageIndex = in.readInt();
|
||||
mCategory = in.readInt();
|
||||
mKeyword = in.readString();
|
||||
mAdvanceSearch = in.readInt();
|
||||
mMinRating = in.readInt();
|
||||
this.mMode = in.readInt();
|
||||
this.mPageIndex = in.readInt();
|
||||
this.mCategory = in.readInt();
|
||||
this.mKeyword = in.readString();
|
||||
this.mAdvanceSearch = in.readInt();
|
||||
this.mMinRating = in.readInt();
|
||||
this.mImagePath = in.readString();
|
||||
this.mUseSimilarityScan = in.readByte() != 0;
|
||||
this.mOnlySearchCovers = in.readByte() != 0;
|
||||
this.mShowExpunged = in.readByte() != 0;
|
||||
}
|
||||
|
||||
public static final Parcelable.Creator<ListUrlBuilder> CREATOR = new Parcelable.Creator<ListUrlBuilder>() {
|
||||
|
||||
public static final Creator<ListUrlBuilder> CREATOR = new Creator<ListUrlBuilder>() {
|
||||
@Override
|
||||
public ListUrlBuilder createFromParcel(Parcel source) {
|
||||
return new ListUrlBuilder(source);
|
||||
|
||||
@@ -41,7 +41,7 @@ public class GalleryApiParser {
|
||||
gi.title = ParserUtils.trim(g.getString("title"));
|
||||
gi.titleJpn = ParserUtils.trim(g.getString("title_jpn"));
|
||||
gi.category = EhUtils.getCategory(g.getString("category"));
|
||||
gi.thumb = g.getString("thumb");
|
||||
gi.thumb = EhUtils.handleThumbUrlResolution(g.getString("thumb"));
|
||||
gi.uploader = g.getString("uploader");
|
||||
gi.posted = ParserUtils.formatDate(ParserUtils.parseLong(g.getString("posted")) * 1000);
|
||||
gi.rating = Float.parseFloat(g.getString("rating"));
|
||||
|
||||
@@ -18,6 +18,7 @@ package com.hippo.ehviewer.client.parser;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.hippo.ehviewer.client.EhUtils;
|
||||
import com.hippo.ehviewer.client.data.GalleryComment;
|
||||
@@ -53,7 +54,7 @@ import java.util.regex.Pattern;
|
||||
public class GalleryDetailParser {
|
||||
|
||||
private static final Pattern PATTERN_ERROR = Pattern.compile("<div class=\"d\">\n<p>([^<]+)</p>");
|
||||
private static final Pattern PATTERN_DETAIL = Pattern.compile("var gid = (\\d+).+?var token = \"([a-f0-9]+)\"", Pattern.DOTALL);
|
||||
private static final Pattern PATTERN_DETAIL = Pattern.compile("var gid = (\\d+);.+?var token = \"([a-f0-9]+)\";.+?var apiuid = ([\\-\\d]+);.+?var apikey = \"([a-f0-9]+)\";", Pattern.DOTALL);
|
||||
private static final Pattern PATTERN_TORRENT = Pattern.compile("<a[^<>]*onclick=\"return popUp\\('([^']+)'[^)]+\\)\">Torrent Download \\( (\\d+) \\)</a>");
|
||||
private static final Pattern PATTERN_TAG_GROUP = Pattern.compile("<tr><td[^<>]+>([\\w\\s]+):</td><td>(?:<div[^<>]+><a[^<>]+>[\\w\\s]+</a></div>)+</td></tr>");
|
||||
private static final Pattern PATTERN_TAG = Pattern.compile("<div[^<>]+><a[^<>]+>([\\w\\s]+)</a></div>");
|
||||
@@ -108,6 +109,8 @@ public class GalleryDetailParser {
|
||||
if (matcher.find()) {
|
||||
gd.gid = Long.parseLong(matcher.group(1));
|
||||
gd.token = matcher.group(2);
|
||||
gd.apiUid = NumberUtils.parseLongSafely(matcher.group(3), -1L);
|
||||
gd.apiKey = matcher.group(4);
|
||||
} else {
|
||||
throw new ParseException("Can't parse gallery detail", body);
|
||||
}
|
||||
@@ -127,7 +130,7 @@ public class GalleryDetailParser {
|
||||
// Thumb url
|
||||
Element gd1 = gm.getElementById("gd1");
|
||||
try {
|
||||
gd.thumb = StringUtils.trim(gd1.child(0).attr("src"));
|
||||
gd.thumb = EhUtils.handleThumbUrlResolution(StringUtils.trim(gd1.child(0).attr("src")));
|
||||
} catch (Exception e) {
|
||||
gd.thumb = "";
|
||||
}
|
||||
@@ -195,7 +198,7 @@ public class GalleryDetailParser {
|
||||
if (null != rating_label) {
|
||||
String ratingStr = StringUtils.trim(rating_label.text());
|
||||
if ("Not Yet Rated".equals(ratingStr)) {
|
||||
gd.rating = Float.NaN;
|
||||
gd.rating = -1.0f;
|
||||
} else {
|
||||
int index = ratingStr.indexOf(' ');
|
||||
if (index == -1 || index >= ratingStr.length()) {
|
||||
@@ -205,7 +208,7 @@ public class GalleryDetailParser {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
gd.rating = Float.NaN;
|
||||
gd.rating = -1.0f;
|
||||
}
|
||||
|
||||
// isFavorited
|
||||
@@ -342,11 +345,40 @@ public class GalleryDetailParser {
|
||||
public static GalleryComment parseComment(Element element) {
|
||||
try {
|
||||
GalleryComment comment = new GalleryComment();
|
||||
// Id
|
||||
Element a = element.previousElementSibling();
|
||||
String name = a.attr("name");
|
||||
comment.id = Integer.parseInt(StringUtils.trim(name).substring(1));
|
||||
// Vote up and vote down
|
||||
Element c4 = JsoupUtils.getElementByClass(element, "c4");
|
||||
if (null != c4) {
|
||||
Elements es = c4.children();
|
||||
if (2 == es.size()) {
|
||||
comment.voteUp = !TextUtils.isEmpty(StringUtils.trim(es.get(0).attr("style")));
|
||||
comment.voteDown = !TextUtils.isEmpty(StringUtils.trim(es.get(1).attr("style")));
|
||||
}
|
||||
}
|
||||
// Vote state
|
||||
Element c7 = JsoupUtils.getElementByClass(element, "c7");
|
||||
if (null != c7) {
|
||||
comment.voteState = StringUtils.trim(c7.text());
|
||||
}
|
||||
// Score
|
||||
Element c5 = JsoupUtils.getElementByClass(element, "c5");
|
||||
if (null != c5) {
|
||||
Elements es = c5.children();
|
||||
if (!es.isEmpty()) {
|
||||
comment.score = NumberUtils.parseIntSafely(StringUtils.trim(es.get(0).text()), 0);
|
||||
}
|
||||
}
|
||||
// time
|
||||
Element c3 = JsoupUtils.getElementByClass(element, "c3");
|
||||
String temp = c3.ownText();
|
||||
temp = temp.substring("Posted on ".length(), temp.length() - " by: ".length());
|
||||
comment.time = WEB_COMMENT_DATE_FORMAT.parse(temp).getTime();
|
||||
// user
|
||||
comment.user = c3.child(0).text();
|
||||
// comment
|
||||
comment.comment = JsoupUtils.getElementByClass(element, "c6").html();
|
||||
return comment;
|
||||
} catch (Exception e) {
|
||||
|
||||
@@ -121,13 +121,14 @@ public class GalleryListParser {
|
||||
// Thumb url
|
||||
Elements es = it2.children();
|
||||
if (null != es && es.size() >= 1) {
|
||||
gi.thumb = es.get(0).attr("src");
|
||||
gi.thumb = EhUtils.handleThumbUrlResolution(es.get(0).attr("src"));
|
||||
} else {
|
||||
String html = it2.html();
|
||||
int index1 = html.indexOf('~');
|
||||
int index2 = StringUtils.ordinalIndexOf(html, '~', 2);
|
||||
if (index1 < index2) {
|
||||
gi.thumb = "http://" +StringUtils.replace(html.substring(index1 + 1, index2), "~", "/");
|
||||
gi.thumb = EhUtils.handleThumbUrlResolution(
|
||||
"http://" +StringUtils.replace(html.substring(index1 + 1, index2), "~", "/"));
|
||||
} else {
|
||||
Log.w(TAG, "Can't parse gallery info thumb url");
|
||||
gi.thumb = "";
|
||||
@@ -162,10 +163,10 @@ public class GalleryListParser {
|
||||
// Rating
|
||||
Element it4r = JsoupUtils.getElementByClass(e, "it4r");
|
||||
if (null != it4r) {
|
||||
gi.rating = NumberUtils.parseFloatSafely(parseRating(it4r.attr("style")), Float.NaN);
|
||||
gi.rating = NumberUtils.parseFloatSafely(parseRating(it4r.attr("style")), -1.0f);
|
||||
} else {
|
||||
Log.w(TAG, "Can't parse gallery info rating");
|
||||
gi.rating = Float.NaN;
|
||||
gi.rating = -1.0f;
|
||||
}
|
||||
// Uploader
|
||||
Element itu = JsoupUtils.getElementByClass(e, "itu");
|
||||
|
||||
@@ -26,9 +26,9 @@ import java.util.regex.Pattern;
|
||||
|
||||
public class GalleryPageParser {
|
||||
|
||||
private static final Pattern PATTERN_IMAGE_URL = Pattern.compile("<div id=\"i3\"><a[^>]+><img id=\"img\" src=\"([^\"]+)\"");
|
||||
private static final Pattern PATTERN_IMAGE_URL = Pattern.compile("<(?:/iframe|div id=\"i3\")[^>]*><a[^>]+><img[^>]*src=\"(.+?)\"");
|
||||
private static final Pattern PATTERN_SKIP_HATH_KEY = Pattern.compile("onclick=\"return nl\\('([^\\)]+)'\\)");
|
||||
private static final Pattern PATTERN_ORIGIN_IMAGE_URL = Pattern.compile("<div id=\"i7\" class=\"if\"> <img[^>]+/> <a href=\"([^\"]+)\">");
|
||||
private static final Pattern PATTERN_ORIGIN_IMAGE_URL = Pattern.compile("<a href=\"([^\"]+)fullimg.php([^\"]+)\">");
|
||||
|
||||
public static Result parse(String body) throws ParseException {
|
||||
Matcher m;
|
||||
@@ -43,9 +43,10 @@ public class GalleryPageParser {
|
||||
}
|
||||
m = PATTERN_ORIGIN_IMAGE_URL.matcher(body);
|
||||
if (m.find()) {
|
||||
result.originImageUrl = StringUtils.unescapeXml(StringUtils.trim(m.group(1)));
|
||||
result.originImageUrl = StringUtils.unescapeXml(m.group(1)) + "fullimg.php" + StringUtils.unescapeXml(m.group(2));
|
||||
}
|
||||
if (!TextUtils.isEmpty(result.imageUrl) && !TextUtils.isEmpty(result.skipHathKey)) {
|
||||
|
||||
if (!TextUtils.isEmpty(result.imageUrl)) {
|
||||
return result;
|
||||
} else {
|
||||
throw new ParseException("Parse image url and skip hath key error", body);
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright 2016 Hippo Seven
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.hippo.ehviewer.client.parser;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
public class VoteCommentParser {
|
||||
|
||||
public static class Result {
|
||||
public long id;
|
||||
public int score;
|
||||
public int vote;
|
||||
public int expectVote;
|
||||
}
|
||||
|
||||
// {"comment_id":1253922,"comment_score":-19,"comment_vote":0}
|
||||
public static Result parse(String body, int vote) throws JSONException {
|
||||
Result result = new Result();
|
||||
JSONObject jo = new JSONObject(body);
|
||||
result.id = jo.getLong("comment_id");
|
||||
result.score = jo.getInt("comment_score");
|
||||
result.vote = jo.getInt("comment_vote");
|
||||
result.expectVote = vote;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
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.JsoupUtils;
|
||||
@@ -47,7 +48,7 @@ public class WhatsHotParser {
|
||||
galleryInfo.gid = result.gid;
|
||||
galleryInfo.token = result.token;
|
||||
temp = JsoupUtils.getElementByTag(temp, "img");
|
||||
galleryInfo.thumb = temp.attr("src");
|
||||
galleryInfo.thumb = EhUtils.handleThumbUrlResolution(temp.attr("src"));
|
||||
galleryInfo.title = temp.attr("title");
|
||||
galleryInfo.generateSLang();
|
||||
galleryInfoList.add(galleryInfo);
|
||||
|
||||
@@ -48,7 +48,6 @@ import com.hippo.yorozuya.sparse.SparseJLArray;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
// TODO Stop and delete action should not pass through DownloadService
|
||||
public class DownloadService extends Service implements DownloadManager.DownloadListener {
|
||||
|
||||
public static final String ACTION_START = "start";
|
||||
@@ -346,7 +345,9 @@ public class DownloadService extends Service implements DownloadManager.Download
|
||||
return;
|
||||
}
|
||||
|
||||
mDownloadingDelay.cancel();
|
||||
if (null != mDownloadingDelay) {
|
||||
mDownloadingDelay.cancel();
|
||||
}
|
||||
|
||||
ensureDownloadedBuilder();
|
||||
|
||||
@@ -444,7 +445,10 @@ public class DownloadService extends Service implements DownloadManager.Download
|
||||
return;
|
||||
}
|
||||
|
||||
mDownloadingDelay.cancel();
|
||||
if (null != mDownloadingDelay) {
|
||||
mDownloadingDelay.cancel();
|
||||
}
|
||||
|
||||
checkStopSelf();
|
||||
}
|
||||
|
||||
|
||||
@@ -54,15 +54,9 @@ public class EhGalleryProvider extends GalleryProvider implements SpiderQueen.On
|
||||
|
||||
if (mSpiderQueen != null) {
|
||||
mSpiderQueen.removeOnSpiderListener(this);
|
||||
final SpiderQueen spiderQueen = mSpiderQueen;
|
||||
// Activity recreate may called, so wait 3000s
|
||||
SimpleHandler.getInstance().postDelayed(new ReleaseTask(mSpiderQueen), 3000);
|
||||
mSpiderQueen = null;
|
||||
// Activity recreate may called
|
||||
SimpleHandler.getInstance().postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
SpiderQueen.releaseSpiderQueen(spiderQueen, SpiderQueen.MODE_READ);
|
||||
}
|
||||
}, 3000);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -200,4 +194,21 @@ public class EhGalleryProvider extends GalleryProvider implements SpiderQueen.On
|
||||
public void onGetImageFailure(int index, String error) {
|
||||
notifyPageFailed(index, error);
|
||||
}
|
||||
|
||||
private static class ReleaseTask implements Runnable {
|
||||
|
||||
private SpiderQueen mSpiderQueen;
|
||||
|
||||
public ReleaseTask(SpiderQueen spiderQueen) {
|
||||
mSpiderQueen = spiderQueen;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (null != mSpiderQueen) {
|
||||
SpiderQueen.releaseSpiderQueen(mSpiderQueen, SpiderQueen.MODE_READ);
|
||||
mSpiderQueen = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -121,7 +121,8 @@ public class GalleryPageView extends GLFrameLayout {
|
||||
}
|
||||
|
||||
public void showInfo() {
|
||||
mImage.setVisibility(GONE);
|
||||
// For image valid rect
|
||||
mImage.setVisibility(INVISIBLE);
|
||||
mInfo.setVisibility(VISIBLE);
|
||||
}
|
||||
|
||||
|
||||
@@ -88,9 +88,6 @@ public class GalleryView extends GLView implements GestureRecognizer.Listener {
|
||||
private static final int METHOD_SET_SCALE_MODE = 18;
|
||||
private static final int METHOD_SET_START_POSITION = 19;
|
||||
private static final int METHOD_ON_ATTACH_TO_ROOT = 20;
|
||||
private static final int METHOD_ON_DETACH_FROM_ROOT = 21;
|
||||
private static final int METHOD_PAUSE = 22;
|
||||
private static final int METHOD_RESUME = 23;
|
||||
|
||||
private final Context mContext;
|
||||
private MovableTextTexture mPageTextTexture;
|
||||
@@ -114,6 +111,7 @@ public class GalleryView extends GLView implements GestureRecognizer.Listener {
|
||||
|
||||
private boolean mEnableRequestFill = true;
|
||||
private boolean mRequestFill = false;
|
||||
private boolean mWillFill = false;
|
||||
|
||||
private boolean mScale = false;
|
||||
private boolean mScroll = false;
|
||||
@@ -247,40 +245,17 @@ public class GalleryView extends GLView implements GestureRecognizer.Listener {
|
||||
postMethod(METHOD_ON_ATTACH_TO_ROOT);
|
||||
}
|
||||
|
||||
private void onDetachFromRootInternal() {
|
||||
@Override
|
||||
public void onDetachFromRoot() {
|
||||
// When detached, render() will not be called. So do it here
|
||||
detachLayoutManager();
|
||||
if (null != mPageTextTexture) {
|
||||
mPageTextTexture.recycle();
|
||||
mPageTextTexture = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDetachFromRoot() {
|
||||
super.onDetachFromRoot();
|
||||
mEdgeView.onDetachFromRoot();
|
||||
postMethod(METHOD_ON_DETACH_FROM_ROOT);
|
||||
}
|
||||
|
||||
private void pauseInternal() {
|
||||
mPause = true;
|
||||
}
|
||||
|
||||
public void pause() {
|
||||
postMethod(METHOD_PAUSE);
|
||||
}
|
||||
|
||||
private void resumeInternal() {
|
||||
if (mPause) {
|
||||
mPause = false;
|
||||
if (null != mLayoutManager) {
|
||||
mLayoutManager.bindUnloadedPage();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void resume() {
|
||||
postMethod(METHOD_RESUME);
|
||||
}
|
||||
|
||||
@LayoutMode
|
||||
@@ -311,7 +286,9 @@ public class GalleryView extends GLView implements GestureRecognizer.Listener {
|
||||
public void requestFill() {
|
||||
if (mEnableRequestFill) {
|
||||
mRequestFill = true;
|
||||
invalidate();
|
||||
if (!mWillFill) {
|
||||
invalidate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -785,15 +762,6 @@ public class GalleryView extends GLView implements GestureRecognizer.Listener {
|
||||
case METHOD_ON_ATTACH_TO_ROOT:
|
||||
onAttachToRootInternal();
|
||||
break;
|
||||
case METHOD_ON_DETACH_FROM_ROOT:
|
||||
onDetachFromRootInternal();
|
||||
break;
|
||||
case METHOD_PAUSE:
|
||||
pauseInternal();
|
||||
break;
|
||||
case METHOD_RESUME:
|
||||
resumeInternal();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -803,6 +771,7 @@ public class GalleryView extends GLView implements GestureRecognizer.Listener {
|
||||
|
||||
@Override
|
||||
public void render(GLCanvas canvas) {
|
||||
mWillFill = true;
|
||||
int oldCurrentIndex = mCurrentIndex.get();
|
||||
|
||||
// Dispatch method
|
||||
@@ -814,6 +783,7 @@ public class GalleryView extends GLView implements GestureRecognizer.Listener {
|
||||
}
|
||||
|
||||
fill();
|
||||
mWillFill = false;
|
||||
|
||||
super.render(canvas);
|
||||
mEdgeView.render(canvas);
|
||||
@@ -975,8 +945,6 @@ public class GalleryView extends GLView implements GestureRecognizer.Listener {
|
||||
|
||||
public abstract void onDataChanged();
|
||||
|
||||
public abstract void bindUnloadedPage();
|
||||
|
||||
public abstract void onPageLeft();
|
||||
|
||||
public abstract void onPageRight();
|
||||
|
||||
@@ -208,6 +208,9 @@ public class ImageView extends GLView implements ImageTexture.Callback {
|
||||
mImageTexture.setCallback(null);
|
||||
}
|
||||
|
||||
int oldTextureWidth = mTextureWidth;
|
||||
int oldTextureHeight = mTextureHeight;
|
||||
|
||||
mImageTexture = imageTexture;
|
||||
|
||||
if (imageTexture != null) {
|
||||
@@ -222,8 +225,9 @@ public class ImageView extends GLView implements ImageTexture.Callback {
|
||||
mTextureHeight = 1;
|
||||
}
|
||||
|
||||
// Start alpha animation
|
||||
if (isAttachedToRoot()) {
|
||||
// Start alpha animation, do not show animation for image has no valid rect
|
||||
getValidRect(mValidRect);
|
||||
if (!mValidRect.isEmpty()) {
|
||||
startAnimation(mAlphaAnimation, true);
|
||||
}
|
||||
} else {
|
||||
@@ -233,6 +237,10 @@ public class ImageView extends GLView implements ImageTexture.Callback {
|
||||
|
||||
mScaleOffsetDirty = true;
|
||||
mPositionInRootDirty = true;
|
||||
|
||||
if (oldTextureWidth != mTextureWidth || oldTextureHeight != mTextureHeight) {
|
||||
requestLayout();
|
||||
}
|
||||
}
|
||||
|
||||
public ImageTexture getImageTexture() {
|
||||
|
||||
@@ -449,9 +449,8 @@ public class PagerLayoutManager extends GalleryView.LayoutManager {
|
||||
image.getScaleDefault(scales);
|
||||
float scale = image.getScale();
|
||||
float endScale = scales[0];
|
||||
for (int i = 0, size = scales.length; i < size; i++) {
|
||||
float value = scales[i];
|
||||
if (scale < value) {
|
||||
for (float value: scales) {
|
||||
if (scale < value - 0.01f) {
|
||||
endScale = value;
|
||||
break;
|
||||
}
|
||||
@@ -717,23 +716,6 @@ public class PagerLayoutManager extends GalleryView.LayoutManager {
|
||||
mGalleryView.requestFill();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bindUnloadedPage() {
|
||||
if (null == mAdapter) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (null != mCurrent && !mCurrent.getImageView().isLoaded()) {
|
||||
mAdapter.bind(mCurrent, mIndex);
|
||||
}
|
||||
if (null != mPrevious && !mPrevious.getImageView().isLoaded()) {
|
||||
mAdapter.bind(mPrevious, mIndex - 1);
|
||||
}
|
||||
if (null != mNext && !mNext.getImageView().isLoaded()) {
|
||||
mAdapter.bind(mNext, mIndex + 1);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageLeft() {
|
||||
int size = mAdapter.size();
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,116 @@
|
||||
/*
|
||||
* Copyright 2016 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.preference;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.util.AttributeSet;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.hippo.ehviewer.EhApplication;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.Settings;
|
||||
import com.hippo.ehviewer.download.DownloadManager;
|
||||
import com.hippo.unifile.UniFile;
|
||||
import com.hippo.yorozuya.NumberUtils;
|
||||
|
||||
public class CleanRedundancyPreference extends TaskPreference {
|
||||
|
||||
public CleanRedundancyPreference(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public CleanRedundancyPreference(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
public CleanRedundancyPreference(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
protected Task onCreateTask() {
|
||||
return new ClearTask(getContext());
|
||||
}
|
||||
|
||||
private static class ClearTask extends Task {
|
||||
|
||||
private final EhApplication mApplication;
|
||||
private final DownloadManager mManager;
|
||||
|
||||
public ClearTask(@NonNull Context context) {
|
||||
super(context);
|
||||
mApplication = (EhApplication) context.getApplicationContext();
|
||||
mManager = EhApplication.getDownloadManager(mApplication);
|
||||
}
|
||||
|
||||
// True for cleared
|
||||
private boolean clearFile(UniFile file) {
|
||||
String name = file.getName();
|
||||
int index = name.indexOf('-');
|
||||
if (index >= 0) {
|
||||
name = name.substring(0, index);
|
||||
}
|
||||
long gid = NumberUtils.parseLongSafely(name, -1L);
|
||||
if (-1L == gid) {
|
||||
return false;
|
||||
}
|
||||
if (mManager.containDownloadInfo(gid)) {
|
||||
return false;
|
||||
}
|
||||
file.delete();
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object doInBackground(Void... params) {
|
||||
UniFile dir = Settings.getDownloadLocation();
|
||||
if (null == dir) {
|
||||
return 0;
|
||||
}
|
||||
UniFile[] files = dir.listFiles();
|
||||
if (null == files) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int count = 0;
|
||||
for (UniFile f: files) {
|
||||
if (clearFile(f)) {
|
||||
++count;
|
||||
}
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Object o) {
|
||||
int count;
|
||||
if (o instanceof Integer) {
|
||||
count = (Integer) o;
|
||||
} else {
|
||||
count = 0;
|
||||
}
|
||||
|
||||
Toast.makeText(mApplication, 0 == count ?
|
||||
mApplication.getString(R.string.settings_download_clean_redundancy_no_redundancy):
|
||||
mApplication.getString(R.string.settings_download_clean_redundancy_done, count), Toast.LENGTH_SHORT).show();
|
||||
super.onPostExecute(o);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -42,12 +42,6 @@ public class ClearDownloadPathCachePreference extends MessagePreference {
|
||||
init(context);
|
||||
}
|
||||
|
||||
public ClearDownloadPathCachePreference(Context context,
|
||||
AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
||||
super(context, attrs, defStyleAttr, defStyleRes);
|
||||
init(context);
|
||||
}
|
||||
|
||||
public void init(Context context) {
|
||||
setDialogMessage(context.getString(R.string.settings_advanced_clear_download_path_cache_message));
|
||||
}
|
||||
|
||||
@@ -47,11 +47,6 @@ public class DefaultCategoryPreference extends DialogPreference {
|
||||
init();
|
||||
}
|
||||
|
||||
public DefaultCategoryPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
||||
super(context, attrs, defStyleAttr, defStyleRes);
|
||||
init();
|
||||
}
|
||||
|
||||
private void init() {
|
||||
setDialogLayoutResource(R.layout.preference_dialog_default_categories);
|
||||
}
|
||||
|
||||
@@ -69,11 +69,6 @@ public class ExcludedTagNamespacesPreference extends DialogPreference {
|
||||
init();
|
||||
}
|
||||
|
||||
public ExcludedTagNamespacesPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
||||
super(context, attrs, defStyleAttr, defStyleRes);
|
||||
init();
|
||||
}
|
||||
|
||||
private void init() {
|
||||
setDialogLayoutResource(R.layout.preference_dialog_excluded_tag_namespaces);
|
||||
}
|
||||
|
||||
@@ -66,11 +66,6 @@ public class HatHProxyPreference extends DialogPreference implements View.OnClic
|
||||
init();
|
||||
}
|
||||
|
||||
public HatHProxyPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
||||
super(context, attrs, defStyleAttr, defStyleRes);
|
||||
init();
|
||||
}
|
||||
|
||||
private void init() {
|
||||
setDialogLayoutResource(R.layout.preference_dialog_hath_proxy);
|
||||
updateSummary(Settings.getHathProxy(), Settings.getHathIp(), Settings.getHathPort());
|
||||
|
||||
@@ -0,0 +1,213 @@
|
||||
/*
|
||||
* Copyright 2016 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.preference;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.os.Parcel;
|
||||
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;
|
||||
import com.hippo.ehviewer.Settings;
|
||||
import com.hippo.ehviewer.client.EhEngine;
|
||||
import com.hippo.ehviewer.client.data.GalleryInfo;
|
||||
import com.hippo.ehviewer.download.DownloadManager;
|
||||
import com.hippo.ehviewer.spider.SpiderQueen;
|
||||
import com.hippo.unifile.UniFile;
|
||||
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 {
|
||||
|
||||
public RestoreDownloadPreference(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public RestoreDownloadPreference(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
public RestoreDownloadPreference(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
protected Task onCreateTask() {
|
||||
return new RestoreTask(getContext());
|
||||
}
|
||||
|
||||
private static class RestoreTask extends Task {
|
||||
|
||||
private final EhApplication mApplication;
|
||||
private final DownloadManager mManager;
|
||||
private final OkHttpClient mHttpClient;
|
||||
|
||||
public RestoreTask(@NonNull Context context) {
|
||||
super(context);
|
||||
mApplication = (EhApplication) context.getApplicationContext();
|
||||
mManager = EhApplication.getDownloadManager(mApplication);
|
||||
mHttpClient = EhApplication.getOkHttpClient(mApplication);
|
||||
}
|
||||
|
||||
private RestoreItem getRestoreItem(UniFile file) {
|
||||
if (null == file || !file.isDirectory()) {
|
||||
return null;
|
||||
}
|
||||
UniFile siFile = file.findFile(SpiderQueen.SPIDER_INFO_FILENAME);
|
||||
if (null == siFile) {
|
||||
return null;
|
||||
}
|
||||
|
||||
InputStream is = null;
|
||||
try {
|
||||
is = siFile.openInputStream();
|
||||
// Skip start page
|
||||
IOUtils.readAsciiLine(is);
|
||||
long gid = Long.parseLong(IOUtils.readAsciiLine(is));
|
||||
if (mManager.containDownloadInfo(gid)) {
|
||||
return null;
|
||||
}
|
||||
String token = IOUtils.readAsciiLine(is);
|
||||
RestoreItem restoreItem = new RestoreItem();
|
||||
restoreItem.gid = gid;
|
||||
restoreItem.token = token;
|
||||
restoreItem.dirname = file.getName();
|
||||
return restoreItem;
|
||||
} catch (IOException e) {
|
||||
return null;
|
||||
} finally {
|
||||
IOUtils.closeQuietly(is);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object doInBackground(Void... params) {
|
||||
UniFile dir = Settings.getDownloadLocation();
|
||||
if (null == dir) {
|
||||
return null;
|
||||
}
|
||||
|
||||
List<RestoreItem> restoreItemList = new ArrayList<>();
|
||||
|
||||
UniFile[] files = dir.listFiles();
|
||||
for (UniFile file: files) {
|
||||
RestoreItem restoreItem = getRestoreItem(file);
|
||||
if (null != restoreItem) {
|
||||
restoreItemList.add(restoreItem);
|
||||
}
|
||||
}
|
||||
|
||||
if (0 == restoreItemList.size()) {
|
||||
return Collections.EMPTY_LIST;
|
||||
}
|
||||
|
||||
try {
|
||||
return EhEngine.fillGalleryListByApi(null, mHttpClient, new ArrayList<GalleryInfo>(restoreItemList));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
protected void onPostExecute(Object o) {
|
||||
if (!(o instanceof List)) {
|
||||
Toast.makeText(mApplication, R.string.settings_download_restore_failed, Toast.LENGTH_SHORT).show();
|
||||
} else {
|
||||
List<RestoreItem> list = (List<RestoreItem>) o;
|
||||
if (list.isEmpty()) {
|
||||
Toast.makeText(mApplication, R.string.settings_download_restore_not_found, Toast.LENGTH_SHORT).show();
|
||||
} else {
|
||||
int count = 0;
|
||||
for (int i = 0, n = list.size(); i < n; i++) {
|
||||
RestoreItem item = list.get(i);
|
||||
// Avoid failed gallery info
|
||||
if (null != item.title) {
|
||||
// Put to download
|
||||
mManager.addDownload(item, null);
|
||||
// Put download dir to DB
|
||||
EhDB.putDownloadDirname(item.gid, item.dirname);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
Toast.makeText(mApplication,
|
||||
mApplication.getString(R.string.settings_download_restore_successfully, count),
|
||||
Toast.LENGTH_SHORT).show();
|
||||
|
||||
Preference preference = getPreference();
|
||||
if (null != preference) {
|
||||
Context context = preference.getContext();
|
||||
if (context instanceof Activity) {
|
||||
((Activity) context).setResult(Activity.RESULT_OK);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
super.onPostExecute(o);
|
||||
}
|
||||
}
|
||||
|
||||
private static class RestoreItem extends GalleryInfo {
|
||||
|
||||
public String dirname;
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
super.writeToParcel(dest, flags);
|
||||
dest.writeString(this.dirname);
|
||||
}
|
||||
|
||||
public RestoreItem() {
|
||||
}
|
||||
|
||||
protected RestoreItem(Parcel in) {
|
||||
super(in);
|
||||
this.dirname = in.readString();
|
||||
}
|
||||
|
||||
public static final Creator<RestoreItem> CREATOR = new Creator<RestoreItem>() {
|
||||
@Override
|
||||
public RestoreItem createFromParcel(Parcel source) {
|
||||
return new RestoreItem(source);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RestoreItem[] newArray(int size) {
|
||||
return new RestoreItem[size];
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -42,11 +42,6 @@ public class SignOutPreference extends MessagePreference {
|
||||
init();
|
||||
}
|
||||
|
||||
public SignOutPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
||||
super(context, attrs, defStyleAttr, defStyleRes);
|
||||
init();
|
||||
}
|
||||
|
||||
private void init() {
|
||||
setDialogMessage(getContext().getString(R.string.settings_eh_sign_out_warning));
|
||||
}
|
||||
|
||||
@@ -0,0 +1,186 @@
|
||||
/*
|
||||
* Copyright 2016 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.preference;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.support.annotation.CallSuper;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.util.AttributeSet;
|
||||
|
||||
import com.hippo.ehviewer.EhApplication;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.preference.DialogPreference;
|
||||
import com.hippo.yorozuya.IntIdGenerator;
|
||||
|
||||
public abstract class TaskPreference extends DialogPreference {
|
||||
|
||||
private Task mTask;
|
||||
private int mTaskId = IntIdGenerator.INVALID_ID;
|
||||
|
||||
public TaskPreference(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public TaskPreference(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
public TaskPreference(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPrepareDialogBuilder(AlertDialog.Builder builder) {
|
||||
builder.setTitle(null);
|
||||
builder.setView(R.layout.preference_dialog_task);
|
||||
builder.setCancelable(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDialogCreated(AlertDialog dialog) {
|
||||
if (null == mTask) {
|
||||
mTask = onCreateTask();
|
||||
mTask.setPreference(this);
|
||||
mTaskId = ((EhApplication) getContext().getApplicationContext()).putGlobalStuff(mTask);
|
||||
mTask.execute();
|
||||
}
|
||||
}
|
||||
|
||||
protected void onTaskEnd() {
|
||||
// Dismiss dialog
|
||||
Dialog dialog = getDialog();
|
||||
if (null != dialog) {
|
||||
dialog.dismiss();
|
||||
}
|
||||
// Clear async
|
||||
mTask = null;
|
||||
mTaskId = IntIdGenerator.INVALID_ID;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
protected abstract Task onCreateTask();
|
||||
|
||||
@Override
|
||||
public void onActivityDestroy() {
|
||||
super.onActivityDestroy();
|
||||
|
||||
if (null != mTask) {
|
||||
mTask.setPreference(null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Parcelable onSaveInstanceState() {
|
||||
final Parcelable superState = super.onSaveInstanceState();
|
||||
final SavedState myState = new SavedState(superState);
|
||||
myState.asyncTaskId = mTaskId;
|
||||
return myState;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onRestoreInstanceState(Parcelable state) {
|
||||
if (state == null || !state.getClass().equals(SavedState.class)) {
|
||||
// Didn't save state for us in onSaveInstanceState
|
||||
super.onRestoreInstanceState(state);
|
||||
return;
|
||||
}
|
||||
|
||||
SavedState myState = (SavedState) state;
|
||||
mTaskId = myState.asyncTaskId;
|
||||
if (IntIdGenerator.INVALID_ID != mTaskId) {
|
||||
Object o = ((EhApplication) getContext().getApplicationContext()).getGlobalStuff(mTaskId);
|
||||
if (o instanceof Task) {
|
||||
mTask = (Task) o;
|
||||
mTask.setPreference(this);
|
||||
}
|
||||
}
|
||||
if (null == mTask) {
|
||||
mTaskId = IntIdGenerator.INVALID_ID;
|
||||
}
|
||||
|
||||
// TODO if not task, show not reopen dialog
|
||||
|
||||
super.onRestoreInstanceState(myState.getSuperState());
|
||||
}
|
||||
|
||||
private static class SavedState extends BaseSavedState {
|
||||
int asyncTaskId;
|
||||
|
||||
public SavedState(Parcel source) {
|
||||
super(source);
|
||||
asyncTaskId = source.readInt();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
super.writeToParcel(dest, flags);
|
||||
dest.writeInt(asyncTaskId);
|
||||
}
|
||||
|
||||
public SavedState(Parcelable superState) {
|
||||
super(superState);
|
||||
}
|
||||
|
||||
public static final Parcelable.Creator<SavedState> CREATOR =
|
||||
new Parcelable.Creator<SavedState>() {
|
||||
@Override
|
||||
public SavedState createFromParcel(Parcel in) {
|
||||
return new SavedState(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SavedState[] newArray(int size) {
|
||||
return new SavedState[size];
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public abstract static class Task extends AsyncTask<Void, Void, Object> {
|
||||
|
||||
private final EhApplication mApplication;
|
||||
@Nullable
|
||||
private TaskPreference mPreference;
|
||||
|
||||
public Task(@NonNull Context context) {
|
||||
mApplication = (EhApplication) context.getApplicationContext();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public TaskPreference getPreference() {
|
||||
return mPreference;
|
||||
}
|
||||
|
||||
public void setPreference(@Nullable TaskPreference preference) {
|
||||
mPreference = preference;
|
||||
}
|
||||
|
||||
@CallSuper
|
||||
@Override
|
||||
protected void onPostExecute(Object o) {
|
||||
mApplication.removeGlobalStuff(this);
|
||||
if (null != mPreference) {
|
||||
mPreference.onTaskEnd();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -34,6 +34,7 @@ import com.hippo.unifile.FilenameFilter;
|
||||
import com.hippo.unifile.UniFile;
|
||||
import com.hippo.yorozuya.FileUtils;
|
||||
import com.hippo.yorozuya.IOUtils;
|
||||
import com.hippo.yorozuya.MathUtils;
|
||||
import com.hippo.yorozuya.Utilities;
|
||||
import com.hippo.yorozuya.io.InputStreamPipe;
|
||||
import com.hippo.yorozuya.io.OutputStreamPipe;
|
||||
@@ -54,7 +55,8 @@ public final class SpiderDen {
|
||||
private static SimpleDiskCache sCache;
|
||||
|
||||
public static void initialize(Context context) {
|
||||
sCache = new SimpleDiskCache(new File(context.getCacheDir(), "image"), 160 * 1024 * 1024);
|
||||
sCache = new SimpleDiskCache(new File(context.getCacheDir(), "image"),
|
||||
MathUtils.clamp(Settings.getReadCacheSize(), 40, 640) * 1024 * 1024);
|
||||
}
|
||||
|
||||
private static class StartWithFilenameFilter implements FilenameFilter {
|
||||
@@ -76,6 +78,11 @@ public final class SpiderDen {
|
||||
if (dir != null) {
|
||||
// Read from DB
|
||||
String dirname = EhDB.getDownloadDirname(galleryInfo.gid);
|
||||
if (null != dirname) {
|
||||
// Some dirname may be invalid in some version
|
||||
dirname = FileUtils.sanitizeFilename(dirname);
|
||||
EhDB.putDownloadDirname(galleryInfo.gid, dirname);
|
||||
}
|
||||
|
||||
// Find it
|
||||
if (null == dirname) {
|
||||
@@ -128,6 +135,17 @@ public final class SpiderDen {
|
||||
return mDownloadDir != null && mDownloadDir.ensureDir();
|
||||
}
|
||||
|
||||
public boolean isReady() {
|
||||
switch (mMode) {
|
||||
case SpiderQueen.MODE_READ:
|
||||
return sCache != null;
|
||||
case SpiderQueen.MODE_DOWNLOAD:
|
||||
return mDownloadDir != null && mDownloadDir.isDirectory();
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public UniFile getDownloadDir() {
|
||||
return mDownloadDir != null && mDownloadDir.isDirectory() ? mDownloadDir : null;
|
||||
|
||||
@@ -18,6 +18,7 @@ package com.hippo.ehviewer.spider;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.util.SparseArray;
|
||||
|
||||
@@ -102,6 +103,10 @@ public class SpiderInfo {
|
||||
spiderInfo.previewPerPage = Integer.parseInt(IOUtils.readAsciiLine(is));
|
||||
// Pages
|
||||
spiderInfo.pages = Integer.parseInt(IOUtils.readAsciiLine(is));
|
||||
// Check pages
|
||||
if (spiderInfo.pages <= 0) {
|
||||
return null;
|
||||
}
|
||||
// PToken
|
||||
spiderInfo.pTokenMap = new SparseArray<>(spiderInfo.pages);
|
||||
while (true) { // EOFException will raise
|
||||
@@ -110,7 +115,9 @@ public class SpiderInfo {
|
||||
if (pos > 0 || pos < line.length() - 1) {
|
||||
int index = Integer.parseInt(line.substring(0, pos));
|
||||
String pToken = line.substring(pos + 1);
|
||||
spiderInfo.pTokenMap.put(index, pToken);
|
||||
if (!TextUtils.isEmpty(pToken)) {
|
||||
spiderInfo.pTokenMap.put(index, pToken);
|
||||
}
|
||||
} else {
|
||||
Log.e(TAG, "Can't parse index and pToken, index = " + pos);
|
||||
}
|
||||
@@ -147,12 +154,14 @@ public class SpiderInfo {
|
||||
writer.write(Integer.toString(pages));
|
||||
writer.write("\n");
|
||||
for (int i = 0; i < pTokenMap.size(); i++) {
|
||||
if (TOKEN_FAILED.equals(pTokenMap.valueAt(i))) {
|
||||
Integer key = pTokenMap.keyAt(i);
|
||||
String value = pTokenMap.valueAt(i);
|
||||
if (TOKEN_FAILED.equals(value) || TextUtils.isEmpty(value)) {
|
||||
continue;
|
||||
}
|
||||
writer.write(Integer.toString(pTokenMap.keyAt(i)));
|
||||
writer.write(Integer.toString(key));
|
||||
writer.write(" ");
|
||||
writer.write(pTokenMap.valueAt(i));
|
||||
writer.write(value);
|
||||
writer.write("\n");
|
||||
}
|
||||
writer.flush();
|
||||
|
||||
@@ -35,6 +35,7 @@ import com.hippo.ehviewer.GetText;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.Settings;
|
||||
import com.hippo.ehviewer.client.EhConfig;
|
||||
import com.hippo.ehviewer.client.EhEngine;
|
||||
import com.hippo.ehviewer.client.EhRequestBuilder;
|
||||
import com.hippo.ehviewer.client.EhUrl;
|
||||
import com.hippo.ehviewer.client.data.GalleryInfo;
|
||||
@@ -48,7 +49,9 @@ import com.hippo.ehviewer.gallery.GalleryProvider;
|
||||
import com.hippo.ehviewer.gallery.gl.GalleryPageView;
|
||||
import com.hippo.image.Image;
|
||||
import com.hippo.unifile.UniFile;
|
||||
import com.hippo.util.ExceptionUtils;
|
||||
import com.hippo.yorozuya.IOUtils;
|
||||
import com.hippo.yorozuya.MathUtils;
|
||||
import com.hippo.yorozuya.OSUtils;
|
||||
import com.hippo.yorozuya.PriorityThread;
|
||||
import com.hippo.yorozuya.PriorityThreadFactory;
|
||||
@@ -63,7 +66,6 @@ import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.net.MalformedURLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
@@ -71,7 +73,9 @@ import java.util.Queue;
|
||||
import java.util.Stack;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
import java.util.concurrent.ThreadFactory;
|
||||
import java.util.concurrent.LinkedBlockingDeque;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import okhttp3.Call;
|
||||
@@ -129,16 +133,15 @@ public class SpiderQueen implements Runnable {
|
||||
@Nullable
|
||||
private volatile Thread mQueenThread;
|
||||
private final Object mQueenLock = new Object();
|
||||
private final ThreadFactory mThreadFactory = new PriorityThreadFactory(
|
||||
SpiderWorker.class.getSimpleName(), Process.THREAD_PRIORITY_BACKGROUND);
|
||||
|
||||
@Nullable
|
||||
private Thread mDecoderThread;
|
||||
private final Stack<Integer> mDecodeRequestStack = new Stack<>();
|
||||
private final AtomicInteger mDecodingIndex = new AtomicInteger(GalleryPageView.INVALID_INDEX);
|
||||
|
||||
private volatile Thread[] mWorkers;
|
||||
private final Object mWorkerLock = new Object();
|
||||
private ThreadPoolExecutor mWorkerPoolExecutor;
|
||||
private int mWorkerCount;
|
||||
|
||||
private final Object mPTokenLock = new Object();
|
||||
private volatile SpiderInfo mSpiderInfo;
|
||||
@@ -166,7 +169,7 @@ public class SpiderQueen implements Runnable {
|
||||
|
||||
private final List<OnSpiderListener> mSpiderListeners = new ArrayList<>();
|
||||
|
||||
private final int mSpiderWorkerNumber;
|
||||
private final int mWorkerMaxCount;
|
||||
private final int mPreloadNumber;
|
||||
|
||||
private SpiderQueen(EhApplication application, @NonNull GalleryInfo galleryInfo) {
|
||||
@@ -175,8 +178,12 @@ public class SpiderQueen implements Runnable {
|
||||
mGalleryInfo = galleryInfo;
|
||||
mSpiderDen = new SpiderDen(mGalleryInfo);
|
||||
|
||||
mSpiderWorkerNumber = Settings.getMultiThreadDownload();
|
||||
mPreloadNumber = Settings.getPreloadImage();
|
||||
mWorkerMaxCount = MathUtils.clamp(Settings.getMultiThreadDownload(), 1, 10);
|
||||
mPreloadNumber = MathUtils.clamp(Settings.getPreloadImage(), 0, 100);
|
||||
|
||||
mWorkerPoolExecutor = new ThreadPoolExecutor(mWorkerMaxCount, mWorkerMaxCount,
|
||||
0, TimeUnit.SECONDS, new LinkedBlockingDeque<Runnable>(),
|
||||
new PriorityThreadFactory(SpiderWorker.class.getSimpleName(), Process.THREAD_PRIORITY_BACKGROUND));
|
||||
}
|
||||
|
||||
public void addOnSpiderListener(OnSpiderListener listener) {
|
||||
@@ -415,11 +422,11 @@ public class SpiderQueen implements Runnable {
|
||||
}
|
||||
|
||||
public Object forceRequest(int index) {
|
||||
return request(index, true);
|
||||
return request(index, true, false);
|
||||
}
|
||||
|
||||
public Object request(int index) {
|
||||
return request(index, false);
|
||||
return request(index, false, true);
|
||||
}
|
||||
|
||||
private int getPageState(int index) {
|
||||
@@ -465,7 +472,7 @@ public class SpiderQueen implements Runnable {
|
||||
* Float for download percent<br>
|
||||
* null for wait
|
||||
*/
|
||||
private Object request(int index, boolean force) {
|
||||
private Object request(int index, boolean force, boolean addNeighbor) {
|
||||
if (mQueenThread == null) {
|
||||
return null;
|
||||
}
|
||||
@@ -488,8 +495,8 @@ public class SpiderQueen implements Runnable {
|
||||
}
|
||||
}
|
||||
|
||||
// For not force add, add next some pages to request queue
|
||||
if (!force) {
|
||||
// Add next some pages to request queue
|
||||
if (addNeighbor) {
|
||||
mRequestPageQueue2.clear();
|
||||
int[] pageStateArray = mPageStateArray;
|
||||
int size;
|
||||
@@ -541,17 +548,13 @@ public class SpiderQueen implements Runnable {
|
||||
|
||||
private void ensureWorkers() {
|
||||
synchronized (mWorkerLock) {
|
||||
if (mWorkers == null) {
|
||||
mWorkers = new Thread[mSpiderWorkerNumber];
|
||||
if (null == mWorkerPoolExecutor) {
|
||||
Log.e(TAG, "Try to start worker after stopped");
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0, n = mWorkers.length; i < n; i++) {
|
||||
if (mWorkers[i] == null) {
|
||||
SpiderWorker worker = new SpiderWorker(i);
|
||||
Thread thread = mThreadFactory.newThread(worker);
|
||||
mWorkers[i] = thread;
|
||||
thread.start();
|
||||
}
|
||||
for (; mWorkerCount < mWorkerMaxCount; mWorkerCount++) {
|
||||
mWorkerPoolExecutor.execute(new SpiderWorker());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -687,7 +690,9 @@ public class SpiderQueen implements Runnable {
|
||||
for (int i = 0, n = previewSet.size(); i < n; i++) {
|
||||
GalleryPageUrlParser.Result result = GalleryPageUrlParser.parse(previewSet.getPageUrlAt(i));
|
||||
if (result != null) {
|
||||
spiderInfo.pTokenMap.put(result.page, result.pToken);
|
||||
synchronized (mPTokenLock) {
|
||||
spiderInfo.pTokenMap.put(result.page, result.pToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -732,7 +737,11 @@ public class SpiderQueen implements Runnable {
|
||||
// Save to local
|
||||
writeSpiderInfoToLocal(mSpiderInfo);
|
||||
|
||||
return mSpiderInfo.pTokenMap.get(index);
|
||||
String pToken;
|
||||
synchronized (mPTokenLock) {
|
||||
pToken = mSpiderInfo.pTokenMap.get(index);
|
||||
}
|
||||
return pToken;
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
@@ -887,18 +896,9 @@ public class SpiderQueen implements Runnable {
|
||||
|
||||
// Interrupt all workers
|
||||
synchronized (mWorkerLock) {
|
||||
if (mWorkers != null) {
|
||||
for (int i = 0, n = mWorkers.length; i < n; i++) {
|
||||
Thread thread = mWorkers[i];
|
||||
if (thread != null) {
|
||||
thread.interrupt();
|
||||
mWorkers[i] = null;
|
||||
}
|
||||
}
|
||||
mWorkers = null;
|
||||
}
|
||||
mWorkerPoolExecutor.shutdownNow();
|
||||
mWorkerPoolExecutor = null;
|
||||
}
|
||||
|
||||
notifyFinish();
|
||||
|
||||
if (DEBUG_LOG) {
|
||||
@@ -906,77 +906,71 @@ public class SpiderQueen implements Runnable {
|
||||
}
|
||||
}
|
||||
|
||||
private void updatePageState(int index, @State int state) {
|
||||
updatePageState(index, state, null);
|
||||
}
|
||||
|
||||
private boolean isStateDone(int state) {
|
||||
return state == STATE_FINISHED || state == STATE_FAILED;
|
||||
}
|
||||
|
||||
private void updatePageState(int index, @State int state, String error) {
|
||||
int oldState;
|
||||
synchronized (mPageStateLock) {
|
||||
oldState = mPageStateArray[index];
|
||||
mPageStateArray[index] = state;
|
||||
|
||||
if (!isStateDone(oldState) && isStateDone(state)) {
|
||||
mDownloadedPages.incrementAndGet();
|
||||
} else if (isStateDone(oldState) && !isStateDone(state)) {
|
||||
mDownloadedPages.decrementAndGet();
|
||||
}
|
||||
if (oldState != STATE_FINISHED && state == STATE_FINISHED) {
|
||||
mFinishedPages.incrementAndGet();
|
||||
} else if (oldState == STATE_FINISHED && state != STATE_FINISHED) {
|
||||
mFinishedPages.decrementAndGet();
|
||||
}
|
||||
|
||||
// Clear
|
||||
if (state == STATE_DOWNLOADING) {
|
||||
mPageErrorMap.remove(index);
|
||||
} else if (state == STATE_FINISHED || state == STATE_FAILED) {
|
||||
mPagePercentMap.remove(index);
|
||||
}
|
||||
|
||||
// Get default error
|
||||
if (state == STATE_FAILED) {
|
||||
if (error == null) {
|
||||
error = GetText.getString(R.string.error_unknown);
|
||||
}
|
||||
mPageErrorMap.put(index, error);
|
||||
}
|
||||
}
|
||||
|
||||
// Notify listeners
|
||||
if (state == STATE_FAILED) {
|
||||
notifyPageFailure(index, error);
|
||||
} else if (state == STATE_FINISHED) {
|
||||
notifyPageSuccess(index);
|
||||
}
|
||||
}
|
||||
|
||||
private class SpiderWorker implements Runnable {
|
||||
|
||||
private final int mWorkerIndex;
|
||||
private final long mGid;
|
||||
|
||||
public SpiderWorker(int workerIndex) {
|
||||
mWorkerIndex = workerIndex;
|
||||
public SpiderWorker() {
|
||||
mGid = mGalleryInfo.gid;
|
||||
}
|
||||
|
||||
private void updatePageState(int index, @State int state) {
|
||||
updatePageState(index, state, null);
|
||||
}
|
||||
|
||||
private boolean isStateDone(int state) {
|
||||
return state == STATE_FINISHED || state == STATE_FAILED;
|
||||
}
|
||||
|
||||
private void updatePageState(int index, @State int state, String error) {
|
||||
int oldState;
|
||||
synchronized (mPageStateLock) {
|
||||
oldState = mPageStateArray[index];
|
||||
mPageStateArray[index] = state;
|
||||
|
||||
if (!isStateDone(oldState) && isStateDone(state)) {
|
||||
mDownloadedPages.incrementAndGet();
|
||||
} else if (isStateDone(oldState) && !isStateDone(state)) {
|
||||
mDownloadedPages.decrementAndGet();
|
||||
}
|
||||
if (oldState != STATE_FINISHED && state == STATE_FINISHED) {
|
||||
mFinishedPages.incrementAndGet();
|
||||
} else if (oldState == STATE_FINISHED && state != STATE_FINISHED) {
|
||||
mFinishedPages.decrementAndGet();
|
||||
}
|
||||
|
||||
// Clear
|
||||
if (state == STATE_DOWNLOADING) {
|
||||
mPageErrorMap.remove(index);
|
||||
} else if (state == STATE_FINISHED || state == STATE_FAILED) {
|
||||
mPagePercentMap.remove(index);
|
||||
}
|
||||
|
||||
// Get default error
|
||||
if (state == STATE_FAILED) {
|
||||
if (error == null) {
|
||||
error = GetText.getString(R.string.error_unknown);
|
||||
}
|
||||
mPageErrorMap.put(index, error);
|
||||
}
|
||||
}
|
||||
|
||||
// Notify listeners
|
||||
if (state == STATE_FAILED) {
|
||||
notifyPageFailure(index, error);
|
||||
} else if (state == STATE_FINISHED) {
|
||||
notifyPageSuccess(index);
|
||||
}
|
||||
}
|
||||
|
||||
private GalleryPageParser.Result getImageUrl(long gid, int index, String pToken,
|
||||
String skipHathKey) throws IOException, ParseException, Image509Exception {
|
||||
String skipHathKey) throws Exception {
|
||||
String url = EhUrl.getPageUrl(gid, index, pToken);
|
||||
if (skipHathKey != null) {
|
||||
url = url + "?nl=" + skipHathKey;
|
||||
}
|
||||
if (DEBUG_LOG) {
|
||||
Log.d(TAG, url);
|
||||
}
|
||||
Response response = mHttpClient.newCall(new EhRequestBuilder(url).build()).execute();
|
||||
String body = response.body().string();
|
||||
GalleryPageParser.Result result = GalleryPageParser.parse(body);
|
||||
|
||||
GalleryPageParser.Result result = EhEngine.getGalleryPage(null, mHttpClient, url);
|
||||
if (StringUtils.endsWith(result.imageUrl, URL_509_SUFFIX_ARRAY)) {
|
||||
// Get 509
|
||||
// Notify listeners
|
||||
@@ -996,17 +990,18 @@ public class SpiderQueen implements Runnable {
|
||||
|
||||
// Try twice
|
||||
for (int i = 0; i < 2; i++) {
|
||||
if (i > 0 && TextUtils.isEmpty(skipHathKey)) {
|
||||
// No need to get image url twice without skip hath key
|
||||
break;
|
||||
}
|
||||
|
||||
GalleryPageParser.Result result = null;
|
||||
try {
|
||||
result = getImageUrl(gid, index, pToken, skipHathKey);
|
||||
} catch (MalformedURLException e) {
|
||||
error = GetText.getString(R.string.error_invalid_url);
|
||||
} catch (IOException e) {
|
||||
error = GetText.getString(R.string.error_socket);
|
||||
} catch (ParseException e) {
|
||||
error = GetText.getString(R.string.error_parse_error);
|
||||
} catch (Image509Exception e) {
|
||||
error = GetText.getString(R.string.error_509);
|
||||
} catch (Exception e) {
|
||||
error = ExceptionUtils.getReadableString(e);
|
||||
}
|
||||
if (result == null) {
|
||||
// Get image url failed
|
||||
@@ -1046,7 +1041,7 @@ public class SpiderQueen implements Runnable {
|
||||
Response response = call.execute();
|
||||
if (response.code() >= 400) {
|
||||
// Maybe 404
|
||||
call.cancel();
|
||||
response.body().close();
|
||||
continue;
|
||||
}
|
||||
ResponseBody responseBody = response.body();
|
||||
@@ -1064,7 +1059,7 @@ public class SpiderQueen implements Runnable {
|
||||
if (null == pipe) {
|
||||
// Can't get pipe
|
||||
error = GetText.getString(R.string.error_write_failed);
|
||||
call.cancel();
|
||||
response.body().close();
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1079,7 +1074,7 @@ public class SpiderQueen implements Runnable {
|
||||
while (!Thread.currentThread().isInterrupted()) {
|
||||
int bytesRead = is.read(data);
|
||||
if (bytesRead == -1) {
|
||||
call.cancel();
|
||||
response.body().close();
|
||||
break;
|
||||
}
|
||||
os.write(data, 0, bytesRead);
|
||||
@@ -1182,7 +1177,7 @@ public class SpiderQueen implements Runnable {
|
||||
int i = mSpiderInfo.pTokenMap.indexOfKey(index);
|
||||
String pToken = mSpiderInfo.pTokenMap.valueAt(i);
|
||||
if (SpiderInfo.TOKEN_FAILED.equals(pToken)) {
|
||||
mSpiderInfo.pTokenMap.setValueAt(i, null);
|
||||
mSpiderInfo.pTokenMap.remove(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1240,27 +1235,17 @@ public class SpiderQueen implements Runnable {
|
||||
Log.i(TAG, Thread.currentThread().getName() + ": start");
|
||||
}
|
||||
|
||||
while (!Thread.currentThread().isInterrupted() && runInternal());
|
||||
while (mSpiderDen.isReady() && !Thread.currentThread().isInterrupted() && runInternal());
|
||||
|
||||
|
||||
boolean finish = true;
|
||||
boolean finish;
|
||||
// Clear in spider worker array
|
||||
synchronized (mWorkerLock) {
|
||||
if (mWorkers != null && mWorkerIndex < mWorkers.length &&
|
||||
mWorkers[mWorkerIndex] == Thread.currentThread()) {
|
||||
mWorkers[mWorkerIndex] = null;
|
||||
}
|
||||
if (mWorkers != null) {
|
||||
for (Thread mWorker : mWorkers) {
|
||||
if (null != mWorker) {
|
||||
finish = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (finish) {
|
||||
mWorkers = null;
|
||||
mWorkerCount--;
|
||||
if (mWorkerCount < 0) {
|
||||
Log.e(TAG, "WTF, mWorkerCount < 0, not thread safe or something wrong");
|
||||
mWorkerCount = 0;
|
||||
}
|
||||
finish = mWorkerCount <= 0;
|
||||
}
|
||||
|
||||
if (finish) {
|
||||
@@ -1307,7 +1292,10 @@ public class SpiderQueen implements Runnable {
|
||||
InputStreamPipe pipe = mSpiderDen.openInputStreamPipe(index);
|
||||
if (pipe == null) {
|
||||
mDecodingIndex.lazySet(GalleryPageView.INVALID_INDEX);
|
||||
notifyGetImageFailure(index, GetText.getString(R.string.error_not_found));
|
||||
// Can't find the file, it might be removed from cache,
|
||||
// Reset it state and request it
|
||||
updatePageState(index, STATE_NONE, null);
|
||||
request(index, false, false);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
@@ -117,7 +117,7 @@ public final class CommonOperations {
|
||||
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
UrlOpener.openUrl(mActivity, url, false, false);
|
||||
UrlOpener.openUrl(mActivity, url, false);
|
||||
}
|
||||
}).show();
|
||||
}
|
||||
@@ -309,4 +309,15 @@ public final class CommonOperations {
|
||||
IOUtils.closeQuietly(is);
|
||||
}
|
||||
}
|
||||
|
||||
public static void removeNoMediaFile(UniFile file) {
|
||||
if (null == file) {
|
||||
return;
|
||||
}
|
||||
|
||||
UniFile noMedia = file.subFile(".nomedia");
|
||||
if (null != noMedia && noMedia.isFile()) {
|
||||
noMedia.delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
/*
|
||||
* Copyright 2016 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.ui;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.hippo.easyrecyclerview.EasyRecyclerView;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.view.ViewTransition;
|
||||
import com.hippo.yorozuya.ViewUtils;
|
||||
|
||||
public class DictActivity extends ToolbarActivity {
|
||||
|
||||
private static final int REQUEST_CODE_SELECT_DICT_FILE = 0;
|
||||
|
||||
@Nullable
|
||||
private EasyRecyclerView mRecyclerView;
|
||||
@Nullable
|
||||
private ViewTransition mViewTransition;
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_dict);
|
||||
setNavigationIcon(R.drawable.v_arrow_left_dark_x24);
|
||||
|
||||
mRecyclerView = (EasyRecyclerView) ViewUtils.$$(this, R.id.recycler_view);
|
||||
TextView tip = (TextView) ViewUtils.$$(this, R.id.tip);
|
||||
mViewTransition = new ViewTransition(mRecyclerView, tip);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
|
||||
mRecyclerView = null;
|
||||
mViewTransition = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
super.onCreateOptionsMenu(menu);
|
||||
getMenuInflater().inflate(R.menu.activity_dict, menu);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case android.R.id.home:
|
||||
finish();
|
||||
return true;
|
||||
case R.id.action_import:
|
||||
Intent intent = new Intent();
|
||||
intent.setType("application/octet-stream");
|
||||
intent.setAction(Intent.ACTION_GET_CONTENT);
|
||||
startActivityForResult(Intent.createChooser(intent,
|
||||
getString(R.string.select_dict_file)), REQUEST_CODE_SELECT_DICT_FILE);
|
||||
return true;
|
||||
default:
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
if (REQUEST_CODE_SELECT_DICT_FILE == requestCode) {
|
||||
if (Activity.RESULT_OK != resultCode) {
|
||||
return;
|
||||
}
|
||||
Uri uri = data.getData();
|
||||
if (null == uri) {
|
||||
return;
|
||||
}
|
||||
Intent intent = new Intent(this, DictImportActivity.class);
|
||||
intent.setAction(Intent.ACTION_VIEW);
|
||||
intent.setData(uri);
|
||||
startActivity(intent);
|
||||
} else {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,213 @@
|
||||
package com.hippo.ehviewer.ui;
|
||||
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.ServiceConnection;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.IBinder;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.hippo.dict.DictImportService;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.util.TextUrl;
|
||||
|
||||
public class DictImportActivity extends EhActivity {
|
||||
|
||||
private final static String TAG = "DictImportActivity";
|
||||
private static final boolean DEBUG = false;
|
||||
|
||||
private DictImportService serviceBinder;
|
||||
private int mItemNum = 0;
|
||||
|
||||
private Button mConfirmBtn;
|
||||
private Button mCancelBtn;
|
||||
private Button mHideBtn;
|
||||
|
||||
private ProgressBar mProgressBar;
|
||||
private TextView mProgressTipView;
|
||||
private TextView mTipView;
|
||||
private Uri mDictUri;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
setContentView(R.layout.activity_dict_improt);
|
||||
|
||||
Intent intent = new Intent(DictImportActivity.this, DictImportService.class);
|
||||
if (DEBUG) {
|
||||
Log.d(TAG, "[onCreate] bind service");
|
||||
}
|
||||
bindService(intent, conn, Context.BIND_AUTO_CREATE);
|
||||
startService(intent);
|
||||
|
||||
|
||||
mConfirmBtn = (Button) findViewById(R.id.btn_confirm);
|
||||
mCancelBtn = (Button) findViewById(R.id.btn_cancel);
|
||||
mHideBtn = (Button) findViewById(R.id.btn_hide);
|
||||
|
||||
mProgressBar = (ProgressBar) findViewById(R.id.bar_import);
|
||||
mProgressTipView = (TextView) findViewById(R.id.tv_progress);
|
||||
mTipView = (TextView) findViewById(R.id.tv_tip);
|
||||
|
||||
mConfirmBtn.setOnClickListener(confirmListener);
|
||||
mCancelBtn.setOnClickListener(cancelListener);
|
||||
mHideBtn.setOnClickListener(hideListener);
|
||||
}
|
||||
|
||||
private final ServiceConnection conn = new ServiceConnection() {
|
||||
@Override
|
||||
public void onServiceDisconnected(ComponentName name) {
|
||||
if (DEBUG) {
|
||||
Log.w(TAG, "[onServiceConnected] disconnect to service");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onServiceConnected(ComponentName name, IBinder service) {
|
||||
serviceBinder = ((DictImportService.DictImportServiceBinder) service).getService();
|
||||
serviceBinder.setOnProgressListener(importListener);
|
||||
|
||||
// if we are doing a task,we load improt infomation from service
|
||||
// and ignore the newer import task
|
||||
if (serviceBinder.isRunning()) {
|
||||
initFromService();
|
||||
} else {
|
||||
initFromIntent();
|
||||
}
|
||||
|
||||
if (DEBUG) {
|
||||
Log.d(TAG, "[onServiceConnected] connect to service");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private final DictImportService.ProcessListener importListener = new DictImportService.ProcessListener() {
|
||||
@Override
|
||||
public void process(int progress) {
|
||||
if (DEBUG) {
|
||||
Log.i(TAG, "[process] " + progress);
|
||||
}
|
||||
mProgressBar.setProgress(progress);
|
||||
mProgressTipView.setText(progress + "/" + mItemNum);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processTotal(int total) {
|
||||
mItemNum = total;
|
||||
mProgressBar.setMax(mItemNum);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processComplete() {
|
||||
mCancelBtn.setText(getResources().getString(R.string.done));
|
||||
mHideBtn.setVisibility(View.GONE);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
private final View.OnClickListener cancelListener = new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
DictImportActivity.this.finish();
|
||||
}
|
||||
};
|
||||
|
||||
private final View.OnClickListener abortListener = new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
if (DEBUG) {
|
||||
Log.d(TAG, "[onClick] abort");
|
||||
}
|
||||
if (serviceBinder != null) {
|
||||
serviceBinder.abortImport();
|
||||
}
|
||||
DictImportActivity.this.finish();
|
||||
}
|
||||
};
|
||||
|
||||
private final View.OnClickListener confirmListener = new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
if (DEBUG) {
|
||||
Log.d(TAG, "[onClick] confirm");
|
||||
}
|
||||
if (serviceBinder == null) {
|
||||
// todo error tip
|
||||
if (DEBUG) {
|
||||
Log.e(TAG, "[onClick] service is not connected");
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (mDictUri == null) {
|
||||
// todo error tip
|
||||
if (DEBUG) {
|
||||
Log.e(TAG, "[onClick] mDictUri is not be init");
|
||||
}
|
||||
return;
|
||||
}
|
||||
serviceBinder.importDict(mDictUri);
|
||||
|
||||
view.setVisibility(View.GONE);
|
||||
mCancelBtn.setOnClickListener(abortListener);
|
||||
mHideBtn.setVisibility(View.VISIBLE);
|
||||
mProgressBar.setVisibility(View.VISIBLE);
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
private final View.OnClickListener hideListener = new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
if (DEBUG) {
|
||||
Log.d(TAG, "[onClick] hide");
|
||||
}
|
||||
DictImportActivity.this.finish();
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
serviceBinder.removeOnProgressListener(importListener);
|
||||
unbindService(conn);
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
|
||||
private void initFromService() {
|
||||
mDictUri = serviceBinder.getUri();
|
||||
if (mDictUri == null) {
|
||||
if (DEBUG) {
|
||||
Log.e(TAG, "[initFromService] error use of initFromService,you may use initFromIntent instead");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (DEBUG) {
|
||||
Log.d(TAG, "[initFromService] " + mDictUri.toString());
|
||||
}
|
||||
|
||||
mItemNum = serviceBinder.getItemNum();
|
||||
mProgressBar.setMax(mItemNum);
|
||||
mConfirmBtn.setVisibility(View.GONE);
|
||||
mHideBtn.setVisibility(View.VISIBLE);
|
||||
mProgressBar.setVisibility(View.VISIBLE);
|
||||
mTipView.setText(TextUrl.getFileName(mDictUri.toString()));
|
||||
mCancelBtn.setOnClickListener(abortListener);
|
||||
}
|
||||
|
||||
private void initFromIntent() {
|
||||
mDictUri = getIntent().getData();
|
||||
if (DEBUG) {
|
||||
Log.d(TAG, "[initFromIntent] " + mDictUri.toString());
|
||||
}
|
||||
mTipView.setText(TextUrl.getFileName(mDictUri.toString()));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -16,10 +16,8 @@
|
||||
|
||||
package com.hippo.ehviewer.ui;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
@@ -29,7 +27,7 @@ import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.rippleold.RippleSalon;
|
||||
import com.hippo.ripple.Ripple;
|
||||
import com.hippo.widget.DirExplorer;
|
||||
import com.hippo.yorozuya.ViewUtils;
|
||||
|
||||
@@ -52,7 +50,6 @@ public class DirPickerActivity extends ToolbarActivity
|
||||
@Nullable
|
||||
private View mOk;
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
@@ -73,7 +70,7 @@ public class DirPickerActivity extends ToolbarActivity
|
||||
mDirExplorer.setCurrentFile(file);
|
||||
mDirExplorer.setOnChangeDirListener(this);
|
||||
|
||||
RippleSalon.addRipple(mOk, false);
|
||||
Ripple.addRipple(mOk, false);
|
||||
|
||||
mOk.setOnClickListener(this);
|
||||
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright 2016 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.ui;
|
||||
|
||||
// It is a dump activity to make Chrome or maybe other browser to send implicit intent when open eh url.
|
||||
// Take a look at AndroidManifest to know how it works.
|
||||
public class DumpBrowsableActivity extends EhActivity {}
|
||||
@@ -30,7 +30,7 @@ import com.hippo.easyrecyclerview.EasyRecyclerView;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.Settings;
|
||||
import com.hippo.ehviewer.client.EhConfig;
|
||||
import com.hippo.rippleold.RippleSalon;
|
||||
import com.hippo.ripple.Ripple;
|
||||
import com.hippo.widget.SensitiveCheckBox;
|
||||
import com.hippo.yorozuya.ViewUtils;
|
||||
|
||||
@@ -163,11 +163,11 @@ public class ExcludedLanguagesActivity extends ToolbarActivity
|
||||
mDeselectAll.setOnClickListener(this);
|
||||
mInvertSelection.setOnClickListener(this);
|
||||
|
||||
RippleSalon.addRipple(mCancel, false);
|
||||
RippleSalon.addRipple(mOk, false);
|
||||
RippleSalon.addRipple(mSelectAll, false);
|
||||
RippleSalon.addRipple(mDeselectAll, false);
|
||||
RippleSalon.addRipple(mInvertSelection, false);
|
||||
Ripple.addRipple(mCancel, false);
|
||||
Ripple.addRipple(mOk, false);
|
||||
Ripple.addRipple(mSelectAll, false);
|
||||
Ripple.addRipple(mDeselectAll, false);
|
||||
Ripple.addRipple(mInvertSelection, false);
|
||||
}
|
||||
|
||||
private boolean isDecimal(String str) {
|
||||
|
||||
@@ -23,6 +23,7 @@ import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ActivityInfo;
|
||||
import android.content.res.Resources;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
@@ -35,8 +36,10 @@ import android.text.TextUtils;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
import android.webkit.MimeTypeMap;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.SeekBar;
|
||||
import android.widget.Spinner;
|
||||
@@ -62,8 +65,10 @@ import com.hippo.gl.view.GLRootView;
|
||||
import com.hippo.image.Image;
|
||||
import com.hippo.unifile.UniFile;
|
||||
import com.hippo.util.SystemUiHelper;
|
||||
import com.hippo.widget.ColorView;
|
||||
import com.hippo.yorozuya.AnimationUtils;
|
||||
import com.hippo.yorozuya.ConcurrentPool;
|
||||
import com.hippo.yorozuya.MathUtils;
|
||||
import com.hippo.yorozuya.SimpleAnimatorListener;
|
||||
import com.hippo.yorozuya.SimpleHandler;
|
||||
import com.hippo.yorozuya.ViewUtils;
|
||||
@@ -80,6 +85,7 @@ public class GalleryActivity extends EhActivity
|
||||
|
||||
public static final String KEY_ACTION = "action";
|
||||
public static final String KEY_FILENAME = "filename";
|
||||
public static final String KEY_URI = "uri";
|
||||
public static final String KEY_GALLERY_INFO = "gallery_info";
|
||||
public static final String KEY_PAGE = "page";
|
||||
public static final String KEY_CURRENT_INDEX = "current_index";
|
||||
@@ -89,6 +95,7 @@ public class GalleryActivity extends EhActivity
|
||||
|
||||
private String mAction;
|
||||
private String mFilename;
|
||||
private Uri mUri;
|
||||
private GalleryInfo mGalleryInfo;
|
||||
private int mPage;
|
||||
|
||||
@@ -104,9 +111,13 @@ public class GalleryActivity extends EhActivity
|
||||
private SystemUiHelper mSystemUiHelper;
|
||||
private boolean mShowSystemUi;
|
||||
|
||||
@Nullable
|
||||
private ColorView mMaskView;
|
||||
@Nullable
|
||||
private View mClock;
|
||||
@Nullable
|
||||
private TextView mProgress;
|
||||
@Nullable
|
||||
private View mBattery;
|
||||
@Nullable
|
||||
private View mSeekBarPanel;
|
||||
@@ -177,6 +188,11 @@ public class GalleryActivity extends EhActivity
|
||||
if (mGalleryInfo != null) {
|
||||
mGalleryProvider = new EhGalleryProvider(this, mGalleryInfo);
|
||||
}
|
||||
} else if (Intent.ACTION_VIEW.equals(mAction)) {
|
||||
if (mUri != null) {
|
||||
// Only support zip now
|
||||
mGalleryProvider = new ZipGalleryProvider(new File(mUri.getPath()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -188,6 +204,7 @@ public class GalleryActivity extends EhActivity
|
||||
|
||||
mAction = intent.getAction();
|
||||
mFilename = intent.getStringExtra(KEY_FILENAME);
|
||||
mUri = intent.getData();
|
||||
mGalleryInfo = intent.getParcelableExtra(KEY_GALLERY_INFO);
|
||||
mPage = intent.getIntExtra(KEY_PAGE, -1);
|
||||
buildProvider();
|
||||
@@ -196,6 +213,7 @@ public class GalleryActivity extends EhActivity
|
||||
private void onRestore(@NonNull Bundle savedInstanceState) {
|
||||
mAction = savedInstanceState.getString(KEY_ACTION);
|
||||
mFilename = savedInstanceState.getString(KEY_FILENAME);
|
||||
mUri= savedInstanceState.getParcelable(KEY_URI);
|
||||
mGalleryInfo = savedInstanceState.getParcelable(KEY_GALLERY_INFO);
|
||||
mPage = savedInstanceState.getInt(KEY_PAGE, -1);
|
||||
mCurrentIndex = savedInstanceState.getInt(KEY_CURRENT_INDEX);
|
||||
@@ -207,6 +225,7 @@ public class GalleryActivity extends EhActivity
|
||||
super.onSaveInstanceState(outState);
|
||||
outState.putString(KEY_ACTION, mAction);
|
||||
outState.putString(KEY_FILENAME, mFilename);
|
||||
outState.putParcelable(KEY_URI, mUri);
|
||||
if (mGalleryInfo != null) {
|
||||
outState.putParcelable(KEY_GALLERY_INFO, mGalleryInfo);
|
||||
}
|
||||
@@ -216,6 +235,14 @@ public class GalleryActivity extends EhActivity
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
if (Settings.getReadingFullscreen() && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
Window w = getWindow();
|
||||
w.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION,
|
||||
WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
|
||||
w.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS,
|
||||
WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
|
||||
}
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
if (savedInstanceState == null) {
|
||||
@@ -249,20 +276,25 @@ public class GalleryActivity extends EhActivity
|
||||
glRootView.setContentPane(mGalleryView);
|
||||
|
||||
// System UI helper
|
||||
int systemUiLevel;
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
||||
systemUiLevel = SystemUiHelper.LEVEL_IMMERSIVE;
|
||||
} else {
|
||||
systemUiLevel = SystemUiHelper.LEVEL_LOW_PROFILE;
|
||||
if (Settings.getReadingFullscreen()) {
|
||||
int systemUiLevel;
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
||||
systemUiLevel = SystemUiHelper.LEVEL_IMMERSIVE;
|
||||
} else {
|
||||
systemUiLevel = SystemUiHelper.LEVEL_HIDE_STATUS_BAR;
|
||||
}
|
||||
mSystemUiHelper = new SystemUiHelper(this, systemUiLevel,
|
||||
SystemUiHelper.FLAG_LAYOUT_IN_SCREEN_OLDER_DEVICES | SystemUiHelper.FLAG_IMMERSIVE_STICKY);
|
||||
mSystemUiHelper.hide();
|
||||
mShowSystemUi = false;
|
||||
}
|
||||
mSystemUiHelper = new SystemUiHelper(this, systemUiLevel,
|
||||
SystemUiHelper.FLAG_LAYOUT_IN_SCREEN_OLDER_DEVICES | SystemUiHelper.FLAG_IMMERSIVE_STICKY);
|
||||
mSystemUiHelper.hide();
|
||||
mShowSystemUi = false;
|
||||
|
||||
mMaskView = (ColorView) ViewUtils.$$(this, R.id.mask);
|
||||
mClock = ViewUtils.$$(this, R.id.clock);
|
||||
mProgress = (TextView) ViewUtils.$$(this, R.id.progress);
|
||||
mBattery = ViewUtils.$$(this, R.id.battery);
|
||||
mClock.setVisibility(Settings.getShowClock() ? View.VISIBLE : View.GONE);
|
||||
mProgress.setVisibility(Settings.getShowProgress() ? View.VISIBLE : View.GONE);
|
||||
mBattery.setVisibility(Settings.getShowBattery() ? View.VISIBLE : View.GONE);
|
||||
|
||||
mSeekBarPanel = ViewUtils.$$(this, R.id.seek_bar_panel);
|
||||
@@ -283,6 +315,25 @@ public class GalleryActivity extends EhActivity
|
||||
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||
}
|
||||
|
||||
// Orientation
|
||||
int orientation;
|
||||
switch (Settings.getScreenRotation()) {
|
||||
default:
|
||||
case 0:
|
||||
orientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
|
||||
break;
|
||||
case 1:
|
||||
orientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT;
|
||||
break;
|
||||
case 2:
|
||||
orientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE;
|
||||
break;
|
||||
}
|
||||
setRequestedOrientation(orientation);
|
||||
|
||||
// Screen lightness
|
||||
setScreenLightness(Settings.getCustomScreenLightness(), Settings.getScreenLightness());
|
||||
|
||||
if (Settings.getGuideGallery()) {
|
||||
FrameLayout mainLayout = (FrameLayout) ViewUtils.$$(this, R.id.main);
|
||||
mainLayout.addView(new GalleryGuideView(this));
|
||||
@@ -303,6 +354,10 @@ public class GalleryActivity extends EhActivity
|
||||
mGalleryProvider = null;
|
||||
}
|
||||
|
||||
mMaskView = null;
|
||||
mClock = null;
|
||||
mProgress = null;
|
||||
mBattery = null;
|
||||
mSeekBarPanel = null;
|
||||
mLeftText = null;
|
||||
mRightText = null;
|
||||
@@ -311,24 +366,6 @@ public class GalleryActivity extends EhActivity
|
||||
SimpleHandler.getInstance().removeCallbacks(mHideSliderRunnable);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
|
||||
if (null != mGalleryView) {
|
||||
mGalleryView.pause();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
|
||||
if (null != mGalleryView) {
|
||||
mGalleryView.resume();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWindowFocusChanged(boolean hasFocus) {
|
||||
super.onWindowFocusChanged(hasFocus);
|
||||
@@ -435,6 +472,18 @@ public class GalleryActivity extends EhActivity
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("SetTextI18n")
|
||||
private void updateProgress() {
|
||||
if (mProgress == null) {
|
||||
return;
|
||||
}
|
||||
if (mSize <= 0 || mCurrentIndex < 0) {
|
||||
mProgress.setText(null);
|
||||
} else {
|
||||
mProgress.setText((mCurrentIndex + 1) + "/" + mSize);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("SetTextI18n")
|
||||
private void updateSlider() {
|
||||
if (mSeekBar == null || mRightText == null || mLeftText == null || mSize <= 0 || mCurrentIndex < 0) {
|
||||
@@ -650,35 +699,86 @@ public class GalleryActivity extends EhActivity
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param lightness 0 - 200
|
||||
*/
|
||||
private void setScreenLightness(boolean enable, int lightness) {
|
||||
if (null == mMaskView) {
|
||||
return;
|
||||
}
|
||||
|
||||
Window w = getWindow();
|
||||
WindowManager.LayoutParams lp = w.getAttributes();
|
||||
if (enable) {
|
||||
lightness = MathUtils.clamp(lightness, 0, 200);
|
||||
if (lightness > 100) {
|
||||
mMaskView.setColor(0);
|
||||
// Avoid BRIGHTNESS_OVERRIDE_OFF,
|
||||
// screen may be off when lp.screenBrightness is 0.0f
|
||||
lp.screenBrightness = Math.max((lightness - 100) / 100.0f, 0.01f);
|
||||
} else {
|
||||
mMaskView.setColor(MathUtils.lerp(0xde, 0x00, lightness / 100.0f) << 24);
|
||||
lp.screenBrightness = 0.01f;
|
||||
}
|
||||
} else {
|
||||
mMaskView.setColor(0);
|
||||
lp.screenBrightness = WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_NONE;
|
||||
}
|
||||
w.setAttributes(lp);
|
||||
}
|
||||
|
||||
private class GalleryMenuHelper implements DialogInterface.OnClickListener {
|
||||
|
||||
private final View mView;
|
||||
private final Spinner mScreenRotation;
|
||||
private final Spinner mReadingDirection;
|
||||
private final Spinner mScaleMode;
|
||||
private final Spinner mStartPosition;
|
||||
private final SwitchCompat mKeepScreenOn;
|
||||
private final SwitchCompat mShowClock;
|
||||
private final SwitchCompat mShowProgress;
|
||||
private final SwitchCompat mShowBattery;
|
||||
private final SwitchCompat mVolumePage;
|
||||
private final SwitchCompat mReadingFullscreen;
|
||||
private final SwitchCompat mCustomScreenLightness;
|
||||
private final SeekBar mScreenLightness;
|
||||
|
||||
@SuppressLint("InflateParams")
|
||||
public GalleryMenuHelper(Context context) {
|
||||
mView = LayoutInflater.from(context).inflate(R.layout.dialog_gallery_menu, null);
|
||||
mScreenRotation = (Spinner) mView.findViewById(R.id.screen_rotation);
|
||||
mReadingDirection = (Spinner) mView.findViewById(R.id.reading_direction);
|
||||
mScaleMode = (Spinner) mView.findViewById(R.id.page_scaling);
|
||||
mStartPosition = (Spinner) mView.findViewById(R.id.start_position);
|
||||
mKeepScreenOn = (SwitchCompat) mView.findViewById(R.id.keep_screen_on);
|
||||
mShowClock = (SwitchCompat) mView.findViewById(R.id.show_clock);
|
||||
mShowProgress = (SwitchCompat) mView.findViewById(R.id.show_progress);
|
||||
mShowBattery = (SwitchCompat) mView.findViewById(R.id.show_battery);
|
||||
mVolumePage = (SwitchCompat) mView.findViewById(R.id.volume_page);
|
||||
mReadingFullscreen = (SwitchCompat) mView.findViewById(R.id.reading_fullscreen);
|
||||
mCustomScreenLightness = (SwitchCompat) mView.findViewById(R.id.custom_screen_lightness);
|
||||
mScreenLightness = (SeekBar) mView.findViewById(R.id.screen_lightness);
|
||||
|
||||
mScreenRotation.setSelection(Settings.getScreenRotation());
|
||||
mReadingDirection.setSelection(Settings.getReadingDirection());
|
||||
mScaleMode.setSelection(Settings.getPageScaling());
|
||||
mStartPosition.setSelection(Settings.getStartPosition());
|
||||
mKeepScreenOn.setChecked(Settings.getKeepScreenOn());
|
||||
mShowClock.setChecked(Settings.getShowClock());
|
||||
mShowProgress.setChecked(Settings.getShowProgress());
|
||||
mShowBattery.setChecked(Settings.getShowBattery());
|
||||
mVolumePage.setChecked(Settings.getVolumePage());
|
||||
mReadingFullscreen.setChecked(Settings.getReadingFullscreen());
|
||||
mCustomScreenLightness.setChecked(Settings.getCustomScreenLightness());
|
||||
mScreenLightness.setProgress(Settings.getScreenLightness());
|
||||
mScreenLightness.setEnabled(Settings.getCustomScreenLightness());
|
||||
|
||||
mCustomScreenLightness.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||
mScreenLightness.setEnabled(isChecked);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public View getView() {
|
||||
@@ -687,22 +787,48 @@ public class GalleryActivity extends EhActivity
|
||||
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
int screenRotation = mScreenRotation.getSelectedItemPosition();
|
||||
int layoutMode = GalleryView.sanitizeLayoutMode(mReadingDirection.getSelectedItemPosition());
|
||||
int scaleMode = ImageView.sanitizeScaleMode(mScaleMode.getSelectedItemPosition());
|
||||
int startPosition = ImageView.sanitizeStartPosition(mStartPosition.getSelectedItemPosition());
|
||||
boolean keepScreenOn = mKeepScreenOn.isChecked();
|
||||
boolean showClock = mShowClock.isChecked();
|
||||
boolean showProgress = mShowProgress.isChecked();
|
||||
boolean showBattery = mShowBattery.isChecked();
|
||||
boolean volumePage = mVolumePage.isChecked();
|
||||
boolean readingFullscreen = mReadingFullscreen.isChecked();
|
||||
boolean customScreenLightness = mCustomScreenLightness.isChecked();
|
||||
int screenLightness = mScreenLightness.getProgress();
|
||||
|
||||
boolean oldReadingFullscreen = Settings.getReadingFullscreen();
|
||||
|
||||
Settings.putScreenRotation(screenRotation);
|
||||
Settings.putReadingDirection(layoutMode);
|
||||
Settings.putPageScaling(scaleMode);
|
||||
Settings.putStartPosition(startPosition);
|
||||
Settings.putKeepScreenOn(keepScreenOn);
|
||||
Settings.putShowClock(showClock);
|
||||
Settings.putShowProgress(showProgress);
|
||||
Settings.putShowBattery(showBattery);
|
||||
Settings.putVolumePage(volumePage);
|
||||
Settings.putReadingFullscreen(readingFullscreen);
|
||||
Settings.putCustomScreenLightness(customScreenLightness);
|
||||
Settings.putScreenLightness(screenLightness);
|
||||
|
||||
int orientation;
|
||||
switch (screenRotation) {
|
||||
default:
|
||||
case 0:
|
||||
orientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
|
||||
break;
|
||||
case 1:
|
||||
orientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT;
|
||||
break;
|
||||
case 2:
|
||||
orientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE;
|
||||
break;
|
||||
}
|
||||
setRequestedOrientation(orientation);
|
||||
if (mGalleryView != null) {
|
||||
mGalleryView.setLayoutMode(layoutMode);
|
||||
mGalleryView.setScaleMode(scaleMode);
|
||||
@@ -716,13 +842,21 @@ public class GalleryActivity extends EhActivity
|
||||
if (mClock != null) {
|
||||
mClock.setVisibility(showClock ? View.VISIBLE : View.GONE);
|
||||
}
|
||||
if (mProgress != null) {
|
||||
mProgress.setVisibility(showProgress ? View.VISIBLE : View.GONE);
|
||||
}
|
||||
if (mBattery != null) {
|
||||
mBattery.setVisibility(showBattery ? View.VISIBLE : View.GONE);
|
||||
}
|
||||
setScreenLightness(customScreenLightness, screenLightness);
|
||||
|
||||
// Update slider
|
||||
mLayoutMode = layoutMode;
|
||||
updateSlider();
|
||||
|
||||
if (oldReadingFullscreen != readingFullscreen) {
|
||||
recreate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -857,10 +991,12 @@ public class GalleryActivity extends EhActivity
|
||||
case KEY_SIZE:
|
||||
GalleryActivity.this.mSize = mValue;
|
||||
updateSlider();
|
||||
updateProgress();
|
||||
break;
|
||||
case KEY_CURRENT_INDEX:
|
||||
GalleryActivity.this.mCurrentIndex = mValue;
|
||||
updateSlider();
|
||||
updateProgress();
|
||||
break;
|
||||
case KEY_TAP_MENU_AREA:
|
||||
onTapMenuArea();
|
||||
|
||||
@@ -19,6 +19,8 @@ package com.hippo.ehviewer.ui;
|
||||
import android.Manifest;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.graphics.Bitmap;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.PersistableBundle;
|
||||
@@ -28,7 +30,6 @@ import android.support.annotation.Nullable;
|
||||
import android.support.annotation.StringRes;
|
||||
import android.support.design.widget.NavigationView;
|
||||
import android.support.design.widget.Snackbar;
|
||||
import android.support.v4.widget.DrawerLayout;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
@@ -39,11 +40,14 @@ import android.widget.FrameLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.hippo.drawerlayout.DrawerLayout;
|
||||
import com.hippo.ehviewer.AppConfig;
|
||||
import com.hippo.ehviewer.Crash;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.Settings;
|
||||
import com.hippo.ehviewer.client.EhUrlOpener;
|
||||
import com.hippo.ehviewer.client.EhUtils;
|
||||
import com.hippo.ehviewer.client.data.ListUrlBuilder;
|
||||
import com.hippo.ehviewer.ui.scene.AnalyticsScene;
|
||||
import com.hippo.ehviewer.ui.scene.BaseScene;
|
||||
import com.hippo.ehviewer.ui.scene.CookieSignInScene;
|
||||
@@ -64,14 +68,24 @@ import com.hippo.ehviewer.ui.scene.SelectSiteScene;
|
||||
import com.hippo.ehviewer.ui.scene.SignInScene;
|
||||
import com.hippo.ehviewer.ui.scene.WarningScene;
|
||||
import com.hippo.ehviewer.ui.scene.WebViewSignInScene;
|
||||
import com.hippo.ehviewer.widget.EhDrawerLayout;
|
||||
import com.hippo.io.UniFileInputStreamPipe;
|
||||
import com.hippo.scene.Announcer;
|
||||
import com.hippo.scene.SceneFragment;
|
||||
import com.hippo.scene.StageActivity;
|
||||
import com.hippo.unifile.UniFile;
|
||||
import com.hippo.util.BitmapUtils;
|
||||
import com.hippo.util.PermissionRequester;
|
||||
import com.hippo.widget.LoadImageView;
|
||||
import com.hippo.yorozuya.IOUtils;
|
||||
import com.hippo.yorozuya.ResourcesUtils;
|
||||
import com.hippo.yorozuya.ViewUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
||||
public final class MainActivity extends StageActivity
|
||||
implements NavigationView.OnNavigationItemSelectedListener {
|
||||
|
||||
@@ -97,7 +111,7 @@ public final class MainActivity extends StageActivity
|
||||
Whole life cycle
|
||||
---------------*/
|
||||
@Nullable
|
||||
private DrawerLayout mDrawerLayout;
|
||||
private EhDrawerLayout mDrawerLayout;
|
||||
@Nullable
|
||||
private NavigationView mNavView;
|
||||
@Nullable
|
||||
@@ -251,6 +265,38 @@ public final class MainActivity extends StageActivity
|
||||
return announcer;
|
||||
}
|
||||
|
||||
private File saveImageToTempFile(UniFile file) {
|
||||
if (null == file) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Bitmap bitmap = null;
|
||||
try {
|
||||
bitmap = BitmapUtils.decodeStream(new UniFileInputStreamPipe(file), -1, -1, 500 * 500, false, false, null);
|
||||
} catch (OutOfMemoryError e) {
|
||||
// Ignore
|
||||
}
|
||||
if (null == bitmap) {
|
||||
return null;
|
||||
}
|
||||
|
||||
File temp = AppConfig.createTempFile();
|
||||
if (null == temp) {
|
||||
return null;
|
||||
}
|
||||
|
||||
OutputStream os = null;
|
||||
try {
|
||||
os = new FileOutputStream(temp);
|
||||
bitmap.compress(Bitmap.CompressFormat.JPEG, 90, os);
|
||||
return temp;
|
||||
} catch (IOException e) {
|
||||
return null;
|
||||
} finally {
|
||||
IOUtils.closeQuietly(os);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean handleIntent(Intent intent) {
|
||||
if (intent == null) {
|
||||
return false;
|
||||
@@ -263,6 +309,29 @@ public final class MainActivity extends StageActivity
|
||||
startScene(processAnnouncer(announcer));
|
||||
return true;
|
||||
}
|
||||
} else if (Intent.ACTION_SEND.equals(action)) {
|
||||
String type = intent.getType();
|
||||
if ("text/plain".equals(type)) {
|
||||
ListUrlBuilder builder = new ListUrlBuilder();
|
||||
builder.setKeyword(intent.getStringExtra(Intent.EXTRA_TEXT));
|
||||
startScene(processAnnouncer(GalleryListScene.getStartAnnouncer(builder)));
|
||||
return true;
|
||||
} else if (type.startsWith("image/")) {
|
||||
Uri uri = intent.getParcelableExtra(Intent.EXTRA_STREAM);
|
||||
if (null != uri) {
|
||||
UniFile file = UniFile.fromUri(this, uri);
|
||||
File temp = saveImageToTempFile(file);
|
||||
if (null != temp) {
|
||||
ListUrlBuilder builder = new ListUrlBuilder();
|
||||
builder.setMode(ListUrlBuilder.MODE_IMAGE_SEARCH);
|
||||
builder.setImagePath(temp.getPath());
|
||||
builder.setUseSimilarityScan(true);
|
||||
builder.setShowExpunged(true);
|
||||
startScene(processAnnouncer(GalleryListScene.getStartAnnouncer(builder)));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
@@ -271,11 +340,20 @@ public final class MainActivity extends StageActivity
|
||||
@Override
|
||||
protected void onUnrecognizedIntent(@Nullable Intent intent) {
|
||||
if (!handleIntent(intent)) {
|
||||
boolean handleUrl = false;
|
||||
if (intent != null && Intent.ACTION_VIEW.equals(intent.getAction())) {
|
||||
handleUrl = true;
|
||||
Toast.makeText(this, R.string.error_cannot_parse_the_url, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
if (0 == getSceneCount()) {
|
||||
finish();
|
||||
if (handleUrl) {
|
||||
finish();
|
||||
} else {
|
||||
Bundle args = new Bundle();
|
||||
args.putString(GalleryListScene.KEY_ACTION, GalleryListScene.ACTION_HOMEPAGE);
|
||||
startScene(processAnnouncer(new Announcer(GalleryListScene.class).setArgs(args)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -290,13 +368,14 @@ public final class MainActivity extends StageActivity
|
||||
protected void onCreate2(@Nullable Bundle savedInstanceState) {
|
||||
setContentView(R.layout.activity_main);
|
||||
|
||||
mDrawerLayout = (DrawerLayout) ViewUtils.$$(this, R.id.draw_view);
|
||||
mDrawerLayout = (EhDrawerLayout) ViewUtils.$$(this, R.id.draw_view);
|
||||
mNavView = (NavigationView) ViewUtils.$$(this, R.id.nav_view);
|
||||
mRightDrawer = (FrameLayout) ViewUtils.$$(this, R.id.right_drawer);
|
||||
View headerLayout = mNavView.getHeaderView(0);
|
||||
mAvatar = (LoadImageView) ViewUtils.$$(headerLayout, R.id.avatar);
|
||||
mDisplayName = (TextView) ViewUtils.$$(headerLayout, R.id.display_name);
|
||||
|
||||
mDrawerLayout.setStatusBarColor(ResourcesUtils.getAttrColor(this, R.attr.colorPrimaryDark));
|
||||
// Pre-L need shadow drawable
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
|
||||
mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow_left, Gravity.LEFT);
|
||||
@@ -320,7 +399,8 @@ public final class MainActivity extends StageActivity
|
||||
|
||||
private void checkDownloadLocation() {
|
||||
UniFile uniFile = Settings.getDownloadLocation();
|
||||
if (null != uniFile && uniFile.ensureDir()) {
|
||||
// null == uniFile for first start
|
||||
if (null == uniFile || uniFile.ensureDir()) {
|
||||
return;
|
||||
}
|
||||
new AlertDialog.Builder(this)
|
||||
@@ -423,6 +503,18 @@ public final class MainActivity extends StageActivity
|
||||
mDisplayName.setText(displayName);
|
||||
}
|
||||
|
||||
public void addAboveSnackView(View view) {
|
||||
if (mDrawerLayout != null) {
|
||||
mDrawerLayout.addAboveSnackView(view);
|
||||
}
|
||||
}
|
||||
|
||||
public void removeAboveSnackView(View view) {
|
||||
if (mDrawerLayout != null) {
|
||||
mDrawerLayout.removeAboveSnackView(view);
|
||||
}
|
||||
}
|
||||
|
||||
public int getDrawerLockMode(int edgeGravity) {
|
||||
if (mDrawerLayout != null) {
|
||||
return mDrawerLayout.getDrawerLockMode(edgeGravity);
|
||||
|
||||
@@ -19,6 +19,7 @@ package com.hippo.ehviewer.ui;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.text.TextUtils;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
|
||||
import com.hippo.ehviewer.R;
|
||||
@@ -62,6 +63,17 @@ public class SetSecurityActivity extends ToolbarActivity implements View.OnClick
|
||||
mPatternView = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case android.R.id.home:
|
||||
finish();
|
||||
return true;
|
||||
default:
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (v == mCancel) {
|
||||
|
||||
@@ -25,20 +25,14 @@ import com.hippo.ehviewer.Analytics;
|
||||
import com.hippo.ehviewer.EhApplication;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.Settings;
|
||||
import com.hippo.ehviewer.UrlOpener;
|
||||
import com.hippo.ehviewer.ui.CommonOperations;
|
||||
import com.hippo.util.ActivityHelper;
|
||||
import com.hippo.util.AppHelper;
|
||||
|
||||
public class AboutFragment extends PreferenceFragment
|
||||
implements Preference.OnPreferenceChangeListener,
|
||||
Preference.OnPreferenceClickListener {
|
||||
|
||||
private static final String KEY_AUTHOR = "author";
|
||||
private static final String KEY_GOOGLE_PLUS = "google_plus";
|
||||
private static final String KEY_WEBSITE = "website";
|
||||
private static final String KEY_SOURCE = "source";
|
||||
private static final String KEY_CHANGELOG = "changelog";
|
||||
private static final String KEY_LICENSE = "license";
|
||||
private static final String KEY_DONATE = "donate";
|
||||
private static final String KEY_CHECK_FOR_UPDATES = "check_for_updates";
|
||||
|
||||
@@ -48,11 +42,7 @@ public class AboutFragment extends PreferenceFragment
|
||||
addPreferencesFromResource(R.xml.about_settings);
|
||||
|
||||
Preference author = findPreference(KEY_AUTHOR);
|
||||
Preference googlePlus = findPreference(KEY_GOOGLE_PLUS);
|
||||
Preference enableAnalytics = findPreference(Settings.KEY_ENABLE_ANALYTICS);
|
||||
Preference website = findPreference(KEY_WEBSITE);
|
||||
Preference source = findPreference(KEY_SOURCE);
|
||||
Preference changelog = findPreference(KEY_CHANGELOG);
|
||||
Preference donate = findPreference(KEY_DONATE);
|
||||
Preference checkForUpdate = findPreference(KEY_CHECK_FOR_UPDATES);
|
||||
|
||||
@@ -60,10 +50,6 @@ public class AboutFragment extends PreferenceFragment
|
||||
donate.setSummary(getString(R.string.settings_about_donate_summary).replace('$', '@'));
|
||||
|
||||
author.setOnPreferenceClickListener(this);
|
||||
googlePlus.setOnPreferenceClickListener(this);
|
||||
website.setOnPreferenceClickListener(this);
|
||||
source.setOnPreferenceClickListener(this);
|
||||
changelog.setOnPreferenceClickListener(this);
|
||||
donate.setOnPreferenceClickListener(this);
|
||||
checkForUpdate.setOnPreferenceClickListener(this);
|
||||
|
||||
@@ -86,20 +72,8 @@ public class AboutFragment extends PreferenceFragment
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
String key = preference.getKey();
|
||||
if (KEY_AUTHOR.equals(key)) {
|
||||
ActivityHelper.sendEmail(getActivity(), EhApplication.getDeveloperEmail(),
|
||||
AppHelper.sendEmail(getActivity(), EhApplication.getDeveloperEmail(),
|
||||
"About EhViewer", null);
|
||||
} else if (KEY_GOOGLE_PLUS.equals(key)) {
|
||||
UrlOpener.openUrl(getActivity(), "https://plus.google.com/communities/103823982034655188459",
|
||||
false, true);
|
||||
} else if (KEY_WEBSITE.equals(key)) {
|
||||
UrlOpener.openUrl(getActivity(), "http://www.ehviewer.com",
|
||||
false, true);
|
||||
} else if (KEY_SOURCE.equals(key)) {
|
||||
UrlOpener.openUrl(getActivity(), "https://github.com/seven332/EhViewer",
|
||||
false, true);
|
||||
} else if (KEY_CHANGELOG.equals(key)) {
|
||||
UrlOpener.openUrl(getActivity(), "http://www.ehviewer.com/changlog",
|
||||
false, true);
|
||||
} else if (KEY_DONATE.equals(key)) {
|
||||
new AlertDialog.Builder(getActivity())
|
||||
.setTitle(R.string.settings_about_donate)
|
||||
|
||||
@@ -16,51 +16,33 @@
|
||||
|
||||
package com.hippo.ehviewer.ui.fragment;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.Activity;
|
||||
import android.content.ActivityNotFoundException;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Parcel;
|
||||
import android.preference.Preference;
|
||||
import android.preference.PreferenceFragment;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.hippo.app.ProgressDialog;
|
||||
import com.hippo.ehviewer.EhApplication;
|
||||
import com.hippo.ehviewer.EhDB;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.Settings;
|
||||
import com.hippo.ehviewer.client.EhClient;
|
||||
import com.hippo.ehviewer.client.EhRequest;
|
||||
import com.hippo.ehviewer.client.data.GalleryInfo;
|
||||
import com.hippo.ehviewer.download.DownloadManager;
|
||||
import com.hippo.ehviewer.spider.SpiderQueen;
|
||||
import com.hippo.ehviewer.ui.CommonOperations;
|
||||
import com.hippo.ehviewer.ui.DirPickerActivity;
|
||||
import com.hippo.unifile.UniFile;
|
||||
import com.hippo.yorozuya.IOUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class DownloadFragment extends PreferenceFragment implements Preference.OnPreferenceClickListener {
|
||||
|
||||
private static final String TAG = DownloadFragment.class.getSimpleName();
|
||||
public class DownloadFragment extends PreferenceFragment implements
|
||||
Preference.OnPreferenceChangeListener,
|
||||
Preference.OnPreferenceClickListener {
|
||||
|
||||
public static final int REQUEST_CODE_PICK_IMAGE_DIR = 0;
|
||||
public static final int REQUEST_CODE_PICK_IMAGE_DIR_L = 1;
|
||||
|
||||
public static final String KEY_DOWNLOAD_LOCATION = "download_location";
|
||||
public static final String KEY_RESTORE_DOWNLOAD_ITEMS = "restore_download_items";
|
||||
|
||||
@Nullable
|
||||
private Preference mDownloadLocation;
|
||||
@@ -70,15 +52,18 @@ public class DownloadFragment extends PreferenceFragment implements Preference.O
|
||||
super.onCreate(savedInstanceState);
|
||||
addPreferencesFromResource(R.xml.download_settings);
|
||||
|
||||
Preference mediaScan = findPreference(Settings.KEY_MEDIA_SCAN);
|
||||
Preference imageResolution = findPreference(Settings.KEY_IMAGE_RESOLUTION);
|
||||
mDownloadLocation = findPreference(KEY_DOWNLOAD_LOCATION);
|
||||
Preference restoreDownloadItems = findPreference(KEY_RESTORE_DOWNLOAD_ITEMS);
|
||||
|
||||
onUpdateDownloadLocation();
|
||||
|
||||
mediaScan.setOnPreferenceChangeListener(this);
|
||||
imageResolution.setOnPreferenceChangeListener(this);
|
||||
|
||||
if (mDownloadLocation != null) {
|
||||
mDownloadLocation.setOnPreferenceClickListener(this);
|
||||
}
|
||||
restoreDownloadItems.setOnPreferenceClickListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -111,18 +96,13 @@ public class DownloadFragment extends PreferenceFragment implements Preference.O
|
||||
showDirPickerDialogL();
|
||||
}
|
||||
return true;
|
||||
} else if (KEY_RESTORE_DOWNLOAD_ITEMS.equals(key)) {
|
||||
ProgressDialog dialog = ProgressDialog.show(getActivity(), null,
|
||||
getString(R.string.settings_download_restoring), true, false);
|
||||
new RestoreTask(dialog).execute();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void showDirPickerDialogKK() {
|
||||
new AlertDialog.Builder(getActivity()).setMessage(R.string.settings_download_pick_dir_kk)
|
||||
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
||||
.setPositiveButton(R.string.settings_download_continue, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
openDirPicker();
|
||||
@@ -146,7 +126,7 @@ public class DownloadFragment extends PreferenceFragment implements Preference.O
|
||||
};
|
||||
|
||||
new AlertDialog.Builder(getActivity()).setMessage(R.string.settings_download_pick_dir_l)
|
||||
.setPositiveButton(android.R.string.ok, listener)
|
||||
.setPositiveButton(R.string.settings_download_continue, listener)
|
||||
.setNeutralButton(R.string.settings_download_document, listener)
|
||||
.show();
|
||||
}
|
||||
@@ -160,18 +140,18 @@ public class DownloadFragment extends PreferenceFragment implements Preference.O
|
||||
startActivityForResult(intent, REQUEST_CODE_PICK_IMAGE_DIR);
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
||||
private void openDirPickerL() {
|
||||
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
|
||||
try {
|
||||
startActivityForResult(intent, REQUEST_CODE_PICK_IMAGE_DIR_L);
|
||||
} catch (ActivityNotFoundException e) {
|
||||
Toast.makeText(getActivity(), R.string.error_cant_find_activity, Toast.LENGTH_SHORT).show();
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
|
||||
try {
|
||||
startActivityForResult(intent, REQUEST_CODE_PICK_IMAGE_DIR_L);
|
||||
} catch (ActivityNotFoundException e) {
|
||||
Toast.makeText(getActivity(), R.string.error_cant_find_activity, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@TargetApi(Build.VERSION_CODES.KITKAT)
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
switch (requestCode) {
|
||||
case REQUEST_CODE_PICK_IMAGE_DIR: {
|
||||
@@ -188,7 +168,7 @@ public class DownloadFragment extends PreferenceFragment implements Preference.O
|
||||
break;
|
||||
}
|
||||
case REQUEST_CODE_PICK_IMAGE_DIR_L: {
|
||||
if (resultCode == Activity.RESULT_OK) {
|
||||
if (resultCode == Activity.RESULT_OK && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
Uri treeUri = data.getData();
|
||||
getActivity().getContentResolver().takePersistableUriPermission(
|
||||
treeUri, Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
|
||||
@@ -209,166 +189,25 @@ public class DownloadFragment extends PreferenceFragment implements Preference.O
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private class RestoreTask extends AsyncTask<Void, Void, List<RestoreItem>> {
|
||||
|
||||
private final ProgressDialog mDialog;
|
||||
private final DownloadManager mManager;
|
||||
|
||||
public RestoreTask(ProgressDialog dialog) {
|
||||
mDialog = dialog;
|
||||
mManager = EhApplication.getDownloadManager(getActivity());
|
||||
}
|
||||
|
||||
private RestoreItem getRestoreItem(UniFile file) {
|
||||
if (null == file || !file.isDirectory()) {
|
||||
return null;
|
||||
}
|
||||
UniFile siFile = file.findFile(SpiderQueen.SPIDER_INFO_FILENAME);
|
||||
if (null == siFile) {
|
||||
return null;
|
||||
}
|
||||
|
||||
InputStream is = null;
|
||||
try {
|
||||
is = siFile.openInputStream();
|
||||
// Skip start page
|
||||
IOUtils.readAsciiLine(is);
|
||||
long gid = Long.parseLong(IOUtils.readAsciiLine(is));
|
||||
if (mManager.containDownloadInfo(gid)) {
|
||||
return null;
|
||||
}
|
||||
String token = IOUtils.readAsciiLine(is);
|
||||
RestoreItem restoreItem = new RestoreItem();
|
||||
restoreItem.gid = gid;
|
||||
restoreItem.token = token;
|
||||
restoreItem.dirname = file.getName();
|
||||
return restoreItem;
|
||||
} catch (IOException e) {
|
||||
return null;
|
||||
} finally {
|
||||
IOUtils.closeQuietly(is);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<RestoreItem> doInBackground(Void... params) {
|
||||
UniFile dir = Settings.getDownloadLocation();
|
||||
if (null == dir) {
|
||||
return null;
|
||||
}
|
||||
|
||||
List<RestoreItem> restoreItemList = new ArrayList<>();
|
||||
|
||||
UniFile[] files = dir.listFiles();
|
||||
for (UniFile file: files) {
|
||||
RestoreItem restoreItem = getRestoreItem(file);
|
||||
if (null != restoreItem) {
|
||||
restoreItemList.add(restoreItem);
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
String key = preference.getKey();
|
||||
if (Settings.KEY_MEDIA_SCAN.equals(key)) {
|
||||
if (newValue instanceof Boolean) {
|
||||
UniFile downloadLocation = Settings.getDownloadLocation();
|
||||
if ((Boolean) newValue) {
|
||||
CommonOperations.removeNoMediaFile(downloadLocation);
|
||||
} else {
|
||||
CommonOperations.ensureNoMediaFile(downloadLocation);
|
||||
}
|
||||
}
|
||||
|
||||
if (0 == restoreItemList.size()) {
|
||||
return null;
|
||||
} else {
|
||||
return restoreItemList;
|
||||
return true;
|
||||
} else if (Settings.KEY_IMAGE_RESOLUTION.equals(key)) {
|
||||
if (newValue instanceof String) {
|
||||
Settings.putImageResolution((String) newValue);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(List<RestoreItem> restoreItemList) {
|
||||
if (null == restoreItemList) {
|
||||
Toast.makeText(getActivity(), R.string.settings_download_restore_not_found,
|
||||
Toast.LENGTH_SHORT).show();
|
||||
mDialog.dismiss();
|
||||
return;
|
||||
}
|
||||
|
||||
EhRequest request = new EhRequest();
|
||||
request.setMethod(EhClient.METHOD_FILL_GALLERY_LIST_BY_API);
|
||||
request.setArgs(new ArrayList<GalleryInfo>(restoreItemList));
|
||||
request.setCallback(new EhClient.Callback<List<GalleryInfo>>() {
|
||||
@Override
|
||||
public void onSuccess(List<GalleryInfo> galleryInfoList) {
|
||||
DownloadManager downloadManager = EhApplication.getDownloadManager(getActivity());
|
||||
|
||||
int count = 0;
|
||||
for (int i = 0, n = galleryInfoList.size(); i < n; i++) {
|
||||
GalleryInfo galleryInfo = galleryInfoList.get(i);
|
||||
// Avoid failed gallery info
|
||||
if (null != galleryInfo.title) {
|
||||
// Put to download
|
||||
downloadManager.addDownload(galleryInfo, null);
|
||||
// Put download dir to DB
|
||||
if (galleryInfo instanceof RestoreItem) {
|
||||
EhDB.putDownloadDirname(galleryInfo.gid, ((RestoreItem) galleryInfo).dirname);
|
||||
} else {
|
||||
Log.w(TAG, "The GalleryInfo is not RestoreItem");
|
||||
}
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
Toast.makeText(getActivity(),
|
||||
getString(R.string.settings_download_restore_successfully, count),
|
||||
Toast.LENGTH_SHORT).show();
|
||||
|
||||
mDialog.dismiss();
|
||||
|
||||
getActivity().setResult(Activity.RESULT_OK);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Exception e) {
|
||||
Toast.makeText(getActivity(), R.string.settings_download_restore_failed,
|
||||
Toast.LENGTH_SHORT).show();
|
||||
mDialog.dismiss();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCancel() {
|
||||
mDialog.dismiss();
|
||||
}
|
||||
});
|
||||
|
||||
EhClient client = EhApplication.getEhClient(getActivity());
|
||||
client.execute(request);
|
||||
}
|
||||
}
|
||||
|
||||
private static class RestoreItem extends GalleryInfo {
|
||||
|
||||
public String dirname;
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
super.writeToParcel(dest, flags);
|
||||
dest.writeString(this.dirname);
|
||||
}
|
||||
|
||||
public RestoreItem() {
|
||||
}
|
||||
|
||||
protected RestoreItem(Parcel in) {
|
||||
super(in);
|
||||
this.dirname = in.readString();
|
||||
}
|
||||
|
||||
public static final Creator<RestoreItem> CREATOR = new Creator<RestoreItem>() {
|
||||
@Override
|
||||
public RestoreItem createFromParcel(Parcel source) {
|
||||
return new RestoreItem(source);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RestoreItem[] newArray(int size) {
|
||||
return new RestoreItem[size];
|
||||
}
|
||||
};
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -34,9 +34,11 @@ public class EhFragment extends PreferenceFragment
|
||||
|
||||
Preference gallerySite = findPreference(Settings.KEY_GALLERY_SITE);
|
||||
Preference listMode = findPreference(Settings.KEY_LIST_MODE);
|
||||
Preference thumbSize = findPreference(Settings.KEY_THUMB_SIZE);
|
||||
|
||||
gallerySite.setOnPreferenceChangeListener(this);
|
||||
listMode.setOnPreferenceChangeListener(this);
|
||||
thumbSize.setOnPreferenceChangeListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -48,6 +50,8 @@ public class EhFragment extends PreferenceFragment
|
||||
} else if (Settings.KEY_LIST_MODE.equals(key)) {
|
||||
getActivity().setResult(Activity.RESULT_OK);
|
||||
return true;
|
||||
} else if (Settings.KEY_THUMB_SIZE.equals(key)) {
|
||||
getActivity().setResult(Activity.RESULT_OK);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ import android.view.ViewGroup;
|
||||
|
||||
import com.hippo.ehviewer.ui.MainActivity;
|
||||
import com.hippo.scene.SceneFragment;
|
||||
import com.hippo.util.ActivityHelper;
|
||||
import com.hippo.util.AppHelper;
|
||||
|
||||
public abstract class BaseScene extends SceneFragment {
|
||||
|
||||
@@ -49,6 +49,20 @@ public abstract class BaseScene extends SceneFragment {
|
||||
}
|
||||
}
|
||||
|
||||
public void addAboveSnackView(View view) {
|
||||
FragmentActivity activity = getActivity();
|
||||
if (activity instanceof MainActivity) {
|
||||
((MainActivity) activity).addAboveSnackView(view);
|
||||
}
|
||||
}
|
||||
|
||||
public void removeAboveSnackView(View view) {
|
||||
FragmentActivity activity = getActivity();
|
||||
if (activity instanceof MainActivity) {
|
||||
((MainActivity) activity).removeAboveSnackView(view);
|
||||
}
|
||||
}
|
||||
|
||||
public void setDrawerLockMode(int lockMode, int edgeGravity) {
|
||||
FragmentActivity activity = getActivity();
|
||||
if (activity instanceof MainActivity) {
|
||||
@@ -154,7 +168,7 @@ public abstract class BaseScene extends SceneFragment {
|
||||
setNavCheckedItem(getNavCheckedItem());
|
||||
|
||||
// Hide soft ime
|
||||
ActivityHelper.hideSoftInput(getActivity());
|
||||
AppHelper.hideSoftInput(getActivity());
|
||||
}
|
||||
|
||||
public void createThemeContext(@StyleRes int style) {
|
||||
@@ -198,14 +212,14 @@ public abstract class BaseScene extends SceneFragment {
|
||||
public void hideSoftInput() {
|
||||
FragmentActivity activity = getActivity();
|
||||
if (null != activity) {
|
||||
ActivityHelper.hideSoftInput(activity);
|
||||
AppHelper.hideSoftInput(activity);
|
||||
}
|
||||
}
|
||||
|
||||
public void showSoftInput(@Nullable View view) {
|
||||
FragmentActivity activity = getActivity();
|
||||
if (null != activity && null != view) {
|
||||
ActivityHelper.showSoftInput(activity, view);
|
||||
AppHelper.showSoftInput(activity, view);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,7 @@ package com.hippo.ehviewer.ui.scene;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.design.widget.TextInputLayout;
|
||||
@@ -79,6 +80,25 @@ public class CookieSignInScene extends BaseScene implements EditText.OnEditorAct
|
||||
|
||||
mOk.setOnClickListener(this);
|
||||
|
||||
// Try to get old version cookie info
|
||||
Context context = getContext2();
|
||||
AssertUtils.assertNotNull(context);
|
||||
SharedPreferences sharedPreferences = context.getSharedPreferences("eh_info", 0);
|
||||
String ipbMemberId = sharedPreferences.getString("ipb_member_id", null);
|
||||
String ipbPassHash = sharedPreferences.getString("ipb_pass_hash", null);
|
||||
boolean getIt = false;
|
||||
if (!TextUtils.isEmpty(ipbMemberId)) {
|
||||
mIpbMemberId.setText(ipbMemberId);
|
||||
getIt = true;
|
||||
}
|
||||
if (!TextUtils.isEmpty(ipbPassHash)) {
|
||||
mIpbPassHash.setText(ipbPassHash);
|
||||
getIt = true;
|
||||
}
|
||||
if (getIt) {
|
||||
showTip(R.string.found_cookies, LENGTH_SHORT);
|
||||
}
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
|
||||
@@ -26,8 +26,8 @@ import com.hippo.ehviewer.Crash;
|
||||
import com.hippo.ehviewer.EhApplication;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.ui.MainActivity;
|
||||
import com.hippo.rippleold.RippleSalon;
|
||||
import com.hippo.util.ActivityHelper;
|
||||
import com.hippo.ripple.Ripple;
|
||||
import com.hippo.util.AppHelper;
|
||||
import com.hippo.yorozuya.ViewUtils;
|
||||
|
||||
public class CrashScene extends BaseScene implements View.OnClickListener {
|
||||
@@ -70,8 +70,8 @@ public class CrashScene extends BaseScene implements View.OnClickListener {
|
||||
mCancel.setOnClickListener(this);
|
||||
mSend.setOnClickListener(this);
|
||||
|
||||
RippleSalon.addRipple(mCancel, true);
|
||||
RippleSalon.addRipple(mSend, true);
|
||||
Ripple.addRipple(mCancel, true);
|
||||
Ripple.addRipple(mSend, true);
|
||||
|
||||
return view;
|
||||
}
|
||||
@@ -81,7 +81,7 @@ public class CrashScene extends BaseScene implements View.OnClickListener {
|
||||
MainActivity activity = getActivity2();
|
||||
|
||||
if (mSend == v && null != mCrash && null != activity) {
|
||||
ActivityHelper.sendEmail(activity, EhApplication.getDeveloperEmail(),
|
||||
AppHelper.sendEmail(activity, EhApplication.getDeveloperEmail(),
|
||||
"I found a bug in EhViewer !", mCrash);
|
||||
}
|
||||
Crash.resetCrashFile();
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
package com.hippo.ehviewer.ui.scene;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
@@ -33,9 +32,9 @@ import android.support.annotation.Nullable;
|
||||
import android.support.design.widget.FloatingActionButton;
|
||||
import android.support.v4.widget.DrawerLayout;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.support.v7.widget.SimpleItemAnimator;
|
||||
import android.support.v7.widget.StaggeredGridLayoutManager;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.util.Log;
|
||||
import android.util.SparseBooleanArray;
|
||||
@@ -45,6 +44,7 @@ import android.view.LayoutInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.ViewTreeObserver;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ListView;
|
||||
@@ -59,6 +59,7 @@ import com.hippo.app.CheckBoxDialogBuilder;
|
||||
import com.hippo.easyrecyclerview.EasyRecyclerView;
|
||||
import com.hippo.easyrecyclerview.FastScroller;
|
||||
import com.hippo.easyrecyclerview.HandlerDrawable;
|
||||
import com.hippo.easyrecyclerview.MarginItemDecoration;
|
||||
import com.hippo.ehviewer.EhApplication;
|
||||
import com.hippo.ehviewer.EhDB;
|
||||
import com.hippo.ehviewer.R;
|
||||
@@ -74,7 +75,7 @@ import com.hippo.ehviewer.spider.SpiderDen;
|
||||
import com.hippo.ehviewer.ui.GalleryActivity;
|
||||
import com.hippo.ehviewer.ui.MainActivity;
|
||||
import com.hippo.ehviewer.widget.SimpleRatingView;
|
||||
import com.hippo.rippleold.RippleSalon;
|
||||
import com.hippo.ripple.Ripple;
|
||||
import com.hippo.scene.Announcer;
|
||||
import com.hippo.unifile.UniFile;
|
||||
import com.hippo.util.ApiHelper;
|
||||
@@ -82,12 +83,12 @@ import com.hippo.util.DrawableManager;
|
||||
import com.hippo.view.ViewTransition;
|
||||
import com.hippo.widget.FabLayout;
|
||||
import com.hippo.widget.LoadImageView;
|
||||
import com.hippo.widget.recyclerview.AutoStaggeredGridLayoutManager;
|
||||
import com.hippo.yorozuya.AssertUtils;
|
||||
import com.hippo.yorozuya.FileUtils;
|
||||
import com.hippo.yorozuya.LongList;
|
||||
import com.hippo.yorozuya.ObjectUtils;
|
||||
import com.hippo.yorozuya.ResourcesUtils;
|
||||
import com.hippo.yorozuya.SimpleHandler;
|
||||
import com.hippo.yorozuya.ViewUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -131,7 +132,7 @@ public class DownloadsScene extends ToolbarScene
|
||||
@Nullable
|
||||
private DownloadAdapter mAdapter;
|
||||
@Nullable
|
||||
private LinearLayoutManager mLayoutManager;
|
||||
private AutoStaggeredGridLayoutManager mLayoutManager;
|
||||
|
||||
private ShowcaseView mShowcaseView;
|
||||
|
||||
@@ -278,6 +279,7 @@ public class DownloadsScene extends ToolbarScene
|
||||
|
||||
Context context = getContext2();
|
||||
AssertUtils.assertNotNull(content);
|
||||
Resources resources = context.getResources();
|
||||
|
||||
Drawable drawable = DrawableManager.getDrawable(context, R.drawable.big_download);
|
||||
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
|
||||
@@ -286,9 +288,11 @@ public class DownloadsScene extends ToolbarScene
|
||||
mAdapter = new DownloadAdapter();
|
||||
mAdapter.setHasStableIds(true);
|
||||
mRecyclerView.setAdapter(mAdapter);
|
||||
mLayoutManager = new LinearLayoutManager(context);
|
||||
mLayoutManager = new AutoStaggeredGridLayoutManager(0, StaggeredGridLayoutManager.VERTICAL);
|
||||
mLayoutManager.setColumnSize(resources.getDimensionPixelOffset(R.dimen.gallery_list_column_width));
|
||||
mLayoutManager.setStrategy(AutoStaggeredGridLayoutManager.STRATEGY_MIN_SIZE);
|
||||
mRecyclerView.setLayoutManager(mLayoutManager);
|
||||
mRecyclerView.setSelector(RippleSalon.generateRippleDrawable(false));
|
||||
mRecyclerView.setSelector(Ripple.generateRippleDrawable(context, false));
|
||||
mRecyclerView.setDrawSelectorOnTop(true);
|
||||
mRecyclerView.hasFixedSize();
|
||||
mRecyclerView.setClipToPadding(false);
|
||||
@@ -301,9 +305,12 @@ public class DownloadsScene extends ToolbarScene
|
||||
if (itemAnimator instanceof SimpleItemAnimator) {
|
||||
((SimpleItemAnimator) itemAnimator).setSupportsChangeAnimations(false);
|
||||
}
|
||||
int paddingH = context.getResources().getDimensionPixelOffset(R.dimen.list_content_margin_h);
|
||||
int paddingV = context.getResources().getDimensionPixelOffset(R.dimen.list_content_margin_v);
|
||||
mRecyclerView.setPadding(paddingV, paddingH, paddingV, paddingH);
|
||||
int interval = resources.getDimensionPixelOffset(R.dimen.gallery_list_interval);
|
||||
int paddingH = resources.getDimensionPixelOffset(R.dimen.gallery_list_margin_h);
|
||||
int paddingV = resources.getDimensionPixelOffset(R.dimen.gallery_list_margin_v);
|
||||
MarginItemDecoration decoration = new MarginItemDecoration(interval, paddingH, paddingV, paddingH, paddingV);
|
||||
mRecyclerView.addItemDecoration(decoration);
|
||||
decoration.applyPaddings(mRecyclerView);
|
||||
if (mInitPosition >= 0) {
|
||||
mRecyclerView.scrollToPosition(mInitPosition);
|
||||
mInitPosition = -1;
|
||||
@@ -319,6 +326,7 @@ public class DownloadsScene extends ToolbarScene
|
||||
mFabLayout.setHidePrimaryFab(true);
|
||||
mFabLayout.setAutoCancel(false);
|
||||
mFabLayout.setOnClickFabListener(this);
|
||||
addAboveSnackView(mFabLayout);
|
||||
|
||||
updateView();
|
||||
|
||||
@@ -328,11 +336,16 @@ public class DownloadsScene extends ToolbarScene
|
||||
}
|
||||
|
||||
private void guide() {
|
||||
if (Settings.getGuideDownloadThumb()) {
|
||||
SimpleHandler.getInstance().post(new Runnable() {
|
||||
if (Settings.getGuideDownloadThumb() && null != mRecyclerView) {
|
||||
mRecyclerView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
|
||||
@Override
|
||||
public void run() {
|
||||
guideDownloadThumb();
|
||||
public void onGlobalLayout() {
|
||||
if (Settings.getGuideDownloadThumb()) {
|
||||
guideDownloadThumb();
|
||||
}
|
||||
if (null != mRecyclerView) {
|
||||
ViewUtils.removeOnGlobalLayoutListener(mRecyclerView.getViewTreeObserver(), this);
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
@@ -346,7 +359,7 @@ public class DownloadsScene extends ToolbarScene
|
||||
guideDownloadLabels();
|
||||
return;
|
||||
}
|
||||
int position = mLayoutManager.findFirstCompletelyVisibleItemPosition();
|
||||
int position = mLayoutManager.findFirstCompletelyVisibleItemPositions(null)[0];
|
||||
if (position < 0) {
|
||||
guideDownloadLabels();
|
||||
return;
|
||||
@@ -424,9 +437,12 @@ public class DownloadsScene extends ToolbarScene
|
||||
mRecyclerView.stopScroll();
|
||||
mRecyclerView = null;
|
||||
}
|
||||
if (null != mFabLayout) {
|
||||
removeAboveSnackView(mFabLayout);
|
||||
mFabLayout = null;
|
||||
}
|
||||
|
||||
mRecyclerView = null;
|
||||
mFabLayout = null;
|
||||
mViewTransition = null;
|
||||
mAdapter = null;
|
||||
mLayoutManager = null;
|
||||
@@ -1049,8 +1065,8 @@ public class DownloadsScene extends ToolbarScene
|
||||
thumb.setOnClickListener(this);
|
||||
start.setOnClickListener(this);
|
||||
stop.setOnClickListener(this);
|
||||
RippleSalon.addRipple(start, false);
|
||||
RippleSalon.addRipple(stop, false);
|
||||
Ripple.addRipple(start, false);
|
||||
Ripple.addRipple(stop, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1115,7 +1131,6 @@ public class DownloadsScene extends ToolbarScene
|
||||
return new DownloadHolder(mInflater.inflate(R.layout.item_download, parent, false));
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
||||
@Override
|
||||
public void onBindViewHolder(DownloadHolder holder, int position) {
|
||||
if (mList == null) {
|
||||
@@ -1135,7 +1150,7 @@ public class DownloadsScene extends ToolbarScene
|
||||
bindForState(holder, info);
|
||||
|
||||
// Update transition name
|
||||
if (ApiHelper.SUPPORT_TRANSITION) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
long gid = info.gid;
|
||||
holder.thumb.setTransitionName(TransitionNameFactory.getThumbTransitionName(gid));
|
||||
}
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package com.hippo.ehviewer.ui.scene;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.support.v4.app.Fragment;
|
||||
@@ -27,7 +26,6 @@ import android.view.View;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.scene.TransitionHelper;
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
||||
class EnterGalleryDetailTransaction implements TransitionHelper {
|
||||
|
||||
private final View mThumb;
|
||||
@@ -43,15 +41,17 @@ class EnterGalleryDetailTransaction implements TransitionHelper {
|
||||
return false;
|
||||
}
|
||||
|
||||
exit.setSharedElementReturnTransition(
|
||||
TransitionInflater.from(context).inflateTransition(R.transition.trans_move));
|
||||
exit.setExitTransition(
|
||||
TransitionInflater.from(context).inflateTransition(android.R.transition.fade));
|
||||
enter.setSharedElementEnterTransition(
|
||||
TransitionInflater.from(context).inflateTransition(R.transition.trans_move));
|
||||
enter.setEnterTransition(
|
||||
TransitionInflater.from(context).inflateTransition(android.R.transition.fade));
|
||||
transaction.addSharedElement(mThumb, mThumb.getTransitionName());
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
exit.setSharedElementReturnTransition(
|
||||
TransitionInflater.from(context).inflateTransition(R.transition.trans_move));
|
||||
exit.setExitTransition(
|
||||
TransitionInflater.from(context).inflateTransition(android.R.transition.fade));
|
||||
enter.setSharedElementEnterTransition(
|
||||
TransitionInflater.from(context).inflateTransition(R.transition.trans_move));
|
||||
enter.setEnterTransition(
|
||||
TransitionInflater.from(context).inflateTransition(android.R.transition.fade));
|
||||
transaction.addSharedElement(mThumb, mThumb.getTransitionName());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -71,7 +71,8 @@ import com.hippo.ehviewer.ui.annotation.DrawerLifeCircle;
|
||||
import com.hippo.ehviewer.ui.annotation.ViewLifeCircle;
|
||||
import com.hippo.ehviewer.ui.annotation.WholeLifeCircle;
|
||||
import com.hippo.ehviewer.widget.SearchBar;
|
||||
import com.hippo.rippleold.RippleSalon;
|
||||
import com.hippo.refreshlayout.RefreshLayout;
|
||||
import com.hippo.ripple.Ripple;
|
||||
import com.hippo.scene.Announcer;
|
||||
import com.hippo.scene.SceneFragment;
|
||||
import com.hippo.util.ApiHelper;
|
||||
@@ -79,7 +80,6 @@ import com.hippo.util.DrawableManager;
|
||||
import com.hippo.widget.ContentLayout;
|
||||
import com.hippo.widget.FabLayout;
|
||||
import com.hippo.widget.SearchBarMover;
|
||||
import com.hippo.widget.refreshlayout.RefreshLayout;
|
||||
import com.hippo.yorozuya.AssertUtils;
|
||||
import com.hippo.yorozuya.LayoutUtils;
|
||||
import com.hippo.yorozuya.ObjectUtils;
|
||||
@@ -244,7 +244,7 @@ public class FavoritesScene extends BaseScene implements
|
||||
Context context = getContext2();
|
||||
AssertUtils.assertNotNull(context);
|
||||
Resources resources = context.getResources();
|
||||
int paddingTopSB = resources.getDimensionPixelOffset(R.dimen.list_padding_top_search_bar);
|
||||
int paddingTopSB = resources.getDimensionPixelOffset(R.dimen.gallery_padding_top_search_bar);
|
||||
|
||||
mHelper = new FavoritesHelper();
|
||||
mHelper.setEmptyString(resources.getString(R.string.gallery_list_empty_hit));
|
||||
@@ -252,7 +252,7 @@ public class FavoritesScene extends BaseScene implements
|
||||
contentLayout.getFastScroller().setOnDragHandlerListener(this);
|
||||
|
||||
mAdapter = new FavoritesAdapter(inflater, resources, mRecyclerView, Settings.getListMode());
|
||||
mRecyclerView.setSelector(RippleSalon.generateRippleDrawable(false));
|
||||
mRecyclerView.setSelector(Ripple.generateRippleDrawable(context, false));
|
||||
mRecyclerView.setDrawSelectorOnTop(true);
|
||||
mRecyclerView.hasFixedSize();
|
||||
mRecyclerView.setClipToPadding(false);
|
||||
@@ -260,8 +260,6 @@ public class FavoritesScene extends BaseScene implements
|
||||
mRecyclerView.setOnItemLongClickListener(this);
|
||||
mRecyclerView.setChoiceMode(EasyRecyclerView.CHOICE_MODE_MULTIPLE_CUSTOM);
|
||||
mRecyclerView.setCustomCheckedListener(this);
|
||||
mRecyclerView.setPadding(mRecyclerView.getPaddingLeft(), mRecyclerView.getPaddingTop() + paddingTopSB,
|
||||
mRecyclerView.getPaddingRight(), mRecyclerView.getPaddingBottom());
|
||||
|
||||
fastScroller.setPadding(fastScroller.getPaddingLeft(), fastScroller.getPaddingTop() + paddingTopSB,
|
||||
fastScroller.getPaddingRight(), fastScroller.getPaddingBottom());
|
||||
@@ -280,6 +278,7 @@ public class FavoritesScene extends BaseScene implements
|
||||
mFabLayout.setAutoCancel(false);
|
||||
mFabLayout.setHidePrimaryFab(true);
|
||||
mFabLayout.setOnClickFabListener(this);
|
||||
addAboveSnackView(mFabLayout);
|
||||
|
||||
// Restore search mode
|
||||
if (mSearchMode) {
|
||||
@@ -395,11 +394,14 @@ public class FavoritesScene extends BaseScene implements
|
||||
mRecyclerView.stopScroll();
|
||||
mRecyclerView = null;
|
||||
}
|
||||
if (null != mFabLayout) {
|
||||
removeAboveSnackView(mFabLayout);
|
||||
mFabLayout = null;
|
||||
}
|
||||
|
||||
mAdapter = null;
|
||||
|
||||
mSearchBar = null;
|
||||
mFabLayout = null;
|
||||
|
||||
mSearchBarMover = null;
|
||||
mLeftDrawable = null;
|
||||
@@ -476,7 +478,7 @@ public class FavoritesScene extends BaseScene implements
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
||||
context = builder.getContext();
|
||||
final LayoutInflater inflater = LayoutInflater.from(context);
|
||||
EasyRecyclerView rv = (EasyRecyclerView) inflater.inflate(R.layout.dialog_favorite_info, null);
|
||||
EasyRecyclerView rv = (EasyRecyclerView) inflater.inflate(R.layout.dialog_recycler_view, null);
|
||||
rv.setAdapter(new InfoAdapter(inflater));
|
||||
rv.setLayoutManager(new LinearLayoutManager(context));
|
||||
LinearDividerItemDecoration decoration = new LinearDividerItemDecoration(
|
||||
@@ -484,7 +486,7 @@ public class FavoritesScene extends BaseScene implements
|
||||
LayoutUtils.dp2pix(context, 1));
|
||||
decoration.setPadding(ResourcesUtils.getAttrDimensionPixelOffset(context, R.attr.dialogPreferredPadding));
|
||||
rv.addItemDecoration(decoration);
|
||||
rv.setSelector(RippleSalon.generateRippleDrawable(false));
|
||||
rv.setSelector(Ripple.generateRippleDrawable(context, false));
|
||||
rv.setClipToPadding(false);
|
||||
builder.setView(rv).show();
|
||||
}
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package com.hippo.ehviewer.ui.scene;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Build;
|
||||
@@ -33,12 +32,11 @@ import android.widget.TextView;
|
||||
import com.hippo.drawable.TriangleDrawable;
|
||||
import com.hippo.easyrecyclerview.MarginItemDecoration;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.Settings;
|
||||
import com.hippo.ehviewer.client.EhCacheKeyFactory;
|
||||
import com.hippo.ehviewer.client.EhUtils;
|
||||
import com.hippo.ehviewer.client.data.GalleryInfo;
|
||||
import com.hippo.ehviewer.widget.TileThumb;
|
||||
import com.hippo.util.ApiHelper;
|
||||
import com.hippo.widget.recyclerview.AutoGridLayoutManager;
|
||||
import com.hippo.widget.recyclerview.AutoStaggeredGridLayoutManager;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
@@ -58,7 +56,9 @@ abstract class GalleryAdapter extends RecyclerView.Adapter<GalleryHolder> {
|
||||
private final Resources mResources;
|
||||
private final RecyclerView mRecyclerView;
|
||||
private final AutoStaggeredGridLayoutManager mLayoutManager;
|
||||
private RecyclerView.ItemDecoration mGirdDecoration;
|
||||
private final int mPaddingTopSB;
|
||||
private MarginItemDecoration mListDecoration;
|
||||
private MarginItemDecoration mGirdDecoration;
|
||||
private int mType = TYPE_INVALID;
|
||||
|
||||
public GalleryAdapter(@NonNull LayoutInflater inflater, @NonNull Resources resources,
|
||||
@@ -67,16 +67,20 @@ abstract class GalleryAdapter extends RecyclerView.Adapter<GalleryHolder> {
|
||||
mResources = resources;
|
||||
mRecyclerView = recyclerView;
|
||||
mLayoutManager = new AutoStaggeredGridLayoutManager(0, StaggeredGridLayoutManager.VERTICAL);
|
||||
mPaddingTopSB = resources.getDimensionPixelOffset(R.dimen.gallery_padding_top_search_bar);
|
||||
|
||||
mRecyclerView.setAdapter(this);
|
||||
mRecyclerView.setLayoutManager(mLayoutManager);
|
||||
|
||||
int paddingH = mResources.getDimensionPixelOffset(R.dimen.list_content_margin_h);
|
||||
int paddingV = mResources.getDimensionPixelOffset(R.dimen.list_content_margin_v);
|
||||
mRecyclerView.setPadding(paddingV, paddingH, paddingV, paddingH);
|
||||
setType(type);
|
||||
}
|
||||
|
||||
private void adjustPaddings() {
|
||||
RecyclerView recyclerView = mRecyclerView;
|
||||
recyclerView.setPadding(recyclerView.getPaddingLeft(), recyclerView.getPaddingTop() + mPaddingTopSB,
|
||||
recyclerView.getPaddingRight(), recyclerView.getPaddingBottom());
|
||||
}
|
||||
|
||||
public int getType() {
|
||||
return mType;
|
||||
}
|
||||
@@ -87,27 +91,44 @@ abstract class GalleryAdapter extends RecyclerView.Adapter<GalleryHolder> {
|
||||
}
|
||||
mType = type;
|
||||
|
||||
RecyclerView recyclerView = mRecyclerView;
|
||||
switch (type) {
|
||||
default:
|
||||
case GalleryAdapter.TYPE_LIST: {
|
||||
int columnWidth = mResources.getDimensionPixelOffset(R.dimen.gallery_list_column_width);
|
||||
mLayoutManager.setColumnSize(columnWidth);
|
||||
mLayoutManager.setStrategy(AutoGridLayoutManager.STRATEGY_MIN_SIZE);
|
||||
mLayoutManager.setStrategy(AutoStaggeredGridLayoutManager.STRATEGY_MIN_SIZE);
|
||||
if (null != mGirdDecoration) {
|
||||
mRecyclerView.removeItemDecoration(mGirdDecoration);
|
||||
recyclerView.removeItemDecoration(mGirdDecoration);
|
||||
}
|
||||
if (null == mListDecoration) {
|
||||
int interval = mResources.getDimensionPixelOffset(R.dimen.gallery_list_interval);
|
||||
int paddingH = mResources.getDimensionPixelOffset(R.dimen.gallery_list_margin_h);
|
||||
int paddingV = mResources.getDimensionPixelOffset(R.dimen.gallery_list_margin_v);
|
||||
mListDecoration = new MarginItemDecoration(interval, paddingH, paddingV, paddingH, paddingV);
|
||||
}
|
||||
recyclerView.addItemDecoration(mListDecoration);
|
||||
mListDecoration.applyPaddings(recyclerView);
|
||||
adjustPaddings();
|
||||
notifyDataSetChanged();
|
||||
break;
|
||||
}
|
||||
case GalleryAdapter.TYPE_GRID: {
|
||||
int columnWidth = mResources.getDimensionPixelOffset(R.dimen.gallery_grid_column_width);
|
||||
int columnWidth = mResources.getDimensionPixelOffset(Settings.getThumbSizeResId());
|
||||
mLayoutManager.setColumnSize(columnWidth);
|
||||
mLayoutManager.setStrategy(AutoGridLayoutManager.STRATEGY_SUITABLE_SIZE);
|
||||
if (null == mGirdDecoration) {
|
||||
mGirdDecoration = new MarginItemDecoration(
|
||||
mResources.getDimensionPixelOffset(R.dimen.gallery_grid_margin) / 2);
|
||||
mLayoutManager.setStrategy(AutoStaggeredGridLayoutManager.STRATEGY_SUITABLE_SIZE);
|
||||
if (null != mListDecoration) {
|
||||
recyclerView.removeItemDecoration(mListDecoration);
|
||||
}
|
||||
mRecyclerView.addItemDecoration(mGirdDecoration);
|
||||
if (null == mGirdDecoration) {
|
||||
int interval = mResources.getDimensionPixelOffset(R.dimen.gallery_grid_interval);
|
||||
int paddingH = mResources.getDimensionPixelOffset(R.dimen.gallery_grid_margin_h);
|
||||
int paddingV = mResources.getDimensionPixelOffset(R.dimen.gallery_grid_margin_v);
|
||||
mGirdDecoration = new MarginItemDecoration(interval, paddingH, paddingV, paddingH, paddingV);
|
||||
}
|
||||
recyclerView.addItemDecoration(mGirdDecoration);
|
||||
mGirdDecoration.applyPaddings(recyclerView);
|
||||
adjustPaddings();
|
||||
notifyDataSetChanged();
|
||||
break;
|
||||
}
|
||||
@@ -138,7 +159,6 @@ abstract class GalleryAdapter extends RecyclerView.Adapter<GalleryHolder> {
|
||||
public abstract GalleryInfo getDataAt(int position);
|
||||
|
||||
@Override
|
||||
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
||||
public void onBindViewHolder(GalleryHolder holder, int position) {
|
||||
GalleryInfo gi = getDataAt(position);
|
||||
if (null == gi) {
|
||||
@@ -170,7 +190,7 @@ abstract class GalleryAdapter extends RecyclerView.Adapter<GalleryHolder> {
|
||||
int color = EhUtils.getCategoryColor(gi.category);
|
||||
if (!(drawable instanceof TriangleDrawable)) {
|
||||
drawable = new TriangleDrawable(color);
|
||||
category.setBackground(drawable);
|
||||
category.setBackgroundDrawable(drawable);
|
||||
} else {
|
||||
((TriangleDrawable) drawable).setColor(color);
|
||||
}
|
||||
@@ -180,7 +200,7 @@ abstract class GalleryAdapter extends RecyclerView.Adapter<GalleryHolder> {
|
||||
}
|
||||
|
||||
// Update transition name
|
||||
if (ApiHelper.SUPPORT_TRANSITION) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
long gid = gi.gid;
|
||||
holder.thumb.setTransitionName(TransitionNameFactory.getThumbTransitionName(gid));
|
||||
}
|
||||
|
||||
@@ -17,25 +17,36 @@
|
||||
package com.hippo.ehviewer.ui.scene;
|
||||
|
||||
import android.animation.Animator;
|
||||
import android.annotation.TargetApi;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.content.ClipData;
|
||||
import android.content.ClipboardManager;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Typeface;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Parcelable;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.design.widget.FloatingActionButton;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.support.v7.widget.DefaultItemAnimator;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.text.Spannable;
|
||||
import android.text.SpannableString;
|
||||
import android.text.SpannableStringBuilder;
|
||||
import android.text.TextUtils;
|
||||
import android.text.style.ClickableSpan;
|
||||
import android.text.style.ForegroundColorSpan;
|
||||
import android.text.style.RelativeSizeSpan;
|
||||
import android.text.style.StyleSpan;
|
||||
import android.text.style.URLSpan;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewAnimationUtils;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ImageView;
|
||||
@@ -50,8 +61,10 @@ import com.hippo.ehviewer.client.EhClient;
|
||||
import com.hippo.ehviewer.client.EhRequest;
|
||||
import com.hippo.ehviewer.client.EhUrl;
|
||||
import com.hippo.ehviewer.client.data.GalleryComment;
|
||||
import com.hippo.ehviewer.client.parser.VoteCommentParser;
|
||||
import com.hippo.ehviewer.ui.MainActivity;
|
||||
import com.hippo.rippleold.RippleSalon;
|
||||
import com.hippo.reveal.ViewAnimationUtils;
|
||||
import com.hippo.ripple.Ripple;
|
||||
import com.hippo.scene.SceneFragment;
|
||||
import com.hippo.text.Html;
|
||||
import com.hippo.text.URLImageGetter;
|
||||
@@ -59,32 +72,54 @@ import com.hippo.util.DrawableManager;
|
||||
import com.hippo.util.ReadableTime;
|
||||
import com.hippo.util.TextUrl;
|
||||
import com.hippo.view.ViewTransition;
|
||||
import com.hippo.widget.FabLayout;
|
||||
import com.hippo.widget.LinkifyTextView;
|
||||
import com.hippo.yorozuya.AnimationUtils;
|
||||
import com.hippo.yorozuya.AssertUtils;
|
||||
import com.hippo.yorozuya.IntList;
|
||||
import com.hippo.yorozuya.LayoutUtils;
|
||||
import com.hippo.yorozuya.ResourcesUtils;
|
||||
import com.hippo.yorozuya.SimpleAnimatorListener;
|
||||
import com.hippo.yorozuya.StringUtils;
|
||||
import com.hippo.yorozuya.ViewUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public final class GalleryCommentsScene extends ToolbarScene
|
||||
implements EasyRecyclerView.OnItemClickListener,
|
||||
EasyRecyclerView.OnItemLongClickListener, View.OnClickListener {
|
||||
View.OnClickListener {
|
||||
|
||||
public static final String TAG = GalleryCommentsScene.class.getSimpleName();
|
||||
|
||||
public static final String KEY_API_UID = "api_uid";
|
||||
public static final String KEY_API_KEY = "api_key";
|
||||
public static final String KEY_GID = "gid";
|
||||
public static final String KEY_TOKEN = "token";
|
||||
public static final String KEY_COMMENTS = "comments";
|
||||
|
||||
private long mApiUid;
|
||||
private String mApiKey;
|
||||
private long mGid;
|
||||
private String mToken;
|
||||
@Nullable
|
||||
private GalleryComment[] mComments;
|
||||
|
||||
@Nullable
|
||||
private EasyRecyclerView mRecyclerView;
|
||||
@Nullable
|
||||
private FabLayout mFabLayout;
|
||||
@Nullable
|
||||
private FloatingActionButton mFab;
|
||||
@Nullable
|
||||
private View mEditPanel;
|
||||
@Nullable
|
||||
private ImageView mSendImage;
|
||||
@Nullable
|
||||
private EditText mEditText;
|
||||
|
||||
@Nullable
|
||||
private CommentAdapter mAdapter;
|
||||
@Nullable
|
||||
private ViewTransition mViewTransition;
|
||||
|
||||
private boolean mInAnimation = false;
|
||||
@@ -105,7 +140,9 @@ public final class GalleryCommentsScene extends ToolbarScene
|
||||
return;
|
||||
}
|
||||
|
||||
mGid = args.getLong(KEY_GID, -1);
|
||||
mApiUid = args.getLong(KEY_API_UID, -1L);
|
||||
mApiKey = args.getString(KEY_API_KEY);
|
||||
mGid = args.getLong(KEY_GID, -1L);
|
||||
mToken = args.getString(KEY_TOKEN, null);
|
||||
Parcelable[] parcelables = args.getParcelableArray(KEY_COMMENTS);
|
||||
if (parcelables instanceof GalleryComment[]) {
|
||||
@@ -118,7 +155,9 @@ public final class GalleryCommentsScene extends ToolbarScene
|
||||
}
|
||||
|
||||
private void onRestore(@NonNull Bundle savedInstanceState) {
|
||||
mGid = savedInstanceState.getLong(KEY_GID, -1);
|
||||
mApiUid = savedInstanceState.getLong(KEY_API_UID, -1L);
|
||||
mApiKey = savedInstanceState.getString(KEY_API_KEY);
|
||||
mGid = savedInstanceState.getLong(KEY_GID, -1L);
|
||||
mToken = savedInstanceState.getString(KEY_TOKEN, null);
|
||||
Parcelable[] parcelables = savedInstanceState.getParcelableArray(KEY_COMMENTS);
|
||||
if (parcelables instanceof GalleryComment[]) {
|
||||
@@ -129,6 +168,8 @@ public final class GalleryCommentsScene extends ToolbarScene
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
outState.putLong(KEY_API_UID, mApiUid);
|
||||
outState.putString(KEY_API_KEY, mApiKey);
|
||||
outState.putLong(KEY_GID, mGid);
|
||||
outState.putString(KEY_TOKEN, mToken);
|
||||
outState.putParcelableArray(KEY_COMMENTS, mComments);
|
||||
@@ -139,17 +180,18 @@ public final class GalleryCommentsScene extends ToolbarScene
|
||||
public View onCreateView3(LayoutInflater inflater,
|
||||
@Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
View view = inflater.inflate(R.layout.scene_gallery_comments, container, false);
|
||||
mRecyclerView = (EasyRecyclerView) view.findViewById(R.id.recycler_view);
|
||||
mRecyclerView = (EasyRecyclerView) ViewUtils.$$(view, R.id.recycler_view);
|
||||
TextView tip = (TextView) ViewUtils.$$(view, R.id.tip);
|
||||
mEditPanel = ViewUtils.$$(view, R.id.edit_panel);
|
||||
mSendImage = (ImageView) ViewUtils.$$(mEditPanel, R.id.send);
|
||||
mEditText = (EditText) ViewUtils.$$(mEditPanel, R.id.edit_text);
|
||||
mFabLayout = (FabLayout) ViewUtils.$$(view, R.id.fab_layout);
|
||||
mFab = (FloatingActionButton) ViewUtils.$$(view, R.id.fab);
|
||||
|
||||
Context context = getContext2();
|
||||
AssertUtils.assertNotNull(context);
|
||||
Resources resources = context.getResources();
|
||||
int paddingBottomFab = resources.getDimensionPixelOffset(R.dimen.list_padding_bottom_fab);
|
||||
int paddingBottomFab = resources.getDimensionPixelOffset(R.dimen.gallery_padding_bottom_fab);
|
||||
|
||||
Drawable drawable = DrawableManager.getDrawable(context, R.drawable.big_weird_face);
|
||||
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
|
||||
@@ -164,23 +206,26 @@ public final class GalleryCommentsScene extends ToolbarScene
|
||||
LayoutUtils.dp2pix(context, 1));
|
||||
decoration.setShowLastDivider(true);
|
||||
mRecyclerView.addItemDecoration(decoration);
|
||||
mRecyclerView.setSelector(RippleSalon.generateRippleDrawable(false));
|
||||
mRecyclerView.setSelector(Ripple.generateRippleDrawable(context, false));
|
||||
mRecyclerView.setHasFixedSize(true);
|
||||
mRecyclerView.setOnItemClickListener(this);
|
||||
mRecyclerView.setOnItemLongClickListener(this);
|
||||
mRecyclerView.setPadding(mRecyclerView.getPaddingLeft(), mRecyclerView.getPaddingTop(),
|
||||
mRecyclerView.getPaddingRight(), mRecyclerView.getPaddingBottom() + paddingBottomFab);
|
||||
// Cancel change animator
|
||||
RecyclerView.ItemAnimator itemAnimator = mRecyclerView.getItemAnimator();
|
||||
if (itemAnimator instanceof DefaultItemAnimator) {
|
||||
((DefaultItemAnimator) itemAnimator).setSupportsChangeAnimations(false);
|
||||
}
|
||||
|
||||
mSendImage.setOnClickListener(this);
|
||||
mFab.setOnClickListener(this);
|
||||
|
||||
addAboveSnackView(mEditPanel);
|
||||
addAboveSnackView(mFabLayout);
|
||||
|
||||
mViewTransition = new ViewTransition(mRecyclerView, tip);
|
||||
|
||||
if (mComments == null || mComments.length <= 0) {
|
||||
mViewTransition.showView(1);
|
||||
} else {
|
||||
mViewTransition.showView(0);
|
||||
}
|
||||
updateView(false);
|
||||
|
||||
return view;
|
||||
}
|
||||
@@ -193,7 +238,18 @@ public final class GalleryCommentsScene extends ToolbarScene
|
||||
mRecyclerView.stopScroll();
|
||||
mRecyclerView = null;
|
||||
}
|
||||
if (null != mEditPanel) {
|
||||
removeAboveSnackView(mEditPanel);
|
||||
mEditPanel = null;
|
||||
}
|
||||
if (null != mFabLayout) {
|
||||
removeAboveSnackView(mFabLayout);
|
||||
mFabLayout = null;
|
||||
}
|
||||
|
||||
mFab = null;
|
||||
mSendImage = null;
|
||||
mEditText = null;
|
||||
mAdapter = null;
|
||||
mViewTransition = null;
|
||||
}
|
||||
@@ -210,6 +266,140 @@ public final class GalleryCommentsScene extends ToolbarScene
|
||||
onBackPressed();
|
||||
}
|
||||
|
||||
private void voteComment(long id, int vote) {
|
||||
Context context = getContext2();
|
||||
MainActivity activity = getActivity2();
|
||||
if (null == context || null == activity) {
|
||||
return;
|
||||
}
|
||||
|
||||
EhRequest request = new EhRequest()
|
||||
.setMethod(EhClient.METHOD_VOTE_COMMENT)
|
||||
.setArgs(mApiUid, mApiKey, mGid, mToken, id, vote)
|
||||
.setCallback(new VoteCommentListener(context,
|
||||
activity.getStageId(), getTag()));
|
||||
EhApplication.getEhClient(context).execute(request);
|
||||
}
|
||||
|
||||
private class InfoHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
private final TextView key;
|
||||
private final TextView value;
|
||||
|
||||
public InfoHolder(View itemView) {
|
||||
super(itemView);
|
||||
key = (TextView) ViewUtils.$$(itemView, R.id.key);
|
||||
value = (TextView) ViewUtils.$$(itemView, R.id.value);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("InflateParams")
|
||||
public void showVoteStatusDialog(Context context, String voteStatus) {
|
||||
String[] temp = StringUtils.split(voteStatus, ',');
|
||||
final int length = temp.length;
|
||||
final String[] userArray = new String[length];
|
||||
final String[] voteArray = new String[length];
|
||||
for (int i = 0; i < length; i++) {
|
||||
String str = StringUtils.trim(temp[i]);
|
||||
int index = str.lastIndexOf(' ');
|
||||
if (index < 0) {
|
||||
Log.d(TAG, "Something wrong happened about vote state");
|
||||
userArray[i] = str;
|
||||
voteArray[i] = "";
|
||||
} else {
|
||||
userArray[i] = StringUtils.trim(str.substring(0, index));
|
||||
voteArray[i] = StringUtils.trim(str.substring(index + 1));
|
||||
}
|
||||
}
|
||||
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
||||
context = builder.getContext();
|
||||
final LayoutInflater inflater = LayoutInflater.from(context);
|
||||
EasyRecyclerView rv = (EasyRecyclerView) inflater.inflate(R.layout.dialog_recycler_view, null);
|
||||
rv.setAdapter(new RecyclerView.Adapter<InfoHolder>() {
|
||||
@Override
|
||||
public InfoHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
return new InfoHolder(inflater.inflate(R.layout.item_favorite_info_data, parent, false));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(InfoHolder holder, int position) {
|
||||
holder.key.setText(userArray[position]);
|
||||
holder.value.setText(voteArray[position]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return length;
|
||||
}
|
||||
});
|
||||
rv.setLayoutManager(new LinearLayoutManager(context));
|
||||
LinearDividerItemDecoration decoration = new LinearDividerItemDecoration(
|
||||
LinearDividerItemDecoration.VERTICAL, context.getResources().getColor(R.color.divider),
|
||||
LayoutUtils.dp2pix(context, 1));
|
||||
decoration.setPadding(ResourcesUtils.getAttrDimensionPixelOffset(context, R.attr.dialogPreferredPadding));
|
||||
rv.addItemDecoration(decoration);
|
||||
rv.setSelector(Ripple.generateRippleDrawable(context, false));
|
||||
rv.setClipToPadding(false);
|
||||
builder.setView(rv).show();
|
||||
}
|
||||
|
||||
private void showCommentDialog(int position) {
|
||||
final Context context = getContext2();
|
||||
if (null == context || null == mComments || position >= mComments.length || position < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
final GalleryComment comment = mComments[position];
|
||||
List<String> menu = new ArrayList<>();
|
||||
final IntList menuId = new IntList();
|
||||
Resources resources = context.getResources();
|
||||
if (0 == comment.id || mApiUid < 0) {
|
||||
// 0 id is uploader comment, can't vote
|
||||
// Not sign in, can't vote
|
||||
menu.add(resources.getString(R.string.copy_comment_text));
|
||||
menuId.add(R.id.copy);
|
||||
} else {
|
||||
menu.add(resources.getString(R.string.copy_comment_text));
|
||||
menuId.add(R.id.copy);
|
||||
menu.add(resources.getString(comment.voteUp ? R.string.cancel_vote_up : R.string.vote_up));
|
||||
menuId.add(R.id.vote_up);
|
||||
menu.add(resources.getString(comment.voteDown ? R.string.cancel_vote_down : R.string.vote_down));
|
||||
menuId.add(R.id.vote_down);
|
||||
}
|
||||
if (!TextUtils.isEmpty(comment.voteState)) {
|
||||
menu.add(resources.getString(R.string.check_vote_status));
|
||||
menuId.add(R.id.check_vote_status);
|
||||
}
|
||||
|
||||
new AlertDialog.Builder(context)
|
||||
.setItems(menu.toArray(new String[menu.size()]), new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
if (which < 0 || which >= menuId.size()) {
|
||||
return;
|
||||
}
|
||||
int id = menuId.get(which);
|
||||
switch (id) {
|
||||
case R.id.copy:
|
||||
ClipboardManager cmb = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
|
||||
cmb.setPrimaryClip(ClipData.newPlainText(null, comment.comment));
|
||||
showTip(R.string.copied_to_clipboard, LENGTH_SHORT);
|
||||
break;
|
||||
case R.id.vote_up:
|
||||
voteComment(comment.id, 1);
|
||||
break;
|
||||
case R.id.vote_down:
|
||||
voteComment(comment.id, -1);
|
||||
break;
|
||||
case R.id.check_vote_status:
|
||||
showVoteStatusDialog(context, comment.voteState);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}).show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onItemClick(EasyRecyclerView parent, View view, int position, long id) {
|
||||
Activity activity = getActivity2();
|
||||
@@ -224,20 +414,33 @@ public final class GalleryCommentsScene extends ToolbarScene
|
||||
commentHolder.comment.clearCurrentSpan();
|
||||
|
||||
if (span instanceof URLSpan) {
|
||||
UrlOpener.openUrl(activity, ((URLSpan) span).getURL(), true, true);
|
||||
UrlOpener.openUrl(activity, ((URLSpan) span).getURL(), true);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
||||
showCommentDialog(position);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onItemLongClick(EasyRecyclerView parent, View view, int position, long id) {
|
||||
return false;
|
||||
private void updateView(boolean animation) {
|
||||
if (null == mViewTransition) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (mComments == null || mComments.length <= 0) {
|
||||
mViewTransition.showView(1, animation);
|
||||
} else {
|
||||
mViewTransition.showView(0, animation);
|
||||
}
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
||||
private void showEditPanelWithAnimationL() {
|
||||
private void showEditPanelWithAnimation() {
|
||||
if (null == mFab || null == mEditPanel) {
|
||||
return;
|
||||
}
|
||||
|
||||
mInAnimation = true;
|
||||
mFab.setTranslationX(0.0f);
|
||||
mFab.setTranslationY(0.0f);
|
||||
@@ -255,10 +458,10 @@ public final class GalleryCommentsScene extends ToolbarScene
|
||||
int halfW = mEditPanel.getWidth() / 2;
|
||||
int halfH = mEditPanel.getHeight() / 2;
|
||||
Animator animator = ViewAnimationUtils.createCircularReveal(mEditPanel, halfW, halfH, 0,
|
||||
(float) Math.hypot(halfW, halfH)).setDuration(300);
|
||||
(float) Math.hypot(halfW, halfH)).setDuration(300L);
|
||||
animator.addListener(new SimpleAnimatorListener() {
|
||||
@Override
|
||||
public void onAnimationEnd(Animator animation) {
|
||||
public void onAnimationEnd(Animator a) {
|
||||
mInAnimation = false;
|
||||
}
|
||||
});
|
||||
@@ -269,21 +472,22 @@ public final class GalleryCommentsScene extends ToolbarScene
|
||||
|
||||
private void showEditPanel(boolean animation) {
|
||||
if (animation) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
showEditPanelWithAnimationL();
|
||||
} else {
|
||||
// TODO Add animation for pre-L
|
||||
mFab.setVisibility(View.INVISIBLE);
|
||||
mEditPanel.setVisibility(View.VISIBLE);
|
||||
}
|
||||
showEditPanelWithAnimation();
|
||||
} else {
|
||||
if (null == mFab || null == mEditPanel) {
|
||||
return;
|
||||
}
|
||||
|
||||
mFab.setVisibility(View.INVISIBLE);
|
||||
mEditPanel.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
||||
private void hideEditPanelWithAnimationL() {
|
||||
private void hideEditPanelWithAnimation() {
|
||||
if (null == mFab || null == mEditPanel) {
|
||||
return;
|
||||
}
|
||||
|
||||
mInAnimation = true;
|
||||
int halfW = mEditPanel.getWidth() / 2;
|
||||
int halfH = mEditPanel.getHeight() / 2;
|
||||
@@ -291,7 +495,7 @@ public final class GalleryCommentsScene extends ToolbarScene
|
||||
(float) Math.hypot(halfW, halfH), 0.0f).setDuration(300L);
|
||||
animator.addListener(new SimpleAnimatorListener() {
|
||||
@Override
|
||||
public void onAnimationEnd(Animator animation) {
|
||||
public void onAnimationEnd(Animator a) {
|
||||
mEditPanel.setVisibility(View.GONE);
|
||||
mFab.setVisibility(View.VISIBLE);
|
||||
int fabStartX = mEditPanel.getLeft() + (mEditPanel.getWidth() / 2) - (mFab.getWidth() / 2);
|
||||
@@ -300,7 +504,8 @@ public final class GalleryCommentsScene extends ToolbarScene
|
||||
mFab.setY(fabStartY);
|
||||
mFab.setScaleX(0.0f);
|
||||
mFab.setScaleY(0.0f);
|
||||
mFab.animate().translationX(0.0f).translationY(0.0f).scaleX(1.0f).scaleY(1.0f)
|
||||
mFab.setRotation(-45.0f);
|
||||
mFab.animate().translationX(0.0f).translationY(0.0f).scaleX(1.0f).scaleY(1.0f).rotation(0.0f)
|
||||
.setInterpolator(AnimationUtils.SLOW_FAST_SLOW_INTERPOLATOR)
|
||||
.setDuration(300L).setListener(new SimpleAnimatorListener() {
|
||||
@Override
|
||||
@@ -315,14 +520,12 @@ public final class GalleryCommentsScene extends ToolbarScene
|
||||
|
||||
private void hideEditPanel(boolean animation) {
|
||||
if (animation) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
hideEditPanelWithAnimationL();
|
||||
} else {
|
||||
// TODO Add animation for pre-L
|
||||
mFab.setVisibility(View.VISIBLE);
|
||||
mEditPanel.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
hideEditPanelWithAnimation();
|
||||
} else {
|
||||
if (null == mFab || null == mEditPanel) {
|
||||
return;
|
||||
}
|
||||
|
||||
mFab.setVisibility(View.VISIBLE);
|
||||
mEditPanel.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
@@ -331,7 +534,7 @@ public final class GalleryCommentsScene extends ToolbarScene
|
||||
@Nullable
|
||||
private String getGalleryDetailUrl() {
|
||||
if (mGid != -1 && mToken != null) {
|
||||
return EhUrl.getGalleryDetailUrl(mGid, mToken, 0, true);
|
||||
return EhUrl.getGalleryDetailUrl(mGid, mToken, 0, false);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
@@ -341,7 +544,7 @@ public final class GalleryCommentsScene extends ToolbarScene
|
||||
public void onClick(View v) {
|
||||
Context context = getContext2();
|
||||
MainActivity activity = getActivity2();
|
||||
if (null == context || null == activity) {
|
||||
if (null == context || null == activity || null == mEditText) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -378,7 +581,7 @@ public final class GalleryCommentsScene extends ToolbarScene
|
||||
if (mInAnimation) {
|
||||
return;
|
||||
}
|
||||
if (mEditPanel.getVisibility() == View.VISIBLE) {
|
||||
if (null != mEditPanel && mEditPanel.getVisibility() == View.VISIBLE) {
|
||||
hideEditPanel(true);
|
||||
} else {
|
||||
finish();
|
||||
@@ -387,9 +590,9 @@ public final class GalleryCommentsScene extends ToolbarScene
|
||||
|
||||
private class CommentHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
public TextView user;
|
||||
public TextView time;
|
||||
public LinkifyTextView comment;
|
||||
public final TextView user;
|
||||
public final TextView time;
|
||||
public final LinkifyTextView comment;
|
||||
|
||||
public CommentHolder(View itemView) {
|
||||
super(itemView);
|
||||
@@ -413,18 +616,35 @@ public final class GalleryCommentsScene extends ToolbarScene
|
||||
return new CommentHolder(mInflater.inflate(R.layout.item_gallery_comment, parent, false));
|
||||
}
|
||||
|
||||
public CharSequence generateComment(Context context, TextView textView, GalleryComment comment) {
|
||||
SpannableStringBuilder ssb = Html.fromHtml(comment.comment, new URLImageGetter(textView,
|
||||
EhApplication.getConaco(context)), null);
|
||||
|
||||
if (0 != comment.id && 0 != comment.score) {
|
||||
int score = comment.score;
|
||||
String scoreString = score > 0 ? "+" + score : Integer.toString(score);
|
||||
SpannableString ss = new SpannableString(scoreString);
|
||||
ss.setSpan(new RelativeSizeSpan(0.8f), 0, scoreString.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
ss.setSpan(new StyleSpan(Typeface.BOLD), 0, scoreString.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
ss.setSpan(new ForegroundColorSpan(context.getResources().getColor(R.color.secondary_text_default_light))
|
||||
, 0, scoreString.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
ssb.append(" ").append(ss);
|
||||
}
|
||||
|
||||
return TextUrl.handleTextUrl(ssb);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(CommentHolder holder, int position) {
|
||||
Context context = getContext2();
|
||||
if (null == context) {
|
||||
if (null == context || null == mComments) {
|
||||
return;
|
||||
}
|
||||
|
||||
GalleryComment comment = mComments[position];
|
||||
holder.user.setText(comment.user);
|
||||
holder.time.setText(ReadableTime.getTimeAgo(comment.time));
|
||||
holder.comment.setText(TextUrl.handleTextUrl(Html.fromHtml(comment.comment,
|
||||
new URLImageGetter(holder.comment, EhApplication.getConaco(context)), null)));
|
||||
holder.comment.setText(generateComment(context, holder.comment, comment));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -434,6 +654,10 @@ public final class GalleryCommentsScene extends ToolbarScene
|
||||
}
|
||||
|
||||
private void onCommentGallerySuccess(GalleryComment[] result) {
|
||||
if (null == mAdapter) {
|
||||
return;
|
||||
}
|
||||
|
||||
mComments = result;
|
||||
mAdapter.notifyDataSetChanged();
|
||||
Bundle re = new Bundle();
|
||||
@@ -444,6 +668,45 @@ public final class GalleryCommentsScene extends ToolbarScene
|
||||
if (mEditText != null) {
|
||||
mEditText.setText("");
|
||||
}
|
||||
|
||||
updateView(true);
|
||||
}
|
||||
|
||||
private void onVoteCommentSuccess(VoteCommentParser.Result result) {
|
||||
if (null == mAdapter || null == mComments) {
|
||||
return;
|
||||
}
|
||||
|
||||
int position = -1;
|
||||
for (int i = 0, n = mComments.length; i < n; i++) {
|
||||
GalleryComment comment = mComments[i];
|
||||
if (comment.id == result.id) {
|
||||
position = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (-1 == position) {
|
||||
Log.d(TAG, "Can't find comment with id " + result.id);
|
||||
return;
|
||||
}
|
||||
|
||||
// Update comment
|
||||
GalleryComment comment = mComments[position];
|
||||
comment.score = result.score;
|
||||
if (result.expectVote > 0) {
|
||||
comment.voteUp = 0 != result.vote;
|
||||
comment.voteDown = false;
|
||||
} else {
|
||||
comment.voteDown = 0 != result.vote;
|
||||
comment.voteUp = false;
|
||||
}
|
||||
|
||||
mAdapter.notifyItemChanged(position);
|
||||
|
||||
Bundle re = new Bundle();
|
||||
re.putParcelableArray(KEY_COMMENTS, mComments);
|
||||
setResult(SceneFragment.RESULT_OK, re);
|
||||
}
|
||||
|
||||
private static class CommentGalleryListener extends EhCallback<GalleryCommentsScene, GalleryComment[]> {
|
||||
@@ -476,4 +739,37 @@ public final class GalleryCommentsScene extends ToolbarScene
|
||||
return scene instanceof GalleryCommentsScene;
|
||||
}
|
||||
}
|
||||
|
||||
private static class VoteCommentListener extends EhCallback<GalleryCommentsScene, VoteCommentParser.Result> {
|
||||
|
||||
public VoteCommentListener(Context context, int stageId, String sceneTag) {
|
||||
super(context, stageId, sceneTag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess(VoteCommentParser.Result result) {
|
||||
showTip(result.expectVote > 0 ?
|
||||
(0 != result.vote ? R.string.vote_up_successfully : R.string.cancel_vote_up_successfully) :
|
||||
(0 != result.vote ? R.string.vote_down_successfully : R.string.cancel_vote_down_successfully),
|
||||
LENGTH_SHORT);
|
||||
|
||||
GalleryCommentsScene scene = getScene();
|
||||
if (scene != null) {
|
||||
scene.onVoteCommentSuccess(result);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Exception e) {
|
||||
showTip(R.string.vote_failed, LENGTH_SHORT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCancel() {}
|
||||
|
||||
@Override
|
||||
public boolean isInstance(SceneFragment scene) {
|
||||
return scene instanceof GalleryCommentsScene;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,6 @@
|
||||
package com.hippo.ehviewer.ui.scene;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.Activity;
|
||||
import android.app.Dialog;
|
||||
import android.app.DownloadManager;
|
||||
@@ -36,6 +35,7 @@ import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentTransaction;
|
||||
import android.support.v4.view.ViewCompat;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.support.v7.widget.PopupMenu;
|
||||
import android.text.TextUtils;
|
||||
@@ -45,7 +45,6 @@ import android.view.Gravity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewAnimationUtils;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
@@ -55,10 +54,13 @@ import android.widget.ListView;
|
||||
import android.widget.RatingBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.hippo.beerbelly.BeerBelly;
|
||||
import com.hippo.drawable.RoundSideRectDrawable;
|
||||
import com.hippo.ehviewer.AppConfig;
|
||||
import com.hippo.ehviewer.EhApplication;
|
||||
import com.hippo.ehviewer.EhDB;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.Settings;
|
||||
import com.hippo.ehviewer.UrlOpener;
|
||||
import com.hippo.ehviewer.client.EhCacheKeyFactory;
|
||||
import com.hippo.ehviewer.client.EhClient;
|
||||
@@ -79,14 +81,15 @@ import com.hippo.ehviewer.ui.CommonOperations;
|
||||
import com.hippo.ehviewer.ui.GalleryActivity;
|
||||
import com.hippo.ehviewer.ui.MainActivity;
|
||||
import com.hippo.ehviewer.ui.annotation.WholeLifeCircle;
|
||||
import com.hippo.rippleold.RippleSalon;
|
||||
import com.hippo.reveal.ViewAnimationUtils;
|
||||
import com.hippo.ripple.Ripple;
|
||||
import com.hippo.scene.Announcer;
|
||||
import com.hippo.scene.SceneFragment;
|
||||
import com.hippo.scene.TransitionHelper;
|
||||
import com.hippo.text.Html;
|
||||
import com.hippo.text.URLImageGetter;
|
||||
import com.hippo.util.ActivityHelper;
|
||||
import com.hippo.util.ApiHelper;
|
||||
import com.hippo.util.AppHelper;
|
||||
import com.hippo.util.DrawableManager;
|
||||
import com.hippo.util.ExceptionUtils;
|
||||
import com.hippo.util.ReadableTime;
|
||||
@@ -97,9 +100,14 @@ import com.hippo.widget.ProgressView;
|
||||
import com.hippo.widget.ProgressiveRatingBar;
|
||||
import com.hippo.widget.SimpleGridAutoSpanLayout;
|
||||
import com.hippo.yorozuya.AssertUtils;
|
||||
import com.hippo.yorozuya.IOUtils;
|
||||
import com.hippo.yorozuya.SimpleHandler;
|
||||
import com.hippo.yorozuya.ViewUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.util.List;
|
||||
@@ -197,6 +205,8 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
|
||||
private TextView mRate;
|
||||
@Nullable
|
||||
private TextView mSimilar;
|
||||
@Nullable
|
||||
private TextView mSearchCover;
|
||||
// Tags
|
||||
@Nullable
|
||||
private LinearLayout mTags;
|
||||
@@ -421,9 +431,9 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
|
||||
mActionGroup = (ViewGroup) ViewUtils.$$(mHeader, R.id.action_card);
|
||||
mDownload = (TextView) ViewUtils.$$(mActionGroup, R.id.download);
|
||||
mRead = ViewUtils.$$(mActionGroup, R.id.read);
|
||||
RippleSalon.addRipple(mOtherActions, false);
|
||||
RippleSalon.addRipple(mDownload, false);
|
||||
RippleSalon.addRipple(mRead, false);
|
||||
Ripple.addRipple(mOtherActions, false);
|
||||
Ripple.addRipple(mDownload, false);
|
||||
Ripple.addRipple(mRead, false);
|
||||
mUploader.setOnClickListener(this);
|
||||
mCategory.setOnClickListener(this);
|
||||
mOtherActions.setOnClickListener(this);
|
||||
@@ -442,7 +452,7 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
|
||||
mSize = (TextView) ViewUtils.$$(mInfo, R.id.size);
|
||||
mPosted = (TextView) ViewUtils.$$(mInfo, R.id.posted);
|
||||
mFavoredTimes = (TextView) ViewUtils.$$(mInfo, R.id.favoredTimes);
|
||||
RippleSalon.addRipple(mInfo, false);
|
||||
Ripple.addRipple(mInfo, false);
|
||||
mInfo.setOnClickListener(this);
|
||||
|
||||
mActions = ViewUtils.$$(belowHeader, R.id.actions);
|
||||
@@ -455,16 +465,19 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
|
||||
mShare = (TextView) ViewUtils.$$(mActions, R.id.share);
|
||||
mRate = (TextView) ViewUtils.$$(mActions, R.id.rate);
|
||||
mSimilar = (TextView) ViewUtils.$$(mActions, R.id.similar);
|
||||
RippleSalon.addRipple(mHeartGroup, false);
|
||||
RippleSalon.addRipple(mTorrent, false);
|
||||
RippleSalon.addRipple(mShare, false);
|
||||
RippleSalon.addRipple(mRate, false);
|
||||
RippleSalon.addRipple(mSimilar, false);
|
||||
mSearchCover = (TextView) ViewUtils.$$(mActions, R.id.search_cover);
|
||||
Ripple.addRipple(mHeartGroup, false);
|
||||
Ripple.addRipple(mTorrent, false);
|
||||
Ripple.addRipple(mShare, false);
|
||||
Ripple.addRipple(mRate, false);
|
||||
Ripple.addRipple(mSimilar, false);
|
||||
Ripple.addRipple(mSearchCover, false);
|
||||
mHeartGroup.setOnClickListener(this);
|
||||
mTorrent.setOnClickListener(this);
|
||||
mShare.setOnClickListener(this);
|
||||
mRate.setOnClickListener(this);
|
||||
mSimilar.setOnClickListener(this);
|
||||
mSearchCover.setOnClickListener(this);
|
||||
ensureActionDrawable(context);
|
||||
|
||||
mTags = (LinearLayout) ViewUtils.$$(belowHeader, R.id.tags);
|
||||
@@ -472,13 +485,13 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
|
||||
|
||||
mComments = (LinearLayout) ViewUtils.$$(belowHeader, R.id.comments);
|
||||
mCommentsText = (TextView) ViewUtils.$$(mComments, R.id.comments_text);
|
||||
RippleSalon.addRipple(mComments, false);
|
||||
Ripple.addRipple(mComments, false);
|
||||
mComments.setOnClickListener(this);
|
||||
|
||||
mPreviews = ViewUtils.$$(belowHeader, R.id.previews);
|
||||
mGridLayout = (SimpleGridAutoSpanLayout) ViewUtils.$$(mPreviews, R.id.grid_layout);
|
||||
mPreviewText = (TextView) ViewUtils.$$(mPreviews, R.id.preview_text);
|
||||
RippleSalon.addRipple(mPreviews, false);
|
||||
Ripple.addRipple(mPreviews, false);
|
||||
mPreviews.setOnClickListener(this);
|
||||
|
||||
mProgress = ViewUtils.$$(mainView, R.id.progress);
|
||||
@@ -552,6 +565,7 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
|
||||
mShare = null;
|
||||
mRate = null;
|
||||
mSimilar = null;
|
||||
mSearchCover = null;
|
||||
|
||||
mTags = null;
|
||||
mNoTags = null;
|
||||
@@ -602,7 +616,7 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
|
||||
private boolean request() {
|
||||
Context context = getContext2();
|
||||
MainActivity activity = getActivity2();
|
||||
String url = getGalleryDetailUrl(true);
|
||||
String url = getGalleryDetailUrl(false);
|
||||
if (null == context || null == activity || null == url) {
|
||||
return false;
|
||||
}
|
||||
@@ -637,9 +651,10 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
|
||||
setActionDrawable(mRate, rate);
|
||||
Drawable similar = DrawableManager.getDrawable(context, R.drawable.v_similar_primary_x48);
|
||||
setActionDrawable(mSimilar, similar);
|
||||
Drawable searchCover = DrawableManager.getDrawable(context, R.drawable.v_file_find_primary_x48);
|
||||
setActionDrawable(mSearchCover, searchCover);
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
||||
private boolean createCircularReveal() {
|
||||
if (mColorBg == null) {
|
||||
return false;
|
||||
@@ -647,7 +662,7 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
|
||||
|
||||
int w = mColorBg.getWidth();
|
||||
int h = mColorBg.getHeight();
|
||||
if (mColorBg.isAttachedToWindow() && w != 0 && h != 0) {
|
||||
if (ViewCompat.isAttachedToWindow(mColorBg) && w != 0 && h != 0) {
|
||||
ViewAnimationUtils.createCircularReveal(mColorBg, w / 2, h / 2, 0,
|
||||
(float) Math.hypot(w / 2, h / 2)).setDuration(300).start();
|
||||
return true;
|
||||
@@ -692,8 +707,7 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
|
||||
break;
|
||||
}
|
||||
|
||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP &&
|
||||
(oldState == STATE_INIT || oldState == STATE_FAILED || oldState == STATE_REFRESH) &&
|
||||
if ((oldState == STATE_INIT || oldState == STATE_FAILED || oldState == STATE_REFRESH) &&
|
||||
(state == STATE_NORMAL || state == STATE_REFRESH_HEADER)) {
|
||||
if (!createCircularReveal()) {
|
||||
SimpleHandler.getInstance().post(new Runnable() {
|
||||
@@ -881,7 +895,7 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
|
||||
mPreviewText.setText(R.string.more_previews);
|
||||
}
|
||||
|
||||
int columnWidth = resources.getDimensionPixelOffset(R.dimen.preview_grid_column_width);
|
||||
int columnWidth = resources.getDimensionPixelOffset(Settings.getThumbSizeResId());
|
||||
mGridLayout.setColumnSize(columnWidth);
|
||||
mGridLayout.setStrategy(SimpleGridAutoSpanLayout.STRATEGY_SUITABLE_SIZE);
|
||||
for (int i = 0, size = previewSet.size(); i < size; i++) {
|
||||
@@ -899,7 +913,7 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
|
||||
|
||||
private static String getRatingText(float rating, Resources resources) {
|
||||
String undefine = "(´_ゝ`)";
|
||||
if (Float.isNaN(rating)) {
|
||||
if (-1.0f == rating) {
|
||||
return undefine;
|
||||
}
|
||||
|
||||
@@ -942,12 +956,12 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
|
||||
return resources.getString(R.string.rating_text, getRatingText(rating, resources), rating, ratingCount);
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
||||
private void setTransitionName() {
|
||||
long gid = getGid();
|
||||
|
||||
if (gid != -1 && ApiHelper.SUPPORT_TRANSITION && mThumb != null &&
|
||||
mTitle != null && mUploader != null && mCategory != null) {
|
||||
mTitle != null && mUploader != null && mCategory != null &&
|
||||
Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
mThumb.setTransitionName(TransitionNameFactory.getThumbTransitionName(gid));
|
||||
mTitle.setTransitionName(TransitionNameFactory.getTitleTransitionName(gid));
|
||||
mUploader.setTransitionName(TransitionNameFactory.getUploaderTransitionName(gid));
|
||||
@@ -973,7 +987,7 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
|
||||
String url = getGalleryDetailUrl(false);
|
||||
Activity activity = getActivity2();
|
||||
if (null != url && null != activity) {
|
||||
UrlOpener.openUrl(activity, url, false, false);
|
||||
UrlOpener.openUrl(activity, url, false);
|
||||
}
|
||||
break;
|
||||
case R.id.action_refresh:
|
||||
@@ -1030,6 +1044,39 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
|
||||
}
|
||||
}
|
||||
|
||||
private void showCoverGalleryList() {
|
||||
Context context = getContext2();
|
||||
if (null == context) {
|
||||
return;
|
||||
}
|
||||
long gid = getGid();
|
||||
if (-1L == gid) {
|
||||
return;
|
||||
}
|
||||
File temp = AppConfig.createTempFile();
|
||||
if (null == temp) {
|
||||
return;
|
||||
}
|
||||
BeerBelly beerBelly = EhApplication.getConaco(context).getBeerBelly();
|
||||
|
||||
OutputStream os = null;
|
||||
try {
|
||||
os = new FileOutputStream(temp);
|
||||
if (beerBelly.pullFromDiskCache(EhCacheKeyFactory.getThumbKey(gid), os)) {
|
||||
ListUrlBuilder lub = new ListUrlBuilder();
|
||||
lub.setMode(ListUrlBuilder.MODE_IMAGE_SEARCH);
|
||||
lub.setImagePath(temp.getPath());
|
||||
lub.setUseSimilarityScan(true);
|
||||
lub.setShowExpunged(true);
|
||||
GalleryListScene.startScene(this, lub);
|
||||
}
|
||||
} catch (FileNotFoundException e) {
|
||||
// Ignore
|
||||
} finally {
|
||||
IOUtils.closeQuietly(os);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Context context = getContext2();
|
||||
@@ -1112,7 +1159,7 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
|
||||
} else if (mShare == v) {
|
||||
String url = getGalleryDetailUrl(false);
|
||||
if (url != null) {
|
||||
ActivityHelper.share(activity, url);
|
||||
AppHelper.share(activity, url);
|
||||
}
|
||||
} else if (mTorrent == v) {
|
||||
if (mGalleryDetail != null) {
|
||||
@@ -1128,6 +1175,10 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
|
||||
if (mGalleryDetail == null) {
|
||||
return;
|
||||
}
|
||||
if (mGalleryDetail.apiUid < 0) {
|
||||
showTip(R.string.sign_in_first, LENGTH_SHORT);
|
||||
return;
|
||||
}
|
||||
RateDialogHelper helper = new RateDialogHelper();
|
||||
Dialog dialog = new AlertDialog.Builder(context)
|
||||
.setTitle(R.string.rate)
|
||||
@@ -1138,11 +1189,15 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
|
||||
helper.setDialog(dialog, mGalleryDetail.rating);
|
||||
} else if (mSimilar == v) {
|
||||
showSimilarGalleryList();
|
||||
} else if (mSearchCover == v) {
|
||||
showCoverGalleryList();
|
||||
} else if (mComments == v) {
|
||||
if (mGalleryDetail == null) {
|
||||
return;
|
||||
}
|
||||
Bundle args = new Bundle();
|
||||
args.putLong(GalleryCommentsScene.KEY_API_UID, mGalleryDetail.apiUid);
|
||||
args.putString(GalleryCommentsScene.KEY_API_KEY, mGalleryDetail.apiKey);
|
||||
args.putLong(GalleryCommentsScene.KEY_GID, mGalleryDetail.gid);
|
||||
args.putString(GalleryCommentsScene.KEY_TOKEN, mGalleryDetail.token);
|
||||
args.putParcelableArray(GalleryCommentsScene.KEY_COMMENTS, mGalleryDetail.comments);
|
||||
@@ -1238,7 +1293,7 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
switch (which) {
|
||||
case 0:
|
||||
UrlOpener.openUrl(context, EhUrl.getTagDefinitionUrl(tag2), false, true);
|
||||
UrlOpener.openUrl(context, EhUrl.getTagDefinitionUrl(tag2), false);
|
||||
break;
|
||||
case 1:
|
||||
addTagFilter(tag);
|
||||
@@ -1399,7 +1454,6 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
|
||||
}
|
||||
|
||||
@Override
|
||||
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
||||
public boolean onTransition(Context context,
|
||||
FragmentTransaction transaction, Fragment exit, Fragment enter) {
|
||||
if (!(enter instanceof GalleryListScene) && !(enter instanceof DownloadsScene) &&
|
||||
@@ -1407,15 +1461,17 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
|
||||
return false;
|
||||
}
|
||||
|
||||
exit.setSharedElementReturnTransition(
|
||||
TransitionInflater.from(context).inflateTransition(R.transition.trans_move));
|
||||
exit.setExitTransition(
|
||||
TransitionInflater.from(context).inflateTransition(android.R.transition.fade));
|
||||
enter.setSharedElementEnterTransition(
|
||||
TransitionInflater.from(context).inflateTransition(R.transition.trans_move));
|
||||
enter.setEnterTransition(
|
||||
TransitionInflater.from(context).inflateTransition(android.R.transition.fade));
|
||||
transaction.addSharedElement(mThumb, mThumb.getTransitionName());
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
exit.setSharedElementReturnTransition(
|
||||
TransitionInflater.from(context).inflateTransition(R.transition.trans_move));
|
||||
exit.setExitTransition(
|
||||
TransitionInflater.from(context).inflateTransition(android.R.transition.fade));
|
||||
enter.setSharedElementEnterTransition(
|
||||
TransitionInflater.from(context).inflateTransition(R.transition.trans_move));
|
||||
enter.setEnterTransition(
|
||||
TransitionInflater.from(context).inflateTransition(android.R.transition.fade));
|
||||
transaction.addSharedElement(mThumb, mThumb.getTransitionName());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1431,7 +1487,7 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
|
||||
e.printStackTrace();
|
||||
Context context = getContext2();
|
||||
if (null != context && null != mTip) {
|
||||
String error = ExceptionUtils.getReadableString(context, e);
|
||||
String error = ExceptionUtils.getReadableString(e);
|
||||
mTip.setText(error);
|
||||
adjustViewVisibility(STATE_FAILED, true);
|
||||
}
|
||||
@@ -1603,7 +1659,7 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
|
||||
mProgressView.setVisibility(View.GONE);
|
||||
mErrorText.setVisibility(View.VISIBLE);
|
||||
mListView.setVisibility(View.GONE);
|
||||
mErrorText.setText(ExceptionUtils.getReadableString(context, e));
|
||||
mErrorText.setText(ExceptionUtils.getReadableString(e));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1690,7 +1746,8 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
|
||||
|
||||
EhRequest request = new EhRequest()
|
||||
.setMethod(EhClient.METHOD_GET_RATE_GALLERY)
|
||||
.setArgs(mGalleryDetail.gid, mGalleryDetail.token, mRatingBar.getRating())
|
||||
.setArgs(mGalleryDetail.apiUid, mGalleryDetail.apiKey,
|
||||
mGalleryDetail.gid, mGalleryDetail.token, mRatingBar.getRating())
|
||||
.setCallback(new RateGalleryListener(context,
|
||||
activity.getStageId(), getTag(), mGalleryDetail.gid));
|
||||
EhApplication.getEhClient(context).execute(request);
|
||||
|
||||
@@ -36,7 +36,7 @@ import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.client.EhUrl;
|
||||
import com.hippo.ehviewer.client.EhUtils;
|
||||
import com.hippo.ehviewer.client.data.GalleryDetail;
|
||||
import com.hippo.rippleold.RippleSalon;
|
||||
import com.hippo.ripple.Ripple;
|
||||
import com.hippo.yorozuya.AssertUtils;
|
||||
import com.hippo.yorozuya.LayoutUtils;
|
||||
import com.hippo.yorozuya.ViewUtils;
|
||||
@@ -166,7 +166,7 @@ public final class GalleryInfoScene extends ToolbarScene implements EasyRecycler
|
||||
LayoutUtils.dp2pix(context, 1));
|
||||
decoration.setPadding(context.getResources().getDimensionPixelOffset(R.dimen.keyline_margin));
|
||||
mRecyclerView.addItemDecoration(decoration);
|
||||
mRecyclerView.setSelector(RippleSalon.generateRippleDrawable(false));
|
||||
mRecyclerView.setSelector(Ripple.generateRippleDrawable(context, false));
|
||||
mRecyclerView.setClipToPadding(false);
|
||||
mRecyclerView.setHasFixedSize(true);
|
||||
mRecyclerView.setOnItemClickListener(this);
|
||||
|
||||
@@ -20,6 +20,7 @@ import android.animation.Animator;
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Point;
|
||||
import android.graphics.drawable.Drawable;
|
||||
@@ -68,28 +69,32 @@ import com.hippo.ehviewer.client.EhUrl;
|
||||
import com.hippo.ehviewer.client.EhUtils;
|
||||
import com.hippo.ehviewer.client.data.GalleryInfo;
|
||||
import com.hippo.ehviewer.client.data.ListUrlBuilder;
|
||||
import com.hippo.ehviewer.client.exception.EhException;
|
||||
import com.hippo.ehviewer.client.parser.GalleryListParser;
|
||||
import com.hippo.ehviewer.dao.QuickSearch;
|
||||
import com.hippo.ehviewer.ui.CommonOperations;
|
||||
import com.hippo.ehviewer.ui.MainActivity;
|
||||
import com.hippo.ehviewer.widget.SearchBar;
|
||||
import com.hippo.ehviewer.widget.SearchLayout;
|
||||
import com.hippo.rippleold.RippleSalon;
|
||||
import com.hippo.refreshlayout.RefreshLayout;
|
||||
import com.hippo.ripple.Ripple;
|
||||
import com.hippo.scene.Announcer;
|
||||
import com.hippo.scene.SceneFragment;
|
||||
import com.hippo.util.ApiHelper;
|
||||
import com.hippo.util.AppHelper;
|
||||
import com.hippo.util.DrawableManager;
|
||||
import com.hippo.view.ViewTransition;
|
||||
import com.hippo.widget.ContentLayout;
|
||||
import com.hippo.widget.FabLayout;
|
||||
import com.hippo.widget.SearchBarMover;
|
||||
import com.hippo.widget.refreshlayout.RefreshLayout;
|
||||
import com.hippo.yorozuya.AnimationUtils;
|
||||
import com.hippo.yorozuya.AssertUtils;
|
||||
import com.hippo.yorozuya.MathUtils;
|
||||
import com.hippo.yorozuya.SimpleAnimatorListener;
|
||||
import com.hippo.yorozuya.StringUtils;
|
||||
import com.hippo.yorozuya.ViewUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.util.List;
|
||||
@@ -106,6 +111,8 @@ public final class GalleryListScene extends BaseScene
|
||||
|
||||
private static final int BACK_PRESSED_INTERVAL = 2000;
|
||||
|
||||
public final static int REQUEST_CODE_SELECT_IMAGE = 0;
|
||||
|
||||
public final static String KEY_ACTION = "action";
|
||||
public final static String ACTION_HOMEPAGE = "action_homepage";
|
||||
public final static String ACTION_WHATS_HOT = "action_whats_hot";
|
||||
@@ -394,8 +401,8 @@ public final class GalleryListScene extends BaseScene
|
||||
mFabLayout = (FabLayout) ViewUtils.$$(mainLayout, R.id.fab_layout);
|
||||
mSearchFab = ViewUtils.$$(mainLayout, R.id.search_fab);
|
||||
|
||||
int paddingTopSB = resources.getDimensionPixelOffset(R.dimen.list_padding_top_search_bar);
|
||||
int paddingBottomFab = resources.getDimensionPixelOffset(R.dimen.list_padding_bottom_fab);
|
||||
int paddingTopSB = resources.getDimensionPixelOffset(R.dimen.gallery_padding_top_search_bar);
|
||||
int paddingBottomFab = resources.getDimensionPixelOffset(R.dimen.gallery_padding_bottom_fab);
|
||||
|
||||
mViewTransition = new ViewTransition(contentLayout, mSearchLayout);
|
||||
|
||||
@@ -406,14 +413,12 @@ public final class GalleryListScene extends BaseScene
|
||||
|
||||
mAdapter = new GalleryListAdapter(inflater, resources,
|
||||
mRecyclerView, Settings.getListMode());
|
||||
mRecyclerView.setSelector(RippleSalon.generateRippleDrawable(false));
|
||||
mRecyclerView.setSelector(Ripple.generateRippleDrawable(context, false));
|
||||
mRecyclerView.setDrawSelectorOnTop(true);
|
||||
mRecyclerView.hasFixedSize();
|
||||
mRecyclerView.setClipToPadding(false);
|
||||
mRecyclerView.setOnItemClickListener(this);
|
||||
mRecyclerView.setOnItemLongClickListener(this);
|
||||
mRecyclerView.setPadding(mRecyclerView.getPaddingLeft(), mRecyclerView.getPaddingTop() + paddingTopSB,
|
||||
mRecyclerView.getPaddingRight(), mRecyclerView.getPaddingBottom());
|
||||
mRecyclerView.addOnScrollListener(mOnScrollListener);
|
||||
|
||||
fastScroller.setPadding(fastScroller.getPaddingLeft(), fastScroller.getPaddingTop() + paddingTopSB,
|
||||
@@ -438,6 +443,7 @@ public final class GalleryListScene extends BaseScene
|
||||
mFabLayout.setHidePrimaryFab(false);
|
||||
mFabLayout.setOnClickFabListener(this);
|
||||
mFabLayout.setOnExpandListener(this);
|
||||
addAboveSnackView(mFabLayout);
|
||||
|
||||
mActionFabDrawable = new AddDeleteDrawable(context);
|
||||
mActionFabDrawable.setColor(resources.getColor(R.color.primary_drawable_dark));
|
||||
@@ -517,11 +523,14 @@ public final class GalleryListScene extends BaseScene
|
||||
mRecyclerView.stopScroll();
|
||||
mRecyclerView = null;
|
||||
}
|
||||
if (null != mFabLayout) {
|
||||
removeAboveSnackView(mFabLayout);
|
||||
mFabLayout = null;
|
||||
}
|
||||
|
||||
mAdapter = null;
|
||||
mSearchLayout = null;
|
||||
mSearchBar = null;
|
||||
mFabLayout = null;
|
||||
mSearchFab = null;
|
||||
mViewTransition = null;
|
||||
mLeftDrawable = null;
|
||||
@@ -557,6 +566,12 @@ public final class GalleryListScene extends BaseScene
|
||||
return;
|
||||
}
|
||||
|
||||
// Can't add image search as quick search
|
||||
if (ListUrlBuilder.MODE_IMAGE_SEARCH == urlBuilder.getMode()) {
|
||||
showTip(R.string.image_search_not_quick_search, LENGTH_SHORT);
|
||||
return;
|
||||
}
|
||||
|
||||
// Check duplicate
|
||||
for (QuickSearch q: list) {
|
||||
if (urlBuilder.equalsQuickSearch(q)) {
|
||||
@@ -793,6 +808,7 @@ public final class GalleryListScene extends BaseScene
|
||||
}
|
||||
builder.setError(null);
|
||||
mHelper.goTo(goTo);
|
||||
AppHelper.hideSoftInput(dialog);
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
@@ -869,7 +885,8 @@ public final class GalleryListScene extends BaseScene
|
||||
mShowActionFab = true;
|
||||
View fab = mFabLayout.getPrimaryFab();
|
||||
fab.setVisibility(View.VISIBLE);
|
||||
fab.animate().scaleX(1.0f).scaleY(1.0f).setListener(null)
|
||||
fab.setRotation(-45.0f);
|
||||
fab.animate().scaleX(1.0f).scaleY(1.0f).rotation(0.0f).setListener(null)
|
||||
.setDuration(ANIMATE_TIME).setStartDelay(0L)
|
||||
.setInterpolator(AnimationUtils.FAST_SLOW_INTERPOLATOR).start();
|
||||
}
|
||||
@@ -904,7 +921,8 @@ public final class GalleryListScene extends BaseScene
|
||||
.setInterpolator(AnimationUtils.SLOW_FAST_INTERPOLATOR).start();
|
||||
}
|
||||
mSearchFab.setVisibility(View.VISIBLE);
|
||||
mSearchFab.animate().scaleX(1.0f).scaleY(1.0f).setListener(null)
|
||||
mSearchFab.setRotation(-45.0f);
|
||||
mSearchFab.animate().scaleX(1.0f).scaleY(1.0f).rotation(0.0f).setListener(null)
|
||||
.setDuration(ANIMATE_TIME).setStartDelay(delay)
|
||||
.setInterpolator(AnimationUtils.FAST_SLOW_INTERPOLATOR).start();
|
||||
} else {
|
||||
@@ -915,7 +933,7 @@ public final class GalleryListScene extends BaseScene
|
||||
fab.setScaleY(0.0f);
|
||||
mSearchFab.setVisibility(View.VISIBLE);
|
||||
mSearchFab.setScaleX(1.0f);
|
||||
mSearchFab.setScaleX(1.0f);
|
||||
mSearchFab.setScaleY(1.0f);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -938,7 +956,8 @@ public final class GalleryListScene extends BaseScene
|
||||
}
|
||||
View fab = mFabLayout.getPrimaryFab();
|
||||
fab.setVisibility(View.VISIBLE);
|
||||
fab.animate().scaleX(1.0f).scaleY(1.0f).setListener(null)
|
||||
fab.setRotation(-45.0f);
|
||||
fab.animate().scaleX(1.0f).scaleY(1.0f).rotation(0.0f).setListener(null)
|
||||
.setDuration(ANIMATE_TIME).setStartDelay(delay)
|
||||
.setInterpolator(AnimationUtils.FAST_SLOW_INTERPOLATOR).start();
|
||||
|
||||
@@ -950,7 +969,7 @@ public final class GalleryListScene extends BaseScene
|
||||
fab.setScaleY(1.0f);
|
||||
mSearchFab.setVisibility(View.INVISIBLE);
|
||||
mSearchFab.setScaleX(0.0f);
|
||||
mSearchFab.setScaleX(0.0f);
|
||||
mSearchFab.setScaleY(0.0f);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1111,7 +1130,12 @@ public final class GalleryListScene extends BaseScene
|
||||
startScene(new Announcer(GalleryDetailScene.class).setArgs(args));
|
||||
return;
|
||||
} else {
|
||||
mSearchLayout.formatListUrlBuilder(mUrlBuilder, query);
|
||||
try {
|
||||
mSearchLayout.formatListUrlBuilder(mUrlBuilder, query);
|
||||
} catch (EhException e) {
|
||||
showTip(e.getMessage(), LENGTH_LONG);
|
||||
return;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
mUrlBuilder.reset();
|
||||
@@ -1177,6 +1201,15 @@ public final class GalleryListScene extends BaseScene
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSelectImage() {
|
||||
Intent intent = new Intent();
|
||||
intent.setType("image/*");
|
||||
intent.setAction(Intent.ACTION_GET_CONTENT);
|
||||
startActivityForResult(Intent.createChooser(intent,
|
||||
getString(R.string.select_image)), REQUEST_CODE_SELECT_IMAGE);
|
||||
}
|
||||
|
||||
// SearchBarMover.Helper
|
||||
@Override
|
||||
public boolean isValidView(RecyclerView recyclerView) {
|
||||
@@ -1201,10 +1234,25 @@ public final class GalleryListScene extends BaseScene
|
||||
}
|
||||
|
||||
public static void startScene(SceneFragment scene, ListUrlBuilder lub) {
|
||||
scene.startScene(getStartAnnouncer(lub));
|
||||
}
|
||||
|
||||
public static Announcer getStartAnnouncer(ListUrlBuilder lub) {
|
||||
Bundle args = new Bundle();
|
||||
args.putString(KEY_ACTION, ACTION_LIST_URL_BUILDER);
|
||||
args.putParcelable(KEY_LIST_URL_BUILDER, lub);
|
||||
scene.startScene(new Announcer(GalleryListScene.class).setArgs(args));
|
||||
return new Announcer(GalleryListScene.class).setArgs(args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
if (REQUEST_CODE_SELECT_IMAGE == requestCode) {
|
||||
if (Activity.RESULT_OK == resultCode && null != mSearchLayout && null != data) {
|
||||
mSearchLayout.setImageUri(data.getData());
|
||||
}
|
||||
} else {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
}
|
||||
}
|
||||
|
||||
private class GalleryListAdapter extends GalleryAdapter {
|
||||
@@ -1243,6 +1291,15 @@ public final class GalleryListScene extends BaseScene
|
||||
activity.getStageId(), getTag(), taskId));
|
||||
request.setArgs();
|
||||
mClient.execute(request);
|
||||
} else if (ListUrlBuilder.MODE_IMAGE_SEARCH == mUrlBuilder.getMode()) {
|
||||
EhRequest request = new EhRequest();
|
||||
request.setMethod(EhClient.METHOD_IMAGE_SEARCH);
|
||||
request.setCallback(new GetGalleryListListener(getContext(),
|
||||
activity.getStageId(), getTag(), taskId));
|
||||
request.setArgs(new File(StringUtils.avoidNull(mUrlBuilder.getImagePath())),
|
||||
mUrlBuilder.isUseSimilarityScan(),
|
||||
mUrlBuilder.isOnlySearchCovers(), mUrlBuilder.isShowExpunged());
|
||||
mClient.execute(request);
|
||||
} else {
|
||||
String url = mUrlBuilder.build();
|
||||
EhRequest request = new EhRequest();
|
||||
|
||||
@@ -38,6 +38,7 @@ import com.hippo.easyrecyclerview.EasyRecyclerView;
|
||||
import com.hippo.easyrecyclerview.MarginItemDecoration;
|
||||
import com.hippo.ehviewer.EhApplication;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.Settings;
|
||||
import com.hippo.ehviewer.client.EhClient;
|
||||
import com.hippo.ehviewer.client.EhRequest;
|
||||
import com.hippo.ehviewer.client.EhUrl;
|
||||
@@ -141,15 +142,16 @@ public class GalleryPreviewsScene extends ToolbarScene implements EasyRecyclerVi
|
||||
|
||||
mAdapter = new GalleryPreviewAdapter();
|
||||
mRecyclerView.setAdapter(mAdapter);
|
||||
int columnWidth = resources.getDimensionPixelOffset(R.dimen.preview_grid_column_width);
|
||||
int columnWidth = resources.getDimensionPixelOffset(Settings.getThumbSizeResId());
|
||||
AutoGridLayoutManager layoutManager = new AutoGridLayoutManager(context, columnWidth);
|
||||
layoutManager.setStrategy(AutoGridLayoutManager.STRATEGY_SUITABLE_SIZE);
|
||||
mRecyclerView.setLayoutManager(layoutManager);
|
||||
int padding = LayoutUtils.dp2pix(context, 4);
|
||||
mRecyclerView.setPadding(padding, padding, padding, padding);
|
||||
mRecyclerView.setClipToPadding(false);
|
||||
mRecyclerView.addItemDecoration(new MarginItemDecoration(padding));
|
||||
mRecyclerView.setOnItemClickListener(this);
|
||||
int padding = LayoutUtils.dp2pix(context, 4);
|
||||
MarginItemDecoration decoration = new MarginItemDecoration(padding, padding, padding, padding, padding);
|
||||
mRecyclerView.addItemDecoration(decoration);
|
||||
decoration.applyPaddings(mRecyclerView);
|
||||
|
||||
mHelper = new GalleryPreviewHelper();
|
||||
contentLayout.setHelper(mHelper);
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package com.hippo.ehviewer.ui.scene;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.res.Resources;
|
||||
@@ -25,8 +24,8 @@ import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.support.v7.widget.StaggeredGridLayoutManager;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
@@ -46,6 +45,7 @@ import com.h6ah4i.android.widget.advrecyclerview.utils.AbstractSwipeableItemView
|
||||
import com.hippo.easyrecyclerview.EasyRecyclerView;
|
||||
import com.hippo.easyrecyclerview.FastScroller;
|
||||
import com.hippo.easyrecyclerview.HandlerDrawable;
|
||||
import com.hippo.easyrecyclerview.MarginItemDecoration;
|
||||
import com.hippo.ehviewer.EhDB;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.client.EhCacheKeyFactory;
|
||||
@@ -55,13 +55,14 @@ import com.hippo.ehviewer.dao.HistoryInfo;
|
||||
import com.hippo.ehviewer.ui.CommonOperations;
|
||||
import com.hippo.ehviewer.ui.MainActivity;
|
||||
import com.hippo.ehviewer.widget.SimpleRatingView;
|
||||
import com.hippo.rippleold.RippleSalon;
|
||||
import com.hippo.ripple.Ripple;
|
||||
import com.hippo.scene.Announcer;
|
||||
import com.hippo.scene.SceneFragment;
|
||||
import com.hippo.util.ApiHelper;
|
||||
import com.hippo.util.DrawableManager;
|
||||
import com.hippo.view.ViewTransition;
|
||||
import com.hippo.widget.LoadImageView;
|
||||
import com.hippo.widget.recyclerview.AutoStaggeredGridLayoutManager;
|
||||
import com.hippo.yorozuya.AssertUtils;
|
||||
import com.hippo.yorozuya.ResourcesUtils;
|
||||
import com.hippo.yorozuya.ViewUtils;
|
||||
@@ -119,17 +120,23 @@ public class HistoryScene extends ToolbarScene
|
||||
final GeneralItemAnimator animator = new SwipeDismissItemAnimator();
|
||||
animator.setSupportsChangeAnimations(false);
|
||||
mRecyclerView.setItemAnimator(animator);
|
||||
LinearLayoutManager layoutManager = new LinearLayoutManager(context);
|
||||
AutoStaggeredGridLayoutManager layoutManager = new AutoStaggeredGridLayoutManager(
|
||||
0, StaggeredGridLayoutManager.VERTICAL);
|
||||
layoutManager.setColumnSize(resources.getDimensionPixelOffset(R.dimen.gallery_list_column_width));
|
||||
layoutManager.setStrategy(AutoStaggeredGridLayoutManager.STRATEGY_MIN_SIZE);
|
||||
mRecyclerView.setLayoutManager(layoutManager);
|
||||
mRecyclerView.setSelector(RippleSalon.generateRippleDrawable(false));
|
||||
mRecyclerView.setSelector(Ripple.generateRippleDrawable(context, false));
|
||||
mRecyclerView.setDrawSelectorOnTop(true);
|
||||
mRecyclerView.hasFixedSize();
|
||||
mRecyclerView.setClipToPadding(false);
|
||||
mRecyclerView.setOnItemClickListener(this);
|
||||
mRecyclerView.setOnItemLongClickListener(this);
|
||||
int paddingH = resources.getDimensionPixelOffset(R.dimen.list_content_margin_h);
|
||||
int paddingV = resources.getDimensionPixelOffset(R.dimen.list_content_margin_v);
|
||||
mRecyclerView.setPadding(paddingV, paddingH, paddingV, paddingH);
|
||||
int interval = resources.getDimensionPixelOffset(R.dimen.gallery_list_interval);
|
||||
int paddingH = resources.getDimensionPixelOffset(R.dimen.gallery_list_margin_h);
|
||||
int paddingV = resources.getDimensionPixelOffset(R.dimen.gallery_list_margin_v);
|
||||
MarginItemDecoration decoration = new MarginItemDecoration(interval, paddingH, paddingV, paddingH, paddingV);
|
||||
mRecyclerView.addItemDecoration(decoration);
|
||||
decoration.applyPaddings(mRecyclerView);
|
||||
guardManager.attachRecyclerView(mRecyclerView);
|
||||
swipeManager.attachRecyclerView(mRecyclerView);
|
||||
|
||||
@@ -334,7 +341,6 @@ public class HistoryScene extends ToolbarScene
|
||||
}
|
||||
|
||||
@Override
|
||||
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
||||
public void onBindViewHolder(HistoryHolder holder, int position) {
|
||||
if (null == mLazyList) {
|
||||
return;
|
||||
@@ -355,7 +361,7 @@ public class HistoryScene extends ToolbarScene
|
||||
holder.simpleLanguage.setText(gi.simpleLanguage);
|
||||
|
||||
// Update transition name
|
||||
if (ApiHelper.SUPPORT_TRANSITION) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
long gid = gi.gid;
|
||||
holder.thumb.setTransitionName(TransitionNameFactory.getThumbTransitionName(gid));
|
||||
}
|
||||
|
||||
@@ -226,7 +226,7 @@ public final class ProgressScene extends BaseScene implements View.OnClickListen
|
||||
|
||||
if (null != context && null != mViewTransition && null != mTip) {
|
||||
// Show tip
|
||||
mError = ExceptionUtils.getReadableString(context, e);
|
||||
mError = ExceptionUtils.getReadableString(e);
|
||||
mViewTransition.showView(1);
|
||||
mTip.setText(mError);
|
||||
}
|
||||
|
||||
@@ -29,7 +29,6 @@ import android.view.ViewGroup;
|
||||
import android.view.inputmethod.EditorInfo;
|
||||
import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.hippo.ehviewer.EhApplication;
|
||||
import com.hippo.ehviewer.R;
|
||||
@@ -43,7 +42,6 @@ import com.hippo.ehviewer.client.parser.ProfileParser;
|
||||
import com.hippo.ehviewer.ui.MainActivity;
|
||||
import com.hippo.scene.Announcer;
|
||||
import com.hippo.scene.SceneFragment;
|
||||
import com.hippo.util.ExceptionUtils;
|
||||
import com.hippo.yorozuya.AssertUtils;
|
||||
import com.hippo.yorozuya.ViewUtils;
|
||||
|
||||
@@ -144,7 +142,7 @@ public final class SignInScene extends BaseScene implements EditText.OnEditorAct
|
||||
mSkipSigningIn.setOnClickListener(this);
|
||||
|
||||
Context context = getContext2();
|
||||
AssertUtils.assertNotNull(container);
|
||||
AssertUtils.assertNotNull(context);
|
||||
EhApplication application = (EhApplication) context.getApplicationContext();
|
||||
if (application.containGlobalStuff(mRequestId)) {
|
||||
mSigningIn = true;
|
||||
@@ -219,7 +217,7 @@ public final class SignInScene extends BaseScene implements EditText.OnEditorAct
|
||||
}
|
||||
|
||||
if (mRegister == v) {
|
||||
UrlOpener.openUrl(activity, EhUrl.URL_REGISTER, false, true);
|
||||
UrlOpener.openUrl(activity, EhUrl.URL_REGISTER, false);
|
||||
} else if (mSignIn == v) {
|
||||
signIn();
|
||||
} else if (mSignInViaWebView == v) {
|
||||
@@ -329,12 +327,11 @@ public final class SignInScene extends BaseScene implements EditText.OnEditorAct
|
||||
new AlertDialog.Builder(context)
|
||||
.setTitle(R.string.sign_in_failed)
|
||||
.setMessage(R.string.sign_in_failed_plain)
|
||||
.setNegativeButton(android.R.string.cancel, null)
|
||||
.setPositiveButton(R.string.get_it, null)
|
||||
.show();
|
||||
}
|
||||
|
||||
public void onSignInSuccess() {
|
||||
public void onSignInEnd() {
|
||||
Context context = getContext2();
|
||||
if (null == context) {
|
||||
return;
|
||||
@@ -349,38 +346,12 @@ public final class SignInScene extends BaseScene implements EditText.OnEditorAct
|
||||
}
|
||||
}
|
||||
|
||||
public void onSignInFailure(Exception e) {
|
||||
Context context = getContext2();
|
||||
if (null == context) {
|
||||
return;
|
||||
}
|
||||
|
||||
mSigningIn = false;
|
||||
Toast.makeText(context, ExceptionUtils.getReadableString(context, e),
|
||||
Toast.LENGTH_SHORT).show();
|
||||
hideProgress();
|
||||
whetherToSkip();
|
||||
}
|
||||
|
||||
public void onGetProfileSuccess() {
|
||||
public void onGetProfileEnd() {
|
||||
mSigningIn = false;
|
||||
updateAvatar();
|
||||
redirectTo();
|
||||
}
|
||||
|
||||
public void onGetProfileFailure(Exception e) {
|
||||
Context context = getContext2();
|
||||
if (null == context) {
|
||||
return;
|
||||
}
|
||||
|
||||
mSigningIn = false;
|
||||
Toast.makeText(context, ExceptionUtils.getReadableString(context, e),
|
||||
Toast.LENGTH_SHORT).show();
|
||||
hideProgress();
|
||||
whetherToSkip();
|
||||
}
|
||||
|
||||
private class SignInListener extends EhCallback<SignInScene, String> {
|
||||
|
||||
public SignInListener(Context context, int stageId, String sceneTag) {
|
||||
@@ -394,7 +365,7 @@ public final class SignInScene extends BaseScene implements EditText.OnEditorAct
|
||||
|
||||
SignInScene scene = getScene();
|
||||
if (scene != null) {
|
||||
scene.onSignInSuccess();
|
||||
scene.onSignInEnd();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -405,7 +376,7 @@ public final class SignInScene extends BaseScene implements EditText.OnEditorAct
|
||||
|
||||
SignInScene scene = getScene();
|
||||
if (scene != null) {
|
||||
scene.onSignInFailure(e);
|
||||
scene.onSignInEnd();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -434,7 +405,7 @@ public final class SignInScene extends BaseScene implements EditText.OnEditorAct
|
||||
|
||||
SignInScene scene = getScene();
|
||||
if (scene != null) {
|
||||
scene.onGetProfileSuccess();
|
||||
scene.onGetProfileEnd();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -445,7 +416,7 @@ public final class SignInScene extends BaseScene implements EditText.OnEditorAct
|
||||
|
||||
SignInScene scene = getScene();
|
||||
if (scene != null) {
|
||||
scene.onGetProfileFailure(e);
|
||||
scene.onGetProfileEnd();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,12 +18,14 @@ package com.hippo.ehviewer.ui.scene;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.webkit.CookieManager;
|
||||
import android.webkit.CookieSyncManager;
|
||||
import android.webkit.WebView;
|
||||
import android.webkit.WebViewClient;
|
||||
|
||||
@@ -63,7 +65,21 @@ public class WebViewSignInScene extends BaseScene {
|
||||
AssertUtils.assertNotNull(context);
|
||||
|
||||
EhUtils.signOut(context);
|
||||
CookieManager.getInstance().removeAllCookie();
|
||||
|
||||
// http://stackoverflow.com/questions/32284642/how-to-handle-an-uncatched-exception
|
||||
CookieManager cookieManager = CookieManager.getInstance();
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
cookieManager.flush();
|
||||
cookieManager.removeAllCookies(null);
|
||||
cookieManager.removeSessionCookies(null);
|
||||
} else {
|
||||
CookieSyncManager cookieSyncManager = CookieSyncManager.createInstance(context);
|
||||
cookieSyncManager.startSync();
|
||||
cookieManager.removeAllCookie();
|
||||
cookieManager.removeSessionCookie();
|
||||
cookieSyncManager.stopSync();
|
||||
}
|
||||
|
||||
mWebView = new WebView(context);
|
||||
mWebView.getSettings().setJavaScriptEnabled(true);
|
||||
mWebView.setWebViewClient(new LoginWebViewClient());
|
||||
@@ -105,7 +121,7 @@ public class WebViewSignInScene extends BaseScene {
|
||||
}
|
||||
|
||||
private void addCookie(Context context, String domain, Cookie cookie) {
|
||||
EhApplication.getEhCookieStore(context).add(EhCookieStore.newCookie(cookie, domain, true, true));
|
||||
EhApplication.getEhCookieStore(context).add(EhCookieStore.newCookie(cookie, domain, true, true, true));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,166 @@
|
||||
/*
|
||||
* Copyright 2016 Hippo Seven
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.hippo.ehviewer.widget;
|
||||
|
||||
import android.animation.ValueAnimator;
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.design.widget.CoordinatorLayout;
|
||||
import android.support.design.widget.Snackbar;
|
||||
import android.support.v4.view.ViewCompat;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
|
||||
import com.hippo.drawerlayout.DrawerLayout;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.yorozuya.AnimationUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@CoordinatorLayout.DefaultBehavior(EhDrawerLayout.Behavior.class)
|
||||
public class EhDrawerLayout extends DrawerLayout {
|
||||
|
||||
private List<View> mAboveSnackViewList;
|
||||
|
||||
public EhDrawerLayout(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
public EhDrawerLayout(Context context, AttributeSet attrs, int defStyle) {
|
||||
super(context, attrs, defStyle);
|
||||
}
|
||||
|
||||
public void addAboveSnackView(View view) {
|
||||
if (null == mAboveSnackViewList) {
|
||||
mAboveSnackViewList = new ArrayList<>();
|
||||
}
|
||||
mAboveSnackViewList.add(view);
|
||||
}
|
||||
|
||||
public void removeAboveSnackView(View view) {
|
||||
if (null == mAboveSnackViewList) {
|
||||
return;
|
||||
}
|
||||
mAboveSnackViewList.remove(view);
|
||||
}
|
||||
|
||||
public int getAboveSnackViewCount() {
|
||||
return null == mAboveSnackViewList ? 0 : mAboveSnackViewList.size();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public View getAboveSnackViewAt(int index) {
|
||||
if (null == mAboveSnackViewList || index < 0 || index >= mAboveSnackViewList.size()) {
|
||||
return null;
|
||||
} else {
|
||||
return mAboveSnackViewList.get(index);
|
||||
}
|
||||
}
|
||||
|
||||
public static class Behavior extends CoordinatorLayout.Behavior<EhDrawerLayout> {
|
||||
// We only support the FAB <> Snackbar shift movement on Honeycomb and above. This is
|
||||
// because we can use view translation properties which greatly simplifies the code.
|
||||
private static final boolean SNACKBAR_BEHAVIOR_ENABLED = Build.VERSION.SDK_INT >= 11;
|
||||
|
||||
@Override
|
||||
public boolean layoutDependsOn(CoordinatorLayout parent,
|
||||
EhDrawerLayout child, View dependency) {
|
||||
// We're dependent on all SnackbarLayouts (if enabled)
|
||||
return SNACKBAR_BEHAVIOR_ENABLED && dependency instanceof Snackbar.SnackbarLayout;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onDependentViewChanged(CoordinatorLayout parent, EhDrawerLayout child,
|
||||
View dependency) {
|
||||
if (dependency instanceof Snackbar.SnackbarLayout) {
|
||||
for (int i = 0, n = child.getAboveSnackViewCount(); i < n; i++) {
|
||||
View view = child.getAboveSnackViewAt(i);
|
||||
updateChildTranslationForSnackbar(parent, child, view);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void updateChildTranslationForSnackbar(CoordinatorLayout parent,
|
||||
EhDrawerLayout view, final View child) {
|
||||
final float targetTransY = getChildTranslationYForSnackbar(parent, view);
|
||||
float childTranslationY = 0.0f;
|
||||
Object obj = child.getTag(R.id.fab_translation_y);
|
||||
if (obj instanceof Float) {
|
||||
childTranslationY = (Float) obj;
|
||||
}
|
||||
if (childTranslationY == targetTransY) {
|
||||
// We're already at (or currently animating to) the target value, return...
|
||||
return;
|
||||
}
|
||||
|
||||
ValueAnimator fabTranslationYAnimator = null;
|
||||
obj = child.getTag(R.id.fab_translation_y_animator);
|
||||
if (obj instanceof ValueAnimator) {
|
||||
fabTranslationYAnimator = (ValueAnimator) obj;
|
||||
}
|
||||
// Make sure that any current animation is cancelled
|
||||
if (fabTranslationYAnimator != null && fabTranslationYAnimator.isRunning()) {
|
||||
fabTranslationYAnimator.cancel();
|
||||
}
|
||||
|
||||
final float currentTransY = ViewCompat.getTranslationY(child);
|
||||
|
||||
if (child.isShown()
|
||||
&& Math.abs(currentTransY - targetTransY) > (child.getHeight() * 0.667f)) {
|
||||
// If the FAB will be travelling by more than 2/3 of it's height, let's animate
|
||||
// it instead
|
||||
if (fabTranslationYAnimator == null) {
|
||||
fabTranslationYAnimator = ValueAnimator.ofFloat();
|
||||
fabTranslationYAnimator.setInterpolator(AnimationUtils.FAST_SLOW_INTERPOLATOR);
|
||||
fabTranslationYAnimator.addUpdateListener(
|
||||
new ValueAnimator.AnimatorUpdateListener() {
|
||||
@Override
|
||||
public void onAnimationUpdate(ValueAnimator animation) {
|
||||
ViewCompat.setTranslationY(child, (Float) animation.getAnimatedValue());
|
||||
}
|
||||
});
|
||||
child.setTag(R.id.fab_translation_y_animator, fabTranslationYAnimator);
|
||||
}
|
||||
fabTranslationYAnimator.setFloatValues(currentTransY, targetTransY);
|
||||
fabTranslationYAnimator.start();
|
||||
} else {
|
||||
// Now update the translation Y
|
||||
ViewCompat.setTranslationY(child, targetTransY);
|
||||
}
|
||||
|
||||
child.setTag(R.id.fab_translation_y, targetTransY);
|
||||
}
|
||||
|
||||
private float getChildTranslationYForSnackbar(CoordinatorLayout parent,
|
||||
EhDrawerLayout child) {
|
||||
float minOffset = 0;
|
||||
final List<View> dependencies = parent.getDependencies(child);
|
||||
for (int i = 0, z = dependencies.size(); i < z; i++) {
|
||||
final View view = dependencies.get(i);
|
||||
if (view instanceof Snackbar.SnackbarLayout && parent.doViewsOverlap(child, view)) {
|
||||
minOffset = Math.min(minOffset,
|
||||
ViewCompat.getTranslationY(view) - view.getHeight());
|
||||
}
|
||||
}
|
||||
|
||||
return minOffset;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright 2016 Hippo Seven
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.hippo.ehviewer.widget;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
|
||||
import com.hippo.drawerlayout.DrawerLayoutChild;
|
||||
import com.hippo.widget.DrawerView;
|
||||
|
||||
public class EhDrawerView extends DrawerView implements DrawerLayoutChild {
|
||||
|
||||
private int mFitPaddingTop;
|
||||
|
||||
public EhDrawerView(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public EhDrawerView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
public EhDrawerView(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFitPadding(int top, int bottom) {
|
||||
mFitPaddingTop = top;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLayoutPaddingTop() {
|
||||
return mFitPaddingTop;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLayoutPaddingBottom() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
* Copyright 2016 Hippo Seven
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.hippo.ehviewer.widget;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
import android.os.Build;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.design.widget.NavigationView;
|
||||
import android.util.AttributeSet;
|
||||
|
||||
import com.hippo.drawerlayout.DrawerLayoutChild;
|
||||
|
||||
public class EhNavigationView extends NavigationView implements DrawerLayoutChild {
|
||||
|
||||
private static final int SCRIM_COLOR = 0x44000000;
|
||||
private static final boolean DRAW_SCRIM = Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP;
|
||||
private Paint mPaint;
|
||||
private int mFitPaddingTop;
|
||||
|
||||
public EhNavigationView(Context context) {
|
||||
super(context);
|
||||
init();
|
||||
}
|
||||
|
||||
public EhNavigationView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
init();
|
||||
}
|
||||
|
||||
public EhNavigationView(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
init();
|
||||
}
|
||||
|
||||
private void init() {
|
||||
if (DRAW_SCRIM) {
|
||||
setWillNotDraw(false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(@NonNull Canvas canvas) {
|
||||
super.draw(canvas);
|
||||
|
||||
if (DRAW_SCRIM && mFitPaddingTop > 0) {
|
||||
if (null == mPaint) {
|
||||
mPaint = new Paint();
|
||||
mPaint.setColor(SCRIM_COLOR);
|
||||
}
|
||||
canvas.drawRect(0, 0, getWidth(), mFitPaddingTop, mPaint);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFitPadding(int top, int bottom) {
|
||||
mFitPaddingTop = top;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLayoutPaddingTop() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLayoutPaddingBottom() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright 2016 Hippo Seven
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.hippo.ehviewer.widget;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
|
||||
import com.hippo.drawerlayout.DrawerLayoutChild;
|
||||
import com.hippo.scene.StageLayout;
|
||||
|
||||
public class EhStageLayout extends StageLayout implements DrawerLayoutChild {
|
||||
|
||||
private int mFitPaddingTop;
|
||||
|
||||
public EhStageLayout(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public EhStageLayout(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
public EhStageLayout(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFitPadding(int top, int bottom) {
|
||||
mFitPaddingTop = top;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLayoutPaddingTop() {
|
||||
return mFitPaddingTop;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLayoutPaddingBottom() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -16,12 +16,11 @@
|
||||
|
||||
package com.hippo.ehviewer.widget;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.Context;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Paint;
|
||||
import android.os.Build;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
@@ -60,15 +59,8 @@ public class GalleryGuideView extends ViewGroup implements View.OnClickListener
|
||||
init(context);
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
||||
public GalleryGuideView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
||||
super(context, attrs, defStyleAttr, defStyleRes);
|
||||
init(context);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private void init(Context context) {
|
||||
mBgColor = context.getResources().getColor(R.color.guide_bg);
|
||||
mBgColor = ContextCompat.getColor(context, R.color.guide_bg);
|
||||
mPaint = new Paint();
|
||||
mPaint.setColor(Color.WHITE);
|
||||
mPaint.setStyle(Paint.Style.STROKE);
|
||||
|
||||
@@ -0,0 +1,242 @@
|
||||
/*
|
||||
* Copyright 2016 Hippo Seven
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.hippo.ehviewer.widget;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.net.Uri;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.view.AbsSavedState;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import com.hippo.ehviewer.AppConfig;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.client.data.ListUrlBuilder;
|
||||
import com.hippo.ehviewer.client.exception.EhException;
|
||||
import com.hippo.io.UniFileInputStreamPipe;
|
||||
import com.hippo.unifile.UniFile;
|
||||
import com.hippo.util.BitmapUtils;
|
||||
import com.hippo.yorozuya.IOUtils;
|
||||
import com.hippo.yorozuya.ViewUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
public final class ImageSearchLayout extends LinearLayout implements View.OnClickListener {
|
||||
|
||||
private static final String TAG = ImageSearchLayout.class.getSimpleName();
|
||||
|
||||
private ImageView mPreview;
|
||||
private View mSelectImage;
|
||||
private CheckBox mSearchUSS;
|
||||
private CheckBox mSearchOSC;
|
||||
private CheckBox mSearchSE;
|
||||
|
||||
private Helper mHelper;
|
||||
|
||||
@Nullable
|
||||
private String mImagePath;
|
||||
|
||||
public ImageSearchLayout(Context context) {
|
||||
super(context);
|
||||
init(context);
|
||||
}
|
||||
|
||||
public ImageSearchLayout(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
init(context);
|
||||
}
|
||||
|
||||
public ImageSearchLayout(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
init(context);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public void init(Context context) {
|
||||
setOrientation(VERTICAL);
|
||||
setDividerDrawable(context.getResources().getDrawable(R.drawable.spacer_keyline));
|
||||
setShowDividers(SHOW_DIVIDER_MIDDLE);
|
||||
LayoutInflater.from(context).inflate(R.layout.widget_image_search, this);
|
||||
|
||||
mPreview = (ImageView) ViewUtils.$$(this, R.id.preview);
|
||||
mSelectImage = ViewUtils.$$(this, R.id.select_image);
|
||||
mSearchUSS = (CheckBox) ViewUtils.$$(this, R.id.search_uss);
|
||||
mSearchOSC = (CheckBox) ViewUtils.$$(this, R.id.search_osc);
|
||||
mSearchSE = (CheckBox) ViewUtils.$$(this, R.id.search_se);
|
||||
|
||||
mSelectImage.setOnClickListener(this);
|
||||
}
|
||||
|
||||
public void setHelper(Helper helper) {
|
||||
mHelper = helper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (v == mSelectImage) {
|
||||
if (null != mHelper) {
|
||||
mHelper.onSelectImage();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setImageUri(@Nullable Uri imageUri) {
|
||||
if (null == imageUri) {
|
||||
return;
|
||||
}
|
||||
|
||||
Context context = getContext();
|
||||
UniFile file = UniFile.fromUri(context, imageUri);
|
||||
if (null == file) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
int maxSize = context.getResources().getDimensionPixelOffset(R.dimen.image_search_max_size);
|
||||
Bitmap bitmap = BitmapUtils.decodeStream(new UniFileInputStreamPipe(file), maxSize, maxSize);
|
||||
if (null == bitmap) {
|
||||
return;
|
||||
}
|
||||
File temp = AppConfig.createTempFile();
|
||||
if (null == temp) {
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO ehentai image search is bad when I'm writing this line.
|
||||
// Re-compress image will make image search failed.
|
||||
OutputStream os = null;
|
||||
try {
|
||||
os = new FileOutputStream(temp);
|
||||
bitmap.compress(Bitmap.CompressFormat.JPEG, 90, os);
|
||||
mImagePath = temp.getPath();
|
||||
mPreview.setImageBitmap(bitmap);
|
||||
mPreview.setVisibility(VISIBLE);
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
IOUtils.closeQuietly(os);
|
||||
}
|
||||
} catch (OutOfMemoryError e) {
|
||||
Log.e(TAG, "Out of memory");
|
||||
}
|
||||
}
|
||||
|
||||
private void setImagePath(@Nullable String imagePath) {
|
||||
if (null == imagePath) {
|
||||
return;
|
||||
}
|
||||
|
||||
InputStream is = null;
|
||||
try {
|
||||
is = new FileInputStream(imagePath);
|
||||
Bitmap bitmap = BitmapFactory.decodeStream(is);
|
||||
if (null == bitmap) {
|
||||
return;
|
||||
}
|
||||
mImagePath = imagePath;
|
||||
mPreview.setImageBitmap(bitmap);
|
||||
mPreview.setVisibility(VISIBLE);
|
||||
} catch (FileNotFoundException e) {
|
||||
// Ignore
|
||||
} finally {
|
||||
IOUtils.closeQuietly(is);
|
||||
}
|
||||
}
|
||||
|
||||
public void formatListUrlBuilder(ListUrlBuilder builder) throws EhException {
|
||||
if (null == mImagePath) {
|
||||
throw new EhException(getContext().getString(R.string.select_image_first));
|
||||
}
|
||||
|
||||
builder.setImagePath(mImagePath);
|
||||
builder.setUseSimilarityScan(mSearchUSS.isChecked());
|
||||
builder.setOnlySearchCovers(mSearchOSC.isChecked());
|
||||
builder.setShowExpunged(mSearchSE.isChecked());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Parcelable onSaveInstanceState() {
|
||||
Parcelable superState = super.onSaveInstanceState();
|
||||
SavedState ss = new SavedState(superState);
|
||||
ss.imagePath = mImagePath;
|
||||
return ss;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onRestoreInstanceState(Parcelable state) {
|
||||
SavedState ss = (SavedState) state;
|
||||
super.onRestoreInstanceState(ss.getSuperState());
|
||||
setImagePath(ss.imagePath);
|
||||
}
|
||||
|
||||
private static class SavedState extends AbsSavedState {
|
||||
|
||||
String imagePath;
|
||||
|
||||
/**
|
||||
* Constructor called from {@link ImageSearchLayout#onSaveInstanceState()}
|
||||
*/
|
||||
protected SavedState(Parcelable superState) {
|
||||
super(superState);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor called from {@link #CREATOR}
|
||||
*/
|
||||
protected SavedState(Parcel source) {
|
||||
super(source);
|
||||
imagePath = source.readString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel out, int flags) {
|
||||
super.writeToParcel(out, flags);
|
||||
out.writeString(imagePath);
|
||||
}
|
||||
|
||||
public static final Parcelable.Creator<SavedState> CREATOR
|
||||
= new Parcelable.Creator<SavedState>() {
|
||||
@Override
|
||||
public SavedState createFromParcel(Parcel in) {
|
||||
return new SavedState(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SavedState[] newArray(int size) {
|
||||
return new SavedState[size];
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public interface Helper {
|
||||
void onSelectImage();
|
||||
}
|
||||
}
|
||||
@@ -20,7 +20,7 @@ import android.animation.Animator;
|
||||
import android.animation.ObjectAnimator;
|
||||
import android.content.Context;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Path;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
@@ -43,6 +43,7 @@ import android.widget.ImageView;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.hippo.dict.DictManager;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.view.ViewTransition;
|
||||
import com.hippo.yorozuya.AnimationUtils;
|
||||
@@ -69,7 +70,7 @@ public class SearchBar extends FrameLayout implements View.OnClickListener,
|
||||
|
||||
private int mState = STATE_NORMAL;
|
||||
|
||||
private final Path mPath = new Path();
|
||||
private final Rect mRect = new Rect();
|
||||
private int mWidth;
|
||||
private int mHeight;
|
||||
private int mBaseHeight;
|
||||
@@ -85,6 +86,7 @@ public class SearchBar extends FrameLayout implements View.OnClickListener,
|
||||
private ViewTransition mViewTransition;
|
||||
|
||||
private SearchDatabase mSearchDatabase;
|
||||
private DictManager mDictManager;
|
||||
private List<String> mSuggestionList;
|
||||
private ArrayAdapter mSuggestionAdapter;
|
||||
|
||||
@@ -111,9 +113,10 @@ public class SearchBar extends FrameLayout implements View.OnClickListener,
|
||||
}
|
||||
|
||||
private void init(Context context) {
|
||||
setBackgroundResource(R.drawable.card_white_2dp);
|
||||
setBackgroundResource(R.drawable.card_white_no_padding_2dp);
|
||||
|
||||
mSearchDatabase = SearchDatabase.getInstance(getContext());
|
||||
mDictManager = new DictManager(getContext());
|
||||
|
||||
LayoutInflater inflater = LayoutInflater.from(context);
|
||||
inflater.inflate(R.layout.widget_search_bar, this);
|
||||
@@ -170,8 +173,11 @@ public class SearchBar extends FrameLayout implements View.OnClickListener,
|
||||
|
||||
private void updateSuggestions() {
|
||||
String prefix = mEditText.getText().toString();
|
||||
String[] dictSuggestions = mDictManager.getSuggestions(prefix);
|
||||
String[] suggestions = mSearchDatabase.getSuggestions(prefix);
|
||||
|
||||
mSuggestionList.clear();
|
||||
Collections.addAll(mSuggestionList, dictSuggestions);
|
||||
Collections.addAll(mSuggestionList, suggestions);
|
||||
if (mSuggestionList.size() == 0) {
|
||||
removeListHeader();
|
||||
@@ -425,10 +431,9 @@ public class SearchBar extends FrameLayout implements View.OnClickListener,
|
||||
public void draw(@NonNull Canvas canvas) {
|
||||
if (mInAnimation) {
|
||||
final int state = canvas.save();
|
||||
float bottom = MathUtils.lerp(mBaseHeight, mHeight, mProgress);
|
||||
mPath.rewind();
|
||||
mPath.addRect(0f, 0f, mWidth, bottom, Path.Direction.CW);
|
||||
canvas.clipPath(mPath);
|
||||
int bottom = MathUtils.lerp(mBaseHeight, mHeight, mProgress);
|
||||
mRect.set(0, 0, mWidth, bottom);
|
||||
canvas.clipRect(mRect);
|
||||
super.draw(canvas);
|
||||
canvas.restoreToCount(state);
|
||||
} else {
|
||||
@@ -480,10 +485,15 @@ public class SearchBar extends FrameLayout implements View.OnClickListener,
|
||||
|
||||
public interface Helper {
|
||||
void onClickTitle();
|
||||
|
||||
void onClickLeftIcon();
|
||||
|
||||
void onClickRightIcon();
|
||||
|
||||
void onSearchEditTextClick();
|
||||
|
||||
void onApplySearch(String query);
|
||||
|
||||
void onSearchEditTextBackPressed();
|
||||
}
|
||||
|
||||
|
||||
@@ -60,7 +60,6 @@ public class SearchDatabase {
|
||||
public String[] getSuggestions(String prefix) {
|
||||
List<String> queryList = new LinkedList<>();
|
||||
|
||||
// TODO add limit
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("SELECT * FROM ").append(TABLE_SUGGESTIONS);
|
||||
if (!TextUtils.isEmpty(prefix)) {
|
||||
|
||||
@@ -18,12 +18,12 @@ package com.hippo.ehviewer.widget;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v7.widget.AppCompatEditText;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.MotionEvent;
|
||||
import android.widget.EditText;
|
||||
|
||||
public class SearchEditText extends EditText {
|
||||
public class SearchEditText extends AppCompatEditText {
|
||||
|
||||
private SearchEditTextListener mListener;
|
||||
|
||||
|
||||
@@ -16,8 +16,10 @@
|
||||
|
||||
package com.hippo.ehviewer.widget;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Parcelable;
|
||||
import android.support.annotation.IntDef;
|
||||
@@ -37,9 +39,11 @@ import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.hippo.easyrecyclerview.EasyRecyclerView;
|
||||
import com.hippo.easyrecyclerview.MarginItemDecoration;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.client.data.ListUrlBuilder;
|
||||
import com.hippo.rippleold.RippleSalon;
|
||||
import com.hippo.ehviewer.client.exception.EhException;
|
||||
import com.hippo.ripple.Ripple;
|
||||
import com.hippo.widget.RadioGridGroup;
|
||||
import com.hippo.yorozuya.ViewUtils;
|
||||
|
||||
@@ -47,9 +51,9 @@ import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
public class SearchLayout extends EasyRecyclerView implements CompoundButton.OnCheckedChangeListener,
|
||||
View.OnClickListener {
|
||||
View.OnClickListener, ImageSearchLayout.Helper {
|
||||
|
||||
@IntDef({SEARCH_MODE_NORMAL, SEARCH_MODE_IMAGE, SEARCH_MODE_SPECIFY})
|
||||
@IntDef({SEARCH_MODE_NORMAL, SEARCH_MODE_IMAGE})
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
private @interface SearchMode {}
|
||||
|
||||
@@ -59,22 +63,19 @@ public class SearchLayout extends EasyRecyclerView implements CompoundButton.OnC
|
||||
|
||||
public static final int SEARCH_MODE_NORMAL = 0;
|
||||
public static final int SEARCH_MODE_IMAGE = 1;
|
||||
public static final int SEARCH_MODE_SPECIFY = 2;
|
||||
|
||||
private static final int ITEM_TYPE_NORMAL = 0;
|
||||
private static final int ITEM_TYPE_NORMAL_ADVANCE = 1;
|
||||
private static final int ITEM_TYPE_IMAGE = 2;
|
||||
private static final int ITEM_TYPE_SPECIFY = 3;
|
||||
private static final int ITEM_TYPE_ACTION = 4;
|
||||
private static final int ITEM_TYPE_ACTION = 3;
|
||||
|
||||
private static final int[] SEARCH_ITEM_COUNT_ARRAY = {
|
||||
3, 2, 2
|
||||
3, 2
|
||||
};
|
||||
|
||||
private static final int[][] SEARCH_ITEM_TYPE = {
|
||||
{ITEM_TYPE_NORMAL, ITEM_TYPE_NORMAL_ADVANCE, ITEM_TYPE_ACTION}, // SEARCH_MODE_NORMAL
|
||||
{ITEM_TYPE_IMAGE, ITEM_TYPE_ACTION}, // SEARCH_MODE_IMAGE
|
||||
{ITEM_TYPE_SPECIFY, ITEM_TYPE_ACTION} // SEARCH_MODE_SPECIFY
|
||||
};
|
||||
|
||||
private LayoutInflater mInflater;
|
||||
@@ -86,13 +87,15 @@ public class SearchLayout extends EasyRecyclerView implements CompoundButton.OnC
|
||||
private CategoryTable mCategoryTable;
|
||||
private RadioGridGroup mNormalSearchMode;
|
||||
private ImageView mNormalSearchModeHelp;
|
||||
private View mSearchTagHelp;
|
||||
private SwitchCompat mEnableAdvanceSwitch;
|
||||
|
||||
private View mAdvanceView;
|
||||
private AdvanceSearchTable mTableAdvanceSearch;
|
||||
|
||||
private ImageSearchLayout mImageView;
|
||||
|
||||
private View mActionView;
|
||||
private TextView mAction;
|
||||
|
||||
private LinearLayoutManager mLayoutManager;
|
||||
private SearchAdapter mAdapter;
|
||||
@@ -109,42 +112,49 @@ public class SearchLayout extends EasyRecyclerView implements CompoundButton.OnC
|
||||
init(context);
|
||||
}
|
||||
|
||||
@SuppressLint("InflateParams")
|
||||
private void init(Context context) {
|
||||
Resources resources = context.getResources();
|
||||
mInflater = LayoutInflater.from(context);
|
||||
|
||||
mLayoutManager = new LinearLayoutManager(context);
|
||||
mAdapter = new SearchAdapter();
|
||||
//mAnimator = new SearchItemAnimator(this);
|
||||
setLayoutManager(mLayoutManager);
|
||||
setAdapter(mAdapter);
|
||||
setHasFixedSize(true);
|
||||
setClipToPadding(false);
|
||||
//setItemAnimator(mAnimator);
|
||||
int paddingH = resources.getDimensionPixelOffset(R.dimen.list_content_margin_h);
|
||||
int paddingV = resources.getDimensionPixelOffset(R.dimen.list_content_margin_v);
|
||||
setPadding(paddingV, paddingH, paddingV, paddingH);
|
||||
|
||||
FrameLayout frameLayout = new FrameLayout(context);
|
||||
int interval = resources.getDimensionPixelOffset(R.dimen.search_layout_interval);
|
||||
int paddingH = resources.getDimensionPixelOffset(R.dimen.search_layout_margin_h);
|
||||
int paddingV = resources.getDimensionPixelOffset(R.dimen.search_layout_margin_v);
|
||||
MarginItemDecoration decoration = new MarginItemDecoration(
|
||||
interval, paddingH, paddingV, paddingH, paddingV);
|
||||
addItemDecoration(decoration);
|
||||
decoration.applyPaddings(this);
|
||||
|
||||
// Create normal view
|
||||
View normalView = mInflater.inflate(R.layout.search_normal, frameLayout, false);
|
||||
View normalView = mInflater.inflate(R.layout.search_normal, null);
|
||||
mNormalView = normalView;
|
||||
mCategoryTable = (CategoryTable) normalView.findViewById(R.id.search_category_table);
|
||||
mNormalSearchMode = (RadioGridGroup) normalView.findViewById(R.id.normal_search_mode);
|
||||
mNormalSearchModeHelp = (ImageView) normalView.findViewById(R.id.normal_search_mode_help);
|
||||
mEnableAdvanceSwitch = (SwitchCompat) normalView.findViewById(R.id.search_enable_advance);
|
||||
mNormalSearchModeHelp.setOnClickListener(this);
|
||||
RippleSalon.addRipple(mNormalSearchModeHelp, false);
|
||||
Ripple.addRipple(mNormalSearchModeHelp, false);
|
||||
mEnableAdvanceSwitch.setOnCheckedChangeListener(SearchLayout.this);
|
||||
mEnableAdvanceSwitch.setSwitchPadding(resources.getDimensionPixelSize(R.dimen.switch_padding));
|
||||
|
||||
// Create advance view
|
||||
mAdvanceView = mInflater.inflate(R.layout.search_advance, frameLayout, false);
|
||||
mAdvanceView = mInflater.inflate(R.layout.search_advance, null);
|
||||
mTableAdvanceSearch = (AdvanceSearchTable) mAdvanceView.findViewById(R.id.search_advance_search_table);
|
||||
|
||||
// Create image view
|
||||
mImageView = (ImageSearchLayout) mInflater.inflate(R.layout.search_image, null);
|
||||
mImageView.setHelper(this);
|
||||
|
||||
// Create action view
|
||||
mActionView = new View(context);// TODO mInflater.inflate(R.layout.search_action, frameLayout, false);
|
||||
mActionView = mInflater.inflate(R.layout.search_action, null);
|
||||
mAction = (TextView) mActionView.findViewById(R.id.action);
|
||||
mAction.setOnClickListener(this);
|
||||
}
|
||||
|
||||
public void setHelper(Helper helper) {
|
||||
@@ -155,12 +165,24 @@ public class SearchLayout extends EasyRecyclerView implements CompoundButton.OnC
|
||||
mLayoutManager.scrollToPositionWithOffset(0, 0);
|
||||
}
|
||||
|
||||
public void setImageUri(Uri imageUri) {
|
||||
mImageView.setImageUri(imageUri);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSelectImage() {
|
||||
if (mHelper != null) {
|
||||
mHelper.onSelectImage();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void dispatchSaveInstanceState(@NonNull SparseArray<Parcelable> container) {
|
||||
super.dispatchSaveInstanceState(container);
|
||||
|
||||
mNormalView.saveHierarchyState(container);
|
||||
mAdvanceView.saveHierarchyState(container);
|
||||
mImageView.saveHierarchyState(container);
|
||||
mActionView.saveHierarchyState(container);
|
||||
}
|
||||
|
||||
@@ -170,6 +192,7 @@ public class SearchLayout extends EasyRecyclerView implements CompoundButton.OnC
|
||||
|
||||
mNormalView.restoreHierarchyState(container);
|
||||
mAdvanceView.restoreHierarchyState(container);
|
||||
mImageView.restoreHierarchyState(container);
|
||||
mActionView.restoreHierarchyState(container);
|
||||
}
|
||||
|
||||
@@ -214,29 +237,35 @@ public class SearchLayout extends EasyRecyclerView implements CompoundButton.OnC
|
||||
return R.id.search_specify_gallery == mNormalSearchMode.getCheckedRadioButtonId();
|
||||
}
|
||||
|
||||
// TODO image search
|
||||
public void formatListUrlBuilder(ListUrlBuilder urlBuilder, String query) {
|
||||
public void formatListUrlBuilder(ListUrlBuilder urlBuilder, String query) throws EhException {
|
||||
urlBuilder.reset();
|
||||
|
||||
int nsMode = mNormalSearchMode.getCheckedRadioButtonId();
|
||||
switch (nsMode) {
|
||||
default:
|
||||
case R.id.search_normal_search:
|
||||
urlBuilder.setMode(ListUrlBuilder.MODE_NORMAL);
|
||||
switch (mSearchMode) {
|
||||
case SEARCH_MODE_NORMAL:
|
||||
int nsMode = mNormalSearchMode.getCheckedRadioButtonId();
|
||||
switch (nsMode) {
|
||||
default:
|
||||
case R.id.search_normal_search:
|
||||
urlBuilder.setMode(ListUrlBuilder.MODE_NORMAL);
|
||||
break;
|
||||
case R.id.search_specify_uploader:
|
||||
urlBuilder.setMode(ListUrlBuilder.MODE_UPLOADER);
|
||||
break;
|
||||
case R.id.search_specify_tag:
|
||||
urlBuilder.setMode(ListUrlBuilder.MODE_TAG);
|
||||
break;
|
||||
}
|
||||
urlBuilder.setKeyword(query);
|
||||
urlBuilder.setCategory(mCategoryTable.getCategory());
|
||||
if (mEnableAdvance) {
|
||||
urlBuilder.setAdvanceSearch(mTableAdvanceSearch.getAdvanceSearch());
|
||||
urlBuilder.setMinRating(mTableAdvanceSearch.getMinRating());
|
||||
}
|
||||
break;
|
||||
case R.id.search_specify_uploader:
|
||||
urlBuilder.setMode(ListUrlBuilder.MODE_UPLOADER);
|
||||
case SEARCH_MODE_IMAGE:
|
||||
urlBuilder.setMode(ListUrlBuilder.MODE_IMAGE_SEARCH);
|
||||
mImageView.formatListUrlBuilder(urlBuilder);
|
||||
break;
|
||||
case R.id.search_specify_tag:
|
||||
urlBuilder.setMode(ListUrlBuilder.MODE_TAG);
|
||||
break;
|
||||
}
|
||||
|
||||
urlBuilder.setKeyword(query);
|
||||
urlBuilder.setCategory(mCategoryTable.getCategory());
|
||||
if (mEnableAdvance) {
|
||||
urlBuilder.setAdvanceSearch(mTableAdvanceSearch.getAdvanceSearch());
|
||||
urlBuilder.setMinRating(mTableAdvanceSearch.getMinRating());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -263,7 +292,7 @@ public class SearchLayout extends EasyRecyclerView implements CompoundButton.OnC
|
||||
int oldItemCount = mAdapter.getItemCount();
|
||||
|
||||
mSearchMode++;
|
||||
if (mSearchMode > SEARCH_MODE_SPECIFY) {
|
||||
if (mSearchMode > SEARCH_MODE_IMAGE) {
|
||||
mSearchMode = SEARCH_MODE_NORMAL;
|
||||
}
|
||||
|
||||
@@ -272,6 +301,19 @@ public class SearchLayout extends EasyRecyclerView implements CompoundButton.OnC
|
||||
mAdapter.notifyItemRangeRemoved(0, oldItemCount - 1);
|
||||
mAdapter.notifyItemRangeInserted(0, newItemCount - 1);
|
||||
|
||||
// Update action text
|
||||
int resId;
|
||||
switch (mSearchMode) {
|
||||
default:
|
||||
case SEARCH_MODE_NORMAL:
|
||||
resId = R.string.image_search;
|
||||
break;
|
||||
case SEARCH_MODE_IMAGE:
|
||||
resId = R.string.keyword_search;
|
||||
break;
|
||||
}
|
||||
mAction.setText(resId);
|
||||
|
||||
if (mHelper != null) {
|
||||
mHelper.onChangeSearchMode();
|
||||
}
|
||||
@@ -283,6 +325,8 @@ public class SearchLayout extends EasyRecyclerView implements CompoundButton.OnC
|
||||
new AlertDialog.Builder(getContext())
|
||||
.setMessage(R.string.search_tip)
|
||||
.show();
|
||||
} else if (mAction == v) {
|
||||
toggleSearchMode();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -321,6 +365,17 @@ public class SearchLayout extends EasyRecyclerView implements CompoundButton.OnC
|
||||
mActionView.setLayoutParams(new RecyclerView.LayoutParams(
|
||||
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||
ViewGroup.LayoutParams.WRAP_CONTENT));
|
||||
int resId;
|
||||
switch (mSearchMode) {
|
||||
default:
|
||||
case SEARCH_MODE_NORMAL:
|
||||
resId = R.string.image_search;
|
||||
break;
|
||||
case SEARCH_MODE_IMAGE:
|
||||
resId = R.string.keyword_search;
|
||||
break;
|
||||
}
|
||||
mAction.setText(resId);
|
||||
view = mActionView;
|
||||
} else {
|
||||
view = mInflater.inflate(R.layout.search_category, parent, false);
|
||||
@@ -337,6 +392,11 @@ public class SearchLayout extends EasyRecyclerView implements CompoundButton.OnC
|
||||
ViewUtils.removeFromParent(mAdvanceView);
|
||||
content.addView(mAdvanceView);
|
||||
break;
|
||||
case ITEM_TYPE_IMAGE:
|
||||
title.setText(R.string.search_image);
|
||||
ViewUtils.removeFromParent(mImageView);
|
||||
content.addView(mImageView);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -351,5 +411,6 @@ public class SearchLayout extends EasyRecyclerView implements CompoundButton.OnC
|
||||
|
||||
public interface Helper {
|
||||
void onChangeSearchMode();
|
||||
void onSelectImage();
|
||||
}
|
||||
}
|
||||
@@ -25,7 +25,11 @@ import android.view.View;
|
||||
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.util.DrawableManager;
|
||||
import com.hippo.yorozuya.MathUtils;
|
||||
|
||||
/**
|
||||
* 5 stars, from 0 to 10
|
||||
*/
|
||||
public class SimpleRatingView extends View {
|
||||
|
||||
private Drawable mStarDrawable;
|
||||
@@ -96,7 +100,7 @@ public class SimpleRatingView extends View {
|
||||
public void setRating(float rating) {
|
||||
if (mRating != rating) {
|
||||
mRating = rating;
|
||||
int ratingInt = (int) Math.ceil(rating * 2);
|
||||
int ratingInt = MathUtils.clamp((int) Math.ceil(rating * 2), 0, 10);
|
||||
if (mRatingInt != ratingInt) {
|
||||
mRatingInt = ratingInt;
|
||||
invalidate();
|
||||
|
||||
@@ -240,7 +240,8 @@ public class ImageTexture implements Texture, Animatable {
|
||||
private class AnimateRunnable implements Runnable {
|
||||
|
||||
public void doRun() {
|
||||
long lastTime = SystemClock.currentThreadTimeMillis();
|
||||
long lastTime = SystemClock.elapsedRealtime();
|
||||
long lastDelay = -1L;
|
||||
|
||||
synchronized (mImage) {
|
||||
// Check recycled
|
||||
@@ -309,9 +310,12 @@ public class ImageTexture implements Texture, Animatable {
|
||||
|
||||
mImage.advance();
|
||||
long delay = mImage.getDelay();
|
||||
long time = System.currentTimeMillis();
|
||||
delay -= time - lastTime;
|
||||
long time = SystemClock.elapsedRealtime();
|
||||
if (-1L != lastDelay) {
|
||||
delay -= (time - lastTime) - lastDelay;
|
||||
}
|
||||
lastTime = time;
|
||||
lastDelay = delay;
|
||||
mFrameDirty.lazySet(true);
|
||||
invalidateSelf();
|
||||
|
||||
|
||||
@@ -573,28 +573,34 @@ public class GLRootView extends GLSurfaceView
|
||||
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
|
||||
unfreeze();
|
||||
super.surfaceChanged(holder, format, w, h);
|
||||
|
||||
requestLayoutContentPane();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void surfaceCreated(SurfaceHolder holder) {
|
||||
unfreeze();
|
||||
super.surfaceCreated(holder);
|
||||
|
||||
if (mContentView != null && !mContentView.isAttachedToRoot()) {
|
||||
mContentView.attachToRoot(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void surfaceDestroyed(SurfaceHolder holder) {
|
||||
unfreeze();
|
||||
super.surfaceDestroyed(holder);
|
||||
|
||||
if (mContentView != null && mContentView.isAttachedToRoot()) {
|
||||
mContentView.detachFromRoot();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDetachedFromWindow() {
|
||||
unfreeze();
|
||||
super.onDetachedFromWindow();
|
||||
|
||||
if (mContentView != null) {
|
||||
mContentView.detachFromRoot();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
package com.hippo.okhttp;
|
||||
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
@@ -176,6 +178,35 @@ public class CookieDBStore implements CookieJar {
|
||||
}
|
||||
}
|
||||
|
||||
private Cookie getInternal(HttpUrl url, String name, List<CookieWithID> cookies) {
|
||||
for (Iterator<CookieWithID> i = cookies.iterator(); i.hasNext();) {
|
||||
CookieWithID cwi = i.next();
|
||||
Cookie cookie = cwi.cookie;
|
||||
// Check expired
|
||||
if (hasExpired(cookie)) {
|
||||
// Remove from list
|
||||
i.remove();
|
||||
// Remove from DB
|
||||
CookieDB.removeCookie(cwi.id);
|
||||
} else if (cookie.name().equals(name) && cookie.matches(url)) {
|
||||
return cookie;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public synchronized Cookie get(HttpUrl url, String name) {
|
||||
String host = url.host();
|
||||
for (String key : map.keySet()) {
|
||||
if (domainMatch(host, key)) {
|
||||
List<CookieWithID> cookies = map.get(key);
|
||||
return getInternal(url, name, cookies);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public synchronized List<Cookie> get(HttpUrl url) {
|
||||
List<Cookie> result = new ArrayList<>();
|
||||
|
||||
@@ -185,6 +216,7 @@ public class CookieDBStore implements CookieJar {
|
||||
List<CookieWithID> cookies = map.get(key);
|
||||
// cookies can not be null
|
||||
getInternal(url, cookies, result);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,11 +16,9 @@
|
||||
|
||||
package com.hippo.preference;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.res.TypedArray;
|
||||
import android.os.Build;
|
||||
import android.preference.Preference;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
@@ -48,12 +46,6 @@ public class ActivityPreference extends Preference {
|
||||
init(context, attrs, defStyleAttr, 0);
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
||||
public ActivityPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
||||
super(context, attrs, defStyleAttr, defStyleRes);
|
||||
init(context, attrs, defStyleAttr, defStyleRes);
|
||||
}
|
||||
|
||||
private void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
||||
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ActivityPreference, defStyleAttr, defStyleRes);
|
||||
String clazzName = a.getString(R.styleable.ActivityPreference_activity);
|
||||
|
||||
@@ -16,17 +16,17 @@
|
||||
|
||||
package com.hippo.preference;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.preference.Preference;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.annotation.DrawableRes;
|
||||
import android.support.annotation.StringRes;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
@@ -45,11 +45,8 @@ import com.hippo.ehviewer.R;
|
||||
* actual preference controls.
|
||||
*/
|
||||
public abstract class DialogPreference extends Preference implements
|
||||
DialogInterface.OnClickListener, DialogInterface.OnDismissListener {
|
||||
|
||||
private static final String KEY_SUPER = "super";
|
||||
private static final String KEY_IS_DIALOG_SHOWING = "is_dialog_showing";
|
||||
private static final String KEY_DIALOG_BUNDLE = "dialog_bundle";
|
||||
DialogInterface.OnClickListener, DialogInterface.OnDismissListener,
|
||||
PreferenceManager.OnActivityDestroyListener {
|
||||
|
||||
private AlertDialog.Builder mBuilder;
|
||||
|
||||
@@ -80,12 +77,6 @@ public abstract class DialogPreference extends Preference implements
|
||||
init(context, attrs, defStyleAttr, 0);
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
||||
public DialogPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
||||
super(context, attrs, defStyleAttr, defStyleRes);
|
||||
init(context, attrs, defStyleAttr, defStyleRes);
|
||||
}
|
||||
|
||||
private void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
||||
final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.DialogPreference, defStyleAttr, defStyleRes);
|
||||
mDialogTitle = a.getString(R.styleable.DialogPreference_dialogTitle);
|
||||
@@ -272,6 +263,8 @@ public abstract class DialogPreference extends Preference implements
|
||||
|
||||
onPrepareDialogBuilder(mBuilder);
|
||||
|
||||
PreferenceUtils.registerOnActivityDestroyListener(this, this);
|
||||
|
||||
// Create the dialog
|
||||
final AlertDialog dialog = mDialog = mBuilder.create();
|
||||
if (state != null) {
|
||||
@@ -336,6 +329,8 @@ public abstract class DialogPreference extends Preference implements
|
||||
|
||||
@Override
|
||||
public void onDismiss(DialogInterface dialog) {
|
||||
PreferenceUtils.unregisterOnActivityDestroyListener(this, this);
|
||||
|
||||
mDialog = null;
|
||||
onDialogClosed(mWhichButtonClicked == DialogInterface.BUTTON_POSITIVE);
|
||||
}
|
||||
@@ -359,6 +354,15 @@ public abstract class DialogPreference extends Preference implements
|
||||
return mDialog;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityDestroy() {
|
||||
if (mDialog == null || !mDialog.isShowing()) {
|
||||
return;
|
||||
}
|
||||
|
||||
mDialog.dismiss();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Parcelable onSaveInstanceState() {
|
||||
final Parcelable superState = super.onSaveInstanceState();
|
||||
@@ -366,25 +370,59 @@ public abstract class DialogPreference extends Preference implements
|
||||
return superState;
|
||||
}
|
||||
|
||||
final Bundle myState = new Bundle();
|
||||
myState.putParcelable(KEY_SUPER, superState);
|
||||
myState.putBoolean(KEY_IS_DIALOG_SHOWING, true);
|
||||
myState.putBundle(KEY_DIALOG_BUNDLE, mDialog.onSaveInstanceState());
|
||||
final SavedState myState = new SavedState(superState);
|
||||
myState.isDialogShowing = true;
|
||||
myState.dialogBundle = mDialog.onSaveInstanceState();
|
||||
return myState;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onRestoreInstanceState(Parcelable state) {
|
||||
if (state == null || !state.getClass().equals(Bundle.class)) {
|
||||
if (state == null || !state.getClass().equals(SavedState.class)) {
|
||||
// Didn't save state for us in onSaveInstanceState
|
||||
super.onRestoreInstanceState(state);
|
||||
return;
|
||||
}
|
||||
|
||||
Bundle myState = (Bundle) state;
|
||||
super.onRestoreInstanceState(myState.getParcelable(KEY_SUPER));
|
||||
if (myState.getBoolean(KEY_IS_DIALOG_SHOWING)) {
|
||||
showDialog(myState.getBundle(KEY_DIALOG_BUNDLE));
|
||||
SavedState myState = (SavedState) state;
|
||||
super.onRestoreInstanceState(myState.getSuperState());
|
||||
if (myState.isDialogShowing) {
|
||||
showDialog(myState.dialogBundle);
|
||||
}
|
||||
}
|
||||
|
||||
private static class SavedState extends BaseSavedState {
|
||||
boolean isDialogShowing;
|
||||
Bundle dialogBundle;
|
||||
|
||||
public SavedState(Parcel source) {
|
||||
super(source);
|
||||
isDialogShowing = source.readInt() == 1;
|
||||
dialogBundle = source.readBundle(DialogPreference.class.getClassLoader());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
super.writeToParcel(dest, flags);
|
||||
dest.writeInt(isDialogShowing ? 1 : 0);
|
||||
dest.writeBundle(dialogBundle);
|
||||
}
|
||||
|
||||
public SavedState(Parcelable superState) {
|
||||
super(superState);
|
||||
}
|
||||
|
||||
public static final Parcelable.Creator<SavedState> CREATOR =
|
||||
new Parcelable.Creator<SavedState>() {
|
||||
@Override
|
||||
public SavedState createFromParcel(Parcel in) {
|
||||
return new SavedState(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SavedState[] newArray(int size) {
|
||||
return new SavedState[size];
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -52,11 +52,6 @@ public class ListPreference extends DialogPreference {
|
||||
init(context, attrs, defStyleAttr, 0);
|
||||
}
|
||||
|
||||
public ListPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
||||
super(context, attrs, defStyleAttr, defStyleRes);
|
||||
init(context, attrs, defStyleAttr, defStyleRes);
|
||||
}
|
||||
|
||||
private void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
||||
setNegativeButtonText(android.R.string.cancel);
|
||||
|
||||
|
||||
@@ -16,10 +16,8 @@
|
||||
|
||||
package com.hippo.preference;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.os.Build;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.text.method.LinkMovementMethod;
|
||||
import android.util.AttributeSet;
|
||||
@@ -34,7 +32,6 @@ public class MessagePreference extends DialogPreference {
|
||||
private CharSequence mDialogMessage;
|
||||
private boolean mDialogMessageLinkify;
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
||||
public MessagePreference(Context context) {
|
||||
super(context);
|
||||
init(context, null, 0, 0);
|
||||
@@ -50,12 +47,6 @@ public class MessagePreference extends DialogPreference {
|
||||
init(context, attrs, defStyleAttr, 0);
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
||||
public MessagePreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
||||
super(context, attrs, defStyleAttr, defStyleRes);
|
||||
init(context, attrs, defStyleAttr, defStyleRes);
|
||||
}
|
||||
|
||||
public void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
||||
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.MessagePreference, defStyleAttr, defStyleRes);
|
||||
String message = a.getString(R.styleable.MessagePreference_dialogMessage);
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
* Copyright 2016 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.preference;
|
||||
|
||||
import android.preference.Preference;
|
||||
import android.preference.PreferenceManager;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
public final class PreferenceUtils {
|
||||
private PreferenceUtils() {}
|
||||
|
||||
private static final Method mRegisterOnActivityDestroyListener;
|
||||
private static final Method mUnregisterOnActivityDestroyListener;
|
||||
|
||||
static {
|
||||
Method method;
|
||||
Class<?> clazz = PreferenceManager.class;
|
||||
|
||||
method = null;
|
||||
try {
|
||||
method = clazz.getDeclaredMethod("registerOnActivityDestroyListener",
|
||||
PreferenceManager.OnActivityDestroyListener.class);
|
||||
if (null != method) {
|
||||
method.setAccessible(true);
|
||||
}
|
||||
} catch (NoSuchMethodException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
mRegisterOnActivityDestroyListener = method;
|
||||
|
||||
method = null;
|
||||
try {
|
||||
method = clazz.getDeclaredMethod("unregisterOnActivityDestroyListener",
|
||||
PreferenceManager.OnActivityDestroyListener.class);
|
||||
if (null != method) {
|
||||
method.setAccessible(true);
|
||||
}
|
||||
} catch (NoSuchMethodException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
mUnregisterOnActivityDestroyListener = method;
|
||||
}
|
||||
|
||||
@SuppressWarnings("TryWithIdenticalCatches")
|
||||
public static void registerOnActivityDestroyListener(Preference preference,
|
||||
PreferenceManager.OnActivityDestroyListener listener) {
|
||||
if (null == mRegisterOnActivityDestroyListener || null == preference || null == listener) {
|
||||
return;
|
||||
}
|
||||
PreferenceManager preferenceManager = preference.getPreferenceManager();
|
||||
if (null == preferenceManager) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
mRegisterOnActivityDestroyListener.invoke(preferenceManager, listener);
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("TryWithIdenticalCatches")
|
||||
public static void unregisterOnActivityDestroyListener(Preference preference,
|
||||
PreferenceManager.OnActivityDestroyListener listener) {
|
||||
if (null == mUnregisterOnActivityDestroyListener || null == preference || null == listener) {
|
||||
return;
|
||||
}
|
||||
PreferenceManager preferenceManager = preference.getPreferenceManager();
|
||||
if (null == preferenceManager) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
mUnregisterOnActivityDestroyListener.invoke(preferenceManager, listener);
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,229 @@
|
||||
/*
|
||||
* Copyright (C) 2011 The Android Open Source Project
|
||||
*
|
||||
* 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.preference;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.preference.Preference;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
import android.widget.SeekBar;
|
||||
|
||||
import com.hippo.ehviewer.R;
|
||||
|
||||
public class SeekBarPreference extends Preference implements SeekBar.OnSeekBarChangeListener {
|
||||
|
||||
private int mProgress;
|
||||
private int mMax;
|
||||
private boolean mTrackingTouch;
|
||||
|
||||
public SeekBarPreference(Context context) {
|
||||
super(context);
|
||||
init(context, null, 0, 0);
|
||||
}
|
||||
|
||||
public SeekBarPreference(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
init(context, attrs, 0, 0);
|
||||
}
|
||||
|
||||
public SeekBarPreference(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
init(context, attrs, defStyleAttr, 0);
|
||||
}
|
||||
|
||||
private void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
||||
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SeekBarPreference, defStyleAttr, defStyleRes);
|
||||
setMax(a.getInt(R.styleable.SeekBarPreference_max, mMax));
|
||||
a.recycle();
|
||||
|
||||
setLayoutResource(R.layout.preference_widget_seekbar);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onBindView(View view) {
|
||||
super.onBindView(view);
|
||||
SeekBar seekBar = (SeekBar) view.findViewById(R.id.seekbar);
|
||||
seekBar.setOnSeekBarChangeListener(this);
|
||||
seekBar.setMax(mMax);
|
||||
seekBar.setProgress(mProgress);
|
||||
seekBar.setEnabled(isEnabled());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSetInitialValue(boolean restoreValue, Object defaultValue) {
|
||||
setProgress(restoreValue ? getPersistedInt(mProgress)
|
||||
: (Integer) defaultValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object onGetDefaultValue(TypedArray a, int index) {
|
||||
return a.getInt(index, 0);
|
||||
}
|
||||
|
||||
public void setMax(int max) {
|
||||
if (max != mMax) {
|
||||
mMax = max;
|
||||
notifyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public void setProgress(int progress) {
|
||||
setProgress(progress, true);
|
||||
}
|
||||
|
||||
private void setProgress(int progress, boolean notifyChanged) {
|
||||
if (progress > mMax) {
|
||||
progress = mMax;
|
||||
}
|
||||
if (progress < 0) {
|
||||
progress = 0;
|
||||
}
|
||||
if (progress != mProgress) {
|
||||
mProgress = progress;
|
||||
persistInt(progress);
|
||||
if (notifyChanged) {
|
||||
notifyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int getProgress() {
|
||||
return mProgress;
|
||||
}
|
||||
|
||||
/**
|
||||
* Persist the seekBar's progress value if callChangeListener
|
||||
* returns true, otherwise set the seekBar's progress to the stored value
|
||||
*/
|
||||
void syncProgress(SeekBar seekBar) {
|
||||
int progress = seekBar.getProgress();
|
||||
if (progress != mProgress) {
|
||||
if (callChangeListener(progress)) {
|
||||
setProgress(progress, false);
|
||||
} else {
|
||||
seekBar.setProgress(mProgress);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onProgressChanged(
|
||||
SeekBar seekBar, int progress, boolean fromUser) {
|
||||
if (fromUser && !mTrackingTouch) {
|
||||
syncProgress(seekBar);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStartTrackingTouch(SeekBar seekBar) {
|
||||
mTrackingTouch = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStopTrackingTouch(SeekBar seekBar) {
|
||||
mTrackingTouch = false;
|
||||
if (seekBar.getProgress() != mProgress) {
|
||||
syncProgress(seekBar);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Parcelable onSaveInstanceState() {
|
||||
/*
|
||||
* Suppose a client uses this preference type without persisting. We
|
||||
* must save the instance state so it is able to, for example, survive
|
||||
* orientation changes.
|
||||
*/
|
||||
|
||||
final Parcelable superState = super.onSaveInstanceState();
|
||||
if (isPersistent()) {
|
||||
// No need to save instance state since it's persistent
|
||||
return superState;
|
||||
}
|
||||
|
||||
// Save the instance state
|
||||
final SavedState myState = new SavedState(superState);
|
||||
myState.progress = mProgress;
|
||||
myState.max = mMax;
|
||||
return myState;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onRestoreInstanceState(Parcelable state) {
|
||||
if (!state.getClass().equals(SavedState.class)) {
|
||||
// Didn't save state for us in onSaveInstanceState
|
||||
super.onRestoreInstanceState(state);
|
||||
return;
|
||||
}
|
||||
|
||||
// Restore the instance state
|
||||
SavedState myState = (SavedState) state;
|
||||
super.onRestoreInstanceState(myState.getSuperState());
|
||||
mProgress = myState.progress;
|
||||
mMax = myState.max;
|
||||
notifyChanged();
|
||||
}
|
||||
|
||||
/**
|
||||
* SavedState, a subclass of {@link BaseSavedState}, will store the state
|
||||
* of MyPreference, a subclass of Preference.
|
||||
* <p>
|
||||
* It is important to always call through to super methods.
|
||||
*/
|
||||
private static class SavedState extends BaseSavedState {
|
||||
int progress;
|
||||
int max;
|
||||
|
||||
public SavedState(Parcel source) {
|
||||
super(source);
|
||||
|
||||
// Restore the click counter
|
||||
progress = source.readInt();
|
||||
max = source.readInt();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
super.writeToParcel(dest, flags);
|
||||
|
||||
// Save the click counter
|
||||
dest.writeInt(progress);
|
||||
dest.writeInt(max);
|
||||
}
|
||||
|
||||
public SavedState(Parcelable superState) {
|
||||
super(superState);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public static final Parcelable.Creator<SavedState> CREATOR =
|
||||
new Parcelable.Creator<SavedState>() {
|
||||
@Override
|
||||
public SavedState createFromParcel(Parcel in) {
|
||||
return new SavedState(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SavedState[] newArray(int size) {
|
||||
return new SavedState[size];
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -16,10 +16,8 @@
|
||||
|
||||
package com.hippo.preference;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.os.Build;
|
||||
import android.preference.TwoStatePreference;
|
||||
import android.support.annotation.StringRes;
|
||||
import android.support.v7.widget.SwitchCompat;
|
||||
@@ -82,12 +80,6 @@ public class SwitchPreference extends TwoStatePreference {
|
||||
init(context, attrs, defStyleAttr, 0);
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
||||
public SwitchPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
||||
super(context, attrs, defStyleAttr, defStyleRes);
|
||||
init(context, attrs, defStyleAttr, defStyleRes);
|
||||
}
|
||||
|
||||
public void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
||||
setWidgetLayoutResource(R.layout.preference_widget_fixed_switch);
|
||||
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SwitchPreference, defStyleAttr, defStyleRes);
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Copyright 2016 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.preference;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.preference.Preference;
|
||||
import android.util.AttributeSet;
|
||||
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.UrlOpener;
|
||||
|
||||
public class UrlPreference extends Preference {
|
||||
|
||||
private String mUrl;
|
||||
|
||||
public UrlPreference(Context context) {
|
||||
super(context);
|
||||
init(context, null, 0, 0);
|
||||
}
|
||||
|
||||
public UrlPreference(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
init(context, attrs, 0, 0);
|
||||
}
|
||||
|
||||
public UrlPreference(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
init(context, attrs, defStyleAttr, 0);
|
||||
}
|
||||
|
||||
private void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
||||
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.UrlPreference, defStyleAttr, defStyleRes);
|
||||
mUrl = a.getString(R.styleable.UrlPreference_url);
|
||||
a.recycle();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getSummary() {
|
||||
if (null != mUrl) {
|
||||
return mUrl;
|
||||
} else {
|
||||
return super.getSummary();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onClick() {
|
||||
UrlOpener.openUrl(getContext(), mUrl, true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright 2016 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.reveal;
|
||||
|
||||
public interface Reveal {
|
||||
|
||||
void setRevealEnable(boolean enable);
|
||||
|
||||
void setReveal(int centerX, int centerY, float radius);
|
||||
}
|
||||
Loaded 100 of 219 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user