mirror of
https://github.com/seven332/EhViewer
synced 2026-12-01 11:38:03 +08:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ed15f403cc | ||
|
|
2c69b67731 | ||
|
|
ed8073eebf | ||
|
|
c03b33fe2f | ||
|
|
1fe7500251 | ||
|
|
8900b0fa4a | ||
|
|
7626c8e89e | ||
|
|
81428446d9 | ||
|
|
d6b6976277 | ||
|
|
b5f15cbbd2 | ||
|
|
075fe52b4e | ||
|
|
0d8054b59d | ||
|
|
5706771c88 | ||
|
|
6c08f068d0 | ||
|
|
9ad1c9b050 | ||
|
|
3ac64cd973 | ||
|
|
27660f448f | ||
|
|
c5c01b3a48 | ||
|
|
1166c0d547 | ||
|
|
9e2c5715ed | ||
|
|
a4f9580171 | ||
|
|
e84a060194 | ||
|
|
5d858501b0 | ||
|
|
cf24c86981 | ||
|
|
ed67831156 | ||
|
|
43d7e532db | ||
|
|
c8f38c0079 | ||
|
|
249960825a | ||
|
|
cdaf2b80b6 | ||
|
|
d345512caa | ||
|
|
ec2cc5b13a | ||
|
|
9a5f6ccb74 | ||
|
|
42c4c4cfda | ||
|
|
5325c0c4f7 | ||
|
|
ff8bf2be64 | ||
|
|
5b4ee608b8 | ||
|
|
2aadad487e | ||
|
|
e97c82dbd7 | ||
|
|
d56c429175 | ||
|
|
47e8f73296 | ||
|
|
2c50429ef9 | ||
|
|
933f51c96b | ||
|
|
59e704c992 | ||
|
|
fb4c79a722 | ||
|
|
644113ba56 | ||
|
|
2160deb34a | ||
|
|
d4a39990ed | ||
|
|
6e315ea94d | ||
|
|
25d75deb3c | ||
|
|
275a0766fa | ||
|
|
4b2801190c |
No files matched your search
+2
-2
@@ -10,8 +10,8 @@ android {
|
||||
applicationId "com.hippo.ehviewer"
|
||||
minSdkVersion 16
|
||||
targetSdkVersion 23
|
||||
versionCode 49
|
||||
versionName "0.9.1"
|
||||
versionCode 50
|
||||
versionName "0.9.2"
|
||||
vectorDrawables.useSupportLibrary = true
|
||||
}
|
||||
|
||||
|
||||
@@ -87,6 +87,18 @@
|
||||
android:theme="@style/AppTheme.NoActionBar"
|
||||
android:label="@string/license"/>
|
||||
|
||||
<activity
|
||||
android:name="com.hippo.ehviewer.ui.FilterActivity"
|
||||
android:configChanges="screenSize|uiMode"
|
||||
android:theme="@style/AppTheme.NoActionBar"
|
||||
android:label="@string/filter"/>
|
||||
|
||||
<activity
|
||||
android:name="com.hippo.ehviewer.ui.SetSecurityActivity"
|
||||
android:configChanges="screenSize|uiMode"
|
||||
android:theme="@style/AppTheme.NoActionBar"
|
||||
android:label="@string/set_pattern_protection"/>
|
||||
|
||||
<service
|
||||
android:name="com.hippo.ehviewer.download.DownloadService"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
|
||||
@@ -16,11 +16,14 @@
|
||||
|
||||
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.support.annotation.NonNull;
|
||||
|
||||
import com.hippo.scene.StageActivity;
|
||||
import com.hippo.util.PackageUtils;
|
||||
import com.hippo.util.ReadableTime;
|
||||
import com.hippo.yorozuya.IOUtils;
|
||||
@@ -34,6 +37,12 @@ import java.io.PrintWriter;
|
||||
|
||||
public class 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();
|
||||
@@ -55,6 +64,25 @@ public class Crash {
|
||||
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) {
|
||||
topSceneClazzName = ((StageActivity) topActivity).getTopSceneClazzName();
|
||||
}
|
||||
}
|
||||
} 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");
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package com.hippo.ehviewer;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.ActivityManager;
|
||||
import android.content.ComponentCallbacks2;
|
||||
import android.content.Context;
|
||||
@@ -24,6 +25,7 @@ import android.content.pm.PackageManager;
|
||||
import android.graphics.Bitmap;
|
||||
import android.os.Debug;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.util.LruCache;
|
||||
import android.util.Log;
|
||||
import android.util.SparseArray;
|
||||
@@ -32,10 +34,12 @@ import com.hippo.beerbelly.SimpleDiskCache;
|
||||
import com.hippo.conaco.Conaco;
|
||||
import com.hippo.ehviewer.client.EhClient;
|
||||
import com.hippo.ehviewer.client.EhCookieStore;
|
||||
import com.hippo.ehviewer.client.EhEngine;
|
||||
import com.hippo.ehviewer.client.data.GalleryDetail;
|
||||
import com.hippo.ehviewer.client.data.LargePreviewSet;
|
||||
import com.hippo.ehviewer.download.DownloadManager;
|
||||
import com.hippo.ehviewer.spider.SpiderDen;
|
||||
import com.hippo.ehviewer.ui.CommonOperations;
|
||||
import com.hippo.network.StatusCodeException;
|
||||
import com.hippo.okhttp.CookieDB;
|
||||
import com.hippo.scene.SceneApplication;
|
||||
@@ -45,6 +49,8 @@ import com.hippo.yorozuya.FileUtils;
|
||||
import com.hippo.yorozuya.SimpleHandler;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
@@ -74,6 +80,8 @@ public class EhApplication extends SceneApplication implements Thread.UncaughtEx
|
||||
private SimpleDiskCache mSpiderInfoCache;
|
||||
private DownloadManager mDownloadManager;
|
||||
|
||||
private final List<Activity> mActivityList = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
// Prepare to catch crash
|
||||
@@ -91,6 +99,7 @@ public class EhApplication extends SceneApplication implements Thread.UncaughtEx
|
||||
AppConfig.initialize(this);
|
||||
SpiderDen.initialize(this);
|
||||
EhDB.initialize(this);
|
||||
EhEngine.initialize();
|
||||
|
||||
if (EhDB.needMerge()) {
|
||||
EhDB.mergeOldDB(this);
|
||||
@@ -100,6 +109,8 @@ public class EhApplication extends SceneApplication implements Thread.UncaughtEx
|
||||
Analytics.start(this);
|
||||
}
|
||||
|
||||
CommonOperations.ensureNoMediaFile(Settings.getDownloadLocation());
|
||||
|
||||
// Update version code
|
||||
try {
|
||||
PackageInfo pi= getPackageManager().getPackageInfo(getPackageName(), 0);
|
||||
@@ -113,23 +124,27 @@ public class EhApplication extends SceneApplication implements Thread.UncaughtEx
|
||||
}
|
||||
}
|
||||
|
||||
public void clearMemoryCache() {
|
||||
if (null != mConaco) {
|
||||
mConaco.clearMemoryCache();
|
||||
}
|
||||
if (null != mGalleryDetailCache) {
|
||||
mGalleryDetailCache.evictAll();
|
||||
}
|
||||
if (null != mLargePreviewSetCache) {
|
||||
mLargePreviewSetCache.evictAll();
|
||||
}
|
||||
if (null != mPreviewPagesCache) {
|
||||
mPreviewPagesCache.evictAll();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTrimMemory(int level) {
|
||||
super.onTrimMemory(level);
|
||||
|
||||
if (level >= ComponentCallbacks2.TRIM_MEMORY_RUNNING_LOW) {
|
||||
if (null != mConaco) {
|
||||
mConaco.clearMemoryCache();
|
||||
}
|
||||
if (null != mGalleryDetailCache) {
|
||||
mGalleryDetailCache.evictAll();
|
||||
}
|
||||
if (null != mLargePreviewSetCache) {
|
||||
mLargePreviewSetCache.evictAll();
|
||||
}
|
||||
if (null != mPreviewPagesCache) {
|
||||
mPreviewPagesCache.evictAll();
|
||||
}
|
||||
clearMemoryCache();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -319,4 +334,21 @@ public class EhApplication extends SceneApplication implements Thread.UncaughtEx
|
||||
public static String getDeveloperEmail() {
|
||||
return "ehviewersu$gmail.com".replace('$', '@');
|
||||
}
|
||||
|
||||
public void registerActivity(Activity activity) {
|
||||
mActivityList.add(activity);
|
||||
}
|
||||
|
||||
public void unregisterActivity(Activity activity) {
|
||||
mActivityList.remove(activity);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Activity getTopActivity() {
|
||||
if (!mActivityList.isEmpty()) {
|
||||
return mActivityList.get(mActivityList.size() - 1);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -34,12 +34,15 @@ import com.hippo.ehviewer.dao.DownloadInfo;
|
||||
import com.hippo.ehviewer.dao.DownloadLabel;
|
||||
import com.hippo.ehviewer.dao.DownloadLabelDao;
|
||||
import com.hippo.ehviewer.dao.DownloadsDao;
|
||||
import com.hippo.ehviewer.dao.Filter;
|
||||
import com.hippo.ehviewer.dao.FilterDao;
|
||||
import com.hippo.ehviewer.dao.HistoryDao;
|
||||
import com.hippo.ehviewer.dao.HistoryInfo;
|
||||
import com.hippo.ehviewer.dao.LocalFavoriteInfo;
|
||||
import com.hippo.ehviewer.dao.LocalFavoritesDao;
|
||||
import com.hippo.ehviewer.dao.QuickSearch;
|
||||
import com.hippo.ehviewer.dao.QuickSearchDao;
|
||||
import com.hippo.util.SqlUtils;
|
||||
import com.hippo.yorozuya.sparse.SparseJLArray;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -72,6 +75,10 @@ public class EhDB {
|
||||
|
||||
@Override
|
||||
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
|
||||
switch (oldVersion) {
|
||||
case 1: // 1 to 2
|
||||
FilterDao.createTable(db, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -277,7 +284,7 @@ public class EhDB {
|
||||
continue;
|
||||
}
|
||||
|
||||
HistoryInfo info = new HistoryInfo();
|
||||
HistoryInfo info = new HistoryInfo(gi);
|
||||
info.setMode(cursor.getInt(1));
|
||||
info.setTime(cursor.getLong(2));
|
||||
dao.insert(info);
|
||||
@@ -358,6 +365,11 @@ public class EhDB {
|
||||
dao.deleteByKey(gid);
|
||||
}
|
||||
|
||||
public static synchronized void clearDownloadDirname() {
|
||||
DownloadDirnameDao dao = sDaoSession.getDownloadDirnameDao();
|
||||
dao.deleteAll();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static synchronized List<DownloadLabel> getAllDownloadLabelList() {
|
||||
DownloadLabelDao dao = sDaoSession.getDownloadLabelDao();
|
||||
@@ -417,9 +429,10 @@ public class EhDB {
|
||||
}
|
||||
|
||||
public static synchronized List<GalleryInfo> searchLocalFavorites(String query) {
|
||||
query = SqlUtils.sqlEscapeString("%" + query+ "%");
|
||||
LocalFavoritesDao dao = sDaoSession.getLocalFavoritesDao();
|
||||
List<LocalFavoriteInfo> list = dao.queryBuilder().orderAsc(LocalFavoritesDao.Properties.Time)
|
||||
.where(LocalFavoritesDao.Properties.Title.like("%" + query+ "%")).list();
|
||||
.where(LocalFavoritesDao.Properties.Title.like(query)).list();
|
||||
List<GalleryInfo> result = new ArrayList<>();
|
||||
result.addAll(list);
|
||||
return result;
|
||||
@@ -528,4 +541,27 @@ public class EhDB {
|
||||
dao.deleteInTx(list);
|
||||
}
|
||||
}
|
||||
|
||||
public static synchronized void deleteHistoryInfo(HistoryInfo info) {
|
||||
HistoryDao dao = sDaoSession.getHistoryDao();
|
||||
dao.delete(info);
|
||||
}
|
||||
|
||||
public static synchronized void clearHistoryInfo() {
|
||||
HistoryDao dao = sDaoSession.getHistoryDao();
|
||||
dao.deleteAll();
|
||||
}
|
||||
|
||||
public static synchronized List<Filter> getAllFilter() {
|
||||
return sDaoSession.getFilterDao().queryBuilder().list();
|
||||
}
|
||||
|
||||
public static synchronized void addFilter(Filter filter) {
|
||||
long id = sDaoSession.getFilterDao().insert(filter);
|
||||
filter.setId(id);
|
||||
}
|
||||
|
||||
public static synchronized void deleteFilter(Filter filter) {
|
||||
sDaoSession.getFilterDao().delete(filter);
|
||||
}
|
||||
}
|
||||
@@ -30,6 +30,7 @@ import com.hippo.ehviewer.client.data.FavListUrlBuilder;
|
||||
import com.hippo.ehviewer.client.data.ListUrlBuilder;
|
||||
import com.hippo.ehviewer.gallery.gl.GalleryView;
|
||||
import com.hippo.ehviewer.gallery.gl.ImageView;
|
||||
import com.hippo.ehviewer.ui.CommonOperations;
|
||||
import com.hippo.unifile.UniFile;
|
||||
import com.hippo.yorozuya.AssertUtils;
|
||||
import com.hippo.yorozuya.FileUtils;
|
||||
@@ -198,9 +199,53 @@ public class Settings {
|
||||
return sEhConfig;
|
||||
}
|
||||
|
||||
private static final String KEY_NEED_SIGN_IN = "need_sign_in";
|
||||
private static final boolean DEFAULT_NEED_SIGN_IN = true;
|
||||
|
||||
public static boolean getNeedSignIn() {
|
||||
return getBoolean(KEY_NEED_SIGN_IN, DEFAULT_NEED_SIGN_IN);
|
||||
}
|
||||
|
||||
public static void putNeedSignIn(boolean value) {
|
||||
putBoolean(KEY_NEED_SIGN_IN, value);
|
||||
}
|
||||
|
||||
private static final String KEY_SELECT_SITE = "select_site";
|
||||
private static final boolean DEFAULT_SELECT_SITE = true;
|
||||
|
||||
public static boolean getSelectSite() {
|
||||
return getBoolean(KEY_SELECT_SITE, DEFAULT_SELECT_SITE);
|
||||
}
|
||||
|
||||
public static void putSelectSite(boolean value) {
|
||||
putBoolean(KEY_SELECT_SITE, value);
|
||||
}
|
||||
|
||||
private static final String KEY_QUICK_SEARCH_TIP = "quick_search_tip";
|
||||
private static final boolean DEFAULT_QUICK_SEARCH_TIP = true;
|
||||
|
||||
public static boolean getQuickSearchTip() {
|
||||
return getBoolean(KEY_QUICK_SEARCH_TIP, DEFAULT_QUICK_SEARCH_TIP);
|
||||
}
|
||||
|
||||
public static void putQuickSearchTip(boolean value) {
|
||||
putBoolean(KEY_QUICK_SEARCH_TIP, value);
|
||||
}
|
||||
|
||||
/********************
|
||||
****** Eh
|
||||
********************/
|
||||
public static final String KEY_GALLERY_SITE = "gallery_site";
|
||||
private static final int DEFAULT_GALLERY_SITE = 1;
|
||||
|
||||
public static int getGallerySite() {
|
||||
return getIntFromStr(KEY_GALLERY_SITE, DEFAULT_GALLERY_SITE);
|
||||
}
|
||||
|
||||
public static void putGallerySite(int value) {
|
||||
putIntToStr(KEY_GALLERY_SITE, value);
|
||||
}
|
||||
|
||||
public static final String KEY_LIST_MODE = "list_mode";
|
||||
private static final int DEFAULT_LIST_MODE = 0;
|
||||
|
||||
@@ -254,6 +299,72 @@ public class Settings {
|
||||
putString(KEY_EXCLUDED_LANGUAGES, value);
|
||||
}
|
||||
|
||||
private static final String KEY_HATH_PROXY = "hath_proxy";
|
||||
private static final boolean DEFAULT_HATH_PROXY = false;
|
||||
|
||||
public static boolean getHathProxy() {
|
||||
return getBoolean(KEY_HATH_PROXY, DEFAULT_HATH_PROXY);
|
||||
}
|
||||
|
||||
public static void putHathProxy(boolean value) {
|
||||
if (value) {
|
||||
sEhConfig.hahClientIp = Settings.getHathIp();
|
||||
sEhConfig.hahClientPort = Settings.getHathPort();
|
||||
sEhConfig.hahClientPasskey = Settings.getHathPasskey();
|
||||
} else {
|
||||
sEhConfig.hahClientIp = DEFAULT_HATH_IP;
|
||||
sEhConfig.hahClientPort = DEFAULT_HATH_PORT;
|
||||
sEhConfig.hahClientPasskey = DEFAULT_HATH_PASSKEY;
|
||||
}
|
||||
sEhConfig.setDirty();
|
||||
putBoolean(KEY_HATH_PROXY, value);
|
||||
}
|
||||
|
||||
private static final String KEY_HATH_IP = "hath_ip";
|
||||
private static final String DEFAULT_HATH_IP = null;
|
||||
|
||||
public static String getHathIp() {
|
||||
return getString(KEY_HATH_IP, DEFAULT_HATH_IP);
|
||||
}
|
||||
|
||||
public static void putHathIp(String value) {
|
||||
if (Settings.getHathProxy()) {
|
||||
sEhConfig.hahClientIp = value;
|
||||
sEhConfig.setDirty();
|
||||
}
|
||||
putString(KEY_HATH_IP, value);
|
||||
}
|
||||
|
||||
private static final String KEY_HATH_PORT = "hath_port";
|
||||
private static final int DEFAULT_HATH_PORT = -1;
|
||||
|
||||
public static int getHathPort() {
|
||||
return getInt(KEY_HATH_PORT, DEFAULT_HATH_PORT);
|
||||
}
|
||||
|
||||
public static void putHathPort(int value) {
|
||||
if (Settings.getHathProxy()) {
|
||||
sEhConfig.hahClientPort = value;
|
||||
sEhConfig.setDirty();
|
||||
}
|
||||
putInt(KEY_HATH_PORT, value);
|
||||
}
|
||||
|
||||
private static final String KEY_HATH_PASSKEY = "hath_passkey";
|
||||
private static final String DEFAULT_HATH_PASSKEY = null;
|
||||
|
||||
public static String getHathPasskey() {
|
||||
return getString(KEY_HATH_PASSKEY, DEFAULT_HATH_PASSKEY);
|
||||
}
|
||||
|
||||
public static void putHathPasskey(String value) {
|
||||
if (Settings.getHathProxy()) {
|
||||
sEhConfig.hahClientPasskey = value;
|
||||
sEhConfig.setDirty();
|
||||
}
|
||||
putString(KEY_HATH_PASSKEY, value);
|
||||
}
|
||||
|
||||
/********************
|
||||
****** Read
|
||||
********************/
|
||||
@@ -370,6 +481,8 @@ public class Settings {
|
||||
putString(KEY_DOWNLOAD_SAVE_PATH, uri.getEncodedPath());
|
||||
putString(KEY_DOWNLOAD_SAVE_QUERY, uri.getEncodedQuery());
|
||||
putString(KEY_DOWNLOAD_SAVE_FRAGMENT, uri.getEncodedFragment());
|
||||
|
||||
CommonOperations.ensureNoMediaFile(location);
|
||||
}
|
||||
|
||||
private static final String KEY_RECENT_DOWNLOAD_LABEL = "recent_download_label";
|
||||
@@ -636,6 +749,17 @@ public class Settings {
|
||||
putBoolean(KEY_SAVE_PARSE_ERROR_BODY, value);
|
||||
}
|
||||
|
||||
public static final String KEY_SECURITY = "security";
|
||||
public static final String DEFAULT_SECURITY = "";
|
||||
|
||||
public static String getSecurity() {
|
||||
return getString(KEY_SECURITY, DEFAULT_SECURITY);
|
||||
}
|
||||
|
||||
public static void putSecurity(String value) {
|
||||
putString(KEY_SECURITY, value);
|
||||
}
|
||||
|
||||
/********************
|
||||
****** Guide
|
||||
********************/
|
||||
@@ -682,4 +806,15 @@ public class Settings {
|
||||
public static void puttGuideDownloadLabels(boolean value) {
|
||||
putBoolean(KEY_GUIDE_DOWNLOAD_LABELS, value);
|
||||
}
|
||||
|
||||
private static final String KEY_GUIDE_GALLERY = "guide_gallery";
|
||||
private static final boolean DEFAULT_GUIDE_GALLERY = true;
|
||||
|
||||
public static boolean getGuideGallery() {
|
||||
return getBoolean(KEY_GUIDE_GALLERY, DEFAULT_GUIDE_GALLERY);
|
||||
}
|
||||
|
||||
public static void putGuideGallery(boolean value) {
|
||||
putBoolean(KEY_GUIDE_GALLERY, value);
|
||||
}
|
||||
}
|
||||
@@ -17,10 +17,12 @@
|
||||
package com.hippo.ehviewer;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.ActivityNotFoundException;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.net.Uri;
|
||||
import android.provider.Browser;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.customtabs.CustomTabsIntent;
|
||||
import android.text.TextUtils;
|
||||
import android.widget.Toast;
|
||||
@@ -36,7 +38,7 @@ public final class UrlOpener {
|
||||
private UrlOpener() {
|
||||
}
|
||||
|
||||
public static void openUrl(Activity activity, String url, boolean ehUrl, boolean customTabs) {
|
||||
public static void openUrl(@NonNull Context context, String url, boolean ehUrl, boolean customTabs) {
|
||||
if (TextUtils.isEmpty(url)) {
|
||||
return;
|
||||
}
|
||||
@@ -47,17 +49,19 @@ public final class UrlOpener {
|
||||
if (ehUrl) {
|
||||
Announcer announcer = EhUrlOpener.parseUrl(url);
|
||||
if (null != announcer) {
|
||||
intent = new Intent(activity, MainActivity.class);
|
||||
intent = new Intent(context, MainActivity.class);
|
||||
intent.setAction(StageActivity.ACTION_START_SCENE);
|
||||
intent.putExtra(StageActivity.KEY_SCENE_NAME, announcer.getClazz().getName());
|
||||
intent.putExtra(StageActivity.KEY_SCENE_ARGS, announcer.getArgs());
|
||||
activity.startActivity(intent);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
context.startActivity(intent);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// CustomTabs
|
||||
if (customTabs) {
|
||||
if (customTabs && context instanceof Activity) {
|
||||
Activity activity = (Activity) context;
|
||||
String packageName = CustomTabsHelper.getPackageNameToUseFixed(activity);
|
||||
if (packageName != null) {
|
||||
new CustomTabsIntent.Builder()
|
||||
@@ -70,15 +74,12 @@ public final class UrlOpener {
|
||||
}
|
||||
|
||||
// Intent.ACTION_VIEW
|
||||
intent = new Intent(Intent.ACTION_VIEW);
|
||||
intent.setData(uri);
|
||||
PackageManager pm = activity.getPackageManager();
|
||||
ResolveInfo ri = pm.resolveActivity(intent, 0);
|
||||
if (ri != null) {
|
||||
activity.startActivity(intent);
|
||||
return;
|
||||
intent = new Intent(Intent.ACTION_VIEW, uri);
|
||||
intent.putExtra(Browser.EXTRA_APPLICATION_ID, context.getPackageName());
|
||||
try {
|
||||
context.startActivity(intent);
|
||||
} catch (ActivityNotFoundException e) {
|
||||
Toast.makeText(context, R.string.error_cant_find_activity, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
Toast.makeText(activity, R.string.error_cant_find_activity, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
@@ -150,7 +150,7 @@ public class EhClient {
|
||||
case METHOD_SIGN_IN:
|
||||
return EhEngine.signIn(this, mOkHttpClient, (String) params[0], (String) params[1]);
|
||||
case METHOD_GET_GALLERY_LIST:
|
||||
return EhEngine.getGalleryList(this, mOkHttpClient, (String) params[0], (Boolean) params[1]);
|
||||
return EhEngine.getGalleryList(this, mOkHttpClient, (String) params[0]);
|
||||
case METHOD_FILL_GALLERY_LIST_BY_API:
|
||||
return EhEngine.fillGalleryListByApi(this, mOkHttpClient, (List<GalleryInfo>) params[0]);
|
||||
case METHOD_GET_GALLERY_DETAIL:
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
package com.hippo.ehviewer.client;
|
||||
|
||||
import android.text.TextUtils;
|
||||
import com.hippo.network.InetValidator;
|
||||
|
||||
/**
|
||||
* Some configurable stuff about EH. It ends up cookie.
|
||||
@@ -398,12 +398,12 @@ public class EhConfig implements Cloneable {
|
||||
/**
|
||||
* show warning
|
||||
*/
|
||||
private static final String CONTENT_WARNING_SHOW = "0";
|
||||
public static final String CONTENT_WARNING_SHOW = "0";
|
||||
|
||||
/**
|
||||
* not show warning
|
||||
*/
|
||||
private static final String CONTENT_WARNING_NOT_SHOW = "1";
|
||||
public static final String CONTENT_WARNING_NOT_SHOW = "1";
|
||||
|
||||
/**
|
||||
* Load images through the Hentai@Home Network<br/>
|
||||
@@ -618,13 +618,15 @@ public class EhConfig implements Cloneable {
|
||||
}
|
||||
}
|
||||
|
||||
public void setDirty() {
|
||||
public synchronized void setDirty() {
|
||||
mDirty = true;
|
||||
}
|
||||
|
||||
private void updateUconfig() {
|
||||
String hahClientIpPort = (TextUtils.isEmpty(hahClientIp) || hahClientPort == -1) ?
|
||||
"" : hahClientIp + "%3A" + hahClientPort;
|
||||
String hahClientIpPort = (InetValidator.isValidInet4Address(hahClientIp) &&
|
||||
InetValidator.isValidInetPort(hahClientPort)) ?
|
||||
hahClientIp + "%3A" + hahClientPort : "";
|
||||
String hahClientPasskey = null == this.hahClientPasskey ? "" : this.hahClientPasskey;
|
||||
mUconfig = KEY_LOAD_FROM_HAH + "_" + loadFromHAH + "-" +
|
||||
KEY_SCALE_WIDTH + "_" + scaleWidth + "-" +
|
||||
KEY_SCALE_HEIGHT + "_" + scaleHeight + "-" +
|
||||
@@ -650,7 +652,7 @@ public class EhConfig implements Cloneable {
|
||||
KEY_MULTI_PAGE_THUMB + "_" + multiPageThumb;
|
||||
}
|
||||
|
||||
public String uconfig() {
|
||||
public synchronized String uconfig() {
|
||||
if (mDirty) {
|
||||
mDirty = false;
|
||||
updateUconfig();
|
||||
|
||||
@@ -31,6 +31,15 @@ public class EhCookieStore extends CookieDBStore {
|
||||
public static final String KEY_IPD_MEMBER_ID = "ipb_member_id";
|
||||
public static final String KEY_IPD_PASS_HASH = "ipb_pass_hash";
|
||||
|
||||
public static final Cookie sTipsCookie =
|
||||
new Cookie.Builder()
|
||||
.name(EhConfig.KEY_CONTENT_WARNING)
|
||||
.value(EhConfig.CONTENT_WARNING_NOT_SHOW)
|
||||
.domain(EhUrl.DOMAIN_G)
|
||||
.path("/")
|
||||
.expiresAt(Long.MAX_VALUE)
|
||||
.build();
|
||||
|
||||
public void signOut() {
|
||||
removeAll();
|
||||
}
|
||||
@@ -68,27 +77,39 @@ public class EhCookieStore extends CookieDBStore {
|
||||
public List<Cookie> loadForRequest(HttpUrl url, Request request) {
|
||||
List<Cookie> cookies = super.loadForRequest(url, request);
|
||||
Object tag = request.tag();
|
||||
String host = url.host();
|
||||
|
||||
if (url.host().equals(EhUrl.DOMAIN_EX) && tag instanceof EhConfig) {
|
||||
EhConfig ehConfig = (EhConfig) tag;
|
||||
boolean checkTips = domainMatch(host, EhUrl.DOMAIN_G);
|
||||
boolean checkUconfig = (domainMatch(host, EhUrl.DOMAIN_E) || domainMatch(host, EhUrl.DOMAIN_EX)) && tag instanceof EhConfig;
|
||||
|
||||
if (checkTips || checkUconfig) {
|
||||
List<Cookie> result = new ArrayList<>(cookies.size() + 1);
|
||||
// Add all but skip uconfig
|
||||
// Add all but skip some
|
||||
for (Cookie cookie: cookies) {
|
||||
if (EhConfig.KEY_UCONFIG.equals(cookie.name())) {
|
||||
String name = cookie.name();
|
||||
if (checkTips && EhConfig.KEY_CONTENT_WARNING.equals(name)) {
|
||||
continue;
|
||||
}
|
||||
if (checkUconfig && EhConfig.KEY_UCONFIG.equals(name)) {
|
||||
continue;
|
||||
}
|
||||
result.add(cookie);
|
||||
}
|
||||
// Add uconfig from EhConfig
|
||||
Cookie uconfigCookie = new Cookie.Builder()
|
||||
.name(EhConfig.KEY_UCONFIG)
|
||||
.value(ehConfig.uconfig())
|
||||
.domain(EhUrl.DOMAIN_EX)
|
||||
.path("/")
|
||||
.build();
|
||||
result.add(uconfigCookie);
|
||||
|
||||
// Add some
|
||||
if (checkTips) {
|
||||
result.add(sTipsCookie);
|
||||
}
|
||||
if (checkUconfig) {
|
||||
EhConfig ehConfig = (EhConfig) tag;
|
||||
Cookie uconfigCookie = new Cookie.Builder()
|
||||
.name(EhConfig.KEY_UCONFIG)
|
||||
.value(ehConfig.uconfig())
|
||||
.domain(host)
|
||||
.path("/")
|
||||
.expiresAt(Long.MAX_VALUE)
|
||||
.build();
|
||||
result.add(uconfigCookie);
|
||||
}
|
||||
return Collections.unmodifiableList(result);
|
||||
} else {
|
||||
return cookies;
|
||||
|
||||
@@ -49,6 +49,8 @@ import com.hippo.yorozuya.IOUtils;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Document;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
@@ -79,6 +81,12 @@ public class EhEngine {
|
||||
|
||||
public static final MediaType JSON = MediaType.parse("application/json; charset=utf-8");
|
||||
|
||||
public static EhFilter sEhFilter;
|
||||
|
||||
public static void initialize() {
|
||||
sEhFilter = EhFilter.getInstance();
|
||||
}
|
||||
|
||||
private static void saveParseErrorBody(ParseException e) {
|
||||
File dir = AppConfig.getExternalParseErrorDir();
|
||||
if (null == dir) {
|
||||
@@ -169,7 +177,7 @@ public class EhEngine {
|
||||
}
|
||||
|
||||
public static GalleryListParser.Result getGalleryList(EhClient.Task task, OkHttpClient okHttpClient,
|
||||
String url, boolean callApi) throws Exception {
|
||||
String url) throws Exception {
|
||||
Log.d(TAG, url);
|
||||
Request request = new EhRequestBuilder(url, task.getEhConfig()).build();
|
||||
Call call = okHttpClient.newCall(request);
|
||||
@@ -192,8 +200,30 @@ public class EhEngine {
|
||||
throw e;
|
||||
}
|
||||
|
||||
if (callApi && result.galleryInfos.size() > 0) {
|
||||
fillGalleryListByApi(task, okHttpClient, result.galleryInfos);
|
||||
// Filter title and uploader
|
||||
List<GalleryInfo> list = result.galleryInfos;
|
||||
for (int i = 0, n = list.size(); i < n; i++) {
|
||||
GalleryInfo info = list.get(i);
|
||||
if (!sEhFilter.filterTitle(info) || !sEhFilter.filterUploader(info)) {
|
||||
list.remove(i);
|
||||
i--;
|
||||
n--;
|
||||
}
|
||||
}
|
||||
|
||||
if (list.size() > 0 && (Settings.getShowJpnTitle() || sEhFilter.needCallApi())) {
|
||||
// Fill by api
|
||||
fillGalleryListByApi(task, okHttpClient, list);
|
||||
|
||||
// Filter tag
|
||||
for (int i = 0, n = list.size(); i < n; i++) {
|
||||
GalleryInfo info = list.get(i);
|
||||
if (!sEhFilter.filterTag(info)) {
|
||||
list.remove(i);
|
||||
i--;
|
||||
n--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
@@ -229,7 +259,7 @@ public class EhEngine {
|
||||
}
|
||||
json.put("gidlist", ja);
|
||||
json.put("namespace", 1);
|
||||
String url = EhUrl.API_EX;
|
||||
String url = EhUrl.getApiUrl();
|
||||
Log.d(TAG, url);
|
||||
Request request = new EhRequestBuilder(url)
|
||||
.post(RequestBody.create(JSON, json.toString()))
|
||||
@@ -296,8 +326,9 @@ public class EhEngine {
|
||||
code = response.code();
|
||||
headers = response.headers();
|
||||
body = response.body().string();
|
||||
return Pair.create(GalleryDetailParser.parseLargePreview(body),
|
||||
GalleryDetailParser.parsePreviewPages(body));
|
||||
Document document = Jsoup.parse(body);
|
||||
return Pair.create(GalleryDetailParser.parseLargePreviewSet(document, body),
|
||||
GalleryDetailParser.parsePreviewPages(document, body));
|
||||
} catch (Exception e) {
|
||||
throwException(call, code, headers, body, e);
|
||||
throw e;
|
||||
@@ -314,7 +345,7 @@ public class EhEngine {
|
||||
json.put("token", token);
|
||||
json.put("rating", (int) Math.ceil(rating * 2));
|
||||
final RequestBody requestBody = RequestBody.create(JSON, json.toString());
|
||||
String url = EhUrl.API_EX;
|
||||
String url = EhUrl.getApiUrl();
|
||||
Log.d(TAG, url);
|
||||
Request request = new EhRequestBuilder(url, task.getEhConfig())
|
||||
.post(requestBody)
|
||||
@@ -361,7 +392,8 @@ public class EhEngine {
|
||||
code = response.code();
|
||||
headers = response.headers();
|
||||
body = response.body().string();
|
||||
return GalleryDetailParser.parseComment(body);
|
||||
Document document = Jsoup.parse(body);
|
||||
return GalleryDetailParser.parseComments(document);
|
||||
} catch (Exception e) {
|
||||
throwException(call, code, headers, body, e);
|
||||
throw e;
|
||||
@@ -375,7 +407,7 @@ public class EhEngine {
|
||||
.put("pagelist", new JSONArray().put(
|
||||
new JSONArray().put(gid).put(gtoken).put(page + 1)));
|
||||
final RequestBody requestBody = RequestBody.create(JSON, json.toString());
|
||||
String url = EhUrl.API_EX;
|
||||
String url = EhUrl.getApiUrl();
|
||||
Log.d(TAG, url);
|
||||
Request request = new EhRequestBuilder(url, task.getEhConfig())
|
||||
.post(requestBody)
|
||||
@@ -572,19 +604,45 @@ public class EhEngine {
|
||||
|
||||
String body = null;
|
||||
Headers headers = null;
|
||||
List<GalleryInfo> list;
|
||||
int code = -1;
|
||||
try {
|
||||
Response response = call.execute();
|
||||
code = response.code();
|
||||
headers = response.headers();
|
||||
body = response.body().string();
|
||||
List<GalleryInfo> list = WhatsHotParser.parse(body);
|
||||
fillGalleryListByApi(task, okHttpClient, list);
|
||||
return list;
|
||||
list = WhatsHotParser.parse(body);
|
||||
} catch (Exception e) {
|
||||
throwException(call, code, headers, body, e);
|
||||
throw e;
|
||||
}
|
||||
|
||||
// Filter title
|
||||
for (int i = 0, n = list.size(); i < n; i++) {
|
||||
GalleryInfo info = list.get(i);
|
||||
if (!sEhFilter.filterTitle(info)) {
|
||||
list.remove(i);
|
||||
i--;
|
||||
n--;
|
||||
}
|
||||
}
|
||||
|
||||
if (list.size() > 0) {
|
||||
// Fill by api
|
||||
fillGalleryListByApi(task, okHttpClient, list);
|
||||
|
||||
// Filter uploader and tag
|
||||
for (int i = 0, n = list.size(); i < n; i++) {
|
||||
GalleryInfo info = list.get(i);
|
||||
if (!sEhFilter.filterUploader(info) || !sEhFilter.filterTag(info)) {
|
||||
list.remove(i);
|
||||
i--;
|
||||
n--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
private static ProfileParser.Result getProfileInternal(EhClient.Task task,
|
||||
|
||||
@@ -0,0 +1,223 @@
|
||||
/*
|
||||
* Copyright 2016 Hippo Seven
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.hippo.ehviewer.client;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import com.hippo.ehviewer.EhDB;
|
||||
import com.hippo.ehviewer.client.data.GalleryInfo;
|
||||
import com.hippo.ehviewer.dao.Filter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public final class EhFilter {
|
||||
|
||||
private static final String TAG = EhFilter.class.getSimpleName();
|
||||
|
||||
public static final int MODE_TITLE = 0;
|
||||
public static final int MODE_UPLOADER = 1;
|
||||
public static final int MODE_TAG = 2;
|
||||
|
||||
private final List<Filter> mTitleFilterList = new ArrayList<>();
|
||||
private final List<Filter> mUploaderFilterList = new ArrayList<>();
|
||||
private final List<Filter> mTagFilterList = new ArrayList<>();
|
||||
|
||||
private static EhFilter sInstance;
|
||||
|
||||
public static EhFilter getInstance() {
|
||||
if (sInstance == null) {
|
||||
sInstance = new EhFilter();
|
||||
}
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
private EhFilter() {
|
||||
List<Filter> list = EhDB.getAllFilter();
|
||||
for (int i = 0, n = list.size(); i < n; i++) {
|
||||
Filter filter = list.get(i);
|
||||
switch (filter.mode) {
|
||||
case MODE_TITLE:
|
||||
filter.text = filter.text.toLowerCase();
|
||||
mTitleFilterList.add(filter);
|
||||
break;
|
||||
case MODE_UPLOADER:
|
||||
mUploaderFilterList.add(filter);
|
||||
break;
|
||||
case MODE_TAG:
|
||||
filter.text = filter.text.toLowerCase();
|
||||
mTagFilterList.add(filter);
|
||||
break;
|
||||
default:
|
||||
Log.d(TAG, "Unknown mode: " + filter.mode);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public List<Filter> getTitleFilterList() {
|
||||
return mTitleFilterList;
|
||||
}
|
||||
|
||||
public List<Filter> getUploaderFilterList() {
|
||||
return mUploaderFilterList;
|
||||
}
|
||||
|
||||
public List<Filter> getTagFilterList() {
|
||||
return mTagFilterList;
|
||||
}
|
||||
|
||||
public synchronized void addFilter(Filter filter) {
|
||||
EhDB.addFilter(filter);
|
||||
|
||||
switch (filter.mode) {
|
||||
case MODE_TITLE:
|
||||
filter.text = filter.text.toLowerCase();
|
||||
mTitleFilterList.add(filter);
|
||||
break;
|
||||
case MODE_UPLOADER:
|
||||
mUploaderFilterList.add(filter);
|
||||
break;
|
||||
case MODE_TAG:
|
||||
mTagFilterList.add(filter);
|
||||
break;
|
||||
default:
|
||||
Log.d(TAG, "Unknown mode: " + filter.mode);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void deleteFilter(Filter filter) {
|
||||
EhDB.deleteFilter(filter);
|
||||
|
||||
switch (filter.mode) {
|
||||
case MODE_TITLE:
|
||||
mTitleFilterList.remove(filter);
|
||||
break;
|
||||
case MODE_UPLOADER:
|
||||
mUploaderFilterList.remove(filter);
|
||||
break;
|
||||
case MODE_TAG:
|
||||
mTagFilterList.remove(filter);
|
||||
break;
|
||||
default:
|
||||
Log.d(TAG, "Unknown mode: " + filter.mode);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized boolean needCallApi() {
|
||||
return 0 != mTagFilterList.size();
|
||||
}
|
||||
|
||||
public synchronized boolean filterTitle(GalleryInfo info) {
|
||||
if (null == info) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Title
|
||||
String title = info.title;
|
||||
List<Filter> filters = mTitleFilterList;
|
||||
if (null != title && filters.size() > 0) {
|
||||
title = title.toLowerCase();
|
||||
for (int i = 0, n = filters.size(); i < n; i++) {
|
||||
if (title.contains(filters.get(i).text)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public synchronized boolean filterUploader(GalleryInfo info) {
|
||||
if (null == info) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Uploader
|
||||
String uploader = info.uploader;
|
||||
List<Filter> filters = mUploaderFilterList;
|
||||
if (null != uploader && filters.size() > 0) {
|
||||
for (int i = 0, n = filters.size(); i < n; i++) {
|
||||
if (uploader.equals(filters.get(i).text)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean matchTag(String tag, String filter) {
|
||||
if (null == tag || null == filter) {
|
||||
return false;
|
||||
}
|
||||
|
||||
String tagNamespace;
|
||||
String tagName;
|
||||
String filterNamespace;
|
||||
String filterName;
|
||||
int index = tag.indexOf(':');
|
||||
if (index < 0) {
|
||||
tagNamespace = null;
|
||||
tagName = tag;
|
||||
} else {
|
||||
tagNamespace = tag.substring(0, index);
|
||||
tagName = tag.substring(index + 1);
|
||||
}
|
||||
index = filter.indexOf(':');
|
||||
if (index < 0) {
|
||||
filterNamespace = null;
|
||||
filterName = filter;
|
||||
} else {
|
||||
filterNamespace = filter.substring(0, index);
|
||||
filterName = filter.substring(index + 1);
|
||||
}
|
||||
|
||||
if (null != tagNamespace && null != filterNamespace &&
|
||||
!tagNamespace.equals(filterNamespace)) {
|
||||
return false;
|
||||
}
|
||||
if (!tagName.equals(filterName)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public synchronized boolean filterTag(GalleryInfo info) {
|
||||
if (null == info) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Tag
|
||||
String[] tags = info.simpleTags;
|
||||
List<Filter> filters = mTagFilterList;
|
||||
if (null != tags && filters.size() > 0) {
|
||||
for (String tag: tags) {
|
||||
for (int i = 0, n = filters.size(); i < n; i++) {
|
||||
if (matchTag(tag, filters.get(i).text)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -16,10 +16,14 @@
|
||||
|
||||
package com.hippo.ehviewer.client;
|
||||
|
||||
import com.hippo.ehviewer.Settings;
|
||||
import com.hippo.network.UrlBuilder;
|
||||
|
||||
public class EhUrl {
|
||||
|
||||
public static final int SITE_G = 0;
|
||||
public static final int SITE_EX = 1;
|
||||
|
||||
public static final String DOMAIN_EX = "exhentai.org";
|
||||
public static final String DOMAIN_E = "e-hentai.org";
|
||||
public static final String DOMAIN_G = "g.e-hentai.org";
|
||||
@@ -30,19 +34,51 @@ public class EhUrl {
|
||||
|
||||
public static final String API_SIGN_IN = "http://forums.e-hentai.org/index.php?act=Login&CODE=01";
|
||||
|
||||
public static final String API_G = HOST_G + "api.php";
|
||||
public static final String API_EX = HOST_EX + "api.php";
|
||||
|
||||
public static final String URL_SIGN_IN = "http://forums.e-hentai.org/index.php?act=Login";
|
||||
public static final String URL_REGISTER = "http://forums.e-hentai.org/index.php?act=Reg&CODE=00";
|
||||
public static final String URL_FAVORITES = HOST_EX + "favorites.php";
|
||||
public static final String URL_FAVORITES_G = HOST_G + "favorites.php";
|
||||
public static final String URL_FAVORITES_EX = HOST_EX + "favorites.php";
|
||||
public static final String URL_FORUMS = "https://forums.e-hentai.org/";
|
||||
|
||||
public static String getGalleryDetailUrl(long gid, String token) {
|
||||
return getGalleryDetailUrl(gid, token, 0, false);
|
||||
}
|
||||
|
||||
public static String getHost() {
|
||||
switch (Settings.getGallerySite()) {
|
||||
default:
|
||||
case SITE_G:
|
||||
return HOST_G;
|
||||
case SITE_EX:
|
||||
return HOST_EX;
|
||||
}
|
||||
}
|
||||
|
||||
public static String getFavoritesUrl() {
|
||||
switch (Settings.getGallerySite()) {
|
||||
default:
|
||||
case SITE_G:
|
||||
return URL_FAVORITES_G;
|
||||
case SITE_EX:
|
||||
return URL_FAVORITES_EX;
|
||||
}
|
||||
}
|
||||
|
||||
public static String getApiUrl() {
|
||||
switch (Settings.getGallerySite()) {
|
||||
default:
|
||||
case SITE_G:
|
||||
return API_G;
|
||||
case SITE_EX:
|
||||
return API_EX;
|
||||
}
|
||||
}
|
||||
|
||||
public static String getGalleryDetailUrl(long gid, String token, int index, boolean allComment) {
|
||||
UrlBuilder builder = new UrlBuilder(HOST_EX + "g/" + gid + '/' + token + '/');
|
||||
UrlBuilder builder = new UrlBuilder(getHost() + "g/" + gid + '/' + token + '/');
|
||||
if (index != 0) {
|
||||
builder.addQuery("p", index);
|
||||
}
|
||||
@@ -53,10 +89,10 @@ public class EhUrl {
|
||||
}
|
||||
|
||||
public static String getPageUrl(long gid, int index, String pToken) {
|
||||
return HOST_EX + "s/" + pToken + '/' + gid + '-' + (index + 1);
|
||||
return getHost() + "s/" + pToken + '/' + gid + '-' + (index + 1);
|
||||
}
|
||||
|
||||
public static String getAddFavorites(long gid, String token) {
|
||||
return HOST_EX + "gallerypopups.php?gid=" + gid + "&t=" + token + "&act=addfav";
|
||||
return getHost() + "gallerypopups.php?gid=" + gid + "&t=" + token + "&act=addfav";
|
||||
}
|
||||
}
|
||||
@@ -119,10 +119,11 @@ public class EhUtils {
|
||||
EhApplication.getEhCookieStore(context).signOut();
|
||||
Settings.putAvatar(null);
|
||||
Settings.putDisplayName(null);
|
||||
Settings.putNeedSignIn(true);
|
||||
}
|
||||
|
||||
public static boolean hasSignedIn(Context context) {
|
||||
return EhApplication.getEhCookieStore(context).hasSignedIn();
|
||||
public static boolean needSignedIn(Context context) {
|
||||
return Settings.getNeedSignIn() && !EhApplication.getEhCookieStore(context).hasSignedIn();
|
||||
}
|
||||
|
||||
public static String getSuitableTitle(GalleryInfo gi) {
|
||||
|
||||
@@ -66,7 +66,7 @@ public class FavListUrlBuilder implements Parcelable {
|
||||
}
|
||||
|
||||
public String build() {
|
||||
UrlBuilder ub = new UrlBuilder(EhUrl.URL_FAVORITES);
|
||||
UrlBuilder ub = new UrlBuilder(EhUrl.getFavoritesUrl());
|
||||
if (isValidFavCat(mFavCat)) {
|
||||
ub.addQuery("favcat", Integer.toString(mFavCat));
|
||||
}
|
||||
|
||||
@@ -90,6 +90,13 @@ public class GalleryInfo implements Parcelable {
|
||||
@Nullable
|
||||
public String[] simpleTags;
|
||||
|
||||
public int thumbWidth;
|
||||
public int thumbHeight;
|
||||
|
||||
public int spanSize;
|
||||
public int spanIndex;
|
||||
public int spanGroupIndex;
|
||||
|
||||
/**
|
||||
* language from title
|
||||
*/
|
||||
@@ -123,6 +130,11 @@ public class GalleryInfo implements Parcelable {
|
||||
dest.writeFloat(this.rating);
|
||||
dest.writeString(this.simpleLanguage);
|
||||
dest.writeStringArray(this.simpleTags);
|
||||
dest.writeInt(this.thumbWidth);
|
||||
dest.writeInt(this.thumbHeight);
|
||||
dest.writeInt(this.spanSize);
|
||||
dest.writeInt(this.spanIndex);
|
||||
dest.writeInt(this.spanGroupIndex);
|
||||
}
|
||||
|
||||
public GalleryInfo() {}
|
||||
@@ -139,6 +151,11 @@ public class GalleryInfo implements Parcelable {
|
||||
this.rating = in.readFloat();
|
||||
this.simpleLanguage = in.readString();
|
||||
this.simpleTags = in.createStringArray();
|
||||
this.thumbWidth = in.readInt();
|
||||
this.thumbHeight = in.readInt();
|
||||
this.spanSize = in.readInt();
|
||||
this.spanIndex = in.readInt();
|
||||
this.spanGroupIndex = in.readInt();
|
||||
}
|
||||
|
||||
public static final Parcelable.Creator<GalleryInfo> CREATOR = new Parcelable.Creator<GalleryInfo>() {
|
||||
|
||||
@@ -21,10 +21,11 @@ import android.os.Parcelable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
// TODO Add url field?
|
||||
public class GalleryTagGroup implements Parcelable {
|
||||
|
||||
public String groupName;
|
||||
private ArrayList<String> mTagList;
|
||||
private final ArrayList<String> mTagList;
|
||||
|
||||
public void addTag(String tag) {
|
||||
mTagList.add(tag);
|
||||
|
||||
@@ -25,9 +25,9 @@ import java.util.ArrayList;
|
||||
|
||||
public class LargePreviewSet implements Parcelable {
|
||||
|
||||
private IntList mIndexList;
|
||||
private ArrayList<String> mImageUrlList;
|
||||
private ArrayList<String> mPageUrlList;
|
||||
private final IntList mIndexList;
|
||||
private final ArrayList<String> mImageUrlList;
|
||||
private final ArrayList<String> mPageUrlList;
|
||||
|
||||
public int size() {
|
||||
return mImageUrlList.size();
|
||||
|
||||
@@ -315,7 +315,7 @@ public class ListUrlBuilder implements Cloneable, Parcelable {
|
||||
default:
|
||||
case MODE_NORMAL: {
|
||||
boolean filter = false;
|
||||
UrlBuilder ub = new UrlBuilder(EhUrl.HOST_EX);
|
||||
UrlBuilder ub = new UrlBuilder(EhUrl.getHost());
|
||||
if (mCategory != EhUtils.NONE) {
|
||||
ub.addQuery("f_doujinshi", ((mCategory & EhConfig.DOUJINSHI) == 0) ? "0" : "1");
|
||||
ub.addQuery("f_manga", ((mCategory & EhConfig.MANGA) == 0) ? "0" : "1");
|
||||
@@ -367,7 +367,7 @@ public class ListUrlBuilder implements Cloneable, Parcelable {
|
||||
return ub.build();
|
||||
}
|
||||
case MODE_UPLOADER: {
|
||||
StringBuilder sb = new StringBuilder(EhUrl.HOST_EX);
|
||||
StringBuilder sb = new StringBuilder(EhUrl.getHost());
|
||||
sb.append("uploader/");
|
||||
try {
|
||||
sb.append(URLEncoder.encode(mKeyword, "UTF-8"));
|
||||
@@ -380,7 +380,7 @@ public class ListUrlBuilder implements Cloneable, Parcelable {
|
||||
return sb.toString();
|
||||
}
|
||||
case MODE_TAG: {
|
||||
StringBuilder sb = new StringBuilder(EhUrl.HOST_EX);
|
||||
StringBuilder sb = new StringBuilder(EhUrl.getHost());
|
||||
sb.append("tag/");
|
||||
try {
|
||||
sb.append(URLEncoder.encode(mKeyword, "UTF-8"));
|
||||
|
||||
@@ -22,13 +22,13 @@ import java.util.ArrayList;
|
||||
|
||||
public class NormalPreviewSet {
|
||||
|
||||
private IntList mIndexList = new IntList();
|
||||
private ArrayList<String> mImageUrlList = new ArrayList<>();
|
||||
private IntList mXOffsetList = new IntList();
|
||||
private IntList mYOffsetList = new IntList();
|
||||
private IntList mWidthList = new IntList();
|
||||
private IntList mHeightList = new IntList();
|
||||
private ArrayList<String> mPageUrlList = new ArrayList<>();
|
||||
private final IntList mIndexList = new IntList();
|
||||
private final ArrayList<String> mImageUrlList = new ArrayList<>();
|
||||
private final IntList mXOffsetList = new IntList();
|
||||
private final IntList mYOffsetList = new IntList();
|
||||
private final IntList mWidthList = new IntList();
|
||||
private final IntList mHeightList = new IntList();
|
||||
private final ArrayList<String> mPageUrlList = new ArrayList<>();
|
||||
|
||||
public void addItem(int index, String imageUrl, int xOffset, int yOffset, int width,
|
||||
int height, String pageUrl) {
|
||||
|
||||
@@ -1,26 +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.client.exception;
|
||||
|
||||
public class NotFoundException extends EhException {
|
||||
|
||||
public static final String MESSAGE = "Not found";
|
||||
|
||||
public NotFoundException() {
|
||||
super(MESSAGE);
|
||||
}
|
||||
}
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package com.hippo.ehviewer.client.parser;
|
||||
|
||||
import com.hippo.ehviewer.client.EhUrl;
|
||||
import com.hippo.ehviewer.client.data.GalleryInfo;
|
||||
import com.hippo.ehviewer.client.exception.ParseException;
|
||||
import com.hippo.util.JsoupUtils;
|
||||
@@ -52,7 +51,7 @@ public class FavoritesParser {
|
||||
int limit;
|
||||
|
||||
try {
|
||||
Document d = Jsoup.parse(body, EhUrl.HOST_EX);
|
||||
Document d = Jsoup.parse(body);
|
||||
Element ido = JsoupUtils.getElementByClass(d, "ido");
|
||||
Elements fps = ido.getElementsByClass("fp");
|
||||
// Last one is "fp fps"
|
||||
|
||||
@@ -16,6 +16,9 @@
|
||||
|
||||
package com.hippo.ehviewer.client.parser;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import com.hippo.ehviewer.client.EhUtils;
|
||||
import com.hippo.ehviewer.client.data.GalleryComment;
|
||||
import com.hippo.ehviewer.client.data.GalleryDetail;
|
||||
@@ -26,10 +29,17 @@ 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.JsoupUtils;
|
||||
import com.hippo.yorozuya.NumberUtils;
|
||||
|
||||
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;
|
||||
import java.util.Date;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
@@ -86,6 +96,9 @@ public class GalleryDetailParser {
|
||||
private static final Pattern NORMAL_PREVIEW_PATTERN = Pattern.compile("<div class=\"gdtm\"[^<>]*><div[^<>]*width:(\\d+)[^<>]*height:(\\d+)[^<>]*\\((.+?)\\)[^<>]*-(\\d+)px[^<>]*><a[^<>]*href=\"(.+?)\"[^<>]*><img alt=\"([\\d,]+)\"");
|
||||
private static final Pattern LARGE_PREVIEW_PATTERN = Pattern.compile("<div class=\"gdtl\".+?<a href=\"(.+?)\"><img alt=\"([\\d,]+)\".+?src=\"(.+?)\"");
|
||||
|
||||
private static final GalleryTagGroup[] EMPTY_GALLERY_TAG_GROUP_ARRAY = new GalleryTagGroup[0];
|
||||
private static final GalleryComment[] EMPTY_GALLERY_COMMENT_ARRAY = new GalleryComment[0];
|
||||
|
||||
static {
|
||||
WEB_COMMENT_DATE_FORMAT.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||
}
|
||||
@@ -112,10 +125,11 @@ public class GalleryDetailParser {
|
||||
|
||||
GalleryDetail galleryDetail = new GalleryDetail();
|
||||
parseDetail(body, galleryDetail);
|
||||
galleryDetail.tags = parseTagGroup(body);
|
||||
galleryDetail.comments = parseComment(body);
|
||||
galleryDetail.previewPages = parsePreviewPages(body);
|
||||
galleryDetail.previewSet = parseLargePreview(body);
|
||||
Document document = Jsoup.parse(body);
|
||||
galleryDetail.tags = parseTagGroups(document);
|
||||
galleryDetail.comments = parseComments(document);
|
||||
galleryDetail.previewPages = parsePreviewPages(document, body);
|
||||
galleryDetail.previewSet = parseLargePreviewSet(document, body);
|
||||
return galleryDetail;
|
||||
}
|
||||
|
||||
@@ -178,7 +192,62 @@ public class GalleryDetailParser {
|
||||
gd.isFavored = m.find() && "Favorite Gallery".equals(ParserUtils.trim(m.group(1)));
|
||||
}
|
||||
|
||||
public static GalleryTagGroup[] parseTagGroup(String body) throws EhException {
|
||||
@Nullable
|
||||
private static GalleryTagGroup parseTagGroup(Element element) {
|
||||
try {
|
||||
GalleryTagGroup group = new GalleryTagGroup();
|
||||
|
||||
String nameSpace = element.child(0).text();
|
||||
// Remove last ':'
|
||||
nameSpace = nameSpace.substring(0, nameSpace.length() - 1);
|
||||
group.groupName = nameSpace;
|
||||
|
||||
Elements tags = element.child(1).children();
|
||||
for (int i = 0, n = tags.size(); i < n; i++) {
|
||||
String tag = tags.get(i).text();
|
||||
// Sometimes parody tag is followed with '|' and english translate, just remove them
|
||||
int index = tag.indexOf('|');
|
||||
if (index >= 0) {
|
||||
tag = tag.substring(0, index);
|
||||
}
|
||||
group.addTag(tag);
|
||||
}
|
||||
|
||||
return group.size() > 0 ? group : null;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse tag groups with html parser
|
||||
*/
|
||||
@NonNull
|
||||
public static GalleryTagGroup[] parseTagGroups(Document document) {
|
||||
try {
|
||||
Element taglist = document.getElementById("taglist");
|
||||
Elements tagGroups = taglist.child(0).child(0).children();
|
||||
|
||||
List<GalleryTagGroup> list = new ArrayList<>(tagGroups.size());
|
||||
for (int i = 0, n = tagGroups.size(); i < n; i++) {
|
||||
GalleryTagGroup group = parseTagGroup(tagGroups.get(i));
|
||||
if (null != group) {
|
||||
list.add(group);
|
||||
}
|
||||
}
|
||||
return list.toArray(new GalleryTagGroup[list.size()]);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return EMPTY_GALLERY_TAG_GROUP_ARRAY;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse tag groups with regular expressions
|
||||
*/
|
||||
@NonNull
|
||||
private static GalleryTagGroup[] parseTagGroups(String body) throws EhException {
|
||||
List<GalleryTagGroup> list = new LinkedList<>();
|
||||
|
||||
Matcher m = TAG_GROUP_PATTERN.matcher(body);
|
||||
@@ -199,7 +268,52 @@ public class GalleryDetailParser {
|
||||
}
|
||||
}
|
||||
|
||||
public static GalleryComment[] parseComment(String body) {
|
||||
@Nullable
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
public static GalleryComment parseComment(Element element) {
|
||||
try {
|
||||
GalleryComment comment = new GalleryComment();
|
||||
Element c3 = JsoupUtils.getElementByClass(element, "c3");
|
||||
String temp = c3.ownText();
|
||||
temp = temp.substring("Posted on ".length(), temp.length() - " by: ".length());
|
||||
comment.time = WEB_COMMENT_DATE_FORMAT.parse(temp).getTime();
|
||||
comment.user = c3.child(0).text();
|
||||
comment.comment = JsoupUtils.getElementByClass(element, "c6").html();
|
||||
return comment;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse comments with html parser
|
||||
*/
|
||||
@NonNull
|
||||
public static GalleryComment[] parseComments(Document document) {
|
||||
try {
|
||||
Element cdiv = document.getElementById("cdiv");
|
||||
Elements c1s = cdiv.getElementsByClass("c1");
|
||||
|
||||
List<GalleryComment> list = new ArrayList<>(c1s.size());
|
||||
for (int i = 0, n = c1s.size(); i < n; i++) {
|
||||
GalleryComment comment = parseComment(c1s.get(i));
|
||||
if (null != comment) {
|
||||
list.add(comment);
|
||||
}
|
||||
}
|
||||
return list.toArray(new GalleryComment[list.size()]);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return EMPTY_GALLERY_COMMENT_ARRAY;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse comments with regular expressions
|
||||
*/
|
||||
@NonNull
|
||||
public static GalleryComment[] parseComments(String body) {
|
||||
List<GalleryComment> list = new LinkedList<>();
|
||||
|
||||
Matcher m = COMMENT_PATTERN.matcher(body);
|
||||
@@ -221,6 +335,22 @@ public class GalleryDetailParser {
|
||||
return list.toArray(new GalleryComment[list.size()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse preview pages with html parser
|
||||
*/
|
||||
public static int parsePreviewPages(Document document, String body) throws ParseException {
|
||||
try {
|
||||
Elements elements = document.getElementsByClass("ptt").first().child(0).child(0).children();
|
||||
return Integer.parseInt(elements.get(elements.size() - 2).text());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new ParseException("Can't parse preview pages", body);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse preview pages with regular expressions
|
||||
*/
|
||||
public static int parsePreviewPages(String body) throws ParseException {
|
||||
Matcher m = PREVIEW_PAGES_PATTERN.matcher(body);
|
||||
int previewPages = -1;
|
||||
@@ -235,6 +365,9 @@ public class GalleryDetailParser {
|
||||
return previewPages;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse pages with regular expressions
|
||||
*/
|
||||
public static int parsePages(String body) throws ParseException {
|
||||
Matcher m = PAGES_PATTERN.matcher(body);
|
||||
if (m.find()) {
|
||||
@@ -244,7 +377,37 @@ public class GalleryDetailParser {
|
||||
}
|
||||
}
|
||||
|
||||
public static LargePreviewSet parseLargePreview(String body) throws ParseException {
|
||||
/**
|
||||
* Parse large previews with regular expressions
|
||||
*/
|
||||
public static LargePreviewSet parseLargePreviewSet(Document document, String body) throws ParseException {
|
||||
try {
|
||||
LargePreviewSet largePreviewSet = new LargePreviewSet();
|
||||
Element gdt = document.getElementById("gdt");
|
||||
Elements gdtls = gdt.getElementsByClass("gdtl");
|
||||
int n = gdtls.size();
|
||||
if (n <= 0) {
|
||||
throw new ParseException("Can't parse large preview", body);
|
||||
}
|
||||
for (int i = 0; i < n; i++) {
|
||||
Element element = gdtls.get(i).child(0);
|
||||
String pageUrl = element.attr("href");
|
||||
element = element.child(0);
|
||||
String imageUrl = element.attr("src");
|
||||
int index = Integer.parseInt(element.attr("alt")) - 1;
|
||||
largePreviewSet.addItem(index, imageUrl, pageUrl);
|
||||
}
|
||||
return largePreviewSet;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new ParseException("Can't parse large preview", body);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse large previews with regular expressions
|
||||
*/
|
||||
public static LargePreviewSet parseLargePreviewSet(String body) throws ParseException {
|
||||
Matcher m = LARGE_PREVIEW_PATTERN.matcher(body);
|
||||
LargePreviewSet largePreviewSet = new LargePreviewSet();
|
||||
|
||||
@@ -260,6 +423,9 @@ public class GalleryDetailParser {
|
||||
return largePreviewSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse normal previews with regular expressions
|
||||
*/
|
||||
public static NormalPreviewSet parseNormalPreviewSet(String body) throws ParseException {
|
||||
Matcher m = NORMAL_PREVIEW_PATTERN.matcher(body);
|
||||
NormalPreviewSet normalPreviewSet = new NormalPreviewSet();
|
||||
@@ -276,5 +442,4 @@ public class GalleryDetailParser {
|
||||
|
||||
return normalPreviewSet;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -20,11 +20,11 @@ import android.support.annotation.NonNull;
|
||||
|
||||
import com.hippo.ehviewer.client.EhUtils;
|
||||
import com.hippo.ehviewer.client.data.GalleryInfo;
|
||||
import com.hippo.ehviewer.client.exception.NotFoundException;
|
||||
import com.hippo.ehviewer.client.exception.ParseException;
|
||||
import com.hippo.yorozuya.NumberUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
@@ -52,6 +52,7 @@ public class GalleryListParser {
|
||||
public List<GalleryInfo> galleryInfos;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static Result parse(@NonNull String body) throws Exception {
|
||||
Result result = new Result();
|
||||
Matcher m;
|
||||
@@ -61,7 +62,8 @@ public class GalleryListParser {
|
||||
if (m.find()) {
|
||||
result.pages = ParserUtils.parseInt(m.group(1));
|
||||
} else if (body.contains("No hits found</p>")) {
|
||||
throw new NotFoundException();
|
||||
result.pages = 0;
|
||||
result.galleryInfos = Collections.EMPTY_LIST;
|
||||
} else {
|
||||
// Can not get page number
|
||||
throw new ParseException("Can't parse gallery list", body);
|
||||
@@ -77,8 +79,8 @@ public class GalleryListParser {
|
||||
|
||||
gi.category = EhUtils.getCategory(ParserUtils.trim(m.group(1)));
|
||||
gi.posted = ParserUtils.trim(m.group(2));
|
||||
//gi.thumbHeight = ParserUtils.parseInt(m.group(3));
|
||||
//gi.thumbWidth = ParserUtils.parseInt(m.group(4));
|
||||
gi.thumbHeight = ParserUtils.parseInt(m.group(3));
|
||||
gi.thumbWidth = ParserUtils.parseInt(m.group(4));
|
||||
|
||||
if (m.group(5) == null) {
|
||||
gi.thumb = ParserUtils.trim("http://" + m.group(7).replace('~', '/'));
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package com.hippo.ehviewer.client.parser;
|
||||
|
||||
import com.hippo.ehviewer.client.EhUrl;
|
||||
import com.hippo.ehviewer.client.data.GalleryInfo;
|
||||
import com.hippo.ehviewer.client.exception.ParseException;
|
||||
import com.hippo.util.JsoupUtils;
|
||||
@@ -35,7 +34,7 @@ public class WhatsHotParser {
|
||||
public static List<GalleryInfo> parse(String body) throws ParseException {
|
||||
try {
|
||||
List<GalleryInfo> galleryInfoList = new ArrayList<>(15);
|
||||
Document d = Jsoup.parse(body, EhUrl.HOST_G);
|
||||
Document d = Jsoup.parse(body);
|
||||
Element pp = d.getElementById("pp");
|
||||
Elements id1List = pp.getElementsByClass("id1");
|
||||
for (int i = 0, n = id1List.size(); i < n; i++) {
|
||||
|
||||
@@ -64,8 +64,8 @@ public class GalleryView extends GLView implements GestureRecognizer.Listener {
|
||||
|
||||
private static final float[] LEFT_AREA = {0.0f, 0.0f, 1.0f / 3.0f, 1f};
|
||||
private static final float[] RIGHT_AREA = {2.0f / 3.0f, 0.0f, 1.0f, 1f};
|
||||
private static final float[] MENU_AREA = {1.0f / 3.0f, 0.0f, 2.0f / 3.0f, 3.0f / 4.0f};
|
||||
private static final float[] SLIDER_AREA = {1.0f / 3.0f, 3.0f / 4.0f, 2.0f / 3.0f, 1.0f};
|
||||
private static final float[] MENU_AREA = {1.0f / 3.0f, 0.0f, 2.0f / 3.0f, 2.0f / 3.0f};
|
||||
private static final float[] SLIDER_AREA = {1.0f / 3.0f, 2.0f / 3.0f, 2.0f / 3.0f, 1.0f};
|
||||
|
||||
private static final int METHOD_ON_SINGLE_TAP_UP = 0;
|
||||
private static final int METHOD_ON_SINGLE_TAP_CONFIRMED = 1;
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Copyright 2016 Hippo Seven
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.hippo.ehviewer.preference;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.util.AttributeSet;
|
||||
|
||||
import com.hippo.ehviewer.EhDB;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.preference.MessagePreference;
|
||||
|
||||
public class ClearDownloadPathCachePreference extends MessagePreference {
|
||||
|
||||
public ClearDownloadPathCachePreference(Context context) {
|
||||
super(context);
|
||||
init(context);
|
||||
}
|
||||
|
||||
public ClearDownloadPathCachePreference(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
init(context);
|
||||
}
|
||||
|
||||
public ClearDownloadPathCachePreference(Context context,
|
||||
AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
init(context);
|
||||
}
|
||||
|
||||
public ClearDownloadPathCachePreference(Context context,
|
||||
AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
||||
super(context, attrs, defStyleAttr, defStyleRes);
|
||||
init(context);
|
||||
}
|
||||
|
||||
public void init(Context context) {
|
||||
setDialogMessage(context.getString(R.string.settings_advanced_clear_download_path_cache_message));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPrepareDialogBuilder(AlertDialog.Builder builder) {
|
||||
super.onPrepareDialogBuilder(builder);
|
||||
builder.setTitle(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDialogClosed(boolean positiveResult) {
|
||||
super.onDialogClosed(positiveResult);
|
||||
|
||||
if (positiveResult) {
|
||||
EhDB.clearDownloadDirname();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,197 @@
|
||||
/*
|
||||
* Copyright 2016 Hippo Seven
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.hippo.ehviewer.preference;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.design.widget.TextInputLayout;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.support.v7.widget.SwitchCompat;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
import android.widget.EditText;
|
||||
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.Settings;
|
||||
import com.hippo.network.InetValidator;
|
||||
import com.hippo.preference.DialogPreference;
|
||||
import com.hippo.yorozuya.ViewUtils;
|
||||
|
||||
public class HatHProxyPreference extends DialogPreference implements View.OnClickListener {
|
||||
|
||||
@Nullable
|
||||
private SwitchCompat mEnable;
|
||||
@Nullable
|
||||
private TextInputLayout mIpInputLayout;
|
||||
@Nullable
|
||||
private EditText mIp;
|
||||
@Nullable
|
||||
private TextInputLayout mPortInputLayout;
|
||||
@Nullable
|
||||
private EditText mPort;
|
||||
@Nullable
|
||||
private TextInputLayout mPasskeyInputLayout;
|
||||
@Nullable
|
||||
private EditText mPasskey;
|
||||
|
||||
public HatHProxyPreference(Context context) {
|
||||
super(context);
|
||||
init();
|
||||
}
|
||||
|
||||
public HatHProxyPreference(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
init();
|
||||
}
|
||||
|
||||
public HatHProxyPreference(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
init();
|
||||
}
|
||||
|
||||
public HatHProxyPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
||||
super(context, attrs, defStyleAttr, defStyleRes);
|
||||
init();
|
||||
}
|
||||
|
||||
private void init() {
|
||||
setDialogLayoutResource(R.layout.preference_dialog_hath_proxy);
|
||||
updateSummary(Settings.getHathProxy(), Settings.getHathIp(), Settings.getHathPort());
|
||||
}
|
||||
|
||||
private void updateSummary(boolean hathProxy, String hathIp, int hathPort) {
|
||||
if (InetValidator.isValidInet4Address(hathIp) && InetValidator.isValidInetPort(hathPort)) {
|
||||
Context context = getContext();
|
||||
setSummary(context.getString(R.string.settings_eh_hath_proxy_summary_1,
|
||||
context.getString(hathProxy ? R.string.enabled : R.string.disabled), hathIp, hathPort));
|
||||
} else {
|
||||
setSummary(R.string.settings_eh_hath_proxy_summary_2);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPrepareDialogBuilder(AlertDialog.Builder builder) {
|
||||
super.onPrepareDialogBuilder(builder);
|
||||
builder.setPositiveButton(android.R.string.ok, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressLint("SetTextI18n")
|
||||
protected void onDialogCreated(AlertDialog dialog) {
|
||||
super.onDialogCreated(dialog);
|
||||
|
||||
dialog.getButton(DialogInterface.BUTTON_POSITIVE).setOnClickListener(this);
|
||||
|
||||
mEnable = (SwitchCompat) ViewUtils.$$(dialog, R.id.enable);
|
||||
mIpInputLayout = (TextInputLayout) ViewUtils.$$(dialog, R.id.ip_input_layout);
|
||||
mIp = (EditText) ViewUtils.$$(dialog, R.id.ip);
|
||||
mPortInputLayout = (TextInputLayout) ViewUtils.$$(dialog, R.id.port_input_layout);
|
||||
mPort = (EditText) ViewUtils.$$(dialog, R.id.port);
|
||||
mPasskeyInputLayout = (TextInputLayout) ViewUtils.$$(dialog, R.id.passkey_input_layout);
|
||||
mPasskey = (EditText) ViewUtils.$$(dialog, R.id.passkey);
|
||||
|
||||
mEnable.setChecked(Settings.getHathProxy());
|
||||
String ip = Settings.getHathIp();
|
||||
if (!InetValidator.isValidInet4Address(ip)) {
|
||||
ip = null;
|
||||
}
|
||||
String portString;
|
||||
int port = Settings.getHathPort();
|
||||
if (!InetValidator.isValidInetPort(port)) {
|
||||
portString = null;
|
||||
} else {
|
||||
portString = Integer.toString(Settings.getHathPort());
|
||||
}
|
||||
mIp.setText(ip);
|
||||
mPort.setText(portString);
|
||||
mPasskey.setText(Settings.getHathPasskey());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDialogClosed(boolean positiveResult) {
|
||||
super.onDialogClosed(positiveResult);
|
||||
mEnable = null;
|
||||
mIpInputLayout = null;
|
||||
mIp = null;
|
||||
mPortInputLayout = null;
|
||||
mPort = null;
|
||||
mPasskeyInputLayout = null;
|
||||
mPasskey = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Dialog dialog = getDialog();
|
||||
Context context = getContext();
|
||||
if (null == dialog || null == context || null == mEnable ||
|
||||
null == mIpInputLayout || null == mIp ||
|
||||
null == mPortInputLayout || null == mPort ||
|
||||
null == mPasskeyInputLayout || null == mPasskey) {
|
||||
return;
|
||||
}
|
||||
|
||||
boolean enable = mEnable.isChecked();
|
||||
|
||||
String ip = mIp.getText().toString().trim();
|
||||
if (ip.isEmpty()) {
|
||||
if (enable) {
|
||||
mIpInputLayout.setError(context.getString(R.string.text_is_empty));
|
||||
return;
|
||||
}
|
||||
} else if (!InetValidator.isValidInet4Address(ip)) {
|
||||
mIpInputLayout.setError(context.getString(R.string.domain_not_supported));
|
||||
return;
|
||||
} else {
|
||||
mIpInputLayout.setError(null);
|
||||
}
|
||||
|
||||
int port;
|
||||
String portString = mPort.getText().toString().trim();
|
||||
if (portString.isEmpty()) {
|
||||
if (enable) {
|
||||
mPortInputLayout.setError(context.getString(R.string.text_is_empty));
|
||||
return;
|
||||
} else {
|
||||
port = -1;
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
port = Integer.parseInt(portString);
|
||||
} catch (NumberFormatException e) {
|
||||
port = -1;
|
||||
}
|
||||
if (!InetValidator.isValidInetPort(port)) {
|
||||
mPortInputLayout.setError(context.getString(R.string.invalid_port));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
String passkey = mPasskey.getText().toString();
|
||||
|
||||
Settings.putHathProxy(enable);
|
||||
Settings.putHathIp(ip);
|
||||
Settings.putHathPort(port);
|
||||
Settings.putHathPasskey(passkey);
|
||||
|
||||
updateSummary(enable, ip, port);
|
||||
|
||||
dialog.dismiss();
|
||||
}
|
||||
}
|
||||
@@ -30,6 +30,7 @@ import com.hippo.ehviewer.client.data.GalleryInfo;
|
||||
import com.hippo.ehviewer.gallery.GalleryProvider;
|
||||
import com.hippo.io.UniFileInputStreamPipe;
|
||||
import com.hippo.io.UniFileOutputStreamPipe;
|
||||
import com.hippo.unifile.FilenameFilter;
|
||||
import com.hippo.unifile.UniFile;
|
||||
import com.hippo.yorozuya.FileUtils;
|
||||
import com.hippo.yorozuya.IOUtils;
|
||||
@@ -56,16 +57,54 @@ public final class SpiderDen {
|
||||
sCache = new SimpleDiskCache(new File(context.getCacheDir(), "image"), 160 * 1024 * 1024);
|
||||
}
|
||||
|
||||
private static class StartWithFilenameFilter implements FilenameFilter {
|
||||
|
||||
private final String mPrefix;
|
||||
|
||||
public StartWithFilenameFilter(String prefix) {
|
||||
mPrefix = prefix;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean accept(UniFile dir, String filename) {
|
||||
return filename.startsWith(mPrefix);
|
||||
}
|
||||
}
|
||||
|
||||
public static UniFile getGalleryDownloadDir(GalleryInfo galleryInfo) {
|
||||
UniFile dir = Settings.getDownloadLocation();
|
||||
if (dir != null) {
|
||||
// Read from DB
|
||||
String dirname = EhDB.getDownloadDirname(galleryInfo.gid);
|
||||
if (dirname == null) {
|
||||
|
||||
// Find it
|
||||
if (null == dirname) {
|
||||
UniFile[] files = dir.listFiles(new StartWithFilenameFilter(galleryInfo.gid + "-"));
|
||||
if (null != files) {
|
||||
// Get max-length-name dir
|
||||
int maxLength = -1;
|
||||
for (UniFile file : files) {
|
||||
if (file.isDirectory()) {
|
||||
String name = file.getName();
|
||||
int length = name.length();
|
||||
if (length > maxLength) {
|
||||
maxLength = length;
|
||||
dirname = name;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (null != dirname) {
|
||||
EhDB.putDownloadDirname(galleryInfo.gid, dirname);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Create it
|
||||
if (null == dirname) {
|
||||
dirname = FileUtils.sanitizeFilename(galleryInfo.gid + "-" + EhUtils.getSuitableTitle(galleryInfo));
|
||||
// Put into DB
|
||||
EhDB.putDownloadDirname(galleryInfo.gid, dirname);
|
||||
}
|
||||
|
||||
return dir.subFile(dirname);
|
||||
} else {
|
||||
return null;
|
||||
|
||||
@@ -34,7 +34,6 @@ public class SpiderInfo {
|
||||
private static final String TAG = SpiderInfo.class.getSimpleName();
|
||||
|
||||
static final String TOKEN_FAILED = "failed";
|
||||
static final String TOKEN_WAIT = "wait";
|
||||
|
||||
int startPage = 0;
|
||||
long gid = -1;
|
||||
@@ -95,11 +94,8 @@ public class SpiderInfo {
|
||||
spiderInfo.gid = Long.parseLong(IOUtils.readAsciiLine(is));
|
||||
// Token
|
||||
spiderInfo.token = IOUtils.readAsciiLine(is);
|
||||
// Deprecated, mode, only ex is support now, MUST be 1
|
||||
if (1 != Integer.parseInt(IOUtils.readAsciiLine(is))) {
|
||||
Log.w(TAG, "Not ex mode");
|
||||
return null;
|
||||
}
|
||||
// Deprecated, mode, skip it
|
||||
IOUtils.readAsciiLine(is);
|
||||
// Preview pages
|
||||
spiderInfo.previewPages = Integer.parseInt(IOUtils.readAsciiLine(is));
|
||||
// Preview pre page
|
||||
|
||||
@@ -37,6 +37,7 @@ import com.hippo.ehviewer.client.EhConfig;
|
||||
import com.hippo.ehviewer.client.EhRequestBuilder;
|
||||
import com.hippo.ehviewer.client.EhUrl;
|
||||
import com.hippo.ehviewer.client.data.GalleryInfo;
|
||||
import com.hippo.ehviewer.client.data.LargePreviewSet;
|
||||
import com.hippo.ehviewer.client.data.NormalPreviewSet;
|
||||
import com.hippo.ehviewer.client.exception.Image509Exception;
|
||||
import com.hippo.ehviewer.client.exception.ParseException;
|
||||
@@ -63,13 +64,12 @@ import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.net.MalformedURLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Queue;
|
||||
import java.util.Set;
|
||||
import java.util.Stack;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
import java.util.concurrent.ThreadFactory;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
@@ -140,7 +140,7 @@ public class SpiderQueen implements Runnable {
|
||||
|
||||
private final Object mPTokenLock = new Object();
|
||||
private volatile SpiderInfo mSpiderInfo;
|
||||
private final Queue<Integer> mRequestPTokenQueue = new LinkedList<>();
|
||||
private final Queue<Integer> mRequestPTokenQueue = new ConcurrentLinkedQueue<>();
|
||||
|
||||
private final Object mPageStateLock = new Object();
|
||||
private volatile int[] mPageStateArray;
|
||||
@@ -154,8 +154,6 @@ public class SpiderQueen implements Runnable {
|
||||
// For download, when it go to mPageStateArray.size(), done
|
||||
private volatile int mDownloadPage = -1;
|
||||
|
||||
private final Set<Integer> mRequestPreviewPageSet = new HashSet<>();
|
||||
|
||||
private final AtomicInteger mDownloadedPages = new AtomicInteger(0);
|
||||
private final AtomicInteger mFinishedPages = new AtomicInteger(0);
|
||||
|
||||
@@ -681,6 +679,28 @@ public class SpiderQueen implements Runnable {
|
||||
return null;
|
||||
}
|
||||
|
||||
private void readPreviews(String body, SpiderInfo spiderInfo) throws ParseException {
|
||||
try {
|
||||
NormalPreviewSet previewSet = GalleryDetailParser.parseNormalPreviewSet(body);
|
||||
spiderInfo.previewPerPage = previewSet.size();
|
||||
for (int i = 0, n = previewSet.size(); i < n; i++) {
|
||||
GalleryPageUrlParser.Result result = GalleryPageUrlParser.parse(previewSet.getPageUrlAt(i));
|
||||
if (result != null) {
|
||||
spiderInfo.pTokenMap.put(result.page, result.pToken);
|
||||
}
|
||||
}
|
||||
} catch (ParseException e) {
|
||||
LargePreviewSet previewSet = GalleryDetailParser.parseLargePreviewSet(body);
|
||||
spiderInfo.previewPerPage = previewSet.size();
|
||||
for (int i = 0, n = previewSet.size(); i < n; i++) {
|
||||
GalleryPageUrlParser.Result result = GalleryPageUrlParser.parse(previewSet.getPageUrlAt(i));
|
||||
if (result != null) {
|
||||
spiderInfo.pTokenMap.put(result.page, result.pToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private SpiderInfo readSpiderInfoFromInternet(EhConfig config) {
|
||||
try {
|
||||
SpiderInfo spiderInfo = new SpiderInfo();
|
||||
@@ -693,17 +713,9 @@ public class SpiderQueen implements Runnable {
|
||||
String body = response.body().string();
|
||||
|
||||
spiderInfo.pages = GalleryDetailParser.parsePages(body);
|
||||
spiderInfo.previewPages = GalleryDetailParser.parsePreviewPages(body);
|
||||
NormalPreviewSet previewSet = GalleryDetailParser.parseNormalPreviewSet(body);
|
||||
spiderInfo.previewPerPage = previewSet.size();
|
||||
spiderInfo.pTokenMap = new SparseArray<>(spiderInfo.pages);
|
||||
for (int i = 0, n = previewSet.size(); i < n; i++) {
|
||||
GalleryPageUrlParser.Result result = GalleryPageUrlParser.parse(previewSet.getPageUrlAt(i));
|
||||
if (result != null) {
|
||||
spiderInfo.pTokenMap.put(result.page, result.pToken);
|
||||
}
|
||||
}
|
||||
|
||||
spiderInfo.previewPages = GalleryDetailParser.parsePreviewPages(body);
|
||||
readPreviews(body, spiderInfo);
|
||||
return spiderInfo;
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
@@ -713,12 +725,6 @@ public class SpiderQueen implements Runnable {
|
||||
private String getPTokenFromInternet(int index, EhConfig config) {
|
||||
// Check previewIndex
|
||||
int previewIndex = index / mSpiderInfo.previewPerPage;
|
||||
synchronized (mRequestPreviewPageSet) {
|
||||
if (mRequestPreviewPageSet.contains(previewIndex)) {
|
||||
return SpiderInfo.TOKEN_WAIT;
|
||||
}
|
||||
mRequestPreviewPageSet.add(previewIndex);
|
||||
}
|
||||
|
||||
try {
|
||||
String url = EhUrl.getGalleryDetailUrl(
|
||||
@@ -729,23 +735,15 @@ public class SpiderQueen implements Runnable {
|
||||
Request request = new EhRequestBuilder(url, config).build();
|
||||
Response response = mHttpClient.newCall(request).execute();
|
||||
String body = response.body().string();
|
||||
NormalPreviewSet previewSet = GalleryDetailParser.parseNormalPreviewSet(body);
|
||||
synchronized (mPTokenLock) {
|
||||
for (int i = 0, n = previewSet.size(); i < n; i++) {
|
||||
GalleryPageUrlParser.Result result = GalleryPageUrlParser.parse(previewSet.getPageUrlAt(i));
|
||||
if (result != null) {
|
||||
mSpiderInfo.pTokenMap.put(result.page, result.pToken);
|
||||
}
|
||||
}
|
||||
writeSpiderInfoToLocal(mSpiderInfo);
|
||||
}
|
||||
mSpiderInfo.previewPages = GalleryDetailParser.parsePreviewPages(body);
|
||||
readPreviews(body, mSpiderInfo);
|
||||
|
||||
// Save to local
|
||||
writeSpiderInfoToLocal(mSpiderInfo);
|
||||
|
||||
return mSpiderInfo.pTokenMap.get(index);
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
} finally {
|
||||
synchronized (mRequestPreviewPageSet) {
|
||||
mRequestPreviewPageSet.remove(previewIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -831,10 +829,7 @@ public class SpiderQueen implements Runnable {
|
||||
|
||||
// handle pToken request
|
||||
while (!Thread.currentThread().isInterrupted()) {
|
||||
Integer index;
|
||||
synchronized (mPTokenLock) {
|
||||
index = mRequestPTokenQueue.poll();
|
||||
}
|
||||
Integer index = mRequestPTokenQueue.poll();
|
||||
|
||||
if (index == null) {
|
||||
// No request index, wait here
|
||||
@@ -863,8 +858,12 @@ public class SpiderQueen implements Runnable {
|
||||
|
||||
// Get pToken from internet
|
||||
pToken = getPTokenFromInternet(index, config);
|
||||
if (null == pToken) {
|
||||
// Preview size may changed, so try to get pToken twice
|
||||
pToken = getPTokenFromInternet(index, config);
|
||||
}
|
||||
|
||||
if (null == pToken || SpiderInfo.TOKEN_WAIT.equals(pToken)) {
|
||||
if (null == pToken) {
|
||||
// If failed, set the pToken "failed"
|
||||
synchronized (mPTokenLock) {
|
||||
mSpiderInfo.pTokenMap.put(index, SpiderInfo.TOKEN_FAILED);
|
||||
@@ -872,10 +871,8 @@ public class SpiderQueen implements Runnable {
|
||||
}
|
||||
|
||||
// Notify worker
|
||||
if (!SpiderInfo.TOKEN_WAIT.equals(pToken)) {
|
||||
synchronized (mWorkerLock) {
|
||||
mWorkerLock.notifyAll();
|
||||
}
|
||||
synchronized (mWorkerLock) {
|
||||
mWorkerLock.notifyAll();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,13 +37,17 @@ import com.hippo.ehviewer.client.data.GalleryInfo;
|
||||
import com.hippo.ehviewer.dao.DownloadLabel;
|
||||
import com.hippo.ehviewer.download.DownloadManager;
|
||||
import com.hippo.ehviewer.download.DownloadService;
|
||||
import com.hippo.ehviewer.ui.scene.BaseScene;
|
||||
import com.hippo.text.Html;
|
||||
import com.hippo.unifile.UniFile;
|
||||
import com.hippo.yorozuya.FileUtils;
|
||||
import com.hippo.yorozuya.IOUtils;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.List;
|
||||
|
||||
import okhttp3.OkHttpClient;
|
||||
@@ -216,7 +220,8 @@ public final class CommonOperations {
|
||||
client.execute(request);
|
||||
}
|
||||
|
||||
public static void startDownload(final Activity activity, final GalleryInfo galleryInfo, boolean forceDefault) {
|
||||
// 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);
|
||||
|
||||
boolean justStart = forceDefault || dm.containDownloadInfo(galleryInfo.gid);
|
||||
@@ -239,6 +244,8 @@ public final class CommonOperations {
|
||||
intent.putExtra(DownloadService.KEY_LABEL, label);
|
||||
intent.putExtra(DownloadService.KEY_GALLERY_INFO, galleryInfo);
|
||||
activity.startService(intent);
|
||||
// Notify
|
||||
activity.showTip(R.string.added_to_download_list, BaseScene.LENGTH_SHORT);
|
||||
} else {
|
||||
// Let use chose label
|
||||
List<DownloadLabel> list = dm.getLabelList();
|
||||
@@ -274,10 +281,32 @@ public final class CommonOperations {
|
||||
} else {
|
||||
Settings.putHasDefaultDownloadLabel(false);
|
||||
}
|
||||
// Notify
|
||||
activity.showTip(R.string.added_to_download_list, BaseScene.LENGTH_SHORT);
|
||||
}
|
||||
}, activity.getString(R.string.remember_download_label), false)
|
||||
.setTitle(R.string.download)
|
||||
.show();
|
||||
}
|
||||
}
|
||||
|
||||
public static void ensureNoMediaFile(UniFile file) {
|
||||
if (null == file) {
|
||||
return;
|
||||
}
|
||||
|
||||
UniFile noMedia = file.createFile(".nomedia");
|
||||
if (null == noMedia) {
|
||||
return;
|
||||
}
|
||||
|
||||
InputStream is = null;
|
||||
try {
|
||||
is = noMedia.openInputStream();
|
||||
} catch (IOException e) {
|
||||
// Ignore
|
||||
} finally {
|
||||
IOUtils.closeQuietly(is);
|
||||
}
|
||||
}
|
||||
}
|
||||
+18
-1
@@ -16,15 +16,32 @@
|
||||
|
||||
package com.hippo.ehviewer.ui;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
|
||||
import com.google.analytics.tracking.android.EasyTracker;
|
||||
import com.hippo.ehviewer.EhApplication;
|
||||
import com.hippo.ehviewer.Settings;
|
||||
|
||||
public class TrackedActivity extends AppCompatActivity {
|
||||
public class EhActivity extends AppCompatActivity {
|
||||
|
||||
private boolean mTrackStarted;
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
((EhApplication) getApplication()).registerActivity(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
|
||||
((EhApplication) getApplication()).unregisterActivity(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
+19
-1
@@ -16,14 +16,32 @@
|
||||
|
||||
package com.hippo.ehviewer.ui;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import com.google.analytics.tracking.android.EasyTracker;
|
||||
import com.hippo.app.AppCompatPreferenceActivity;
|
||||
import com.hippo.ehviewer.EhApplication;
|
||||
import com.hippo.ehviewer.Settings;
|
||||
|
||||
public class TrackedPreferenceActivity extends AppCompatPreferenceActivity {
|
||||
public class EhPreferenceActivity extends AppCompatPreferenceActivity {
|
||||
|
||||
private boolean mTrackStarted;
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
((EhApplication) getApplication()).registerActivity(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
|
||||
((EhApplication) getApplication()).unregisterActivity(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
@@ -0,0 +1,429 @@
|
||||
/*
|
||||
* Copyright 2016 Hippo Seven
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.hippo.ehviewer.ui;
|
||||
|
||||
import android.content.DialogInterface;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.design.widget.TextInputLayout;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.text.TextUtils;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.Spinner;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.hippo.easyrecyclerview.EasyRecyclerView;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.client.EhFilter;
|
||||
import com.hippo.ehviewer.dao.Filter;
|
||||
import com.hippo.util.DrawableManager;
|
||||
import com.hippo.view.ViewTransition;
|
||||
import com.hippo.yorozuya.ViewUtils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class FilterActivity extends ToolbarActivity {
|
||||
|
||||
@Nullable
|
||||
private EasyRecyclerView mRecyclerView;
|
||||
@Nullable
|
||||
private ViewTransition mViewTransition;
|
||||
@Nullable
|
||||
private FilterAdapter mAdapter;
|
||||
@Nullable
|
||||
private FilterList mFilterList;
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_filter);
|
||||
setNavigationIcon(R.drawable.v_arrow_left_dark_x24);
|
||||
|
||||
mFilterList = new FilterList();
|
||||
|
||||
mRecyclerView = (EasyRecyclerView) ViewUtils.$$(this, R.id.recycler_view);
|
||||
TextView tip = (TextView) ViewUtils.$$(this, R.id.tip);
|
||||
mViewTransition = new ViewTransition(mRecyclerView, tip);
|
||||
|
||||
Drawable drawable = DrawableManager.getDrawable(this, R.drawable.big_filter);
|
||||
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
|
||||
tip.setCompoundDrawables(null, drawable, null, null);
|
||||
|
||||
mAdapter = new FilterAdapter();
|
||||
mRecyclerView.setAdapter(mAdapter);
|
||||
mRecyclerView.setClipToPadding(false);
|
||||
mRecyclerView.setClipChildren(false);
|
||||
mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
|
||||
mRecyclerView.hasFixedSize();
|
||||
|
||||
updateView(false);
|
||||
}
|
||||
|
||||
private void updateView(boolean animation) {
|
||||
if (null == mViewTransition) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (null == mFilterList || 0 == mFilterList.size()) {
|
||||
mViewTransition.showView(1, animation);
|
||||
} else {
|
||||
mViewTransition.showView(0, animation);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
|
||||
mRecyclerView = null;
|
||||
mViewTransition = null;
|
||||
mAdapter = null;
|
||||
mFilterList = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
super.onCreateOptionsMenu(menu);
|
||||
getMenuInflater().inflate(R.menu.activity_filter, menu);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case android.R.id.home:
|
||||
finish();
|
||||
return true;
|
||||
case R.id.action_add:
|
||||
showAddFilterDialog();
|
||||
return true;
|
||||
case R.id.action_tip:
|
||||
showTipDialog();
|
||||
return true;
|
||||
default:
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
||||
|
||||
private void showTipDialog() {
|
||||
new AlertDialog.Builder(this)
|
||||
.setTitle(R.string.filter)
|
||||
.setMessage(R.string.filter_tip)
|
||||
.show();
|
||||
}
|
||||
|
||||
private void showAddFilterDialog() {
|
||||
AlertDialog dialog = new AlertDialog.Builder(this)
|
||||
.setTitle(R.string.add_filter)
|
||||
.setView(R.layout.dialog_add_filter)
|
||||
.setPositiveButton(R.string.add, null)
|
||||
.show();
|
||||
AddFilterDialogHelper helper = new AddFilterDialogHelper();
|
||||
helper.setDialog(dialog);
|
||||
}
|
||||
|
||||
private void showDeleteFilterDialog(final Filter filter) {
|
||||
int messageId;
|
||||
switch (filter.mode) {
|
||||
case EhFilter.MODE_TITLE:
|
||||
messageId = R.string.delete_title_filter;
|
||||
break;
|
||||
case EhFilter.MODE_UPLOADER:
|
||||
messageId = R.string.delete_uploader_filter;
|
||||
break;
|
||||
case EhFilter.MODE_TAG:
|
||||
messageId = R.string.delete_tag_filter;
|
||||
break;
|
||||
default:
|
||||
messageId = R.string.delete_filter;
|
||||
}
|
||||
String message = getString(messageId, filter.text);
|
||||
|
||||
new AlertDialog.Builder(this)
|
||||
.setMessage(message)
|
||||
.setPositiveButton(R.string.delete, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
if (DialogInterface.BUTTON_POSITIVE != which || null == mFilterList) {
|
||||
return;
|
||||
}
|
||||
mFilterList.delete(filter);
|
||||
if (null != mAdapter) {
|
||||
mAdapter.notifyDataSetChanged();
|
||||
}
|
||||
updateView(true);
|
||||
}
|
||||
}).show();
|
||||
}
|
||||
|
||||
private class AddFilterDialogHelper implements View.OnClickListener {
|
||||
|
||||
@Nullable
|
||||
private AlertDialog mDialog;
|
||||
@Nullable
|
||||
private Spinner mSpinner;
|
||||
@Nullable
|
||||
private TextInputLayout mInputLayout;
|
||||
@Nullable
|
||||
private EditText mEditText;
|
||||
|
||||
public void setDialog(AlertDialog dialog) {
|
||||
mDialog = dialog;
|
||||
mSpinner = (Spinner) ViewUtils.$$(dialog, R.id.spinner);
|
||||
mInputLayout = (TextInputLayout) ViewUtils.$$(dialog, R.id.text_input_layout);
|
||||
mEditText = mInputLayout.getEditText();
|
||||
View button = dialog.getButton(DialogInterface.BUTTON_POSITIVE);
|
||||
if (null != button) {
|
||||
button.setOnClickListener(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (null == mFilterList || null == mDialog || null == mSpinner ||
|
||||
null == mInputLayout || null == mEditText) {
|
||||
return;
|
||||
}
|
||||
|
||||
String text = mEditText.getText().toString().trim();
|
||||
if (TextUtils.isEmpty(text)) {
|
||||
mInputLayout.setError(getString(R.string.text_is_empty));
|
||||
return;
|
||||
} else {
|
||||
mInputLayout.setError(null);
|
||||
}
|
||||
int mode = mSpinner.getSelectedItemPosition();
|
||||
|
||||
Filter filter = new Filter();
|
||||
filter.mode = mode;
|
||||
filter.text = text;
|
||||
mFilterList.add(filter);
|
||||
|
||||
if (null != mAdapter) {
|
||||
mAdapter.notifyDataSetChanged();
|
||||
}
|
||||
updateView(true);
|
||||
|
||||
mDialog.dismiss();
|
||||
mDialog = null;
|
||||
mSpinner = null;
|
||||
mInputLayout = null;
|
||||
mEditText = null;
|
||||
}
|
||||
}
|
||||
|
||||
private class FilterHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
|
||||
|
||||
private final TextView text;
|
||||
private final ImageView icon;
|
||||
|
||||
public FilterHolder(View itemView) {
|
||||
super(itemView);
|
||||
text = (TextView) ViewUtils.$$(itemView, R.id.text);
|
||||
icon = (ImageView) itemView.findViewById(R.id.icon);
|
||||
|
||||
if (null != icon) {
|
||||
icon.setOnClickListener(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
int position = getAdapterPosition();
|
||||
if (position < 0 || null == mFilterList) {
|
||||
return;
|
||||
}
|
||||
Filter filter = mFilterList.get(position);
|
||||
if (FilterList.MODE_HEADER != filter.mode) {
|
||||
showDeleteFilterDialog(filter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class FilterAdapter extends RecyclerView.Adapter<FilterHolder> {
|
||||
|
||||
private static final int TYPE_ITEM = 0;
|
||||
private static final int TYPE_HEADER = 1;
|
||||
|
||||
@Override
|
||||
public int getItemViewType(int position) {
|
||||
if (null == mFilterList) {
|
||||
return TYPE_ITEM;
|
||||
}
|
||||
|
||||
if (mFilterList.get(position).mode == FilterList.MODE_HEADER) {
|
||||
return TYPE_HEADER;
|
||||
} else {
|
||||
return TYPE_ITEM;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public FilterHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
int layoutId;
|
||||
switch (viewType) {
|
||||
default:
|
||||
case TYPE_ITEM:
|
||||
layoutId = R.layout.item_filter;
|
||||
break;
|
||||
case TYPE_HEADER:
|
||||
layoutId = R.layout.item_filter_header;
|
||||
break;
|
||||
}
|
||||
|
||||
FilterHolder holder = new FilterHolder(getLayoutInflater().inflate(layoutId, parent, false));
|
||||
|
||||
if (R.layout.item_filter == layoutId) {
|
||||
holder.icon.setImageDrawable(
|
||||
DrawableManager.getDrawable(FilterActivity.this, R.drawable.v_delete_x24));
|
||||
}
|
||||
|
||||
return holder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(FilterHolder holder, int position) {
|
||||
if (null == mFilterList) {
|
||||
return;
|
||||
}
|
||||
|
||||
Filter filter = mFilterList.get(position);
|
||||
if (FilterList.MODE_HEADER == filter.mode) {
|
||||
holder.text.setText(filter.text);
|
||||
} else {
|
||||
holder.text.setText(filter.text);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return null != mFilterList ? mFilterList.size(): 0;
|
||||
}
|
||||
}
|
||||
|
||||
private class FilterList {
|
||||
|
||||
public static final int MODE_HEADER = -1;
|
||||
|
||||
private final EhFilter mEhFilter;
|
||||
private final List<Filter> mTitleFilterList;
|
||||
private final List<Filter> mUploaderFilterList;
|
||||
private final List<Filter> mTagFilterList;
|
||||
|
||||
private Filter mTitleHeader;
|
||||
private Filter mUploaderHeader;
|
||||
private Filter mTagHeader;
|
||||
|
||||
public FilterList() {
|
||||
mEhFilter = EhFilter.getInstance();
|
||||
mTitleFilterList = mEhFilter.getTitleFilterList();
|
||||
mUploaderFilterList = mEhFilter.getUploaderFilterList();
|
||||
mTagFilterList = mEhFilter.getTagFilterList();
|
||||
}
|
||||
|
||||
public int size() {
|
||||
int count = 0;
|
||||
int size = mTitleFilterList.size();
|
||||
count += 0 == size ? 0 : size + 1;
|
||||
size = mUploaderFilterList.size();
|
||||
count += 0 == size ? 0 : size + 1;
|
||||
size = mTagFilterList.size();
|
||||
count += 0 == size ? 0 : size + 1;
|
||||
return count;
|
||||
}
|
||||
|
||||
private Filter getTitleHeader() {
|
||||
if (null == mTitleHeader) {
|
||||
mTitleHeader = new Filter();
|
||||
mTitleHeader.mode = MODE_HEADER;
|
||||
mTitleHeader.text = getString(R.string.filter_title);
|
||||
}
|
||||
return mTitleHeader;
|
||||
}
|
||||
|
||||
private Filter getUploaderHeader() {
|
||||
if (null == mUploaderHeader) {
|
||||
mUploaderHeader = new Filter();
|
||||
mUploaderHeader.mode = MODE_HEADER;
|
||||
mUploaderHeader.text = getString(R.string.filter_uploader);
|
||||
}
|
||||
return mUploaderHeader;
|
||||
}
|
||||
|
||||
private Filter getTagHeader() {
|
||||
if (null == mTagHeader) {
|
||||
mTagHeader = new Filter();
|
||||
mTagHeader.mode = MODE_HEADER;
|
||||
mTagHeader.text = getString(R.string.filter_tag);
|
||||
}
|
||||
return mTagHeader;
|
||||
}
|
||||
|
||||
public Filter get(int index) {
|
||||
int size = mTitleFilterList.size();
|
||||
if (0 != size) {
|
||||
if (index == 0) {
|
||||
return getTitleHeader();
|
||||
} else if (index <= size) {
|
||||
return mTitleFilterList.get(index - 1);
|
||||
} else {
|
||||
index -= size + 1;
|
||||
}
|
||||
}
|
||||
|
||||
size = mUploaderFilterList.size();
|
||||
if (0 != size) {
|
||||
if (index == 0) {
|
||||
return getUploaderHeader();
|
||||
} else if (index <= size) {
|
||||
return mUploaderFilterList.get(index - 1);
|
||||
} else {
|
||||
index -= size + 1;
|
||||
}
|
||||
}
|
||||
|
||||
size = mTagFilterList.size();
|
||||
if (0 != size) {
|
||||
if (index == 0) {
|
||||
return getTagHeader();
|
||||
} else if (index <= size) {
|
||||
return mTagFilterList.get(index - 1);
|
||||
} else {
|
||||
index -= size + 1;
|
||||
}
|
||||
}
|
||||
|
||||
throw new IndexOutOfBoundsException();
|
||||
}
|
||||
|
||||
public void add(Filter filter) {
|
||||
mEhFilter.addFilter(filter);
|
||||
}
|
||||
|
||||
public void delete(Filter filter) {
|
||||
mEhFilter.deleteFilter(filter);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,7 @@ package com.hippo.ehviewer.ui;
|
||||
|
||||
import android.animation.Animator;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.res.Resources;
|
||||
@@ -30,9 +31,12 @@ import android.support.v7.app.AlertDialog;
|
||||
import android.support.v7.widget.SwitchCompat;
|
||||
import android.text.TextUtils;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
import android.webkit.MimeTypeMap;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.SeekBar;
|
||||
import android.widget.Spinner;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
@@ -49,21 +53,23 @@ import com.hippo.ehviewer.gallery.ZipGalleryProvider;
|
||||
import com.hippo.ehviewer.gallery.gl.GalleryPageView;
|
||||
import com.hippo.ehviewer.gallery.gl.GalleryView;
|
||||
import com.hippo.ehviewer.gallery.gl.ImageView;
|
||||
import com.hippo.ehviewer.widget.GalleryGuideView;
|
||||
import com.hippo.ehviewer.widget.ReversibleSeekBar;
|
||||
import com.hippo.gl.glrenderer.ImageTexture;
|
||||
import com.hippo.gl.view.GLRootView;
|
||||
import com.hippo.image.Image;
|
||||
import com.hippo.unifile.UniFile;
|
||||
import com.hippo.util.SystemUiHelper;
|
||||
import com.hippo.widget.Slider;
|
||||
import com.hippo.yorozuya.AnimationUtils;
|
||||
import com.hippo.yorozuya.ConcurrentPool;
|
||||
import com.hippo.yorozuya.SimpleAnimatorListener;
|
||||
import com.hippo.yorozuya.SimpleHandler;
|
||||
import com.hippo.yorozuya.ViewUtils;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class GalleryActivity extends TrackedActivity
|
||||
implements GalleryProviderListener, Slider.OnSetProgressListener,
|
||||
public class GalleryActivity extends EhActivity
|
||||
implements GalleryProviderListener, SeekBar.OnSeekBarChangeListener,
|
||||
GalleryView.Listener {
|
||||
|
||||
public static final String ACTION_DIR = "dir";
|
||||
@@ -102,13 +108,13 @@ public class GalleryActivity extends TrackedActivity
|
||||
@Nullable
|
||||
private View mBattery;
|
||||
@Nullable
|
||||
private View mSliderPanel;
|
||||
private View mSeekBarPanel;
|
||||
@Nullable
|
||||
private TextView mLeftText;
|
||||
@Nullable
|
||||
private TextView mRightText;
|
||||
@Nullable
|
||||
private Slider mSlider;
|
||||
private ReversibleSeekBar mSeekBar;
|
||||
|
||||
private int mLayoutMode;
|
||||
private int mSize;
|
||||
@@ -119,8 +125,8 @@ public class GalleryActivity extends TrackedActivity
|
||||
private final Runnable mRequestLayoutSliderTask = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (mSliderPanel != null) {
|
||||
mSliderPanel.requestLayout();
|
||||
if (mSeekBarPanel != null) {
|
||||
mSeekBarPanel.requestLayout();
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -128,8 +134,8 @@ public class GalleryActivity extends TrackedActivity
|
||||
private final SimpleAnimatorListener mHideSliderListener = new SimpleAnimatorListener() {
|
||||
@Override
|
||||
public void onAnimationEnd(Animator animation) {
|
||||
if (mSliderPanel != null) {
|
||||
mSliderPanel.setVisibility(View.INVISIBLE);
|
||||
if (mSeekBarPanel != null) {
|
||||
mSeekBarPanel.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -137,8 +143,8 @@ public class GalleryActivity extends TrackedActivity
|
||||
private final Runnable mHideSliderRunnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (mSliderPanel != null) {
|
||||
hideSlider(mSliderPanel);
|
||||
if (mSeekBarPanel != null) {
|
||||
hideSlider(mSeekBarPanel);
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -249,21 +255,16 @@ public class GalleryActivity extends TrackedActivity
|
||||
mSystemUiShowing = true;
|
||||
}
|
||||
|
||||
mClock = findViewById(R.id.clock);
|
||||
mBattery = findViewById(R.id.battery);
|
||||
mClock = ViewUtils.$$(this, R.id.clock);
|
||||
mBattery = ViewUtils.$$(this, R.id.battery);
|
||||
mClock.setVisibility(Settings.getShowClock() ? View.VISIBLE : View.GONE);
|
||||
mBattery.setVisibility(Settings.getShowBattery() ? View.VISIBLE : View.GONE);
|
||||
|
||||
if (mClock != null && !Settings.getShowClock()) {
|
||||
mClock.setVisibility(View.GONE);
|
||||
}
|
||||
if (mBattery != null && !Settings.getShowBattery()) {
|
||||
mBattery.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
mSliderPanel = findViewById(R.id.slider_panel);
|
||||
mLeftText = (TextView) mSliderPanel.findViewById(R.id.left);
|
||||
mRightText = (TextView) mSliderPanel.findViewById(R.id.right);
|
||||
mSlider = (Slider) mSliderPanel.findViewById(R.id.slider);
|
||||
mSlider.setOnSetProgressListener(this);
|
||||
mSeekBarPanel = findViewById(R.id.seek_bar_panel);
|
||||
mLeftText = (TextView) mSeekBarPanel.findViewById(R.id.left);
|
||||
mRightText = (TextView) mSeekBarPanel.findViewById(R.id.right);
|
||||
mSeekBar = (ReversibleSeekBar) mSeekBarPanel.findViewById(R.id.seek_bar);
|
||||
mSeekBar.setOnSeekBarChangeListener(this);
|
||||
|
||||
mSize = mGalleryProvider.size();
|
||||
mCurrentIndex = startPage;
|
||||
@@ -276,6 +277,11 @@ public class GalleryActivity extends TrackedActivity
|
||||
} else {
|
||||
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||
}
|
||||
|
||||
if (Settings.getGuideGallery()) {
|
||||
FrameLayout mainLayout = (FrameLayout) ViewUtils.$$(this, R.id.main);
|
||||
mainLayout.addView(new GalleryGuideView(this));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -292,10 +298,10 @@ public class GalleryActivity extends TrackedActivity
|
||||
mGalleryProvider = null;
|
||||
}
|
||||
|
||||
mSliderPanel = null;
|
||||
mSeekBarPanel = null;
|
||||
mLeftText = null;
|
||||
mRightText = null;
|
||||
mSlider = null;
|
||||
mSeekBar = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -424,7 +430,7 @@ public class GalleryActivity extends TrackedActivity
|
||||
|
||||
@SuppressLint("SetTextI18n")
|
||||
private void updateSlider() {
|
||||
if (mSlider == null || mRightText == null || mLeftText == null || mSize <= 0 || mCurrentIndex < 0) {
|
||||
if (mSeekBar == null || mRightText == null || mLeftText == null || mSize <= 0 || mCurrentIndex < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -433,16 +439,16 @@ public class GalleryActivity extends TrackedActivity
|
||||
if (mLayoutMode == GalleryView.LAYOUT_MODE_RIGHT_TO_LEFT) {
|
||||
start = mRightText;
|
||||
end = mLeftText;
|
||||
mSlider.setReverse(true);
|
||||
mSeekBar.setReverse(true);
|
||||
} else {
|
||||
start = mLeftText;
|
||||
end = mRightText;
|
||||
mSlider.setReverse(false);
|
||||
mSeekBar.setReverse(false);
|
||||
}
|
||||
start.setText(Integer.toString(mCurrentIndex + 1));
|
||||
end.setText(Integer.toString(mSize));
|
||||
mSlider.setRange(1, mSize);
|
||||
mSlider.setProgress(mCurrentIndex + 1);
|
||||
mSeekBar.setMax(mSize - 1);
|
||||
mSeekBar.setProgress(mCurrentIndex);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -525,21 +531,31 @@ public class GalleryActivity extends TrackedActivity
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSetProgress(Slider slider, int newProgress, int oldProgress,
|
||||
boolean byUser, boolean confirm) {
|
||||
if (confirm && byUser && mGalleryView != null) {
|
||||
mGalleryView.setCurrentPage(newProgress - 1);
|
||||
@SuppressLint("SetTextI18n")
|
||||
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
|
||||
TextView start;
|
||||
if (mLayoutMode == GalleryView.LAYOUT_MODE_RIGHT_TO_LEFT) {
|
||||
start = mRightText;
|
||||
} else {
|
||||
start = mLeftText;
|
||||
}
|
||||
if (fromUser && null != start) {
|
||||
start.setText(Integer.toString(progress + 1));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFingerDown() {
|
||||
public void onStartTrackingTouch(SeekBar seekBar) {
|
||||
SimpleHandler.getInstance().removeCallbacks(mHideSliderRunnable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFingerUp() {
|
||||
public void onStopTrackingTouch(SeekBar seekBar) {
|
||||
SimpleHandler.getInstance().postDelayed(mHideSliderRunnable, HIDE_SLIDER_DELAY);
|
||||
int progress = seekBar.getProgress();
|
||||
if (progress != mCurrentIndex && null != mGalleryView) {
|
||||
mGalleryView.setCurrentPage(progress);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -614,8 +630,8 @@ public class GalleryActivity extends TrackedActivity
|
||||
private final SwitchCompat mVolumePage;
|
||||
|
||||
@SuppressLint("InflateParams")
|
||||
public GalleryMenuHelper() {
|
||||
mView = getLayoutInflater().inflate(R.layout.dialog_gallery_menu, null);
|
||||
public GalleryMenuHelper(Context context) {
|
||||
mView = LayoutInflater.from(context).inflate(R.layout.dialog_gallery_menu, null);
|
||||
mReadingDirection = (Spinner) mView.findViewById(R.id.reading_direction);
|
||||
mScaleMode = (Spinner) mView.findViewById(R.id.page_scaling);
|
||||
mStartPosition = (Spinner) mView.findViewById(R.id.start_position);
|
||||
@@ -773,24 +789,24 @@ public class GalleryActivity extends TrackedActivity
|
||||
}
|
||||
|
||||
private void onTapMenuArea() {
|
||||
GalleryMenuHelper helper = new GalleryMenuHelper();
|
||||
new AlertDialog.Builder(GalleryActivity.this)
|
||||
.setTitle(R.string.gallery_menu_title)
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(GalleryActivity.this);
|
||||
GalleryMenuHelper helper = new GalleryMenuHelper(builder.getContext());
|
||||
builder.setTitle(R.string.gallery_menu_title)
|
||||
.setView(helper.getView())
|
||||
.setPositiveButton(android.R.string.ok, helper).show();
|
||||
}
|
||||
|
||||
private void onTapSliderArea() {
|
||||
if (mSliderPanel == null || mSize <= 0 || mCurrentIndex < 0) {
|
||||
if (mSeekBarPanel == null || mSize <= 0 || mCurrentIndex < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
SimpleHandler.getInstance().removeCallbacks(mHideSliderRunnable);
|
||||
|
||||
if (mSliderPanel.getVisibility() == View.VISIBLE) {
|
||||
hideSlider(mSliderPanel);
|
||||
if (mSeekBarPanel.getVisibility() == View.VISIBLE) {
|
||||
hideSlider(mSeekBarPanel);
|
||||
} else {
|
||||
showSlider(mSliderPanel);
|
||||
showSlider(mSeekBarPanel);
|
||||
SimpleHandler.getInstance().postDelayed(mHideSliderRunnable, HIDE_SLIDER_DELAY);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ import android.support.annotation.StringRes;
|
||||
import android.support.design.widget.NavigationView;
|
||||
import android.support.design.widget.Snackbar;
|
||||
import android.support.v4.widget.DrawerLayout;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.Gravity;
|
||||
@@ -58,12 +59,15 @@ import com.hippo.ehviewer.ui.scene.GalleryPreviewsScene;
|
||||
import com.hippo.ehviewer.ui.scene.HistoryScene;
|
||||
import com.hippo.ehviewer.ui.scene.ProgressScene;
|
||||
import com.hippo.ehviewer.ui.scene.QuickSearchScene;
|
||||
import com.hippo.ehviewer.ui.scene.SecurityScene;
|
||||
import com.hippo.ehviewer.ui.scene.SelectSiteScene;
|
||||
import com.hippo.ehviewer.ui.scene.SignInScene;
|
||||
import com.hippo.ehviewer.ui.scene.WarningScene;
|
||||
import com.hippo.ehviewer.ui.scene.WebViewSignInScene;
|
||||
import com.hippo.scene.Announcer;
|
||||
import com.hippo.scene.SceneFragment;
|
||||
import com.hippo.scene.StageActivity;
|
||||
import com.hippo.unifile.UniFile;
|
||||
import com.hippo.util.PermissionRequester;
|
||||
import com.hippo.widget.LoadImageView;
|
||||
import com.hippo.yorozuya.ViewUtils;
|
||||
@@ -75,14 +79,14 @@ public final class MainActivity extends StageActivity
|
||||
|
||||
private static final int PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE = 0;
|
||||
|
||||
private static final int REQUEST_CODE_UPDATE_PROFILE = 0;
|
||||
|
||||
private static final String KEY_NAV_CHECKED_ITEM = "nav_checked_item";
|
||||
|
||||
public static final int CHECK_STEP_WARNING = 0;
|
||||
public static final int CHECK_STEP_ANALYTICS = 1;
|
||||
public static final int CHECK_STEP_CRASH = 2;
|
||||
public static final int CHECK_STEP_SIGN_IN = 3;
|
||||
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 String KEY_TARGET_SCENE = "target_scene";
|
||||
public static final String KEY_TARGET_ARGS = "target_args";
|
||||
@@ -104,12 +108,14 @@ public final class MainActivity extends StageActivity
|
||||
private int mNavCheckedItem = 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);
|
||||
registerLaunchMode(SelectSiteScene.class, SceneFragment.LAUNCH_MODE_SINGLE_TASK);
|
||||
registerLaunchMode(GalleryListScene.class, SceneFragment.LAUNCH_MODE_SINGLE_TOP);
|
||||
registerLaunchMode(QuickSearchScene.class, SceneFragment.LAUNCH_MODE_SINGLE_TASK);
|
||||
registerLaunchMode(GalleryDetailScene.class, SceneFragment.LAUNCH_MODE_STANDARD);
|
||||
@@ -125,6 +131,11 @@ public final class MainActivity extends StageActivity
|
||||
|
||||
public void startSceneForCheckStep(int checkStep, Bundle args) {
|
||||
switch (checkStep) {
|
||||
case CHECK_STEP_SECURITY:
|
||||
if (Settings.getShowWarning()) {
|
||||
startScene(new Announcer(WarningScene.class).setArgs(args));
|
||||
break;
|
||||
}
|
||||
case CHECK_STEP_WARNING:
|
||||
if (Settings.getAskAnalytics()) {
|
||||
startScene(new Announcer(AnalyticsScene.class).setArgs(args));
|
||||
@@ -136,11 +147,16 @@ public final class MainActivity extends StageActivity
|
||||
break;
|
||||
}
|
||||
case CHECK_STEP_CRASH:
|
||||
if (!EhUtils.hasSignedIn(this)) {
|
||||
if (EhUtils.needSignedIn(this)) {
|
||||
startScene(new Announcer(SignInScene.class).setArgs(args));
|
||||
break;
|
||||
}
|
||||
case CHECK_STEP_SIGN_IN:
|
||||
if (Settings.getSelectSite()) {
|
||||
startScene(new Announcer(SelectSiteScene.class).setArgs(args));
|
||||
break;
|
||||
}
|
||||
case CHECK_STEP_SELECT_SITE:
|
||||
String targetScene = null;
|
||||
Bundle targetArgs = null;
|
||||
if (null != args) {
|
||||
@@ -176,14 +192,18 @@ public final class MainActivity extends StageActivity
|
||||
@Nullable
|
||||
@Override
|
||||
protected Announcer getLaunchAnnouncer() {
|
||||
if (Settings.getShowWarning()) {
|
||||
if (!TextUtils.isEmpty(Settings.getSecurity())) {
|
||||
return new Announcer(SecurityScene.class);
|
||||
} else if (Settings.getShowWarning()) {
|
||||
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.hasSignedIn(this)) {
|
||||
} else if (EhUtils.needSignedIn(this)) {
|
||||
return new Announcer(SignInScene.class);
|
||||
} else if (Settings.getSelectSite()) {
|
||||
return new Announcer(SelectSiteScene.class);
|
||||
} else {
|
||||
Bundle args = new Bundle();
|
||||
args.putString(GalleryListScene.KEY_ACTION, GalleryListScene.ACTION_HOMEPAGE);
|
||||
@@ -194,7 +214,12 @@ public final class MainActivity extends StageActivity
|
||||
// Sometimes scene can't show directly
|
||||
private Announcer processAnnouncer(Announcer announcer) {
|
||||
if (0 == getSceneCount()) {
|
||||
if (Settings.getShowWarning()) {
|
||||
if (!TextUtils.isEmpty(Settings.getSecurity())) {
|
||||
Bundle newArgs = new Bundle();
|
||||
newArgs.putString(KEY_TARGET_SCENE, announcer.getClazz().getName());
|
||||
newArgs.putBundle(KEY_TARGET_ARGS, announcer.getArgs());
|
||||
return new Announcer(SecurityScene.class).setArgs(newArgs);
|
||||
} else if (Settings.getShowWarning()) {
|
||||
Bundle newArgs = new Bundle();
|
||||
newArgs.putString(KEY_TARGET_SCENE, announcer.getClazz().getName());
|
||||
newArgs.putBundle(KEY_TARGET_ARGS, announcer.getArgs());
|
||||
@@ -209,11 +234,16 @@ public final class MainActivity extends StageActivity
|
||||
newArgs.putString(KEY_TARGET_SCENE, announcer.getClazz().getName());
|
||||
newArgs.putBundle(KEY_TARGET_ARGS, announcer.getArgs());
|
||||
return new Announcer(CrashScene.class).setArgs(newArgs);
|
||||
} else if (!EhUtils.hasSignedIn(this)) {
|
||||
} else if (EhUtils.needSignedIn(this)) {
|
||||
Bundle newArgs = new Bundle();
|
||||
newArgs.putString(KEY_TARGET_SCENE, announcer.getClazz().getName());
|
||||
newArgs.putBundle(KEY_TARGET_ARGS, announcer.getArgs());
|
||||
return new Announcer(SignInScene.class).setArgs(newArgs);
|
||||
} else if (Settings.getSelectSite()) {
|
||||
Bundle newArgs = new Bundle();
|
||||
newArgs.putString(KEY_TARGET_SCENE, announcer.getClazz().getName());
|
||||
newArgs.putBundle(KEY_TARGET_ARGS, announcer.getArgs());
|
||||
return new Announcer(SelectSiteScene.class).setArgs(newArgs);
|
||||
}
|
||||
}
|
||||
return announcer;
|
||||
@@ -280,11 +310,24 @@ public final class MainActivity extends StageActivity
|
||||
if (savedInstanceState == null) {
|
||||
onInit();
|
||||
CommonOperations.checkUpdate(this, false);
|
||||
checkDownloadLocation();
|
||||
} else {
|
||||
onRestore(savedInstanceState);
|
||||
}
|
||||
}
|
||||
|
||||
private void checkDownloadLocation() {
|
||||
UniFile uniFile = Settings.getDownloadLocation();
|
||||
if (null != uniFile && uniFile.ensureDir()) {
|
||||
return;
|
||||
}
|
||||
new AlertDialog.Builder(this)
|
||||
.setTitle(R.string.waring)
|
||||
.setMessage(R.string.invalid_download_location)
|
||||
.setPositiveButton(R.string.get_it, null)
|
||||
.show();
|
||||
}
|
||||
|
||||
private void onInit() {
|
||||
// Check permission
|
||||
PermissionRequester.request(this, Manifest.permission.WRITE_EXTERNAL_STORAGE,
|
||||
@@ -339,7 +382,7 @@ public final class MainActivity extends StageActivity
|
||||
BaseScene baseScene = (BaseScene) scene;
|
||||
mRightDrawer.removeAllViews();
|
||||
View drawerView = baseScene.onCreateDrawerView(
|
||||
getLayoutInflater(), mRightDrawer, savedInstanceState);
|
||||
baseScene.getLayoutInflater2(), mRightDrawer, savedInstanceState);
|
||||
if (drawerView != null) {
|
||||
mRightDrawer.addView(drawerView);
|
||||
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED, Gravity.RIGHT);
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* Copyright 2016 Hippo Seven
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.hippo.ehviewer.ui;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.text.TextUtils;
|
||||
import android.view.View;
|
||||
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.Settings;
|
||||
import com.hippo.widget.lockpattern.LockPatternUtils;
|
||||
import com.hippo.widget.lockpattern.LockPatternView;
|
||||
import com.hippo.yorozuya.ViewUtils;
|
||||
|
||||
public class SetSecurityActivity extends ToolbarActivity implements View.OnClickListener {
|
||||
|
||||
@Nullable
|
||||
private LockPatternView mPatternView;
|
||||
@Nullable
|
||||
private View mCancel;
|
||||
@Nullable
|
||||
private View mSet;
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_set_security);
|
||||
setNavigationIcon(R.drawable.v_arrow_left_dark_x24);
|
||||
|
||||
mPatternView = (LockPatternView) ViewUtils.$$(this, R.id.pattern_view);
|
||||
mCancel = ViewUtils.$$(this, R.id.cancel);
|
||||
mSet = ViewUtils.$$(this, R.id.set);
|
||||
|
||||
String pattern = Settings.getSecurity();
|
||||
if (!TextUtils.isEmpty(pattern)) {
|
||||
mPatternView.setPattern(LockPatternView.DisplayMode.Correct,
|
||||
LockPatternUtils.stringToPattern(pattern));
|
||||
}
|
||||
|
||||
mCancel.setOnClickListener(this);
|
||||
mSet.setOnClickListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
mPatternView = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (v == mCancel) {
|
||||
finish();
|
||||
} else if (v == mSet) {
|
||||
if (null != mPatternView) {
|
||||
String security;
|
||||
if (mPatternView.getCellSize() <= 1) {
|
||||
security = "";
|
||||
} else {
|
||||
security = mPatternView.getPatternString();
|
||||
}
|
||||
Settings.putSecurity(security);
|
||||
}
|
||||
finish();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -43,7 +43,7 @@ import com.hippo.util.DrawableManager;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.List;
|
||||
|
||||
public final class SettingsActivity extends TrackedPreferenceActivity {
|
||||
public final class SettingsActivity extends EhPreferenceActivity {
|
||||
|
||||
private static final int REQUEST_CODE_FRAGMENT = 0;
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ import android.view.ViewGroup;
|
||||
|
||||
import com.hippo.ehviewer.R;
|
||||
|
||||
public class ToolbarActivity extends TrackedActivity {
|
||||
public class ToolbarActivity extends EhActivity {
|
||||
|
||||
@Override
|
||||
public void setContentView(@LayoutRes int layoutResID) {
|
||||
|
||||
@@ -20,10 +20,13 @@ import android.content.res.Resources;
|
||||
import android.os.Bundle;
|
||||
import android.preference.Preference;
|
||||
import android.preference.PreferenceFragment;
|
||||
import android.text.TextUtils;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.hippo.ehviewer.AppConfig;
|
||||
import com.hippo.ehviewer.EhApplication;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.Settings;
|
||||
import com.hippo.util.LogCat;
|
||||
import com.hippo.util.ReadableTime;
|
||||
|
||||
@@ -32,6 +35,8 @@ import java.io.File;
|
||||
public class AdvancedFragment extends PreferenceFragment implements Preference.OnPreferenceClickListener {
|
||||
|
||||
private static final String KEY_DUMP_LOGCAT = "dump_logcat";
|
||||
private static final String KEY_CLEAR_MEMORY_CACHE = "clear_memory_cache";
|
||||
private static final String KEY_PATTERN_PROTECTION = "pattern_protection";
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
@@ -39,8 +44,20 @@ public class AdvancedFragment extends PreferenceFragment implements Preference.O
|
||||
addPreferencesFromResource(R.xml.advanced_settings);
|
||||
|
||||
Preference dumpLogcat = findPreference(KEY_DUMP_LOGCAT);
|
||||
Preference clearMemoryCache = findPreference(KEY_CLEAR_MEMORY_CACHE);
|
||||
|
||||
dumpLogcat.setOnPreferenceClickListener(this);
|
||||
clearMemoryCache.setOnPreferenceClickListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
|
||||
Preference patternProtection = findPreference(KEY_PATTERN_PROTECTION);
|
||||
patternProtection.setSummary(TextUtils.isEmpty(Settings.getSecurity()) ?
|
||||
R.string.settings_advanced_pattern_protection_not_set :
|
||||
R.string.settings_advanced_pattern_protection_set);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -58,9 +75,12 @@ public class AdvancedFragment extends PreferenceFragment implements Preference.O
|
||||
}
|
||||
Resources resources = getResources();
|
||||
Toast.makeText(getActivity(),
|
||||
ok ? resources.getString(R.string.settings_about_dump_logcat_to, file.getPath()) :
|
||||
resources.getString(R.string.settings_about_dump_logcat_failed), Toast.LENGTH_SHORT).show();
|
||||
ok ? resources.getString(R.string.settings_advanced_dump_logcat_to, file.getPath()) :
|
||||
resources.getString(R.string.settings_advanced_dump_logcat_failed), Toast.LENGTH_SHORT).show();
|
||||
return true;
|
||||
} else if (KEY_CLEAR_MEMORY_CACHE.equals(key)) {
|
||||
((EhApplication) getActivity().getApplication()).clearMemoryCache();
|
||||
Runtime.getRuntime().gc();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package com.hippo.ehviewer.ui.scene;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.view.LayoutInflater;
|
||||
@@ -58,7 +59,7 @@ public class AnalyticsScene extends BaseScene implements View.OnClickListener {
|
||||
TextView text = (TextView) ViewUtils.$$(view, R.id.text);
|
||||
|
||||
text.setText(Html.fromHtml(getString(R.string.analytics_explain)));
|
||||
text.setMovementMethod(new LinkMovementMethod2(getActivity()));
|
||||
text.setMovementMethod(LinkMovementMethod2.getInstance());
|
||||
|
||||
mCancel.setOnClickListener(this);
|
||||
mOk.setOnClickListener(this);
|
||||
@@ -79,18 +80,25 @@ public class AnalyticsScene extends BaseScene implements View.OnClickListener {
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Context context = getContext2();
|
||||
if (null == context) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (mCancel == v) {
|
||||
Settings.putEnableAnalytics(false);
|
||||
} else if (mOk == v) {
|
||||
Settings.putEnableAnalytics(true);
|
||||
// Start Analytics
|
||||
Analytics.start(getContext());
|
||||
Analytics.start(context);
|
||||
}
|
||||
Settings.putAskAnalytics(false);
|
||||
|
||||
// Start new scene and finish it self
|
||||
((MainActivity) getActivity()).startSceneForCheckStep(
|
||||
MainActivity.CHECK_STEP_ANALYTICS, getArguments());
|
||||
MainActivity activity = getActivity2();
|
||||
if (null != activity) {
|
||||
activity.startSceneForCheckStep(MainActivity.CHECK_STEP_ANALYTICS, getArguments());
|
||||
}
|
||||
finish();
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
package com.hippo.ehviewer.ui.scene;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.IdRes;
|
||||
import android.support.annotation.Nullable;
|
||||
@@ -151,14 +153,52 @@ public abstract class BaseScene extends SceneFragment {
|
||||
return mViewCreated;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityCreated(Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
if (savedInstanceState != null) {
|
||||
onRestoreInstanceState(savedInstanceState);
|
||||
@Nullable
|
||||
public Context getContext2() {
|
||||
return super.getContext();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Resources getResources2() {
|
||||
Context context = getContext2();
|
||||
if (null != context) {
|
||||
return context.getResources();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
protected void onRestoreInstanceState(Bundle savedInstanceState) {
|
||||
@Nullable
|
||||
public MainActivity getActivity2() {
|
||||
FragmentActivity activity = getActivity();
|
||||
if (activity instanceof MainActivity) {
|
||||
return (MainActivity) activity;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public LayoutInflater getLayoutInflater2() {
|
||||
FragmentActivity activity = getActivity();
|
||||
if (null != activity) {
|
||||
return activity.getLayoutInflater();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void hideSoftInput() {
|
||||
FragmentActivity activity = getActivity();
|
||||
if (null != activity) {
|
||||
ActivityHelper.hideSoftInput(activity);
|
||||
}
|
||||
}
|
||||
|
||||
public void showSoftInput(@Nullable View view) {
|
||||
FragmentActivity activity = getActivity();
|
||||
if (null != activity && null != view) {
|
||||
ActivityHelper.showSoftInput(activity, view);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -36,7 +36,6 @@ import com.hippo.ehviewer.client.EhCookieStore;
|
||||
import com.hippo.ehviewer.client.EhUrl;
|
||||
import com.hippo.ehviewer.client.EhUtils;
|
||||
import com.hippo.rippleold.RippleSalon;
|
||||
import com.hippo.util.ActivityHelper;
|
||||
import com.hippo.yorozuya.AssertUtils;
|
||||
import com.hippo.yorozuya.ViewUtils;
|
||||
|
||||
@@ -90,7 +89,7 @@ public class CookieSignInScene extends BaseScene implements EditText.OnEditorAct
|
||||
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
|
||||
ActivityHelper.showSoftInput(getActivity(), mIpbMemberId);
|
||||
showSoftInput(mIpbMemberId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -144,7 +143,8 @@ public class CookieSignInScene extends BaseScene implements EditText.OnEditorAct
|
||||
}
|
||||
|
||||
public void enter() {
|
||||
if (null == mIpbMemberIdLayout || null == mIpbPassHashLayout ||
|
||||
Context context = getContext2();
|
||||
if (null == context || null == mIpbMemberIdLayout || null == mIpbPassHashLayout ||
|
||||
null == mIpbMemberId || null == mIpbPassHash) {
|
||||
return;
|
||||
}
|
||||
@@ -165,10 +165,10 @@ public class CookieSignInScene extends BaseScene implements EditText.OnEditorAct
|
||||
mIpbPassHashLayout.setError(null);
|
||||
}
|
||||
|
||||
ActivityHelper.hideSoftInput(getActivity());
|
||||
hideSoftInput();
|
||||
|
||||
if (!checkIpbMemberId(ipbMemberId) || !(checkIpbPassHash(ipbPassHash))) {
|
||||
new AlertDialog.Builder(getContext()).setTitle(R.string.waring)
|
||||
new AlertDialog.Builder(context).setTitle(R.string.waring)
|
||||
.setMessage(R.string.wrong_cookie_warning)
|
||||
.setNegativeButton(R.string.i_dont_think_so, null)
|
||||
.setPositiveButton(R.string.i_will_check_it, new DialogInterface.OnClickListener() {
|
||||
@@ -192,12 +192,12 @@ public class CookieSignInScene extends BaseScene implements EditText.OnEditorAct
|
||||
}
|
||||
|
||||
private void storeCookie(String id, String hash) {
|
||||
Context context = getContext();
|
||||
Context context = getContext2();
|
||||
if (null == context) {
|
||||
return;
|
||||
}
|
||||
|
||||
EhUtils.signOut(getContext());
|
||||
EhUtils.signOut(context);
|
||||
|
||||
EhCookieStore store = EhApplication.getEhCookieStore(context);
|
||||
store.add(newCookie(EhCookieStore.KEY_IPD_MEMBER_ID, id, EhUrl.DOMAIN_E));
|
||||
|
||||
@@ -78,15 +78,18 @@ public class CrashScene extends BaseScene implements View.OnClickListener {
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (mSend == v && null != mCrash) {
|
||||
ActivityHelper.sendEmail(getActivity(), EhApplication.getDeveloperEmail(),
|
||||
MainActivity activity = getActivity2();
|
||||
|
||||
if (mSend == v && null != mCrash && null != activity) {
|
||||
ActivityHelper.sendEmail(activity, EhApplication.getDeveloperEmail(),
|
||||
"I found a bug in EhViewer !", mCrash);
|
||||
}
|
||||
Crash.resetCrashFile();
|
||||
|
||||
// Start new scene and finish it self
|
||||
((MainActivity) getActivity()).startSceneForCheckStep(
|
||||
MainActivity.CHECK_STEP_CRASH, getArguments());
|
||||
if (null != activity) {
|
||||
activity.startSceneForCheckStep(MainActivity.CHECK_STEP_CRASH, getArguments());
|
||||
}
|
||||
finish();
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package com.hippo.ehviewer.ui.scene;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.graphics.drawable.NinePatchDrawable;
|
||||
@@ -52,6 +53,7 @@ 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 java.util.List;
|
||||
@@ -77,7 +79,7 @@ public class DownloadLabelsScene extends ToolbarScene {
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
mList = EhApplication.getDownloadManager(getContext()).getLabelList();
|
||||
mList = EhApplication.getDownloadManager(getContext2()).getLabelList();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -97,7 +99,9 @@ public class DownloadLabelsScene extends ToolbarScene {
|
||||
TextView tip = (TextView) ViewUtils.$$(view, R.id.tip);
|
||||
mViewTransition = new ViewTransition(mRecyclerView, tip);
|
||||
|
||||
Drawable drawable = DrawableManager.getDrawable(getContext(), R.drawable.big_label);
|
||||
Context context = getContext2();
|
||||
AssertUtils.assertNotNull(context);
|
||||
Drawable drawable = DrawableManager.getDrawable(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);
|
||||
@@ -109,7 +113,7 @@ public class DownloadLabelsScene extends ToolbarScene {
|
||||
// drag & drop manager
|
||||
RecyclerViewDragDropManager dragDropManager = new RecyclerViewDragDropManager();
|
||||
dragDropManager.setDraggingItemShadowDrawable(
|
||||
(NinePatchDrawable) getResources().getDrawable(R.drawable.shadow_8dp));
|
||||
(NinePatchDrawable) context.getResources().getDrawable(R.drawable.shadow_8dp));
|
||||
// swipe manager
|
||||
RecyclerViewSwipeManager swipeManager = new RecyclerViewSwipeManager();
|
||||
RecyclerView.Adapter adapter = new LabelAdapter();
|
||||
@@ -120,7 +124,7 @@ public class DownloadLabelsScene extends ToolbarScene {
|
||||
final GeneralItemAnimator animator = new SwipeDismissItemAnimator();
|
||||
animator.setSupportsChangeAnimations(false);
|
||||
mRecyclerView.hasFixedSize();
|
||||
mRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
|
||||
mRecyclerView.setLayoutManager(new LinearLayoutManager(context));
|
||||
mRecyclerView.setAdapter(adapter);
|
||||
mRecyclerView.setItemAnimator(animator);
|
||||
guardManager.attachRecyclerView(mRecyclerView);
|
||||
@@ -160,10 +164,15 @@ public class DownloadLabelsScene extends ToolbarScene {
|
||||
|
||||
@Override
|
||||
public boolean onMenuItemClick(MenuItem item) {
|
||||
Context context = getContext2();
|
||||
if (null == context) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int id = item.getItemId();
|
||||
switch (id) {
|
||||
case R.id.action_add: {
|
||||
EditTextDialogBuilder builder = new EditTextDialogBuilder(getContext(), null, getString(R.string.download_labels));
|
||||
EditTextDialogBuilder builder = new EditTextDialogBuilder(context, null, getString(R.string.download_labels));
|
||||
builder.setTitle(R.string.new_label_title);
|
||||
builder.setPositiveButton(android.R.string.ok, null);
|
||||
AlertDialog dialog = builder.show();
|
||||
@@ -199,17 +208,22 @@ public class DownloadLabelsScene extends ToolbarScene {
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Context context = getContext2();
|
||||
if (null == context) {
|
||||
return;
|
||||
}
|
||||
|
||||
String text = mBuilder.getText();
|
||||
if (TextUtils.isEmpty(text)) {
|
||||
mBuilder.setError(getString(R.string.label_text_is_empty));
|
||||
} else if (getString(R.string.default_download_label_name).equals(text)) {
|
||||
mBuilder.setError(getString(R.string.label_text_is_invalid));
|
||||
} else if (EhApplication.getDownloadManager(getContext()).containLabel(text)) {
|
||||
} else if (EhApplication.getDownloadManager(context).containLabel(text)) {
|
||||
mBuilder.setError(getString(R.string.label_text_exist));
|
||||
} else {
|
||||
mBuilder.setError(null);
|
||||
mDialog.dismiss();
|
||||
EhApplication.getDownloadManager(getContext()).addLabel(text);
|
||||
EhApplication.getDownloadManager(context).addLabel(text);
|
||||
if (mAdapter != null && mList != null) {
|
||||
mAdapter.notifyItemInserted(mList.size() - 1);
|
||||
}
|
||||
@@ -245,17 +259,22 @@ public class DownloadLabelsScene extends ToolbarScene {
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Context context = getContext2();
|
||||
if (null == context) {
|
||||
return;
|
||||
}
|
||||
|
||||
String text = mBuilder.getText();
|
||||
if (TextUtils.isEmpty(text)) {
|
||||
mBuilder.setError(getString(R.string.label_text_is_empty));
|
||||
} else if (getString(R.string.default_download_label_name).equals(text)) {
|
||||
mBuilder.setError(getString(R.string.label_text_is_invalid));
|
||||
} else if (EhApplication.getDownloadManager(getContext()).containLabel(text)) {
|
||||
} else if (EhApplication.getDownloadManager(context).containLabel(text)) {
|
||||
mBuilder.setError(getString(R.string.label_text_exist));
|
||||
} else {
|
||||
mBuilder.setError(null);
|
||||
mDialog.dismiss();
|
||||
EhApplication.getDownloadManager(getContext()).renameLabel(mOriginalLabel, text);
|
||||
EhApplication.getDownloadManager(context).renameLabel(mOriginalLabel, text);
|
||||
if (mAdapter != null) {
|
||||
mAdapter.notifyItemChanged(mPosition);
|
||||
}
|
||||
@@ -282,7 +301,8 @@ public class DownloadLabelsScene extends ToolbarScene {
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (mList == null || mRecyclerView == null) {
|
||||
Context context = getContext2();
|
||||
if (null == context || null == mList || null == mRecyclerView) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -294,7 +314,7 @@ public class DownloadLabelsScene extends ToolbarScene {
|
||||
if (label == v) {
|
||||
DownloadLabel raw = mList.get(index);
|
||||
EditTextDialogBuilder builder = new EditTextDialogBuilder(
|
||||
getContext(), raw.getLabel(), getString(R.string.download_labels));
|
||||
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();
|
||||
@@ -312,10 +332,16 @@ public class DownloadLabelsScene extends ToolbarScene {
|
||||
implements DraggableItemAdapter<LabelHolder>,
|
||||
SwipeableItemAdapter<LabelHolder> {
|
||||
|
||||
private final LayoutInflater mInflater;
|
||||
|
||||
public LabelAdapter() {
|
||||
mInflater = getLayoutInflater2();
|
||||
AssertUtils.assertNotNull(mInflater);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LabelHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
return new LabelHolder(getActivity().getLayoutInflater()
|
||||
.inflate(R.layout.item_label_list, parent, false));
|
||||
return new LabelHolder(mInflater.inflate(R.layout.item_label_list, parent, false));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -348,11 +374,12 @@ public class DownloadLabelsScene extends ToolbarScene {
|
||||
|
||||
@Override
|
||||
public void onMoveItem(int fromPosition, int toPosition) {
|
||||
if (fromPosition == toPosition) {
|
||||
Context context = getContext2();
|
||||
if (null == context || fromPosition == toPosition) {
|
||||
return;
|
||||
}
|
||||
|
||||
EhApplication.getDownloadManager(getContext()).moveLabel(fromPosition, toPosition);
|
||||
EhApplication.getDownloadManager(context).moveLabel(fromPosition, toPosition);
|
||||
if (mAdapter != null && mList != null) {
|
||||
notifyItemMoved(fromPosition, toPosition);
|
||||
}
|
||||
@@ -397,19 +424,20 @@ public class DownloadLabelsScene extends ToolbarScene {
|
||||
protected void onPerformAction() {
|
||||
super.onPerformAction();
|
||||
|
||||
final Context context = getContext2();
|
||||
final List<DownloadLabel> list = mList;
|
||||
if (list == null || mPosition < 0 || mPosition >= list.size()) {
|
||||
if (null == context || null == list || mPosition < 0 || mPosition >= list.size()) {
|
||||
return;
|
||||
}
|
||||
final DownloadLabel label = list.get(mPosition);
|
||||
|
||||
new AlertDialog.Builder(getContext())
|
||||
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(getContext()).deleteLabel(label.getLabel());
|
||||
EhApplication.getDownloadManager(context).deleteLabel(label.getLabel());
|
||||
}
|
||||
})
|
||||
.setOnDismissListener(new DialogInterface.OnDismissListener() {
|
||||
|
||||
@@ -18,8 +18,11 @@ package com.hippo.ehviewer.ui.scene;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Point;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.AsyncTask;
|
||||
@@ -34,6 +37,7 @@ import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.support.v7.widget.SimpleItemAnimator;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.util.Log;
|
||||
import android.util.SparseBooleanArray;
|
||||
import android.view.Display;
|
||||
import android.view.Gravity;
|
||||
@@ -68,6 +72,7 @@ import com.hippo.ehviewer.download.DownloadManager;
|
||||
import com.hippo.ehviewer.download.DownloadService;
|
||||
import com.hippo.ehviewer.spider.SpiderDen;
|
||||
import com.hippo.ehviewer.ui.GalleryActivity;
|
||||
import com.hippo.ehviewer.ui.MainActivity;
|
||||
import com.hippo.ehviewer.widget.SimpleRatingView;
|
||||
import com.hippo.rippleold.RippleSalon;
|
||||
import com.hippo.scene.Announcer;
|
||||
@@ -77,6 +82,7 @@ import com.hippo.util.DrawableManager;
|
||||
import com.hippo.view.ViewTransition;
|
||||
import com.hippo.widget.FabLayout;
|
||||
import com.hippo.widget.LoadImageView;
|
||||
import com.hippo.yorozuya.AssertUtils;
|
||||
import com.hippo.yorozuya.FileUtils;
|
||||
import com.hippo.yorozuya.LongList;
|
||||
import com.hippo.yorozuya.ObjectUtils;
|
||||
@@ -94,6 +100,8 @@ public class DownloadsScene extends ToolbarScene
|
||||
EasyRecyclerView.OnItemLongClickListener,
|
||||
FabLayout.OnClickFabListener, FastScroller.OnDragHandlerListener {
|
||||
|
||||
private static final String TAG = DownloadsScene.class.getSimpleName();
|
||||
|
||||
public static final String KEY_ACTION = "action";
|
||||
private static final String KEY_LABEL = "label";
|
||||
|
||||
@@ -123,6 +131,8 @@ public class DownloadsScene extends ToolbarScene
|
||||
@Nullable
|
||||
private LinearLayoutManager mLayoutManager;
|
||||
|
||||
private ShowcaseView mShowcaseView;
|
||||
|
||||
@Override
|
||||
public int getNavCheckedItem() {
|
||||
return R.id.nav_downloads;
|
||||
@@ -145,7 +155,9 @@ public class DownloadsScene extends ToolbarScene
|
||||
|
||||
handleArguments(getArguments());
|
||||
|
||||
mDownloadManager = EhApplication.getDownloadManager(getContext());
|
||||
Context context = getContext2();
|
||||
AssertUtils.assertNotNull(context);
|
||||
mDownloadManager = EhApplication.getDownloadManager(context);
|
||||
mDownloadManager.addDownloadInfoListener(this);
|
||||
|
||||
if (savedInstanceState == null) {
|
||||
@@ -162,11 +174,19 @@ public class DownloadsScene extends ToolbarScene
|
||||
|
||||
DownloadManager manager = mDownloadManager;
|
||||
if (null == manager) {
|
||||
manager = EhApplication.getDownloadManager(getContext());
|
||||
Context context = getContext2();
|
||||
if (null != context) {
|
||||
manager = EhApplication.getDownloadManager(context);
|
||||
}
|
||||
} else {
|
||||
mDownloadManager = null;
|
||||
}
|
||||
manager.removeDownloadInfoListener(this);
|
||||
|
||||
if (null != manager) {
|
||||
manager.removeDownloadInfoListener(this);
|
||||
} else {
|
||||
Log.e(TAG, "Can't removeDownloadInfoListener");
|
||||
}
|
||||
}
|
||||
|
||||
private void updateForLabel() {
|
||||
@@ -226,14 +246,17 @@ public class DownloadsScene extends ToolbarScene
|
||||
TextView tip = (TextView) ViewUtils.$$(view, R.id.tip);
|
||||
mViewTransition = new ViewTransition(content, tip);
|
||||
|
||||
Drawable drawable = DrawableManager.getDrawable(getContext(), R.drawable.big_download);
|
||||
Context context = getContext2();
|
||||
AssertUtils.assertNotNull(content);
|
||||
|
||||
Drawable drawable = DrawableManager.getDrawable(context, R.drawable.big_download);
|
||||
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
|
||||
tip.setCompoundDrawables(null, drawable, null, null);
|
||||
|
||||
mAdapter = new DownloadAdapter();
|
||||
mAdapter.setHasStableIds(true);
|
||||
mRecyclerView.setAdapter(mAdapter);
|
||||
mLayoutManager = new LinearLayoutManager(getContext());
|
||||
mLayoutManager = new LinearLayoutManager(context);
|
||||
mRecyclerView.setLayoutManager(mLayoutManager);
|
||||
mRecyclerView.setSelector(RippleSalon.generateRippleDrawable(false));
|
||||
mRecyclerView.setDrawSelectorOnTop(true);
|
||||
@@ -248,13 +271,13 @@ public class DownloadsScene extends ToolbarScene
|
||||
if (itemAnimator instanceof SimpleItemAnimator) {
|
||||
((SimpleItemAnimator) itemAnimator).setSupportsChangeAnimations(false);
|
||||
}
|
||||
int paddingH = getResources().getDimensionPixelOffset(R.dimen.list_content_margin_h);
|
||||
int paddingV = getResources().getDimensionPixelOffset(R.dimen.list_content_margin_v);
|
||||
int paddingH = context.getResources().getDimensionPixelOffset(R.dimen.list_content_margin_h);
|
||||
int paddingV = context.getResources().getDimensionPixelOffset(R.dimen.list_content_margin_v);
|
||||
mRecyclerView.setPadding(paddingV, paddingH, paddingV, paddingH);
|
||||
|
||||
fastScroller.attachToRecyclerView(mRecyclerView);
|
||||
HandlerDrawable handlerDrawable = new HandlerDrawable();
|
||||
handlerDrawable.setColor(ResourcesUtils.getAttrColor(getContext(), R.attr.colorAccent));
|
||||
handlerDrawable.setColor(ResourcesUtils.getAttrColor(context, R.attr.colorAccent));
|
||||
fastScroller.setHandlerDrawable(handlerDrawable);
|
||||
fastScroller.setOnDragHandlerListener(this);
|
||||
|
||||
@@ -284,7 +307,8 @@ public class DownloadsScene extends ToolbarScene
|
||||
}
|
||||
|
||||
private void guideDownloadThumb() {
|
||||
if (!Settings.getGuideDownloadThumb() || null == mLayoutManager || null == mRecyclerView) {
|
||||
MainActivity activity = getActivity2();
|
||||
if (null == activity || !Settings.getGuideDownloadThumb() || null == mLayoutManager || null == mRecyclerView) {
|
||||
guideDownloadLabels();
|
||||
return;
|
||||
}
|
||||
@@ -299,7 +323,7 @@ public class DownloadsScene extends ToolbarScene
|
||||
return;
|
||||
}
|
||||
|
||||
new ShowcaseView.Builder(getActivity())
|
||||
mShowcaseView = new ShowcaseView.Builder(activity)
|
||||
.withMaterialShowcase()
|
||||
.setStyle(R.style.Guide)
|
||||
.setTarget(new ViewTarget(((DownloadHolder) holder).thumb))
|
||||
@@ -310,6 +334,7 @@ public class DownloadsScene extends ToolbarScene
|
||||
.setShowcaseEventListener(new SimpleShowcaseEventListener() {
|
||||
@Override
|
||||
public void onShowcaseViewDidHide(ShowcaseView showcaseView) {
|
||||
mShowcaseView = null;
|
||||
ViewUtils.removeFromParent(showcaseView);
|
||||
Settings.putGuideDownloadThumb(false);
|
||||
guideDownloadLabels();
|
||||
@@ -318,15 +343,16 @@ public class DownloadsScene extends ToolbarScene
|
||||
}
|
||||
|
||||
private void guideDownloadLabels() {
|
||||
if (!Settings.getGuideDownloadLabels()) {
|
||||
MainActivity activity = getActivity2();
|
||||
if (null == activity || !Settings.getGuideDownloadLabels()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Display display = getActivity().getWindowManager().getDefaultDisplay();
|
||||
Display display = activity.getWindowManager().getDefaultDisplay();
|
||||
Point point = new Point();
|
||||
display.getSize(point);
|
||||
|
||||
new ShowcaseView.Builder(getActivity())
|
||||
mShowcaseView = new ShowcaseView.Builder(activity)
|
||||
.withMaterialShowcase()
|
||||
.setStyle(R.style.Guide)
|
||||
.setTarget(new PointTarget(point.x, point.y / 3))
|
||||
@@ -337,6 +363,7 @@ public class DownloadsScene extends ToolbarScene
|
||||
.setShowcaseEventListener(new SimpleShowcaseEventListener() {
|
||||
@Override
|
||||
public void onShowcaseViewDidHide(ShowcaseView showcaseView) {
|
||||
mShowcaseView = null;
|
||||
ViewUtils.removeFromParent(showcaseView);
|
||||
Settings.puttGuideDownloadLabels(false);
|
||||
openDrawer(Gravity.RIGHT);
|
||||
@@ -355,6 +382,11 @@ public class DownloadsScene extends ToolbarScene
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
|
||||
if (null != mShowcaseView) {
|
||||
ViewUtils.removeFromParent(mShowcaseView);
|
||||
mShowcaseView = null;
|
||||
}
|
||||
|
||||
mRecyclerView = null;
|
||||
mFabLayout = null;
|
||||
mViewTransition = null;
|
||||
@@ -375,16 +407,17 @@ public class DownloadsScene extends ToolbarScene
|
||||
@Override
|
||||
public boolean onMenuItemClick(MenuItem item) {
|
||||
// Skip when in choice mode
|
||||
if (mRecyclerView == null || mRecyclerView.isInCustomChoice()) {
|
||||
Activity activity = getActivity2();
|
||||
if (null == activity || null == mRecyclerView || mRecyclerView.isInCustomChoice()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int id = item.getItemId();
|
||||
switch (id) {
|
||||
case R.id.action_start_all: {
|
||||
Intent intent = new Intent(getActivity(), DownloadService.class);
|
||||
Intent intent = new Intent(activity, DownloadService.class);
|
||||
intent.setAction(DownloadService.ACTION_START_ALL);
|
||||
getActivity().startService(intent);
|
||||
activity.startService(intent);
|
||||
return true;
|
||||
}
|
||||
case R.id.action_stop_all: {
|
||||
@@ -412,6 +445,9 @@ public class DownloadsScene extends ToolbarScene
|
||||
@Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
View view = inflater.inflate(R.layout.drawer_list, container, false);
|
||||
|
||||
final Context context = getContext2();
|
||||
AssertUtils.assertNotNull(context);
|
||||
|
||||
Toolbar toolbar = (Toolbar) view.findViewById(R.id.toolbar);
|
||||
toolbar.setTitle(R.string.download_labels);
|
||||
toolbar.inflateMenu(R.menu.drawer_download);
|
||||
@@ -436,7 +472,7 @@ public class DownloadsScene extends ToolbarScene
|
||||
for (int i = 0, n = list.size(); i < n; i++) {
|
||||
items[i + 2] = list.get(i).getLabel();
|
||||
}
|
||||
new AlertDialog.Builder(getContext())
|
||||
new AlertDialog.Builder(context)
|
||||
.setTitle(R.string.default_download_label)
|
||||
.setItems(items, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
@@ -461,7 +497,7 @@ public class DownloadsScene extends ToolbarScene
|
||||
}
|
||||
});
|
||||
|
||||
List<DownloadLabel> list = EhApplication.getDownloadManager(getContext()).getLabelList();
|
||||
List<DownloadLabel> list = EhApplication.getDownloadManager(context).getLabelList();
|
||||
final List<String> labels = new ArrayList<>(list.size() + 1);
|
||||
// Add default label name
|
||||
labels.add(getString(R.string.default_download_label_name));
|
||||
@@ -471,7 +507,7 @@ public class DownloadsScene extends ToolbarScene
|
||||
|
||||
// TODO handle download label items update
|
||||
ListView listView = (ListView) view.findViewById(R.id.list_view);
|
||||
listView.setAdapter(new ArrayAdapter<>(getContext(), R.layout.item_simple_list, labels));
|
||||
listView.setAdapter(new ArrayAdapter<>(context, R.layout.item_simple_list, labels));
|
||||
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
@@ -495,6 +531,10 @@ public class DownloadsScene extends ToolbarScene
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
if (null != mShowcaseView) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (mRecyclerView != null && mRecyclerView.isInCustomChoice()) {
|
||||
mRecyclerView.outOfCustomChoiceMode();
|
||||
} else {
|
||||
@@ -518,8 +558,9 @@ public class DownloadsScene extends ToolbarScene
|
||||
|
||||
@Override
|
||||
public boolean onItemClick(EasyRecyclerView parent, View view, int position, long id) {
|
||||
Activity activity = getActivity2();
|
||||
EasyRecyclerView recyclerView = mRecyclerView;
|
||||
if (recyclerView == null) {
|
||||
if (null == activity || null == recyclerView) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -535,7 +576,7 @@ public class DownloadsScene extends ToolbarScene
|
||||
return false;
|
||||
}
|
||||
|
||||
Intent intent = new Intent(getActivity(), GalleryActivity.class);
|
||||
Intent intent = new Intent(activity, GalleryActivity.class);
|
||||
intent.setAction(GalleryActivity.ACTION_EH);
|
||||
intent.putExtra(GalleryActivity.KEY_GALLERY_INFO, list.get(position));
|
||||
startActivity(intent);
|
||||
@@ -567,8 +608,10 @@ public class DownloadsScene extends ToolbarScene
|
||||
|
||||
@Override
|
||||
public void onClickSecondaryFab(FabLayout view, FloatingActionButton fab, int position) {
|
||||
Context context = getContext2();
|
||||
Activity activity = getActivity2();
|
||||
EasyRecyclerView recyclerView = mRecyclerView;
|
||||
if (recyclerView == null) {
|
||||
if (null == context || null == activity || null == recyclerView) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -606,10 +649,10 @@ public class DownloadsScene extends ToolbarScene
|
||||
|
||||
switch (position) {
|
||||
case 1: { // Start
|
||||
Intent intent = new Intent(getActivity(), DownloadService.class);
|
||||
Intent intent = new Intent(activity, DownloadService.class);
|
||||
intent.setAction(DownloadService.ACTION_START_RANGE);
|
||||
intent.putExtra(DownloadService.KEY_GID_LIST, gidList);
|
||||
getActivity().startService(intent);
|
||||
activity.startService(intent);
|
||||
// Cancel check mode
|
||||
recyclerView.outOfCustomChoiceMode();
|
||||
break;
|
||||
@@ -623,7 +666,7 @@ public class DownloadsScene extends ToolbarScene
|
||||
break;
|
||||
}
|
||||
case 3: { // Delete
|
||||
CheckBoxDialogBuilder builder = new CheckBoxDialogBuilder(getContext(),
|
||||
CheckBoxDialogBuilder builder = new CheckBoxDialogBuilder(context,
|
||||
getString(R.string.download_remove_dialog_message_2, gidList.size()),
|
||||
getString(R.string.download_remove_dialog_check_text),
|
||||
Settings.getRemoveImageFiles());
|
||||
@@ -635,7 +678,7 @@ public class DownloadsScene extends ToolbarScene
|
||||
break;
|
||||
}
|
||||
case 4: {// Move
|
||||
List<DownloadLabel> labelRawList = EhApplication.getDownloadManager(getContext()).getLabelList();
|
||||
List<DownloadLabel> labelRawList = EhApplication.getDownloadManager(context).getLabelList();
|
||||
List<String> labelList = new ArrayList<>(labelRawList.size() + 1);
|
||||
labelList.add(getString(R.string.default_download_label_name));
|
||||
for (int i = 0, n = labelRawList.size(); i < n; i++) {
|
||||
@@ -645,7 +688,7 @@ public class DownloadsScene extends ToolbarScene
|
||||
|
||||
MoveDialogHelper helper = new MoveDialogHelper(labels, downloadInfoList);
|
||||
|
||||
new AlertDialog.Builder(getContext())
|
||||
new AlertDialog.Builder(context)
|
||||
.setTitle(R.string.download_move_dialog_title)
|
||||
.setItems(labels, helper)
|
||||
.show();
|
||||
@@ -728,12 +771,17 @@ public class DownloadsScene extends ToolbarScene
|
||||
}
|
||||
|
||||
private void bindForState(DownloadHolder holder, DownloadInfo info) {
|
||||
Resources resources = getResources2();
|
||||
if (null == resources) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (info.state) {
|
||||
case DownloadInfo.STATE_NONE:
|
||||
bindState(holder, info, getContext().getString(R.string.download_state_none));
|
||||
bindState(holder, info, resources.getString(R.string.download_state_none));
|
||||
break;
|
||||
case DownloadInfo.STATE_WAIT:
|
||||
bindState(holder, info, getContext().getString(R.string.download_state_wait));
|
||||
bindState(holder, info, resources.getString(R.string.download_state_wait));
|
||||
break;
|
||||
case DownloadInfo.STATE_DOWNLOAD:
|
||||
bindProgress(holder, info);
|
||||
@@ -741,14 +789,14 @@ public class DownloadsScene extends ToolbarScene
|
||||
case DownloadInfo.STATE_FAILED:
|
||||
String text;
|
||||
if (info.legacy <= 0) {
|
||||
text = getContext().getString(R.string.download_state_failed);
|
||||
text = resources.getString(R.string.download_state_failed);
|
||||
} else {
|
||||
text = getContext().getString(R.string.download_state_failed_2, info.legacy);
|
||||
text = resources.getString(R.string.download_state_failed_2, info.legacy);
|
||||
}
|
||||
bindState(holder, info, text);
|
||||
break;
|
||||
case DownloadInfo.STATE_FINISH:
|
||||
bindState(holder, info, getContext().getString(R.string.download_state_finish));
|
||||
bindState(holder, info, resources.getString(R.string.download_state_finish));
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -912,7 +960,11 @@ public class DownloadsScene extends ToolbarScene
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
// Cancel check mode
|
||||
if (mRecyclerView != null) {
|
||||
Context context = getContext2();
|
||||
if (null == context) {
|
||||
return;
|
||||
}
|
||||
if (null != mRecyclerView) {
|
||||
mRecyclerView.outOfCustomChoiceMode();
|
||||
}
|
||||
|
||||
@@ -922,7 +974,7 @@ public class DownloadsScene extends ToolbarScene
|
||||
} else {
|
||||
label = mLabels[which];
|
||||
}
|
||||
EhApplication.getDownloadManager(getContext()).changeLabel(mDownloadInfoList, label);
|
||||
EhApplication.getDownloadManager(context).changeLabel(mDownloadInfoList, label);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -969,8 +1021,10 @@ public class DownloadsScene extends ToolbarScene
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Context context = getContext2();
|
||||
Activity activity = getActivity2();
|
||||
EasyRecyclerView recyclerView = mRecyclerView;
|
||||
if (recyclerView == null || recyclerView.isInCustomChoice()) {
|
||||
if (null == context || null == activity || null == recyclerView || recyclerView.isInCustomChoice()) {
|
||||
return;
|
||||
}
|
||||
List<DownloadInfo> list = mList;
|
||||
@@ -993,17 +1047,17 @@ public class DownloadsScene extends ToolbarScene
|
||||
}
|
||||
startScene(announcer);
|
||||
} else if (start == v) {
|
||||
Intent intent = new Intent(getActivity(), DownloadService.class);
|
||||
Intent intent = new Intent(activity, DownloadService.class);
|
||||
intent.setAction(DownloadService.ACTION_START);
|
||||
intent.putExtra(DownloadService.KEY_GALLERY_INFO, list.get(index));
|
||||
getActivity().startService(intent);
|
||||
activity.startService(intent);
|
||||
} else if (stop == v) {
|
||||
if (null != mDownloadManager) {
|
||||
mDownloadManager.stopDownload(list.get(index).gid);
|
||||
}
|
||||
} else if (delete == v) {
|
||||
GalleryInfo galleryInfo = list.get(index);
|
||||
CheckBoxDialogBuilder builder = new CheckBoxDialogBuilder(getContext(),
|
||||
CheckBoxDialogBuilder builder = new CheckBoxDialogBuilder(context,
|
||||
getString(R.string.download_remove_dialog_message, EhUtils.getSuitableTitle(galleryInfo)),
|
||||
getString(R.string.download_remove_dialog_check_text),
|
||||
Settings.getRemoveImageFiles());
|
||||
@@ -1017,6 +1071,13 @@ public class DownloadsScene extends ToolbarScene
|
||||
|
||||
private class DownloadAdapter extends RecyclerView.Adapter<DownloadHolder> {
|
||||
|
||||
private final LayoutInflater mInflater;
|
||||
|
||||
public DownloadAdapter() {
|
||||
mInflater = getLayoutInflater2();
|
||||
AssertUtils.assertNotNull(mInflater);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
if (mList == null || position < 0 || position >= mList.size()) {
|
||||
@@ -1027,7 +1088,7 @@ public class DownloadsScene extends ToolbarScene
|
||||
|
||||
@Override
|
||||
public DownloadHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
return new DownloadHolder(getActivity().getLayoutInflater().inflate(R.layout.item_download, parent, false));
|
||||
return new DownloadHolder(mInflater.inflate(R.layout.item_download, parent, false));
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
||||
|
||||
@@ -16,17 +16,18 @@
|
||||
|
||||
package com.hippo.ehviewer.ui.scene;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Point;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.design.widget.FloatingActionButton;
|
||||
import android.support.v4.widget.DrawerLayout;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.support.v7.widget.GridLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.text.Spannable;
|
||||
@@ -60,8 +61,8 @@ import com.hippo.ehviewer.client.EhRequest;
|
||||
import com.hippo.ehviewer.client.EhUrl;
|
||||
import com.hippo.ehviewer.client.data.FavListUrlBuilder;
|
||||
import com.hippo.ehviewer.client.data.GalleryInfo;
|
||||
import com.hippo.ehviewer.client.exception.NotFoundException;
|
||||
import com.hippo.ehviewer.client.parser.FavoritesParser;
|
||||
import com.hippo.ehviewer.ui.MainActivity;
|
||||
import com.hippo.ehviewer.ui.annotation.DrawerLifeCircle;
|
||||
import com.hippo.ehviewer.ui.annotation.ViewLifeCircle;
|
||||
import com.hippo.ehviewer.ui.annotation.WholeLifeCircle;
|
||||
@@ -69,13 +70,13 @@ import com.hippo.ehviewer.widget.SearchBar;
|
||||
import com.hippo.rippleold.RippleSalon;
|
||||
import com.hippo.scene.Announcer;
|
||||
import com.hippo.scene.SceneFragment;
|
||||
import com.hippo.scene.StageActivity;
|
||||
import com.hippo.util.ApiHelper;
|
||||
import com.hippo.util.DrawableManager;
|
||||
import com.hippo.widget.ContentLayout;
|
||||
import com.hippo.widget.FabLayout;
|
||||
import com.hippo.widget.SearchBarMover;
|
||||
import com.hippo.widget.refreshlayout.RefreshLayout;
|
||||
import com.hippo.yorozuya.AssertUtils;
|
||||
import com.hippo.yorozuya.ObjectUtils;
|
||||
import com.hippo.yorozuya.SimpleHandler;
|
||||
import com.hippo.yorozuya.ViewUtils;
|
||||
@@ -172,6 +173,8 @@ public class FavoritesScene extends BaseScene implements
|
||||
}
|
||||
};
|
||||
|
||||
private ShowcaseView mShowcaseView;
|
||||
|
||||
@Override
|
||||
public int getNavCheckedItem() {
|
||||
return R.id.nav_favourite;
|
||||
@@ -181,7 +184,9 @@ public class FavoritesScene extends BaseScene implements
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
mClient = EhApplication.getEhClient(getContext());
|
||||
Context context = getContext2();
|
||||
AssertUtils.assertNotNull(context);
|
||||
mClient = EhApplication.getEhClient(context);
|
||||
mFavCatArray = Settings.getFavCat();
|
||||
|
||||
if (savedInstanceState == null) {
|
||||
@@ -248,15 +253,18 @@ public class FavoritesScene extends BaseScene implements
|
||||
mSearchBar = (SearchBar) ViewUtils.$$(view, R.id.search_bar);
|
||||
mFabLayout = (FabLayout) ViewUtils.$$(view, R.id.fab_layout);
|
||||
|
||||
Resources resources = getResources();
|
||||
Context context = getContext2();
|
||||
AssertUtils.assertNotNull(context);
|
||||
Resources resources = context.getResources();
|
||||
int paddingTopSB = resources.getDimensionPixelOffset(R.dimen.list_padding_top_search_bar);
|
||||
|
||||
mHelper = new FavoritesHelper();
|
||||
mHelper.setEmptyString(resources.getString(R.string.gallery_list_empty_hit));
|
||||
contentLayout.setHelper(mHelper);
|
||||
contentLayout.getFastScroller().setOnDragHandlerListener(this);
|
||||
|
||||
GridLayoutManager layoutManager = new GridLayoutManager(getContext(), 1);
|
||||
mRecyclerView.setLayoutManager(layoutManager);
|
||||
mAdapter = new FavoritesAdapter(inflater, resources, mRecyclerView, Settings.getListMode());
|
||||
mAdapter.register();
|
||||
mRecyclerView.setSelector(RippleSalon.generateRippleDrawable(false));
|
||||
mRecyclerView.setDrawSelectorOnTop(true);
|
||||
mRecyclerView.hasFixedSize();
|
||||
@@ -265,10 +273,6 @@ public class FavoritesScene extends BaseScene implements
|
||||
mRecyclerView.setOnItemLongClickListener(this);
|
||||
mRecyclerView.setChoiceMode(EasyRecyclerView.CHOICE_MODE_MULTIPLE_CUSTOM);
|
||||
mRecyclerView.setCustomCheckedListener(this);
|
||||
mAdapter = new FavoritesAdapter(LayoutInflater.from(getContext()),
|
||||
getContext(), mRecyclerView, layoutManager, Settings.getListMode());
|
||||
mRecyclerView.setAdapter(mAdapter);
|
||||
mAdapter.register();
|
||||
mRecyclerView.setPadding(mRecyclerView.getPaddingLeft(), mRecyclerView.getPaddingTop() + paddingTopSB,
|
||||
mRecyclerView.getPaddingRight(), mRecyclerView.getPaddingBottom());
|
||||
|
||||
@@ -277,9 +281,9 @@ public class FavoritesScene extends BaseScene implements
|
||||
|
||||
refreshLayout.setHeaderTranslationY(paddingTopSB);
|
||||
|
||||
mLeftDrawable = new DrawerArrowDrawable(getContext());
|
||||
mLeftDrawable = new DrawerArrowDrawable(context);
|
||||
mSearchBar.setLeftDrawable(mLeftDrawable);
|
||||
mSearchBar.setRightDrawable(DrawableManager.getDrawable(getContext(), R.drawable.v_magnify_x24));
|
||||
mSearchBar.setRightDrawable(DrawableManager.getDrawable(context, R.drawable.v_magnify_x24));
|
||||
mSearchBar.setHelper(this);
|
||||
mSearchBar.setAllowEmptySearch(false);
|
||||
updateSearchBar();
|
||||
@@ -308,15 +312,16 @@ public class FavoritesScene extends BaseScene implements
|
||||
}
|
||||
|
||||
private void guideCollections() {
|
||||
if (!Settings.getGuideCollections()) {
|
||||
Activity activity = getActivity2();
|
||||
if (null == activity || !Settings.getGuideCollections()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Display display = getActivity().getWindowManager().getDefaultDisplay();
|
||||
Display display = activity.getWindowManager().getDefaultDisplay();
|
||||
Point point = new Point();
|
||||
display.getSize(point);
|
||||
|
||||
new ShowcaseView.Builder(getActivity())
|
||||
mShowcaseView = new ShowcaseView.Builder(activity)
|
||||
.withMaterialShowcase()
|
||||
.setStyle(R.style.Guide)
|
||||
.setTarget(new PointTarget(point.x, point.y / 3))
|
||||
@@ -327,6 +332,7 @@ public class FavoritesScene extends BaseScene implements
|
||||
.setShowcaseEventListener(new SimpleShowcaseEventListener() {
|
||||
@Override
|
||||
public void onShowcaseViewDidHide(ShowcaseView showcaseView) {
|
||||
mShowcaseView = null;
|
||||
ViewUtils.removeFromParent(showcaseView);
|
||||
Settings.putGuideCollections(false);
|
||||
openDrawer(Gravity.RIGHT);
|
||||
@@ -337,7 +343,8 @@ public class FavoritesScene extends BaseScene implements
|
||||
// keyword of mUrlBuilder, fav cat of mUrlBuilder, mFavCatArray.
|
||||
// They changed, call it
|
||||
private void updateSearchBar() {
|
||||
if (mUrlBuilder == null || mSearchBar == null || mFavCatArray == null) {
|
||||
Context context = getContext2();
|
||||
if (null == context || null == mUrlBuilder || null == mSearchBar || null == mFavCatArray) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -364,7 +371,7 @@ public class FavoritesScene extends BaseScene implements
|
||||
|
||||
// Update hint
|
||||
if (!ObjectUtils.equal(favCatName, mOldFavCat)) {
|
||||
Drawable searchImage = DrawableManager.getDrawable(getContext(), R.drawable.v_magnify_x24);
|
||||
Drawable searchImage = DrawableManager.getDrawable(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);
|
||||
@@ -386,6 +393,11 @@ public class FavoritesScene extends BaseScene implements
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
|
||||
if (null != mShowcaseView) {
|
||||
ViewUtils.removeFromParent(mShowcaseView);
|
||||
mShowcaseView = null;
|
||||
}
|
||||
|
||||
if (null != mAdapter) {
|
||||
mAdapter.unregister();
|
||||
mAdapter = null;
|
||||
@@ -409,7 +421,8 @@ public class FavoritesScene extends BaseScene implements
|
||||
}
|
||||
|
||||
private void showFavoritesInfoDialog() {
|
||||
if (mFavCatArray == null || mFavCountArray == null) {
|
||||
Context context = getContext2();
|
||||
if (null == context || null == mFavCatArray || null == mFavCountArray) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -419,7 +432,7 @@ public class FavoritesScene extends BaseScene implements
|
||||
sb.append(mFavCatArray[i]).append(": ").append(mFavCountArray[i]).append("\n");
|
||||
}
|
||||
|
||||
new AlertDialog.Builder(getContext())
|
||||
new AlertDialog.Builder(context)
|
||||
.setTitle(R.string.favorites_info)
|
||||
.setMessage(sb.toString())
|
||||
.show();
|
||||
@@ -432,6 +445,9 @@ public class FavoritesScene extends BaseScene implements
|
||||
Toolbar toolbar = (Toolbar) ViewUtils.$$(view, R.id.toolbar);
|
||||
ListView listView = (ListView) view.findViewById(R.id.list_view);
|
||||
|
||||
final Context context = getContext2();
|
||||
AssertUtils.assertNotNull(context);
|
||||
|
||||
toolbar.setTitle(R.string.collections);
|
||||
toolbar.inflateMenu(R.menu.drawer_favorites);
|
||||
toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
|
||||
@@ -448,7 +464,7 @@ public class FavoritesScene extends BaseScene implements
|
||||
items[1] = getString(R.string.local_favorites);
|
||||
String[] favCat = Settings.getFavCat();
|
||||
System.arraycopy(favCat, 0, items, 2, 10);
|
||||
new AlertDialog.Builder(getContext())
|
||||
new AlertDialog.Builder(context)
|
||||
.setTitle(R.string.default_favorites_collection)
|
||||
.setItems(items, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
@@ -468,7 +484,7 @@ public class FavoritesScene extends BaseScene implements
|
||||
if (mFavCatArray != null) {
|
||||
Collections.addAll(mDrawerList, mFavCatArray);
|
||||
}
|
||||
mDrawerAdapter = new ArrayAdapter<>(getContext(), R.layout.item_simple_list, mDrawerList);
|
||||
mDrawerAdapter = new ArrayAdapter<>(context, R.layout.item_simple_list, mDrawerList);
|
||||
listView.setAdapter(mDrawerAdapter);
|
||||
listView.setOnItemClickListener(this);
|
||||
|
||||
@@ -485,6 +501,10 @@ public class FavoritesScene extends BaseScene implements
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
if (null != mShowcaseView) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (mRecyclerView != null && mRecyclerView.isInCustomChoice()) {
|
||||
mRecyclerView.outOfCustomChoiceMode();
|
||||
} else if (mSearchMode) {
|
||||
@@ -656,7 +676,8 @@ public class FavoritesScene extends BaseScene implements
|
||||
@Override
|
||||
@Implemented(FabLayout.OnClickFabListener.class)
|
||||
public void onClickSecondaryFab(FabLayout view, FloatingActionButton fab, int position) {
|
||||
if (mRecyclerView == null || mHelper == null || !mRecyclerView.isInCustomChoice()) {
|
||||
Context context = getContext2();
|
||||
if (null == context || null == mRecyclerView || null == mHelper || !mRecyclerView.isInCustomChoice()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -671,7 +692,7 @@ public class FavoritesScene extends BaseScene implements
|
||||
switch (position) {
|
||||
case 0: { // Delete
|
||||
DeleteDialogHelper helper = new DeleteDialogHelper();
|
||||
new AlertDialog.Builder(getContext())
|
||||
new AlertDialog.Builder(context)
|
||||
.setTitle(R.string.delete_favorites_dialog_title)
|
||||
.setMessage(getString(R.string.delete_favorites_dialog_message, mModifyGiList.size()))
|
||||
.setPositiveButton(android.R.string.ok, helper)
|
||||
@@ -685,7 +706,7 @@ public class FavoritesScene extends BaseScene implements
|
||||
String[] array = new String[11];
|
||||
array[0] = getString(R.string.local_favorites);
|
||||
System.arraycopy(Settings.getFavCat(), 0, array, 1, 10);
|
||||
new AlertDialog.Builder(getContext())
|
||||
new AlertDialog.Builder(context)
|
||||
.setTitle(R.string.move_favorites_dialog_title)
|
||||
.setItems(array, helper)
|
||||
.setOnCancelListener(helper)
|
||||
@@ -823,6 +844,7 @@ public class FavoritesScene extends BaseScene implements
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private void onGetFavoritesLocal(String keyword, int taskId) {
|
||||
if (mHelper != null && mHelper.isCurrentTask(taskId)) {
|
||||
List<GalleryInfo> list;
|
||||
@@ -832,7 +854,8 @@ public class FavoritesScene extends BaseScene implements
|
||||
list = EhDB.searchLocalFavorites(keyword);
|
||||
}
|
||||
if (list.size() == 0) {
|
||||
mHelper.onGetException(taskId, new NotFoundException());
|
||||
mHelper.setPages(taskId, 0);
|
||||
mHelper.onGetPageData(taskId, Collections.EMPTY_LIST);
|
||||
} else {
|
||||
mHelper.setPages(taskId, 1);
|
||||
mHelper.onGetPageData(taskId, list);
|
||||
@@ -930,9 +953,9 @@ public class FavoritesScene extends BaseScene implements
|
||||
|
||||
private class FavoritesAdapter extends GalleryAdapter {
|
||||
|
||||
public FavoritesAdapter(LayoutInflater inflater, Context context,
|
||||
RecyclerView recyclerView, GridLayoutManager layoutManager, int type) {
|
||||
super(inflater, context, recyclerView, layoutManager, type);
|
||||
public FavoritesAdapter(@NonNull LayoutInflater inflater, @NonNull Resources resources,
|
||||
@NonNull RecyclerView recyclerView, int type) {
|
||||
super(inflater, resources, recyclerView, type);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -951,7 +974,8 @@ public class FavoritesScene extends BaseScene implements
|
||||
|
||||
@Override
|
||||
protected void getPageData(final int taskId, int type, int page) {
|
||||
if (mUrlBuilder == null || mClient == null) {
|
||||
MainActivity activity = getActivity2();
|
||||
if (null == activity || null == mUrlBuilder || null == mClient ) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -973,7 +997,7 @@ public class FavoritesScene extends BaseScene implements
|
||||
EhRequest request = new EhRequest();
|
||||
request.setMethod(EhClient.METHOD_ADD_FAVORITES_RANGE);
|
||||
request.setCallback(new AddFavoritesListener(getContext(),
|
||||
((StageActivity) getActivity()).getStageId(), getTag(),
|
||||
activity.getStageId(), getTag(),
|
||||
taskId, mUrlBuilder.getKeyword()));
|
||||
request.setArgs(gidArray, tokenArray, mModifyFavCat);
|
||||
mClient.execute(request);
|
||||
@@ -987,7 +1011,7 @@ public class FavoritesScene extends BaseScene implements
|
||||
String url;
|
||||
if (local) {
|
||||
// Local fav is shown now, but operation need be done for cloud fav
|
||||
url = EhUrl.URL_FAVORITES;
|
||||
url = EhUrl.getFavoritesUrl();
|
||||
} else {
|
||||
url = mUrlBuilder.build();
|
||||
}
|
||||
@@ -996,7 +1020,7 @@ public class FavoritesScene extends BaseScene implements
|
||||
EhRequest request = new EhRequest();
|
||||
request.setMethod(EhClient.METHOD_MODIFY_FAVORITES);
|
||||
request.setCallback(new GetFavoritesListener(getContext(),
|
||||
((StageActivity) getActivity()).getStageId(), getTag(),
|
||||
activity.getStageId(), getTag(),
|
||||
taskId, local, mUrlBuilder.getKeyword()));
|
||||
request.setArgs(url, gidArray, mModifyFavCat, Settings.getShowJpnTitle());
|
||||
mClient.execute(request);
|
||||
@@ -1015,7 +1039,7 @@ public class FavoritesScene extends BaseScene implements
|
||||
EhRequest request = new EhRequest();
|
||||
request.setMethod(EhClient.METHOD_GET_FAVORITES);
|
||||
request.setCallback(new GetFavoritesListener(getContext(),
|
||||
((StageActivity) getActivity()).getStageId(), getTag(),
|
||||
activity.getStageId(), getTag(),
|
||||
taskId, false, mUrlBuilder.getKeyword()));
|
||||
request.setArgs(url, Settings.getShowJpnTitle());
|
||||
mClient.execute(request);
|
||||
@@ -1032,7 +1056,7 @@ public class FavoritesScene extends BaseScene implements
|
||||
|
||||
@Override
|
||||
protected Context getContext() {
|
||||
return FavoritesScene.this.getContext();
|
||||
return FavoritesScene.this.getContext2();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -17,14 +17,14 @@
|
||||
package com.hippo.ehviewer.ui.scene;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Build;
|
||||
import android.support.annotation.IntDef;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.widget.GridLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.support.v7.widget.StaggeredGridLayoutManager;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
@@ -38,8 +38,10 @@ import com.hippo.ehviewer.Settings;
|
||||
import com.hippo.ehviewer.client.EhCacheKeyFactory;
|
||||
import com.hippo.ehviewer.client.EhUtils;
|
||||
import com.hippo.ehviewer.client.data.GalleryInfo;
|
||||
import com.hippo.ehviewer.widget.TileThumb;
|
||||
import com.hippo.util.ApiHelper;
|
||||
import com.hippo.util.LayoutUtils2;
|
||||
import com.hippo.widget.recyclerview.AutoGridLayoutManager;
|
||||
import com.hippo.widget.recyclerview.AutoStaggeredGridLayoutManager;
|
||||
import com.hippo.yorozuya.Messenger;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
@@ -56,20 +58,21 @@ abstract class GalleryAdapter extends RecyclerView.Adapter<GalleryHolder> implem
|
||||
public static final int TYPE_GRID = 1;
|
||||
|
||||
private final LayoutInflater mInflater;
|
||||
private final Context mContext;
|
||||
private final Resources mResources;
|
||||
private final RecyclerView mRecyclerView;
|
||||
private final GridLayoutManager mLayoutManager;
|
||||
private final AutoStaggeredGridLayoutManager mLayoutManager;
|
||||
private RecyclerView.ItemDecoration mGirdDecoration;
|
||||
private int mType = TYPE_INVALID;
|
||||
|
||||
public GalleryAdapter(LayoutInflater inflater, Context context,
|
||||
RecyclerView recyclerView, GridLayoutManager layoutManager, int type) {
|
||||
public GalleryAdapter(@NonNull LayoutInflater inflater, @NonNull Resources resources,
|
||||
@NonNull RecyclerView recyclerView, int type) {
|
||||
mInflater = inflater;
|
||||
mContext = context;
|
||||
mResources = context.getResources();
|
||||
mResources = resources;
|
||||
mRecyclerView = recyclerView;
|
||||
mLayoutManager = layoutManager;
|
||||
mLayoutManager = new AutoStaggeredGridLayoutManager(0, StaggeredGridLayoutManager.VERTICAL);
|
||||
|
||||
mRecyclerView.setAdapter(this);
|
||||
mRecyclerView.setLayoutManager(mLayoutManager);
|
||||
|
||||
int paddingH = mResources.getDimensionPixelOffset(R.dimen.list_content_margin_h);
|
||||
int paddingV = mResources.getDimensionPixelOffset(R.dimen.list_content_margin_v);
|
||||
@@ -90,9 +93,9 @@ abstract class GalleryAdapter extends RecyclerView.Adapter<GalleryHolder> implem
|
||||
switch (type) {
|
||||
default:
|
||||
case GalleryAdapter.TYPE_LIST: {
|
||||
int minWidth = mResources.getDimensionPixelOffset(R.dimen.gallery_list_min_width);
|
||||
int spanCount = LayoutUtils2.calculateSpanCount(mContext, minWidth);
|
||||
mLayoutManager.setSpanCount(spanCount);
|
||||
int columnWidth = mResources.getDimensionPixelOffset(R.dimen.gallery_list_column_width);
|
||||
mLayoutManager.setColumnSize(columnWidth);
|
||||
mLayoutManager.setStrategy(AutoGridLayoutManager.STRATEGY_MIN_SIZE);
|
||||
if (null != mGirdDecoration) {
|
||||
mRecyclerView.removeItemDecoration(mGirdDecoration);
|
||||
}
|
||||
@@ -100,12 +103,12 @@ abstract class GalleryAdapter extends RecyclerView.Adapter<GalleryHolder> implem
|
||||
break;
|
||||
}
|
||||
case GalleryAdapter.TYPE_GRID: {
|
||||
int minWidth = mResources.getDimensionPixelOffset(R.dimen.gallery_grid_min_width);
|
||||
int spanCount = LayoutUtils2.calculateSpanCount(mContext, minWidth);
|
||||
mLayoutManager.setSpanCount(spanCount);
|
||||
int columnWidth = mResources.getDimensionPixelOffset(R.dimen.gallery_grid_column_width);
|
||||
mLayoutManager.setColumnSize(columnWidth);
|
||||
mLayoutManager.setStrategy(AutoGridLayoutManager.STRATEGY_SUITABLE_SIZE);
|
||||
if (null == mGirdDecoration) {
|
||||
mGirdDecoration = new MarginItemDecoration(
|
||||
mResources.getDimensionPixelOffset(R.dimen.list_content_interval));
|
||||
mResources.getDimensionPixelOffset(R.dimen.gallery_grid_margin) / 2);
|
||||
}
|
||||
mRecyclerView.addItemDecoration(mGirdDecoration);
|
||||
notifyDataSetChanged();
|
||||
@@ -163,6 +166,7 @@ abstract class GalleryAdapter extends RecyclerView.Adapter<GalleryHolder> implem
|
||||
break;
|
||||
}
|
||||
case TYPE_GRID: {
|
||||
((TileThumb) holder.thumb).setThumbSize(gi.thumbWidth, gi.thumbHeight);
|
||||
holder.thumb.load(EhCacheKeyFactory.getThumbKey(gi.gid), gi.thumb);
|
||||
View category = holder.category;
|
||||
Drawable drawable = category.getBackground();
|
||||
|
||||
@@ -18,7 +18,9 @@ package com.hippo.ehviewer.ui.scene;
|
||||
|
||||
import android.animation.Animator;
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
@@ -48,18 +50,18 @@ import com.hippo.ehviewer.client.EhClient;
|
||||
import com.hippo.ehviewer.client.EhRequest;
|
||||
import com.hippo.ehviewer.client.EhUrl;
|
||||
import com.hippo.ehviewer.client.data.GalleryComment;
|
||||
import com.hippo.ehviewer.ui.MainActivity;
|
||||
import com.hippo.rippleold.RippleSalon;
|
||||
import com.hippo.scene.SceneFragment;
|
||||
import com.hippo.scene.StageActivity;
|
||||
import com.hippo.text.Html;
|
||||
import com.hippo.text.URLImageGetter;
|
||||
import com.hippo.util.ActivityHelper;
|
||||
import com.hippo.util.DrawableManager;
|
||||
import com.hippo.util.ReadableTime;
|
||||
import com.hippo.util.TextUrl;
|
||||
import com.hippo.view.ViewTransition;
|
||||
import com.hippo.widget.LinkifyTextView;
|
||||
import com.hippo.yorozuya.AnimationUtils;
|
||||
import com.hippo.yorozuya.AssertUtils;
|
||||
import com.hippo.yorozuya.LayoutUtils;
|
||||
import com.hippo.yorozuya.SimpleAnimatorListener;
|
||||
import com.hippo.yorozuya.ViewUtils;
|
||||
@@ -143,19 +145,22 @@ public final class GalleryCommentsScene extends ToolbarScene
|
||||
mEditText = (EditText) ViewUtils.$$(mEditPanel, R.id.edit_text);
|
||||
mFab = (FloatingActionButton) ViewUtils.$$(view, R.id.fab);
|
||||
|
||||
int paddingBottomFab = getResources().getDimensionPixelOffset(R.dimen.list_padding_bottom_fab);
|
||||
Context context = getContext2();
|
||||
AssertUtils.assertNotNull(context);
|
||||
Resources resources = context.getResources();
|
||||
int paddingBottomFab = resources.getDimensionPixelOffset(R.dimen.list_padding_bottom_fab);
|
||||
|
||||
Drawable drawable = DrawableManager.getDrawable(getContext(), R.drawable.big_weird_face);
|
||||
Drawable drawable = DrawableManager.getDrawable(context, R.drawable.big_weird_face);
|
||||
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
|
||||
tip.setCompoundDrawables(null, drawable, null, null);
|
||||
|
||||
mAdapter = new CommentAdapter();
|
||||
recyclerView.setAdapter(mAdapter);
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(getContext(),
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(context,
|
||||
LinearLayoutManager.VERTICAL, false));
|
||||
LinearDividerItemDecoration decoration = new LinearDividerItemDecoration(
|
||||
LinearDividerItemDecoration.VERTICAL, getResources().getColor(R.color.divider),
|
||||
LayoutUtils.dp2pix(getContext(), 1));
|
||||
LinearDividerItemDecoration.VERTICAL, context.getResources().getColor(R.color.divider),
|
||||
LayoutUtils.dp2pix(context, 1));
|
||||
decoration.setShowLastDivider(true);
|
||||
recyclerView.addItemDecoration(decoration);
|
||||
recyclerView.setSelector(RippleSalon.generateRippleDrawable(false));
|
||||
@@ -200,6 +205,11 @@ public final class GalleryCommentsScene extends ToolbarScene
|
||||
|
||||
@Override
|
||||
public boolean onItemClick(EasyRecyclerView parent, View view, int position, long id) {
|
||||
Activity activity = getActivity2();
|
||||
if (null == activity) {
|
||||
return false;
|
||||
}
|
||||
|
||||
RecyclerView.ViewHolder holder = parent.getChildViewHolder(view);
|
||||
if (holder instanceof CommentHolder) {
|
||||
CommentHolder commentHolder = (CommentHolder) holder;
|
||||
@@ -207,7 +217,7 @@ public final class GalleryCommentsScene extends ToolbarScene
|
||||
commentHolder.comment.clearCurrentSpan();
|
||||
|
||||
if (span instanceof URLSpan) {
|
||||
UrlOpener.openUrl(getActivity(), ((URLSpan) span).getURL(), true, true);
|
||||
UrlOpener.openUrl(activity, ((URLSpan) span).getURL(), true, true);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -322,6 +332,12 @@ public final class GalleryCommentsScene extends ToolbarScene
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Context context = getContext2();
|
||||
MainActivity activity = getActivity2();
|
||||
if (null == context || null == activity) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (mFab == v) {
|
||||
if (!mInAnimation) {
|
||||
showEditPanel(true);
|
||||
@@ -341,10 +357,10 @@ public final class GalleryCommentsScene extends ToolbarScene
|
||||
EhRequest request = new EhRequest()
|
||||
.setMethod(EhClient.METHOD_GET_COMMENT_GALLERY)
|
||||
.setArgs(url, comment)
|
||||
.setCallback(new CommentGalleryListener(getContext(),
|
||||
((StageActivity) getActivity()).getStageId(), getTag()));
|
||||
EhApplication.getEhClient(getContext()).execute(request);
|
||||
ActivityHelper.hideSoftInput(getActivity());
|
||||
.setCallback(new CommentGalleryListener(context,
|
||||
activity.getStageId(), getTag()));
|
||||
EhApplication.getEhClient(context).execute(request);
|
||||
hideSoftInput();
|
||||
hideEditPanel(true);
|
||||
}
|
||||
}
|
||||
@@ -378,19 +394,30 @@ public final class GalleryCommentsScene extends ToolbarScene
|
||||
|
||||
private class CommentAdapter extends RecyclerView.Adapter<CommentHolder> {
|
||||
|
||||
private final LayoutInflater mInflater;
|
||||
|
||||
public CommentAdapter() {
|
||||
mInflater = getLayoutInflater2();
|
||||
AssertUtils.assertNotNull(mInflater);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommentHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
return new CommentHolder(getActivity().getLayoutInflater()
|
||||
.inflate(R.layout.item_gallery_comment, parent, false));
|
||||
return new CommentHolder(mInflater.inflate(R.layout.item_gallery_comment, parent, false));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(CommentHolder holder, int position) {
|
||||
Context context = getContext2();
|
||||
if (null == context) {
|
||||
return;
|
||||
}
|
||||
|
||||
GalleryComment comment = mComments[position];
|
||||
holder.user.setText(comment.user);
|
||||
holder.time.setText(ReadableTime.getTimeAgo(comment.time));
|
||||
holder.comment.setText(TextUrl.handleTextUrl(Html.fromHtml(comment.comment,
|
||||
new URLImageGetter(holder.comment, EhApplication.getConaco(getContext())), null)));
|
||||
new URLImageGetter(holder.comment, EhApplication.getConaco(context)), null)));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -16,8 +16,8 @@
|
||||
|
||||
package com.hippo.ehviewer.ui.scene;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.Activity;
|
||||
import android.app.Dialog;
|
||||
import android.app.DownloadManager;
|
||||
import android.content.Context;
|
||||
@@ -61,6 +61,7 @@ import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.UrlOpener;
|
||||
import com.hippo.ehviewer.client.EhCacheKeyFactory;
|
||||
import com.hippo.ehviewer.client.EhClient;
|
||||
import com.hippo.ehviewer.client.EhFilter;
|
||||
import com.hippo.ehviewer.client.EhRequest;
|
||||
import com.hippo.ehviewer.client.EhUrl;
|
||||
import com.hippo.ehviewer.client.EhUtils;
|
||||
@@ -72,13 +73,14 @@ import com.hippo.ehviewer.client.data.LargePreviewSet;
|
||||
import com.hippo.ehviewer.client.data.ListUrlBuilder;
|
||||
import com.hippo.ehviewer.client.parser.RateGalleryParser;
|
||||
import com.hippo.ehviewer.dao.DownloadInfo;
|
||||
import com.hippo.ehviewer.dao.Filter;
|
||||
import com.hippo.ehviewer.ui.CommonOperations;
|
||||
import com.hippo.ehviewer.ui.GalleryActivity;
|
||||
import com.hippo.ehviewer.ui.MainActivity;
|
||||
import com.hippo.ehviewer.ui.annotation.WholeLifeCircle;
|
||||
import com.hippo.rippleold.RippleSalon;
|
||||
import com.hippo.scene.Announcer;
|
||||
import com.hippo.scene.SceneFragment;
|
||||
import com.hippo.scene.StageActivity;
|
||||
import com.hippo.scene.TransitionHelper;
|
||||
import com.hippo.text.Html;
|
||||
import com.hippo.text.URLImageGetter;
|
||||
@@ -86,14 +88,14 @@ import com.hippo.util.ActivityHelper;
|
||||
import com.hippo.util.ApiHelper;
|
||||
import com.hippo.util.DrawableManager;
|
||||
import com.hippo.util.ExceptionUtils;
|
||||
import com.hippo.util.LayoutUtils2;
|
||||
import com.hippo.util.ReadableTime;
|
||||
import com.hippo.view.ViewTransition;
|
||||
import com.hippo.widget.AutoWrapLayout;
|
||||
import com.hippo.widget.LoadImageView;
|
||||
import com.hippo.widget.ProgressView;
|
||||
import com.hippo.widget.ProgressiveRatingBar;
|
||||
import com.hippo.widget.SimpleGridLayout;
|
||||
import com.hippo.widget.SimpleGridAutoSpanLayout;
|
||||
import com.hippo.yorozuya.AssertUtils;
|
||||
import com.hippo.yorozuya.SimpleHandler;
|
||||
import com.hippo.yorozuya.ViewUtils;
|
||||
|
||||
@@ -193,6 +195,8 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
|
||||
private TextView mShare;
|
||||
@Nullable
|
||||
private TextView mRate;
|
||||
@Nullable
|
||||
private TextView mSimilar;
|
||||
// Tags
|
||||
@Nullable
|
||||
private LinearLayout mTags;
|
||||
@@ -207,7 +211,7 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
|
||||
@Nullable
|
||||
private View mPreviews;
|
||||
@Nullable
|
||||
private SimpleGridLayout mGridLayout;
|
||||
private SimpleGridAutoSpanLayout mGridLayout;
|
||||
@Nullable
|
||||
private TextView mPreviewText;
|
||||
// Progress
|
||||
@@ -345,7 +349,9 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
|
||||
|
||||
long gid = getGid();
|
||||
if (gid != -1) {
|
||||
mDownloadState = EhApplication.getDownloadManager(getContext()).getDownloadState(gid);
|
||||
Context context = getContext2();
|
||||
AssertUtils.assertNotNull(context);
|
||||
mDownloadState = EhApplication.getDownloadManager(context).getDownloadState(gid);
|
||||
} else {
|
||||
mDownloadState = DownloadInfo.STATE_INVALID;
|
||||
}
|
||||
@@ -396,7 +402,10 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
|
||||
mTip = (TextView) ViewUtils.$$(main, R.id.tip);
|
||||
mViewTransition = new ViewTransition(mainView, progressView, mTip);
|
||||
|
||||
Drawable drawable = DrawableManager.getDrawable(getContext(), R.drawable.big_weird_face);
|
||||
Context context = getContext2();
|
||||
AssertUtils.assertNotNull(context);
|
||||
|
||||
Drawable drawable = DrawableManager.getDrawable(context, R.drawable.big_weird_face);
|
||||
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
|
||||
mTip.setCompoundDrawables(null, drawable, null, null);
|
||||
mTip.setOnClickListener(this);
|
||||
@@ -421,6 +430,8 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
|
||||
mDownload.setOnLongClickListener(this);
|
||||
mRead.setOnClickListener(this);
|
||||
|
||||
mUploader.setOnLongClickListener(this);
|
||||
|
||||
mBelowHeader = mainView.findViewById(R.id.below_header);
|
||||
View belowHeader = mBelowHeader;
|
||||
|
||||
@@ -442,15 +453,18 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
|
||||
mTorrent = (TextView) ViewUtils.$$(mActions, R.id.torrent);
|
||||
mShare = (TextView) ViewUtils.$$(mActions, R.id.share);
|
||||
mRate = (TextView) ViewUtils.$$(mActions, R.id.rate);
|
||||
mSimilar = (TextView) ViewUtils.$$(mActions, R.id.similar);
|
||||
RippleSalon.addRipple(mHeartGroup, false);
|
||||
RippleSalon.addRipple(mTorrent, false);
|
||||
RippleSalon.addRipple(mShare, false);
|
||||
RippleSalon.addRipple(mRate, false);
|
||||
RippleSalon.addRipple(mSimilar, false);
|
||||
mHeartGroup.setOnClickListener(this);
|
||||
mTorrent.setOnClickListener(this);
|
||||
mShare.setOnClickListener(this);
|
||||
mRate.setOnClickListener(this);
|
||||
ensureActionDrawable();
|
||||
mSimilar.setOnClickListener(this);
|
||||
ensureActionDrawable(context);
|
||||
|
||||
mTags = (LinearLayout) ViewUtils.$$(belowHeader, R.id.tags);
|
||||
mNoTags = (TextView) ViewUtils.$$(mTags, R.id.no_tags);
|
||||
@@ -461,7 +475,7 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
|
||||
mComments.setOnClickListener(this);
|
||||
|
||||
mPreviews = ViewUtils.$$(belowHeader, R.id.previews);
|
||||
mGridLayout = (SimpleGridLayout) ViewUtils.$$(mPreviews, R.id.grid_layout);
|
||||
mGridLayout = (SimpleGridAutoSpanLayout) ViewUtils.$$(mPreviews, R.id.grid_layout);
|
||||
mPreviewText = (TextView) ViewUtils.$$(mPreviews, R.id.preview_text);
|
||||
RippleSalon.addRipple(mPreviews, false);
|
||||
mPreviews.setOnClickListener(this);
|
||||
@@ -487,7 +501,7 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
|
||||
adjustViewVisibility(STATE_FAILED, false);
|
||||
}
|
||||
|
||||
EhApplication.getDownloadManager(getContext()).addDownloadInfoListener(this);
|
||||
EhApplication.getDownloadManager(context).addDownloadInfoListener(this);
|
||||
|
||||
return view;
|
||||
}
|
||||
@@ -501,7 +515,9 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
|
||||
EhApplication.getDownloadManager(getContext()).removeDownloadInfoListener(this);
|
||||
Context context = getContext2();
|
||||
AssertUtils.assertNotNull(context);
|
||||
EhApplication.getDownloadManager(context).removeDownloadInfoListener(this);
|
||||
|
||||
mTip = null;
|
||||
mViewTransition = null;
|
||||
@@ -534,6 +550,7 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
|
||||
mTorrent = null;
|
||||
mShare = null;
|
||||
mRate = null;
|
||||
mSimilar = null;
|
||||
|
||||
mTags = null;
|
||||
mNoTags = null;
|
||||
@@ -553,6 +570,9 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
|
||||
}
|
||||
|
||||
private boolean prepareData() {
|
||||
Context context = getContext2();
|
||||
AssertUtils.assertNotNull(context);
|
||||
|
||||
if (mGalleryDetail != null) {
|
||||
return true;
|
||||
}
|
||||
@@ -563,12 +583,12 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
|
||||
}
|
||||
|
||||
// Get from cache
|
||||
mGalleryDetail = EhApplication.getGalleryDetailCache(getContext()).get(gid);
|
||||
mGalleryDetail = EhApplication.getGalleryDetailCache(context).get(gid);
|
||||
if (mGalleryDetail != null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
EhApplication application = (EhApplication) getContext().getApplicationContext();
|
||||
EhApplication application = (EhApplication) context.getApplicationContext();
|
||||
if (application.containGlobalStuff(mRequestId)) {
|
||||
// request exist
|
||||
return true;
|
||||
@@ -579,19 +599,21 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
|
||||
}
|
||||
|
||||
private boolean request() {
|
||||
Context context = getContext2();
|
||||
MainActivity activity = getActivity2();
|
||||
String url = getGalleryDetailUrl(true);
|
||||
if (url == null) {
|
||||
if (null == context || null == activity || null == url) {
|
||||
return false;
|
||||
}
|
||||
|
||||
EhClient.Callback callback = new GetGalleryDetailListener(getContext(),
|
||||
((StageActivity) getActivity()).getStageId(), getTag());
|
||||
mRequestId = ((EhApplication) getContext().getApplicationContext()).putGlobalStuff(callback);
|
||||
EhClient.Callback callback = new GetGalleryDetailListener(context,
|
||||
activity.getStageId(), getTag());
|
||||
mRequestId = ((EhApplication) context.getApplicationContext()).putGlobalStuff(callback);
|
||||
EhRequest request = new EhRequest()
|
||||
.setMethod(EhClient.METHOD_GET_GALLERY_DETAIL)
|
||||
.setArgs(url)
|
||||
.setCallback(callback);
|
||||
EhApplication.getEhClient(getContext()).execute(request);
|
||||
EhApplication.getEhClient(context).execute(request);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -601,17 +623,19 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
|
||||
text.setCompoundDrawables(null, drawable, null, null);
|
||||
}
|
||||
|
||||
private void ensureActionDrawable() {
|
||||
Drawable heart = DrawableManager.getDrawable(getContext(), R.drawable.v_heart_primary_x48);
|
||||
private void ensureActionDrawable(Context context) {
|
||||
Drawable heart = DrawableManager.getDrawable(context, R.drawable.v_heart_primary_x48);
|
||||
setActionDrawable(mHeart, heart);
|
||||
Drawable heartOutline = DrawableManager.getDrawable(getContext(), R.drawable.v_heart_outline_primary_x48);
|
||||
Drawable heartOutline = DrawableManager.getDrawable(context, R.drawable.v_heart_outline_primary_x48);
|
||||
setActionDrawable(mHeartOutline, heartOutline);
|
||||
Drawable torrent = DrawableManager.getDrawable(getContext(), R.drawable.v_utorrent_primary_x48);
|
||||
Drawable torrent = DrawableManager.getDrawable(context, R.drawable.v_utorrent_primary_x48);
|
||||
setActionDrawable(mTorrent, torrent);
|
||||
Drawable share = DrawableManager.getDrawable(getContext(), R.drawable.v_share_primary_x48);
|
||||
Drawable share = DrawableManager.getDrawable(context, R.drawable.v_share_primary_x48);
|
||||
setActionDrawable(mShare, share);
|
||||
Drawable rate = DrawableManager.getDrawable(getContext(), R.drawable.v_thumb_up_primary_x48);
|
||||
Drawable rate = DrawableManager.getDrawable(context, R.drawable.v_thumb_up_primary_x48);
|
||||
setActionDrawable(mRate, rate);
|
||||
Drawable similar = DrawableManager.getDrawable(context, R.drawable.v_similar_primary_x48);
|
||||
setActionDrawable(mSimilar, similar);
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
||||
@@ -729,7 +753,8 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
|
||||
return;
|
||||
}
|
||||
|
||||
Resources resources = getContext().getResources();
|
||||
Resources resources = getResources2();
|
||||
AssertUtils.assertNotNull(resources);
|
||||
|
||||
mThumb.load(EhCacheKeyFactory.getThumbKey(gd.gid), gd.thumb, true);
|
||||
mTitle.setText(EhUtils.getSuitableTitle(gd));
|
||||
@@ -759,7 +784,10 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private void bindTags(GalleryTagGroup[] tagGroups) {
|
||||
if (mTags == null || mNoTags == null) {
|
||||
Context context = getContext2();
|
||||
LayoutInflater inflater = getLayoutInflater2();
|
||||
Resources resources = getResources2();
|
||||
if (null == context || null == inflater || null == resources || null == mTags || null == mNoTags) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -771,9 +799,8 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
|
||||
mNoTags.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
LayoutInflater inflater = getActivity().getLayoutInflater();
|
||||
int colorTag = getResources().getColor(R.color.colorPrimary);
|
||||
int colorName = getResources().getColor(R.color.purple_a400);
|
||||
int colorTag = resources.getColor(R.color.colorPrimary);
|
||||
int colorName = resources.getColor(R.color.purple_a400);
|
||||
for (GalleryTagGroup tg : tagGroups) {
|
||||
LinearLayout ll = (LinearLayout) inflater.inflate(R.layout.gallery_tag_group, mTags, false);
|
||||
ll.setOrientation(LinearLayout.HORIZONTAL);
|
||||
@@ -784,7 +811,7 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
|
||||
tgName.setText(tg.groupName);
|
||||
tgName.setBackgroundDrawable(new RoundSideRectDrawable(colorName));
|
||||
|
||||
AutoWrapLayout awl = new AutoWrapLayout(getContext());
|
||||
AutoWrapLayout awl = new AutoWrapLayout(context);
|
||||
ll.addView(awl, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||
for (int j = 0, z = tg.size(); j < z; j++) {
|
||||
TextView tag = (TextView) inflater.inflate(R.layout.item_gallery_tag, awl, false);
|
||||
@@ -794,12 +821,15 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
|
||||
tag.setBackgroundDrawable(new RoundSideRectDrawable(colorTag));
|
||||
tag.setTag(R.id.tag, tg.groupName + ":" + tagStr);
|
||||
tag.setOnClickListener(this);
|
||||
tag.setOnLongClickListener(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void bindComments(GalleryComment[] comments) {
|
||||
if (mComments == null || mCommentsText == null) {
|
||||
Context context = getContext2();
|
||||
LayoutInflater inflater = getLayoutInflater2();
|
||||
if (null == context || null == inflater || null == mComments || null == mCommentsText) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -815,7 +845,6 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
|
||||
mCommentsText.setText(R.string.more_comment);
|
||||
}
|
||||
|
||||
LayoutInflater inflater = getActivity().getLayoutInflater();
|
||||
int length = Math.min(maxShowCount, comments.length);
|
||||
for (int i = 0; i < length; i++) {
|
||||
GalleryComment comment = comments[i];
|
||||
@@ -828,12 +857,14 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
|
||||
TextView c = (TextView) v.findViewById(R.id.comment);
|
||||
c.setMaxLines(5);
|
||||
c.setText(Html.fromHtml(comment.comment,
|
||||
new URLImageGetter(c, EhApplication.getConaco(getContext())), null));
|
||||
new URLImageGetter(c, EhApplication.getConaco(context)), null));
|
||||
}
|
||||
}
|
||||
|
||||
private void bindPreviews(GalleryDetail gd) {
|
||||
if (mGridLayout == null || mPreviewText == null) {
|
||||
LayoutInflater inflater = getLayoutInflater2();
|
||||
Resources resources = getResources2();
|
||||
if (null == inflater || null == resources || null == mGridLayout || null == mPreviewText) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -848,11 +879,9 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
|
||||
mPreviewText.setText(R.string.more_previews);
|
||||
}
|
||||
|
||||
int minWidth = getResources().getDimensionPixelOffset(R.dimen.preview_grid_min_width);
|
||||
int spanCount = LayoutUtils2.calculateSpanCount(getContext(), minWidth);
|
||||
mGridLayout.setColumnCount(spanCount);
|
||||
|
||||
LayoutInflater inflater = getActivity().getLayoutInflater();
|
||||
int columnWidth = resources.getDimensionPixelOffset(R.dimen.preview_grid_column_width);
|
||||
mGridLayout.setColumnSize(columnWidth);
|
||||
mGridLayout.setStrategy(SimpleGridAutoSpanLayout.STRATEGY_SUITABLE_SIZE);
|
||||
for (int i = 0, size = previewSet.size(); i < size; i++) {
|
||||
View view = inflater.inflate(R.layout.item_gallery_preview, mGridLayout, false);
|
||||
mGridLayout.addView(view);
|
||||
@@ -908,7 +937,8 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
|
||||
}
|
||||
|
||||
private String getAllRatingText(float rating, int ratedTimes) {
|
||||
Resources resources = getResources();
|
||||
Resources resources = getResources2();
|
||||
AssertUtils.assertNotNull(resources);
|
||||
return resources.getString(R.string.rating_text, getRatingText(rating, resources), rating, ratedTimes);
|
||||
}
|
||||
|
||||
@@ -930,7 +960,9 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
|
||||
return;
|
||||
}
|
||||
|
||||
PopupMenu popup = new PopupMenu(getContext(), mOtherActions, Gravity.TOP);
|
||||
Context context = getContext2();
|
||||
AssertUtils.assertNotNull(context);
|
||||
PopupMenu popup = new PopupMenu(context, mOtherActions, Gravity.TOP);
|
||||
mPopupMenu = popup;
|
||||
popup.getMenuInflater().inflate(R.menu.scene_gallery_detail, popup.getMenu());
|
||||
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
|
||||
@@ -939,8 +971,9 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
|
||||
switch (item.getItemId()) {
|
||||
case R.id.action_open_in_other_app:
|
||||
String url = getGalleryDetailUrl(false);
|
||||
if (url != null) {
|
||||
UrlOpener.openUrl(getActivity(), url, false, false);
|
||||
Activity activity = getActivity2();
|
||||
if (null != url && null != activity) {
|
||||
UrlOpener.openUrl(activity, url, false, false);
|
||||
}
|
||||
break;
|
||||
case R.id.action_refresh:
|
||||
@@ -955,8 +988,48 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
|
||||
});
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static String getArtist(GalleryTagGroup[] tagGroups) {
|
||||
if (null == tagGroups) {
|
||||
return null;
|
||||
}
|
||||
for (GalleryTagGroup tagGroup: tagGroups) {
|
||||
if ("artist".equals(tagGroup.groupName) && tagGroup.size() > 0) {
|
||||
return tagGroup.getTagAt(0);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void showSimilarGalleryList() {
|
||||
GalleryDetail gd = mGalleryDetail;
|
||||
if (null == gd) {
|
||||
return;
|
||||
}
|
||||
String artist = getArtist(gd.tags);
|
||||
if (null != artist) {
|
||||
ListUrlBuilder lub = new ListUrlBuilder();
|
||||
lub.setMode(ListUrlBuilder.MODE_TAG);
|
||||
lub.setKeyword("artist:" + artist);
|
||||
GalleryListScene.startScene(this, lub);
|
||||
return;
|
||||
}
|
||||
if (null != gd.uploader) {
|
||||
ListUrlBuilder lub = new ListUrlBuilder();
|
||||
lub.setMode(ListUrlBuilder.MODE_UPLOADER);
|
||||
lub.setKeyword(gd.uploader);
|
||||
GalleryListScene.startScene(this, lub);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Context context = getContext2();
|
||||
MainActivity activity = getActivity2();
|
||||
if (null == context || null == activity) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (mTip == v) {
|
||||
if (request()) {
|
||||
adjustViewVisibility(STATE_REFRESH, true);
|
||||
@@ -986,7 +1059,7 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
|
||||
} else if (mDownload == v) {
|
||||
GalleryInfo galleryInfo = getGalleryInfo();
|
||||
if (galleryInfo != null) {
|
||||
CommonOperations.startDownload(getActivity(), galleryInfo, false);
|
||||
CommonOperations.startDownload(activity, galleryInfo, false);
|
||||
}
|
||||
} else if (mRead == v) {
|
||||
GalleryInfo galleryInfo = null;
|
||||
@@ -996,7 +1069,7 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
|
||||
galleryInfo = mGalleryDetail;
|
||||
}
|
||||
if (galleryInfo != null) {
|
||||
Intent intent = new Intent(getActivity(), GalleryActivity.class);
|
||||
Intent intent = new Intent(activity, GalleryActivity.class);
|
||||
intent.setAction(GalleryActivity.ACTION_EH);
|
||||
intent.putExtra(GalleryActivity.KEY_GALLERY_INFO, galleryInfo);
|
||||
startActivity(intent);
|
||||
@@ -1014,16 +1087,16 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
|
||||
}
|
||||
if (mGalleryDetail.isFavored) {
|
||||
mModifingFavorites = true;
|
||||
CommonOperations.removeFromFavorites(getActivity(), mGalleryDetail,
|
||||
new ModifyFavoritesListener(getContext(),
|
||||
((StageActivity) getActivity()).getStageId(), getTag(), true));
|
||||
CommonOperations.removeFromFavorites(activity, mGalleryDetail,
|
||||
new ModifyFavoritesListener(context,
|
||||
activity.getStageId(), getTag(), true));
|
||||
remove = true;
|
||||
}
|
||||
if (!remove) {
|
||||
mModifingFavorites = true;
|
||||
CommonOperations.addToFavorites(getActivity(), mGalleryDetail,
|
||||
new ModifyFavoritesListener(getContext(),
|
||||
((StageActivity) getActivity()).getStageId(), getTag(), false));
|
||||
CommonOperations.addToFavorites(activity, mGalleryDetail,
|
||||
new ModifyFavoritesListener(context,
|
||||
activity.getStageId(), getTag(), false));
|
||||
}
|
||||
// Update UI
|
||||
updateFavoriteDrawable();
|
||||
@@ -1031,29 +1104,32 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
|
||||
} else if (mShare == v) {
|
||||
String url = getGalleryDetailUrl(false);
|
||||
if (url != null) {
|
||||
ActivityHelper.share(getActivity(), url);
|
||||
ActivityHelper.share(activity, url);
|
||||
}
|
||||
} else if (mTorrent == v) {
|
||||
if (mGalleryDetail != null) {
|
||||
TorrentListDialogHelper helper = new TorrentListDialogHelper(mGalleryDetail.torrentUrl);
|
||||
Dialog dialog = new AlertDialog.Builder(getContext())
|
||||
TorrentListDialogHelper helper = new TorrentListDialogHelper();
|
||||
Dialog dialog = new AlertDialog.Builder(context)
|
||||
.setTitle(R.string.torrents)
|
||||
.setView(helper.getView())
|
||||
.setView(R.layout.dialog_torrent_list)
|
||||
.setOnDismissListener(helper)
|
||||
.show();
|
||||
helper.setDialog(dialog);
|
||||
helper.setDialog(dialog, mGalleryDetail.torrentUrl);
|
||||
}
|
||||
} else if (mRate == v) {
|
||||
if (mGalleryDetail == null) {
|
||||
return;
|
||||
}
|
||||
RateDialogHelper helper = new RateDialogHelper(mGalleryDetail.rating);
|
||||
new AlertDialog.Builder(getContext())
|
||||
RateDialogHelper helper = new RateDialogHelper();
|
||||
Dialog dialog = new AlertDialog.Builder(context)
|
||||
.setTitle(R.string.rate)
|
||||
.setView(helper.view)
|
||||
.setView(R.layout.dialog_rate)
|
||||
.setNegativeButton(android.R.string.cancel, null)
|
||||
.setPositiveButton(android.R.string.ok, helper)
|
||||
.show();
|
||||
helper.setDialog(dialog, mGalleryDetail.rating);
|
||||
} else if (mSimilar == v) {
|
||||
showSimilarGalleryList();
|
||||
} else if (mComments == v) {
|
||||
if (mGalleryDetail == null) {
|
||||
return;
|
||||
@@ -1082,10 +1158,9 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
|
||||
return;
|
||||
}
|
||||
|
||||
Context context = getContext();
|
||||
GalleryInfo galleryInfo = getGalleryInfo();
|
||||
o = v.getTag(R.id.index);
|
||||
if (null != context && null != galleryInfo && o instanceof Integer) {
|
||||
if (null != galleryInfo && o instanceof Integer) {
|
||||
int index = (Integer) o;
|
||||
Intent intent = new Intent(context, GalleryActivity.class);
|
||||
intent.setAction(GalleryActivity.ACTION_EH);
|
||||
@@ -1097,14 +1172,81 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
|
||||
}
|
||||
}
|
||||
|
||||
private void showBlockUploaderDialog() {
|
||||
Context context = getContext2();
|
||||
if (null == context) {
|
||||
return;
|
||||
}
|
||||
final String uploader = getUploader();
|
||||
if (null == uploader) {
|
||||
return;
|
||||
}
|
||||
|
||||
new AlertDialog.Builder(context)
|
||||
.setMessage(getString(R.string.block_the_uploader, uploader))
|
||||
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
if (DialogInterface.BUTTON_POSITIVE != which) {
|
||||
return;
|
||||
}
|
||||
|
||||
Filter filter = new Filter();
|
||||
filter.mode = EhFilter.MODE_UPLOADER;
|
||||
filter.text = uploader;
|
||||
EhFilter.getInstance().addFilter(filter);
|
||||
|
||||
showTip(getString(R.string.uploader_blocked, uploader), LENGTH_SHORT);
|
||||
}
|
||||
}).show();
|
||||
}
|
||||
|
||||
private void showBlockTagDialog(final String tag) {
|
||||
Context context = getContext2();
|
||||
if (null == context) {
|
||||
return;
|
||||
}
|
||||
|
||||
new AlertDialog.Builder(context)
|
||||
.setMessage(getString(R.string.block_the_tag, tag))
|
||||
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
if (DialogInterface.BUTTON_POSITIVE != which) {
|
||||
return;
|
||||
}
|
||||
|
||||
Filter filter = new Filter();
|
||||
filter.mode = EhFilter.MODE_TAG;
|
||||
filter.text = tag;
|
||||
EhFilter.getInstance().addFilter(filter);
|
||||
|
||||
showTip(getString(R.string.tag_blocked, tag), LENGTH_SHORT);
|
||||
}
|
||||
}).show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onLongClick(View v) {
|
||||
if (mDownload == v) {
|
||||
MainActivity activity = getActivity2();
|
||||
if (null == activity) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (mUploader == v) {
|
||||
showBlockUploaderDialog();
|
||||
} else if (mDownload == v) {
|
||||
GalleryInfo galleryInfo = getGalleryInfo();
|
||||
if (galleryInfo != null) {
|
||||
CommonOperations.startDownload(getActivity(), galleryInfo, true);
|
||||
CommonOperations.startDownload(activity, galleryInfo, true);
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
String tag = (String) v.getTag(R.id.tag);
|
||||
if (null != tag) {
|
||||
showBlockTagDialog(tag);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -1173,12 +1315,13 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
|
||||
}
|
||||
|
||||
private void updateDownloadState() {
|
||||
Context context = getContext2();
|
||||
long gid = getGid();
|
||||
if (-1L == gid) {
|
||||
if (null == context || -1L == gid) {
|
||||
return;
|
||||
}
|
||||
|
||||
int downloadState = EhApplication.getDownloadManager(getContext()).getDownloadState(gid);
|
||||
int downloadState = EhApplication.getDownloadManager(context).getDownloadState(gid);
|
||||
if (downloadState == mDownloadState) {
|
||||
return;
|
||||
}
|
||||
@@ -1263,12 +1406,11 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
|
||||
|
||||
private void onGetGalleryDetailFailure(Exception e) {
|
||||
e.printStackTrace();
|
||||
if (isViewCreated()) {
|
||||
String error = ExceptionUtils.getReadableString(getContext(), e);
|
||||
if (mTip != null) {
|
||||
mTip.setText(error);
|
||||
adjustViewVisibility(STATE_FAILED, true);
|
||||
}
|
||||
Context context = getContext2();
|
||||
if (null != context && null != mTip) {
|
||||
String error = ExceptionUtils.getReadableString(context, e);
|
||||
mTip.setText(error);
|
||||
adjustViewVisibility(STATE_FAILED, true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1333,42 +1475,41 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
|
||||
private class TorrentListDialogHelper implements AdapterView.OnItemClickListener,
|
||||
DialogInterface.OnDismissListener, EhClient.Callback<Pair<String, String>[]> {
|
||||
|
||||
private final View mView;
|
||||
private final ProgressView mProgressView;
|
||||
private final TextView mErrorText;
|
||||
private final ListView mListView;
|
||||
|
||||
@Nullable
|
||||
private ProgressView mProgressView;
|
||||
@Nullable
|
||||
private TextView mErrorText;
|
||||
@Nullable
|
||||
private ListView mListView;
|
||||
@Nullable
|
||||
private EhRequest mRequest;
|
||||
@Nullable
|
||||
private Dialog mDialog;
|
||||
|
||||
@SuppressLint("InflateParams")
|
||||
public TorrentListDialogHelper(String url) {
|
||||
mView = getActivity().getLayoutInflater().inflate(R.layout.dialog_torrent_list, null);
|
||||
mProgressView = (ProgressView) ViewUtils.$$(mView, R.id.progress);
|
||||
mErrorText = (TextView) ViewUtils.$$(mView, R.id.text);
|
||||
mListView = (ListView) ViewUtils.$$(mView, R.id.list_view);
|
||||
public void setDialog(@Nullable Dialog dialog, String url) {
|
||||
mDialog = dialog;
|
||||
mProgressView = (ProgressView) ViewUtils.$$(dialog, R.id.progress);
|
||||
mErrorText = (TextView) ViewUtils.$$(dialog, R.id.text);
|
||||
mListView = (ListView) ViewUtils.$$(dialog, R.id.list_view);
|
||||
mListView.setOnItemClickListener(this);
|
||||
|
||||
if (mTorrentList == null) {
|
||||
mErrorText.setVisibility(View.GONE);
|
||||
mListView.setVisibility(View.GONE);
|
||||
mRequest = new EhRequest().setMethod(EhClient.METHOD_GET_TORRENT_LIST)
|
||||
.setArgs(url)
|
||||
.setCallback(this);
|
||||
EhApplication.getEhClient(getContext()).execute(mRequest);
|
||||
} else {
|
||||
bind(mTorrentList);
|
||||
Context context = getContext2();
|
||||
if (context != null) {
|
||||
if (mTorrentList == null) {
|
||||
mErrorText.setVisibility(View.GONE);
|
||||
mListView.setVisibility(View.GONE);
|
||||
mRequest = new EhRequest().setMethod(EhClient.METHOD_GET_TORRENT_LIST)
|
||||
.setArgs(url)
|
||||
.setCallback(this);
|
||||
EhApplication.getEhClient(context).execute(mRequest);
|
||||
} else {
|
||||
bind(mTorrentList);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setDialog(@Nullable Dialog dialog) {
|
||||
mDialog = dialog;
|
||||
}
|
||||
|
||||
private void bind(Pair<String, String>[] data) {
|
||||
if (null == mDialog) {
|
||||
if (null == mDialog || null == mProgressView || null == mErrorText || null == mListView) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1389,13 +1530,10 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
|
||||
}
|
||||
}
|
||||
|
||||
public View getView() {
|
||||
return mView;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
if (mTorrentList != null && position < mTorrentList.length) {
|
||||
Context context = getContext2();
|
||||
if (null != context && null != mTorrentList && position < mTorrentList.length) {
|
||||
String url = mTorrentList[position].first;
|
||||
String name = mTorrentList[position].second;
|
||||
// Use system download service
|
||||
@@ -1403,7 +1541,7 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
|
||||
r.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, name + ".torrent");
|
||||
r.allowScanningByMediaScanner();
|
||||
r.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
|
||||
DownloadManager dm = (DownloadManager) getContext().getSystemService(Context.DOWNLOAD_SERVICE);
|
||||
DownloadManager dm = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
|
||||
dm.enqueue(r);
|
||||
}
|
||||
|
||||
@@ -1420,6 +1558,9 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
|
||||
mRequest = null;
|
||||
}
|
||||
mDialog = null;
|
||||
mProgressView = null;
|
||||
mErrorText = null;
|
||||
mListView = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1433,12 +1574,13 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
|
||||
|
||||
@Override
|
||||
public void onFailure(Exception e) {
|
||||
if (mRequest != null) {
|
||||
mRequest = null;
|
||||
mRequest = null;
|
||||
Context context = getContext2();
|
||||
if (null != context && null != mProgressView && null != mErrorText && null != mListView) {
|
||||
mProgressView.setVisibility(View.GONE);
|
||||
mErrorText.setVisibility(View.VISIBLE);
|
||||
mListView.setVisibility(View.GONE);
|
||||
mErrorText.setText(ExceptionUtils.getReadableString(getContext(), e));
|
||||
mErrorText.setText(ExceptionUtils.getReadableString(context, e));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1497,37 +1639,41 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
|
||||
private class RateDialogHelper implements ProgressiveRatingBar.OnUserRateListener,
|
||||
DialogInterface.OnClickListener {
|
||||
|
||||
public View view;
|
||||
private final ProgressiveRatingBar mRatingBar;
|
||||
private final TextView mRatingText;
|
||||
@Nullable
|
||||
private ProgressiveRatingBar mRatingBar;
|
||||
@Nullable
|
||||
private TextView mRatingText;
|
||||
|
||||
@SuppressLint("InflateParams")
|
||||
private RateDialogHelper(float rating) {
|
||||
view = getActivity().getLayoutInflater().inflate(R.layout.dialog_rate, null);
|
||||
mRatingText = (TextView) view.findViewById(R.id.rating_text);
|
||||
mRatingBar = (ProgressiveRatingBar) view.findViewById(R.id.rating_view);
|
||||
mRatingText.setText(getRatingText(rating, getResources()));
|
||||
public void setDialog(Dialog dialog, float rating) {
|
||||
mRatingText = (TextView) ViewUtils.$$(dialog, R.id.rating_text);
|
||||
mRatingBar = (ProgressiveRatingBar) ViewUtils.$$(dialog, R.id.rating_view);
|
||||
mRatingText.setText(getRatingText(rating, getResources2()));
|
||||
mRatingBar.setRating(rating);
|
||||
mRatingBar.setOnUserRateListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUserRate(float rating) {
|
||||
mRatingText.setText(getRatingText(rating, getResources()));
|
||||
if (null != mRatingText) {
|
||||
mRatingText.setText(getRatingText(rating, getResources2()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
if (which != DialogInterface.BUTTON_POSITIVE || mGalleryDetail == null) {
|
||||
Context context = getContext2();
|
||||
MainActivity activity = getActivity2();
|
||||
if (null == context || null == activity || which != DialogInterface.BUTTON_POSITIVE ||
|
||||
null == mGalleryDetail || null == mRatingBar) {
|
||||
return;
|
||||
}
|
||||
|
||||
EhRequest request = new EhRequest()
|
||||
.setMethod(EhClient.METHOD_GET_RATE_GALLERY)
|
||||
.setArgs(mGalleryDetail.gid, mGalleryDetail.token, mRatingBar.getRating())
|
||||
.setCallback(new RateGalleryListener(getContext(),
|
||||
((StageActivity) getActivity()).getStageId(), getTag(), mGalleryDetail.gid));
|
||||
EhApplication.getEhClient(getContext()).execute(request);
|
||||
.setCallback(new RateGalleryListener(context,
|
||||
activity.getStageId(), getTag(), mGalleryDetail.gid));
|
||||
EhApplication.getEhClient(context).execute(request);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -37,6 +37,7 @@ import com.hippo.ehviewer.client.EhUrl;
|
||||
import com.hippo.ehviewer.client.EhUtils;
|
||||
import com.hippo.ehviewer.client.data.GalleryDetail;
|
||||
import com.hippo.rippleold.RippleSalon;
|
||||
import com.hippo.yorozuya.AssertUtils;
|
||||
import com.hippo.yorozuya.LayoutUtils;
|
||||
import com.hippo.yorozuya.ViewUtils;
|
||||
|
||||
@@ -79,7 +80,8 @@ public final class GalleryInfoScene extends ToolbarScene implements EasyRecycler
|
||||
return;
|
||||
}
|
||||
|
||||
Resources resources = getResources();
|
||||
Resources resources = getResources2();
|
||||
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));
|
||||
@@ -151,14 +153,17 @@ public final class GalleryInfoScene extends ToolbarScene implements EasyRecycler
|
||||
@Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
View view = inflater.inflate(R.layout.scene_gallery_info, container, false);
|
||||
|
||||
Context context = getContext2();
|
||||
AssertUtils.assertNotNull(context);
|
||||
|
||||
EasyRecyclerView recyclerView = (EasyRecyclerView) ViewUtils.$$(view, R.id.recycler_view);
|
||||
InfoAdapter adapter = new InfoAdapter();
|
||||
recyclerView.setAdapter(adapter);
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false));
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false));
|
||||
LinearDividerItemDecoration decoration = new LinearDividerItemDecoration(
|
||||
LinearDividerItemDecoration.VERTICAL, getResources().getColor(R.color.divider),
|
||||
LayoutUtils.dp2pix(getContext(), 1));
|
||||
decoration.setPadding(getResources().getDimensionPixelOffset(R.dimen.keyline_margin));
|
||||
LinearDividerItemDecoration.VERTICAL, context.getResources().getColor(R.color.divider),
|
||||
LayoutUtils.dp2pix(context, 1));
|
||||
decoration.setPadding(context.getResources().getDimensionPixelOffset(R.dimen.keyline_margin));
|
||||
recyclerView.addItemDecoration(decoration);
|
||||
recyclerView.setSelector(RippleSalon.generateRippleDrawable(false));
|
||||
recyclerView.setClipToPadding(false);
|
||||
@@ -176,8 +181,9 @@ public final class GalleryInfoScene extends ToolbarScene implements EasyRecycler
|
||||
|
||||
@Override
|
||||
public boolean onItemClick(EasyRecyclerView parent, View view, int position, long id) {
|
||||
if (position != 0 && mValues != null) {
|
||||
ClipboardManager cmb = (ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE);
|
||||
Context context = getContext2();
|
||||
if (null != context && 0 != position && null != mValues) {
|
||||
ClipboardManager cmb = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
|
||||
cmb.setPrimaryClip(ClipData.newPlainText(null, mValues.get(position)));
|
||||
showTip(R.string.copied_to_clipboard, LENGTH_SHORT);
|
||||
return true;
|
||||
@@ -209,6 +215,13 @@ public final class GalleryInfoScene extends ToolbarScene implements EasyRecycler
|
||||
private static final int TYPE_HEADER = 0;
|
||||
private static final int TYPE_DATA = 1;
|
||||
|
||||
private final LayoutInflater mInflater;
|
||||
|
||||
public InfoAdapter() {
|
||||
mInflater = getLayoutInflater2();
|
||||
AssertUtils.assertNotNull(mInflater);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemViewType(int position) {
|
||||
if (position == 0) {
|
||||
@@ -220,7 +233,7 @@ public final class GalleryInfoScene extends ToolbarScene implements EasyRecycler
|
||||
|
||||
@Override
|
||||
public InfoHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
return new InfoHolder(getActivity().getLayoutInflater().inflate(viewType == TYPE_HEADER ?
|
||||
return new InfoHolder(mInflater.inflate(viewType == TYPE_HEADER ?
|
||||
R.layout.item_gallery_info_header : R.layout.item_gallery_info_data, parent, false));
|
||||
}
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package com.hippo.ehviewer.ui.scene;
|
||||
|
||||
import android.animation.Animator;
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.res.Resources;
|
||||
@@ -29,7 +30,6 @@ import android.support.annotation.Nullable;
|
||||
import android.support.design.widget.FloatingActionButton;
|
||||
import android.support.v4.widget.DrawerLayout;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.support.v7.widget.GridLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.text.Spannable;
|
||||
@@ -50,6 +50,7 @@ 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.app.CheckBoxDialogBuilder;
|
||||
import com.hippo.app.EditTextDialogBuilder;
|
||||
import com.hippo.drawable.AddDeleteDrawable;
|
||||
import com.hippo.drawable.DrawerArrowDrawable;
|
||||
@@ -67,12 +68,12 @@ import com.hippo.ehviewer.client.data.ListUrlBuilder;
|
||||
import com.hippo.ehviewer.client.parser.GalleryListParser;
|
||||
import com.hippo.ehviewer.dao.QuickSearch;
|
||||
import com.hippo.ehviewer.ui.CommonOperations;
|
||||
import com.hippo.ehviewer.ui.MainActivity;
|
||||
import com.hippo.ehviewer.widget.SearchBar;
|
||||
import com.hippo.ehviewer.widget.SearchLayout;
|
||||
import com.hippo.rippleold.RippleSalon;
|
||||
import com.hippo.scene.Announcer;
|
||||
import com.hippo.scene.SceneFragment;
|
||||
import com.hippo.scene.StageActivity;
|
||||
import com.hippo.util.ApiHelper;
|
||||
import com.hippo.util.DrawableManager;
|
||||
import com.hippo.view.ViewTransition;
|
||||
@@ -80,6 +81,7 @@ import com.hippo.widget.ContentLayout;
|
||||
import com.hippo.widget.SearchBarMover;
|
||||
import com.hippo.widget.refreshlayout.RefreshLayout;
|
||||
import com.hippo.yorozuya.AnimationUtils;
|
||||
import com.hippo.yorozuya.AssertUtils;
|
||||
import com.hippo.yorozuya.MathUtils;
|
||||
import com.hippo.yorozuya.SimpleAnimatorListener;
|
||||
import com.hippo.yorozuya.SimpleHandler;
|
||||
@@ -169,6 +171,8 @@ public final class GalleryListScene extends BaseScene
|
||||
}
|
||||
};
|
||||
|
||||
private ShowcaseView mShowcaseView;
|
||||
|
||||
@Override
|
||||
public int getNavCheckedItem() {
|
||||
return mNavCheckedId;
|
||||
@@ -209,7 +213,9 @@ public final class GalleryListScene extends BaseScene
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
mClient = EhApplication.getEhClient(getContext());
|
||||
Context context = getContext2();
|
||||
AssertUtils.assertNotNull(context);
|
||||
mClient = EhApplication.getEhClient(context);
|
||||
|
||||
if (savedInstanceState == null) {
|
||||
onInit();
|
||||
@@ -290,11 +296,11 @@ public final class GalleryListScene extends BaseScene
|
||||
// Update search bar title, drawer checked item
|
||||
private void onUpdateUrlBuilder() {
|
||||
ListUrlBuilder builder = mUrlBuilder;
|
||||
if (null == builder) {
|
||||
Resources resources = getResources2();
|
||||
if (null == resources || null == builder) {
|
||||
return;
|
||||
}
|
||||
|
||||
Resources resources = getResources();
|
||||
String keyword = builder.getKeyword();
|
||||
int category = builder.getCategory();
|
||||
|
||||
@@ -304,7 +310,7 @@ public final class GalleryListScene extends BaseScene
|
||||
}
|
||||
|
||||
// Update title
|
||||
String title = getSuitableTitleForUrlBuilder(getResources(), builder, true);
|
||||
String title = getSuitableTitleForUrlBuilder(resources, builder, true);
|
||||
if (null == title) {
|
||||
title = resources.getString(R.string.search);
|
||||
}
|
||||
@@ -333,7 +339,9 @@ public final class GalleryListScene extends BaseScene
|
||||
@Nullable Bundle savedInstanceState) {
|
||||
View view = inflater.inflate(R.layout.scene_gallery_list, container, false);
|
||||
|
||||
Resources resources = getContext().getResources();
|
||||
Context context = getContext2();
|
||||
AssertUtils.assertNotNull(context);
|
||||
Resources resources = context.getResources();
|
||||
|
||||
View mainLayout = ViewUtils.$$(view, R.id.main_layout);
|
||||
ContentLayout contentLayout = (ContentLayout) ViewUtils.$$(mainLayout, R.id.content_layout);
|
||||
@@ -354,18 +362,15 @@ public final class GalleryListScene extends BaseScene
|
||||
contentLayout.setHelper(mHelper);
|
||||
contentLayout.getFastScroller().setOnDragHandlerListener(this);
|
||||
|
||||
GridLayoutManager layoutManager = new GridLayoutManager(getContext(), 1);
|
||||
mRecyclerView.setLayoutManager(layoutManager);
|
||||
mAdapter = new GalleryListAdapter(inflater, resources,
|
||||
mRecyclerView, Settings.getListMode());
|
||||
mAdapter.register();
|
||||
mRecyclerView.setSelector(RippleSalon.generateRippleDrawable(false));
|
||||
mRecyclerView.setDrawSelectorOnTop(true);
|
||||
mRecyclerView.hasFixedSize();
|
||||
mRecyclerView.setClipToPadding(false);
|
||||
mRecyclerView.setOnItemClickListener(this);
|
||||
mRecyclerView.setOnItemLongClickListener(this);
|
||||
mAdapter = new GalleryListAdapter(LayoutInflater.from(getContext()),
|
||||
getContext(), mRecyclerView, layoutManager, Settings.getListMode());
|
||||
mRecyclerView.setAdapter(mAdapter);
|
||||
mAdapter.register();
|
||||
mRecyclerView.setPadding(mRecyclerView.getPaddingLeft(), mRecyclerView.getPaddingTop() + paddingTopSB,
|
||||
mRecyclerView.getPaddingRight(), mRecyclerView.getPaddingBottom());
|
||||
|
||||
@@ -374,13 +379,13 @@ public final class GalleryListScene extends BaseScene
|
||||
|
||||
refreshLayout.setHeaderTranslationY(paddingTopSB);
|
||||
|
||||
mLeftDrawable = new DrawerArrowDrawable(getContext());
|
||||
mRightDrawable = new AddDeleteDrawable(getContext());
|
||||
mLeftDrawable = new DrawerArrowDrawable(context);
|
||||
mRightDrawable = new AddDeleteDrawable(context);
|
||||
mSearchBar.setLeftDrawable(mLeftDrawable);
|
||||
mSearchBar.setRightDrawable(mRightDrawable);
|
||||
mSearchBar.setHelper(this);
|
||||
mSearchBar.setOnStateChangeListener(this);
|
||||
setSearchBarHint(getContext(), mSearchBar);
|
||||
setSearchBarHint(context, mSearchBar);
|
||||
|
||||
mSearchLayout.setHelper(this);
|
||||
mSearchLayout.setPadding(mSearchLayout.getPaddingLeft(), mSearchLayout.getPaddingTop() + paddingTopSB,
|
||||
@@ -410,15 +415,16 @@ public final class GalleryListScene extends BaseScene
|
||||
}
|
||||
|
||||
private void guideQuickSearch() {
|
||||
if (!Settings.getGuideQuickSearch()) {
|
||||
Activity activity = getActivity2();
|
||||
if (null == activity || !Settings.getGuideQuickSearch()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Display display = getActivity().getWindowManager().getDefaultDisplay();
|
||||
Display display = activity.getWindowManager().getDefaultDisplay();
|
||||
Point point = new Point();
|
||||
display.getSize(point);
|
||||
|
||||
new ShowcaseView.Builder(getActivity())
|
||||
mShowcaseView = new ShowcaseView.Builder(activity)
|
||||
.withMaterialShowcase()
|
||||
.setStyle(R.style.Guide)
|
||||
.setTarget(new PointTarget(point.x, point.y / 3))
|
||||
@@ -429,6 +435,7 @@ public final class GalleryListScene extends BaseScene
|
||||
.setShowcaseEventListener(new SimpleShowcaseEventListener() {
|
||||
@Override
|
||||
public void onShowcaseViewDidHide(ShowcaseView showcaseView) {
|
||||
mShowcaseView = null;
|
||||
ViewUtils.removeFromParent(showcaseView);
|
||||
Settings.putGuideQuickSearch(false);
|
||||
openDrawer(Gravity.RIGHT);
|
||||
@@ -440,6 +447,11 @@ public final class GalleryListScene extends BaseScene
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
|
||||
if (null != mShowcaseView) {
|
||||
ViewUtils.removeFromParent(mShowcaseView);
|
||||
mShowcaseView = null;
|
||||
}
|
||||
|
||||
if (null != mSearchBarMover) {
|
||||
mSearchBarMover.cancelAnimation();
|
||||
mSearchBarMover = null;
|
||||
@@ -465,14 +477,35 @@ public final class GalleryListScene extends BaseScene
|
||||
mFabAnimatorListener = null;
|
||||
}
|
||||
|
||||
private void showQuickSearchTipDialog(final List<QuickSearch> list,
|
||||
final ArrayAdapter<QuickSearch> adapter, final ListView listView, final TextView tip) {
|
||||
Context context = getContext2();
|
||||
if (null == context) {
|
||||
return;
|
||||
}
|
||||
final CheckBoxDialogBuilder builder = new CheckBoxDialogBuilder(
|
||||
context, getString(R.string.add_quick_search_tip), getString(R.string.get_it), false);
|
||||
builder.setTitle(R.string.readme);
|
||||
builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
if (builder.isChecked()) {
|
||||
Settings.putQuickSearchTip(false);
|
||||
}
|
||||
showAddQuickSearchDialog(list, adapter, listView, tip);
|
||||
}
|
||||
}).show();
|
||||
}
|
||||
|
||||
private void showAddQuickSearchDialog(final List<QuickSearch> list,
|
||||
final ArrayAdapter<QuickSearch> adapter, final ListView listView, final TextView tip) {
|
||||
if (null == mUrlBuilder) {
|
||||
Context context = getContext2();
|
||||
if (null == context || null == mUrlBuilder) {
|
||||
return;
|
||||
}
|
||||
|
||||
final EditTextDialogBuilder builder = new EditTextDialogBuilder(getContext(),
|
||||
getSuitableTitleForUrlBuilder(getResources(), mUrlBuilder, false), getString(R.string.quick_search));
|
||||
final EditTextDialogBuilder builder = new EditTextDialogBuilder(context,
|
||||
getSuitableTitleForUrlBuilder(context.getResources(), mUrlBuilder, false), getString(R.string.quick_search));
|
||||
builder.setTitle(R.string.add_quick_search_dialog_title);
|
||||
builder.setPositiveButton(android.R.string.ok, null);
|
||||
final AlertDialog dialog = builder.show();
|
||||
@@ -511,8 +544,11 @@ public final class GalleryListScene extends BaseScene
|
||||
final TextView tip = (TextView) ViewUtils.$$(view, R.id.tip);
|
||||
final ListView listView = (ListView) ViewUtils.$$(view, R.id.list_view);
|
||||
|
||||
Context context = getContext2();
|
||||
AssertUtils.assertNotNull(context);
|
||||
|
||||
final List<QuickSearch> list = EhDB.getAllQuickSearch();
|
||||
final ArrayAdapter<QuickSearch> adapter = new ArrayAdapter<>(getContext(), R.layout.item_simple_list, list);
|
||||
final ArrayAdapter<QuickSearch> adapter = new ArrayAdapter<>(context, R.layout.item_simple_list, list);
|
||||
listView.setAdapter(adapter);
|
||||
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||
@Override
|
||||
@@ -539,7 +575,11 @@ public final class GalleryListScene extends BaseScene
|
||||
int id = item.getItemId();
|
||||
switch (id) {
|
||||
case R.id.action_add:
|
||||
showAddQuickSearchDialog(list, adapter, listView, tip);
|
||||
if (Settings.getQuickSearchTip()) {
|
||||
showQuickSearchTipDialog(list, adapter, listView, tip);
|
||||
} else {
|
||||
showAddQuickSearchDialog(list, adapter, listView, tip);
|
||||
}
|
||||
break;
|
||||
case R.id.action_settings:
|
||||
startScene(new Announcer(QuickSearchScene.class));
|
||||
@@ -587,6 +627,10 @@ public final class GalleryListScene extends BaseScene
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
if (null != mShowcaseView) {
|
||||
return;
|
||||
}
|
||||
|
||||
boolean handle;
|
||||
switch (mState) {
|
||||
default:
|
||||
@@ -633,24 +677,26 @@ public final class GalleryListScene extends BaseScene
|
||||
|
||||
@Override
|
||||
public boolean onItemLongClick(EasyRecyclerView parent, View view, int position, long id) {
|
||||
if (null == mHelper) {
|
||||
final Context context = getContext2();
|
||||
final MainActivity activity = getActivity2();
|
||||
if (null == context || null == activity || null == mHelper) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final GalleryInfo gi = mHelper.getDataAt(position);
|
||||
new AlertDialog.Builder(getContext())
|
||||
new AlertDialog.Builder(context)
|
||||
.setTitle(EhUtils.getSuitableTitle(gi))
|
||||
.setItems(R.array.gallery_list_menu_entries, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
switch (which) {
|
||||
case 0: // Download
|
||||
CommonOperations.startDownload(getActivity(), gi, false);
|
||||
CommonOperations.startDownload(activity, gi, false);
|
||||
break;
|
||||
case 1: // Favorites
|
||||
CommonOperations.addToFavorites(getActivity(), gi,
|
||||
new addToFavoriteListener(getContext(),
|
||||
((StageActivity) getActivity()).getStageId(), getTag()));
|
||||
CommonOperations.addToFavorites(activity, gi,
|
||||
new addToFavoriteListener(context,
|
||||
activity.getStageId(), getTag()));
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -944,9 +990,9 @@ public final class GalleryListScene extends BaseScene
|
||||
|
||||
private class GalleryListAdapter extends GalleryAdapter {
|
||||
|
||||
public GalleryListAdapter(LayoutInflater inflater, Context context,
|
||||
RecyclerView recyclerView, GridLayoutManager layoutManager, int type) {
|
||||
super(inflater, context, recyclerView, layoutManager, type);
|
||||
public GalleryListAdapter(@NonNull LayoutInflater inflater,
|
||||
@NonNull Resources resources, @NonNull RecyclerView recyclerView, int type) {
|
||||
super(inflater, resources, recyclerView, type);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -965,7 +1011,8 @@ public final class GalleryListScene extends BaseScene
|
||||
|
||||
@Override
|
||||
protected void getPageData(int taskId, int type, int page) {
|
||||
if (null == mClient || null == mUrlBuilder) {
|
||||
MainActivity activity = getActivity2();
|
||||
if (null == activity || null == mClient || null == mUrlBuilder) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -974,7 +1021,7 @@ public final class GalleryListScene extends BaseScene
|
||||
EhRequest request = new EhRequest();
|
||||
request.setMethod(EhClient.METHOD_GET_WHATS_HOT);
|
||||
request.setCallback(new GetWhatsHotListener(getContext(),
|
||||
((StageActivity) getActivity()).getStageId(), getTag(), taskId));
|
||||
activity.getStageId(), getTag(), taskId));
|
||||
request.setArgs();
|
||||
mClient.execute(request);
|
||||
} else {
|
||||
@@ -982,15 +1029,15 @@ public final class GalleryListScene extends BaseScene
|
||||
EhRequest request = new EhRequest();
|
||||
request.setMethod(EhClient.METHOD_GET_GALLERY_LIST);
|
||||
request.setCallback(new GetGalleryListListener(getContext(),
|
||||
((StageActivity) getActivity()).getStageId(), getTag(), taskId));
|
||||
request.setArgs(url, Settings.getShowJpnTitle());
|
||||
activity.getStageId(), getTag(), taskId));
|
||||
request.setArgs(url);
|
||||
mClient.execute(request);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Context getContext() {
|
||||
return GalleryListScene.this.getContext();
|
||||
return GalleryListScene.this.getContext2();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -16,16 +16,15 @@
|
||||
|
||||
package com.hippo.ehviewer.ui.scene;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.res.Resources;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.support.v7.widget.GridLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.util.Pair;
|
||||
import android.view.LayoutInflater;
|
||||
@@ -47,14 +46,16 @@ import com.hippo.ehviewer.client.data.GalleryPreview;
|
||||
import com.hippo.ehviewer.client.data.LargePreviewSet;
|
||||
import com.hippo.ehviewer.client.exception.EhException;
|
||||
import com.hippo.ehviewer.ui.GalleryActivity;
|
||||
import com.hippo.ehviewer.ui.MainActivity;
|
||||
import com.hippo.scene.SceneFragment;
|
||||
import com.hippo.scene.StageActivity;
|
||||
import com.hippo.util.LayoutUtils2;
|
||||
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.SimpleHandler;
|
||||
import com.hippo.yorozuya.ViewUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Locale;
|
||||
@@ -86,7 +87,9 @@ public class GalleryPreviewsScene extends ToolbarScene implements EasyRecyclerVi
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
mClient = EhApplication.getEhClient(getContext());
|
||||
Context context = getContext2();
|
||||
AssertUtils.assertNotNull(context);
|
||||
mClient = EhApplication.getEhClient(context);
|
||||
if (savedInstanceState == null) {
|
||||
onInit();
|
||||
} else {
|
||||
@@ -131,12 +134,17 @@ public class GalleryPreviewsScene extends ToolbarScene implements EasyRecyclerVi
|
||||
contentLayout.hideFastScroll();
|
||||
EasyRecyclerView recyclerView = contentLayout.getRecyclerView();
|
||||
|
||||
Context context = getContext2();
|
||||
AssertUtils.assertNotNull(context);
|
||||
Resources resources = context.getResources();
|
||||
|
||||
mAdapter = new GalleryPreviewAdapter();
|
||||
recyclerView.setAdapter(mAdapter);
|
||||
int minWidth = getResources().getDimensionPixelOffset(R.dimen.preview_grid_min_width);
|
||||
int spanCount = LayoutUtils2.calculateSpanCount(getContext(), minWidth);
|
||||
recyclerView.setLayoutManager(new GridLayoutManager(getContext(), spanCount));
|
||||
int padding = LayoutUtils.dp2pix(getContext(), 4);
|
||||
int columnWidth = resources.getDimensionPixelOffset(R.dimen.preview_grid_column_width);
|
||||
AutoGridLayoutManager layoutManager = new AutoGridLayoutManager(context, columnWidth);
|
||||
layoutManager.setStrategy(AutoGridLayoutManager.STRATEGY_SUITABLE_SIZE);
|
||||
recyclerView.setLayoutManager(layoutManager);
|
||||
int padding = LayoutUtils.dp2pix(context, 4);
|
||||
recyclerView.setPadding(padding, padding, padding, padding);
|
||||
recyclerView.setClipToPadding(false);
|
||||
recyclerView.addItemDecoration(new MarginItemDecoration(padding));
|
||||
@@ -182,6 +190,11 @@ public class GalleryPreviewsScene extends ToolbarScene implements EasyRecyclerVi
|
||||
|
||||
@Override
|
||||
public boolean onMenuItemClick(MenuItem item) {
|
||||
Context context = getContext2();
|
||||
if (null == context) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int id = item.getItemId();
|
||||
switch (id) {
|
||||
case R.id.action_go_to:
|
||||
@@ -191,12 +204,12 @@ public class GalleryPreviewsScene extends ToolbarScene implements EasyRecyclerVi
|
||||
int pages = mHelper.getPages();
|
||||
if (pages > 0 && mHelper.canGoTo()) {
|
||||
GoToDialogHelper helper = new GoToDialogHelper(pages, mHelper.getPageForTop());
|
||||
AlertDialog dialog = new AlertDialog.Builder(getContext()).setTitle(R.string.go_to)
|
||||
.setView(helper.getView())
|
||||
AlertDialog dialog = new AlertDialog.Builder(context).setTitle(R.string.go_to)
|
||||
.setView(R.layout.dialog_go_to)
|
||||
.setPositiveButton(android.R.string.ok, null)
|
||||
.create();
|
||||
dialog.show();
|
||||
helper.setPositiveButtonClickListener(dialog);
|
||||
helper.setDialog(dialog);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -210,7 +223,7 @@ public class GalleryPreviewsScene extends ToolbarScene implements EasyRecyclerVi
|
||||
|
||||
@Override
|
||||
public boolean onItemClick(EasyRecyclerView parent, View view, int position, long id) {
|
||||
Context context = getContext();
|
||||
Context context = getContext2();
|
||||
if (null != context && null != mHelper && null != mGalleryInfo) {
|
||||
GalleryPreview p = mHelper.getDataAt(position);
|
||||
Intent intent = new Intent(context, GalleryActivity.class);
|
||||
@@ -237,9 +250,16 @@ public class GalleryPreviewsScene extends ToolbarScene implements EasyRecyclerVi
|
||||
|
||||
private class GalleryPreviewAdapter extends RecyclerView.Adapter<GalleryPreviewHolder> {
|
||||
|
||||
private final LayoutInflater mInflater;
|
||||
|
||||
public GalleryPreviewAdapter() {
|
||||
mInflater = getLayoutInflater2();
|
||||
AssertUtils.assertNotNull(mInflater);
|
||||
}
|
||||
|
||||
@Override
|
||||
public GalleryPreviewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
return new GalleryPreviewHolder(getActivity().getLayoutInflater().inflate(R.layout.item_gallery_preview, parent, false));
|
||||
return new GalleryPreviewHolder(mInflater.inflate(R.layout.item_gallery_preview, parent, false));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -261,7 +281,8 @@ public class GalleryPreviewsScene extends ToolbarScene implements EasyRecyclerVi
|
||||
|
||||
@Override
|
||||
protected void getPageData(final int taskId, int type, int page) {
|
||||
if (null == mClient || null == mGalleryInfo) {
|
||||
MainActivity activity = getActivity2();
|
||||
if (null == activity || null == mClient || null == mGalleryInfo) {
|
||||
onGetException(taskId, new EhException(getString(R.string.error_cannot_find_gallery)));
|
||||
return;
|
||||
}
|
||||
@@ -283,14 +304,14 @@ public class GalleryPreviewsScene extends ToolbarScene implements EasyRecyclerVi
|
||||
EhRequest request = new EhRequest();
|
||||
request.setMethod(EhClient.METHOD_GET_LARGE_PREVIEW_SET);
|
||||
request.setCallback(new GetLargePreviewSetListener(getContext(),
|
||||
((StageActivity) getActivity()).getStageId(), getTag(), taskId, mGalleryInfo.gid, page));
|
||||
activity.getStageId(), getTag(), taskId, mGalleryInfo.gid, page));
|
||||
request.setArgs(url);
|
||||
mClient.execute(request);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Context getContext() {
|
||||
return GalleryPreviewsScene.this.getContext();
|
||||
return GalleryPreviewsScene.this.getContext2();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -387,35 +408,37 @@ public class GalleryPreviewsScene extends ToolbarScene implements EasyRecyclerVi
|
||||
DialogInterface.OnDismissListener {
|
||||
|
||||
private final int mPages;
|
||||
private final int mCurrentPage;
|
||||
|
||||
private final View mView;
|
||||
private final Slider mSlider;
|
||||
|
||||
@Nullable
|
||||
private Slider mSlider;
|
||||
@Nullable
|
||||
private Dialog mDialog;
|
||||
|
||||
@SuppressLint("InflateParams")
|
||||
private GoToDialogHelper(int pages, int currentPage) {
|
||||
mPages = pages;
|
||||
mView = getActivity().getLayoutInflater().inflate(R.layout.dialog_go_to, null);
|
||||
((TextView) mView.findViewById(R.id.start)).setText("1");
|
||||
((TextView) mView.findViewById(R.id.end)).setText(String.format(Locale.US, "%d", pages));
|
||||
mSlider = (Slider) mView.findViewById(R.id.slider);
|
||||
mSlider.setRange(1, pages);
|
||||
mSlider.setProgress(currentPage + 1);
|
||||
mCurrentPage = currentPage;
|
||||
}
|
||||
|
||||
public View getView() {
|
||||
return mView;
|
||||
}
|
||||
|
||||
public void setPositiveButtonClickListener(AlertDialog dialog) {
|
||||
public void setDialog(@NonNull AlertDialog dialog) {
|
||||
mDialog = dialog;
|
||||
|
||||
((TextView) ViewUtils.$$(dialog, R.id.start)).setText(String.format(Locale.US, "%d", 1));
|
||||
((TextView) ViewUtils.$$(dialog, R.id.end)).setText(String.format(Locale.US, "%d", mPages));
|
||||
mSlider = (Slider) ViewUtils.$$(dialog, R.id.slider);
|
||||
mSlider.setRange(1, mPages);
|
||||
mSlider.setProgress(mCurrentPage + 1);
|
||||
|
||||
dialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(this);
|
||||
dialog.setOnDismissListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (null == mSlider) {
|
||||
return;
|
||||
}
|
||||
|
||||
int page = mSlider.getProgress() - 1;
|
||||
if (page >= 0 && page < mPages && mHelper != null) {
|
||||
mHelper.goTo(page);
|
||||
@@ -431,6 +454,7 @@ public class GalleryPreviewsScene extends ToolbarScene implements EasyRecyclerVi
|
||||
@Override
|
||||
public void onDismiss(DialogInterface dialog) {
|
||||
mDialog = null;
|
||||
mSlider = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,34 +18,49 @@ package com.hippo.ehviewer.ui.scene;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.support.v7.widget.GridLayoutManager;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
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;
|
||||
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.SwipeResultActionRemoveItem;
|
||||
import com.h6ah4i.android.widget.advrecyclerview.touchguard.RecyclerViewTouchActionGuardManager;
|
||||
import com.h6ah4i.android.widget.advrecyclerview.utils.AbstractSwipeableItemViewHolder;
|
||||
import com.hippo.easyrecyclerview.EasyRecyclerView;
|
||||
import com.hippo.easyrecyclerview.FastScroller;
|
||||
import com.hippo.easyrecyclerview.HandlerDrawable;
|
||||
import com.hippo.ehviewer.EhDB;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.Settings;
|
||||
import com.hippo.ehviewer.client.EhCacheKeyFactory;
|
||||
import com.hippo.ehviewer.client.EhUtils;
|
||||
import com.hippo.ehviewer.client.data.GalleryInfo;
|
||||
import com.hippo.ehviewer.dao.HistoryInfo;
|
||||
import com.hippo.ehviewer.ui.CommonOperations;
|
||||
import com.hippo.ehviewer.ui.MainActivity;
|
||||
import com.hippo.ehviewer.widget.SimpleRatingView;
|
||||
import com.hippo.rippleold.RippleSalon;
|
||||
import com.hippo.scene.Announcer;
|
||||
import com.hippo.scene.SceneFragment;
|
||||
import com.hippo.scene.StageActivity;
|
||||
import com.hippo.util.ApiHelper;
|
||||
import com.hippo.util.DrawableManager;
|
||||
import com.hippo.view.ViewTransition;
|
||||
import com.hippo.widget.LoadImageView;
|
||||
import com.hippo.yorozuya.AssertUtils;
|
||||
import com.hippo.yorozuya.ResourcesUtils;
|
||||
import com.hippo.yorozuya.ViewUtils;
|
||||
|
||||
@@ -61,9 +76,9 @@ public class HistoryScene extends ToolbarScene
|
||||
@Nullable
|
||||
private ViewTransition mViewTransition;
|
||||
@Nullable
|
||||
private HistoryAdapter mAdapter;
|
||||
private RecyclerView.Adapter<?> mAdapter;
|
||||
@Nullable
|
||||
private LazyList<HistoryInfo> mList;
|
||||
private LazyList<HistoryInfo> mLazyList;
|
||||
|
||||
@Override
|
||||
public int getNavCheckedItem() {
|
||||
@@ -81,12 +96,26 @@ public class HistoryScene extends ToolbarScene
|
||||
TextView tip = (TextView) ViewUtils.$$(view, R.id.tip);
|
||||
mViewTransition = new ViewTransition(content, tip);
|
||||
|
||||
Drawable drawable = DrawableManager.getDrawable(getContext(), R.drawable.big_history);
|
||||
Context context = getContext2();
|
||||
AssertUtils.assertNotNull(context);
|
||||
Resources resources = context.getResources();
|
||||
|
||||
Drawable drawable = DrawableManager.getDrawable(context, R.drawable.big_history);
|
||||
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
|
||||
tip.setCompoundDrawables(null, drawable, null, null);
|
||||
|
||||
mList = EhDB.getHistoryLazyList();
|
||||
GridLayoutManager layoutManager = new GridLayoutManager(getContext(), 1);
|
||||
RecyclerViewTouchActionGuardManager guardManager = new RecyclerViewTouchActionGuardManager();
|
||||
guardManager.setInterceptVerticalScrollingWhileAnimationRunning(true);
|
||||
guardManager.setEnabled(true);
|
||||
RecyclerViewSwipeManager swipeManager = new RecyclerViewSwipeManager();
|
||||
mAdapter = new HistoryAdapter();
|
||||
mAdapter.setHasStableIds(true);
|
||||
mAdapter = swipeManager.createWrappedAdapter(mAdapter);
|
||||
recyclerView.setAdapter(mAdapter);
|
||||
final GeneralItemAnimator animator = new SwipeDismissItemAnimator();
|
||||
animator.setSupportsChangeAnimations(false);
|
||||
recyclerView.setItemAnimator(animator);
|
||||
LinearLayoutManager layoutManager = new LinearLayoutManager(context);
|
||||
recyclerView.setLayoutManager(layoutManager);
|
||||
recyclerView.setSelector(RippleSalon.generateRippleDrawable(false));
|
||||
recyclerView.setDrawSelectorOnTop(true);
|
||||
@@ -94,21 +123,19 @@ public class HistoryScene extends ToolbarScene
|
||||
recyclerView.setClipToPadding(false);
|
||||
recyclerView.setOnItemClickListener(this);
|
||||
recyclerView.setOnItemLongClickListener(this);
|
||||
mAdapter = new HistoryAdapter(LayoutInflater.from(getContext()),
|
||||
getContext(), recyclerView, layoutManager, Settings.getListMode());
|
||||
recyclerView.setAdapter(mAdapter);
|
||||
mAdapter.register();
|
||||
int paddingH = resources.getDimensionPixelOffset(R.dimen.list_content_margin_h);
|
||||
int paddingV = resources.getDimensionPixelOffset(R.dimen.list_content_margin_v);
|
||||
recyclerView.setPadding(paddingV, paddingH, paddingV, paddingH);
|
||||
guardManager.attachRecyclerView(recyclerView);
|
||||
swipeManager.attachRecyclerView(recyclerView);
|
||||
|
||||
fastScroller.attachToRecyclerView(recyclerView);
|
||||
HandlerDrawable handlerDrawable = new HandlerDrawable();
|
||||
handlerDrawable.setColor(ResourcesUtils.getAttrColor(getContext(), R.attr.colorAccent));
|
||||
handlerDrawable.setColor(ResourcesUtils.getAttrColor(context, R.attr.colorAccent));
|
||||
fastScroller.setHandlerDrawable(handlerDrawable);
|
||||
|
||||
if (null != mList && mList.size() > 0) {
|
||||
mViewTransition.showView(0);
|
||||
} else {
|
||||
mViewTransition.showView(1);
|
||||
}
|
||||
updateLazyList();
|
||||
updateView(false);
|
||||
|
||||
return view;
|
||||
}
|
||||
@@ -124,33 +151,91 @@ public class HistoryScene extends ToolbarScene
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
|
||||
if (null != mList) {
|
||||
mList.close();
|
||||
mList = null;
|
||||
}
|
||||
if (null != mAdapter) {
|
||||
mAdapter.unregister();
|
||||
mAdapter = null;
|
||||
if (null != mLazyList) {
|
||||
mLazyList.close();
|
||||
mLazyList = null;
|
||||
}
|
||||
|
||||
mViewTransition = null;
|
||||
mAdapter = null;
|
||||
}
|
||||
|
||||
// Remember to notify
|
||||
private void updateLazyList() {
|
||||
LazyList<HistoryInfo> lazyList = EhDB.getHistoryLazyList();
|
||||
if (mLazyList != null) {
|
||||
mLazyList.close();
|
||||
}
|
||||
mLazyList = lazyList;
|
||||
}
|
||||
|
||||
private void updateView(boolean animation) {
|
||||
if (null == mAdapter || null == mViewTransition) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (mAdapter.getItemCount() == 0) {
|
||||
mViewTransition.showView(1, animation);
|
||||
} else {
|
||||
mViewTransition.showView(0, animation);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNavigationClick() {
|
||||
onBackPressed();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMenuResId() {
|
||||
return R.menu.scene_history;
|
||||
}
|
||||
|
||||
private void showClearAllDialog() {
|
||||
new AlertDialog.Builder(getContext2())
|
||||
.setMessage(R.string.clear_all_history)
|
||||
.setPositiveButton(R.string.clear_all, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
if (DialogInterface.BUTTON_POSITIVE != which || null == mAdapter) {
|
||||
return;
|
||||
}
|
||||
|
||||
EhDB.clearHistoryInfo();
|
||||
updateLazyList();
|
||||
mAdapter.notifyDataSetChanged();
|
||||
updateView(true);
|
||||
}
|
||||
}).show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onMenuItemClick(MenuItem item) {
|
||||
// Skip when in choice mode
|
||||
Context context = getContext2();
|
||||
if (null == context) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int id = item.getItemId();
|
||||
switch (id) {
|
||||
case R.id.action_clear_all: {
|
||||
showClearAllDialog();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onItemClick(EasyRecyclerView parent, View view, int position, long id) {
|
||||
if (null == mList) {
|
||||
if (null == mLazyList) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Bundle args = new Bundle();
|
||||
args.putString(GalleryDetailScene.KEY_ACTION, GalleryDetailScene.ACTION_GALLERY_INFO);
|
||||
args.putParcelable(GalleryDetailScene.KEY_GALLERY_INFO, mList.get(position));
|
||||
args.putParcelable(GalleryDetailScene.KEY_GALLERY_INFO, mLazyList.get(position));
|
||||
Announcer announcer = new Announcer(GalleryDetailScene.class).setArgs(args);
|
||||
View thumb;
|
||||
if (ApiHelper.SUPPORT_TRANSITION && null != (thumb = view.findViewById(R.id.thumb))) {
|
||||
@@ -162,24 +247,26 @@ public class HistoryScene extends ToolbarScene
|
||||
|
||||
@Override
|
||||
public boolean onItemLongClick(EasyRecyclerView parent, View view, int position, long id) {
|
||||
if (null == mList) {
|
||||
final Context context = getContext2();
|
||||
final MainActivity activity = getActivity2();
|
||||
if (null == context || null == activity || null == mLazyList) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final GalleryInfo gi = mList.get(position);
|
||||
new AlertDialog.Builder(getContext())
|
||||
final GalleryInfo gi = mLazyList.get(position);
|
||||
new AlertDialog.Builder(context)
|
||||
.setTitle(EhUtils.getSuitableTitle(gi))
|
||||
.setItems(R.array.gallery_list_menu_entries, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
switch (which) {
|
||||
case 0: // Download
|
||||
CommonOperations.startDownload(getActivity(), gi, false);
|
||||
CommonOperations.startDownload(activity, gi, false);
|
||||
break;
|
||||
case 1: // Favorites
|
||||
CommonOperations.addToFavorites(getActivity(), gi,
|
||||
new addToFavoriteListener(getContext(),
|
||||
((StageActivity) getActivity()).getStageId(), getTag()));
|
||||
CommonOperations.addToFavorites(activity, gi,
|
||||
new addToFavoriteListener(context,
|
||||
activity.getStageId(), getTag()));
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -187,22 +274,124 @@ public class HistoryScene extends ToolbarScene
|
||||
return true;
|
||||
}
|
||||
|
||||
private class HistoryAdapter extends GalleryAdapter {
|
||||
private class HistoryHolder extends AbstractSwipeableItemViewHolder {
|
||||
|
||||
public HistoryAdapter(LayoutInflater inflater, Context context,
|
||||
RecyclerView recyclerView, GridLayoutManager layoutManager, int type) {
|
||||
super(inflater, context, recyclerView, layoutManager, type);
|
||||
public final LoadImageView thumb;
|
||||
public final TextView title;
|
||||
public final TextView uploader;
|
||||
public final SimpleRatingView rating;
|
||||
public final TextView category;
|
||||
public final TextView posted;
|
||||
public final TextView simpleLanguage;
|
||||
|
||||
public HistoryHolder(View itemView) {
|
||||
super(itemView);
|
||||
|
||||
thumb = (LoadImageView) itemView.findViewById(R.id.thumb);
|
||||
title = (TextView) itemView.findViewById(R.id.title);
|
||||
uploader = (TextView) itemView.findViewById(R.id.uploader);
|
||||
rating = (SimpleRatingView) itemView.findViewById(R.id.rating);
|
||||
category = (TextView) itemView.findViewById(R.id.category);
|
||||
posted = (TextView) itemView.findViewById(R.id.posted);
|
||||
simpleLanguage = (TextView) itemView.findViewById(R.id.simple_language);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public GalleryInfo getDataAt(int position) {
|
||||
return null != mList ? mList.get(position) : null;
|
||||
public View getSwipeableContainerView() {
|
||||
return itemView;
|
||||
}
|
||||
}
|
||||
|
||||
private class HistoryAdapter extends RecyclerView.Adapter<HistoryHolder>
|
||||
implements SwipeableItemAdapter<HistoryHolder> {
|
||||
|
||||
private final LayoutInflater mInflater;
|
||||
|
||||
public HistoryAdapter() {
|
||||
mInflater = getLayoutInflater2();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
if (null == mLazyList) {
|
||||
return super.getItemId(position);
|
||||
} else {
|
||||
return mLazyList.get(position).gid;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public HistoryHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
return new HistoryHolder(mInflater.inflate(R.layout.item_gallery_list, parent, false));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(HistoryHolder holder, int position) {
|
||||
if (null == mLazyList) {
|
||||
return;
|
||||
}
|
||||
|
||||
GalleryInfo gi = mLazyList.get(position);
|
||||
holder.thumb.load(EhCacheKeyFactory.getThumbKey(gi.gid), gi.thumb);
|
||||
holder.title.setText(EhUtils.getSuitableTitle(gi));
|
||||
holder.uploader.setText(gi.uploader);
|
||||
holder.rating.setRating(gi.rating);
|
||||
TextView category = holder.category;
|
||||
String newCategoryText = EhUtils.getCategory(gi.category);
|
||||
if (!newCategoryText.equals(category.getText())) {
|
||||
category.setText(newCategoryText);
|
||||
category.setBackgroundColor(EhUtils.getCategoryColor(gi.category));
|
||||
}
|
||||
holder.posted.setText(gi.posted);
|
||||
holder.simpleLanguage.setText(gi.simpleLanguage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return null != mList ? mList.size() : 0;
|
||||
return null != mLazyList ? mLazyList.size() : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int onGetSwipeReactionType(HistoryHolder holder, int position, int x, int y) {
|
||||
return SwipeableItemConstants.REACTION_CAN_SWIPE_BOTH_H;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSetSwipeBackground(HistoryHolder holder, int position, int type) {}
|
||||
|
||||
@Override
|
||||
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_CANCELED:
|
||||
default:
|
||||
return new SwipeResultActionDefault();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class SwipeResultActionClear extends SwipeResultActionRemoveItem {
|
||||
|
||||
private final int mPosition;
|
||||
|
||||
protected SwipeResultActionClear(int position) {
|
||||
mPosition = position;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPerformAction() {
|
||||
super.onPerformAction();
|
||||
if (null == mLazyList || null == mAdapter) {
|
||||
return;
|
||||
}
|
||||
|
||||
HistoryInfo info = mLazyList.get(mPosition);
|
||||
EhDB.deleteHistoryInfo(info);
|
||||
updateLazyList();
|
||||
mAdapter.notifyItemRemoved(mPosition);
|
||||
updateView(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -30,12 +30,14 @@ import com.hippo.ehviewer.EhApplication;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.client.EhClient;
|
||||
import com.hippo.ehviewer.client.EhRequest;
|
||||
import com.hippo.ehviewer.ui.MainActivity;
|
||||
import com.hippo.scene.Announcer;
|
||||
import com.hippo.scene.SceneFragment;
|
||||
import com.hippo.scene.StageActivity;
|
||||
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;
|
||||
|
||||
/**
|
||||
* Only show a progress with jobs in background
|
||||
@@ -61,7 +63,9 @@ public final class ProgressScene extends BaseScene implements View.OnClickListen
|
||||
private String mPToken;
|
||||
private int mPage;
|
||||
|
||||
@Nullable
|
||||
private TextView mTip;
|
||||
@Nullable
|
||||
private ViewTransition mViewTransition;
|
||||
|
||||
@Override
|
||||
@@ -81,6 +85,12 @@ public final class ProgressScene extends BaseScene implements View.OnClickListen
|
||||
}
|
||||
|
||||
private boolean doJobs() {
|
||||
Context context = getContext2();
|
||||
MainActivity activity = getActivity2();
|
||||
if (null == context || null == activity) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (ACTION_GALLERY_TOKEN.equals(mAction)) {
|
||||
if (mGid == -1 || mPToken == null || mPage == -1) {
|
||||
return false;
|
||||
@@ -89,9 +99,9 @@ public final class ProgressScene extends BaseScene implements View.OnClickListen
|
||||
EhRequest request = new EhRequest()
|
||||
.setMethod(EhClient.METHOD_GET_GALLERY_TOKEN)
|
||||
.setArgs(mGid, mPToken, mPage)
|
||||
.setCallback(new GetGalleryTokenListener(getContext(),
|
||||
((StageActivity) getActivity()).getStageId(), getTag()));
|
||||
EhApplication.getEhClient(getContext()).execute(request);
|
||||
.setCallback(new GetGalleryTokenListener(context,
|
||||
activity.getStageId(), getTag()));
|
||||
EhApplication.getEhClient(context).execute(request);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -155,10 +165,13 @@ public final class ProgressScene extends BaseScene implements View.OnClickListen
|
||||
public View onCreateView(LayoutInflater inflater,
|
||||
@Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
View view = inflater.inflate(R.layout.scene_progress, container, false);
|
||||
View progress = view.findViewById(R.id.progress);
|
||||
mTip = (TextView) view.findViewById(R.id.tip);
|
||||
View progress = ViewUtils.$$(view, R.id.progress);
|
||||
mTip = (TextView) ViewUtils.$$(view, R.id.tip);
|
||||
|
||||
Drawable drawable = DrawableManager.getDrawable(getContext(), R.drawable.big_weird_face);
|
||||
Context context = getContext2();
|
||||
AssertUtils.assertNotNull(context);
|
||||
|
||||
Drawable drawable = DrawableManager.getDrawable(context, R.drawable.big_weird_face);
|
||||
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
|
||||
mTip.setCompoundDrawables(null, drawable, null, null);
|
||||
mTip.setOnClickListener(this);
|
||||
@@ -175,13 +188,23 @@ public final class ProgressScene extends BaseScene implements View.OnClickListen
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
|
||||
mTip = null;
|
||||
mViewTransition = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (mTip == v) {
|
||||
if (doJobs()) {
|
||||
mValid = true;
|
||||
// Show progress
|
||||
mViewTransition.showView(0, true);
|
||||
if (null != mViewTransition) {
|
||||
mViewTransition.showView(0, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -198,10 +221,12 @@ public final class ProgressScene extends BaseScene implements View.OnClickListen
|
||||
|
||||
private void onGetGalleryTokenFailure(Exception e) {
|
||||
mValid = false;
|
||||
mError = ExceptionUtils.getReadableString(getContext(), e);
|
||||
|
||||
if (isViewCreated()) {
|
||||
Context context = getContext2();
|
||||
|
||||
if (null != context && null != mViewTransition && null != mTip) {
|
||||
// Show tip
|
||||
mError = ExceptionUtils.getReadableString(context, e);
|
||||
mViewTransition.showView(1);
|
||||
mTip.setText(mError);
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package com.hippo.ehviewer.ui.scene;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.graphics.drawable.NinePatchDrawable;
|
||||
@@ -48,6 +49,7 @@ 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 java.util.List;
|
||||
@@ -91,7 +93,10 @@ public final class QuickSearchScene extends ToolbarScene {
|
||||
TextView tip = (TextView) ViewUtils.$$(view, R.id.tip);
|
||||
mViewTransition = new ViewTransition(recyclerView, tip);
|
||||
|
||||
Drawable drawable = DrawableManager.getDrawable(getContext(), R.drawable.big_search);
|
||||
Context context = getContext2();
|
||||
AssertUtils.assertNotNull(context);
|
||||
|
||||
Drawable drawable = DrawableManager.getDrawable(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);
|
||||
@@ -103,7 +108,7 @@ public final class QuickSearchScene extends ToolbarScene {
|
||||
// drag & drop manager
|
||||
RecyclerViewDragDropManager dragDropManager = new RecyclerViewDragDropManager();
|
||||
dragDropManager.setDraggingItemShadowDrawable(
|
||||
(NinePatchDrawable) getResources().getDrawable(R.drawable.shadow_8dp));
|
||||
(NinePatchDrawable) context.getResources().getDrawable(R.drawable.shadow_8dp));
|
||||
// swipe manager
|
||||
RecyclerViewSwipeManager swipeManager = new RecyclerViewSwipeManager();
|
||||
RecyclerView.Adapter adapter = new QuickSearchAdapter();
|
||||
@@ -114,7 +119,7 @@ public final class QuickSearchScene extends ToolbarScene {
|
||||
final GeneralItemAnimator animator = new SwipeDismissItemAnimator();
|
||||
animator.setSupportsChangeAnimations(false);
|
||||
recyclerView.hasFixedSize();
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(context));
|
||||
recyclerView.setAdapter(adapter);
|
||||
recyclerView.setItemAnimator(animator);
|
||||
guardManager.attachRecyclerView(recyclerView);
|
||||
@@ -181,10 +186,16 @@ public final class QuickSearchScene extends ToolbarScene {
|
||||
implements DraggableItemAdapter<QuickSearchHolder>,
|
||||
SwipeableItemAdapter<QuickSearchHolder> {
|
||||
|
||||
private final LayoutInflater mInflater;
|
||||
|
||||
public QuickSearchAdapter() {
|
||||
mInflater = getLayoutInflater2();
|
||||
AssertUtils.assertNotNull(mInflater);
|
||||
}
|
||||
|
||||
@Override
|
||||
public QuickSearchHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
return new QuickSearchHolder(getActivity().getLayoutInflater()
|
||||
.inflate(R.layout.item_label_list, parent, false));
|
||||
return new QuickSearchHolder(mInflater.inflate(R.layout.item_label_list, parent, false));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -269,14 +280,15 @@ public final class QuickSearchScene extends ToolbarScene {
|
||||
protected void onPerformAction() {
|
||||
super.onPerformAction();
|
||||
|
||||
Context context = getContext2();
|
||||
final List<QuickSearch> quickSearchList = mQuickSearchList;
|
||||
if (quickSearchList == null || mPosition < 0 || mPosition >= quickSearchList.size()) {
|
||||
if (null == context || null == quickSearchList || mPosition < 0 || mPosition >= quickSearchList.size()) {
|
||||
return;
|
||||
}
|
||||
|
||||
final QuickSearch quickSearch = quickSearchList.get(mPosition);
|
||||
|
||||
new AlertDialog.Builder(getContext())
|
||||
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() {
|
||||
|
||||
@@ -0,0 +1,173 @@
|
||||
/*
|
||||
* 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.content.Context;
|
||||
import android.hardware.Sensor;
|
||||
import android.hardware.SensorManager;
|
||||
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.R;
|
||||
import com.hippo.ehviewer.Settings;
|
||||
import com.hippo.ehviewer.ui.MainActivity;
|
||||
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 java.util.List;
|
||||
|
||||
public class SecurityScene extends BaseScene implements
|
||||
LockPatternView.OnPatternListener, ShakeDetector.OnShakeListener {
|
||||
|
||||
private static final int MAX_RETRY_TIMES = 5;
|
||||
|
||||
private static final String KEY_RETRY_TIMES = "retry_times";
|
||||
|
||||
@Nullable
|
||||
private LockPatternView mPatternView;
|
||||
|
||||
private SensorManager mSensorManager;
|
||||
private Sensor mAccelerometer;
|
||||
private ShakeDetector mShakeDetector;
|
||||
|
||||
private int mRetryTimes;
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
Context context = getContext2();
|
||||
AssertUtils.assertNotNull(context);
|
||||
mSensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
|
||||
if (null != mSensorManager) {
|
||||
mAccelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
|
||||
if (null != mAccelerometer) {
|
||||
mShakeDetector = new ShakeDetector();
|
||||
mShakeDetector.setOnShakeListener(this);
|
||||
}
|
||||
}
|
||||
|
||||
if (null == savedInstanceState) {
|
||||
mRetryTimes = MAX_RETRY_TIMES;
|
||||
} else {
|
||||
mRetryTimes = savedInstanceState.getInt(KEY_RETRY_TIMES);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
|
||||
mSensorManager = null;
|
||||
mAccelerometer = null;
|
||||
mShakeDetector = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
|
||||
if (null != mShakeDetector) {
|
||||
mSensorManager.registerListener(mShakeDetector, mAccelerometer, SensorManager.SENSOR_DELAY_UI);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
|
||||
if (null != mShakeDetector) {
|
||||
mSensorManager.unregisterListener(mShakeDetector);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
outState.putInt(KEY_RETRY_TIMES, mRetryTimes);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater,
|
||||
@Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
View view = inflater.inflate(R.layout.scene_security, container, false);
|
||||
|
||||
mPatternView = (LockPatternView) ViewUtils.$$(view, R.id.pattern_view);
|
||||
mPatternView.setOnPatternListener(this);
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
|
||||
mPatternView = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPatternStart() {}
|
||||
|
||||
@Override
|
||||
public void onPatternCleared() {}
|
||||
|
||||
@Override
|
||||
public void onPatternCellAdded(List<LockPatternView.Cell> pattern) {}
|
||||
|
||||
@Override
|
||||
public void onPatternDetected(List<LockPatternView.Cell> pattern) {
|
||||
MainActivity activity = getActivity2();
|
||||
if (null == activity || null == mPatternView) {
|
||||
return;
|
||||
}
|
||||
|
||||
String enteredPatter = LockPatternUtils.patternToString(pattern);
|
||||
String targetPatter = Settings.getSecurity();
|
||||
|
||||
if (ObjectUtils.equal(enteredPatter, targetPatter)) {
|
||||
activity.startSceneForCheckStep(MainActivity.CHECK_STEP_SECURITY, getArguments());
|
||||
finish();
|
||||
} else {
|
||||
mPatternView.setDisplayMode(LockPatternView.DisplayMode.Wrong);
|
||||
mRetryTimes--;
|
||||
if (mRetryTimes <= 0) {
|
||||
finish();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onShake(int count) {
|
||||
if (count == 10) {
|
||||
MainActivity activity = getActivity2();
|
||||
if (null == activity) {
|
||||
return;
|
||||
}
|
||||
Settings.putSecurity("");
|
||||
activity.startSceneForCheckStep(MainActivity.CHECK_STEP_SECURITY, getArguments());
|
||||
finish();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
* 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 android.widget.RadioGroup;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.Settings;
|
||||
import com.hippo.ehviewer.client.EhUrl;
|
||||
import com.hippo.ehviewer.ui.MainActivity;
|
||||
import com.hippo.yorozuya.ViewUtils;
|
||||
|
||||
public class SelectSiteScene extends BaseScene implements View.OnClickListener {
|
||||
|
||||
private RadioGroup mRadioGroup;
|
||||
private View mOk;
|
||||
|
||||
@Override
|
||||
public boolean needShowLeftDrawer() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
|
||||
@Nullable Bundle savedInstanceState) {
|
||||
View view = inflater.inflate(R.layout.scene_select_site, container, false);
|
||||
|
||||
mRadioGroup = (RadioGroup) ViewUtils.$$(view, R.id.radio_group);
|
||||
mOk = ViewUtils.$$(view, R.id.ok);
|
||||
|
||||
mOk.setOnClickListener(this);
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
|
||||
mRadioGroup = null;
|
||||
mOk = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
MainActivity activity = getActivity2();
|
||||
if (null == activity || null == mRadioGroup) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (v == mOk) {
|
||||
int id = mRadioGroup.getCheckedRadioButtonId();
|
||||
switch (id) {
|
||||
case R.id.site_e:
|
||||
Settings.putSelectSite(false);
|
||||
Settings.putGallerySite(EhUrl.SITE_G);
|
||||
activity.startSceneForCheckStep(MainActivity.CHECK_STEP_SELECT_SITE, getArguments());
|
||||
finish();
|
||||
break;
|
||||
case R.id.site_ex:
|
||||
Settings.putSelectSite(false);
|
||||
Settings.putGallerySite(EhUrl.SITE_EX);
|
||||
activity.startSceneForCheckStep(MainActivity.CHECK_STEP_SELECT_SITE, getArguments());
|
||||
finish();
|
||||
break;
|
||||
default:
|
||||
Toast.makeText(activity, R.string.no_select, Toast.LENGTH_SHORT).show();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -44,8 +44,6 @@ import com.hippo.ehviewer.ui.MainActivity;
|
||||
import com.hippo.rippleold.RippleSalon;
|
||||
import com.hippo.scene.Announcer;
|
||||
import com.hippo.scene.SceneFragment;
|
||||
import com.hippo.scene.StageActivity;
|
||||
import com.hippo.util.ActivityHelper;
|
||||
import com.hippo.util.ExceptionUtils;
|
||||
import com.hippo.yorozuya.AssertUtils;
|
||||
import com.hippo.yorozuya.ViewUtils;
|
||||
@@ -82,6 +80,7 @@ public final class SignInScene extends BaseScene implements EditText.OnEditorAct
|
||||
@Nullable
|
||||
private TextView mSkipSigningIn;
|
||||
|
||||
private boolean mSigningIn;
|
||||
private int mRequestId;
|
||||
|
||||
@Override
|
||||
@@ -148,8 +147,11 @@ public final class SignInScene extends BaseScene implements EditText.OnEditorAct
|
||||
RippleSalon.addRipple(mRegister, true);
|
||||
RippleSalon.addRipple(mSignIn, true);
|
||||
|
||||
EhApplication application = (EhApplication) getContext().getApplicationContext();
|
||||
Context context = getContext2();
|
||||
AssertUtils.assertNotNull(container);
|
||||
EhApplication application = (EhApplication) context.getApplicationContext();
|
||||
if (application.containGlobalStuff(mRequestId)) {
|
||||
mSigningIn = true;
|
||||
// request exist
|
||||
showProgress(false);
|
||||
}
|
||||
@@ -163,7 +165,7 @@ public final class SignInScene extends BaseScene implements EditText.OnEditorAct
|
||||
|
||||
// Show IME
|
||||
if (mProgress != null && View.INVISIBLE != mProgress.getVisibility()) {
|
||||
ActivityHelper.showSoftInput(getActivity(), mUsername);
|
||||
showSoftInput(mUsername);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -215,8 +217,13 @@ public final class SignInScene extends BaseScene implements EditText.OnEditorAct
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
MainActivity activity = getActivity2();
|
||||
if (null == activity) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (mRegister == v) {
|
||||
UrlOpener.openUrl(getActivity(), EhUrl.URL_REGISTER, false, true);
|
||||
UrlOpener.openUrl(activity, EhUrl.URL_REGISTER, false, true);
|
||||
} else if (mSignIn == v) {
|
||||
signIn();
|
||||
} else if (mSignInViaWebView == v) {
|
||||
@@ -224,6 +231,8 @@ public final class SignInScene extends BaseScene implements EditText.OnEditorAct
|
||||
} else if (mSignInViaCookies == v) {
|
||||
startScene(new Announcer(CookieSignInScene.class).setRequestCode(this, REQUEST_CODE_COOKIE));
|
||||
} else if (mSkipSigningIn == v) {
|
||||
// Set gallery size SITE_G if skip sign in
|
||||
Settings.putGallerySite(EhUrl.SITE_G);
|
||||
redirectTo();
|
||||
}
|
||||
}
|
||||
@@ -241,7 +250,13 @@ public final class SignInScene extends BaseScene implements EditText.OnEditorAct
|
||||
}
|
||||
|
||||
private void signIn() {
|
||||
if (null == mUsername || null == mPassword || null == mUsernameLayout ||
|
||||
if (mSigningIn) {
|
||||
return;
|
||||
}
|
||||
|
||||
Context context = getContext2();
|
||||
MainActivity activity = getActivity2();
|
||||
if (null == context || null == activity || null == mUsername || null == mPassword || null == mUsernameLayout ||
|
||||
null == mPasswordLayout) {
|
||||
return;
|
||||
}
|
||||
@@ -263,73 +278,108 @@ public final class SignInScene extends BaseScene implements EditText.OnEditorAct
|
||||
mPasswordLayout.setError(null);
|
||||
}
|
||||
|
||||
ActivityHelper.hideSoftInput(getActivity());
|
||||
hideSoftInput();
|
||||
showProgress(true);
|
||||
|
||||
// Clean up for sign in
|
||||
EhUtils.signOut(getContext());
|
||||
EhUtils.signOut(context);
|
||||
|
||||
EhCallback callback = new SignInListener(getContext(),
|
||||
((StageActivity) getActivity()).getStageId(), getTag());
|
||||
mRequestId = ((EhApplication) getContext().getApplicationContext()).putGlobalStuff(callback);
|
||||
EhCallback callback = new SignInListener(context,
|
||||
activity.getStageId(), getTag());
|
||||
mRequestId = ((EhApplication) context.getApplicationContext()).putGlobalStuff(callback);
|
||||
EhRequest request = new EhRequest()
|
||||
.setMethod(EhClient.METHOD_SIGN_IN)
|
||||
.setArgs(username, password)
|
||||
.setCallback(callback);
|
||||
EhApplication.getEhClient(getContext()).execute(request);
|
||||
EhApplication.getEhClient(context).execute(request);
|
||||
|
||||
mSigningIn = true;
|
||||
}
|
||||
|
||||
private void getProfile() {
|
||||
ActivityHelper.hideSoftInput(getActivity());
|
||||
Context context = getContext2();
|
||||
MainActivity activity = getActivity2();
|
||||
if (null == context || null == activity) {
|
||||
return;
|
||||
}
|
||||
|
||||
hideSoftInput();
|
||||
showProgress(true);
|
||||
|
||||
EhCallback callback = new GetProfileListener(getContext(),
|
||||
((StageActivity) getActivity()).getStageId(), getTag());
|
||||
mRequestId = ((EhApplication) getContext().getApplicationContext()).putGlobalStuff(callback);
|
||||
EhCallback callback = new GetProfileListener(context,
|
||||
activity.getStageId(), getTag());
|
||||
mRequestId = ((EhApplication) context.getApplicationContext()).putGlobalStuff(callback);
|
||||
EhRequest request = new EhRequest()
|
||||
.setMethod(EhClient.METHOD_GET_PROFILE)
|
||||
.setCallback(callback);
|
||||
EhApplication.getEhClient(getContext()).execute(request);
|
||||
EhApplication.getEhClient(context).execute(request);
|
||||
}
|
||||
|
||||
private void redirectTo() {
|
||||
((MainActivity) getActivity()).startSceneForCheckStep(
|
||||
MainActivity.CHECK_STEP_SIGN_IN, getArguments());
|
||||
Settings.putNeedSignIn(false);
|
||||
MainActivity activity = getActivity2();
|
||||
if (null != activity) {
|
||||
activity.startSceneForCheckStep(MainActivity.CHECK_STEP_SIGN_IN, getArguments());
|
||||
}
|
||||
finish();
|
||||
}
|
||||
|
||||
private void whetherToSkip() {
|
||||
new AlertDialog.Builder(getContext())
|
||||
.setTitle(R.string.skip_signing_in)
|
||||
.setMessage(R.string.skip_signing_in_plain)
|
||||
Context context = getContext2();
|
||||
if (null == context) {
|
||||
return;
|
||||
}
|
||||
|
||||
new AlertDialog.Builder(context)
|
||||
.setTitle(R.string.sign_in_failed)
|
||||
.setMessage(R.string.sign_in_failed_plain)
|
||||
.setNegativeButton(android.R.string.cancel, null)
|
||||
.setPositiveButton(R.string.get_it, null)
|
||||
.show();
|
||||
}
|
||||
|
||||
public void onSignInSuccess() {
|
||||
if (EhApplication.getEhCookieStore(getContext()).hasSignedIn()) {
|
||||
Context context = getContext2();
|
||||
if (null == context) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (EhApplication.getEhCookieStore(context).hasSignedIn()) {
|
||||
getProfile();
|
||||
} else {
|
||||
mSigningIn = false;
|
||||
hideProgress();
|
||||
whetherToSkip();
|
||||
}
|
||||
}
|
||||
|
||||
public void onSignInFailure(Exception e) {
|
||||
Toast.makeText(getContext(), ExceptionUtils.getReadableString(getContext(), e),
|
||||
Context context = getContext2();
|
||||
if (null == context) {
|
||||
return;
|
||||
}
|
||||
|
||||
mSigningIn = false;
|
||||
Toast.makeText(context, ExceptionUtils.getReadableString(context, e),
|
||||
Toast.LENGTH_SHORT).show();
|
||||
hideProgress();
|
||||
whetherToSkip();
|
||||
}
|
||||
|
||||
public void onGetProfileSuccess() {
|
||||
mSigningIn = false;
|
||||
updateAvatar();
|
||||
redirectTo();
|
||||
}
|
||||
|
||||
public void onGetProfileFailure(Exception e) {
|
||||
Toast.makeText(getContext(), ExceptionUtils.getReadableString(getContext(), e),
|
||||
Context context = getContext2();
|
||||
if (null == context) {
|
||||
return;
|
||||
}
|
||||
|
||||
mSigningIn = false;
|
||||
Toast.makeText(context, ExceptionUtils.getReadableString(context, e),
|
||||
Toast.LENGTH_SHORT).show();
|
||||
hideProgress();
|
||||
whetherToSkip();
|
||||
|
||||
@@ -0,0 +1,272 @@
|
||||
/*
|
||||
* 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.util.Log;
|
||||
|
||||
import com.hippo.ehviewer.client.data.GalleryInfo;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
// TODO GridLayoutManager do not work at all ! SpaceGroupIndex is useless for layout! I need to create one by myself
|
||||
public class ThumbSpanHelper {
|
||||
|
||||
private static final int MIN_ARRAY_LENGTH = 50;
|
||||
private static final int MAX_ROW_INTERVAL = 3;
|
||||
|
||||
private final List<GalleryInfo> mData;
|
||||
|
||||
// true for occupied, false for free
|
||||
private boolean[] mCells = new boolean[MIN_ARRAY_LENGTH];
|
||||
|
||||
private int mNextIndex;
|
||||
private int mNextGroupIndex;
|
||||
private int mNearSpaceIndex;
|
||||
private int mNearSpaceGroupIndex;
|
||||
private int mAttachedCount;
|
||||
|
||||
private int mSpanCount;
|
||||
|
||||
private boolean mEnable;
|
||||
|
||||
public ThumbSpanHelper(List<GalleryInfo> data) {
|
||||
mData = data;
|
||||
}
|
||||
|
||||
public void setEnable(boolean enable) {
|
||||
if (enable == mEnable) {
|
||||
return;
|
||||
}
|
||||
mEnable = enable;
|
||||
|
||||
if (!enable) {
|
||||
clear();
|
||||
mSpanCount = 0;
|
||||
} else {
|
||||
if (mSpanCount > 0) {
|
||||
rebuild();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setSpanCount(int spanCount) {
|
||||
if (!mEnable) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (spanCount == mSpanCount) {
|
||||
return;
|
||||
}
|
||||
mSpanCount = spanCount;
|
||||
if (spanCount > 0) {
|
||||
rebuild();
|
||||
}
|
||||
}
|
||||
|
||||
public void notifyDataSetChanged() {
|
||||
if (!mEnable || mSpanCount <= 0) {
|
||||
return;
|
||||
}
|
||||
rebuild();
|
||||
}
|
||||
|
||||
public void notifyItemRangeRemoved(int positionStart, int itemCount) {
|
||||
if (!mEnable || mSpanCount <= 0) {
|
||||
return;
|
||||
}
|
||||
rebuild();
|
||||
}
|
||||
|
||||
protected void notifyItemRangeInserted(int positionStart, int itemCount) {
|
||||
if (!mEnable || mSpanCount <= 0) {
|
||||
return;
|
||||
}
|
||||
if (mAttachedCount == positionStart) {
|
||||
append();
|
||||
} else {
|
||||
rebuild();
|
||||
}
|
||||
}
|
||||
|
||||
private void clear() {
|
||||
|
||||
Log.d("TAG", "=======================clear=======================");
|
||||
|
||||
if (mSpanCount > 0) {
|
||||
if (mNextGroupIndex > 0 || mNextIndex > 0) {
|
||||
Arrays.fill(mCells, 0, mNextGroupIndex * mSpanCount + mNextIndex, false);
|
||||
}
|
||||
} else {
|
||||
Arrays.fill(mCells, false);
|
||||
}
|
||||
mNextIndex = 0;
|
||||
mNextGroupIndex = 0;
|
||||
mNearSpaceIndex = 0;
|
||||
mNearSpaceGroupIndex = 0;
|
||||
mAttachedCount = 0;
|
||||
}
|
||||
|
||||
private void rebuild() {
|
||||
clear();
|
||||
append();
|
||||
}
|
||||
|
||||
private void append() {
|
||||
if (1 == mSpanCount) {
|
||||
for (int i = mAttachedCount, n = mData.size(); i < n; i++) {
|
||||
GalleryInfo gi = mData.get(i);
|
||||
gi.spanSize = 1;
|
||||
gi.spanGroupIndex = i;
|
||||
gi.spanIndex = 0;
|
||||
}
|
||||
mAttachedCount = mData.size();
|
||||
} else if (mSpanCount >= 2) {
|
||||
for (int i = mAttachedCount, n = mData.size(); i < n; i++) {
|
||||
GalleryInfo gi = mData.get(i);
|
||||
int spanSize = gi.thumbWidth <= gi.thumbHeight ? 1 : 2;
|
||||
gi.spanSize = spanSize;
|
||||
|
||||
if (1 == spanSize) {
|
||||
// Update near space
|
||||
updateNearSpace();
|
||||
|
||||
Log.d("TAG", "Update mNearSpaceGroupIndex = " + mNearSpaceGroupIndex + ", mNearSpaceIndex = " + mNearSpaceIndex);
|
||||
|
||||
if (mNextIndex == mNearSpaceIndex && mNextGroupIndex == mNearSpaceGroupIndex) {
|
||||
// No space, just append
|
||||
gi.spanIndex = mNextIndex;
|
||||
gi.spanGroupIndex = mNextGroupIndex;
|
||||
|
||||
// Update cell
|
||||
int start = gi.spanGroupIndex * mSpanCount + gi.spanIndex;
|
||||
fillCell(start, start + 1);
|
||||
|
||||
// Update field
|
||||
mNextIndex++;
|
||||
if (mSpanCount == mNextIndex) {
|
||||
mNextIndex = 0;
|
||||
mNextGroupIndex++;
|
||||
}
|
||||
mNearSpaceIndex = mNextIndex;
|
||||
mNearSpaceGroupIndex = mNextGroupIndex;
|
||||
|
||||
Log.d("TAG", "type 0");
|
||||
Log.d("TAG", "i = " + i + ", spanSize = " + spanSize + ", spanGroupIndex = " + gi.spanGroupIndex + ", spanIndex = " + gi.spanIndex);
|
||||
Log.d("TAG", "mNextGroupIndex = " + mNextGroupIndex + ", mNextIndex = " + mNextIndex);
|
||||
Log.d("TAG", "mNearSpaceGroupIndex = " + mNearSpaceGroupIndex + ", mNearSpaceIndex = " + mNearSpaceIndex);
|
||||
|
||||
} else {
|
||||
// Found space
|
||||
gi.spanIndex = mNearSpaceIndex;
|
||||
gi.spanGroupIndex = mNearSpaceGroupIndex;
|
||||
|
||||
// Update cell
|
||||
int start = gi.spanGroupIndex * mSpanCount + gi.spanIndex;
|
||||
fillCell(start, start + 1);
|
||||
|
||||
// Find near space
|
||||
findNearSpace(start + 1);
|
||||
|
||||
Log.d("TAG", "type 1");
|
||||
Log.d("TAG", "i = " + i + ", spanSize = " + spanSize + ", spanGroupIndex = " + gi.spanGroupIndex + ", spanIndex = " + gi.spanIndex);
|
||||
Log.d("TAG", "mNextGroupIndex = " + mNextGroupIndex + ", mNextIndex = " + mNextIndex);
|
||||
Log.d("TAG", "mNearSpaceGroupIndex = " + mNearSpaceGroupIndex + ", mNearSpaceIndex = " + mNearSpaceIndex);
|
||||
}
|
||||
} else {
|
||||
boolean syncNear = mNextIndex == mNearSpaceIndex && mNextGroupIndex == mNearSpaceGroupIndex;
|
||||
// false for old, true for new
|
||||
boolean oldOrNew;
|
||||
if (mSpanCount - mNextIndex >= 2) {
|
||||
gi.spanIndex = mNextIndex;
|
||||
gi.spanGroupIndex = mNextGroupIndex;
|
||||
oldOrNew = true;
|
||||
} else {
|
||||
// Go to next row
|
||||
gi.spanIndex = 0;
|
||||
gi.spanGroupIndex = mNextGroupIndex + 1;
|
||||
oldOrNew = false;
|
||||
}
|
||||
|
||||
// Update cell
|
||||
int start = gi.spanGroupIndex * mSpanCount + gi.spanIndex;
|
||||
fillCell(start, start + 2);
|
||||
|
||||
// Update field
|
||||
if (syncNear && !oldOrNew) {
|
||||
mNearSpaceIndex = mNextIndex;
|
||||
mNearSpaceGroupIndex = mNextGroupIndex;
|
||||
}
|
||||
mNextIndex = gi.spanIndex + 2;
|
||||
mNextGroupIndex = gi.spanGroupIndex;
|
||||
if (mSpanCount == mNextIndex) {
|
||||
mNextIndex = 0;
|
||||
mNextGroupIndex++;
|
||||
}
|
||||
if (syncNear && oldOrNew) {
|
||||
mNearSpaceIndex = mNextIndex;
|
||||
mNearSpaceGroupIndex = mNextGroupIndex;
|
||||
}
|
||||
|
||||
Log.d("TAG", "type 2");
|
||||
Log.d("TAG", "i = " + i + ", spanSize = " + spanSize + ", spanGroupIndex = " + gi.spanGroupIndex + ", spanIndex = " + gi.spanIndex);
|
||||
Log.d("TAG", "mNextGroupIndex = " + mNextGroupIndex + ", mNextIndex = " + mNextIndex);
|
||||
Log.d("TAG", "mNearSpaceGroupIndex = " + mNearSpaceGroupIndex + ", mNearSpaceIndex = " + mNearSpaceIndex);
|
||||
}
|
||||
}
|
||||
mAttachedCount = mData.size();
|
||||
}
|
||||
}
|
||||
|
||||
private void updateNearSpace() {
|
||||
// Check is space is near enough
|
||||
if (mNextGroupIndex - mNearSpaceGroupIndex <= MAX_ROW_INTERVAL) {
|
||||
return;
|
||||
}
|
||||
|
||||
// The space is too far, find a near one
|
||||
int start = Math.max(0, mNextGroupIndex - MAX_ROW_INTERVAL) * mSpanCount;
|
||||
findNearSpace(start);
|
||||
}
|
||||
|
||||
private void findNearSpace(int start) {
|
||||
int end = mNextGroupIndex * mSpanCount + mNextIndex;
|
||||
boolean[] cells = mCells;
|
||||
for (int i = start; i < end; i++) {
|
||||
if (!cells[i]) {
|
||||
// Find space !
|
||||
mNearSpaceIndex = i % mSpanCount;
|
||||
mNearSpaceGroupIndex = i / mSpanCount;
|
||||
return;
|
||||
}
|
||||
}
|
||||
// Can't find space
|
||||
mNearSpaceIndex = mNextIndex;
|
||||
mNearSpaceGroupIndex = mNextGroupIndex;
|
||||
}
|
||||
|
||||
private void fillCell(int start, int end) {
|
||||
boolean[] array = mCells;
|
||||
// Avoid IndexOutOfBoundsException
|
||||
if (end >= array.length) {
|
||||
boolean[] newArray = new boolean[end + (end < (MIN_ARRAY_LENGTH / 2) ? MIN_ARRAY_LENGTH : end >> 1)];
|
||||
System.arraycopy(array, 0, newArray, 0, array.length);
|
||||
mCells = array = newArray;
|
||||
}
|
||||
Arrays.fill(array, start, end, true);
|
||||
}
|
||||
}
|
||||
@@ -80,8 +80,10 @@ public final class WarningScene extends BaseScene implements View.OnClickListene
|
||||
Settings.putShowWarning(false);
|
||||
|
||||
// Start new scene and finish it self
|
||||
((MainActivity) getActivity()).startSceneForCheckStep(
|
||||
MainActivity.CHECK_STEP_WARNING, getArguments());
|
||||
MainActivity activity = getActivity2();
|
||||
if (null != activity) {
|
||||
activity.startSceneForCheckStep(MainActivity.CHECK_STEP_WARNING, getArguments());
|
||||
}
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@ 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;
|
||||
@@ -58,9 +59,12 @@ public class WebViewSignInScene extends BaseScene {
|
||||
@SuppressLint("SetJavaScriptEnabled")
|
||||
public View onCreateView(LayoutInflater inflater,
|
||||
@Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
EhUtils.signOut(getContext());
|
||||
Context context = getContext2();
|
||||
AssertUtils.assertNotNull(context);
|
||||
|
||||
EhUtils.signOut(context);
|
||||
CookieManager.getInstance().removeAllCookie();
|
||||
mWebView = new WebView(getContext());
|
||||
mWebView = new WebView(context);
|
||||
mWebView.getSettings().setJavaScriptEnabled(true);
|
||||
mWebView.setWebViewClient(new LoginWebViewClient());
|
||||
mWebView.loadUrl(EhUrl.URL_SIGN_IN);
|
||||
@@ -106,7 +110,7 @@ public class WebViewSignInScene extends BaseScene {
|
||||
|
||||
@Override
|
||||
public void onPageFinished(WebView view, String url) {
|
||||
Context context = getContext();
|
||||
Context context = getContext2();
|
||||
if (context == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,211 @@
|
||||
/*
|
||||
* Copyright 2016 Hippo Seven
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.hippo.ehviewer.widget;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.Context;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Paint;
|
||||
import android.os.Build;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.Settings;
|
||||
import com.hippo.yorozuya.ViewUtils;
|
||||
|
||||
public class GalleryGuideView extends ViewGroup implements View.OnClickListener {
|
||||
|
||||
private int mBgColor;
|
||||
private Paint mPaint;
|
||||
private final float[] mPoints = new float[3 * 4];
|
||||
private int mStep;
|
||||
|
||||
private TextView mLeftText;
|
||||
private TextView mRightText;
|
||||
private TextView mMenuText;
|
||||
private TextView mProgressText;
|
||||
private TextView mLongClickText;
|
||||
|
||||
public GalleryGuideView(Context context) {
|
||||
super(context);
|
||||
init(context);
|
||||
}
|
||||
|
||||
public GalleryGuideView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
init(context);
|
||||
}
|
||||
|
||||
public GalleryGuideView(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
init(context);
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
||||
public GalleryGuideView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
||||
super(context, attrs, defStyleAttr, defStyleRes);
|
||||
init(context);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private void init(Context context) {
|
||||
mBgColor = context.getResources().getColor(R.color.guide_bg);
|
||||
mPaint = new Paint();
|
||||
mPaint.setColor(Color.WHITE);
|
||||
mPaint.setStyle(Paint.Style.STROKE);
|
||||
mPaint.setStrokeWidth(context.getResources().getDimension(R.dimen.gallery_guide_divider_width));
|
||||
setOnClickListener(this);
|
||||
setWillNotDraw(false);
|
||||
bind();
|
||||
}
|
||||
|
||||
private void bind() {
|
||||
// Clear up
|
||||
removeAllViews();
|
||||
mLeftText = null;
|
||||
mRightText = null;
|
||||
mMenuText = null;
|
||||
mProgressText = null;
|
||||
mLongClickText = null;
|
||||
|
||||
switch (mStep) {
|
||||
case 0:
|
||||
bind1();
|
||||
break;
|
||||
default:
|
||||
case 1:
|
||||
bind2();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void bind1() {
|
||||
LayoutInflater inflater = LayoutInflater.from(getContext());
|
||||
inflater.inflate(R.layout.widget_gallery_guide_1, this);
|
||||
mLeftText = (TextView) getChildAt(0);
|
||||
mRightText = (TextView) getChildAt(1);
|
||||
mMenuText = (TextView) getChildAt(2);
|
||||
mProgressText = (TextView) getChildAt(3);
|
||||
}
|
||||
|
||||
private void bind2() {
|
||||
LayoutInflater inflater = LayoutInflater.from(getContext());
|
||||
inflater.inflate(R.layout.widget_gallery_guide_2, this);
|
||||
mLongClickText = (TextView) getChildAt(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||
int widthSize = MeasureSpec.getSize(widthMeasureSpec);
|
||||
int widthMode = MeasureSpec.getMode(widthMeasureSpec);
|
||||
int heightSize = MeasureSpec.getSize(heightMeasureSpec);
|
||||
int heightMode = MeasureSpec.getMode(heightMeasureSpec);
|
||||
if (MeasureSpec.EXACTLY != widthMode || MeasureSpec.EXACTLY != heightMode) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
switch (mStep) {
|
||||
case 0:
|
||||
mLeftText.measure(MeasureSpec.makeMeasureSpec(widthSize / 3, MeasureSpec.EXACTLY),
|
||||
MeasureSpec.makeMeasureSpec(heightSize, MeasureSpec.EXACTLY));
|
||||
mRightText.measure(MeasureSpec.makeMeasureSpec(widthSize / 3, MeasureSpec.EXACTLY),
|
||||
MeasureSpec.makeMeasureSpec(heightSize, MeasureSpec.EXACTLY));
|
||||
mMenuText.measure(MeasureSpec.makeMeasureSpec(widthSize / 3, MeasureSpec.EXACTLY),
|
||||
MeasureSpec.makeMeasureSpec(heightSize * 2 / 3, MeasureSpec.EXACTLY));
|
||||
mProgressText.measure(MeasureSpec.makeMeasureSpec(widthSize / 3, MeasureSpec.EXACTLY),
|
||||
MeasureSpec.makeMeasureSpec(heightSize / 3, MeasureSpec.EXACTLY));
|
||||
break;
|
||||
default:
|
||||
case 1:
|
||||
mLongClickText.measure(MeasureSpec.makeMeasureSpec(widthSize, MeasureSpec.EXACTLY),
|
||||
MeasureSpec.makeMeasureSpec(heightSize, MeasureSpec.EXACTLY));
|
||||
break;
|
||||
}
|
||||
|
||||
setMeasuredDimension(widthSize, heightSize);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onLayout(boolean changed, int l, int t, int r, int b) {
|
||||
int width = r - l;
|
||||
int height = b - t;
|
||||
|
||||
switch (mStep) {
|
||||
case 0:
|
||||
mLeftText.layout(0, 0, width / 3, height);
|
||||
mRightText.layout(width * 2 / 3, 0, width, height);
|
||||
mMenuText.layout(width / 3, 0, width * 2 / 3, height * 2 / 3);
|
||||
mProgressText.layout(width / 3, height * 2 / 3, width * 2 / 3, height);
|
||||
break;
|
||||
default:
|
||||
case 1:
|
||||
mLongClickText.layout(0, 0, width, height);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
|
||||
super.onSizeChanged(w, h, oldw, oldh);
|
||||
|
||||
if (0 == mStep) {
|
||||
mPoints[0] = w / 3;
|
||||
mPoints[1] = 0;
|
||||
mPoints[2] = w / 3;
|
||||
mPoints[3] = h;
|
||||
|
||||
mPoints[4] = w * 2 / 3;
|
||||
mPoints[5] = 0;
|
||||
mPoints[6] = w * 2 / 3;
|
||||
mPoints[7] = h;
|
||||
|
||||
mPoints[8] = w / 3;
|
||||
mPoints[9] = h * 2 / 3;
|
||||
mPoints[10] = w * 2 / 3;
|
||||
mPoints[11] = h * 2 / 3;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDraw(Canvas canvas) {
|
||||
super.onDraw(canvas);
|
||||
canvas.drawColor(mBgColor);
|
||||
if (0 == mStep) {
|
||||
canvas.drawLines(mPoints, mPaint);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
switch (mStep) {
|
||||
case 0:
|
||||
mStep++;
|
||||
bind();
|
||||
break;
|
||||
default:
|
||||
case 1:
|
||||
Settings.putGuideGallery(false);
|
||||
ViewUtils.removeFromParent(this);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* Copyright 2016 Hippo Seven
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.hippo.ehviewer.widget;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Canvas;
|
||||
import android.support.v7.widget.AppCompatSeekBar;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.MotionEvent;
|
||||
|
||||
public class ReversibleSeekBar extends AppCompatSeekBar {
|
||||
|
||||
private boolean mReverse;
|
||||
|
||||
public ReversibleSeekBar(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public ReversibleSeekBar(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
public ReversibleSeekBar(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
}
|
||||
|
||||
public void setReverse(boolean reverse) {
|
||||
mReverse = reverse;
|
||||
invalidate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Canvas canvas) {
|
||||
boolean reverse = mReverse;
|
||||
int saveCount = 0;
|
||||
if (reverse) {
|
||||
saveCount = canvas.save();
|
||||
float px = this.getWidth() / 2.0f;
|
||||
float py = this.getHeight() / 2.0f;
|
||||
canvas.scale(-1, 1, px, py);
|
||||
}
|
||||
super.draw(canvas);
|
||||
if (reverse) {
|
||||
canvas.restoreToCount(saveCount);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onTouchEvent(MotionEvent event) {
|
||||
boolean reverse = mReverse;
|
||||
float x = 0.0f, y = 0.0f;
|
||||
if (reverse) {
|
||||
x = event.getX();
|
||||
y = event.getY();
|
||||
event.setLocation(getWidth() - x, y);
|
||||
}
|
||||
boolean result = super.onTouchEvent(event);
|
||||
if (reverse) {
|
||||
event.setLocation(x, y);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -23,6 +23,7 @@ import android.database.sqlite.SQLiteDatabase;
|
||||
import android.database.sqlite.SQLiteOpenHelper;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.hippo.util.SqlUtils;
|
||||
import com.hippo.yorozuya.Say;
|
||||
|
||||
import java.util.LinkedList;
|
||||
@@ -64,7 +65,7 @@ public class SearchDatabase {
|
||||
sb.append("SELECT * FROM ").append(TABLE_SUGGESTIONS);
|
||||
if (!TextUtils.isEmpty(prefix)) {
|
||||
sb.append(" WHERE ").append(COLUMN_QUERY).append(" LIKE '")
|
||||
.append(prefix).append("%'");
|
||||
.append(SqlUtils.sqlEscapeString(prefix)).append("%'");
|
||||
}
|
||||
sb.append(" ORDER BY ").append(COLUMN_DATE).append(" DESC")
|
||||
.append(" LIMIT 5");
|
||||
|
||||
@@ -280,7 +280,9 @@ public class SearchLayout extends EasyRecyclerView implements CompoundButton.OnC
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (mNormalSearchModeHelp == v) {
|
||||
new AlertDialog.Builder(getContext()).setTitle("TODO").setMessage("TODO").show();
|
||||
new AlertDialog.Builder(getContext())
|
||||
.setMessage(R.string.search_tip)
|
||||
.show();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+14
-15
@@ -22,48 +22,47 @@ import android.util.AttributeSet;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.SeekBar;
|
||||
|
||||
import com.hippo.widget.Slider;
|
||||
public class SeekBarPanel extends LinearLayout {
|
||||
|
||||
public class SliderPanel extends LinearLayout {
|
||||
private SeekBar mSeekBar;
|
||||
|
||||
private Slider mSlider;
|
||||
|
||||
public SliderPanel(Context context) {
|
||||
public SeekBarPanel(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public SliderPanel(Context context, AttributeSet attrs) {
|
||||
public SeekBarPanel(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
public SliderPanel(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
public SeekBarPanel(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewAdded(View child) {
|
||||
if (child instanceof Slider) {
|
||||
mSlider = (Slider) child;
|
||||
if (child instanceof SeekBar) {
|
||||
mSeekBar = (SeekBar) child;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewRemoved(View child) {
|
||||
if (child == mSlider) {
|
||||
mSlider = null;
|
||||
if (child == mSeekBar) {
|
||||
mSeekBar = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onTouchEvent(@NonNull MotionEvent event) {
|
||||
if (mSlider == null) {
|
||||
if (mSeekBar == null) {
|
||||
return super.onTouchEvent(event);
|
||||
} else {
|
||||
final float offsetX = -mSlider.getLeft();
|
||||
final float offsetY = -mSlider.getTop();
|
||||
final float offsetX = -mSeekBar.getLeft();
|
||||
final float offsetY = -mSeekBar.getTop();
|
||||
event.offsetLocation(offsetX, offsetY);
|
||||
mSlider.onTouchEvent(event);
|
||||
mSeekBar.onTouchEvent(event);
|
||||
event.offsetLocation(-offsetX, -offsetY);
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright 2016 Hippo Seven
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.hippo.ehviewer.widget;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
|
||||
import com.hippo.widget.LoadImageView;
|
||||
import com.hippo.yorozuya.MathUtils;
|
||||
|
||||
public class TileThumb extends LoadImageView {
|
||||
|
||||
private static final float MIN_ASPECT = 0.33f;
|
||||
private static final float MAX_ASPECT = 1.5f;
|
||||
private static final float DEFAULT_ASPECT = 0.67f;
|
||||
|
||||
public TileThumb(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public TileThumb(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
public TileThumb(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
}
|
||||
|
||||
public void setThumbSize(int thumbWidth, int thumbHeight) {
|
||||
float aspect;
|
||||
if (thumbWidth > 0 && thumbHeight > 0) {
|
||||
aspect = MathUtils.clamp(thumbWidth / (float) thumbHeight, MIN_ASPECT, MAX_ASPECT);
|
||||
} else {
|
||||
aspect = DEFAULT_ASPECT;
|
||||
}
|
||||
setAspect(aspect);
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,7 @@ package com.hippo.gl.view;
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.Context;
|
||||
import android.graphics.Matrix;
|
||||
import android.graphics.PixelFormat;
|
||||
import android.opengl.GLSurfaceView;
|
||||
import android.os.Build;
|
||||
import android.os.Parcelable;
|
||||
@@ -86,7 +87,7 @@ public class GLRootView extends GLSurfaceView
|
||||
private int mCompensation;
|
||||
// mCompensationMatrix maps the coordinates of touch events. It is kept sync
|
||||
// with mCompensation.
|
||||
private Matrix mCompensationMatrix = new Matrix();
|
||||
private final Matrix mCompensationMatrix = new Matrix();
|
||||
private int mDisplayRotation;
|
||||
|
||||
private int mFlags = FLAG_NEED_LAYOUT;
|
||||
@@ -119,15 +120,9 @@ public class GLRootView extends GLSurfaceView
|
||||
setBackgroundDrawable(null);
|
||||
setEGLContextClientVersion(2);
|
||||
|
||||
// do not need depth buffer
|
||||
setEGLConfigChooser(new BestConfigChooser());
|
||||
setRenderer(this);
|
||||
// setFormat is done by SurfaceView in SDK 2.3 and newer.
|
||||
//if (ApiHelper.USE_888_PIXEL_FORMAT) {
|
||||
// getHolder().setFormat(PixelFormat.RGB_888);
|
||||
//} else {
|
||||
// getHolder().setFormat(PixelFormat.RGB_565);
|
||||
//}
|
||||
getHolder().setFormat(PixelFormat.RGB_888);
|
||||
|
||||
// Uncomment this to enable gl error check.
|
||||
// setDebugFlags(DEBUG_CHECK_GL_ERROR);
|
||||
@@ -196,7 +191,7 @@ public class GLRootView extends GLSurfaceView
|
||||
}
|
||||
}
|
||||
|
||||
private Runnable mRequestRenderOnAnimationFrame = new Runnable() {
|
||||
private final Runnable mRequestRenderOnAnimationFrame = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
superRequestRender();
|
||||
@@ -229,8 +224,8 @@ public class GLRootView extends GLSurfaceView
|
||||
|
||||
int w = getWidth();
|
||||
int h = getHeight();
|
||||
int displayRotation = 0;
|
||||
int compensation = 0;
|
||||
int displayRotation;
|
||||
int compensation;
|
||||
|
||||
// Get the new orientation values
|
||||
if (mOrientationSource != null) {
|
||||
@@ -633,35 +628,6 @@ public class GLRootView extends GLSurfaceView
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
protected boolean fitSystemWindows(@NonNull Rect insets) {
|
||||
int fitPaddingLeft = insets.left;
|
||||
int fitPaddingTop = insets.top;
|
||||
int fitPaddingRight = insets.right;
|
||||
int fitPaddingBottom = insets.bottom;
|
||||
|
||||
GLView contentView = mContentView;
|
||||
if (contentView != null) {
|
||||
for (int i = 0, n = contentView.getComponentCount(); i < n; i++) {
|
||||
GLView component = contentView.getComponent(i);
|
||||
if (component instanceof FitPaddingImpl) {
|
||||
((FitPaddingImpl) component).onFitPadding(fitPaddingLeft ,fitPaddingTop,
|
||||
fitPaddingRight, fitPaddingBottom);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
insets.left = 0;
|
||||
insets.top = 0;
|
||||
insets.right = 0;
|
||||
insets.bottom = 0;
|
||||
|
||||
return super.fitSystemWindows(insets);
|
||||
}
|
||||
*/
|
||||
|
||||
private static abstract class BaseConfigChooser implements EGLConfigChooser {
|
||||
|
||||
public BaseConfigChooser(int[] configSpec) {
|
||||
@@ -719,7 +685,10 @@ public class GLRootView extends GLSurfaceView
|
||||
private final int[] mValue = new int[1];
|
||||
|
||||
public BestConfigChooser() {
|
||||
super(new int[] {EGL10.EGL_NONE});
|
||||
super(new int[] {
|
||||
EGL10.EGL_DEPTH_SIZE, 0,
|
||||
EGL10.EGL_STENCIL_SIZE, 0,
|
||||
EGL10.EGL_NONE});
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -739,17 +708,13 @@ public class GLRootView extends GLSurfaceView
|
||||
EGL10.EGL_BLUE_SIZE, 0);
|
||||
int alphaSize = findConfigAttrib(egl, display, config,
|
||||
EGL10.EGL_ALPHA_SIZE, 0);
|
||||
int depthSize = findConfigAttrib(egl, display, config,
|
||||
EGL10.EGL_DEPTH_SIZE, 0);
|
||||
int stencilSize = findConfigAttrib(egl, display, config,
|
||||
EGL10.EGL_STENCIL_SIZE, 0);
|
||||
int sampleBuffers = findConfigAttrib(egl, display, config,
|
||||
EGL10.EGL_SAMPLE_BUFFERS, 0);
|
||||
int samples = findConfigAttrib(egl, display, config,
|
||||
EGL10.EGL_SAMPLES, 0);
|
||||
|
||||
int score = redSize + greenSize + blueSize + alphaSize +
|
||||
depthSize + stencilSize + sampleBuffers + samples;
|
||||
sampleBuffers + samples;
|
||||
|
||||
if (score > maxScore) {
|
||||
maxScore = score;
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
package com.hippo.hardware;
|
||||
|
||||
import android.hardware.Sensor;
|
||||
import android.hardware.SensorEvent;
|
||||
import android.hardware.SensorEventListener;
|
||||
import android.hardware.SensorManager;
|
||||
|
||||
// http://jasonmcreynolds.com/?p=388
|
||||
public class ShakeDetector implements SensorEventListener {
|
||||
|
||||
/*
|
||||
* The gForce that is necessary to register as shake.
|
||||
* Must be greater than 1G (one earth gravity unit).
|
||||
* You can install "G-Force", by Blake La Pierre
|
||||
* from the Google Play Store and run it to see how
|
||||
* many G's it takes to register a shake
|
||||
*/
|
||||
private static final float SHAKE_THRESHOLD_GRAVITY = 2.7F;
|
||||
private static final int SHAKE_SLOP_TIME_MS = 500;
|
||||
private static final int SHAKE_COUNT_RESET_TIME_MS = 3000;
|
||||
|
||||
private OnShakeListener mListener;
|
||||
private long mShakeTimestamp;
|
||||
private int mShakeCount;
|
||||
|
||||
public void setOnShakeListener(OnShakeListener listener) {
|
||||
mListener = listener;
|
||||
}
|
||||
|
||||
public interface OnShakeListener {
|
||||
void onShake(int count);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAccuracyChanged(Sensor sensor, int accuracy) {
|
||||
// ignore
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSensorChanged(SensorEvent event) {
|
||||
|
||||
if (mListener != null) {
|
||||
float x = event.values[0];
|
||||
float y = event.values[1];
|
||||
float z = event.values[2];
|
||||
|
||||
float gX = x / SensorManager.GRAVITY_EARTH;
|
||||
float gY = y / SensorManager.GRAVITY_EARTH;
|
||||
float gZ = z / SensorManager.GRAVITY_EARTH;
|
||||
|
||||
// gForce will be close to 1 when there is no movement.
|
||||
float gForce = (float) Math.sqrt(gX * gX + gY * gY + gZ * gZ);
|
||||
|
||||
if (gForce > SHAKE_THRESHOLD_GRAVITY) {
|
||||
final long now = System.currentTimeMillis();
|
||||
// ignore shake events too close to each other (500ms)
|
||||
if (mShakeTimestamp + SHAKE_SLOP_TIME_MS > now) {
|
||||
return;
|
||||
}
|
||||
|
||||
// reset the shake count after 3 seconds of no shakes
|
||||
if (mShakeTimestamp + SHAKE_COUNT_RESET_TIME_MS < now) {
|
||||
mShakeCount = 0;
|
||||
}
|
||||
|
||||
mShakeTimestamp = now;
|
||||
mShakeCount++;
|
||||
|
||||
mListener.onShake(mShakeCount);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* 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.network;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public final class InetValidator {
|
||||
|
||||
private static final String IPV4_REGEX =
|
||||
"^(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})$";
|
||||
|
||||
private static final Pattern IPV4_PATTERN = Pattern.compile(IPV4_REGEX);
|
||||
|
||||
public static boolean isValidInet4Address(String inet4Address) {
|
||||
if (null == inet4Address) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Matcher matcher = IPV4_PATTERN.matcher(inet4Address);
|
||||
if (!matcher.find()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// verify that address subgroups are legal
|
||||
for (int i = 1; i <= 4; i++) {
|
||||
String ipSegment = matcher.group(i);
|
||||
if (ipSegment == null || ipSegment.length() == 0) {
|
||||
return false;
|
||||
}
|
||||
int iIpSegment;
|
||||
try {
|
||||
iIpSegment = Integer.parseInt(ipSegment);
|
||||
} catch(NumberFormatException e) {
|
||||
return false;
|
||||
}
|
||||
if (iIpSegment > 255) {
|
||||
return false;
|
||||
}
|
||||
if (ipSegment.length() > 1 && ipSegment.startsWith("0")) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean isValidInetPort(int inetPort) {
|
||||
return inetPort >= 0 && inetPort <= 65535;
|
||||
}
|
||||
|
||||
private InetValidator() {}
|
||||
}
|
||||
@@ -45,7 +45,7 @@ public class CookieDBStore implements CookieJar {
|
||||
: domainMatch(urlHost, cookie.domain());
|
||||
}
|
||||
|
||||
private static boolean domainMatch(String urlHost, String cookieDomain) {
|
||||
public static boolean domainMatch(String urlHost, String cookieDomain) {
|
||||
if (urlHost.equals(cookieDomain)) {
|
||||
return true; // As in 'example.com' matching 'example.com'.
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ public class MessagePreference extends DialogPreference {
|
||||
protected void onPrepareDialogBuilder(AlertDialog.Builder builder) {
|
||||
super.onPrepareDialogBuilder(builder);
|
||||
builder.setMessage(mDialogMessage);
|
||||
builder.setPositiveButton(android.R.string.ok, null);
|
||||
builder.setPositiveButton(android.R.string.ok, this);
|
||||
builder.setNegativeButton(null, null);
|
||||
}
|
||||
|
||||
|
||||
@@ -23,8 +23,8 @@ import com.hippo.yorozuya.IntIdGenerator;
|
||||
|
||||
public class SceneApplication extends Application {
|
||||
|
||||
private IntIdGenerator mIdGenerator = new IntIdGenerator();
|
||||
private SparseArray<StageActivity> mStageMap = new SparseArray<>();
|
||||
private final IntIdGenerator mIdGenerator = new IntIdGenerator();
|
||||
private final SparseArray<StageActivity> mStageMap = new SparseArray<>();
|
||||
|
||||
void registerStageActivity(StageActivity stage) {
|
||||
int id = mIdGenerator.nextId();
|
||||
|
||||
@@ -97,14 +97,18 @@ public class SceneFragment extends Fragment {
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("deprecation")
|
||||
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
|
||||
view.setTag(R.id.fragment_tag, getTag());
|
||||
view.setBackgroundColor(getContext().getResources().getColor(R.color.background_light));
|
||||
view.setBackgroundColor(getResources().getColor(R.color.background_light));
|
||||
|
||||
// Notify
|
||||
((StageActivity) getActivity()).onSceneViewCreated(this, savedInstanceState);
|
||||
FragmentActivity activity = getActivity();
|
||||
if (activity instanceof StageActivity) {
|
||||
((StageActivity) activity).onSceneViewCreated(this, savedInstanceState);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -112,14 +116,20 @@ public class SceneFragment extends Fragment {
|
||||
super.onDestroyView();
|
||||
|
||||
// Notify
|
||||
((StageActivity) getActivity()).onSceneViewDestroyed(this);
|
||||
FragmentActivity activity = getActivity();
|
||||
if (activity instanceof StageActivity) {
|
||||
((StageActivity) activity).onSceneViewDestroyed(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
|
||||
((StageActivity) getActivity()).onSceneDestroyed(this);
|
||||
FragmentActivity activity = getActivity();
|
||||
if (activity instanceof StageActivity) {
|
||||
((StageActivity) activity).onSceneDestroyed(this);
|
||||
}
|
||||
}
|
||||
|
||||
void addRequest(String requestSceneTag, int requestCode) {
|
||||
|
||||
@@ -27,7 +27,7 @@ import android.util.Log;
|
||||
import android.view.View;
|
||||
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.ui.TrackedActivity;
|
||||
import com.hippo.ehviewer.ui.EhActivity;
|
||||
import com.hippo.yorozuya.AssertUtils;
|
||||
import com.hippo.yorozuya.IntIdGenerator;
|
||||
|
||||
@@ -39,7 +39,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
public abstract class StageActivity extends TrackedActivity {
|
||||
public abstract class StageActivity extends EhActivity {
|
||||
|
||||
private static final String TAG = StageActivity.class.getSimpleName();
|
||||
|
||||
@@ -575,4 +575,18 @@ public abstract class StageActivity extends TrackedActivity {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getTopSceneClazzName() {
|
||||
int index = mSceneTagList.size() - 1;
|
||||
if (index < 0) {
|
||||
return null;
|
||||
}
|
||||
String tag = mSceneTagList.get(index);
|
||||
Fragment fragment = getSupportFragmentManager().findFragmentByTag(tag);
|
||||
if (null == fragment) {
|
||||
return null;
|
||||
}
|
||||
return fragment.getClass().getName();
|
||||
}
|
||||
}
|
||||
@@ -16,11 +16,11 @@
|
||||
|
||||
package com.hippo.text;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.text.Layout;
|
||||
import android.text.NoCopySpan;
|
||||
import android.text.Selection;
|
||||
import android.text.Spannable;
|
||||
import android.text.method.MovementMethod;
|
||||
import android.text.method.ScrollingMovementMethod;
|
||||
import android.text.style.ClickableSpan;
|
||||
import android.text.style.URLSpan;
|
||||
@@ -40,11 +40,7 @@ public class LinkMovementMethod2 extends ScrollingMovementMethod {
|
||||
private static final int UP = 2;
|
||||
private static final int DOWN = 3;
|
||||
|
||||
private final Activity mActivity;
|
||||
|
||||
public LinkMovementMethod2(Activity activity) {
|
||||
mActivity = activity;
|
||||
}
|
||||
private LinkMovementMethod2() {}
|
||||
|
||||
@Override
|
||||
public boolean canSelectArbitrarily() {
|
||||
@@ -227,7 +223,7 @@ public class LinkMovementMethod2 extends ScrollingMovementMethod {
|
||||
if (action == MotionEvent.ACTION_UP) {
|
||||
ClickableSpan span = link[0];
|
||||
if (span instanceof URLSpan) {
|
||||
UrlOpener.openUrl(mActivity, ((URLSpan) span).getURL(), true, true);
|
||||
UrlOpener.openUrl(widget.getContext(), ((URLSpan) span).getURL(), true, true);
|
||||
} else {
|
||||
span.onClick(widget);
|
||||
}
|
||||
@@ -263,5 +259,13 @@ public class LinkMovementMethod2 extends ScrollingMovementMethod {
|
||||
}
|
||||
}
|
||||
|
||||
public static MovementMethod getInstance() {
|
||||
if (sInstance == null)
|
||||
sInstance = new LinkMovementMethod2();
|
||||
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
private static LinkMovementMethod2 sInstance;
|
||||
private static final Object FROM_BELOW = new NoCopySpan.Concrete();
|
||||
}
|
||||
@@ -1,39 +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.util;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Point;
|
||||
import android.view.Display;
|
||||
import android.view.WindowManager;
|
||||
|
||||
import com.hippo.yorozuya.MathUtils;
|
||||
|
||||
public final class LayoutUtils2 {
|
||||
|
||||
private static final Point sPoint = new Point();
|
||||
|
||||
private LayoutUtils2() {}
|
||||
|
||||
public static int calculateSpanCount(Context context, int minWidth) {
|
||||
WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
|
||||
Display display = wm.getDefaultDisplay();
|
||||
display.getSize(sPoint);
|
||||
int width = sPoint.x;
|
||||
return MathUtils.clamp(width / minWidth, 1, Integer.MAX_VALUE);
|
||||
}
|
||||
}
|
||||
@@ -54,4 +54,19 @@ public class SqlUtils {
|
||||
dropTable(db, tableName);
|
||||
}
|
||||
}
|
||||
|
||||
public static String sqlEscapeString(String value) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
int length = value.length();
|
||||
for (int i = 0; i < length; i++) {
|
||||
char c = value.charAt(i);
|
||||
if (c == '\'') {
|
||||
sb.append('\'');
|
||||
}
|
||||
sb.append(c);
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
@@ -50,8 +50,6 @@ import java.util.List;
|
||||
|
||||
public class ContentLayout extends FrameLayout {
|
||||
|
||||
private static final String TAG = ContentLayout.class.getSimpleName();
|
||||
|
||||
private ProgressView mProgressView;
|
||||
private TextView mTipView;
|
||||
private ViewGroup mContentView;
|
||||
@@ -208,7 +206,7 @@ public class ContentLayout extends FrameLayout {
|
||||
/**
|
||||
* Generate task id
|
||||
*/
|
||||
private IntIdGenerator mIdGenerator = new IntIdGenerator();
|
||||
private final IntIdGenerator mIdGenerator = new IntIdGenerator();
|
||||
|
||||
/**
|
||||
* Store the page divider index
|
||||
@@ -359,6 +357,10 @@ public class ContentLayout extends FrameLayout {
|
||||
mEmptyString = str;
|
||||
}
|
||||
|
||||
public List<E> getData() {
|
||||
return mData;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws IndexOutOfBoundsException
|
||||
* if {@code location < 0 || location >= size()}
|
||||
@@ -412,36 +414,10 @@ public class ContentLayout extends FrameLayout {
|
||||
notifyItemRangeRemoved(index, 1);
|
||||
}
|
||||
|
||||
public void onGetEmptyData(int taskId) {
|
||||
if (mCurrentTaskId != taskId) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (mCurrentTaskType) {
|
||||
case TYPE_REFRESH:
|
||||
case TYPE_SOMEWHERE:
|
||||
showText(mEmptyString);
|
||||
break;
|
||||
case TYPE_NEXT_PAGE:
|
||||
case TYPE_NEXT_PAGE_KEEP_POS:
|
||||
// Last page ?
|
||||
break;
|
||||
case TYPE_PRE_PAGE:
|
||||
case TYPE_PRE_PAGE_KEEP_POS:
|
||||
case TYPE_REFRESH_PAGE:
|
||||
// TODO
|
||||
break;
|
||||
}
|
||||
|
||||
mRefreshLayout.setHeaderRefreshing(false);
|
||||
mRefreshLayout.setFooterRefreshing(false);
|
||||
}
|
||||
|
||||
public void onGetPageData(int taskId, List<E> data) {
|
||||
if (mCurrentTaskId == taskId) {
|
||||
showContent();
|
||||
|
||||
int dataSize;
|
||||
|
||||
switch (mCurrentTaskType) {
|
||||
case TYPE_REFRESH:
|
||||
mStartPage = 0;
|
||||
@@ -449,71 +425,201 @@ public class ContentLayout extends FrameLayout {
|
||||
mPageDivider.clear();
|
||||
mPageDivider.add(data.size());
|
||||
|
||||
mData.clear();
|
||||
mData.addAll(data);
|
||||
notifyDataSetChanged();
|
||||
if (data.isEmpty()) {
|
||||
mData.clear();
|
||||
notifyDataSetChanged();
|
||||
|
||||
mRecyclerView.stopScroll();
|
||||
LayoutManagerUtils.scrollToPositionWithOffset(mRecyclerView.getLayoutManager(), 0, 0);
|
||||
onScrollToPosition();
|
||||
if (true || mEndPage >= mPages) { // Not found
|
||||
// Ui change, show empty string
|
||||
mRefreshLayout.setHeaderRefreshing(false);
|
||||
mRefreshLayout.setFooterRefreshing(false);
|
||||
showEmptyString();
|
||||
} else {
|
||||
// Ui change, show progress bar
|
||||
mRefreshLayout.setHeaderRefreshing(false);
|
||||
mRefreshLayout.setFooterRefreshing(false);
|
||||
showProgressBar();
|
||||
|
||||
// Get next page
|
||||
mCurrentTaskId = mIdGenerator.nextId();
|
||||
mCurrentTaskType = TYPE_NEXT_PAGE_KEEP_POS;
|
||||
mCurrentTaskPage = mEndPage;
|
||||
getPageData(mCurrentTaskId, mCurrentTaskType, mCurrentTaskPage);
|
||||
}
|
||||
} else {
|
||||
mData.clear();
|
||||
mData.addAll(data);
|
||||
notifyDataSetChanged();
|
||||
|
||||
// Ui change, show content
|
||||
mRefreshLayout.setHeaderRefreshing(false);
|
||||
mRefreshLayout.setFooterRefreshing(false);
|
||||
showContent();
|
||||
|
||||
// RecyclerView scroll
|
||||
mRecyclerView.stopScroll();
|
||||
LayoutManagerUtils.scrollToPositionWithOffset(mRecyclerView.getLayoutManager(), 0, 0);
|
||||
onScrollToPosition();
|
||||
}
|
||||
break;
|
||||
case TYPE_PRE_PAGE:
|
||||
case TYPE_PRE_PAGE_KEEP_POS:
|
||||
mData.addAll(0, data);
|
||||
notifyItemRangeInserted(0, data.size());
|
||||
|
||||
dataSize = data.size();
|
||||
for (int i = 0, n = mPageDivider.size(); i < n; i++) {
|
||||
mPageDivider.set(i, mPageDivider.get(i) + dataSize);
|
||||
}
|
||||
mPageDivider.add(0, dataSize);
|
||||
|
||||
mStartPage--;
|
||||
// assert mStartPage >= 0
|
||||
if (mCurrentTaskType == TYPE_PRE_PAGE_KEEP_POS) {
|
||||
mRecyclerView.stopScroll();
|
||||
LayoutManagerUtils.scrollToPositionProperly(mRecyclerView.getLayoutManager(), getContext(),
|
||||
dataSize - 1, mOnScrollToPositionListener);
|
||||
|
||||
if (data.isEmpty()) {
|
||||
if (true || mStartPage <= 0) { // OK, that's all
|
||||
if (mData.isEmpty()) {
|
||||
// Ui change, show empty string
|
||||
mRefreshLayout.setHeaderRefreshing(false);
|
||||
mRefreshLayout.setFooterRefreshing(false);
|
||||
showEmptyString();
|
||||
} else {
|
||||
// Ui change, show content
|
||||
mRefreshLayout.setHeaderRefreshing(false);
|
||||
mRefreshLayout.setFooterRefreshing(false);
|
||||
showContent();
|
||||
|
||||
if (mCurrentTaskType == TYPE_PRE_PAGE) {
|
||||
// RecyclerView scroll, to top
|
||||
mRecyclerView.stopScroll();
|
||||
LayoutManagerUtils.scrollToPositionWithOffset(mRecyclerView.getLayoutManager(), 0, 0);
|
||||
onScrollToPosition();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Keep UI
|
||||
|
||||
// Get previous
|
||||
mCurrentTaskId = mIdGenerator.nextId();
|
||||
// Keep mCurrentTaskType
|
||||
mCurrentTaskPage = mStartPage - 1;
|
||||
getPageData(mCurrentTaskId, mCurrentTaskType, mCurrentTaskPage);
|
||||
}
|
||||
} else {
|
||||
mRecyclerView.stopScroll();
|
||||
LayoutManagerUtils.scrollToPositionWithOffset(mRecyclerView.getLayoutManager(), 0, 0);
|
||||
onScrollToPosition();
|
||||
mData.addAll(0, data);
|
||||
notifyItemRangeInserted(0, data.size());
|
||||
|
||||
// Ui change, show content
|
||||
mRefreshLayout.setHeaderRefreshing(false);
|
||||
mRefreshLayout.setFooterRefreshing(false);
|
||||
showContent();
|
||||
|
||||
// RecyclerView scroll
|
||||
if (mCurrentTaskType == TYPE_PRE_PAGE_KEEP_POS) {
|
||||
mRecyclerView.stopScroll();
|
||||
LayoutManagerUtils.scrollToPositionProperly(mRecyclerView.getLayoutManager(), getContext(),
|
||||
dataSize - 1, mOnScrollToPositionListener);
|
||||
} else {
|
||||
mRecyclerView.stopScroll();
|
||||
LayoutManagerUtils.scrollToPositionWithOffset(mRecyclerView.getLayoutManager(), 0, 0);
|
||||
onScrollToPosition();
|
||||
}
|
||||
}
|
||||
break;
|
||||
case TYPE_NEXT_PAGE:
|
||||
case TYPE_NEXT_PAGE_KEEP_POS:
|
||||
dataSize = data.size();
|
||||
int oldDataSize = mData.size();
|
||||
mData.addAll(data);
|
||||
notifyItemRangeInserted(oldDataSize, dataSize);
|
||||
|
||||
mPageDivider.add(oldDataSize + dataSize);
|
||||
|
||||
mEndPage++;
|
||||
if (mCurrentTaskType == TYPE_NEXT_PAGE_KEEP_POS) {
|
||||
mRecyclerView.stopScroll();
|
||||
mRecyclerView.smoothScrollBy(0, mNextPageScrollSize);
|
||||
onScrollToPosition();
|
||||
|
||||
if (data.isEmpty()) {
|
||||
if (true || mEndPage >= mPages) { // OK, that's all
|
||||
if (mData.isEmpty()) {
|
||||
// Ui change, show empty string
|
||||
mRefreshLayout.setHeaderRefreshing(false);
|
||||
mRefreshLayout.setFooterRefreshing(false);
|
||||
showEmptyString();
|
||||
} else {
|
||||
// Ui change, show content
|
||||
mRefreshLayout.setHeaderRefreshing(false);
|
||||
mRefreshLayout.setFooterRefreshing(false);
|
||||
showContent();
|
||||
|
||||
if (mCurrentTaskType == TYPE_NEXT_PAGE) {
|
||||
// RecyclerView scroll
|
||||
mRecyclerView.stopScroll();
|
||||
LayoutManagerUtils.scrollToPositionWithOffset(mRecyclerView.getLayoutManager(), oldDataSize, 0);
|
||||
onScrollToPosition();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Keep UI
|
||||
|
||||
// Get next page
|
||||
mCurrentTaskId = mIdGenerator.nextId();
|
||||
// Keep mCurrentTaskType
|
||||
mCurrentTaskPage = mEndPage;
|
||||
getPageData(mCurrentTaskId, mCurrentTaskType, mCurrentTaskPage);
|
||||
}
|
||||
} else {
|
||||
mRecyclerView.stopScroll();
|
||||
LayoutManagerUtils.scrollToPositionWithOffset(mRecyclerView.getLayoutManager(), oldDataSize, 0);
|
||||
onScrollToPosition();
|
||||
mData.addAll(data);
|
||||
notifyItemRangeInserted(oldDataSize, dataSize);
|
||||
|
||||
// Ui change, show content
|
||||
mRefreshLayout.setHeaderRefreshing(false);
|
||||
mRefreshLayout.setFooterRefreshing(false);
|
||||
showContent();
|
||||
|
||||
if (mCurrentTaskType == TYPE_NEXT_PAGE_KEEP_POS) {
|
||||
mRecyclerView.stopScroll();
|
||||
mRecyclerView.smoothScrollBy(0, mNextPageScrollSize);
|
||||
onScrollToPosition();
|
||||
} else {
|
||||
mRecyclerView.stopScroll();
|
||||
LayoutManagerUtils.scrollToPositionWithOffset(mRecyclerView.getLayoutManager(), oldDataSize, 0);
|
||||
onScrollToPosition();
|
||||
}
|
||||
}
|
||||
break;
|
||||
case TYPE_SOMEWHERE:
|
||||
mData.clear();
|
||||
mData.addAll(data);
|
||||
notifyDataSetChanged();
|
||||
|
||||
mStartPage = mCurrentTaskPage;
|
||||
mEndPage = mCurrentTaskPage + 1;
|
||||
|
||||
mPageDivider.clear();
|
||||
mPageDivider.add(data.size());
|
||||
|
||||
mRecyclerView.stopScroll();
|
||||
LayoutManagerUtils.scrollToPositionWithOffset(mRecyclerView.getLayoutManager(), 0, 0);
|
||||
onScrollToPosition();
|
||||
if (data.isEmpty()) {
|
||||
mData.clear();
|
||||
notifyDataSetChanged();
|
||||
|
||||
if (true || mEndPage >= mPages) { // Not found
|
||||
// Ui change, show empty string
|
||||
mRefreshLayout.setHeaderRefreshing(false);
|
||||
mRefreshLayout.setFooterRefreshing(false);
|
||||
showEmptyString();
|
||||
} else {
|
||||
// Ui change, show progress bar
|
||||
mRefreshLayout.setHeaderRefreshing(false);
|
||||
mRefreshLayout.setFooterRefreshing(false);
|
||||
showProgressBar();
|
||||
|
||||
// Get next page
|
||||
mCurrentTaskId = mIdGenerator.nextId();
|
||||
mCurrentTaskType = TYPE_NEXT_PAGE_KEEP_POS;
|
||||
mCurrentTaskPage = mEndPage;
|
||||
getPageData(mCurrentTaskId, mCurrentTaskType, mCurrentTaskPage);
|
||||
}
|
||||
} else {
|
||||
mData.clear();
|
||||
mData.addAll(data);
|
||||
notifyDataSetChanged();
|
||||
|
||||
// Ui change, show content
|
||||
mRefreshLayout.setHeaderRefreshing(false);
|
||||
mRefreshLayout.setFooterRefreshing(false);
|
||||
showContent();
|
||||
|
||||
// RecyclerView scroll
|
||||
mRecyclerView.stopScroll();
|
||||
LayoutManagerUtils.scrollToPositionWithOffset(mRecyclerView.getLayoutManager(), 0, 0);
|
||||
onScrollToPosition();
|
||||
}
|
||||
break;
|
||||
case TYPE_REFRESH_PAGE:
|
||||
if (mCurrentTaskPage < mStartPage || mCurrentTaskPage >= mEndPage) {
|
||||
@@ -534,17 +640,27 @@ public class ContentLayout extends FrameLayout {
|
||||
mPageDivider.set(i, mPageDivider.get(i) - oldIndexEnd + newIndexEnd);
|
||||
}
|
||||
|
||||
if (newIndexEnd > oldIndexEnd && newIndexEnd > 0) {
|
||||
mRecyclerView.stopScroll();
|
||||
LayoutManagerUtils.scrollToPositionWithOffset(mRecyclerView.getLayoutManager(), newIndexEnd - 1, 0);
|
||||
onScrollToPosition();
|
||||
if (mData.isEmpty()) {
|
||||
// Ui change, show empty string
|
||||
mRefreshLayout.setHeaderRefreshing(false);
|
||||
mRefreshLayout.setFooterRefreshing(false);
|
||||
showEmptyString();
|
||||
} else {
|
||||
// Ui change, show content
|
||||
mRefreshLayout.setHeaderRefreshing(false);
|
||||
mRefreshLayout.setFooterRefreshing(false);
|
||||
showContent();
|
||||
|
||||
// RecyclerView scroll
|
||||
if (newIndexEnd > oldIndexEnd && newIndexEnd > 0) {
|
||||
mRecyclerView.stopScroll();
|
||||
LayoutManagerUtils.scrollToPositionWithOffset(mRecyclerView.getLayoutManager(), newIndexEnd - 1, 0);
|
||||
onScrollToPosition();
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
mRefreshLayout.setHeaderRefreshing(false);
|
||||
mRefreshLayout.setFooterRefreshing(false);
|
||||
}
|
||||
|
||||
public void onGetException(int taskId, Exception e) {
|
||||
|
||||
@@ -0,0 +1,96 @@
|
||||
/*
|
||||
* 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.widget;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
|
||||
public class SimpleGridAutoSpanLayout extends SimpleGridLayout {
|
||||
|
||||
public static final int STRATEGY_MIN_SIZE = 0;
|
||||
public static final int STRATEGY_SUITABLE_SIZE = 1;
|
||||
|
||||
private int mColumnSize = -1;
|
||||
private boolean mColumnSizeChanged = true;
|
||||
private int mStrategy;
|
||||
|
||||
public SimpleGridAutoSpanLayout(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public SimpleGridAutoSpanLayout(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
public SimpleGridAutoSpanLayout(Context context, AttributeSet attrs, int defStyle) {
|
||||
super(context, attrs, defStyle);
|
||||
}
|
||||
|
||||
public void setColumnSize(int columnSize) {
|
||||
if (columnSize == mColumnSize) {
|
||||
return;
|
||||
}
|
||||
mColumnSize = columnSize;
|
||||
mColumnSizeChanged = true;
|
||||
}
|
||||
|
||||
public void setStrategy(int strategy) {
|
||||
if (strategy == mStrategy) {
|
||||
return;
|
||||
}
|
||||
mStrategy = strategy;
|
||||
mColumnSizeChanged = true;
|
||||
}
|
||||
|
||||
public static int getSpanCountForSuitableSize(int total, int single) {
|
||||
int span = total / single;
|
||||
if (span <= 0) {
|
||||
return 1;
|
||||
}
|
||||
int span2 = span + 1;
|
||||
float deviation = Math.abs(1 - (total / span / (float) single));
|
||||
float deviation2 = Math.abs(1 - (total / span2 / (float) single));
|
||||
return deviation < deviation2 ? span : span2;
|
||||
}
|
||||
|
||||
public static int getSpanCountForMinSize(int total, int single) {
|
||||
return Math.max(1, total / single);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||
int widthMode = MeasureSpec.getMode(widthMeasureSpec);
|
||||
int widthSize = MeasureSpec.getSize(widthMeasureSpec);
|
||||
|
||||
if (mColumnSizeChanged && mColumnSize > 0 && widthMode == MeasureSpec.EXACTLY) {
|
||||
int totalSpace = widthSize - getPaddingRight() - getPaddingLeft();
|
||||
int spanCount;
|
||||
switch (mStrategy) {
|
||||
default:
|
||||
case STRATEGY_MIN_SIZE:
|
||||
spanCount = getSpanCountForMinSize(totalSpace, mColumnSize);
|
||||
break;
|
||||
case STRATEGY_SUITABLE_SIZE:
|
||||
spanCount = getSpanCountForSuitableSize(totalSpace, mColumnSize);
|
||||
break;
|
||||
}
|
||||
setColumnCount(spanCount);
|
||||
mColumnSizeChanged = false;
|
||||
}
|
||||
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* Copyright (C) 2007 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.hippo.widget.lockpattern;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Utilities for the lock pattern and its settings.
|
||||
*/
|
||||
public class LockPatternUtils {
|
||||
|
||||
/**
|
||||
* Deserialize a pattern.
|
||||
* @param string The pattern serialized with {@link #patternToString}
|
||||
* @return The pattern.
|
||||
*/
|
||||
public static List<LockPatternView.Cell> stringToPattern(String string) {
|
||||
List<LockPatternView.Cell> result = new ArrayList<>();
|
||||
|
||||
final byte[] bytes = string.getBytes();
|
||||
for (int i = 0; i < bytes.length; i++) {
|
||||
byte b = bytes[i];
|
||||
result.add(LockPatternView.Cell.of(b / 3, b % 3));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialize a pattern.
|
||||
* @param pattern The pattern.
|
||||
* @return The pattern in string form.
|
||||
*/
|
||||
public static String patternToString(List<LockPatternView.Cell> pattern) {
|
||||
if (pattern == null) {
|
||||
return "";
|
||||
}
|
||||
final int patternSize = pattern.size();
|
||||
|
||||
byte[] res = new byte[patternSize];
|
||||
for (int i = 0; i < patternSize; i++) {
|
||||
LockPatternView.Cell cell = pattern.get(i);
|
||||
res[i] = (byte) (cell.getRow() * 3 + cell.getColumn());
|
||||
}
|
||||
return new String(res);
|
||||
}
|
||||
|
||||
public static boolean isPatternVaild(String pattern) {
|
||||
byte[] bytes = pattern.getBytes();
|
||||
if (bytes.length <= 9 && bytes.length >= 2) {
|
||||
for (byte b : bytes) {
|
||||
if (b >= 9 || b < 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,126 @@
|
||||
/*
|
||||
* 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.widget.recyclerview;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.v7.widget.GridLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class AutoGridLayoutManager extends GridLayoutManager {
|
||||
|
||||
public static final int STRATEGY_MIN_SIZE = 0;
|
||||
public static final int STRATEGY_SUITABLE_SIZE = 1;
|
||||
|
||||
private int mColumnSize = -1;
|
||||
private boolean mColumnSizeChanged = true;
|
||||
private int mStrategy;
|
||||
|
||||
private List<OnUpdateSpanCountListener> mListeners;
|
||||
|
||||
public AutoGridLayoutManager(Context context, int columnSize) {
|
||||
super(context, 1);
|
||||
setColumnSize(columnSize);
|
||||
}
|
||||
|
||||
public AutoGridLayoutManager(Context context, int columnSize, int orientation, boolean reverseLayout) {
|
||||
super(context, 1, orientation, reverseLayout);
|
||||
setColumnSize(columnSize);
|
||||
}
|
||||
|
||||
public void setColumnSize(int columnSize) {
|
||||
if (columnSize == mColumnSize) {
|
||||
return;
|
||||
}
|
||||
mColumnSize = columnSize;
|
||||
mColumnSizeChanged = true;
|
||||
}
|
||||
|
||||
public void setStrategy(int strategy) {
|
||||
if (strategy == mStrategy) {
|
||||
return;
|
||||
}
|
||||
mStrategy = strategy;
|
||||
mColumnSizeChanged = true;
|
||||
}
|
||||
|
||||
public static int getSpanCountForSuitableSize(int total, int single) {
|
||||
int span = total / single;
|
||||
if (span <= 0) {
|
||||
return 1;
|
||||
}
|
||||
int span2 = span + 1;
|
||||
float deviation = Math.abs(1 - (total / span / (float) single));
|
||||
float deviation2 = Math.abs(1 - (total / span2 / (float) single));
|
||||
return deviation < deviation2 ? span : span2;
|
||||
}
|
||||
|
||||
public static int getSpanCountForMinSize(int total, int single) {
|
||||
return Math.max(1, total / single);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLayoutChildren(RecyclerView.Recycler recycler, RecyclerView.State state) {
|
||||
if (mColumnSizeChanged && mColumnSize > 0) {
|
||||
int totalSpace;
|
||||
if (getOrientation() == VERTICAL) {
|
||||
totalSpace = getWidth() - getPaddingRight() - getPaddingLeft();
|
||||
} else {
|
||||
totalSpace = getHeight() - getPaddingTop() - getPaddingBottom();
|
||||
}
|
||||
|
||||
int spanCount;
|
||||
switch (mStrategy) {
|
||||
default:
|
||||
case STRATEGY_MIN_SIZE:
|
||||
spanCount = getSpanCountForMinSize(totalSpace, mColumnSize);
|
||||
break;
|
||||
case STRATEGY_SUITABLE_SIZE:
|
||||
spanCount = getSpanCountForSuitableSize(totalSpace, mColumnSize);
|
||||
break;
|
||||
}
|
||||
setSpanCount(spanCount);
|
||||
mColumnSizeChanged = false;
|
||||
|
||||
if (null != mListeners) {
|
||||
for (int i = 0, n = mListeners.size(); i < n; i++) {
|
||||
mListeners.get(i).onUpdateSpanCount(spanCount);
|
||||
}
|
||||
}
|
||||
}
|
||||
super.onLayoutChildren(recycler, state);
|
||||
}
|
||||
|
||||
public void addOnUpdateSpanCountListener(OnUpdateSpanCountListener listener) {
|
||||
if (null == mListeners) {
|
||||
mListeners = new ArrayList<>();
|
||||
}
|
||||
mListeners.add(listener);
|
||||
}
|
||||
|
||||
public void removeOnUpdateSpanCountListener(OnUpdateSpanCountListener listener) {
|
||||
if (null != mListeners) {
|
||||
mListeners.remove(listener);
|
||||
}
|
||||
}
|
||||
|
||||
public interface OnUpdateSpanCountListener {
|
||||
void onUpdateSpanCount(int spanCount);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
/*
|
||||
* 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.widget.recyclerview;
|
||||
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.support.v7.widget.StaggeredGridLayoutManager;
|
||||
import android.view.View;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class AutoStaggeredGridLayoutManager extends StaggeredGridLayoutManager {
|
||||
|
||||
public static final int STRATEGY_MIN_SIZE = 0;
|
||||
public static final int STRATEGY_SUITABLE_SIZE = 1;
|
||||
|
||||
private int mColumnSize = -1;
|
||||
private boolean mColumnSizeChanged = true;
|
||||
private int mStrategy;
|
||||
|
||||
private List<OnUpdateSpanCountListener> mListeners;
|
||||
|
||||
public AutoStaggeredGridLayoutManager(int columnSize, int orientation) {
|
||||
super(1, orientation);
|
||||
setColumnSize(columnSize);
|
||||
}
|
||||
|
||||
public void setColumnSize(int columnSize) {
|
||||
if (columnSize == mColumnSize) {
|
||||
return;
|
||||
}
|
||||
mColumnSize = columnSize;
|
||||
mColumnSizeChanged = true;
|
||||
}
|
||||
|
||||
public void setStrategy(int strategy) {
|
||||
if (strategy == mStrategy) {
|
||||
return;
|
||||
}
|
||||
mStrategy = strategy;
|
||||
mColumnSizeChanged = true;
|
||||
}
|
||||
|
||||
public static int getSpanCountForSuitableSize(int total, int single) {
|
||||
int span = total / single;
|
||||
if (span <= 0) {
|
||||
return 1;
|
||||
}
|
||||
int span2 = span + 1;
|
||||
float deviation = Math.abs(1 - (total / span / (float) single));
|
||||
float deviation2 = Math.abs(1 - (total / span2 / (float) single));
|
||||
return deviation < deviation2 ? span : span2;
|
||||
}
|
||||
|
||||
public static int getSpanCountForMinSize(int total, int single) {
|
||||
return Math.max(1, total / single);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMeasure(RecyclerView.Recycler recycler, RecyclerView.State state, int widthSpec, int heightSpec) {
|
||||
if (mColumnSizeChanged && mColumnSize > 0) {
|
||||
int totalSpace;
|
||||
if (getOrientation() == VERTICAL) {
|
||||
if (View.MeasureSpec.EXACTLY != View.MeasureSpec.getMode(widthSpec)) {
|
||||
throw new IllegalStateException("RecyclerView need a fixed width for AutoStaggeredGridLayoutManager");
|
||||
}
|
||||
totalSpace = View.MeasureSpec.getSize(widthSpec) - getPaddingRight() - getPaddingLeft();
|
||||
} else {
|
||||
if (View.MeasureSpec.EXACTLY != View.MeasureSpec.getMode(heightSpec)) {
|
||||
throw new IllegalStateException("RecyclerView need a fixed height for AutoStaggeredGridLayoutManager");
|
||||
}
|
||||
totalSpace = View.MeasureSpec.getSize(heightSpec) - getPaddingTop() - getPaddingBottom();
|
||||
}
|
||||
|
||||
int spanCount;
|
||||
switch (mStrategy) {
|
||||
default:
|
||||
case STRATEGY_MIN_SIZE:
|
||||
spanCount = getSpanCountForMinSize(totalSpace, mColumnSize);
|
||||
break;
|
||||
case STRATEGY_SUITABLE_SIZE:
|
||||
spanCount = getSpanCountForSuitableSize(totalSpace, mColumnSize);
|
||||
break;
|
||||
}
|
||||
setSpanCount(spanCount);
|
||||
mColumnSizeChanged = false;
|
||||
|
||||
if (null != mListeners) {
|
||||
for (int i = 0, n = mListeners.size(); i < n; i++) {
|
||||
mListeners.get(i).onUpdateSpanCount(spanCount);
|
||||
}
|
||||
}
|
||||
}
|
||||
super.onMeasure(recycler, state, widthSpec, heightSpec);
|
||||
}
|
||||
|
||||
public void addOnUpdateSpanCountListener(OnUpdateSpanCountListener listener) {
|
||||
if (null == mListeners) {
|
||||
mListeners = new ArrayList<>();
|
||||
}
|
||||
mListeners.add(listener);
|
||||
}
|
||||
|
||||
public void removeOnUpdateSpanCountListener(OnUpdateSpanCountListener listener) {
|
||||
if (null != mListeners) {
|
||||
mListeners.remove(listener);
|
||||
}
|
||||
}
|
||||
|
||||
public interface OnUpdateSpanCountListener {
|
||||
void onUpdateSpanCount(int spanCount);
|
||||
}
|
||||
}
|
||||
@@ -19,7 +19,6 @@ include $(CLEAR_VARS)
|
||||
LOCAL_MODULE := gif
|
||||
LOCAL_SRC_FILES := \
|
||||
dgif_lib.c \
|
||||
egif_lib.c \
|
||||
gif_hash.c \
|
||||
gifalloc.c \
|
||||
openbsd-reallocarray.c
|
||||
|
||||
@@ -97,6 +97,9 @@ DGifOpenFileHandle(int FileHandle, int *Error)
|
||||
free((char *)GifFile);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*@i1@*/memset(Private, '\0', sizeof(GifFilePrivateType));
|
||||
|
||||
#ifdef _WIN32
|
||||
_setmode(FileHandle, O_BINARY); /* Make sure it is in binary mode. */
|
||||
#endif /* _WIN32 */
|
||||
@@ -179,6 +182,7 @@ DGifOpen(void *userData, InputFunc readFunc, int *Error)
|
||||
free((char *)GifFile);
|
||||
return NULL;
|
||||
}
|
||||
/*@i1@*/memset(Private, '\0', sizeof(GifFilePrivateType));
|
||||
|
||||
GifFile->Private = (void *)Private;
|
||||
Private->FileHandle = 0;
|
||||
@@ -764,7 +768,7 @@ DGifSetupDecompress(GifFileType *GifFile)
|
||||
BitsPerPixel = CodeSize;
|
||||
|
||||
/* this can only happen on a severely malformed GIF */
|
||||
if (BitsPerPixel > 8 || Private->RunningBits > 32) {
|
||||
if (BitsPerPixel > 8) {
|
||||
GifFile->Error = D_GIF_ERR_READ_FAILED; /* somewhat bogus error code */
|
||||
return GIF_ERROR; /* Failed to read Code size. */
|
||||
}
|
||||
@@ -1229,19 +1233,19 @@ DGifGlance(GifFileType *GifFile)
|
||||
|
||||
if (sp->ImageDesc.Interlace) {
|
||||
int i, j;
|
||||
/*
|
||||
* The way an interlaced image should be read -
|
||||
/*
|
||||
* The way an interlaced image should be read -
|
||||
* offsets and jumps...
|
||||
*/
|
||||
int InterlacedOffset[] = { 0, 4, 2, 1 };
|
||||
int InterlacedJumps[] = { 8, 8, 4, 2 };
|
||||
/* Need to perform 4 passes on the image */
|
||||
for (i = 0; i < 4; i++)
|
||||
for (j = InterlacedOffset[i];
|
||||
for (j = InterlacedOffset[i];
|
||||
j < sp->ImageDesc.Height;
|
||||
j += InterlacedJumps[i]) {
|
||||
if (DGifGetLine(GifFile,
|
||||
sp->RasterBits+j*sp->ImageDesc.Width,
|
||||
if (DGifGetLine(GifFile,
|
||||
sp->RasterBits+j*sp->ImageDesc.Width,
|
||||
sp->ImageDesc.Width) == GIF_ERROR)
|
||||
return GIF_ERROR;
|
||||
}
|
||||
@@ -1266,7 +1270,7 @@ DGifGlance(GifFileType *GifFile)
|
||||
/* Create an extension block with our data */
|
||||
if (ExtData != NULL) {
|
||||
if (GifAddExtensionBlock(&GifFile->ExtensionBlockCount,
|
||||
&GifFile->ExtensionBlocks,
|
||||
&GifFile->ExtensionBlocks,
|
||||
ExtFunction, ExtData[0], &ExtData[1])
|
||||
== GIF_ERROR)
|
||||
return (GIF_ERROR);
|
||||
@@ -1278,7 +1282,7 @@ DGifGlance(GifFileType *GifFile)
|
||||
if (ExtData != NULL)
|
||||
if (GifAddExtensionBlock(&GifFile->ExtensionBlockCount,
|
||||
&GifFile->ExtensionBlocks,
|
||||
CONTINUE_EXT_FUNC_CODE,
|
||||
CONTINUE_EXT_FUNC_CODE,
|
||||
ExtData[0], &ExtData[1]) == GIF_ERROR)
|
||||
return (GIF_ERROR);
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -13,7 +13,7 @@ extern "C" {
|
||||
|
||||
#define GIFLIB_MAJOR 5
|
||||
#define GIFLIB_MINOR 1
|
||||
#define GIFLIB_RELEASE 2
|
||||
#define GIFLIB_RELEASE 3
|
||||
|
||||
#define GIF_ERROR 0
|
||||
#define GIF_OK 1
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
~ 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.
|
||||
-->
|
||||
|
||||
<vector
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:height="120dp"
|
||||
android:width="120dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
|
||||
<path
|
||||
android:fillColor="@color/big_icon"
|
||||
android:pathData="@string/pd_big_filter"/>
|
||||
|
||||
</vector>
|
||||
@@ -0,0 +1,29 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
~ 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.
|
||||
-->
|
||||
|
||||
<vector
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:height="24dp"
|
||||
android:width="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
|
||||
<path
|
||||
android:fillColor="@color/primary_drawable_dark"
|
||||
android:pathData="@string/pd_clear_all"/>
|
||||
|
||||
</vector>
|
||||
@@ -0,0 +1,29 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
~ 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.
|
||||
-->
|
||||
|
||||
<vector
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:height="24dp"
|
||||
android:width="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
|
||||
<path
|
||||
android:fillColor="@color/primary_drawable_light"
|
||||
android:pathData="@string/pd_delete"/>
|
||||
|
||||
</vector>
|
||||
@@ -0,0 +1,29 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
~ 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.
|
||||
-->
|
||||
|
||||
<vector
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:height="24dp"
|
||||
android:width="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
|
||||
<path
|
||||
android:fillColor="@color/primary_drawable_dark"
|
||||
android:pathData="@string/pd_info_outline"/>
|
||||
|
||||
</vector>
|
||||
@@ -0,0 +1,29 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
~ 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.
|
||||
-->
|
||||
|
||||
<vector
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="48dp"
|
||||
android:height="48dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
|
||||
<path
|
||||
android:fillColor="?attr/colorPrimary"
|
||||
android:pathData="@string/pd_similar"/>
|
||||
|
||||
</vector>
|
||||
@@ -0,0 +1,86 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
~ 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.
|
||||
-->
|
||||
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
|
||||
android:text="@string/set_pattern_protection_tip"
|
||||
android:padding="@dimen/keyline_margin"
|
||||
android:gravity="center"/>
|
||||
|
||||
<Space
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1"/>
|
||||
|
||||
<android.support.v7.widget.ButtonBarLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/buttonPanel"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:paddingLeft="12dp"
|
||||
android:paddingRight="12dp"
|
||||
android:paddingTop="4dp"
|
||||
android:paddingBottom="4dp"
|
||||
android:gravity="bottom"
|
||||
style="?attr/buttonBarStyle">
|
||||
|
||||
<Button
|
||||
android:id="@+id/cancel"
|
||||
style="?attr/buttonBarNegativeButtonStyle"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="@android:string/cancel"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/set"
|
||||
style="?attr/buttonBarPositiveButtonStyle"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="@string/set"/>
|
||||
|
||||
</android.support.v7.widget.ButtonBarLayout>
|
||||
</LinearLayout>
|
||||
|
||||
<FrameLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1">
|
||||
|
||||
<com.hippo.widget.lockpattern.LockPatternView
|
||||
android:id="@+id/pattern_view"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"/>
|
||||
|
||||
</FrameLayout>
|
||||
</LinearLayout>
|
||||
@@ -0,0 +1,39 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
~ 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.
|
||||
-->
|
||||
|
||||
<FrameLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<com.hippo.easyrecyclerview.EasyRecyclerView
|
||||
android:id="@+id/recycler_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:padding="@dimen/keyline_margin"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tip"
|
||||
android:layout_width="228dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:gravity="center_horizontal"
|
||||
android:drawablePadding="16dp"
|
||||
android:text="@string/no_filter"
|
||||
style="@style/TextAppearance.AppCompat.Medium"/>
|
||||
|
||||
</FrameLayout>
|
||||
@@ -15,8 +15,11 @@
|
||||
~ limitations under the License.
|
||||
-->
|
||||
|
||||
<merge
|
||||
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<FrameLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/main"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<com.hippo.gl.view.GLRootView
|
||||
android:id="@+id/gl_root_view"
|
||||
@@ -44,8 +47,8 @@
|
||||
app:color="@color/secondary_text_dark"
|
||||
app:warningColor="@color/red_500"/>
|
||||
|
||||
<com.hippo.ehviewer.widget.SliderPanel
|
||||
android:id="@+id/slider_panel"
|
||||
<com.hippo.ehviewer.widget.SeekBarPanel
|
||||
android:id="@+id/seek_bar_panel"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="bottom"
|
||||
@@ -62,9 +65,8 @@
|
||||
android:layout_gravity="center_vertical"
|
||||
android:gravity="center_horizontal"/>
|
||||
|
||||
<com.hippo.widget.Slider
|
||||
android:id="@+id/slider"
|
||||
style="@style/Slider.Dark"
|
||||
<com.hippo.ehviewer.widget.ReversibleSeekBar
|
||||
android:id="@+id/seek_bar"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="48dp"
|
||||
android:layout_weight="1"
|
||||
@@ -77,5 +79,5 @@
|
||||
android:layout_gravity="center_vertical"
|
||||
android:gravity="center_horizontal"/>
|
||||
|
||||
</com.hippo.ehviewer.widget.SliderPanel>
|
||||
</merge>
|
||||
</com.hippo.ehviewer.widget.SeekBarPanel>
|
||||
</FrameLayout>
|
||||
@@ -0,0 +1,84 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
~ 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.
|
||||
-->
|
||||
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
|
||||
android:text="@string/set_pattern_protection_tip"
|
||||
android:padding="@dimen/keyline_margin"
|
||||
android:gravity="center"/>
|
||||
|
||||
<FrameLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1">
|
||||
|
||||
<com.hippo.widget.MaxSizeContainer
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:layout_margin="32dp"
|
||||
app:maxWidth="320dp"
|
||||
app:maxHeight="320dp">
|
||||
|
||||
<com.hippo.widget.lockpattern.LockPatternView
|
||||
android:id="@+id/pattern_view"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"/>
|
||||
|
||||
</com.hippo.widget.MaxSizeContainer>
|
||||
</FrameLayout>
|
||||
|
||||
<android.support.v7.widget.ButtonBarLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/buttonPanel"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:paddingLeft="12dp"
|
||||
android:paddingRight="12dp"
|
||||
android:paddingTop="4dp"
|
||||
android:paddingBottom="4dp"
|
||||
android:gravity="bottom"
|
||||
style="?attr/buttonBarStyle">
|
||||
|
||||
<Button
|
||||
android:id="@+id/cancel"
|
||||
style="?attr/buttonBarNegativeButtonStyle"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="@android:string/cancel"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/set"
|
||||
style="?attr/buttonBarPositiveButtonStyle"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="@string/set"/>
|
||||
|
||||
</android.support.v7.widget.ButtonBarLayout>
|
||||
</LinearLayout>
|
||||
@@ -0,0 +1,51 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
~ 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.
|
||||
-->
|
||||
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:paddingLeft="?attr/dialogPreferredPadding"
|
||||
android:paddingTop="@dimen/abc_dialog_padding_top_material"
|
||||
android:paddingRight="?attr/dialogPreferredPadding">
|
||||
|
||||
<com.hippo.widget.CuteSpinner
|
||||
android:id="@+id/spinner"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:entries="@array/filter_entries"/>
|
||||
|
||||
<android.support.design.widget.TextInputLayout
|
||||
android:id="@+id/text_input_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:layout_marginTop="16dp">
|
||||
|
||||
<android.support.design.widget.TextInputEditText
|
||||
android:id="@+id/edit_text"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/filter_text"
|
||||
android:imeOptions="actionDone"
|
||||
android:inputType="text"
|
||||
android:maxLines="1"
|
||||
android:singleLine="true"/>
|
||||
|
||||
</android.support.design.widget.TextInputLayout>
|
||||
</LinearLayout>
|
||||
Loaded 100 of 127 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user