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