pull/43/head
kunfei 5 years ago
parent 74f7136992
commit 5b827ca9b0
  1. 23
      app/src/main/java/io/legado/app/ui/explore/ExploreShowActivity.kt
  2. 11
      app/src/main/java/io/legado/app/ui/widget/anima/RotateLoading.kt
  3. 2
      app/src/main/res/layout/view_load_more.xml

@ -12,7 +12,6 @@ import io.legado.app.base.VMBaseActivity
import io.legado.app.data.entities.SearchBook import io.legado.app.data.entities.SearchBook
import io.legado.app.ui.book.info.BookInfoActivity import io.legado.app.ui.book.info.BookInfoActivity
import io.legado.app.utils.getViewModel import io.legado.app.utils.getViewModel
import io.legado.app.utils.gone
import kotlinx.android.synthetic.main.activity_explore_show.* import kotlinx.android.synthetic.main.activity_explore_show.*
import kotlinx.android.synthetic.main.view_load_more.view.* import kotlinx.android.synthetic.main.view_load_more.view.*
import org.jetbrains.anko.startActivity import org.jetbrains.anko.startActivity
@ -41,37 +40,21 @@ class ExploreShowActivity : VMBaseActivity<ExploreShowViewModel>(R.layout.activi
loadMoreView = loadMoreView =
LayoutInflater.from(this).inflate(R.layout.view_load_more, recycler_view, false) LayoutInflater.from(this).inflate(R.layout.view_load_more, recycler_view, false)
adapter.addFooterView(loadMoreView) adapter.addFooterView(loadMoreView)
recycler_view.addOnScrollListener(object : RecyclerView.OnScrollListener() {
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
super.onScrolled(recyclerView, dx, dy)
if (!recyclerView.canScrollVertically(1)) {
scrollToBottom()
}
}
})
}
private fun scrollToBottom() {
adapter.let {
if (it.getActualItemCount() > 0 && hasMore) {
loadMoreView.rotate_loading.show() loadMoreView.rotate_loading.show()
viewModel.explore()
}
}
} }
private fun upData(books: List<SearchBook>) { private fun upData(books: List<SearchBook>) {
if (books.isEmpty() && adapter.isEmpty()) { if (books.isEmpty() && adapter.isEmpty()) {
hasMore = false hasMore = false
loadMoreView.rotate_loading.gone() loadMoreView.rotate_loading.hide(View.INVISIBLE)
loadMoreView.tv_text.text = "" loadMoreView.tv_text.text = ""
} else if (books.isEmpty()) { } else if (books.isEmpty()) {
hasMore = false hasMore = false
loadMoreView.rotate_loading.gone() loadMoreView.rotate_loading.hide(View.INVISIBLE)
loadMoreView.tv_text.text = "我是有底线的" loadMoreView.tv_text.text = "我是有底线的"
} else if (adapter.getItems().contains(books.first()) && adapter.getItems().contains(books.last())) { } else if (adapter.getItems().contains(books.first()) && adapter.getItems().contains(books.last())) {
hasMore = false hasMore = false
loadMoreView.rotate_loading.gone() loadMoreView.rotate_loading.hide(View.INVISIBLE)
loadMoreView.tv_text.text = "我是有底线的" loadMoreView.tv_text.text = "我是有底线的"
} else { } else {
adapter.addItems(books) adapter.addItems(books)

@ -176,20 +176,19 @@ class RotateLoading : View {
post(shown) post(shown)
} }
fun hide() { fun hide(visibility: Int = GONE) {
removeCallbacks(shown) removeCallbacks(shown)
removeCallbacks(hidden) removeCallbacks(hidden)
post(hidden) stopInternal(visibility)
} }
private fun startInternal() { private fun startInternal() {
startAnimator() startAnimator()
isStarted = true isStarted = true
invalidate() invalidate()
} }
private fun stopInternal() { private fun stopInternal(visibility: Int = GONE) {
stopAnimator() stopAnimator()
invalidate() invalidate()
} }
@ -206,10 +205,10 @@ class RotateLoading : View {
.start() .start()
} }
private fun stopAnimator() { private fun stopAnimator(visibility: Int = GONE) {
animate().cancel() animate().cancel()
isStarted = false isStarted = false
visibility = GONE this.visibility = visibility
} }
companion object { companion object {

@ -11,7 +11,7 @@
android:layout_height="36dp" android:layout_height="36dp"
android:layout_margin="6dp" android:layout_margin="6dp"
android:layout_gravity="center" android:layout_gravity="center"
android:visibility="gone" android:visibility="invisible"
app:loading_width="2dp" /> app:loading_width="2dp" />
<TextView <TextView

Loading…
Cancel
Save