@@ -27,25 +27,31 @@ public class BlogInfoTable extends BaseTable<BlogInfo> {
2727 public static final String TITLE = "title" ;
2828 public static final String LINK = "link" ;
2929 public static final String BLOGER_ID = "bloger_id" ;
30+ public static final String BLOGER_JSON = "bloger_json" ;
3031 public static final String SUMMARY = "summary" ;
3132 public static final String LOACAL_PATH = "local_path" ;
3233 public static final String DATESTAMP = "datestamp" ;
34+ public static final String VISITTIME = "visit_time" ;
3335 public static final String EXTRA_MSG = "extra_msg" ;
3436 public static final String TYPE = "type" ;
37+ public static final String FAVO = "isFavo" ;
3538
3639
3740 // 创建帖子表的sql语言
3841 protected static final String SQL_CREATE_TABLE = "create table if not exists " + TABLE_NAME
3942 + " ( "
4043 + ID + " integer primary key autoincrement, "
41- + BLOG_ID + " text, "
44+ + BLOG_ID + " text UNIQUE , "
4245 + TITLE + " text, "
4346 + LINK + " text, "
4447 + BLOGER_ID + " text, "
48+ + BLOGER_JSON + " text, "
4549 + SUMMARY + " text, "
4650 + LOACAL_PATH + " text, "
51+ + VISITTIME + " integer, "
4752 + DATESTAMP + " text, "
4853 + EXTRA_MSG + " text, "
54+ + FAVO + " integer, "
4955 + TYPE + " integer "
5056 + " ) " ;
5157
@@ -74,19 +80,19 @@ public static void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
7480 // TODO 实现升级逻辑
7581 }
7682
77- public void saveAsyc (final BlogInfo info ) {
83+ public void saveBlogAsyc (final BlogInfo info ) {
7884 ThreadManager .getPoolProxy ().execute (new Runnable () {
7985 @ Override
8086 public void run () {
81- save (info );
87+ saveBlog (info );
8288 }
8389 });
8490 }
8591
8692 /**
8793 * 插入新的消息
8894 */
89- public boolean save (BlogInfo info ) {
95+ public boolean saveBlog (BlogInfo info ) {
9096 if (info == null ) {
9197 return false ;
9298 }
@@ -95,9 +101,30 @@ public boolean save(BlogInfo info) {
95101 String [] selectionArgs = new String []{info .blogId };
96102
97103 ContentValues values = toContentValues (info );
98- return insertOrUpdate (TABLE_NAME , selection , selectionArgs , values );
104+ return insertOrUpdate (TABLE_NAME , selection , selectionArgs , values , false );
99105 }
100106
107+ public boolean doFavo (BlogInfo info ) {
108+ if (info == null ) {
109+ return false ;
110+ }
111+
112+ ContentValues values = new ContentValues ();
113+ values .put (FAVO , info .isFavo );
114+ return update (info .blogId , values );
115+ }
116+
117+ private boolean update (String blogID , ContentValues values ) {
118+ if (values == null || TextUtils .isEmpty (blogID )) {
119+ return false ;
120+ }
121+
122+ String selection = BLOG_ID + " = ? " ;
123+ String [] selectionArgs = new String []{blogID };
124+ return update (TABLE_NAME , selection , selectionArgs , values );
125+ }
126+
127+
101128 public boolean delete (BlogInfo info ) {
102129 if (info == null ) {
103130 return false ;
@@ -163,6 +190,26 @@ public BlogInfo queryByBlogerId(String blogerId) {
163190 return query (TABLE_NAME , selection , selectionArgs );
164191 }
165192
193+ public List <BlogInfo > getFavoList () {
194+ String orderBy = VISITTIME + " desc " ;
195+ String selection = FAVO + " = ? " ;
196+ String [] selectionArgs = new String []{String .valueOf (1 )};
197+
198+ String limit = null ;
199+
200+ return queryList (TABLE_NAME , selection , selectionArgs , orderBy , limit );
201+ }
202+
203+ public List <BlogInfo > getHistoryList () {
204+ String orderBy = VISITTIME + " desc " ;
205+ String selection = FAVO + " != ? " ;
206+ String [] selectionArgs = new String []{String .valueOf (1 )};
207+
208+ String limit = null ;
209+
210+ return queryList (TABLE_NAME , selection , selectionArgs , orderBy , limit );
211+ }
212+
166213 public List <BlogInfo > queryList (int type ) {
167214 return queryList (type , 0 , 0 );
168215 }
@@ -175,11 +222,9 @@ public List<BlogInfo> queryList(int type, int startIndex, int num) {
175222 return null ;
176223 }
177224
178- String orderBy = DATESTAMP + " desc " ;
179- String selection = null ;
180- String [] selectionArgs = null ;
181- // String selection = TYPE + " = ? ";
182- // String[] selectionArgs = new String[]{String.valueOf(type)};
225+ String orderBy = VISITTIME + " desc " ;
226+ String selection = TYPE + " = ? " ;
227+ String [] selectionArgs = new String []{String .valueOf (type )};
183228
184229 String limit = null ;
185230 if (num > 0 ) {
@@ -197,11 +242,14 @@ protected ContentValues toContentValues(BlogInfo info) {
197242 values .put (TITLE , info .title );
198243 values .put (LINK , info .link );
199244 values .put (BLOGER_ID , info .blogerID );
245+ values .put (BLOGER_JSON , info .blogerJson );
200246 values .put (SUMMARY , info .summary );
201247 values .put (LOACAL_PATH , info .localPath );
202248 values .put (DATESTAMP , info .dateStamp );
249+ values .put (VISITTIME , info .visitTime );
203250 values .put (EXTRA_MSG , info .extraMsg );
204251 values .put (TYPE , info .type );
252+ values .put (FAVO , info .isFavo ?1 :0 );
205253 return values ;
206254 }
207255 return null ;
@@ -217,11 +265,14 @@ protected void readCursor(ArrayList<BlogInfo> list, Cursor cursor) throws JSONEx
217265 blogInfo .title = cursor .getString (cursor .getColumnIndex (TITLE ));
218266 blogInfo .link = cursor .getString (cursor .getColumnIndex (LINK ));
219267 blogInfo .blogerID = cursor .getString (cursor .getColumnIndex (BLOGER_ID ));
268+ blogInfo .blogerJson = cursor .getString (cursor .getColumnIndex (BLOGER_JSON ));
220269 blogInfo .summary = cursor .getString (cursor .getColumnIndex (SUMMARY ));
221270 blogInfo .localPath = cursor .getString (cursor .getColumnIndex (LOACAL_PATH ));
222271 blogInfo .dateStamp = cursor .getString (cursor .getColumnIndex (DATESTAMP ));
272+ blogInfo .visitTime = cursor .getInt (cursor .getColumnIndex (VISITTIME ));
223273 blogInfo .extraMsg = cursor .getString (cursor .getColumnIndex (EXTRA_MSG ));
224274 blogInfo .type = cursor .getInt (cursor .getColumnIndex (TYPE ));
275+ blogInfo .isFavo = cursor .getInt (cursor .getColumnIndex (TYPE )) == 1 ;
225276 list .add (blogInfo );
226277 } while (cursor .moveToNext ());
227278 }
0 commit comments