mirror of
https://github.com/ankidroid/Anki-Android.git
synced 2024-09-20 03:52:15 +02:00
Fix StudyOptionsDialog crashes with getCol does not work
- getCol may return null if there are no permissions yet - getCol may need to eat an exception if the backend is locked
This commit is contained in:
parent
d86863f3dd
commit
722fe806bd
@ -386,7 +386,7 @@ public class StudyOptionsFragment extends Fragment implements Toolbar.OnMenuItem
|
||||
mToolbar.setOnMenuItemClickListener(this);
|
||||
Menu menu = mToolbar.getMenu();
|
||||
// Switch on or off rebuild/empty/custom study depending on whether or not filtered deck
|
||||
if (getCol().getDecks().isDyn(getCol().getDecks().selected())) {
|
||||
if (getCol() != null && getCol().getDecks().isDyn(getCol().getDecks().selected())) {
|
||||
menu.findItem(R.id.action_rebuild).setVisible(true);
|
||||
menu.findItem(R.id.action_empty).setVisible(true);
|
||||
menu.findItem(R.id.action_custom_study).setVisible(false);
|
||||
@ -412,9 +412,9 @@ public class StudyOptionsFragment extends Fragment implements Toolbar.OnMenuItem
|
||||
menu.findItem(R.id.action_export).setVisible(false);
|
||||
}
|
||||
// Switch on or off unbury depending on if there are cards to unbury
|
||||
menu.findItem(R.id.action_unbury).setVisible(getCol().getSched().haveBuried());
|
||||
menu.findItem(R.id.action_unbury).setVisible(getCol() != null && getCol().getSched().haveBuried());
|
||||
// Switch on or off undo depending on whether undo is available
|
||||
if (!getCol().undoAvailable()) {
|
||||
if (getCol() == null || !getCol().undoAvailable()) {
|
||||
menu.findItem(R.id.action_undo).setVisible(false);
|
||||
} else {
|
||||
menu.findItem(R.id.action_undo).setVisible(true);
|
||||
@ -740,8 +740,13 @@ public class StudyOptionsFragment extends Fragment implements Toolbar.OnMenuItem
|
||||
return HtmlCompat.fromHtml(withFixedNewlines, HtmlCompat.FROM_HTML_MODE_LEGACY);
|
||||
}
|
||||
|
||||
private Collection getCol() {
|
||||
return CollectionHelper.getInstance().getCol(getContext());
|
||||
private @Nullable Collection getCol() {
|
||||
try {
|
||||
return CollectionHelper.getInstance().getCol(getContext());
|
||||
} catch (Exception e) {
|
||||
// This may happen if the backend is locked or similar.
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
@ -59,7 +59,7 @@ public class DeckPickerTest extends RobolectricTest {
|
||||
|
||||
@Parameters
|
||||
public static java.util.Collection<String> initParameters() {
|
||||
return Arrays.asList("normal"); //, "xlarge");
|
||||
return Arrays.asList("normal", "xlarge");
|
||||
}
|
||||
|
||||
@Before
|
||||
|
Loading…
Reference in New Issue
Block a user