pull/37/head
kunfei 6 years ago
parent 15b3644312
commit 8fbd6d3667
  1. 58
      app/src/main/java/io/legado/app/ui/rss/article/RssArticlesActivity.kt
  2. 4
      app/src/main/java/io/legado/app/ui/rss/article/RssArticlesViewModel.kt
  3. 8
      app/src/main/java/io/legado/app/ui/widget/anima/RefreshProgressBar.kt

@ -1,8 +1,11 @@
package io.legado.app.ui.rss.article package io.legado.app.ui.rss.article
import android.annotation.SuppressLint
import android.os.Bundle import android.os.Bundle
import android.view.Menu import android.view.Menu
import android.view.MenuItem import android.view.MenuItem
import android.view.MotionEvent
import android.view.View
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
import androidx.lifecycle.LiveData import androidx.lifecycle.LiveData
import androidx.lifecycle.Observer import androidx.lifecycle.Observer
@ -29,13 +32,18 @@ class RssArticlesActivity : VMBaseActivity<RssArticlesViewModel>(R.layout.activi
private val editSource = 12319 private val editSource = 12319
private var adapter: RssArticlesAdapter? = null private var adapter: RssArticlesAdapter? = null
private var rssArticlesData: LiveData<List<RssArticle>>? = null private var rssArticlesData: LiveData<List<RssArticle>>? = null
private var url: String? = null
private var durTouchX = -1000000f
private var durTouchY = -1000000f
override fun onActivityCreated(savedInstanceState: Bundle?) { override fun onActivityCreated(savedInstanceState: Bundle?) {
initView() initView()
viewModel.titleLiveData.observe(this, Observer { viewModel.titleLiveData.observe(this, Observer {
title_bar.title = it title_bar.title = it
}) })
intent.getStringExtra("url")?.let { url = intent.getStringExtra("url")
url?.let {
initData(it) initData(it)
viewModel.loadContent(it) { viewModel.loadContent(it) {
refresh_progress_bar.isAutoLoading = false refresh_progress_bar.isAutoLoading = false
@ -77,6 +85,54 @@ class RssArticlesActivity : VMBaseActivity<RssArticlesViewModel>(R.layout.activi
adapter = RssArticlesAdapter(this, this) adapter = RssArticlesAdapter(this, this)
recycler_view.adapter = adapter recycler_view.adapter = adapter
refresh_progress_bar.isAutoLoading = true refresh_progress_bar.isAutoLoading = true
recycler_view.setOnTouchListener(object : View.OnTouchListener {
@SuppressLint("ClickableViewAccessibility")
override fun onTouch(v: View?, event: MotionEvent?): Boolean {
when (event?.action) {
MotionEvent.ACTION_DOWN -> {
durTouchX = event.x
durTouchY = event.y
}
MotionEvent.ACTION_MOVE -> {
if (durTouchX == -1000000f) {
durTouchX = event.x
}
if (durTouchY == -1000000f)
durTouchY = event.y
val dY = event.y - durTouchY //>0下拉
durTouchY = event.y
if (!refresh_progress_bar.isAutoLoading && refresh_progress_bar.getSecondDurProgress() == refresh_progress_bar.secondFinalProgress) {
if (recycler_view.adapter!!.itemCount > 0) {
if (0 == (recycler_view.layoutManager as LinearLayoutManager).findFirstCompletelyVisibleItemPosition()) {
refresh_progress_bar.setSecondDurProgress((refresh_progress_bar.getSecondDurProgress() + dY / 2).toInt())
}
} else {
refresh_progress_bar.setSecondDurProgress((refresh_progress_bar.getSecondDurProgress() + dY / 2).toInt())
}
return refresh_progress_bar.getSecondDurProgress() > 0
}
}
MotionEvent.ACTION_UP -> {
if (!refresh_progress_bar.isAutoLoading && refresh_progress_bar.secondMaxProgress > 0 && refresh_progress_bar.getSecondDurProgress() > 0) {
if (refresh_progress_bar.getSecondDurProgress() >= refresh_progress_bar.secondMaxProgress) {
refresh_progress_bar.isAutoLoading = true
url?.let {
viewModel.loadContent(it) {
refresh_progress_bar.isAutoLoading = false
}
}
} else {
refresh_progress_bar.setSecondDurProgressWithAnim(0)
}
}
durTouchX = -1000000f
durTouchY = -1000000f
}
}
return false
}
})
} }
private fun initData(origin: String) { private fun initData(origin: String) {

@ -22,8 +22,8 @@ class RssArticlesViewModel(application: Application) : BaseViewModel(application
} ?: let { } ?: let {
rssSource = RssSource(sourceUrl = url) rssSource = RssSource(sourceUrl = url)
} }
rssSource?.let { rssSource?.let { rssSource ->
Rss.getArticles(it, this) Rss.getArticles(rssSource, this)
.onSuccess(IO) { .onSuccess(IO) {
it?.let { it?.let {
App.db.rssArticleDao().insert(*it.toTypedArray()) App.db.rssArticleDao().insert(*it.toTypedArray())

@ -34,11 +34,8 @@ class RefreshProgressBar @JvmOverloads constructor(
var isAutoLoading: Boolean = false var isAutoLoading: Boolean = false
set(loading) { set(loading) {
if (loading && visibility != VISIBLE) {
visibility = VISIBLE
}
field = loading field = loading
if (!this.isAutoLoading) { if (!loading) {
secondDurProgress = 0 secondDurProgress = 0
secondFinalProgress = 0 secondFinalProgress = 0
} }
@ -135,9 +132,6 @@ class RefreshProgressBar @JvmOverloads constructor(
} }
this.invalidate() this.invalidate()
} }
if (secondDurProgress == 0 && durProgress == 0 && secondFinalProgress == 0 && visibility == VISIBLE) {
visibility = INVISIBLE
}
} }
} }

Loading…
Cancel
Save