mirror of
https://github.com/seven332/EhViewer
synced 2026-11-30 19:18:03 +08:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4a5a426fd3 | ||
|
|
06adf8594c | ||
|
|
1ac43e6293 | ||
|
|
ceeb84812b | ||
|
|
bfd85e9bc7 | ||
|
|
8c3796605e | ||
|
|
3214bae157 | ||
|
|
a5b178df49 | ||
|
|
c2a93f2ce4 | ||
|
|
257758b27d | ||
|
|
2681e4a6e6 | ||
|
|
722653ac46 | ||
|
|
cb706941c5 | ||
|
|
195e9a5655 | ||
|
|
ed2043ab7a | ||
|
|
405655d0e2 | ||
|
|
0cead11180 | ||
|
|
141ab73089 | ||
|
|
7c349153de | ||
|
|
168b701cca | ||
|
|
0b67e685d2 | ||
|
|
741bb10a1c | ||
|
|
829591229d | ||
|
|
cbed5ee8cb | ||
|
|
a2db9038e3 | ||
|
|
14328eaf83 | ||
|
|
a11fb869e2 | ||
|
|
1285abdf71 | ||
|
|
f0fa226b16 | ||
|
|
88aebbd075 | ||
|
|
2c08a7b56f | ||
|
|
561e396c97 | ||
|
|
f8676b71dc | ||
|
|
259550e5cc | ||
|
|
478e53ab96 | ||
|
|
286b39e679 | ||
|
|
af771c7086 | ||
|
|
24d386da44 | ||
|
|
419405f4e2 | ||
|
|
e8de8ac5c8 | ||
|
|
934ec87390 | ||
|
|
46bd8e4297 | ||
|
|
70ceb83205 | ||
|
|
0553fda3fa | ||
|
|
b5f36dafdc | ||
|
|
77fd0eb73e | ||
|
|
ff6b0bf01d | ||
|
|
6734ace077 | ||
|
|
c013c82f90 | ||
|
|
618ca14eca | ||
|
|
700ebdfee3 | ||
|
|
9899552e4b | ||
|
|
7104fddded | ||
|
|
54f1c4806f | ||
|
|
9c66298cb8 | ||
|
|
bb266d46d3 | ||
|
|
8cd7d01e10 | ||
|
|
9692224dec | ||
|
|
41b4f00b91 | ||
|
|
611a4c8853 | ||
|
|
c8f1080b9e | ||
|
|
92ecf84c5e | ||
|
|
d9c0c80172 | ||
|
|
74a7b16252 | ||
|
|
5ccbeda6d5 | ||
|
|
75a2be5d38 | ||
|
|
c5d5778961 | ||
|
|
eb16df63e1 | ||
|
|
1bb2f6eb5f | ||
|
|
4a905a5226 | ||
|
|
fe60b26eec | ||
|
|
3b1028b9cc | ||
|
|
36b7a6211e | ||
|
|
8cd89f8a06 | ||
|
|
b599f6e71c | ||
|
|
2e38237a99 | ||
|
|
d23c145790 | ||
|
|
c3e0bbaa0a | ||
|
|
4582556f65 | ||
|
|
e07316f25a | ||
|
|
7379bdaa67 | ||
|
|
c4519c5914 | ||
|
|
358d9861f5 | ||
|
|
bdf2df0ed1 | ||
|
|
291a6515c1 | ||
|
|
2667bacd9d | ||
|
|
7967f289b7 | ||
|
|
31e1cb7e6d | ||
|
|
a472d0509a | ||
|
|
3f71a97cbd | ||
|
|
ed8c818d4f | ||
|
|
1db14cd998 | ||
|
|
d06dd87ff4 | ||
|
|
a31a64efd6 | ||
|
|
cfa87a5a02 | ||
|
|
2833691c34 | ||
|
|
22d6ed8c39 | ||
|
|
110bae7cb7 | ||
|
|
5bd7d6fae3 | ||
|
|
afa45fd8d9 | ||
|
|
2c544607ec | ||
|
|
730b52d6cd | ||
|
|
0704579d26 | ||
|
|
cb92fbad3d | ||
|
|
c7c6f8f706 | ||
|
|
fdd81e21b1 | ||
|
|
1093da6565 | ||
|
|
c625315a76 | ||
|
|
1deb4c2d6c | ||
|
|
9201b9baed | ||
|
|
557bd9f54b | ||
|
|
0353dbdb27 | ||
|
|
8b07cf62a9 | ||
|
|
111025cb98 | ||
|
|
b3d9c4c2b9 | ||
|
|
f2695b6a2c | ||
|
|
f6ec40e8ed | ||
|
|
9bc6920448 | ||
|
|
abb8483723 | ||
|
|
81eadbb794 | ||
|
|
22cc32778d | ||
|
|
c9d432b7c8 | ||
|
|
168a1dcfb2 | ||
|
|
b6718078f2 | ||
|
|
960a7751ad | ||
|
|
e5335de859 | ||
|
|
1eb960eaf9 | ||
|
|
6bc9f0da64 | ||
|
|
f4d986a5bd | ||
|
|
9aa22aab34 | ||
|
|
afa839ed0b | ||
|
|
f2725331fe | ||
|
|
590963024a | ||
|
|
1f55977182 | ||
|
|
4bed3d5b8e | ||
|
|
7eab4e00e1 | ||
|
|
776813df17 | ||
|
|
12beeedf29 | ||
|
|
d0e7f25fd9 | ||
|
|
ab2a066992 | ||
|
|
596f95e463 | ||
|
|
79d07f98a8 | ||
|
|
22ec2e8926 | ||
|
|
bc4d20d0a4 | ||
|
|
84ed520c1c | ||
|
|
34eb6a423a | ||
|
|
7dc1491c26 | ||
|
|
6ecce9ddc5 | ||
|
|
029373a8d2 | ||
|
|
e8c06fd876 | ||
|
|
8c9218e8af | ||
|
|
f922d41775 | ||
|
|
e483105eb2 | ||
|
|
9aecb79b17 | ||
|
|
bfc6bf07d9 | ||
|
|
b671999e5a | ||
|
|
3ed2cb329c | ||
|
|
fe9970523f | ||
|
|
62944f7b71 | ||
|
|
a7e1101c87 | ||
|
|
b79d991b25 | ||
|
|
10a15fc5cf | ||
|
|
428a5ab20e | ||
|
|
b3d19d752b | ||
|
|
73b702aa56 | ||
|
|
3360035402 | ||
|
|
b97069a04e | ||
|
|
9df8d050b2 | ||
|
|
ba4ca96b77 | ||
|
|
fd93baf583 | ||
|
|
0a9a1976cd | ||
|
|
450e05c819 | ||
|
|
59d36d29da | ||
|
|
f0cd92f82e | ||
|
|
e847338ef4 | ||
|
|
23c34258ff | ||
|
|
d441960107 |
No files matched your search
@@ -7,3 +7,4 @@
|
||||
.idea
|
||||
/captures
|
||||
release
|
||||
google-services.json
|
||||
@@ -1,4 +1,4 @@
|
||||
[](https://t.me/ehviewer) [](https://plus.google.com/communities/103823982034655188459)
|
||||
[](https://t.me/ehviewer)
|
||||
|
||||
# EhViewer
|
||||
|
||||
|
||||
+20
-10
@@ -1,15 +1,17 @@
|
||||
apply plugin: 'com.android.application'
|
||||
apply plugin: 'com.google.gms.google-services'
|
||||
apply plugin: 'io.fabric'
|
||||
apply plugin: 'android-chinese-string'
|
||||
|
||||
android {
|
||||
compileSdkVersion 27
|
||||
compileSdkVersion 28
|
||||
|
||||
defaultConfig {
|
||||
applicationId "com.hippo.ehviewer"
|
||||
minSdkVersion 14
|
||||
targetSdkVersion 27
|
||||
versionCode 84
|
||||
versionName "1.1.0"
|
||||
targetSdkVersion 28
|
||||
versionCode 89
|
||||
versionName "1.3.2"
|
||||
vectorDrawables.useSupportLibrary = true
|
||||
resConfigs "zh", "zh-rCN", "zh-rHK", "zh-rTW",
|
||||
"es", "ja", "ko", "fr", "de"
|
||||
@@ -21,8 +23,9 @@ android {
|
||||
}
|
||||
|
||||
lintOptions {
|
||||
abortOnError false
|
||||
checkReleaseBuilds false
|
||||
disable 'MissingTranslation'
|
||||
abortOnError true
|
||||
checkReleaseBuilds true
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
@@ -61,11 +64,16 @@ clean {
|
||||
dependencies {
|
||||
implementation fileTree(include: ['*.jar'], dir: 'libs')
|
||||
implementation "com.android.support:appcompat-v7:$supportLibrary"
|
||||
implementation "com.android.support:cardview-v7:$supportLibrary"
|
||||
implementation "com.android.support:design:$supportLibrary"
|
||||
implementation 'com.google.firebase:firebase-core:16.0.6'
|
||||
implementation 'com.crashlytics.sdk.android:crashlytics:2.9.7'
|
||||
implementation 'com.github.amlcurran.showcaseview:library:5.4.3'
|
||||
implementation 'com.github.seven332:android-recaptcha:2bbb3459a8'
|
||||
implementation 'com.github.seven332:android-resource:0.1.0'
|
||||
implementation 'com.github.seven332:animator:0.1.0'
|
||||
implementation 'com.github.seven332:beerbelly:0.1.4'
|
||||
implementation 'com.github.seven332.commons-compress:android-lite:464e96d3b4'
|
||||
implementation 'com.github.seven332:conaco:0.1.5-eh'
|
||||
implementation 'com.github.seven332:drawerlayout:0.2.1'
|
||||
implementation 'com.github.seven332:easyrecyclerview:0.1.1'
|
||||
@@ -74,17 +82,18 @@ dependencies {
|
||||
implementation 'com.github.seven332:glview-image:0.1.0'
|
||||
implementation 'com.github.seven332:hotspot:0.1.0'
|
||||
implementation 'com.github.seven332:image:0.1.12'
|
||||
implementation 'com.github.seven332.junrar:android-lite:46ecc9630a'
|
||||
implementation 'com.github.seven332:okhttp:3.5.0'
|
||||
implementation 'com.github.seven332:refreshlayout:0.1.0'
|
||||
implementation 'com.github.seven332:ripple:0.1.2'
|
||||
implementation 'com.github.seven332:streampipe:0.1.0'
|
||||
implementation 'com.github.seven332:tuxiang:0.1.2'
|
||||
implementation 'com.github.seven332:unifile:b59c14e47b'
|
||||
implementation 'com.github.seven332:unifile:a3571536be'
|
||||
implementation 'com.github.seven332:yorozuya:0.1.2'
|
||||
implementation 'com.github.seven332:yorozuya-thread:0.1.1'
|
||||
implementation 'com.github.seven332:yorozuya-collect:0.1.4'
|
||||
implementation 'com.h6ah4i.android.widget.advrecyclerview:advrecyclerview:0.9.2'
|
||||
implementation 'com.squareup.okhttp3:okhttp:3.11.0'
|
||||
implementation 'com.h6ah4i.android.widget.advrecyclerview:advrecyclerview:0.11.0'
|
||||
implementation 'com.squareup.okhttp3:okhttp:3.12.0'
|
||||
implementation 'org.ccil.cowan.tagsoup:tagsoup:1.2.1'
|
||||
implementation 'org.greenrobot:greendao:2.2.1'
|
||||
implementation 'org.jsoup:jsoup:1.11.3'
|
||||
@@ -97,8 +106,9 @@ configurations.all {
|
||||
resolutionStrategy {
|
||||
force 'com.github.seven332:glgallery:c56b14c6fa'
|
||||
force 'com.github.seven332:glview-image:4c744db'
|
||||
force 'com.github.seven332:image:bbf0bbb0a0'
|
||||
force 'com.github.seven332:image:29266a3c7b'
|
||||
|
||||
exclude group: 'com.github.seven332', module: 'okhttp'
|
||||
exclude group: 'com.squareup.okio', module: 'okio'
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -22,7 +22,9 @@
|
||||
<uses-permission android:name="android.permission.INTERNET"/>
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
|
||||
<uses-permission android:name="android.permission.USE_FINGERPRINT" />
|
||||
<uses-permission android:name="android.permission.USE_BIOMETRIC"/>
|
||||
<uses-permission android:name="android.permission.USE_FINGERPRINT"/>
|
||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
|
||||
|
||||
<uses-feature android:glEsVersion="0x00020000" android:required="true"/>
|
||||
|
||||
@@ -34,7 +36,8 @@
|
||||
android:theme="@style/AppTheme"
|
||||
android:allowBackup="true"
|
||||
android:fullBackupContent="@xml/backup_scheme"
|
||||
android:largeHeap="true">
|
||||
android:largeHeap="true"
|
||||
android:networkSecurityConfig="@xml/network_security_config">
|
||||
|
||||
<activity
|
||||
android:name="com.hippo.ehviewer.ui.MainActivity"
|
||||
@@ -85,17 +88,41 @@
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.VIEW"/>
|
||||
<category android:name="android.intent.category.DEFAULT"/>
|
||||
<category android:name="android.intent.category.BROWSABLE"/>
|
||||
<data android:scheme="file"/>
|
||||
<data android:scheme="content"/>
|
||||
<data android:host="*"/>
|
||||
<data android:mimeType="application/octet-stream"/>
|
||||
<data android:mimeType="application/7z"/>
|
||||
<data android:mimeType="application/rar"/>
|
||||
<data android:mimeType="application/zip"/>
|
||||
<data android:mimeType="application/x-7z-compressed"/>
|
||||
<data android:mimeType="application/x-rar-compressed"/>
|
||||
<data android:mimeType="application/x-zip-compressed"/>
|
||||
</intent-filter>
|
||||
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.VIEW"/>
|
||||
<category android:name="android.intent.category.DEFAULT"/>
|
||||
<category android:name="android.intent.category.BROWSABLE"/>
|
||||
<data android:scheme="file"/>
|
||||
<data android:scheme="content"/>
|
||||
<data android:host="*"/>
|
||||
<data android:pathPattern=".*\\.7z"/>
|
||||
<data android:pathPattern=".*\\.rar"/>
|
||||
<data android:pathPattern=".*\\.zip"/>
|
||||
</intent-filter>
|
||||
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.VIEW"/>
|
||||
<category android:name="android.intent.category.DEFAULT"/>
|
||||
<category android:name="android.intent.category.BROWSABLE"/>
|
||||
<data android:scheme="file"/>
|
||||
<data android:scheme="content"/>
|
||||
<data android:host="*"/>
|
||||
<data android:mimeType="*/*"/>
|
||||
<data android:pathPattern=".*\\.7z"/>
|
||||
<data android:pathPattern=".*\\.rar"/>
|
||||
<data android:pathPattern=".*\\.zip"/>
|
||||
</intent-filter>
|
||||
</activity>
|
||||
@@ -103,48 +130,48 @@
|
||||
<activity
|
||||
android:name="com.hippo.ehviewer.ui.SettingsActivity"
|
||||
android:configChanges="screenSize|uiMode"
|
||||
android:theme="@style/AppTheme"/>
|
||||
android:theme="@style/AppTheme.Settings"/>
|
||||
|
||||
<activity
|
||||
android:name="com.hippo.ehviewer.ui.ExcludedLanguagesActivity"
|
||||
android:configChanges="screenSize|uiMode"
|
||||
android:theme="@style/AppTheme.NoActionBar"
|
||||
android:theme="@style/AppTheme.Toolbar"
|
||||
android:label="@string/excluded_languages"/>
|
||||
|
||||
<activity
|
||||
android:name="com.hippo.ehviewer.ui.DirPickerActivity"
|
||||
android:configChanges="screenSize|uiMode"
|
||||
android:theme="@style/AppTheme.NoActionBar"
|
||||
android:theme="@style/AppTheme.Toolbar"
|
||||
android:label="@string/dir_picker"/>
|
||||
|
||||
<activity
|
||||
android:name="com.hippo.ehviewer.ui.LicenseActivity"
|
||||
android:configChanges="screenSize|uiMode"
|
||||
android:theme="@style/AppTheme.NoActionBar"
|
||||
android:theme="@style/AppTheme.Toolbar"
|
||||
android:label="@string/license"/>
|
||||
|
||||
<activity
|
||||
android:name="com.hippo.ehviewer.ui.FilterActivity"
|
||||
android:configChanges="screenSize|uiMode"
|
||||
android:theme="@style/AppTheme.NoActionBar"
|
||||
android:theme="@style/AppTheme.Toolbar"
|
||||
android:label="@string/filter"/>
|
||||
|
||||
<activity
|
||||
android:name="com.hippo.ehviewer.ui.SetSecurityActivity"
|
||||
android:configChanges="screenSize|uiMode"
|
||||
android:theme="@style/AppTheme.NoActionBar"
|
||||
android:theme="@style/AppTheme.Toolbar"
|
||||
android:label="@string/set_pattern_protection"/>
|
||||
|
||||
<activity
|
||||
android:name="com.hippo.ehviewer.ui.UConfigActivity"
|
||||
android:configChanges="screenSize|uiMode"
|
||||
android:theme="@style/AppTheme.NoActionBar"
|
||||
android:theme="@style/AppTheme.Toolbar"
|
||||
android:label="@string/u_config"/>
|
||||
|
||||
<activity
|
||||
android:name="com.hippo.ehviewer.ui.HostsActivity"
|
||||
android:configChanges="screenSize|uiMode"
|
||||
android:theme="@style/AppTheme.NoActionBar"
|
||||
android:theme="@style/AppTheme.Toolbar"
|
||||
android:label="@string/hosts"/>
|
||||
|
||||
<activity
|
||||
|
||||
@@ -0,0 +1,108 @@
|
||||
/*
|
||||
* Copyright 2018 Hippo Seven
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.hippo.app;
|
||||
|
||||
import android.content.Context;
|
||||
import android.preference.PreferenceActivity;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.text.TextUtils;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ListAdapter;
|
||||
import android.widget.TextView;
|
||||
import com.hippo.ehviewer.R;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class PrettyPreferenceActivity extends AppCompatPreferenceActivity {
|
||||
|
||||
@Override
|
||||
public void setListAdapter(ListAdapter adapter) {
|
||||
int count = adapter.getCount();
|
||||
List<PreferenceActivity.Header> headers = new ArrayList<>(count);
|
||||
for (int i = 0; i < count; ++i) {
|
||||
headers.add((PreferenceActivity.Header) adapter.getItem(i));
|
||||
}
|
||||
|
||||
super.setListAdapter(new HeaderAdapter(this, headers, R.layout.item_preference_header, true));
|
||||
}
|
||||
|
||||
private static class HeaderAdapter extends ArrayAdapter<PreferenceActivity.Header> {
|
||||
private static class HeaderViewHolder {
|
||||
ImageView icon;
|
||||
TextView title;
|
||||
TextView summary;
|
||||
}
|
||||
|
||||
private LayoutInflater mInflater;
|
||||
private int mLayoutResId;
|
||||
private boolean mRemoveIconIfEmpty;
|
||||
|
||||
private HeaderAdapter(Context context, List<PreferenceActivity.Header> objects, int layoutResId,
|
||||
boolean removeIconBehavior) {
|
||||
super(context, 0, objects);
|
||||
mInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
mLayoutResId = layoutResId;
|
||||
mRemoveIconIfEmpty = removeIconBehavior;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public View getView(int position, View convertView, @NonNull ViewGroup parent) {
|
||||
HeaderViewHolder holder;
|
||||
View view;
|
||||
|
||||
if (convertView == null) {
|
||||
view = mInflater.inflate(mLayoutResId, parent, false);
|
||||
holder = new HeaderViewHolder();
|
||||
holder.icon = view.findViewById(android.R.id.icon);
|
||||
holder.title = view.findViewById(android.R.id.title);
|
||||
holder.summary = view.findViewById(android.R.id.summary);
|
||||
view.setTag(holder);
|
||||
} else {
|
||||
view = convertView;
|
||||
holder = (HeaderViewHolder) view.getTag();
|
||||
}
|
||||
|
||||
// All view fields must be updated every time, because the view may be recycled
|
||||
PreferenceActivity.Header header = getItem(position);
|
||||
if (mRemoveIconIfEmpty) {
|
||||
if (header.iconRes == 0) {
|
||||
holder.icon.setVisibility(View.GONE);
|
||||
} else {
|
||||
holder.icon.setVisibility(View.VISIBLE);
|
||||
holder.icon.setImageResource(header.iconRes);
|
||||
}
|
||||
} else {
|
||||
holder.icon.setImageResource(header.iconRes);
|
||||
}
|
||||
holder.title.setText(header.getTitle(getContext().getResources()));
|
||||
CharSequence summary = header.getSummary(getContext().getResources());
|
||||
if (!TextUtils.isEmpty(summary)) {
|
||||
holder.summary.setVisibility(View.VISIBLE);
|
||||
holder.summary.setText(summary);
|
||||
} else {
|
||||
holder.summary.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
return view;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -46,13 +46,13 @@ public class AddDeleteDrawable extends Drawable {
|
||||
/**
|
||||
* @param context used to get the configuration for the drawable from
|
||||
*/
|
||||
public AddDeleteDrawable(Context context) {
|
||||
public AddDeleteDrawable(Context context, int color) {
|
||||
Resources resources = context.getResources();
|
||||
|
||||
mSize = resources.getDimensionPixelSize(R.dimen.add_size);
|
||||
float barThickness = Math.round(resources.getDimension(R.dimen.add_thickness));
|
||||
|
||||
mPaint.setColor(resources.getColor(R.color.primary_drawable_light));
|
||||
mPaint.setColor(color);
|
||||
mPaint.setStyle(Paint.Style.STROKE);
|
||||
mPaint.setStrokeJoin(Paint.Join.MITER);
|
||||
mPaint.setStrokeCap(Paint.Cap.BUTT);
|
||||
|
||||
@@ -0,0 +1,180 @@
|
||||
/*
|
||||
* Copyright 2018 Hippo Seven
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.hippo.drawable;
|
||||
|
||||
import android.content.res.ColorStateList;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.ColorFilter;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.Region;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v4.graphics.drawable.DrawableCompat;
|
||||
|
||||
public class DrawableWrapper extends Drawable implements Drawable.Callback {
|
||||
private Drawable mDrawable;
|
||||
|
||||
public DrawableWrapper(Drawable drawable) {
|
||||
this.setWrappedDrawable(drawable);
|
||||
}
|
||||
|
||||
public void draw(@NonNull Canvas canvas) {
|
||||
this.mDrawable.draw(canvas);
|
||||
}
|
||||
|
||||
protected void onBoundsChange(Rect bounds) {
|
||||
this.mDrawable.setBounds(bounds);
|
||||
}
|
||||
|
||||
public void setChangingConfigurations(int configs) {
|
||||
this.mDrawable.setChangingConfigurations(configs);
|
||||
}
|
||||
|
||||
public int getChangingConfigurations() {
|
||||
return this.mDrawable.getChangingConfigurations();
|
||||
}
|
||||
|
||||
public void setDither(boolean dither) {
|
||||
this.mDrawable.setDither(dither);
|
||||
}
|
||||
|
||||
public void setFilterBitmap(boolean filter) {
|
||||
this.mDrawable.setFilterBitmap(filter);
|
||||
}
|
||||
|
||||
public void setAlpha(int alpha) {
|
||||
this.mDrawable.setAlpha(alpha);
|
||||
}
|
||||
|
||||
public void setColorFilter(ColorFilter cf) {
|
||||
this.mDrawable.setColorFilter(cf);
|
||||
}
|
||||
|
||||
public boolean isStateful() {
|
||||
return this.mDrawable.isStateful();
|
||||
}
|
||||
|
||||
public boolean setState(@NonNull int[] stateSet) {
|
||||
return this.mDrawable.setState(stateSet);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public int[] getState() {
|
||||
return this.mDrawable.getState();
|
||||
}
|
||||
|
||||
public void jumpToCurrentState() {
|
||||
this.mDrawable.jumpToCurrentState();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public Drawable getCurrent() {
|
||||
return this.mDrawable.getCurrent();
|
||||
}
|
||||
|
||||
public boolean setVisible(boolean visible, boolean restart) {
|
||||
return super.setVisible(visible, restart) || this.mDrawable.setVisible(visible, restart);
|
||||
}
|
||||
|
||||
public int getOpacity() {
|
||||
return this.mDrawable.getOpacity();
|
||||
}
|
||||
|
||||
public Region getTransparentRegion() {
|
||||
return this.mDrawable.getTransparentRegion();
|
||||
}
|
||||
|
||||
public int getIntrinsicWidth() {
|
||||
return this.mDrawable.getIntrinsicWidth();
|
||||
}
|
||||
|
||||
public int getIntrinsicHeight() {
|
||||
return this.mDrawable.getIntrinsicHeight();
|
||||
}
|
||||
|
||||
public int getMinimumWidth() {
|
||||
return this.mDrawable.getMinimumWidth();
|
||||
}
|
||||
|
||||
public int getMinimumHeight() {
|
||||
return this.mDrawable.getMinimumHeight();
|
||||
}
|
||||
|
||||
public boolean getPadding(@NonNull Rect padding) {
|
||||
return this.mDrawable.getPadding(padding);
|
||||
}
|
||||
|
||||
public void invalidateDrawable(@NonNull Drawable who) {
|
||||
this.invalidateSelf();
|
||||
}
|
||||
|
||||
public void scheduleDrawable(@NonNull Drawable who, @NonNull Runnable what, long when) {
|
||||
this.scheduleSelf(what, when);
|
||||
}
|
||||
|
||||
public void unscheduleDrawable(@NonNull Drawable who, @NonNull Runnable what) {
|
||||
this.unscheduleSelf(what);
|
||||
}
|
||||
|
||||
protected boolean onLevelChange(int level) {
|
||||
return this.mDrawable.setLevel(level);
|
||||
}
|
||||
|
||||
public void setAutoMirrored(boolean mirrored) {
|
||||
DrawableCompat.setAutoMirrored(this.mDrawable, mirrored);
|
||||
}
|
||||
|
||||
public boolean isAutoMirrored() {
|
||||
return DrawableCompat.isAutoMirrored(this.mDrawable);
|
||||
}
|
||||
|
||||
public void setTint(int tint) {
|
||||
DrawableCompat.setTint(this.mDrawable, tint);
|
||||
}
|
||||
|
||||
public void setTintList(ColorStateList tint) {
|
||||
DrawableCompat.setTintList(this.mDrawable, tint);
|
||||
}
|
||||
|
||||
public void setTintMode(@NonNull PorterDuff.Mode tintMode) {
|
||||
DrawableCompat.setTintMode(this.mDrawable, tintMode);
|
||||
}
|
||||
|
||||
public void setHotspot(float x, float y) {
|
||||
DrawableCompat.setHotspot(this.mDrawable, x, y);
|
||||
}
|
||||
|
||||
public void setHotspotBounds(int left, int top, int right, int bottom) {
|
||||
DrawableCompat.setHotspotBounds(this.mDrawable, left, top, right, bottom);
|
||||
}
|
||||
|
||||
public Drawable getWrappedDrawable() {
|
||||
return this.mDrawable;
|
||||
}
|
||||
|
||||
public void setWrappedDrawable(Drawable drawable) {
|
||||
if (this.mDrawable != null) {
|
||||
this.mDrawable.setCallback(null);
|
||||
}
|
||||
|
||||
this.mDrawable = drawable;
|
||||
if (drawable != null) {
|
||||
drawable.setCallback(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -28,6 +28,7 @@ import android.graphics.Rect;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Build;
|
||||
|
||||
import android.support.annotation.ColorInt;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.yorozuya.MathUtils;
|
||||
|
||||
@@ -66,11 +67,11 @@ public class DrawerArrowDrawable extends Drawable {
|
||||
/**
|
||||
* @param context used to get the configuration for the drawable from
|
||||
*/
|
||||
public DrawerArrowDrawable(Context context) {
|
||||
public DrawerArrowDrawable(Context context, int color) {
|
||||
Resources resources = context.getResources();
|
||||
|
||||
mPaint.setAntiAlias(true);
|
||||
mPaint.setColor(resources.getColor(R.color.primary_drawable_light));
|
||||
mPaint.setColor(color);
|
||||
mSize = resources.getDimensionPixelSize(R.dimen.dad_drawable_size);
|
||||
// round this because having this floating may cause bad measurements
|
||||
mBarSize = Math.round(resources.getDimension(R.dimen.dad_bar_size));
|
||||
@@ -144,6 +145,11 @@ public class DrawerArrowDrawable extends Drawable {
|
||||
canvas.restore();
|
||||
}
|
||||
|
||||
public void setColor(@ColorInt int color) {
|
||||
mPaint.setColor(color);
|
||||
invalidateSelf();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAlpha(int i) {
|
||||
mPaint.setAlpha(i);
|
||||
|
||||
@@ -20,7 +20,6 @@ import android.graphics.Canvas;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.RectF;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.support.v7.graphics.drawable.DrawableWrapper;
|
||||
|
||||
import com.hippo.yorozuya.MathUtils;
|
||||
|
||||
|
||||
@@ -17,15 +17,32 @@
|
||||
package com.hippo.ehviewer;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.google.analytics.tracking.android.EasyTracker;
|
||||
import android.os.Bundle;
|
||||
import com.google.firebase.analytics.FirebaseAnalytics;
|
||||
import com.hippo.scene.SceneFragment;
|
||||
|
||||
|
||||
public final class Analytics {
|
||||
|
||||
private static FirebaseAnalytics analytics;
|
||||
|
||||
private Analytics() {}
|
||||
|
||||
public static void start(Context context) {
|
||||
EasyTracker.getInstance(context).set("&uid", Settings.getUserID());
|
||||
analytics = FirebaseAnalytics.getInstance(context);
|
||||
analytics.setUserId(Settings.getUserID());
|
||||
}
|
||||
|
||||
public static boolean isEnabled() {
|
||||
return analytics != null && Settings.getEnableAnalytics();
|
||||
}
|
||||
|
||||
public static void onSceneView(SceneFragment scene) {
|
||||
if (isEnabled()) {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString("scene_simple_class", scene.getClass().getSimpleName());
|
||||
bundle.putString("scene_class", scene.getClass().getName());
|
||||
analytics.logEvent("scene_view", bundle);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -37,7 +37,6 @@ public class AppConfig {
|
||||
private static final String DOWNLOAD = "download";
|
||||
private static final String TEMP = "temp";
|
||||
private static final String IMAGE = "image";
|
||||
private static final String CRASH = "crash";
|
||||
private static final String PARSE_ERROR = "parse_error";
|
||||
private static final String LOGCAT = "logcat";
|
||||
private static final String DATA = "data";
|
||||
@@ -95,11 +94,6 @@ public class AppConfig {
|
||||
return getDirInExternalAppDir(IMAGE);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static File getExternalCrashDir() {
|
||||
return getDirInExternalAppDir(CRASH);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static File getExternalParseErrorDir() {
|
||||
return getDirInExternalAppDir(PARSE_ERROR);
|
||||
|
||||
@@ -1,205 +0,0 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Build;
|
||||
import android.os.Debug;
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import com.hippo.scene.StageActivity;
|
||||
import com.hippo.util.PackageUtils;
|
||||
import com.hippo.util.ReadableTime;
|
||||
import com.hippo.yorozuya.FileUtils;
|
||||
import com.hippo.yorozuya.IOUtils;
|
||||
import com.hippo.yorozuya.OSUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.PrintWriter;
|
||||
|
||||
public final class Crash {
|
||||
private Crash() {}
|
||||
|
||||
@NonNull
|
||||
private static String avoidNull(String str) {
|
||||
return null != str ? str : "null";
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private static void collectInfo(Context context, FileWriter fw) throws IOException {
|
||||
try {
|
||||
PackageManager pm = context.getPackageManager();
|
||||
PackageInfo pi = pm.getPackageInfo(context.getPackageName(), PackageManager.GET_ACTIVITIES);
|
||||
if (pi != null) {
|
||||
String versionName = pi.versionName == null ? "null" : pi.versionName;
|
||||
String versionCode = String.valueOf(pi.versionCode);
|
||||
fw.write("======== PackageInfo ========\r\n");
|
||||
fw.write("PackageName=");fw.write(pi.packageName);fw.write("\r\n");
|
||||
fw.write("VersionName=");fw.write(versionName);fw.write("\r\n");
|
||||
fw.write("VersionCode=");fw.write(versionCode);fw.write("\r\n");
|
||||
String signature = PackageUtils.getSignature(context, pi.packageName);
|
||||
fw.write("Signature=");fw.write(null != signature ? signature : "null");fw.write("\r\n");
|
||||
fw.write("\r\n");
|
||||
}
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
fw.write("======== PackageInfo ========\r\n");
|
||||
fw.write("Can't get package information\r\n");
|
||||
fw.write("\r\n");
|
||||
}
|
||||
|
||||
// Runtime
|
||||
String topActivityClazzName = "null";
|
||||
String topSceneClazzName = "null";
|
||||
try {
|
||||
Activity topActivity = ((EhApplication) context.getApplicationContext()).getTopActivity();
|
||||
if (null != topActivity) {
|
||||
topActivityClazzName = topActivity.getClass().getName();
|
||||
if (topActivity instanceof StageActivity) {
|
||||
Class<?> clazz = ((StageActivity) topActivity).getTopSceneClass();
|
||||
if (clazz != null) {
|
||||
topSceneClazzName = clazz.getName();
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
// Ignore
|
||||
}
|
||||
fw.write("======== Runtime ========\r\n");
|
||||
fw.write("TopActivity=");fw.write(avoidNull(topActivityClazzName));fw.write("\r\n");
|
||||
fw.write("TopScene=");fw.write(avoidNull(topSceneClazzName));fw.write("\r\n");
|
||||
fw.write("\r\n");
|
||||
|
||||
// Device info
|
||||
fw.write("======== DeviceInfo ========\r\n");
|
||||
fw.write("BOARD=");fw.write(Build.BOARD);fw.write("\r\n");
|
||||
fw.write("BOOTLOADER=");fw.write(Build.BOOTLOADER);fw.write("\r\n");
|
||||
fw.write("CPU_ABI=");fw.write(Build.CPU_ABI);fw.write("\r\n");
|
||||
fw.write("CPU_ABI2=");fw.write(Build.CPU_ABI2);fw.write("\r\n");
|
||||
fw.write("DEVICE=");fw.write(Build.DEVICE);fw.write("\r\n");
|
||||
fw.write("DISPLAY=");fw.write(Build.DISPLAY);fw.write("\r\n");
|
||||
fw.write("FINGERPRINT=");fw.write(Build.FINGERPRINT);fw.write("\r\n");
|
||||
fw.write("HARDWARE=");fw.write(Build.HARDWARE);fw.write("\r\n");
|
||||
fw.write("HOST=");fw.write(Build.HOST);fw.write("\r\n");
|
||||
fw.write("ID=");fw.write(Build.ID);fw.write("\r\n");
|
||||
fw.write("MANUFACTURER=");fw.write(Build.MANUFACTURER);fw.write("\r\n");
|
||||
fw.write("MODEL=");fw.write(Build.MODEL);fw.write("\r\n");
|
||||
fw.write("PRODUCT=");fw.write(Build.PRODUCT);fw.write("\r\n");
|
||||
fw.write("RADIO=");fw.write(Build.getRadioVersion());fw.write("\r\n");
|
||||
fw.write("SERIAL=");fw.write(Build.SERIAL);fw.write("\r\n");
|
||||
fw.write("TAGS=");fw.write(Build.TAGS);fw.write("\r\n");
|
||||
fw.write("TYPE=");fw.write(Build.TYPE);fw.write("\r\n");
|
||||
fw.write("USER=");fw.write(Build.USER);fw.write("\r\n");
|
||||
fw.write("CODENAME=");fw.write(Build.VERSION.CODENAME);fw.write("\r\n");
|
||||
fw.write("INCREMENTAL=");fw.write(Build.VERSION.INCREMENTAL);fw.write("\r\n");
|
||||
fw.write("RELEASE=");fw.write(Build.VERSION.RELEASE);fw.write("\r\n");
|
||||
fw.write("SDK=");fw.write(Integer.toString(Build.VERSION.SDK_INT));fw.write("\r\n");
|
||||
fw.write("MEMORY=");fw.write(FileUtils.humanReadableByteCount(OSUtils.getAppAllocatedMemory(), false));fw.write("\r\n");
|
||||
fw.write("MEMORY_NATIVE=");fw.write(FileUtils.humanReadableByteCount(Debug.getNativeHeapAllocatedSize(), false));fw.write("\r\n");
|
||||
fw.write("MEMORY_MAX=");fw.write(FileUtils.humanReadableByteCount(OSUtils.getAppMaxMemory(), false));fw.write("\r\n");
|
||||
fw.write("MEMORY_TOTAL=");fw.write(FileUtils.humanReadableByteCount(OSUtils.getTotalMemory(), false));fw.write("\r\n");
|
||||
fw.write("\r\n");
|
||||
}
|
||||
|
||||
public static void getThrowableInfo(Throwable t, FileWriter fw) {
|
||||
PrintWriter printWriter = new PrintWriter(fw);
|
||||
t.printStackTrace(printWriter);
|
||||
Throwable cause = t.getCause();
|
||||
while (cause != null) {
|
||||
cause.printStackTrace(printWriter);
|
||||
cause = cause.getCause();
|
||||
}
|
||||
}
|
||||
|
||||
public static void saveCrashInfo2File(Context context, Throwable ex) {
|
||||
File dir = AppConfig.getExternalCrashDir();
|
||||
if (dir == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
String nowString = ReadableTime.getFilenamableTime(System.currentTimeMillis());
|
||||
String fileName = "crash-" + nowString + ".log";
|
||||
File file = new File(dir, fileName);
|
||||
|
||||
FileWriter fw = null;
|
||||
try {
|
||||
fw = new FileWriter(file);
|
||||
fw.write("TIME=");fw.write(nowString);fw.write("\r\n");
|
||||
fw.write("\r\n");
|
||||
collectInfo(context, fw);
|
||||
fw.write("======== CrashInfo ========\r\n");
|
||||
getThrowableInfo(ex, fw);
|
||||
fw.write("\r\n");
|
||||
|
||||
fw.flush();
|
||||
|
||||
Settings.putCrashFilename(fileName);
|
||||
} catch (Exception e) {
|
||||
file.delete();
|
||||
} finally {
|
||||
IOUtils.closeQuietly(fw);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean hasCrashFile() {
|
||||
String filename = Settings.getCrashFilename();
|
||||
if (filename == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
File dir = AppConfig.getExternalCrashDir();
|
||||
if (dir == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return new File(dir, filename).isFile();
|
||||
}
|
||||
|
||||
public static String getCrashContent() {
|
||||
String filename = Settings.getCrashFilename();
|
||||
if (filename == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
File dir = AppConfig.getExternalCrashDir();
|
||||
if (dir == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
File file = new File(dir, filename);
|
||||
|
||||
InputStream is = null;
|
||||
try {
|
||||
is = new FileInputStream(file);
|
||||
return IOUtils.readString(is, "UTF-8");
|
||||
} catch (IOException e) {
|
||||
return null;
|
||||
} finally {
|
||||
IOUtils.closeQuietly(is);
|
||||
}
|
||||
}
|
||||
|
||||
public static void resetCrashFile() {
|
||||
Settings.putCrashFilename(null);
|
||||
}
|
||||
}
|
||||
@@ -26,6 +26,7 @@ import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.util.LruCache;
|
||||
import android.util.Log;
|
||||
import com.facebook.soloader.SoLoader;
|
||||
import com.hippo.beerbelly.SimpleDiskCache;
|
||||
import com.hippo.conaco.Conaco;
|
||||
import com.hippo.content.RecordingApplication;
|
||||
@@ -49,6 +50,7 @@ import com.hippo.yorozuya.IntIdGenerator;
|
||||
import com.hippo.yorozuya.OSUtils;
|
||||
import com.hippo.yorozuya.SimpleHandler;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
@@ -56,20 +58,17 @@ import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import okhttp3.OkHttpClient;
|
||||
|
||||
public class EhApplication extends RecordingApplication implements Thread.UncaughtExceptionHandler {
|
||||
public class EhApplication extends RecordingApplication {
|
||||
|
||||
private static final String TAG = EhApplication.class.getSimpleName();
|
||||
|
||||
public static final boolean BETA = false;
|
||||
public static final boolean AUTO_UPDATE = true;
|
||||
|
||||
private static final boolean DEBUG_CONACO = false;
|
||||
private static final boolean DEBUG_PRINT_NATIVE_MEMORY = false;
|
||||
private static final boolean DEBUG_PRINT_IMAGE_COUNT = false;
|
||||
private static final long DEBUG_PRINT_INTERVAL = 3000L;
|
||||
|
||||
private Thread.UncaughtExceptionHandler mDefaultHandler;
|
||||
|
||||
private final IntIdGenerator mIdGenerator = new IntIdGenerator();
|
||||
private final HashMap<Integer, Object> mGlobalStuffMap = new HashMap<>();
|
||||
private EhCookieStore mEhCookieStore;
|
||||
@@ -86,12 +85,14 @@ public class EhApplication extends RecordingApplication implements Thread.Uncaug
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
// Prepare to catch crash
|
||||
mDefaultHandler = Thread.getDefaultUncaughtExceptionHandler();
|
||||
Thread.setDefaultUncaughtExceptionHandler(this);
|
||||
|
||||
super.onCreate();
|
||||
|
||||
try {
|
||||
SoLoader.init(this, 0);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Could not initialize SoLoader", e);
|
||||
}
|
||||
|
||||
GetText.initialize(this);
|
||||
StatusCodeException.initialize(this);
|
||||
Settings.initialize(this);
|
||||
@@ -317,34 +318,6 @@ public class EhApplication extends RecordingApplication implements Thread.Uncaug
|
||||
return application.mHosts;
|
||||
}
|
||||
|
||||
private boolean handleException(Throwable ex) {
|
||||
if (ex == null) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
ex.printStackTrace();
|
||||
Crash.saveCrashInfo2File(this, ex);
|
||||
return true;
|
||||
} catch (Throwable tr) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void uncaughtException(Thread thread, Throwable ex) {
|
||||
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);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static String getDeveloperEmail() {
|
||||
return "ehviewersu$gmail.com".replace('$', '@');
|
||||
|
||||
@@ -43,6 +43,7 @@ import com.hippo.ehviewer.dao.LocalFavoritesDao;
|
||||
import com.hippo.ehviewer.dao.QuickSearch;
|
||||
import com.hippo.ehviewer.dao.QuickSearchDao;
|
||||
import com.hippo.ehviewer.download.DownloadManager;
|
||||
import com.hippo.util.ExceptionUtils;
|
||||
import com.hippo.util.SqlUtils;
|
||||
import com.hippo.yorozuya.FileUtils;
|
||||
import com.hippo.yorozuya.IOUtils;
|
||||
@@ -156,7 +157,8 @@ public class EhDB {
|
||||
SQLiteDatabase oldDB;
|
||||
try {
|
||||
oldDB = oldDBHelper.getReadableDatabase();
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -178,7 +180,8 @@ public class EhDB {
|
||||
try {
|
||||
// In 0.6.x version, NaN is stored
|
||||
gi.rating = cursor.getFloat(7);
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
gi.rating = -1.0f;
|
||||
}
|
||||
|
||||
@@ -189,7 +192,8 @@ public class EhDB {
|
||||
}
|
||||
cursor.close();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
// Ignore
|
||||
}
|
||||
|
||||
@@ -219,7 +223,8 @@ public class EhDB {
|
||||
}
|
||||
cursor.close();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
// Ignore
|
||||
}
|
||||
|
||||
@@ -255,7 +260,8 @@ public class EhDB {
|
||||
}
|
||||
cursor.close();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
// Ignore
|
||||
}
|
||||
|
||||
@@ -296,7 +302,8 @@ public class EhDB {
|
||||
}
|
||||
cursor.close();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
// Ignore
|
||||
}
|
||||
|
||||
@@ -325,13 +332,15 @@ public class EhDB {
|
||||
}
|
||||
cursor.close();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
// Ignore
|
||||
}
|
||||
|
||||
try {
|
||||
oldDBHelper.close();
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
// Ignore
|
||||
}
|
||||
}
|
||||
@@ -726,7 +735,8 @@ public class EhDB {
|
||||
}
|
||||
|
||||
return null;
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
// Ignore
|
||||
return context.getString(R.string.cant_read_the_file);
|
||||
}
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package com.hippo.ehviewer;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.net.Uri;
|
||||
@@ -25,19 +24,17 @@ import android.support.annotation.DimenRes;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.util.Log;
|
||||
|
||||
import com.hippo.ehviewer.client.EhConfig;
|
||||
import com.hippo.ehviewer.client.EhUtils;
|
||||
import com.hippo.ehviewer.client.data.FavListUrlBuilder;
|
||||
import com.hippo.ehviewer.ui.CommonOperations;
|
||||
import com.hippo.glgallery.GalleryView;
|
||||
import com.hippo.unifile.UniFile;
|
||||
import com.hippo.util.ExceptionUtils;
|
||||
import com.hippo.yorozuya.AssertUtils;
|
||||
import com.hippo.yorozuya.FileUtils;
|
||||
import com.hippo.yorozuya.MathUtils;
|
||||
import com.hippo.yorozuya.NumberUtils;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class Settings {
|
||||
@@ -237,6 +234,28 @@ public class Settings {
|
||||
/********************
|
||||
****** Eh
|
||||
********************/
|
||||
|
||||
public static final String KEY_THEME = "theme";
|
||||
public static final int THEME_LIGHT = 0;
|
||||
public static final int THEME_DARK = 1;
|
||||
public static final int THEME_BLACK = 2;
|
||||
private static final int DEFAULT_THEME = THEME_LIGHT;
|
||||
|
||||
public static int getTheme() {
|
||||
return getIntFromStr(KEY_THEME, DEFAULT_THEME);
|
||||
}
|
||||
|
||||
public static void putTheme(int theme) {
|
||||
putIntToStr(KEY_THEME, theme);
|
||||
}
|
||||
|
||||
public static final String KEY_APPLY_NAV_BAR_THEME_COLOR = "apply_nav_bar_theme_color";
|
||||
private static final boolean DEFAULT_APPLY_NAV_BAR_THEME_COLOR = false;
|
||||
|
||||
public static boolean getApplyNavBarThemeColor() {
|
||||
return getBoolean(KEY_APPLY_NAV_BAR_THEME_COLOR, DEFAULT_APPLY_NAV_BAR_THEME_COLOR);
|
||||
}
|
||||
|
||||
public static final String KEY_GALLERY_SITE = "gallery_site";
|
||||
private static final int DEFAULT_GALLERY_SITE = 1;
|
||||
|
||||
@@ -615,7 +634,8 @@ public class Settings {
|
||||
builder.encodedQuery(getString(KEY_DOWNLOAD_SAVE_QUERY, null));
|
||||
builder.encodedFragment(getString(KEY_DOWNLOAD_SAVE_FRAGMENT, null));
|
||||
dir = UniFile.fromUri(sContext, builder.build());
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
// Ignore
|
||||
}
|
||||
return dir != null ? dir : UniFile.fromFile(AppConfig.getDefaultDownloadDir());
|
||||
@@ -778,7 +798,7 @@ public class Settings {
|
||||
}
|
||||
|
||||
public static void putFavCat(String[] value) {
|
||||
Assert.assertEquals(10, value.length);
|
||||
AssertUtils.assertEquals(10, value.length);
|
||||
sSettingsPre.edit()
|
||||
.putString(KEY_FAV_CAT_0, value[0])
|
||||
.putString(KEY_FAV_CAT_1, value[1])
|
||||
@@ -809,7 +829,7 @@ public class Settings {
|
||||
}
|
||||
|
||||
public static void putFavCount(int[] count) {
|
||||
Assert.assertEquals(10, count.length);
|
||||
AssertUtils.assertEquals(10, count.length);
|
||||
sSettingsPre.edit()
|
||||
.putInt(KEY_FAV_COUNT_0, count[0])
|
||||
.putInt(KEY_FAV_COUNT_1, count[1])
|
||||
@@ -956,8 +976,8 @@ public class Settings {
|
||||
********************/
|
||||
private static final String KEY_BETA_UPDATE_CHANNEL = "beta_update_channel";
|
||||
private static final boolean DEFAULT_BETA_UPDATE_CHANNEL = EhApplication.BETA;
|
||||
private static final String KEY_AUTO_CHECK_FOR_UPDATES = "auto_check_for_updates";
|
||||
private static final boolean DEFAULT_AUTO_CHECK_FOR_UPDATES = EhApplication.AUTO_UPDATE;
|
||||
private static final String KEY_SKIP_UPDATE_VERSION = "skip_update_version";
|
||||
private static final int DEFAULT_SKIP_UPDATE_VERSION = 0;
|
||||
|
||||
public static boolean getBetaUpdateChannel() {
|
||||
return getBoolean(KEY_BETA_UPDATE_CHANNEL, DEFAULT_BETA_UPDATE_CHANNEL);
|
||||
@@ -967,23 +987,12 @@ public class Settings {
|
||||
putBoolean(KEY_BETA_UPDATE_CHANNEL, value);
|
||||
}
|
||||
|
||||
public static boolean getAutoCheckUpdateEnable() {
|
||||
return getBoolean(KEY_AUTO_CHECK_FOR_UPDATES, DEFAULT_AUTO_CHECK_FOR_UPDATES);
|
||||
public static int getSkipUpdateVersion() {
|
||||
return getInt(KEY_SKIP_UPDATE_VERSION, DEFAULT_SKIP_UPDATE_VERSION);
|
||||
}
|
||||
|
||||
/********************
|
||||
****** Crash
|
||||
********************/
|
||||
private static final String KEY_CRASH_FILENAME = "crash_filename";
|
||||
private static final String DEFAULT_CRASH_FILENAME = null;
|
||||
|
||||
public static String getCrashFilename() {
|
||||
return getString(KEY_CRASH_FILENAME, DEFAULT_CRASH_FILENAME);
|
||||
}
|
||||
|
||||
@SuppressLint("CommitPrefEdits")
|
||||
public static void putCrashFilename(String value) {
|
||||
sSettingsPre.edit().putString(KEY_CRASH_FILENAME, value).commit();
|
||||
public static void putSkipUpdateVersion(int value) {
|
||||
putInt(KEY_SKIP_UPDATE_VERSION, value);
|
||||
}
|
||||
|
||||
/********************
|
||||
|
||||
@@ -18,13 +18,12 @@ package com.hippo.ehviewer.client;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.AsyncTask;
|
||||
|
||||
import com.hippo.ehviewer.EhApplication;
|
||||
import com.hippo.ehviewer.client.data.GalleryInfo;
|
||||
import com.hippo.ehviewer.client.exception.CancelledException;
|
||||
import com.hippo.util.ExceptionUtils;
|
||||
import com.hippo.yorozuya.SimpleHandler;
|
||||
import com.hippo.yorozuya.thread.PriorityThreadFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
@@ -34,7 +33,6 @@ import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import okhttp3.Call;
|
||||
import okhttp3.OkHttpClient;
|
||||
|
||||
@@ -193,7 +191,8 @@ public class EhClient {
|
||||
default:
|
||||
return new IllegalStateException("Can't detect method " + mMethod);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
return e;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,6 @@ import android.support.annotation.Nullable;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.util.Pair;
|
||||
|
||||
import com.hippo.ehviewer.AppConfig;
|
||||
import com.hippo.ehviewer.GetText;
|
||||
import com.hippo.ehviewer.R;
|
||||
@@ -48,21 +47,13 @@ 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 junit.framework.Assert;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Document;
|
||||
import org.jsoup.select.Elements;
|
||||
|
||||
import com.hippo.util.ExceptionUtils;
|
||||
import com.hippo.yorozuya.AssertUtils;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import okhttp3.Call;
|
||||
import okhttp3.FormBody;
|
||||
import okhttp3.Headers;
|
||||
@@ -72,6 +63,11 @@ import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.RequestBody;
|
||||
import okhttp3.Response;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Document;
|
||||
import org.jsoup.select.Elements;
|
||||
|
||||
public class EhEngine {
|
||||
|
||||
@@ -93,7 +89,7 @@ public class EhEngine {
|
||||
}
|
||||
|
||||
private static void doThrowException(Call call, int code, @Nullable Headers headers,
|
||||
@Nullable String body, Exception e) throws Exception {
|
||||
@Nullable String body, Throwable e) throws Throwable {
|
||||
if (call.isCanceled()) {
|
||||
throw new CancelledException();
|
||||
}
|
||||
@@ -126,7 +122,7 @@ public class EhEngine {
|
||||
}
|
||||
|
||||
private static void throwException(Call call, int code, @Nullable Headers headers,
|
||||
@Nullable String body, Exception e) throws Exception {
|
||||
@Nullable String body, Throwable e) throws Throwable {
|
||||
try {
|
||||
doThrowException(call, code, headers, body, e);
|
||||
} catch (Throwable error) {
|
||||
@@ -136,7 +132,7 @@ public class EhEngine {
|
||||
}
|
||||
|
||||
public static String signIn(@Nullable EhClient.Task task, OkHttpClient okHttpClient,
|
||||
String username, String password, String recaptchaChallenge, String recaptchaResponse) throws Exception {
|
||||
String username, String password, String recaptchaChallenge, String recaptchaResponse) throws Throwable {
|
||||
FormBody.Builder builder = new FormBody.Builder()
|
||||
.add("UserName", username)
|
||||
.add("PassWord", password)
|
||||
@@ -168,14 +164,15 @@ public class EhEngine {
|
||||
headers = response.headers();
|
||||
body = response.body().string();
|
||||
return SignInParser.parse(body);
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
throwException(call, code, headers, body, e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
public static GalleryListParser.Result getGalleryList(@Nullable EhClient.Task task, OkHttpClient okHttpClient,
|
||||
String url) throws Exception {
|
||||
String url) throws Throwable {
|
||||
Log.d(TAG, url);
|
||||
Request request = new EhRequestBuilder(url, null != task ? task.getEhConfig() : Settings.getEhConfig()).build();
|
||||
Call call = okHttpClient.newCall(request);
|
||||
@@ -195,7 +192,8 @@ public class EhEngine {
|
||||
headers = response.headers();
|
||||
body = response.body().string();
|
||||
result = GalleryListParser.parse(body);
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
throwException(call, code, headers, body, e);
|
||||
throw e;
|
||||
}
|
||||
@@ -211,7 +209,7 @@ public class EhEngine {
|
||||
}
|
||||
}
|
||||
|
||||
if (list.size() > 0 && (Settings.getShowJpnTitle() || Settings.getShowGalleryPages() || sEhFilter.needCallApi())) {
|
||||
if (list.size() > 0 && (TextUtils.isEmpty(list.get(0).uploader) || Settings.getShowJpnTitle() || Settings.getShowGalleryPages() || sEhFilter.needCallApi())) {
|
||||
// Fill by api
|
||||
fillGalleryListByApi(task, okHttpClient, list);
|
||||
|
||||
@@ -235,7 +233,7 @@ public class EhEngine {
|
||||
|
||||
// At least, GalleryInfo contain valid gid and token
|
||||
public static List<GalleryInfo> fillGalleryListByApi(@Nullable EhClient.Task task, OkHttpClient okHttpClient,
|
||||
List<GalleryInfo> galleryInfoList) throws Exception {
|
||||
List<GalleryInfo> galleryInfoList) throws Throwable {
|
||||
// We can only request 25 items one time at most
|
||||
final int MAX_REQUEST_SIZE = 25;
|
||||
List<GalleryInfo> requestItems = new ArrayList<>(MAX_REQUEST_SIZE);
|
||||
@@ -250,7 +248,7 @@ public class EhEngine {
|
||||
}
|
||||
|
||||
private static void doFillGalleryListByApi(@Nullable EhClient.Task task, OkHttpClient okHttpClient,
|
||||
List<GalleryInfo> galleryInfoList) throws Exception {
|
||||
List<GalleryInfo> galleryInfoList) throws Throwable {
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("method", "gdata");
|
||||
JSONArray ja = new JSONArray();
|
||||
@@ -284,14 +282,15 @@ public class EhEngine {
|
||||
headers = response.headers();
|
||||
body = response.body().string();
|
||||
GalleryApiParser.parse(body, galleryInfoList);
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
throwException(call, code, headers, body, e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
public static GalleryDetail getGalleryDetail(@Nullable EhClient.Task task, OkHttpClient okHttpClient,
|
||||
String url) throws Exception {
|
||||
String url) throws Throwable {
|
||||
Log.d(TAG, url);
|
||||
Request request = new EhRequestBuilder(url, null != task ? task.getEhConfig() : Settings.getEhConfig()).build();
|
||||
Call call = okHttpClient.newCall(request);
|
||||
@@ -310,7 +309,8 @@ public class EhEngine {
|
||||
headers = response.headers();
|
||||
body = response.body().string();
|
||||
return GalleryDetailParser.parse(body);
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
throwException(call, code, headers, body, e);
|
||||
throw e;
|
||||
}
|
||||
@@ -318,7 +318,7 @@ public class EhEngine {
|
||||
|
||||
|
||||
public static Pair<PreviewSet, Integer> getPreviewSet(
|
||||
@Nullable EhClient.Task task, OkHttpClient okHttpClient, String url) throws Exception {
|
||||
@Nullable EhClient.Task task, OkHttpClient okHttpClient, String url) throws Throwable {
|
||||
Log.d(TAG, url);
|
||||
Request request = new EhRequestBuilder(url, null != task ? task.getEhConfig() : Settings.getEhConfig()).build();
|
||||
Call call = okHttpClient.newCall(request);
|
||||
@@ -338,7 +338,8 @@ public class EhEngine {
|
||||
body = response.body().string();
|
||||
return Pair.create(GalleryDetailParser.parsePreviewSet(body),
|
||||
GalleryDetailParser.parsePreviewPages(body));
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
throwException(call, code, headers, body, e);
|
||||
throw e;
|
||||
}
|
||||
@@ -346,7 +347,7 @@ public class EhEngine {
|
||||
|
||||
public static RateGalleryParser.Result rateGallery(@Nullable EhClient.Task task,
|
||||
OkHttpClient okHttpClient, long apiUid, String apiKey, long gid,
|
||||
String token, float rating) throws Exception {
|
||||
String token, float rating) throws Throwable {
|
||||
final JSONObject json = new JSONObject();
|
||||
json.put("method", "rategallery");
|
||||
json.put("apiuid", apiUid);
|
||||
@@ -376,14 +377,15 @@ public class EhEngine {
|
||||
headers = response.headers();
|
||||
body = response.body().string();
|
||||
return RateGalleryParser.parse(body);
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
throwException(call, code, headers, body, e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
public static GalleryComment[] commentGallery(@Nullable EhClient.Task task,
|
||||
OkHttpClient okHttpClient, String url, String comment) throws Exception {
|
||||
OkHttpClient okHttpClient, String url, String comment) throws Throwable {
|
||||
FormBody.Builder builder = new FormBody.Builder()
|
||||
.add("commenttext_new", comment);
|
||||
Log.d(TAG, url);
|
||||
@@ -413,14 +415,15 @@ public class EhEngine {
|
||||
}
|
||||
|
||||
return GalleryDetailParser.parseComments(document);
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
throwException(call, code, headers, body, e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
public static String getGalleryToken(@Nullable EhClient.Task task, OkHttpClient okHttpClient,
|
||||
long gid, String gtoken, int page) throws Exception {
|
||||
long gid, String gtoken, int page) throws Throwable {
|
||||
JSONObject json = new JSONObject()
|
||||
.put("method", "gtoken")
|
||||
.put("pagelist", new JSONArray().put(
|
||||
@@ -447,14 +450,15 @@ public class EhEngine {
|
||||
headers = response.headers();
|
||||
body = response.body().string();
|
||||
return GalleryTokenApiParser.parse(body);
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
throwException(call, code, headers, body, e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
public static FavoritesParser.Result getFavorites(@Nullable EhClient.Task task, OkHttpClient okHttpClient,
|
||||
String url, boolean callApi) throws Exception {
|
||||
String url, boolean callApi) throws Throwable {
|
||||
Log.d(TAG, url);
|
||||
Request request = new EhRequestBuilder(url, null != task ? task.getEhConfig() : Settings.getEhConfig()).build();
|
||||
Call call = okHttpClient.newCall(request);
|
||||
@@ -474,16 +478,19 @@ public class EhEngine {
|
||||
headers = response.headers();
|
||||
body = response.body().string();
|
||||
result = FavoritesParser.parse(body);
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
throwException(call, code, headers, body, e);
|
||||
throw e;
|
||||
}
|
||||
|
||||
if (callApi && result.galleryInfoList.size() > 0) {
|
||||
fillGalleryListByApi(task, okHttpClient, result.galleryInfoList);
|
||||
List<GalleryInfo> list = result.galleryInfoList;
|
||||
|
||||
if (list.size() > 0 && (TextUtils.isEmpty(list.get(0).uploader) || Settings.getShowJpnTitle() || Settings.getShowGalleryPages())) {
|
||||
fillGalleryListByApi(task, okHttpClient, list);
|
||||
}
|
||||
|
||||
for (GalleryInfo info : result.galleryInfoList) {
|
||||
for (GalleryInfo info : list) {
|
||||
info.thumb = EhUrl.getFixedPreviewThumbUrl(info.thumb);
|
||||
}
|
||||
|
||||
@@ -495,7 +502,7 @@ public class EhEngine {
|
||||
* @param note max 250 characters
|
||||
*/
|
||||
public static Void addFavorites(@Nullable EhClient.Task task, OkHttpClient okHttpClient,
|
||||
long gid, String token, int dstCat, String note) throws Exception {
|
||||
long gid, String token, int dstCat, String note) throws Throwable {
|
||||
String catStr;
|
||||
if (dstCat == -1) {
|
||||
catStr = "favdel";
|
||||
@@ -531,7 +538,8 @@ public class EhEngine {
|
||||
headers = response.headers();
|
||||
body = response.body().string();
|
||||
throwException(call, code, headers, body, null);
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
throwException(call, code, headers, body, e);
|
||||
throw e;
|
||||
}
|
||||
@@ -540,8 +548,8 @@ public class EhEngine {
|
||||
}
|
||||
|
||||
public static Void addFavoritesRange(@Nullable EhClient.Task task, OkHttpClient okHttpClient,
|
||||
long[] gidArray, String[] tokenArray, int dstCat) throws Exception {
|
||||
Assert.assertEquals(gidArray.length, tokenArray.length);
|
||||
long[] gidArray, String[] tokenArray, int dstCat) throws Throwable {
|
||||
AssertUtils.assertEquals(gidArray.length, tokenArray.length);
|
||||
for (int i = 0, n = gidArray.length; i < n; i++) {
|
||||
addFavorites(task, okHttpClient, gidArray[i], tokenArray[i], dstCat, null);
|
||||
}
|
||||
@@ -549,7 +557,7 @@ public class EhEngine {
|
||||
}
|
||||
|
||||
public static FavoritesParser.Result modifyFavorites(@Nullable EhClient.Task task, OkHttpClient okHttpClient,
|
||||
String url, long[] gidArray, int dstCat, boolean callApi) throws Exception {
|
||||
String url, long[] gidArray, int dstCat, boolean callApi) throws Throwable {
|
||||
String catStr;
|
||||
if (dstCat == -1) {
|
||||
catStr = "delete";
|
||||
@@ -585,16 +593,18 @@ public class EhEngine {
|
||||
headers = response.headers();
|
||||
body = response.body().string();
|
||||
result = FavoritesParser.parse(body);
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
throwException(call, code, headers, body, e);
|
||||
throw e;
|
||||
}
|
||||
|
||||
if (callApi && result.galleryInfoList.size() > 0) {
|
||||
fillGalleryListByApi(task, okHttpClient, result.galleryInfoList);
|
||||
List<GalleryInfo> list = result.galleryInfoList;
|
||||
if (list.size() > 0 && (TextUtils.isEmpty(list.get(0).uploader) || Settings.getShowJpnTitle() || Settings.getShowGalleryPages())) {
|
||||
fillGalleryListByApi(task, okHttpClient, list);
|
||||
}
|
||||
|
||||
for (GalleryInfo info : result.galleryInfoList) {
|
||||
for (GalleryInfo info : list) {
|
||||
info.thumb = EhUrl.getFixedPreviewThumbUrl(info.thumb);
|
||||
}
|
||||
|
||||
@@ -602,7 +612,7 @@ public class EhEngine {
|
||||
}
|
||||
|
||||
public static Pair<String, String>[] getTorrentList(@Nullable EhClient.Task task, OkHttpClient okHttpClient,
|
||||
String url) throws Exception {
|
||||
String url) throws Throwable {
|
||||
Log.d(TAG, url);
|
||||
Request request = new EhRequestBuilder(url, null != task ? task.getEhConfig() : Settings.getEhConfig()).build();
|
||||
Call call = okHttpClient.newCall(request);
|
||||
@@ -622,7 +632,8 @@ public class EhEngine {
|
||||
headers = response.headers();
|
||||
body = response.body().string();
|
||||
result = TorrentParser.parse(body);
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
throwException(call, code, headers, body, e);
|
||||
throw e;
|
||||
}
|
||||
@@ -631,7 +642,7 @@ public class EhEngine {
|
||||
}
|
||||
|
||||
public static Pair<String, Pair<String, String>[]> getArchiveList(@Nullable EhClient.Task task, OkHttpClient okHttpClient,
|
||||
String url) throws Exception {
|
||||
String url) throws Throwable {
|
||||
Log.d(TAG, url);
|
||||
Request request = new EhRequestBuilder(url, null != task ? task.getEhConfig() : Settings.getEhConfig()).build();
|
||||
Call call = okHttpClient.newCall(request);
|
||||
@@ -651,7 +662,8 @@ public class EhEngine {
|
||||
headers = response.headers();
|
||||
body = response.body().string();
|
||||
result = ArchiveParser.parse(body);
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
throwException(call, code, headers, body, e);
|
||||
throw e;
|
||||
}
|
||||
@@ -660,7 +672,7 @@ public class EhEngine {
|
||||
}
|
||||
|
||||
public static Void downloadArchive(@Nullable EhClient.Task task, OkHttpClient okHttpClient,
|
||||
long gid, String token, String or, String res) throws Exception {
|
||||
long gid, String token, String or, String res) throws Throwable {
|
||||
if (or == null || or.length() == 0) {
|
||||
throw new EhException("Invalid form param or: " + or);
|
||||
}
|
||||
@@ -690,7 +702,8 @@ public class EhEngine {
|
||||
headers = response.headers();
|
||||
body = response.body().string();
|
||||
throwException(call, code, headers, body, null);
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
throwException(call, code, headers, body, e);
|
||||
throw e;
|
||||
}
|
||||
@@ -704,7 +717,7 @@ public class EhEngine {
|
||||
}
|
||||
|
||||
public static List<GalleryInfo> getWhatsHot(@Nullable EhClient.Task task,
|
||||
OkHttpClient okHttpClient) throws Exception {
|
||||
OkHttpClient okHttpClient) throws Throwable {
|
||||
String url = EhUrl.HOST_E;
|
||||
Log.d(TAG, url);
|
||||
Request request = new EhRequestBuilder(url, null != task ? task.getEhConfig() : Settings.getEhConfig()).build();
|
||||
@@ -725,7 +738,8 @@ public class EhEngine {
|
||||
headers = response.headers();
|
||||
body = response.body().string();
|
||||
list = WhatsHotParser.parse(body);
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
throwException(call, code, headers, body, e);
|
||||
throw e;
|
||||
}
|
||||
@@ -743,7 +757,7 @@ public class EhEngine {
|
||||
}
|
||||
|
||||
private static ProfileParser.Result getProfileInternal(@Nullable EhClient.Task task,
|
||||
OkHttpClient okHttpClient, String url) throws Exception {
|
||||
OkHttpClient okHttpClient, String url) throws Throwable {
|
||||
Log.d(TAG, url);
|
||||
Request request = new EhRequestBuilder(url, null != task ? task.getEhConfig() : Settings.getEhConfig()).build();
|
||||
Call call = okHttpClient.newCall(request);
|
||||
@@ -762,14 +776,15 @@ public class EhEngine {
|
||||
headers = response.headers();
|
||||
body = response.body().string();
|
||||
return ProfileParser.parse(body);
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
throwException(call, code, headers, body, e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
public static ProfileParser.Result getProfile(@Nullable EhClient.Task task,
|
||||
OkHttpClient okHttpClient) throws Exception {
|
||||
OkHttpClient okHttpClient) throws Throwable {
|
||||
String url = EhUrl.URL_FORUMS;
|
||||
Log.d(TAG, url);
|
||||
Request request = new EhRequestBuilder(url, null != task ? task.getEhConfig() : Settings.getEhConfig()).build();
|
||||
@@ -789,14 +804,15 @@ public class EhEngine {
|
||||
headers = response.headers();
|
||||
body = response.body().string();
|
||||
return getProfileInternal(task, okHttpClient, ForumsParser.parse(body));
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
throwException(call, code, headers, body, e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
public static VoteCommentParser.Result voteComment(@Nullable EhClient.Task task, OkHttpClient okHttpClient,
|
||||
long apiUid, String apiKey, long gid, String token, long commentId, int commentVote) throws Exception {
|
||||
long apiUid, String apiKey, long gid, String token, long commentId, int commentVote) throws Throwable {
|
||||
final JSONObject json = new JSONObject();
|
||||
json.put("method", "votecomment");
|
||||
json.put("apiuid", apiUid);
|
||||
@@ -827,7 +843,8 @@ public class EhEngine {
|
||||
headers = response.headers();
|
||||
body = response.body().string();
|
||||
return VoteCommentParser.parse(body, commentVote);
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
throwException(call, code, headers, body, e);
|
||||
throw e;
|
||||
}
|
||||
@@ -837,7 +854,7 @@ public class EhEngine {
|
||||
* @param image Must be jpeg
|
||||
*/
|
||||
public static GalleryListParser.Result imageSearch(@Nullable EhClient.Task task, OkHttpClient okHttpClient,
|
||||
File image, boolean uss, boolean osc, boolean se) throws Exception {
|
||||
File image, boolean uss, boolean osc, boolean se) throws Throwable {
|
||||
MultipartBody.Builder builder = new MultipartBody.Builder();
|
||||
builder.setType(MultipartBody.FORM);
|
||||
builder.addPart(
|
||||
@@ -891,7 +908,8 @@ public class EhEngine {
|
||||
headers = response.headers();
|
||||
body = response.body().string();
|
||||
result = GalleryListParser.parse(body);
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
throwException(call, code, headers, body, e);
|
||||
throw e;
|
||||
}
|
||||
@@ -907,7 +925,7 @@ public class EhEngine {
|
||||
}
|
||||
}
|
||||
|
||||
if (list.size() > 0 && (Settings.getShowJpnTitle() || Settings.getShowGalleryPages() || sEhFilter.needCallApi())) {
|
||||
if (list.size() > 0 && (TextUtils.isEmpty(list.get(0).uploader) || Settings.getShowJpnTitle() || Settings.getShowGalleryPages() || sEhFilter.needCallApi())) {
|
||||
// Fill by api
|
||||
fillGalleryListByApi(task, okHttpClient, list);
|
||||
|
||||
@@ -930,7 +948,7 @@ public class EhEngine {
|
||||
}
|
||||
|
||||
public static GalleryPageParser.Result getGalleryPage(@Nullable EhClient.Task task,
|
||||
OkHttpClient okHttpClient, String url) throws Exception {
|
||||
OkHttpClient okHttpClient, String url) throws Throwable {
|
||||
Log.d(TAG, url);
|
||||
Request request = new EhRequestBuilder(url, null != task ? task.getEhConfig() : Settings.getEhConfig()).build();
|
||||
Call call = okHttpClient.newCall(request);
|
||||
@@ -949,7 +967,8 @@ public class EhEngine {
|
||||
headers = response.headers();
|
||||
body = response.body().string();
|
||||
return GalleryPageParser.parse(body);
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
throwException(call, code, headers, body, e);
|
||||
throw e;
|
||||
}
|
||||
|
||||
@@ -17,13 +17,10 @@
|
||||
package com.hippo.ehviewer.client;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
import android.util.Pair;
|
||||
import com.hippo.ehviewer.Settings;
|
||||
import com.hippo.network.UrlBuilder;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import okhttp3.HttpUrl;
|
||||
|
||||
public class EhUrl {
|
||||
@@ -58,8 +55,6 @@ public class EhUrl {
|
||||
private static final String URL_PREFIX_THUMB_E = "https://ehgt.org/t/";
|
||||
private static final String URL_PREFIX_THUMB_EX = "https://exhentai.org/t/";
|
||||
|
||||
public static final Pattern PATTERN_DETAIL_URL = Pattern.compile("g/(\\d+)/([0-9a-f]{10})");
|
||||
|
||||
public static String getGalleryDetailUrl(long gid, String token) {
|
||||
return getGalleryDetailUrl(gid, token, 0, false);
|
||||
}
|
||||
@@ -181,13 +176,4 @@ public class EhUrl {
|
||||
return originUrl;
|
||||
}
|
||||
}
|
||||
|
||||
public static Pair<Long, String> parseGalleryDetailUrl(String url) {
|
||||
Matcher matcher = PATTERN_DETAIL_URL.matcher(url);
|
||||
if (matcher.find()) {
|
||||
return new Pair<>(Long.parseLong(matcher.group(1)), matcher.group(2));
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -40,6 +40,7 @@ public class GalleryDetail extends GalleryInfo {
|
||||
public GalleryComment[] comments;
|
||||
public int previewPages;
|
||||
public PreviewSet previewSet;
|
||||
public String favoriteName;
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
@@ -64,6 +65,7 @@ public class GalleryDetail extends GalleryInfo {
|
||||
dest.writeParcelableArray(this.comments, 0);
|
||||
dest.writeInt(this.previewPages);
|
||||
dest.writeParcelable(previewSet, flags);
|
||||
dest.writeString(this.favoriteName);
|
||||
}
|
||||
|
||||
public GalleryDetail() {
|
||||
@@ -96,6 +98,7 @@ public class GalleryDetail extends GalleryInfo {
|
||||
}
|
||||
this.previewPages = in.readInt();
|
||||
this.previewSet = in.readParcelable(PreviewSet.class.getClassLoader());
|
||||
this.favoriteName = in.readString();
|
||||
}
|
||||
|
||||
public static final Creator<GalleryDetail> CREATOR = new Creator<GalleryDetail>() {
|
||||
|
||||
@@ -79,6 +79,23 @@ public class GalleryInfo implements Parcelable {
|
||||
Pattern.compile("[(\\[]dutch[)\\]]", Pattern.CASE_INSENSITIVE),
|
||||
};
|
||||
|
||||
public static final String[] S_LANG_TAGS = {
|
||||
"language:english",
|
||||
"language:chinese",
|
||||
"language:spanish",
|
||||
"language:korean",
|
||||
"language:russian",
|
||||
"language:french",
|
||||
"language:portuguese",
|
||||
"language:thai",
|
||||
"language:german",
|
||||
"language:italian",
|
||||
"language:vietnamese",
|
||||
"language:polish",
|
||||
"language:hungarian",
|
||||
"language:dutch",
|
||||
};
|
||||
|
||||
public long gid ;
|
||||
public String token;
|
||||
public String title;
|
||||
@@ -105,6 +122,26 @@ public class GalleryInfo implements Parcelable {
|
||||
public String simpleLanguage;
|
||||
|
||||
public final void generateSLang() {
|
||||
if (simpleTags != null) {
|
||||
generateSLangFromTags();
|
||||
}
|
||||
if (simpleLanguage == null && title != null) {
|
||||
generateSLangFromTitle();
|
||||
}
|
||||
}
|
||||
|
||||
private void generateSLangFromTags() {
|
||||
for (String tag : simpleTags) {
|
||||
for (int i = 0; i < S_LANGS.length; i++) {
|
||||
if (S_LANG_TAGS[i].equals(tag)) {
|
||||
simpleLanguage = S_LANGS[i];
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void generateSLangFromTitle() {
|
||||
for (int i = 0; i < S_LANGS.length; i++) {
|
||||
if (S_LANG_PATTERNS[i].matcher(title).find()) {
|
||||
simpleLanguage = S_LANGS[i];
|
||||
|
||||
@@ -21,17 +21,15 @@ import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.client.data.GalleryInfo;
|
||||
import com.hippo.ehviewer.client.exception.EhException;
|
||||
import com.hippo.ehviewer.client.exception.ParseException;
|
||||
import com.hippo.util.ExceptionUtils;
|
||||
import com.hippo.util.JsoupUtils;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import com.hippo.yorozuya.AssertUtils;
|
||||
import java.util.List;
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Document;
|
||||
import org.jsoup.nodes.Element;
|
||||
import org.jsoup.select.Elements;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class FavoritesParser {
|
||||
|
||||
public static class Result {
|
||||
@@ -54,14 +52,15 @@ public class FavoritesParser {
|
||||
//noinspection ConstantConditions
|
||||
Elements fps = ido.getElementsByClass("fp");
|
||||
// Last one is "fp fps"
|
||||
Assert.assertEquals(11, fps.size());
|
||||
AssertUtils.assertEquals(11, fps.size());
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
Element fp = fps.get(i);
|
||||
countArray[i] = ParserUtils.parseInt(fp.child(0).text());
|
||||
catArray[i] = ParserUtils.trim(fp.child(2).text());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
e.printStackTrace();
|
||||
throw new ParseException("Parse favorites error", body);
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ package com.hippo.ehviewer.client.parser;
|
||||
|
||||
import com.hippo.ehviewer.client.EhUrl;
|
||||
import com.hippo.ehviewer.client.exception.ParseException;
|
||||
|
||||
import com.hippo.util.ExceptionUtils;
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Document;
|
||||
import org.jsoup.nodes.Element;
|
||||
@@ -31,7 +31,8 @@ public class ForumsParser {
|
||||
Element userlinks = d.getElementById("userlinks");
|
||||
Element child = userlinks.child(0).child(0).child(0);
|
||||
return child.attr("href");
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
throw new ParseException("Parse forums error", body);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,6 +54,7 @@ public class GalleryApiParser {
|
||||
}
|
||||
gi.simpleTags = tags;
|
||||
gi.pages = Integer.parseInt(g.getString("filecount"));
|
||||
gi.generateSLang();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,6 @@ package com.hippo.ehviewer.client.parser;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.hippo.ehviewer.Settings;
|
||||
import com.hippo.ehviewer.client.EhUrl;
|
||||
import com.hippo.ehviewer.client.EhUtils;
|
||||
@@ -33,15 +32,10 @@ import com.hippo.ehviewer.client.exception.EhException;
|
||||
import com.hippo.ehviewer.client.exception.OffensiveException;
|
||||
import com.hippo.ehviewer.client.exception.ParseException;
|
||||
import com.hippo.ehviewer.client.exception.PiningException;
|
||||
import com.hippo.util.ExceptionUtils;
|
||||
import com.hippo.util.JsoupUtils;
|
||||
import com.hippo.yorozuya.NumberUtils;
|
||||
import com.hippo.yorozuya.StringUtils;
|
||||
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Document;
|
||||
import org.jsoup.nodes.Element;
|
||||
import org.jsoup.select.Elements;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
@@ -52,6 +46,10 @@ import java.util.Locale;
|
||||
import java.util.TimeZone;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Document;
|
||||
import org.jsoup.nodes.Element;
|
||||
import org.jsoup.select.Elements;
|
||||
|
||||
public class GalleryDetailParser {
|
||||
|
||||
@@ -142,7 +140,8 @@ public class GalleryDetailParser {
|
||||
Element gd1 = gm.getElementById("gd1");
|
||||
try {
|
||||
gd.thumb = parseCoverStyle(StringUtils.trim(gd1.child(0).attr("style")));
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
gd.thumb = "";
|
||||
}
|
||||
|
||||
@@ -168,7 +167,8 @@ public class GalleryDetailParser {
|
||||
String href = gdc.child(0).attr("href");
|
||||
String category = href.substring(href.lastIndexOf('/') + 1);
|
||||
gd.category = EhUtils.getCategory(category);
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
gd.category = EhUtils.UNKNOWN;
|
||||
}
|
||||
|
||||
@@ -193,7 +193,8 @@ public class GalleryDetailParser {
|
||||
for (int i = 0, n = es.size(); i < n; i++) {
|
||||
parseDetailInfo(gd, es.get(i), body);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
// Ignore
|
||||
}
|
||||
|
||||
@@ -227,7 +228,16 @@ public class GalleryDetailParser {
|
||||
// isFavorited
|
||||
Element gdf = gm.getElementById("gdf");
|
||||
gd.isFavorited = null != gdf && !StringUtils.trim(gdf.text()).equals("Add to Favorites");
|
||||
} catch (Exception e) {
|
||||
if (gdf != null) {
|
||||
final String favoriteName = StringUtils.trim(gdf.text());
|
||||
if (favoriteName.equals("Add to Favorites")) {
|
||||
gd.favoriteName = null;
|
||||
} else {
|
||||
gd.favoriteName = StringUtils.trim(gdf.text());
|
||||
}
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
throw new ParseException("Can't parse gallery detail", body);
|
||||
}
|
||||
}
|
||||
@@ -309,7 +319,8 @@ public class GalleryDetailParser {
|
||||
}
|
||||
|
||||
return group.size() > 0 ? group : null;
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
@@ -332,7 +343,8 @@ public class GalleryDetailParser {
|
||||
}
|
||||
}
|
||||
return list.toArray(new GalleryTagGroup[list.size()]);
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
e.printStackTrace();
|
||||
return EMPTY_GALLERY_TAG_GROUP_ARRAY;
|
||||
}
|
||||
@@ -404,7 +416,8 @@ public class GalleryDetailParser {
|
||||
// comment
|
||||
comment.comment = JsoupUtils.getElementByClass(element, "c6").html();
|
||||
return comment;
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
@@ -427,7 +440,8 @@ public class GalleryDetailParser {
|
||||
}
|
||||
}
|
||||
return list.toArray(new GalleryComment[list.size()]);
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
e.printStackTrace();
|
||||
return EMPTY_GALLERY_COMMENT_ARRAY;
|
||||
}
|
||||
@@ -466,7 +480,8 @@ public class GalleryDetailParser {
|
||||
try {
|
||||
Elements elements = document.getElementsByClass("ptt").first().child(0).child(0).children();
|
||||
return Integer.parseInt(elements.get(elements.size() - 2).text());
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
e.printStackTrace();
|
||||
throw new ParseException("Can't parse preview pages", body);
|
||||
}
|
||||
@@ -541,7 +556,8 @@ public class GalleryDetailParser {
|
||||
largePreviewSet.addItem(index, imageUrl, pageUrl);
|
||||
}
|
||||
return largePreviewSet;
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
e.printStackTrace();
|
||||
throw new ParseException("Can't parse large preview", body);
|
||||
}
|
||||
|
||||
@@ -29,16 +29,25 @@ import java.util.regex.Pattern;
|
||||
*/
|
||||
public final class GalleryDetailUrlParser {
|
||||
|
||||
public static final Pattern URL_PATTERN = Pattern.compile("https?://(?:" +
|
||||
EhUrl.DOMAIN_EX + "|" + EhUrl.DOMAIN_E + "|" + EhUrl.DOMAIN_LOFI + ")/g/(\\d+)/(\\w+)");
|
||||
private static final Pattern URL_STRICT_PATTERN = Pattern.compile(
|
||||
"https?://(?:" + EhUrl.DOMAIN_EX + "|" + EhUrl.DOMAIN_E + "|" + EhUrl.DOMAIN_LOFI + ")/(?:g|mpv)/(\\d+)/([0-9a-f]{10})");
|
||||
|
||||
private static final Pattern URL_PATTERN = Pattern.compile(
|
||||
"(\\d+)/([0-9a-f]{10})");
|
||||
|
||||
@Nullable
|
||||
public static Result parse(String url) {
|
||||
return parse(url, true);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static Result parse(String url, boolean strict) {
|
||||
if (url == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Matcher m = URL_PATTERN.matcher(url);
|
||||
Pattern pattern = strict ? URL_STRICT_PATTERN : URL_PATTERN;
|
||||
Matcher m = pattern.matcher(url);
|
||||
if (m.find()) {
|
||||
Result result = new Result();
|
||||
result.gid = Long.parseLong(m.group(1));
|
||||
|
||||
@@ -19,24 +19,22 @@ package com.hippo.ehviewer.client.parser;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.util.Log;
|
||||
|
||||
import com.hippo.ehviewer.client.EhUtils;
|
||||
import com.hippo.ehviewer.client.data.GalleryInfo;
|
||||
import com.hippo.ehviewer.client.exception.ParseException;
|
||||
import com.hippo.util.ExceptionUtils;
|
||||
import com.hippo.util.JsoupUtils;
|
||||
import com.hippo.yorozuya.NumberUtils;
|
||||
import com.hippo.yorozuya.StringUtils;
|
||||
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Document;
|
||||
import org.jsoup.nodes.Element;
|
||||
import org.jsoup.select.Elements;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Document;
|
||||
import org.jsoup.nodes.Element;
|
||||
import org.jsoup.select.Elements;
|
||||
|
||||
public class GalleryListParser {
|
||||
|
||||
@@ -54,7 +52,8 @@ public class GalleryListParser {
|
||||
try {
|
||||
Elements es = d.getElementsByClass("ptt").first().child(0).child(0).children();
|
||||
return Integer.parseInt(es.get(es.size() - 2).text().trim());
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
throw new ParseException("Can't parse gallery list pages", body);
|
||||
}
|
||||
}
|
||||
@@ -182,6 +181,62 @@ public class GalleryListParser {
|
||||
return gi;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static GalleryInfo parseGalleryInfoThumbVersion(Element e) {
|
||||
GalleryInfo gi = new GalleryInfo();
|
||||
|
||||
// Title (required)
|
||||
Element id2 = JsoupUtils.getElementByClass(e, "id2");
|
||||
if (id2 == null) {
|
||||
return null;
|
||||
}
|
||||
gi.title = id2.text().trim();
|
||||
|
||||
// gid, token (required)
|
||||
Element a = id2.children().first();
|
||||
if (a == null) {
|
||||
return null;
|
||||
}
|
||||
GalleryDetailUrlParser.Result result = GalleryDetailUrlParser.parse(a.attr("href"));
|
||||
if (result == null) {
|
||||
return null;
|
||||
}
|
||||
gi.gid = result.gid;
|
||||
gi.token = result.token;
|
||||
|
||||
// Thumbnail
|
||||
Element id3 = JsoupUtils.getElementByClass(e, "id3");
|
||||
if (id3 != null) {
|
||||
a = id3.children().first();
|
||||
if (a != null) {
|
||||
Element img = a.children().first();
|
||||
if (img != null) {
|
||||
gi.thumb = EhUtils.handleThumbUrlResolution(img.attr("src"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Category
|
||||
Element id41 = JsoupUtils.getElementByClass(e, "id41");
|
||||
if (id41 != null) {
|
||||
gi.category = EhUtils.getCategory(id41.attr("title").trim());
|
||||
} else {
|
||||
gi.category = EhUtils.UNKNOWN;
|
||||
}
|
||||
|
||||
// Rating
|
||||
Element id43 = JsoupUtils.getElementByClass(e, "id43");
|
||||
if (id43 != null) {
|
||||
gi.rating = NumberUtils.parseFloatSafely(parseRating(id43.attr("style")), -1.0f);
|
||||
} else {
|
||||
gi.rating = -1.0f;
|
||||
}
|
||||
|
||||
gi.generateSLang();
|
||||
|
||||
return gi;
|
||||
}
|
||||
|
||||
public static Result parse(@NonNull String body) throws Exception {
|
||||
Result result = new Result();
|
||||
Document d = Jsoup.parse(body);
|
||||
@@ -209,10 +264,29 @@ public class GalleryListParser {
|
||||
}
|
||||
}
|
||||
result.galleryInfoList = list;
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
throw new ParseException("Can't parse gallery list", body);
|
||||
}
|
||||
|
||||
// Maybe it's thumbnail version
|
||||
if (result.galleryInfoList.isEmpty()) {
|
||||
try {
|
||||
Elements es = d.getElementsByClass("itg").first().children();
|
||||
List<GalleryInfo> list = new ArrayList<>(es.size() - 1);
|
||||
for (int i = 0; i < es.size(); i++) {
|
||||
GalleryInfo gi = parseGalleryInfoThumbVersion(es.get(i));
|
||||
if (null != gi) {
|
||||
list.add(gi);
|
||||
}
|
||||
}
|
||||
result.galleryInfoList = list;
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
throw new ParseException("Can't parse gallery list", body);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -16,8 +16,8 @@
|
||||
|
||||
package com.hippo.ehviewer.client.parser;
|
||||
|
||||
import android.support.annotation.Nullable;
|
||||
import com.hippo.ehviewer.client.EhUrl;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@@ -26,15 +26,25 @@ import java.util.regex.Pattern;
|
||||
*/
|
||||
public final class GalleryPageUrlParser {
|
||||
|
||||
public static final Pattern URL_PATTERN = Pattern.compile("https?://(?:" +
|
||||
EhUrl.DOMAIN_EX + "|" + EhUrl.DOMAIN_E + "|" + EhUrl.DOMAIN_LOFI + ")/s/(\\w+)/(\\d+)-(\\d+)");
|
||||
private static final Pattern URL_STRICT_PATTERN = Pattern.compile(
|
||||
"https?://(?:" + EhUrl.DOMAIN_EX + "|" + EhUrl.DOMAIN_E + "|" + EhUrl.DOMAIN_LOFI + ")/s/([0-9a-f]{10})/(\\d+)-(\\d+)");
|
||||
|
||||
private static final Pattern URL_PATTERN = Pattern.compile(
|
||||
"([0-9a-f]{10})/(\\d+)-(\\d+)");
|
||||
|
||||
@Nullable
|
||||
public static Result parse(String url) {
|
||||
return parse(url, true);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static Result parse(String url, boolean strict) {
|
||||
if (url == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Matcher m = URL_PATTERN.matcher(url);
|
||||
Pattern pattern = strict ? URL_STRICT_PATTERN : URL_PATTERN;
|
||||
Matcher m = pattern.matcher(url);
|
||||
if (m.find()) {
|
||||
Result result = new Result();
|
||||
result.gid = Long.parseLong(m.group(2));
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
package com.hippo.ehviewer.client.parser;
|
||||
|
||||
import com.hippo.ehviewer.client.exception.EhException;
|
||||
|
||||
import com.hippo.util.ExceptionUtils;
|
||||
import org.json.JSONObject;
|
||||
|
||||
public class GalleryTokenApiParser {
|
||||
@@ -36,7 +36,8 @@ public class GalleryTokenApiParser {
|
||||
JSONObject jo = new JSONObject(body).getJSONArray("tokenlist").getJSONObject(0);
|
||||
try {
|
||||
return jo.getString("token");
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
throw new EhException(jo.getString("error"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,10 +18,9 @@ package com.hippo.ehviewer.client.parser;
|
||||
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import com.hippo.ehviewer.client.EhUrl;
|
||||
import com.hippo.ehviewer.client.exception.ParseException;
|
||||
|
||||
import com.hippo.util.ExceptionUtils;
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Document;
|
||||
import org.jsoup.nodes.Element;
|
||||
@@ -43,11 +42,13 @@ public class ProfileParser {
|
||||
} else if (!result.avatar.startsWith("http")) {
|
||||
result.avatar = EhUrl.URL_FORUMS + result.avatar;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
Log.i(TAG, "No avatar");
|
||||
}
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
throw new ParseException("Parse forums error", body);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,16 +19,15 @@ package com.hippo.ehviewer.client.parser;
|
||||
import com.hippo.ehviewer.client.EhUtils;
|
||||
import com.hippo.ehviewer.client.data.GalleryInfo;
|
||||
import com.hippo.ehviewer.client.exception.ParseException;
|
||||
import com.hippo.util.ExceptionUtils;
|
||||
import com.hippo.util.JsoupUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Document;
|
||||
import org.jsoup.nodes.Element;
|
||||
import org.jsoup.select.Elements;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class WhatsHotParser {
|
||||
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
@@ -54,7 +53,8 @@ public class WhatsHotParser {
|
||||
galleryInfoList.add(galleryInfo);
|
||||
}
|
||||
return galleryInfoList;
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
throw new ParseException("Parse whats hot error", body);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -566,6 +566,9 @@ public class DownloadManager implements SpiderQueen.OnSpiderListener {
|
||||
for (DownloadInfoListener l: mDownloadInfoListeners) {
|
||||
l.onReload();
|
||||
}
|
||||
|
||||
// Ensure download
|
||||
ensureDownload();
|
||||
}
|
||||
|
||||
@SuppressLint("StaticFieldLeak")
|
||||
|
||||
@@ -0,0 +1,218 @@
|
||||
/*
|
||||
* Copyright 2018 Hippo Seven
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.hippo.ehviewer.gallery;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
import android.os.Process;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import com.hippo.ehviewer.GetText;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.gallery.archive.Archive;
|
||||
import com.hippo.ehviewer.gallery.archive.ArchiveEntry;
|
||||
import com.hippo.glgallery.GalleryPageView;
|
||||
import com.hippo.image.Image;
|
||||
import com.hippo.unifile.UniFile;
|
||||
import com.hippo.unifile.UniRandomAccessFile;
|
||||
import com.hippo.util.NaturalComparator;
|
||||
import com.hippo.yorozuya.IOUtils;
|
||||
import com.hippo.yorozuya.thread.PriorityThread;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Stack;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
public class ArchiveGalleryProvider extends GalleryProvider2 implements Runnable {
|
||||
|
||||
private static final String TAG = ArchiveGalleryProvider.class.getSimpleName();
|
||||
private static final AtomicInteger sIdGenerator = new AtomicInteger();
|
||||
|
||||
private final UniFile file;
|
||||
private final Stack<Integer> requests = new Stack<>();
|
||||
private final AtomicInteger decodingIndex = new AtomicInteger(GalleryPageView.INVALID_INDEX);
|
||||
@Nullable
|
||||
private Thread bgThread;
|
||||
private volatile int size = STATE_WAIT;
|
||||
private String error;
|
||||
|
||||
public ArchiveGalleryProvider(Context context, Uri uri) {
|
||||
file = UniFile.fromUri(context, uri);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start() {
|
||||
super.start();
|
||||
|
||||
bgThread = new PriorityThread(this, TAG + '-' + sIdGenerator.incrementAndGet(),
|
||||
Process.THREAD_PRIORITY_BACKGROUND);
|
||||
bgThread.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
super.stop();
|
||||
|
||||
if (bgThread != null) {
|
||||
bgThread.interrupt();
|
||||
bgThread = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return size;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onRequest(int index) {
|
||||
synchronized (requests) {
|
||||
if (!requests.contains(index) && index != decodingIndex.get()) {
|
||||
requests.add(index);
|
||||
requests.notify();
|
||||
}
|
||||
}
|
||||
notifyPageWait(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onForceRequest(int index) {
|
||||
onRequest(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCancelRequest(int index) {
|
||||
synchronized (requests) {
|
||||
requests.remove(Integer.valueOf(index));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getError() {
|
||||
return error;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String getImageFilename(int index) {
|
||||
// TODO
|
||||
return Integer.toString(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean save(int index, @NonNull UniFile file) {
|
||||
// TODO
|
||||
return false;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public UniFile save(int index, @NonNull UniFile dir, @NonNull String filename) {
|
||||
// TODO
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
UniRandomAccessFile uraf = null;
|
||||
if (file != null) {
|
||||
try {
|
||||
uraf = file.createRandomAccessFile("r");
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
if (uraf == null) {
|
||||
size = STATE_ERROR;
|
||||
error = GetText.getString(R.string.error_reading_failed);
|
||||
notifyDataChanged();
|
||||
return;
|
||||
}
|
||||
|
||||
Archive archive = null;
|
||||
try {
|
||||
archive = Archive.create(uraf);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (archive == null) {
|
||||
size = STATE_ERROR;
|
||||
error = GetText.getString(R.string.error_invalid_archive);
|
||||
notifyDataChanged();
|
||||
return;
|
||||
}
|
||||
|
||||
List<ArchiveEntry> entries = archive.getArchiveEntries();
|
||||
Collections.sort(entries, naturalComparator);
|
||||
|
||||
// Update size and notify changed
|
||||
size = entries.size();
|
||||
notifyDataChanged();
|
||||
|
||||
while (!Thread.currentThread().isInterrupted()) {
|
||||
int index;
|
||||
synchronized (requests) {
|
||||
if (requests.isEmpty()) {
|
||||
try {
|
||||
requests.wait();
|
||||
} catch (InterruptedException e) {
|
||||
// Interrupted
|
||||
break;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
index = requests.pop();
|
||||
decodingIndex.lazySet(index);
|
||||
}
|
||||
|
||||
// Check index valid
|
||||
if (index < 0 || index >= entries.size()) {
|
||||
decodingIndex.lazySet(GalleryPageView.INVALID_INDEX);
|
||||
notifyPageFailed(index, GetText.getString(R.string.error_out_of_range));
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
InputStream is = entries.get(index).getInputStream();
|
||||
Image image = Image.decode(is, true);
|
||||
decodingIndex.lazySet(GalleryPageView.INVALID_INDEX);
|
||||
if (image != null) {
|
||||
notifyPageSucceed(index, image);
|
||||
} else {
|
||||
notifyPageFailed(index, GetText.getString(R.string.error_decoding_failed));
|
||||
}
|
||||
} catch (IOException e) {
|
||||
decodingIndex.lazySet(GalleryPageView.INVALID_INDEX);
|
||||
notifyPageFailed(index, GetText.getString(R.string.error_reading_failed));
|
||||
}
|
||||
}
|
||||
|
||||
// Clear
|
||||
IOUtils.closeQuietly(archive);
|
||||
}
|
||||
|
||||
private static Comparator<ArchiveEntry> naturalComparator = new Comparator<ArchiveEntry>() {
|
||||
private NaturalComparator comparator = new NaturalComparator();
|
||||
@Override
|
||||
public int compare(ArchiveEntry o1, ArchiveEntry o2) {
|
||||
return comparator.compare(o1.getName(), o2.getName());
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -20,23 +20,22 @@ import android.os.Process;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.util.Log;
|
||||
|
||||
import com.hippo.ehviewer.GetText;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.glgallery.GalleryPageView;
|
||||
import com.hippo.image.Image;
|
||||
import com.hippo.unifile.FilenameFilter;
|
||||
import com.hippo.unifile.UniFile;
|
||||
import com.hippo.util.NaturalComparator;
|
||||
import com.hippo.yorozuya.FileUtils;
|
||||
import com.hippo.yorozuya.IOUtils;
|
||||
import com.hippo.yorozuya.StringUtils;
|
||||
import com.hippo.yorozuya.thread.PriorityThread;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FilenameFilter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.Stack;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
@@ -173,7 +172,7 @@ public class DirGalleryProvider extends GalleryProvider2 implements Runnable {
|
||||
@Override
|
||||
public void run() {
|
||||
// It may take a long time, so run it in new thread
|
||||
UniFile[] files = mDir.listFiles();
|
||||
UniFile[] files = mDir.listFiles(imageFilter);
|
||||
|
||||
if (files == null) {
|
||||
mSize = STATE_ERROR;
|
||||
@@ -187,7 +186,7 @@ public class DirGalleryProvider extends GalleryProvider2 implements Runnable {
|
||||
}
|
||||
|
||||
// Sort it
|
||||
Arrays.sort(files);
|
||||
Arrays.sort(files, naturalComparator);
|
||||
|
||||
// Put file list
|
||||
mFileList.lazySet(files);
|
||||
@@ -244,11 +243,14 @@ public class DirGalleryProvider extends GalleryProvider2 implements Runnable {
|
||||
Log.i(TAG, "ImageDecoder end");
|
||||
}
|
||||
|
||||
private static class ImageFilter implements FilenameFilter {
|
||||
private static FilenameFilter imageFilter =
|
||||
(dir, name) -> StringUtils.endsWith(name.toLowerCase(), SUPPORT_IMAGE_EXTENSIONS);
|
||||
|
||||
private static Comparator<UniFile> naturalComparator = new Comparator<UniFile>() {
|
||||
private NaturalComparator comparator = new NaturalComparator();
|
||||
@Override
|
||||
public boolean accept(File dir, String filename) {
|
||||
return StringUtils.endsWith(filename.toLowerCase(), SUPPORT_IMAGE_EXTENSIONS);
|
||||
public int compare(UniFile o1, UniFile o2) {
|
||||
return comparator.compare(o1.getName(), o2.getName());
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -1,228 +0,0 @@
|
||||
/*
|
||||
* 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.gallery;
|
||||
|
||||
import android.os.Process;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.util.Log;
|
||||
|
||||
import com.hippo.ehviewer.GetText;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.glgallery.GalleryPageView;
|
||||
import com.hippo.image.Image;
|
||||
import com.hippo.unifile.UniFile;
|
||||
import com.hippo.yorozuya.StringUtils;
|
||||
import com.hippo.yorozuya.thread.PriorityThread;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Enumeration;
|
||||
import java.util.List;
|
||||
import java.util.Stack;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipException;
|
||||
import java.util.zip.ZipFile;
|
||||
|
||||
public class ZipGalleryProvider extends GalleryProvider2 implements Runnable {
|
||||
|
||||
private static final String TAG = ZipGalleryProvider.class.getSimpleName();
|
||||
private static final AtomicInteger sIdGenerator = new AtomicInteger();
|
||||
|
||||
private final File mFile;
|
||||
private final Stack<Integer> mRequests = new Stack<>();
|
||||
private final AtomicInteger mDecodingIndex = new AtomicInteger(GalleryPageView.INVALID_INDEX);
|
||||
@Nullable
|
||||
private Thread mBgThread;
|
||||
private volatile int mSize = STATE_WAIT;
|
||||
private String mError;
|
||||
|
||||
public ZipGalleryProvider(File file) {
|
||||
mFile = file;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start() {
|
||||
super.start();
|
||||
|
||||
mBgThread = new PriorityThread(this, TAG + '-' + sIdGenerator.incrementAndGet(),
|
||||
Process.THREAD_PRIORITY_BACKGROUND);
|
||||
mBgThread.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
super.stop();
|
||||
|
||||
if (mBgThread != null) {
|
||||
mBgThread.interrupt();
|
||||
mBgThread = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return mSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onRequest(int index) {
|
||||
synchronized (mRequests) {
|
||||
if (!mRequests.contains(index) && index != mDecodingIndex.get()) {
|
||||
mRequests.add(index);
|
||||
mRequests.notify();
|
||||
}
|
||||
}
|
||||
notifyPageWait(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onForceRequest(int index) {
|
||||
onRequest(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCancelRequest(int index) {
|
||||
synchronized (mRequests) {
|
||||
mRequests.remove(Integer.valueOf(index));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getError() {
|
||||
return mError;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String getImageFilename(int index) {
|
||||
// TODO
|
||||
return Integer.toString(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean save(int index, @NonNull UniFile file) {
|
||||
// TODO
|
||||
return false;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public UniFile save(int index, @NonNull UniFile dir, @NonNull String filename) {
|
||||
// TODO
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
ZipFile zipFile = null;
|
||||
try {
|
||||
zipFile = new ZipFile(mFile);
|
||||
} catch (ZipException e) {
|
||||
mError = GetText.getString(R.string.error_invalid_zip_file);
|
||||
} catch (FileNotFoundException e) {
|
||||
mError = GetText.getString(R.string.error_not_found);
|
||||
} catch (IOException e) {
|
||||
mError = GetText.getString(R.string.error_reading_failed);
|
||||
}
|
||||
|
||||
// Check zip file null
|
||||
if (zipFile == null) {
|
||||
mSize = STATE_ERROR;
|
||||
|
||||
// Notify to to show error
|
||||
notifyDataChanged();
|
||||
|
||||
Log.i(TAG, "ImageDecoder end with error");
|
||||
return;
|
||||
}
|
||||
|
||||
// Get all image name
|
||||
List<String> filenames = new ArrayList<>(zipFile.size());
|
||||
Enumeration<? extends ZipEntry> enumeration = zipFile.entries();
|
||||
while (enumeration.hasMoreElements()) {
|
||||
ZipEntry zipEntry = enumeration.nextElement();
|
||||
String filename = zipEntry.getName();
|
||||
if (!zipEntry.isDirectory() && StringUtils.endsWith(filename, SUPPORT_IMAGE_EXTENSIONS)) {
|
||||
filenames.add(filename);
|
||||
}
|
||||
}
|
||||
Collections.sort(filenames);
|
||||
|
||||
// Update size and notify changed
|
||||
mSize = filenames.size();
|
||||
notifyDataChanged();
|
||||
|
||||
while (!Thread.currentThread().isInterrupted()) {
|
||||
int index;
|
||||
synchronized (mRequests) {
|
||||
if (mRequests.isEmpty()) {
|
||||
try {
|
||||
mRequests.wait();
|
||||
} catch (InterruptedException e) {
|
||||
// Interrupted
|
||||
break;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
index = mRequests.pop();
|
||||
mDecodingIndex.lazySet(index);
|
||||
}
|
||||
|
||||
// Check index valid
|
||||
if (index < 0 || index >= filenames.size()) {
|
||||
mDecodingIndex.lazySet(GalleryPageView.INVALID_INDEX);
|
||||
notifyPageFailed(index, GetText.getString(R.string.error_out_of_range));
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
ZipEntry zipEntry = zipFile.getEntry(filenames.get(index));
|
||||
if (zipEntry != null) {
|
||||
InputStream is = zipFile.getInputStream(zipEntry);
|
||||
Image image = Image.decode(is, true);
|
||||
mDecodingIndex.lazySet(GalleryPageView.INVALID_INDEX);
|
||||
if (image != null) {
|
||||
notifyPageSucceed(index, image);
|
||||
} else {
|
||||
notifyPageFailed(index, GetText.getString(R.string.error_decoding_failed));
|
||||
}
|
||||
} else {
|
||||
mDecodingIndex.lazySet(GalleryPageView.INVALID_INDEX);
|
||||
notifyPageFailed(index, GetText.getString(R.string.error_reading_failed));
|
||||
}
|
||||
} catch (IOException e) {
|
||||
mDecodingIndex.lazySet(GalleryPageView.INVALID_INDEX);
|
||||
notifyPageFailed(index, GetText.getString(R.string.error_reading_failed));
|
||||
}
|
||||
}
|
||||
|
||||
// Clear
|
||||
try {
|
||||
zipFile.close();
|
||||
} catch (IOException e) {
|
||||
// Ignore
|
||||
}
|
||||
|
||||
Log.i(TAG, "ImageDecoder end");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
* Copyright 2018 Hippo Seven
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.hippo.ehviewer.gallery.archive;
|
||||
|
||||
import com.hippo.ehviewer.gallery.GalleryProvider2;
|
||||
import com.hippo.unifile.UniRandomAccessFile;
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class Archive implements Closeable {
|
||||
|
||||
private static final byte[] FILE_SIGNATURE_SEVEN_Z = { 0x37, 0x7A, (byte) 0xBC, (byte) 0xAF, 0x27, 0x1C };
|
||||
private static final byte[] FILE_SIGNATURE_ZIP = { 0x50, 0x4B };
|
||||
private static final byte[] FILE_SIGNATURE_RAR = { 0x52, 0x61, 0x72, 0x21, 0x1A, 0x07, 0x00 };
|
||||
|
||||
public abstract List<ArchiveEntry> getArchiveEntries();
|
||||
|
||||
public static Archive create(UniRandomAccessFile file) throws IOException {
|
||||
byte[] bytes = new byte[8];
|
||||
readFully(file, bytes, 8);
|
||||
file.seek(0);
|
||||
|
||||
if (equals(bytes, FILE_SIGNATURE_SEVEN_Z, FILE_SIGNATURE_SEVEN_Z.length)) {
|
||||
return SevenZArchive.create(file);
|
||||
} else if (equals(bytes, FILE_SIGNATURE_ZIP, FILE_SIGNATURE_ZIP.length)) {
|
||||
return ZipArchive.create(file);
|
||||
} else if (equals(bytes, FILE_SIGNATURE_RAR, FILE_SIGNATURE_RAR.length)) {
|
||||
return RarArchive.create(file);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
static boolean isSupportedFilename(String name) {
|
||||
for (String extension : GalleryProvider2.SUPPORT_IMAGE_EXTENSIONS) {
|
||||
if (name.endsWith(extension)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static int readFully(UniRandomAccessFile file, byte[] bytes, int count) throws IOException {
|
||||
if (count <= 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int read = 0;
|
||||
do {
|
||||
int l = file.read(bytes, read, count - read);
|
||||
if (l < 0)
|
||||
break;
|
||||
read += l;
|
||||
} while (read < count);
|
||||
|
||||
if (read == 0) {
|
||||
return -1;
|
||||
} else {
|
||||
return read;
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean equals(byte[] b1, byte[] b2, int size) {
|
||||
if (b1.length < size || b2.length < size) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int i = 0; i < size; i++) {
|
||||
if (b1[i] != b2[i]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright 2018 Hippo Seven
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.hippo.ehviewer.gallery.archive;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
public abstract class ArchiveEntry {
|
||||
|
||||
public abstract String getName();
|
||||
|
||||
public abstract InputStream getInputStream() throws IOException;
|
||||
}
|
||||
@@ -0,0 +1,198 @@
|
||||
/*
|
||||
* Copyright 2018 Hippo Seven
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.hippo.ehviewer.gallery.archive;
|
||||
|
||||
import com.github.junrar.Volume;
|
||||
import com.github.junrar.VolumeManager;
|
||||
import com.github.junrar.exception.RarException;
|
||||
import com.github.junrar.io.IReadOnlyAccess;
|
||||
import com.github.junrar.rarfile.FileHeader;
|
||||
import com.hippo.unifile.UniRandomAccessFile;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class RarArchive extends Archive {
|
||||
|
||||
private com.github.junrar.Archive file;
|
||||
|
||||
private RarArchive(com.github.junrar.Archive file) {
|
||||
this.file = file;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ArchiveEntry> getArchiveEntries() {
|
||||
List<ArchiveEntry> result = new ArrayList<>();
|
||||
|
||||
for (FileHeader fileHeader : file.getFileHeaders()) {
|
||||
if (isSupportedFilename(fileHeader.getFileNameString().toLowerCase())) {
|
||||
result.add(new RarArchiveEntry(file, fileHeader));
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
file.close();
|
||||
}
|
||||
|
||||
public static Archive create(UniRandomAccessFile file) throws IOException {
|
||||
VolumeManager volumeManager = new UniRandomAccessFileVolumeManager(file);
|
||||
com.github.junrar.Archive archive;
|
||||
try {
|
||||
archive = new com.github.junrar.Archive(volumeManager);
|
||||
if (archive.getMainHeader().isSolid()) {
|
||||
throw new IOException("Solid archive is not supported");
|
||||
}
|
||||
} catch (RarException e) {
|
||||
throw new IOException("Invalid rar archive", e);
|
||||
}
|
||||
return new RarArchive(archive);
|
||||
}
|
||||
|
||||
public static class RarArchiveEntry extends ArchiveEntry {
|
||||
|
||||
private com.github.junrar.Archive file;
|
||||
private FileHeader header;
|
||||
|
||||
private RarArchiveEntry(com.github.junrar.Archive file, FileHeader header) {
|
||||
this.file = file;
|
||||
this.header = header;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return header.getFileNameString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream getInputStream() throws IOException {
|
||||
try {
|
||||
return file.getInputStream(header);
|
||||
} catch (RarException e) {
|
||||
throw new IOException("Can't getInputStream from rar archive", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static class UniRandomAccessFileVolumeManager implements VolumeManager {
|
||||
|
||||
private UniRandomAccessFile file;
|
||||
|
||||
private UniRandomAccessFileVolumeManager(UniRandomAccessFile file) {
|
||||
this.file = file;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Volume nextArchive(com.github.junrar.Archive archive, Volume lastVolume) {
|
||||
if (lastVolume == null) {
|
||||
return new UniRandomAccessFileVolume(archive, file);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static class UniRandomAccessFileVolume implements Volume {
|
||||
|
||||
private com.github.junrar.Archive archive;
|
||||
private UniRandomAccessFile file;
|
||||
|
||||
private UniRandomAccessFileVolume(com.github.junrar.Archive archive, UniRandomAccessFile file) {
|
||||
this.archive = archive;
|
||||
this.file = file;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IReadOnlyAccess getReadOnlyAccess() {
|
||||
return new UniReadOnlyAccessFile(file);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getLength() throws IOException {
|
||||
return file.length();
|
||||
}
|
||||
|
||||
@Override
|
||||
public com.github.junrar.Archive getArchive() {
|
||||
return archive;
|
||||
}
|
||||
}
|
||||
|
||||
private static class UniReadOnlyAccessFile implements IReadOnlyAccess {
|
||||
|
||||
private UniRandomAccessFile file;
|
||||
|
||||
private UniReadOnlyAccessFile(UniRandomAccessFile file) {
|
||||
this.file = file;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getPosition() throws IOException {
|
||||
return file.getFilePointer();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPosition(long pos) throws IOException {
|
||||
file.seek(pos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int read() throws IOException {
|
||||
byte[] b = new byte[1];
|
||||
if (file.read(b) == -1) {
|
||||
return -1;
|
||||
} else {
|
||||
return b[0];
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int read(byte[] buffer, int off, int count) throws IOException {
|
||||
return file.read(buffer, off, count);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int readFully(byte[] buffer, int count) throws IOException {
|
||||
if (count <= 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int read = 0;
|
||||
do {
|
||||
int l = read(buffer, read, count - read);
|
||||
if (l < 0)
|
||||
break;
|
||||
read += l;
|
||||
} while (read < count);
|
||||
|
||||
if (read == 0) {
|
||||
return -1;
|
||||
} else {
|
||||
return read;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
file.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
/*
|
||||
* Copyright 2018 Hippo Seven
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.hippo.ehviewer.gallery.archive;
|
||||
|
||||
import com.hippo.unifile.UniRandomAccessFile;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import okio.Store;
|
||||
import okio.UniRandomAccessFileStore;
|
||||
import org.apache.commons.compress.archivers.sevenz.SevenZFile;
|
||||
|
||||
public class SevenZArchive extends Archive {
|
||||
|
||||
private SevenZFile file;
|
||||
|
||||
public SevenZArchive(SevenZFile file) {
|
||||
this.file = file;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ArchiveEntry> getArchiveEntries() {
|
||||
List<ArchiveEntry> result = new ArrayList<>();
|
||||
|
||||
for (org.apache.commons.compress.archivers.sevenz.SevenZArchiveEntry archive : file.getEntries()) {
|
||||
if (archive.getSize() != 0
|
||||
&& !archive.isDirectory()
|
||||
&& isSupportedFilename(archive.getName().toLowerCase())) {
|
||||
result.add(new SevenZArchiveEntry(file, archive));
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
file.close();
|
||||
}
|
||||
|
||||
public static Archive create(UniRandomAccessFile file) throws IOException {
|
||||
Store store = new UniRandomAccessFileStore(file);
|
||||
SevenZFile sevenZFile = new SevenZFile(store);
|
||||
|
||||
// Check whether the archive is solid
|
||||
for (org.apache.commons.compress.archivers.sevenz.SevenZArchiveEntry entry : sevenZFile.getEntries()) {
|
||||
if (entry.getSize() != 0
|
||||
&& !entry.isDirectory()
|
||||
&& !entry.isFirstInFolder()) {
|
||||
throw new IOException("Solid archive is not supported");
|
||||
}
|
||||
}
|
||||
|
||||
return new SevenZArchive(sevenZFile);
|
||||
}
|
||||
|
||||
public static class SevenZArchiveEntry extends ArchiveEntry {
|
||||
|
||||
private SevenZFile file;
|
||||
private org.apache.commons.compress.archivers.sevenz.SevenZArchiveEntry entry;
|
||||
|
||||
private SevenZArchiveEntry(
|
||||
SevenZFile file,
|
||||
org.apache.commons.compress.archivers.sevenz.SevenZArchiveEntry entry
|
||||
) {
|
||||
this.file = file;
|
||||
this.entry = entry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return entry.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream getInputStream() throws IOException {
|
||||
file.setEntry(entry);
|
||||
return file.getInputStreamForCurrentEntry();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* Copyright 2018 Hippo Seven
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.hippo.ehviewer.gallery.archive;
|
||||
|
||||
import com.hippo.unifile.UniRandomAccessFile;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Enumeration;
|
||||
import java.util.List;
|
||||
import okio.Store;
|
||||
import okio.UniRandomAccessFileStore;
|
||||
import org.apache.commons.compress.archivers.zip.ZipFile;
|
||||
|
||||
public class ZipArchive extends Archive {
|
||||
|
||||
private ZipFile file;
|
||||
|
||||
private ZipArchive(ZipFile file) {
|
||||
this.file = file;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ArchiveEntry> getArchiveEntries() {
|
||||
List<ArchiveEntry> result = new ArrayList<>();
|
||||
|
||||
Enumeration<org.apache.commons.compress.archivers.zip.ZipArchiveEntry> entries = file.getEntries();
|
||||
while (entries.hasMoreElements()) {
|
||||
org.apache.commons.compress.archivers.zip.ZipArchiveEntry entry = entries.nextElement();
|
||||
if (isSupportedFilename(entry.getName().toLowerCase())) {
|
||||
result.add(new ZipArchiveEntry(file, entry));
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
file.close();
|
||||
}
|
||||
|
||||
public static Archive create(UniRandomAccessFile file) throws IOException {
|
||||
Store store = new UniRandomAccessFileStore(file);
|
||||
ZipFile zipFile = new ZipFile(store);
|
||||
return new ZipArchive(zipFile);
|
||||
}
|
||||
|
||||
public static class ZipArchiveEntry extends ArchiveEntry {
|
||||
|
||||
private ZipFile file;
|
||||
private org.apache.commons.compress.archivers.zip.ZipArchiveEntry entry;
|
||||
|
||||
private ZipArchiveEntry(
|
||||
ZipFile file,
|
||||
org.apache.commons.compress.archivers.zip.ZipArchiveEntry entry
|
||||
) {
|
||||
this.file = file;
|
||||
this.entry = entry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return entry.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream getInputStream() throws IOException {
|
||||
return file.getInputStream(entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -62,6 +62,9 @@ public class CleanRedundancyPreference extends TaskPreference {
|
||||
// True for cleared
|
||||
private boolean clearFile(UniFile file) {
|
||||
String name = file.getName();
|
||||
if (name == null) {
|
||||
return false;
|
||||
}
|
||||
int index = name.indexOf('-');
|
||||
if (index >= 0) {
|
||||
name = name.substring(0, index);
|
||||
|
||||
@@ -23,7 +23,6 @@ import android.preference.Preference;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.util.AttributeSet;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.hippo.ehviewer.EhApplication;
|
||||
import com.hippo.ehviewer.EhDB;
|
||||
import com.hippo.ehviewer.R;
|
||||
@@ -34,14 +33,13 @@ import com.hippo.ehviewer.download.DownloadManager;
|
||||
import com.hippo.ehviewer.spider.SpiderInfo;
|
||||
import com.hippo.ehviewer.spider.SpiderQueen;
|
||||
import com.hippo.unifile.UniFile;
|
||||
import com.hippo.util.ExceptionUtils;
|
||||
import com.hippo.yorozuya.IOUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import okhttp3.OkHttpClient;
|
||||
|
||||
public class RestoreDownloadPreference extends TaskPreference {
|
||||
@@ -133,7 +131,8 @@ public class RestoreDownloadPreference extends TaskPreference {
|
||||
|
||||
try {
|
||||
return EhEngine.fillGalleryListByApi(null, mHttpClient, new ArrayList<GalleryInfo>(restoreItemList));
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -80,6 +80,7 @@ import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import okhttp3.Call;
|
||||
import okhttp3.MediaType;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
@@ -748,7 +749,8 @@ public final class SpiderQueen implements Runnable {
|
||||
spiderInfo.pTokenMap = new SparseArray<>(spiderInfo.pages);
|
||||
readPreviews(body, 0, spiderInfo);
|
||||
return spiderInfo;
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -790,7 +792,8 @@ public final class SpiderQueen implements Runnable {
|
||||
pToken = spiderInfo.pTokenMap.get(index);
|
||||
}
|
||||
return pToken;
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -802,7 +805,8 @@ public final class SpiderQueen implements Runnable {
|
||||
UniFile file = downloadDir.createFile(SPIDER_INFO_FILENAME);
|
||||
try {
|
||||
spiderInfo.write(file.openOutputStream());
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
// Ignore
|
||||
}
|
||||
}
|
||||
@@ -1033,7 +1037,7 @@ public final class SpiderQueen implements Runnable {
|
||||
return pageUrl;
|
||||
}
|
||||
|
||||
private GalleryPageParser.Result getImageUrl(int index, String pageUrl) throws Exception {
|
||||
private GalleryPageParser.Result getImageUrl(int index, String pageUrl) throws Throwable {
|
||||
GalleryPageParser.Result result = EhEngine.getGalleryPage(null, mHttpClient, pageUrl);
|
||||
if (StringUtils.endsWith(result.imageUrl, URL_509_SUFFIX_ARRAY)) {
|
||||
// Get 509
|
||||
@@ -1070,7 +1074,8 @@ public final class SpiderQueen implements Runnable {
|
||||
result = getImageUrl(index, pageUrl);
|
||||
} catch (Image509Exception e) {
|
||||
error = GetText.getString(R.string.error_509);
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
error = ExceptionUtils.getReadableString(e);
|
||||
}
|
||||
if (result == null) {
|
||||
@@ -1121,17 +1126,26 @@ public final class SpiderQueen implements Runnable {
|
||||
|
||||
Call call = mHttpClient.newCall(new EhRequestBuilder(imageUrl).build());
|
||||
Response response = call.execute();
|
||||
ResponseBody responseBody = response.body();
|
||||
|
||||
if (response.code() >= 400) {
|
||||
// Maybe 404
|
||||
response.body().close();
|
||||
response.close();
|
||||
error = "Bad code: " + response.code();
|
||||
continue;
|
||||
}
|
||||
ResponseBody responseBody = response.body();
|
||||
|
||||
if (responseBody == null) {
|
||||
error = "Empty response body";
|
||||
continue;
|
||||
}
|
||||
|
||||
// Get extension
|
||||
String extension = MimeTypeMap.getSingleton().getExtensionFromMimeType(
|
||||
responseBody.contentType().toString());
|
||||
String extension = null;
|
||||
MediaType mediaType = responseBody.contentType();
|
||||
if (mediaType != null) {
|
||||
extension = MimeTypeMap.getSingleton().getExtensionFromMimeType(mediaType.toString());
|
||||
}
|
||||
// Ensure extension
|
||||
if (!Utilities.contain(GalleryProvider2.SUPPORT_IMAGE_EXTENSIONS, extension)) {
|
||||
extension = GalleryProvider2.SUPPORT_IMAGE_EXTENSIONS[0];
|
||||
@@ -1142,7 +1156,7 @@ public final class SpiderQueen implements Runnable {
|
||||
if (null == pipe) {
|
||||
// Can't get pipe
|
||||
error = GetText.getString(R.string.error_write_failed);
|
||||
response.body().close();
|
||||
response.close();
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1157,7 +1171,7 @@ public final class SpiderQueen implements Runnable {
|
||||
while (!Thread.currentThread().isInterrupted()) {
|
||||
int bytesRead = is.read(data);
|
||||
if (bytesRead == -1) {
|
||||
response.body().close();
|
||||
response.close();
|
||||
break;
|
||||
}
|
||||
os.write(data, 0, bytesRead);
|
||||
@@ -1197,6 +1211,7 @@ public final class SpiderQueen implements Runnable {
|
||||
updatePageState(index, STATE_FINISHED);
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
error = GetText.getString(R.string.error_socket);
|
||||
} finally {
|
||||
IOUtils.closeQuietly(is);
|
||||
|
||||
@@ -33,6 +33,7 @@ import com.hippo.ehviewer.Settings;
|
||||
import com.hippo.ehviewer.UrlOpener;
|
||||
import com.hippo.ehviewer.client.EhClient;
|
||||
import com.hippo.ehviewer.client.EhRequest;
|
||||
import com.hippo.ehviewer.client.data.GalleryDetail;
|
||||
import com.hippo.ehviewer.client.data.GalleryInfo;
|
||||
import com.hippo.ehviewer.dao.DownloadLabel;
|
||||
import com.hippo.ehviewer.download.DownloadManager;
|
||||
@@ -100,17 +101,13 @@ public final class CommonOperations {
|
||||
}
|
||||
|
||||
private void showUpToDateDialog() {
|
||||
if (!mFeedback) {
|
||||
return;
|
||||
}
|
||||
|
||||
new AlertDialog.Builder(mActivity)
|
||||
.setMessage(R.string.update_to_date)
|
||||
.setPositiveButton(android.R.string.ok, null)
|
||||
.show();
|
||||
}
|
||||
|
||||
private void showUpdateDialog(String versionName, String size, CharSequence info, final String url) {
|
||||
private void showUpdateDialog(String versionName, int versionCode, String size, CharSequence info, final String url) {
|
||||
new AlertDialog.Builder(mActivity)
|
||||
.setTitle(R.string.update)
|
||||
.setMessage(mActivity.getString(R.string.update_plain, versionName, size, info))
|
||||
@@ -119,16 +116,22 @@ public final class CommonOperations {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
UrlOpener.openUrl(mActivity, url, false);
|
||||
}
|
||||
})
|
||||
.setNegativeButton(R.string.update_ignore, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
Settings.putSkipUpdateVersion(versionCode);
|
||||
}
|
||||
}).show();
|
||||
}
|
||||
|
||||
|
||||
private void handleResult(JSONObject jo) {
|
||||
if (null == jo || mActivity.isFinishing()) {
|
||||
return;
|
||||
}
|
||||
|
||||
String versionName;
|
||||
int versionCode;
|
||||
String size;
|
||||
CharSequence info;
|
||||
String url;
|
||||
@@ -137,10 +140,12 @@ public final class CommonOperations {
|
||||
PackageManager pm = mActivity.getPackageManager();
|
||||
PackageInfo pi = pm.getPackageInfo(mActivity.getPackageName(), PackageManager.GET_ACTIVITIES);
|
||||
int currentVersionCode = pi.versionCode;
|
||||
int newVersionCode = jo.getInt("version_code");
|
||||
if (currentVersionCode >= newVersionCode) {
|
||||
versionCode = jo.getInt("version_code");
|
||||
if (currentVersionCode >= versionCode) {
|
||||
// Update to date
|
||||
showUpToDateDialog();
|
||||
if (mFeedback) {
|
||||
showUpToDateDialog();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -152,7 +157,9 @@ public final class CommonOperations {
|
||||
return;
|
||||
}
|
||||
|
||||
showUpdateDialog(versionName, size, info, url);
|
||||
if (mFeedback || versionCode != Settings.getSkipUpdateVersion()) {
|
||||
showUpdateDialog(versionName, versionCode, size, info, url);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -185,33 +192,31 @@ public final class CommonOperations {
|
||||
public static void addToFavorites(final Activity activity, final GalleryInfo galleryInfo,
|
||||
final EhClient.Callback<Void> listener) {
|
||||
int slot = Settings.getDefaultFavSlot();
|
||||
String[] items = new String[11];
|
||||
items[0] = activity.getString(R.string.local_favorites);
|
||||
String[] favCat = Settings.getFavCat();
|
||||
System.arraycopy(favCat, 0, items, 1, 10);
|
||||
if (slot >= -1 && slot <= 9) {
|
||||
doAddToFavorites(activity, galleryInfo, slot, listener);
|
||||
String newFavoriteName = slot >= 0 ? items[slot + 1] : null;
|
||||
doAddToFavorites(activity, galleryInfo, slot, galleryInfo instanceof GalleryDetail
|
||||
? new UpdateFavoriteNameCallback(listener, (GalleryDetail) galleryInfo, newFavoriteName)
|
||||
: listener);
|
||||
} else {
|
||||
String[] items = new String[11];
|
||||
items[0] = activity.getString(R.string.local_favorites);
|
||||
String[] favCat = Settings.getFavCat();
|
||||
System.arraycopy(favCat, 0, items, 1, 10);
|
||||
new ListCheckBoxDialogBuilder(activity, items,
|
||||
new ListCheckBoxDialogBuilder.OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(ListCheckBoxDialogBuilder builder, AlertDialog dialog, int position) {
|
||||
int slot = position - 1;
|
||||
doAddToFavorites(activity, galleryInfo, slot, listener);
|
||||
if (builder.isChecked()) {
|
||||
Settings.putDefaultFavSlot(slot);
|
||||
} else {
|
||||
Settings.putDefaultFavSlot(Settings.INVALID_DEFAULT_FAV_SLOT);
|
||||
}
|
||||
(builder, dialog, position) -> {
|
||||
int slot1 = position - 1;
|
||||
String newFavoriteName = (slot1 >= 0 && slot1 <= 9) ? items[slot1+1] : null;
|
||||
doAddToFavorites(activity, galleryInfo, slot1, galleryInfo instanceof GalleryDetail
|
||||
? new UpdateFavoriteNameCallback(listener, (GalleryDetail) galleryInfo, newFavoriteName)
|
||||
: listener);
|
||||
if (builder.isChecked()) {
|
||||
Settings.putDefaultFavSlot(slot1);
|
||||
} else {
|
||||
Settings.putDefaultFavSlot(Settings.INVALID_DEFAULT_FAV_SLOT);
|
||||
}
|
||||
}, activity.getString(R.string.remember_favorite_collection), false)
|
||||
.setTitle(R.string.add_favorites_dialog_title)
|
||||
.setOnCancelListener(new DialogInterface.OnCancelListener() {
|
||||
@Override
|
||||
public void onCancel(DialogInterface dialog) {
|
||||
listener.onCancel();
|
||||
}
|
||||
})
|
||||
.setOnCancelListener(dialog -> listener.onCancel())
|
||||
.show();
|
||||
}
|
||||
}
|
||||
@@ -222,10 +227,42 @@ public final class CommonOperations {
|
||||
EhRequest request = new EhRequest();
|
||||
request.setMethod(EhClient.METHOD_ADD_FAVORITES);
|
||||
request.setArgs(galleryInfo.gid, galleryInfo.token, -1, "");
|
||||
request.setCallback(listener);
|
||||
request.setCallback(galleryInfo instanceof GalleryDetail
|
||||
? new UpdateFavoriteNameCallback(listener, (GalleryDetail) galleryInfo, null)
|
||||
: listener);
|
||||
client.execute(request);
|
||||
}
|
||||
|
||||
private static class UpdateFavoriteNameCallback implements EhClient.Callback<Void> {
|
||||
|
||||
private final EhClient.Callback<Void> delegate;
|
||||
private final GalleryDetail detail;
|
||||
private final String newFavoriteName;
|
||||
|
||||
UpdateFavoriteNameCallback(EhClient.Callback<Void> delegate, GalleryDetail detail,
|
||||
String newFavoriteName) {
|
||||
this.delegate = delegate;
|
||||
this.detail = detail;
|
||||
this.newFavoriteName = newFavoriteName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess(Void result) {
|
||||
detail.favoriteName = newFavoriteName;
|
||||
delegate.onSuccess(result);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Exception e) {
|
||||
delegate.onFailure(e);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCancel() {
|
||||
delegate.onCancel();
|
||||
}
|
||||
}
|
||||
|
||||
// TODO Add context if activity and context are different style
|
||||
public static void startDownload(final MainActivity activity, final GalleryInfo galleryInfo, boolean forceDefault) {
|
||||
final DownloadManager dm = EhApplication.getDownloadManager(activity);
|
||||
|
||||
@@ -25,12 +25,11 @@ import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.hippo.android.resource.AttrResources;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ripple.Ripple;
|
||||
import com.hippo.widget.DirExplorer;
|
||||
import com.hippo.yorozuya.ViewUtils;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class DirPickerActivity extends ToolbarActivity
|
||||
@@ -70,7 +69,7 @@ public class DirPickerActivity extends ToolbarActivity
|
||||
mDirExplorer.setCurrentFile(file);
|
||||
mDirExplorer.setOnChangeDirListener(this);
|
||||
|
||||
Ripple.addRipple(mOk, false);
|
||||
Ripple.addRipple(mOk, !AttrResources.getAttrBoolean(this, R.attr.isLightTheme));
|
||||
|
||||
mOk.setOnClickListener(this);
|
||||
|
||||
|
||||
@@ -17,25 +17,41 @@
|
||||
package com.hippo.ehviewer.ui;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.annotation.StyleRes;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.view.WindowManager;
|
||||
import com.google.analytics.tracking.android.EasyTracker;
|
||||
import com.google.firebase.analytics.FirebaseAnalytics;
|
||||
import com.hippo.android.resource.AttrResources;
|
||||
import com.hippo.content.ContextLocalWrapper;
|
||||
import com.hippo.ehviewer.Analytics;
|
||||
import com.hippo.ehviewer.EhApplication;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.Settings;
|
||||
import java.util.Locale;
|
||||
|
||||
public abstract class EhActivity extends AppCompatActivity {
|
||||
|
||||
private boolean mTrackStarted;
|
||||
@StyleRes
|
||||
protected abstract int getThemeResId(int theme);
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
setTheme(getThemeResId(Settings.getTheme()));
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
((EhApplication) getApplication()).registerActivity(this);
|
||||
|
||||
if (Analytics.isEnabled()) {
|
||||
FirebaseAnalytics.getInstance(this);
|
||||
}
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && Settings.getApplyNavBarThemeColor()) {
|
||||
getWindow().setNavigationBarColor(AttrResources.getAttrColor(this, R.attr.colorPrimaryDark));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -45,26 +61,6 @@ public abstract class EhActivity extends AppCompatActivity {
|
||||
((EhApplication) getApplication()).unregisterActivity(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
|
||||
if (Settings.getEnableAnalytics()) {
|
||||
EasyTracker.getInstance(this).activityStart(this);
|
||||
mTrackStarted = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop() {
|
||||
super.onStop();
|
||||
|
||||
if (mTrackStarted) {
|
||||
EasyTracker.getInstance(this).activityStop(this);
|
||||
mTrackStarted = false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
|
||||
@@ -18,25 +18,41 @@ package com.hippo.ehviewer.ui;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.annotation.StyleRes;
|
||||
import android.view.WindowManager;
|
||||
import com.google.analytics.tracking.android.EasyTracker;
|
||||
import com.hippo.app.AppCompatPreferenceActivity;
|
||||
import com.google.firebase.analytics.FirebaseAnalytics;
|
||||
import com.hippo.android.resource.AttrResources;
|
||||
import com.hippo.app.PrettyPreferenceActivity;
|
||||
import com.hippo.content.ContextLocalWrapper;
|
||||
import com.hippo.ehviewer.Analytics;
|
||||
import com.hippo.ehviewer.EhApplication;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.Settings;
|
||||
import java.util.Locale;
|
||||
|
||||
public abstract class EhPreferenceActivity extends AppCompatPreferenceActivity {
|
||||
public abstract class EhPreferenceActivity extends PrettyPreferenceActivity {
|
||||
|
||||
private boolean mTrackStarted;
|
||||
@StyleRes
|
||||
protected abstract int getThemeResId(int theme);
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
setTheme(getThemeResId(Settings.getTheme()));
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
((EhApplication) getApplication()).registerActivity(this);
|
||||
|
||||
if (Analytics.isEnabled()) {
|
||||
FirebaseAnalytics.getInstance(this);
|
||||
}
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && Settings.getApplyNavBarThemeColor()) {
|
||||
getWindow().setNavigationBarColor(AttrResources.getAttrColor(this, R.attr.colorPrimaryDark));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -46,26 +62,6 @@ public abstract class EhPreferenceActivity extends AppCompatPreferenceActivity {
|
||||
((EhApplication) getApplication()).unregisterActivity(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
|
||||
if (Settings.getEnableAnalytics()) {
|
||||
EasyTracker.getInstance(this).activityStart(this);
|
||||
mTrackStarted = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop() {
|
||||
super.onStop();
|
||||
|
||||
if (mTrackStarted) {
|
||||
EasyTracker.getInstance(this).activityStop(this);
|
||||
mTrackStarted = false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
|
||||
@@ -25,7 +25,7 @@ import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.hippo.android.resource.AttrResources;
|
||||
import com.hippo.easyrecyclerview.EasyRecyclerView;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.Settings;
|
||||
@@ -164,11 +164,12 @@ public class ExcludedLanguagesActivity extends ToolbarActivity
|
||||
mDeselectAll.setOnClickListener(this);
|
||||
mInvertSelection.setOnClickListener(this);
|
||||
|
||||
Ripple.addRipple(mCancel, false);
|
||||
Ripple.addRipple(mOk, false);
|
||||
Ripple.addRipple(mSelectAll, false);
|
||||
Ripple.addRipple(mDeselectAll, false);
|
||||
Ripple.addRipple(mInvertSelection, false);
|
||||
boolean isDarkTheme = !AttrResources.getAttrBoolean(this, R.attr.isLightTheme);
|
||||
Ripple.addRipple(mCancel, isDarkTheme);
|
||||
Ripple.addRipple(mOk, isDarkTheme);
|
||||
Ripple.addRipple(mSelectAll, isDarkTheme);
|
||||
Ripple.addRipple(mDeselectAll, isDarkTheme);
|
||||
Ripple.addRipple(mInvertSelection, isDarkTheme);
|
||||
}
|
||||
|
||||
private boolean isDecimal(String str) {
|
||||
|
||||
@@ -68,7 +68,7 @@ public class FilterActivity extends ToolbarActivity {
|
||||
TextView tip = (TextView) ViewUtils.$$(this, R.id.tip);
|
||||
mViewTransition = new ViewTransition(mRecyclerView, tip);
|
||||
|
||||
Drawable drawable = DrawableManager.getDrawable(this, R.drawable.big_filter);
|
||||
Drawable drawable = DrawableManager.getVectorDrawable(this, R.drawable.big_filter);
|
||||
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
|
||||
tip.setCompoundDrawables(null, drawable, null, null);
|
||||
|
||||
@@ -309,7 +309,7 @@ public class FilterActivity extends ToolbarActivity {
|
||||
|
||||
if (R.layout.item_filter == layoutId) {
|
||||
holder.icon.setImageDrawable(
|
||||
DrawableManager.getDrawable(FilterActivity.this, R.drawable.v_delete_x24));
|
||||
DrawableManager.getVectorDrawable(FilterActivity.this, R.drawable.v_delete_x24));
|
||||
}
|
||||
|
||||
return holder;
|
||||
|
||||
@@ -48,16 +48,16 @@ import android.widget.SeekBar;
|
||||
import android.widget.Spinner;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.hippo.android.resource.AttrResources;
|
||||
import com.hippo.ehviewer.AppConfig;
|
||||
import com.hippo.ehviewer.BuildConfig;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.Settings;
|
||||
import com.hippo.ehviewer.client.data.GalleryInfo;
|
||||
import com.hippo.ehviewer.gallery.ArchiveGalleryProvider;
|
||||
import com.hippo.ehviewer.gallery.DirGalleryProvider;
|
||||
import com.hippo.ehviewer.gallery.EhGalleryProvider;
|
||||
import com.hippo.ehviewer.gallery.GalleryProvider2;
|
||||
import com.hippo.ehviewer.gallery.ZipGalleryProvider;
|
||||
import com.hippo.ehviewer.widget.GalleryGuideView;
|
||||
import com.hippo.ehviewer.widget.ReversibleSeekBar;
|
||||
import com.hippo.glgallery.GalleryPageView;
|
||||
@@ -76,7 +76,6 @@ import com.hippo.yorozuya.ResourcesUtils;
|
||||
import com.hippo.yorozuya.SimpleAnimatorListener;
|
||||
import com.hippo.yorozuya.SimpleHandler;
|
||||
import com.hippo.yorozuya.ViewUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
@@ -87,7 +86,6 @@ public class GalleryActivity extends EhActivity implements SeekBar.OnSeekBarChan
|
||||
GalleryView.Listener {
|
||||
|
||||
public static final String ACTION_DIR = "dir";
|
||||
public static final String ACTION_ZIP = "zip";
|
||||
public static final String ACTION_EH = "eh";
|
||||
|
||||
public static final String KEY_ACTION = "action";
|
||||
@@ -182,6 +180,19 @@ public class GalleryActivity extends EhActivity implements SeekBar.OnSeekBarChan
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
protected int getThemeResId(int theme) {
|
||||
switch (theme) {
|
||||
case Settings.THEME_LIGHT:
|
||||
default:
|
||||
return R.style.AppTheme_Gallery;
|
||||
case Settings.THEME_DARK:
|
||||
return R.style.AppTheme_Gallery_Dark;
|
||||
case Settings.THEME_BLACK:
|
||||
return R.style.AppTheme_Gallery_Black;
|
||||
}
|
||||
}
|
||||
|
||||
private void buildProvider() {
|
||||
if (mGalleryProvider != null) {
|
||||
return;
|
||||
@@ -191,10 +202,6 @@ public class GalleryActivity extends EhActivity implements SeekBar.OnSeekBarChan
|
||||
if (mFilename != null) {
|
||||
mGalleryProvider = new DirGalleryProvider(UniFile.fromFile(new File(mFilename)));
|
||||
}
|
||||
} else if (ACTION_ZIP.equals(mAction)) {
|
||||
if (mFilename != null) {
|
||||
mGalleryProvider = new ZipGalleryProvider(new File(mFilename));
|
||||
}
|
||||
} else if (ACTION_EH.equals(mAction)) {
|
||||
if (mGalleryInfo != null) {
|
||||
mGalleryProvider = new EhGalleryProvider(this, mGalleryInfo);
|
||||
@@ -202,7 +209,7 @@ public class GalleryActivity extends EhActivity implements SeekBar.OnSeekBarChan
|
||||
} else if (Intent.ACTION_VIEW.equals(mAction)) {
|
||||
if (mUri != null) {
|
||||
// Only support zip now
|
||||
mGalleryProvider = new ZipGalleryProvider(new File(mUri.getPath()));
|
||||
mGalleryProvider = new ArchiveGalleryProvider(this, mUri);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -281,22 +288,21 @@ public class GalleryActivity extends EhActivity implements SeekBar.OnSeekBarChan
|
||||
mGLRootView = (GLRootView) ViewUtils.$$(this, R.id.gl_root_view);
|
||||
mGalleryAdapter = new GalleryAdapter(mGLRootView, mGalleryProvider);
|
||||
Resources resources = getResources();
|
||||
int primaryColor = ResourcesUtils.getAttrColor(this, R.attr.colorPrimary);
|
||||
mGalleryView = new GalleryView.Builder(this, mGalleryAdapter)
|
||||
.setListener(this)
|
||||
.setLayoutMode(Settings.getReadingDirection())
|
||||
.setScaleMode(Settings.getPageScaling())
|
||||
.setStartPosition(Settings.getStartPosition())
|
||||
.setStartPage(startPage)
|
||||
.setBackgroundColor(resources.getColor(R.color.gallery_background))
|
||||
.setEdgeColor(primaryColor & 0xffffff | 0x33000000)
|
||||
.setBackgroundColor(AttrResources.getAttrColor(this, android.R.attr.colorBackground))
|
||||
.setEdgeColor(AttrResources.getAttrColor(this, R.attr.colorEdgeEffect) & 0xffffff | 0x33000000)
|
||||
.setPagerInterval(Settings.getShowPageInterval() ? resources.getDimensionPixelOffset(R.dimen.gallery_pager_interval) : 0)
|
||||
.setScrollInterval(Settings.getShowPageInterval() ? resources.getDimensionPixelOffset(R.dimen.gallery_scroll_interval) : 0)
|
||||
.setPageMinHeight(resources.getDimensionPixelOffset(R.dimen.gallery_page_min_height))
|
||||
.setPageInfoInterval(resources.getDimensionPixelOffset(R.dimen.gallery_page_info_interval))
|
||||
.setProgressColor(primaryColor)
|
||||
.setProgressColor(ResourcesUtils.getAttrColor(this, R.attr.colorPrimary))
|
||||
.setProgressSize(resources.getDimensionPixelOffset(R.dimen.gallery_progress_size))
|
||||
.setPageTextColor(resources.getColor(R.color.secondary_text_default_dark))
|
||||
.setPageTextColor(AttrResources.getAttrColor(this, android.R.attr.textColorSecondary))
|
||||
.setPageTextSize(resources.getDimensionPixelOffset(R.dimen.gallery_page_text_size))
|
||||
.setPageTextTypeface(Typeface.DEFAULT)
|
||||
.setErrorTextColor(resources.getColor(R.color.red_500))
|
||||
|
||||
@@ -37,6 +37,7 @@ import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
import com.hippo.android.resource.AttrResources;
|
||||
import com.hippo.easyrecyclerview.EasyRecyclerView;
|
||||
import com.hippo.easyrecyclerview.LinearDividerItemDecoration;
|
||||
import com.hippo.ehviewer.EhApplication;
|
||||
@@ -81,11 +82,11 @@ public class HostsActivity extends ToolbarActivity
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
|
||||
LinearDividerItemDecoration decoration = new LinearDividerItemDecoration(
|
||||
LinearDividerItemDecoration.VERTICAL,
|
||||
getResources().getColor(R.color.divider),
|
||||
AttrResources.getAttrColor(this, R.attr.dividerColor),
|
||||
LayoutUtils.dp2pix(this, 1));
|
||||
decoration.setShowLastDivider(true);
|
||||
recyclerView.addItemDecoration(decoration);
|
||||
recyclerView.setSelector(Ripple.generateRippleDrawable(this, false));
|
||||
recyclerView.setSelector(Ripple.generateRippleDrawable(this, !AttrResources.getAttrBoolean(this, R.attr.isLightTheme)));
|
||||
recyclerView.setHasFixedSize(true);
|
||||
recyclerView.setOnItemClickListener(this);
|
||||
recyclerView.setPadding(
|
||||
|
||||
@@ -36,26 +36,26 @@ import android.support.design.widget.NavigationView;
|
||||
import android.support.design.widget.Snackbar;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Pair;
|
||||
import android.view.Gravity;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
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.EhApplication;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.Settings;
|
||||
import com.hippo.ehviewer.client.EhUrl;
|
||||
import com.hippo.ehviewer.client.EhUrlOpener;
|
||||
import com.hippo.ehviewer.client.EhUtils;
|
||||
import com.hippo.ehviewer.client.data.ListUrlBuilder;
|
||||
import com.hippo.ehviewer.client.parser.GalleryDetailUrlParser;
|
||||
import com.hippo.ehviewer.client.parser.GalleryPageUrlParser;
|
||||
import com.hippo.ehviewer.ui.scene.AnalyticsScene;
|
||||
import com.hippo.ehviewer.ui.scene.BaseScene;
|
||||
import com.hippo.ehviewer.ui.scene.CookieSignInScene;
|
||||
import com.hippo.ehviewer.ui.scene.CrashScene;
|
||||
import com.hippo.ehviewer.ui.scene.DownloadLabelsScene;
|
||||
import com.hippo.ehviewer.ui.scene.DownloadsScene;
|
||||
import com.hippo.ehviewer.ui.scene.FavoritesScene;
|
||||
@@ -115,16 +115,15 @@ public final class MainActivity extends StageActivity
|
||||
private LoadImageView mAvatar;
|
||||
@Nullable
|
||||
private TextView mDisplayName;
|
||||
@Nullable
|
||||
private Button mChangeTheme;
|
||||
|
||||
private int mNavCheckedItem = 0;
|
||||
|
||||
private int mClipTextHashCode = 0;
|
||||
|
||||
static {
|
||||
registerLaunchMode(SecurityScene.class, SceneFragment.LAUNCH_MODE_SINGLE_TASK);
|
||||
registerLaunchMode(WarningScene.class, SceneFragment.LAUNCH_MODE_SINGLE_TASK);
|
||||
registerLaunchMode(AnalyticsScene.class, SceneFragment.LAUNCH_MODE_SINGLE_TASK);
|
||||
registerLaunchMode(CrashScene.class, SceneFragment.LAUNCH_MODE_SINGLE_TASK);
|
||||
registerLaunchMode(SignInScene.class, SceneFragment.LAUNCH_MODE_SINGLE_TASK);
|
||||
registerLaunchMode(WebViewSignInScene.class, SceneFragment.LAUNCH_MODE_SINGLE_TASK);
|
||||
registerLaunchMode(CookieSignInScene.class, SceneFragment.LAUNCH_MODE_SINGLE_TASK);
|
||||
@@ -142,6 +141,19 @@ public final class MainActivity extends StageActivity
|
||||
registerLaunchMode(ProgressScene.class, SceneFragment.LAUNCH_MODE_STANDARD);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getThemeResId(int theme) {
|
||||
switch (theme) {
|
||||
case Settings.THEME_LIGHT:
|
||||
default:
|
||||
return R.style.AppTheme_Main;
|
||||
case Settings.THEME_DARK:
|
||||
return R.style.AppTheme_Main_Dark;
|
||||
case Settings.THEME_BLACK:
|
||||
return R.style.AppTheme_Main_Black;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getContainerViewId() {
|
||||
return R.id.fragment_container;
|
||||
@@ -156,8 +168,6 @@ public final class MainActivity extends StageActivity
|
||||
return new Announcer(WarningScene.class);
|
||||
} else if (Settings.getAskAnalytics()) {
|
||||
return new Announcer(AnalyticsScene.class);
|
||||
} else if (Crash.hasCrashFile()) {
|
||||
return new Announcer(CrashScene.class);
|
||||
} else if (EhUtils.needSignedIn(this)) {
|
||||
return new Announcer(SignInScene.class);
|
||||
} else if (Settings.getSelectSite()) {
|
||||
@@ -187,11 +197,6 @@ public final class MainActivity extends StageActivity
|
||||
newArgs.putString(AnalyticsScene.KEY_TARGET_SCENE, announcer.getClazz().getName());
|
||||
newArgs.putBundle(AnalyticsScene.KEY_TARGET_ARGS, announcer.getArgs());
|
||||
return new Announcer(AnalyticsScene.class).setArgs(newArgs);
|
||||
} else if (Crash.hasCrashFile()) {
|
||||
Bundle newArgs = new Bundle();
|
||||
newArgs.putString(CrashScene.KEY_TARGET_SCENE, announcer.getClazz().getName());
|
||||
newArgs.putBundle(CrashScene.KEY_TARGET_ARGS, announcer.getArgs());
|
||||
return new Announcer(CrashScene.class).setArgs(newArgs);
|
||||
} else if (EhUtils.needSignedIn(this)) {
|
||||
Bundle newArgs = new Bundle();
|
||||
newArgs.putString(SignInScene.KEY_TARGET_SCENE, announcer.getClazz().getName());
|
||||
@@ -322,6 +327,7 @@ public final class MainActivity extends StageActivity
|
||||
View headerLayout = mNavView.getHeaderView(0);
|
||||
mAvatar = (LoadImageView) ViewUtils.$$(headerLayout, R.id.avatar);
|
||||
mDisplayName = (TextView) ViewUtils.$$(headerLayout, R.id.display_name);
|
||||
mChangeTheme = (Button) ViewUtils.$$(this, R.id.change_theme);
|
||||
|
||||
mDrawerLayout.setStatusBarColor(ResourcesUtils.getAttrColor(this, R.attr.colorPrimaryDark));
|
||||
// Pre-L need shadow drawable
|
||||
@@ -336,11 +342,15 @@ public final class MainActivity extends StageActivity
|
||||
mNavView.setNavigationItemSelectedListener(this);
|
||||
}
|
||||
|
||||
mChangeTheme.setText(getThemeText());
|
||||
mChangeTheme.setOnClickListener(v -> {
|
||||
Settings.putTheme(getNextTheme());
|
||||
((EhApplication) getApplication()).recreate();
|
||||
});
|
||||
|
||||
if (savedInstanceState == null) {
|
||||
onInit();
|
||||
if (Settings.getAutoCheckUpdateEnable()) {
|
||||
CommonOperations.checkUpdate(this, false);
|
||||
}
|
||||
CommonOperations.checkUpdate(this, false);
|
||||
checkDownloadLocation();
|
||||
if (Settings.getCellularNetworkWarning()) {
|
||||
checkCellularNetwork();
|
||||
@@ -350,6 +360,35 @@ public final class MainActivity extends StageActivity
|
||||
}
|
||||
}
|
||||
|
||||
private String getThemeText() {
|
||||
int resId;
|
||||
switch (Settings.getTheme()) {
|
||||
default:
|
||||
case Settings.THEME_LIGHT:
|
||||
resId = R.string.theme_light;
|
||||
break;
|
||||
case Settings.THEME_DARK:
|
||||
resId = R.string.theme_dark;
|
||||
break;
|
||||
case Settings.THEME_BLACK:
|
||||
resId = R.string.theme_black;
|
||||
break;
|
||||
}
|
||||
return getString(resId);
|
||||
}
|
||||
|
||||
private int getNextTheme() {
|
||||
switch (Settings.getTheme()) {
|
||||
default:
|
||||
case Settings.THEME_LIGHT:
|
||||
return Settings.THEME_DARK;
|
||||
case Settings.THEME_DARK:
|
||||
return Settings.THEME_BLACK;
|
||||
case Settings.THEME_BLACK:
|
||||
return Settings.THEME_LIGHT;
|
||||
}
|
||||
}
|
||||
|
||||
private void checkDownloadLocation() {
|
||||
UniFile uniFile = Settings.getDownloadLocation();
|
||||
// null == uniFile for first start
|
||||
@@ -373,20 +412,16 @@ public final class MainActivity extends StageActivity
|
||||
// Check permission
|
||||
PermissionRequester.request(this, Manifest.permission.WRITE_EXTERNAL_STORAGE,
|
||||
getString(R.string.write_rationale), PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE);
|
||||
|
||||
mClipTextHashCode = Settings.getClipboardTextHashCode();
|
||||
}
|
||||
|
||||
private void onRestore(Bundle savedInstanceState) {
|
||||
mNavCheckedItem = savedInstanceState.getInt(KEY_NAV_CHECKED_ITEM);
|
||||
mClipTextHashCode = savedInstanceState.getInt(KEY_CLIP_TEXT_HASH_CODE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle outState, PersistableBundle outPersistentState) {
|
||||
super.onSaveInstanceState(outState, outPersistentState);
|
||||
outState.putInt(KEY_NAV_CHECKED_ITEM, mNavCheckedItem);
|
||||
outState.putInt(KEY_CLIP_TEXT_HASH_CODE, mClipTextHashCode);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -440,34 +475,44 @@ public final class MainActivity extends StageActivity
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private Announcer createAnnouncerFromClipboardUrl(String url) {
|
||||
GalleryDetailUrlParser.Result result1 = GalleryDetailUrlParser.parse(url, false);
|
||||
if (result1 != null) {
|
||||
Bundle args = new Bundle();
|
||||
args.putString(GalleryDetailScene.KEY_ACTION, GalleryDetailScene.ACTION_GID_TOKEN);
|
||||
args.putLong(GalleryDetailScene.KEY_GID, result1.gid);
|
||||
args.putString(GalleryDetailScene.KEY_TOKEN, result1.token);
|
||||
return new Announcer(GalleryDetailScene.class).setArgs(args);
|
||||
}
|
||||
|
||||
GalleryPageUrlParser.Result result2 = GalleryPageUrlParser.parse(url, false);
|
||||
if (result2 != null) {
|
||||
Bundle args = new Bundle();
|
||||
args.putString(ProgressScene.KEY_ACTION, ProgressScene.ACTION_GALLERY_TOKEN);
|
||||
args.putLong(ProgressScene.KEY_GID, result2.gid);
|
||||
args.putString(ProgressScene.KEY_PTOKEN, result2.pToken);
|
||||
args.putInt(ProgressScene.KEY_PAGE, result2.page);
|
||||
return new Announcer(ProgressScene.class).setArgs(args);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private void checkClipboardUrlInternal() {
|
||||
String text = getTextFromClipboard();
|
||||
int hashCode = text != null ? text.hashCode() : 0;
|
||||
|
||||
if (text != null && hashCode != 0 && mClipTextHashCode != hashCode) {
|
||||
Pair<Long, String> pair = EhUrl.parseGalleryDetailUrl(text);
|
||||
if (pair != null) {
|
||||
long gid = pair.first;
|
||||
String token = pair.second;
|
||||
new AlertDialog.Builder(this)
|
||||
.setTitle(R.string.clipboard_gallery_url_dialog_title)
|
||||
.setMessage(R.string.clipboard_gallery_url_dialog_message)
|
||||
.setNegativeButton(android.R.string.cancel, null)
|
||||
.setPositiveButton(android.R.string.ok, (dialog, which) -> {
|
||||
Bundle args = new Bundle();
|
||||
args.putString(GalleryDetailScene.KEY_ACTION, GalleryDetailScene.ACTION_GID_TOKEN);
|
||||
args.putLong(GalleryDetailScene.KEY_GID, gid);
|
||||
args.putString(GalleryDetailScene.KEY_TOKEN, token);
|
||||
startScene(new Announcer(GalleryDetailScene.class).setArgs(args));
|
||||
})
|
||||
.show();
|
||||
if (text != null && hashCode != 0 && Settings.getClipboardTextHashCode() != hashCode) {
|
||||
Announcer announcer = createAnnouncerFromClipboardUrl(text);
|
||||
if (announcer != null && mDrawerLayout != null) {
|
||||
Snackbar snackbar = Snackbar.make(mDrawerLayout, R.string.clipboard_gallery_url_snack_message, Snackbar.LENGTH_INDEFINITE);
|
||||
snackbar.setAction(R.string.clipboard_gallery_url_snack_action, v -> startScene(announcer));
|
||||
snackbar.show();
|
||||
}
|
||||
}
|
||||
|
||||
if (mClipTextHashCode != hashCode) {
|
||||
mClipTextHashCode = hashCode;
|
||||
Settings.putClipboardTextHashCode(hashCode);
|
||||
}
|
||||
Settings.putClipboardTextHashCode(hashCode);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -17,8 +17,10 @@
|
||||
package com.hippo.ehviewer.ui;
|
||||
|
||||
import android.hardware.fingerprint.FingerprintManager;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.annotation.RequiresApi;
|
||||
import android.text.TextUtils;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
@@ -62,7 +64,7 @@ public class SetSecurityActivity extends ToolbarActivity implements View.OnClick
|
||||
FingerprintManager fingerprintManager = getSystemService(FingerprintManager.class);
|
||||
// The line below prevents the false positive inspection from Android Studio
|
||||
// noinspection ResourceType
|
||||
if (fingerprintManager.hasEnrolledFingerprints()) {
|
||||
if (fingerprintManager != null && hasEnrolledFingerprints(fingerprintManager)) {
|
||||
mFingerprint.setVisibility(View.VISIBLE);
|
||||
mFingerprint.setChecked(Settings.getEnableFingerprint());
|
||||
}
|
||||
@@ -72,6 +74,16 @@ public class SetSecurityActivity extends ToolbarActivity implements View.OnClick
|
||||
mSet.setOnClickListener(this);
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.M)
|
||||
public static boolean hasEnrolledFingerprints(FingerprintManager fingerprintManager) {
|
||||
try {
|
||||
return fingerprintManager.isHardwareDetected()
|
||||
&& fingerprintManager.hasEnrolledFingerprints();
|
||||
} catch (Throwable e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
|
||||
@@ -17,31 +17,22 @@
|
||||
package com.hippo.ehviewer.ui;
|
||||
|
||||
import android.app.Fragment;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.StringRes;
|
||||
import android.support.v7.app.ActionBar;
|
||||
import android.support.v7.app.ActionBarDrawerToggle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ListAdapter;
|
||||
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.Settings;
|
||||
import com.hippo.ehviewer.ui.fragment.AboutFragment;
|
||||
import com.hippo.ehviewer.ui.fragment.AdvancedFragment;
|
||||
import com.hippo.ehviewer.ui.fragment.DownloadFragment;
|
||||
import com.hippo.ehviewer.ui.fragment.EhFragment;
|
||||
import com.hippo.ehviewer.ui.fragment.ReadFragment;
|
||||
import com.hippo.ehviewer.ui.fragment.PrivacyFragment;
|
||||
import com.hippo.ehviewer.ui.fragment.ReadFragment;
|
||||
import com.hippo.util.DrawableManager;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.List;
|
||||
|
||||
public final class SettingsActivity extends EhPreferenceActivity {
|
||||
@@ -57,75 +48,17 @@ public final class SettingsActivity extends EhPreferenceActivity {
|
||||
PrivacyFragment.class.getName(),
|
||||
};
|
||||
|
||||
private class FakeLayoutInflater extends LayoutInflater {
|
||||
|
||||
private final LayoutInflater mInflater;
|
||||
|
||||
protected FakeLayoutInflater(LayoutInflater inflater) {
|
||||
super(null);
|
||||
mInflater = inflater;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LayoutInflater cloneInContext(Context newContext) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View inflate(int resource, ViewGroup root, boolean attachToRoot) {
|
||||
return mInflater.inflate(R.layout.item_preference_header, root, attachToRoot);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("TryWithIdenticalCatches")
|
||||
private void replaceHeaderLayoutResId() {
|
||||
try {
|
||||
ListAdapter adapter = getListAdapter();
|
||||
Class headerAdapterClazz = Class.forName("android.preference.PreferenceActivity$HeaderAdapter");
|
||||
if (!headerAdapterClazz.isInstance(adapter)) {
|
||||
return;
|
||||
}
|
||||
|
||||
boolean ok = false;
|
||||
|
||||
// For lollipop and above this work
|
||||
try {
|
||||
Field field = headerAdapterClazz.getDeclaredField("mLayoutResId");
|
||||
field.setAccessible(true);
|
||||
field.setInt(adapter, R.layout.item_preference_header);
|
||||
|
||||
ok = true;
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
} catch (NoSuchFieldException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// For pre-lollipop this work
|
||||
if (!ok) {
|
||||
try {
|
||||
Field field = headerAdapterClazz.getDeclaredField("mInflater");
|
||||
field.setAccessible(true);
|
||||
field.set(adapter, new FakeLayoutInflater((LayoutInflater) field.get(adapter)));
|
||||
|
||||
ok = true;
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
} catch (NoSuchFieldException e) {
|
||||
e.printStackTrace();
|
||||
} catch (ClassCastException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
if (ok) {
|
||||
getListView().setDivider(new ColorDrawable(Color.TRANSPARENT));
|
||||
getListView().setDividerHeight(0);
|
||||
}
|
||||
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@Override
|
||||
protected int getThemeResId(int theme) {
|
||||
switch (theme) {
|
||||
case Settings.THEME_LIGHT:
|
||||
default:
|
||||
return R.style.AppTheme_Settings;
|
||||
case Settings.THEME_DARK:
|
||||
return R.style.AppTheme_Settings_Dark;
|
||||
case Settings.THEME_BLACK:
|
||||
return R.style.AppTheme_Settings_Black;
|
||||
}
|
||||
}
|
||||
|
||||
private void setActionBarUpIndicator(Drawable drawable) {
|
||||
@@ -144,16 +77,14 @@ public final class SettingsActivity extends EhPreferenceActivity {
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setActionBarUpIndicator(DrawableManager.getDrawable(this, R.drawable.v_arrow_left_dark_x24));
|
||||
|
||||
replaceHeaderLayoutResId();
|
||||
setActionBarUpIndicator(DrawableManager.getVectorDrawable(this, R.drawable.v_arrow_left_dark_x24));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case android.R.id.home:
|
||||
finish();
|
||||
onBackPressed();
|
||||
return true;
|
||||
default:
|
||||
return super.onOptionsItemSelected(item);
|
||||
|
||||
@@ -25,9 +25,23 @@ import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.Settings;
|
||||
|
||||
public abstract class ToolbarActivity extends EhActivity {
|
||||
|
||||
@Override
|
||||
protected int getThemeResId(int theme) {
|
||||
switch (theme) {
|
||||
case Settings.THEME_LIGHT:
|
||||
default:
|
||||
return R.style.AppTheme_Toolbar;
|
||||
case Settings.THEME_DARK:
|
||||
return R.style.AppTheme_Toolbar_Dark;
|
||||
case Settings.THEME_BLACK:
|
||||
return R.style.AppTheme_Toolbar_Black;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setContentView(@LayoutRes int layoutResID) {
|
||||
super.setContentView(R.layout.activity_toolbar);
|
||||
|
||||
@@ -19,18 +19,20 @@ package com.hippo.ehviewer.ui.fragment;
|
||||
import android.content.ClipData;
|
||||
import android.content.ClipboardManager;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.preference.Preference;
|
||||
import android.preference.PreferenceFragment;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.util.Base64;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.hippo.ehviewer.Analytics;
|
||||
import com.hippo.ehviewer.EhApplication;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.Settings;
|
||||
import com.hippo.ehviewer.ui.CommonOperations;
|
||||
import com.hippo.util.AppHelper;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
public class AboutFragment extends PreferenceFragment
|
||||
implements Preference.OnPreferenceClickListener {
|
||||
@@ -49,14 +51,12 @@ public class AboutFragment extends PreferenceFragment
|
||||
Preference checkForUpdate = findPreference(KEY_CHECK_FOR_UPDATES);
|
||||
|
||||
author.setSummary(getString(R.string.settings_about_author_summary).replace('$', '@'));
|
||||
donate.setSummary(getString(R.string.settings_about_donate_summary).replace('$', '@'));
|
||||
|
||||
author.setOnPreferenceClickListener(this);
|
||||
donate.setOnPreferenceClickListener(this);
|
||||
checkForUpdate.setOnPreferenceClickListener(this);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
String key = preference.getKey();
|
||||
@@ -64,17 +64,51 @@ public class AboutFragment extends PreferenceFragment
|
||||
AppHelper.sendEmail(getActivity(), EhApplication.getDeveloperEmail(),
|
||||
"About EhViewer", null);
|
||||
} else if (KEY_DONATE.equals(key)) {
|
||||
ClipboardManager cmb = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
|
||||
cmb.setPrimaryClip(ClipData.newPlainText(null, "seven332$163.com".replace('$', '@')));
|
||||
Toast.makeText(getActivity(), R.string.settings_about_donate_toast, Toast.LENGTH_SHORT).show();
|
||||
|
||||
new AlertDialog.Builder(getActivity())
|
||||
.setTitle(R.string.settings_about_donate)
|
||||
.setMessage(getString(R.string.settings_about_donate_message).replace('$', '@'))
|
||||
.show();
|
||||
showDonationDialog();
|
||||
} else if (KEY_CHECK_FOR_UPDATES.equals(key)) {
|
||||
CommonOperations.checkUpdate(getActivity(), true);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void showDonationDialog() {
|
||||
AlertDialog dialog = new AlertDialog.Builder(getActivity())
|
||||
.setView(R.layout.dialog_donate)
|
||||
.show();
|
||||
|
||||
String alipayStr = base64Decode("c2V2ZW4zMzJAMTYzLmNvbQ==");
|
||||
TextView alipayText = dialog.findViewById(R.id.alipay_text);
|
||||
alipayText.setText(alipayStr);
|
||||
dialog.findViewById(R.id.alipay_copy).setOnClickListener(v -> copyToClipboard(alipayStr));
|
||||
|
||||
String paypalStr = base64Decode("aHR0cHM6Ly9wYXlwYWwubWUvc2V2ZW4zMzI=");
|
||||
TextView paypalText = dialog.findViewById(R.id.paypal_text);
|
||||
paypalText.setText(paypalStr);
|
||||
dialog.findViewById(R.id.paypal_open).setOnClickListener(v -> openUrl(paypalStr));
|
||||
dialog.findViewById(R.id.paypal_copy).setOnClickListener(v -> copyToClipboard(paypalStr));
|
||||
}
|
||||
|
||||
private static String base64Decode(String encoded) {
|
||||
byte[] bytes = Base64.decode(encoded, Base64.DEFAULT);
|
||||
try {
|
||||
return new String(bytes, "UTF-8");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void copyToClipboard(String text) {
|
||||
ClipboardManager cmb = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
|
||||
if (cmb != null) {
|
||||
cmb.setPrimaryClip(ClipData.newPlainText(null, text));
|
||||
Toast.makeText(getActivity(), R.string.settings_about_donate_copied, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
private void openUrl(String url) {
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW);
|
||||
intent.setData(Uri.parse(url));
|
||||
Intent chooser = Intent.createChooser(intent, "");
|
||||
startActivity(chooser);
|
||||
}
|
||||
}
|
||||
@@ -17,10 +17,11 @@
|
||||
package com.hippo.ehviewer.ui.fragment;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.preference.Preference;
|
||||
import android.preference.PreferenceFragment;
|
||||
|
||||
import com.hippo.ehviewer.EhApplication;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.Settings;
|
||||
|
||||
@@ -32,21 +33,35 @@ public class EhFragment extends PreferenceFragment
|
||||
super.onCreate(savedInstanceState);
|
||||
addPreferencesFromResource(R.xml.eh_settings);
|
||||
|
||||
Preference theme = findPreference(Settings.KEY_THEME);
|
||||
Preference applyNavBarThemeColor = findPreference(Settings.KEY_APPLY_NAV_BAR_THEME_COLOR);
|
||||
Preference gallerySite = findPreference(Settings.KEY_GALLERY_SITE);
|
||||
Preference listMode = findPreference(Settings.KEY_LIST_MODE);
|
||||
Preference detailSize = findPreference(Settings.KEY_DETAIL_SIZE);
|
||||
Preference thumbSize = findPreference(Settings.KEY_THUMB_SIZE);
|
||||
|
||||
theme.setOnPreferenceChangeListener(this);
|
||||
applyNavBarThemeColor.setOnPreferenceChangeListener(this);
|
||||
gallerySite.setOnPreferenceChangeListener(this);
|
||||
listMode.setOnPreferenceChangeListener(this);
|
||||
detailSize.setOnPreferenceChangeListener(this);
|
||||
thumbSize.setOnPreferenceChangeListener(this);
|
||||
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
|
||||
getPreferenceScreen().removePreference(applyNavBarThemeColor);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
String key = preference.getKey();
|
||||
if (Settings.KEY_GALLERY_SITE.equals(key)) {
|
||||
if (Settings.KEY_THEME.equals(key)) {
|
||||
((EhApplication) getActivity().getApplication()).recreate();
|
||||
return true;
|
||||
} else if (Settings.KEY_APPLY_NAV_BAR_THEME_COLOR.equals(key)) {
|
||||
((EhApplication) getActivity().getApplication()).recreate();
|
||||
return true;
|
||||
} else if (Settings.KEY_GALLERY_SITE.equals(key)) {
|
||||
getActivity().setResult(Activity.RESULT_OK);
|
||||
return true;
|
||||
} else if (Settings.KEY_LIST_MODE.equals(key)) {
|
||||
|
||||
@@ -33,6 +33,7 @@ import android.view.Gravity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import com.hippo.ehviewer.Analytics;
|
||||
import com.hippo.ehviewer.ui.MainActivity;
|
||||
import com.hippo.scene.SceneFragment;
|
||||
import com.hippo.util.AppHelper;
|
||||
@@ -261,6 +262,12 @@ public abstract class BaseScene extends SceneFragment {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
Analytics.onSceneView(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(@NonNull Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
|
||||
@@ -35,8 +35,8 @@ import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.client.EhCookieStore;
|
||||
import com.hippo.ehviewer.client.EhUrl;
|
||||
import com.hippo.ehviewer.client.EhUtils;
|
||||
import com.hippo.yorozuya.AssertUtils;
|
||||
import com.hippo.yorozuya.ViewUtils;
|
||||
import junit.framework.Assert;
|
||||
import okhttp3.Cookie;
|
||||
|
||||
public class CookieSignInScene extends SolidScene implements EditText.OnEditorActionListener,
|
||||
@@ -72,13 +72,13 @@ public class CookieSignInScene extends SolidScene implements EditText.OnEditorAc
|
||||
View view = inflater.inflate(R.layout.scene_cookie_sign_in, container, false);
|
||||
mIpbMemberIdLayout = (TextInputLayout) ViewUtils.$$(view, R.id.ipb_member_id_layout);
|
||||
mIpbMemberId = mIpbMemberIdLayout.getEditText();
|
||||
Assert.assertNotNull(mIpbMemberId);
|
||||
AssertUtils.assertNotNull(mIpbMemberId);
|
||||
mIpbPassHashLayout = (TextInputLayout) ViewUtils.$$(view, R.id.ipb_pass_hash_layout);
|
||||
mIpbPassHash = mIpbPassHashLayout.getEditText();
|
||||
Assert.assertNotNull(mIpbPassHash);
|
||||
AssertUtils.assertNotNull(mIpbPassHash);
|
||||
mIgneousLayout = (TextInputLayout) ViewUtils.$$(view, R.id.igneous_layout);
|
||||
mIgneous = mIgneousLayout.getEditText();
|
||||
Assert.assertNotNull(mIgneous);
|
||||
AssertUtils.assertNotNull(mIgneous);
|
||||
mOk = ViewUtils.$$(view, R.id.ok);
|
||||
|
||||
mIpbPassHash.setOnEditorActionListener(this);
|
||||
@@ -87,7 +87,7 @@ public class CookieSignInScene extends SolidScene implements EditText.OnEditorAc
|
||||
|
||||
// Try to get old version cookie info
|
||||
Context context = getContext2();
|
||||
Assert.assertNotNull(context);
|
||||
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);
|
||||
|
||||
@@ -1,95 +0,0 @@
|
||||
/*
|
||||
* 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.scene;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.hippo.ehviewer.Crash;
|
||||
import com.hippo.ehviewer.EhApplication;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.ui.MainActivity;
|
||||
import com.hippo.ripple.Ripple;
|
||||
import com.hippo.util.AppHelper;
|
||||
import com.hippo.yorozuya.ViewUtils;
|
||||
|
||||
public class CrashScene extends SolidScene implements View.OnClickListener {
|
||||
|
||||
/*---------------
|
||||
Whole life cycle
|
||||
---------------*/
|
||||
@Nullable
|
||||
private String mCrash;
|
||||
|
||||
/*---------------
|
||||
View life cycle
|
||||
---------------*/
|
||||
@Nullable
|
||||
private View mCancel;
|
||||
@Nullable
|
||||
private View mSend;
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
mCrash = Crash.getCrashContent();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
mCrash = null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView2(LayoutInflater inflater,
|
||||
@Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
View view = inflater.inflate(R.layout.scene_crash, container, false);
|
||||
|
||||
mCancel = ViewUtils.$$(view, R.id.cancel);
|
||||
mSend = ViewUtils.$$(view, R.id.send);
|
||||
|
||||
mCancel.setOnClickListener(this);
|
||||
mSend.setOnClickListener(this);
|
||||
|
||||
Ripple.addRipple(mCancel, true);
|
||||
Ripple.addRipple(mSend, true);
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
MainActivity activity = getActivity2();
|
||||
|
||||
if (mSend == v && null != mCrash && null != activity) {
|
||||
AppHelper.sendEmail(activity, EhApplication.getDeveloperEmail(),
|
||||
"I found a bug in EhViewer !", mCrash);
|
||||
}
|
||||
Crash.resetCrashFile();
|
||||
|
||||
// Start new scene and finish it self
|
||||
if (null != activity) {
|
||||
startSceneForCheckStep(CHECK_STEP_CRASH, getArguments());
|
||||
}
|
||||
finish();
|
||||
}
|
||||
}
|
||||
@@ -32,20 +32,13 @@ import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.h6ah4i.android.widget.advrecyclerview.animator.GeneralItemAnimator;
|
||||
import com.h6ah4i.android.widget.advrecyclerview.animator.SwipeDismissItemAnimator;
|
||||
import com.h6ah4i.android.widget.advrecyclerview.draggable.DraggableItemAdapter;
|
||||
import com.h6ah4i.android.widget.advrecyclerview.draggable.ItemDraggableRange;
|
||||
import com.h6ah4i.android.widget.advrecyclerview.draggable.RecyclerViewDragDropManager;
|
||||
import com.h6ah4i.android.widget.advrecyclerview.swipeable.RecyclerViewSwipeManager;
|
||||
import com.h6ah4i.android.widget.advrecyclerview.swipeable.SwipeableItemAdapter;
|
||||
import com.h6ah4i.android.widget.advrecyclerview.swipeable.SwipeableItemConstants;
|
||||
import com.h6ah4i.android.widget.advrecyclerview.swipeable.action.SwipeResultAction;
|
||||
import com.h6ah4i.android.widget.advrecyclerview.swipeable.action.SwipeResultActionDefault;
|
||||
import com.h6ah4i.android.widget.advrecyclerview.swipeable.action.SwipeResultActionMoveToSwipedDirection;
|
||||
import com.h6ah4i.android.widget.advrecyclerview.touchguard.RecyclerViewTouchActionGuardManager;
|
||||
import com.h6ah4i.android.widget.advrecyclerview.utils.AbstractDraggableSwipeableItemViewHolder;
|
||||
import com.h6ah4i.android.widget.advrecyclerview.utils.AbstractDraggableItemViewHolder;
|
||||
import com.hippo.app.EditTextDialogBuilder;
|
||||
import com.hippo.easyrecyclerview.EasyRecyclerView;
|
||||
import com.hippo.ehviewer.EhApplication;
|
||||
@@ -53,10 +46,8 @@ import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.dao.DownloadLabel;
|
||||
import com.hippo.util.DrawableManager;
|
||||
import com.hippo.view.ViewTransition;
|
||||
import com.hippo.yorozuya.AssertUtils;
|
||||
import com.hippo.yorozuya.ViewUtils;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class DownloadLabelsScene extends ToolbarScene {
|
||||
@@ -101,8 +92,8 @@ public class DownloadLabelsScene extends ToolbarScene {
|
||||
mViewTransition = new ViewTransition(mRecyclerView, tip);
|
||||
|
||||
Context context = getContext2();
|
||||
Assert.assertNotNull(context);
|
||||
Drawable drawable = DrawableManager.getDrawable(context, R.drawable.big_label);
|
||||
AssertUtils.assertNotNull(context);
|
||||
Drawable drawable = DrawableManager.getVectorDrawable(context, R.drawable.big_label);
|
||||
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
|
||||
tip.setCompoundDrawables(null, drawable, null, null);
|
||||
tip.setText(R.string.no_download_label);
|
||||
@@ -115,12 +106,9 @@ public class DownloadLabelsScene extends ToolbarScene {
|
||||
RecyclerViewDragDropManager dragDropManager = new RecyclerViewDragDropManager();
|
||||
dragDropManager.setDraggingItemShadowDrawable(
|
||||
(NinePatchDrawable) context.getResources().getDrawable(R.drawable.shadow_8dp));
|
||||
// swipe manager
|
||||
RecyclerViewSwipeManager swipeManager = new RecyclerViewSwipeManager();
|
||||
RecyclerView.Adapter adapter = new LabelAdapter();
|
||||
adapter.setHasStableIds(true);
|
||||
adapter = dragDropManager.createWrappedAdapter(adapter); // wrap for dragging
|
||||
adapter = swipeManager.createWrappedAdapter(adapter); // wrap for swiping
|
||||
mAdapter = adapter;
|
||||
final GeneralItemAnimator animator = new SwipeDismissItemAnimator();
|
||||
animator.setSupportsChangeAnimations(false);
|
||||
@@ -129,7 +117,6 @@ public class DownloadLabelsScene extends ToolbarScene {
|
||||
mRecyclerView.setAdapter(adapter);
|
||||
mRecyclerView.setItemAnimator(animator);
|
||||
guardManager.attachRecyclerView(mRecyclerView);
|
||||
swipeManager.attachRecyclerView(mRecyclerView);
|
||||
dragDropManager.attachRecyclerView(mRecyclerView);
|
||||
|
||||
updateView();
|
||||
@@ -287,66 +274,77 @@ public class DownloadLabelsScene extends ToolbarScene {
|
||||
}
|
||||
}
|
||||
|
||||
private class LabelHolder extends AbstractDraggableSwipeableItemViewHolder
|
||||
private class LabelHolder extends AbstractDraggableItemViewHolder
|
||||
implements View.OnClickListener {
|
||||
|
||||
public final View swipeHandler;
|
||||
public final TextView label;
|
||||
public final View dragHandler;
|
||||
public final View delete;
|
||||
|
||||
public LabelHolder(View itemView) {
|
||||
super(itemView);
|
||||
|
||||
swipeHandler = ViewUtils.$$(itemView, R.id.swipe_handler);
|
||||
label = (TextView) ViewUtils.$$(itemView, R.id.label);
|
||||
dragHandler = ViewUtils.$$(itemView, R.id.drag_handler);
|
||||
delete = ViewUtils.$$(itemView, R.id.delete);
|
||||
|
||||
label.setOnClickListener(this);
|
||||
delete.setOnClickListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
int position = getAdapterPosition();
|
||||
Context context = getContext2();
|
||||
if (null == context || null == mList || null == mRecyclerView) {
|
||||
return;
|
||||
}
|
||||
|
||||
int index = mRecyclerView.getChildAdapterPosition(itemView);
|
||||
if (index < 0 || index >= mList.size()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (label == v) {
|
||||
DownloadLabel raw = mList.get(index);
|
||||
DownloadLabel raw = mList.get(position);
|
||||
EditTextDialogBuilder builder = new EditTextDialogBuilder(
|
||||
context, raw.getLabel(), getString(R.string.download_labels));
|
||||
builder.setTitle(R.string.rename_label_title);
|
||||
builder.setPositiveButton(android.R.string.ok, null);
|
||||
AlertDialog dialog = builder.show();
|
||||
new RenameLabelDialogHelper(builder, dialog, raw.getLabel(), index);
|
||||
new RenameLabelDialogHelper(builder, dialog, raw.getLabel(), position);
|
||||
} else if (delete == v) {
|
||||
final DownloadLabel label = mList.get(position);
|
||||
new AlertDialog.Builder(context)
|
||||
.setTitle(R.string.delete_label_title)
|
||||
.setMessage(getString(R.string.delete_label_message, label.getLabel()))
|
||||
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
EhApplication.getDownloadManager(context).deleteLabel(label.getLabel());
|
||||
}
|
||||
})
|
||||
.setOnDismissListener(new DialogInterface.OnDismissListener() {
|
||||
@Override
|
||||
public void onDismiss(DialogInterface dialog) {
|
||||
if (null != mAdapter) {
|
||||
mAdapter.notifyDataSetChanged();
|
||||
}
|
||||
updateView();
|
||||
}
|
||||
}).show();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getSwipeableContainerView() {
|
||||
return swipeHandler;
|
||||
}
|
||||
}
|
||||
|
||||
private class LabelAdapter extends RecyclerView.Adapter<LabelHolder>
|
||||
implements DraggableItemAdapter<LabelHolder>,
|
||||
SwipeableItemAdapter<LabelHolder> {
|
||||
implements DraggableItemAdapter<LabelHolder> {
|
||||
|
||||
private final LayoutInflater mInflater;
|
||||
|
||||
public LabelAdapter() {
|
||||
mInflater = getLayoutInflater2();
|
||||
Assert.assertNotNull(mInflater);
|
||||
AssertUtils.assertNotNull(mInflater);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LabelHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
return new LabelHolder(mInflater.inflate(R.layout.item_label_list, parent, false));
|
||||
return new LabelHolder(mInflater.inflate(R.layout.item_download_label, parent, false));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -354,7 +352,6 @@ public class DownloadLabelsScene extends ToolbarScene {
|
||||
if (mList != null) {
|
||||
holder.label.setText(mList.get(position).getLabel());
|
||||
}
|
||||
holder.setSwipeItemHorizontalSlideAmount(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -396,69 +393,9 @@ public class DownloadLabelsScene extends ToolbarScene {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int onGetSwipeReactionType(LabelHolder holder, int position, int x, int y) {
|
||||
if (ViewUtils.isViewUnder(holder.getSwipeableContainerView(), x, y, 0)) {
|
||||
return SwipeableItemConstants.REACTION_CAN_SWIPE_LEFT;
|
||||
} else {
|
||||
return SwipeableItemConstants.REACTION_CAN_NOT_SWIPE_BOTH_H;
|
||||
}
|
||||
}
|
||||
public void onItemDragStarted(int position) { }
|
||||
|
||||
@Override
|
||||
public void onSetSwipeBackground(LabelHolder holder, int position, int type) {}
|
||||
|
||||
@Override
|
||||
public SwipeResultAction onSwipeItem(LabelHolder holder, int position, int result) {
|
||||
switch (result) {
|
||||
// swipe left --- pin
|
||||
case SwipeableItemConstants.RESULT_SWIPED_LEFT:
|
||||
return new SwipeLeftResultAction(position);
|
||||
// other --- do nothing
|
||||
case SwipeableItemConstants.RESULT_SWIPED_RIGHT:
|
||||
case SwipeableItemConstants.RESULT_CANCELED:
|
||||
default:
|
||||
return new SwipeResultActionDefault();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class SwipeLeftResultAction extends SwipeResultActionMoveToSwipedDirection {
|
||||
|
||||
private final int mPosition;
|
||||
|
||||
public SwipeLeftResultAction(int position) {
|
||||
mPosition = position;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPerformAction() {
|
||||
super.onPerformAction();
|
||||
|
||||
final Context context = getContext2();
|
||||
final List<DownloadLabel> list = mList;
|
||||
if (null == context || null == list || mPosition < 0 || mPosition >= list.size()) {
|
||||
return;
|
||||
}
|
||||
final DownloadLabel label = list.get(mPosition);
|
||||
|
||||
new AlertDialog.Builder(context)
|
||||
.setTitle(R.string.delete_label_title)
|
||||
.setMessage(getString(R.string.delete_label_message, label.getLabel()))
|
||||
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
EhApplication.getDownloadManager(context).deleteLabel(label.getLabel());
|
||||
}
|
||||
})
|
||||
.setOnDismissListener(new DialogInterface.OnDismissListener() {
|
||||
@Override
|
||||
public void onDismiss(DialogInterface dialog) {
|
||||
if (null != mAdapter) {
|
||||
mAdapter.notifyDataSetChanged();
|
||||
}
|
||||
updateView();
|
||||
}
|
||||
}).show();
|
||||
}
|
||||
public void onItemDragFinished(int fromPosition, int toPosition, boolean result) { }
|
||||
}
|
||||
}
|
||||
@@ -50,11 +50,11 @@ import android.widget.ArrayAdapter;
|
||||
import android.widget.ListView;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.github.amlcurran.showcaseview.ShowcaseView;
|
||||
import com.github.amlcurran.showcaseview.SimpleShowcaseEventListener;
|
||||
import com.github.amlcurran.showcaseview.targets.PointTarget;
|
||||
import com.github.amlcurran.showcaseview.targets.ViewTarget;
|
||||
import com.hippo.android.resource.AttrResources;
|
||||
import com.hippo.app.CheckBoxDialogBuilder;
|
||||
import com.hippo.conaco.DataContainer;
|
||||
import com.hippo.conaco.ProgressNotifier;
|
||||
@@ -88,15 +88,12 @@ 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.IOUtils;
|
||||
import com.hippo.yorozuya.ObjectUtils;
|
||||
import com.hippo.yorozuya.ResourcesUtils;
|
||||
import com.hippo.yorozuya.ViewUtils;
|
||||
import com.hippo.yorozuya.collect.LongList;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
@@ -194,7 +191,7 @@ public class DownloadsScene extends ToolbarScene
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
Context context = getContext2();
|
||||
Assert.assertNotNull(context);
|
||||
AssertUtils.assertNotNull(context);
|
||||
mDownloadManager = EhApplication.getDownloadManager(context);
|
||||
mDownloadManager.addDownloadInfoListener(this);
|
||||
|
||||
@@ -287,10 +284,10 @@ public class DownloadsScene extends ToolbarScene
|
||||
mViewTransition = new ViewTransition(content, tip);
|
||||
|
||||
Context context = getContext2();
|
||||
Assert.assertNotNull(content);
|
||||
AssertUtils.assertNotNull(content);
|
||||
Resources resources = context.getResources();
|
||||
|
||||
Drawable drawable = DrawableManager.getDrawable(context, R.drawable.big_download);
|
||||
Drawable drawable = DrawableManager.getVectorDrawable(context, R.drawable.big_download);
|
||||
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
|
||||
tip.setCompoundDrawables(null, drawable, null, null);
|
||||
|
||||
@@ -301,7 +298,7 @@ public class DownloadsScene extends ToolbarScene
|
||||
mLayoutManager.setColumnSize(resources.getDimensionPixelOffset(Settings.getDetailSizeResId()));
|
||||
mLayoutManager.setStrategy(AutoStaggeredGridLayoutManager.STRATEGY_MIN_SIZE);
|
||||
mRecyclerView.setLayoutManager(mLayoutManager);
|
||||
mRecyclerView.setSelector(Ripple.generateRippleDrawable(context, false));
|
||||
mRecyclerView.setSelector(Ripple.generateRippleDrawable(context, !AttrResources.getAttrBoolean(context, R.attr.isLightTheme)));
|
||||
mRecyclerView.setDrawSelectorOnTop(true);
|
||||
mRecyclerView.hasFixedSize();
|
||||
mRecyclerView.setClipToPadding(false);
|
||||
@@ -327,7 +324,7 @@ public class DownloadsScene extends ToolbarScene
|
||||
|
||||
fastScroller.attachToRecyclerView(mRecyclerView);
|
||||
HandlerDrawable handlerDrawable = new HandlerDrawable();
|
||||
handlerDrawable.setColor(ResourcesUtils.getAttrColor(context, R.attr.colorAccent));
|
||||
handlerDrawable.setColor(AttrResources.getAttrColor(context, R.attr.widgetColorThemeAccent));
|
||||
fastScroller.setHandlerDrawable(handlerDrawable);
|
||||
fastScroller.setOnDragHandlerListener(this);
|
||||
|
||||
@@ -520,7 +517,7 @@ public class DownloadsScene extends ToolbarScene
|
||||
View view = inflater.inflate(R.layout.drawer_list, container, false);
|
||||
|
||||
final Context context = getContext2();
|
||||
Assert.assertNotNull(context);
|
||||
AssertUtils.assertNotNull(context);
|
||||
|
||||
Toolbar toolbar = (Toolbar) view.findViewById(R.id.toolbar);
|
||||
toolbar.setTitle(R.string.download_labels);
|
||||
@@ -1085,8 +1082,10 @@ public class DownloadsScene extends ToolbarScene
|
||||
thumb.setOnClickListener(this);
|
||||
start.setOnClickListener(this);
|
||||
stop.setOnClickListener(this);
|
||||
Ripple.addRipple(start, false);
|
||||
Ripple.addRipple(stop, false);
|
||||
|
||||
boolean isDarkTheme = !AttrResources.getAttrBoolean(getContext2(), R.attr.isLightTheme);
|
||||
Ripple.addRipple(start, isDarkTheme);
|
||||
Ripple.addRipple(stop, isDarkTheme);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1132,10 +1131,17 @@ public class DownloadsScene extends ToolbarScene
|
||||
private class DownloadAdapter extends RecyclerView.Adapter<DownloadHolder> {
|
||||
|
||||
private final LayoutInflater mInflater;
|
||||
private final int mListThumbWidth;
|
||||
private final int mListThumbHeight;
|
||||
|
||||
public DownloadAdapter() {
|
||||
mInflater = getLayoutInflater2();
|
||||
Assert.assertNotNull(mInflater);
|
||||
AssertUtils.assertNotNull(mInflater);
|
||||
|
||||
View calculator = mInflater.inflate(R.layout.item_gallery_list_thumb_height, null);
|
||||
ViewUtils.measureView(calculator, 1024, ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||
mListThumbHeight = calculator.getMeasuredHeight();
|
||||
mListThumbWidth = mListThumbHeight * 2 / 3;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1148,7 +1154,14 @@ public class DownloadsScene extends ToolbarScene
|
||||
|
||||
@Override
|
||||
public DownloadHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
return new DownloadHolder(mInflater.inflate(R.layout.item_download, parent, false));
|
||||
DownloadHolder holder = new DownloadHolder(mInflater.inflate(R.layout.item_download, parent, false));
|
||||
|
||||
ViewGroup.LayoutParams lp = holder.thumb.getLayoutParams();
|
||||
lp.width = mListThumbWidth;
|
||||
lp.height = mListThumbHeight;
|
||||
holder.thumb.setLayoutParams(lp);
|
||||
|
||||
return holder;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -45,10 +45,10 @@ import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.github.amlcurran.showcaseview.ShowcaseView;
|
||||
import com.github.amlcurran.showcaseview.SimpleShowcaseEventListener;
|
||||
import com.github.amlcurran.showcaseview.targets.PointTarget;
|
||||
import com.hippo.android.resource.AttrResources;
|
||||
import com.hippo.annotation.Implemented;
|
||||
import com.hippo.drawable.DrawerArrowDrawable;
|
||||
import com.hippo.easyrecyclerview.EasyRecyclerView;
|
||||
@@ -78,12 +78,10 @@ import com.hippo.util.DrawableManager;
|
||||
import com.hippo.widget.ContentLayout;
|
||||
import com.hippo.widget.FabLayout;
|
||||
import com.hippo.widget.SearchBarMover;
|
||||
import com.hippo.yorozuya.AssertUtils;
|
||||
import com.hippo.yorozuya.ObjectUtils;
|
||||
import com.hippo.yorozuya.SimpleHandler;
|
||||
import com.hippo.yorozuya.ViewUtils;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
@@ -176,7 +174,7 @@ public class FavoritesScene extends BaseScene implements
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
Context context = getContext2();
|
||||
Assert.assertNotNull(context);
|
||||
AssertUtils.assertNotNull(context);
|
||||
mClient = EhApplication.getEhClient(context);
|
||||
mFavCatArray = Settings.getFavCat();
|
||||
mFavCountArray = Settings.getFavCount();
|
||||
@@ -240,7 +238,7 @@ public class FavoritesScene extends BaseScene implements
|
||||
View view = inflater.inflate(R.layout.scene_favorites, container, false);
|
||||
ContentLayout contentLayout = (ContentLayout) view.findViewById(R.id.content_layout);
|
||||
MainActivity activity = getActivity2();
|
||||
Assert.assertNotNull(activity);
|
||||
AssertUtils.assertNotNull(activity);
|
||||
mDrawerLayout = (EhDrawerLayout) ViewUtils.$$(activity, R.id.draw_view);
|
||||
mRecyclerView = contentLayout.getRecyclerView();
|
||||
FastScroller fastScroller = contentLayout.getFastScroller();
|
||||
@@ -249,7 +247,7 @@ public class FavoritesScene extends BaseScene implements
|
||||
mFabLayout = (FabLayout) ViewUtils.$$(view, R.id.fab_layout);
|
||||
|
||||
Context context = getContext2();
|
||||
Assert.assertNotNull(context);
|
||||
AssertUtils.assertNotNull(context);
|
||||
Resources resources = context.getResources();
|
||||
int paddingTopSB = resources.getDimensionPixelOffset(R.dimen.gallery_padding_top_search_bar);
|
||||
|
||||
@@ -259,7 +257,7 @@ public class FavoritesScene extends BaseScene implements
|
||||
contentLayout.getFastScroller().setOnDragHandlerListener(this);
|
||||
|
||||
mAdapter = new FavoritesAdapter(inflater, resources, mRecyclerView, Settings.getListMode());
|
||||
mRecyclerView.setSelector(Ripple.generateRippleDrawable(context, false));
|
||||
mRecyclerView.setSelector(Ripple.generateRippleDrawable(context, !AttrResources.getAttrBoolean(context, R.attr.isLightTheme)));
|
||||
mRecyclerView.setDrawSelectorOnTop(true);
|
||||
mRecyclerView.hasFixedSize();
|
||||
mRecyclerView.setClipToPadding(false);
|
||||
@@ -273,9 +271,9 @@ public class FavoritesScene extends BaseScene implements
|
||||
|
||||
refreshLayout.setHeaderTranslationY(paddingTopSB);
|
||||
|
||||
mLeftDrawable = new DrawerArrowDrawable(context);
|
||||
mLeftDrawable = new DrawerArrowDrawable(context, AttrResources.getAttrColor(context, R.attr.drawableColorPrimary));
|
||||
mSearchBar.setLeftDrawable(mLeftDrawable);
|
||||
mSearchBar.setRightDrawable(DrawableManager.getDrawable(context, R.drawable.v_magnify_x24));
|
||||
mSearchBar.setRightDrawable(DrawableManager.getVectorDrawable(context, R.drawable.v_magnify_x24));
|
||||
mSearchBar.setHelper(this);
|
||||
mSearchBar.setAllowEmptySearch(false);
|
||||
updateSearchBar();
|
||||
@@ -364,7 +362,7 @@ public class FavoritesScene extends BaseScene implements
|
||||
|
||||
// Update hint
|
||||
if (!ObjectUtils.equal(favCatName, mOldFavCat)) {
|
||||
Drawable searchImage = DrawableManager.getDrawable(context, R.drawable.v_magnify_x24);
|
||||
Drawable searchImage = DrawableManager.getVectorDrawable(context, R.drawable.v_magnify_x24);
|
||||
SpannableStringBuilder ssb = new SpannableStringBuilder(" ");
|
||||
ssb.append(getString(R.string.favorites_search_bar_hint, favCatName));
|
||||
int textSize = (int) (mSearchBar.getEditTextTextSize() * 1.25);
|
||||
@@ -486,7 +484,7 @@ public class FavoritesScene extends BaseScene implements
|
||||
final Context context = getContext2();
|
||||
Toolbar toolbar = (Toolbar) ViewUtils.$$(view, R.id.toolbar);
|
||||
|
||||
Assert.assertNotNull(context);
|
||||
AssertUtils.assertNotNull(context);
|
||||
|
||||
toolbar.setTitle(R.string.collections);
|
||||
toolbar.inflateMenu(R.menu.drawer_favorites);
|
||||
@@ -607,7 +605,10 @@ public class FavoritesScene extends BaseScene implements
|
||||
if (mRecyclerView != null && mRecyclerView.isInCustomChoice()) {
|
||||
mRecyclerView.toggleItemChecked(position);
|
||||
} else if (mHelper != null) {
|
||||
GalleryInfo gi = mHelper.getDataAt(position);
|
||||
GalleryInfo gi = mHelper.getDataAtEx(position);
|
||||
if (gi == null) {
|
||||
return true;
|
||||
}
|
||||
Bundle args = new Bundle();
|
||||
args.putString(GalleryDetailScene.KEY_ACTION, GalleryDetailScene.ACTION_GALLERY_INFO);
|
||||
args.putParcelable(GalleryDetailScene.KEY_GALLERY_INFO, gi);
|
||||
@@ -753,7 +754,10 @@ public class FavoritesScene extends BaseScene implements
|
||||
SparseBooleanArray stateArray = mRecyclerView.getCheckedItemPositions();
|
||||
for (int i = 0, n = stateArray.size(); i < n; i++) {
|
||||
if (stateArray.valueAt(i)) {
|
||||
mModifyGiList.add(mHelper.getDataAt(stateArray.keyAt(i)));
|
||||
GalleryInfo gi = mHelper.getDataAtEx(stateArray.keyAt(i));
|
||||
if (gi != null) {
|
||||
mModifyGiList.add(gi);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1004,7 +1008,7 @@ public class FavoritesScene extends BaseScene implements
|
||||
@Nullable
|
||||
@Override
|
||||
public GalleryInfo getDataAt(int position) {
|
||||
return null != mHelper ? mHelper.getDataAt(position) : null;
|
||||
return null != mHelper ? mHelper.getDataAtEx(position) : null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -38,6 +38,7 @@ import com.hippo.ehviewer.client.EhUtils;
|
||||
import com.hippo.ehviewer.client.data.GalleryInfo;
|
||||
import com.hippo.ehviewer.widget.TileThumb;
|
||||
import com.hippo.widget.recyclerview.AutoStaggeredGridLayoutManager;
|
||||
import com.hippo.yorozuya.ViewUtils;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
@@ -58,6 +59,8 @@ abstract class GalleryAdapter extends RecyclerView.Adapter<GalleryHolder> {
|
||||
private final int mPaddingTopSB;
|
||||
private MarginItemDecoration mListDecoration;
|
||||
private MarginItemDecoration mGirdDecoration;
|
||||
private final int mListThumbWidth;
|
||||
private final int mListThumbHeight;
|
||||
private int mType = TYPE_INVALID;
|
||||
|
||||
public GalleryAdapter(@NonNull LayoutInflater inflater, @NonNull Resources resources,
|
||||
@@ -71,6 +74,11 @@ abstract class GalleryAdapter extends RecyclerView.Adapter<GalleryHolder> {
|
||||
mRecyclerView.setAdapter(this);
|
||||
mRecyclerView.setLayoutManager(mLayoutManager);
|
||||
|
||||
View calculator = inflater.inflate(R.layout.item_gallery_list_thumb_height, null);
|
||||
ViewUtils.measureView(calculator, 1024, ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||
mListThumbHeight = calculator.getMeasuredHeight();
|
||||
mListThumbWidth = mListThumbHeight * 2 / 3;
|
||||
|
||||
setType(type);
|
||||
}
|
||||
|
||||
@@ -146,7 +154,17 @@ abstract class GalleryAdapter extends RecyclerView.Adapter<GalleryHolder> {
|
||||
layoutId = R.layout.item_gallery_grid;
|
||||
break;
|
||||
}
|
||||
return new GalleryHolder(mInflater.inflate(layoutId, parent, false));
|
||||
|
||||
GalleryHolder holder = new GalleryHolder(mInflater.inflate(layoutId, parent, false));
|
||||
|
||||
if (viewType == TYPE_LIST) {
|
||||
ViewGroup.LayoutParams lp = holder.thumb.getLayoutParams();
|
||||
lp.width = mListThumbWidth;
|
||||
lp.height = mListThumbHeight;
|
||||
holder.thumb.setLayoutParams(lp);
|
||||
}
|
||||
|
||||
return holder;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -178,7 +196,7 @@ abstract class GalleryAdapter extends RecyclerView.Adapter<GalleryHolder> {
|
||||
category.setBackgroundColor(EhUtils.getCategoryColor(gi.category));
|
||||
}
|
||||
holder.posted.setText(gi.posted);
|
||||
if (gi.pages == 0) {
|
||||
if (gi.pages == 0 || !Settings.getShowGalleryPages()) {
|
||||
holder.pages.setText(null);
|
||||
RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) holder.simpleLanguage.getLayoutParams();
|
||||
lp.addRule(RelativeLayout.LEFT_OF, 0);
|
||||
|
||||
@@ -51,7 +51,7 @@ import android.view.ViewGroup;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.hippo.android.resource.AttrResources;
|
||||
import com.hippo.easyrecyclerview.EasyRecyclerView;
|
||||
import com.hippo.easyrecyclerview.LinearDividerItemDecoration;
|
||||
import com.hippo.ehviewer.EhApplication;
|
||||
@@ -77,15 +77,13 @@ import com.hippo.widget.FabLayout;
|
||||
import com.hippo.widget.LinkifyTextView;
|
||||
import com.hippo.widget.ObservedTextView;
|
||||
import com.hippo.yorozuya.AnimationUtils;
|
||||
import com.hippo.yorozuya.AssertUtils;
|
||||
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 com.hippo.yorozuya.collect.IntList;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -192,11 +190,11 @@ public final class GalleryCommentsScene extends ToolbarScene
|
||||
mFab = (FloatingActionButton) ViewUtils.$$(view, R.id.fab);
|
||||
|
||||
Context context = getContext2();
|
||||
Assert.assertNotNull(context);
|
||||
AssertUtils.assertNotNull(context);
|
||||
Resources resources = context.getResources();
|
||||
int paddingBottomFab = resources.getDimensionPixelOffset(R.dimen.gallery_padding_bottom_fab);
|
||||
|
||||
Drawable drawable = DrawableManager.getDrawable(context, R.drawable.big_weird_face);
|
||||
Drawable drawable = DrawableManager.getVectorDrawable(context, R.drawable.big_sad_pandroid);
|
||||
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
|
||||
tip.setCompoundDrawables(null, drawable, null, null);
|
||||
|
||||
@@ -205,11 +203,11 @@ public final class GalleryCommentsScene extends ToolbarScene
|
||||
mRecyclerView.setLayoutManager(new LinearLayoutManager(context,
|
||||
LinearLayoutManager.VERTICAL, false));
|
||||
LinearDividerItemDecoration decoration = new LinearDividerItemDecoration(
|
||||
LinearDividerItemDecoration.VERTICAL, context.getResources().getColor(R.color.divider),
|
||||
LinearDividerItemDecoration.VERTICAL, AttrResources.getAttrColor(context, R.attr.dividerColor),
|
||||
LayoutUtils.dp2pix(context, 1));
|
||||
decoration.setShowLastDivider(true);
|
||||
mRecyclerView.addItemDecoration(decoration);
|
||||
mRecyclerView.setSelector(Ripple.generateRippleDrawable(context, false));
|
||||
mRecyclerView.setSelector(Ripple.generateRippleDrawable(context, !AttrResources.getAttrBoolean(context, R.attr.isLightTheme)));
|
||||
mRecyclerView.setHasFixedSize(true);
|
||||
mRecyclerView.setOnItemClickListener(this);
|
||||
mRecyclerView.setPadding(mRecyclerView.getPaddingLeft(), mRecyclerView.getPaddingTop(),
|
||||
@@ -338,11 +336,11 @@ public final class GalleryCommentsScene extends ToolbarScene
|
||||
});
|
||||
rv.setLayoutManager(new LinearLayoutManager(context));
|
||||
LinearDividerItemDecoration decoration = new LinearDividerItemDecoration(
|
||||
LinearDividerItemDecoration.VERTICAL, context.getResources().getColor(R.color.divider),
|
||||
LinearDividerItemDecoration.VERTICAL, AttrResources.getAttrColor(context, R.attr.dividerColor),
|
||||
LayoutUtils.dp2pix(context, 1));
|
||||
decoration.setPadding(ResourcesUtils.getAttrDimensionPixelOffset(context, R.attr.dialogPreferredPadding));
|
||||
rv.addItemDecoration(decoration);
|
||||
rv.setSelector(Ripple.generateRippleDrawable(context, false));
|
||||
rv.setSelector(Ripple.generateRippleDrawable(context, !AttrResources.getAttrBoolean(context, R.attr.isLightTheme)));
|
||||
rv.setClipToPadding(false);
|
||||
builder.setView(rv).show();
|
||||
}
|
||||
@@ -460,7 +458,7 @@ public final class GalleryCommentsScene extends ToolbarScene
|
||||
return;
|
||||
}
|
||||
|
||||
mFab.setVisibility(View.INVISIBLE);
|
||||
((View) mFab).setVisibility(View.INVISIBLE);
|
||||
mEditPanel.setVisibility(View.VISIBLE);
|
||||
int halfW = mEditPanel.getWidth() / 2;
|
||||
int halfH = mEditPanel.getHeight() / 2;
|
||||
@@ -485,7 +483,7 @@ public final class GalleryCommentsScene extends ToolbarScene
|
||||
return;
|
||||
}
|
||||
|
||||
mFab.setVisibility(View.INVISIBLE);
|
||||
((View) mFab).setVisibility(View.INVISIBLE);
|
||||
mEditPanel.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
@@ -508,7 +506,7 @@ public final class GalleryCommentsScene extends ToolbarScene
|
||||
}
|
||||
|
||||
mEditPanel.setVisibility(View.GONE);
|
||||
mFab.setVisibility(View.VISIBLE);
|
||||
((View) mFab).setVisibility(View.VISIBLE);
|
||||
int fabStartX = mEditPanel.getLeft() + (mEditPanel.getWidth() / 2) - (mFab.getWidth() / 2);
|
||||
int fabStartY = mEditPanel.getTop() + (mEditPanel.getHeight() / 2) - (mFab.getHeight() / 2);
|
||||
mFab.setX(fabStartX);
|
||||
@@ -537,7 +535,7 @@ public final class GalleryCommentsScene extends ToolbarScene
|
||||
return;
|
||||
}
|
||||
|
||||
mFab.setVisibility(View.VISIBLE);
|
||||
((View) mFab).setVisibility(View.VISIBLE);
|
||||
mEditPanel.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
}
|
||||
@@ -619,7 +617,7 @@ public final class GalleryCommentsScene extends ToolbarScene
|
||||
|
||||
public CommentAdapter() {
|
||||
mInflater = getLayoutInflater2();
|
||||
Assert.assertNotNull(mInflater);
|
||||
AssertUtils.assertNotNull(mInflater);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -637,7 +635,7 @@ public final class GalleryCommentsScene extends ToolbarScene
|
||||
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))
|
||||
ss.setSpan(new ForegroundColorSpan(AttrResources.getAttrColor(context, android.R.attr.textColorSecondary))
|
||||
, 0, scoreString.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
ssb.append(" ").append(ss);
|
||||
}
|
||||
|
||||
Regular → Executable
+41
-37
@@ -53,7 +53,7 @@ import android.widget.LinearLayout;
|
||||
import android.widget.ListView;
|
||||
import android.widget.RatingBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.hippo.android.resource.AttrResources;
|
||||
import com.hippo.beerbelly.BeerBelly;
|
||||
import com.hippo.drawable.RoundSideRectDrawable;
|
||||
import com.hippo.ehviewer.AppConfig;
|
||||
@@ -101,14 +101,12 @@ import com.hippo.widget.LoadImageView;
|
||||
import com.hippo.widget.ObservedTextView;
|
||||
import com.hippo.widget.ProgressView;
|
||||
import com.hippo.widget.SimpleGridAutoSpanLayout;
|
||||
import com.hippo.yorozuya.AssertUtils;
|
||||
import com.hippo.yorozuya.FileUtils;
|
||||
import com.hippo.yorozuya.IOUtils;
|
||||
import com.hippo.yorozuya.IntIdGenerator;
|
||||
import com.hippo.yorozuya.SimpleHandler;
|
||||
import com.hippo.yorozuya.ViewUtils;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
@@ -409,7 +407,7 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
|
||||
long gid = getGid();
|
||||
if (gid != -1) {
|
||||
Context context = getContext2();
|
||||
Assert.assertNotNull(context);
|
||||
AssertUtils.assertNotNull(context);
|
||||
mDownloadState = EhApplication.getDownloadManager(context).getDownloadState(gid);
|
||||
} else {
|
||||
mDownloadState = DownloadInfo.STATE_INVALID;
|
||||
@@ -424,13 +422,14 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
|
||||
mViewTransition = new ViewTransition(mainView, progressView, mTip);
|
||||
|
||||
Context context = getContext2();
|
||||
Assert.assertNotNull(context);
|
||||
AssertUtils.assertNotNull(context);
|
||||
|
||||
Drawable drawable = DrawableManager.getDrawable(context, R.drawable.big_weird_face);
|
||||
Drawable drawable = DrawableManager.getVectorDrawable(context, R.drawable.big_sad_pandroid);
|
||||
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
|
||||
mTip.setCompoundDrawables(null, drawable, null, null);
|
||||
mTip.setOnClickListener(this);
|
||||
|
||||
boolean isDarkTheme = !AttrResources.getAttrBoolean(context, R.attr.isLightTheme);
|
||||
mHeader = ViewUtils.$$(mainView, R.id.header);
|
||||
mColorBg = ViewUtils.$$(mHeader, R.id.color_bg);
|
||||
mThumb = (LoadImageView) ViewUtils.$$(mHeader, R.id.thumb);
|
||||
@@ -441,9 +440,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);
|
||||
Ripple.addRipple(mOtherActions, false);
|
||||
Ripple.addRipple(mDownload, false);
|
||||
Ripple.addRipple(mRead, false);
|
||||
Ripple.addRipple(mOtherActions, isDarkTheme);
|
||||
Ripple.addRipple(mDownload, isDarkTheme);
|
||||
Ripple.addRipple(mRead, isDarkTheme);
|
||||
mUploader.setOnClickListener(this);
|
||||
mCategory.setOnClickListener(this);
|
||||
mOtherActions.setOnClickListener(this);
|
||||
@@ -462,7 +461,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);
|
||||
Ripple.addRipple(mInfo, false);
|
||||
Ripple.addRipple(mInfo, isDarkTheme);
|
||||
mInfo.setOnClickListener(this);
|
||||
|
||||
mActions = ViewUtils.$$(belowHeader, R.id.actions);
|
||||
@@ -477,13 +476,13 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
|
||||
mRate = (TextView) ViewUtils.$$(mActions, R.id.rate);
|
||||
mSimilar = (TextView) ViewUtils.$$(mActions, R.id.similar);
|
||||
mSearchCover = (TextView) ViewUtils.$$(mActions, R.id.search_cover);
|
||||
Ripple.addRipple(mHeartGroup, false);
|
||||
Ripple.addRipple(mTorrent, false);
|
||||
Ripple.addRipple(mArchive, false);
|
||||
Ripple.addRipple(mShare, false);
|
||||
Ripple.addRipple(mRate, false);
|
||||
Ripple.addRipple(mSimilar, false);
|
||||
Ripple.addRipple(mSearchCover, false);
|
||||
Ripple.addRipple(mHeartGroup, isDarkTheme);
|
||||
Ripple.addRipple(mTorrent, isDarkTheme);
|
||||
Ripple.addRipple(mArchive, isDarkTheme);
|
||||
Ripple.addRipple(mShare, isDarkTheme);
|
||||
Ripple.addRipple(mRate, isDarkTheme);
|
||||
Ripple.addRipple(mSimilar, isDarkTheme);
|
||||
Ripple.addRipple(mSearchCover, isDarkTheme);
|
||||
mHeartGroup.setOnClickListener(this);
|
||||
mTorrent.setOnClickListener(this);
|
||||
mArchive.setOnClickListener(this);
|
||||
@@ -498,13 +497,13 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
|
||||
|
||||
mComments = (LinearLayout) ViewUtils.$$(belowHeader, R.id.comments);
|
||||
mCommentsText = (TextView) ViewUtils.$$(mComments, R.id.comments_text);
|
||||
Ripple.addRipple(mComments, false);
|
||||
Ripple.addRipple(mComments, isDarkTheme);
|
||||
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);
|
||||
Ripple.addRipple(mPreviews, false);
|
||||
Ripple.addRipple(mPreviews, isDarkTheme);
|
||||
mPreviews.setOnClickListener(this);
|
||||
|
||||
mProgress = ViewUtils.$$(mainView, R.id.progress);
|
||||
@@ -543,7 +542,7 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
|
||||
super.onDestroyView();
|
||||
|
||||
Context context = getContext2();
|
||||
Assert.assertNotNull(context);
|
||||
AssertUtils.assertNotNull(context);
|
||||
EhApplication.getDownloadManager(context).removeDownloadInfoListener(this);
|
||||
|
||||
mTip = null;
|
||||
@@ -600,7 +599,7 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
|
||||
|
||||
private boolean prepareData() {
|
||||
Context context = getContext2();
|
||||
Assert.assertNotNull(context);
|
||||
AssertUtils.assertNotNull(context);
|
||||
|
||||
if (mGalleryDetail != null) {
|
||||
return true;
|
||||
@@ -653,21 +652,21 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
|
||||
}
|
||||
|
||||
private void ensureActionDrawable(Context context) {
|
||||
Drawable heart = DrawableManager.getDrawable(context, R.drawable.v_heart_primary_x48);
|
||||
Drawable heart = DrawableManager.getVectorDrawable(context, R.drawable.v_heart_primary_x48);
|
||||
setActionDrawable(mHeart, heart);
|
||||
Drawable heartOutline = DrawableManager.getDrawable(context, R.drawable.v_heart_outline_primary_x48);
|
||||
Drawable heartOutline = DrawableManager.getVectorDrawable(context, R.drawable.v_heart_outline_primary_x48);
|
||||
setActionDrawable(mHeartOutline, heartOutline);
|
||||
Drawable torrent = DrawableManager.getDrawable(context, R.drawable.v_utorrent_primary_x48);
|
||||
Drawable torrent = DrawableManager.getVectorDrawable(context, R.drawable.v_utorrent_primary_x48);
|
||||
setActionDrawable(mTorrent, torrent);
|
||||
Drawable archive = DrawableManager.getDrawable(context, R.drawable.v_archive_primary_x48);
|
||||
Drawable archive = DrawableManager.getVectorDrawable(context, R.drawable.v_archive_primary_x48);
|
||||
setActionDrawable(mArchive, archive);
|
||||
Drawable share = DrawableManager.getDrawable(context, R.drawable.v_share_primary_x48);
|
||||
Drawable share = DrawableManager.getVectorDrawable(context, R.drawable.v_share_primary_x48);
|
||||
setActionDrawable(mShare, share);
|
||||
Drawable rate = DrawableManager.getDrawable(context, R.drawable.v_thumb_up_primary_x48);
|
||||
Drawable rate = DrawableManager.getVectorDrawable(context, R.drawable.v_thumb_up_primary_x48);
|
||||
setActionDrawable(mRate, rate);
|
||||
Drawable similar = DrawableManager.getDrawable(context, R.drawable.v_similar_primary_x48);
|
||||
Drawable similar = DrawableManager.getVectorDrawable(context, R.drawable.v_similar_primary_x48);
|
||||
setActionDrawable(mSimilar, similar);
|
||||
Drawable searchCover = DrawableManager.getDrawable(context, R.drawable.v_file_find_primary_x48);
|
||||
Drawable searchCover = DrawableManager.getVectorDrawable(context, R.drawable.v_file_find_primary_x48);
|
||||
setActionDrawable(mSearchCover, searchCover);
|
||||
}
|
||||
|
||||
@@ -724,7 +723,7 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
|
||||
}
|
||||
|
||||
if ((oldState == STATE_INIT || oldState == STATE_FAILED || oldState == STATE_REFRESH) &&
|
||||
(state == STATE_NORMAL || state == STATE_REFRESH_HEADER)) {
|
||||
(state == STATE_NORMAL || state == STATE_REFRESH_HEADER) && AttrResources.getAttrBoolean(getContext2(), R.attr.isLightTheme)) {
|
||||
if (!createCircularReveal()) {
|
||||
SimpleHandler.getInstance().post(new Runnable() {
|
||||
@Override
|
||||
@@ -766,6 +765,11 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
|
||||
|
||||
if (gd.isFavorited || EhDB.containLocalFavorites(gd.gid)) {
|
||||
mHeart.setVisibility(View.VISIBLE);
|
||||
if (gd.favoriteName == null) {
|
||||
mHeart.setText(R.string.local_favorites);
|
||||
} else {
|
||||
mHeart.setText(gd.favoriteName);
|
||||
}
|
||||
mHeartOutline.setVisibility(View.GONE);
|
||||
} else {
|
||||
mHeart.setVisibility(View.GONE);
|
||||
@@ -785,7 +789,7 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
|
||||
}
|
||||
|
||||
Resources resources = getResources2();
|
||||
Assert.assertNotNull(resources);
|
||||
AssertUtils.assertNotNull(resources);
|
||||
|
||||
mThumb.load(EhCacheKeyFactory.getThumbKey(gd.gid), gd.thumb);
|
||||
mTitle.setText(EhUtils.getSuitableTitle(gd));
|
||||
@@ -830,8 +834,8 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
|
||||
mNoTags.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
int colorTag = resources.getColor(R.color.colorPrimary);
|
||||
int colorName = resources.getColor(R.color.purple_a400);
|
||||
int colorTag = AttrResources.getAttrColor(context, R.attr.tagBackgroundColor);
|
||||
int colorName = AttrResources.getAttrColor(context, R.attr.tagGroupBackgroundColor);
|
||||
for (GalleryTagGroup tg : tagGroups) {
|
||||
LinearLayout ll = (LinearLayout) inflater.inflate(R.layout.gallery_tag_group, mTags, false);
|
||||
ll.setOrientation(LinearLayout.HORIZONTAL);
|
||||
@@ -961,7 +965,7 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
|
||||
|
||||
private String getAllRatingText(float rating, int ratingCount) {
|
||||
Resources resources = getResources2();
|
||||
Assert.assertNotNull(resources);
|
||||
AssertUtils.assertNotNull(resources);
|
||||
return resources.getString(R.string.rating_text, getRatingText(rating, resources), rating, ratingCount);
|
||||
}
|
||||
|
||||
@@ -984,7 +988,7 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
|
||||
}
|
||||
|
||||
Context context = getContext2();
|
||||
Assert.assertNotNull(context);
|
||||
AssertUtils.assertNotNull(context);
|
||||
PopupMenu popup = new PopupMenu(context, mOtherActions, Gravity.TOP);
|
||||
mPopupMenu = popup;
|
||||
popup.getMenuInflater().inflate(R.menu.scene_gallery_detail, popup.getMenu());
|
||||
@@ -1533,7 +1537,7 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
|
||||
private void onModifyFavoritesSuccess(boolean addOrRemove) {
|
||||
mModifingFavorites = false;
|
||||
if (mGalleryDetail != null) {
|
||||
mGalleryDetail.isFavorited = !addOrRemove;
|
||||
mGalleryDetail.isFavorited = !addOrRemove && mGalleryDetail.favoriteName != null;
|
||||
updateFavoriteDrawable();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,19 +29,18 @@ import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.hippo.android.resource.AttrResources;
|
||||
import com.hippo.easyrecyclerview.EasyRecyclerView;
|
||||
import com.hippo.easyrecyclerview.LinearDividerItemDecoration;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.Settings;
|
||||
import com.hippo.ehviewer.client.EhUrl;
|
||||
import com.hippo.ehviewer.client.EhUtils;
|
||||
import com.hippo.ehviewer.client.data.GalleryDetail;
|
||||
import com.hippo.ripple.Ripple;
|
||||
import com.hippo.yorozuya.AssertUtils;
|
||||
import com.hippo.yorozuya.LayoutUtils;
|
||||
import com.hippo.yorozuya.ViewUtils;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public final class GalleryInfoScene extends ToolbarScene implements EasyRecyclerView.OnItemClickListener {
|
||||
@@ -85,7 +84,7 @@ public final class GalleryInfoScene extends ToolbarScene implements EasyRecycler
|
||||
}
|
||||
|
||||
Resources resources = getResources2();
|
||||
Assert.assertNotNull(resources);
|
||||
AssertUtils.assertNotNull(resources);
|
||||
mKeys.add(resources.getString(R.string.header_key));
|
||||
mValues.add(resources.getString(R.string.header_value));
|
||||
mKeys.add(resources.getString(R.string.key_gid));
|
||||
@@ -128,6 +127,8 @@ public final class GalleryInfoScene extends ToolbarScene implements EasyRecycler
|
||||
mValues.add(Integer.toString(gd.torrentCount));
|
||||
mKeys.add(resources.getString(R.string.key_torrent_url));
|
||||
mValues.add(gd.torrentUrl);
|
||||
mKeys.add(resources.getString(R.string.favorite_name));
|
||||
mValues.add(gd.favoriteName);
|
||||
}
|
||||
|
||||
protected void onInit() {
|
||||
@@ -156,18 +157,19 @@ public final class GalleryInfoScene extends ToolbarScene implements EasyRecycler
|
||||
View view = inflater.inflate(R.layout.scene_gallery_info, container, false);
|
||||
|
||||
Context context = getContext2();
|
||||
Assert.assertNotNull(context);
|
||||
AssertUtils.assertNotNull(context);
|
||||
|
||||
mRecyclerView = (EasyRecyclerView) ViewUtils.$$(view, R.id.recycler_view);
|
||||
InfoAdapter adapter = new InfoAdapter();
|
||||
mRecyclerView.setAdapter(adapter);
|
||||
mRecyclerView.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false));
|
||||
LinearDividerItemDecoration decoration = new LinearDividerItemDecoration(
|
||||
LinearDividerItemDecoration.VERTICAL, context.getResources().getColor(R.color.divider),
|
||||
LinearDividerItemDecoration.VERTICAL,
|
||||
AttrResources.getAttrColor(context, R.attr.dividerColor),
|
||||
LayoutUtils.dp2pix(context, 1));
|
||||
decoration.setPadding(context.getResources().getDimensionPixelOffset(R.dimen.keyline_margin));
|
||||
mRecyclerView.addItemDecoration(decoration);
|
||||
mRecyclerView.setSelector(Ripple.generateRippleDrawable(context, false));
|
||||
mRecyclerView.setSelector(Ripple.generateRippleDrawable(context, !AttrResources.getAttrBoolean(context, R.attr.isLightTheme)));
|
||||
mRecyclerView.setClipToPadding(false);
|
||||
mRecyclerView.setHasFixedSize(true);
|
||||
mRecyclerView.setOnItemClickListener(this);
|
||||
@@ -197,6 +199,12 @@ public final class GalleryInfoScene extends ToolbarScene implements EasyRecycler
|
||||
if (null != context && 0 != position && null != mValues) {
|
||||
ClipboardManager cmb = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
|
||||
cmb.setPrimaryClip(ClipData.newPlainText(null, mValues.get(position)));
|
||||
|
||||
if (position == 3) {
|
||||
// Save it to avoid detect the gallery
|
||||
Settings.putClipboardTextHashCode(mValues.get(position).hashCode());
|
||||
}
|
||||
|
||||
showTip(R.string.copied_to_clipboard, LENGTH_SHORT);
|
||||
return true;
|
||||
} else {
|
||||
@@ -231,7 +239,7 @@ public final class GalleryInfoScene extends ToolbarScene implements EasyRecycler
|
||||
|
||||
public InfoAdapter() {
|
||||
mInflater = getLayoutInflater2();
|
||||
Assert.assertNotNull(mInflater);
|
||||
AssertUtils.assertNotNull(mInflater);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -49,10 +49,10 @@ import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.github.amlcurran.showcaseview.ShowcaseView;
|
||||
import com.github.amlcurran.showcaseview.SimpleShowcaseEventListener;
|
||||
import com.github.amlcurran.showcaseview.targets.PointTarget;
|
||||
import com.hippo.android.resource.AttrResources;
|
||||
import com.hippo.app.CheckBoxDialogBuilder;
|
||||
import com.hippo.app.EditTextDialogBuilder;
|
||||
import com.hippo.drawable.AddDeleteDrawable;
|
||||
@@ -70,7 +70,9 @@ 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.GalleryDetailUrlParser;
|
||||
import com.hippo.ehviewer.client.parser.GalleryListParser;
|
||||
import com.hippo.ehviewer.client.parser.GalleryPageUrlParser;
|
||||
import com.hippo.ehviewer.dao.QuickSearch;
|
||||
import com.hippo.ehviewer.ui.CommonOperations;
|
||||
import com.hippo.ehviewer.ui.MainActivity;
|
||||
@@ -88,16 +90,15 @@ import com.hippo.widget.ContentLayout;
|
||||
import com.hippo.widget.FabLayout;
|
||||
import com.hippo.widget.SearchBarMover;
|
||||
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 junit.framework.Assert;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public final class GalleryListScene extends BaseScene
|
||||
@@ -171,7 +172,7 @@ public final class GalleryListScene extends BaseScene
|
||||
@Override
|
||||
public void onAnimationEnd(Animator animation) {
|
||||
if (null != mFabLayout) {
|
||||
mFabLayout.getPrimaryFab().setVisibility(View.INVISIBLE);
|
||||
((View) mFabLayout.getPrimaryFab()).setVisibility(View.INVISIBLE);
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -257,7 +258,7 @@ public final class GalleryListScene extends BaseScene
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
Context context = getContext2();
|
||||
Assert.assertNotNull(context);
|
||||
AssertUtils.assertNotNull(context);
|
||||
mClient = EhApplication.getEhClient(context);
|
||||
|
||||
if (savedInstanceState == null) {
|
||||
@@ -304,7 +305,7 @@ public final class GalleryListScene extends BaseScene
|
||||
|
||||
private void setSearchBarHint(Context context, SearchBar searchBar) {
|
||||
Resources resources = context.getResources();
|
||||
Drawable searchImage = DrawableManager.getDrawable(context, R.drawable.v_magnify_x24);
|
||||
Drawable searchImage = DrawableManager.getVectorDrawable(context, R.drawable.v_magnify_x24);
|
||||
SpannableStringBuilder ssb = new SpannableStringBuilder(" ");
|
||||
ssb.append(resources.getString(EhUrl.SITE_EX == Settings.getGallerySite() ?
|
||||
R.string.gallery_list_search_bar_hint_exhentai :
|
||||
@@ -317,6 +318,92 @@ public final class GalleryListScene extends BaseScene
|
||||
searchBar.setEditTextHint(ssb);
|
||||
}
|
||||
|
||||
private void setSearchBarSuggestionProvider(SearchBar searchBar) {
|
||||
searchBar.setSuggestionProvider(text -> {
|
||||
GalleryDetailUrlParser.Result result1 = GalleryDetailUrlParser.parse(text, false);
|
||||
if (result1 != null) {
|
||||
return Collections.singletonList(new GalleryDetailUrlSuggestion(result1.gid, result1.token));
|
||||
}
|
||||
GalleryPageUrlParser.Result result2 = GalleryPageUrlParser.parse(text, false);
|
||||
if (result2 != null) {
|
||||
return Collections.singletonList(new GalleryPageUrlSuggestion(result2.gid, result2.pToken, result2.page));
|
||||
}
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
private abstract class UrlSuggestion extends SearchBar.Suggestion {
|
||||
@Override
|
||||
public CharSequence getText(float textSize) {
|
||||
Drawable bookImage = DrawableManager.getVectorDrawable(getContext2(), R.drawable.v_book_open_x24);
|
||||
SpannableStringBuilder ssb = new SpannableStringBuilder(" ");
|
||||
ssb.append(getResources2().getString(R.string.gallery_list_search_bar_open_gallery));
|
||||
int imageSize = (int) (textSize * 1.25);
|
||||
if (bookImage != null) {
|
||||
bookImage.setBounds(0, 0, imageSize, imageSize);
|
||||
ssb.setSpan(new ImageSpan(bookImage), 1, 2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
}
|
||||
return ssb;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick() {
|
||||
startScene(createAnnouncer());
|
||||
|
||||
if (mState == STATE_SIMPLE_SEARCH) {
|
||||
setState(STATE_NORMAL);
|
||||
} else if (mState == STATE_SEARCH_SHOW_LIST) {
|
||||
setState(STATE_SEARCH);
|
||||
}
|
||||
}
|
||||
|
||||
public abstract Announcer createAnnouncer();
|
||||
|
||||
@Override
|
||||
public void onLongClick() { }
|
||||
}
|
||||
|
||||
private class GalleryDetailUrlSuggestion extends UrlSuggestion {
|
||||
private long mGid;
|
||||
private String mToken;
|
||||
|
||||
private GalleryDetailUrlSuggestion(long gid, String token) {
|
||||
mGid = gid;
|
||||
mToken = token;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Announcer createAnnouncer() {
|
||||
Bundle args = new Bundle();
|
||||
args.putString(GalleryDetailScene.KEY_ACTION, GalleryDetailScene.ACTION_GID_TOKEN);
|
||||
args.putLong(GalleryDetailScene.KEY_GID, mGid);
|
||||
args.putString(GalleryDetailScene.KEY_TOKEN, mToken);
|
||||
return new Announcer(GalleryDetailScene.class).setArgs(args);
|
||||
}
|
||||
}
|
||||
|
||||
private class GalleryPageUrlSuggestion extends UrlSuggestion {
|
||||
private long mGid;
|
||||
private String mPToken;
|
||||
private int mPage;
|
||||
|
||||
private GalleryPageUrlSuggestion(long gid, String pToken, int page) {
|
||||
mGid = gid;
|
||||
mPToken = pToken;
|
||||
mPage = page;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Announcer createAnnouncer() {
|
||||
Bundle args = new Bundle();
|
||||
args.putString(ProgressScene.KEY_ACTION, ProgressScene.ACTION_GALLERY_TOKEN);
|
||||
args.putLong(ProgressScene.KEY_GID, mGid);
|
||||
args.putString(ProgressScene.KEY_PTOKEN, mPToken);
|
||||
args.putInt(ProgressScene.KEY_PAGE, mPage);
|
||||
return new Announcer(ProgressScene.class).setArgs(args);
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static String getSuitableTitleForUrlBuilder(
|
||||
Resources resources, ListUrlBuilder urlBuilder, boolean appName) {
|
||||
@@ -386,7 +473,7 @@ public final class GalleryListScene extends BaseScene
|
||||
View view = inflater.inflate(R.layout.scene_gallery_list, container, false);
|
||||
|
||||
Context context = getContext2();
|
||||
Assert.assertNotNull(context);
|
||||
AssertUtils.assertNotNull(context);
|
||||
Resources resources = context.getResources();
|
||||
|
||||
mHideActionFabSlop = ViewConfiguration.get(context).getScaledTouchSlop();
|
||||
@@ -414,7 +501,7 @@ public final class GalleryListScene extends BaseScene
|
||||
|
||||
mAdapter = new GalleryListAdapter(inflater, resources,
|
||||
mRecyclerView, Settings.getListMode());
|
||||
mRecyclerView.setSelector(Ripple.generateRippleDrawable(context, false));
|
||||
mRecyclerView.setSelector(Ripple.generateRippleDrawable(context, !AttrResources.getAttrBoolean(context, R.attr.isLightTheme)));
|
||||
mRecyclerView.setDrawSelectorOnTop(true);
|
||||
mRecyclerView.hasFixedSize();
|
||||
mRecyclerView.setClipToPadding(false);
|
||||
@@ -427,13 +514,14 @@ public final class GalleryListScene extends BaseScene
|
||||
|
||||
refreshLayout.setHeaderTranslationY(paddingTopSB);
|
||||
|
||||
mLeftDrawable = new DrawerArrowDrawable(context);
|
||||
mRightDrawable = new AddDeleteDrawable(context);
|
||||
mLeftDrawable = new DrawerArrowDrawable(context, AttrResources.getAttrColor(context, R.attr.drawableColorPrimary));
|
||||
mRightDrawable = new AddDeleteDrawable(context, AttrResources.getAttrColor(context, R.attr.drawableColorPrimary));
|
||||
mSearchBar.setLeftDrawable(mLeftDrawable);
|
||||
mSearchBar.setRightDrawable(mRightDrawable);
|
||||
mSearchBar.setHelper(this);
|
||||
mSearchBar.setOnStateChangeListener(this);
|
||||
setSearchBarHint(context, mSearchBar);
|
||||
setSearchBarSuggestionProvider(mSearchBar);
|
||||
|
||||
mSearchLayout.setHelper(this);
|
||||
mSearchLayout.setPadding(mSearchLayout.getPaddingLeft(), mSearchLayout.getPaddingTop() + paddingTopSB,
|
||||
@@ -446,8 +534,7 @@ public final class GalleryListScene extends BaseScene
|
||||
mFabLayout.setOnExpandListener(this);
|
||||
addAboveSnackView(mFabLayout);
|
||||
|
||||
mActionFabDrawable = new AddDeleteDrawable(context);
|
||||
mActionFabDrawable.setColor(resources.getColor(R.color.primary_drawable_dark));
|
||||
mActionFabDrawable = new AddDeleteDrawable(context, resources.getColor(R.color.primary_drawable_dark));
|
||||
mFabLayout.getPrimaryFab().setImageDrawable(mActionFabDrawable);
|
||||
|
||||
mSearchFab.setOnClickListener(this);
|
||||
@@ -632,7 +719,7 @@ public final class GalleryListScene extends BaseScene
|
||||
final ListView listView = (ListView) ViewUtils.$$(view, R.id.list_view);
|
||||
|
||||
Context context = getContext2();
|
||||
Assert.assertNotNull(context);
|
||||
AssertUtils.assertNotNull(context);
|
||||
|
||||
final List<QuickSearch> list = EhDB.getAllQuickSearch();
|
||||
final ArrayAdapter<QuickSearch> adapter = new ArrayAdapter<>(context, R.layout.item_simple_list, list);
|
||||
@@ -745,7 +832,11 @@ public final class GalleryListScene extends BaseScene
|
||||
return false;
|
||||
}
|
||||
|
||||
GalleryInfo gi = mHelper.getDataAt(position);
|
||||
GalleryInfo gi = mHelper.getDataAtEx(position);
|
||||
if (gi == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Bundle args = new Bundle();
|
||||
args.putString(GalleryDetailScene.KEY_ACTION, GalleryDetailScene.ACTION_GALLERY_INFO);
|
||||
args.putParcelable(GalleryDetailScene.KEY_GALLERY_INFO, gi);
|
||||
@@ -859,7 +950,11 @@ public final class GalleryListScene extends BaseScene
|
||||
return false;
|
||||
}
|
||||
|
||||
final GalleryInfo gi = mHelper.getDataAt(position);
|
||||
final GalleryInfo gi = mHelper.getDataAtEx(position);
|
||||
if (gi == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
new AlertDialog.Builder(context)
|
||||
.setTitle(EhUtils.getSuitableTitle(gi))
|
||||
.setItems(R.array.gallery_list_menu_entries, new DialogInterface.OnClickListener() {
|
||||
@@ -1106,36 +1201,11 @@ public final class GalleryListScene extends BaseScene
|
||||
}
|
||||
|
||||
if (mState == STATE_SEARCH || mState == STATE_SEARCH_SHOW_LIST) {
|
||||
if (mSearchLayout.isSpecifyGallery()) {
|
||||
int index = query.indexOf(' ');
|
||||
if (index <= 0 || index >= query.length() - 1) {
|
||||
showTip(R.string.error_invalid_specify_gallery, LENGTH_LONG);
|
||||
return;
|
||||
}
|
||||
|
||||
long gid;
|
||||
String token;
|
||||
try {
|
||||
gid = Long.parseLong(query.substring(0, index));
|
||||
} catch (NumberFormatException e) {
|
||||
showTip(R.string.error_invalid_specify_gallery, LENGTH_LONG);
|
||||
return;
|
||||
}
|
||||
token = query.substring(index + 1);
|
||||
|
||||
Bundle args = new Bundle();
|
||||
args.putString(GalleryDetailScene.KEY_ACTION, GalleryDetailScene.ACTION_GID_TOKEN);
|
||||
args.putLong(GalleryDetailScene.KEY_GID, gid);
|
||||
args.putString(GalleryDetailScene.KEY_TOKEN, token);
|
||||
startScene(new Announcer(GalleryDetailScene.class).setArgs(args));
|
||||
try {
|
||||
mSearchLayout.formatListUrlBuilder(mUrlBuilder, query);
|
||||
} catch (EhException e) {
|
||||
showTip(e.getMessage(), LENGTH_LONG);
|
||||
return;
|
||||
} else {
|
||||
try {
|
||||
mSearchLayout.formatListUrlBuilder(mUrlBuilder, query);
|
||||
} catch (EhException e) {
|
||||
showTip(e.getMessage(), LENGTH_LONG);
|
||||
return;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
mUrlBuilder.reset();
|
||||
@@ -1278,7 +1348,7 @@ public final class GalleryListScene extends BaseScene
|
||||
@Nullable
|
||||
@Override
|
||||
public GalleryInfo getDataAt(int position) {
|
||||
return null != mHelper ? mHelper.getDataAt(position) : null;
|
||||
return null != mHelper ? mHelper.getDataAtEx(position) : null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -53,11 +53,10 @@ import com.hippo.widget.ContentLayout;
|
||||
import com.hippo.widget.LoadImageView;
|
||||
import com.hippo.widget.Slider;
|
||||
import com.hippo.widget.recyclerview.AutoGridLayoutManager;
|
||||
import com.hippo.yorozuya.AssertUtils;
|
||||
import com.hippo.yorozuya.LayoutUtils;
|
||||
import com.hippo.yorozuya.ViewUtils;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Locale;
|
||||
|
||||
@@ -91,7 +90,7 @@ public class GalleryPreviewsScene extends ToolbarScene implements EasyRecyclerVi
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
Context context = getContext2();
|
||||
Assert.assertNotNull(context);
|
||||
AssertUtils.assertNotNull(context);
|
||||
mClient = EhApplication.getEhClient(context);
|
||||
if (savedInstanceState == null) {
|
||||
onInit();
|
||||
@@ -138,7 +137,7 @@ public class GalleryPreviewsScene extends ToolbarScene implements EasyRecyclerVi
|
||||
mRecyclerView = contentLayout.getRecyclerView();
|
||||
|
||||
Context context = getContext2();
|
||||
Assert.assertNotNull(context);
|
||||
AssertUtils.assertNotNull(context);
|
||||
Resources resources = context.getResources();
|
||||
|
||||
mAdapter = new GalleryPreviewAdapter();
|
||||
@@ -232,12 +231,14 @@ public class GalleryPreviewsScene extends ToolbarScene implements EasyRecyclerVi
|
||||
public boolean onItemClick(EasyRecyclerView parent, View view, int position, long id) {
|
||||
Context context = getContext2();
|
||||
if (null != context && null != mHelper && null != mGalleryInfo) {
|
||||
GalleryPreview p = mHelper.getDataAt(position);
|
||||
Intent intent = new Intent(context, GalleryActivity.class);
|
||||
intent.setAction(GalleryActivity.ACTION_EH);
|
||||
intent.putExtra(GalleryActivity.KEY_GALLERY_INFO, mGalleryInfo);
|
||||
intent.putExtra(GalleryActivity.KEY_PAGE, p.getPosition());
|
||||
startActivity(intent);
|
||||
GalleryPreview p = mHelper.getDataAtEx(position);
|
||||
if (p != null) {
|
||||
Intent intent = new Intent(context, GalleryActivity.class);
|
||||
intent.setAction(GalleryActivity.ACTION_EH);
|
||||
intent.putExtra(GalleryActivity.KEY_GALLERY_INFO, mGalleryInfo);
|
||||
intent.putExtra(GalleryActivity.KEY_PAGE, p.getPosition());
|
||||
startActivity(intent);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -261,7 +262,7 @@ public class GalleryPreviewsScene extends ToolbarScene implements EasyRecyclerVi
|
||||
|
||||
public GalleryPreviewAdapter() {
|
||||
mInflater = getLayoutInflater2();
|
||||
Assert.assertNotNull(mInflater);
|
||||
AssertUtils.assertNotNull(mInflater);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -273,9 +274,11 @@ public class GalleryPreviewsScene extends ToolbarScene implements EasyRecyclerVi
|
||||
@SuppressLint("SetTextI18n")
|
||||
public void onBindViewHolder(GalleryPreviewHolder holder, int position) {
|
||||
if (null != mHelper) {
|
||||
GalleryPreview preview = mHelper.getDataAt(position);
|
||||
preview.load(holder.image);
|
||||
holder.text.setText(Integer.toString(preview.getPosition() + 1));
|
||||
GalleryPreview preview = mHelper.getDataAtEx(position);
|
||||
if (preview != null) {
|
||||
preview.load(holder.image);
|
||||
holder.text.setText(Integer.toString(preview.getPosition() + 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -31,7 +31,6 @@ import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.h6ah4i.android.widget.advrecyclerview.animator.GeneralItemAnimator;
|
||||
import com.h6ah4i.android.widget.advrecyclerview.animator.SwipeDismissItemAnimator;
|
||||
import com.h6ah4i.android.widget.advrecyclerview.swipeable.RecyclerViewSwipeManager;
|
||||
@@ -42,6 +41,7 @@ import com.h6ah4i.android.widget.advrecyclerview.swipeable.action.SwipeResultAct
|
||||
import com.h6ah4i.android.widget.advrecyclerview.swipeable.action.SwipeResultActionRemoveItem;
|
||||
import com.h6ah4i.android.widget.advrecyclerview.touchguard.RecyclerViewTouchActionGuardManager;
|
||||
import com.h6ah4i.android.widget.advrecyclerview.utils.AbstractSwipeableItemViewHolder;
|
||||
import com.hippo.android.resource.AttrResources;
|
||||
import com.hippo.easyrecyclerview.EasyRecyclerView;
|
||||
import com.hippo.easyrecyclerview.FastScroller;
|
||||
import com.hippo.easyrecyclerview.HandlerDrawable;
|
||||
@@ -64,11 +64,8 @@ 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.ResourcesUtils;
|
||||
import com.hippo.yorozuya.AssertUtils;
|
||||
import com.hippo.yorozuya.ViewUtils;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import de.greenrobot.dao.query.LazyList;
|
||||
|
||||
public class HistoryScene extends ToolbarScene
|
||||
@@ -104,10 +101,10 @@ public class HistoryScene extends ToolbarScene
|
||||
mViewTransition = new ViewTransition(content, tip);
|
||||
|
||||
Context context = getContext2();
|
||||
Assert.assertNotNull(context);
|
||||
AssertUtils.assertNotNull(context);
|
||||
Resources resources = context.getResources();
|
||||
|
||||
Drawable drawable = DrawableManager.getDrawable(context, R.drawable.big_history);
|
||||
Drawable drawable = DrawableManager.getVectorDrawable(context, R.drawable.big_history);
|
||||
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
|
||||
tip.setCompoundDrawables(null, drawable, null, null);
|
||||
|
||||
@@ -127,7 +124,7 @@ public class HistoryScene extends ToolbarScene
|
||||
layoutManager.setColumnSize(resources.getDimensionPixelOffset(Settings.getDetailSizeResId()));
|
||||
layoutManager.setStrategy(AutoStaggeredGridLayoutManager.STRATEGY_MIN_SIZE);
|
||||
mRecyclerView.setLayoutManager(layoutManager);
|
||||
mRecyclerView.setSelector(Ripple.generateRippleDrawable(context, false));
|
||||
mRecyclerView.setSelector(Ripple.generateRippleDrawable(context, !AttrResources.getAttrBoolean(context, R.attr.isLightTheme)));
|
||||
mRecyclerView.setDrawSelectorOnTop(true);
|
||||
mRecyclerView.hasFixedSize();
|
||||
mRecyclerView.setClipToPadding(false);
|
||||
@@ -144,7 +141,7 @@ public class HistoryScene extends ToolbarScene
|
||||
|
||||
fastScroller.attachToRecyclerView(mRecyclerView);
|
||||
HandlerDrawable handlerDrawable = new HandlerDrawable();
|
||||
handlerDrawable.setColor(ResourcesUtils.getAttrColor(context, R.attr.colorAccent));
|
||||
handlerDrawable.setColor(AttrResources.getAttrColor(context, R.attr.widgetColorThemeAccent));
|
||||
fastScroller.setHandlerDrawable(handlerDrawable);
|
||||
|
||||
updateLazyList();
|
||||
@@ -293,6 +290,7 @@ public class HistoryScene extends ToolbarScene
|
||||
|
||||
private class HistoryHolder extends AbstractSwipeableItemViewHolder {
|
||||
|
||||
public final View card;
|
||||
public final LoadImageView thumb;
|
||||
public final TextView title;
|
||||
public final TextView uploader;
|
||||
@@ -304,6 +302,7 @@ public class HistoryScene extends ToolbarScene
|
||||
public HistoryHolder(View itemView) {
|
||||
super(itemView);
|
||||
|
||||
card = itemView.findViewById(R.id.card);
|
||||
thumb = (LoadImageView) itemView.findViewById(R.id.thumb);
|
||||
title = (TextView) itemView.findViewById(R.id.title);
|
||||
uploader = (TextView) itemView.findViewById(R.id.uploader);
|
||||
@@ -315,7 +314,7 @@ public class HistoryScene extends ToolbarScene
|
||||
|
||||
@Override
|
||||
public View getSwipeableContainerView() {
|
||||
return itemView;
|
||||
return card;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -323,9 +322,16 @@ public class HistoryScene extends ToolbarScene
|
||||
implements SwipeableItemAdapter<HistoryHolder> {
|
||||
|
||||
private final LayoutInflater mInflater;
|
||||
private final int mListThumbWidth;
|
||||
private final int mListThumbHeight;
|
||||
|
||||
public HistoryAdapter() {
|
||||
mInflater = getLayoutInflater2();
|
||||
|
||||
View calculator = mInflater.inflate(R.layout.item_gallery_list_thumb_height, null);
|
||||
ViewUtils.measureView(calculator, 1024, ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||
mListThumbHeight = calculator.getMeasuredHeight();
|
||||
mListThumbWidth = mListThumbHeight * 2 / 3;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -339,7 +345,14 @@ public class HistoryScene extends ToolbarScene
|
||||
|
||||
@Override
|
||||
public HistoryHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
return new HistoryHolder(mInflater.inflate(R.layout.item_gallery_list, parent, false));
|
||||
HistoryHolder holder = new HistoryHolder(mInflater.inflate(R.layout.item_history, parent, false));
|
||||
|
||||
ViewGroup.LayoutParams lp = holder.thumb.getLayoutParams();
|
||||
lp.width = mListThumbWidth;
|
||||
lp.height = mListThumbHeight;
|
||||
holder.thumb.setLayoutParams(lp);
|
||||
|
||||
return holder;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -376,9 +389,12 @@ public class HistoryScene extends ToolbarScene
|
||||
|
||||
@Override
|
||||
public int onGetSwipeReactionType(HistoryHolder holder, int position, int x, int y) {
|
||||
return SwipeableItemConstants.REACTION_CAN_SWIPE_BOTH_H;
|
||||
return SwipeableItemConstants.REACTION_CAN_SWIPE_LEFT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSwipeItemStarted(HistoryHolder holder, int position) { }
|
||||
|
||||
@Override
|
||||
public void onSetSwipeBackground(HistoryHolder holder, int position, int type) {}
|
||||
|
||||
@@ -386,8 +402,8 @@ public class HistoryScene extends ToolbarScene
|
||||
public SwipeResultAction onSwipeItem(HistoryHolder holder, int position, int result) {
|
||||
switch (result) {
|
||||
case SwipeableItemConstants.RESULT_SWIPED_LEFT:
|
||||
case SwipeableItemConstants.RESULT_SWIPED_RIGHT:
|
||||
return new SwipeResultActionClear(position);
|
||||
case SwipeableItemConstants.RESULT_SWIPED_RIGHT:
|
||||
case SwipeableItemConstants.RESULT_CANCELED:
|
||||
default:
|
||||
return new SwipeResultActionDefault();
|
||||
|
||||
@@ -25,7 +25,6 @@ import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.hippo.ehviewer.EhApplication;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.client.EhClient;
|
||||
@@ -36,10 +35,9 @@ import com.hippo.scene.SceneFragment;
|
||||
import com.hippo.util.DrawableManager;
|
||||
import com.hippo.util.ExceptionUtils;
|
||||
import com.hippo.view.ViewTransition;
|
||||
import com.hippo.yorozuya.AssertUtils;
|
||||
import com.hippo.yorozuya.ViewUtils;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
/**
|
||||
* Only show a progress with jobs in background
|
||||
*/
|
||||
@@ -170,9 +168,9 @@ public final class ProgressScene extends BaseScene implements View.OnClickListen
|
||||
mTip = (TextView) ViewUtils.$$(view, R.id.tip);
|
||||
|
||||
Context context = getContext2();
|
||||
Assert.assertNotNull(context);
|
||||
AssertUtils.assertNotNull(context);
|
||||
|
||||
Drawable drawable = DrawableManager.getDrawable(context, R.drawable.big_weird_face);
|
||||
Drawable drawable = DrawableManager.getVectorDrawable(context, R.drawable.big_sad_pandroid);
|
||||
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
|
||||
mTip.setCompoundDrawables(null, drawable, null, null);
|
||||
mTip.setOnClickListener(this);
|
||||
|
||||
@@ -29,30 +29,21 @@ import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.h6ah4i.android.widget.advrecyclerview.animator.GeneralItemAnimator;
|
||||
import com.h6ah4i.android.widget.advrecyclerview.animator.SwipeDismissItemAnimator;
|
||||
import com.h6ah4i.android.widget.advrecyclerview.draggable.DraggableItemAdapter;
|
||||
import com.h6ah4i.android.widget.advrecyclerview.draggable.ItemDraggableRange;
|
||||
import com.h6ah4i.android.widget.advrecyclerview.draggable.RecyclerViewDragDropManager;
|
||||
import com.h6ah4i.android.widget.advrecyclerview.swipeable.RecyclerViewSwipeManager;
|
||||
import com.h6ah4i.android.widget.advrecyclerview.swipeable.SwipeableItemAdapter;
|
||||
import com.h6ah4i.android.widget.advrecyclerview.swipeable.SwipeableItemConstants;
|
||||
import com.h6ah4i.android.widget.advrecyclerview.swipeable.action.SwipeResultAction;
|
||||
import com.h6ah4i.android.widget.advrecyclerview.swipeable.action.SwipeResultActionDefault;
|
||||
import com.h6ah4i.android.widget.advrecyclerview.swipeable.action.SwipeResultActionMoveToSwipedDirection;
|
||||
import com.h6ah4i.android.widget.advrecyclerview.touchguard.RecyclerViewTouchActionGuardManager;
|
||||
import com.h6ah4i.android.widget.advrecyclerview.utils.AbstractDraggableSwipeableItemViewHolder;
|
||||
import com.h6ah4i.android.widget.advrecyclerview.utils.AbstractDraggableItemViewHolder;
|
||||
import com.hippo.easyrecyclerview.EasyRecyclerView;
|
||||
import com.hippo.ehviewer.EhDB;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.dao.QuickSearch;
|
||||
import com.hippo.util.DrawableManager;
|
||||
import com.hippo.view.ViewTransition;
|
||||
import com.hippo.yorozuya.AssertUtils;
|
||||
import com.hippo.yorozuya.ViewUtils;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public final class QuickSearchScene extends ToolbarScene {
|
||||
@@ -97,9 +88,9 @@ public final class QuickSearchScene extends ToolbarScene {
|
||||
mViewTransition = new ViewTransition(mRecyclerView, tip);
|
||||
|
||||
Context context = getContext2();
|
||||
Assert.assertNotNull(context);
|
||||
AssertUtils.assertNotNull(context);
|
||||
|
||||
Drawable drawable = DrawableManager.getDrawable(context, R.drawable.big_search);
|
||||
Drawable drawable = DrawableManager.getVectorDrawable(context, R.drawable.big_search);
|
||||
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
|
||||
tip.setCompoundDrawables(null, drawable, null, null);
|
||||
tip.setText(R.string.no_quick_search);
|
||||
@@ -113,11 +104,9 @@ public final class QuickSearchScene extends ToolbarScene {
|
||||
dragDropManager.setDraggingItemShadowDrawable(
|
||||
(NinePatchDrawable) context.getResources().getDrawable(R.drawable.shadow_8dp));
|
||||
// swipe manager
|
||||
RecyclerViewSwipeManager swipeManager = new RecyclerViewSwipeManager();
|
||||
RecyclerView.Adapter adapter = new QuickSearchAdapter();
|
||||
adapter.setHasStableIds(true);
|
||||
adapter = dragDropManager.createWrappedAdapter(adapter); // wrap for dragging
|
||||
adapter = swipeManager.createWrappedAdapter(adapter); // wrap for swiping
|
||||
mAdapter = adapter;
|
||||
final GeneralItemAnimator animator = new SwipeDismissItemAnimator();
|
||||
animator.setSupportsChangeAnimations(false);
|
||||
@@ -126,7 +115,6 @@ public final class QuickSearchScene extends ToolbarScene {
|
||||
mRecyclerView.setAdapter(adapter);
|
||||
mRecyclerView.setItemAnimator(animator);
|
||||
guardManager.attachRecyclerView(mRecyclerView);
|
||||
swipeManager.attachRecyclerView(mRecyclerView);
|
||||
dragDropManager.attachRecyclerView(mRecyclerView);
|
||||
|
||||
updateView();
|
||||
@@ -151,7 +139,6 @@ public final class QuickSearchScene extends ToolbarScene {
|
||||
}
|
||||
|
||||
mViewTransition = null;
|
||||
mAdapter = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -169,41 +156,66 @@ public final class QuickSearchScene extends ToolbarScene {
|
||||
}
|
||||
}
|
||||
|
||||
private class QuickSearchHolder extends AbstractDraggableSwipeableItemViewHolder {
|
||||
private class QuickSearchHolder extends AbstractDraggableItemViewHolder implements View.OnClickListener {
|
||||
|
||||
public final View swipeHandler;
|
||||
public final TextView label;
|
||||
public final View dragHandler;
|
||||
public final View delete;
|
||||
|
||||
public QuickSearchHolder(View itemView) {
|
||||
super(itemView);
|
||||
|
||||
swipeHandler = ViewUtils.$$(itemView, R.id.swipe_handler);
|
||||
label = (TextView) ViewUtils.$$(itemView, R.id.label);
|
||||
dragHandler = ViewUtils.$$(itemView, R.id.drag_handler);
|
||||
delete = ViewUtils.$$(itemView, R.id.delete);
|
||||
|
||||
delete.setOnClickListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getSwipeableContainerView() {
|
||||
return swipeHandler;
|
||||
public void onClick(View v) {
|
||||
int position = getAdapterPosition();
|
||||
Context context = getContext2();
|
||||
if (position == RecyclerView.NO_POSITION || mQuickSearchList == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final QuickSearch quickSearch = mQuickSearchList.get(position);
|
||||
new AlertDialog.Builder(context)
|
||||
.setTitle(R.string.delete_quick_search_title)
|
||||
.setMessage(getString(R.string.delete_quick_search_message, quickSearch.name))
|
||||
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
EhDB.deleteQuickSearch(quickSearch);
|
||||
mQuickSearchList.remove(position);
|
||||
}
|
||||
})
|
||||
.setOnDismissListener(new DialogInterface.OnDismissListener() {
|
||||
@Override
|
||||
public void onDismiss(DialogInterface dialog) {
|
||||
if (null != mAdapter) {
|
||||
mAdapter.notifyDataSetChanged();
|
||||
}
|
||||
updateView();
|
||||
}
|
||||
}).show();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private class QuickSearchAdapter extends RecyclerView.Adapter<QuickSearchHolder>
|
||||
implements DraggableItemAdapter<QuickSearchHolder>,
|
||||
SwipeableItemAdapter<QuickSearchHolder> {
|
||||
implements DraggableItemAdapter<QuickSearchHolder> {
|
||||
|
||||
private final LayoutInflater mInflater;
|
||||
|
||||
public QuickSearchAdapter() {
|
||||
mInflater = getLayoutInflater2();
|
||||
Assert.assertNotNull(mInflater);
|
||||
AssertUtils.assertNotNull(mInflater);
|
||||
}
|
||||
|
||||
@Override
|
||||
public QuickSearchHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
return new QuickSearchHolder(mInflater.inflate(R.layout.item_label_list, parent, false));
|
||||
return new QuickSearchHolder(mInflater.inflate(R.layout.item_quick_search, parent, false));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -211,7 +223,6 @@ public final class QuickSearchScene extends ToolbarScene {
|
||||
if (mQuickSearchList != null) {
|
||||
holder.label.setText(mQuickSearchList.get(position).name);
|
||||
}
|
||||
holder.setSwipeItemHorizontalSlideAmount(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -255,71 +266,9 @@ public final class QuickSearchScene extends ToolbarScene {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int onGetSwipeReactionType(QuickSearchHolder holder, int position, int x, int y) {
|
||||
if (ViewUtils.isViewUnder(holder.getSwipeableContainerView(), x, y, 0)) {
|
||||
return SwipeableItemConstants.REACTION_CAN_SWIPE_LEFT;
|
||||
} else {
|
||||
return SwipeableItemConstants.REACTION_CAN_NOT_SWIPE_BOTH_H;
|
||||
}
|
||||
}
|
||||
public void onItemDragStarted(int position) { }
|
||||
|
||||
@Override
|
||||
public void onSetSwipeBackground(QuickSearchHolder holder, int position, int type) {}
|
||||
|
||||
@Override
|
||||
public SwipeResultAction onSwipeItem(QuickSearchHolder holder, int position, int result) {
|
||||
switch (result) {
|
||||
// swipe left --- pin
|
||||
case SwipeableItemConstants.RESULT_SWIPED_LEFT:
|
||||
return new SwipeLeftResultAction(position);
|
||||
// other --- do nothing
|
||||
case SwipeableItemConstants.RESULT_SWIPED_RIGHT:
|
||||
case SwipeableItemConstants.RESULT_CANCELED:
|
||||
default:
|
||||
return new SwipeResultActionDefault();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class SwipeLeftResultAction extends SwipeResultActionMoveToSwipedDirection {
|
||||
|
||||
private final int mPosition;
|
||||
|
||||
public SwipeLeftResultAction(int position) {
|
||||
mPosition = position;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPerformAction() {
|
||||
super.onPerformAction();
|
||||
|
||||
Context context = getContext2();
|
||||
final List<QuickSearch> quickSearchList = mQuickSearchList;
|
||||
if (null == context || null == quickSearchList || mPosition < 0 || mPosition >= quickSearchList.size()) {
|
||||
return;
|
||||
}
|
||||
|
||||
final QuickSearch quickSearch = quickSearchList.get(mPosition);
|
||||
|
||||
new AlertDialog.Builder(context)
|
||||
.setTitle(R.string.delete_quick_search_title)
|
||||
.setMessage(getString(R.string.delete_quick_search_message, quickSearch.name))
|
||||
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
EhDB.deleteQuickSearch(quickSearch);
|
||||
quickSearchList.remove(mPosition);
|
||||
}
|
||||
})
|
||||
.setOnDismissListener(new DialogInterface.OnDismissListener() {
|
||||
@Override
|
||||
public void onDismiss(DialogInterface dialog) {
|
||||
if (null != mAdapter) {
|
||||
mAdapter.notifyDataSetChanged();
|
||||
}
|
||||
updateView();
|
||||
}
|
||||
}).show();
|
||||
}
|
||||
public void onItemDragFinished(int fromPosition, int toPosition, boolean result) { }
|
||||
}
|
||||
}
|
||||
@@ -28,18 +28,16 @@ import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.Settings;
|
||||
import com.hippo.ehviewer.ui.MainActivity;
|
||||
import com.hippo.ehviewer.ui.SetSecurityActivity;
|
||||
import com.hippo.hardware.ShakeDetector;
|
||||
import com.hippo.widget.lockpattern.LockPatternUtils;
|
||||
import com.hippo.widget.lockpattern.LockPatternView;
|
||||
import com.hippo.yorozuya.AssertUtils;
|
||||
import com.hippo.yorozuya.ObjectUtils;
|
||||
import com.hippo.yorozuya.ViewUtils;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class SecurityScene extends SolidScene implements
|
||||
@@ -58,6 +56,7 @@ public class SecurityScene extends SolidScene implements
|
||||
private SensorManager mSensorManager;
|
||||
private Sensor mAccelerometer;
|
||||
private ShakeDetector mShakeDetector;
|
||||
@Nullable
|
||||
private FingerprintManager mFingerprintManager;
|
||||
|
||||
private CancellationSignal mFingerprintCancellationSignal;
|
||||
@@ -74,7 +73,7 @@ public class SecurityScene extends SolidScene implements
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
Context context = getContext2();
|
||||
Assert.assertNotNull(context);
|
||||
AssertUtils.assertNotNull(context);
|
||||
mSensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
|
||||
if (null != mSensorManager) {
|
||||
mAccelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
|
||||
@@ -130,7 +129,7 @@ public class SecurityScene extends SolidScene implements
|
||||
@Override
|
||||
public void onAuthenticationSucceeded(
|
||||
FingerprintManager.AuthenticationResult result) {
|
||||
mFingerprintIcon.setImageResource(R.drawable.ic_fingerprint_success);
|
||||
mFingerprintIcon.setImageResource(R.drawable.fingerprint_success);
|
||||
mFingerprintIcon.postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
@@ -237,8 +236,7 @@ public class SecurityScene extends SolidScene implements
|
||||
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
|
||||
&& Settings.getEnableFingerprint()
|
||||
&& mFingerprintManager != null
|
||||
&& mFingerprintManager.isHardwareDetected()
|
||||
&& mFingerprintManager.hasEnrolledFingerprints();
|
||||
&& SetSecurityActivity.hasEnrolledFingerprints(mFingerprintManager);
|
||||
}
|
||||
|
||||
private Runnable mResetFingerprintRunnable = new Runnable() {
|
||||
@@ -251,7 +249,7 @@ public class SecurityScene extends SolidScene implements
|
||||
|
||||
private void fingerprintError(boolean unrecoverable) {
|
||||
// Do not decrease mRetryTimes here since Android system will handle it :)
|
||||
mFingerprintIcon.setImageResource(R.drawable.ic_fingerprint_error);
|
||||
mFingerprintIcon.setImageResource(R.drawable.fingerprint_error);
|
||||
mFingerprintIcon.removeCallbacks(mResetFingerprintRunnable);
|
||||
if (unrecoverable) {
|
||||
mFingerprintIcon.postDelayed(new Runnable() {
|
||||
|
||||
@@ -29,7 +29,6 @@ import android.view.ViewGroup;
|
||||
import android.view.inputmethod.EditorInfo;
|
||||
import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.hippo.ehviewer.EhApplication;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.Settings;
|
||||
@@ -44,11 +43,10 @@ import com.hippo.ehviewer.widget.RecaptchaView;
|
||||
import com.hippo.scene.Announcer;
|
||||
import com.hippo.scene.SceneFragment;
|
||||
import com.hippo.util.ExceptionUtils;
|
||||
import com.hippo.yorozuya.AssertUtils;
|
||||
import com.hippo.yorozuya.IntIdGenerator;
|
||||
import com.hippo.yorozuya.ViewUtils;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
public final class SignInScene extends SolidScene implements EditText.OnEditorActionListener,
|
||||
View.OnClickListener {
|
||||
|
||||
@@ -125,10 +123,10 @@ public final class SignInScene extends SolidScene implements EditText.OnEditorAc
|
||||
mProgress = ViewUtils.$$(view, R.id.progress);
|
||||
mUsernameLayout = (TextInputLayout) ViewUtils.$$(loginForm, R.id.username_layout);
|
||||
mUsername = mUsernameLayout.getEditText();
|
||||
Assert.assertNotNull(mUsername);
|
||||
AssertUtils.assertNotNull(mUsername);
|
||||
mPasswordLayout = (TextInputLayout) ViewUtils.$$(loginForm, R.id.password_layout);
|
||||
mPassword = mPasswordLayout.getEditText();
|
||||
Assert.assertNotNull(mPassword);
|
||||
AssertUtils.assertNotNull(mPassword);
|
||||
mRecaptcha = (EditText) ViewUtils.$$(loginForm, R.id.recaptcha);
|
||||
mRecaptchaView = (RecaptchaView) ViewUtils.$$(loginForm, R.id.recaptcha_image);
|
||||
mRegister = ViewUtils.$$(loginForm, R.id.register);
|
||||
@@ -150,7 +148,7 @@ public final class SignInScene extends SolidScene implements EditText.OnEditorAc
|
||||
mSkipSigningIn.setOnClickListener(this);
|
||||
|
||||
Context context = getContext2();
|
||||
Assert.assertNotNull(context);
|
||||
AssertUtils.assertNotNull(context);
|
||||
EhApplication application = (EhApplication) context.getApplicationContext();
|
||||
if (application.containGlobalStuff(mRequestId)) {
|
||||
mSigningIn = true;
|
||||
|
||||
@@ -18,8 +18,6 @@ package com.hippo.ehviewer.ui.scene;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
|
||||
import com.hippo.ehviewer.Crash;
|
||||
import com.hippo.ehviewer.Settings;
|
||||
import com.hippo.ehviewer.client.EhUtils;
|
||||
import com.hippo.scene.Announcer;
|
||||
@@ -34,9 +32,8 @@ public class SolidScene extends BaseScene {
|
||||
public static final int CHECK_STEP_SECURITY = 0;
|
||||
public static final int CHECK_STEP_WARNING = 1;
|
||||
public static final int CHECK_STEP_ANALYTICS = 2;
|
||||
public static final int CHECK_STEP_CRASH = 3;
|
||||
public static final int CHECK_STEP_SIGN_IN = 4;
|
||||
public static final int CHECK_STEP_SELECT_SITE = 5;
|
||||
public static final int CHECK_STEP_SIGN_IN = 3;
|
||||
public static final int CHECK_STEP_SELECT_SITE = 4;
|
||||
|
||||
public static final String KEY_TARGET_SCENE = "target_scene";
|
||||
public static final String KEY_TARGET_ARGS = "target_args";
|
||||
@@ -54,11 +51,6 @@ public class SolidScene extends BaseScene {
|
||||
break;
|
||||
}
|
||||
case CHECK_STEP_ANALYTICS:
|
||||
if (Crash.hasCrashFile()) {
|
||||
startScene(new Announcer(CrashScene.class).setArgs(args));
|
||||
break;
|
||||
}
|
||||
case CHECK_STEP_CRASH:
|
||||
if (EhUtils.needSignedIn(getContext2())) {
|
||||
startScene(new Announcer(SignInScene.class).setArgs(args));
|
||||
break;
|
||||
|
||||
@@ -32,10 +32,10 @@ import com.hippo.ehviewer.EhApplication;
|
||||
import com.hippo.ehviewer.client.EhCookieStore;
|
||||
import com.hippo.ehviewer.client.EhUrl;
|
||||
import com.hippo.ehviewer.client.EhUtils;
|
||||
import com.hippo.yorozuya.AssertUtils;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import junit.framework.Assert;
|
||||
import okhttp3.Cookie;
|
||||
import okhttp3.HttpUrl;
|
||||
|
||||
@@ -59,7 +59,7 @@ public class WebViewSignInScene extends SolidScene {
|
||||
public View onCreateView2(LayoutInflater inflater,
|
||||
@Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
Context context = getContext2();
|
||||
Assert.assertNotNull(context);
|
||||
AssertUtils.assertNotNull(context);
|
||||
|
||||
EhUtils.signOut(context);
|
||||
|
||||
|
||||
@@ -21,15 +21,15 @@ import android.os.Bundle;
|
||||
import android.os.Parcelable;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TableLayout;
|
||||
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.client.EhConfig;
|
||||
import com.hippo.widget.CheckTextView;
|
||||
import com.hippo.yorozuya.NumberUtils;
|
||||
|
||||
public class CategoryTable extends TableLayout {
|
||||
public class CategoryTable extends TableLayout implements View.OnLongClickListener {
|
||||
|
||||
private static final String STATE_KEY_SUPER = "super";
|
||||
private static final String STATE_KEY_CATEGORY = "category";
|
||||
@@ -45,6 +45,8 @@ public class CategoryTable extends TableLayout {
|
||||
private CheckTextView mAsianPorn;
|
||||
private CheckTextView mMisc;
|
||||
|
||||
private CheckTextView[] mOptions;
|
||||
|
||||
public CategoryTable(Context context) {
|
||||
super(context);
|
||||
init();
|
||||
@@ -78,6 +80,29 @@ public class CategoryTable extends TableLayout {
|
||||
ViewGroup row4 = (ViewGroup) getChildAt(4);
|
||||
mAsianPorn = (CheckTextView) row4.getChildAt(0);
|
||||
mMisc = (CheckTextView) row4.getChildAt(1);
|
||||
|
||||
mOptions = new CheckTextView[] {
|
||||
mDoujinshi, mManga, mArtistCG, mGameCG, mWestern,
|
||||
mNonH, mImageSets, mCosplay, mAsianPorn, mMisc
|
||||
};
|
||||
|
||||
for (CheckTextView option : mOptions) {
|
||||
option.setOnLongClickListener(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onLongClick(View v) {
|
||||
if (v instanceof CheckTextView) {
|
||||
boolean checked = ((CheckTextView) v).isChecked();
|
||||
for (CheckTextView option : mOptions) {
|
||||
if (option != v) {
|
||||
option.setChecked(!checked, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -21,12 +21,11 @@ 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 android.widget.LinearLayout;
|
||||
import com.hippo.drawerlayout.DrawerLayoutChild;
|
||||
|
||||
public class EhNavigationView extends NavigationView implements DrawerLayoutChild {
|
||||
public class EhNavigationView extends LinearLayout implements DrawerLayoutChild {
|
||||
|
||||
private static final int SCRIM_COLOR = 0x44000000;
|
||||
private static final boolean DRAW_SCRIM = Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP;
|
||||
|
||||
@@ -18,15 +18,13 @@ package com.hippo.ehviewer.widget;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Paint;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.hippo.android.resource.AttrResources;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.Settings;
|
||||
import com.hippo.yorozuya.ViewUtils;
|
||||
@@ -60,9 +58,9 @@ public class GalleryGuideView extends ViewGroup implements View.OnClickListener
|
||||
}
|
||||
|
||||
private void init(Context context) {
|
||||
mBgColor = ContextCompat.getColor(context, R.color.guide_bg);
|
||||
mBgColor = AttrResources.getAttrColor(context, R.attr.guideBackgroundColor);
|
||||
mPaint = new Paint();
|
||||
mPaint.setColor(Color.WHITE);
|
||||
mPaint.setColor(AttrResources.getAttrColor(context, R.attr.guideTitleColor));
|
||||
mPaint.setStyle(Paint.Style.STROKE);
|
||||
mPaint.setStrokeWidth(context.getResources().getDimension(R.dimen.gallery_guide_divider_width));
|
||||
setOnClickListener(this);
|
||||
|
||||
@@ -26,6 +26,7 @@ import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Parcelable;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v7.widget.CardView;
|
||||
import android.text.Editable;
|
||||
import android.text.TextUtils;
|
||||
import android.text.TextWatcher;
|
||||
@@ -37,24 +38,20 @@ import android.view.ViewGroup;
|
||||
import android.view.inputmethod.EditorInfo;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.view.ViewTransition;
|
||||
import com.hippo.yorozuya.AnimationUtils;
|
||||
import com.hippo.yorozuya.MathUtils;
|
||||
import com.hippo.yorozuya.SimpleAnimatorListener;
|
||||
import com.hippo.yorozuya.ViewUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class SearchBar extends FrameLayout implements View.OnClickListener,
|
||||
public class SearchBar extends CardView implements View.OnClickListener,
|
||||
TextView.OnEditorActionListener, TextWatcher,
|
||||
SearchEditText.SearchEditTextListener {
|
||||
|
||||
@@ -79,17 +76,19 @@ public class SearchBar extends FrameLayout implements View.OnClickListener,
|
||||
private TextView mTitleTextView;
|
||||
private ImageView mActionButton;
|
||||
private SearchEditText mEditText;
|
||||
private ListView mListView;
|
||||
private View mListContainer;
|
||||
private View mListHeader;
|
||||
|
||||
private ViewTransition mViewTransition;
|
||||
|
||||
private SearchDatabase mSearchDatabase;
|
||||
private List<String> mSuggestionList;
|
||||
private ArrayAdapter mSuggestionAdapter;
|
||||
private List<Suggestion> mSuggestionList;
|
||||
private SuggestionAdapter mSuggestionAdapter;
|
||||
|
||||
private Helper mHelper;
|
||||
private OnStateChangeListener mOnStateChangeListener;
|
||||
private SuggestionProvider mSuggestionProvider;
|
||||
|
||||
private boolean mAllowEmptySearch = true;
|
||||
|
||||
@@ -111,8 +110,6 @@ public class SearchBar extends FrameLayout implements View.OnClickListener,
|
||||
}
|
||||
|
||||
private void init(Context context) {
|
||||
setBackgroundResource(R.drawable.card_white_no_padding_2dp);
|
||||
|
||||
mSearchDatabase = SearchDatabase.getInstance(getContext());
|
||||
|
||||
LayoutInflater inflater = LayoutInflater.from(context);
|
||||
@@ -122,7 +119,7 @@ public class SearchBar extends FrameLayout implements View.OnClickListener,
|
||||
mActionButton = (ImageView) ViewUtils.$$(this, R.id.search_action);
|
||||
mEditText = (SearchEditText) ViewUtils.$$(this, R.id.search_edit_text);
|
||||
mListContainer = ViewUtils.$$(this, R.id.list_container);
|
||||
ListView list = (ListView) ViewUtils.$$(mListContainer, R.id.search_bar_list);
|
||||
mListView = (ListView) ViewUtils.$$(mListContainer, R.id.search_bar_list);
|
||||
mListHeader = ViewUtils.$$(mListContainer, R.id.list_header);
|
||||
|
||||
mViewTransition = new ViewTransition(mTitleTextView, mEditText);
|
||||
@@ -139,22 +136,18 @@ public class SearchBar extends FrameLayout implements View.OnClickListener,
|
||||
mBaseHeight = getMeasuredHeight();
|
||||
|
||||
mSuggestionList = new ArrayList<>();
|
||||
mSuggestionAdapter = new ArrayAdapter<>(getContext(), R.layout.item_simple_list, mSuggestionList);
|
||||
list.setAdapter(mSuggestionAdapter);
|
||||
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||
mSuggestionAdapter = new SuggestionAdapter(LayoutInflater.from(getContext()));
|
||||
mListView.setAdapter(mSuggestionAdapter);
|
||||
mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
String suggestion = mSuggestionList.get(MathUtils.clamp(position, 0, mSuggestionList.size() - 1));
|
||||
mEditText.setText(suggestion);
|
||||
mEditText.setSelection(mEditText.getText().length());
|
||||
mSuggestionList.get(position).onClick();
|
||||
}
|
||||
});
|
||||
list.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
|
||||
mListView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
|
||||
@Override
|
||||
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
String suggestion = mSuggestionList.get(MathUtils.clamp(position, 0, mSuggestionList.size() - 1));
|
||||
mSearchDatabase.deleteQuery(suggestion);
|
||||
updateSuggestions();
|
||||
mSuggestionList.get(position).onLongClick();
|
||||
return true;
|
||||
}
|
||||
});
|
||||
@@ -169,16 +162,36 @@ public class SearchBar extends FrameLayout implements View.OnClickListener,
|
||||
}
|
||||
|
||||
private void updateSuggestions() {
|
||||
String prefix = mEditText.getText().toString();
|
||||
String[] suggestions = mSearchDatabase.getSuggestions(prefix);
|
||||
updateSuggestions(true);
|
||||
}
|
||||
|
||||
private void updateSuggestions(boolean scrollToTop) {
|
||||
mSuggestionList.clear();
|
||||
Collections.addAll(mSuggestionList, suggestions);
|
||||
|
||||
String text = mEditText.getText().toString();
|
||||
|
||||
if (mSuggestionProvider != null) {
|
||||
List<Suggestion> suggestions = mSuggestionProvider.providerSuggestions(text);
|
||||
if (suggestions != null && !suggestions.isEmpty()) {
|
||||
mSuggestionList.addAll(suggestions);
|
||||
}
|
||||
}
|
||||
|
||||
String[] keywords = mSearchDatabase.getSuggestions(text, 128);
|
||||
for (String keyword : keywords) {
|
||||
mSuggestionList.add(new KeywordSuggestion(keyword));
|
||||
}
|
||||
|
||||
if (mSuggestionList.size() == 0) {
|
||||
removeListHeader();
|
||||
} else {
|
||||
addListHeader();
|
||||
}
|
||||
mSuggestionAdapter.notifyDataSetChanged();
|
||||
|
||||
if (scrollToTop) {
|
||||
mListView.setSelection(0);
|
||||
}
|
||||
}
|
||||
|
||||
public void setAllowEmptySearch(boolean allowEmptySearch) {
|
||||
@@ -201,6 +214,10 @@ public class SearchBar extends FrameLayout implements View.OnClickListener,
|
||||
mOnStateChangeListener = listener;
|
||||
}
|
||||
|
||||
public void setSuggestionProvider(SuggestionProvider suggestionProvider) {
|
||||
mSuggestionProvider = suggestionProvider;
|
||||
}
|
||||
|
||||
public void setText(String text) {
|
||||
mEditText.setText(text);
|
||||
}
|
||||
@@ -490,4 +507,82 @@ public class SearchBar extends FrameLayout implements View.OnClickListener,
|
||||
|
||||
void onStateChange(SearchBar searchBar, int newState, int oldState, boolean animation);
|
||||
}
|
||||
|
||||
public interface SuggestionProvider {
|
||||
|
||||
List<Suggestion> providerSuggestions(String text);
|
||||
}
|
||||
|
||||
private class SuggestionAdapter extends BaseAdapter {
|
||||
|
||||
private LayoutInflater mInflater;
|
||||
|
||||
private SuggestionAdapter(LayoutInflater inflater) {
|
||||
mInflater = inflater;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return mSuggestionList.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getItem(int position) {
|
||||
return mSuggestionList.get(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
return position;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
TextView textView;
|
||||
if (convertView == null) {
|
||||
textView = (TextView) mInflater.inflate(R.layout.item_simple_list, parent, false);
|
||||
} else {
|
||||
textView = (TextView) convertView;
|
||||
}
|
||||
|
||||
textView.setText(mSuggestionList.get(position).getText(textView.getTextSize()));
|
||||
|
||||
return textView;
|
||||
}
|
||||
}
|
||||
|
||||
public abstract static class Suggestion {
|
||||
|
||||
public abstract CharSequence getText(float textSize);
|
||||
|
||||
public abstract void onClick();
|
||||
|
||||
public abstract void onLongClick();
|
||||
}
|
||||
|
||||
public class KeywordSuggestion extends Suggestion {
|
||||
|
||||
private String mKeyword;
|
||||
|
||||
private KeywordSuggestion(String keyword) {
|
||||
mKeyword = keyword;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getText(float textSize) {
|
||||
return mKeyword;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick() {
|
||||
mEditText.setText(mKeyword);
|
||||
mEditText.setSelection(mEditText.getText().length());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLongClick() {
|
||||
mSearchDatabase.deleteQuery(mKeyword);
|
||||
updateSuggestions(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -57,10 +57,10 @@ public final class SearchDatabase {
|
||||
mDatabase = databaseHelper.getWritableDatabase();
|
||||
}
|
||||
|
||||
public String[] getSuggestions(String prefix) {
|
||||
public String[] getSuggestions(String prefix, int limit) {
|
||||
List<String> queryList = new LinkedList<>();
|
||||
limit = Math.max(0, limit);
|
||||
|
||||
// TODO add limit
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("SELECT * FROM ").append(TABLE_SUGGESTIONS);
|
||||
if (!TextUtils.isEmpty(prefix)) {
|
||||
@@ -68,7 +68,7 @@ public final class SearchDatabase {
|
||||
.append(SqlUtils.sqlEscapeString(prefix)).append("%'");
|
||||
}
|
||||
sb.append(" ORDER BY ").append(COLUMN_DATE).append(" DESC")
|
||||
.append(" LIMIT 5");
|
||||
.append(" LIMIT ").append(limit);
|
||||
Cursor cursor = mDatabase.rawQuery(sb.toString(), null);
|
||||
int queryIndex = cursor.getColumnIndex(COLUMN_QUERY);
|
||||
if (cursor.moveToFirst()) {
|
||||
|
||||
@@ -37,7 +37,7 @@ import android.widget.CompoundButton;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.hippo.android.resource.AttrResources;
|
||||
import com.hippo.easyrecyclerview.EasyRecyclerView;
|
||||
import com.hippo.easyrecyclerview.MarginItemDecoration;
|
||||
import com.hippo.ehviewer.R;
|
||||
@@ -46,7 +46,6 @@ import com.hippo.ehviewer.client.exception.EhException;
|
||||
import com.hippo.ripple.Ripple;
|
||||
import com.hippo.widget.RadioGridGroup;
|
||||
import com.hippo.yorozuya.ViewUtils;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
@@ -139,7 +138,7 @@ public class SearchLayout extends EasyRecyclerView implements CompoundButton.OnC
|
||||
mNormalSearchModeHelp = (ImageView) normalView.findViewById(R.id.normal_search_mode_help);
|
||||
mEnableAdvanceSwitch = (SwitchCompat) normalView.findViewById(R.id.search_enable_advance);
|
||||
mNormalSearchModeHelp.setOnClickListener(this);
|
||||
Ripple.addRipple(mNormalSearchModeHelp, false);
|
||||
Ripple.addRipple(mNormalSearchModeHelp, !AttrResources.getAttrBoolean(context, R.attr.isLightTheme));
|
||||
mEnableAdvanceSwitch.setOnCheckedChangeListener(SearchLayout.this);
|
||||
mEnableAdvanceSwitch.setSwitchPadding(resources.getDimensionPixelSize(R.dimen.switch_padding));
|
||||
|
||||
@@ -233,10 +232,6 @@ public class SearchLayout extends EasyRecyclerView implements CompoundButton.OnC
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isSpecifyGallery() {
|
||||
return R.id.search_specify_gallery == mNormalSearchMode.getCheckedRadioButtonId();
|
||||
}
|
||||
|
||||
public void formatListUrlBuilder(ListUrlBuilder urlBuilder, String query) throws EhException {
|
||||
urlBuilder.reset();
|
||||
|
||||
|
||||
@@ -58,9 +58,9 @@ public class SimpleRatingView extends View {
|
||||
|
||||
private void init(Context context) {
|
||||
Resources resources = context.getResources();
|
||||
mStarDrawable = DrawableManager.getDrawable(context, R.drawable.v_star_x16);
|
||||
mStarHalfDrawable = DrawableManager.getDrawable(context, R.drawable.v_star_half_x16);
|
||||
mStarOutlineDrawable = DrawableManager.getDrawable(context, R.drawable.v_star_outline_x16);
|
||||
mStarDrawable = DrawableManager.getVectorDrawable(context, R.drawable.v_star_x16);
|
||||
mStarHalfDrawable = DrawableManager.getVectorDrawable(context, R.drawable.v_star_half_x16);
|
||||
mStarOutlineDrawable = DrawableManager.getVectorDrawable(context, R.drawable.v_star_outline_x16);
|
||||
mRatingSize = resources.getDimensionPixelOffset(R.dimen.rating_size);
|
||||
mRatingInterval = resources.getDimensionPixelOffset(R.dimen.rating_interval);
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
import android.view.View;
|
||||
|
||||
import com.hippo.android.resource.AttrResources;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.yorozuya.collect.IntList;
|
||||
|
||||
@@ -102,7 +103,7 @@ public class SceneFragment extends Fragment {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
|
||||
view.setTag(R.id.fragment_tag, getTag());
|
||||
view.setBackgroundColor(getResources().getColor(R.color.background_light));
|
||||
view.setBackgroundDrawable(AttrResources.getAttrDrawable(getContext(), android.R.attr.windowBackground));
|
||||
|
||||
// Notify
|
||||
FragmentActivity activity = getActivity();
|
||||
|
||||
@@ -25,13 +25,10 @@ import android.support.v4.app.FragmentManager;
|
||||
import android.support.v4.app.FragmentTransaction;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.ui.EhActivity;
|
||||
import com.hippo.yorozuya.AssertUtils;
|
||||
import com.hippo.yorozuya.IntIdGenerator;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
@@ -334,7 +331,7 @@ public abstract class StageActivity extends EhActivity {
|
||||
String tag = mSceneTagList.get(mSceneTagList.size() - 1);
|
||||
Fragment fragment = fragmentManager.findFragmentByTag(tag);
|
||||
if (fragment != null) {
|
||||
Assert.assertTrue(SceneFragment.class.isInstance(fragment));
|
||||
AssertUtils.assertTrue(SceneFragment.class.isInstance(fragment));
|
||||
currentScene = (SceneFragment) fragment;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,9 +46,10 @@ import android.text.style.TextAppearanceSpan;
|
||||
import android.text.style.TypefaceSpan;
|
||||
import android.text.style.URLSpan;
|
||||
import android.text.style.UnderlineSpan;
|
||||
|
||||
import com.hippo.ehviewer.R;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringReader;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import org.ccil.cowan.tagsoup.HTMLSchema;
|
||||
import org.ccil.cowan.tagsoup.Parser;
|
||||
import org.xml.sax.Attributes;
|
||||
@@ -58,11 +59,6 @@ import org.xml.sax.Locator;
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.XMLReader;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringReader;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* This class processes HTML strings into displayable styled text.
|
||||
* Not all HTML tags are supported.
|
||||
@@ -678,7 +674,7 @@ class HtmlToSpannedConverter implements ContentHandler {
|
||||
}
|
||||
|
||||
if (d == null) {
|
||||
d = Html.sResources.getDrawable(R.drawable.image_failed);
|
||||
d = Resources.getSystem().getDrawable(android.R.drawable.ic_menu_report_image);
|
||||
d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
|
||||
}
|
||||
|
||||
|
||||
@@ -24,14 +24,11 @@ import android.support.annotation.DrawableRes;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.graphics.drawable.VectorDrawableCompat;
|
||||
import android.support.v7.widget.AppCompatDrawableManager;
|
||||
|
||||
public final class DrawableManager {
|
||||
|
||||
private static final AppCompatDrawableManager sManager = AppCompatDrawableManager.get();
|
||||
|
||||
public static Drawable getDrawable(@NonNull Context context, @DrawableRes int resId) {
|
||||
return sManager.getDrawable(context, resId);
|
||||
public static Drawable getVectorDrawable(@NonNull Context context, @DrawableRes int resId) {
|
||||
return getVectorDrawable(context.getResources(), resId, context.getTheme());
|
||||
}
|
||||
|
||||
public static Drawable getVectorDrawable(@NonNull Resources res,
|
||||
|
||||
@@ -35,7 +35,7 @@ public final class ExceptionUtils {
|
||||
private static final String TAG = ExceptionUtils.class.getSimpleName();
|
||||
|
||||
@NonNull
|
||||
public static String getReadableString(@NonNull Exception e) {
|
||||
public static String getReadableString(@NonNull Throwable e) {
|
||||
e.printStackTrace();
|
||||
if (e instanceof MalformedURLException) {
|
||||
return GetText.getString(R.string.error_invalid_url);
|
||||
@@ -62,4 +62,15 @@ public final class ExceptionUtils {
|
||||
return GetText.getString(R.string.error_unknown);
|
||||
}
|
||||
}
|
||||
|
||||
public static void throwIfFatal(@NonNull Throwable t) {
|
||||
// values here derived from https://github.com/ReactiveX/RxJava/issues/748#issuecomment-32471495
|
||||
if (t instanceof VirtualMachineError) {
|
||||
throw (VirtualMachineError) t;
|
||||
} else if (t instanceof ThreadDeath) {
|
||||
throw (ThreadDeath) t;
|
||||
} else if (t instanceof LinkageError) {
|
||||
throw (LinkageError) t;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
/*
|
||||
* Copyright 2018 Hippo Seven
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.hippo.util;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
||||
/**
|
||||
* Implements natural sort order.
|
||||
*/
|
||||
public class NaturalComparator implements Comparator<String> {
|
||||
|
||||
@Override
|
||||
public int compare(String o1, String o2) {
|
||||
if (o1 == null && o2 == null) {
|
||||
return 0;
|
||||
}
|
||||
if (o1 == null) {
|
||||
return -1;
|
||||
}
|
||||
if (o2 == null) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
int index1 = 0;
|
||||
int index2 = 0;
|
||||
while (true) {
|
||||
String data1 = nextSlice(o1, index1);
|
||||
String data2 = nextSlice(o2, index2);
|
||||
|
||||
if (data1 == null && data2 == null) {
|
||||
return 0;
|
||||
}
|
||||
if (data1 == null) {
|
||||
return -1;
|
||||
}
|
||||
if (data2 == null) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
index1 += data1.length();
|
||||
index2 += data2.length();
|
||||
|
||||
int result;
|
||||
if (isDigit(data1) && isDigit(data2)) {
|
||||
result = Long.compare(Long.valueOf(data1), Long.valueOf(data2));
|
||||
if (result == 0) {
|
||||
result = -Integer.compare(data1.length(), data2.length());
|
||||
}
|
||||
} else {
|
||||
result = data1.compareToIgnoreCase(data2);
|
||||
}
|
||||
|
||||
if (result != 0) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isDigit(String str) {
|
||||
// Just check the first char
|
||||
char ch = str.charAt(0);
|
||||
return ch >= '0' && ch <= '9';
|
||||
}
|
||||
|
||||
private static String nextSlice(String str, int index) {
|
||||
int length = str.length();
|
||||
if (index == length) {
|
||||
return null;
|
||||
}
|
||||
|
||||
char ch = str.charAt(index);
|
||||
if (ch == '.' || ch == ' ') {
|
||||
return str.substring(index, index + 1);
|
||||
} else if (ch >= '0' && ch <= '9') {
|
||||
return str.substring(index, nextNumberBound(str, index + 1));
|
||||
} else {
|
||||
return str.substring(index, nextOtherBound(str, index + 1));
|
||||
}
|
||||
}
|
||||
|
||||
private static int nextNumberBound(String str, int index) {
|
||||
for (int length = str.length(); index < length; index++) {
|
||||
char ch = str.charAt(index);
|
||||
if (ch < '0' || ch > '9') {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return index;
|
||||
}
|
||||
|
||||
private static int nextOtherBound(String str, int index) {
|
||||
for (int length = str.length(); index < length; index++) {
|
||||
char ch = str.charAt(index);
|
||||
if (ch == '.' || ch == ' ' || (ch >= '0' && ch <= '9')) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return index;
|
||||
}
|
||||
}
|
||||
@@ -40,7 +40,8 @@ public final class PackageUtils {
|
||||
} else {
|
||||
Log.e(TAG, "Can't find signature in package " + packageName);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
Log.e(TAG, "Can't find package " + packageName, e);
|
||||
}
|
||||
return null;
|
||||
|
||||
@@ -0,0 +1,104 @@
|
||||
package com.hippo.util;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
||||
/**
|
||||
* Compares each path segment in natural sort order.
|
||||
* {@code \} and {@code /} are the same. Duplicate {@code \} and {@code /} are ignored.
|
||||
* Leading {@code \} and {@code /} are ignored, so there is no difference between
|
||||
* relative path and absolute path.
|
||||
* {@code /./} and {@code /../} are treated as normal path.
|
||||
*/
|
||||
public class PathNaturalComparator implements Comparator<String> {
|
||||
|
||||
private static final boolean TYPE_SEPARATOR = false;
|
||||
private static final boolean TYPE_NORMAL = true;
|
||||
|
||||
private Comparator<String> naturalComparator = new NaturalComparator();
|
||||
|
||||
@Override
|
||||
public int compare(String o1, String o2) {
|
||||
if (o1 == null && o2 == null) {
|
||||
return 0;
|
||||
}
|
||||
if (o1 == null) {
|
||||
return -1;
|
||||
}
|
||||
if (o2 == null) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
int index1 = 0;
|
||||
int index2 = 0;
|
||||
|
||||
while (true) {
|
||||
String data1;
|
||||
String data2;
|
||||
|
||||
for (;;) {
|
||||
int newIndex1 = nextSegmentStart(o1, index1);
|
||||
if (newIndex1 == index1) {
|
||||
data1 = null;
|
||||
break;
|
||||
}
|
||||
if (getType(o1.charAt(newIndex1 - 1)) == TYPE_NORMAL) {
|
||||
data1 = o1.substring(index1, newIndex1);
|
||||
index1 = newIndex1;
|
||||
break;
|
||||
}
|
||||
index1 = newIndex1;
|
||||
}
|
||||
|
||||
for (;;) {
|
||||
int newIndex2 = nextSegmentStart(o2, index2);
|
||||
if (newIndex2 == index2) {
|
||||
data2 = null;
|
||||
break;
|
||||
}
|
||||
if (getType(o2.charAt(newIndex2 - 1)) == TYPE_NORMAL) {
|
||||
data2 = o2.substring(index2, newIndex2);
|
||||
index2 = newIndex2;
|
||||
break;
|
||||
}
|
||||
index2 = newIndex2;
|
||||
}
|
||||
|
||||
if (data1 == null && data2 == null) {
|
||||
return 0;
|
||||
}
|
||||
if (data1 == null) {
|
||||
return -1;
|
||||
}
|
||||
if (data2 == null) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
int result = naturalComparator.compare(data1, data2);
|
||||
if (result != 0) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static int nextSegmentStart(String str, int index) {
|
||||
if (index >= str.length()) {
|
||||
return index;
|
||||
}
|
||||
|
||||
boolean type = getType(str.charAt(index));
|
||||
int i = index + 1;
|
||||
while (i < str.length() && type == getType(str.charAt(i))) {
|
||||
i += 1;
|
||||
}
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
private static boolean getType(char c) {
|
||||
if (c == '/' || c == '\\') {
|
||||
return TYPE_SEPARATOR;
|
||||
} else {
|
||||
return TYPE_NORMAL;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -24,13 +24,13 @@ import android.content.IntentFilter;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.Color;
|
||||
import android.os.BatteryManager;
|
||||
import android.support.v7.widget.AppCompatTextView;
|
||||
import android.util.AttributeSet;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.hippo.drawable.BatteryDrawable;
|
||||
import com.hippo.ehviewer.R;
|
||||
|
||||
public class BatteryView extends TextView {
|
||||
public class BatteryView extends AppCompatTextView {
|
||||
|
||||
private int mColor;
|
||||
private int mWarningColor;
|
||||
|
||||
@@ -27,12 +27,11 @@ import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Parcelable;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v7.widget.AppCompatTextView;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.animation.Interpolator;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.hotspot.Hotspot;
|
||||
import com.hippo.hotspot.Hotspotable;
|
||||
@@ -40,7 +39,7 @@ import com.hippo.yorozuya.AnimationUtils;
|
||||
import com.hippo.yorozuya.MathUtils;
|
||||
import com.hippo.yorozuya.SimpleAnimatorListener;
|
||||
|
||||
public class CheckTextView extends TextView implements OnClickListener, Hotspotable {
|
||||
public class CheckTextView extends AppCompatTextView implements OnClickListener, Hotspotable {
|
||||
|
||||
private static final String STATE_KEY_SUPER = "super";
|
||||
private static final String STATE_KEY_CHECKED = "checked";
|
||||
|
||||
@@ -21,6 +21,7 @@ import android.graphics.drawable.Drawable;
|
||||
import android.os.Bundle;
|
||||
import android.os.Parcelable;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
@@ -30,7 +31,7 @@ import android.view.ViewGroup;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.hippo.android.resource.AttrResources;
|
||||
import com.hippo.easyrecyclerview.EasyRecyclerView;
|
||||
import com.hippo.easyrecyclerview.FastScroller;
|
||||
import com.hippo.easyrecyclerview.HandlerDrawable;
|
||||
@@ -43,9 +44,7 @@ import com.hippo.util.ExceptionUtils;
|
||||
import com.hippo.view.ViewTransition;
|
||||
import com.hippo.yorozuya.IntIdGenerator;
|
||||
import com.hippo.yorozuya.LayoutUtils;
|
||||
import com.hippo.yorozuya.ResourcesUtils;
|
||||
import com.hippo.yorozuya.collect.IntList;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -92,7 +91,7 @@ public class ContentLayout extends FrameLayout {
|
||||
|
||||
mFastScroller.attachToRecyclerView(mRecyclerView);
|
||||
HandlerDrawable drawable = new HandlerDrawable();
|
||||
drawable.setColor(ResourcesUtils.getAttrColor(context, R.attr.colorAccent));
|
||||
drawable.setColor(AttrResources.getAttrColor(context, R.attr.widgetColorThemeAccent));
|
||||
mFastScroller.setHandlerDrawable(drawable);
|
||||
|
||||
mRefreshLayout.setHeaderColorSchemeResources(
|
||||
@@ -303,7 +302,7 @@ public class ContentLayout extends FrameLayout {
|
||||
mRefreshLayout = contentLayout.mRefreshLayout;
|
||||
mRecyclerView = contentLayout.mRecyclerView;
|
||||
|
||||
Drawable drawable = DrawableManager.getDrawable(getContext(), R.drawable.big_weird_face);
|
||||
Drawable drawable = DrawableManager.getVectorDrawable(getContext(), R.drawable.big_sad_pandroid);
|
||||
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
|
||||
mTipView.setCompoundDrawables(null, drawable, null, null);
|
||||
|
||||
@@ -370,6 +369,15 @@ public class ContentLayout extends FrameLayout {
|
||||
return mData.get(location);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public E getDataAtEx(int location) {
|
||||
if (location >= 0 && location < mData.size()) {
|
||||
return mData.get(location);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return mData.size();
|
||||
}
|
||||
|
||||
@@ -18,11 +18,10 @@ package com.hippo.widget;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.content.res.TypedArray;
|
||||
import android.support.v7.widget.AppCompatSpinner;
|
||||
import android.support.v7.widget.TintTypedArray;
|
||||
import android.util.AttributeSet;
|
||||
import android.widget.ArrayAdapter;
|
||||
|
||||
import com.hippo.ehviewer.R;
|
||||
|
||||
public class CuteSpinner extends AppCompatSpinner {
|
||||
@@ -58,7 +57,7 @@ public class CuteSpinner extends AppCompatSpinner {
|
||||
}
|
||||
|
||||
private void init(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
TintTypedArray a = TintTypedArray.obtainStyledAttributes(context, attrs,
|
||||
TypedArray a = context.obtainStyledAttributes(attrs,
|
||||
android.support.v7.appcompat.R.styleable.Spinner, defStyleAttr, 0);
|
||||
final CharSequence[] entries = a.getTextArray(R.styleable.Spinner_android_entries);
|
||||
if (entries != null) {
|
||||
|
||||
@@ -24,13 +24,12 @@ import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.hippo.android.resource.AttrResources;
|
||||
import com.hippo.easyrecyclerview.EasyRecyclerView;
|
||||
import com.hippo.easyrecyclerview.LinearDividerItemDecoration;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ripple.Ripple;
|
||||
import com.hippo.yorozuya.LayoutUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileFilter;
|
||||
import java.util.ArrayList;
|
||||
@@ -73,11 +72,11 @@ public class DirExplorer extends EasyRecyclerView implements EasyRecyclerView.On
|
||||
setAdapter(mAdapter);
|
||||
setLayoutManager(new LinearLayoutManager(context));
|
||||
LinearDividerItemDecoration decoration = new LinearDividerItemDecoration(
|
||||
LinearDividerItemDecoration.VERTICAL, getResources().getColor(R.color.divider),
|
||||
LinearDividerItemDecoration.VERTICAL, AttrResources.getAttrColor(context, R.attr.dividerColor),
|
||||
LayoutUtils.dp2pix(context, 1));
|
||||
decoration.setShowLastDivider(true);
|
||||
addItemDecoration(decoration);
|
||||
setSelector(Ripple.generateRippleDrawable(context, false));
|
||||
setSelector(Ripple.generateRippleDrawable(context, !AttrResources.getAttrBoolean(context, R.attr.isLightTheme)));
|
||||
setOnItemClickListener(this);
|
||||
|
||||
mCurrentFile = Environment.getExternalStorageDirectory();
|
||||
|
||||
@@ -26,13 +26,11 @@ import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.animation.Interpolator;
|
||||
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.yorozuya.AnimationUtils;
|
||||
import com.hippo.yorozuya.AssertUtils;
|
||||
import com.hippo.yorozuya.SimpleAnimatorListener;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
public class FabLayout extends ViewGroup implements View.OnClickListener {
|
||||
|
||||
private static final long ANIMATE_TIME = 300L;
|
||||
@@ -109,9 +107,9 @@ public class FabLayout extends ViewGroup implements View.OnClickListener {
|
||||
|
||||
@Override
|
||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||
Assert.assertEquals("Measure mode must be MeasureSpec.EXACTLY",
|
||||
AssertUtils.assertEquals("Measure mode must be MeasureSpec.EXACTLY",
|
||||
MeasureSpec.getMode(widthMeasureSpec), MeasureSpec.EXACTLY);
|
||||
Assert.assertEquals("Measure mode must be MeasureSpec.EXACTLY",
|
||||
AssertUtils.assertEquals("Measure mode must be MeasureSpec.EXACTLY",
|
||||
MeasureSpec.getMode(heightMeasureSpec), MeasureSpec.EXACTLY);
|
||||
|
||||
int width = MeasureSpec.getSize(widthMeasureSpec);
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright 2018 Hippo Seven
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.hippo.widget;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.support.design.widget.TextInputEditText;
|
||||
import android.util.AttributeSet;
|
||||
import android.widget.TextView;
|
||||
import com.hippo.util.ExceptionUtils;
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
// Avoid crash on some Meizu devices
|
||||
// https://github.com/android-in-china/Compatibility/issues/11
|
||||
// https://stackoverflow.com/questions/51891415/nullpointerexception-on-meizu-devices-in-editor-updatecursorpositionmz/52001305
|
||||
public class HackyTextInputEditText extends TextInputEditText {
|
||||
|
||||
public HackyTextInputEditText(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getHint() {
|
||||
boolean isMeizu = Build.MANUFACTURER.toLowerCase().contains("meizu");
|
||||
boolean isPreP = Build.VERSION.SDK_INT < Build.VERSION_CODES.P;
|
||||
|
||||
if (isMeizu && isPreP) {
|
||||
try {
|
||||
return getSuperHint();
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
return super.getHint();
|
||||
}
|
||||
} else {
|
||||
return super.getHint();
|
||||
}
|
||||
}
|
||||
|
||||
public CharSequence getSuperHint() throws NoSuchFieldException, IllegalAccessException {
|
||||
Field field = TextView.class.getDeclaredField("mHint");
|
||||
field.setAccessible(true);
|
||||
return (CharSequence) field.get(this);
|
||||
}
|
||||
}
|
||||
@@ -29,7 +29,6 @@ import android.support.annotation.NonNull;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
|
||||
import com.hippo.conaco.Conaco;
|
||||
import com.hippo.conaco.ConacoTask;
|
||||
import com.hippo.conaco.DataContainer;
|
||||
@@ -40,7 +39,7 @@ import com.hippo.ehviewer.R;
|
||||
import com.hippo.image.ImageBitmap;
|
||||
import com.hippo.image.ImageDrawable;
|
||||
import com.hippo.image.RecycledException;
|
||||
|
||||
import com.hippo.util.DrawableManager;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
@@ -309,7 +308,7 @@ public class LoadImageView extends FixedAspectImageView implements Unikery<Image
|
||||
public void onFailure() {
|
||||
mFailed = true;
|
||||
clearDrawable();
|
||||
setImageDrawable(getContext().getResources().getDrawable(R.drawable.image_failed));
|
||||
setImageDrawable(DrawableManager.getVectorDrawable(getContext(), R.drawable.image_failed));
|
||||
if (mRetryType == RETRY_TYPE_CLICK) {
|
||||
setOnClickListener(this);
|
||||
} else if (mRetryType == RETRY_TYPE_LONG_CLICK) {
|
||||
|
||||
@@ -21,10 +21,8 @@ import android.content.res.TypedArray;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.hippo.ehviewer.R;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import com.hippo.yorozuya.AssertUtils;
|
||||
|
||||
public class MaxSizeContainer extends ViewGroup {
|
||||
|
||||
@@ -70,7 +68,7 @@ public class MaxSizeContainer extends ViewGroup {
|
||||
|
||||
@Override
|
||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||
Assert.assertEquals("getChildCount() must be 1", 1, getChildCount());
|
||||
AssertUtils.assertEquals("getChildCount() must be 1", 1, getChildCount());
|
||||
|
||||
View child = getChildAt(0);
|
||||
if (child.getVisibility() != GONE) {
|
||||
@@ -84,7 +82,7 @@ public class MaxSizeContainer extends ViewGroup {
|
||||
|
||||
@Override
|
||||
protected void onLayout(boolean changed, int l, int t, int r, int b) {
|
||||
Assert.assertEquals("getChildCount() must be 1", 1, getChildCount());
|
||||
AssertUtils.assertEquals("getChildCount() must be 1", 1, getChildCount());
|
||||
|
||||
View child = getChildAt(0);
|
||||
if (child.getVisibility() != GONE) {
|
||||
|
||||
Loaded 100 of 255 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user