public void deleteFav(MainPageItem qy) { Cursor cursor = null; String where = FavTable.USER_ID + " = '" + MyApplication.getInstance().getCurrentUser().getObjectId() + "' AND " + FavTable.OBJECT_ID + " = '" + qy.getObjectId() + "'"; cursor = dbHelper.query(DBHelper.TABLE_NAME, null, where, null, null, null, null); if (cursor != null && cursor.getCount() > 0) { cursor.moveToFirst(); int isLove = cursor.getInt(cursor.getColumnIndex(FavTable.IS_LOVE)); if (isLove == 0) { dbHelper.delete(DBHelper.TABLE_NAME, where, null); } else { ContentValues cv = new ContentValues(); cv.put(FavTable.IS_FAV, 0); dbHelper.update(DBHelper.TABLE_NAME, cv, where, null); } } if (cursor != null) { cursor.close(); dbHelper.close(); } }
public ArrayList<MainPageItem> queryFav() { ArrayList<MainPageItem> contents = null; // ContentResolver resolver = context.getContentResolver(); Cursor cursor = dbHelper.query(DBHelper.TABLE_NAME, null, null, null, null, null, null); LogUtils.i(TAG, cursor.getCount() + ""); if (cursor == null) { return null; } contents = new ArrayList<MainPageItem>(); for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) { MainPageItem content = new MainPageItem(); content.setMyFav(cursor.getInt(3) == 1 ? true : false); content.setMyLove(cursor.getInt(4) == 1 ? true : false); LogUtils.i( TAG, cursor.getColumnIndex("isfav") + ".." + cursor.getColumnIndex("islove") + ".." + content.getMyFav() + "..." + content.getMyLove()); contents.add(content); } if (cursor != null) { cursor.close(); } // if (contents.size() > 0) { // return contents; // } return contents; }
/** * 设置内容的收藏状态 * * @param context * @param lists */ public List<MainPageItem> setFavInFav(List<MainPageItem> lists) { Cursor cursor = null; if (lists != null && lists.size() > 0) { for (Iterator iterator = lists.iterator(); iterator.hasNext(); ) { MainPageItem content = (MainPageItem) iterator.next(); content.setMyFav(true); String where = FavTable.USER_ID + " = '" + MyApplication.getInstance().getCurrentUser().getObjectId() + "' AND " + FavTable.OBJECT_ID + " = '" + content.getObjectId() + "'"; cursor = dbHelper.query(DBHelper.TABLE_NAME, null, where, null, null, null, null); if (cursor != null && cursor.getCount() > 0) { cursor.moveToFirst(); if (cursor.getInt(cursor.getColumnIndex(FavTable.IS_LOVE)) == 1) { content.setMyLove(true); } else { content.setMyLove(false); } } LogUtils.i(TAG, content.getMyFav() + ".." + content.getMyLove()); } } if (cursor != null) { cursor.close(); dbHelper.close(); } return lists; }
public long insertFav(MainPageItem qy) { long uri = 0; Cursor cursor = null; String where = FavTable.USER_ID + " = '" + MyApplication.getInstance().getCurrentUser().getObjectId() + "' AND " + FavTable.OBJECT_ID + " = '" + qy.getObjectId() + "'"; cursor = dbHelper.query(DBHelper.TABLE_NAME, null, where, null, null, null, null); if (cursor != null && cursor.getCount() > 0) { cursor.moveToFirst(); ContentValues conv = new ContentValues(); conv.put(FavTable.IS_FAV, 1); conv.put(FavTable.IS_LOVE, 1); dbHelper.update(DBHelper.TABLE_NAME, conv, where, null); } else { ContentValues cv = new ContentValues(); cv.put(FavTable.USER_ID, MyApplication.getInstance().getCurrentUser().getObjectId()); cv.put(FavTable.OBJECT_ID, qy.getObjectId()); cv.put(FavTable.IS_LOVE, qy.getMyLove() == true ? 1 : 0); cv.put(FavTable.IS_FAV, qy.getMyFav() == true ? 1 : 0); uri = dbHelper.insert(DBHelper.TABLE_NAME, null, cv); } if (cursor != null) { cursor.close(); dbHelper.close(); } return uri; }
public boolean isLoved(MainPageItem qy) { Cursor cursor = null; String where = FavTable.USER_ID + " = '" + MyApplication.getInstance().getCurrentUser().getObjectId() + "' AND " + FavTable.OBJECT_ID + " = '" + qy.getObjectId() + "'"; cursor = dbHelper.query(DBHelper.TABLE_NAME, null, where, null, null, null, null); if (cursor != null && cursor.getCount() > 0) { cursor.moveToFirst(); if (cursor.getInt(cursor.getColumnIndex(FavTable.IS_LOVE)) == 1) { return true; } } return false; }
private void addDataInfo() { mDbHelper = new DBHelper(this); mCursor = mDbHelper.query(); if (mCursor.getCount() < 6) { // add emergency info mDbHelper.insert( "Emergency Infomation a", "emergency infomation a emergency infomation a emergency infomation a", "1"); mDbHelper.insert( "Emergency Infomation b", "emergency infomation b emergency infomation b emergency infomation b", "1"); mDbHelper.insert( "Emergency Infomation c", "emergency infomation c emergency infomation c emergency infomation c", "1"); mDbHelper.insert( "Emergency Infomation d", "emergency infomation d emergency infomation d emergency infomation d", "1"); mDbHelper.insert( "Emergency Infomation e", "emergency infomation e emergency infomation e emergency infomation e", "1"); mDbHelper.insert( "Emergency Infomation f", "emergency infomation f emergency infomation f emergency infomation f", "1"); mDbHelper.insert( "Emergency Infomation g", "emergency infomation g emergency infomation g emergency infomation g", "1"); mDbHelper.insert( "Emergency Infomation h", "emergency infomation h emergency infomation h emergency infomation h", "1"); mDbHelper.insert( "Emergency Infomation i", "emergency infomation i emergency infomation i emergency infomation i", "1"); // add easy info mDbHelper.insert( "Easy Infomation 1", "easy infomation 1 easy infomation 1 easy infomation 1 easy infomation 1", "2"); mDbHelper.insert( "Easy Infomation 2", "easy infomation 2 easy infomation 2 easy infomation 2 easy infomation 2", "2"); mDbHelper.insert( "Easy Infomation 3", "easy infomation 3 easy infomation 3 easy infomation 3 easy infomation 3", "2"); mDbHelper.insert( "Easy Infomation 4", "easy infomation 4 easy infomation 4 easy infomation 4 easy infomation 4", "2"); mDbHelper.insert( "Easy Infomation 5", "easy infomation 5 easy infomation 5 easy infomation 5 easy infomation 5", "2"); mDbHelper.insert( "Easy Infomation 6", "easy infomation 6 easy infomation 6 easy infomation 6 easy infomation 6", "2"); mDbHelper.insert( "Easy Infomation 7", "easy infomation 7 easy infomation 7 easy infomation 7 easy infomation 7", "2"); mDbHelper.insert( "Easy Infomation 8", "easy infomation 8 easy infomation 8 easy infomation 8 easy infomation 8", "2"); mDbHelper.insert( "Easy Infomation 9", "easy infomation 9 easy infomation 9 easy infomation 9 easy infomation 9", "2"); } else { } }