Updated on 2026-08-14
This commit is contained in:
parent
1bb825744e
commit
92e21cc79c
5 changed files with 62 additions and 26 deletions
|
|
@ -108,9 +108,9 @@ internal class NewsDetailsModel @Inject constructor(
|
|||
private val stateFactory by lazy(LazyThreadSafetyMode.NONE) {
|
||||
NewsDetailsStateFactory(
|
||||
currentStateProvider = Provider { _state.value },
|
||||
shareManager = shareManager,
|
||||
onStateUpdate = { newState -> _state.update { newState } },
|
||||
onRetryClick = ::onRetryClicked,
|
||||
onShareClick = ::onShareClick,
|
||||
)
|
||||
}
|
||||
|
||||
|
|
@ -149,6 +149,11 @@ internal class NewsDetailsModel @Inject constructor(
|
|||
urlOpener.openUrl(relatedArticle.url)
|
||||
}
|
||||
|
||||
private fun onShareClick(article: ArticleUM) {
|
||||
shareManager.shareText(article.newsUrl)
|
||||
analyticsEventHandler.send(NewsDetailsAnalyticsEvent.NewsShareButtonClick(article.id))
|
||||
}
|
||||
|
||||
private fun onArticleIndexChanged(newIndex: Int) {
|
||||
stateFactory.updateSelectedArticleIndex(newIndex)
|
||||
val currentArticle = when (state.value.articlesStateUM) {
|
||||
|
|
|
|||
|
|
@ -70,4 +70,20 @@ internal sealed class NewsDetailsAnalyticsEvent(
|
|||
ERROR_MESSAGE to message,
|
||||
),
|
||||
)
|
||||
|
||||
data class NewsShareButtonClick(
|
||||
private val newsId: Int,
|
||||
) : NewsDetailsAnalyticsEvent(
|
||||
event = "News Share Button Clicked",
|
||||
params = mapOf(
|
||||
"News Id" to newsId.toString(),
|
||||
),
|
||||
), OneTimePerSessionEvent {
|
||||
override val oneTimeEventId: String = event
|
||||
override val throttleSeconds: Long = THROTTLE_SECONDS
|
||||
}
|
||||
|
||||
private companion object {
|
||||
const val THROTTLE_SECONDS = 10L
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,5 @@
|
|||
package com.tangem.features.feed.model.news.details.factory
|
||||
|
||||
import com.tangem.core.navigation.share.ShareManager
|
||||
import com.tangem.features.feed.ui.news.details.state.ArticleUM
|
||||
import com.tangem.features.feed.ui.news.details.state.ArticlesStateUM
|
||||
import com.tangem.features.feed.ui.news.details.state.NewsDetailsUM
|
||||
|
|
@ -10,7 +9,7 @@ import kotlinx.collections.immutable.toImmutableList
|
|||
|
||||
internal class NewsDetailsStateFactory(
|
||||
private val currentStateProvider: Provider<NewsDetailsUM>,
|
||||
private val shareManager: ShareManager,
|
||||
private val onShareClick: (ArticleUM) -> Unit,
|
||||
private val onStateUpdate: (NewsDetailsUM) -> Unit,
|
||||
private val onRetryClick: () -> Unit,
|
||||
) {
|
||||
|
|
@ -23,11 +22,7 @@ internal class NewsDetailsStateFactory(
|
|||
articles = articles.toImmutableList(),
|
||||
articlesStateUM = ArticlesStateUM.Content,
|
||||
selectedArticleIndex = selectedIndex,
|
||||
onShareClick = {
|
||||
currentArticle?.let {
|
||||
shareManager.shareText(it.newsUrl)
|
||||
}
|
||||
},
|
||||
onShareClick = { currentArticle?.let(onShareClick) },
|
||||
),
|
||||
)
|
||||
}
|
||||
|
|
@ -38,11 +33,7 @@ internal class NewsDetailsStateFactory(
|
|||
onStateUpdate(
|
||||
currentState.copy(
|
||||
selectedArticleIndex = newIndex,
|
||||
onShareClick = {
|
||||
currentArticle?.let {
|
||||
shareManager.shareText(it.newsUrl)
|
||||
}
|
||||
},
|
||||
onShareClick = { currentArticle?.let(onShareClick) },
|
||||
),
|
||||
)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue