From a012e26d635153a012fce067df200cc50d02ab5e Mon Sep 17 00:00:00 2001 From: evermind Date: Wed, 5 May 2021 08:55:54 +0200 Subject: [PATCH] =?UTF-8?q?fix=20Rotation=20crash=20on=20=E2=80=9EVideo=20?= =?UTF-8?q?not=20available=E2=80=9C=20page=20(#5941)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The EmptyFragment should not have a constructor at all. Now a static methods creates the Fragment and arguments are handled via a Bundle. --- .../org/schabi/newpipe/fragments/EmptyFragment.java | 11 ++++++++--- .../newpipe/fragments/detail/VideoDetailFragment.java | 6 +++--- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/fragments/EmptyFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/EmptyFragment.java index fbf2711bc..d4e73bcac 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/EmptyFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/EmptyFragment.java @@ -11,15 +11,20 @@ import org.schabi.newpipe.BaseFragment; import org.schabi.newpipe.R; public class EmptyFragment extends BaseFragment { - final boolean showMessage; + private static final String SHOW_MESSAGE = "SHOW_MESSAGE"; - public EmptyFragment(final boolean showMessage) { - this.showMessage = showMessage; + public static final EmptyFragment newInstance(final boolean showMessage) { + final EmptyFragment emptyFragment = new EmptyFragment(); + final Bundle bundle = new Bundle(1); + bundle.putBoolean(SHOW_MESSAGE, showMessage); + emptyFragment.setArguments(bundle); + return emptyFragment; } @Override public View onCreateView(final LayoutInflater inflater, @Nullable final ViewGroup container, final Bundle savedInstanceState) { + final boolean showMessage = getArguments().getBoolean(SHOW_MESSAGE); final View view = inflater.inflate(R.layout.fragment_empty, container, false); view.findViewById(R.id.empty_state_view).setVisibility( showMessage ? View.VISIBLE : View.GONE); diff --git a/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java index 71739ba3d..784a1c3be 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java @@ -929,20 +929,20 @@ public final class VideoDetailFragment if (showRelatedItems && binding.relatedItemsLayout == null) { // temp empty fragment. will be updated in handleResult - pageAdapter.addFragment(new EmptyFragment(false), RELATED_TAB_TAG); + pageAdapter.addFragment(EmptyFragment.newInstance(false), RELATED_TAB_TAG); tabIcons.add(R.drawable.ic_art_track); tabContentDescriptions.add(R.string.related_items_tab_description); } if (showDescription) { // temp empty fragment. will be updated in handleResult - pageAdapter.addFragment(new EmptyFragment(false), DESCRIPTION_TAB_TAG); + pageAdapter.addFragment(EmptyFragment.newInstance(false), DESCRIPTION_TAB_TAG); tabIcons.add(R.drawable.ic_description); tabContentDescriptions.add(R.string.description_tab_description); } if (pageAdapter.getCount() == 0) { - pageAdapter.addFragment(new EmptyFragment(true), EMPTY_TAB_TAG); + pageAdapter.addFragment(EmptyFragment.newInstance(true), EMPTY_TAB_TAG); } pageAdapter.notifyDataSetUpdate();