Ejemplo n.º 1
0
 public void saveFavourite(News news) {
   if (news != null) {
     ContentValues values = new ContentValues();
     values.put(DBHelper.COLUMN_NEWS_ID, news.get_id());
     values.put(DBHelper.COLUMN_NEWS_TITLE, news.getTitle());
     values.put(DBHelper.COLUMN_NEWS_TYPE, news.getType());
     values.put(DBHelper.COLUMN_NEWS_IMAGE, news.getImage());
     db.insert(DBHelper.TABLE_NAME, null, values);
   }
 }
Ejemplo n.º 2
0
 public List<News> loadFavourite() {
   List<News> favLists = new ArrayList<News>();
   Cursor cursor = db.query(DBHelper.TABLE_NAME, null, null, null, null, null, null);
   if (cursor.moveToFirst()) {
     do {
       News news = new News();
       news.set_id(cursor.getString(1));
       news.setTitle(cursor.getString(2));
       news.setImage(cursor.getString(3));
       news.setType(cursor.getString(4));
       favLists.add(news);
     } while (cursor.moveToNext());
   }
   cursor.close();
   return favLists;
 }
Ejemplo n.º 3
0
 public boolean isFavourite(News news) {
   Cursor cursor =
       db.query(
           DBHelper.TABLE_NAME,
           null,
           DBHelper.COLUMN_NEWS_ID + " = ?",
           new String[] {news.get_id() + ""},
           null,
           null,
           null);
   if (cursor.moveToNext()) {
     cursor.close();
     return true;
   } else {
     return false;
   }
 }
Ejemplo n.º 4
0
 public void deleteFavourite(News news) {
   if (news != null) {
     db.delete(
         DBHelper.TABLE_NAME, DBHelper.COLUMN_NEWS_ID + " = ?", new String[] {news.get_id() + ""});
   }
 }