Skip to content

Commit

Permalink
Fixed broken animation for news without contacts infos
Browse files Browse the repository at this point in the history
  • Loading branch information
s1g53gv committed Dec 3, 2024
1 parent 2d8a22e commit 0378563
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,22 @@ class NewsDetailViewModel(
private const val NEWS_ARG = "news"
}

private val news = MutableStateFlow<News?>(savedStateHandle.get(NEWS_ARG))
private val newsId = MutableStateFlow<String?>(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<Resource<News>> = news.combine(newsId) { _news, _newsId ->
val newsFlow: Flow<Resource<News>> = 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()
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,9 @@ class NewsDetailsFragment : Fragment() {
}
sharedElementReturnTransition = null

if (savedInstanceState == null)
if (savedInstanceState == null) {
postponeEnterTransition()
}
}

override fun onCreateView(
Expand All @@ -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 -> {
Expand All @@ -108,7 +109,6 @@ class NewsDetailsFragment : Fragment() {
}

private fun loadNewsData(news: News) {
setTransitionNames(news.id)

binding.date.text = dateFormat.format(news.date)

Expand All @@ -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()
}

Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

}
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/layout/fragment_news_details.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down

0 comments on commit 0378563

Please sign in to comment.