添加热门点击数显示

This commit is contained in:
seven332 committed 2014-06-15 22:42:56 +08:00
1 parent 1d2978952b
commit 6f93bb5b88
4 files changed
+106 -2

No files matched your search

+11 -1
View File
@@ -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" />
<TextView
android:id="@+id/uploader"
@@ -85,4 +85,14 @@
android:layout_marginRight="4.0dip"
android:paddingBottom="1.0dp" />
<TextView
android:id="@+id/count"
style="@style/CardSubtitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginTop="1.0dip"
android:layout_marginRight="5.0dip"
android:visibility="gone" />
</RelativeLayout>
@@ -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<GalleryPopular> CREATOR =
new Parcelable.Creator<GalleryPopular>() {
@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);
}
}
@@ -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);
}
@@ -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;
}