From 3fd75f63314da4156bbd7fc6d2d311da0e21b394 Mon Sep 17 00:00:00 2001 From: leeeha Date: Sun, 10 Sep 2023 16:18:14 +0900 Subject: [PATCH 01/11] =?UTF-8?q?[fix]=20#192=20onStart=20=ED=95=A8?= =?UTF-8?q?=EC=88=98=EC=97=90=EC=84=9C=20=EC=9C=84=EB=8B=88=ED=94=BC?= =?UTF-8?q?=EB=93=9C=20=EB=A6=AC=EC=8A=A4=ED=8A=B8=20=EC=A1=B0=ED=9A=8C?= =?UTF-8?q?=ED=95=98=EC=A7=80=20=EC=95=8A=EB=8F=84=EB=A1=9D=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/feed/WineyFeedFragment.kt | 65 ++++++++++--------- .../main/feed/detail/DetailActivity.kt | 4 -- .../main/mypage/myfeed/MyFeedFragment.kt | 1 + 3 files changed, 34 insertions(+), 36 deletions(-) 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..36e61e6b 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,7 +58,6 @@ 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() @@ -91,12 +89,8 @@ class WineyFeedFragment : removeRecyclerviewItemChangeAnimation() } - override fun onStart() { - super.onStart() - viewModel.getWineyFeed() - } - private fun restoreScrollPosition() { + Timber.e("RESTORE ITEM INDEX: $selectedItemIndex") binding.rvWineyfeedPost.post { if (selectedItemIndex != -1) { binding.rvWineyfeedPost.layoutManager?.scrollToPosition(selectedItemIndex + 1) @@ -235,28 +229,12 @@ class WineyFeedFragment : } private fun initGetFeedStateObserver() { - viewLifecycleOwner.lifecycleScope.launch { + viewLifeCycleScope.launch { viewLifecycleOwner.repeatOnLifecycle(Lifecycle.State.STARTED) { viewModel.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,6 +249,25 @@ 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 -> when (state) { @@ -394,14 +391,18 @@ class WineyFeedFragment : } private fun navigateToDetail(wineyFeed: WineyFeed) { - selectedItemIndex = wineyFeedAdapter.snapshot().indexOf(wineyFeed) - selectedScrollPosition = binding.rvWineyfeedPost.layoutManager?.onSaveInstanceState() + val currentItemSnapshotList = wineyFeedAdapter.snapshot() + Timber.e("CURRENT PAGE SIZE: ${currentItemSnapshotList.size}") - 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) + 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/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/MyFeedFragment.kt b/app/src/main/java/org/go/sopt/winey/presentation/main/mypage/myfeed/MyFeedFragment.kt index e75716be..7c6dee83 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 @@ -234,6 +234,7 @@ class MyFeedFragment : BindingFragment(R.layout.fragment_ 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) From d90b96b8e0d0c4e6a3bd3a423c4753797ff22e06 Mon Sep 17 00:00:00 2001 From: leeeha Date: Sun, 10 Sep 2023 16:21:11 +0900 Subject: [PATCH 02/11] =?UTF-8?q?[chore]=20#192=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EC=88=9C=EC=84=9C=20=EC=A0=95=EB=A0=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/feed/WineyFeedFragment.kt | 19 +++++++++---------- .../main/feed/WineyFeedViewModel.kt | 10 +++++----- 2 files changed, 14 insertions(+), 15 deletions(-) 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 36e61e6b..f01ae86d 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 @@ -58,12 +58,12 @@ import javax.inject.Inject @AndroidEntryPoint class WineyFeedFragment : BindingFragment(R.layout.fragment_winey_feed) { - 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 selectedItemIndex: Int = -1 @Inject lateinit var dataStoreRepository: DataStoreRepository @@ -74,7 +74,6 @@ class WineyFeedFragment : override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) amplitudeUtils.logEvent("view_homefeed") - binding.vm = mainViewModel mainViewModel.getHasNewNoti() @@ -82,8 +81,8 @@ class WineyFeedFragment : setSwipeRefreshListener() initFabClickListener() initNotificationButtonClickListener() - initDeleteFeedStateObserver() + initDeleteFeedStateObserver() initGetFeedStateObserver() initPostLikeStateObserver() removeRecyclerviewItemChangeAnimation() @@ -110,7 +109,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) @@ -172,7 +171,7 @@ class WineyFeedFragment : stringOf(R.string.comment_delete_dialog_positive_button), handleNegativeButton = {}, handlePositiveButton = { - viewModel.deleteFeed(feed.feedId) + wineyFeedViewModel.deleteFeed(feed.feedId) deletePagingDataItem(feed.feedId) } ) @@ -200,7 +199,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 -> { @@ -209,7 +208,7 @@ class WineyFeedFragment : true, stringOf(R.string.snackbar_feed_delete_success) ) - viewModel.initDeleteFeedState() + wineyFeedViewModel.initDeleteFeedState() } is UiState.Failure -> { @@ -231,7 +230,7 @@ class WineyFeedFragment : private fun initGetFeedStateObserver() { viewLifeCycleScope.launch { viewLifecycleOwner.repeatOnLifecycle(Lifecycle.State.STARTED) { - viewModel.getWineyFeedListState.collectLatest { state -> + wineyFeedViewModel.getWineyFeedListState.collectLatest { state -> when (state) { is UiState.Success -> { initPagingLoadStateListener() @@ -269,7 +268,7 @@ class WineyFeedFragment : } private fun initPostLikeStateObserver() { - viewModel.postWineyFeedLikeState.flowWithLifecycle(viewLifeCycle).onEach { state -> + wineyFeedViewModel.postWineyFeedLikeState.flowWithLifecycle(viewLifeCycle).onEach { state -> when (state) { is UiState.Success -> { val item = wineyFeedAdapter.updateItem( 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..8f51d8cb 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 @@ -34,10 +34,6 @@ class WineyFeedViewModel @Inject constructor( private val _deleteWineyFeedState = MutableStateFlow>(UiState.Empty) val deleteWineyFeedState: StateFlow> = _deleteWineyFeedState.asStateFlow() - fun initDeleteFeedState() { - _deleteWineyFeedState.value = UiState.Empty - } - init { getWineyFeed() } @@ -59,6 +55,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 +71,7 @@ class WineyFeedViewModel @Inject constructor( } } - fun getWineyFeed() { + private fun getWineyFeed() { viewModelScope.launch { _getWineyFeedListState.emit(UiState.Loading) From 254124061e8c0ef1ad13b59d6a2596ccf9122aef Mon Sep 17 00:00:00 2001 From: leeeha Date: Sun, 10 Sep 2023 16:31:05 +0900 Subject: [PATCH 03/11] =?UTF-8?q?[fix]=20#192=20=EB=A7=88=EC=9D=B4?= =?UTF-8?q?=ED=94=BC=EB=93=9C=20=ED=94=84=EB=9E=98=EA=B7=B8=EB=A8=BC?= =?UTF-8?q?=ED=8A=B8=EC=97=90=EC=84=9C=EB=8F=84=20onStart=EC=97=90?= =?UTF-8?q?=EC=84=9C=20=EB=A6=AC=EC=8A=A4=ED=8A=B8=20=EC=9E=AC=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20=ED=95=98=EC=A7=80=20=EC=95=8A=EB=8F=84=EB=A1=9D=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/feed/WineyFeedFragment.kt | 2 +- .../main/mypage/myfeed/MyFeedFragment.kt | 80 +++++++++---------- .../main/mypage/myfeed/MyFeedViewModel.kt | 2 +- 3 files changed, 40 insertions(+), 44 deletions(-) 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 f01ae86d..eac38fe0 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 @@ -391,7 +391,7 @@ class WineyFeedFragment : private fun navigateToDetail(wineyFeed: WineyFeed) { val currentItemSnapshotList = wineyFeedAdapter.snapshot() - Timber.e("CURRENT PAGE SIZE: ${currentItemSnapshotList.size}") + Timber.e("CURRENT ITEM SIZE: ${currentItemSnapshotList.size}") selectedItemIndex = currentItemSnapshotList.indexOf(wineyFeed) Timber.e("CLICKED ITEM INDEX: $selectedItemIndex") 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 7c6dee83..abc96935 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,14 @@ 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 selectedItemIndex: Int = -1 override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) @@ -61,11 +57,6 @@ class MyFeedFragment : BindingFragment(R.layout.fragment_ initDeleteFeedStateObserver() } - override fun onStart() { - super.onStart() - viewModel.getMyFeed() - } - private fun initAdapter() { wineyFeedLoadAdapter = WineyFeedLoadAdapter() myFeedAdapter = MyFeedAdapter( @@ -81,6 +72,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 +122,7 @@ class MyFeedFragment : BindingFragment(R.layout.fragment_ } private fun initBackButtonClickListener() { - binding.imgMyfeedBack.setOnSingleClickListener { + binding.imgMyfeedBack.setOnClickListener { navigateTo() parentFragmentManager.popBackStack() } @@ -178,25 +170,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 +185,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) { @@ -232,33 +228,33 @@ class MyFeedFragment : BindingFragment(R.layout.fragment_ } 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}") + + 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..10008bae 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 @@ -59,7 +59,7 @@ class MyFeedViewModel @Inject constructor( } } - fun getMyFeed() { + private fun getMyFeed() { viewModelScope.launch { _getMyFeedListState.emit(UiState.Loading) From 6c32f7cbcaf4ab72935e86d1bd7a77b5261120cc Mon Sep 17 00:00:00 2001 From: HyeseonBaek Date: Sun, 10 Sep 2023 17:44:04 +0900 Subject: [PATCH 04/11] =?UTF-8?q?[fix]=20#193=20Notloading=20=EC=8B=9C?= =?UTF-8?q?=EC=97=90=EB=8F=84=20=ED=8F=AC=EC=A7=80=EC=85=98=20=EC=B4=88?= =?UTF-8?q?=EA=B8=B0=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../go/sopt/winey/presentation/main/feed/WineyFeedFragment.kt | 1 + 1 file changed, 1 insertion(+) 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 eac38fe0..8ec0ed48 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 @@ -258,6 +258,7 @@ class WineyFeedFragment : is LoadState.NotLoading -> { binding.rvWineyfeedPost.isVisible = wineyFeedAdapter.itemCount > 0 restoreScrollPosition() + selectedItemIndex = -1 } is LoadState.Error -> { From 30c6616e6e5145718661e21322622a5f525e8992 Mon Sep 17 00:00:00 2001 From: leeeha Date: Sun, 10 Sep 2023 18:14:11 +0900 Subject: [PATCH 05/11] =?UTF-8?q?[fix]=20#192=20=EC=8A=A4=ED=81=AC?= =?UTF-8?q?=EB=A1=A4=20=EC=9C=84=EC=B9=98=20=EB=B3=B5=EC=9B=90=ED=95=9C=20?= =?UTF-8?q?=EB=92=A4=EC=97=90=20=EC=9D=B8=EB=8D=B1=EC=8A=A4=20-1=EB=A1=9C?= =?UTF-8?q?=20=EC=B4=88=EA=B8=B0=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 인덱스 초기화 해주지 않으면 LoadStateListener에 의해 NotLoading 상태일 때 이전에 저장해뒀던 그 위치로 스크롤이 되돌아가려는 문제가 발생함. --- .../go/sopt/winey/presentation/main/feed/WineyFeedFragment.kt | 1 + 1 file changed, 1 insertion(+) 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 eac38fe0..b892e731 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 @@ -93,6 +93,7 @@ class WineyFeedFragment : binding.rvWineyfeedPost.post { if (selectedItemIndex != -1) { binding.rvWineyfeedPost.layoutManager?.scrollToPosition(selectedItemIndex + 1) + selectedItemIndex = -1 } } } From ab78897912bcf4e30d1bbb9a6906a7b2eb13f2a7 Mon Sep 17 00:00:00 2001 From: HyeseonBaek Date: Mon, 11 Sep 2023 21:03:50 +0900 Subject: [PATCH 06/11] =?UTF-8?q?Revert=20"[fix]=20#193=20Notloading=20?= =?UTF-8?q?=EC=8B=9C=EC=97=90=EB=8F=84=20=ED=8F=AC=EC=A7=80=EC=85=98=20?= =?UTF-8?q?=EC=B4=88=EA=B8=B0=ED=99=94"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 6c32f7cbcaf4ab72935e86d1bd7a77b5261120cc. --- .../go/sopt/winey/presentation/main/feed/WineyFeedFragment.kt | 1 - 1 file changed, 1 deletion(-) 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 45407b52..b892e731 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 @@ -259,7 +259,6 @@ class WineyFeedFragment : is LoadState.NotLoading -> { binding.rvWineyfeedPost.isVisible = wineyFeedAdapter.itemCount > 0 restoreScrollPosition() - selectedItemIndex = -1 } is LoadState.Error -> { From 68c7b4ca6a27a0498fc41d2aaf299f2e6a1b007b Mon Sep 17 00:00:00 2001 From: HyeseonBaek Date: Wed, 13 Sep 2023 00:43:24 +0900 Subject: [PATCH 07/11] =?UTF-8?q?[add]=20#192=20wineyFeedViewModel?= =?UTF-8?q?=EC=97=90=EB=8F=84=20=EB=94=94=ED=85=8C=EC=9D=BC=ED=8E=98?= =?UTF-8?q?=EC=9D=B4=EC=A7=80=20=EC=A1=B0=ED=9A=8C=20=ED=95=A8=EC=88=98=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/go/sopt/winey/domain/entity/WineyFeed.kt | 2 +- .../presentation/main/feed/WineyFeedViewModel.kt | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) 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/WineyFeedViewModel.kt b/app/src/main/java/org/go/sopt/winey/presentation/main/feed/WineyFeedViewModel.kt index 8f51d8cb..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>> = @@ -43,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) From 75deef073592d963fc9d5bc16a4f769568be2868 Mon Sep 17 00:00:00 2001 From: HyeseonBaek Date: Wed, 13 Sep 2023 00:45:15 +0900 Subject: [PATCH 08/11] =?UTF-8?q?[add]=20#192=20=EB=94=94=ED=85=8C?= =?UTF-8?q?=EC=9D=BC=ED=8E=98=EC=9D=B4=EC=A7=80=EC=97=90=EC=84=9C=20?= =?UTF-8?q?=EC=83=9D=EA=B8=B4=20=EB=B3=80=EA=B2=BD=EC=82=AC=ED=95=AD(?= =?UTF-8?q?=EC=A2=8B=EC=95=84=EC=9A=94,=20=EB=8C=93=EA=B8=80=EC=88=98,=20?= =?UTF-8?q?=EC=A2=8B=EC=95=84=EC=9A=94=EC=88=98)=20=EC=97=85=EB=8D=B0?= =?UTF-8?q?=EC=9D=B4=ED=8A=B8=20=ED=95=A8=EC=88=98=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../presentation/main/feed/WineyFeedAdapter.kt | 14 ++++++++++++++ 1 file changed, 14 insertions(+) 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() From f808a1583218f45f94a43dcfee8169f50ea3a2b8 Mon Sep 17 00:00:00 2001 From: HyeseonBaek Date: Wed, 13 Sep 2023 00:47:35 +0900 Subject: [PATCH 09/11] =?UTF-8?q?[fix]=20#192=20=EB=94=94=ED=85=8C?= =?UTF-8?q?=EC=9D=BC=ED=8E=98=EC=9D=B4=EC=A7=80=20=EB=8B=A4=EB=85=80?= =?UTF-8?q?=EC=98=AC=20=EC=8B=9C=20=ED=95=B4=EB=8B=B9=20=ED=94=BC=EB=93=9C?= =?UTF-8?q?=EB=A7=8C=20=EB=B6=88=EB=9F=AC=EC=99=80=20=EB=B0=98=EC=98=81?= =?UTF-8?q?=EC=8B=9C=ED=82=B4=EC=9C=BC=EB=A1=9C=EC=84=9C=20=EC=8A=A4?= =?UTF-8?q?=ED=81=AC=EB=A1=A4=EC=9C=84=EC=B9=98=20=EB=B3=B5=EC=9B=90=20/?= =?UTF-8?q?=20=EB=B3=80=EA=B2=BD=EC=82=AC=ED=95=AD=20ui=20=EB=B0=98?= =?UTF-8?q?=EC=98=81=20=EB=AC=B8=EC=A0=9C=20=EB=AA=A8=EB=91=90=20=ED=95=B4?= =?UTF-8?q?=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/feed/WineyFeedFragment.kt | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) 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 b892e731..ddf56b1e 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 @@ -63,6 +63,7 @@ class WineyFeedFragment : 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 @@ -88,6 +89,32 @@ class WineyFeedFragment : removeRecyclerviewItemChangeAnimation() } + override fun onStart() { + super.onStart() + if (selectedItemId != -1) { + wineyFeedViewModel.getFeedDetail(selectedItemId) + updateFeed() + } + } + private fun updateFeed() { + 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 restoreScrollPosition() { Timber.e("RESTORE ITEM INDEX: $selectedItemIndex") binding.rvWineyfeedPost.post { @@ -393,7 +420,7 @@ class WineyFeedFragment : private fun navigateToDetail(wineyFeed: WineyFeed) { val currentItemSnapshotList = wineyFeedAdapter.snapshot() Timber.e("CURRENT ITEM SIZE: ${currentItemSnapshotList.size}") - + selectedItemId = wineyFeed.feedId selectedItemIndex = currentItemSnapshotList.indexOf(wineyFeed) Timber.e("CLICKED ITEM INDEX: $selectedItemIndex") From c1a388005c1463c4145843c878c4a3fd320842fa Mon Sep 17 00:00:00 2001 From: HyeseonBaek Date: Wed, 13 Sep 2023 00:54:11 +0900 Subject: [PATCH 10/11] =?UTF-8?q?[chore]=20#192=20=ED=95=A8=EC=88=98?= =?UTF-8?q?=EB=AA=85=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/feed/WineyFeedFragment.kt | 39 ++++++++++--------- 1 file changed, 20 insertions(+), 19 deletions(-) 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 ddf56b1e..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 @@ -93,25 +93,7 @@ class WineyFeedFragment : super.onStart() if (selectedItemId != -1) { wineyFeedViewModel.getFeedDetail(selectedItemId) - updateFeed() - } - } - private fun updateFeed() { - 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") - } - } + initGetFeedDetailObserver() } } @@ -351,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() From c07c7609b25e09fb3f92360302e943b008b55bae Mon Sep 17 00:00:00 2001 From: HyeseonBaek Date: Wed, 13 Sep 2023 00:57:49 +0900 Subject: [PATCH 11/11] =?UTF-8?q?[fix]=20#192=20=EB=A7=88=EC=9D=B4?= =?UTF-8?q?=ED=94=BC=EB=93=9C=EC=97=90=EB=8F=84=20=EA=B0=99=EC=9D=80=20?= =?UTF-8?q?=ED=95=B4=EA=B2=B0=EC=82=AC=ED=95=AD=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/mypage/myfeed/MyFeedAdapter.kt | 14 ++++++++- .../main/mypage/myfeed/MyFeedFragment.kt | 29 ++++++++++++++++++- .../main/mypage/myfeed/MyFeedViewModel.kt | 16 ++++++++++ 3 files changed, 57 insertions(+), 2 deletions(-) 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 abc96935..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 @@ -43,6 +43,7 @@ class MyFeedFragment : BindingFragment(R.layout.fragment_ 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?) { @@ -56,6 +57,13 @@ class MyFeedFragment : BindingFragment(R.layout.fragment_ initPostLikeStateObserver() initDeleteFeedStateObserver() } + override fun onStart() { + super.onStart() + if (selectedItemId != -1) { + viewModel.getFeedDetail(selectedItemId) + initGetFeedDetailObserver() + } + } private fun initAdapter() { wineyFeedLoadAdapter = WineyFeedLoadAdapter() @@ -227,10 +235,29 @@ 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) { val currentItemSnapshotList = myFeedAdapter.snapshot() Timber.e("CURRENT ITEM SIZE: ${currentItemSnapshotList.size}") - + selectedItemId = wineyFeed.feedId selectedItemIndex = currentItemSnapshotList.indexOf(wineyFeed) Timber.e("CLICKED ITEM INDEX: $selectedItemIndex") 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 10008bae..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() } @@ -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)