diff --git a/AndroidManifest.xml b/AndroidManifest.xml index c40e082fe..91ae19f2e 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -16,8 +16,8 @@ --> + android:versionCode="26" + android:versionName="0.6.5" > mDownloadIndexSet; private volatile Object mDownloadLock = new Object(); + private int mCurReadIndex = 0; + /** * Do no work in UI thread * @author Hippo @@ -132,13 +135,8 @@ public class ExDownloader implements Runnable { mControlorArray = new HttpHelper.DownloadControlor[mWorkerNum]; // Make sure dir - mDir = EhUtils.getGalleryDir(mGid, mTitle); + mDir = EhUtils.getGalleryDir(mGid); Utils.ensureDir(mDir, true); - // Create mark file - File makeFile = new File(mDir, EhUtils.EH_DOWNLOAD_FILENAME); - try { - new FileOutputStream(makeFile).close(); - } catch (IOException e) {} } public void setListenerForImageSet(ListenerForImageSet l) { @@ -244,6 +242,15 @@ public class ExDownloader implements Runnable { ensureWorkers(); } + public void setCurReadIndex(final int index) { + new BgThread() { + @Override + public void run() { + writeCurReadIndex(index); + } + }.start(); + } + public int getMaxEnsureIndex() { if (mImageNum != -1) { return mImageNum - 1; @@ -288,7 +295,7 @@ public class ExDownloader implements Runnable { } private File getExDownloadInfoFile() { - return new File(mManager.getExDownloadInfoDir(), String.valueOf(mGid)); + return new File(mDir, EhUtils.EH_DOWNLOAD_FILENAME); } private boolean checkMode(int samlpe, int target) { @@ -300,6 +307,7 @@ public class ExDownloader implements Runnable { * This function parser the download info file.
* The file look like this:
* + * 00000000
* 728874
* 306429c222
* 1
@@ -317,7 +325,7 @@ public class ExDownloader implements Runnable { * @param ediFile * @return */ - private boolean parserEdiFile(File ediFile) { + private synchronized boolean parserEdiFile(File ediFile) { if (!ediFile.exists() || !ediFile.isFile() || !ediFile.canRead() || !ediFile.canWrite()) return false; @@ -326,6 +334,8 @@ public class ExDownloader implements Runnable { try { is = new BufferedInputStream(new FileInputStream(ediFile), IO_BUFFER_SIZE); + // skip read index + Utils.readAsciiLine(is); if (mGid != Integer.valueOf(Utils.readAsciiLine(is)) || !mToken.equals(Utils.readAsciiLine(is))) return false; @@ -377,9 +387,11 @@ public class ExDownloader implements Runnable { } } - private void writeEdiFile(File ediFile) { + private synchronized void writeEdiFile(File ediFile) { try { FileWriter writer = new FileWriter(ediFile); + writer.write(String.format("%08x", mCurReadIndex)); + writer.write("\n"); writer.write(String.valueOf(mGid)); writer.write("\n"); writer.write(mToken); @@ -406,6 +418,27 @@ public class ExDownloader implements Runnable { } catch (IOException e) {} } + private synchronized void writeCurReadIndex(int index) { + mCurReadIndex = index; + try { + RandomAccessFile raf = new RandomAccessFile(getExDownloadInfoFile(), "rw"); + raf.write(String.format("%08x", mCurReadIndex).getBytes()); + raf.close(); + } catch (Throwable e) {} + } + + public static int readCurReadIndex(int gid) { + try { + RandomAccessFile raf = new RandomAccessFile(new File(EhUtils.getGalleryDir(gid), + EhUtils.EH_DOWNLOAD_FILENAME), "r"); + int index = Integer.parseInt(raf.readLine(), 16); + raf.close(); + return index; + } catch (Throwable e) { + return 0; + } + } + private void getDetailInfo(int pageIndex, File ediFile, boolean needPreviewInfo) throws Exception { HttpHelper hh = new HttpHelper(mContext); EdDetailParser edp = new EdDetailParser(); @@ -478,7 +511,7 @@ public class ExDownloader implements Runnable { try { File ediFile = getExDownloadInfoFile(); if (!parserEdiFile(ediFile) || mPreviewPerPage == -1 || - (mMode == EhClient.MODE_EX && mImageNum == -1)) { + ((mMode == EhClient.MODE_EX || mMode == EhClient.MODE_G) && mImageNum == -1)) { getDetailInfo(0, ediFile, true); } diff --git a/src/com/hippo/ehviewer/ehclient/ExDownloaderManager.java b/src/com/hippo/ehviewer/ehclient/ExDownloaderManager.java index 140a04d0b..c3a4efc88 100644 --- a/src/com/hippo/ehviewer/ehclient/ExDownloaderManager.java +++ b/src/com/hippo/ehviewer/ehclient/ExDownloaderManager.java @@ -16,8 +16,6 @@ package com.hippo.ehviewer.ehclient; -import java.io.File; - import android.content.Context; import android.util.SparseArray; @@ -29,7 +27,6 @@ public class ExDownloaderManager { private final Context mContext; private final SparseArray mExDownloadList; - private final File mExDownloadInfoDir; private static ExDownloaderManager sInstance; @@ -44,18 +41,6 @@ public class ExDownloaderManager { private ExDownloaderManager() { mContext = AppContext.getInstance(); mExDownloadList = new SparseArray(); - // Init download info dir - String cachePath = mContext.getExternalCacheDir() != null - ? mContext.getExternalCacheDir().getPath() - : mContext.getCacheDir().getPath(); - mExDownloadInfoDir = new File(cachePath, TAG); - if (!mExDownloadInfoDir.exists()) { - mExDownloadInfoDir.mkdirs(); - } - } - - public File getExDownloadInfoDir() { - return mExDownloadInfoDir; } public synchronized ExDownloader getExDownloader(int gid, String token, String title, int mode) { diff --git a/src/com/hippo/ehviewer/gallery/GalleryView.java b/src/com/hippo/ehviewer/gallery/GalleryView.java index 70c4b5533..6d0257552 100644 --- a/src/com/hippo/ehviewer/gallery/GalleryView.java +++ b/src/com/hippo/ehviewer/gallery/GalleryView.java @@ -767,6 +767,7 @@ public class GalleryView extends GLView setState(); loadImage(mCurIndex-1); + mImageSet.setCurReadIndex(mCurIndex); if (mGalleryViewListener != null) { mGalleryViewListener.onPageChanged(mCurIndex); } @@ -805,6 +806,7 @@ public class GalleryView extends GLView setState(); loadImage(mCurIndex+1); + mImageSet.setCurReadIndex(mCurIndex); if (mGalleryViewListener != null) { mGalleryViewListener.onPageChanged(mCurIndex); } @@ -844,6 +846,7 @@ public class GalleryView extends GLView loadImage(mCurIndex); loadImage(mCurIndex+1); + mImageSet.setCurReadIndex(mCurIndex); if (mGalleryViewListener != null) { mGalleryViewListener.onPageChanged(mCurIndex); } diff --git a/src/com/hippo/ehviewer/gallery/data/ImageSet.java b/src/com/hippo/ehviewer/gallery/data/ImageSet.java index d2c1cc857..5933544c4 100644 --- a/src/com/hippo/ehviewer/gallery/data/ImageSet.java +++ b/src/com/hippo/ehviewer/gallery/data/ImageSet.java @@ -88,7 +88,7 @@ public class ImageSet implements ExDownloader.ListenerForImageSet { public ImageSet(int gid, String token, String title, int startIndex) { - mDir = EhUtils.getGalleryDir(gid, title); + mDir = EhUtils.getGalleryDir(gid); Utils.ensureDir(mDir, true); // Init ExDownloader @@ -128,6 +128,10 @@ public class ImageSet implements ExDownloader.ListenerForImageSet { mExDownloader.setStartIndex(startIndex); } + public void setCurReadIndex(int index) { + mExDownloader.setCurReadIndex(index); + } + public Object getImage(int index) { // Try to get file name String filename = mImageFilenameArray.get(index); diff --git a/src/com/hippo/ehviewer/ui/DownloadActivity.java b/src/com/hippo/ehviewer/ui/DownloadActivity.java index a4abd763d..226d3cfff 100644 --- a/src/com/hippo/ehviewer/ui/DownloadActivity.java +++ b/src/com/hippo/ehviewer/ui/DownloadActivity.java @@ -229,7 +229,7 @@ public class DownloadActivity extends AbsActivity { intent.putExtra(GalleryActivity.KEY_GID, gi.gid); intent.putExtra(GalleryActivity.KEY_TOKEN, gi.token); intent.putExtra(GalleryActivity.KEY_TITLE, gi.title); - intent.putExtra(GalleryActivity.KEY_START_INDEX, 0); + intent.putExtra(GalleryActivity.KEY_START_INDEX, -1); startActivity(intent); } }); @@ -360,7 +360,7 @@ public class DownloadActivity extends AbsActivity { mServiceConn.getService().delete(mDownloadInfo); // Delete dir GalleryInfo gi = mDownloadInfo.galleryInfo; - Utils.deleteDirInThread(EhUtils.getGalleryDir(gi.gid, gi.title)); + Utils.deleteDirInThread(EhUtils.getGalleryDir(gi.gid)); } return true; } diff --git a/src/com/hippo/ehviewer/ui/GalleryActivity.java b/src/com/hippo/ehviewer/ui/GalleryActivity.java index a54b2499e..899b9f91a 100644 --- a/src/com/hippo/ehviewer/ui/GalleryActivity.java +++ b/src/com/hippo/ehviewer/ui/GalleryActivity.java @@ -34,6 +34,7 @@ import android.widget.TextView; import com.hippo.ehviewer.AppHandler; import com.hippo.ehviewer.R; import com.hippo.ehviewer.app.MaterialAlertDialog; +import com.hippo.ehviewer.ehclient.ExDownloader; import com.hippo.ehviewer.gallery.GalleryView; import com.hippo.ehviewer.gallery.data.ImageSet; import com.hippo.ehviewer.gallery.ui.GLRootView; @@ -199,6 +200,8 @@ public class GalleryActivity extends AbsActivity String token = intent.getStringExtra(KEY_TOKEN); mTitle = intent.getStringExtra(KEY_TITLE); int startIndex = intent.getIntExtra(KEY_START_INDEX, 0); + if (startIndex == -1) + startIndex = ExDownloader.readCurReadIndex(mGid); if (mGid == -1 || token == null || mTitle == null) { new MaterialAlertDialog.Builder(this).setTitle(R.string.error) @@ -214,6 +217,7 @@ public class GalleryActivity extends AbsActivity } else { mImageSet = new ImageSet(mGid, token, mTitle, startIndex); mGalleryView = new GalleryView(getApplicationContext(), mImageSet, startIndex); + GLRootView glrv= (GLRootView)findViewById(R.id.gl_root_view); glrv.setContentPane(mGalleryView); @@ -302,6 +306,7 @@ public class GalleryActivity extends AbsActivity public void onSizeUpdate(int size) { updateTitle(); mPageSeeker.setMax(size - 1); + mPageSeeker.setProgress(mGalleryView.getCurIndex() + 1); } private void showSeekBubble() { diff --git a/src/com/hippo/ehviewer/ui/SettingsActivity.java b/src/com/hippo/ehviewer/ui/SettingsActivity.java index 0f5b690aa..a9f0f033b 100644 --- a/src/com/hippo/ehviewer/ui/SettingsActivity.java +++ b/src/com/hippo/ehviewer/ui/SettingsActivity.java @@ -57,7 +57,6 @@ import com.hippo.ehviewer.app.MaterialAlertDialog; import com.hippo.ehviewer.data.Data; import com.hippo.ehviewer.data.DownloadInfo; import com.hippo.ehviewer.ehclient.EhInfo; -import com.hippo.ehviewer.ehclient.ExDownloaderManager; import com.hippo.ehviewer.network.HttpHelper; import com.hippo.ehviewer.preference.ListPreference; import com.hippo.ehviewer.util.BgThread; @@ -599,9 +598,6 @@ public class SettingsActivity extends AbsPreferenceActivity { for (int i = 0; i < targetDirList.size(); i++) { File dir = targetDirList.get(i); Utils.deleteFile(dir); - // Delete gid file - new File(ExDownloaderManager.getInstance().getExDownloadInfoDir(), - String.valueOf(EhUtils.getGidFromDirname(dir.getName()))).delete(); handler.post(new CleanResponder(CleanResponder.STATE_DOING, targetDirList.size(), i + 1)); } // Close windows diff --git a/src/com/hippo/ehviewer/util/EhUtils.java b/src/com/hippo/ehviewer/util/EhUtils.java index 44ad0a239..708c68aff 100644 --- a/src/com/hippo/ehviewer/util/EhUtils.java +++ b/src/com/hippo/ehviewer/util/EhUtils.java @@ -18,6 +18,7 @@ package com.hippo.ehviewer.util; import java.io.File; + public final class EhUtils { public static final String EH_DOWNLOAD_FILENAME = ".ehviewer"; @@ -25,20 +26,11 @@ public final class EhUtils { /** * Get gallery for read and download * @param gid - * @param title * @return */ - public static File getGalleryDir(int gid, String title) { + public static File getGalleryDir(int gid) { return new File(Config.getDownloadPath(), - Utils.standardizeFilename(gid + "-" + title)); - } - - public static int getGidFromDirname(String dirname) { - int index = dirname.indexOf('-'); - if (index == -1) - return 0; - else - return Utils.parseIntSafely(dirname.substring(0, index), 0); + Utils.standardizeFilename(Integer.toString(gid))); } /**