From 283b56be5b5bc4bedfcb87156a26ff5a99fe6c5a Mon Sep 17 00:00:00 2001 From: Grishka Date: Thu, 28 Sep 2023 19:56:25 +0300 Subject: [PATCH] Finally fix the mysterious RecyclerView crash --- mastodon/build.gradle | 4 ++-- .../android/fragments/ProfileFragment.java | 18 +++++++----------- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/mastodon/build.gradle b/mastodon/build.gradle index f277c8376..b7b7e49cf 100644 --- a/mastodon/build.gradle +++ b/mastodon/build.gradle @@ -9,8 +9,8 @@ android { applicationId "org.joinmastodon.android" minSdk 23 targetSdk 33 - versionCode 68 - versionName "2.1.2" + versionCode 69 + versionName "2.1.3" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" resConfigs "ar-rSA", "be-rBY", "bn-rBD", "bs-rBA", "ca-rES", "cs-rCZ", "da-rDK", "de-rDE", "el-rGR", "es-rES", "eu-rES", "fa-rIR", "fi-rFI", "fil-rPH", "fr-rFR", "ga-rIE", "gd-rGB", "gl-rES", "hi-rIN", "hr-rHR", "hu-rHU", "hy-rAM", "ig-rNG", "in-rID", "is-rIS", "it-rIT", "iw-rIL", "ja-rJP", "kab", "ko-rKR", "my-rMM", "nl-rNL", "no-rNO", "oc-rFR", "pl-rPL", "pt-rBR", "pt-rPT", "ro-rRO", "ru-rRU", "si-rLK", "sl-rSI", "sv-rSE", "th-rTH", "tr-rTR", "uk-rUA", "ur-rIN", "vi-rVN", "zh-rCN", "zh-rTW" } diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/ProfileFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/ProfileFragment.java index cff9f787e..b4a8679b0 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/ProfileFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/ProfileFragment.java @@ -238,7 +238,6 @@ public class ProfileFragment extends LoaderFragment implements OnBackPressedList pager.setOffscreenPageLimit(4); pager.setAdapter(new ProfilePagerAdapter()); pager.getLayoutParams().height=getResources().getDisplayMetrics().heightPixels; - pager.setVisibility(View.GONE); // Prevents a strange NPE when search is opened on the search tab. Shown in onShown() scrollView.setScrollableChildSupplier(this::getScrollableRecyclerView); @@ -1041,19 +1040,11 @@ public class ProfileFragment extends LoaderFragment implements OnBackPressedList return actionButton.getVisibility()==View.VISIBLE && actionButtonWrap.getTop()+actionButtonWrap.getHeight()>scrollView.getScrollY(); } - @Override - protected void onShown(){ - super.onShown(); - pager.setVisibility(View.VISIBLE); - } - private class ProfilePagerAdapter extends RecyclerView.Adapter{ @NonNull @Override public SimpleViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType){ - FrameLayout view=tabViews[viewType]; - ((ViewGroup)view.getParent()).removeView(view); - view.setVisibility(View.VISIBLE); + FrameLayout view=new FrameLayout(parent.getContext()); view.setLayoutParams(new RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); return new SimpleViewHolder(view); } @@ -1061,8 +1052,13 @@ public class ProfileFragment extends LoaderFragment implements OnBackPressedList @Override public void onBindViewHolder(@NonNull SimpleViewHolder holder, int position){ Fragment fragment=getFragmentForPage(position); + FrameLayout fragmentView=tabViews[position]; + fragmentView.setVisibility(View.VISIBLE); + if(fragmentView.getParent() instanceof ViewGroup parent) + parent.removeView(fragmentView); + ((FrameLayout)holder.itemView).addView(fragmentView); if(!fragment.isAdded()){ - getChildFragmentManager().beginTransaction().add(holder.itemView.getId(), fragment).commit(); + getChildFragmentManager().beginTransaction().add(fragmentView.getId(), fragment).commit(); holder.itemView.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener(){ @Override public boolean onPreDraw(){