From 34ebd35fc083961f64876a5e2db356bbe2a29e6f Mon Sep 17 00:00:00 2001 From: Grishka Date: Fri, 15 Apr 2022 17:12:12 +0300 Subject: [PATCH] Make instance catalog work if joinmastodon.org is unavailable --- .../onboarding/InstanceCatalogFragment.java | 26 +++++++++++++------ 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/onboarding/InstanceCatalogFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/onboarding/InstanceCatalogFragment.java index c5a24b7e..10aa1605 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/onboarding/InstanceCatalogFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/onboarding/InstanceCatalogFragment.java @@ -142,7 +142,8 @@ public class InstanceCatalogFragment extends BaseRecyclerFragmentcc.serversCount).reversed()).forEach(categories::add); - 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); - } + updateCategories(); } @Override public void onError(ErrorResponse error){ getCategoriesRequest=null; error.showToast(getActivity()); + CatalogCategory all=new CatalogCategory(); + all.category="all"; + categories.add(all); + updateCategories(); } }) .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 public void onDestroy(){ super.onDestroy();