Skip to content

Commit 345d2d0

Browse files
committed
解决FeedDetail数据库读取bug
1 parent 148ef6d commit 345d2d0

File tree

11 files changed

+174
-147
lines changed

11 files changed

+174
-147
lines changed

AndroidManifest.xml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,17 @@
77
<uses-sdk
88
android:minSdkVersion="8"
99
android:targetSdkVersion="18" />
10-
10+
11+
<uses-permission android:name="android.permission.INTERNET"/>
12+
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
13+
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>
14+
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
15+
16+
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> <!-- 获取mac地址作为用户的备用唯一标识 -->
17+
<uses-permission android:name="android.permission.READ_PHONE_STATE" /> <!-- 获取用户手机的IMEI,用来唯一的标识用户。 -->
18+
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <!-- 用于评论模块分享位置信息 -->
19+
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /><!-- 用于评论模块分享位置信息 -->
20+
1121
<application
1222
android:allowBackup="true"
1323
android:icon="@drawable/ic_launcher"
@@ -22,7 +32,7 @@
2232
</intent-filter>
2333
</activity>
2434
<activity android:name="com.dreamteam.app.ui.Main"></activity>
25-
<activity android:name="GuideActivity"></activity>
35+
<activity android:name="com.dreamteam.app.ui.GuideActivity"></activity>
2636
<activity android:name="com.dreamteam.app.ui.FeedCategory"></activity>
2737
<activity android:name="com.dreamteam.app.ui.CategoryDetail"></activity>
2838
</application>

bin/AndroidManifest.xml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,17 @@
77
<uses-sdk
88
android:minSdkVersion="8"
99
android:targetSdkVersion="18" />
10-
10+
11+
<uses-permission android:name="android.permission.INTERNET"/>
12+
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
13+
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>
14+
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
15+
16+
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> <!-- 获取mac地址作为用户的备用唯一标识 -->
17+
<uses-permission android:name="android.permission.READ_PHONE_STATE" /> <!-- 获取用户手机的IMEI,用来唯一的标识用户。 -->
18+
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <!-- 用于评论模块分享位置信息 -->
19+
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /><!-- 用于评论模块分享位置信息 -->
20+
1121
<application
1222
android:allowBackup="true"
1323
android:icon="@drawable/ic_launcher"
@@ -22,7 +32,7 @@
2232
</intent-filter>
2333
</activity>
2434
<activity android:name="com.dreamteam.app.ui.Main"></activity>
25-
<activity android:name="GuideActivity"></activity>
35+
<activity android:name="com.dreamteam.app.ui.GuideActivity"></activity>
2636
<activity android:name="com.dreamteam.app.ui.FeedCategory"></activity>
2737
<activity android:name="com.dreamteam.app.ui.CategoryDetail"></activity>
2838
</application>

res/values/strings.xml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,17 @@
1313
<item>名人博客</item>
1414
<item>外语资讯</item>
1515
<item>娱乐八卦</item>
16-
</string-array>
16+
</string-array>
17+
18+
<string-array name="feed_category_en">
19+
<item>news</item>
20+
<item>science</item>
21+
<item>cultule</item>
22+
<item>sports</item>
23+
<item>manga</item>
24+
<item>blog</item>
25+
<item>english</item>
26+
<item>fun</item>
27+
</string-array>
28+
1729
</resources>

src/com/dreamteam/app/adapter/CategoryDetailAdapter.java

Lines changed: 59 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
import android.widget.ImageButton;
1616
import android.widget.TextView;
1717

18+
import com.dreamteam.app.db.DBHelper;
1819
import com.dreamteam.app.db.FeedDBHelper;
1920
import com.dreamteam.app.entity.Feed;
20-
import com.dreamteam.app.entity.Section;
2121
import com.dreateam.app.ui.R;
2222

