Skip to content

Commit 1ea46b1

Browse files
committed
chapter list improving ...
1 parent 794f360 commit 1ea46b1

11 files changed

Lines changed: 93 additions & 12 deletions

File tree

baseworld/src/com/tianxia/lib/baseworld/activity/AdapterActivity.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ public void setListView(int resId) {
4040
* @return
4141
*/
4242
protected abstract View getView(int position, View convertView);
43+
protected boolean isItemEnabled(int position) {
44+
return true;
45+
}
4346

4447
/**
4548
* the listView's item click event
@@ -72,6 +75,12 @@ public Adapter(Context context) {
7275
public int getCount() {
7376
return listData.size();
7477
}
78+
79+
@Override
80+
public boolean isEnabled(int position) {
81+
return AdapterActivity.this.isItemEnabled(position);
82+
}
83+
7584
@Override
7685
public View getView(int position, View convertView, ViewGroup parent) {
7786
return AdapterActivity.this.getView(position, convertView);
329 Bytes
Loading
1.35 KB
Loading

healthworld/res/layout/chapter_list_activity.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
<ListView android:id="@+id/chapter_list"
2222
android:layout_width="fill_parent"
2323
android:layout_height="fill_parent"
24-
android:divider="@drawable/app_divider_h_gray"
24+
android:layout_marginLeft="8dip"
25+
android:divider="@drawable/app_divider_h_dashed"
2526
android:cacheColorHint="#00000000">
2627
</ListView>
2728
</LinearLayout>

healthworld/res/layout/chapter_list_item.xml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,21 @@
22
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
33
android:layout_width="fill_parent"
44
android:layout_height="fill_parent"
5-
android:padding="8dip">
5+
android:padding="8dip"
6+
android:paddingTop="12dip"
7+
android:paddingBottom="12dip">
68
<TextView android:id="@+id/item_text"
79
android:layout_alignParentLeft="true"
810
android:layout_width="fill_parent"
911
android:layout_height="wrap_content"
10-
android:textSize="18dip"
12+
android:textSize="14dip"
1113
android:textColor="#192F06" />
1214
<ImageView android:id="@+id/item_arrow"
1315
android:layout_alignParentRight="true"
1416
android:layout_centerVertical="true"
1517
android:layout_width="wrap_content"
1618
android:layout_height="fill_parent"
1719
android:layout_marginLeft="6dip"
18-
android:layout_marginRight="10dip"
20+
android:layout_marginRight="6dip"
1921
android:src="@drawable/app_arrow"/>
2022
</RelativeLayout>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:layout_width="fill_parent"
4+
android:layout_height="fill_parent"
5+
android:padding="8dip">
6+
<TextView android:id="@+id/item_text"
7+
android:layout_alignParentLeft="true"
8+
android:layout_width="wrap_content"
9+
android:layout_height="wrap_content"
10+
android:paddingTop="8dip"
11+
android:drawableLeft="@drawable/chapter_section"
12+
android:textSize="18dip"
13+
android:textColor="#192F06" />
14+
</RelativeLayout>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
* Copyright (C) 2012 Jayfeng.
3+
*/
4+
5+
package com.tianxia.app.healthworld.digest;
6+
7+
import android.app.Activity;
8+
import android.os.Bundle;
9+
10+
public class ChapterDetailsActivity extends Activity{
11+
12+
@Override
13+
protected void onCreate(Bundle savedInstanceState) {
14+
super.onCreate(savedInstanceState);
15+
}
16+
}
17+
18+
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
* Copyright (C) 2012 Jayfeng.
3+
*/
4+
5+
package com.tianxia.app.healthworld.digest;
6+
7+
import android.view.View;
8+
import android.content.Context;
9+
import android.util.AttributeSet;
10+
11+
public class ChapterDetailsView extends View{
12+
13+
public ChapterDetailsView(Context context,AttributeSet attrs) {
14+
super(context, attrs);
15+
}
16+
}
17+
18+

healthworld/src/com/tianxia/app/healthworld/digest/ChapterListActivity.java

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public void onSuccess(String result){
7979

8080
@Override
8181
public void onFailure(Throwable arg0) {
82-
System.out.println("fail -----------------------------");
82+
//System.out.println("fail -----------------------------");
8383
//mAppLoadingProgressBar.setVisibility(View.INVISIBLE);
8484
//mAppLoadingTextView.setText(R.string.app_loading_fail);
8585
listView.setAdapter(null);
@@ -99,8 +99,9 @@ private void showChapterList(String result) {
9999
chapterInfo = new ChapterInfo();
100100
chapterInfo.title = chapterList.getJSONObject(i).optString("title");
101101
chapterInfo.url = chapterList.getJSONObject(i).optString("url");
102+
chapterInfo.level = 1;
102103
listData.add(chapterInfo);
103-
chapterInfo.subChapters = recurseChapters(chapterList.getJSONObject(i).optJSONArray("subChapters"));
104+
chapterInfo.subChapters = recurseChapters(chapterList.getJSONObject(i).optJSONArray("subChapters"), chapterInfo.level + 1);
104105
}
105106

106107
adapter = new Adapter(ChapterListActivity.this);
@@ -111,7 +112,7 @@ private void showChapterList(String result) {
111112
}
112113
}
113114

114-
private List<ChapterInfo> recurseChapters(JSONArray jsonarray) {
115+
private List<ChapterInfo> recurseChapters(JSONArray jsonarray, int level) {
115116
List<ChapterInfo> result = null;
116117
if (jsonarray == null || jsonarray.length() == 0) {
117118
return result;
@@ -123,7 +124,8 @@ private List<ChapterInfo> recurseChapters(JSONArray jsonarray) {
123124
try {
124125
chapterInfo.title = jsonarray.getJSONObject(i).optString("title");
125126
chapterInfo.url = jsonarray.getJSONObject(i).optString("url");
126-
chapterInfo.subChapters = recurseChapters(jsonarray.getJSONObject(i).optJSONArray("subChapters"));
127+
chapterInfo.level = level;
128+
chapterInfo.subChapters = recurseChapters(jsonarray.getJSONObject(i).optJSONArray("subChapters"), level + 1);
127129
result.add(chapterInfo);
128130
listData.add(chapterInfo);
129131
} catch (JSONException e) {
@@ -135,15 +137,29 @@ private List<ChapterInfo> recurseChapters(JSONArray jsonarray) {
135137

136138
protected View getView(int position, View convertView) {
137139
View view = convertView;
138-
if (view == null) {
140+
if (listData.get(position).level == 1 && listData.get(position).subChapters != null) {
141+
view = LayoutInflater.from(getApplicationContext()).inflate(R.layout.chapter_section_list_item, null);
142+
} else {
139143
view = LayoutInflater.from(getApplicationContext()).inflate(R.layout.chapter_list_item, null);
140144
}
141145

142146
mItemTextView = (TextView) view.findViewById(R.id.item_text);
143-
mItemTextView.setText(listData.get(position).title);
147+
if (listData.get(position).subChapters == null) {
148+
mItemTextView.setText(" ❂ " + listData.get(position).title);
149+
} else {
150+
mItemTextView.setText(" " + listData.get(position).title);
151+
}
144152
return view;
145153
}
146154

155+
protected boolean isItemEnabled(int position) {
156+
if (listData.get(position).level == 1 && listData.get(position).subChapters != null) {
157+
return false;
158+
} else {
159+
return true;
160+
}
161+
}
162+
147163
protected void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
148164
//toko
149165
}

healthworld/src/com/tianxia/app/healthworld/infomation/InfomationTabActivity.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,11 @@ protected View getView(int position, View convertView) {
200200
try {
201201
Date date = mSinaWeiboDateFormat.parse(dateString);
202202
int second = (int)(System.currentTimeMillis() - date.getTime())/1000;
203-
if (second > 59 && second < 1800) {
203+
if (second > 3600 && second <= 86400 ) {
204+
mItemDate.setText(second/3600 + "小时前");
205+
} else if (second > 59 && second <= 3600) {
204206
mItemDate.setText(second/60 + "分钟前");
205-
} else if (second < 59) {
207+
} else if (second <= 59) {
206208
mItemDate.setText(second + "秒前");
207209
} else {
208210
mItemDate.setText(mSimpleDateFormat.format(date));

0 commit comments

Comments
 (0)