BD: changeDaySentence() reasigna la frase de un día (rewarded)
This commit is contained in:
1 parent
4919118fc5
commit
a7dc176318
1 file changed
+44
@@ -320,6 +320,50 @@ public class DatabaseHelper {
|
|||||||
cal.get(java.util.Calendar.DAY_OF_MONTH));
|
cal.get(java.util.Calendar.DAY_OF_MONTH));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cambia la frase asignada a un día (rewarded): borra la asignación y
|
||||||
|
* asigna una frase sin usar distinta de la anterior. Devuelve el nuevo ID
|
||||||
|
* (0 si no quedan frases).
|
||||||
|
*/
|
||||||
|
int changeDaySentence(int year, int month, int dayOfMonth) {
|
||||||
|
String diaArg = String.format(Locale.US, "%04d%02d%02d", year, month, dayOfMonth);
|
||||||
|
int oldId = -1;
|
||||||
|
try (Cursor c = userDb.rawQuery("SELECT IDFrase FROM frasesG WHERE Tday = ?",
|
||||||
|
new String[]{diaArg})) {
|
||||||
|
if (c.moveToFirst()) {
|
||||||
|
oldId = c.getInt(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
userDb.delete("frasesG", "Tday = ?", new String[]{diaArg});
|
||||||
|
int nuevoId = pickUnusedID();
|
||||||
|
if (nuevoId == 0 || nuevoId == oldId) {
|
||||||
|
/* Sin frases nuevas: reponer la que había si la borró sin reemplazo */
|
||||||
|
if (nuevoId == 0) {
|
||||||
|
if (oldId > 0) {
|
||||||
|
ContentValues cv = new ContentValues();
|
||||||
|
cv.put("Tday", diaArg);
|
||||||
|
cv.put("IDFrase", oldId);
|
||||||
|
userDb.insertWithOnConflict("frasesG", null, cv, SQLiteDatabase.CONFLICT_IGNORE);
|
||||||
|
}
|
||||||
|
return oldId > 0 ? oldId : 0;
|
||||||
|
}
|
||||||
|
/* La aleatoria cayó en la misma: reintentar una vez */
|
||||||
|
nuevoId = pickUnusedID();
|
||||||
|
if (nuevoId == 0 || nuevoId == oldId) {
|
||||||
|
ContentValues cv = new ContentValues();
|
||||||
|
cv.put("Tday", diaArg);
|
||||||
|
cv.put("IDFrase", oldId > 0 ? oldId : nuevoId);
|
||||||
|
userDb.insertWithOnConflict("frasesG", null, cv, SQLiteDatabase.CONFLICT_IGNORE);
|
||||||
|
return oldId > 0 ? oldId : nuevoId;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ContentValues cv = new ContentValues();
|
||||||
|
cv.put("Tday", diaArg);
|
||||||
|
cv.put("IDFrase", nuevoId);
|
||||||
|
userDb.insertWithOnConflict("frasesG", null, cv, SQLiteDatabase.CONFLICT_IGNORE);
|
||||||
|
return nuevoId;
|
||||||
|
}
|
||||||
|
|
||||||
/** Returns an array of favorite IDs */
|
/** Returns an array of favorite IDs */
|
||||||
Integer[] getIDFavs() {
|
Integer[] getIDFavs() {
|
||||||
List<Integer> a = new ArrayList<>();
|
List<Integer> a = new ArrayList<>();
|
||||||
|
|||||||
Reference in new issue
Block a user