@@ -48,6 +48,7 @@ import com.into.websoso.ui.main.feed.dialog.FeedReportDialogFragment
4848import com.into.websoso.ui.main.feed.dialog.RemoveMenuType.REMOVE_FEED
4949import com.into.websoso.ui.main.feed.dialog.ReportMenuType
5050import com.into.websoso.ui.novelDetail.NovelDetailActivity
51+ import com.into.websoso.ui.novelDetail.NovelDetailViewModel
5152import com.into.websoso.ui.novelFeed.model.NovelFeedUiState
5253import com.into.websoso.ui.otherUserPage.BlockUserDialogFragment
5354import com.into.websoso.ui.otherUserPage.OtherUserPageActivity
@@ -60,6 +61,7 @@ class NovelFeedFragment : BaseFragment<FragmentNovelFeedBinding>(R.layout.fragme
6061 private val popupBinding: MenuFeedPopupBinding
6162 get() = _popupBinding ? : error(" error: binding is null" )
6263 private val novelFeedViewModel: NovelFeedViewModel by activityViewModels()
64+ private val novelDetailViewModel: NovelDetailViewModel by activityViewModels()
6365 private val feedAdapter: FeedAdapter by lazy { FeedAdapter (onClickFeedItem()) }
6466 private val singleEventHandler: SingleEventHandler by lazy { SingleEventHandler .from() }
6567 private lateinit var activityResultCallback: ActivityResultLauncher <Intent >
@@ -70,7 +72,6 @@ class NovelFeedFragment : BaseFragment<FragmentNovelFeedBinding>(R.layout.fragme
7072 savedInstanceState : Bundle ? ,
7173 ): View {
7274 _popupBinding = MenuFeedPopupBinding .inflate(inflater, container, false )
73-
7475 return super .onCreateView(inflater, container, savedInstanceState)
7576 }
7677
@@ -221,19 +222,21 @@ class NovelFeedFragment : BaseFragment<FragmentNovelFeedBinding>(R.layout.fragme
221222 noinline event : () -> Unit ,
222223 ) {
223224 when (Dialog ::class ) {
224- DialogRemovePopupMenuBinding ::class ->
225+ DialogRemovePopupMenuBinding ::class -> {
225226 FeedRemoveDialogFragment
226227 .newInstance(
227228 menuType = menuType,
228229 event = { event() },
229230 ).show(childFragmentManager, FeedRemoveDialogFragment .TAG )
231+ }
230232
231- DialogReportPopupMenuBinding ::class ->
233+ DialogReportPopupMenuBinding ::class -> {
232234 FeedReportDialogFragment
233235 .newInstance(
234236 menuType = menuType,
235237 event = { event() },
236238 ).show(childFragmentManager, FeedReportDialogFragment .TAG )
239+ }
237240 }
238241 }
239242
@@ -281,9 +284,11 @@ class NovelFeedFragment : BaseFragment<FragmentNovelFeedBinding>(R.layout.fragme
281284 activityResultCallback =
282285 registerForActivityResult(StartActivityForResult ()) { result ->
283286 when (result.resultCode) {
284- OtherUserProfileBack .RESULT_OK -> novelFeedViewModel.updateRefreshedFeeds(
285- novelId,
286- )
287+ OtherUserProfileBack .RESULT_OK -> {
288+ novelFeedViewModel.updateRefreshedFeeds(
289+ novelId,
290+ )
291+ }
287292
288293 BlockUser .RESULT_OK -> {
289294 val nickname =
@@ -361,8 +366,14 @@ class NovelFeedFragment : BaseFragment<FragmentNovelFeedBinding>(R.layout.fragme
361366 private fun setupObserver () {
362367 novelFeedViewModel.feedUiState.observe(viewLifecycleOwner) { novelFeedUiState ->
363368 when {
364- novelFeedUiState.loading -> binding.wllNovelFeed.setWebsosoLoadingVisibility(true )
365- novelFeedUiState.error -> binding.wllNovelFeed.setLoadingLayoutVisibility(false )
369+ novelFeedUiState.loading -> {
370+ binding.wllNovelFeed.setWebsosoLoadingVisibility(true )
371+ }
372+
373+ novelFeedUiState.error -> {
374+ binding.wllNovelFeed.setLoadingLayoutVisibility(false )
375+ }
376+
366377 ! novelFeedUiState.loading -> {
367378 binding.wllNovelFeed.setWebsosoLoadingVisibility(false )
368379 binding.sptrNovelFeedRefresh.setRefreshing(false )
@@ -376,11 +387,35 @@ class NovelFeedFragment : BaseFragment<FragmentNovelFeedBinding>(R.layout.fragme
376387 binding.rvNovelFeed.scrollToPosition(0 )
377388 }
378389 }
390+
391+ novelDetailViewModel.novelDetailModel.observe(viewLifecycleOwner) {
392+ val currentFeedState = novelFeedViewModel.feedUiState.value ? : return @observe
393+ if (currentFeedState.feeds.isEmpty()) return @observe
394+ updateFeeds(currentFeedState)
395+ }
379396 }
380397
381398 private fun updateFeeds (novelFeedUiState : NovelFeedUiState ) {
382399 binding.clNovelFeedNone.isVisible = novelFeedUiState.feeds.isEmpty()
383- val feeds = novelFeedUiState.feeds.map { Feed (it) }
400+
401+ val genre: String =
402+ novelDetailViewModel.novelDetailModel.value
403+ ?.novel
404+ ?.getGenres
405+ ?.firstOrNull()
406+ ?.trim()
407+ .orEmpty()
408+ .ifEmpty { ETC }
409+
410+ val feeds = novelFeedUiState.feeds.map { feed ->
411+ Feed (
412+ feed.copy(
413+ novel = feed.novel.copy(
414+ genre = genre,
415+ ),
416+ ),
417+ )
418+ }
384419 when (novelFeedUiState.isLoadable) {
385420 true -> feedAdapter.submitList(feeds + Loading )
386421 false -> feedAdapter.submitList(feeds)
@@ -405,6 +440,7 @@ class NovelFeedFragment : BaseFragment<FragmentNovelFeedBinding>(R.layout.fragme
405440
406441 companion object {
407442 private const val NOVEL_ID = " NOVEL_ID"
443+ private const val ETC = " 기타"
408444
409445 fun newInstance (novelId : Long ): NovelFeedFragment =
410446 NovelFeedFragment ().also {
0 commit comments