Added check that Fragment is not null

This commit is contained in:
misaochan 2016-01-26 16:53:31 +13:00
parent 5e500fa653
commit 4f654f3b72

View file

@ -133,34 +133,39 @@ public class CategorizationFragment extends SherlockFragment{
protected void setCatsAfterAsync(ArrayList<String> categories, String filter) { protected void setCatsAfterAsync(ArrayList<String> categories, String filter) {
ArrayList<CategoryItem> items = new ArrayList<CategoryItem>(); if (getActivity() != null) {
HashSet<String> existingKeys = new HashSet<String>(); ArrayList<CategoryItem> items = new ArrayList<CategoryItem>();
for(CategoryItem item : categoriesAdapter.getItems()) { HashSet<String> existingKeys = new HashSet<String>();
if(item.selected) { for (CategoryItem item : categoriesAdapter.getItems()) {
items.add(item); if (item.selected) {
existingKeys.add(item.name); items.add(item);
existingKeys.add(item.name);
}
} }
} for (String category : categories) {
for(String category : categories) { if (!existingKeys.contains(category)) {
if(!existingKeys.contains(category)) { items.add(new CategoryItem(category, false));
items.add(new CategoryItem(category, false)); }
} }
}
categoriesAdapter.setItems(items); categoriesAdapter.setItems(items);
categoriesAdapter.notifyDataSetInvalidated(); categoriesAdapter.notifyDataSetInvalidated();
categoriesSearchInProgress.setVisibility(View.GONE); categoriesSearchInProgress.setVisibility(View.GONE);
if (categories.isEmpty()) { if (categories.isEmpty()) {
if(TextUtils.isEmpty(filter)) { if (TextUtils.isEmpty(filter)) {
// If we found no recent cats, show the skip message! // If we found no recent cats, show the skip message!
categoriesSkip.setVisibility(View.VISIBLE); categoriesSkip.setVisibility(View.VISIBLE);
} else {
categoriesNotFoundView.setText(getString(R.string.categories_not_found, filter));
categoriesNotFoundView.setVisibility(View.VISIBLE);
}
} else { } else {
categoriesNotFoundView.setText(getString(R.string.categories_not_found, filter)); categoriesList.smoothScrollToPosition(existingKeys.size());
categoriesNotFoundView.setVisibility(View.VISIBLE);
} }
} else { }
categoriesList.smoothScrollToPosition(existingKeys.size()); else {
Log.e(TAG, "Error: Fragment is null");
} }
} }