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