private APIResponse post(final String urlString, final ContentValues values) { FormEncodingBuilder formEncodingBuilder = new FormEncodingBuilder(); for (Entry<String, Object> entry : values.valueSet()) { formEncodingBuilder.add(entry.getKey(), (String) entry.getValue()); } return this.post(urlString, formEncodingBuilder.build()); }
/** * Stores the values to the content provider using this service as the context. Fills in the * timestamp and expiration before storing. * * @param values the values to store * @param now the timestamp */ public final void putValues(final ContentValues values, final long now) { updateReadings(now); putValues(getContentResolver(), uri, values, now); for (Entry<String, Object> key : values.valueSet()) { notifyDataChanged(key.getKey()); } }
private APIResponse get(final String urlString, final ContentValues values) { List<String> parameters = new ArrayList<String>(); for (Entry<String, Object> entry : values.valueSet()) { StringBuilder builder = new StringBuilder(); builder.append((String) entry.getKey()); builder.append("="); builder.append(URLEncoder.encode((String) entry.getValue())); parameters.add(builder.toString()); } return this.get(urlString + "?" + TextUtils.join("&", parameters)); }
private String builderGetParametersString(ContentValues values) { List<String> parameters = new ArrayList<String>(); for (Entry<String, Object> entry : values.valueSet()) { StringBuilder builder = new StringBuilder(); builder.append((String) entry.getKey()); builder.append("="); builder.append(URLEncoder.encode((String) entry.getValue())); parameters.add(builder.toString()); } return TextUtils.join("&", parameters); }
/** * Merges set values with those coming from another source, keeping the existing value if one * already exists */ public synchronized void mergeWithoutReplacement(ContentValues other) { if (setValues == null) { setValues = new ContentValues(); } for (Entry<String, Object> item : other.valueSet()) { if (setValues.containsKey(item.getKey())) { continue; } AndroidUtilities.putInto(setValues, item.getKey(), item.getValue()); } }
public static void validateCursor(ContentValues expectedValues, Cursor valueCursor) { assertTrue(valueCursor.moveToFirst()); Set<Map.Entry<String, Object>> valueSet = expectedValues.valueSet(); for (Map.Entry<String, Object> entry : valueSet) { String columnName = entry.getKey(); int idx = valueCursor.getColumnIndex(columnName); assertFalse(idx == -1); String expectedValue = entry.getValue().toString(); assertEquals(expectedValue, valueCursor.getString(idx)); } valueCursor.close(); }
private String getPostDataString(ContentValues cv) throws UnsupportedEncodingException { boolean first = true; StringBuilder sb = new StringBuilder(); for (Map.Entry<String, Object> entry : cv.valueSet()) { if (first) first = false; else { sb.append("&"); } sb.append(URLEncoder.encode(entry.getKey(), "UTF-8")); sb.append("="); sb.append(URLEncoder.encode((String) entry.getValue(), "UTF-8")); } return sb.toString(); }
/** Insert request headers for a download into the DB. */ private void insertRequestHeaders(SQLiteDatabase db, long downloadId, ContentValues values) { ContentValues rowValues = new ContentValues(); rowValues.put(Downloads.RequestHeaders.COLUMN_DOWNLOAD_ID, downloadId); for (Map.Entry<String, Object> entry : values.valueSet()) { String key = entry.getKey(); if (key.startsWith(Downloads.RequestHeaders.INSERT_KEY_PREFIX)) { String headerLine = entry.getValue().toString(); if (!headerLine.contains(":")) { throw new IllegalArgumentException("Invalid HTTP header line: " + headerLine); } String[] parts = headerLine.split(":", 2); rowValues.put(Downloads.RequestHeaders.COLUMN_HEADER, parts[0].trim()); rowValues.put(Downloads.RequestHeaders.COLUMN_VALUE, parts[1].trim()); db.insert(Downloads.RequestHeaders.HEADERS_DB_TABLE, null, rowValues); } } }
public String printContentValues(ContentValues vals) { String str_message = new String(); Set<Map.Entry<String, Object>> s = vals.valueSet(); Iterator itr = s.iterator(); Log.d("DatabaseSync", "ContentValue Length :: " + vals.size()); while (itr.hasNext()) { Map.Entry me = (Map.Entry) itr.next(); String key = me.getKey().toString(); Object value = me.getValue(); if (key != ApparelDB.ApparelTable.COLUMN_NAME_APPAREL_IMG || (key != ApparelDB.ApparelTable.COLUMN_NAME_ALL_PIECES_IMG)) { str_message += key + " : " + (String) (value == null ? null : value.toString()) + "\r\n"; } } return str_message; }
/** * Performs an insert, adding a new row with the given values. * * @param values the set of values with which to populate the new row * @param allowReplace if true, the statement does "INSERT OR REPLACE" instead of "INSERT", * silently deleting any previously existing rows that would cause a conflict * @return the row ID of the newly inserted row, or -1 if an error occurred */ private synchronized long insertInternal(ContentValues values, boolean allowReplace) { try { SQLiteStatement stmt = getStatement(allowReplace); stmt.clearBindings(); if (LOCAL_LOGV) Log.v(TAG, "--- inserting in table " + mTableName); for (Map.Entry<String, Object> e : values.valueSet()) { final String key = e.getKey(); int i = getColumnIndex(key); DatabaseUtils.bindObjectToProgram(stmt, i, e.getValue()); if (LOCAL_LOGV) { Log.v(TAG, "binding " + e.getValue() + " to column " + i + " (" + key + ")"); } } return stmt.executeInsert(); } catch (SQLException e) { Log.e(TAG, "Error inserting " + values + " into table " + mTableName, e); return -1; } }
private APIResponse post(final String urlString, final ContentValues values) { List<String> parameters = new ArrayList<String>(); for (Entry<String, Object> entry : values.valueSet()) { final StringBuilder builder = new StringBuilder(); builder.append((String) entry.getKey()); builder.append("="); try { builder.append(URLEncoder.encode((String) entry.getValue(), "UTF-8")); } catch (UnsupportedEncodingException e) { Log.e(this.getClass().getName(), e.getLocalizedMessage()); return new APIResponse(context); } parameters.add(builder.toString()); } final String parameterString = TextUtils.join("&", parameters); return this.post(urlString, parameterString); }
static void validateCurrentRecord( String error, Cursor valueCursor, ContentValues expectedValues) { Set<Map.Entry<String, Object>> valueSet = expectedValues.valueSet(); for (Map.Entry<String, Object> entry : valueSet) { String columnName = entry.getKey(); int idx = valueCursor.getColumnIndex(columnName); assertFalse("Column '" + columnName + "' not found. " + error, idx == -1); String expectedValue = entry.getValue().toString(); assertEquals( "Value '" + entry.getValue().toString() + "' did not match the expected value '" + expectedValue + "'. " + error, expectedValue, valueCursor.getString(idx)); } }
public int update(String table, ContentValues values, String whereClause, String[] whereArgs) throws SQLiteBridgeException { if (values == null) return 0; ArrayList<String> valueNames = new ArrayList<String>(); StringBuilder sb = new StringBuilder("UPDATE "); sb.append(table); sb.append(" SET "); boolean isFirst = true; for (Entry<String, Object> value : values.valueSet()) { if (isFirst) isFirst = false; else sb.append(", "); sb.append(value.getKey()); Object val = value.getValue(); if (val == null) { sb.append(" = NULL"); } else { sb.append(" = ?"); valueNames.add(val.toString()); } } if (!TextUtils.isEmpty(whereClause)) { sb.append(" WHERE "); sb.append(whereClause); for (int i = 0; i < whereArgs.length; i++) { valueNames.add(whereArgs[i]); } } String[] binds = new String[valueNames.size()]; valueNames.toArray(binds); internalQuery(sb.toString(), binds); return (int) mQueryResults[RESULT_ROWS_CHANGED]; }
public long insert(String table, String nullColumnHack, ContentValues values) throws SQLiteBridgeException { if (values == null) return 0; ArrayList<String> valueNames = new ArrayList<String>(); ArrayList<String> valueBinds = new ArrayList<String>(); ArrayList<String> keyNames = new ArrayList<String>(); for (Entry<String, Object> value : values.valueSet()) { keyNames.add(value.getKey()); Object val = value.getValue(); if (val == null) { valueNames.add("NULL"); } else { valueNames.add("?"); valueBinds.add(val.toString()); } } StringBuilder sb = new StringBuilder("INSERT into "); sb.append(table); sb.append(" ("); sb.append(TextUtils.join(", ", keyNames)); sb.append(")"); // XXX - Do we need to bind these values? sb.append(" VALUES ("); sb.append(TextUtils.join(", ", valueNames)); sb.append(") "); String[] binds = new String[valueBinds.size()]; valueBinds.toArray(binds); internalQuery(sb.toString(), binds); return mQueryResults[RESULT_INSERT_ROW_ID]; }
@Override public boolean commit() { Log.d(AnkiDroidApp.TAG, "DeckOptions - commit() changes back to database"); try { for (Entry<String, Object> entry : mUpdate.valueSet()) { Log.i( AnkiDroidApp.TAG, "Change value for key '" + entry.getKey() + "': " + entry.getValue()); if (entry.getKey().equals("name")) { if (!mCol.getDecks().rename(mDeck, (String) entry.getValue())) { Themes.showThemedToast( DeckOptions.this, getResources().getString(R.string.rename_error, mDeck.get("name")), false); } } else if (entry.getKey().equals("desc")) { mDeck.put("desc", (String) entry.getValue()); mCol.getDecks().save(mDeck); } else if (entry.getKey().equals("deckConf")) { mCol.getDecks().setConf(mDeck, Long.parseLong((String) entry.getValue())); mOptions = mCol.getDecks().confForDid(mDeck.getLong("id")); } else if (entry.getKey().equals("maxAnswerTime")) { mOptions.put("maxTaken", Integer.parseInt((String) entry.getValue())); } else if (entry.getKey().equals("showAnswerTimer")) { mOptions.put("timer", (Boolean) entry.getValue() ? 1 : 0); } else if (entry.getKey().equals("autoPlayAudio")) { mOptions.put("autoplay", (Boolean) entry.getValue()); } else if (entry.getKey().equals("replayQuestion")) { mOptions.put("replayq", (Boolean) entry.getValue()); } else if (entry.getKey().equals("newSteps")) { String steps = (String) entry.getValue(); if (steps.matches("[0-9\\s]*")) { mOptions.getJSONObject("new").put("delays", getDelays(steps)); } } else if (entry.getKey().equals("newGradIvl")) { JSONArray ja = new JSONArray(); ja.put(Integer.parseInt((String) entry.getValue())); ja.put(mOptions.getJSONObject("new").getJSONArray("ints").get(1)); mOptions.getJSONObject("new").put("ints", ja); } else if (entry.getKey().equals("newEasy")) { JSONArray ja = new JSONArray(); ja.put(mOptions.getJSONObject("new").getJSONArray("ints").get(0)); ja.put(Integer.parseInt((String) entry.getValue())); mOptions.getJSONObject("new").put("ints", ja); } else if (entry.getKey().equals("initialFactor")) { mOptions .getJSONObject("new") .put("initialFactor", (int) (Integer.parseInt((String) entry.getValue()) * 10)); } else if (entry.getKey().equals("newOrder")) { mOptions .getJSONObject("new") .put("order", Integer.parseInt((String) entry.getValue())); } else if (entry.getKey().equals("newPerDay")) { mOptions .getJSONObject("new") .put("perDay", Integer.parseInt((String) entry.getValue())); } else if (entry.getKey().equals("newSeparate")) { mOptions.getJSONObject("new").put("separate", (Boolean) entry.getValue()); } else if (entry.getKey().equals("revPerDay")) { mOptions .getJSONObject("rev") .put("perDay", Integer.parseInt((String) entry.getValue())); } else if (entry.getKey().equals("revSpaceMax")) { mOptions .getJSONObject("rev") .put("fuzz", Integer.parseInt((String) entry.getValue()) / 100.0f); } else if (entry.getKey().equals("revSpaceMin")) { mOptions .getJSONObject("rev") .put("minSpace", Integer.parseInt((String) entry.getValue())); } else if (entry.getKey().equals("easyBonus")) { mOptions .getJSONObject("rev") .put("ease4", Integer.parseInt((String) entry.getValue()) / 100.0f); } else if (entry.getKey().equals("revIvlFct")) { mOptions .getJSONObject("rev") .put("ivlFct", Double.parseDouble((String) entry.getValue())); } else if (entry.getKey().equals("revMaxIvl")) { mOptions .getJSONObject("rev") .put("maxIvl", Integer.parseInt((String) entry.getValue())); } else if (entry.getKey().equals("lapSteps")) { String steps = (String) entry.getValue(); if (steps.matches("[0-9\\s]*")) { mOptions.getJSONObject("lapse").put("delays", getDelays(steps)); } } else if (entry.getKey().equals("lapNewIvl")) { mOptions .getJSONObject("lapse") .put("mult", Float.parseFloat((String) entry.getValue()) / 100); } else if (entry.getKey().equals("lapMinIvl")) { mOptions .getJSONObject("lapse") .put("minInt", Integer.parseInt((String) entry.getValue())); } else if (entry.getKey().equals("lapLeechThres")) { mOptions .getJSONObject("lapse") .put("leechFails", Integer.parseInt((String) entry.getValue())); } else if (entry.getKey().equals("lapLeechAct")) { mOptions .getJSONObject("lapse") .put("leechAction", Integer.parseInt((String) entry.getValue())); } } } catch (JSONException e) { throw new RuntimeException(e); } // save conf try { mCol.getDecks().save(mOptions); } catch (RuntimeException e) { Log.e(AnkiDroidApp.TAG, "DeckOptions - RuntimeException on saving conf: " + e); AnkiDroidApp.saveExceptionReportFile(e, "DeckOptionsSaveConf"); setResult(DeckPicker.RESULT_DB_ERROR); finish(); } // make sure we refresh the parent cached values cacheValues(); updateSummaries(); // and update any listeners for (OnSharedPreferenceChangeListener listener : listeners) { listener.onSharedPreferenceChanged(DeckPreferenceHack.this, null); } return true; }
public Set<Entry<String, Object>> valueSet() { return contentValues.valueSet(); }
private void fillNullValuesForColumn(SQLiteDatabase db, ContentValues values) { String column = values.valueSet().iterator().next().getKey(); db.update(DB_TABLE, values, column + " is null", null); values.clear(); }
@Override public Set<Map.Entry<String, Object>> valueSet() { return contentValues.valueSet(); }
public void testQueriesDB() { SQLiteDatabase db = (new NewsDBHelper(mContext)).getWritableDatabase(); assertTrue("Error: Unable to open the DB", db.isOpen()); ContentValues newsFeedTestValues = new ContentValues(); newsFeedTestValues.put( NewsContract.NewsFeed.COLUMN_ARTICLEID, "football/2015/aug/23/arsene-wenger-arsenal-liverpool"); newsFeedTestValues.put(NewsContract.NewsFeed.COLUMN_SECTIONID, "football"); newsFeedTestValues.put( NewsContract.NewsFeed.COLUMN_APIURL, "http://content.guardianapis.com/football/2015/aug/23/arsene-wenger-arsenal-liverpool"); newsFeedTestValues.put( NewsContract.NewsFeed.COLUMN_WEBURL, "http://www.theguardian.com/football/2015/aug/23/arsene-wenger-arsenal-liverpool"); newsFeedTestValues.put( NewsContract.NewsFeed.COLUMN_WEBTITLE, "Arsène Wenger: Arsenal must ‘play with good pace’ to beat Liverpool"); newsFeedTestValues.put( NewsContract.NewsFeed.COLUMN_TRAILTEXT, "Liverpool have shown greater resilience this season but on their last visit to Arsenal they were whacked 4-1"); newsFeedTestValues.put(NewsContract.NewsFeed.COLUMN_PUBLISHDATE, Utility.getYesterdayDate()); newsFeedTestValues.put(NewsContract.NewsFeed.COLUMN_SAVEDFLAG, "0"); newsFeedTestValues.put( NewsContract.NewsFeed.COLUMN_IMAGEURL, "http://media.guim.co.uk/fece5c28990b3b8baa19229a88164a4c6d52c21c/0_31_3500_2101/1000.jpg\\"); newsFeedTestValues.put( NewsContract.NewsFeed.COLUMN_THUMBNAILURL, "http://media.guim.co.uk/fece5c28990b3b8baa19229a88164a4c6d52c21c/0_31_3500_2101/1000.jpg\\"); newsFeedTestValues.put( NewsContract.NewsFeed.COLUMN_BYLINE, "http://media.guim.co.uk/fece5c28990b3b8baa19229a88164a4c6d52c21c/0_31_3500_2101/1000.jpg\\"); long newsFeedRowID = db.insert(NewsContract.NewsFeed.TABLE_NAME, null, newsFeedTestValues); assertTrue(newsFeedRowID != -1); Cursor cursor = db.query(NewsContract.NewsFeed.TABLE_NAME, null, null, null, null, null, null); assertTrue("Error: Unable to retrieve data from NewsFeedTable", cursor.moveToFirst()); int columnIndex; String columnName, columnValue; // Intialising the columnIndex from 1 instead of 0 as the 0th colum is _ID // which is not present in the content value set. for (columnIndex = 1; columnIndex < cursor.getColumnCount(); ++columnIndex) { columnName = cursor.getColumnName(columnIndex); columnValue = cursor.getString(columnIndex); assertTrue( "Error: Unable to retrieve the column from contentValueSet", newsFeedTestValues.containsKey(columnName)); assertTrue( "Error: Unable to match the key (" + columnName + ") with value (" + newsFeedTestValues.get(columnName) + ") pair ", ((String) newsFeedTestValues.get(columnName)).equals(columnValue)); } assertFalse("Error: Multiple rows returned", cursor.moveToNext()); cursor.moveToFirst(); columnIndex = cursor.getColumnIndex("_id"); ContentValues newsArticleTestValues = new ContentValues(); newsArticleTestValues.put( NewsContract.NewsArticle.COLUMN_NEWSFEED_KEY, cursor.getInt(columnIndex)); newsArticleTestValues.put( NewsContract.NewsArticle.COLUMN_WEBURL, "http://www.theguardian.com/football/2015/aug/23/arsene-wenger-arsenal-liverpool"); newsArticleTestValues.put(NewsContract.NewsArticle.COLUMN_SECTIONID, "football"); newsArticleTestValues.put( NewsContract.NewsArticle.COLUMN_ARTICLEID, "football/2015/aug/23/arsene-wenger-arsenal-liverpool"); newsArticleTestValues.put( NewsContract.NewsArticle.COLUMN_HEADLINE, "Arsène Wenger: Arsenal must ‘play with good pace’ to beat Liverpool"); newsArticleTestValues.put(NewsContract.NewsArticle.COLUMN_DOWNLOADFLAG, "0"); newsArticleTestValues.put( NewsContract.NewsArticle.COLUMN_TRAILTEXT, "Liverpool have shown greater resilience this season but on their last visit to Arsenal they were whacked 4-1"); newsArticleTestValues.put( NewsContract.NewsArticle.COLUMN_HTML_BODY, "<p>There is nothing quite like the cauldron of a match day to expose the gossamer fragility of the football manager’s lot. When Arsenal last hosted Liverpool back in April, the scene played out in the theatre that hosts the post-match soliloquies epitomised the extremes that come with the territory.</p> <p>Enter Brendan Rodgers, accompanied by some notably discordant music. On the field <a href=\\\"http://www.theguardian.com/football/2015/apr/04/arsenal-liverpool-premier-league-match-report\\\" title=\\\"\\\">his team had been whacked 4-1</a>, lurching painfully away from the Champions League reckoning. Off it the club was reeling from the opening salvo of Raheem Sterling’s exit strategy. That <a href=\\\"http://www.theguardian.com/football/2015/apr/01/raheem-sterling-not-money-grabbing-contract-liverpool\\\" title=\\\"\\\">bizarrely timed BBC interview</a>, which bought the player’s future into sharp focus, was the talk of Merseyside and beyond. All in all it was a tough old afternoon for Rodgers.</p> <p>Arsène Wenger could empathise. He, too, has had his moments over a long career in which problems pile up to the point where it is difficult to breathe calmly and think with clarity. Those are the points when the imperative is to somehow hold your nerve while those around you tug at every loose fray. It had been only a few months previously that <a href=\\\"http://www.theguardian.com/football/2014/dec/07/arsenal-arsene-wenger-booed-train-stoke\\\" title=\\\"\\\">Wenger had been heckled by his own supporters at the railway station after a defeat at Stoke</a>. But here he was, basking in the glow of one of Arsenal’s most convincing performances, a classic example of Wenger’s vision of joyful, fast, fluid football. It was, as Wenger put it proudly afterwards, “the game we love”.</p> <p>Aesthetics apart, it was also important in that it crowned a long winning run at the Emirates Stadium. That attacking masterclass against Liverpool was an 11th successive victory in domestic football for Arsenal – their best home form in aeons.</p> <p>Since then? It has not escaped Wenger’s attention in the embryonic stages of this new season that Arsenal’s home potency has been diluted. Results since that Liverpool game, spanning the end of the last campaign and start of this, do not make pretty reading. Last season finished up with goalless draws against <a href=\\\"http://www.theguardian.com/football/2015/apr/26/arsenal-chelsea-premier-league-match-report\\\" title=\\\"\\\">Chelsea</a> and <a href=\\\"http://www.theguardian.com/football/2015/may/20/arsenal-sunderland-premier-league-match-report\\\" title=\\\"\\\">Sunderland</a>, a smash and grab three points for <a href=\\\"http://www.theguardian.com/football/2015/may/11/arsenal-swansea-premier-league-match-report\\\" title=\\\"\\\">Swansea</a>, and the only bright spot was a handsome win against a <a href=\\\"http://www.theguardian.com/football/2015/may/24/arsenal-west-bromwich-albion-premier-league-match-report\\\" title=\\\"\\\">West Brom</a> team that were halfway to the beach. This term began with a subdued and error-strewn <a href=\\\"http://www.theguardian.com/football/2015/aug/09/arsenal-west-ham-premier-league-match-report\\\" title=\\\"\\\">loss against West Ham</a>.</p> <p>Wenger wants the pattern to change back – and quickly. “You need to be strong at home that is for sure,” he says. “If you want to win the championship you need to win your home games. It can happen that you lose the odd game but overall you need home strength.”</p> <p>All those games that frustrated Arsenal stemmed from a familiar model of Wenger’s men passing their way into cul-de-sacs formed by a well organised and diligent opposition rearguard. Chelsea, Swansea, West Ham and to an extent desperate Sunderland pulled off the same trick. Swamp the area in front of the final third Arsenal are trying to pick holes through, sit tight, and take it from there.</p> <p>“Against teams who came only to defend, we didn’t find the goal,” Wenger said. “But it happens to all the other teams as well. Normally you would think over 19 games you can sometimes be unlucky once or twice. Most of the time if you really dominate the games you will win.” The key to avoid falling into a similar trap when Liverpool visit on Monday night comes down to one critical aspect. “Play with good pace,” Wenger said.</p> <p>Liverpool are unlikely to be as obliging as they were last April, when Rodgers had a final stab at playing three at the back to see his defence comprehensively dismantled. There is a definite sense that they have started this campaign with more emphasis on resilience. With the fixture list putting up two assignments with bad memories – <a href=\\\"http://www.theguardian.com/football/2015/may/24/stoke-city-liverpool-premier-league-match-report\\\" title=\\\"\\\">Stoke</a> and Arsenal away where they conceded a combined 10 goals – before the international break gives Rodgers good reason to play more safely than he might normally want to. <a href=\\\"http://www.theguardian.com/football/2015/aug/21/jordan-henderson-liverpool-arsenal\\\" title=\\\"\\\">Jordan Henderson</a> has been impressive in the anchoring midfield role, and his fitness will be a big factor in Liverpool’s approach.</p> <p>Rodgers’ team are a work in progress as he tries to integrate the new signings, and build sparks and connections within the group. Although Wenger has set great store on the “cohesion” that comes with his squad being stable and largely unchanged, he is still tinkering to find the ideal balance. He seems undecided about whether it is best to play Santi Cazorla or Aaron Ramsey in central midfield (with the other positioned wider). “It is tricky,” Wenger said.</p> <aside class=\\\"element element-rich-link\\\"> <p> <span>Related: </span><a href=\\\"http://www.theguardian.com/football/2015/aug/22/arsene-wenger-arsenal-capitalise-talent-turnover\\\">Arsène Wenger says competition at ‘big, big clubs’ is good for Arsenal</a> </p> </aside> <p>“Santi is an important player in the buildup of our game. He is naturally a guy who brings fluidity, and gets you out of tight situations.” Sometimes, though Wenger wants more “physical power in the centre of the park” which is where Ramsey gets the nod.</p> <p>Although he says it is an “impossible job” to keep all the options who like to play centrally happy, Wenger is glad he is not having to deal with too much flux in his team. He does not Rodgers the job of rebuilding with Luis Suárez and Raheem Sterling prised away in successive summers.</p> <p>“Let’s remember two years ago with Suárez, Sturridge and Sterling they scored over a hundred goals. To score more than 100 goals in the Premier League, you need special quality to do that. Sterling was part of that. I personally rate Raheem Sterling. We will see that in the longer term. He’s a quality player. But they bought Firmino. We will see what he will produce. He is a similar player.”</p> <p>Does he have some empathy, having himself endured the picking off of key players in the past? “They refused to sell us Suárez so I cannot feel too much sympathy for them,” Wenger said with a wry smile.</p>"); newsArticleTestValues.put(NewsContract.NewsArticle.COLUMN_BYLINE, "Amy Lawrence"); newsArticleTestValues.put( NewsContract.NewsArticle.COLUMN_IMAGEURL, "http://media.guim.co.uk/fece5c28990b3b8baa19229a88164a4c6d52c21c/0_31_3500_2101/1000.jpg\\"); newsArticleTestValues.put( NewsContract.NewsArticle.COLUMN_THUMBNAILURL, "http://media.guim.co.uk/fece5c28990b3b8baa19229a88164a4c6d52c21c/0_31_3500_2101/1000.jpg\\"); newsArticleTestValues.put( NewsContract.NewsArticle.COLUMN_APIURL, "http://media.guim.co.uk/fece5c28990b3b8baa19229a88164a4c6d52c21c/0_31_3500_2101/1000.jpg\\"); long newsArticleRowID = db.insert(NewsContract.NewsArticle.TABLE_NAME, null, newsArticleTestValues); assertTrue(newsArticleRowID != -1); cursor = db.query(NewsContract.NewsArticle.TABLE_NAME, null, null, null, null, null, null); assertTrue("Error: Unable to retrieve data from NewsArticleTable", cursor.moveToFirst()); String error = "testInsertReadDb weatherEntry failed to validate"; Set<Map.Entry<String, Object>> valueSet = newsArticleTestValues.valueSet(); for (Map.Entry<String, Object> entry : valueSet) { columnName = entry.getKey(); int idx = cursor.getColumnIndex(columnName); assertFalse("Column '" + columnName + "' not found. " + error, idx == -1); String expectedValue = entry.getValue().toString(); assertEquals( "Value '" + entry.getValue().toString() + "' did not match the expected value '" + expectedValue + "'. " + error, expectedValue, cursor.getString(idx)); } assertFalse("Error: Multiple rows returned", cursor.moveToNext()); db.close(); cursor.close(); }
@Override public boolean commit() { Timber.d("DeckOptions - commit() changes back to database"); try { for (Entry<String, Object> entry : mUpdate.valueSet()) { String key = entry.getKey(); Object value = entry.getValue(); Timber.i("Change value for key '" + key + "': " + value); if (key.equals("maxAnswerTime")) { mOptions.put("maxTaken", (Integer) value); } else if (key.equals("newFactor")) { mOptions.getJSONObject("new").put("initialFactor", (Integer) value * 10); } else if (key.equals("newOrder")) { int newValue = Integer.parseInt((String) value); // Sorting is slow, so only do it if we change order int oldValue = mOptions.getJSONObject("new").getInt("order"); if (oldValue != newValue) { mOptions.getJSONObject("new").put("order", newValue); DeckTask.launchDeckTask( DeckTask.TASK_TYPE_REORDER, mConfChangeHandler, new DeckTask.TaskData(new Object[] {mOptions})); } mOptions.getJSONObject("new").put("order", Integer.parseInt((String) value)); } else if (key.equals("newPerDay")) { mOptions.getJSONObject("new").put("perDay", (Integer) value); } else if (key.equals("newGradIvl")) { JSONArray ja = new JSONArray(); // [graduating, easy] ja.put((Integer) value); ja.put(mOptions.getJSONObject("new").getJSONArray("ints").get(1)); mOptions.getJSONObject("new").put("ints", ja); } else if (key.equals("newEasy")) { JSONArray ja = new JSONArray(); // [graduating, easy] ja.put(mOptions.getJSONObject("new").getJSONArray("ints").get(0)); ja.put((Integer) value); mOptions.getJSONObject("new").put("ints", ja); } else if (key.equals("newBury")) { mOptions.getJSONObject("new").put("bury", (Boolean) value); } else if (key.equals("revPerDay")) { mOptions.getJSONObject("rev").put("perDay", (Integer) value); } else if (key.equals("easyBonus")) { mOptions.getJSONObject("rev").put("ease4", (Integer) value / 100.0f); } else if (key.equals("revIvlFct")) { mOptions.getJSONObject("rev").put("ivlFct", (Integer) value / 100.0f); } else if (key.equals("revMaxIvl")) { mOptions.getJSONObject("rev").put("maxIvl", (Integer) value); } else if (key.equals("revBury")) { mOptions.getJSONObject("rev").put("bury", (Boolean) value); } else if (key.equals("lapMinIvl")) { mOptions.getJSONObject("lapse").put("minInt", (Integer) value); } else if (key.equals("lapLeechThres")) { mOptions.getJSONObject("lapse").put("leechFails", (Integer) value); } else if (key.equals("lapLeechAct")) { mOptions.getJSONObject("lapse").put("leechAction", Integer.parseInt((String) value)); } else if (key.equals("lapNewIvl")) { mOptions.getJSONObject("lapse").put("mult", (Integer) value / 100.0f); } else if (key.equals("showAnswerTimer")) { mOptions.put("timer", (Boolean) value ? 1 : 0); } else if (key.equals("autoPlayAudio")) { mOptions.put("autoplay", (Boolean) value); } else if (key.equals("replayQuestion")) { mOptions.put("replayq", (Boolean) value); } else if (key.equals("desc")) { mDeck.put("desc", (String) value); mCol.getDecks().save(mDeck); } else if (key.equals("newSteps")) { mOptions .getJSONObject("new") .put("delays", StepsPreference.convertToJSON((String) value)); } else if (key.equals("lapSteps")) { mOptions .getJSONObject("lapse") .put("delays", StepsPreference.convertToJSON((String) value)); } else if (key.equals("deckConf")) { long newConfId = Long.parseLong((String) value); mOptions = mCol.getDecks().getConf(newConfId); DeckTask.launchDeckTask( DeckTask.TASK_TYPE_CONF_CHANGE, mConfChangeHandler, new DeckTask.TaskData(new Object[] {mDeck, mOptions})); // Restart to reflect the new preference values restartActivity(); } else if (key.equals("confRename")) { String newName = (String) value; if (!TextUtils.isEmpty(newName)) { mOptions.put("name", newName); } } else if (key.equals("confReset")) { if ((Boolean) value) { DeckTask.launchDeckTask( DeckTask.TASK_TYPE_CONF_RESET, mConfChangeHandler, new DeckTask.TaskData(new Object[] {mOptions})); } } else if (key.equals("confAdd")) { String newName = (String) value; if (!TextUtils.isEmpty(newName)) { // New config clones current config long id = mCol.getDecks().confId(newName, mOptions.toString()); mDeck.put("conf", id); mCol.getDecks().save(mDeck); } } else if (key.equals("confRemove")) { if (mOptions.getLong("id") == 1) { // Don't remove the options group if it's the default group Themes.showThemedToast( DeckOptions.this, getResources().getString(R.string.default_conf_delete_error), false); } else { // Remove options group, handling the case where the user needs to confirm full sync try { remConf(); } catch (ConfirmModSchemaException e) { // Libanki determined that a full sync will be required, so confirm with the user // before proceeding // TODO : Use ConfirmationDialog DialogFragment -- not compatible with // PreferenceActivity new MaterialDialog.Builder(DeckOptions.this) .content(R.string.full_sync_confirmation) .positiveText(R.string.dialog_ok) .negativeText(R.string.dialog_cancel) .callback( new MaterialDialog.ButtonCallback() { @Override public void onPositive(MaterialDialog dialog) { mCol.modSchemaNoCheck(); try { remConf(); } catch (ConfirmModSchemaException e) { // This should never be reached as we just forced modSchema throw new RuntimeException(e); } } }) .build() .show(); } } } else if (key.equals("confSetSubdecks")) { if ((Boolean) value) { DeckTask.launchDeckTask( DeckTask.TASK_TYPE_CONF_SET_SUBDECKS, mConfChangeHandler, new DeckTask.TaskData(new Object[] {mDeck, mOptions})); } } } } catch (JSONException e) { throw new RuntimeException(e); } // save conf try { mCol.getDecks().save(mOptions); } catch (RuntimeException e) { Timber.e("DeckOptions - RuntimeException on saving conf: " + e); AnkiDroidApp.sendExceptionReport(e, "DeckOptionsSaveConf"); setResult(DeckPicker.RESULT_DB_ERROR); finish(); } // make sure we refresh the parent cached values cacheValues(); buildLists(); updateSummaries(); // and update any listeners for (OnSharedPreferenceChangeListener listener : listeners) { listener.onSharedPreferenceChanged(DeckPreferenceHack.this, null); } return true; }