diff --git a/app/src/main/java/com/hippo/ehviewer/ehclient/ExDownloader.java b/app/src/main/java/com/hippo/ehviewer/ehclient/ExDownloader.java index eef98b30a..a74e5aaba 100644 --- a/app/src/main/java/com/hippo/ehviewer/ehclient/ExDownloader.java +++ b/app/src/main/java/com/hippo/ehviewer/ehclient/ExDownloader.java @@ -16,20 +16,6 @@ package com.hippo.ehviewer.ehclient; -import java.io.BufferedInputStream; -import java.io.EOFException; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileWriter; -import java.io.IOException; -import java.io.InputStream; -import java.io.RandomAccessFile; -import java.util.HashSet; -import java.util.List; -import java.util.Queue; -import java.util.Set; -import java.util.concurrent.ConcurrentLinkedQueue; - import android.app.NotificationManager; import android.content.Context; import android.os.Process; @@ -44,6 +30,20 @@ import com.hippo.ehviewer.util.EhUtils; import com.hippo.ehviewer.util.Log; import com.hippo.ehviewer.util.Utils; +import java.io.BufferedInputStream; +import java.io.EOFException; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.io.RandomAccessFile; +import java.util.HashSet; +import java.util.List; +import java.util.Queue; +import java.util.Set; +import java.util.concurrent.ConcurrentLinkedQueue; + // TODO what a mess public final class ExDownloader implements Runnable { @@ -106,7 +106,7 @@ public final class ExDownloader implements Runnable { private volatile long mLastUpdateSpeedTime = 0; private volatile long mAccumulateSize; private volatile HashSet mDownloadIndexSet; - private volatile Object mDownloadLock = new Object(); + private final Object mDownloadLock = new Object(); private int mCurReadIndex = 0; @@ -476,7 +476,7 @@ public final class ExDownloader implements Runnable { if (edp.isLastPage) { mPreviewPageNum = pageIndex + 1; mImageNum = pageIndex * mPreviewPerPage + pageTokenArray.size(); - } else if (!edp.isLastPage && mPreviewPageNum == -1) { + } else if (mPreviewPageNum == -1) { mCurMaxPreviewPage = Math.max(mCurMaxPreviewPage, pageIndex + 1); } } else { diff --git a/app/src/main/java/com/hippo/ehviewer/ui/SettingsActivity.java b/app/src/main/java/com/hippo/ehviewer/ui/SettingsActivity.java index 6a25f6b4d..549d5dfdc 100644 --- a/app/src/main/java/com/hippo/ehviewer/ui/SettingsActivity.java +++ b/app/src/main/java/com/hippo/ehviewer/ui/SettingsActivity.java @@ -486,56 +486,71 @@ public class SettingsActivity extends AbsPreferenceActivity { public boolean onPreferenceClick(Preference preference) { final String key = preference.getKey(); if (KEY_CLEAN_REDUNDANCY.equals(key)) { - - // Create a thread to do clean task - new BgThread() { - @Override - public void run() { - Data data = Data.getInstance(); - List diList = data.getAllDownloads(); - File downloadDir = new File(Config.getDownloadPath()); - String[] files = downloadDir.list(); - Handler handler = AppHandler.getInstance(); - List targetDirList = new ArrayList(); - - if (files == null) { - // Check files null - handler.post(new CleanResponder(CleanResponder.STATE_NONE, 0, 0)); - return; - } - - for (String filename : files) { - // If in download list, just continue - if (isInDownloadList(diList, filename)) - continue; - File dir = new File(downloadDir, filename); - // If there is no tag file, just continue - if (!new File(dir, EhUtils.EH_DOWNLOAD_FILENAME).exists()) - continue; - // Add to list - targetDirList.add(dir); - } - - if (targetDirList.isEmpty()) { - handler.post(new CleanResponder(CleanResponder.STATE_NONE, 0, 0)); - return; - } else { - handler.post(new CleanResponder(CleanResponder.STATE_START, 0, 0)); - } - // Do delete - for (int i = 0; i < targetDirList.size(); i++) { - File dir = targetDirList.get(i); - Utils.deleteFile(dir); - handler.post(new CleanResponder(CleanResponder.STATE_DOING, targetDirList.size(), i + 1)); - } - // Close windows - handler.post(new CleanResponder(CleanResponder.STATE_DONE, targetDirList.size(), targetDirList - .size())); - } - }.start(); + new MaterialAlertDialog.Builder(getActivity()).setTitle(R.string.warning) + .setMessage(R.string.clean_redundancy_mesg) + .setPositiveButton(R.string.are_you_sure_sure) + .setNegativeButton(R.string.are_you_sure_no) + .setButtonListener(new MaterialAlertDialog.OnClickListener() { + @Override + public boolean onClick(MaterialAlertDialog dialog, int which) { + if (which == MaterialAlertDialog.POSITIVE) { + cleanRedundancy(); + } return true; + } + }).show(); } return true; } + + + private void cleanRedundancy() { + // Create a thread to do clean task + new BgThread() { + @Override + public void run() { + Data data = Data.getInstance(); + List diList = data.getAllDownloads(); + File downloadDir = new File(Config.getDownloadPath()); + String[] files = downloadDir.list(); + Handler handler = AppHandler.getInstance(); + List targetDirList = new ArrayList(); + + if (files == null) { + // Check files null + handler.post(new CleanResponder(CleanResponder.STATE_NONE, 0, 0)); + return; + } + + for (String filename : files) { + // If in download list, just continue + if (isInDownloadList(diList, filename)) + continue; + File dir = new File(downloadDir, filename); + // If there is no tag file, just continue + if (!new File(dir, EhUtils.EH_DOWNLOAD_FILENAME).exists()) + continue; + // Add to list + targetDirList.add(dir); + } + + if (targetDirList.isEmpty()) { + handler.post(new CleanResponder(CleanResponder.STATE_NONE, 0, 0)); + return; + } else { + handler.post(new CleanResponder(CleanResponder.STATE_START, 0, 0)); + } + // Do delete + for (int i = 0; i < targetDirList.size(); i++) { + File dir = targetDirList.get(i); + Utils.deleteFile(dir); + handler.post(new CleanResponder(CleanResponder.STATE_DOING, targetDirList.size(), i + 1)); + } + // Close windows + handler.post(new CleanResponder(CleanResponder.STATE_DONE, targetDirList.size(), targetDirList + .size())); + } + }.start(); + } } public static class DownloadFragment extends PreferenceFragment implements diff --git a/app/src/main/java/com/hippo/ehviewer/util/Config.java b/app/src/main/java/com/hippo/ehviewer/util/Config.java index 901bb82b7..048f19139 100644 --- a/app/src/main/java/com/hippo/ehviewer/util/Config.java +++ b/app/src/main/java/com/hippo/ehviewer/util/Config.java @@ -41,7 +41,6 @@ public final class Config { private static boolean mInit = false; - private static Context mContext; private static SharedPreferences mConfigPre; /** @@ -54,8 +53,7 @@ public final class Config { return; mInit = true; - mContext = context; - mConfigPre = PreferenceManager.getDefaultSharedPreferences(mContext); + mConfigPre = PreferenceManager.getDefaultSharedPreferences(context); if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { sExternalDir = new File(Environment.getExternalStorageDirectory(), EXTERANL_DIR_NAME); diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index b46444724..dcf1734ce 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -246,6 +246,7 @@ 自定义解码可能会更使用更少内存,解码更快 自定义解码暂不支持 x86, mips 清理阅读冗余 + 你确定要清理阅读冗余吗?不在下载列表中的画廊图片文件将被删除。 未发现冗余 完成冗余清理,共清理 %d 项 解码格式 @@ -379,6 +380,10 @@ Hippo 摄于成都大熊猫繁育研究基地 + + 算了 + 确定 + 分享 过滤 diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml index 93be0334a..32c566426 100644 --- a/app/src/main/res/values-zh-rHK/strings.xml +++ b/app/src/main/res/values-zh-rHK/strings.xml @@ -234,6 +234,7 @@ 自定義解碼可能會更使用更少內存,解碼更快 自定義解碼暫不支持 x86, mips 清理閲讀宂餘 + 你確定要清理閲讀宂餘嗎?不在下載列表中的畫廊圖片文件文件將被刪除。 未發現宂餘 完成宂餘清理,共清理 %d 項 解碼格式 @@ -367,6 +368,10 @@ Hippo 攝於成都大熊貓繁育研究基地 + + 算了 + 確定 + 分享 過濾 diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index d64ead1b5..eec093ba0 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -234,6 +234,7 @@ 自定義解碼可能會更使用更少記憶體,解碼更快 自定義解碼暫不支援 x86, mips 清理閱讀冗餘 + 你確定要清理閱讀冗餘嗎?不在下載列表中的畫廊圖片檔案檔案將被刪除。 未發現冗餘 完成冗餘清理,共清理 %d 項 解碼格式 @@ -367,6 +368,10 @@ Hippo 攝於成都大熊貓繁育研究基地 + + 算了 + 確定 + 分享 過濾 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index adb64a411..40bd01743 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -251,6 +251,7 @@ Custom codec may cost less memory, decode faster Custom codec do not support x86, mips Clean redundancy + Are you sure you want to clean redundancy? It will delete all gallery files which is not in the download list. No redundancy Redundancy cleaning completed, clean-up %d items totally Decode format @@ -404,6 +405,10 @@ Taken by Hippo at Chengdu Research Base of Giant Panda Breeding + + No + Sure + share filter