WIP feeds

This commit is contained in:
Erik Cavazos 2023-08-06 23:22:53 -06:00
parent 4a8d05c87b
commit 38e46d72f2
6 changed files with 27 additions and 18 deletions

View File

@ -57,6 +57,8 @@ class FeedFragment : Fragment(), OnUserInteractedWithPostCallback {
private val viewModel: FeedViewModel by activityViewModels()
val optionsViewModel: BottomSheetPostOptionsViewModel by activityViewModels()
private var currentUserId = 0
private lateinit var viewBinding: FragmentFeedBinding
private lateinit var adapter: PostsRecyclerViewAdapter
@ -101,7 +103,7 @@ class FeedFragment : Fragment(), OnUserInteractedWithPostCallback {
viewBinding.homeDrawer.setNavigationItemSelectedListener {
when(it.itemId) {
R.id.my_profile_menu_item -> {
startActivity(Intent(requireActivity(), ProfileActivity::class.java))
ProfileActivity.startActivity(requireContext(), currentUserId)
true
}
R.id.drafts_menu_item -> {
@ -168,13 +170,12 @@ class FeedFragment : Fragment(), OnUserInteractedWithPostCallback {
textViewName?.text = it.name
textViewEmail?.text = it.email
currentUserId = it.id
}
viewModel.posts.observe(viewLifecycleOwner){
if (it.first != null) {
if (it?.first != null) {
adapter.updateList(it.first!!, it.second)
}
}
@ -183,9 +184,6 @@ class FeedFragment : Fragment(), OnUserInteractedWithPostCallback {
viewBinding.swipeToRefresh.isRefreshing = it
}
// viewModel.noMoreContent.observe(viewLifecycleOwner) {
//
// }
viewModel.errorLoading.observe(viewLifecycleOwner) {
errorViewModel.error.postValue(it)

View File

@ -22,7 +22,7 @@ abstract class PostListingViewModelBase : ViewModel() {
@Inject
lateinit var getProfilePosts: GetProfilePosts
val posts: MutableLiveData<Pair<FeedDto?, UpdateEvent>> = MutableLiveData()
val posts: MutableLiveData<Pair<FeedDto?, UpdateEvent>?> = MutableLiveData()
val loadingPosts = MutableLiveData(false)

View File

@ -44,11 +44,15 @@ class ProfileViewModel @Inject constructor(private val getProfileUseCase: GetPro
override fun getFeed(refresh: Boolean) {
viewModelScope.launch {
if(refresh) {
posts.value = Pair(null, UpdateEvent(UpdateEvent.UpdateType.REFRESH, null))
getLastId()
}
getProfilePostsUseCase(profileId, getLastId(), false, null).onEach { feedDtoResource ->
when (feedDtoResource) {
is Resource.Success -> {
loadingPosts.postValue(false)
posts.postValue(Pair(posts.value?.first?.concatFeed(feedDtoResource.data) ?: feedDtoResource.data, UpdateEvent(UpdateEvent.UpdateType.PAGE_ADDED, null)))
posts.postValue(Pair(posts.value?.first?.concatFeed(feedDtoResource.data) ?: feedDtoResource.data, UpdateEvent(if(refresh) UpdateEvent.UpdateType.REFRESH else UpdateEvent.UpdateType.PAGE_ADDED, null)))
noMoreContent.postValue(feedDtoResource.data?.moreContent == false)
}

View File

@ -17,7 +17,6 @@ import com.isolaatti.databinding.FragmentDiscussionsBinding
import com.isolaatti.home.FeedFragment
import com.isolaatti.posting.PostViewerActivity
import com.isolaatti.posting.comments.presentation.BottomSheetPostComments
import com.isolaatti.posting.common.domain.OnUserInteractedWithPostCallback
import com.isolaatti.posting.common.options_bottom_sheet.domain.Options
import com.isolaatti.posting.common.options_bottom_sheet.presentation.BottomSheetPostOptionsViewModel
import com.isolaatti.posting.common.options_bottom_sheet.ui.BottomSheetPostOptionsFragment
@ -38,7 +37,7 @@ import io.noties.markwon.image.destination.ImageDestinationProcessorRelativeToAb
import io.noties.markwon.linkify.LinkifyPlugin
@AndroidEntryPoint
class DiscussionsFragment : Fragment() {
class ProfileMainFragment : Fragment() {
lateinit var viewBinding: FragmentDiscussionsBinding
private val viewModel: ProfileViewModel by viewModels()
val optionsViewModel: BottomSheetPostOptionsViewModel by activityViewModels()
@ -62,8 +61,8 @@ class DiscussionsFragment : Fragment() {
viewBinding.textViewDescription.text = profile.descriptionText
}
private val postsObserver: Observer<Pair<FeedDto?, UpdateEvent>> = Observer {
if(it.first != null) {
private val postsObserver: Observer<Pair<FeedDto?, UpdateEvent>?> = Observer {
if(it?.first != null) {
postsAdapter.updateList(it.first!!, it.second)
}
@ -96,11 +95,11 @@ class DiscussionsFragment : Fragment() {
viewBinding.bottomAppBar.setOnMenuItemClickListener {
when(it.itemId) {
R.id.audios_menu_item -> {
findNavController().navigate(DiscussionsFragmentDirections.actionDiscussionsFragmentToAudiosFragment())
findNavController().navigate(ProfileMainFragmentDirections.actionDiscussionsFragmentToAudiosFragment())
true
}
R.id.images_menu_item -> {
findNavController().navigate(DiscussionsFragmentDirections.actionDiscussionsFragmentToImagesFragment())
findNavController().navigate(ProfileMainFragmentDirections.actionDiscussionsFragmentToImagesFragment())
true
}
else -> { false }
@ -109,11 +108,18 @@ class DiscussionsFragment : Fragment() {
viewBinding.feedRecyclerView.adapter = postsAdapter
viewBinding.feedRecyclerView.layoutManager = LinearLayoutManager(requireContext(), LinearLayoutManager.VERTICAL, false)
viewBinding.swipeToRefresh.setOnRefreshListener {
viewModel.getFeed(true)
}
}
private fun setObservers() {
viewModel.profile.observe(viewLifecycleOwner, profileObserver)
viewModel.posts.observe(viewLifecycleOwner, postsObserver)
viewModel.loadingPosts.observe(viewLifecycleOwner) {
viewBinding.swipeToRefresh.isRefreshing = it
}
}
private fun getData() {

View File

@ -97,6 +97,7 @@
</com.google.android.material.appbar.CollapsingToolbarLayout>
</com.google.android.material.appbar.AppBarLayout>
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/swipe_to_refresh"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="80dp"

View File

@ -2,11 +2,11 @@
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/profile_navigation"
app:startDestination="@id/discussionsFragment">
app:startDestination="@id/mainFragment">
<fragment
android:id="@+id/discussionsFragment"
android:name="com.isolaatti.profile.ui.DiscussionsFragment"
android:id="@+id/mainFragment"
android:name="com.isolaatti.profile.ui.ProfileMainFragment"
android:label="DiscussionsFragment" >
<action
android:id="@+id/action_discussionsFragment_to_audiosFragment"