修正图片多次加载错误
This commit is contained in:
1 parent
626f7141e9
commit
ab4b4ad598
7 files changed
+50
-11
No files matched your search
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -24,6 +24,7 @@ import android.widget.AdapterView.OnItemLongClickListener;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.hippo.ehviewer.BeautifyScreen;
|
||||
import com.hippo.ehviewer.ImageLoadManager;
|
||||
import com.hippo.ehviewer.ListMangaDetail;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.dialog.DialogBuilder;
|
||||
@@ -36,6 +37,7 @@ import com.hippo.ehviewer.util.Favourite;
|
||||
import com.hippo.ehviewer.util.Ui;
|
||||
import com.hippo.ehviewer.view.AlertButton;
|
||||
import com.hippo.ehviewer.view.OlImageView;
|
||||
import com.hippo.ehviewer.widget.LoadImageView;
|
||||
|
||||
public class FavouriteActivity extends Activity{
|
||||
private static final String TAG = "FavouriteActivity";
|
||||
@@ -44,6 +46,8 @@ public class FavouriteActivity extends Activity{
|
||||
private ArrayList<ListMangaDetail> mFavouriteLmd;
|
||||
private int longClickItemIndex;
|
||||
|
||||
private ImageLoadManager mImageLoadManager;
|
||||
|
||||
private DownloadServiceConnection mServiceConn = new DownloadServiceConnection();
|
||||
|
||||
// List item long click dialog
|
||||
@@ -111,12 +115,10 @@ public class FavouriteActivity extends Activity{
|
||||
if (convertView == null)
|
||||
convertView = mInflater.inflate(R.layout.list_item, null);
|
||||
|
||||
OlImageView thumb = (OlImageView)convertView.findViewById(R.id.cover);
|
||||
LoadImageView thumb = (LoadImageView)convertView.findViewById(R.id.cover);
|
||||
if (!lmd.gid.equals(thumb.getKey())) {
|
||||
thumb.setUrl(lmd.thumb);
|
||||
thumb.setKey(lmd.gid);
|
||||
thumb.setCache(Cache.memoryCache, Cache.cpCache);
|
||||
thumb.loadFromCache();
|
||||
thumb.setLoadInfo(lmd.thumb, lmd.gid);
|
||||
mImageLoadManager.add(thumb, true);
|
||||
|
||||
// Set manga name
|
||||
TextView name = (TextView) convertView.findViewById(R.id.name);
|
||||
@@ -169,6 +171,8 @@ public class FavouriteActivity extends Activity{
|
||||
|
||||
longClickDialog = setLongClickDialog();
|
||||
|
||||
mImageLoadManager = new ImageLoadManager(getApplicationContext(), Cache.memoryCache, Cache.cpCache);
|
||||
|
||||
getActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
|
||||
// For colourfy the activity
|
||||
|
||||
@@ -968,11 +968,21 @@ public class MangaListActivity extends Activity {
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
ListMangaDetail lmd= lmdArray.get(position);
|
||||
if (convertView == null)
|
||||
boolean isNew = false;
|
||||
if (convertView == null) {
|
||||
isNew = true;
|
||||
convertView = mInflater.inflate(R.layout.list_item, null);
|
||||
|
||||
}
|
||||
LoadImageView thumb = (LoadImageView)convertView.findViewById(R.id.cover);
|
||||
if (!lmd.gid.equals(thumb.getKey())) {
|
||||
if (!isNew) {
|
||||
// TODO default index = 0, should get it id
|
||||
((ViewGroup)convertView).removeView(thumb);
|
||||
ViewGroup.LayoutParams lp = thumb.getLayoutParams();
|
||||
thumb = new LoadImageView(MangaListActivity.this);
|
||||
thumb.setId(R.id.cover);
|
||||
((ViewGroup)convertView).addView(thumb, 0, lp);
|
||||
}
|
||||
thumb.setLoadInfo(lmd.thumb, lmd.gid);
|
||||
mImageLoadManager.add(thumb, false);
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.hippo.ehviewer.network;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
@@ -45,6 +47,8 @@ public class HttpHelper {
|
||||
LruCache<String, Bitmap> memoryCache,
|
||||
DiskCache diskCache, boolean getImage) {
|
||||
HttpURLConnection conn = null;
|
||||
ByteArrayOutputStream baos = null;
|
||||
InputStream is = null;
|
||||
Bitmap bitmap = null;
|
||||
try {
|
||||
Log.d(TAG, "Get Image " + urlStr);
|
||||
@@ -54,7 +58,7 @@ public class HttpHelper {
|
||||
conn.setConnectTimeout(DEFAULT_TIMEOUT);
|
||||
conn.setReadTimeout(DEFAULT_TIMEOUT);
|
||||
conn.connect();
|
||||
InputStream is = conn.getInputStream();
|
||||
is = conn.getInputStream();
|
||||
|
||||
if (diskCache == null) {
|
||||
if (getImage
|
||||
@@ -63,15 +67,28 @@ public class HttpHelper {
|
||||
memoryCache.put(key, bitmap);
|
||||
}
|
||||
} else {
|
||||
diskCache.put(key, is);
|
||||
if (memoryCache != null || getImage) {
|
||||
Bitmap bmp = (Bitmap)diskCache.get(key, Util.BITMAP);
|
||||
boolean twice = memoryCache != null || getImage;
|
||||
if (twice) {
|
||||
baos = new ByteArrayOutputStream();
|
||||
Util.copy(is, baos);
|
||||
byte[] bytes = baos.toByteArray();
|
||||
// To disk cache
|
||||
is = new ByteArrayInputStream(bytes);
|
||||
diskCache.put(key, is);
|
||||
is.close();
|
||||
//
|
||||
is = new ByteArrayInputStream(bytes);
|
||||
Bitmap bmp = BitmapFactory.decodeStream(is, null, Ui.getBitmapOpt());
|
||||
if (bmp != null) {
|
||||
if (memoryCache != null)
|
||||
memoryCache.put(key, bmp);
|
||||
if (getImage)
|
||||
bitmap = bmp;
|
||||
}
|
||||
is.close();
|
||||
baos.close();
|
||||
} else {
|
||||
diskCache.put(key, is);
|
||||
}
|
||||
}
|
||||
} catch (MalformedURLException e) {
|
||||
@@ -87,6 +104,10 @@ public class HttpHelper {
|
||||
lastEMsgId = R.string.em_network_error;
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (baos != null)
|
||||
Util.closeStreamQuietly(baos);
|
||||
if (is != null)
|
||||
Util.closeStreamQuietly(is);
|
||||
if (conn != null)
|
||||
conn.disconnect();
|
||||
}
|
||||
|
||||
@@ -51,6 +51,10 @@ public class Util {
|
||||
}
|
||||
|
||||
public static void copy(InputStream is, OutputStream os) throws IOException {
|
||||
copy(is, os, 512 * 1024);
|
||||
}
|
||||
|
||||
public static void copy(InputStream is, OutputStream os, int size) throws IOException {
|
||||
byte[] buffer = new byte[512 * 1024];
|
||||
int bytesRead;
|
||||
while((bytesRead = is.read(buffer)) !=-1)
|
||||
|
||||
Reference in new issue
Block a user