Skip to content

Commit

Permalink
make sure the report selection is not empty
Browse files Browse the repository at this point in the history
  • Loading branch information
mathisdt committed Dec 27, 2023
1 parent 7ac586a commit f17f174
Showing 1 changed file with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,24 +124,28 @@ public boolean onOptionsItemSelected(@NonNull MenuItem item) {

private void restoreSelectionState() {
int rangeId = loadSelectedId(Key.REPORT_LAST_RANGE);
checkRadioGroup(binding.range, rangeId);
checkRadioGroup(binding.range, rangeId, R.id.rangeLast);

int unitId = loadSelectedId(Key.REPORT_LAST_UNIT);
checkRadioGroup(binding.unit, unitId);
checkRadioGroup(binding.unit, unitId, R.id.unitWeek);

int groupingId = loadSelectedId(Key.REPORT_LAST_GROUPING);
checkRadioGroup(binding.grouping, groupingId);
checkRadioGroup(binding.grouping, groupingId, R.id.groupingNone);
}

private int loadSelectedId(Key key) {
return preferences.getInt(key.getName(), NO_ID);
}

private void checkRadioGroup(RadioGroup group, int idToCheck) {
if (idToCheck == NO_ID || group.findViewById(idToCheck) == null) {
private void checkRadioGroup(RadioGroup group, int idToCheck, int backupIdToCheck) {
if (group.findViewById(idToCheck) == null) {
return;
}
group.check(idToCheck);
if (idToCheck == NO_ID) {
group.check(backupIdToCheck);
} else {
group.check(idToCheck);
}
}

private void preview() {
Expand Down

0 comments on commit f17f174

Please sign in to comment.