Merge pull request #5430 from Stypox/fix-feed
Fix reload feed button does nothing
This commit is contained in:
commit
5814743d59
1 changed files with 12 additions and 22 deletions
|
@ -32,14 +32,11 @@ import androidx.appcompat.app.AlertDialog
|
||||||
import androidx.core.content.edit
|
import androidx.core.content.edit
|
||||||
import androidx.core.os.bundleOf
|
import androidx.core.os.bundleOf
|
||||||
import androidx.core.view.isVisible
|
import androidx.core.view.isVisible
|
||||||
import androidx.lifecycle.Observer
|
|
||||||
import androidx.lifecycle.ViewModelProvider
|
import androidx.lifecycle.ViewModelProvider
|
||||||
import androidx.preference.PreferenceManager
|
import androidx.preference.PreferenceManager
|
||||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
|
||||||
import icepick.State
|
import icepick.State
|
||||||
import org.schabi.newpipe.R
|
import org.schabi.newpipe.R
|
||||||
import org.schabi.newpipe.database.feed.model.FeedGroupEntity
|
import org.schabi.newpipe.database.feed.model.FeedGroupEntity
|
||||||
import org.schabi.newpipe.databinding.ErrorRetryBinding
|
|
||||||
import org.schabi.newpipe.databinding.FragmentFeedBinding
|
import org.schabi.newpipe.databinding.FragmentFeedBinding
|
||||||
import org.schabi.newpipe.fragments.list.BaseListFragment
|
import org.schabi.newpipe.fragments.list.BaseListFragment
|
||||||
import org.schabi.newpipe.ktx.animate
|
import org.schabi.newpipe.ktx.animate
|
||||||
|
@ -51,12 +48,9 @@ import java.util.Calendar
|
||||||
class FeedFragment : BaseListFragment<FeedState, Unit>() {
|
class FeedFragment : BaseListFragment<FeedState, Unit>() {
|
||||||
private var _feedBinding: FragmentFeedBinding? = null
|
private var _feedBinding: FragmentFeedBinding? = null
|
||||||
private val feedBinding get() = _feedBinding!!
|
private val feedBinding get() = _feedBinding!!
|
||||||
|
private val errorBinding get() = _feedBinding!!.errorPanel
|
||||||
private var _errorBinding: ErrorRetryBinding? = null
|
|
||||||
private val errorBinding get() = _errorBinding!!
|
|
||||||
|
|
||||||
private lateinit var viewModel: FeedViewModel
|
private lateinit var viewModel: FeedViewModel
|
||||||
private lateinit var swipeRefreshLayout: SwipeRefreshLayout
|
|
||||||
@State
|
@State
|
||||||
@JvmField
|
@JvmField
|
||||||
var listState: Parcelable? = null
|
var listState: Parcelable? = null
|
||||||
|
@ -83,18 +77,17 @@ class FeedFragment : BaseListFragment<FeedState, Unit>() {
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onViewCreated(rootView: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(rootView: View, savedInstanceState: Bundle?) {
|
||||||
super.onViewCreated(rootView, savedInstanceState)
|
// super.onViewCreated() calls initListeners() which require the binding to be initialized
|
||||||
_feedBinding = FragmentFeedBinding.bind(rootView)
|
_feedBinding = FragmentFeedBinding.bind(rootView)
|
||||||
_errorBinding = feedBinding.errorPanel
|
super.onViewCreated(rootView, savedInstanceState)
|
||||||
|
|
||||||
feedBinding.swiperefresh.setOnRefreshListener { reloadContent() }
|
|
||||||
viewModel = ViewModelProvider(this, FeedViewModel.Factory(requireContext(), groupId)).get(FeedViewModel::class.java)
|
viewModel = ViewModelProvider(this, FeedViewModel.Factory(requireContext(), groupId)).get(FeedViewModel::class.java)
|
||||||
viewModel.stateLiveData.observe(viewLifecycleOwner, Observer { it?.let(::handleResult) })
|
viewModel.stateLiveData.observe(viewLifecycleOwner) { it?.let(::handleResult) }
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onPause() {
|
override fun onPause() {
|
||||||
super.onPause()
|
super.onPause()
|
||||||
listState = _feedBinding?.itemsList?.layoutManager?.onSaveInstanceState()
|
listState = feedBinding.itemsList.layoutManager?.onSaveInstanceState()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
|
@ -112,10 +105,8 @@ class FeedFragment : BaseListFragment<FeedState, Unit>() {
|
||||||
|
|
||||||
override fun initListeners() {
|
override fun initListeners() {
|
||||||
super.initListeners()
|
super.initListeners()
|
||||||
// Using the non-null property may result in a NullPointerException
|
feedBinding.refreshRootView.setOnClickListener { reloadContent() }
|
||||||
_feedBinding?.refreshRootView?.setOnClickListener {
|
feedBinding.swiperefresh.setOnRefreshListener { reloadContent() }
|
||||||
triggerUpdate()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// /////////////////////////////////////////////////////////////////////////
|
// /////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -242,12 +233,12 @@ class FeedFragment : BaseListFragment<FeedState, Unit>() {
|
||||||
val isIndeterminate = progressState.currentProgress == -1 &&
|
val isIndeterminate = progressState.currentProgress == -1 &&
|
||||||
progressState.maxProgress == -1
|
progressState.maxProgress == -1
|
||||||
|
|
||||||
if (!isIndeterminate) {
|
feedBinding.loadingProgressText.text = if (!isIndeterminate) {
|
||||||
feedBinding.loadingProgressText.text = "${progressState.currentProgress}/${progressState.maxProgress}"
|
"${progressState.currentProgress}/${progressState.maxProgress}"
|
||||||
} else if (progressState.progressMessage > 0) {
|
} else if (progressState.progressMessage > 0) {
|
||||||
_feedBinding?.loadingProgressText?.setText(progressState.progressMessage)
|
progressState.progressMessage.toString()
|
||||||
} else {
|
} else {
|
||||||
_feedBinding?.loadingProgressText?.text = "∞/∞"
|
"∞/∞"
|
||||||
}
|
}
|
||||||
|
|
||||||
feedBinding.loadingProgressBar.isIndeterminate = isIndeterminate ||
|
feedBinding.loadingProgressBar.isIndeterminate = isIndeterminate ||
|
||||||
|
@ -317,11 +308,10 @@ class FeedFragment : BaseListFragment<FeedState, Unit>() {
|
||||||
// /////////////////////////////////////////////////////////////////////////
|
// /////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
override fun doInitialLoadLogic() {}
|
override fun doInitialLoadLogic() {}
|
||||||
override fun reloadContent() = triggerUpdate()
|
|
||||||
override fun loadMoreItems() {}
|
override fun loadMoreItems() {}
|
||||||
override fun hasMoreItems() = false
|
override fun hasMoreItems() = false
|
||||||
|
|
||||||
private fun triggerUpdate() {
|
override fun reloadContent() {
|
||||||
getActivity()?.startService(
|
getActivity()?.startService(
|
||||||
Intent(requireContext(), FeedLoadService::class.java).apply {
|
Intent(requireContext(), FeedLoadService::class.java).apply {
|
||||||
putExtra(FeedLoadService.EXTRA_GROUP_ID, groupId)
|
putExtra(FeedLoadService.EXTRA_GROUP_ID, groupId)
|
||||||
|
|
Loading…
Reference in a new issue