WIP cargo mas posts en feed
This commit is contained in:
parent
19b61c959b
commit
f301aca982
@ -9,6 +9,7 @@ import android.view.View
|
|||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import androidx.fragment.app.activityViewModels
|
import androidx.fragment.app.activityViewModels
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
|
import com.isolaatti.BuildConfig
|
||||||
import com.isolaatti.R
|
import com.isolaatti.R
|
||||||
import com.isolaatti.common.ErrorMessageViewModel
|
import com.isolaatti.common.ErrorMessageViewModel
|
||||||
import com.isolaatti.databinding.FragmentFeedBinding
|
import com.isolaatti.databinding.FragmentFeedBinding
|
||||||
@ -75,7 +76,7 @@ class FeedFragment : Fragment(), OnUserInteractedWithPostCallback {
|
|||||||
override fun configureConfiguration(builder: MarkwonConfiguration.Builder) {
|
override fun configureConfiguration(builder: MarkwonConfiguration.Builder) {
|
||||||
builder
|
builder
|
||||||
.imageDestinationProcessor(ImageDestinationProcessorRelativeToAbsolute
|
.imageDestinationProcessor(ImageDestinationProcessorRelativeToAbsolute
|
||||||
.create("https://isolaatti.com/"))
|
.create(BuildConfig.backend))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.usePlugin(PicassoImagesPluginDef.picassoImagePlugin)
|
.usePlugin(PicassoImagesPluginDef.picassoImagePlugin)
|
||||||
@ -85,15 +86,40 @@ class FeedFragment : Fragment(), OnUserInteractedWithPostCallback {
|
|||||||
viewBinding.feedRecyclerView.adapter = adapter
|
viewBinding.feedRecyclerView.adapter = adapter
|
||||||
viewBinding.feedRecyclerView.layoutManager = LinearLayoutManager(requireContext())
|
viewBinding.feedRecyclerView.layoutManager = LinearLayoutManager(requireContext())
|
||||||
|
|
||||||
|
viewBinding.refreshButton.setOnClickListener {
|
||||||
|
viewModel.getFeed(refresh = true)
|
||||||
|
}
|
||||||
|
|
||||||
|
viewBinding.swipeToRefresh.setOnRefreshListener {
|
||||||
|
viewModel.getFeed(refresh = true)
|
||||||
|
viewBinding.swipeToRefresh.isRefreshing = false
|
||||||
|
}
|
||||||
|
|
||||||
|
viewBinding.loadMoreButton.setOnClickListener {
|
||||||
|
viewModel.getFeed(refresh = false)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
viewModel.posts.observe(viewLifecycleOwner){
|
viewModel.posts.observe(viewLifecycleOwner){
|
||||||
Log.d("recycler", it.data.toString())
|
if (it != null) {
|
||||||
adapter.updateList(it,null)
|
adapter.updateList(it,null)
|
||||||
}
|
}
|
||||||
Log.d("FeedFragment", errorViewModel.toString())
|
}
|
||||||
|
|
||||||
|
viewModel.loadingPosts.observe(viewLifecycleOwner) {
|
||||||
|
viewBinding.progressBarLoading.visibility = if(it) View.VISIBLE else View.GONE
|
||||||
|
viewBinding.loadMoreButton.visibility = if(it) View.GONE else View.VISIBLE
|
||||||
|
}
|
||||||
|
|
||||||
|
viewModel.noMoreContent.observe(viewLifecycleOwner) {
|
||||||
|
val visibility = if(it) View.VISIBLE else View.GONE
|
||||||
|
viewBinding.noMoreContentToShowTextView.visibility = visibility
|
||||||
|
viewBinding.refreshButton.visibility = visibility
|
||||||
|
viewBinding.loadMoreButton.visibility = if(it) View.GONE else View.VISIBLE
|
||||||
|
}
|
||||||
|
|
||||||
viewModel.errorLoading.observe(viewLifecycleOwner) {
|
viewModel.errorLoading.observe(viewLifecycleOwner) {
|
||||||
errorViewModel.error.postValue(it)
|
errorViewModel.error.postValue(it)
|
||||||
Log.d("FeedFragment", it.toString())
|
|
||||||
}
|
}
|
||||||
viewModel.postLiked.observe(viewLifecycleOwner) {
|
viewModel.postLiked.observe(viewLifecycleOwner) {
|
||||||
viewModel.posts.value?.let { feed ->
|
viewModel.posts.value?.let { feed ->
|
||||||
@ -108,6 +134,7 @@ class FeedFragment : Fragment(), OnUserInteractedWithPostCallback {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
override fun onLiked(postId: Long) = viewModel.likePost(postId)
|
override fun onLiked(postId: Long) = viewModel.likePost(postId)
|
||||||
|
|
||||||
override fun onUnLiked(postId: Long) = viewModel.unLikePost(postId)
|
override fun onUnLiked(postId: Long) = viewModel.unLikePost(postId)
|
||||||
|
|||||||
@ -32,7 +32,7 @@ class HomeActivity : IsolaattiBaseActivity() {
|
|||||||
viewBinding.navigationRail?.setupWithNavController(navHostFragment.navController)
|
viewBinding.navigationRail?.setupWithNavController(navHostFragment.navController)
|
||||||
|
|
||||||
if(savedInstanceState == null) {
|
if(savedInstanceState == null) {
|
||||||
postsViewModel.getFeed()
|
postsViewModel.getFeed(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -24,12 +24,15 @@ import javax.inject.Inject
|
|||||||
@HiltViewModel
|
@HiltViewModel
|
||||||
class PostsViewModel @Inject constructor(private val postsRepository: PostsRepository, private val likesRepository: LikesRepository) : ViewModel() {
|
class PostsViewModel @Inject constructor(private val postsRepository: PostsRepository, private val likesRepository: LikesRepository) : ViewModel() {
|
||||||
|
|
||||||
private val _posts: MutableLiveData<FeedDto> = MutableLiveData()
|
private val _posts: MutableLiveData<FeedDto?> = MutableLiveData()
|
||||||
val posts: LiveData<FeedDto> get() = _posts
|
val posts: LiveData<FeedDto?> get() = _posts
|
||||||
|
|
||||||
private val _loadingPosts = MutableLiveData(false)
|
private val _loadingPosts = MutableLiveData(false)
|
||||||
val loadingPosts: LiveData<Boolean> get() = _loadingPosts
|
val loadingPosts: LiveData<Boolean> get() = _loadingPosts
|
||||||
|
|
||||||
|
private val _noMoreContent = MutableLiveData(false)
|
||||||
|
val noMoreContent: LiveData<Boolean> get() = _noMoreContent
|
||||||
|
|
||||||
private val _errorLoading: MutableLiveData<Resource.Error.ErrorType?> = MutableLiveData()
|
private val _errorLoading: MutableLiveData<Resource.Error.ErrorType?> = MutableLiveData()
|
||||||
val errorLoading: LiveData<Resource.Error.ErrorType?> get() = _errorLoading
|
val errorLoading: LiveData<Resource.Error.ErrorType?> get() = _errorLoading
|
||||||
|
|
||||||
@ -41,13 +44,17 @@ class PostsViewModel @Inject constructor(private val postsRepository: PostsRepos
|
|||||||
private val _postLiked: MutableLiveData<LikeDto> = MutableLiveData()
|
private val _postLiked: MutableLiveData<LikeDto> = MutableLiveData()
|
||||||
val postLiked: LiveData<LikeDto> get() = _postLiked
|
val postLiked: LiveData<LikeDto> get() = _postLiked
|
||||||
|
|
||||||
fun getFeed() {
|
fun getFeed(refresh: Boolean) {
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
|
if(refresh) {
|
||||||
|
_posts.value = null
|
||||||
|
}
|
||||||
postsRepository.getFeed(getLastId()).onEach {
|
postsRepository.getFeed(getLastId()).onEach {
|
||||||
when(it) {
|
when(it) {
|
||||||
is Resource.Success -> {
|
is Resource.Success -> {
|
||||||
_loadingPosts.postValue(false)
|
_loadingPosts.postValue(false)
|
||||||
_posts.postValue(posts.value?.concatFeed(it.data) ?: it.data)
|
_posts.postValue(posts.value?.concatFeed(it.data) ?: it.data)
|
||||||
|
_noMoreContent.postValue(it.data?.moreContent == false)
|
||||||
}
|
}
|
||||||
is Resource.Loading -> {
|
is Resource.Loading -> {
|
||||||
_loadingPosts.postValue(true)
|
_loadingPosts.postValue(true)
|
||||||
|
|||||||
5
app/src/main/res/drawable/baseline_refresh_24.xml
Normal file
5
app/src/main/res/drawable/baseline_refresh_24.xml
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<vector android:height="24dp" android:tint="#000000"
|
||||||
|
android:viewportHeight="24" android:viewportWidth="24"
|
||||||
|
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<path android:fillColor="@android:color/white" android:pathData="M17.65,6.35C16.2,4.9 14.21,4 12,4c-4.42,0 -7.99,3.58 -7.99,8s3.57,8 7.99,8c3.73,0 6.84,-2.55 7.73,-6h-2.08c-0.82,2.33 -3.04,4 -5.65,4 -3.31,0 -6,-2.69 -6,-6s2.69,-6 6,-6c1.66,0 3.14,0.69 4.22,1.78L13,11h7V4l-2.35,2.35z"/>
|
||||||
|
</vector>
|
||||||
@ -57,16 +57,61 @@
|
|||||||
|
|
||||||
</com.google.android.material.appbar.AppBarLayout>
|
</com.google.android.material.appbar.AppBarLayout>
|
||||||
|
|
||||||
<androidx.recyclerview.widget.RecyclerView
|
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
||||||
android:id="@+id/feed_recycler_view"
|
android:id="@+id/swipe_to_refresh"
|
||||||
android:layout_width="0dp"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="0dp"
|
android:layout_height="0dp"
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintTop_toBottomOf="@+id/topAppBar_layout">
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
|
||||||
app:layout_constraintTop_toBottomOf="@+id/topAppBar_layout"
|
<androidx.core.widget.NestedScrollView
|
||||||
tools:layout_conversion_absoluteHeight="242dp"
|
android:layout_width="match_parent"
|
||||||
tools:layout_conversion_absoluteWidth="531dp" />
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
|
android:id="@+id/feed_recycler_view"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/no_more_content_to_show_text_view"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="16dp"
|
||||||
|
android:text="@string/there_is_no_more_content_to_show"
|
||||||
|
android:textAlignment="center" />
|
||||||
|
|
||||||
|
<ImageButton
|
||||||
|
android:id="@+id/refresh_button"
|
||||||
|
style="@style/Widget.Material3.Button.TextButton"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:gravity="center"
|
||||||
|
android:src="@drawable/baseline_refresh_24" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/load_more_button"
|
||||||
|
style="@style/Widget.Material3.Button.TextButton"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:layout_marginTop="8dp"
|
||||||
|
android:text="@string/load_more" />
|
||||||
|
|
||||||
|
<ProgressBar
|
||||||
|
android:id="@+id/progress_bar_loading"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center" />
|
||||||
|
</LinearLayout>
|
||||||
|
</androidx.core.widget.NestedScrollView>
|
||||||
|
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
|
|
||||||
</FrameLayout>
|
</FrameLayout>
|
||||||
|
|||||||
@ -47,12 +47,51 @@
|
|||||||
</com.google.android.material.appbar.AppBarLayout>
|
</com.google.android.material.appbar.AppBarLayout>
|
||||||
|
|
||||||
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
||||||
|
android:id="@+id/swipe_to_refresh"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent" >
|
android:layout_height="match_parent" >
|
||||||
|
<androidx.core.widget.NestedScrollView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="vertical">
|
||||||
<androidx.recyclerview.widget.RecyclerView
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
android:id="@+id/feed_recycler_view"
|
android:id="@+id/feed_recycler_view"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent" />
|
android:layout_height="match_parent" />
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/no_more_content_to_show_text_view"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:textAlignment="center"
|
||||||
|
android:layout_marginTop="16dp"
|
||||||
|
android:text="@string/there_is_no_more_content_to_show"/>
|
||||||
|
<ImageButton
|
||||||
|
android:id="@+id/refresh_button"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
style="@style/Widget.Material3.Button.TextButton"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:gravity="center"
|
||||||
|
android:src="@drawable/baseline_refresh_24"/>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/load_more_button"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:layout_marginTop="8dp"
|
||||||
|
style="@style/Widget.Material3.Button.TextButton"
|
||||||
|
android:text="@string/load_more"/>
|
||||||
|
<ProgressBar
|
||||||
|
android:id="@+id/progress_bar_loading"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center" />
|
||||||
|
</LinearLayout>
|
||||||
|
</androidx.core.widget.NestedScrollView>
|
||||||
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
|
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
|||||||
@ -41,4 +41,6 @@
|
|||||||
<string name="new_post">New</string>
|
<string name="new_post">New</string>
|
||||||
<string name="discussion">Discussion</string>
|
<string name="discussion">Discussion</string>
|
||||||
<string name="add_audio">New audio</string>
|
<string name="add_audio">New audio</string>
|
||||||
|
<string name="load_more">Load more</string>
|
||||||
|
<string name="there_is_no_more_content_to_show">There is no more content to show</string>
|
||||||
</resources>
|
</resources>
|
||||||
Loading…
x
Reference in New Issue
Block a user