diff --git a/AndroidManifest.xml b/AndroidManifest.xml index eeed58b5e..da29d269f 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -1,8 +1,8 @@ + android:versionCode="15" + android:versionName="0.4.0" > + android:versionCode="15" + android:versionName="0.4.0" > Google 七牛 + 够快 添加标签 diff --git a/res/values/array.xml b/res/values/array.xml index 5972d1fc1..a967a9228 100644 --- a/res/values/array.xml +++ b/res/values/array.xml @@ -78,11 +78,13 @@ @string/update_server_google @string/update_server_qiniu + @string/update_server_gokuai 0 1 + 2 diff --git a/res/values/strings.xml b/res/values/strings.xml index 13dd8335a..22ba154bb 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -162,6 +162,7 @@ Google Qiniu + Gokuai Add tag diff --git a/src/com/hippo/ehviewer/network/HttpHelper.java b/src/com/hippo/ehviewer/network/HttpHelper.java index a1d44f3db..bce593da2 100644 --- a/src/com/hippo/ehviewer/network/HttpHelper.java +++ b/src/com/hippo/ehviewer/network/HttpHelper.java @@ -93,7 +93,13 @@ public class HttpHelper { String encoding = conn.getContentEncoding(); if (encoding != null && encoding.equals("gzip")) is = new GZIPInputStream(is); - baos = new ByteArrayOutputStream(); + + int length = conn.getContentLength(); + if (length >= 0) + baos = new ByteArrayOutputStream(length); + else + baos = new ByteArrayOutputStream(); + Util.copy(is, baos, Constant.BUFFER_SIZE); // Get charset diff --git a/src/com/hippo/ehviewer/service/DownloadService.java b/src/com/hippo/ehviewer/service/DownloadService.java index 137d6cf0b..ea31d9f64 100644 --- a/src/com/hippo/ehviewer/service/DownloadService.java +++ b/src/com/hippo/ehviewer/service/DownloadService.java @@ -11,6 +11,7 @@ import com.hippo.ehviewer.util.Download; import com.hippo.ehviewer.util.EhClient; import com.hippo.ehviewer.util.EhClient.DownloadMangaManager; +import android.app.Notification; import android.app.NotificationManager; import android.app.PendingIntent; import android.app.Service; @@ -18,7 +19,7 @@ import android.content.Context; import android.content.Intent; import android.os.Binder; import android.os.IBinder; -import android.support.v4.app.NotificationCompat; + import com.hippo.ehviewer.util.Log; public class DownloadService extends Service { @@ -34,7 +35,6 @@ public class DownloadService extends Service { private ServiceBinder mBinder = null; private NotificationManager mNotifyManager; - private NotificationCompat.Builder mBuilder; private DownloadMangaManager downloadMangaManager; @@ -47,12 +47,6 @@ public class DownloadService extends Service { mBinder = new ServiceBinder(); mNotifyManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); - mBuilder = new NotificationCompat.Builder(this); - mBuilder.setSmallIcon(R.drawable.ic_launcher); - - Intent intent = new Intent(DownloadService.this,DownloadActivity.class); - PendingIntent pendingIntent = PendingIntent.getActivity(DownloadService.this, 1, intent, PendingIntent.FLAG_UPDATE_CURRENT); - mBuilder.setContentIntent(pendingIntent); downloadMangaManager = mAppContext.getEhClient().new DownloadMangaManager(); @@ -60,10 +54,12 @@ public class DownloadService extends Service { downloadMangaManager.setOnDownloadMangaListener(new EhClient.OnDownloadMangaListener() { @Override public void onDownloadMangaAllStart() { - mBuilder.setContentTitle(getString(R.string.start_download_task)) + Notification.Builder builder = new Notification.Builder(getApplicationContext()); + setNotification(builder); + builder.setContentTitle(getString(R.string.start_download_task)) .setContentText(null) - .setProgress(0, 0, true).setOngoing(true).setAutoCancel(false);; - mNotifyManager.notify(DOWNLOAD_NOTIFY_ID, mBuilder.build()); + .setProgress(0, 0, true).setOngoing(true).setAutoCancel(false); + mNotifyManager.notify(DOWNLOAD_NOTIFY_ID, builder.getNotification()); } @Override @@ -78,11 +74,13 @@ public class DownloadService extends Service { if (di == null) mNotifyManager.cancel(DOWNLOAD_NOTIFY_ID); else { - mBuilder.setContentTitle(getString(R.string.downloading) + Notification.Builder builder = new Notification.Builder(getApplicationContext()); + setNotification(builder); + builder.setContentTitle(getString(R.string.downloading) + " " + di.title) .setContentText(null) - .setProgress(0, 0, true).setOngoing(true).setAutoCancel(false);; - mNotifyManager.notify(DOWNLOAD_NOTIFY_ID, mBuilder.build()); + .setProgress(0, 0, true).setOngoing(true).setAutoCancel(false); + mNotifyManager.notify(DOWNLOAD_NOTIFY_ID, builder.getNotification()); } } @@ -92,12 +90,14 @@ public class DownloadService extends Service { if (di == null) mNotifyManager.cancel(DOWNLOAD_NOTIFY_ID); else { - mBuilder.setContentTitle(getString(R.string.downloading) + Notification.Builder builder = new Notification.Builder(getApplicationContext()); + setNotification(builder); + builder.setContentTitle(getString(R.string.downloading) + " " + di.title) .setContentText(startIndex + " / " + pageSum) .setProgress(pageSum, startIndex, false).setOngoing(true) .setAutoCancel(false); - mNotifyManager.notify(DOWNLOAD_NOTIFY_ID, mBuilder.build()); + mNotifyManager.notify(DOWNLOAD_NOTIFY_ID, builder.getNotification()); mNotifyManager.cancel(Integer.parseInt(id)); } } @@ -118,9 +118,11 @@ public class DownloadService extends Service { DownloadInfo di = Download.get(id); if (di != null) mesg += Download.get(id).title; - mBuilder.setContentTitle(mesg); - mBuilder.setContentText(null).setProgress(0, 0, false).setOngoing(false); - mNotifyManager.notify(Integer.parseInt(id), mBuilder.build()); + Notification.Builder builder = new Notification.Builder(getApplicationContext()); + setNotification(builder); + builder.setContentTitle(mesg); + builder.setContentText(null).setProgress(0, 0, false).setOngoing(false); + mNotifyManager.notify(Integer.parseInt(id), builder.getNotification()); } @Override @@ -129,12 +131,14 @@ public class DownloadService extends Service { if (di == null) mNotifyManager.cancel(DOWNLOAD_NOTIFY_ID); else { - mBuilder.setContentTitle(getString(R.string.downloading) + Notification.Builder builder = new Notification.Builder(getApplicationContext()); + setNotification(builder); + builder.setContentTitle(getString(R.string.downloading) + " " + di.title) .setContentText(index + " / " + pageSum) .setProgress(pageSum, index, false).setOngoing(true) .setAutoCancel(false); - mNotifyManager.notify(DOWNLOAD_NOTIFY_ID, mBuilder.build()); + mNotifyManager.notify(DOWNLOAD_NOTIFY_ID, builder.getNotification()); } } @@ -145,8 +149,17 @@ public class DownloadService extends Service { } }); - } - + } + + private void setNotification(Notification.Builder builder) { + + builder.setSmallIcon(R.drawable.ic_launcher); + + Intent intent = new Intent(DownloadService.this,DownloadActivity.class); + PendingIntent pendingIntent = PendingIntent.getActivity(DownloadService.this, 1, intent, PendingIntent.FLAG_UPDATE_CURRENT); + builder.setContentIntent(pendingIntent); + } + @Override public int onStartCommand(Intent intent, int flags, int startId) { Log.d(TAG, "Service onStartCommand"); @@ -170,7 +183,6 @@ public class DownloadService extends Service { mBinder = null; mNotifyManager = null; - mBuilder = null; } public void add(String gid, String thumb, String detailUrlStr, String title) { diff --git a/src/com/hippo/ehviewer/util/Config.java b/src/com/hippo/ehviewer/util/Config.java index 04a9e32ee..b9f2f8612 100644 --- a/src/com/hippo/ehviewer/util/Config.java +++ b/src/com/hippo/ehviewer/util/Config.java @@ -202,11 +202,11 @@ public class Config { mConfigPre.edit().putString(UPDATE_SERVER, UPDATE_SERVER_DEFAULT) .apply(); } - switch (value) { case 1: return "qiniu"; - + case 2: + return "gokuai"; case 0: default: return "google"; diff --git a/src/com/hippo/ehviewer/util/EhClient.java b/src/com/hippo/ehviewer/util/EhClient.java index eb267b49d..3662f8898 100644 --- a/src/com/hippo/ehviewer/util/EhClient.java +++ b/src/com/hippo/ehviewer/util/EhClient.java @@ -1002,6 +1002,7 @@ public class EhClient { Log.d(TAG, "Download image " + url); HttpURLConnection conn = null; + ByteArrayOutputStream baos = null; try { URL url = new URL(this.url); conn = (HttpURLConnection) url.openConnection(); @@ -1010,7 +1011,12 @@ public class EhClient { conn.connect(); InputStream is = conn.getInputStream(); if (diskCache != null) { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); + + int length = conn.getContentLength(); + if (length >= 0) + baos = new ByteArrayOutputStream(length); + else + baos = new ByteArrayOutputStream(); Util.copy(is, baos); byte[] bytes = baos.toByteArray(); // To disk cache @@ -1057,6 +1063,8 @@ public class EhClient { } finally { if (conn != null) conn.disconnect(); + if (baos != null) + Util.closeStreamQuietly(baos); } sendMessage(res, errorMessageId); }