diff --git a/app/src/main/java/org/go/sopt/winey/domain/entity/WineyFeed.kt b/app/src/main/java/org/go/sopt/winey/domain/entity/WineyFeed.kt index d17b23ba..f3cbca55 100644 --- a/app/src/main/java/org/go/sopt/winey/domain/entity/WineyFeed.kt +++ b/app/src/main/java/org/go/sopt/winey/domain/entity/WineyFeed.kt @@ -12,6 +12,6 @@ data class WineyFeed( val writerLevel: Int, val totalPageSize: Int, val isEnd: Boolean, - val comments: Long, + var comments: Long, val timeAgo: String ) diff --git a/app/src/main/java/org/go/sopt/winey/presentation/main/feed/WineyFeedAdapter.kt b/app/src/main/java/org/go/sopt/winey/presentation/main/feed/WineyFeedAdapter.kt index 324a68bc..cf791f15 100644 --- a/app/src/main/java/org/go/sopt/winey/presentation/main/feed/WineyFeedAdapter.kt +++ b/app/src/main/java/org/go/sopt/winey/presentation/main/feed/WineyFeedAdapter.kt @@ -6,6 +6,7 @@ import android.view.ViewGroup import androidx.paging.PagingDataAdapter import androidx.recyclerview.widget.RecyclerView import org.go.sopt.winey.databinding.ItemWineyfeedPostBinding +import org.go.sopt.winey.domain.entity.DetailFeed import org.go.sopt.winey.domain.entity.WineyFeed import org.go.sopt.winey.util.view.ItemDiffCallback import org.go.sopt.winey.util.view.setOnSingleClickListener @@ -64,6 +65,19 @@ class WineyFeedAdapter( return null } + fun updateSelectedItem(detailFeed: DetailFeed): WineyFeed? { + snapshot().items.forEachIndexed { index, wineyFeed -> + if (wineyFeed.feedId == detailFeed.feedId) { + wineyFeed.isLiked = detailFeed.isLiked + wineyFeed.likes = detailFeed.likes + wineyFeed.comments = detailFeed.comments + notifyItemChanged(index) + return wineyFeed + } + } + return null + } + fun deleteItem(feedId: Int): MutableList { val currentList = snapshot().items val newList = currentList.toMutableList() diff --git a/app/src/main/java/org/go/sopt/winey/presentation/main/feed/WineyFeedFragment.kt b/app/src/main/java/org/go/sopt/winey/presentation/main/feed/WineyFeedFragment.kt index 66f40e2c..fea0eec9 100644 --- a/app/src/main/java/org/go/sopt/winey/presentation/main/feed/WineyFeedFragment.kt +++ b/app/src/main/java/org/go/sopt/winey/presentation/main/feed/WineyFeedFragment.kt @@ -2,7 +2,6 @@ package org.go.sopt.winey.presentation.main.feed import android.content.Intent import android.os.Bundle -import android.os.Parcelable import android.view.Gravity import android.view.View import androidx.core.view.isVisible @@ -59,13 +58,13 @@ import javax.inject.Inject @AndroidEntryPoint class WineyFeedFragment : BindingFragment(R.layout.fragment_winey_feed) { - private var selectedScrollPosition: Parcelable? = null - private var selectedItemIndex: Int = -1 - private val viewModel by viewModels() private val mainViewModel by activityViewModels() + private val wineyFeedViewModel by viewModels() private lateinit var wineyFeedAdapter: WineyFeedAdapter private lateinit var wineyFeedHeaderAdapter: WineyFeedHeaderAdapter private lateinit var wineyFeedLoadAdapter: WineyFeedLoadAdapter + private var selectedItemId: Int = -1 + private var selectedItemIndex: Int = -1 @Inject lateinit var dataStoreRepository: DataStoreRepository @@ -76,7 +75,6 @@ class WineyFeedFragment : override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) amplitudeUtils.logEvent("view_homefeed") - binding.vm = mainViewModel mainViewModel.getHasNewNoti() @@ -84,8 +82,8 @@ class WineyFeedFragment : setSwipeRefreshListener() initFabClickListener() initNotificationButtonClickListener() - initDeleteFeedStateObserver() + initDeleteFeedStateObserver() initGetFeedStateObserver() initPostLikeStateObserver() removeRecyclerviewItemChangeAnimation() @@ -93,13 +91,18 @@ class WineyFeedFragment : override fun onStart() { super.onStart() - viewModel.getWineyFeed() + if (selectedItemId != -1) { + wineyFeedViewModel.getFeedDetail(selectedItemId) + initGetFeedDetailObserver() + } } private fun restoreScrollPosition() { + Timber.e("RESTORE ITEM INDEX: $selectedItemIndex") binding.rvWineyfeedPost.post { if (selectedItemIndex != -1) { binding.rvWineyfeedPost.layoutManager?.scrollToPosition(selectedItemIndex + 1) + selectedItemIndex = -1 } } } @@ -116,7 +119,7 @@ class WineyFeedFragment : wineyFeedLoadAdapter = WineyFeedLoadAdapter() wineyFeedAdapter = WineyFeedAdapter( onlikeButtonClicked = { wineyFeed -> - viewModel.likeFeed(wineyFeed.feedId, !wineyFeed.isLiked) + wineyFeedViewModel.likeFeed(wineyFeed.feedId, !wineyFeed.isLiked) }, onPopupMenuClicked = { anchorView, wineyFeed -> showFeedPopupMenu(anchorView, wineyFeed) @@ -178,7 +181,7 @@ class WineyFeedFragment : stringOf(R.string.comment_delete_dialog_positive_button), handleNegativeButton = {}, handlePositiveButton = { - viewModel.deleteFeed(feed.feedId) + wineyFeedViewModel.deleteFeed(feed.feedId) deletePagingDataItem(feed.feedId) } ) @@ -206,7 +209,7 @@ class WineyFeedFragment : private fun isMyFeed(currentUserId: Int?, writerId: Int) = currentUserId == writerId private fun initDeleteFeedStateObserver() { - viewModel.deleteWineyFeedState.flowWithLifecycle(viewLifeCycle) + wineyFeedViewModel.deleteWineyFeedState.flowWithLifecycle(viewLifeCycle) .onEach { state -> when (state) { is UiState.Success -> { @@ -215,7 +218,7 @@ class WineyFeedFragment : true, stringOf(R.string.snackbar_feed_delete_success) ) - viewModel.initDeleteFeedState() + wineyFeedViewModel.initDeleteFeedState() } is UiState.Failure -> { @@ -235,28 +238,12 @@ class WineyFeedFragment : } private fun initGetFeedStateObserver() { - viewLifecycleOwner.lifecycleScope.launch { + viewLifeCycleScope.launch { viewLifecycleOwner.repeatOnLifecycle(Lifecycle.State.STARTED) { - viewModel.getWineyFeedListState.collectLatest { state -> + wineyFeedViewModel.getWineyFeedListState.collectLatest { state -> when (state) { is UiState.Success -> { - wineyFeedAdapter.addLoadStateListener { loadState -> - when (loadState.refresh) { - is LoadState.Loading -> { - binding.rvWineyfeedPost.isVisible = false - } - - is LoadState.NotLoading -> { - binding.rvWineyfeedPost.isVisible = - wineyFeedAdapter.itemCount > 0 - restoreScrollPosition() - } - - is LoadState.Error -> { - Timber.tag("failure").e(MSG_WINEYFEED_ERROR) - } - } - } + initPagingLoadStateListener() wineyFeedAdapter.submitData(state.data) } @@ -271,8 +258,27 @@ class WineyFeedFragment : } } + private fun initPagingLoadStateListener() { + wineyFeedAdapter.addLoadStateListener { loadState -> + when (loadState.refresh) { + is LoadState.Loading -> { + binding.rvWineyfeedPost.isVisible = false + } + + is LoadState.NotLoading -> { + binding.rvWineyfeedPost.isVisible = wineyFeedAdapter.itemCount > 0 + restoreScrollPosition() + } + + is LoadState.Error -> { + Timber.tag("failure").e(MSG_WINEYFEED_ERROR) + } + } + } + } + private fun initPostLikeStateObserver() { - viewModel.postWineyFeedLikeState.flowWithLifecycle(viewLifeCycle).onEach { state -> + wineyFeedViewModel.postWineyFeedLikeState.flowWithLifecycle(viewLifeCycle).onEach { state -> when (state) { is UiState.Success -> { val item = wineyFeedAdapter.updateItem( @@ -327,6 +333,25 @@ class WineyFeedFragment : } } + private fun initGetFeedDetailObserver() { + viewLifeCycleScope.launch { + wineyFeedViewModel.getFeedDetailState.flowWithLifecycle(viewLifeCycle).collectLatest { state -> + when (state) { + is UiState.Success -> { + val detailFeed = state.data ?: return@collectLatest + wineyFeedAdapter.updateSelectedItem(detailFeed) + } + + is UiState.Failure -> { + snackBar(binding.root) { state.msg } + } + + else -> Timber.tag("failure").e("DetailActivity.MSG_DETAIL_ERROR") + } + } + } + } + private fun isGoalValid(data: User?) { if (data?.isOver == true) { showGoalSettingDialog() @@ -394,14 +419,18 @@ class WineyFeedFragment : } private fun navigateToDetail(wineyFeed: WineyFeed) { - selectedItemIndex = wineyFeedAdapter.snapshot().indexOf(wineyFeed) - selectedScrollPosition = binding.rvWineyfeedPost.layoutManager?.onSaveInstanceState() - - val intent = Intent(requireContext(), DetailActivity::class.java) - intent.putExtra(KEY_FEED_ID, wineyFeed.feedId) - intent.putExtra(KEY_FEED_WRITER_ID, wineyFeed.userId) - intent.putExtra(KEY_PREV_SCREEN, WINEY_FEED_SCREEN) - startActivity(intent) + val currentItemSnapshotList = wineyFeedAdapter.snapshot() + Timber.e("CURRENT ITEM SIZE: ${currentItemSnapshotList.size}") + selectedItemId = wineyFeed.feedId + selectedItemIndex = currentItemSnapshotList.indexOf(wineyFeed) + Timber.e("CLICKED ITEM INDEX: $selectedItemIndex") + + Intent(requireContext(), DetailActivity::class.java).apply { + putExtra(KEY_FEED_ID, wineyFeed.feedId) + putExtra(KEY_FEED_WRITER_ID, wineyFeed.userId) + putExtra(KEY_PREV_SCREEN, WINEY_FEED_SCREEN) + startActivity(this) + } } private fun sendWineyFeedEvent(type: EventType, feed: WineyFeed) { diff --git a/app/src/main/java/org/go/sopt/winey/presentation/main/feed/WineyFeedViewModel.kt b/app/src/main/java/org/go/sopt/winey/presentation/main/feed/WineyFeedViewModel.kt index 867a81a7..0f4d20c9 100644 --- a/app/src/main/java/org/go/sopt/winey/presentation/main/feed/WineyFeedViewModel.kt +++ b/app/src/main/java/org/go/sopt/winey/presentation/main/feed/WineyFeedViewModel.kt @@ -11,6 +11,7 @@ import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.flow.collectLatest import kotlinx.coroutines.launch import org.go.sopt.winey.data.model.remote.request.RequestPostLikeDto +import org.go.sopt.winey.domain.entity.DetailFeed import org.go.sopt.winey.domain.entity.Like import org.go.sopt.winey.domain.entity.WineyFeed import org.go.sopt.winey.domain.repository.FeedRepository @@ -23,6 +24,11 @@ import javax.inject.Inject class WineyFeedViewModel @Inject constructor( private val feedRepository: FeedRepository ) : ViewModel() { + private val _getFeedDetailState = + MutableStateFlow>(UiState.Loading) + val getFeedDetailState: StateFlow> = + _getFeedDetailState.asStateFlow() + private val _getWineyFeedListState = MutableStateFlow>>(UiState.Empty) val getWineyFeedListState: StateFlow>> = @@ -34,10 +40,6 @@ class WineyFeedViewModel @Inject constructor( private val _deleteWineyFeedState = MutableStateFlow>(UiState.Empty) val deleteWineyFeedState: StateFlow> = _deleteWineyFeedState.asStateFlow() - fun initDeleteFeedState() { - _deleteWineyFeedState.value = UiState.Empty - } - init { getWineyFeed() } @@ -47,6 +49,16 @@ class WineyFeedViewModel @Inject constructor( postLike(feedId, requestPostLikeDto) } + fun getFeedDetail(feedId: Int) { + viewModelScope.launch { + feedRepository.getFeedDetail(feedId) + .onSuccess { response -> + _getFeedDetailState.emit(UiState.Success(response)) + } + .onFailure { t -> handleFailureState(_getFeedDetailState, t) } + } + } + fun deleteFeed(feedId: Int) { viewModelScope.launch { _deleteWineyFeedState.emit(UiState.Loading) @@ -59,6 +71,10 @@ class WineyFeedViewModel @Inject constructor( } } + fun initDeleteFeedState() { + _deleteWineyFeedState.value = UiState.Empty + } + private fun postLike(feedId: Int, requestPostLikeDto: RequestPostLikeDto) { viewModelScope.launch { _postWineyFeedLikeState.emit(UiState.Loading) @@ -71,7 +87,7 @@ class WineyFeedViewModel @Inject constructor( } } - fun getWineyFeed() { + private fun getWineyFeed() { viewModelScope.launch { _getWineyFeedListState.emit(UiState.Loading) diff --git a/app/src/main/java/org/go/sopt/winey/presentation/main/feed/detail/DetailActivity.kt b/app/src/main/java/org/go/sopt/winey/presentation/main/feed/detail/DetailActivity.kt index 7256942f..6360a264 100644 --- a/app/src/main/java/org/go/sopt/winey/presentation/main/feed/detail/DetailActivity.kt +++ b/app/src/main/java/org/go/sopt/winey/presentation/main/feed/detail/DetailActivity.kt @@ -40,17 +40,14 @@ import javax.inject.Inject @AndroidEntryPoint class DetailActivity : BindingActivity(R.layout.activity_detail) { private val viewModel by viewModels() - private val feedId by lazy { intent.getIntExtra(KEY_FEED_ID, 0) } private val feedWriterId by lazy { intent.getIntExtra(KEY_FEED_WRITER_ID, 0) } private val prevScreenName by lazy { intent.extras?.getString(KEY_PREV_SCREEN, "") } private var _detailFeedAdapter: DetailFeedAdapter? = null private val detailFeedAdapter get() = requireNotNull(_detailFeedAdapter) - private var _commentAdapter: CommentAdapter? = null private val commentAdapter get() = requireNotNull(_commentAdapter) - private val commentEmptyAdapter by lazy { CommentEmptyAdapter() } @Inject @@ -61,7 +58,6 @@ class DetailActivity : BindingActivity(R.layout.activity_ override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - binding.vm = viewModel viewModel.getFeedDetail(feedId) diff --git a/app/src/main/java/org/go/sopt/winey/presentation/main/mypage/myfeed/MyFeedAdapter.kt b/app/src/main/java/org/go/sopt/winey/presentation/main/mypage/myfeed/MyFeedAdapter.kt index 7b817fea..538b3da7 100644 --- a/app/src/main/java/org/go/sopt/winey/presentation/main/mypage/myfeed/MyFeedAdapter.kt +++ b/app/src/main/java/org/go/sopt/winey/presentation/main/mypage/myfeed/MyFeedAdapter.kt @@ -6,6 +6,7 @@ import android.view.ViewGroup import androidx.paging.PagingDataAdapter import androidx.recyclerview.widget.RecyclerView import org.go.sopt.winey.databinding.ItemMyfeedPostBinding +import org.go.sopt.winey.domain.entity.DetailFeed import org.go.sopt.winey.domain.entity.WineyFeed import org.go.sopt.winey.util.view.ItemDiffCallback import org.go.sopt.winey.util.view.setOnSingleClickListener @@ -60,7 +61,18 @@ class MyFeedAdapter( } } } - + fun updateSelectedItem(detailFeed: DetailFeed): WineyFeed? { + snapshot().items.forEachIndexed { index, wineyFeed -> + if (wineyFeed.feedId == detailFeed.feedId) { + wineyFeed.isLiked = detailFeed.isLiked + wineyFeed.likes = detailFeed.likes + wineyFeed.comments = detailFeed.comments + notifyItemChanged(index) + return wineyFeed + } + } + return null + } fun deleteItem(feedId: Int): MutableList { val currentList = snapshot().items val newList = currentList.toMutableList() diff --git a/app/src/main/java/org/go/sopt/winey/presentation/main/mypage/myfeed/MyFeedFragment.kt b/app/src/main/java/org/go/sopt/winey/presentation/main/mypage/myfeed/MyFeedFragment.kt index e75716be..a6043227 100644 --- a/app/src/main/java/org/go/sopt/winey/presentation/main/mypage/myfeed/MyFeedFragment.kt +++ b/app/src/main/java/org/go/sopt/winey/presentation/main/mypage/myfeed/MyFeedFragment.kt @@ -2,7 +2,6 @@ package org.go.sopt.winey.presentation.main.mypage.myfeed import android.content.Intent import android.os.Bundle -import android.os.Parcelable import android.view.Gravity import android.view.View import androidx.core.view.isVisible @@ -17,7 +16,6 @@ import androidx.lifecycle.repeatOnLifecycle import androidx.paging.LoadState import androidx.paging.PagingData import androidx.recyclerview.widget.SimpleItemAnimator -import com.google.android.material.bottomnavigation.BottomNavigationView import dagger.hilt.android.AndroidEntryPoint import kotlinx.coroutines.flow.collectLatest import kotlinx.coroutines.flow.launchIn @@ -38,16 +36,15 @@ import org.go.sopt.winey.util.fragment.viewLifeCycleScope import org.go.sopt.winey.util.fragment.wineySnackbar import org.go.sopt.winey.util.view.UiState import org.go.sopt.winey.util.view.WineyPopupMenu -import org.go.sopt.winey.util.view.setOnSingleClickListener import timber.log.Timber @AndroidEntryPoint class MyFeedFragment : BindingFragment(R.layout.fragment_myfeed) { - private var selectedScrollPosition: Parcelable? = null - private var selectedItemIndex: Int = -1 private val viewModel by viewModels() private lateinit var myFeedAdapter: MyFeedAdapter private lateinit var wineyFeedLoadAdapter: WineyFeedLoadAdapter + private var selectedItemId: Int = -1 + private var selectedItemIndex: Int = -1 override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) @@ -60,10 +57,12 @@ class MyFeedFragment : BindingFragment(R.layout.fragment_ initPostLikeStateObserver() initDeleteFeedStateObserver() } - override fun onStart() { super.onStart() - viewModel.getMyFeed() + if (selectedItemId != -1) { + viewModel.getFeedDetail(selectedItemId) + initGetFeedDetailObserver() + } } private fun initAdapter() { @@ -81,6 +80,7 @@ class MyFeedFragment : BindingFragment(R.layout.fragment_ } private fun restoreScrollPosition() { + Timber.e("RESTORE ITEM INDEX: $selectedItemIndex") binding.rvMyfeedPost.post { if (selectedItemIndex != -1) { binding.rvMyfeedPost.layoutManager?.scrollToPosition(selectedItemIndex + 1) @@ -130,7 +130,7 @@ class MyFeedFragment : BindingFragment(R.layout.fragment_ } private fun initBackButtonClickListener() { - binding.imgMyfeedBack.setOnSingleClickListener { + binding.imgMyfeedBack.setOnClickListener { navigateTo() parentFragmentManager.popBackStack() } @@ -178,25 +178,7 @@ class MyFeedFragment : BindingFragment(R.layout.fragment_ viewModel.getMyFeedListState.collectLatest { state -> when (state) { is UiState.Success -> { - myFeedAdapter.addLoadStateListener { loadState -> - when (loadState.refresh) { - is LoadState.Loading -> { - binding.clMyfeedEmpty.isVisible = false - binding.rvMyfeedPost.isVisible = false - } - - is LoadState.NotLoading -> { - binding.rvMyfeedPost.isVisible = myFeedAdapter.itemCount > 0 - binding.clMyfeedEmpty.isVisible = - myFeedAdapter.itemCount == 0 - restoreScrollPosition() - } - - is LoadState.Error -> { - Timber.tag("failure").e(MSG_MYFEED_ERROR) - } - } - } + initPagingLoadStateListener() myFeedAdapter.submitData(state.data) } @@ -211,6 +193,28 @@ class MyFeedFragment : BindingFragment(R.layout.fragment_ } } + private fun initPagingLoadStateListener() { + myFeedAdapter.addLoadStateListener { loadState -> + when (loadState.refresh) { + is LoadState.Loading -> { + binding.clMyfeedEmpty.isVisible = false + binding.rvMyfeedPost.isVisible = false + } + + is LoadState.NotLoading -> { + binding.rvMyfeedPost.isVisible = myFeedAdapter.itemCount > 0 + binding.clMyfeedEmpty.isVisible = + myFeedAdapter.itemCount == 0 + restoreScrollPosition() + } + + is LoadState.Error -> { + Timber.tag("failure").e(MSG_MYFEED_ERROR) + } + } + } + } + private fun initPostLikeStateObserver() { viewModel.postMyFeedLikeState.flowWithLifecycle(viewLifeCycle).onEach { state -> when (state) { @@ -231,33 +235,53 @@ class MyFeedFragment : BindingFragment(R.layout.fragment_ }.launchIn(viewLifeCycleScope) } + private fun initGetFeedDetailObserver() { + viewLifeCycleScope.launch { + viewModel.getFeedDetailState.flowWithLifecycle(viewLifeCycle).collectLatest { state -> + when (state) { + is UiState.Success -> { + val detailFeed = state.data ?: return@collectLatest + myFeedAdapter.updateSelectedItem(detailFeed) + } + + is UiState.Failure -> { + snackBar(binding.root) { state.msg } + } + + else -> Timber.tag("failure").e("DetailActivity.MSG_DETAIL_ERROR") + } + } + } + } + private fun navigateToDetail(wineyFeed: WineyFeed) { - selectedItemIndex = myFeedAdapter.snapshot().indexOf(wineyFeed) - selectedScrollPosition = binding.rvMyfeedPost.layoutManager?.onSaveInstanceState() - val intent = Intent(requireContext(), DetailActivity::class.java) - intent.putExtra(KEY_FEED_ID, wineyFeed.feedId) - intent.putExtra(KEY_FEED_WRITER_ID, wineyFeed.userId) - intent.putExtra(KEY_PREV_SCREEN, MY_FEED_SCREEN) - startActivity(intent) + val currentItemSnapshotList = myFeedAdapter.snapshot() + Timber.e("CURRENT ITEM SIZE: ${currentItemSnapshotList.size}") + selectedItemId = wineyFeed.feedId + selectedItemIndex = currentItemSnapshotList.indexOf(wineyFeed) + Timber.e("CLICKED ITEM INDEX: $selectedItemIndex") + + Intent(requireContext(), DetailActivity::class.java).apply { + putExtra(KEY_FEED_ID, wineyFeed.feedId) + putExtra(KEY_FEED_WRITER_ID, wineyFeed.userId) + putExtra(KEY_PREV_SCREEN, MY_FEED_SCREEN) + startActivity(this) + } } private inline fun navigateTo() { parentFragmentManager.commit { replace(R.id.fcv_main, T::class.simpleName) } - val bottomNav: BottomNavigationView = requireActivity().findViewById(R.id.bnv_main) - bottomNav.selectedItemId = R.id.menu_mypage } companion object { private const val KEY_FEED_ID = "feedId" private const val KEY_FEED_WRITER_ID = "feedWriterId" private const val KEY_PREV_SCREEN = "PREV_SCREEN_NAME" - private const val POPUP_MENU_OFFSET = 65 private const val MSG_MYFEED_ERROR = "ERROR" private const val TAG_FEED_DELETE_DIALOG = "DELETE_DIALOG" - private const val MY_FEED_SCREEN = "MyFeedFragment" } } diff --git a/app/src/main/java/org/go/sopt/winey/presentation/main/mypage/myfeed/MyFeedViewModel.kt b/app/src/main/java/org/go/sopt/winey/presentation/main/mypage/myfeed/MyFeedViewModel.kt index 831554a9..cc9851ad 100644 --- a/app/src/main/java/org/go/sopt/winey/presentation/main/mypage/myfeed/MyFeedViewModel.kt +++ b/app/src/main/java/org/go/sopt/winey/presentation/main/mypage/myfeed/MyFeedViewModel.kt @@ -11,6 +11,7 @@ import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.flow.collectLatest import kotlinx.coroutines.launch import org.go.sopt.winey.data.model.remote.request.RequestPostLikeDto +import org.go.sopt.winey.domain.entity.DetailFeed import org.go.sopt.winey.domain.entity.Like import org.go.sopt.winey.domain.entity.WineyFeed import org.go.sopt.winey.domain.repository.FeedRepository @@ -34,6 +35,11 @@ class MyFeedViewModel @Inject constructor( private val _deleteMyFeedState = MutableStateFlow>(UiState.Empty) val deleteMyFeedState: StateFlow> = _deleteMyFeedState.asStateFlow() + private val _getFeedDetailState = + MutableStateFlow>(UiState.Loading) + val getFeedDetailState: StateFlow> = + _getFeedDetailState.asStateFlow() + init { getMyFeed() } @@ -59,7 +65,7 @@ class MyFeedViewModel @Inject constructor( } } - fun getMyFeed() { + private fun getMyFeed() { viewModelScope.launch { _getMyFeedListState.emit(UiState.Loading) @@ -70,6 +76,16 @@ class MyFeedViewModel @Inject constructor( } } + fun getFeedDetail(feedId: Int) { + viewModelScope.launch { + feedRepository.getFeedDetail(feedId) + .onSuccess { response -> + _getFeedDetailState.emit(UiState.Success(response)) + } + .onFailure { t -> handleFailureState(_getFeedDetailState, t) } + } + } + fun deleteFeed(feedId: Int) { viewModelScope.launch { feedRepository.deleteFeed(feedId)