Skip to content

Commit

Permalink
Clear preferences for .db file
Browse files Browse the repository at this point in the history
  • Loading branch information
kamathprasad9 committed Jul 18, 2024
1 parent 5be89c5 commit a36733d
Showing 1 changed file with 15 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,10 @@ protected Integer doInBackground(Integer... params) {
database.importDatabase(file);

if (file.getName().equals("sample_db.zip") || file.getName().equals("sample.db")){
clearPreferences();
selectFirstField();
} else if (file.getName().endsWith(".db")){ // for a .db file, clear the preferences
clearPreferences();
}

} catch (Exception e) {
Expand All @@ -180,6 +183,18 @@ protected Integer doInBackground(Integer... params) {
return 0;
}

private void clearPreferences() {
// clear the previous preferences for a .db import
SharedPreferences.Editor edit = preferences.edit();

edit.putInt(GeneralKeys.SELECTED_FIELD_ID, -1);
edit.putString(GeneralKeys.UNIQUE_NAME, "");
edit.putString(GeneralKeys.PRIMARY_NAME, "");
edit.putString(GeneralKeys.SECONDARY_NAME, "");
edit.putBoolean(GeneralKeys.IMPORT_FIELD_FINISHED, false);
edit.apply();
}

public void selectFirstField() {

try {
Expand Down Expand Up @@ -218,22 +233,6 @@ protected void onPostExecute(Integer result) {
}
}

private int getSelectedFieldId(String field_file) {
ArrayList<FieldObject> fields = database.getAllFieldObjects();

//try and match study alias
for (FieldObject f : fields) {

if (f != null && f.getExp_alias() != null && f.getExp_alias().equals(field_file)) {

return f.getExp_id();

}
}
// if no match found, return -1
return -1;
}

private void showDatabaseExportDialog() {
LayoutInflater inflater = this.getLayoutInflater();
View layout = inflater.inflate(R.layout.dialog_save_database, null);
Expand Down

0 comments on commit a36733d

Please sign in to comment.