mirror of
https://github.com/TeamNewPipe/NewPipe
synced 2024-12-23 08:30:44 +00:00
Fixed default visibility of "new feed items" button
Fixed/Avoid NPEs
This commit is contained in:
parent
700c1b4b25
commit
4eb02f584e
@ -32,6 +32,7 @@ import android.view.MenuInflater
|
|||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
|
import android.widget.Button
|
||||||
import androidx.annotation.Nullable
|
import androidx.annotation.Nullable
|
||||||
import androidx.appcompat.app.AlertDialog
|
import androidx.appcompat.app.AlertDialog
|
||||||
import androidx.appcompat.content.res.AppCompatResources
|
import androidx.appcompat.content.res.AppCompatResources
|
||||||
@ -151,7 +152,7 @@ class FeedFragment : BaseStateFragment<FeedState>() {
|
|||||||
!recyclerView.canScrollVertically(-1)
|
!recyclerView.canScrollVertically(-1)
|
||||||
) {
|
) {
|
||||||
|
|
||||||
if (feedBinding.newItemsLoadedButton.isVisible) {
|
if (tryGetNewItemsLoadedButton()?.isVisible == true) {
|
||||||
hideNewItemsLoaded(true)
|
hideNewItemsLoaded(true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -264,6 +265,9 @@ class FeedFragment : BaseStateFragment<FeedState>() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroyView() {
|
override fun onDestroyView() {
|
||||||
|
// Ensure that all animations are canceled
|
||||||
|
feedBinding.newItemsLoadedButton?.clearAnimation()
|
||||||
|
|
||||||
feedBinding.itemsList.adapter = null
|
feedBinding.itemsList.adapter = null
|
||||||
_feedBinding = null
|
_feedBinding = null
|
||||||
super.onDestroyView()
|
super.onDestroyView()
|
||||||
@ -619,9 +623,9 @@ class FeedFragment : BaseStateFragment<FeedState>() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun showNewItemsLoaded() {
|
private fun showNewItemsLoaded() {
|
||||||
feedBinding.newItemsLoadedButton.clearAnimation()
|
tryGetNewItemsLoadedButton()?.clearAnimation()
|
||||||
feedBinding.newItemsLoadedButton
|
tryGetNewItemsLoadedButton()
|
||||||
.slideUp(
|
?.slideUp(
|
||||||
250L,
|
250L,
|
||||||
delay = 100,
|
delay = 100,
|
||||||
execOnEnd = {
|
execOnEnd = {
|
||||||
@ -636,23 +640,32 @@ class FeedFragment : BaseStateFragment<FeedState>() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun hideNewItemsLoaded(animate: Boolean, delay: Long = 0) {
|
private fun hideNewItemsLoaded(animate: Boolean, delay: Long = 0) {
|
||||||
feedBinding.newItemsLoadedButton.clearAnimation()
|
tryGetNewItemsLoadedButton()?.clearAnimation()
|
||||||
if (animate) {
|
if (animate) {
|
||||||
feedBinding.newItemsLoadedButton.animate(
|
tryGetNewItemsLoadedButton()?.animate(
|
||||||
false,
|
false,
|
||||||
200,
|
200,
|
||||||
delay = delay,
|
delay = delay,
|
||||||
execOnEnd = {
|
execOnEnd = {
|
||||||
// Make the layout invisible so that the onScroll toTop method
|
// Make the layout invisible so that the onScroll toTop method
|
||||||
// only does necessary work
|
// only does necessary work
|
||||||
feedBinding?.newItemsLoadedButton?.isVisible = false
|
tryGetNewItemsLoadedButton()?.isVisible = false
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
} else {
|
} 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
|
// Load Service Handling
|
||||||
// /////////////////////////////////////////////////////////////////////////
|
// /////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -96,7 +96,9 @@
|
|||||||
android:layout_marginBottom="5sp"
|
android:layout_marginBottom="5sp"
|
||||||
android:text="@string/feed_new_items"
|
android:text="@string/feed_new_items"
|
||||||
android:textSize="12sp"
|
android:textSize="12sp"
|
||||||
android:theme="@style/ServiceColoredButton" />
|
android:theme="@style/ServiceColoredButton"
|
||||||
|
android:visibility="gone"
|
||||||
|
tools:visibility="visible" />
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
|
Loading…
Reference in New Issue
Block a user