private void copyBetweenDatabases() { DatabaseHelper dbHelper = new DatabaseHelper(this); try { dbHelper.openDataBase(false); } catch (SQLException e) { e.printStackTrace(); } List<TestContainer> list = dbHelper.getTests(); dbHelper.close(); DatabaseHelper.DB_NAME = DatabaseHelper.DB_NAME.equals(DatabaseHelper.DB_AM) ? DatabaseHelper.DB_RU : DatabaseHelper.DB_AM; dbHelper = new DatabaseHelper(this); try { dbHelper.openDataBase(true); } catch (SQLException e) { e.printStackTrace(); } for (int i = 0; i < list.size(); i++) { int newDbProgress = dbHelper.getTests().get(i).getProgress(); int oldDbProgress = list.get(i).getProgress(); if (oldDbProgress != newDbProgress) { dbHelper.updateProgress(i + 1, oldDbProgress); } } dbHelper.close(); }
private void copyOldData() { SharedPreferences preferences = null; try { preferences = getSharedPreferences("tests", 0); } catch (Exception e) { } if (preferences != null) { DatabaseHelper db = new DatabaseHelper(this); try { db.openDataBase(true); } catch (SQLException e) { e.printStackTrace(); } for (int i = 1; i <= 62; ++i) { String name = "Test" + String.valueOf(i); String percent = preferences.getString(name, null); if (percent != null) { int progress = Integer.parseInt(percent.substring(0, percent.length() - 1)); if (progress != db.getTests().get(i - 1).getProgress()) db.updateProgress(i, progress); } } db.close(); preferences.edit().clear().commit(); } }