|
|
@ -5,7 +5,6 @@ import android.os.Bundle |
|
|
|
import android.view.View |
|
|
|
import android.view.View |
|
|
|
import androidx.fragment.app.activityViewModels |
|
|
|
import androidx.fragment.app.activityViewModels |
|
|
|
import androidx.fragment.app.viewModels |
|
|
|
import androidx.fragment.app.viewModels |
|
|
|
import androidx.lifecycle.LiveData |
|
|
|
|
|
|
|
import androidx.recyclerview.widget.GridLayoutManager |
|
|
|
import androidx.recyclerview.widget.GridLayoutManager |
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager |
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager |
|
|
|
import androidx.recyclerview.widget.RecyclerView |
|
|
|
import androidx.recyclerview.widget.RecyclerView |
|
|
@ -22,6 +21,9 @@ import io.legado.app.ui.widget.recycler.LoadMoreView |
|
|
|
import io.legado.app.ui.widget.recycler.VerticalDivider |
|
|
|
import io.legado.app.ui.widget.recycler.VerticalDivider |
|
|
|
import io.legado.app.utils.startActivity |
|
|
|
import io.legado.app.utils.startActivity |
|
|
|
import io.legado.app.utils.viewbindingdelegate.viewBinding |
|
|
|
import io.legado.app.utils.viewbindingdelegate.viewBinding |
|
|
|
|
|
|
|
import kotlinx.coroutines.Job |
|
|
|
|
|
|
|
import kotlinx.coroutines.flow.collect |
|
|
|
|
|
|
|
import kotlinx.coroutines.launch |
|
|
|
|
|
|
|
|
|
|
|
class RssArticlesFragment : VMBaseFragment<RssArticlesViewModel>(R.layout.fragment_rss_articles), |
|
|
|
class RssArticlesFragment : VMBaseFragment<RssArticlesViewModel>(R.layout.fragment_rss_articles), |
|
|
|
BaseRssArticlesAdapter.CallBack { |
|
|
|
BaseRssArticlesAdapter.CallBack { |
|
|
@ -42,7 +44,7 @@ class RssArticlesFragment : VMBaseFragment<RssArticlesViewModel>(R.layout.fragme |
|
|
|
override val viewModel by viewModels<RssArticlesViewModel>() |
|
|
|
override val viewModel by viewModels<RssArticlesViewModel>() |
|
|
|
lateinit var adapter: BaseRssArticlesAdapter<*> |
|
|
|
lateinit var adapter: BaseRssArticlesAdapter<*> |
|
|
|
private lateinit var loadMoreView: LoadMoreView |
|
|
|
private lateinit var loadMoreView: LoadMoreView |
|
|
|
private var rssArticlesData: LiveData<List<RssArticle>>? = null |
|
|
|
private var articlesFlowJob: Job? = null |
|
|
|
override val isGridLayout: Boolean |
|
|
|
override val isGridLayout: Boolean |
|
|
|
get() = activityViewModel.isGridLayout |
|
|
|
get() = activityViewModel.isGridLayout |
|
|
|
|
|
|
|
|
|
|
@ -92,12 +94,12 @@ class RssArticlesFragment : VMBaseFragment<RssArticlesViewModel>(R.layout.fragme |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private fun initData() { |
|
|
|
private fun initData() { |
|
|
|
activityViewModel.url?.let { |
|
|
|
val rssUrl = activityViewModel.url ?: return |
|
|
|
rssArticlesData?.removeObservers(this) |
|
|
|
articlesFlowJob?.cancel() |
|
|
|
rssArticlesData = appDb.rssArticleDao.liveByOriginSort(it, viewModel.sortName) |
|
|
|
articlesFlowJob = launch { |
|
|
|
rssArticlesData?.observe(viewLifecycleOwner, { list -> |
|
|
|
appDb.rssArticleDao.liveByOriginSort(rssUrl, viewModel.sortName).collect { |
|
|
|
adapter.setItems(list) |
|
|
|
adapter.setItems(it) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|