Add warning before cleaning redundancy
This commit is contained in:
1 parent
0a2c442b75
commit
938c1a2e88
7 files changed
+99
-66
No files matched your search
@@ -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<Integer> 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 {
|
||||
|
||||
@@ -478,56 +478,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<DownloadInfo> diList = data.getAllDownloads();
|
||||
File downloadDir = new File(Config.getDownloadPath());
|
||||
String[] files = downloadDir.list();
|
||||
Handler handler = AppHandler.getInstance();
|
||||
List<File> targetDirList = new ArrayList<File>();
|
||||
|
||||
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<DownloadInfo> diList = data.getAllDownloads();
|
||||
File downloadDir = new File(Config.getDownloadPath());
|
||||
String[] files = downloadDir.list();
|
||||
Handler handler = AppHandler.getInstance();
|
||||
List<File> targetDirList = new ArrayList<File>();
|
||||
|
||||
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
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in new issue
Block a user