add pull to refresh
This commit is contained in:
parent
c5def59621
commit
ce6bb012ce
|
@ -6,12 +6,14 @@ import android.os.Bundle
|
|||
import androidx.activity.viewModels
|
||||
import androidx.lifecycle.Observer
|
||||
import androidx.recyclerview.widget.MergeAdapter
|
||||
import at.connyduck.pixelcat.R
|
||||
import at.connyduck.pixelcat.components.general.BaseActivity
|
||||
import at.connyduck.pixelcat.components.timeline.TimeLineActionListener
|
||||
import at.connyduck.pixelcat.components.util.Success
|
||||
import at.connyduck.pixelcat.components.util.extension.getDisplayWidthInPx
|
||||
import at.connyduck.pixelcat.components.util.extension.hide
|
||||
import at.connyduck.pixelcat.components.util.extension.show
|
||||
import at.connyduck.pixelcat.components.util.getColorForAttr
|
||||
import at.connyduck.pixelcat.dagger.ViewModelFactory
|
||||
import at.connyduck.pixelcat.databinding.ActivityDetailBinding
|
||||
import at.connyduck.pixelcat.db.entitity.StatusEntity
|
||||
|
@ -31,7 +33,6 @@ class DetailActivity: BaseActivity(), TimeLineActionListener {
|
|||
|
||||
private lateinit var repliesAdapter: DetailReplyAdapter
|
||||
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(binding.root)
|
||||
|
@ -44,6 +45,15 @@ class DetailActivity: BaseActivity(), TimeLineActionListener {
|
|||
insets.consumeSystemWindowInsets()
|
||||
}
|
||||
|
||||
binding.detailSwipeRefresh.setColorSchemeColors(
|
||||
getColorForAttr(R.attr.pixelcat_gradient_color_start),
|
||||
getColorForAttr(R.attr.pixelcat_gradient_color_end)
|
||||
)
|
||||
|
||||
binding.detailSwipeRefresh.setOnRefreshListener {
|
||||
viewModel.reload(false)
|
||||
}
|
||||
|
||||
viewModel.setStatusId(intent.getStringExtra(EXTRA_STATUS_ID)!!)
|
||||
|
||||
val displayWidth = getDisplayWidthInPx()
|
||||
|
@ -56,6 +66,7 @@ class DetailActivity: BaseActivity(), TimeLineActionListener {
|
|||
viewModel.currentStatus.observe(this, Observer {
|
||||
if(it is Success) {
|
||||
binding.detailProgress.hide()
|
||||
binding.detailSwipeRefresh.isRefreshing = false
|
||||
binding.detailRecyclerView.show()
|
||||
statusAdapter.submitList(listOf(it.data))
|
||||
}
|
||||
|
|
|
@ -62,9 +62,11 @@ class DetailViewModel @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
fun reload() {
|
||||
currentStatus.value = Loading()
|
||||
replies.value = Loading()
|
||||
fun reload(showLoading: Boolean) {
|
||||
if(showLoading) {
|
||||
currentStatus.value = Loading()
|
||||
replies.value = Loading()
|
||||
}
|
||||
viewModelScope.launch {
|
||||
loadStatus()
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue