diff --git a/app/src/main/java/org/schabi/newpipe/local/feed/FeedFragment.kt b/app/src/main/java/org/schabi/newpipe/local/feed/FeedFragment.kt index 16b38aac9..a982f5e52 100644 --- a/app/src/main/java/org/schabi/newpipe/local/feed/FeedFragment.kt +++ b/app/src/main/java/org/schabi/newpipe/local/feed/FeedFragment.kt @@ -32,6 +32,7 @@ import android.view.MenuInflater import android.view.MenuItem import android.view.View import android.view.ViewGroup +import android.widget.Button import androidx.annotation.Nullable import androidx.appcompat.app.AlertDialog import androidx.appcompat.content.res.AppCompatResources @@ -151,7 +152,7 @@ class FeedFragment : BaseStateFragment() { !recyclerView.canScrollVertically(-1) ) { - if (feedBinding.newItemsLoadedButton.isVisible) { + if (tryGetNewItemsLoadedButton()?.isVisible == true) { hideNewItemsLoaded(true) } } @@ -264,6 +265,9 @@ class FeedFragment : BaseStateFragment() { } override fun onDestroyView() { + // Ensure that all animations are canceled + feedBinding.newItemsLoadedButton?.clearAnimation() + feedBinding.itemsList.adapter = null _feedBinding = null super.onDestroyView() @@ -619,9 +623,9 @@ class FeedFragment : BaseStateFragment() { } private fun showNewItemsLoaded() { - feedBinding.newItemsLoadedButton.clearAnimation() - feedBinding.newItemsLoadedButton - .slideUp( + tryGetNewItemsLoadedButton()?.clearAnimation() + tryGetNewItemsLoadedButton() + ?.slideUp( 250L, delay = 100, execOnEnd = { @@ -636,23 +640,32 @@ class FeedFragment : BaseStateFragment() { } private fun hideNewItemsLoaded(animate: Boolean, delay: Long = 0) { - feedBinding.newItemsLoadedButton.clearAnimation() + tryGetNewItemsLoadedButton()?.clearAnimation() if (animate) { - feedBinding.newItemsLoadedButton.animate( + tryGetNewItemsLoadedButton()?.animate( false, 200, delay = delay, execOnEnd = { // Make the layout invisible so that the onScroll toTop method // only does necessary work - feedBinding?.newItemsLoadedButton?.isVisible = false + tryGetNewItemsLoadedButton()?.isVisible = false } ) } else { - feedBinding.newItemsLoadedButton.isVisible = false + tryGetNewItemsLoadedButton()?.isVisible = false } } + /** + * The view/button can be disposed/set to null under certain circumstances. + * E.g. when the animation is still in progress but the view got destroyed. + * This method is a helper for such states and can be used in affected code blocks. + */ + private fun tryGetNewItemsLoadedButton(): Button? { + return _feedBinding?.newItemsLoadedButton + } + // ///////////////////////////////////////////////////////////////////////// // Load Service Handling // ///////////////////////////////////////////////////////////////////////// diff --git a/app/src/main/res/layout/fragment_feed.xml b/app/src/main/res/layout/fragment_feed.xml index 73e9d2ed1..ebe76af0c 100644 --- a/app/src/main/res/layout/fragment_feed.xml +++ b/app/src/main/res/layout/fragment_feed.xml @@ -96,7 +96,9 @@ android:layout_marginBottom="5sp" android:text="@string/feed_new_items" android:textSize="12sp" - android:theme="@style/ServiceColoredButton" /> + android:theme="@style/ServiceColoredButton" + android:visibility="gone" + tools:visibility="visible" />