From a00afd5d7fc8ff864908ee50afd531200227b2d5 Mon Sep 17 00:00:00 2001 From: Grishka Date: Fri, 29 Sep 2023 03:20:58 +0300 Subject: [PATCH] Same crash fix in 2 more places ugh --- mastodon/build.gradle | 4 ++-- .../android/fragments/discover/DiscoverFragment.java | 12 ++++++++---- .../fragments/settings/SettingsServerFragment.java | 11 +++++++---- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/mastodon/build.gradle b/mastodon/build.gradle index 517d1ee11..592344c16 100644 --- a/mastodon/build.gradle +++ b/mastodon/build.gradle @@ -9,8 +9,8 @@ android { applicationId "org.joinmastodon.android" minSdk 23 targetSdk 33 - versionCode 69 - versionName "2.1.3" + versionCode 70 + versionName "2.1.4" 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/discover/DiscoverFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/discover/DiscoverFragment.java index 69beaca1b..c7e386563 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/discover/DiscoverFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/discover/DiscoverFragment.java @@ -280,15 +280,19 @@ public class DiscoverFragment extends AppKitFragment implements ScrollableToTop, @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); } @Override - public void onBindViewHolder(@NonNull SimpleViewHolder holder, int position){} + public void onBindViewHolder(@NonNull SimpleViewHolder holder, int position){ + FrameLayout view=tabViews[position]; + if(view.getParent() instanceof ViewGroup parent) + parent.removeView(view); + view.setVisibility(View.VISIBLE); + ((FrameLayout)holder.itemView).addView(view, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); + } @Override public int getItemCount(){ diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/SettingsServerFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/SettingsServerFragment.java index f89144158..0d27e27b0 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/SettingsServerFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/SettingsServerFragment.java @@ -146,18 +146,21 @@ public class SettingsServerFragment extends AppKitFragment{ @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); } @Override public void onBindViewHolder(@NonNull SimpleViewHolder holder, int position){ + FrameLayout view=tabViews[position]; + if(view.getParent() instanceof ViewGroup parent) + parent.removeView(view); + view.setVisibility(View.VISIBLE); + ((FrameLayout)holder.itemView).addView(view, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); Fragment fragment=getFragmentForPage(position); if(!fragment.isAdded()){ - getChildFragmentManager().beginTransaction().add(holder.itemView.getId(), fragment).commit(); + getChildFragmentManager().beginTransaction().add(view.getId(), fragment).commit(); holder.itemView.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener(){ @Override public boolean onPreDraw(){