diff --git a/app/src/main/java/it/bz/noi/community/ui/newsDetails/NewsDetailViewModel.kt b/app/src/main/java/it/bz/noi/community/ui/newsDetails/NewsDetailViewModel.kt index c5882d6..9cb2b04 100644 --- a/app/src/main/java/it/bz/noi/community/ui/newsDetails/NewsDetailViewModel.kt +++ b/app/src/main/java/it/bz/noi/community/ui/newsDetails/NewsDetailViewModel.kt @@ -25,22 +25,22 @@ class NewsDetailViewModel( private const val NEWS_ARG = "news" } - private val news = MutableStateFlow(savedStateHandle.get(NEWS_ARG)) - private val newsId = MutableStateFlow(savedStateHandle.get(NEWS_ID_ARG)) + private val news = savedStateHandle.getStateFlow(NEWS_ARG, null as News?) + private val newsId = savedStateHandle.getStateFlow(NEWS_ID_ARG, null as String?) - val newsFlow: Flow> = news.combine(newsId) { _news, _newsId -> + val newsFlow: Flow> = news.combine(newsId) { news, newsId -> Resource.loading(null) when { - _news != null -> { + news != null -> { Resource.success( - data = _news + data = news ) } - _newsId != null -> { + newsId != null -> { try { Resource.success( data = mainRepository.getNewsDetails( - _newsId!!, + newsId, Utils.getAppLanguage() ) ) diff --git a/app/src/main/java/it/bz/noi/community/ui/newsDetails/NewsDetailsFragment.kt b/app/src/main/java/it/bz/noi/community/ui/newsDetails/NewsDetailsFragment.kt index cdcd491..232118b 100644 --- a/app/src/main/java/it/bz/noi/community/ui/newsDetails/NewsDetailsFragment.kt +++ b/app/src/main/java/it/bz/noi/community/ui/newsDetails/NewsDetailsFragment.kt @@ -65,8 +65,9 @@ class NewsDetailsFragment : Fragment() { } sharedElementReturnTransition = null - if (savedInstanceState == null) + if (savedInstanceState == null) { postponeEnterTransition() + } } override fun onCreateView( @@ -85,7 +86,7 @@ class NewsDetailsFragment : Fragment() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - + setTransitionNames() viewModel.newsFlow.asLiveData(Dispatchers.Main).observe(viewLifecycleOwner) { when (it.status) { Status.SUCCESS -> { @@ -108,7 +109,6 @@ class NewsDetailsFragment : Fragment() { } private fun loadNewsData(news: News) { - setTransitionNames(news.id) binding.date.text = dateFormat.format(news.date) @@ -117,8 +117,10 @@ class NewsDetailsFragment : Fragment() { binding.title.text = detail.title binding.shortText.text = detail.abstract + binding.shortText.isVisible = detail.abstract?.isNotBlank() == true binding.longText.text = detail.text?.let { Html.fromHtml(it, Html.FROM_HTML_MODE_LEGACY) } + binding.longText.isVisible = detail.text?.isNotBlank() == true binding.longText.movementMethod = LinkMovementMethod.getInstance() } @@ -185,15 +187,16 @@ class NewsDetailsFragment : Fragment() { } else { binding.images.isVisible = false } + startPostponedEnterTransition() } - private fun setTransitionNames(newsId: String) { - binding.header.transitionName = "header_${newsId}" - binding.logo.transitionName = "logo_${newsId}" - binding.publisher.transitionName = "publisher_${newsId}" - binding.date.transitionName = "date_${newsId}" - binding.title.transitionName = "title_${newsId}" - binding.shortText.transitionName = "shortText_${newsId}" + private fun setTransitionNames() { + binding.header.transitionName = "header" + binding.logo.transitionName = "logo" + binding.publisher.transitionName = "publisher" + binding.date.transitionName = "date" + binding.title.transitionName = "title" + binding.shortText.transitionName = "shortText" } private fun writeEmail(receiverAddress: String) { diff --git a/app/src/main/java/it/bz/noi/community/ui/today/news/NewsFragment.kt b/app/src/main/java/it/bz/noi/community/ui/today/news/NewsFragment.kt index 0d122e0..cd1857f 100644 --- a/app/src/main/java/it/bz/noi/community/ui/today/news/NewsFragment.kt +++ b/app/src/main/java/it/bz/noi/community/ui/today/news/NewsFragment.kt @@ -218,16 +218,16 @@ class NewsVH(private val binding: VhNewsBinding, detailListener: NewsDetailListe .into(binding.logo) } - setTransitionNames(news.id) + setTransitionNames() } - private fun setTransitionNames(newsId: String) { - binding.header.transitionName = "header_${newsId}" - binding.logo.transitionName = "logo_${newsId}" - binding.publisher.transitionName = "publisher_${newsId}" - binding.date.transitionName = "date_${newsId}" - binding.title.transitionName = "title_${newsId}" - binding.shortText.transitionName = "shortText_${newsId}" + private fun setTransitionNames() { + binding.header.transitionName = "header" + binding.logo.transitionName = "logo" + binding.publisher.transitionName = "publisher" + binding.date.transitionName = "date" + binding.title.transitionName = "title" + binding.shortText.transitionName = "shortText" } } diff --git a/app/src/main/res/layout/fragment_news_details.xml b/app/src/main/res/layout/fragment_news_details.xml index 0ebf06f..d7073f6 100644 --- a/app/src/main/res/layout/fragment_news_details.xml +++ b/app/src/main/res/layout/fragment_news_details.xml @@ -93,6 +93,7 @@ SPDX-License-Identifier: CC0-1.0 android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="18dp" + app:layout_goneMarginTop="0dp" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/shortText" tools:itemCount="1" @@ -103,6 +104,7 @@ SPDX-License-Identifier: CC0-1.0 android:layout_width="0dp" android:layout_height="wrap_content" android:layout_marginTop="20dp" + app:layout_goneMarginTop="0dp" android:textColor="@color/secondary_color" android:textColorLink="@color/secondary_color" app:layout_constraintStart_toStartOf="parent"