Skip to content

Instantly share code, notes, and snippets.

@varundwarkani
Created May 8, 2020 18:18
Show Gist options
  • Save varundwarkani/84c07fc6b0fe8d8058c90ffc2a6840f0 to your computer and use it in GitHub Desktop.
Save varundwarkani/84c07fc6b0fe8d8058c90ffc2a6840f0 to your computer and use it in GitHub Desktop.
private boolean validateDB() {
//One - DB might be corrupt with some wrong data flow.
//Two - Restoring using a bad file (Possibly, not a DB file).
appDatabase = AppDatabase.getAppDatabase(getApplicationContext());
if (sharedPreferences.getBoolean("restoringDatabase", false)) {
sharedPreferences.edit().putBoolean("restoringDatabase", false).apply();
//Check if restore has been done properly and delete the backupCheckpoint.
if (appDatabase.userDao().getUserCount() <= 0) {
//reset the file and delete the restoredFile. Alert the user of the same.
if (restoreDatabase()) {
//File successfully restored. Delete the backup file.
restoreSuccessDialog();
deleteRestoreBackupFile(getApplicationContext());
} else {
//File probably deleted or some other issue. Alert here with flushing DB.
flushDB();
resetScreen();
restoreFailureDialog();
}
return false;
}
} else {
if (appDatabase.userDao().getUserCount() <= 0) {
//Alert here that no user so DB flushed.
//Flush DB, take user to Name screen, delete restore File if present and create a new one.
flushDB();
resetScreen();
deleteRestoreBackupFile(getApplicationContext());
backupDatabaseForRestore(this, getApplicationContext());
dbIssueDialog();
return false;
}
}
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment