From 817b1ddb32594175b0f7d062dc76d298a32bb8fd Mon Sep 17 00:00:00 2001 From: Jerry <158509342+rry-je@users.noreply.github.com> Date: Thu, 17 Oct 2024 13:43:15 +0200 Subject: [PATCH] Fix stuck UI after rotation (#275) --- .../kotlin/org/fossify/gallery/adapters/MyPagerAdapter.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/src/main/kotlin/org/fossify/gallery/adapters/MyPagerAdapter.kt b/app/src/main/kotlin/org/fossify/gallery/adapters/MyPagerAdapter.kt index b95564e52..bf829134a 100644 --- a/app/src/main/kotlin/org/fossify/gallery/adapters/MyPagerAdapter.kt +++ b/app/src/main/kotlin/org/fossify/gallery/adapters/MyPagerAdapter.kt @@ -33,7 +33,6 @@ class MyPagerAdapter(val activity: ViewPagerActivity, fm: FragmentManager, val m } fragment.arguments = bundle - fragment.listener = activity return fragment } @@ -41,6 +40,10 @@ class MyPagerAdapter(val activity: ViewPagerActivity, fm: FragmentManager, val m override fun instantiateItem(container: ViewGroup, position: Int): Any { val fragment = super.instantiateItem(container, position) as ViewPagerFragment + + // getItem() might not be called if the activity is recreated, so the listener must be set here + fragment.listener = activity + fragments[position] = fragment return fragment }