Add pull to refresh to comments
This commit is contained in:
parent
696228517d
commit
07168c1c1f
|
@ -136,7 +136,7 @@ class LoginActivity : BaseThemedWithoutBarActivity() {
|
||||||
val credentialsDeferred: Deferred<Application?> = async {
|
val credentialsDeferred: Deferred<Application?> = async {
|
||||||
try {
|
try {
|
||||||
pixelfedAPI.registerApplication(
|
pixelfedAPI.registerApplication(
|
||||||
appName, "$oauthScheme://$PACKAGE_ID", SCOPE
|
appName, "$oauthScheme://$PACKAGE_ID", SCOPE, "https://pixeldroid.org"
|
||||||
)
|
)
|
||||||
} catch (exception: IOException) {
|
} catch (exception: IOException) {
|
||||||
return@async null
|
return@async null
|
||||||
|
|
|
@ -39,7 +39,7 @@ class PostActivity : BaseThemedWithBarActivity() {
|
||||||
|
|
||||||
private lateinit var binding: ActivityPostBinding
|
private lateinit var binding: ActivityPostBinding
|
||||||
private lateinit var profileAdapter: PagingDataAdapter<Status, RecyclerView.ViewHolder>
|
private lateinit var profileAdapter: PagingDataAdapter<Status, RecyclerView.ViewHolder>
|
||||||
private lateinit var viewModel: FeedViewModel<Status>
|
private lateinit var commentViewModel: FeedViewModel<Status>
|
||||||
private var job: Job? = null
|
private var job: Job? = null
|
||||||
|
|
||||||
|
|
||||||
|
@ -105,7 +105,7 @@ class PostActivity : BaseThemedWithBarActivity() {
|
||||||
private fun retrieveComments() {
|
private fun retrieveComments() {
|
||||||
// get the view model
|
// get the view model
|
||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
viewModel = ViewModelProvider(this@PostActivity, ProfileViewModelFactory(
|
commentViewModel = ViewModelProvider(this@PostActivity, ProfileViewModelFactory(
|
||||||
CommentContentRepository(
|
CommentContentRepository(
|
||||||
apiHolder.setToCurrentUser(),
|
apiHolder.setToCurrentUser(),
|
||||||
status.id
|
status.id
|
||||||
|
@ -118,7 +118,7 @@ class PostActivity : BaseThemedWithBarActivity() {
|
||||||
binding.commentRecyclerView, binding.motionLayout, binding.errorLayout,
|
binding.commentRecyclerView, binding.motionLayout, binding.errorLayout,
|
||||||
profileAdapter)
|
profileAdapter)
|
||||||
|
|
||||||
job = launch(job, lifecycleScope, viewModel, profileAdapter)
|
job = launch(job, lifecycleScope, commentViewModel, profileAdapter)
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun postComment(
|
private suspend fun postComment(
|
||||||
|
|
|
@ -55,6 +55,10 @@ internal fun <T: Any> initAdapter(
|
||||||
footer = ReposLoadStateAdapter { adapter.retry() }
|
footer = ReposLoadStateAdapter { adapter.retry() }
|
||||||
)
|
)
|
||||||
|
|
||||||
|
swipeRefreshLayout.setOnRefreshListener {
|
||||||
|
adapter.refresh()
|
||||||
|
}
|
||||||
|
|
||||||
adapter.addLoadStateListener { loadState ->
|
adapter.addLoadStateListener { loadState ->
|
||||||
|
|
||||||
if(!progressBar.isVisible && swipeRefreshLayout.isRefreshing) {
|
if(!progressBar.isVisible && swipeRefreshLayout.isRefreshing) {
|
||||||
|
|
|
@ -75,10 +75,6 @@ open class CachedFeedFragment<T: FeedContentDatabase> : BaseFragment() {
|
||||||
initAdapter(binding.progressBar, binding.swipeRefreshLayout,
|
initAdapter(binding.progressBar, binding.swipeRefreshLayout,
|
||||||
binding.list, binding.motionLayout, binding.errorLayout, adapter)
|
binding.list, binding.motionLayout, binding.errorLayout, adapter)
|
||||||
|
|
||||||
binding.swipeRefreshLayout.setOnRefreshListener {
|
|
||||||
adapter.refresh()
|
|
||||||
}
|
|
||||||
|
|
||||||
return binding.root
|
return binding.root
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -64,10 +64,6 @@ open class UncachedFeedFragment<T: FeedContent> : BaseFragment() {
|
||||||
initAdapter(binding.progressBar, binding.swipeRefreshLayout, binding.list,
|
initAdapter(binding.progressBar, binding.swipeRefreshLayout, binding.list,
|
||||||
binding.motionLayout, binding.errorLayout, adapter)
|
binding.motionLayout, binding.errorLayout, adapter)
|
||||||
|
|
||||||
binding.swipeRefreshLayout.setOnRefreshListener {
|
|
||||||
adapter.refresh()
|
|
||||||
}
|
|
||||||
|
|
||||||
return binding.root
|
return binding.root
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,12 +7,6 @@
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
tools:context=".posts.PostActivity">
|
tools:context=".posts.PostActivity">
|
||||||
|
|
||||||
|
|
||||||
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
|
||||||
android:id="@+id/postRefreshLayout"
|
|
||||||
android:layout_width="0dp"
|
|
||||||
android:layout_height="0dp" />
|
|
||||||
|
|
||||||
<com.google.android.material.appbar.AppBarLayout
|
<com.google.android.material.appbar.AppBarLayout
|
||||||
android:id="@+id/app_bar_layout"
|
android:id="@+id/app_bar_layout"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
@ -89,14 +83,21 @@
|
||||||
layout="@layout/error_layout"
|
layout="@layout/error_layout"
|
||||||
tools:layout_editor_absoluteX="50dp" />
|
tools:layout_editor_absoluteX="50dp" />
|
||||||
|
|
||||||
|
|
||||||
|
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
||||||
|
android:id="@+id/postRefreshLayout"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@id/errorLayout">
|
||||||
|
|
||||||
<androidx.recyclerview.widget.RecyclerView
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
android:id="@+id/commentRecyclerView"
|
android:id="@+id/commentRecyclerView"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:visibility="visible"
|
android:visibility="visible"
|
||||||
app:layoutManager="LinearLayoutManager"
|
app:layoutManager="LinearLayoutManager"
|
||||||
app:layout_constraintTop_toBottomOf="@id/errorLayout"
|
|
||||||
tools:listitem="@layout/comment" />
|
tools:listitem="@layout/comment" />
|
||||||
|
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
|
||||||
|
|
||||||
<ProgressBar
|
<ProgressBar
|
||||||
android:id="@+id/postCommentsProgressBar"
|
android:id="@+id/postCommentsProgressBar"
|
||||||
|
|
Loading…
Reference in New Issue