diff --git a/bin/EhViewer.apk b/bin/EhViewer.apk index f24148b8a..bbc6c9fc3 100644 Binary files a/bin/EhViewer.apk and b/bin/EhViewer.apk differ diff --git a/bin/classes.dex b/bin/classes.dex index 339398c2b..3ee6635f6 100644 Binary files a/bin/classes.dex and b/bin/classes.dex differ diff --git a/bin/resources.ap_ b/bin/resources.ap_ index e913ef0ee..17002ea17 100644 Binary files a/bin/resources.ap_ and b/bin/resources.ap_ differ diff --git a/src/com/hippo/ehviewer/activity/FavouriteActivity.java b/src/com/hippo/ehviewer/activity/FavouriteActivity.java index 20106a773..23adca338 100644 --- a/src/com/hippo/ehviewer/activity/FavouriteActivity.java +++ b/src/com/hippo/ehviewer/activity/FavouriteActivity.java @@ -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 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 diff --git a/src/com/hippo/ehviewer/activity/MangaListActivity.java b/src/com/hippo/ehviewer/activity/MangaListActivity.java index 829b98930..47f6bceac 100644 --- a/src/com/hippo/ehviewer/activity/MangaListActivity.java +++ b/src/com/hippo/ehviewer/activity/MangaListActivity.java @@ -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); diff --git a/src/com/hippo/ehviewer/network/HttpHelper.java b/src/com/hippo/ehviewer/network/HttpHelper.java index 0da2d1b18..97c45bbdf 100644 --- a/src/com/hippo/ehviewer/network/HttpHelper.java +++ b/src/com/hippo/ehviewer/network/HttpHelper.java @@ -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 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(); } diff --git a/src/com/hippo/ehviewer/util/Util.java b/src/com/hippo/ehviewer/util/Util.java index 9068d8aed..9954948b7 100644 --- a/src/com/hippo/ehviewer/util/Util.java +++ b/src/com/hippo/ehviewer/util/Util.java @@ -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)