2323
/**
@@ -29,22 +29,16 @@ public class CategoryDetailAdapter extends BaseAdapter
2929
{
3030
public static final String tag = "CategoryDetailAdapter";
3131
private LayoutInflater inflater;
32-
3332
private Context context;
34-
3533
private ArrayList<Feed> feeds = new ArrayList<Feed>();
36-
private String tableName;
37-
34+
private String tableName;//所分类对应的表名
35+
public static final String SECTION_TABLE_NAME = "section";
3836

39-
public CategoryDetailAdapter(Context context)
40-
{
41-
this.context = context;
42-
}
43-
44-
public CategoryDetailAdapter(Context context, ArrayList<Feed> feeds)
37+
public CategoryDetailAdapter(Context context, ArrayList<Feed> feeds, String tableName)
4538
{
4639
this.context = context;
4740
this.feeds = feeds;
41+
this.tableName = tableName;
4842
}
4943

5044
public void updateData(ArrayList<Feed> feeds)
@@ -60,15 +54,15 @@ public int getCount()
6054
}
6155

6256
@Override
63-
public Object getItem(int arg0)
57+
public Object getItem(int position)
6458
{
65-
return null;
59+
return feeds.get(position);
6660
}
6761

6862
@Override
69-
public long getItemId(int arg0)
63+
public long getItemId(int id)
7064
{
71-
return 0;
65+
return id;
7266
}
7367

7468
@Override
@@ -81,49 +75,70 @@ public View getView(final int position, View convertView, ViewGroup parent)
8175
inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
8276
convertView = inflater.inflate(R.layout.category_detail_item, null);
8377
holder = new ViewHolder();
84-
holder.FEED_TITLE = (TextView) convertView.findViewById(R.id.category_detail_feed_title);
85-
holder.ADD_BTN = (ImageButton) convertView.findViewById(R.id.category_detail_add);
86-
holder.ADD_BTN.setOnClickListener(new OnClickListener()
78+
holder.feedTitle = (TextView) convertView.findViewById(R.id.category_detail_feed_title);
79+
holder.addBtn = (ImageButton) convertView.findViewById(R.id.category_detail_add);
80+
holder.addBtn.setOnClickListener(new OnClickListener()
8781
{
88-
/* (non-Javadoc)
89-
* @see android.view.View.OnClickListener#onClick(android.view.View)
90-
*/
9182
@Override
9283
public void onClick(View v)
9384
{
94-
if(feeds.get(position).getSelectStatus() == 1)
85+
Feed feed = feeds.get(position);
86+
87+
//已经选中,取消选中状态
88+
if(feed.getSelectStatus() == 1)
89+
{
90+
//该变传入feeds
91+
feed.setSelectStatus(0);
92+
Bitmap bmp = BitmapFactory.decodeResource(context.getResources(),
93+
R.drawable.add);
94+
holder.addBtn.setImageBitmap(bmp);
95+
//删除section表中记录的数据
96+
DBHelper helper = new DBHelper(context, "reader.db", null, 1);
97+
SQLiteDatabase db = helper.getWritableDatabase();
98+
db.delete(SECTION_TABLE_NAME, "url=?", new String[]{feed.getUrl()});
99+
db.close();
100+
//更新feed.db中所对应表的状态为0
101+
FeedDBHelper helper_1 = new FeedDBHelper(context, "feed.db", null, 1);
102+
SQLiteDatabase db_1 = helper_1.getWritableDatabase();
103+
ContentValues values = new ContentValues();
104+
values.put("select_status", 0);
105+
db_1.update(tableName, values, "url=?", new String[]{feed.getUrl()});
106+
db_1.close();
95107
return;
108+
}
109+
//否则,选中状态
110+
feed.setSelectStatus(1);
96111
Bitmap bmp = BitmapFactory.decodeResource(context.getResources(),
97112
R.drawable.added);
98-
holder.ADD_BTN.setImageBitmap(bmp);
99-
100-
FeedDBHelper helper = new FeedDBHelper(context, "feed.db", null, 1);
113+
holder.addBtn.setImageBitmap(bmp);
114+
//加入section表
115+
DBHelper helper = new DBHelper(context, "reader.db", null, 1);
101116
SQLiteDatabase db = helper.getWritableDatabase();
102117
ContentValues values = new ContentValues();
103-
values.put("select_status", 1);
104-
db.update(tableName, values, "id=?", new String[]{"" + position});
118+
values.put("title", feed.getTitle());
119+
values.put("url", feed.getUrl());
120+
db.insert(SECTION_TABLE_NAME, null, values);
105121
db.close();
106-
107-
String title = feeds.get(position).getTitle();
108-
String url = feeds.get(position).getUrl();
109-
Section s = new Section();
110-
s.setTitle(title);
111-
s.setUrl(url);
112-
s.setTableName(tableName);
122+
//更新feed.db中所对应表的状态为1
123+
FeedDBHelper helper_1 = new FeedDBHelper(context, "feed.db", null, 1);
124+
SQLiteDatabase db_1 = helper_1.getWritableDatabase();
125+
values.put("select_status", 1);
126+
db_1.update(tableName, values, "url=?", new String[]{feed.getUrl()});
127+
db_1.close();
113128
}
114129
});
115-
116130
convertView.setTag(holder);
117131
}
118132
else
119133
{
120134
holder = (ViewHolder) convertView.getTag();
121135
}
122-
123-
Feed f = feeds.get(position);
124-
holder.FEED_TITLE.setText((CharSequence) f.getTitle());
136+
Feed feed = feeds.get(position);
137+
holder.feedTitle.setText((CharSequence)
138+
feed.getTitle());
139+
//addBtn状态图标设置
125140
Bitmap bm = null;
126-
if(f.getSelectStatus() == 1)
141+
if(feed.getSelectStatus() == 1)
127142
{
128143
bm = BitmapFactory.decodeResource(context.getResources(),
129144
R.drawable.added);
@@ -135,17 +150,15 @@ public void onClick(View v)
135150
R.drawable.add);
136151
notifyDataSetChanged();
137152
}
138-
holder.ADD_BTN.setImageBitmap(bm);
153+
holder.addBtn.setImageBitmap(bm);
139154
return convertView;
140155
}
156+
157+
141158
private static final class ViewHolder
142159
{
143-
TextView FEED_TITLE;
144-
ImageButton ADD_BTN;
145-
}
146-
public void setTabelName(String tableName)
147-
{
148-
this.tableName = tableName;
160+
TextView feedTitle;
161+
ImageButton addBtn;
149162
}
150163

