Пример #1
0
    public boolean updateNewsItemCover(ATPNews newsItem) {
      String cover = newsItem.getCover();
      ContentValues cv = new ContentValues();
      cv.put(AppDatabase.NewsDatabase.COVER, cover);

      // If 'cover' not present in the players.json file, NULL is returned
      // Different that 'winner' where and empty string is returned given entries are
      // like "winner:""
      String WHERE =
          AppDatabase.NewsDatabase.HASHED_TITLE
              + "="
              + "'"
              + newsItem.getHashedTitle()
              + "'"
              + " AND "
              + "( "
              + AppDatabase.NewsDatabase.COVER
              + "<>"
              + "'"
              + cover
              + "'"
              + " OR "
              + AppDatabase.NewsDatabase.COVER
              + " ISNULL"
              + " )";
      int rowsUpdated =
          getWritableDatabase().update(AppDatabase.NewsDatabase.TABLE_NAME, cv, WHERE, null);

      return rowsUpdated > 0 ? true : false;
    }
Пример #2
0
    public long insertNewsItem(ATPNews newsItem) {
      ContentValues cv = new ContentValues();
      cv.put(AppDatabase.NewsDatabase.PUB_DATE, newsItem.getPubDate());
      cv.put(AppDatabase.NewsDatabase.PUB_DATE_MILLIS, newsItem.getPubDateMillis());
      cv.put(AppDatabase.NewsDatabase.PUB_DATE_DAYS_OF_YEAR, newsItem.getPubDateDaysOfYear());

      /*String title = newsItem.getTitle();
      int hashedTitle = title.toLowerCase().hashCode();*/
      cv.put(AppDatabase.NewsDatabase.TITLE, newsItem.getTitle());
      cv.put(AppDatabase.NewsDatabase.COVER, newsItem.getCover());
      cv.put(AppDatabase.NewsDatabase.PLAYER_PHOTO_URL, newsItem.getPlayerPhotoUrl());
      cv.put(AppDatabase.NewsDatabase.HASHED_TITLE, newsItem.getHashedTitle());
      cv.put(AppDatabase.NewsDatabase.DESCRIPTION, newsItem.getDescription());
      cv.put(AppDatabase.NewsDatabase.LINK, newsItem.getLink());
      cv.put(AppDatabase.NewsDatabase.SHARE_TEXT, newsItem.getNewsShare());
      cv.put(AppDatabase.NewsDatabase.IS_STARRED, newsItem.getIsStarred());
      cv.put(AppDatabase.NewsDatabase.IS_SHARED, newsItem.getIsShared());
      cv.put(AppDatabase.NewsDatabase.IS_HIDDEN, newsItem.getIsIsHidden());
      cv.put(AppDatabase.NewsDatabase.IS_DELETED, newsItem.getIsDeleted());

      return getWritableDatabase()
          .insertWithOnConflict(
              AppDatabase.NewsDatabase.TABLE_NAME, null, cv, SQLiteDatabase.CONFLICT_IGNORE);
    }