summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2012-10-14 09:50:05 +0400
committerAndrew Dolgov <[email protected]>2012-10-14 09:50:05 +0400
commitd81003594c647261967951cb874dfb540c1e50bc (patch)
tree9b56efe6961c3e1d778a3399824018829d7022a1 /src
parent90f92b7025c638bbd558527197c51ba9912c9d96 (diff)
improve rescan speed
Diffstat (limited to 'src')
-rw-r--r--src/org/fox/ttcomics/ComicListFragment.java109
-rw-r--r--src/org/fox/ttcomics/CommonActivity.java2
2 files changed, 61 insertions, 50 deletions
diff --git a/src/org/fox/ttcomics/ComicListFragment.java b/src/org/fox/ttcomics/ComicListFragment.java
index 15011e4..4fe63df 100644
--- a/src/org/fox/ttcomics/ComicListFragment.java
+++ b/src/org/fox/ttcomics/ComicListFragment.java
@@ -214,13 +214,15 @@ public class ComicListFragment extends Fragment implements OnItemClickListener {
m_prefs = PreferenceManager.getDefaultSharedPreferences(activity.getApplicationContext());
}
- protected void rescan() {
+ protected void rescan(final boolean fullRescan) {
AsyncTask<String, Integer, Integer> rescanTask = new AsyncTask<String, Integer, Integer>() {
@Override
protected void onProgressUpdate(Integer... progress) {
- m_activity.setProgress(Math.round(((float)progress[0] / (float)progress[1]) * 10000));
+ if (isAdded()) {
+ m_activity.setProgress(Math.round(((float)progress[0] / (float)progress[1]) * 10000));
+ }
}
@Override
@@ -240,65 +242,74 @@ public class ComicListFragment extends Fragment implements OnItemClickListener {
java.util.Arrays.sort(archives);
for (File archive : archives) {
+ String filePath = archive.getAbsolutePath();
+
if (archive.isDirectory() && m_mode == 0) {
- m_files.add(archive.getAbsolutePath());
+ m_files.add(filePath);
} else if (archive.getName().toLowerCase().matches(".*\\.(cbz|zip)") && isAdded() && m_activity != null) {
try {
- CbzComicArchive cba = new CbzComicArchive(archive.getAbsolutePath());
-
- if (cba.getCount() > 0) {
- // Get cover
-
- try {
- InputStream is = cba.getItem(0);
-
- File thumbnailDir = new File(storage.getAbsolutePath() + "/" + m_activity.THUMBNAIL_PATH);
+ int size = m_activity.getSize(filePath);
+
+ if (size == -1 || fullRescan) {
+
+ CbzComicArchive cba = new CbzComicArchive(filePath);
- if (!thumbnailDir.isDirectory()) { thumbnailDir.mkdirs(); };
+ if (cba.getCount() > 0) {
+ // Get cover
- File thumbnailFile = new File(CommonActivity.getCacheFileName(archive.getAbsolutePath()));
+ try {
+ InputStream is = cba.getItem(0);
- if (thumbnailDir.isDirectory() && !thumbnailFile.exists()) {
- FileOutputStream fos = new FileOutputStream(thumbnailFile.getAbsolutePath());
+ File thumbnailDir = new File(storage.getAbsolutePath() + "/" + m_activity.THUMBNAIL_PATH);
+
+ if (!thumbnailDir.isDirectory()) { thumbnailDir.mkdirs(); };
- byte[] buffer = new byte[1024];
- int len = 0;
- while ((len = is.read(buffer)) != -1) {
- fos.write(buffer, 0, len);
- }
+ File thumbnailFile = new File(CommonActivity.getCacheFileName(filePath));
- fos.close();
- is.close();
+ if (thumbnailDir.isDirectory() && !thumbnailFile.exists()) {
+ FileOutputStream fos = new FileOutputStream(thumbnailFile.getAbsolutePath());
+
+ byte[] buffer = new byte[1024];
+ int len = 0;
+ while ((len = is.read(buffer)) != -1) {
+ fos.write(buffer, 0, len);
+ }
+
+ fos.close();
+ is.close();
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
}
- } catch (IOException e) {
- e.printStackTrace();
+
+ size = cba.getCount();
+
+ m_activity.setSize(filePath, size);
}
+ }
- int lastPos = m_activity.getLastPosition(archive.getAbsolutePath());
-
- switch (m_mode) {
- case 0:
- m_files.add(archive.getAbsolutePath());
- break;
- case 1:
- if (lastPos == 0) {
- m_files.add(archive.getAbsolutePath());
- }
- break;
- case 2:
- if (lastPos > 0 && lastPos != cba.getCount()-1) {
- m_files.add(archive.getAbsolutePath());
- }
- break;
- case 3:
- if (lastPos == cba.getCount()-1) {
- m_files.add(archive.getAbsolutePath());
- }
- break;
+ int lastPos = m_activity.getLastPosition(filePath);
+
+ switch (m_mode) {
+ case 0:
+ m_files.add(filePath);
+ break;
+ case 1:
+ if (lastPos == 0) {
+ m_files.add(filePath);
}
-
- m_activity.setSize(archive.getAbsolutePath(), cba.getCount());
+ break;
+ case 2:
+ if (lastPos > 0 && lastPos != size - 1) {
+ m_files.add(filePath);
+ }
+ break;
+ case 3:
+ if (lastPos == size - 1) {
+ m_files.add(filePath);
+ }
+ break;
}
} catch (IOException e) {
// TODO Auto-generated catch block
@@ -335,7 +346,7 @@ public class ComicListFragment extends Fragment implements OnItemClickListener {
super.onResume();
if (m_files.size() == 0) {
- rescan();
+ rescan(false);
} else {
m_adapter.notifyDataSetChanged();
}
diff --git a/src/org/fox/ttcomics/CommonActivity.java b/src/org/fox/ttcomics/CommonActivity.java
index 9b66f20..933778e 100644
--- a/src/org/fox/ttcomics/CommonActivity.java
+++ b/src/org/fox/ttcomics/CommonActivity.java
@@ -107,7 +107,7 @@ public class CommonActivity extends FragmentActivity {
ComicListFragment frag = (ComicListFragment) getSupportFragmentManager().findFragmentByTag(FRAG_COMICS_LIST);
if (frag != null && frag.isAdded()) {
- frag.rescan();
+ frag.rescan(true);
}
return true;