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

View File

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

View File

@ -44,11 +44,15 @@ class ProfileViewModel @Inject constructor(private val getProfileUseCase: GetPro
override fun getFeed(refresh: Boolean) { override fun getFeed(refresh: Boolean) {
viewModelScope.launch { viewModelScope.launch {
if(refresh) {
posts.value = Pair(null, UpdateEvent(UpdateEvent.UpdateType.REFRESH, null))
getLastId()
}
getProfilePostsUseCase(profileId, getLastId(), false, null).onEach { feedDtoResource -> getProfilePostsUseCase(profileId, getLastId(), false, null).onEach { feedDtoResource ->
when (feedDtoResource) { when (feedDtoResource) {
is Resource.Success -> { is Resource.Success -> {
loadingPosts.postValue(false) 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) 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.home.FeedFragment
import com.isolaatti.posting.PostViewerActivity import com.isolaatti.posting.PostViewerActivity
import com.isolaatti.posting.comments.presentation.BottomSheetPostComments 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.domain.Options
import com.isolaatti.posting.common.options_bottom_sheet.presentation.BottomSheetPostOptionsViewModel import com.isolaatti.posting.common.options_bottom_sheet.presentation.BottomSheetPostOptionsViewModel
import com.isolaatti.posting.common.options_bottom_sheet.ui.BottomSheetPostOptionsFragment 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 import io.noties.markwon.linkify.LinkifyPlugin
@AndroidEntryPoint @AndroidEntryPoint
class DiscussionsFragment : Fragment() { class ProfileMainFragment : Fragment() {
lateinit var viewBinding: FragmentDiscussionsBinding lateinit var viewBinding: FragmentDiscussionsBinding
private val viewModel: ProfileViewModel by viewModels() private val viewModel: ProfileViewModel by viewModels()
val optionsViewModel: BottomSheetPostOptionsViewModel by activityViewModels() val optionsViewModel: BottomSheetPostOptionsViewModel by activityViewModels()
@ -62,8 +61,8 @@ class DiscussionsFragment : Fragment() {
viewBinding.textViewDescription.text = profile.descriptionText viewBinding.textViewDescription.text = profile.descriptionText
} }
private val postsObserver: Observer<Pair<FeedDto?, UpdateEvent>> = Observer { private val postsObserver: Observer<Pair<FeedDto?, UpdateEvent>?> = Observer {
if(it.first != null) { if(it?.first != null) {
postsAdapter.updateList(it.first!!, it.second) postsAdapter.updateList(it.first!!, it.second)
} }
@ -96,11 +95,11 @@ class DiscussionsFragment : Fragment() {
viewBinding.bottomAppBar.setOnMenuItemClickListener { viewBinding.bottomAppBar.setOnMenuItemClickListener {
when(it.itemId) { when(it.itemId) {
R.id.audios_menu_item -> { R.id.audios_menu_item -> {
findNavController().navigate(DiscussionsFragmentDirections.actionDiscussionsFragmentToAudiosFragment()) findNavController().navigate(ProfileMainFragmentDirections.actionDiscussionsFragmentToAudiosFragment())
true true
} }
R.id.images_menu_item -> { R.id.images_menu_item -> {
findNavController().navigate(DiscussionsFragmentDirections.actionDiscussionsFragmentToImagesFragment()) findNavController().navigate(ProfileMainFragmentDirections.actionDiscussionsFragmentToImagesFragment())
true true
} }
else -> { false } else -> { false }
@ -109,11 +108,18 @@ class DiscussionsFragment : Fragment() {
viewBinding.feedRecyclerView.adapter = postsAdapter viewBinding.feedRecyclerView.adapter = postsAdapter
viewBinding.feedRecyclerView.layoutManager = LinearLayoutManager(requireContext(), LinearLayoutManager.VERTICAL, false) viewBinding.feedRecyclerView.layoutManager = LinearLayoutManager(requireContext(), LinearLayoutManager.VERTICAL, false)
viewBinding.swipeToRefresh.setOnRefreshListener {
viewModel.getFeed(true)
}
} }
private fun setObservers() { private fun setObservers() {
viewModel.profile.observe(viewLifecycleOwner, profileObserver) viewModel.profile.observe(viewLifecycleOwner, profileObserver)
viewModel.posts.observe(viewLifecycleOwner, postsObserver) viewModel.posts.observe(viewLifecycleOwner, postsObserver)
viewModel.loadingPosts.observe(viewLifecycleOwner) {
viewBinding.swipeToRefresh.isRefreshing = it
}
} }
private fun getData() { private fun getData() {

View File

@ -97,6 +97,7 @@
</com.google.android.material.appbar.CollapsingToolbarLayout> </com.google.android.material.appbar.CollapsingToolbarLayout>
</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"
android:layout_marginBottom="80dp" android:layout_marginBottom="80dp"

View File

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