Add GalleryProvider.cancelRequest(int), fix SpiderQueen.request(int, boolean)
This commit is contained in:
1 parent
efdb488781
commit
feb9bbadc6
9 files changed
+144
-61
No files matched your search
@@ -22,6 +22,7 @@ import android.util.Log;
|
||||
|
||||
import com.hippo.ehviewer.GetText;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.gallery.gl.GalleryPageView;
|
||||
import com.hippo.image.Image;
|
||||
import com.hippo.yorozuya.PriorityThread;
|
||||
import com.hippo.yorozuya.StringUtils;
|
||||
@@ -47,6 +48,7 @@ public class ZipGalleryProvider extends GalleryProvider implements Runnable {
|
||||
|
||||
private final File mFile;
|
||||
private final Stack<Integer> mRequests = new Stack<>();
|
||||
private final AtomicInteger mDecodingIndex = new AtomicInteger(GalleryPageView.INVALID_INDEX);
|
||||
@Nullable
|
||||
private Thread mBgThread;
|
||||
private volatile int mSize = STATE_WAIT;
|
||||
@@ -83,12 +85,21 @@ public class ZipGalleryProvider extends GalleryProvider implements Runnable {
|
||||
@Override
|
||||
public void request(int index) {
|
||||
synchronized (mRequests) {
|
||||
mRequests.add(index);
|
||||
mRequests.notify();
|
||||
if (!mRequests.contains(index) && index != mDecodingIndex.get()) {
|
||||
mRequests.add(index);
|
||||
mRequests.notify();
|
||||
}
|
||||
}
|
||||
notifyPageWait(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cancelRequest(int index) {
|
||||
synchronized (mRequests) {
|
||||
mRequests.remove(Integer.valueOf(index));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getError() {
|
||||
return mError;
|
||||
@@ -150,10 +161,12 @@ public class ZipGalleryProvider extends GalleryProvider implements Runnable {
|
||||
continue;
|
||||
}
|
||||
index = mRequests.pop();
|
||||
mDecodingIndex.lazySet(index);
|
||||
}
|
||||
|
||||
// Check index valid
|
||||
if (index < 0 || index >= filenames.size()) {
|
||||
mDecodingIndex.lazySet(GalleryPageView.INVALID_INDEX);
|
||||
notifyPageFailed(index, GetText.getString(R.string.error_out_of_range));
|
||||
continue;
|
||||
}
|
||||
@@ -163,15 +176,18 @@ public class ZipGalleryProvider extends GalleryProvider implements Runnable {
|
||||
if (zipEntry != null) {
|
||||
InputStream is = zipFile.getInputStream(zipEntry);
|
||||
Image image = Image.decode(is, false);
|
||||
mDecodingIndex.lazySet(GalleryPageView.INVALID_INDEX);
|
||||
if (image != null) {
|
||||
notifyPageSucceed(index, image);
|
||||
} else {
|
||||
notifyPageFailed(index, GetText.getString(R.string.error_decoding_failed));
|
||||
}
|
||||
} else {
|
||||
mDecodingIndex.lazySet(GalleryPageView.INVALID_INDEX);
|
||||
notifyPageFailed(index, GetText.getString(R.string.error_reading_failed));
|
||||
}
|
||||
} catch (IOException e) {
|
||||
mDecodingIndex.lazySet(GalleryPageView.INVALID_INDEX);
|
||||
notifyPageFailed(index, GetText.getString(R.string.error_reading_failed));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user