From 07168c1c1f53c616a8490cee9561ef8c331211a3 Mon Sep 17 00:00:00 2001 From: Matthieu <24-artectrex@users.noreply.shinice.net> Date: Tue, 2 Aug 2022 21:19:05 +0200 Subject: [PATCH] Add pull to refresh to comments --- .../main/java/org/pixeldroid/app/LoginActivity.kt | 2 +- .../java/org/pixeldroid/app/posts/PostActivity.kt | 6 +++--- .../app/posts/feeds/CommonFeedFragmentUtils.kt | 4 ++++ .../posts/feeds/cachedFeeds/CachedFeedFragment.kt | 4 ---- .../feeds/uncachedFeeds/UncachedFeedFragment.kt | 4 ---- app/src/main/res/layout/activity_post.xml | 15 ++++++++------- 6 files changed, 16 insertions(+), 19 deletions(-) diff --git a/app/src/main/java/org/pixeldroid/app/LoginActivity.kt b/app/src/main/java/org/pixeldroid/app/LoginActivity.kt index 1f1d4f93..1f14c33a 100644 --- a/app/src/main/java/org/pixeldroid/app/LoginActivity.kt +++ b/app/src/main/java/org/pixeldroid/app/LoginActivity.kt @@ -136,7 +136,7 @@ class LoginActivity : BaseThemedWithoutBarActivity() { val credentialsDeferred: Deferred = async { try { pixelfedAPI.registerApplication( - appName, "$oauthScheme://$PACKAGE_ID", SCOPE + appName, "$oauthScheme://$PACKAGE_ID", SCOPE, "https://pixeldroid.org" ) } catch (exception: IOException) { return@async null diff --git a/app/src/main/java/org/pixeldroid/app/posts/PostActivity.kt b/app/src/main/java/org/pixeldroid/app/posts/PostActivity.kt index 3d0532b3..761bed14 100644 --- a/app/src/main/java/org/pixeldroid/app/posts/PostActivity.kt +++ b/app/src/main/java/org/pixeldroid/app/posts/PostActivity.kt @@ -39,7 +39,7 @@ class PostActivity : BaseThemedWithBarActivity() { private lateinit var binding: ActivityPostBinding private lateinit var profileAdapter: PagingDataAdapter - private lateinit var viewModel: FeedViewModel + private lateinit var commentViewModel: FeedViewModel private var job: Job? = null @@ -105,7 +105,7 @@ class PostActivity : BaseThemedWithBarActivity() { private fun retrieveComments() { // get the view model @Suppress("UNCHECKED_CAST") - viewModel = ViewModelProvider(this@PostActivity, ProfileViewModelFactory( + commentViewModel = ViewModelProvider(this@PostActivity, ProfileViewModelFactory( CommentContentRepository( apiHolder.setToCurrentUser(), status.id @@ -118,7 +118,7 @@ class PostActivity : BaseThemedWithBarActivity() { binding.commentRecyclerView, binding.motionLayout, binding.errorLayout, profileAdapter) - job = launch(job, lifecycleScope, viewModel, profileAdapter) + job = launch(job, lifecycleScope, commentViewModel, profileAdapter) } private suspend fun postComment( diff --git a/app/src/main/java/org/pixeldroid/app/posts/feeds/CommonFeedFragmentUtils.kt b/app/src/main/java/org/pixeldroid/app/posts/feeds/CommonFeedFragmentUtils.kt index f0d7959c..7c166d6d 100644 --- a/app/src/main/java/org/pixeldroid/app/posts/feeds/CommonFeedFragmentUtils.kt +++ b/app/src/main/java/org/pixeldroid/app/posts/feeds/CommonFeedFragmentUtils.kt @@ -55,6 +55,10 @@ internal fun initAdapter( footer = ReposLoadStateAdapter { adapter.retry() } ) + swipeRefreshLayout.setOnRefreshListener { + adapter.refresh() + } + adapter.addLoadStateListener { loadState -> if(!progressBar.isVisible && swipeRefreshLayout.isRefreshing) { diff --git a/app/src/main/java/org/pixeldroid/app/posts/feeds/cachedFeeds/CachedFeedFragment.kt b/app/src/main/java/org/pixeldroid/app/posts/feeds/cachedFeeds/CachedFeedFragment.kt index 76b088d5..592f5a53 100644 --- a/app/src/main/java/org/pixeldroid/app/posts/feeds/cachedFeeds/CachedFeedFragment.kt +++ b/app/src/main/java/org/pixeldroid/app/posts/feeds/cachedFeeds/CachedFeedFragment.kt @@ -75,10 +75,6 @@ open class CachedFeedFragment : BaseFragment() { initAdapter(binding.progressBar, binding.swipeRefreshLayout, binding.list, binding.motionLayout, binding.errorLayout, adapter) - binding.swipeRefreshLayout.setOnRefreshListener { - adapter.refresh() - } - return binding.root } diff --git a/app/src/main/java/org/pixeldroid/app/posts/feeds/uncachedFeeds/UncachedFeedFragment.kt b/app/src/main/java/org/pixeldroid/app/posts/feeds/uncachedFeeds/UncachedFeedFragment.kt index ef24a535..9037bfe2 100644 --- a/app/src/main/java/org/pixeldroid/app/posts/feeds/uncachedFeeds/UncachedFeedFragment.kt +++ b/app/src/main/java/org/pixeldroid/app/posts/feeds/uncachedFeeds/UncachedFeedFragment.kt @@ -64,10 +64,6 @@ open class UncachedFeedFragment : BaseFragment() { initAdapter(binding.progressBar, binding.swipeRefreshLayout, binding.list, binding.motionLayout, binding.errorLayout, adapter) - binding.swipeRefreshLayout.setOnRefreshListener { - adapter.refresh() - } - return binding.root } } diff --git a/app/src/main/res/layout/activity_post.xml b/app/src/main/res/layout/activity_post.xml index 739d8e70..410ef8bb 100644 --- a/app/src/main/res/layout/activity_post.xml +++ b/app/src/main/res/layout/activity_post.xml @@ -7,12 +7,6 @@ android:layout_height="match_parent" tools:context=".posts.PostActivity"> - - - + + + +