151164
}

src/com/dreamteam/app/adapter/FeedCategoryAdapter.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,26 +18,26 @@ public class FeedCategoryAdapter extends BaseAdapter
1818
{
1919
private Context context;
2020
private LayoutInflater inflater;
21-
private String[] categories;
21+
private String[] categories_zh;
2222

2323

2424
public FeedCategoryAdapter(Context context)
2525
{
2626
this.context = context;
27-
categories = context.getResources()
27+
categories_zh = context.getResources()
2828
.getStringArray(R.array.feed_category);
2929
}
3030

3131
@Override
3232
public int getCount()
3333
{
34-
return categories.length;
34+
return categories_zh.length;
3535
}
3636

3737
@Override
3838
public Object getItem(int position)
3939
{
40-
return categories[position];
40+
return categories_zh[position];
4141
}
4242

4343
@Override
@@ -56,19 +56,19 @@ public View getView(int position, View convertView, ViewGroup parent)
5656
inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
5757
convertView = inflater.inflate(R.layout.category_item, null);
5858
viewHolder = new ViewHolder();
59-
viewHolder.CATEGORY_TITLE = (TextView) convertView.findViewById(R.id.category_title);
59+
viewHolder.categoryTitle = (TextView) convertView.findViewById(R.id.category_title);
6060
convertView.setTag(viewHolder);
6161
}
6262
else
6363
{
6464
viewHolder = (ViewHolder) convertView.getTag();
6565
}
66-
viewHolder.CATEGORY_TITLE.setText(categories[position]);
66+
viewHolder.categoryTitle.setText(categories_zh[position]);
6767
return convertView;
6868
}
6969

7070
private static final class ViewHolder
7171
{
72-
TextView CATEGORY_TITLE;
72+
TextView categoryTitle;
7373
}
7474
}

src/com/dreamteam/app/commons/AppConfig.java

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,11 @@
1717
*/
1818
public class AppConfig
1919
{
20-
//sd��
20+
//SD卡目录
2121
public static final String APP_ROOT_DIR = FileUtils.getSDRootPath() + File.separator + "SimpleReader";
2222
public static final String APP_CACHE_DIR = APP_ROOT_DIR + File.separator + "cache";
2323
public static final String APP_SECTION_DIR = APP_CACHE_DIR + File.separator + "sections";
2424
public static final String APP_IMAGE_CACHE_DIR = APP_CACHE_DIR + File.separator + "images";
2525
public static final String APP_IMAGE_DIR = APP_ROOT_DIR + File.separator + "images";
2626

27-
public static final String FEED_FILE_NAME = APP_ROOT_DIR + File.separator + "favorite.feed";
28-
29-
public static final String SECTION_TABLE_NAME = "section";
30-
public static final String FEED_TABLE_NAME = "feed";
31-
32-
public static final int ITEM_PAGE_SIZE = 10;
33-
34-
public static final String FEED_SRC_FILE_NAME = APP_ROOT_DIR + File.separator + "feed.data";
35-
public static final String SECTION_FILE_NAME = APP_ROOT_DIR + File.separator + "favorite.feed";
36-
37-
//Action
38-
public static final String SPEECH_ACTION = "com.dreamteam.reader.SPEECH_ACTION";
39-
4027
}

src/com/dreamteam/app/db/DBHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
public class DBHelper extends SQLiteOpenHelper
1414
{
1515
public static final String CREATE_FAVORITE_FEED =
16-
"create table section(title text, url text, category_id integer)";
16+
"create table section(title text, url text)";
1717
public static final String CREATE_FAVORITE_ITEM =
1818
"create table favorite_item(title text, pubdate text, item_detail text)";
1919

0 commit comments

Comments
 (0)