Skip to content

Commit

Permalink
Merge pull request TeamNewPipe#6550 from Douile/fix/clickthrough-feed…
Browse files Browse the repository at this point in the history
…-refresh

Disable feed click events while refresh overlay is shown
  • Loading branch information
Stypox authored and ShareASmile committed Aug 16, 2021
1 parent 14a2407 commit 902ef11
Showing 1 changed file with 50 additions and 1 deletion.
51 changes: 50 additions & 1 deletion app/src/main/java/org/schabi/newpipe/local/feed/FeedFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ import org.schabi.newpipe.local.feed.service.FeedLoadService
import org.schabi.newpipe.report.UserAction
import org.schabi.newpipe.util.AnimationUtils.animateView
import org.schabi.newpipe.util.Localization

class FeedFragment : BaseListFragment<FeedState, Unit>() {
private lateinit var viewModel: FeedViewModel
private lateinit var swipeRefreshLayout: SwipeRefreshLayout
Expand All @@ -63,6 +62,14 @@ class FeedFragment : BaseListFragment<FeedState, Unit>() {
private var groupId = FeedGroupEntity.GROUP_ALL_ID
private var groupName = ""
private var oldestSubscriptionUpdate: Calendar? = null
private var oldestSubscriptionUpdate: OffsetDateTime? = null

private lateinit var groupAdapter: GroupAdapter<GroupieViewHolder>
@State @JvmField var showPlayedItems: Boolean = true

private var onSettingsChangeListener: SharedPreferences.OnSharedPreferenceChangeListener? = null
private var updateListViewModeOnResume = false
private var isRefreshing = false

init {
setHasOptionsMenu(true)
Expand Down Expand Up @@ -191,6 +198,21 @@ class FeedFragment : BaseListFragment<FeedState, Unit>() {
empty_state_view?.let { animateView(it, false, 0) }
animateView(error_panel, false, 0)
swipeRefreshLayout.isRefreshing = false
super.showLoading()
feedBinding.itemsList.animateHideRecyclerViewAllowingScrolling()
feedBinding.refreshRootView.animate(false, 0)
feedBinding.loadingProgressText.animate(true, 200)
feedBinding.swipeRefreshLayout.isRefreshing = true
isRefreshing = true
}

override fun hideLoading() {
super.hideLoading()
feedBinding.itemsList.animate(true, 0)
feedBinding.refreshRootView.animate(true, 200)
feedBinding.loadingProgressText.animate(false, 0)
feedBinding.swipeRefreshLayout.isRefreshing = false
isRefreshing = false
}

override fun showEmptyState() {
Expand Down Expand Up @@ -227,6 +249,15 @@ class FeedFragment : BaseListFragment<FeedState, Unit>() {
updateRefreshViewState()
}

override fun handleError() {
super.handleError()
feedBinding.itemsList.animateHideRecyclerViewAllowingScrolling()
feedBinding.refreshRootView.animate(false, 0)
feedBinding.loadingProgressText.animate(false, 0)
feedBinding.swipeRefreshLayout.isRefreshing = false
isRefreshing = false
}

private fun handleProgressState(progressState: FeedState.ProgressState) {
showLoading()

Expand All @@ -246,6 +277,24 @@ class FeedFragment : BaseListFragment<FeedState, Unit>() {
loading_progress_bar.progress = progressState.currentProgress

loading_progress_bar.max = progressState.maxProgress
private val listenerStreamItem = object : OnItemClickListener, OnItemLongClickListener {
override fun onItemClick(item: Item<*>, view: View) {
if (item is StreamItem && !isRefreshing) {
val stream = item.streamWithState.stream
NavigationHelper.openVideoDetailFragment(
requireContext(), fm,
stream.serviceId, stream.url, stream.title, null, false
)
}
}

override fun onItemLongClick(item: Item<*>, view: View): Boolean {
if (item is StreamItem && !isRefreshing) {
showStreamDialog(item.streamWithState.stream.toStreamInfoItem())
return true
}
return false
}
}

private fun handleLoadedState(loadedState: FeedState.LoadedState) {
Expand Down

0 comments on commit 902ef11

Please sign in to comment.