|
|
|
@ -1,23 +1,20 @@ |
|
|
|
|
package io.legado.app.ui.rss.article |
|
|
|
|
|
|
|
|
|
import android.os.Bundle |
|
|
|
|
import android.view.LayoutInflater |
|
|
|
|
import android.view.Menu |
|
|
|
|
import android.view.MenuItem |
|
|
|
|
import android.view.View |
|
|
|
|
import androidx.core.content.ContextCompat |
|
|
|
|
import androidx.lifecycle.LiveData |
|
|
|
|
import androidx.lifecycle.Observer |
|
|
|
|
import androidx.recyclerview.widget.DividerItemDecoration |
|
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager |
|
|
|
|
import androidx.recyclerview.widget.RecyclerView |
|
|
|
|
import io.legado.app.App |
|
|
|
|
import io.legado.app.R |
|
|
|
|
import io.legado.app.base.VMBaseActivity |
|
|
|
|
import io.legado.app.data.entities.RssArticle |
|
|
|
|
import io.legado.app.lib.theme.ATH |
|
|
|
|
import io.legado.app.ui.rss.read.ReadRssActivity |
|
|
|
|
import io.legado.app.ui.rss.source.edit.RssSourceEditActivity |
|
|
|
|
import io.legado.app.ui.widget.LoadMoreView |
|
|
|
|
import io.legado.app.utils.getViewModel |
|
|
|
|
import kotlinx.android.synthetic.main.activity_rss_artivles.* |
|
|
|
|
import kotlinx.android.synthetic.main.view_load_more.view.* |
|
|
|
@ -26,26 +23,22 @@ import org.jetbrains.anko.startActivity |
|
|
|
|
import org.jetbrains.anko.startActivityForResult |
|
|
|
|
|
|
|
|
|
class RssArticlesActivity : VMBaseActivity<RssArticlesViewModel>(R.layout.activity_rss_artivles), |
|
|
|
|
RssArticlesViewModel.CallBack, |
|
|
|
|
RssArticlesAdapter.CallBack { |
|
|
|
|
|
|
|
|
|
override val viewModel: RssArticlesViewModel |
|
|
|
|
get() = getViewModel(RssArticlesViewModel::class.java) |
|
|
|
|
|
|
|
|
|
override lateinit var adapter: RssArticlesAdapter |
|
|
|
|
private val editSource = 12319 |
|
|
|
|
private var adapter: RssArticlesAdapter? = null |
|
|
|
|
private var rssArticlesData: LiveData<List<RssArticle>>? = null |
|
|
|
|
private var url: String? = null |
|
|
|
|
private lateinit var loadMoreView: View |
|
|
|
|
private lateinit var loadMoreView: LoadMoreView |
|
|
|
|
|
|
|
|
|
override fun onActivityCreated(savedInstanceState: Bundle?) { |
|
|
|
|
initView() |
|
|
|
|
viewModel.callBack = this |
|
|
|
|
viewModel.titleLiveData.observe(this, Observer { |
|
|
|
|
title_bar.title = it |
|
|
|
|
}) |
|
|
|
|
url = intent.getStringExtra("url") |
|
|
|
|
url?.let { |
|
|
|
|
initData(it) |
|
|
|
|
} |
|
|
|
|
initView() |
|
|
|
|
refresh_recycler_view.startLoading() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -60,11 +53,9 @@ class RssArticlesActivity : VMBaseActivity<RssArticlesViewModel>(R.layout.activi |
|
|
|
|
startActivityForResult<RssSourceEditActivity>(editSource, Pair("data", it)) |
|
|
|
|
} |
|
|
|
|
R.id.menu_clear -> { |
|
|
|
|
intent.getStringExtra("url")?.let { |
|
|
|
|
viewModel.url?.let { |
|
|
|
|
refresh_progress_bar.isAutoLoading = true |
|
|
|
|
viewModel.clear(it) { |
|
|
|
|
refresh_progress_bar.isAutoLoading = false |
|
|
|
|
} |
|
|
|
|
viewModel.clear() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -82,13 +73,11 @@ class RssArticlesActivity : VMBaseActivity<RssArticlesViewModel>(R.layout.activi |
|
|
|
|
}) |
|
|
|
|
adapter = RssArticlesAdapter(this, this) |
|
|
|
|
recycler_view.adapter = adapter |
|
|
|
|
loadMoreView = LoadMoreView(this) |
|
|
|
|
adapter.addFooterView(loadMoreView) |
|
|
|
|
refresh_recycler_view.onRefreshStart = { |
|
|
|
|
url?.let { |
|
|
|
|
viewModel.loadContent(it, { |
|
|
|
|
refresh_progress_bar.isAutoLoading = false |
|
|
|
|
}, { |
|
|
|
|
addLoadMoreView() |
|
|
|
|
}) |
|
|
|
|
viewModel.url?.let { |
|
|
|
|
viewModel.loadContent() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
recycler_view.addOnScrollListener(object : RecyclerView.OnScrollListener() { |
|
|
|
@ -101,27 +90,19 @@ class RssArticlesActivity : VMBaseActivity<RssArticlesViewModel>(R.layout.activi |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun addLoadMoreView() { |
|
|
|
|
if (adapter?.getFooterCount() == 0) { |
|
|
|
|
loadMoreView = |
|
|
|
|
LayoutInflater.from(this).inflate(R.layout.view_load_more, recycler_view, false) |
|
|
|
|
adapter?.addFooterView(loadMoreView) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun initData(origin: String) { |
|
|
|
|
rssArticlesData?.removeObservers(this) |
|
|
|
|
rssArticlesData = App.db.rssArticleDao().liveByOrigin(origin) |
|
|
|
|
rssArticlesData?.observe(this, Observer { |
|
|
|
|
adapter?.setItems(it) |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun scrollToBottom() { |
|
|
|
|
adapter?.let { |
|
|
|
|
if (it.getActualItemCount() > 0) { |
|
|
|
|
if (viewModel.isLoading) return |
|
|
|
|
if (loadMoreView.hasMore && adapter.getActualItemCount() > 0) { |
|
|
|
|
loadMoreView.rotate_loading.show() |
|
|
|
|
viewModel.loadContent() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun loadFinally() { |
|
|
|
|
if (viewModel.hasMore) { |
|
|
|
|
loadMoreView.startLoad() |
|
|
|
|
} else { |
|
|
|
|
loadMoreView.noMore() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|