use of com.nolanlawson.keepscore.db.GameDBHelper in project KeepScore by nolanlawson.
the class MainActivity method exportToSpreadsheet.
private void exportToSpreadsheet(final List<Integer> gameIds) {
final ProgressDialog progressDialog = showProgressDialog(R.string.text_loading_generic, // plus one for saving the spreadsheet itself
gameIds.size() + 1);
new AsyncTask<Void, Void, String>() {
@Override
protected String doInBackground(Void... params) {
List<Game> games = new ArrayList<Game>();
GameDBHelper dbHelper = null;
try {
dbHelper = new GameDBHelper(MainActivity.this);
for (Integer gameId : gameIds) {
games.add(dbHelper.findGameById(gameId));
publishProgress((Void) null);
}
} finally {
if (dbHelper != null) {
dbHelper.close();
}
}
String filename = SdcardHelper.createSpreadsheetFilename();
SdcardHelper.saveSpreadsheet(filename, games, MainActivity.this);
publishProgress((Void) null);
return filename;
}
@Override
protected void onProgressUpdate(Void... values) {
super.onProgressUpdate(values);
progressDialog.incrementProgressBy(1);
}
@Override
protected void onPostExecute(String filename) {
super.onPostExecute(filename);
progressDialog.dismiss();
sendSpreadsheetAsAttachment(filename, gameIds.size());
}
}.execute((Void) null);
}
use of com.nolanlawson.keepscore.db.GameDBHelper in project KeepScore by nolanlawson.
the class PeriodicAutomaticBackupService method onHandleIntent.
@Override
protected void onHandleIntent(Intent intent) {
String filename = SdcardHelper.createBackupFilename(Format.GZIP);
GameDBHelper dbHelper = null;
try {
dbHelper = new GameDBHelper(this);
List<Game> games = dbHelper.findAllGames();
log.i("Beginning periodic automatic backup of %d saved KeepScore games...", games.size());
GamesBackup gamesBackup = new GamesBackup();
gamesBackup.setVersion(GamesBackupSerializer.CURRENT_VERSION);
gamesBackup.setDateSaved(System.currentTimeMillis());
gamesBackup.setGameCount(games.size());
gamesBackup.setAutomatic(true);
gamesBackup.setFilename(filename);
gamesBackup.setGames(games);
String xmlData = GamesBackupSerializer.serialize(gamesBackup);
SdcardHelper.save(filename, Format.GZIP, Location.Backups, xmlData);
log.i("KeepScore backed up %d games to \"%s\".", games.size(), filename);
} finally {
if (dbHelper != null) {
dbHelper.close();
}
}
}
Aggregations