From 6f93bb5b88f6f16ecb082dd6b8699bd7208f58f1 Mon Sep 17 00:00:00 2001 From: seven332 Date: Sun, 15 Jun 2014 22:42:56 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=83=AD=E9=97=A8=E7=82=B9?= =?UTF-8?q?=E5=87=BB=E6=95=B0=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- res/layout/list_item.xml | 12 +++- .../hippo/ehviewer/data/GalleryPopular.java | 65 +++++++++++++++++++ src/com/hippo/ehviewer/ehclient/EhClient.java | 4 +- .../ehviewer/ui/AbstractGalleryActivity.java | 27 ++++++++ 4 files changed, 106 insertions(+), 2 deletions(-) create mode 100644 src/com/hippo/ehviewer/data/GalleryPopular.java diff --git a/res/layout/list_item.xml b/res/layout/list_item.xml index 85c553a88..75cd49c18 100644 --- a/res/layout/list_item.xml +++ b/res/layout/list_item.xml @@ -33,7 +33,7 @@ android:layout_toRightOf="@id/cover" android:layout_marginLeft="8.0dip" android:layout_marginTop="1.0dip" - android:layout_marginRight="4.0dip" /> + android:layout_marginRight="32.0dip" /> + + \ No newline at end of file diff --git a/src/com/hippo/ehviewer/data/GalleryPopular.java b/src/com/hippo/ehviewer/data/GalleryPopular.java new file mode 100644 index 000000000..d8b84a3d8 --- /dev/null +++ b/src/com/hippo/ehviewer/data/GalleryPopular.java @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2014 Hippo Seven + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.hippo.ehviewer.data; + +import android.os.Parcel; +import android.os.Parcelable; + +public class GalleryPopular extends GalleryInfo { + public long count; + + public static final Parcelable.Creator CREATOR = + new Parcelable.Creator() { + @Override + public GalleryPopular createFromParcel(Parcel source) { + GalleryPopular p = new GalleryPopular(); + p.gid = source.readInt(); + p.token = source.readString(); + p.title = source.readString(); + p.posted = source.readString(); + p.category = source.readInt(); + p.thumb = source.readString(); + p.uploader = source.readString(); + p.rating = source.readFloat(); + p.count = source.readLong(); + return p; + } + + @Override + public GalleryPopular[] newArray(int size) { + return new GalleryPopular[size]; + } + }; + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(Parcel dest, int flags) { + dest.writeInt(gid); + dest.writeString(token); + dest.writeString(title); + dest.writeString(posted); + dest.writeInt(category); + dest.writeString(thumb); + dest.writeString(uploader); + dest.writeFloat(rating); + dest.writeLong(count); + } +} diff --git a/src/com/hippo/ehviewer/ehclient/EhClient.java b/src/com/hippo/ehviewer/ehclient/EhClient.java index 350613f14..78be7ca0d 100644 --- a/src/com/hippo/ehviewer/ehclient/EhClient.java +++ b/src/com/hippo/ehviewer/ehclient/EhClient.java @@ -45,6 +45,7 @@ import com.hippo.ehviewer.R; import com.hippo.ehviewer.data.Comment; import com.hippo.ehviewer.data.GalleryDetail; import com.hippo.ehviewer.data.GalleryInfo; +import com.hippo.ehviewer.data.GalleryPopular; import com.hippo.ehviewer.data.PreviewList; import com.hippo.ehviewer.gallery.data.ImageSet; import com.hippo.ehviewer.network.Downloader; @@ -1813,7 +1814,7 @@ public class EhClient { JSONArray ja = js.getJSONArray("galleries"); for (int i = 0; i < ja.length(); i++) { JSONObject j = ja.getJSONObject(i); - GalleryInfo gi = new GalleryInfo(); + GalleryPopular gi = new GalleryPopular(); gi.gid = j.getInt("gid"); gi.token = j.getString("token"); gi.title = StringEscapeUtils.unescapeHtml4(j.getString("title")); @@ -1822,6 +1823,7 @@ public class EhClient { gi.category = getType(j.getString("category")); gi.uploader = j.getString("uploader"); gi.rating = Float.parseFloat(j.getString("rating")); + gi.count = j.getLong("count"); gis.add(gi); } diff --git a/src/com/hippo/ehviewer/ui/AbstractGalleryActivity.java b/src/com/hippo/ehviewer/ui/AbstractGalleryActivity.java index 9f71c6379..910420f15 100644 --- a/src/com/hippo/ehviewer/ui/AbstractGalleryActivity.java +++ b/src/com/hippo/ehviewer/ui/AbstractGalleryActivity.java @@ -23,6 +23,7 @@ import com.hippo.ehviewer.AppContext; import com.hippo.ehviewer.ImageGeterManager; import com.hippo.ehviewer.R; import com.hippo.ehviewer.data.GalleryInfo; +import com.hippo.ehviewer.data.GalleryPopular; import com.hippo.ehviewer.ehclient.EhClient; import com.hippo.ehviewer.util.Cache; import com.hippo.ehviewer.util.Ui; @@ -399,6 +400,23 @@ public abstract class AbstractGalleryActivity extends AbstractSlidingActivity public long getItemId(int position) { return position; } + + public String getCountStr(long count) { + String str = null; + if (count < 0) { + str = "0"; + } else if (count < 1000) { + str = String.valueOf(count); + } else if (count < 1E10) { + double p = Math.log10(count); + int pInt = (int)p; + str = Math.round(count / Math.pow(10, pInt)) + "E" + pInt; + } else { + str = "***"; + } + return str; + } + @Override public View getView(int position, View convertView, ViewGroup parent) { GalleryInfo gi= mGiList.get(position); @@ -448,6 +466,15 @@ public abstract class AbstractGalleryActivity extends AbstractSlidingActivity // set posted TextView posted = (TextView) convertView.findViewById(R.id.posted); posted.setText(gi.posted); + + // Show count if possible + TextView count = (TextView) convertView.findViewById(R.id.count); + if (gi instanceof GalleryPopular) { + count.setVisibility(View.VISIBLE); + count.setText(getCountStr(((GalleryPopular)gi).count)); + } else { + count.setVisibility(View.GONE); + } } return convertView; }