mirror of
https://github.com/gedoor/legado.git
synced 2025-08-10 00:52:30 +00:00
优化
This commit is contained in:
@@ -22,7 +22,6 @@ class ExploreShowActivity : VMBaseActivity<ActivityExploreShowBinding, ExploreSh
|
||||
|
||||
private val adapter by lazy { ExploreShowAdapter(this, this) }
|
||||
private val loadMoreView by lazy { LoadMoreView(this) }
|
||||
private var isLoading = true
|
||||
|
||||
override fun onActivityCreated(savedInstanceState: Bundle?) {
|
||||
binding.titleBar.title = intent.getStringExtra("exploreName")
|
||||
@@ -42,10 +41,11 @@ class ExploreShowActivity : VMBaseActivity<ActivityExploreShowBinding, ExploreSh
|
||||
}
|
||||
loadMoreView.startLoad()
|
||||
loadMoreView.setOnClickListener {
|
||||
if (!isLoading) {
|
||||
loadMoreView.hasMore()
|
||||
scrollToBottom()
|
||||
isLoading = true
|
||||
if (!loadMoreView.isLoading) {
|
||||
if (!loadMoreView.showErrorDialog()) {
|
||||
loadMoreView.hasMore()
|
||||
scrollToBottom()
|
||||
}
|
||||
}
|
||||
}
|
||||
binding.recyclerView.addOnScrollListener(object : RecyclerView.OnScrollListener() {
|
||||
@@ -60,14 +60,14 @@ class ExploreShowActivity : VMBaseActivity<ActivityExploreShowBinding, ExploreSh
|
||||
|
||||
private fun scrollToBottom() {
|
||||
adapter.let {
|
||||
if (loadMoreView.hasMore && !isLoading) {
|
||||
if (loadMoreView.hasMore && !loadMoreView.isLoading) {
|
||||
viewModel.explore()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun upData(books: List<SearchBook>) {
|
||||
isLoading = false
|
||||
loadMoreView.stopLoad()
|
||||
if (books.isEmpty() && adapter.isEmpty()) {
|
||||
loadMoreView.noMore(getString(R.string.empty))
|
||||
} else if (books.isEmpty()) {
|
||||
|
||||
@@ -26,7 +26,6 @@ import io.legado.app.lib.dialogs.alert
|
||||
import io.legado.app.lib.theme.*
|
||||
import io.legado.app.ui.book.info.BookInfoActivity
|
||||
import io.legado.app.ui.book.source.manage.BookSourceActivity
|
||||
import io.legado.app.ui.widget.recycler.LoadMoreView
|
||||
import io.legado.app.utils.*
|
||||
import io.legado.app.utils.viewbindingdelegate.viewBinding
|
||||
import kotlinx.coroutines.Dispatchers.IO
|
||||
@@ -56,7 +55,6 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
|
||||
setHasStableIds(true)
|
||||
}
|
||||
}
|
||||
private val loadMoreView by lazy { LoadMoreView(this) }
|
||||
private val searchView: SearchView by lazy {
|
||||
binding.titleBar.findViewById(R.id.search_view)
|
||||
}
|
||||
@@ -271,7 +269,6 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
|
||||
}
|
||||
if (viewModel.isSearchLiveData.value == false
|
||||
&& viewModel.searchKey.isNotEmpty()
|
||||
&& loadMoreView.hasMore
|
||||
) {
|
||||
viewModel.search("")
|
||||
}
|
||||
@@ -364,7 +361,6 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
|
||||
*/
|
||||
private fun searchFinally() {
|
||||
binding.refreshProgressBar.isAutoLoading = false
|
||||
loadMoreView.startLoad()
|
||||
binding.fbStop.invisible()
|
||||
}
|
||||
|
||||
|
||||
@@ -7,12 +7,18 @@ import android.view.ViewGroup
|
||||
import android.widget.FrameLayout
|
||||
import io.legado.app.R
|
||||
import io.legado.app.databinding.ViewLoadMoreBinding
|
||||
import io.legado.app.lib.dialogs.alert
|
||||
import io.legado.app.utils.invisible
|
||||
import io.legado.app.utils.visible
|
||||
|
||||
@Suppress("unused")
|
||||
class LoadMoreView(context: Context, attrs: AttributeSet? = null) : FrameLayout(context, attrs) {
|
||||
private val binding = ViewLoadMoreBinding.inflate(LayoutInflater.from(context), this)
|
||||
private var errorMsg = ""
|
||||
|
||||
var isLoading = false
|
||||
private set
|
||||
|
||||
var hasMore = true
|
||||
private set
|
||||
|
||||
@@ -22,23 +28,26 @@ class LoadMoreView(context: Context, attrs: AttributeSet? = null) : FrameLayout(
|
||||
}
|
||||
|
||||
fun startLoad() {
|
||||
isLoading = true
|
||||
binding.tvText.invisible()
|
||||
binding.rotateLoading.show()
|
||||
}
|
||||
|
||||
fun stopLoad() {
|
||||
isLoading = false
|
||||
binding.rotateLoading.hide()
|
||||
}
|
||||
|
||||
fun hasMore() {
|
||||
errorMsg = ""
|
||||
hasMore = true
|
||||
binding.tvText.invisible()
|
||||
binding.rotateLoading.show()
|
||||
startLoad()
|
||||
}
|
||||
|
||||
fun noMore(msg: String? = null) {
|
||||
stopLoad()
|
||||
errorMsg = ""
|
||||
hasMore = false
|
||||
binding.rotateLoading.hide()
|
||||
if (msg != null) {
|
||||
binding.tvText.text = msg
|
||||
} else {
|
||||
@@ -48,10 +57,21 @@ class LoadMoreView(context: Context, attrs: AttributeSet? = null) : FrameLayout(
|
||||
}
|
||||
|
||||
fun error(msg: String) {
|
||||
stopLoad()
|
||||
hasMore = false
|
||||
binding.rotateLoading.hide()
|
||||
binding.tvText.text = msg
|
||||
errorMsg = msg
|
||||
binding.tvText.text = context.getString(R.string.error_load_msg, "点击查看详情")
|
||||
binding.tvText.visible()
|
||||
}
|
||||
|
||||
fun showErrorDialog(): Boolean {
|
||||
if (errorMsg.isBlank()) {
|
||||
return false
|
||||
}
|
||||
context.alert(R.string.error) {
|
||||
setMessage(errorMsg)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user