Save read progress
This commit is contained in:
1 parent
2e5efa1cd6
commit
e3226d3f70
6 files changed
+70
-17
No files matched your search
@@ -62,6 +62,22 @@ public class EhGalleryProvider extends GalleryProvider implements SpiderQueen.On
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getStartPage() {
|
||||
if (mSpiderQueen != null) {
|
||||
return mSpiderQueen.getStartPage();
|
||||
} else {
|
||||
return super.getStartPage();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putStartPage(int page) {
|
||||
if (mSpiderQueen != null) {
|
||||
mSpiderQueen.putStartPage(page);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
if (mSpiderQueen != null) {
|
||||
|
||||
@@ -82,6 +82,12 @@ public abstract class GalleryProvider {
|
||||
|
||||
public abstract String getError();
|
||||
|
||||
public int getStartPage() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void putStartPage(int page) {}
|
||||
|
||||
public void setGalleryProviderListener(GalleryProviderListener listener) {
|
||||
mGalleryProviderListener = listener;
|
||||
}
|
||||
|
||||
@@ -38,6 +38,7 @@ import com.hippo.gl.widget.GLEdgeView;
|
||||
import com.hippo.gl.widget.GLProgressView;
|
||||
import com.hippo.gl.widget.GLTextureView;
|
||||
import com.hippo.yorozuya.LayoutUtils;
|
||||
import com.hippo.yorozuya.MathUtils;
|
||||
import com.hippo.yorozuya.Pool;
|
||||
import com.hippo.yorozuya.ResourcesUtils;
|
||||
|
||||
@@ -140,7 +141,7 @@ public class GalleryView extends GLView implements GestureRecognizer.Listener {
|
||||
|
||||
public GalleryView(@NonNull Context context, @NonNull Adapter adapter,
|
||||
Listener listener, @LayoutMode int layoutMode, @ImageView.Scale int scaleMode,
|
||||
@ImageView.StartPosition int startPosition) {
|
||||
@ImageView.StartPosition int startPosition, int startPage) {
|
||||
mContext = context;
|
||||
mAdapter = adapter;
|
||||
mListener = listener;
|
||||
@@ -152,6 +153,7 @@ public class GalleryView extends GLView implements GestureRecognizer.Listener {
|
||||
mLayoutMode = layoutMode;
|
||||
mScaleMode = scaleMode;
|
||||
mStartPosition = startPosition;
|
||||
mIndex = MathUtils.clamp(startPage, 0, Integer.MAX_VALUE);
|
||||
mProgressColor = ResourcesUtils.getAttrColor(context, R.attr.colorPrimary);
|
||||
mProgressSize = LayoutUtils.dp2pix(context, PROGRESS_SIZE_IN_DP);
|
||||
mErrorSize = context.getResources().getDimension(R.dimen.text_large);
|
||||
|
||||
@@ -36,7 +36,7 @@ public class SpiderInfo {
|
||||
static final String TOKEN_FAILED = "failed";
|
||||
static final String TOKEN_WAIT = "wait";
|
||||
|
||||
int currentIndex = 0;
|
||||
int startPage = 0;
|
||||
long gid = -1;
|
||||
String token = null;
|
||||
int pages = -1;
|
||||
@@ -55,8 +55,8 @@ public class SpiderInfo {
|
||||
try {
|
||||
is = file.openInputStream();
|
||||
spiderInfo = new SpiderInfo();
|
||||
// Current index
|
||||
spiderInfo.currentIndex = Integer.parseInt(IOUtils.readAsciiLine(is), 16);
|
||||
// Start page
|
||||
spiderInfo.startPage = Integer.parseInt(IOUtils.readAsciiLine(is), 16);
|
||||
// Gid
|
||||
spiderInfo.gid = Long.parseLong(IOUtils.readAsciiLine(is));
|
||||
// Token
|
||||
@@ -104,7 +104,7 @@ public class SpiderInfo {
|
||||
OutputStreamWriter writer = null;
|
||||
try {
|
||||
writer = new OutputStreamWriter(os);
|
||||
writer.write(String.format("%08x", currentIndex));
|
||||
writer.write(String.format("%08x", startPage));
|
||||
writer.write("\n");
|
||||
writer.write(Long.toString(gid));
|
||||
writer.write("\n");
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package com.hippo.ehviewer.spider;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Process;
|
||||
import android.support.annotation.IntDef;
|
||||
import android.support.annotation.NonNull;
|
||||
@@ -112,9 +113,12 @@ public class SpiderQueen implements Runnable {
|
||||
|
||||
private static final SparseJLArray<SpiderQueen> sQueenMap = new SparseJLArray<>();
|
||||
|
||||
@NonNull
|
||||
private final OkHttpClient mHttpClient;
|
||||
@NonNull
|
||||
private final GalleryInfo mGalleryInfo;
|
||||
private volatile SpiderDen mSpiderDen;
|
||||
@NonNull
|
||||
private final SpiderDen mSpiderDen;
|
||||
|
||||
private int mReadReference = 0;
|
||||
private int mDownloadReference = 0;
|
||||
@@ -164,9 +168,10 @@ public class SpiderQueen implements Runnable {
|
||||
|
||||
private final List<OnSpiderListener> mSpiderListeners = new ArrayList<>();
|
||||
|
||||
private SpiderQueen(EhApplication application, GalleryInfo galleryInfo) {
|
||||
private SpiderQueen(EhApplication application, @NonNull GalleryInfo galleryInfo) {
|
||||
mHttpClient = EhApplication.getOkHttpClient(application);
|
||||
mGalleryInfo = galleryInfo;
|
||||
mSpiderDen = new SpiderDen(mGalleryInfo);
|
||||
}
|
||||
|
||||
public void addOnSpiderListener(OnSpiderListener listener) {
|
||||
@@ -301,10 +306,7 @@ public class SpiderQueen implements Runnable {
|
||||
mMode = MODE_READ;
|
||||
}
|
||||
|
||||
SpiderDen spiderDen = mSpiderDen;
|
||||
if (spiderDen != null) {
|
||||
spiderDen.setMode(mMode);
|
||||
}
|
||||
mSpiderDen.setMode(mMode);
|
||||
|
||||
// Update download page
|
||||
boolean startWorkers;
|
||||
@@ -533,7 +535,33 @@ public class SpiderQueen implements Runnable {
|
||||
}
|
||||
}
|
||||
|
||||
private SpiderInfo readSpiderInfoFromLocal() {
|
||||
public int getStartPage() {
|
||||
mSpiderInfo = readSpiderInfoFromLocal();
|
||||
if (mSpiderInfo != null) {
|
||||
return mSpiderInfo.startPage;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public void putStartPage(int page) {
|
||||
if (mSpiderInfo != null) {
|
||||
mSpiderInfo.startPage = page;
|
||||
new AsyncTask<Void, Void, Void>() {
|
||||
@Override
|
||||
protected Void doInBackground(Void... params) {
|
||||
writeSpiderInfoToLocal(mSpiderInfo);
|
||||
return null;
|
||||
}
|
||||
}.execute();
|
||||
}
|
||||
}
|
||||
|
||||
private synchronized SpiderInfo readSpiderInfoFromLocal() {
|
||||
if (null != mSpiderInfo) {
|
||||
return mSpiderInfo;
|
||||
}
|
||||
|
||||
// Read from download dir
|
||||
UniFile downloadDir = mSpiderDen.getDownloadDir();
|
||||
if (downloadDir != null) {
|
||||
@@ -627,7 +655,7 @@ public class SpiderQueen implements Runnable {
|
||||
}
|
||||
}
|
||||
|
||||
private void writeSpiderInfoToLocal(@NonNull SpiderInfo spiderInfo) {
|
||||
private synchronized void writeSpiderInfoToLocal(@NonNull SpiderInfo spiderInfo) {
|
||||
// Write to download dir
|
||||
UniFile downloadDir = mSpiderDen.getDownloadDir();
|
||||
if (downloadDir != null) {
|
||||
@@ -651,9 +679,6 @@ public class SpiderQueen implements Runnable {
|
||||
}
|
||||
|
||||
private void runInternal() {
|
||||
mSpiderDen = new SpiderDen(mGalleryInfo);
|
||||
mSpiderDen.setMode(mMode);
|
||||
|
||||
// Get EhConfig
|
||||
EhConfig config = Settings.getEhConfig().clone();
|
||||
config.previewSize = EhConfig.PREVIEW_SIZE_NORMAL;
|
||||
|
||||
@@ -207,7 +207,7 @@ public class GalleryActivity extends TrackedActivity
|
||||
|
||||
mGalleryView = new GalleryView(this, new GalleryAdapter(), this,
|
||||
Settings.getReadingDirection(), Settings.getPageScaling(),
|
||||
Settings.getStartPosition());
|
||||
Settings.getStartPosition(), mGalleryProvider.getStartPage());
|
||||
glRootView.setContentPane(mGalleryView);
|
||||
|
||||
// System UI helper
|
||||
@@ -494,6 +494,10 @@ public class GalleryActivity extends TrackedActivity
|
||||
|
||||
@Override
|
||||
public void onUpdateCurrentIndex(int index) {
|
||||
if (null != mGalleryProvider) {
|
||||
mGalleryProvider.putStartPage(index);
|
||||
}
|
||||
|
||||
NotifyTask task = mNotifyTaskPool.pop();
|
||||
if (task == null) {
|
||||
task = new NotifyTask();
|
||||
|
||||
Reference in new issue
Block a user