Skip to content

Commit 7a9babc

Browse files
committed
fix favo state
1 parent 69c14bb commit 7a9babc

File tree

5 files changed

+26
-6
lines changed

5 files changed

+26
-6
lines changed

app/src/main/java/com/brian/csdnblog/activity/BlogListFrag.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,10 @@ public void onClick(View v) {
165165
});
166166

167167
if (TypeManager.getWebType(mType) == TypeManager.TYPE_WEB_FAVO) {
168-
mAdapter.addDatas(HistoryBlogManager.getInstance().getFavoBlogList());
168+
mAdapter.initListWithDatas(HistoryBlogManager.getInstance().getFavoBlogList());
169169
mRefreshable = false;
170170
} else if (TypeManager.getWebType(mType) == TypeManager.TYPE_WEB_HISTORY) {
171-
mAdapter.addDatas(HistoryBlogManager.getInstance().getHistoryBlogList());
171+
mAdapter.initListWithDatas(HistoryBlogManager.getInstance().getHistoryBlogList());
172172
mRefreshable = false;
173173
} else {
174174
mRefreshable = true;

app/src/main/java/com/brian/csdnblog/activity/MainTabActivity.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ public class MainTabActivity extends SlidingFragmentActivity {
5656
@Override
5757
public void onCreate(Bundle savedInstanceState) {
5858
super.onCreate(savedInstanceState);
59+
setSwipeBackEnable(false);
5960
setContentView(R.layout.activity_main_tab);
6061
ButterKnife.bind(this);
6162

app/src/main/java/com/brian/csdnblog/datacenter/database/BlogInfoTable.java

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public class BlogInfoTable extends BaseTable<BlogInfo> {
4141
protected static final String SQL_CREATE_TABLE = "create table if not exists " + TABLE_NAME
4242
+ " ( "
4343
+ ID + " integer primary key autoincrement, "
44-
+ BLOG_ID + " text UNIQUE, "
44+
+ BLOG_ID + " text UNIQUE NOT NULL, "
4545
+ TITLE + " text, "
4646
+ LINK + " text, "
4747
+ BLOGER_ID + " text, "
@@ -104,16 +104,34 @@ public boolean saveBlog(BlogInfo info) {
104104
return insertOrUpdate(TABLE_NAME, selection, selectionArgs, values, false);
105105
}
106106

107+
public boolean saveOrUpdateBlog(BlogInfo info) {
108+
if (info == null) {
109+
return false;
110+
}
111+
112+
String selection = BLOG_ID + " = ? ";
113+
String[] selectionArgs = new String[]{info.blogId};
114+
115+
ContentValues values = toContentValues(info);
116+
return insertOrUpdate(TABLE_NAME, selection, selectionArgs, values, true);
117+
}
118+
119+
/**
120+
* 收藏或取消收藏博文,更新数据库中的info.isFavo字段
121+
*/
107122
public boolean doFavo(BlogInfo info) {
108123
if (info == null) {
109124
return false;
110125
}
111126

112127
ContentValues values = new ContentValues();
113-
values.put(FAVO, info.isFavo);
128+
values.put(FAVO, info.isFavo?1:0);
114129
return update(info.blogId, values);
115130
}
116131

132+
/**
133+
* 更新blog信息,使用封装好的ContentValues
134+
*/
117135
private boolean update(String blogID, ContentValues values) {
118136
if (values == null || TextUtils.isEmpty(blogID)) {
119137
return false;
@@ -272,7 +290,7 @@ protected void readCursor(ArrayList<BlogInfo> list, Cursor cursor) throws JSONEx
272290
blogInfo.visitTime = cursor.getInt(cursor.getColumnIndex(VISITTIME));
273291
blogInfo.extraMsg = cursor.getString(cursor.getColumnIndex(EXTRA_MSG));
274292
blogInfo.type = cursor.getInt(cursor.getColumnIndex(TYPE));
275-
blogInfo.isFavo = cursor.getInt(cursor.getColumnIndex(TYPE)) == 1;
293+
blogInfo.isFavo = cursor.getInt(cursor.getColumnIndex(FAVO)) == 1;
276294
list.add(blogInfo);
277295
} while (cursor.moveToNext());
278296
}

app/src/main/java/com/brian/csdnblog/datacenter/database/BlogerTable.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public class BlogerTable extends BaseTable<Bloger> {
3737
protected static final String SQL_CREATE_TABLE = "create table if not exists " + TABLE_NAME
3838
+ " ( "
3939
+ ID + " integer primary key autoincrement, "
40-
+ BLOGER_ID + " text UNIQUE, "
40+
+ BLOGER_ID + " text UNIQUE NOT NULL, "
4141
+ URL_HOME + " text, "
4242
+ URL_HEAD + " text, "
4343
+ NICK_NAME + " text, "

app/src/main/java/com/brian/csdnblog/manager/HistoryBlogManager.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ public void removeBlog(BlogInfo blogInfo) {
6060
if (blogInfo == null) {
6161
return;
6262
}
63+
FileUtil.deleteFile(DataManager.getBlogCachePath(Md5.getMD5ofStr(blogInfo.blogId)));
6364
BlogInfoTable.getInstance().delete(blogInfo);
6465
}
6566

0 commit comments

Comments
 (0)