|
|
@ -16,6 +16,7 @@ import io.legado.app.data.entities.RssArticle |
|
|
|
import io.legado.app.databinding.FragmentRssArticlesBinding |
|
|
|
import io.legado.app.databinding.FragmentRssArticlesBinding |
|
|
|
import io.legado.app.databinding.ViewLoadMoreBinding |
|
|
|
import io.legado.app.databinding.ViewLoadMoreBinding |
|
|
|
import io.legado.app.lib.theme.ATH |
|
|
|
import io.legado.app.lib.theme.ATH |
|
|
|
|
|
|
|
import io.legado.app.lib.theme.accentColor |
|
|
|
import io.legado.app.ui.rss.read.ReadRssActivity |
|
|
|
import io.legado.app.ui.rss.read.ReadRssActivity |
|
|
|
import io.legado.app.ui.widget.recycler.LoadMoreView |
|
|
|
import io.legado.app.ui.widget.recycler.LoadMoreView |
|
|
|
import io.legado.app.ui.widget.recycler.VerticalDivider |
|
|
|
import io.legado.app.ui.widget.recycler.VerticalDivider |
|
|
@ -50,18 +51,18 @@ class RssArticlesFragment : VMBaseFragment<RssArticlesViewModel>(R.layout.fragme |
|
|
|
override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) { |
|
|
|
override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) { |
|
|
|
viewModel.init(arguments) |
|
|
|
viewModel.init(arguments) |
|
|
|
initView() |
|
|
|
initView() |
|
|
|
binding.refreshRecyclerView.startLoading() |
|
|
|
|
|
|
|
initView() |
|
|
|
initView() |
|
|
|
initData() |
|
|
|
initData() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private fun initView() = with(binding) { |
|
|
|
private fun initView() = with(binding) { |
|
|
|
ATH.applyEdgeEffectColor(refreshRecyclerView.recyclerView) |
|
|
|
refreshLayout.setColorSchemeColors(accentColor) |
|
|
|
refreshRecyclerView.recyclerView.layoutManager = if (activityViewModel.isGridLayout) { |
|
|
|
ATH.applyEdgeEffectColor(recyclerView) |
|
|
|
refreshRecyclerView.recyclerView.setPadding(8, 0, 8, 0) |
|
|
|
recyclerView.layoutManager = if (activityViewModel.isGridLayout) { |
|
|
|
|
|
|
|
recyclerView.setPadding(8, 0, 8, 0) |
|
|
|
GridLayoutManager(requireContext(), 2) |
|
|
|
GridLayoutManager(requireContext(), 2) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
refreshRecyclerView.recyclerView.addItemDecoration(VerticalDivider(requireContext())) |
|
|
|
recyclerView.addItemDecoration(VerticalDivider(requireContext())) |
|
|
|
LinearLayoutManager(requireContext()) |
|
|
|
LinearLayoutManager(requireContext()) |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
@ -70,18 +71,15 @@ class RssArticlesFragment : VMBaseFragment<RssArticlesViewModel>(R.layout.fragme |
|
|
|
2 -> RssArticlesAdapter2(requireContext(), this@RssArticlesFragment) |
|
|
|
2 -> RssArticlesAdapter2(requireContext(), this@RssArticlesFragment) |
|
|
|
else -> RssArticlesAdapter(requireContext(), this@RssArticlesFragment) |
|
|
|
else -> RssArticlesAdapter(requireContext(), this@RssArticlesFragment) |
|
|
|
} |
|
|
|
} |
|
|
|
refreshRecyclerView.recyclerView.adapter = adapter |
|
|
|
recyclerView.adapter = adapter |
|
|
|
loadMoreView = LoadMoreView(requireContext()) |
|
|
|
loadMoreView = LoadMoreView(requireContext()) |
|
|
|
adapter.addFooterView { |
|
|
|
adapter.addFooterView { |
|
|
|
ViewLoadMoreBinding.bind(loadMoreView) |
|
|
|
ViewLoadMoreBinding.bind(loadMoreView) |
|
|
|
} |
|
|
|
} |
|
|
|
refreshRecyclerView.onRefreshStart = { |
|
|
|
refreshLayout.setOnRefreshListener { |
|
|
|
activityViewModel.rssSource?.let { |
|
|
|
loadArticles() |
|
|
|
viewModel.loadContent(it) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
refreshRecyclerView.recyclerView.addOnScrollListener(object : |
|
|
|
recyclerView.addOnScrollListener(object : RecyclerView.OnScrollListener() { |
|
|
|
RecyclerView.OnScrollListener() { |
|
|
|
|
|
|
|
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) { |
|
|
|
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) { |
|
|
|
super.onScrolled(recyclerView, dx, dy) |
|
|
|
super.onScrolled(recyclerView, dx, dy) |
|
|
|
if (!recyclerView.canScrollVertically(1)) { |
|
|
|
if (!recyclerView.canScrollVertically(1)) { |
|
|
@ -89,6 +87,10 @@ class RssArticlesFragment : VMBaseFragment<RssArticlesViewModel>(R.layout.fragme |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
refreshLayout.post { |
|
|
|
|
|
|
|
refreshLayout.isRefreshing = true |
|
|
|
|
|
|
|
loadArticles() |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private fun initData() { |
|
|
|
private fun initData() { |
|
|
@ -101,6 +103,12 @@ class RssArticlesFragment : VMBaseFragment<RssArticlesViewModel>(R.layout.fragme |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private fun loadArticles() { |
|
|
|
|
|
|
|
activityViewModel.rssSource?.let { |
|
|
|
|
|
|
|
viewModel.loadContent(it) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private fun scrollToBottom() { |
|
|
|
private fun scrollToBottom() { |
|
|
|
if (viewModel.isLoading) return |
|
|
|
if (viewModel.isLoading) return |
|
|
|
if (loadMoreView.hasMore && adapter.getActualItemCount() > 0) { |
|
|
|
if (loadMoreView.hasMore && adapter.getActualItemCount() > 0) { |
|
|
@ -113,7 +121,7 @@ class RssArticlesFragment : VMBaseFragment<RssArticlesViewModel>(R.layout.fragme |
|
|
|
|
|
|
|
|
|
|
|
override fun observeLiveBus() { |
|
|
|
override fun observeLiveBus() { |
|
|
|
viewModel.loadFinally.observe(viewLifecycleOwner) { |
|
|
|
viewModel.loadFinally.observe(viewLifecycleOwner) { |
|
|
|
binding.refreshRecyclerView.stopLoading() |
|
|
|
binding.refreshLayout.isRefreshing = false |
|
|
|
if (it) { |
|
|
|
if (it) { |
|
|
|
loadMoreView.startLoad() |
|
|
|
loadMoreView.startLoad() |
|
|
|
} else { |
|
|
|
} else { |
|
|
|