Prevent crash

This commit is contained in:
M66B 2019-01-15 08:03:04 +00:00
parent 51f49c9c22
commit 05f62b4cae
1 changed files with 11 additions and 7 deletions

View File

@ -449,13 +449,17 @@ public class FragmentMessages extends FragmentEx {
public void onSelectionChanged() {
// Workaround AndroidX bug
FragmentActivity activity = getActivity();
if (activity != null) {
ViewModelMessages modelMessages = ViewModelProviders.of(activity).get(ViewModelMessages.class);
if (selectionTracker.hasSelection())
modelMessages.removeObservers(viewType, getViewLifecycleOwner());
else
modelMessages.observe(viewType, getViewLifecycleOwner(), observer);
}
if (activity != null)
try {
ViewModelMessages modelMessages = ViewModelProviders.of(activity).get(ViewModelMessages.class);
if (selectionTracker.hasSelection())
modelMessages.removeObservers(viewType, getViewLifecycleOwner());
else
modelMessages.observe(viewType, getViewLifecycleOwner(), observer);
} catch (IllegalStateException ex) {
// getViewLifecycleOwner
Log.w(ex);
}
if (selectionTracker.hasSelection()) {
swipeRefresh.setEnabled(false);