Make instance catalog work if joinmastodon.org is unavailable

This commit is contained in:
Grishka 2022-04-15 17:12:12 +03:00
parent 19d0af01fd
commit 34ebd35fc0
1 changed files with 18 additions and 8 deletions

View File

@ -142,7 +142,8 @@ public class InstanceCatalogFragment extends BaseRecyclerFragment<CatalogInstanc
@Override @Override
public void onError(ErrorResponse error){ public void onError(ErrorResponse error){
InstanceCatalogFragment.this.onError(error); error.showToast(getActivity());
onDataLoaded(Collections.emptyList(), false);
} }
}) })
.execNoAuth(""); .execNoAuth("");
@ -155,24 +156,33 @@ public class InstanceCatalogFragment extends BaseRecyclerFragment<CatalogInstanc
all.category="all"; all.category="all";
categories.add(all); categories.add(all);
result.stream().sorted(Comparator.comparingInt((CatalogCategory cc)->cc.serversCount).reversed()).forEach(categories::add); result.stream().sorted(Comparator.comparingInt((CatalogCategory cc)->cc.serversCount).reversed()).forEach(categories::add);
for(CatalogCategory cat:categories){ updateCategories();
int titleRes=getTitleForCategory(cat.category);
TabLayout.Tab tab=categoriesList.newTab().setText(titleRes!=0 ? getString(titleRes) : cat.category).setCustomView(R.layout.item_instance_category);
ImageView emoji=tab.getCustomView().findViewById(R.id.emoji);
emoji.setImageResource(getEmojiForCategory(cat.category));
categoriesList.addTab(tab);
}
} }
@Override @Override
public void onError(ErrorResponse error){ public void onError(ErrorResponse error){
getCategoriesRequest=null; getCategoriesRequest=null;
error.showToast(getActivity()); error.showToast(getActivity());
CatalogCategory all=new CatalogCategory();
all.category="all";
categories.add(all);
updateCategories();
} }
}) })
.execNoAuth(""); .execNoAuth("");
} }
private void updateCategories(){
categoriesList.removeAllTabs();
for(CatalogCategory cat:categories){
int titleRes=getTitleForCategory(cat.category);
TabLayout.Tab tab=categoriesList.newTab().setText(titleRes!=0 ? getString(titleRes) : cat.category).setCustomView(R.layout.item_instance_category);
ImageView emoji=tab.getCustomView().findViewById(R.id.emoji);
emoji.setImageResource(getEmojiForCategory(cat.category));
categoriesList.addTab(tab);
}
}
@Override @Override
public void onDestroy(){ public void onDestroy(){
super.onDestroy(); super.onDestroy();