Search in sources :

Example 6 with GameDBHelper

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);
}
Also used : Game(com.nolanlawson.keepscore.db.Game) GameDBHelper(com.nolanlawson.keepscore.db.GameDBHelper) List(java.util.List) ArrayList(java.util.ArrayList) ProgressDialog(android.app.ProgressDialog)

Example 7 with GameDBHelper

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();
        }
    }
}
Also used : Game(com.nolanlawson.keepscore.db.Game) GameDBHelper(com.nolanlawson.keepscore.db.GameDBHelper) GamesBackup(com.nolanlawson.keepscore.serialization.GamesBackup)

Aggregations

GameDBHelper (com.nolanlawson.keepscore.db.GameDBHelper)7 Game (com.nolanlawson.keepscore.db.Game)5 ArrayList (java.util.ArrayList)4 GamesBackup (com.nolanlawson.keepscore.serialization.GamesBackup)3 ProgressDialog (android.app.ProgressDialog)2 List (java.util.List)2 DialogInterface (android.content.DialogInterface)1 AsyncTask (android.os.AsyncTask)1 EditText (android.widget.EditText)1 LoadGamesBackupResult (com.nolanlawson.keepscore.data.LoadGamesBackupResult)1 Delta (com.nolanlawson.keepscore.db.Delta)1 PlayerScore (com.nolanlawson.keepscore.db.PlayerScore)1