diff --git a/bin/EhViewer.apk b/bin/EhViewer.apk index 1af65d97d..65f7847b1 100644 Binary files a/bin/EhViewer.apk and b/bin/EhViewer.apk differ diff --git a/bin/classes.dex b/bin/classes.dex index 418bf3fee..49b38a792 100644 Binary files a/bin/classes.dex and b/bin/classes.dex differ diff --git a/bin/resources.ap_ b/bin/resources.ap_ index e2af59e8f..603aa7314 100644 Binary files a/bin/resources.ap_ and b/bin/resources.ap_ differ diff --git a/res/raw/change_log b/res/raw/change_log index 7e6a1d948..9135cbd33 100644 --- a/res/raw/change_log +++ b/res/raw/change_log @@ -1,6 +1,8 @@ -Version 0.3.4 (2014-03-23) +Version 0.3.4 (2014-03-28) * 完善用于显示预览图的控件 * 显示漫画标签组名 +* 自动更新改为每日检查 +* 修正其他问题 Version 0.3.3 (2014-03-23) * 测试自动更新 diff --git a/src/com/hippo/ehviewer/UpdateHelper.java b/src/com/hippo/ehviewer/UpdateHelper.java index 33a70dabd..afed1c5f0 100644 --- a/src/com/hippo/ehviewer/UpdateHelper.java +++ b/src/com/hippo/ehviewer/UpdateHelper.java @@ -17,6 +17,7 @@ import com.hippo.ehviewer.dialog.DialogBuilder; import com.hippo.ehviewer.network.Downloader; import com.hippo.ehviewer.util.Config; import com.hippo.ehviewer.util.EhClient; +import com.hippo.ehviewer.util.Util; import com.hippo.ehviewer.view.AlertButton; public class UpdateHelper { @@ -29,10 +30,16 @@ public class UpdateHelper { mActivity = activity; } + public void autoCheckUpdate() { + if (Config.getUpdateDate() < Util.getDate()) + checkUpdate(); + } + public void checkUpdate() { EhClient.checkUpdate(new EhClient.OnCheckUpdateListener() { @Override public void onSuccess(String pageContext) { + Config.setUpdateDate(); String[] items = pageContext.split("\n"); if (items.length > 3) { diff --git a/src/com/hippo/ehviewer/activity/MangaListActivity.java b/src/com/hippo/ehviewer/activity/MangaListActivity.java index df1caa922..8af9a1ad1 100644 --- a/src/com/hippo/ehviewer/activity/MangaListActivity.java +++ b/src/com/hippo/ehviewer/activity/MangaListActivity.java @@ -1409,7 +1409,7 @@ public class MangaListActivity extends Activity { } private void checkUpdate() { - new UpdateHelper(this).checkUpdate(); + new UpdateHelper(this).autoCheckUpdate(); } private void checkLogin(boolean force) { diff --git a/src/com/hippo/ehviewer/util/Config.java b/src/com/hippo/ehviewer/util/Config.java index 5ffa749c2..df7c8724e 100644 --- a/src/com/hippo/ehviewer/util/Config.java +++ b/src/com/hippo/ehviewer/util/Config.java @@ -1,218 +1,228 @@ -package com.hippo.ehviewer.util; - -import java.util.HashSet; -import java.util.Set; - -import com.hippo.ehviewer.view.MangaImage; - -import android.app.Activity; -import android.content.Context; -import android.content.SharedPreferences; -import android.content.SharedPreferences.Editor; -import android.content.pm.ActivityInfo; -import android.os.Environment; -import android.preference.PreferenceManager; - -public class Config { - private static final String TAG = "Config"; - - private static final String KEY_ALLOWED = "allowed"; - private static final String KEY_FIRST = "first_time"; - private static final String KEY_LOGIN = "login"; - private static final String KEY_IS_EXHENTAI = "is_exhentai"; - - private static final String CP_CACHE = "preference_cp_cache"; - private static final String CP_CACHE_DEFAULT = "25"; - private static final String PAGE_CACHE = "preference_page_cache"; - private static final String PAGE_CACHE_DEFAULT = "256"; - private static final String AUTO_PAGE_CACHE = "preference_auto_page_cache"; - private static final String PAGE_SCALING = "preference_page_scaling"; - private static final String PAGE_SCALING_DEFAULT = "3"; - private static final String SCREEN_ORI = "preference_screen_ori"; - private static final String SCREEN_ORI_DEFAULT = "0"; - private static final String DOWNLOAD_PATH = "preference_download_path"; - private static final String DOWNLOAD_PATH_DEFAULT = Environment.getExternalStorageDirectory() + "/EhViewer/download/"; - - private static boolean mInit = false; - - private static Context mContext; - private static SharedPreferences mConfigPre; - - private static final String EMSG = "Please init Config first."; - - /** - * Init Config - * - * @param context Application context - */ - public static void init(Context context) { - if (mInit) - return; - mInit = true; - - mContext = context; - mConfigPre = PreferenceManager.getDefaultSharedPreferences(mContext); - - // Init what in config - MangaImage.setMode(getPageScalingMode()); - } - - /** - * Is init - * @return True if init - */ - public static boolean isInit() { - return mInit; - } - - /** - * Get is it allowed to launch - * - * @return True if allowed - */ - public static boolean isAllowed() { - if (!mInit) { - throw new IllegalStateException(EMSG); - } - return mConfigPre.getBoolean(KEY_ALLOWED, false); - } - - /** - * Allowed the appliation to launch - */ - public static void allowed() { - if (!mInit) { - throw new IllegalStateException(EMSG); - } - mConfigPre.edit().putBoolean(KEY_ALLOWED, true).apply(); - } - - /** - * Check is it first time to launch the application - * - * @return - */ - public static boolean isFirstTime() { - if (!mInit) { - throw new IllegalStateException(); - } - return mConfigPre.getBoolean(KEY_FIRST, true); - } - - /** - * It is first time to launch the application - */ - public static void firstTime() { - mConfigPre.edit().putBoolean(KEY_FIRST, false).apply(); - } - - /** - * Is login last time ? - * - * @return - */ - public static boolean isLogin() { - return mConfigPre.getBoolean(KEY_LOGIN, false); - } - - public static void loginNow() { - mConfigPre.edit().putBoolean(KEY_LOGIN, true).apply(); - } - - public static void logoutNow() { - mConfigPre.edit().putBoolean(KEY_LOGIN, false).apply(); - } - - public static String getDownloadPath() { - return mConfigPre.getString(DOWNLOAD_PATH, DOWNLOAD_PATH_DEFAULT); - } - - /** - * Get cover cache size in MB - * - * @return - */ - public static int getCoverDiskCacheSize() { - try { - return Integer.parseInt(mConfigPre.getString(CP_CACHE, CP_CACHE_DEFAULT)); - } catch (Exception e) { - mConfigPre.edit().putString(CP_CACHE, CP_CACHE_DEFAULT).apply(); - return 25; - } - } - - /** - * Get page cache size in MB - * - * @return - */ - public static int getPageDiskCacheSize() { - if (!mInit) { - throw new IllegalStateException(EMSG); - } - try { - return Integer.parseInt(mConfigPre.getString(PAGE_CACHE, PAGE_CACHE_DEFAULT)); - } catch (Exception e) { - mConfigPre.edit().putString(PAGE_CACHE, PAGE_CACHE_DEFAULT).apply(); - return 256; - } - } - - public static boolean isAutoPageCache() { - if (!mInit) { - throw new IllegalStateException(EMSG); - } - return mConfigPre.getBoolean(AUTO_PAGE_CACHE, false); - } - - public static int getPageScalingMode() { - if (!mInit) { - throw new IllegalStateException(EMSG); - } - int pageScalingMode = 3; - try { - pageScalingMode = Integer.parseInt(mConfigPre.getString( - PAGE_SCALING, PAGE_SCALING_DEFAULT)); - } catch (Exception e) { - mConfigPre.edit().putString(PAGE_SCALING, PAGE_SCALING_DEFAULT) - .apply(); - } - return pageScalingMode; - } - - public static int getScreenOriMode() { - if (!mInit) { - throw new IllegalStateException(EMSG); - } - int screenOriMode = 0; - try { - screenOriMode = Integer.parseInt(mConfigPre.getString( - SCREEN_ORI, SCREEN_ORI_DEFAULT)); - } catch (Exception e) { - mConfigPre.edit().putString(SCREEN_ORI, SCREEN_ORI_DEFAULT) - .apply(); - } - return screenOriPre2Value(screenOriMode); - } - - public static int screenOriPre2Value(int screenOriModePre) { - switch (screenOriModePre) { - case 0: - return ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; - case 1: - return ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; - case 2: - return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; - default: - return ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; - } - } - - public static boolean isExhentai() { - return mConfigPre.getBoolean(KEY_IS_EXHENTAI, false); - } - - public static void exhentai(boolean isExhentai) { - mConfigPre.edit().putBoolean(KEY_IS_EXHENTAI, isExhentai).apply(); - } -} +package com.hippo.ehviewer.util; + +import com.hippo.ehviewer.view.MangaImage; + +import android.content.Context; +import android.content.SharedPreferences; +import android.content.pm.ActivityInfo; +import android.os.Environment; +import android.preference.PreferenceManager; + +public class Config { + @SuppressWarnings("unused") + private static final String TAG = "Config"; + + private static final String KEY_ALLOWED = "allowed"; + private static final String KEY_FIRST = "first_time"; + private static final String KEY_LOGIN = "login"; + private static final String KEY_IS_EXHENTAI = "is_exhentai"; + private static final String KEY_UPDATE_DATE = "update_date"; + + private static final String CP_CACHE = "preference_cp_cache"; + private static final String CP_CACHE_DEFAULT = "25"; + private static final String PAGE_CACHE = "preference_page_cache"; + private static final String PAGE_CACHE_DEFAULT = "256"; + private static final String AUTO_PAGE_CACHE = "preference_auto_page_cache"; + private static final String PAGE_SCALING = "preference_page_scaling"; + private static final String PAGE_SCALING_DEFAULT = "3"; + private static final String SCREEN_ORI = "preference_screen_ori"; + private static final String SCREEN_ORI_DEFAULT = "0"; + private static final String DOWNLOAD_PATH = "preference_download_path"; + private static final String DOWNLOAD_PATH_DEFAULT = Environment.getExternalStorageDirectory() + "/EhViewer/download/"; + + private static boolean mInit = false; + + private static Context mContext; + private static SharedPreferences mConfigPre; + + private static final String EMSG = "Please init Config first."; + + /** + * Init Config + * + * @param context Application context + */ + public static void init(Context context) { + if (mInit) + return; + mInit = true; + + mContext = context; + mConfigPre = PreferenceManager.getDefaultSharedPreferences(mContext); + + // Init what in config + MangaImage.setMode(getPageScalingMode()); + } + + /** + * Is init + * @return True if init + */ + public static boolean isInit() { + return mInit; + } + + /** + * Get is it allowed to launch + * + * @return True if allowed + */ + public static boolean isAllowed() { + if (!mInit) { + throw new IllegalStateException(EMSG); + } + return mConfigPre.getBoolean(KEY_ALLOWED, false); + } + + /** + * Allowed the appliation to launch + */ + public static void allowed() { + if (!mInit) { + throw new IllegalStateException(EMSG); + } + mConfigPre.edit().putBoolean(KEY_ALLOWED, true).apply(); + } + + /** + * Check is it first time to launch the application + * + * @return + */ + public static boolean isFirstTime() { + if (!mInit) { + throw new IllegalStateException(); + } + return mConfigPre.getBoolean(KEY_FIRST, true); + } + + /** + * It is first time to launch the application + */ + public static void firstTime() { + mConfigPre.edit().putBoolean(KEY_FIRST, false).apply(); + } + + /** + * Is login last time ? + * + * @return + */ + public static boolean isLogin() { + return mConfigPre.getBoolean(KEY_LOGIN, false); + } + + public static void loginNow() { + mConfigPre.edit().putBoolean(KEY_LOGIN, true).apply(); + } + + public static void logoutNow() { + mConfigPre.edit().putBoolean(KEY_LOGIN, false).apply(); + } + + public static String getDownloadPath() { + return mConfigPre.getString(DOWNLOAD_PATH, DOWNLOAD_PATH_DEFAULT); + } + + /** + * Get cover cache size in MB + * + * @return + */ + public static int getCoverDiskCacheSize() { + try { + return Integer.parseInt(mConfigPre.getString(CP_CACHE, CP_CACHE_DEFAULT)); + } catch (Exception e) { + mConfigPre.edit().putString(CP_CACHE, CP_CACHE_DEFAULT).apply(); + return 25; + } + } + + /** + * Get page cache size in MB + * + * @return + */ + public static int getPageDiskCacheSize() { + if (!mInit) { + throw new IllegalStateException(EMSG); + } + try { + return Integer.parseInt(mConfigPre.getString(PAGE_CACHE, PAGE_CACHE_DEFAULT)); + } catch (Exception e) { + mConfigPre.edit().putString(PAGE_CACHE, PAGE_CACHE_DEFAULT).apply(); + return 256; + } + } + + public static boolean isAutoPageCache() { + if (!mInit) { + throw new IllegalStateException(EMSG); + } + return mConfigPre.getBoolean(AUTO_PAGE_CACHE, false); + } + + public static int getPageScalingMode() { + if (!mInit) { + throw new IllegalStateException(EMSG); + } + int pageScalingMode = 3; + try { + pageScalingMode = Integer.parseInt(mConfigPre.getString( + PAGE_SCALING, PAGE_SCALING_DEFAULT)); + } catch (Exception e) { + mConfigPre.edit().putString(PAGE_SCALING, PAGE_SCALING_DEFAULT) + .apply(); + } + return pageScalingMode; + } + + public static int getScreenOriMode() { + if (!mInit) { + throw new IllegalStateException(EMSG); + } + int screenOriMode = 0; + try { + screenOriMode = Integer.parseInt(mConfigPre.getString( + SCREEN_ORI, SCREEN_ORI_DEFAULT)); + } catch (Exception e) { + mConfigPre.edit().putString(SCREEN_ORI, SCREEN_ORI_DEFAULT) + .apply(); + } + return screenOriPre2Value(screenOriMode); + } + + public static int screenOriPre2Value(int screenOriModePre) { + switch (screenOriModePre) { + case 0: + return ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; + case 1: + return ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; + case 2: + return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; + default: + return ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; + } + } + + public static boolean isExhentai() { + return mConfigPre.getBoolean(KEY_IS_EXHENTAI, false); + } + + public static void exhentai(boolean isExhentai) { + mConfigPre.edit().putBoolean(KEY_IS_EXHENTAI, isExhentai).apply(); + } + + public static int getUpdateDate() { + return mConfigPre.getInt(KEY_UPDATE_DATE, 0); + } + + public static void setUpdateDate() { + setUpdateDate(Util.getDate()); + } + + public static void setUpdateDate(int date) { + mConfigPre.edit().putInt(KEY_UPDATE_DATE, date).apply(); + } + +} diff --git a/src/com/hippo/ehviewer/util/EhClient.java b/src/com/hippo/ehviewer/util/EhClient.java index d0115913b..324a027ac 100644 --- a/src/com/hippo/ehviewer/util/EhClient.java +++ b/src/com/hippo/ehviewer/util/EhClient.java @@ -69,7 +69,8 @@ import android.util.Log; public class EhClient { private static final String TAG = "EhClient"; - private static String userAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.76 Safari/537.36"; + private static String defaultUserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.76 Safari/537.36"; + private static String userAgent = System.getProperty("http.agent", defaultUserAgent); private static String HOST = "g.e-hentai.org"; private static String API_URL = "http://g.e-hentai.org/api.php"; private static String loginUrl = "http://forums.e-hentai.org/index.php?act=Login&CODE=01"; @@ -481,9 +482,6 @@ public class EhClient { conn.setConnectTimeout(TIMEOUT); conn.setReadTimeout(TIMEOUT); conn.connect(); - - Log.d(TAG, "ResponseCode = " + conn.getResponseCode()); - getStringHUC(conn, sb); } catch (MalformedURLException e) { errorMessageId = R.string.em_url_format_error; diff --git a/src/com/hippo/ehviewer/util/Util.java b/src/com/hippo/ehviewer/util/Util.java index f812d567d..337230fc1 100644 --- a/src/com/hippo/ehviewer/util/Util.java +++ b/src/com/hippo/ehviewer/util/Util.java @@ -9,7 +9,10 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.net.HttpURLConnection; +import java.text.SimpleDateFormat; +import java.util.Date; import java.util.List; +import java.util.Locale; import java.util.zip.GZIPInputStream; import java.util.zip.Inflater; import java.util.zip.InflaterInputStream; @@ -110,7 +113,7 @@ public class Util { } sb.append(Integer.toHexString(v)); } - return sb.toString().toUpperCase(); + return sb.toString().toUpperCase(Locale.getDefault()); } public static byte[] hexStringToByteArray(String s) { @@ -184,4 +187,13 @@ public class Util { } } } + + @SuppressLint("SimpleDateFormat") + public static int getDate() { + int time = 0; + try { + time = Integer.parseInt(new SimpleDateFormat("yyyyMMdd").format(new Date())); + } catch (NumberFormatException e) {} + return time; + } }